From patchwork Tue Jun 23 15:55:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 22839 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id AB7EF27BBE3; Tue, 23 Jun 2020 16:57:24 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 779D127BBE1 for ; Tue, 23 Jun 2020 16:57:24 +0100 (BST) Received: from localhost ([::1]:46486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnlIa-0007Vc-1E for patchwork@mira.cbaines.net; Tue, 23 Jun 2020 11:57:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnlHG-0005kg-QM for guix-patches@gnu.org; Tue, 23 Jun 2020 11:56:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnlHG-0000Qb-Gj for guix-patches@gnu.org; Tue, 23 Jun 2020 11:56:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jnlHG-0007Jx-DX for guix-patches@gnu.org; Tue, 23 Jun 2020 11:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42020] [PATCH 1/4] daemon: Map directly to gcrypt hash functions. References: <20200623153633.15346-1-ludo@gnu.org> In-Reply-To: <20200623153633.15346-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 23 Jun 2020 15:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42020 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42020@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 42020-submit@debbugs.gnu.org id=B42020.159292776128134 (code B ref 42020); Tue, 23 Jun 2020 15:56:02 +0000 Received: (at 42020) by debbugs.gnu.org; 23 Jun 2020 15:56:01 +0000 Received: from localhost ([127.0.0.1]:36996 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnlHF-0007Ji-A9 for submit@debbugs.gnu.org; Tue, 23 Jun 2020 11:56:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42748) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnlHD-0007JR-4T for 42020@debbugs.gnu.org; Tue, 23 Jun 2020 11:55:59 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:35820) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnlH7-0000MZ-GA; Tue, 23 Jun 2020 11:55:53 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=57536 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jnlH6-0006sV-PD; Tue, 23 Jun 2020 11:55:53 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 23 Jun 2020 17:55:44 +0200 Message-Id: <20200623155547.15886-1-ludo@gnu.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * 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 + #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 {