mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-04 19:11:52 -08:00
dev(ciphers): move blake2b.rs and incorrect_hmac_blake2b.rs to dedicated hash_functions directory
This commit is contained in:
@@ -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
|
||||
@@ -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<Blake2bCore, 32, 32>;
|
||||
@@ -1,2 +1,4 @@
|
||||
pub mod blake2b;
|
||||
pub mod incorrect_hmac_blake2b;
|
||||
pub mod keyed_shake256;
|
||||
mod infer_keyed_hash;
|
||||
@@ -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};
|
||||
pub use hash_functions::{blake2b, incorrect_hmac_blake2b, keyed_shake256};
|
||||
Reference in New Issue
Block a user