diff --git a/Cargo.lock b/Cargo.lock index 94ed173..e39adea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,8 +39,7 @@ checksum = "d9aa1eef3994e2ccd304a78fe3fea4a73e5792007f85f09b79bb82143ca5f82b" [[package]] name = "belt-hash" version = "0.2.0-pre.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92eecb3b8b1afdc0ea8eaa6f947ef9ebb0effdee09ea0a1b254d05d082bcb2a3" +source = "git+https://github.com/RustCrypto/hashes.git#7d44caf065dbeb3f10a372a26a8b9f1c927f8433" dependencies = [ "belt-block", "digest", @@ -70,8 +69,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cipher" version = "0.5.0-pre.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "276974d2acb7cf592603150941fc1ff6442acdeb1dc653ac2825928f4703c131" +source = "git+https://github.com/RustCrypto/traits.git#915474f1ed5be0a19fd102d5f75ef8e04c765416" dependencies = [ "crypto-common", "inout", @@ -80,8 +78,7 @@ dependencies = [ [[package]] name = "cmac" version = "0.8.0-pre.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5965a19674a22507a478bb9fc6db32b1a397cd0d91c4a7f8facc1b2547e9de54" +source = "git+https://github.com/RustCrypto/MACs.git#64d671d5c375838173d18e30bc14dffc80c13e51" dependencies = [ "cipher", "dbl", @@ -109,8 +106,7 @@ dependencies = [ [[package]] name = "crypto-common" version = "0.2.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "170d71b5b14dec99db7739f6fc7d6ec2db80b78c3acb77db48392ccc3d8a9ea0" +source = "git+https://github.com/RustCrypto/traits.git#915474f1ed5be0a19fd102d5f75ef8e04c765416" dependencies = [ "hybrid-array", ] @@ -127,8 +123,7 @@ dependencies = [ [[package]] name = "digest" version = "0.11.0-pre.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c478574b20020306f98d61c8ca3322d762e1ff08117422ac6106438605ea516" +source = "git+https://github.com/RustCrypto/traits.git#915474f1ed5be0a19fd102d5f75ef8e04c765416" dependencies = [ "block-buffer", "crypto-common", @@ -161,8 +156,7 @@ dependencies = [ [[package]] name = "hmac" version = "0.13.0-pre.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62c11fc82c6b89c906b4d26b7b5a305d0b3aebd4b458dd1bd0a7ed98c548a28e" +source = "git+https://github.com/RustCrypto/MACs.git#64d671d5c375838173d18e30bc14dffc80c13e51" dependencies = [ "digest", ] @@ -208,8 +202,7 @@ checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" [[package]] name = "sha1" version = "0.11.0-pre.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55f44e40722caefdd99383c25d3ae52a1094a1951215ae76f68837ece4e7f566" +source = "git+https://github.com/RustCrypto/hashes.git#7d44caf065dbeb3f10a372a26a8b9f1c927f8433" dependencies = [ "cfg-if", "cpufeatures", @@ -219,8 +212,7 @@ dependencies = [ [[package]] name = "sha2" version = "0.11.0-pre.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b4241d1a56954dce82cecda5c8e9c794eef6f53abe5e5216bac0a0ea71ffa7" +source = "git+https://github.com/RustCrypto/hashes.git#7d44caf065dbeb3f10a372a26a8b9f1c927f8433" dependencies = [ "cfg-if", "cpufeatures", diff --git a/Cargo.toml b/Cargo.toml index 93fc126..f131cf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,15 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io] +cipher = { git = "https://github.com/RustCrypto/traits.git" } +crypto-common = { git = "https://github.com/RustCrypto/traits.git" } +digest = { git = "https://github.com/RustCrypto/traits.git" } + +cmac = { git = "https://github.com/RustCrypto/MACs.git" } +hmac = { git = "https://github.com/RustCrypto/MACs.git" } + +belt-hash = { git = "https://github.com/RustCrypto/hashes.git" } +sha1 = { git = "https://github.com/RustCrypto/hashes.git" } +sha2 = { git = "https://github.com/RustCrypto/hashes.git" } diff --git a/bake-kdf/src/lib.rs b/bake-kdf/src/lib.rs index b71ec09..64699aa 100644 --- a/bake-kdf/src/lib.rs +++ b/bake-kdf/src/lib.rs @@ -10,7 +10,7 @@ #![warn(missing_docs, rust_2018_idioms)] use belt_hash::digest::FixedOutput; -use belt_hash::{BeltHash, Digest, belt_compress}; +use belt_hash::{BeltHash, Digest, block_api::belt_compress}; /// `belt-keyexpand` key expansion algorithm described in STB 34.101.34-2020 8.1.2. /// diff --git a/hkdf/src/lib.rs b/hkdf/src/lib.rs index d3e17f1..d5bf1ca 100644 --- a/hkdf/src/lib.rs +++ b/hkdf/src/lib.rs @@ -170,12 +170,11 @@ where impl fmt::Debug for HkdfExtract where H: OutputSizeUser, - I: HmacImpl, - I::Core: AlgorithmName, + I: HmacImpl + AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("HkdfExtract<")?; - ::write_alg_name(f)?; + ::write_alg_name(f)?; f.write_str("> { ... }") } } @@ -185,7 +184,7 @@ where /// [crate root](index.html#usage). #[derive(Clone)] pub struct Hkdf = Hmac> { - hmac: I::Core, + hmac: I, _pd: PhantomData, } @@ -206,7 +205,7 @@ impl> Hkdf { return Err(InvalidPrkLength); } Ok(Self { - hmac: I::new_core(prk), + hmac: I::new_from_slice(prk), _pd: PhantomData, }) } @@ -235,7 +234,7 @@ impl> Hkdf { } for (block_n, block) in okm.chunks_mut(chunk_len).enumerate() { - let mut hmac = I::from_core(&self.hmac); + let mut hmac = self.hmac.clone(); if let Some(ref prev) = prev { hmac.update(prev) @@ -272,16 +271,16 @@ impl fmt::Debug for Hkdf where H: OutputSizeUser, I: HmacImpl, - I::Core: AlgorithmName, + I: AlgorithmName, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Hkdf<")?; - ::write_alg_name(f)?; + ::write_alg_name(f)?; f.write_str("> { ... }") } } /// Sealed trait implemented for [`Hmac`] and [`SimpleHmac`]. -pub trait HmacImpl: sealed::Sealed {} +pub trait HmacImpl: sealed::Sealed + Clone {} -impl> HmacImpl for T {} +impl + Clone> HmacImpl for T {} diff --git a/hkdf/src/sealed.rs b/hkdf/src/sealed.rs index e1d02f7..e913e2b 100644 --- a/hkdf/src/sealed.rs +++ b/hkdf/src/sealed.rs @@ -1,18 +1,12 @@ use hmac::digest::{ Digest, FixedOutput, KeyInit, Output, Update, - core_api::{BlockSizeUser, CoreWrapper, OutputSizeUser}, + block_api::{BlockSizeUser, OutputSizeUser}, }; -use hmac::{EagerHash, Hmac, HmacCore, SimpleHmac}; +use hmac::{Hmac, SimpleHmac, block_api::EagerHash}; pub trait Sealed { - type Core: Clone; - fn new_from_slice(key: &[u8]) -> Self; - fn new_core(key: &[u8]) -> Self::Core; - - fn from_core(core: &Self::Core) -> Self; - fn update(&mut self, data: &[u8]); fn finalize(self) -> Output; @@ -22,23 +16,11 @@ impl Sealed for Hmac where H: EagerHash + OutputSizeUser, { - type Core = HmacCore; - #[inline(always)] fn new_from_slice(key: &[u8]) -> Self { KeyInit::new_from_slice(key).expect("HMAC can take a key of any size") } - #[inline(always)] - fn new_core(key: &[u8]) -> Self::Core { - HmacCore::new_from_slice(key).expect("HMAC can take a key of any size") - } - - #[inline(always)] - fn from_core(core: &Self::Core) -> Self { - CoreWrapper::from_core(core.clone()) - } - #[inline(always)] fn update(&mut self, data: &[u8]) { Update::update(self, data); @@ -54,23 +36,11 @@ where } impl Sealed for SimpleHmac { - type Core = Self; - #[inline(always)] fn new_from_slice(key: &[u8]) -> Self { KeyInit::new_from_slice(key).expect("HMAC can take a key of any size") } - #[inline(always)] - fn new_core(key: &[u8]) -> Self::Core { - KeyInit::new_from_slice(key).expect("HMAC can take a key of any size") - } - - #[inline(always)] - fn from_core(core: &Self::Core) -> Self { - core.clone() - } - #[inline(always)] fn update(&mut self, data: &[u8]) { Update::update(self, data); diff --git a/hkdf/tests/rfc5869.rs b/hkdf/tests/rfc5869.rs index bef7699..0b16043 100644 --- a/hkdf/tests/rfc5869.rs +++ b/hkdf/tests/rfc5869.rs @@ -1,5 +1,5 @@ use hex_literal::hex; -use hkdf::{Hkdf, hmac::EagerHash}; +use hkdf::{Hkdf, hmac::block_api::EagerHash}; use sha1::Sha1; use sha2::{Sha256, digest::OutputSizeUser};