crypto: api - Add crypto_attr_alg2 helper
authorHerbert Xu <herbert@gondor.apana.org.au>
Wed, 8 Jul 2009 09:53:16 +0000 (17:53 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 8 Jul 2009 10:58:29 +0000 (18:58 +0800)
This patch adds the helper crypto_attr_alg2 which is similar to
crypto_attr_alg but takes an extra frontend argument.  This is
intended to be used by new style algorithm types such as shash.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/algapi.c
crypto/api.c
crypto/internal.h
include/crypto/algapi.h

index 17a5fff8f7773e1749c80f8553f2c1e4dbe6e45f..2154815201a724f473d67c18d7ade8bd2cbdc5e3 100644 (file)
@@ -644,7 +644,9 @@ const char *crypto_attr_alg_name(struct rtattr *rta)
 }
 EXPORT_SYMBOL_GPL(crypto_attr_alg_name);
 
-struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask)
+struct crypto_alg *crypto_attr_alg2(struct rtattr *rta,
+                                   const struct crypto_type *frontend,
+                                   u32 type, u32 mask)
 {
        const char *name;
        int err;
@@ -654,9 +656,9 @@ struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask)
        if (IS_ERR(name))
                return ERR_PTR(err);
 
-       return crypto_alg_mod_lookup(name, type, mask);
+       return crypto_find_alg(name, frontend, type, mask);
 }
-EXPORT_SYMBOL_GPL(crypto_attr_alg);
+EXPORT_SYMBOL_GPL(crypto_attr_alg2);
 
 int crypto_attr_u32(struct rtattr *rta, u32 *num)
 {
index d5944f92b4162845e305c9dc6f2df85576808240..ba81221b3bef77ec1d64805aebf47f7c53bbc4a2 100644 (file)
@@ -503,6 +503,27 @@ out:
 }
 EXPORT_SYMBOL_GPL(crypto_create_tfm);
 
+struct crypto_alg *crypto_find_alg(const char *alg_name,
+                                  const struct crypto_type *frontend,
+                                  u32 type, u32 mask)
+{
+       struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask) =
+               crypto_alg_mod_lookup;
+
+       if (frontend) {
+               type &= frontend->maskclear;
+               mask &= frontend->maskclear;
+               type |= frontend->type;
+               mask |= frontend->maskset;
+
+               if (frontend->lookup)
+                       lookup = frontend->lookup;
+       }
+
+       return lookup(alg_name, type, mask);
+}
+EXPORT_SYMBOL_GPL(crypto_find_alg);
+
 /*
  *     crypto_alloc_tfm - Locate algorithm and allocate transform
  *     @alg_name: Name of algorithm
@@ -526,21 +547,13 @@ EXPORT_SYMBOL_GPL(crypto_create_tfm);
 void *crypto_alloc_tfm(const char *alg_name,
                       const struct crypto_type *frontend, u32 type, u32 mask)
 {
-       struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask);
        void *tfm;
        int err;
 
-       type &= frontend->maskclear;
-       mask &= frontend->maskclear;
-       type |= frontend->type;
-       mask |= frontend->maskset;
-
-       lookup = frontend->lookup ?: crypto_alg_mod_lookup;
-
        for (;;) {
                struct crypto_alg *alg;
 
-               alg = lookup(alg_name, type, mask);
+               alg = crypto_find_alg(alg_name, frontend, type, mask);
                if (IS_ERR(alg)) {
                        err = PTR_ERR(alg);
                        goto err;
index 95baaea21fbc914cdc6de01f460418e3d967e621..7efa4d0533fffe031a241c3a35d2599726e7b6fc 100644 (file)
@@ -106,6 +106,9 @@ struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
                                      u32 mask);
 void *crypto_create_tfm(struct crypto_alg *alg,
                        const struct crypto_type *frontend);
+struct crypto_alg *crypto_find_alg(const char *alg_name,
+                                  const struct crypto_type *frontend,
+                                  u32 type, u32 mask);
 void *crypto_alloc_tfm(const char *alg_name,
                       const struct crypto_type *frontend, u32 type, u32 mask);
 
index c9bff92a9e0e898e950014b75ec25b5f2fe0d13d..1d15a926041e7a3d443b697c11ea35969d651e5e 100644 (file)
@@ -136,7 +136,16 @@ static inline void crypto_set_spawn(struct crypto_spawn *spawn,
 struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb);
 int crypto_check_attr_type(struct rtattr **tb, u32 type);
 const char *crypto_attr_alg_name(struct rtattr *rta);
-struct crypto_alg *crypto_attr_alg(struct rtattr *rta, u32 type, u32 mask);
+struct crypto_alg *crypto_attr_alg2(struct rtattr *rta,
+                                   const struct crypto_type *frontend,
+                                   u32 type, u32 mask);
+
+static inline struct crypto_alg *crypto_attr_alg(struct rtattr *rta,
+                                                u32 type, u32 mask)
+{
+       return crypto_attr_alg2(rta, NULL, type, mask);
+}
+
 int crypto_attr_u32(struct rtattr *rta, u32 *num);
 void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg,
                             unsigned int head);