@@ -29,11 +29,19 @@ pub use polyval::universal_hash;
2929
3030use core:: convert:: TryInto ;
3131use polyval:: Polyval ;
32- use universal_hash:: generic_array:: { typenum:: U16 , GenericArray } ;
33- use universal_hash:: { Output , UniversalHash } ;
32+ use universal_hash:: { consts:: U16 , NewUniversalHash , UniversalHash } ;
3433#[ cfg( feature = "zeroize" ) ]
3534use zeroize:: Zeroize ;
3635
36+ /// GHASH keys (16-bytes)
37+ pub type Key = universal_hash:: Key < GHash > ;
38+
39+ /// GHASH blocks (16-bytes)
40+ pub type Block = universal_hash:: Block < GHash > ;
41+
42+ /// GHASH tags (16-bytes)
43+ pub type Tag = universal_hash:: Output < GHash > ;
44+
3745/// **GHASH**: universal hash over GF(2^128) used by AES-GCM.
3846///
3947/// GHASH is a universal hash function used for message authentication in
@@ -42,12 +50,11 @@ use zeroize::Zeroize;
4250#[ repr( align( 16 ) ) ]
4351pub struct GHash ( Polyval ) ;
4452
45- impl UniversalHash for GHash {
53+ impl NewUniversalHash for GHash {
4654 type KeySize = U16 ;
47- type BlockSize = U16 ;
4855
4956 /// Initialize GHASH with the given `H` field element
50- fn new ( h : & GenericArray < u8 , U16 > ) -> Self {
57+ fn new ( h : & Key ) -> Self {
5158 let mut h = * h;
5259 h. reverse ( ) ;
5360
@@ -65,12 +72,16 @@ impl UniversalHash for GHash {
6572
6673 result
6774 }
75+ }
76+
77+ impl UniversalHash for GHash {
78+ type BlockSize = U16 ;
6879
6980 /// Input a field element `X` to be authenticated
70- fn update_block ( & mut self , x : & GenericArray < u8 , U16 > ) {
81+ fn update ( & mut self , x : & Block ) {
7182 let mut x = * x;
7283 x. reverse ( ) ;
73- self . 0 . update_block ( & x) ;
84+ self . 0 . update ( & x) ;
7485 }
7586
7687 /// Reset internal state
@@ -79,10 +90,10 @@ impl UniversalHash for GHash {
7990 }
8091
8192 /// Get GHASH output
82- fn result ( self ) -> Output < U16 > {
93+ fn result ( self ) -> Tag {
8394 let mut output = self . 0 . result ( ) . into_bytes ( ) ;
8495 output. reverse ( ) ;
85- Output :: new ( output)
96+ Tag :: new ( output)
8697 }
8798}
8899
@@ -92,7 +103,7 @@ impl UniversalHash for GHash {
92103///
93104/// [1]: https://tools.ietf.org/html/rfc8452#appendix-A
94105#[ allow( non_snake_case) ]
95- fn mulX_POLYVAL ( block : & GenericArray < u8 , U16 > ) -> GenericArray < u8 , U16 > {
106+ fn mulX_POLYVAL ( block : & Block ) -> Block {
96107 let mut v0 = u64:: from_le_bytes ( block[ ..8 ] . try_into ( ) . unwrap ( ) ) ;
97108 let mut v1 = u64:: from_le_bytes ( block[ 8 ..] . try_into ( ) . unwrap ( ) ) ;
98109
0 commit comments