Skip to content

Commit

Permalink
crypto: ahash - Fix setkey crash
Browse files Browse the repository at this point in the history
When the alignment check was made unconditional for ahash we
may end up crashing on shash algorithms because we're always
calling alg->setkey instead of tfm->setkey.

This patch fixes it.

Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
herbertx committed Jul 15, 2009
1 parent faae890 commit a70c522
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions crypto/ahash.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ int crypto_hash_walk_first_compat(struct hash_desc *hdesc,
static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
unsigned int keylen)
{
struct ahash_alg *ahash = crypto_ahash_alg(tfm);
unsigned long alignmask = crypto_ahash_alignmask(tfm);
int ret;
u8 *buffer, *alignbuffer;
Expand All @@ -158,21 +157,20 @@ static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,

alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
memcpy(alignbuffer, key, keylen);
ret = ahash->setkey(tfm, alignbuffer, keylen);
ret = tfm->setkey(tfm, alignbuffer, keylen);
kzfree(buffer);
return ret;
}

int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
unsigned int keylen)
{
struct ahash_alg *ahash = crypto_ahash_alg(tfm);
unsigned long alignmask = crypto_ahash_alignmask(tfm);

if ((unsigned long)key & alignmask)
return ahash_setkey_unaligned(tfm, key, keylen);

return ahash->setkey(tfm, key, keylen);
return tfm->setkey(tfm, key, keylen);
}
EXPORT_SYMBOL_GPL(crypto_ahash_setkey);

Expand Down

0 comments on commit a70c522

Please sign in to comment.