Skip to content

Commit a5596d6

Browse files
committed
crypto: hash - Add crypto_ahash_has_setkey
This patch adds a way for ahash users to determine whether a key is required by a crypto_ahash transform. Cc: [email protected] Signed-off-by: Herbert Xu <[email protected]>
1 parent a0fa2d0 commit a5596d6

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

crypto/ahash.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
451451
struct ahash_alg *alg = crypto_ahash_alg(hash);
452452

453453
hash->setkey = ahash_nosetkey;
454+
hash->has_setkey = false;
454455
hash->export = ahash_no_export;
455456
hash->import = ahash_no_import;
456457

@@ -463,8 +464,10 @@ static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
463464
hash->finup = alg->finup ?: ahash_def_finup;
464465
hash->digest = alg->digest;
465466

466-
if (alg->setkey)
467+
if (alg->setkey) {
467468
hash->setkey = alg->setkey;
469+
hash->has_setkey = true;
470+
}
468471
if (alg->export)
469472
hash->export = alg->export;
470473
if (alg->import)

crypto/shash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,10 @@ int crypto_init_shash_ops_async(struct crypto_tfm *tfm)
355355
crt->finup = shash_async_finup;
356356
crt->digest = shash_async_digest;
357357

358-
if (alg->setkey)
358+
if (alg->setkey) {
359359
crt->setkey = shash_async_setkey;
360+
crt->has_setkey = true;
361+
}
360362
if (alg->export)
361363
crt->export = shash_async_export;
362364
if (alg->import)

include/crypto/hash.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct crypto_ahash {
204204
unsigned int keylen);
205205

206206
unsigned int reqsize;
207+
bool has_setkey;
207208
struct crypto_tfm base;
208209
};
209210

@@ -375,6 +376,11 @@ static inline void *ahash_request_ctx(struct ahash_request *req)
375376
int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
376377
unsigned int keylen);
377378

379+
static inline bool crypto_ahash_has_setkey(struct crypto_ahash *tfm)
380+
{
381+
return tfm->has_setkey;
382+
}
383+
378384
/**
379385
* crypto_ahash_finup() - update and finalize message digest
380386
* @req: reference to the ahash_request handle that holds all information

0 commit comments

Comments
 (0)