Lines Matching refs: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()
61 struct crypto_alg *q, *alg = NULL; in __crypto_alg_lookup() local
82 if (alg) in __crypto_alg_lookup()
83 crypto_mod_put(alg); in __crypto_alg_lookup()
84 alg = q; in __crypto_alg_lookup()
90 return alg; in __crypto_alg_lookup()
93 static void crypto_larval_destroy(struct crypto_alg *alg) in crypto_larval_destroy() argument
95 struct crypto_larval *larval = (void *)alg; in crypto_larval_destroy()
97 BUG_ON(!crypto_is_larval(alg)); in crypto_larval_destroy()
114 larval->alg.cra_flags = CRYPTO_ALG_LARVAL | type; in crypto_larval_alloc()
115 larval->alg.cra_priority = -1; in crypto_larval_alloc()
116 larval->alg.cra_destroy = crypto_larval_destroy; in crypto_larval_alloc()
118 strscpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME); in crypto_larval_alloc()
128 struct crypto_alg *alg; in crypto_larval_add() local
135 refcount_set(&larval->alg.cra_refcnt, 2); in crypto_larval_add()
138 alg = __crypto_alg_lookup(name, type, mask); in crypto_larval_add()
139 if (!alg) { in crypto_larval_add()
140 alg = &larval->alg; in crypto_larval_add()
141 list_add(&alg->cra_list, &crypto_alg_list); in crypto_larval_add()
145 if (alg != &larval->alg) { in crypto_larval_add()
147 if (crypto_is_larval(alg)) in crypto_larval_add()
148 alg = crypto_larval_wait(alg, type, mask); in crypto_larval_add()
151 return alg; in crypto_larval_add()
159 unlinked = list_empty(&larval->alg.cra_list); in crypto_larval_kill()
161 list_del_init(&larval->alg.cra_list); in crypto_larval_kill()
168 crypto_alg_put(&larval->alg); in crypto_larval_kill()
200 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg, in crypto_larval_wait() argument
207 larval = container_of(alg, struct crypto_larval, alg); in crypto_larval_wait()
215 alg = larval->adult; in crypto_larval_wait()
217 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
221 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
222 } else if (!alg || PTR_ERR(alg) == -EEXIST) { in crypto_larval_wait()
223 int err = alg ? -EEXIST : -EAGAIN; in crypto_larval_wait()
232 alg = &larval->alg; in crypto_larval_wait()
233 alg = crypto_alg_lookup(alg->cra_name, type, mask) ?: in crypto_larval_wait()
235 } else if (IS_ERR(alg)) in crypto_larval_wait()
238 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
239 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
240 else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) in crypto_larval_wait()
241 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
242 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
243 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
244 crypto_mod_put(&larval->alg); in crypto_larval_wait()
246 if (!IS_ERR(alg) && crypto_is_larval(alg)) in crypto_larval_wait()
249 return alg; in crypto_larval_wait()
256 struct crypto_alg *alg; in crypto_alg_lookup() local
263 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
265 if (alg) { in crypto_alg_lookup()
270 if (!crypto_is_larval(alg) && in crypto_alg_lookup()
271 ((type ^ alg->cra_flags) & mask)) { in crypto_alg_lookup()
273 crypto_mod_put(alg); in crypto_alg_lookup()
274 alg = ERR_PTR(-ENOENT); in crypto_alg_lookup()
277 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
278 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
280 crypto_mod_put(alg); in crypto_alg_lookup()
281 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
286 return alg; in crypto_alg_lookup()
292 struct crypto_alg *alg; in crypto_larval_lookup() local
300 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
301 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
308 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
311 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
312 alg = crypto_larval_wait(alg, type, mask); in crypto_larval_lookup()
313 else if (alg) in crypto_larval_lookup()
316 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
318 alg = ERR_PTR(-ENOENT); in crypto_larval_lookup()
320 return alg; in crypto_larval_lookup()
339 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
360 alg = crypto_larval_wait(larval, type, mask); in crypto_alg_mod_lookup()
363 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
365 crypto_larval_kill(container_of(larval, struct crypto_larval, alg)); in crypto_alg_mod_lookup()
366 return alg; in crypto_alg_mod_lookup()
378 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
380 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
383 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
385 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
387 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
392 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
399 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
402 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
407 struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfmgfp() argument
414 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfmgfp()
419 tfm->__crt_alg = alg; in __crypto_alloc_tfmgfp()
422 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfmgfp()
430 crypto_shoot_alg(alg); in __crypto_alloc_tfmgfp()
439 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
442 return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL); in __crypto_alloc_tfm()
474 struct crypto_alg *alg; in crypto_alloc_base() local
476 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
477 if (IS_ERR(alg)) { in crypto_alloc_base()
478 err = PTR_ERR(alg); in crypto_alloc_base()
482 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
486 crypto_mod_put(alg); in crypto_alloc_base()
502 static void *crypto_alloc_tfmmem(struct crypto_alg *alg, in crypto_alloc_tfmmem() argument
512 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_alloc_tfmmem()
519 tfm->__crt_alg = alg; in crypto_alloc_tfmmem()
526 void *crypto_create_tfm_node(struct crypto_alg *alg, in crypto_create_tfm_node() argument
534 mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL); in crypto_create_tfm_node()
545 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
554 crypto_shoot_alg(alg); in crypto_create_tfm_node()
565 struct crypto_alg *alg = otfm->__crt_alg; in crypto_clone_tfm() local
570 if (unlikely(!crypto_mod_get(alg))) in crypto_clone_tfm()
573 mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC); in crypto_clone_tfm()
575 crypto_mod_put(alg); in crypto_clone_tfm()
634 struct crypto_alg *alg; in crypto_alloc_tfm_node() local
636 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
637 if (IS_ERR(alg)) { in crypto_alloc_tfm_node()
638 err = PTR_ERR(alg); in crypto_alloc_tfm_node()
642 tfm = crypto_create_tfm_node(alg, frontend, node); in crypto_alloc_tfm_node()
646 crypto_mod_put(alg); in crypto_alloc_tfm_node()
672 struct crypto_alg *alg; in crypto_destroy_tfm() local
679 alg = tfm->__crt_alg; in crypto_destroy_tfm()
681 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
682 alg->cra_exit(tfm); in crypto_destroy_tfm()
684 crypto_mod_put(alg); in crypto_destroy_tfm()
692 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
694 if (!IS_ERR(alg)) { in crypto_has_alg()
695 crypto_mod_put(alg); in crypto_has_alg()
715 void crypto_destroy_alg(struct crypto_alg *alg) in crypto_destroy_alg() argument
717 if (alg->cra_type && alg->cra_type->destroy) in crypto_destroy_alg()
718 alg->cra_type->destroy(alg); in crypto_destroy_alg()
719 if (alg->cra_destroy) in crypto_destroy_alg()
720 alg->cra_destroy(alg); in crypto_destroy_alg()