3333pub use polyval:: universal_hash;
3434
3535use polyval:: Polyval ;
36- use universal_hash:: { consts:: U16 , NewUniversalHash , UniversalHash } ;
36+ use universal_hash:: {
37+ consts:: U16 ,
38+ crypto_common:: { BlockSizeUser , KeySizeUser , ParBlocksSizeUser } ,
39+ KeyInit , UhfBackend , UniversalHash ,
40+ } ;
3741
3842#[ cfg( feature = "zeroize" ) ]
3943use zeroize:: Zeroize ;
@@ -45,7 +49,7 @@ pub type Key = universal_hash::Key<GHash>;
4549pub type Block = universal_hash:: Block < GHash > ;
4650
4751/// GHASH tags (16-bytes)
48- pub type Tag = universal_hash:: Output < GHash > ;
52+ pub type Tag = universal_hash:: Block < GHash > ;
4953
5054/// **GHASH**: universal hash over GF(2^128) used by AES-GCM.
5155///
@@ -54,9 +58,11 @@ pub type Tag = universal_hash::Output<GHash>;
5458#[ derive( Clone ) ]
5559pub struct GHash ( Polyval ) ;
5660
57- impl NewUniversalHash for GHash {
61+ impl KeySizeUser for GHash {
5862 type KeySize = U16 ;
63+ }
5964
65+ impl KeyInit for GHash {
6066 /// Initialize GHASH with the given `H` field element
6167 #[ inline]
6268 fn new ( h : & Key ) -> Self {
@@ -79,29 +85,36 @@ impl NewUniversalHash for GHash {
7985 }
8086}
8187
82- impl UniversalHash for GHash {
88+ impl BlockSizeUser for GHash {
8389 type BlockSize = U16 ;
90+ }
8491
85- /// Input a field element `X` to be authenticated
86- #[ inline]
87- fn update ( & mut self , x : & Block ) {
92+ impl ParBlocksSizeUser for GHash {
93+ type ParBlocksSize = U16 ;
94+ }
95+
96+ impl UhfBackend for GHash {
97+ fn proc_block ( & mut self , x : & Block ) {
8898 let mut x = * x;
8999 x. reverse ( ) ;
90- self . 0 . update ( & x) ;
100+ self . 0 . proc_block ( & x) ;
91101 }
102+ }
92103
93- /// Reset internal state
94- #[ inline]
95- fn reset ( & mut self ) {
96- self . 0 . reset ( ) ;
104+ impl UniversalHash for GHash {
105+ fn update_with_backend (
106+ & mut self ,
107+ f : impl universal_hash:: UhfClosure < BlockSize = Self :: BlockSize > ,
108+ ) {
109+ f. call ( self ) ;
97110 }
98111
99112 /// Get GHASH output
100113 #[ inline]
101114 fn finalize ( self ) -> Tag {
102- let mut output = self . 0 . finalize ( ) . into_bytes ( ) ;
115+ let mut output = self . 0 . finalize ( ) ;
103116 output. reverse ( ) ;
104- Tag :: new ( output)
117+ output. into ( )
105118 }
106119}
107120
0 commit comments