diff --git a/elliptic-curve/Cargo.lock b/elliptic-curve/Cargo.lock index 76ee28dd4..b3896be8b 100644 --- a/elliptic-curve/Cargo.lock +++ b/elliptic-curve/Cargo.lock @@ -28,20 +28,13 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.9.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95" dependencies = [ - "block-padding", "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "cfg-if" version = "1.0.0" @@ -75,6 +68,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "crypto-common" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0" +dependencies = [ + "generic-array", +] + [[package]] name = "der" version = "0.5.1" @@ -87,10 +89,12 @@ dependencies = [ [[package]] name = "digest" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b" dependencies = [ + "block-buffer", + "crypto-common", "generic-array", ] @@ -191,12 +195,6 @@ version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "pem-rfc7468" version = "0.3.1" @@ -270,27 +268,23 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec" dependencies = [ - "block-buffer", "cfg-if", "cpufeatures", "digest", - "opaque-debug", ] [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "31f935e31cf406e8c0e96c2815a5516181b7004ae8c5f296293221e9b1e356bd" dependencies = [ - "block-buffer", "digest", "keccak", - "opaque-debug", ] [[package]] diff --git a/elliptic-curve/Cargo.toml b/elliptic-curve/Cargo.toml index cef05f580..4a19f40f3 100644 --- a/elliptic-curve/Cargo.toml +++ b/elliptic-curve/Cargo.toml @@ -30,7 +30,7 @@ zeroize = { version = "1.5", default-features = false } # optional dependencies base64ct = { version = "1", optional = true, default-features = false } -digest = { version = "0.9", optional = true, default-features = false } +digest = { version = "0.10", optional = true } ff = { version = "0.11", optional = true, default-features = false } group = { version = "0.11", optional = true, default-features = false } hex-literal = { version = "0.3", optional = true } @@ -41,8 +41,8 @@ serde_json = { version = "1", optional = true, default-features = false, feature [dev-dependencies] hex-literal = "0.3" -sha2 = "0.9" -sha3 = "0.9" +sha2 = "0.10" +sha3 = "0.10" [features] default = ["arithmetic"] diff --git a/elliptic-curve/src/hash2field/expand_msg.rs b/elliptic-curve/src/hash2field/expand_msg.rs index fda9fcc83..6fd88dfdc 100644 --- a/elliptic-curve/src/hash2field/expand_msg.rs +++ b/elliptic-curve/src/hash2field/expand_msg.rs @@ -76,7 +76,12 @@ where X: Digest, { if dst.len() > MAX_DST_LEN { - Self::Hashed(X::new().chain(OVERSIZE_DST_SALT).chain(dst).finalize()) + Self::Hashed({ + let mut hash = X::new(); + hash.update(OVERSIZE_DST_SALT); + hash.update(dst); + hash.finalize() + }) } else { Self::Array(dst) } diff --git a/elliptic-curve/src/hash2field/expand_msg/xmd.rs b/elliptic-curve/src/hash2field/expand_msg/xmd.rs index 8e05e715b..5132f3b3a 100644 --- a/elliptic-curve/src/hash2field/expand_msg/xmd.rs +++ b/elliptic-curve/src/hash2field/expand_msg/xmd.rs @@ -5,11 +5,12 @@ use core::marker::PhantomData; use super::{Domain, ExpandMsg, Expander}; use crate::{Error, Result}; use digest::{ + core_api::BlockSizeUser, generic_array::{ typenum::{IsLess, IsLessOrEqual, Unsigned, U256}, GenericArray, }, - BlockInput, Digest, + Digest, }; /// Placeholder type for implementing `expand_message_xmd` based on a hash function @@ -20,14 +21,14 @@ use digest::{ /// - `len_in_bytes > 255 * HashT::OutputSize` pub struct ExpandMsgXmd(PhantomData) where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, HashT::OutputSize: IsLess, HashT::OutputSize: IsLessOrEqual; /// ExpandMsgXmd implements expand_message_xmd for the ExpandMsg trait impl<'a, HashT> ExpandMsg<'a> for ExpandMsgXmd where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, // If `len_in_bytes` is bigger then 256, length of the `DST` will depend on // the output size of the hash, which is still not allowed to be bigger then 256: // https://www.ietf.org/archive/id/draft-irtf-cfrg-hash-to-curve-13.html#section-5.4.1-6 @@ -53,25 +54,25 @@ where let ell = u8::try_from((len_in_bytes + b_in_bytes - 1) / b_in_bytes).map_err(|_| Error)?; let domain = Domain::xmd::(dst); - let mut b_0 = HashT::new().chain(GenericArray::::default()); + let mut b_0 = HashT::new(); + b_0.update(GenericArray::::default()); for msg in msgs { - b_0 = b_0.chain(msg); + b_0.update(msg); } - let b_0 = b_0 - .chain(len_in_bytes_u16.to_be_bytes()) - .chain([0]) - .chain(domain.data()) - .chain([domain.len()]) - .finalize(); + b_0.update(len_in_bytes_u16.to_be_bytes()); + b_0.update([0]); + b_0.update(domain.data()); + b_0.update([domain.len()]); + let b_0 = b_0.finalize(); - let b_vals = HashT::new() - .chain(&b_0[..]) - .chain([1u8]) - .chain(domain.data()) - .chain([domain.len()]) - .finalize(); + let mut b_vals = HashT::new(); + b_vals.update(&b_0[..]); + b_vals.update([1u8]); + b_vals.update(domain.data()); + b_vals.update([domain.len()]); + let b_vals = b_vals.finalize(); Ok(ExpanderXmd { b_0, @@ -87,7 +88,7 @@ where /// [`Expander`] type for [`ExpandMsgXmd`]. pub struct ExpanderXmd<'a, HashT> where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, HashT::OutputSize: IsLess, HashT::OutputSize: IsLessOrEqual, { @@ -101,7 +102,7 @@ where impl<'a, HashT> ExpanderXmd<'a, HashT> where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, HashT::OutputSize: IsLess, HashT::OutputSize: IsLessOrEqual, { @@ -116,12 +117,12 @@ where .zip(&self.b_vals[..]) .enumerate() .for_each(|(j, (b0val, bi1val))| tmp[j] = b0val ^ bi1val); - self.b_vals = HashT::new() - .chain(tmp) - .chain([self.index]) - .chain(self.domain.data()) - .chain([self.domain.len()]) - .finalize(); + let mut b_vals = HashT::new(); + b_vals.update(tmp); + b_vals.update([self.index]); + b_vals.update(self.domain.data()); + b_vals.update([self.domain.len()]); + self.b_vals = b_vals.finalize(); true } else { false @@ -131,7 +132,7 @@ where impl<'a, HashT> Expander for ExpanderXmd<'a, HashT> where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, HashT::OutputSize: IsLess, HashT::OutputSize: IsLessOrEqual, { @@ -163,7 +164,7 @@ mod test { len_in_bytes: u16, bytes: &[u8], ) where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, HashT::OutputSize: IsLess, { let block = HashT::BlockSize::to_usize(); @@ -203,7 +204,7 @@ mod test { domain: &Domain<'_, HashT::OutputSize>, ) -> Result<()> where - HashT: Digest + BlockInput, + HashT: Digest + BlockSizeUser, HashT::OutputSize: IsLess + IsLessOrEqual, { assert_message::(self.msg, domain, L::to_u16(), self.msg_prime); diff --git a/elliptic-curve/src/ops.rs b/elliptic-curve/src/ops.rs index d8038d931..d6a215490 100644 --- a/elliptic-curve/src/ops.rs +++ b/elliptic-curve/src/ops.rs @@ -9,7 +9,7 @@ use subtle::CtOption; use group::Group; #[cfg(feature = "digest")] -use digest::{BlockInput, Digest, FixedOutput, Reset, Update}; +use digest::{core_api::BlockSizeUser, Digest, FixedOutput, Reset}; /// Perform an inversion on a field element (i.e. base field element or scalar) pub trait Invert { @@ -67,7 +67,7 @@ pub trait Reduce: Sized { #[cfg_attr(docsrs, doc(cfg(feature = "digest")))] fn from_be_digest_reduced(digest: D) -> Self where - D: FixedOutput + BlockInput + Clone + Default + Reset + Update, + D: FixedOutput + BlockSizeUser + Clone + Digest + Reset, { Self::from_be_bytes_reduced(digest.finalize()) } @@ -78,7 +78,7 @@ pub trait Reduce: Sized { #[cfg_attr(docsrs, doc(cfg(feature = "digest")))] fn from_le_digest_reduced(digest: D) -> Self where - D: FixedOutput + BlockInput + Clone + Default + Reset + Update, + D: FixedOutput + BlockSizeUser + Clone + Digest + Reset, { Self::from_le_bytes_reduced(digest.finalize()) }