Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: hmac - Zero shash desc in setkey

The shash desc needs to be zeroed after use in setkey as it is
not finalised (finalisation automatically zeroes it).

Also remove the final function as it's been superseded by finup.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+10 -25
+10 -25
crypto/hmac.c
··· 13 13 14 14 #include <crypto/hmac.h> 15 15 #include <crypto/internal/hash.h> 16 - #include <crypto/scatterwalk.h> 17 16 #include <linux/err.h> 18 17 #include <linux/fips.h> 19 - #include <linux/init.h> 20 18 #include <linux/kernel.h> 21 19 #include <linux/module.h> 22 - #include <linux/scatterlist.h> 20 + #include <linux/slab.h> 23 21 #include <linux/string.h> 24 22 25 23 struct hmac_ctx { ··· 37 39 u8 *ipad = &tctx->pads[0]; 38 40 u8 *opad = &tctx->pads[ss]; 39 41 SHASH_DESC_ON_STACK(shash, hash); 40 - unsigned int i; 42 + int err, i; 41 43 42 44 if (fips_enabled && (keylen < 112 / 8)) 43 45 return -EINVAL; ··· 63 65 opad[i] ^= HMAC_OPAD_VALUE; 64 66 } 65 67 66 - return 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); 68 + err = 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); 74 + shash_desc_zero(shash); 75 + return err; 72 76 } 73 77 74 78 static int hmac_export(struct shash_desc *pdesc, void *out) ··· 103 103 struct shash_desc *desc = shash_desc_ctx(pdesc); 104 104 105 105 return crypto_shash_update(desc, data, nbytes); 106 - } 107 - 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 106 } 121 107 122 108 static int hmac_finup(struct shash_desc *pdesc, const u8 *data, ··· 208 222 inst->alg.descsize = sizeof(struct shash_desc) + salg->descsize; 209 223 inst->alg.init = hmac_init; 210 224 inst->alg.update = hmac_update; 211 - inst->alg.final = hmac_final; 212 225 inst->alg.finup = hmac_finup; 213 226 inst->alg.export = hmac_export; 214 227 inst->alg.import = hmac_import;