diff options
Diffstat (limited to 'crypto/hmac.c')
-rw-r--r-- | crypto/hmac.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/crypto/hmac.c b/crypto/hmac.c index 14c6351e639d..7ff2d6a8c7d0 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c | |||
@@ -226,6 +226,7 @@ static struct crypto_instance *hmac_alloc(struct rtattr **tb) | |||
226 | struct crypto_instance *inst; | 226 | struct crypto_instance *inst; |
227 | struct crypto_alg *alg; | 227 | struct crypto_alg *alg; |
228 | int err; | 228 | int err; |
229 | int ds; | ||
229 | 230 | ||
230 | err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_HASH); | 231 | err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_HASH); |
231 | if (err) | 232 | if (err) |
@@ -236,6 +237,13 @@ static struct crypto_instance *hmac_alloc(struct rtattr **tb) | |||
236 | if (IS_ERR(alg)) | 237 | if (IS_ERR(alg)) |
237 | return ERR_CAST(alg); | 238 | return ERR_CAST(alg); |
238 | 239 | ||
240 | inst = ERR_PTR(-EINVAL); | ||
241 | ds = (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == | ||
242 | CRYPTO_ALG_TYPE_HASH ? alg->cra_hash.digestsize : | ||
243 | alg->cra_digest.dia_digestsize; | ||
244 | if (ds > alg->cra_blocksize) | ||
245 | goto out_put_alg; | ||
246 | |||
239 | inst = crypto_alloc_instance("hmac", alg); | 247 | inst = crypto_alloc_instance("hmac", alg); |
240 | if (IS_ERR(inst)) | 248 | if (IS_ERR(inst)) |
241 | goto out_put_alg; | 249 | goto out_put_alg; |
@@ -246,14 +254,10 @@ static struct crypto_instance *hmac_alloc(struct rtattr **tb) | |||
246 | inst->alg.cra_alignmask = alg->cra_alignmask; | 254 | inst->alg.cra_alignmask = alg->cra_alignmask; |
247 | inst->alg.cra_type = &crypto_hash_type; | 255 | inst->alg.cra_type = &crypto_hash_type; |
248 | 256 | ||
249 | inst->alg.cra_hash.digestsize = | 257 | inst->alg.cra_hash.digestsize = ds; |
250 | (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == | ||
251 | CRYPTO_ALG_TYPE_HASH ? alg->cra_hash.digestsize : | ||
252 | alg->cra_digest.dia_digestsize; | ||
253 | 258 | ||
254 | inst->alg.cra_ctxsize = sizeof(struct hmac_ctx) + | 259 | inst->alg.cra_ctxsize = sizeof(struct hmac_ctx) + |
255 | ALIGN(inst->alg.cra_blocksize * 2 + | 260 | ALIGN(inst->alg.cra_blocksize * 2 + ds, |
256 | inst->alg.cra_hash.digestsize, | ||
257 | sizeof(void *)); | 261 | sizeof(void *)); |
258 | 262 | ||
259 | inst->alg.cra_init = hmac_init_tfm; | 263 | inst->alg.cra_init = hmac_init_tfm; |