1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
extern crate alloc;
pub use ;
pub use ;
pub use Error;
pub use ;
/// Type that holds the constants in case both key length and digest length are known at compile
/// time.
;
/// Type that holds the constant in case just the key length is known at compile time.
;
/// Type that holds the constant in case just the digest length is known at compile time.
;
/// Type that holds the constant in case neither the key length nor the digest length is known at
/// compile time.
;
/// Type that is used to bound the implementations to valid key and output lengths.
///
/// We implement [`SupportsKeyLen`] and [`SupportsOutLen`] for [`Blake2s<LengthBounds>`] and
/// [`Blake2b<LengthBounds>`] with the appropriate lengths. This can be used by callers to bound
/// their own implementations to only accept valid lengths.
///
/// # Example
///
/// ```
/// use libcrux_blake2::{Blake2b, Blake2bBuilder, LengthBounds, SupportsKeyLen, SupportsOutLen};
///
/// // A function that does a keyed Blake2b and only accepts valid key lengths
/// fn keyed_hash<const KEY_LEN: usize>(key: &[u8; KEY_LEN], msg: &[u8]) -> [u8; 32]
/// where
/// Blake2b<LengthBounds>: SupportsKeyLen<KEY_LEN>,
/// {
/// let mut hasher = Blake2bBuilder::new_keyed_const(key)
/// .build_const_digest_len::<32>();
/// hasher.update(msg);
/// let mut output = [0u8; 32];
/// hasher.finalize(&mut output);
/// output
/// }
///
/// // This compiles because Blake2b supports 32 byte keys
/// let key = [0; 32]; // this should actually be random
/// let msg = b"a test message";
/// let result = keyed_hash(&key, msg);
///
/// ```
;