all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 42020@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#42020] [PATCH 1/4] daemon: Map directly to gcrypt hash functions.
Date: Tue, 23 Jun 2020 17:55:44 +0200	[thread overview]
Message-ID: <20200623155547.15886-1-ludo@gnu.org> (raw)
In-Reply-To: <20200623153633.15346-1-ludo@gnu.org>

* nix/libutil/hash.hh (HashType): Map directly to GCRY_MD_ values.
(md5HashSize, sha1HashSize, sha256HashSize, sha512HashSize): Remove.
* nix/libutil/hash.cc (Hash::Hash): Use 'gcry_md_get_algo_dlen'.
---
 nix/libutil/hash.cc |  8 +++-----
 nix/libutil/hash.hh | 17 +++++++++--------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc
index ea69aa64f9..251f18f60e 100644
--- a/nix/libutil/hash.cc
+++ b/nix/libutil/hash.cc
@@ -38,11 +38,9 @@ Hash::Hash()
 Hash::Hash(HashType type)
 {
     this->type = type;
-    if (type == htMD5) hashSize = md5HashSize;
-    else if (type == htSHA1) hashSize = sha1HashSize;
-    else if (type == htSHA256) hashSize = sha256HashSize;
-    else if (type == htSHA512) hashSize = sha512HashSize;
-    else throw Error("unknown hash type");
+    hashSize = gcry_md_get_algo_dlen(type);
+
+    if (hashSize == 0) throw Error("unknown hash type");
     assert(hashSize <= maxHashSize);
     memset(hash, 0, maxHashSize);
 }
diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh
index 6b5e47cd8a..7357a34e1d 100644
--- a/nix/libutil/hash.hh
+++ b/nix/libutil/hash.hh
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <gcrypt.h>
+
 #include "types.hh"
 #include "serialise.hh"
 
@@ -7,16 +9,15 @@
 namespace nix {
 
 
-typedef enum { htUnknown, htMD5, htSHA1, htSHA256, htSHA512 } HashType;
-
-
-const int md5HashSize = 16;
-const int sha1HashSize = 20;
-const int sha256HashSize = 32;
-const int sha512HashSize = 64;
-
 extern const string base32Chars;
 
+typedef enum {
+    htUnknown = 0,
+    htMD5 = GCRY_MD_MD5,
+    htSHA1 = GCRY_MD_SHA1,
+    htSHA256 = GCRY_MD_SHA256,
+    htSHA512 = GCRY_MD_SHA512
+} HashType;
 
 struct Hash
 {
-- 
2.26.2





  reply	other threads:[~2020-06-23 15:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-23 15:36 [bug#42020] [PATCH 0/4] Add daemon support for SHA3 and BLAKE2s Ludovic Courtès
2020-06-23 15:55 ` Ludovic Courtès [this message]
2020-06-23 15:55   ` [bug#42020] [PATCH 2/4] daemon: Remove OpenSSL hash compatibility wrappers Ludovic Courtès
2020-06-23 15:55   ` [bug#42020] [PATCH 3/4] daemon: Recognize SHA3 and BLAKE2s Ludovic Courtès
2020-06-23 15:55   ` [bug#42020] [PATCH 4/4] packages: Recognize SHA3 and BLAKE2s for 'content-hash' Ludovic Courtès
2020-06-27 21:44 ` bug#42020: [PATCH 0/4] Add daemon support for SHA3 and BLAKE2s Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200623155547.15886-1-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=42020@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.