Skip to content

Commit cd6ed77

Browse files
ebiggersherbertx
authored andcommitted
crypto: hash - introduce crypto_hash_alg_has_setkey()
Templates that use an shash spawn can use crypto_shash_alg_has_setkey() to determine whether the underlying algorithm requires a key or not. But there was no corresponding function for ahash spawns. Add it. Note that the new function actually has to support both shash and ahash algorithms, since the ahash API can be used with either. Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent c6ba4f3 commit cd6ed77

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎crypto/ahash.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,5 +649,16 @@ struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask)
649649
}
650650
EXPORT_SYMBOL_GPL(ahash_attr_alg);
651651

652+
bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg)
653+
{
654+
struct crypto_alg *alg = &halg->base;
655+
656+
if (alg->cra_type != &crypto_ahash_type)
657+
return crypto_shash_alg_has_setkey(__crypto_shash_alg(alg));
658+
659+
return __crypto_ahash_alg(alg)->setkey != NULL;
660+
}
661+
EXPORT_SYMBOL_GPL(crypto_hash_alg_has_setkey);
662+
652663
MODULE_LICENSE("GPL");
653664
MODULE_DESCRIPTION("Asynchronous cryptographic hash type");

‎include/crypto/internal/hash.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ static inline bool crypto_shash_alg_has_setkey(struct shash_alg *alg)
9090
return alg->setkey != shash_no_setkey;
9191
}
9292

93+
bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg);
94+
9395
int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,
9496
struct hash_alg_common *alg,
9597
struct crypto_instance *inst);

0 commit comments

Comments
 (0)