crypto: hash - add support for new way of freeing instances
authorEric Biggers <ebiggers@google.com>
Fri, 3 Jan 2020 04:04:35 +0000 (20:04 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 9 Jan 2020 03:30:57 +0000 (11:30 +0800)
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>
crypto/ahash.c
crypto/shash.c
include/crypto/internal/hash.h

index c77717fcea8ed25e4bced3364201cb833edba5da..61e374d76b044ea2f580630613eac5bd692ec83a 100644 (file)
@@ -511,6 +511,18 @@ static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
        return crypto_alg_extsize(alg);
 }
 
+static void crypto_ahash_free_instance(struct crypto_instance *inst)
+{
+       struct ahash_instance *ahash = ahash_instance(inst);
+
+       if (!ahash->free) {
+               inst->tmpl->free(inst);
+               return;
+       }
+
+       ahash->free(ahash);
+}
+
 #ifdef CONFIG_NET
 static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
 {
@@ -547,6 +559,7 @@ static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
 static const struct crypto_type crypto_ahash_type = {
        .extsize = crypto_ahash_extsize,
        .init_tfm = crypto_ahash_init_tfm,
+       .free = crypto_ahash_free_instance,
 #ifdef CONFIG_PROC_FS
        .show = crypto_ahash_show,
 #endif
index 4d6ccb59e126b92c7752c06f47b2b15286ff868a..2f6adb49727bc1ca1385f4952aa850533f81d019 100644 (file)
@@ -423,6 +423,18 @@ static int crypto_shash_init_tfm(struct crypto_tfm *tfm)
        return 0;
 }
 
+static void crypto_shash_free_instance(struct crypto_instance *inst)
+{
+       struct shash_instance *shash = shash_instance(inst);
+
+       if (!shash->free) {
+               inst->tmpl->free(inst);
+               return;
+       }
+
+       shash->free(shash);
+}
+
 #ifdef CONFIG_NET
 static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
 {
@@ -459,6 +471,7 @@ static void crypto_shash_show(struct seq_file *m, struct crypto_alg *alg)
 static const struct crypto_type crypto_shash_type = {
        .extsize = crypto_alg_extsize,
        .init_tfm = crypto_shash_init_tfm,
+       .free = crypto_shash_free_instance,
 #ifdef CONFIG_PROC_FS
        .show = crypto_shash_show,
 #endif
index c84b7cb29887bc8cb315c49c03ed188d241d4a77..c550386221bb3f55a9a8b02f2ca381bda24ed3ed 100644 (file)
@@ -30,6 +30,7 @@ struct crypto_hash_walk {
 };
 
 struct ahash_instance {
+       void (*free)(struct ahash_instance *inst);
        union {
                struct {
                        char head[offsetof(struct ahash_alg, halg.base)];
@@ -40,6 +41,7 @@ struct ahash_instance {
 };
 
 struct shash_instance {
+       void (*free)(struct shash_instance *inst);
        union {
                struct {
                        char head[offsetof(struct shash_alg, base)];