Skip to content

Commit

Permalink
Replace SHA3 with SHA2-256
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Mar 3, 2021
1 parent a168e32 commit 44d5380
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion umbral-pre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions umbral-pre/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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));
}
}
10 changes: 5 additions & 5 deletions umbral-pre/src/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,12 +58,12 @@ pub fn unsafe_hash_to_point(data: &[u8], label: &[u8]) -> Option<CurvePoint> {
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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 44d5380

Please sign in to comment.