1313
1414#include <crypto/hmac.h>
1515#include <crypto/internal/hash.h>
16- #include <crypto/scatterwalk.h>
1716#include <linux/err.h>
1817#include <linux/fips.h>
19- #include <linux/init.h>
2018#include <linux/kernel.h>
2119#include <linux/module.h>
22- #include <linux/scatterlist .h>
20+ #include <linux/slab .h>
2321#include <linux/string.h>
2422
2523struct hmac_ctx {
@@ -39,7 +37,7 @@ static int hmac_setkey(struct crypto_shash *parent,
3937 u8 * ipad = & tctx -> pads [0 ];
4038 u8 * opad = & tctx -> pads [ss ];
4139 SHASH_DESC_ON_STACK (shash , hash );
42- unsigned int i ;
40+ int err , i ;
4341
4442 if (fips_enabled && (keylen < 112 / 8 ))
4543 return - EINVAL ;
@@ -65,12 +63,14 @@ static int hmac_setkey(struct crypto_shash *parent,
6563 opad [i ] ^= HMAC_OPAD_VALUE ;
6664 }
6765
68- return crypto_shash_init (shash ) ?:
69- crypto_shash_update (shash , ipad , bs ) ?:
70- crypto_shash_export (shash , ipad ) ?:
71- crypto_shash_init (shash ) ?:
72- crypto_shash_update (shash , opad , bs ) ?:
73- crypto_shash_export (shash , opad );
66+ err = crypto_shash_init (shash ) ?:
67+ crypto_shash_update (shash , ipad , bs ) ?:
68+ crypto_shash_export (shash , ipad ) ?:
69+ crypto_shash_init (shash ) ?:
70+ crypto_shash_update (shash , opad , bs ) ?:
71+ crypto_shash_export (shash , opad );
72+ shash_desc_zero (shash );
73+ return err ;
7474}
7575
7676static int hmac_export (struct shash_desc * pdesc , void * out )
@@ -105,20 +105,6 @@ static int hmac_update(struct shash_desc *pdesc,
105105 return crypto_shash_update (desc , data , nbytes );
106106}
107107
108- static int hmac_final (struct shash_desc * pdesc , u8 * out )
109- {
110- struct crypto_shash * parent = pdesc -> tfm ;
111- int ds = crypto_shash_digestsize (parent );
112- int ss = crypto_shash_statesize (parent );
113- const struct hmac_ctx * tctx = crypto_shash_ctx (parent );
114- const u8 * opad = & tctx -> pads [ss ];
115- struct shash_desc * desc = shash_desc_ctx (pdesc );
116-
117- return crypto_shash_final (desc , out ) ?:
118- crypto_shash_import (desc , opad ) ?:
119- crypto_shash_finup (desc , out , ds , out );
120- }
121-
122108static int hmac_finup (struct shash_desc * pdesc , const u8 * data ,
123109 unsigned int nbytes , u8 * out )
124110{
@@ -222,7 +208,6 @@ static int hmac_create(struct crypto_template *tmpl, struct rtattr **tb)
222208 inst -> alg .descsize = sizeof (struct shash_desc ) + salg -> descsize ;
223209 inst -> alg .init = hmac_init ;
224210 inst -> alg .update = hmac_update ;
225- inst -> alg .final = hmac_final ;
226211 inst -> alg .finup = hmac_finup ;
227212 inst -> alg .export = hmac_export ;
228213 inst -> alg .import = hmac_import ;
0 commit comments