ANDROID: crypto: shash - Add crypto_grab_shash() and crypto_spawn_shash_alg()
authorEric Biggers <ebiggers@google.com>
Wed, 11 Jan 2017 00:47:49 +0000 (16:47 -0800)
committerAmit Pundir <amit.pundir@linaro.org>
Mon, 10 Apr 2017 07:42:16 +0000 (13:12 +0530)
Analogous to crypto_grab_skcipher() and crypto_spawn_skcipher_alg(),
these are useful for algorithms that need to use a shash sub-algorithm,
possibly in addition to other sub-algorithms.

Bug: 32975945
Signed-off-by: Eric Biggers <ebiggers@google.com>
Change-Id: I44e5a519d73f5f839e3b6ecbf8c66e36ec569557

crypto/shash.c
include/crypto/internal/hash.h

index 359754591653c7b265a5e6b89d70e9a9d16d33e3..9ae1e891308d9495d7027a73271424b29c71f0e1 100644 (file)
@@ -683,6 +683,14 @@ void shash_free_instance(struct crypto_instance *inst)
 }
 EXPORT_SYMBOL_GPL(shash_free_instance);
 
+int crypto_grab_shash(struct crypto_shash_spawn *spawn,
+                     const char *name, u32 type, u32 mask)
+{
+       spawn->base.frontend = &crypto_shash_type;
+       return crypto_grab_spawn(&spawn->base, name, type, mask);
+}
+EXPORT_SYMBOL_GPL(crypto_grab_shash);
+
 int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,
                            struct shash_alg *alg,
                            struct crypto_instance *inst)
index 3b4af1d7c7e91ce7482814955ed449b4e6954253..476d99d0edb7050879556c5f99b407ff674f62e8 100644 (file)
@@ -102,6 +102,8 @@ int shash_register_instance(struct crypto_template *tmpl,
                            struct shash_instance *inst);
 void shash_free_instance(struct crypto_instance *inst);
 
+int crypto_grab_shash(struct crypto_shash_spawn *spawn,
+                     const char *name, u32 type, u32 mask);
 int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,
                            struct shash_alg *alg,
                            struct crypto_instance *inst);
@@ -111,6 +113,12 @@ static inline void crypto_drop_shash(struct crypto_shash_spawn *spawn)
        crypto_drop_spawn(&spawn->base);
 }
 
+static inline struct shash_alg *crypto_spawn_shash_alg(
+       struct crypto_shash_spawn *spawn)
+{
+       return container_of(spawn->base.alg, struct shash_alg, base);
+}
+
 struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
 
 int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc);