diff --git a/Cargo.lock b/Cargo.lock index ee78242b9..85fb2bc6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,15 +94,6 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - [[package]] name = "cpufeatures" version = "0.3.0" @@ -211,10 +202,9 @@ dependencies = [ [[package]] name = "keccak" version = "0.2.0-rc.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a412fe37705d515cba9dbf1448291a717e187e2351df908cfc0137cbec3d480" +source = "git+https://github.com/RustCrypto/sponges#38d10d219450dae3c2d4506f7b2ce13e6eb32f63" dependencies = [ - "cpufeatures 0.2.17", + "cpufeatures", ] [[package]] @@ -296,7 +286,7 @@ name = "sha1" version = "0.11.0-rc.5" dependencies = [ "cfg-if", - "cpufeatures 0.3.0", + "cpufeatures", "digest", "hex-literal", ] @@ -316,7 +306,7 @@ name = "sha2" version = "0.11.0-rc.5" dependencies = [ "cfg-if", - "cpufeatures 0.3.0", + "cpufeatures", "digest", "hex-literal", ] diff --git a/Cargo.toml b/Cargo.toml index 2c7653ae8..e8ee1fca7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,3 +34,5 @@ opt-level = 2 sha1 = { path = "sha1" } sha3 = { path = "sha3" } whirlpool = { path = "whirlpool" } + +keccak = { git = "https://github.com/RustCrypto/sponges" } diff --git a/sha3/Cargo.toml b/sha3/Cargo.toml index c06c2bb6c..ffed73131 100644 --- a/sha3/Cargo.toml +++ b/sha3/Cargo.toml @@ -29,7 +29,6 @@ default = ["alloc", "oid"] alloc = ["digest/alloc"] oid = ["digest/oid"] # Enable OID support. zeroize = ["digest/zeroize"] -asm = ["keccak/asm"] # Enable ASM (currently ARMv8 only). [package.metadata.docs.rs] all-features = true diff --git a/sha3/src/block_api.rs b/sha3/src/block_api.rs index 4f6129052..d8b243569 100644 --- a/sha3/src/block_api.rs +++ b/sha3/src/block_api.rs @@ -13,6 +13,7 @@ use digest::{ }, typenum::{IsLessOrEqual, True, U0, U200}, }; +use keccak::KeccakP1600; pub use crate::cshake::{CShake128Core, CShake256Core}; @@ -27,7 +28,7 @@ pub struct Sha3HasherCore< Rate: BlockSizes + IsLessOrEqual, OutputSize: ArraySize + IsLessOrEqual, { - state: [u64; PLEN], + state: KeccakP1600, _pd: PhantomData<(Rate, OutputSize)>, } @@ -75,8 +76,8 @@ where #[inline] fn update_blocks(&mut self, blocks: &[Block]) { for block in blocks { - xor_block(&mut self.state, block); - keccak::p1600(&mut self.state, ROUNDS); + xor_block(self.state.as_mut(), block); + self.state.p1600(ROUNDS); } } } @@ -95,10 +96,10 @@ where let n = block.len(); block[n - 1] |= 0x80; - xor_block(&mut self.state, &block); - keccak::p1600(&mut self.state, ROUNDS); + xor_block(self.state.as_mut(), &block); + self.state.p1600(ROUNDS); - for (o, s) in out.chunks_mut(8).zip(self.state.iter()) { + for (o, s) in out.chunks_mut(8).zip(self.state.as_mut().iter()) { o.copy_from_slice(&s.to_le_bytes()[..o.len()]); } } @@ -119,10 +120,10 @@ where let n = block.len(); block[n - 1] |= 0x80; - xor_block(&mut self.state, &block); - keccak::p1600(&mut self.state, ROUNDS); + xor_block(self.state.as_mut(), &block); + self.state.p1600(ROUNDS); - Sha3ReaderCore::new(&self.state) + Sha3ReaderCore::new(self.state.as_ref()) } } @@ -185,7 +186,7 @@ where #[cfg(feature = "zeroize")] { use digest::zeroize::Zeroize; - self.state.zeroize(); + self.state.as_mut().zeroize(); } } } @@ -210,7 +211,7 @@ where fn serialize(&self) -> SerializedState { let mut serialized_state = SerializedState::::default(); let chunks = serialized_state.chunks_exact_mut(8); - for (val, chunk) in self.state.iter().zip(chunks) { + for (val, chunk) in self.state.as_ref().iter().zip(chunks) { chunk.copy_from_slice(&val.to_le_bytes()); } @@ -227,7 +228,7 @@ where } Ok(Self { - state, + state: KeccakP1600::from(state), _pd: PhantomData, }) }