Lines Matching full:alg

38 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg,
43 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) in crypto_mod_get() argument
45 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
49 void crypto_mod_put(struct crypto_alg *alg) in crypto_mod_put() argument
51 struct module *module = alg->cra_module; in crypto_mod_put()
53 crypto_alg_put(alg); in crypto_mod_put()
62 struct crypto_alg *q, *alg = NULL; in __crypto_alg_lookup() local
83 if (alg) in __crypto_alg_lookup()
84 crypto_mod_put(alg); in __crypto_alg_lookup()
85 alg = q; in __crypto_alg_lookup()
91 return alg; in __crypto_alg_lookup()
94 static void crypto_larval_destroy(struct crypto_alg *alg) in crypto_larval_destroy() argument
96 struct crypto_larval *larval = (void *)alg; in crypto_larval_destroy()
98 BUG_ON(!crypto_is_larval(alg)); in crypto_larval_destroy()
115 larval->alg.cra_flags = CRYPTO_ALG_LARVAL | type; in crypto_larval_alloc()
116 larval->alg.cra_priority = -1; in crypto_larval_alloc()
117 larval->alg.cra_destroy = crypto_larval_destroy; in crypto_larval_alloc()
119 strscpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME); in crypto_larval_alloc()
129 struct crypto_alg *alg; in crypto_larval_add() local
136 refcount_set(&larval->alg.cra_refcnt, 2); in crypto_larval_add()
139 alg = __crypto_alg_lookup(name, type, mask); in crypto_larval_add()
140 if (!alg) { in crypto_larval_add()
141 alg = &larval->alg; in crypto_larval_add()
142 list_add(&alg->cra_list, &crypto_alg_list); in crypto_larval_add()
146 if (alg != &larval->alg) { in crypto_larval_add()
148 if (crypto_is_larval(alg)) in crypto_larval_add()
149 alg = crypto_larval_wait(alg, type, mask); in crypto_larval_add()
152 return alg; in crypto_larval_add()
160 unlinked = list_empty(&larval->alg.cra_list); in crypto_larval_kill()
162 list_del_init(&larval->alg.cra_list); in crypto_larval_kill()
169 crypto_alg_put(&larval->alg); in crypto_larval_kill()
201 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg, in crypto_larval_wait() argument
208 larval = container_of(alg, struct crypto_larval, alg); in crypto_larval_wait()
216 alg = larval->adult; in crypto_larval_wait()
218 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
222 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
223 } else if (!alg || PTR_ERR(alg) == -EEXIST) { in crypto_larval_wait()
224 int err = alg ? -EEXIST : -EAGAIN; in crypto_larval_wait()
233 alg = &larval->alg; in crypto_larval_wait()
234 alg = crypto_alg_lookup(alg->cra_name, type, mask) ?: in crypto_larval_wait()
236 } else if (IS_ERR(alg)) in crypto_larval_wait()
239 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
240 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
241 else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) in crypto_larval_wait()
242 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
243 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
244 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
245 crypto_mod_put(&larval->alg); in crypto_larval_wait()
247 if (!IS_ERR(alg) && crypto_is_larval(alg)) in crypto_larval_wait()
250 return alg; in crypto_larval_wait()
257 struct crypto_alg *alg; in crypto_alg_lookup() local
264 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
266 if (alg) { in crypto_alg_lookup()
271 if (!crypto_is_larval(alg) && in crypto_alg_lookup()
272 ((type ^ alg->cra_flags) & mask)) { in crypto_alg_lookup()
274 crypto_mod_put(alg); in crypto_alg_lookup()
275 alg = ERR_PTR(-ENOENT); in crypto_alg_lookup()
278 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
279 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
281 crypto_mod_put(alg); in crypto_alg_lookup()
282 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
287 return alg; in crypto_alg_lookup()
293 struct crypto_alg *alg; in crypto_larval_lookup() local
301 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
302 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
309 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
312 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
313 alg = crypto_larval_wait(alg, type, mask); in crypto_larval_lookup()
314 else if (alg) in crypto_larval_lookup()
317 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
319 alg = ERR_PTR(-ENOENT); in crypto_larval_lookup()
321 return alg; in crypto_larval_lookup()
340 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
361 alg = crypto_larval_wait(larval, type, mask); in crypto_alg_mod_lookup()
364 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
366 crypto_larval_kill(container_of(larval, struct crypto_larval, alg)); in crypto_alg_mod_lookup()
367 return alg; in crypto_alg_mod_lookup()
379 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
381 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
384 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
386 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
388 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
393 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
400 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
403 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
408 struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfmgfp() argument
415 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfmgfp()
420 tfm->__crt_alg = alg; in __crypto_alloc_tfmgfp()
423 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfmgfp()
431 crypto_shoot_alg(alg); in __crypto_alloc_tfmgfp()
440 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
443 return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL); in __crypto_alloc_tfm()
475 struct crypto_alg *alg; in crypto_alloc_base() local
477 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
478 if (IS_ERR(alg)) { in crypto_alloc_base()
479 err = PTR_ERR(alg); in crypto_alloc_base()
483 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
487 crypto_mod_put(alg); in crypto_alloc_base()
503 static void *crypto_alloc_tfmmem(struct crypto_alg *alg, in crypto_alloc_tfmmem() argument
513 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_alloc_tfmmem()
520 tfm->__crt_alg = alg; in crypto_alloc_tfmmem()
527 void *crypto_create_tfm_node(struct crypto_alg *alg, in crypto_create_tfm_node() argument
535 mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL); in crypto_create_tfm_node()
546 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
555 crypto_shoot_alg(alg); in crypto_create_tfm_node()
566 struct crypto_alg *alg = otfm->__crt_alg; in crypto_clone_tfm() local
571 if (unlikely(!crypto_mod_get(alg))) in crypto_clone_tfm()
574 mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC); in crypto_clone_tfm()
576 crypto_mod_put(alg); in crypto_clone_tfm()
635 struct crypto_alg *alg; in crypto_alloc_tfm_node() local
637 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
638 if (IS_ERR(alg)) { in crypto_alloc_tfm_node()
639 err = PTR_ERR(alg); in crypto_alloc_tfm_node()
643 tfm = crypto_create_tfm_node(alg, frontend, node); in crypto_alloc_tfm_node()
647 crypto_mod_put(alg); in crypto_alloc_tfm_node()
673 struct crypto_alg *alg; in crypto_destroy_tfm() local
680 alg = tfm->__crt_alg; in crypto_destroy_tfm()
682 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
683 alg->cra_exit(tfm); in crypto_destroy_tfm()
685 crypto_mod_put(alg); in crypto_destroy_tfm()
693 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
695 if (!IS_ERR(alg)) { in crypto_has_alg()
696 crypto_mod_put(alg); in crypto_has_alg()
716 void crypto_destroy_alg(struct crypto_alg *alg) in crypto_destroy_alg() argument
718 if (alg->cra_type && alg->cra_type->destroy) in crypto_destroy_alg()
719 alg->cra_type->destroy(alg); in crypto_destroy_alg()
720 if (alg->cra_destroy) in crypto_destroy_alg()
721 alg->cra_destroy(alg); in crypto_destroy_alg()