Skip to content

Commit a70c522

Browse files
committed
crypto: ahash - Fix setkey crash
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 <herbert@gondor.apana.org.au>
1 parent faae890 commit a70c522

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎crypto/ahash.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ int crypto_hash_walk_first_compat(struct hash_desc *hdesc,
145145
static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
146146
unsigned int keylen)
147147
{
148-
struct ahash_alg *ahash = crypto_ahash_alg(tfm);
149148
unsigned long alignmask = crypto_ahash_alignmask(tfm);
150149
int ret;
151150
u8 *buffer, *alignbuffer;
@@ -158,21 +157,20 @@ static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
158157

159158
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
160159
memcpy(alignbuffer, key, keylen);
161-
ret = ahash->setkey(tfm, alignbuffer, keylen);
160+
ret = tfm->setkey(tfm, alignbuffer, keylen);
162161
kzfree(buffer);
163162
return ret;
164163
}
165164

166165
int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
167166
unsigned int keylen)
168167
{
169-
struct ahash_alg *ahash = crypto_ahash_alg(tfm);
170168
unsigned long alignmask = crypto_ahash_alignmask(tfm);
171169

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

175-
return ahash->setkey(tfm, key, keylen);
173+
return tfm->setkey(tfm, key, keylen);
176174
}
177175
EXPORT_SYMBOL_GPL(crypto_ahash_setkey);
178176

0 commit comments

Comments
 (0)