From 44d53804c46c94a4543e0169210a282d8fc4b551 Mon Sep 17 00:00:00 2001 From: Bogdan Opanchuk Date: Tue, 2 Mar 2021 15:05:27 -0800 Subject: [PATCH] Replace SHA3 with SHA2-256 --- umbral-pre/Cargo.toml | 1 - umbral-pre/src/curve.rs | 6 +++--- umbral-pre/src/hashing.rs | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/umbral-pre/Cargo.toml b/umbral-pre/Cargo.toml index 7cce5f48..31fd04b6 100644 --- a/umbral-pre/Cargo.toml +++ b/umbral-pre/Cargo.toml @@ -12,7 +12,6 @@ categories = ["cryptography", "no-std"] [dependencies] k256 = { version = "0.6", default-features = false, features = ["ecdsa", "arithmetic"] } blake2 = "0.9" -sha3 = "0.9" sha2 = "0.9" chacha20poly1305 = "0.7" hkdf = "0.10" diff --git a/umbral-pre/src/curve.rs b/umbral-pre/src/curve.rs index b9be6a12..4803761b 100644 --- a/umbral-pre/src/curve.rs +++ b/umbral-pre/src/curve.rs @@ -267,7 +267,7 @@ impl SerializableToArray for PublicKey { #[cfg(test)] mod tests { - use sha3::Sha3_256; + use sha2::Sha256; use signature::digest::Digest; use super::{PublicKey, SecretKey}; @@ -294,11 +294,11 @@ mod tests { fn test_sign_and_verify() { let sk = SecretKey::random(); let message = b"asdafdahsfdasdfasd"; - let digest = Sha3_256::new().chain(message); + let digest = Sha256::new().chain(message); let signature = sk.sign_digest(digest); let pk = PublicKey::from_secret_key(&sk); - let digest = Sha3_256::new().chain(message); + let digest = Sha256::new().chain(message); assert!(pk.verify_digest(digest, &signature)); } } diff --git a/umbral-pre/src/hashing.rs b/umbral-pre/src/hashing.rs index 927333f8..72899617 100644 --- a/umbral-pre/src/hashing.rs +++ b/umbral-pre/src/hashing.rs @@ -2,7 +2,7 @@ use blake2::VarBlake2b; use digest::{Digest, Update, VariableOutput}; use generic_array::typenum::Unsigned; use generic_array::GenericArray; -use sha3::Sha3_256; +use sha2::Sha256; use crate::curve::{CurvePoint, CurveScalar, PublicKey, SecretKey, Signature}; use crate::traits::SerializableToArray; @@ -58,12 +58,12 @@ pub fn unsafe_hash_to_point(data: &[u8], label: &[u8]) -> Option { None } -pub(crate) struct ScalarDigest(Sha3_256); +pub(crate) struct ScalarDigest(Sha256); // TODO (#2): original uses ExtendedKeccak here impl ScalarDigest { pub fn new() -> Self { - Self(Sha3_256::new()).chain_bytes(b"hash_to_curvebn") + Self(Sha256::new()).chain_bytes(b"hash_to_curvebn") } fn chain_impl(self, bytes: &[u8]) -> Self { @@ -95,11 +95,11 @@ impl ScalarDigest { } } -pub(crate) struct SignatureDigest(Sha3_256); +pub(crate) struct SignatureDigest(Sha256); impl SignatureDigest { pub fn new() -> Self { - Self(Sha3_256::new()) + Self(Sha256::new()) } fn chain_impl(self, bytes: &[u8]) -> Self {