Skip to contentSkip to conversation

crypto: Add crypto_spawn_shash

RFC In review Huang Ying 1 participant 1 message Jun 11, 2009 Crypto API

lore
Share & tools
lore

Huang Ying

author
#0 lore raw

RFC 3/7 crypto: Add crypto_spawn_shash

Needed to use shash in cryptd hash.

---
 crypto/shash.c          |    6 ++++++
 include/crypto/algapi.h |    8 ++++++++
 2 files changed, 14 insertions(+)
include/crypto/algapi.h +8 -0
@@ -240,6 +240,14 @@ static inline struct cipher_alg *crypto_
 	return &crypto_cipher_tfm(tfm)->__crt_alg->cra_cipher;
 }
 
+static inline struct crypto_shash *crypto_spawn_shash(struct crypto_spawn *spawn)
+{
+	u32 type = CRYPTO_ALG_TYPE_SHASH;
+	u32 mask = CRYPTO_ALG_TYPE_MASK;
+
+	return (struct crypto_shash *)(crypto_spawn_tfm(spawn, type, mask));
+}
+
 static inline struct crypto_hash *crypto_spawn_hash(struct crypto_spawn *spawn)
 {
 	u32 type = CRYPTO_ALG_TYPE_HASH;
crypto/shash.c +6 -0
@@ -408,6 +408,9 @@ static int crypto_init_shash_ops_compat(
 	return 0;
 }
 
+static int crypto_shash_init_tfm(struct crypto_tfm *tfm,
+				 const struct crypto_type *frontend);
+
 static int crypto_init_shash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
 {
 	switch (mask & CRYPTO_ALG_TYPE_MASK) {
@@ -415,6 +418,9 @@ static int crypto_init_shash_ops(struct 
 		return crypto_init_shash_ops_compat(tfm);
 	case CRYPTO_ALG_TYPE_AHASH_MASK:
 		return crypto_init_shash_ops_async(tfm);
+	case CRYPTO_ALG_TYPE_MASK:
+		if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_SHASH)
+			return crypto_shash_init_tfm(tfm, &crypto_shash_type);
 	}
 
 	return -EINVAL;