diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-06-23 12:11:00 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-06-27 23:42:20 +0200 |
| commit | 8dc6c387852bb9505be44567a5f56913633cc23a (patch) | |
| tree | 872914ede2ea33f72f8c09b2c3517fdf92ee85f5 /nix/libutil | |
| parent | 3fb6b8f30444d41963ba5bdd441123a6d2df17bd (diff) | |
daemon: Remove OpenSSL hash compatibility wrappers.
* nix/libutil/hash.cc (struct Ctx): Copy from gcrypt-hash.hh.
(start, update, finish): Use gcrypt functions directly instead of
OpenSSL-like wrappers.
* nix/libutil/gcrypt-hash.cc, nix/libutil/gcrypt-hash.hh,
nix/libutil/md5.h, nix/libutil/sha1.h, nix/libutil/sha256.h,
nix/libutil/sha512.h: Remove.
* nix/local.mk (libutil_a_SOURCES, libutil_headers): Adjust
accordingly.
Diffstat (limited to 'nix/libutil')
| -rw-r--r-- | nix/libutil/gcrypt-hash.cc | 51 | ||||
| -rw-r--r-- | nix/libutil/gcrypt-hash.hh | 50 | ||||
| -rw-r--r-- | nix/libutil/hash.cc | 53 | ||||
| -rw-r--r-- | nix/libutil/md5.h | 35 | ||||
| -rw-r--r-- | nix/libutil/sha1.h | 35 | ||||
| -rw-r--r-- | nix/libutil/sha256.h | 35 | ||||
| -rw-r--r-- | nix/libutil/sha512.h | 35 |
7 files changed, 24 insertions, 270 deletions
diff --git a/nix/libutil/gcrypt-hash.cc b/nix/libutil/gcrypt-hash.cc deleted file mode 100644 index c4ae7bfcc24..00000000000 --- a/nix/libutil/gcrypt-hash.cc +++ /dev/null | |||
| @@ -1,51 +0,0 @@ | |||
| 1 | /* GNU Guix --- Functional package management for GNU | ||
| 2 | Copyright (C) 2012, 2013 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of GNU Guix. | ||
| 5 | |||
| 6 | GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <config.h> | ||
| 20 | |||
| 21 | #include <gcrypt-hash.hh> | ||
| 22 | #include <assert.h> | ||
| 23 | |||
| 24 | extern "C" { | ||
| 25 | |||
| 26 | void | ||
| 27 | guix_hash_init (struct guix_hash_context *ctx, int algo) | ||
| 28 | { | ||
| 29 | gcry_error_t err; | ||
| 30 | |||
| 31 | err = gcry_md_open (&ctx->md_handle, algo, 0); | ||
| 32 | assert (err == GPG_ERR_NO_ERROR); | ||
| 33 | } | ||
| 34 | |||
| 35 | void | ||
| 36 | guix_hash_update (struct guix_hash_context *ctx, const void *buffer, size_t len) | ||
| 37 | { | ||
| 38 | gcry_md_write (ctx->md_handle, buffer, len); | ||
| 39 | } | ||
| 40 | |||
| 41 | void | ||
| 42 | guix_hash_final (void *resbuf, struct guix_hash_context *ctx, | ||
| 43 | int algo) | ||
| 44 | { | ||
| 45 | memcpy (resbuf, gcry_md_read (ctx->md_handle, algo), | ||
| 46 | gcry_md_get_algo_dlen (algo)); | ||
| 47 | gcry_md_close (ctx->md_handle); | ||
| 48 | ctx->md_handle = NULL; | ||
| 49 | } | ||
| 50 | |||
| 51 | } | ||
diff --git a/nix/libutil/gcrypt-hash.hh b/nix/libutil/gcrypt-hash.hh deleted file mode 100644 index 11f061159f0..00000000000 --- a/nix/libutil/gcrypt-hash.hh +++ /dev/null | |||
| @@ -1,50 +0,0 @@ | |||
| 1 | /* GNU Guix --- Functional package management for GNU | ||
| 2 | Copyright (C) 2012, 2013 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of GNU Guix. | ||
| 5 | |||
| 6 | GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | /* An OpenSSL-like interface to GNU libgcrypt cryptographic hash | ||
| 20 | functions. */ | ||
| 21 | |||
| 22 | #pragma once | ||
| 23 | #include <gcrypt.h> | ||
| 24 | #include <unistd.h> | ||
| 25 | |||
| 26 | struct guix_hash_context | ||
| 27 | { | ||
| 28 | /* This copy constructor is needed in 'HashSink::currentHash()' where we | ||
| 29 | expect the copy of a 'Ctx' object to yield a truly different context. */ | ||
| 30 | guix_hash_context (guix_hash_context &ref) | ||
| 31 | { | ||
| 32 | if (ref.md_handle == NULL) | ||
| 33 | md_handle = NULL; | ||
| 34 | else | ||
| 35 | gcry_md_copy (&md_handle, ref.md_handle); | ||
| 36 | } | ||
| 37 | |||
| 38 | /* Make sure 'md_handle' is always initialized. */ | ||
| 39 | guix_hash_context (): md_handle (NULL) { }; | ||
| 40 | |||
| 41 | gcry_md_hd_t md_handle; | ||
| 42 | }; | ||
| 43 | |||
| 44 | extern "C" { | ||
| 45 | extern void guix_hash_init (struct guix_hash_context *ctx, int algo); | ||
| 46 | extern void guix_hash_update (struct guix_hash_context *ctx, const void *buffer, | ||
| 47 | size_t len); | ||
| 48 | extern void guix_hash_final (void *resbuf, struct guix_hash_context *ctx, | ||
| 49 | int algo); | ||
| 50 | } | ||
diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc index 251f18f60e8..20d2e4b7240 100644 --- a/nix/libutil/hash.cc +++ b/nix/libutil/hash.cc | |||
| @@ -3,18 +3,6 @@ | |||
| 3 | #include <iostream> | 3 | #include <iostream> |
| 4 | #include <cstring> | 4 | #include <cstring> |
| 5 | 5 | ||
| 6 | #ifdef HAVE_OPENSSL | ||
| 7 | #include <openssl/md5.h> | ||
| 8 | #include <openssl/sha.h> | ||
| 9 | #else | ||
| 10 | extern "C" { | ||
| 11 | #include "md5.h" | ||
| 12 | #include "sha1.h" | ||
| 13 | #include "sha256.h" | ||
| 14 | #include "sha512.h" | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #include "hash.hh" | 6 | #include "hash.hh" |
| 19 | #include "archive.hh" | 7 | #include "archive.hh" |
| 20 | #include "util.hh" | 8 | #include "util.hh" |
| @@ -193,41 +181,48 @@ bool isHash(const string & s) | |||
| 193 | return true; | 181 | return true; |
| 194 | } | 182 | } |
| 195 | 183 | ||
| 196 | 184 | /* The "hash context". */ | |
| 197 | struct Ctx | 185 | struct Ctx |
| 198 | { | 186 | { |
| 199 | MD5_CTX md5; | 187 | /* This copy constructor is needed in 'HashSink::currentHash()' where we |
| 200 | SHA_CTX sha1; | 188 | expect the copy of a 'Ctx' object to yield a truly different context. */ |
| 201 | SHA256_CTX sha256; | 189 | Ctx(Ctx &ref) |
| 202 | SHA512_CTX sha512; | 190 | { |
| 191 | if (ref.md_handle == NULL) | ||
| 192 | md_handle = NULL; | ||
| 193 | else | ||
| 194 | gcry_md_copy (&md_handle, ref.md_handle); | ||
| 195 | } | ||
| 196 | |||
| 197 | /* Make sure 'md_handle' is always initialized. */ | ||
| 198 | Ctx(): md_handle (NULL) { }; | ||
| 199 | |||
| 200 | gcry_md_hd_t md_handle; | ||
| 203 | }; | 201 | }; |
| 204 | 202 | ||
| 205 | 203 | ||
| 206 | static void start(HashType ht, Ctx & ctx) | 204 | static void start(HashType ht, Ctx & ctx) |
| 207 | { | 205 | { |
| 208 | if (ht == htMD5) MD5_Init(&ctx.md5); | 206 | gcry_error_t err; |
| 209 | else if (ht == htSHA1) SHA1_Init(&ctx.sha1); | 207 | |
| 210 | else if (ht == htSHA256) SHA256_Init(&ctx.sha256); | 208 | err = gcry_md_open (&ctx.md_handle, ht, 0); |
| 211 | else if (ht == htSHA512) SHA512_Init(&ctx.sha512); | 209 | assert (err == GPG_ERR_NO_ERROR); |
| 212 | } | 210 | } |
| 213 | 211 | ||
| 214 | 212 | ||
| 215 | static void update(HashType ht, Ctx & ctx, | 213 | static void update(HashType ht, Ctx & ctx, |
| 216 | const unsigned char * bytes, unsigned int len) | 214 | const unsigned char * bytes, unsigned int len) |
| 217 | { | 215 | { |
| 218 | if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len); | 216 | gcry_md_write (ctx.md_handle, bytes, len); |
| 219 | else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len); | ||
| 220 | else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len); | ||
| 221 | else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len); | ||
| 222 | } | 217 | } |
| 223 | 218 | ||
| 224 | 219 | ||
| 225 | static void finish(HashType ht, Ctx & ctx, unsigned char * hash) | 220 | static void finish(HashType ht, Ctx & ctx, unsigned char * hash) |
| 226 | { | 221 | { |
| 227 | if (ht == htMD5) MD5_Final(hash, &ctx.md5); | 222 | memcpy (hash, gcry_md_read (ctx.md_handle, ht), |
| 228 | else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1); | 223 | gcry_md_get_algo_dlen (ht)); |
| 229 | else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256); | 224 | gcry_md_close (ctx.md_handle); |
| 230 | else if (ht == htSHA512) SHA512_Final(hash, &ctx.sha512); | 225 | ctx.md_handle = NULL; |
| 231 | } | 226 | } |
| 232 | 227 | ||
| 233 | 228 | ||
diff --git a/nix/libutil/md5.h b/nix/libutil/md5.h deleted file mode 100644 index 4583a458b3d..00000000000 --- a/nix/libutil/md5.h +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | /* GNU Guix --- Functional package management for GNU | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of GNU Guix. | ||
| 5 | |||
| 6 | GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define MD5_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | MD5_Init (struct MD5_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_MD5); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define MD5_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | MD5_Final (void *resbuf, struct MD5_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (resbuf, ctx, GCRY_MD_MD5); | ||
| 35 | } | ||
diff --git a/nix/libutil/sha1.h b/nix/libutil/sha1.h deleted file mode 100644 index d2d071e0588..00000000000 --- a/nix/libutil/sha1.h +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | /* GNU Guix --- Functional package management for GNU | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of GNU Guix. | ||
| 5 | |||
| 6 | GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define SHA_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | SHA1_Init (struct SHA_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_SHA1); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define SHA1_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | SHA1_Final (void *resbuf, struct SHA_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (resbuf, ctx, GCRY_MD_SHA1); | ||
| 35 | } | ||
diff --git a/nix/libutil/sha256.h b/nix/libutil/sha256.h deleted file mode 100644 index ca95d7fea87..00000000000 --- a/nix/libutil/sha256.h +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | /* GNU Guix --- Functional package management for GNU | ||
| 2 | Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of GNU Guix. | ||
| 5 | |||
| 6 | GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define SHA256_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | SHA256_Init (struct SHA256_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_SHA256); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define SHA256_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | SHA256_Final (void *resbuf, struct SHA256_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (resbuf, ctx, GCRY_MD_SHA256); | ||
| 35 | } | ||
diff --git a/nix/libutil/sha512.h b/nix/libutil/sha512.h deleted file mode 100644 index d2abab4c5ff..00000000000 --- a/nix/libutil/sha512.h +++ /dev/null | |||
| @@ -1,35 +0,0 @@ | |||
| 1 | /* GNU Guix --- Functional package management for GNU | ||
| 2 | Copyright (C) 2012, 2015 Ludovic Courtès <ludo@gnu.org> | ||
| 3 | |||
| 4 | This file is part of GNU Guix. | ||
| 5 | |||
| 6 | GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | under the terms of the GNU General Public License as published by | ||
| 8 | the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | your option) any later version. | ||
| 10 | |||
| 11 | GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | GNU General Public License for more details. | ||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License | ||
| 17 | along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */ | ||
| 18 | |||
| 19 | #include <gcrypt-hash.hh> | ||
| 20 | |||
| 21 | #define SHA512_CTX guix_hash_context | ||
| 22 | |||
| 23 | static inline void | ||
| 24 | SHA512_Init (struct SHA512_CTX *ctx) | ||
| 25 | { | ||
| 26 | guix_hash_init (ctx, GCRY_MD_SHA512); | ||
| 27 | } | ||
| 28 | |||
| 29 | #define SHA512_Update guix_hash_update | ||
| 30 | |||
| 31 | static inline void | ||
| 32 | SHA512_Final (void *resbuf, struct SHA512_CTX *ctx) | ||
| 33 | { | ||
| 34 | guix_hash_final (resbuf, ctx, GCRY_MD_SHA512); | ||
| 35 | } | ||
