1616#define GHASH_DIGEST_SIZE 16
1717
1818struct ghash_ctx {
19- u8 icv [16 ];
20- u8 key [16 ];
19+ u8 key [GHASH_BLOCK_SIZE ];
2120};
2221
2322struct ghash_desc_ctx {
23+ u8 icv [GHASH_BLOCK_SIZE ];
24+ u8 key [GHASH_BLOCK_SIZE ];
2425 u8 buffer [GHASH_BLOCK_SIZE ];
2526 u32 bytes ;
2627};
2728
2829static int ghash_init (struct shash_desc * desc )
2930{
3031 struct ghash_desc_ctx * dctx = shash_desc_ctx (desc );
32+ struct ghash_ctx * ctx = crypto_shash_ctx (desc -> tfm );
3133
3234 memset (dctx , 0 , sizeof (* dctx ));
35+ memcpy (dctx -> key , ctx -> key , GHASH_BLOCK_SIZE );
3336
3437 return 0 ;
3538}
@@ -45,7 +48,6 @@ static int ghash_setkey(struct crypto_shash *tfm,
4548 }
4649
4750 memcpy (ctx -> key , key , GHASH_BLOCK_SIZE );
48- memset (ctx -> icv , 0 , GHASH_BLOCK_SIZE );
4951
5052 return 0 ;
5153}
@@ -54,7 +56,6 @@ static int ghash_update(struct shash_desc *desc,
5456 const u8 * src , unsigned int srclen )
5557{
5658 struct ghash_desc_ctx * dctx = shash_desc_ctx (desc );
57- struct ghash_ctx * ctx = crypto_shash_ctx (desc -> tfm );
5859 unsigned int n ;
5960 u8 * buf = dctx -> buffer ;
6061 int ret ;
@@ -70,7 +71,7 @@ static int ghash_update(struct shash_desc *desc,
7071 src += n ;
7172
7273 if (!dctx -> bytes ) {
73- ret = crypt_s390_kimd (KIMD_GHASH , ctx , buf ,
74+ ret = crypt_s390_kimd (KIMD_GHASH , dctx , buf ,
7475 GHASH_BLOCK_SIZE );
7576 if (ret != GHASH_BLOCK_SIZE )
7677 return - EIO ;
@@ -79,7 +80,7 @@ static int ghash_update(struct shash_desc *desc,
7980
8081 n = srclen & ~(GHASH_BLOCK_SIZE - 1 );
8182 if (n ) {
82- ret = crypt_s390_kimd (KIMD_GHASH , ctx , src , n );
83+ ret = crypt_s390_kimd (KIMD_GHASH , dctx , src , n );
8384 if (ret != n )
8485 return - EIO ;
8586 src += n ;
@@ -94,7 +95,7 @@ static int ghash_update(struct shash_desc *desc,
9495 return 0 ;
9596}
9697
97- static int ghash_flush (struct ghash_ctx * ctx , struct ghash_desc_ctx * dctx )
98+ static int ghash_flush (struct ghash_desc_ctx * dctx )
9899{
99100 u8 * buf = dctx -> buffer ;
100101 int ret ;
@@ -104,24 +105,24 @@ static int ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx)
104105
105106 memset (pos , 0 , dctx -> bytes );
106107
107- ret = crypt_s390_kimd (KIMD_GHASH , ctx , buf , GHASH_BLOCK_SIZE );
108+ ret = crypt_s390_kimd (KIMD_GHASH , dctx , buf , GHASH_BLOCK_SIZE );
108109 if (ret != GHASH_BLOCK_SIZE )
109110 return - EIO ;
111+
112+ dctx -> bytes = 0 ;
110113 }
111114
112- dctx -> bytes = 0 ;
113115 return 0 ;
114116}
115117
116118static int ghash_final (struct shash_desc * desc , u8 * dst )
117119{
118120 struct ghash_desc_ctx * dctx = shash_desc_ctx (desc );
119- struct ghash_ctx * ctx = crypto_shash_ctx (desc -> tfm );
120121 int ret ;
121122
122- ret = ghash_flush (ctx , dctx );
123+ ret = ghash_flush (dctx );
123124 if (!ret )
124- memcpy (dst , ctx -> icv , GHASH_BLOCK_SIZE );
125+ memcpy (dst , dctx -> icv , GHASH_BLOCK_SIZE );
125126 return ret ;
126127}
127128
0 commit comments