@@ -29,14 +29,16 @@ use subtle::{Choice, ConstantTimeEq};
2929/// The `UniversalHash` trait defines a generic interface for universal hash
3030/// functions.
3131pub trait UniversalHash : Clone {
32- /// Size of a block (e.g. field element) this universal hash operates on
33- type BlockSize : ArrayLength < u8 > ;
32+ /// Size of the key for the universal hash function
33+ type KeySize : ArrayLength < u8 > ;
34+ /// Size of the output from the universal hash function
35+ type OutputSize : ArrayLength < u8 > ;
3436
3537 /// Instantiate a universal hash function with the given key
36- fn new ( key : & GenericArray < u8 , Self :: BlockSize > ) -> Self ;
38+ fn new ( key : & GenericArray < u8 , Self :: KeySize > ) -> Self ;
3739
3840 /// Input a block into the universal hash function
39- fn update_block ( & mut self , block : & GenericArray < u8 , Self :: BlockSize > ) ;
41+ fn update_block ( & mut self , block : & GenericArray < u8 , Self :: OutputSize > ) ;
4042
4143 /// Input data into the universal hash function. If the length of the
4244 /// data is not a multiple of the block size, the remaining data is
@@ -45,7 +47,7 @@ pub trait UniversalHash: Clone {
4547 /// This approach is frequently used by AEAD modes which use
4648 /// Message Authentication Codes (MACs) based on universal hashing.
4749 fn update_padded ( & mut self , data : & [ u8 ] ) {
48- let mut chunks = data. chunks_exact ( Self :: BlockSize :: to_usize ( ) ) ;
50+ let mut chunks = data. chunks_exact ( Self :: OutputSize :: to_usize ( ) ) ;
4951
5052 for chunk in & mut chunks {
5153 self . update_block ( GenericArray :: from_slice ( chunk) ) ;
@@ -64,11 +66,11 @@ pub trait UniversalHash: Clone {
6466 fn reset ( & mut self ) ;
6567
6668 /// Obtain the [`Output`] of a `UniversalHash` function and consume it.
67- fn result ( self ) -> Output < Self :: BlockSize > ;
69+ fn result ( self ) -> Output < Self :: OutputSize > ;
6870
6971 /// Obtain the [`Output`] of a `UniversalHash` computation and reset it back
7072 /// to its initial state.
71- fn result_reset ( & mut self ) -> Output < Self :: BlockSize > {
73+ fn result_reset ( & mut self ) -> Output < Self :: OutputSize > {
7274 let res = self . clone ( ) . result ( ) ;
7375 self . reset ( ) ;
7476 res
@@ -77,7 +79,7 @@ pub trait UniversalHash: Clone {
7779 /// Verify the `UniversalHash` of the processed input matches a given [`Output`].
7880 /// This is useful when constructing Message Authentication Codes (MACs)
7981 /// from universal hash functions.
80- fn verify ( self , other : & GenericArray < u8 , Self :: BlockSize > ) -> Result < ( ) , Error > {
82+ fn verify ( self , other : & GenericArray < u8 , Self :: OutputSize > ) -> Result < ( ) , Error > {
8183 if self . result ( ) == other. into ( ) {
8284 Ok ( ( ) )
8385 } else {
0 commit comments