@@ -29,14 +29,16 @@ use subtle::{Choice, ConstantTimeEq};
29
29
/// The `UniversalHash` trait defines a generic interface for universal hash
30
30
/// functions.
31
31
pub 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 > ;
34
36
35
37
/// 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 ;
37
39
38
40
/// 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 > ) ;
40
42
41
43
/// Input data into the universal hash function. If the length of the
42
44
/// data is not a multiple of the block size, the remaining data is
@@ -45,7 +47,7 @@ pub trait UniversalHash: Clone {
45
47
/// This approach is frequently used by AEAD modes which use
46
48
/// Message Authentication Codes (MACs) based on universal hashing.
47
49
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 ( ) ) ;
49
51
50
52
for chunk in & mut chunks {
51
53
self . update_block ( GenericArray :: from_slice ( chunk) ) ;
@@ -64,11 +66,11 @@ pub trait UniversalHash: Clone {
64
66
fn reset ( & mut self ) ;
65
67
66
68
/// Obtain the [`Output`] of a `UniversalHash` function and consume it.
67
- fn result ( self ) -> Output < Self :: BlockSize > ;
69
+ fn result ( self ) -> Output < Self :: OutputSize > ;
68
70
69
71
/// Obtain the [`Output`] of a `UniversalHash` computation and reset it back
70
72
/// to its initial state.
71
- fn result_reset ( & mut self ) -> Output < Self :: BlockSize > {
73
+ fn result_reset ( & mut self ) -> Output < Self :: OutputSize > {
72
74
let res = self . clone ( ) . result ( ) ;
73
75
self . reset ( ) ;
74
76
res
@@ -77,7 +79,7 @@ pub trait UniversalHash: Clone {
77
79
/// Verify the `UniversalHash` of the processed input matches a given [`Output`].
78
80
/// This is useful when constructing Message Authentication Codes (MACs)
79
81
/// 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 > {
81
83
if self . result ( ) == other. into ( ) {
82
84
Ok ( ( ) )
83
85
} else {
0 commit comments