88
99pub use polyval:: universal_hash;
1010
11- use polyval:: { DEFAULT_PARALLELISM , PolyvalGeneric } ;
11+ use polyval:: Polyval ;
1212use universal_hash:: {
1313 KeyInit , UhfBackend , UhfClosure , UniversalHash ,
14- array:: ArraySize ,
1514 common:: { BlockSizeUser , KeySizeUser , ParBlocksSizeUser } ,
1615 consts:: U16 ,
17- typenum:: { Const , ToUInt , U } ,
1816} ;
1917
2018#[ cfg( feature = "zeroize" ) ]
@@ -33,26 +31,17 @@ pub type Tag = universal_hash::Block<GHash>;
3331///
3432/// GHASH is a universal hash function used for message authentication in the AES-GCM authenticated
3533/// encryption cipher.
36- pub type GHash = GHashGeneric < { DEFAULT_PARALLELISM } > ;
37-
38- /// **GHASH**: universal hash over GF(2^128) used by AES-GCM.
39- ///
40- /// GHASH is a universal hash function used for message authentication in the AES-GCM authenticated
41- /// encryption cipher.
42- ///
43- /// Parameterized on a constant that determines how many blocks to process at once: higher numbers
44- /// use more memory, and require more time to re-key, but process data significantly faster.
4534#[ derive( Clone ) ]
46- pub struct GHashGeneric < const N : usize = { DEFAULT_PARALLELISM } > ( PolyvalGeneric < N > ) ;
35+ pub struct GHash ( Polyval ) ;
4736
48- impl < const N : usize > KeySizeUser for GHashGeneric < N > {
37+ impl KeySizeUser for GHash {
4938 type KeySize = U16 ;
5039}
5140
52- impl < const N : usize > GHashGeneric < N > {
53- /// Initialize GHASH with the given `H` field element and initial block
41+ impl GHash {
42+ /// Initialize GHASH with the given `H` field element as the key.
5443 #[ inline]
55- pub fn new_with_init_block ( h : & Key , init_block : u128 ) -> Self {
44+ pub fn new ( h : & Key ) -> Self {
5645 let mut h = * h;
5746 h. reverse ( ) ;
5847
@@ -63,7 +52,7 @@ impl<const N: usize> GHashGeneric<N> {
6352 h. zeroize ( ) ;
6453
6554 #[ allow( clippy:: let_and_return) ]
66- let result = GHashGeneric ( PolyvalGeneric :: new_with_init_block ( & h_polyval, init_block ) ) ;
55+ let result = Self ( Polyval :: new ( & h_polyval) ) ;
6756
6857 #[ cfg( feature = "zeroize" ) ]
6958 h_polyval. zeroize ( ) ;
@@ -72,55 +61,51 @@ impl<const N: usize> GHashGeneric<N> {
7261 }
7362}
7463
75- impl < const N : usize > KeyInit for GHashGeneric < N > {
64+ impl KeyInit for GHash {
7665 /// Initialize GHASH with the given `H` field element
7766 #[ inline]
7867 fn new ( h : & Key ) -> Self {
79- Self :: new_with_init_block ( h , 0 )
68+ Self :: new ( h )
8069 }
8170}
8271
83- struct GHashGenericBackend < ' b , B : UhfBackend > ( & ' b mut B ) ;
72+ struct GHashBackend < ' b , B : UhfBackend > ( & ' b mut B ) ;
8473
85- impl < B : UhfBackend > BlockSizeUser for GHashGenericBackend < ' _ , B > {
74+ impl < B : UhfBackend > BlockSizeUser for GHashBackend < ' _ , B > {
8675 type BlockSize = B :: BlockSize ;
8776}
8877
89- impl < B : UhfBackend > ParBlocksSizeUser for GHashGenericBackend < ' _ , B > {
78+ impl < B : UhfBackend > ParBlocksSizeUser for GHashBackend < ' _ , B > {
9079 type ParBlocksSize = B :: ParBlocksSize ;
9180}
9281
93- impl < B : UhfBackend > UhfBackend for GHashGenericBackend < ' _ , B > {
82+ impl < B : UhfBackend > UhfBackend for GHashBackend < ' _ , B > {
9483 fn proc_block ( & mut self , x : & universal_hash:: Block < B > ) {
9584 let mut x = x. clone ( ) ;
9685 x. reverse ( ) ;
9786 self . 0 . proc_block ( & x) ;
9887 }
9988}
10089
101- impl < const N : usize > BlockSizeUser for GHashGeneric < N > {
90+ impl BlockSizeUser for GHash {
10291 type BlockSize = U16 ;
10392}
10493
105- impl < const N : usize > UniversalHash for GHashGeneric < N >
106- where
107- U < N > : ArraySize ,
108- Const < N > : ToUInt ,
109- {
94+ impl UniversalHash for GHash {
11095 fn update_with_backend ( & mut self , f : impl UhfClosure < BlockSize = Self :: BlockSize > ) {
111- struct GHashGenericClosure < C : UhfClosure > ( C ) ;
96+ struct GhashClosure < C : UhfClosure > ( C ) ;
11297
113- impl < C : UhfClosure > BlockSizeUser for GHashGenericClosure < C > {
98+ impl < C : UhfClosure > BlockSizeUser for GhashClosure < C > {
11499 type BlockSize = C :: BlockSize ;
115100 }
116101
117- impl < C : UhfClosure > UhfClosure for GHashGenericClosure < C > {
102+ impl < C : UhfClosure > UhfClosure for GhashClosure < C > {
118103 fn call < B : UhfBackend < BlockSize = Self :: BlockSize > > ( self , backend : & mut B ) {
119- self . 0 . call ( & mut GHashGenericBackend ( backend) ) ;
104+ self . 0 . call ( & mut GHashBackend ( backend) ) ;
120105 }
121106 }
122107
123- self . 0 . update_with_backend ( GHashGenericClosure ( f) ) ;
108+ self . 0 . update_with_backend ( GhashClosure ( f) ) ;
124109 }
125110
126111 /// Get GHASH output
@@ -132,8 +117,8 @@ where
132117 }
133118}
134119
135- impl < const N : usize > core:: fmt:: Debug for GHashGeneric < N > {
120+ impl core:: fmt:: Debug for GHash {
136121 fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
137- write ! ( f , "GHashGeneric<{}> {{ ... }}" , N )
122+ f . debug_tuple ( "GHash" ) . finish_non_exhaustive ( )
138123 }
139124}
0 commit comments