Commit 4cbbc184 authored by James Morris's avatar James Morris Committed by David S. Miller

[CRYPTO]: Add crypto_alg_available interface.

parent 95d6c210
...@@ -100,13 +100,7 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) ...@@ -100,13 +100,7 @@ struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
struct crypto_tfm *tfm = NULL; struct crypto_tfm *tfm = NULL;
struct crypto_alg *alg; struct crypto_alg *alg;
alg = crypto_alg_lookup(name); alg = crypto_alg_mod_lookup(name);
#ifdef CONFIG_KMOD
if (alg == NULL) {
crypto_alg_autoload(name);
alg = crypto_alg_lookup(name);
}
#endif
if (alg == NULL) if (alg == NULL)
goto out; goto out;
...@@ -208,6 +202,19 @@ int crypto_unregister_alg(struct crypto_alg *alg) ...@@ -208,6 +202,19 @@ int crypto_unregister_alg(struct crypto_alg *alg)
return ret; return ret;
} }
int crypto_alg_available(const char *name, u32 flags)
{
int ret = 0;
struct crypto_alg *alg = crypto_alg_mod_lookup(name);
if (alg) {
crypto_alg_put(alg);
ret = 1;
}
return ret;
}
static void *c_start(struct seq_file *m, loff_t *pos) static void *c_start(struct seq_file *m, loff_t *pos)
{ {
struct list_head *v; struct list_head *v;
...@@ -297,3 +304,4 @@ EXPORT_SYMBOL_GPL(crypto_register_alg); ...@@ -297,3 +304,4 @@ EXPORT_SYMBOL_GPL(crypto_register_alg);
EXPORT_SYMBOL_GPL(crypto_unregister_alg); EXPORT_SYMBOL_GPL(crypto_unregister_alg);
EXPORT_SYMBOL_GPL(crypto_alloc_tfm); EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
EXPORT_SYMBOL_GPL(crypto_free_tfm); EXPORT_SYMBOL_GPL(crypto_free_tfm);
EXPORT_SYMBOL_GPL(crypto_alg_available);
...@@ -25,3 +25,13 @@ void crypto_alg_autoload(const char *name) ...@@ -25,3 +25,13 @@ void crypto_alg_autoload(const char *name)
{ {
request_module(name); request_module(name);
} }
struct crypto_alg *crypto_alg_mod_lookup(const char *name)
{
struct crypto_alg *alg = crypto_alg_lookup(name);
if (alg == NULL) {
crypto_alg_autoload(name);
alg = crypto_alg_lookup(name);
}
return alg;
}
...@@ -40,8 +40,16 @@ static inline u32 crypto_cipher_flags(u32 flags) ...@@ -40,8 +40,16 @@ static inline u32 crypto_cipher_flags(u32 flags)
return flags & (CRYPTO_TFM_MODE_MASK|CRYPTO_TFM_REQ_WEAK_KEY); return flags & (CRYPTO_TFM_MODE_MASK|CRYPTO_TFM_REQ_WEAK_KEY);
} }
struct crypto_alg *crypto_alg_lookup(const char *name);
#ifdef CONFIG_KMOD #ifdef CONFIG_KMOD
void crypto_alg_autoload(const char *name); void crypto_alg_autoload(const char *name);
struct crypto_alg *crypto_alg_mod_lookup(const char *name);
#else
static inline struct crypto_alg *crypto_alg_mod_lookup(const char *name)
{
return crypto_alg_lookup(name);
}
#endif #endif
int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags); int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
......
...@@ -46,6 +46,8 @@ static int mode = 0; ...@@ -46,6 +46,8 @@ static int mode = 0;
static char *xbuf; static char *xbuf;
static char *tvmem; static char *tvmem;
static char *check[] = { "des", "md5", "des3_ede", "rot13", "sha1", NULL };
static void static void
hexdump(unsigned char *buf, unsigned int len) hexdump(unsigned char *buf, unsigned int len)
{ {
...@@ -1299,6 +1301,19 @@ test_des3_ede(void) ...@@ -1299,6 +1301,19 @@ test_des3_ede(void)
crypto_free_tfm(tfm); crypto_free_tfm(tfm);
} }
static void
test_available(void)
{
char **name = check;
while (*name) {
printk("alg %s ", *name);
printk((crypto_alg_available(*name, 0)) ?
"found\n" : "not found\n");
name++;
}
}
static void static void
do_test(void) do_test(void)
{ {
...@@ -1332,6 +1347,10 @@ do_test(void) ...@@ -1332,6 +1347,10 @@ do_test(void)
test_md4(); test_md4();
break; break;
case 100:
test_available();
break;
default: default:
/* useful for debugging */ /* useful for debugging */
printk("not testing anything\n"); printk("not testing anything\n");
......
...@@ -111,6 +111,11 @@ struct crypto_alg { ...@@ -111,6 +111,11 @@ struct crypto_alg {
int crypto_register_alg(struct crypto_alg *alg); int crypto_register_alg(struct crypto_alg *alg);
int crypto_unregister_alg(struct crypto_alg *alg); int crypto_unregister_alg(struct crypto_alg *alg);
/*
* Algorithm query interface.
*/
int crypto_alg_available(const char *name, u32 flags);
/* /*
* Transforms: user-instantiated objects which encapsulate algorithms * Transforms: user-instantiated objects which encapsulate algorithms
* and core processing logic. Managed via crypto_alloc_tfm() and * and core processing logic. Managed via crypto_alloc_tfm() and
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment