Lines Matching refs:alg

39 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); 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
206 larval = container_of(alg, struct crypto_larval, alg); in crypto_larval_wait()
214 alg = larval->adult; in crypto_larval_wait()
216 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
220 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
221 } else if (!alg) { in crypto_larval_wait()
225 alg = &larval->alg; in crypto_larval_wait()
226 type = alg->cra_flags & ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD); in crypto_larval_wait()
228 alg = crypto_alg_lookup(alg->cra_name, type, mask) ?: in crypto_larval_wait()
230 } else if (IS_ERR(alg)) in crypto_larval_wait()
233 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
234 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
235 else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) in crypto_larval_wait()
236 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
237 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
238 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
239 crypto_mod_put(&larval->alg); in crypto_larval_wait()
241 if (!IS_ERR(alg) && crypto_is_larval(alg)) in crypto_larval_wait()
244 return alg; in crypto_larval_wait()
251 struct crypto_alg *alg; in crypto_alg_lookup() local
258 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
260 if (alg) { in crypto_alg_lookup()
265 if (!crypto_is_larval(alg) && in crypto_alg_lookup()
266 ((type ^ alg->cra_flags) & mask)) { in crypto_alg_lookup()
268 crypto_mod_put(alg); in crypto_alg_lookup()
269 alg = ERR_PTR(-ENOENT); in crypto_alg_lookup()
272 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
273 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
275 crypto_mod_put(alg); in crypto_alg_lookup()
276 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
281 return alg; in crypto_alg_lookup()
287 struct crypto_alg *alg; in crypto_larval_lookup() local
295 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
296 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
303 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
306 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
307 alg = crypto_larval_wait(alg); in crypto_larval_lookup()
308 else if (alg) in crypto_larval_lookup()
311 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
313 alg = ERR_PTR(-ENOENT); in crypto_larval_lookup()
315 return alg; in crypto_larval_lookup()
334 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
355 alg = crypto_larval_wait(larval); in crypto_alg_mod_lookup()
358 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
360 crypto_larval_kill(container_of(larval, struct crypto_larval, alg)); in crypto_alg_mod_lookup()
361 return alg; in crypto_alg_mod_lookup()
373 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
375 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
378 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
380 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
382 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
387 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
391 len += crypto_compress_ctxsize(alg); in crypto_ctxsize()
398 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
401 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
406 struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfmgfp() argument
413 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfmgfp()
418 tfm->__crt_alg = alg; in __crypto_alloc_tfmgfp()
421 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfmgfp()
429 crypto_shoot_alg(alg); in __crypto_alloc_tfmgfp()
438 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
441 return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL); in __crypto_alloc_tfm()
473 struct crypto_alg *alg; in crypto_alloc_base() local
475 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
476 if (IS_ERR(alg)) { in crypto_alloc_base()
477 err = PTR_ERR(alg); in crypto_alloc_base()
481 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
485 crypto_mod_put(alg); in crypto_alloc_base()
501 static void *crypto_alloc_tfmmem(struct crypto_alg *alg, in crypto_alloc_tfmmem() argument
511 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_alloc_tfmmem()
518 tfm->__crt_alg = alg; in crypto_alloc_tfmmem()
525 void *crypto_create_tfm_node(struct crypto_alg *alg, in crypto_create_tfm_node() argument
533 mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL); in crypto_create_tfm_node()
543 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
552 crypto_shoot_alg(alg); in crypto_create_tfm_node()
563 struct crypto_alg *alg = otfm->__crt_alg; in crypto_clone_tfm() local
568 if (unlikely(!crypto_mod_get(alg))) in crypto_clone_tfm()
571 mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC); in crypto_clone_tfm()
573 crypto_mod_put(alg); in crypto_clone_tfm()
632 struct crypto_alg *alg; in crypto_alloc_tfm_node() local
634 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
635 if (IS_ERR(alg)) { in crypto_alloc_tfm_node()
636 err = PTR_ERR(alg); in crypto_alloc_tfm_node()
640 tfm = crypto_create_tfm_node(alg, frontend, node); in crypto_alloc_tfm_node()
644 crypto_mod_put(alg); in crypto_alloc_tfm_node()
670 struct crypto_alg *alg; in crypto_destroy_tfm() local
677 alg = tfm->__crt_alg; in crypto_destroy_tfm()
679 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
680 alg->cra_exit(tfm); in crypto_destroy_tfm()
682 crypto_mod_put(alg); in crypto_destroy_tfm()
690 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
692 if (!IS_ERR(alg)) { in crypto_has_alg()
693 crypto_mod_put(alg); in crypto_has_alg()