19 #include <linux/errno.h>
20 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/sched.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
45 return try_module_get(alg->
cra_module) ? crypto_alg_get(alg) :
NULL;
58 static inline int crypto_is_test_larval(
struct crypto_larval *larval)
60 return larval->
alg.cra_driver_name[0];
72 if (crypto_is_moribund(q))
78 if (crypto_is_larval(q) &&
103 static void crypto_larval_destroy(
struct crypto_alg *alg)
107 BUG_ON(!crypto_is_larval(alg));
117 larval = kzalloc(
sizeof(*larval),
GFP_KERNEL);
123 larval->
alg.cra_priority = -1;
124 larval->
alg.cra_destroy = crypto_larval_destroy;
133 static struct crypto_alg *crypto_larval_add(
const char *name,
u32 type,
141 return ERR_CAST(larval);
146 alg = __crypto_alg_lookup(name, type, mask);
149 list_add(&alg->
cra_list, &crypto_alg_list);
153 if (alg != &larval->
alg)
181 alg = ERR_PTR(-
EINTR);
186 else if (crypto_is_test_larval(larval) &&
201 alg = __crypto_alg_lookup(name, type, mask);
220 request_module(
"%s", name);
223 CRYPTO_ALG_NEED_FALLBACK))
224 request_module(
"%s-all", name);
230 return crypto_is_larval(alg) ? crypto_larval_wait(alg) : alg;
232 return crypto_larval_add(name, type, mask);
241 if (ok == NOTIFY_DONE) {
242 request_module(
"cryptomgr");
262 if (IS_ERR(larval) || !crypto_is_larval(larval))
267 if (ok == NOTIFY_STOP)
268 alg = crypto_larval_wait(larval);
283 return type_obj->
init(tfm, type, mask);
285 switch (crypto_tfm_alg_type(tfm)) {
300 static void crypto_exit_ops(
struct crypto_tfm *tfm)
310 switch (crypto_tfm_alg_type(tfm)) {
324 static unsigned int crypto_ctxsize(
struct crypto_alg *alg,
u32 type,
u32 mask)
329 len = alg->
cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1);
331 return len + type_obj->
ctxsize(alg, type, mask);
338 len += crypto_cipher_ctxsize(alg);
342 len += crypto_compress_ctxsize(alg);
361 unsigned int tfm_size;
364 tfm_size =
sizeof(*tfm) + crypto_ctxsize(alg, type, mask);
371 err = crypto_init_ops(tfm, type, mask);
376 goto cra_init_failed;
381 crypto_exit_ops(tfm);
454 unsigned int tfmsize;
459 total = tfmsize +
sizeof(*tfm) + frontend->
extsize(alg);
473 goto cra_init_failed;
478 crypto_exit_ops(tfm);
500 type |= frontend->
type;
507 return lookup(alg_name, type, mask);
585 crypto_exit_ops(tfm);