X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=crypto%2Fhmac.c;h=14c6351e639d9484aa093fac191c7919a99127b4;hb=516c8be3a93ec2b0746ba0907f38c1d1e62f4992;hp=b60c3c7aa320ba08548c050f4fc05d231321de61;hpb=5b39dba5029108800b94a5f4f96e3a05417103ac;p=linux-2.6 diff --git a/crypto/hmac.c b/crypto/hmac.c index b60c3c7aa3..14c6351e63 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -57,14 +57,35 @@ static int hmac_setkey(struct crypto_hash *parent, if (keylen > bs) { struct hash_desc desc; struct scatterlist tmp; + int tmplen; int err; desc.tfm = tfm; desc.flags = crypto_hash_get_flags(parent); desc.flags &= CRYPTO_TFM_REQ_MAY_SLEEP; - sg_init_one(&tmp, inkey, keylen); - err = crypto_hash_digest(&desc, &tmp, keylen, digest); + err = crypto_hash_init(&desc); + if (err) + return err; + + tmplen = bs * 2 + ds; + sg_init_one(&tmp, ipad, tmplen); + + for (; keylen > tmplen; inkey += tmplen, keylen -= tmplen) { + memcpy(ipad, inkey, tmplen); + err = crypto_hash_update(&desc, &tmp, tmplen); + if (err) + return err; + } + + if (keylen) { + memcpy(ipad, inkey, keylen); + err = crypto_hash_update(&desc, &tmp, keylen); + if (err) + return err; + } + + err = crypto_hash_final(&desc, digest); if (err) return err;