From ca719424455465fca4b872c371daf2a46de88b33 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 31 Aug 2018 17:07:07 +0200 Subject: Switch to Guile-Gcrypt. This removes (guix hash) and (guix pk-crypto), which now live as part of Guile-Gcrypt (version 0.1.0.) * guix/gcrypt.scm, guix/hash.scm, guix/pk-crypto.scm, tests/hash.scm, tests/pk-crypto.scm: Remove. * configure.ac: Test for Guile-Gcrypt. Remove LIBGCRYPT and LIBGCRYPT_LIBDIR assignments. * m4/guix.m4 (GUIX_ASSERT_LIBGCRYPT_USABLE): Remove. * README: Add Guile-Gcrypt to the dependencies; move libgcrypt as "required unless --disable-daemon". * doc/guix.texi (Requirements): Likewise. * gnu/packages/bash.scm, guix/derivations.scm, guix/docker.scm, guix/git.scm, guix/http-client.scm, guix/import/cpan.scm, guix/import/cran.scm, guix/import/crate.scm, guix/import/elpa.scm, guix/import/gnu.scm, guix/import/hackage.scm, guix/import/texlive.scm, guix/import/utils.scm, guix/nar.scm, guix/pki.scm, guix/scripts/archive.scm, guix/scripts/authenticate.scm, guix/scripts/download.scm, guix/scripts/hash.scm, guix/scripts/pack.scm, guix/scripts/publish.scm, guix/scripts/refresh.scm, guix/scripts/substitute.scm, guix/store.scm, guix/store/deduplication.scm, guix/tests.scm, tests/base32.scm, tests/builders.scm, tests/challenge.scm, tests/cpan.scm, tests/crate.scm, tests/derivations.scm, tests/gem.scm, tests/nar.scm, tests/opam.scm, tests/pki.scm, tests/publish.scm, tests/pypi.scm, tests/store-deduplication.scm, tests/store.scm, tests/substitute.scm: Adjust imports. * gnu/system/vm.scm: Likewise. (guile-sqlite3&co): Rename to... (gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT. (expression->derivation-in-linux-vm)[config]: Remove. (iso9660-image)[config]: Remove. (qemu-image)[config]: Remove. (system-docker-image)[config]: Remove. * guix/scripts/pack.scm: Adjust imports. (guile-sqlite3&co): Rename to... (gcrypt-sqlite3&co): ... this. Add GUILE-GCRYPT. (self-contained-tarball)[build]: Call 'make-config.scm' without #:libgcrypt argument. (squashfs-image)[libgcrypt]: Remove. [build]: Call 'make-config.scm' without #:libgcrypt. (docker-image)[config, json]: Remove. [build]: Add GUILE-GCRYPT to the extensions Remove (guix config) from the imported modules. * guix/self.scm (specification->package): Remove "libgcrypt", add "guile-gcrypt". (compiled-guix): Remove #:libgcrypt. [guile-gcrypt]: New variable. [dependencies]: Add it. [*core-modules*]: Remove #:libgcrypt from 'make-config.scm' call. Add #:extensions. [*config*]: Remove #:libgcrypt from 'make-config.scm' call. (%dependency-variables): Remove %libgcrypt. (make-config.scm): Remove #:libgcrypt. * build-aux/build-self.scm (guile-gcrypt): New variable. (make-config.scm): Remove #:libgcrypt. (build-program)[fake-gcrypt-hash]: New variable. Add (gcrypt hash) to the imported modules. Adjust load path assignments. * gnu/packages/package-management.scm (guix)[propagated-inputs]: Add GUILE-GCRYPT. [arguments]: In 'wrap-program' phase, add GUILE-GCRYPT to the search path. --- guix/derivations.scm | 2 +- guix/docker.scm | 2 +- guix/gcrypt.scm | 49 ----- guix/git.scm | 2 +- guix/hash.scm | 184 ------------------- guix/http-client.scm | 2 +- guix/import/cpan.scm | 2 +- guix/import/cran.scm | 2 +- guix/import/crate.scm | 2 +- guix/import/elpa.scm | 2 +- guix/import/gnu.scm | 2 +- guix/import/hackage.scm | 2 +- guix/import/texlive.scm | 2 +- guix/import/utils.scm | 2 +- guix/nar.scm | 4 +- guix/pk-crypto.scm | 407 ------------------------------------------ guix/pki.scm | 2 +- guix/scripts/archive.scm | 2 +- guix/scripts/authenticate.scm | 2 +- guix/scripts/download.scm | 2 +- guix/scripts/hash.scm | 6 +- guix/scripts/pack.scm | 60 ++----- guix/scripts/publish.scm | 4 +- guix/scripts/refresh.scm | 2 +- guix/scripts/substitute.scm | 4 +- guix/self.scm | 26 ++- guix/store.scm | 2 +- guix/store/deduplication.scm | 2 +- guix/tests.scm | 2 +- 29 files changed, 56 insertions(+), 728 deletions(-) delete mode 100644 guix/gcrypt.scm delete mode 100644 guix/hash.scm delete mode 100644 guix/pk-crypto.scm (limited to 'guix') diff --git a/guix/derivations.scm b/guix/derivations.scm index da686e89e2..7afecb10cc 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -35,7 +35,7 @@ #:use-module (guix memoization) #:use-module (guix combinators) #:use-module (guix monads) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix records) #:use-module (guix sets) diff --git a/guix/docker.scm b/guix/docker.scm index b869901599..0757d3356f 100644 --- a/guix/docker.scm +++ b/guix/docker.scm @@ -19,7 +19,7 @@ ;;; along with GNU Guix. If not, see . (define-module (guix docker) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base16) #:use-module ((guix build utils) #:select (mkdir-p diff --git a/guix/gcrypt.scm b/guix/gcrypt.scm deleted file mode 100644 index 1517501751..0000000000 --- a/guix/gcrypt.scm +++ /dev/null @@ -1,49 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014, 2015 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix gcrypt) - #:use-module (guix config) - #:use-module (system foreign) - #:export (gcrypt-version - libgcrypt-func)) - -;;; Commentary: -;;; -;;; Common code for the GNU Libgcrypt bindings. Loading this module -;;; initializes Libgcrypt as a side effect. -;;; -;;; Code: - -(define libgcrypt-func - (let ((lib (dynamic-link %libgcrypt))) - (lambda (func) - "Return a pointer to symbol FUNC in libgcrypt." - (dynamic-func func lib)))) - -(define gcrypt-version - ;; According to the manual, this function must be called before any other, - ;; and it's not clear whether it can be called more than once. So call it - ;; right here from the top level. - (let* ((ptr (libgcrypt-func "gcry_check_version")) - (proc (pointer->procedure '* ptr '(*))) - (version (pointer->string (proc %null-pointer)))) - (lambda () - "Return the version number of libgcrypt as a string." - version))) - -;;; gcrypt.scm ends here diff --git a/guix/git.scm b/guix/git.scm index 193e2df111..c577eba5ee 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -21,7 +21,7 @@ #:use-module (git) #:use-module (git object) #:use-module (guix base32) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module ((guix build utils) #:select (mkdir-p)) #:use-module (guix store) #:use-module (guix utils) diff --git a/guix/hash.scm b/guix/hash.scm deleted file mode 100644 index 8d7ba21425..0000000000 --- a/guix/hash.scm +++ /dev/null @@ -1,184 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2018 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix hash) - #:use-module (guix gcrypt) - #:use-module (rnrs bytevectors) - #:use-module (ice-9 binary-ports) - #:use-module (system foreign) - #:use-module ((guix build utils) #:select (dump-port)) - #:use-module (srfi srfi-11) - #:use-module (srfi srfi-26) - #:export (sha1 - sha256 - open-sha256-port - port-sha256 - file-sha256 - open-sha256-input-port)) - -;;; Commentary: -;;; -;;; Cryptographic hashes. -;;; -;;; Code: - - -;;; -;;; Hash. -;;; - -(define-syntax GCRY_MD_SHA256 - ;; Value as of Libgcrypt 1.5.2. - (identifier-syntax 8)) - -(define-syntax GCRY_MD_SHA1 - (identifier-syntax 2)) - -(define bytevector-hash - (let ((hash (pointer->procedure void - (libgcrypt-func "gcry_md_hash_buffer") - `(,int * * ,size_t)))) - (lambda (bv type size) - "Return the hash TYPE, of SIZE bytes, of BV as a bytevector." - (let ((digest (make-bytevector size))) - (hash type (bytevector->pointer digest) - (bytevector->pointer bv) (bytevector-length bv)) - digest)))) - -(define sha1 - (cut bytevector-hash <> GCRY_MD_SHA1 20)) - -(define sha256 - (cut bytevector-hash <> GCRY_MD_SHA256 (/ 256 8))) - -(define open-sha256-md - (let ((open (pointer->procedure int - (libgcrypt-func "gcry_md_open") - `(* ,int ,unsigned-int)))) - (lambda () - (let* ((md (bytevector->pointer (make-bytevector (sizeof '*)))) - (err (open md GCRY_MD_SHA256 0))) - (if (zero? err) - (dereference-pointer md) - (throw 'gcrypt-error err)))))) - -(define md-write - (pointer->procedure void - (libgcrypt-func "gcry_md_write") - `(* * ,size_t))) - -(define md-read - (pointer->procedure '* - (libgcrypt-func "gcry_md_read") - `(* ,int))) - -(define md-close - (pointer->procedure void - (libgcrypt-func "gcry_md_close") - '(*))) - - -(define (open-sha256-port) - "Return two values: an output port, and a thunk. When the thunk is called, -it returns the SHA256 hash (a bytevector) of all the data written to the -output port." - (define sha256-md - (open-sha256-md)) - - (define digest #f) - (define position 0) - - (define (finalize!) - (let ((ptr (md-read sha256-md 0))) - (set! digest (bytevector-copy (pointer->bytevector ptr 32))) - (md-close sha256-md))) - - (define (write! bv offset len) - (if (zero? len) - (begin - (finalize!) - 0) - (let ((ptr (bytevector->pointer bv offset))) - (md-write sha256-md ptr len) - (set! position (+ position len)) - len))) - - (define (get-position) - position) - - (define (close) - (unless digest - (finalize!))) - - (values (make-custom-binary-output-port "sha256" - write! get-position #f - close) - (lambda () - (unless digest - (finalize!)) - digest))) - -(define (port-sha256 port) - "Return the SHA256 hash (a bytevector) of all the data drained from PORT." - (let-values (((out get) - (open-sha256-port))) - (dump-port port out) - (close-port out) - (get))) - -(define (file-sha256 file) - "Return the SHA256 hash (a bytevector) of FILE." - (call-with-input-file file port-sha256)) - -(define (open-sha256-input-port port) - "Return an input port that wraps PORT and a thunk to get the hash of all the -data read from PORT. The thunk always returns the same value." - (define md - (open-sha256-md)) - - (define (read! bv start count) - (let ((n (get-bytevector-n! port bv start count))) - (if (eof-object? n) - 0 - (begin - (unless digest - (let ((ptr (bytevector->pointer bv start))) - (md-write md ptr n))) - n)))) - - (define digest #f) - - (define (finalize!) - (let ((ptr (md-read md 0))) - (set! digest (bytevector-copy (pointer->bytevector ptr 32))) - (md-close md))) - - (define (get-hash) - (unless digest - (finalize!)) - digest) - - (define (unbuffered port) - ;; Guile <= 2.0.9 does not support 'setvbuf' on custom binary input ports. - (setvbuf port _IONBF) - port) - - (values (unbuffered (make-custom-binary-input-port "sha256" read! #f #f #f)) - get-hash)) - -;;; hash.scm ends here diff --git a/guix/http-client.scm b/guix/http-client.scm index 3b34d4ffba..07360e6108 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -34,7 +34,7 @@ #:use-module (guix ui) #:use-module (guix utils) #:use-module (guix base64) - #:autoload (guix hash) (sha256) + #:autoload (gcrypt hash) (sha256) #:use-module ((guix build utils) #:select (mkdir-p dump-port)) #:use-module ((guix build download) diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm index d0ff64ed05..d4bea84353 100644 --- a/guix/import/cpan.scm +++ b/guix/import/cpan.scm @@ -27,7 +27,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (json) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix store) #:use-module (guix utils) #:use-module (guix base32) diff --git a/guix/import/cran.scm b/guix/import/cran.scm index a5203fe78d..89c84f7037 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -29,7 +29,7 @@ #:use-module (web uri) #:use-module (guix memoization) #:use-module (guix http-client) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix store) #:use-module (guix base32) #:use-module ((guix download) #:select (download-to-store)) diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 3724a457a4..e0b400d054 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -20,7 +20,7 @@ #:use-module (guix base32) #:use-module (guix build-system cargo) #:use-module ((guix download) #:prefix download:) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix http-client) #:use-module (guix import json) #:use-module (guix import utils) diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm index c37afaf8e6..83354d3f04 100644 --- a/guix/import/elpa.scm +++ b/guix/import/elpa.scm @@ -32,7 +32,7 @@ #:use-module (guix http-client) #:use-module (guix store) #:use-module (guix ui) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix upstream) #:use-module (guix packages) diff --git a/guix/import/gnu.scm b/guix/import/gnu.scm index bbb17047f0..29324d7554 100644 --- a/guix/import/gnu.scm +++ b/guix/import/gnu.scm @@ -21,7 +21,7 @@ #:use-module (guix import utils) #:use-module (guix utils) #:use-module (guix store) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix upstream) #:use-module (srfi srfi-1) diff --git a/guix/import/hackage.scm b/guix/import/hackage.scm index 54301de2e8..766a0b53f1 100644 --- a/guix/import/hackage.scm +++ b/guix/import/hackage.scm @@ -33,7 +33,7 @@ #:use-module ((guix import utils) #:select (factorize-uri recursive-import)) #:use-module (guix import cabal) #:use-module (guix store) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix memoization) #:use-module (guix upstream) diff --git a/guix/import/texlive.scm b/guix/import/texlive.scm index d4c3714364..791b514485 100644 --- a/guix/import/texlive.scm +++ b/guix/import/texlive.scm @@ -26,7 +26,7 @@ #:use-module (srfi srfi-34) #:use-module (web uri) #:use-module (guix http-client) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix memoization) #:use-module (guix store) #:use-module (guix base32) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 0dc8fd5857..516c0cfaa2 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -23,7 +23,7 @@ (define-module (guix import utils) #:use-module (guix base32) #:use-module ((guix build download) #:prefix build:) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix http-client) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix utils) diff --git a/guix/nar.scm b/guix/nar.scm index 3556de1379..0495b4a40c 100644 --- a/guix/nar.scm +++ b/guix/nar.scm @@ -25,9 +25,9 @@ #:use-module (guix store) #:use-module (guix store database) #:use-module (guix ui) ; for '_' - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix pki) - #:use-module (guix pk-crypto) + #:use-module (gcrypt pk-crypto) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) diff --git a/guix/pk-crypto.scm b/guix/pk-crypto.scm deleted file mode 100644 index 55ba7b1bb8..0000000000 --- a/guix/pk-crypto.scm +++ /dev/null @@ -1,407 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014, 2015, 2017 Ludovic Courtès -;;; -;;; This file is part of GNU Guix. -;;; -;;; GNU Guix is free software; you can redistribute it and/or modify it -;;; under the terms of the GNU General Public License as published by -;;; the Free Software Foundation; either version 3 of the License, or (at -;;; your option) any later version. -;;; -;;; GNU Guix is distributed in the hope that it will be useful, but -;;; WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;;; GNU General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with GNU Guix. If not, see . - -(define-module (guix pk-crypto) - #:use-module (guix base16) - #:use-module (guix gcrypt) - - #:use-module (system foreign) - #:use-module (rnrs bytevectors) - #:use-module (ice-9 match) - #:use-module (ice-9 rdelim) - #:export (canonical-sexp? - error-source - error-string - string->canonical-sexp - canonical-sexp->string - read-file-sexp - number->canonical-sexp - canonical-sexp-car - canonical-sexp-cdr - canonical-sexp-nth - canonical-sexp-nth-data - canonical-sexp-length - canonical-sexp-null? - canonical-sexp-list? - bytevector->hash-data - hash-data->bytevector - key-type - sign - verify - generate-key - find-sexp-token - canonical-sexp->sexp - sexp->canonical-sexp) - #:re-export (gcrypt-version)) - - -;;; Commentary: -;;; -;;; Public key cryptographic routines from GNU Libgcrypt. -;;;; -;;; Libgcrypt uses "canonical s-expressions" to represent key material, -;;; parameters, and data. We keep it as an opaque object to map them to -;;; Scheme s-expressions because (1) Libgcrypt sexps may be stored in secure -;;; memory, and (2) the read syntax is different. -;;; -;;; A 'canonical-sexp->sexp' procedure is provided nevertheless, for use in -;;; cases where it is safe to move data out of Libgcrypt---e.g., when -;;; processing ACL entries, public keys, etc. -;;; -;;; Canonical sexps were defined by Rivest et al. in the IETF draft at -;;; for the purposes of SPKI -;;; (see .) -;;; -;;; Code: - -;; Libgcrypt "s-expressions". -(define-wrapped-pointer-type - canonical-sexp? - naked-pointer->canonical-sexp - canonical-sexp->pointer - (lambda (obj port) - ;; Don't print OBJ's external representation: we don't want key material - ;; to leak in backtraces and such. - (format port "#" - (number->string (object-address obj) 16) - (number->string (pointer-address (canonical-sexp->pointer obj)) - 16)))) - -(define finalize-canonical-sexp! - (libgcrypt-func "gcry_sexp_release")) - -(define-inlinable (pointer->canonical-sexp ptr) - "Return a that wraps PTR." - (let* ((sexp (naked-pointer->canonical-sexp ptr)) - (ptr* (canonical-sexp->pointer sexp))) - ;; Did we already have a object for PTR? - (when (equal? ptr ptr*) - ;; No, so we can safely add a finalizer (in Guile 2.0.9 - ;; 'set-pointer-finalizer!' *adds* a finalizer rather than replacing the - ;; existing one.) - (set-pointer-finalizer! ptr finalize-canonical-sexp!)) - sexp)) - -(define error-source - (let* ((ptr (libgcrypt-func "gcry_strsource")) - (proc (pointer->procedure '* ptr (list int)))) - (lambda (err) - "Return the error source (a string) for ERR, an error code as thrown -along with 'gcry-error'." - (pointer->string (proc err))))) - -(define error-string - (let* ((ptr (libgcrypt-func "gcry_strerror")) - (proc (pointer->procedure '* ptr (list int)))) - (lambda (err) - "Return the error description (a string) for ERR, an error code as -thrown along with 'gcry-error'." - (pointer->string (proc err))))) - -(define string->canonical-sexp - (let* ((ptr (libgcrypt-func "gcry_sexp_new")) - (proc (pointer->procedure int ptr `(* * ,size_t ,int)))) - (lambda (str) - "Parse STR and return the corresponding gcrypt s-expression." - - ;; When STR comes from 'canonical-sexp->string', it may contain - ;; characters that are really meant to be interpreted as bytes as in a C - ;; 'char *'. Thus, convert STR to ISO-8859-1 so the byte values of the - ;; characters are preserved. - (let* ((sexp (bytevector->pointer (make-bytevector (sizeof '*)))) - (err (proc sexp (string->pointer str "ISO-8859-1") 0 1))) - (if (= 0 err) - (pointer->canonical-sexp (dereference-pointer sexp)) - (throw 'gcry-error 'string->canonical-sexp err)))))) - -(define-syntax GCRYSEXP_FMT_ADVANCED - (identifier-syntax 3)) - -(define canonical-sexp->string - (let* ((ptr (libgcrypt-func "gcry_sexp_sprint")) - (proc (pointer->procedure size_t ptr `(* ,int * ,size_t)))) - (lambda (sexp) - "Return a textual representation of SEXP." - (let loop ((len 1024)) - (let* ((buf (bytevector->pointer (make-bytevector len))) - (size (proc (canonical-sexp->pointer sexp) - GCRYSEXP_FMT_ADVANCED buf len))) - (if (zero? size) - (loop (* len 2)) - (pointer->string buf size "ISO-8859-1"))))))) - -(define (read-file-sexp file) - "Return the canonical sexp read from FILE." - (call-with-input-file file - (compose string->canonical-sexp - read-string))) - -(define canonical-sexp-car - (let* ((ptr (libgcrypt-func "gcry_sexp_car")) - (proc (pointer->procedure '* ptr '(*)))) - (lambda (lst) - "Return the first element of LST, an sexp, if that element is a list; -return #f if LST or its first element is not a list (this is different from -the usual Lisp 'car'.)" - (let ((result (proc (canonical-sexp->pointer lst)))) - (if (null-pointer? result) - #f - (pointer->canonical-sexp result)))))) - -(define canonical-sexp-cdr - (let* ((ptr (libgcrypt-func "gcry_sexp_cdr")) - (proc (pointer->procedure '* ptr '(*)))) - (lambda (lst) - "Return the tail of LST, an sexp, or #f if LST is not a list." - (let ((result (proc (canonical-sexp->pointer lst)))) - (if (null-pointer? result) - #f - (pointer->canonical-sexp result)))))) - -(define canonical-sexp-nth - (let* ((ptr (libgcrypt-func "gcry_sexp_nth")) - (proc (pointer->procedure '* ptr `(* ,int)))) - (lambda (lst index) - "Return the INDEXth nested element of LST, an s-expression. Return #f -if that element does not exist, or if it's an atom. (Note: this is obviously -different from Scheme's 'list-ref'.)" - (let ((result (proc (canonical-sexp->pointer lst) index))) - (if (null-pointer? result) - #f - (pointer->canonical-sexp result)))))) - -(define (dereference-size_t p) - "Return the size_t value pointed to by P." - (bytevector-uint-ref (pointer->bytevector p (sizeof size_t)) - 0 (native-endianness) - (sizeof size_t))) - -(define canonical-sexp-length - (let* ((ptr (libgcrypt-func "gcry_sexp_length")) - (proc (pointer->procedure int ptr '(*)))) - (lambda (sexp) - "Return the length of SEXP if it's a list (including the empty list); -return zero if SEXP is an atom." - (proc (canonical-sexp->pointer sexp))))) - -(define token-string? - (let ((token-cs (char-set-union char-set:digit - char-set:letter - (char-set #\- #\. #\/ #\_ - #\: #\* #\+ #\=)))) - (lambda (str) - "Return #t if STR is a token as per Section 4.3 of -." - (and (not (string-null? str)) - (string-every token-cs str) - (not (char-set-contains? char-set:digit (string-ref str 0))))))) - -(define canonical-sexp-nth-data - (let* ((ptr (libgcrypt-func "gcry_sexp_nth_data")) - (proc (pointer->procedure '* ptr `(* ,int *)))) - (lambda (lst index) - "Return as a symbol (for \"sexp tokens\") or a bytevector (for any other -\"octet string\") the INDEXth data element (atom) of LST, an s-expression. -Return #f if that element does not exist, or if it's a list." - (let* ((size* (bytevector->pointer (make-bytevector (sizeof '*)))) - (result (proc (canonical-sexp->pointer lst) index size*))) - (if (null-pointer? result) - #f - (let* ((len (dereference-size_t size*)) - (str (pointer->string result len "ISO-8859-1"))) - ;; The sexp spec speaks of "tokens" and "octet strings". - ;; Sometimes these octet strings are actual strings (text), - ;; sometimes they're bytevectors, and sometimes they're - ;; multi-precision integers (MPIs). Only the application knows. - ;; However, for convenience, we return a symbol when a token is - ;; encountered since tokens are frequent (at least in the 'car' - ;; of each sexp.) - (if (token-string? str) - (string->symbol str) ; an sexp "token" - (bytevector-copy ; application data, textual or binary - (pointer->bytevector result len))))))))) - -(define (number->canonical-sexp number) - "Return an s-expression representing NUMBER." - (string->canonical-sexp (string-append "#" (number->string number 16) "#"))) - -(define* (bytevector->hash-data bv - #:optional - (hash-algo "sha256") - #:key (key-type 'ecc)) - "Given BV, a bytevector containing a hash of type HASH-ALGO, return an -s-expression suitable for use as the 'data' argument for 'sign'. KEY-TYPE -must be a symbol: 'dsa, 'ecc, or 'rsa." - (string->canonical-sexp - (format #f "(data (flags ~a) (hash \"~a\" #~a#))" - (case key-type - ((ecc dsa) "rfc6979") - ((rsa) "pkcs1") - (else (error "unknown key type" key-type))) - hash-algo - (bytevector->base16-string bv)))) - -(define (key-type sexp) - "Return a symbol denoting the type of public or private key represented by -SEXP--e.g., 'rsa', 'ecc'--or #f if SEXP does not denote a valid key." - (case (canonical-sexp-nth-data sexp 0) - ((public-key private-key) - (canonical-sexp-nth-data (canonical-sexp-nth sexp 1) 0)) - (else #f))) - -(define* (hash-data->bytevector data) - "Return two values: the hash value (a bytevector), and the hash algorithm (a -string) extracted from DATA, an sexp as returned by 'bytevector->hash-data'. -Return #f if DATA does not conform." - (let ((hash (find-sexp-token data 'hash))) - (if hash - (let ((algo (canonical-sexp-nth-data hash 1)) - (value (canonical-sexp-nth-data hash 2))) - (values value (symbol->string algo))) - (values #f #f)))) - -(define sign - (let* ((ptr (libgcrypt-func "gcry_pk_sign")) - (proc (pointer->procedure int ptr '(* * *)))) - (lambda (data secret-key) - "Sign DATA, a canonical s-expression representing a suitable hash, with -SECRET-KEY (a canonical s-expression whose car is 'private-key'.) Note that -DATA must be a 'data' s-expression, as returned by -'bytevector->hash-data' (info \"(gcrypt) Cryptographic Functions\")." - (let* ((sig (bytevector->pointer (make-bytevector (sizeof '*)))) - (err (proc sig (canonical-sexp->pointer data) - (canonical-sexp->pointer secret-key)))) - (if (= 0 err) - (pointer->canonical-sexp (dereference-pointer sig)) - (throw 'gcry-error 'sign err)))))) - -(define verify - (let* ((ptr (libgcrypt-func "gcry_pk_verify")) - (proc (pointer->procedure int ptr '(* * *)))) - (lambda (signature data public-key) - "Verify that SIGNATURE is a signature of DATA with PUBLIC-KEY, all of -which are gcrypt s-expressions." - (zero? (proc (canonical-sexp->pointer signature) - (canonical-sexp->pointer data) - (canonical-sexp->pointer public-key)))))) - -(define generate-key - (let* ((ptr (libgcrypt-func "gcry_pk_genkey")) - (proc (pointer->procedure int ptr '(* *)))) - (lambda (params) - "Return as an s-expression a new key pair for PARAMS. PARAMS must be an -s-expression like: (genkey (rsa (nbits 4:2048)))." - (let* ((key (bytevector->pointer (make-bytevector (sizeof '*)))) - (err (proc key (canonical-sexp->pointer params)))) - (if (zero? err) - (pointer->canonical-sexp (dereference-pointer key)) - (throw 'gcry-error 'generate-key err)))))) - -(define find-sexp-token - (let* ((ptr (libgcrypt-func "gcry_sexp_find_token")) - (proc (pointer->procedure '* ptr `(* * ,size_t)))) - (lambda (sexp token) - "Find in SEXP the first element whose 'car' is TOKEN and return it; -return #f if not found." - (let* ((token (string->pointer (symbol->string token))) - (res (proc (canonical-sexp->pointer sexp) token 0))) - (if (null-pointer? res) - #f - (pointer->canonical-sexp res)))))) - -(define-inlinable (canonical-sexp-null? sexp) - "Return #t if SEXP is the empty-list sexp." - (null-pointer? (canonical-sexp->pointer sexp))) - -(define (canonical-sexp-list? sexp) - "Return #t if SEXP is a list." - (or (canonical-sexp-null? sexp) - (> (canonical-sexp-length sexp) 0))) - -(define (canonical-sexp-fold proc seed sexp) - "Fold PROC (as per SRFI-1) over SEXP, a canonical sexp." - (if (canonical-sexp-list? sexp) - (let ((len (canonical-sexp-length sexp))) - (let loop ((index 0) - (result seed)) - (if (= index len) - result - (loop (+ 1 index) - ;; XXX: Call 'nth-data' *before* 'nth' to work around - ;; , which - ;; affects 1.6.0 and earlier versions. - (proc (or (canonical-sexp-nth-data sexp index) - (canonical-sexp-nth sexp index)) - result))))) - (error "sexp is not a list" sexp))) - -(define (canonical-sexp->sexp sexp) - "Return a Scheme sexp corresponding to SEXP. This is particularly useful to -compare sexps (since Libgcrypt does not provide an 'equal?' procedure), or to -use pattern matching." - (if (canonical-sexp-list? sexp) - (reverse - (canonical-sexp-fold (lambda (item result) - (cons (if (canonical-sexp? item) - (canonical-sexp->sexp item) - item) - result)) - '() - sexp)) - - ;; As of Libgcrypt 1.6.0, there's no function to extract the buffer of a - ;; non-list sexp (!), so we first enlist SEXP, then get at its buffer. - (let ((sexp (string->canonical-sexp - (string-append "(" (canonical-sexp->string sexp) - ")")))) - (or (canonical-sexp-nth-data sexp 0) - (canonical-sexp-nth sexp 0))))) - -(define (sexp->canonical-sexp sexp) - "Return a canonical sexp equivalent to SEXP, a Scheme sexp as returned by -'canonical-sexp->sexp'." - ;; XXX: This is inefficient, but the Libgcrypt API doesn't allow us to do - ;; much better. - (string->canonical-sexp - (call-with-output-string - (lambda (port) - (define (write item) - (cond ((list? item) - (display "(" port) - (for-each write item) - (display ")" port)) - ((symbol? item) - (format port " ~a" item)) - ((bytevector? item) - (format port " #~a#" - (bytevector->base16-string item))) - (else - (error "unsupported sexp item type" item)))) - - (write sexp))))) - -(define (gcrypt-error-printer port key args default-printer) - "Print the gcrypt error specified by ARGS." - (match args - ((proc err) - (format port "In procedure ~a: ~a: ~a" - proc (error-source err) (error-string err))))) - -(set-exception-printer! 'gcry-error gcrypt-error-printer) - -;;; pk-crypto.scm ends here diff --git a/guix/pki.scm b/guix/pki.scm index 1551425c33..6326e065e9 100644 --- a/guix/pki.scm +++ b/guix/pki.scm @@ -18,7 +18,7 @@ (define-module (guix pki) #:use-module (guix config) - #:use-module (guix pk-crypto) + #:use-module (gcrypt pk-crypto) #:use-module ((guix utils) #:select (with-atomic-file-output)) #:use-module ((guix build utils) #:select (mkdir-p)) #:use-module (ice-9 match) diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm index a359f405fe..fb2f61ce30 100644 --- a/guix/scripts/archive.scm +++ b/guix/scripts/archive.scm @@ -29,7 +29,7 @@ #:use-module (guix monads) #:use-module (guix ui) #:use-module (guix pki) - #:use-module (guix pk-crypto) + #:use-module (gcrypt pk-crypto) #:use-module (guix scripts) #:use-module (guix scripts build) #:use-module (gnu packages) diff --git a/guix/scripts/authenticate.scm b/guix/scripts/authenticate.scm index 8b19dc871b..f1fd8ee895 100644 --- a/guix/scripts/authenticate.scm +++ b/guix/scripts/authenticate.scm @@ -19,7 +19,7 @@ (define-module (guix scripts authenticate) #:use-module (guix config) #:use-module (guix base16) - #:use-module (guix pk-crypto) + #:use-module (gcrypt pk-crypto) #:use-module (guix pki) #:use-module (guix ui) #:use-module (ice-9 binary-ports) diff --git a/guix/scripts/download.scm b/guix/scripts/download.scm index 1b99bc62cf..b9162d3449 100644 --- a/guix/scripts/download.scm +++ b/guix/scripts/download.scm @@ -20,7 +20,7 @@ #:use-module (guix ui) #:use-module (guix scripts) #:use-module (guix store) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base16) #:use-module (guix base32) #:use-module ((guix download) #:hide (url-fetch)) diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm index cae5d6bcdf..2bd2ac4a06 100644 --- a/guix/scripts/hash.scm +++ b/guix/scripts/hash.scm @@ -20,7 +20,7 @@ (define-module (guix scripts hash) #:use-module (guix base32) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix serialization) #:use-module (guix ui) #:use-module (guix scripts) @@ -44,7 +44,7 @@ `((format . ,bytevector->nix-base32-string))) (define (show-help) - (display (G_ "Usage: guix hash [OPTION] FILE + (display (G_ "Usage: gcrypt hash [OPTION] FILE Return the cryptographic hash of FILE. Supported formats: 'nix-base32' (default), 'base32', and 'base16' ('hex' @@ -93,7 +93,7 @@ and 'hexadecimal' can be used as well).\n")) (exit 0))) (option '(#\V "version") #f #f (lambda args - (show-version-and-exit "guix hash"))))) + (show-version-and-exit "gcrypt hash"))))) diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index fb0677de28..1916f3b9d7 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -41,7 +41,7 @@ #:use-module (gnu packages guile) #:use-module (gnu packages base) #:autoload (gnu packages package-management) (guix) - #:autoload (gnu packages gnupg) (libgcrypt) + #:autoload (gnu packages gnupg) (guile-gcrypt) #:autoload (gnu packages guile) (guile2.0-json guile-json) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) @@ -95,10 +95,12 @@ found." (('gnu _ ...) #t) (_ #f))) -(define guile-sqlite3&co - ;; Guile-SQLite3 and its propagated inputs. - (cons guile-sqlite3 - (package-transitive-propagated-inputs guile-sqlite3))) +(define gcrypt-sqlite3&co + ;; Guile-Gcrypt, Guile-SQLite3, and their propagated inputs. + (append-map (lambda (package) + (cons package + (package-transitive-propagated-inputs package))) + (list guile-gcrypt guile-sqlite3))) (define* (self-contained-tarball name profile #:key target @@ -124,16 +126,14 @@ added to the pack." "guix/store/schema.sql")))) (define build - (with-imported-modules `(((guix config) - => ,(make-config.scm - #:libgcrypt libgcrypt)) + (with-imported-modules `(((guix config) => ,(make-config.scm)) ,@(source-module-closure `((guix build utils) (guix build union) (guix build store-copy) (gnu build install)) #:select? not-config?)) - (with-extensions guile-sqlite3&co + (with-extensions gcrypt-sqlite3&co #~(begin (use-modules (guix build utils) ((guix build union) #:select (relative-file-name)) @@ -251,22 +251,14 @@ points for virtual file systems (like procfs), and optional symlinks. SYMLINKS must be a list of (SOURCE -> TARGET) tuples denoting symlinks to be added to the pack." - (define libgcrypt - ;; XXX: Not strictly needed, but pulled by (guix store database). - (module-ref (resolve-interface '(gnu packages gnupg)) - 'libgcrypt)) - - (define build - (with-imported-modules `(((guix config) - => ,(make-config.scm - #:libgcrypt libgcrypt)) + (with-imported-modules `(((guix config) => ,(make-config.scm)) ,@(source-module-closure '((guix build utils) (guix build store-copy) (gnu build install)) #:select? not-config?)) - (with-extensions guile-sqlite3&co + (with-extensions gcrypt-sqlite3&co #~(begin (use-modules (guix build utils) (gnu build install) @@ -349,32 +341,12 @@ must a be a GNU triplet and it is used to derive the architecture metadata in the image." (define defmod 'define-module) ;trick Geiser - (define config - ;; (guix config) module for consumption by (guix gcrypt). - (scheme-file "gcrypt-config.scm" - #~(begin - (#$defmod (guix config) - #:export (%libgcrypt)) - - ;; XXX: Work around . - (eval-when (expand load eval) - (define %libgcrypt - #+(file-append libgcrypt "/lib/libgcrypt")))))) - - (define json - ;; Pick the guile-json package that corresponds to the Guile used to build - ;; derivations. - (if (string-prefix? "2.0" (package-version (default-guile))) - guile2.0-json - guile-json)) - (define build - ;; Guile-JSON is required by (guix docker). - (with-extensions (list json) - (with-imported-modules `(,@(source-module-closure '((guix docker) - (guix build store-copy)) - #:select? not-config?) - ((guix config) => ,config)) + ;; Guile-JSON and Guile-Gcrypt are required by (guix docker). + (with-extensions (list guile-json guile-gcrypt) + (with-imported-modules (source-module-closure '((guix docker) + (guix build store-copy)) + #:select? not-config?) #~(begin (use-modules (guix docker) (srfi srfi-19) (guix build store-copy)) diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index b5dfdab32f..c5326b33da 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -44,9 +44,9 @@ #:use-module (guix base64) #:use-module (guix config) #:use-module (guix derivations) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix pki) - #:use-module (guix pk-crypto) + #:use-module (gcrypt pk-crypto) #:use-module (guix workers) #:use-module (guix store) #:use-module ((guix serialization) #:select (write-file)) diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm index a8fe993e33..bcc23bd39c 100644 --- a/guix/scripts/refresh.scm +++ b/guix/scripts/refresh.scm @@ -23,7 +23,7 @@ (define-module (guix scripts refresh) #:use-module (guix ui) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix scripts) #:use-module (guix store) #:use-module (guix utils) diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index 7634bb37f6..cd300195d8 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -26,11 +26,11 @@ #:use-module (guix config) #:use-module (guix records) #:use-module ((guix serialization) #:select (restore-file)) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix base32) #:use-module (guix base64) #:use-module (guix cache) - #:use-module (guix pk-crypto) + #:use-module (gcrypt pk-crypto) #:use-module (guix pki) #:use-module ((guix build utils) #:select (mkdir-p dump-port)) #:use-module ((guix build download) diff --git a/guix/self.scm b/guix/self.scm index 81f9b0cfd5..126116e08a 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -83,8 +83,8 @@ GUILE-VERSION (\"2.0\" or \"2.2\"), or #f if none of the packages matches." ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh)) ("guile-git" (ref '(gnu packages guile) 'guile-git)) ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3)) + ("guile-gcrypt" (ref '(gnu packages gnupg) 'guile-gcrypt)) ("gnutls" (ref '(gnu packages tls) 'gnutls)) - ("libgcrypt" (ref '(gnu packages gnupg) 'libgcrypt)) ("zlib" (ref '(gnu packages compression) 'zlib)) ("gzip" (ref '(gnu packages compression) 'gzip)) ("bzip2" (ref '(gnu packages compression) 'bzip2)) @@ -454,7 +454,6 @@ assumed to be part of MODULES." (name (string-append "guix-" version)) (guile-version (effective-version)) (guile-for-build (guile-for-build guile-version)) - (libgcrypt (specification->package "libgcrypt")) (zlib (specification->package "zlib")) (gzip (specification->package "gzip")) (bzip2 (specification->package "bzip2")) @@ -481,6 +480,10 @@ assumed to be part of MODULES." "guile-sqlite3" "guile2.0-sqlite3")) + (define guile-gcrypt + (package-for-guile guile-version + "guile-gcrypt")) + (define gnutls (package-for-guile guile-version "gnutls" "guile2.0-gnutls")) @@ -489,7 +492,7 @@ assumed to be part of MODULES." (match (append-map (lambda (package) (cons (list "x" package) (package-transitive-propagated-inputs package))) - (list gnutls guile-git guile-json + (list guile-gcrypt gnutls guile-git guile-json guile-ssh guile-sqlite3)) (((labels packages _ ...) ...) packages))) @@ -513,10 +516,7 @@ assumed to be part of MODULES." ;; rebuilt when the version changes, which in turn means we ;; can have substitutes for it. #:extra-modules - `(((guix config) - => ,(make-config.scm #:libgcrypt - (specification->package - "libgcrypt")))) + `(((guix config) => ,(make-config.scm))) ;; (guix man-db) is needed at build-time by (guix profiles) ;; but we don't need to compile it; not compiling it allows @@ -526,6 +526,7 @@ assumed to be part of MODULES." ("guix/store/schema.sql" ,(local-file "../guix/store/schema.sql"))) + #:extensions (list guile-gcrypt) #:guile-for-build guile-for-build)) (define *extra-modules* @@ -600,8 +601,7 @@ assumed to be part of MODULES." '() #:extra-modules `(((guix config) - => ,(make-config.scm #:libgcrypt libgcrypt - #:zlib zlib + => ,(make-config.scm #:zlib zlib #:gzip gzip #:bzip2 bzip2 #:xz xz @@ -684,7 +684,7 @@ assumed to be part of MODULES." (define %dependency-variables ;; (guix config) variables corresponding to dependencies. - '(%libgcrypt %libz %xz %gzip %bzip2)) + '(%libz %xz %gzip %bzip2)) (define %persona-variables ;; (guix config) variables that define Guix's persona. @@ -703,7 +703,7 @@ assumed to be part of MODULES." (variables rest ...)))))) (variables %localstatedir %storedir %sysconfdir %system))) -(define* (make-config.scm #:key libgcrypt zlib gzip xz bzip2 +(define* (make-config.scm #:key zlib gzip xz bzip2 (package-name "GNU Guix") (package-version "0") (bug-report-address "bug-guix@gnu.org") @@ -723,7 +723,6 @@ assumed to be part of MODULES." %state-directory %store-database-directory %config-directory - %libgcrypt %libz %gzip %bzip2 @@ -766,9 +765,6 @@ assumed to be part of MODULES." (define %xz #+(and xz (file-append xz "/bin/xz"))) - (define %libgcrypt - #+(and libgcrypt - (file-append libgcrypt "/lib/libgcrypt"))) (define %libz #+(and zlib (file-append zlib "/lib/libz")))) diff --git a/guix/store.scm b/guix/store.scm index f41a1e2690..af7f6980cf 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -25,7 +25,7 @@ #:use-module (guix monads) #:use-module (guix base16) #:use-module (guix base32) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix profiling) #:autoload (guix build syscalls) (terminal-columns) #:use-module (rnrs bytevectors) diff --git a/guix/store/deduplication.scm b/guix/store/deduplication.scm index 8c19d7309e..53810c680f 100644 --- a/guix/store/deduplication.scm +++ b/guix/store/deduplication.scm @@ -21,7 +21,7 @@ ;;; timestamps, deduplicating, etc. (define-module (guix store deduplication) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix build utils) #:use-module (guix base16) #:use-module (srfi srfi-11) diff --git a/guix/tests.scm b/guix/tests.scm index 34e3e0fc2a..06e9f8da0b 100644 --- a/guix/tests.scm +++ b/guix/tests.scm @@ -22,7 +22,7 @@ #:use-module (guix packages) #:use-module (guix base32) #:use-module (guix serialization) - #:use-module (guix hash) + #:use-module (gcrypt hash) #:use-module (guix build-system gnu) #:use-module (gnu packages bootstrap) #:use-module (srfi srfi-34) -- cgit v1.2.3