Skip to content

Commit 619a6eb

Browse files
committed
crypto: shash - Add shash_register_instance
This patch adds shash_register_instance so that shash instances can be registered without bypassing the shash checks applied to normal algorithms. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7d6f564 commit 619a6eb

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎crypto/shash.c‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type,
480480
}
481481
EXPORT_SYMBOL_GPL(crypto_alloc_shash);
482482

483-
int crypto_register_shash(struct shash_alg *alg)
483+
static int shash_prepare_alg(struct shash_alg *alg)
484484
{
485485
struct crypto_alg *base = &alg->base;
486486

@@ -491,6 +491,17 @@ int crypto_register_shash(struct shash_alg *alg)
491491
base->cra_type = &crypto_shash_type;
492492
base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
493493
base->cra_flags |= CRYPTO_ALG_TYPE_SHASH;
494+
return 0;
495+
}
496+
497+
int crypto_register_shash(struct shash_alg *alg)
498+
{
499+
struct crypto_alg *base = &alg->base;
500+
int err;
501+
502+
err = shash_prepare_alg(alg);
503+
if (err)
504+
return err;
494505

495506
return crypto_register_alg(base);
496507
}
@@ -502,6 +513,19 @@ int crypto_unregister_shash(struct shash_alg *alg)
502513
}
503514
EXPORT_SYMBOL_GPL(crypto_unregister_shash);
504515

516+
int shash_register_instance(struct crypto_template *tmpl,
517+
struct shash_instance *inst)
518+
{
519+
int err;
520+
521+
err = shash_prepare_alg(&inst->alg);
522+
if (err)
523+
return err;
524+
525+
return crypto_register_instance(tmpl, shash_crypto_instance(inst));
526+
}
527+
EXPORT_SYMBOL_GPL(shash_register_instance);
528+
505529
void shash_free_instance(struct crypto_instance *inst)
506530
{
507531
crypto_drop_spawn(crypto_instance_ctx(inst));

‎include/crypto/internal/hash.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ int crypto_hash_walk_first_compat(struct hash_desc *hdesc,
5353

5454
int crypto_register_shash(struct shash_alg *alg);
5555
int crypto_unregister_shash(struct shash_alg *alg);
56-
56+
int shash_register_instance(struct crypto_template *tmpl,
57+
struct shash_instance *inst);
5758
void shash_free_instance(struct crypto_instance *inst);
5859

5960
int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,

0 commit comments

Comments
 (0)