Lines Matching refs:alg

39 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg,
44 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) in crypto_mod_get() argument
46 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
50 void crypto_mod_put(struct crypto_alg *alg) in crypto_mod_put() argument
52 struct module *module = alg->cra_module; in crypto_mod_put()
54 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) { in crypto_larval_wait()
224 alg = &larval->alg; in crypto_larval_wait()
225 alg = crypto_alg_lookup(alg->cra_name, type, mask) ?: in crypto_larval_wait()
227 } else if (IS_ERR(alg)) in crypto_larval_wait()
230 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
231 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
232 else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) in crypto_larval_wait()
233 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
234 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
235 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
236 crypto_mod_put(&larval->alg); in crypto_larval_wait()
238 if (!IS_ERR(alg) && crypto_is_larval(alg)) in crypto_larval_wait()
241 return alg; in crypto_larval_wait()
248 struct crypto_alg *alg; in crypto_alg_lookup() local
255 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
257 if (alg) { in crypto_alg_lookup()
262 if (!crypto_is_larval(alg) && in crypto_alg_lookup()
263 ((type ^ alg->cra_flags) & mask)) { in crypto_alg_lookup()
265 crypto_mod_put(alg); in crypto_alg_lookup()
266 alg = ERR_PTR(-ENOENT); in crypto_alg_lookup()
269 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
270 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
272 crypto_mod_put(alg); in crypto_alg_lookup()
273 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
278 return alg; in crypto_alg_lookup()
284 struct crypto_alg *alg; in crypto_larval_lookup() local
292 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
293 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
300 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
303 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
304 alg = crypto_larval_wait(alg, type, mask); in crypto_larval_lookup()
305 else if (alg) in crypto_larval_lookup()
308 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
310 alg = ERR_PTR(-ENOENT); in crypto_larval_lookup()
312 return alg; in crypto_larval_lookup()
331 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
352 alg = crypto_larval_wait(larval, type, mask); in crypto_alg_mod_lookup()
355 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
357 crypto_larval_kill(container_of(larval, struct crypto_larval, alg)); in crypto_alg_mod_lookup()
358 return alg; in crypto_alg_mod_lookup()
370 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
372 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
375 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
377 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
379 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
384 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
391 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
394 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
399 struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfmgfp() argument
406 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfmgfp()
411 tfm->__crt_alg = alg; in __crypto_alloc_tfmgfp()
414 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfmgfp()
422 crypto_shoot_alg(alg); in __crypto_alloc_tfmgfp()
431 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
434 return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL); in __crypto_alloc_tfm()
466 struct crypto_alg *alg; in crypto_alloc_base() local
468 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
469 if (IS_ERR(alg)) { in crypto_alloc_base()
470 err = PTR_ERR(alg); in crypto_alloc_base()
474 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
478 crypto_mod_put(alg); in crypto_alloc_base()
494 static void *crypto_alloc_tfmmem(struct crypto_alg *alg, in crypto_alloc_tfmmem() argument
504 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_alloc_tfmmem()
511 tfm->__crt_alg = alg; in crypto_alloc_tfmmem()
518 void *crypto_create_tfm_node(struct crypto_alg *alg, in crypto_create_tfm_node() argument
526 mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL); in crypto_create_tfm_node()
536 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
545 crypto_shoot_alg(alg); in crypto_create_tfm_node()
556 struct crypto_alg *alg = otfm->__crt_alg; in crypto_clone_tfm() local
561 if (unlikely(!crypto_mod_get(alg))) in crypto_clone_tfm()
564 mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC); in crypto_clone_tfm()
566 crypto_mod_put(alg); in crypto_clone_tfm()
625 struct crypto_alg *alg; in crypto_alloc_tfm_node() local
627 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
628 if (IS_ERR(alg)) { in crypto_alloc_tfm_node()
629 err = PTR_ERR(alg); in crypto_alloc_tfm_node()
633 tfm = crypto_create_tfm_node(alg, frontend, node); in crypto_alloc_tfm_node()
637 crypto_mod_put(alg); in crypto_alloc_tfm_node()
663 struct crypto_alg *alg; in crypto_destroy_tfm() local
670 alg = tfm->__crt_alg; in crypto_destroy_tfm()
672 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
673 alg->cra_exit(tfm); in crypto_destroy_tfm()
675 crypto_mod_put(alg); in crypto_destroy_tfm()
683 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
685 if (!IS_ERR(alg)) { in crypto_has_alg()
686 crypto_mod_put(alg); in crypto_has_alg()
706 void crypto_destroy_alg(struct crypto_alg *alg) in crypto_destroy_alg() argument
708 if (alg->cra_type && alg->cra_type->destroy) in crypto_destroy_alg()
709 alg->cra_type->destroy(alg); in crypto_destroy_alg()
711 if (alg->cra_destroy) in crypto_destroy_alg()
712 alg->cra_destroy(alg); in crypto_destroy_alg()