Skip to content

Commit 7ac9ff4

Browse files
authored
Merge pull request #135 from RustCrypto/new-universal-hash
universal-hash: split out NewUniversalHash trait
2 parents ccff663 + c21d68c commit 7ac9ff4

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

universal-hash/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,26 @@ use generic_array::{ArrayLength, GenericArray};
3030
use subtle::{Choice, ConstantTimeEq};
3131

3232
/// Keys to a [`UniversalHash`].
33-
pub type Key<U> = GenericArray<u8, <U as UniversalHash>::KeySize>;
33+
pub type Key<U> = GenericArray<u8, <U as NewUniversalHash>::KeySize>;
3434

3535
/// Blocks are inputs to a [`UniversalHash`].
3636
pub type Block<U> = GenericArray<u8, <U as UniversalHash>::BlockSize>;
3737

38-
/// The `UniversalHash` trait defines a generic interface for universal hash
39-
/// functions.
40-
pub trait UniversalHash: Clone {
41-
/// Size of the key for the universal hash function
38+
/// Instantiate a [`UniversalHash`] algorithm.
39+
pub trait NewUniversalHash: Sized {
40+
/// Size of the key for the universal hash function.
4241
type KeySize: ArrayLength<u8>;
4342

43+
/// Instantiate a universal hash function with the given key.
44+
fn new(key: &Key<Self>) -> Self;
45+
}
46+
47+
/// The [`UniversalHash`] trait defines a generic interface for universal hash
48+
/// functions.
49+
pub trait UniversalHash: Clone {
4450
/// Size of the inputs to and outputs from the universal hash function
4551
type BlockSize: ArrayLength<u8>;
4652

47-
/// Instantiate a universal hash function with the given key
48-
fn new(key: &Key<Self>) -> Self;
49-
5053
/// Input a block into the universal hash function
5154
fn update(&mut self, block: &Block<Self>);
5255

0 commit comments

Comments
 (0)