Skip to content

Commit 48fb3e5

Browse files
ebiggersherbertx
authored andcommitted
crypto: hash - add support for new way of freeing instances
Add support to shash and ahash for the new way of freeing instances (already used for skcipher, aead, and akcipher) where a ->free() method is installed to the instance struct itself. These methods are more strongly-typed than crypto_template::free(), which they replace. This will allow removing support for the old way of freeing instances. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent aed11cf commit 48fb3e5

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎crypto/ahash.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,18 @@ static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
511511
return crypto_alg_extsize(alg);
512512
}
513513

514+
static void crypto_ahash_free_instance(struct crypto_instance *inst)
515+
{
516+
struct ahash_instance *ahash = ahash_instance(inst);
517+
518+
if (!ahash->free) {
519+
inst->tmpl->free(inst);
520+
return;
521+
}
522+
523+
ahash->free(ahash);
524+
}
525+
514526
#ifdef CONFIG_NET
515527
static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
516528
{
@@ -547,6 +559,7 @@ static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
547559
static const struct crypto_type crypto_ahash_type = {
548560
.extsize = crypto_ahash_extsize,
549561
.init_tfm = crypto_ahash_init_tfm,
562+
.free = crypto_ahash_free_instance,
550563
#ifdef CONFIG_PROC_FS
551564
.show = crypto_ahash_show,
552565
#endif

‎crypto/shash.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,18 @@ static int crypto_shash_init_tfm(struct crypto_tfm *tfm)
423423
return 0;
424424
}
425425

426+
static void crypto_shash_free_instance(struct crypto_instance *inst)
427+
{
428+
struct shash_instance *shash = shash_instance(inst);
429+
430+
if (!shash->free) {
431+
inst->tmpl->free(inst);
432+
return;
433+
}
434+
435+
shash->free(shash);
436+
}
437+
426438
#ifdef CONFIG_NET
427439
static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
428440
{
@@ -459,6 +471,7 @@ static void crypto_shash_show(struct seq_file *m, struct crypto_alg *alg)
459471
static const struct crypto_type crypto_shash_type = {
460472
.extsize = crypto_alg_extsize,
461473
.init_tfm = crypto_shash_init_tfm,
474+
.free = crypto_shash_free_instance,
462475
#ifdef CONFIG_PROC_FS
463476
.show = crypto_shash_show,
464477
#endif

‎include/crypto/internal/hash.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct crypto_hash_walk {
3030
};
3131

3232
struct ahash_instance {
33+
void (*free)(struct ahash_instance *inst);
3334
union {
3435
struct {
3536
char head[offsetof(struct ahash_alg, halg.base)];
@@ -40,6 +41,7 @@ struct ahash_instance {
4041
};
4142

4243
struct shash_instance {
44+
void (*free)(struct shash_instance *inst);
4345
union {
4446
struct {
4547
char head[offsetof(struct shash_alg, base)];

0 commit comments

Comments
 (0)