]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - crypto/api.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux.git] / crypto / api.c
index 70a894e52ff3b78ca460591124ca32aeb24181ff..1d5290c67108316f6495f33674094b5a476e2e14 100644 (file)
@@ -193,17 +193,24 @@ static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg)
        return alg;
 }
 
-struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, u32 mask)
+static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
+                                           u32 mask)
 {
        struct crypto_alg *alg;
+       u32 test = 0;
+
+       if (!((type | mask) & CRYPTO_ALG_TESTED))
+               test |= CRYPTO_ALG_TESTED;
 
        down_read(&crypto_alg_sem);
-       alg = __crypto_alg_lookup(name, type, mask);
+       alg = __crypto_alg_lookup(name, type | test, mask | test);
+       if (!alg && test)
+               alg = __crypto_alg_lookup(name, type, mask) ?
+                     ERR_PTR(-ELIBBAD) : NULL;
        up_read(&crypto_alg_sem);
 
        return alg;
 }
-EXPORT_SYMBOL_GPL(crypto_alg_lookup);
 
 static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type,
                                               u32 mask)
@@ -227,10 +234,12 @@ static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type,
                alg = crypto_alg_lookup(name, type, mask);
        }
 
-       if (alg)
-               return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
+       if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg))
+               alg = crypto_larval_wait(alg);
+       else if (!alg)
+               alg = crypto_larval_add(name, type, mask);
 
-       return crypto_larval_add(name, type, mask);
+       return alg;
 }
 
 int crypto_probing_notify(unsigned long val, void *v)
@@ -253,11 +262,6 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
        struct crypto_alg *larval;
        int ok;
 
-       if (!((type | mask) & CRYPTO_ALG_TESTED)) {
-               type |= CRYPTO_ALG_TESTED;
-               mask |= CRYPTO_ALG_TESTED;
-       }
-
        /*
         * If the internal flag is set for a cipher, require a caller to
         * to invoke the cipher with the internal flag to use that cipher.
@@ -485,20 +489,14 @@ 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);
+       return crypto_alg_mod_lookup(alg_name, type, mask);
 }
 EXPORT_SYMBOL_GPL(crypto_find_alg);