diff --git a/ciphers/src/subtle/blake2b.rs b/ciphers/src/subtle/hash_functions/blake2b.rs similarity index 99% rename from ciphers/src/subtle/blake2b.rs rename to ciphers/src/subtle/hash_functions/blake2b.rs index 26dbf25..13e7532 100644 --- a/ciphers/src/subtle/blake2b.rs +++ b/ciphers/src/subtle/hash_functions/blake2b.rs @@ -33,6 +33,7 @@ pub const OUT_MAX: usize = OUT_LEN; /// Hashes the given `data` with the [Blake2bMac] hash function under the given `key`. /// The both the length of the output the length of the key 32 bytes (or 256 bits). /// +/// TODO: Adapt example /// # Examples /// ///```rust diff --git a/ciphers/src/subtle/incorrect_hmac_blake2b.rs b/ciphers/src/subtle/hash_functions/incorrect_hmac_blake2b.rs similarity index 83% rename from ciphers/src/subtle/incorrect_hmac_blake2b.rs rename to ciphers/src/subtle/hash_functions/incorrect_hmac_blake2b.rs index 0bc72cf..343945c 100644 --- a/ciphers/src/subtle/incorrect_hmac_blake2b.rs +++ b/ciphers/src/subtle/hash_functions/incorrect_hmac_blake2b.rs @@ -1,10 +1,11 @@ use anyhow::ensure; use zeroize::Zeroizing; - +use rosenpass_cipher_traits::KeyedHash; use rosenpass_constant_time::xor; use rosenpass_to::{ops::copy_slice, with_destination, To}; -use crate::subtle::blake2b; +use crate::subtle::hash_functions::blake2b; +use crate::subtle::hash_functions::infer_keyed_hash::InferKeyedHash; /// The key length, 32 bytes or 256 bits. pub const KEY_LEN: usize = 32; @@ -65,3 +66,16 @@ pub fn hash<'a>(key: &'a [u8], data: &'a [u8]) -> impl To<[u8], anyhow::Result<( Ok(()) }) } + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Blake2bCore; + +impl KeyedHash<32, 32> for Blake2bCore { + type Error = anyhow::Error; + + fn keyed_hash(key: &[u8; 32], data: &[u8], out: &mut [u8; 32]) -> Result<(), Self::Error> { + hash(key, data).to(out) + } +} + +pub type Blake2b = InferKeyedHash; diff --git a/ciphers/src/subtle/hash_functions/mod.rs b/ciphers/src/subtle/hash_functions/mod.rs index ac1404e..af0ccb7 100644 --- a/ciphers/src/subtle/hash_functions/mod.rs +++ b/ciphers/src/subtle/hash_functions/mod.rs @@ -1,2 +1,4 @@ +pub mod blake2b; +pub mod incorrect_hmac_blake2b; pub mod keyed_shake256; mod infer_keyed_hash; \ No newline at end of file diff --git a/ciphers/src/subtle/mod.rs b/ciphers/src/subtle/mod.rs index 93bd094..e5f6947 100644 --- a/ciphers/src/subtle/mod.rs +++ b/ciphers/src/subtle/mod.rs @@ -4,13 +4,11 @@ /// - [chacha20poly1305_ietf_libcrux]: The Chacha20Poly1305 AEAD as implemented in [libcrux](https://github.com/cryspen/libcrux) (only used when the feature `experiment_libcrux` is enabled). /// - [incorrect_hmac_blake2b]: An (incorrect) hmac based on [blake2b]. /// - [xchacha20poly1305_ietf] The Chacha20Poly1305 AEAD as implemented in [RustCrypto](https://crates.io/crates/chacha20poly1305) -pub mod blake2b; #[cfg(not(feature = "experiment_libcrux"))] pub mod chacha20poly1305_ietf; #[cfg(feature = "experiment_libcrux")] pub mod chacha20poly1305_ietf_libcrux; -pub mod incorrect_hmac_blake2b; pub mod xchacha20poly1305_ietf; -pub mod hash_functions; +mod hash_functions; -pub use hash_functions::{keyed_shake256}; \ No newline at end of file +pub use hash_functions::{blake2b, incorrect_hmac_blake2b, keyed_shake256}; \ No newline at end of file