hash: Initialize libgcrypt before use.
Fixes <http://bugs.gnu.org/19677>. Reported by Mark H Weaver <mhw@netris.org>. * guix/hash.scm: Use (guix gcrypt). (sha256, open-sha256-md, md-write, md-close): Use 'libgcrypt-func' instead of 'dynamic-func'.
This commit is contained in:
		
							parent
							
								
									4862bc4a1a
								
							
						
					
					
						commit
						19a454448b
					
				
					 1 changed files with 7 additions and 12 deletions
				
			
		| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
;;; GNU Guix --- Functional package management for GNU
 | 
					;;; GNU Guix --- Functional package management for GNU
 | 
				
			||||||
;;; Copyright © 2012, 2013, 2014 Ludovic Courtès <ludo@gnu.org>
 | 
					;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
;;; This file is part of GNU Guix.
 | 
					;;; This file is part of GNU Guix.
 | 
				
			||||||
;;;
 | 
					;;;
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,7 @@
 | 
				
			||||||
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 | 
					;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define-module (guix hash)
 | 
					(define-module (guix hash)
 | 
				
			||||||
  #:use-module (guix config)
 | 
					  #:use-module (guix gcrypt)
 | 
				
			||||||
  #:use-module (rnrs bytevectors)
 | 
					  #:use-module (rnrs bytevectors)
 | 
				
			||||||
  #:use-module (rnrs io ports)
 | 
					  #:use-module (rnrs io ports)
 | 
				
			||||||
  #:use-module (system foreign)
 | 
					  #:use-module (system foreign)
 | 
				
			||||||
| 
						 | 
					@ -46,8 +46,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define sha256
 | 
					(define sha256
 | 
				
			||||||
  (let ((hash (pointer->procedure void
 | 
					  (let ((hash (pointer->procedure void
 | 
				
			||||||
                                  (dynamic-func "gcry_md_hash_buffer"
 | 
					                                  (libgcrypt-func "gcry_md_hash_buffer")
 | 
				
			||||||
                                                (dynamic-link %libgcrypt))
 | 
					 | 
				
			||||||
                                  `(,int * * ,size_t))))
 | 
					                                  `(,int * * ,size_t))))
 | 
				
			||||||
    (lambda (bv)
 | 
					    (lambda (bv)
 | 
				
			||||||
      "Return the SHA256 of BV as a bytevector."
 | 
					      "Return the SHA256 of BV as a bytevector."
 | 
				
			||||||
| 
						 | 
					@ -58,8 +57,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define open-sha256-md
 | 
					(define open-sha256-md
 | 
				
			||||||
  (let ((open (pointer->procedure int
 | 
					  (let ((open (pointer->procedure int
 | 
				
			||||||
                                  (dynamic-func "gcry_md_open"
 | 
					                                  (libgcrypt-func "gcry_md_open")
 | 
				
			||||||
                                                (dynamic-link %libgcrypt))
 | 
					 | 
				
			||||||
                                  `(* ,int ,unsigned-int))))
 | 
					                                  `(* ,int ,unsigned-int))))
 | 
				
			||||||
    (lambda ()
 | 
					    (lambda ()
 | 
				
			||||||
      (let* ((md  (bytevector->pointer (make-bytevector (sizeof '*))))
 | 
					      (let* ((md  (bytevector->pointer (make-bytevector (sizeof '*))))
 | 
				
			||||||
| 
						 | 
					@ -70,20 +68,17 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define md-write
 | 
					(define md-write
 | 
				
			||||||
  (pointer->procedure void
 | 
					  (pointer->procedure void
 | 
				
			||||||
                      (dynamic-func "gcry_md_write"
 | 
					                      (libgcrypt-func "gcry_md_write")
 | 
				
			||||||
                                    (dynamic-link %libgcrypt))
 | 
					 | 
				
			||||||
                      `(* * ,size_t)))
 | 
					                      `(* * ,size_t)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define md-read
 | 
					(define md-read
 | 
				
			||||||
  (pointer->procedure '*
 | 
					  (pointer->procedure '*
 | 
				
			||||||
                      (dynamic-func "gcry_md_read"
 | 
					                      (libgcrypt-func "gcry_md_read")
 | 
				
			||||||
                                    (dynamic-link %libgcrypt))
 | 
					 | 
				
			||||||
                      `(* ,int)))
 | 
					                      `(* ,int)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define md-close
 | 
					(define md-close
 | 
				
			||||||
  (pointer->procedure void
 | 
					  (pointer->procedure void
 | 
				
			||||||
                      (dynamic-func "gcry_md_close"
 | 
					                      (libgcrypt-func "gcry_md_close")
 | 
				
			||||||
                                    (dynamic-link %libgcrypt))
 | 
					 | 
				
			||||||
                      '(*)))
 | 
					                      '(*)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue