From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6MGXJ20m8l4gOwAA0tVLHw (envelope-from ) for ; Tue, 23 Jun 2020 15:57:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YGtSI20m8l5eDgAAB5/wlQ (envelope-from ) for ; Tue, 23 Jun 2020 15:57:33 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2E0369400C1 for ; Tue, 23 Jun 2020 15:57:33 +0000 (UTC) Received: from localhost ([::1]:46914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnlIi-0007jB-4g for larch@yhetil.org; Tue, 23 Jun 2020 11:57:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jnlIE-0006zW-AH for guix-patches@gnu.org; Tue, 23 Jun 2020 11:57:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jnlIE-0000we-12 for guix-patches@gnu.org; Tue, 23 Jun 2020 11:57:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jnlIE-0007M1-0H for guix-patches@gnu.org; Tue, 23 Jun 2020 11:57:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42020] [PATCH 3/4] daemon: Recognize SHA3 and BLAKE2s. 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:57:01 +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.159292776728182 (code B ref 42020); Tue, 23 Jun 2020 15:57:01 +0000 Received: (at 42020) by debbugs.gnu.org; 23 Jun 2020 15:56:07 +0000 Received: from localhost ([127.0.0.1]:37000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnlHH-0007KK-Mh for submit@debbugs.gnu.org; Tue, 23 Jun 2020 11:56:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42768) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jnlHG-0007JX-Dt for 42020@debbugs.gnu.org; Tue, 23 Jun 2020 11:56:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:35822) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jnlHB-0000Ni-3d; Tue, 23 Jun 2020 11:55:57 -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 1jnlHA-0006sV-6p; Tue, 23 Jun 2020 11:55:56 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 23 Jun 2020 17:55:46 +0200 Message-Id: <20200623155547.15886-3-ludo@gnu.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200623155547.15886-1-ludo@gnu.org> References: <20200623155547.15886-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 3.99 X-TUID: axr99L3BzxrQ * nix/libutil/hash.hh (HashType): Add htSHA3_256, htSHA3_512, and htBLAKE2s_256. * nix/libutil/hash.cc (parseHashType, printHashType): Recognize them. * tests/store.scm ("add-to-store"): Test these algorithms. --- nix/libutil/hash.cc | 6 ++++++ nix/libutil/hash.hh | 5 ++++- tests/store.scm | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nix/libutil/hash.cc b/nix/libutil/hash.cc index 20d2e4b724..7853acdd49 100644 --- a/nix/libutil/hash.cc +++ b/nix/libutil/hash.cc @@ -321,6 +321,9 @@ HashType parseHashType(const string & s) else if (s == "sha1") return htSHA1; else if (s == "sha256") return htSHA256; else if (s == "sha512") return htSHA512; + else if (s == "sha3-256") return htSHA3_256; + else if (s == "sha3-512") return htSHA3_512; + else if (s == "blake2s-256") return htBLAKE2s_256; else return htUnknown; } @@ -331,6 +334,9 @@ string printHashType(HashType ht) else if (ht == htSHA1) return "sha1"; else if (ht == htSHA256) return "sha256"; else if (ht == htSHA512) return "sha512"; + else if (ht == htSHA3_256) return "sha3-256"; + else if (ht == htSHA3_512) return "sha3-512"; + else if (ht == htBLAKE2s_256) return "blake2s-256"; else throw Error("cannot print unknown hash type"); } diff --git a/nix/libutil/hash.hh b/nix/libutil/hash.hh index 7357a34e1d..ac58651a02 100644 --- a/nix/libutil/hash.hh +++ b/nix/libutil/hash.hh @@ -16,7 +16,10 @@ typedef enum { htMD5 = GCRY_MD_MD5, htSHA1 = GCRY_MD_SHA1, htSHA256 = GCRY_MD_SHA256, - htSHA512 = GCRY_MD_SHA512 + htSHA512 = GCRY_MD_SHA512, + htSHA3_256 = GCRY_MD_SHA3_256, + htSHA3_512 = GCRY_MD_SHA3_512, + htBLAKE2s_256 = GCRY_MD_BLAKE2S_256 } HashType; struct Hash diff --git a/tests/store.scm b/tests/store.scm index 06f7939657..ee3e01f33b 100644 --- a/tests/store.scm +++ b/tests/store.scm @@ -116,7 +116,7 @@ (list (stat:uid s) (stat:perms s)))) (test-equal "add-to-store" - '("sha1" "sha256" "sha512") + '("sha1" "sha256" "sha512" "sha3-256" "sha3-512" "blake2s-256") (let* ((file (search-path %load-path "guix.scm")) (content (call-with-input-file file get-bytevector-all))) (map (lambda (hash-algo) @@ -125,7 +125,7 @@ (bytevector=? (call-with-input-file file get-bytevector-all) content) hash-algo))) - '("sha1" "sha256" "sha512")))) + '("sha1" "sha256" "sha512" "sha3-256" "sha3-512" "blake2s-256")))) (test-equal "add-data-to-store" #vu8(1 2 3 4 5) -- 2.26.2