Lines Matching +full:mem +full:- +full:type
1 // SPDX-License-Identifier: GPL-2.0-or-later
40 u32 type, u32 mask);
41 static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
46 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
52 struct module *module = alg->cra_module; in crypto_mod_put()
59 static struct crypto_alg *__crypto_alg_lookup(const char *name, u32 type, in __crypto_alg_lookup() argument
63 int best = -2; in __crypto_alg_lookup()
71 if ((q->cra_flags ^ type) & mask) in __crypto_alg_lookup()
74 exact = !strcmp(q->cra_driver_name, name); in __crypto_alg_lookup()
75 fuzzy = !strcmp(q->cra_name, name); in __crypto_alg_lookup()
76 if (!exact && !(fuzzy && q->cra_priority > best)) in __crypto_alg_lookup()
82 best = q->cra_priority; in __crypto_alg_lookup()
99 if (!IS_ERR_OR_NULL(larval->adult)) in crypto_larval_destroy()
100 crypto_mod_put(larval->adult); in crypto_larval_destroy()
104 struct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask) in crypto_larval_alloc() argument
110 return ERR_PTR(-ENOMEM); in crypto_larval_alloc()
112 type &= ~CRYPTO_ALG_TYPE_MASK | (mask ?: CRYPTO_ALG_TYPE_MASK); in crypto_larval_alloc()
114 larval->mask = mask; in crypto_larval_alloc()
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()
120 init_completion(&larval->completion); in crypto_larval_alloc()
126 static struct crypto_alg *crypto_larval_add(const char *name, u32 type, in crypto_larval_add() argument
132 larval = crypto_larval_alloc(name, type, mask); in crypto_larval_add()
136 refcount_set(&larval->alg.cra_refcnt, 2); in crypto_larval_add()
139 alg = __crypto_alg_lookup(name, type, mask); 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()
149 alg = crypto_larval_wait(alg, type, mask); 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()
168 complete_all(&larval->completion); in crypto_larval_kill()
169 crypto_alg_put(&larval->alg); in crypto_larval_kill()
176 err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult); in crypto_schedule_test()
186 if (larval->test_started) in crypto_start_test()
190 if (larval->test_started) { in crypto_start_test()
195 larval->test_started = true; in crypto_start_test()
202 u32 type, u32 mask) in crypto_larval_wait() argument
214 &larval->completion, 60 * HZ); 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()
224 alg = &larval->alg; in crypto_larval_wait()
225 alg = crypto_alg_lookup(alg->cra_name, type, mask) ?: in crypto_larval_wait()
226 ERR_PTR(-EAGAIN); 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()
235 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
236 crypto_mod_put(&larval->alg); in crypto_larval_wait()
244 static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type, in crypto_alg_lookup() argument
251 if (!((type | mask) & CRYPTO_ALG_TESTED)) in crypto_alg_lookup()
255 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
258 if (((type | mask) ^ fips) & fips) in crypto_alg_lookup()
263 ((type ^ alg->cra_flags) & mask)) { 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()
273 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
281 static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type, in crypto_larval_lookup() argument
287 return ERR_PTR(-ENOENT); in crypto_larval_lookup()
289 type &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD); in crypto_larval_lookup()
292 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
294 request_module("crypto-%s", name); in crypto_larval_lookup()
296 if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask & in crypto_larval_lookup()
298 request_module("crypto-%s-all", name); in crypto_larval_lookup()
300 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
304 alg = crypto_larval_wait(alg, type, mask); 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()
329 struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask) in crypto_alg_mod_lookup() argument
339 * not be an internal cipher, use type | CRYPTO_ALG_INTERNAL and in crypto_alg_mod_lookup()
342 if (!((type | mask) & CRYPTO_ALG_INTERNAL)) in crypto_alg_mod_lookup()
345 larval = crypto_larval_lookup(name, type, mask); in crypto_alg_mod_lookup()
352 alg = crypto_larval_wait(larval, type, mask); in crypto_alg_mod_lookup()
355 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
364 const struct crypto_type *type = tfm->__crt_alg->cra_type; in crypto_exit_ops() local
366 if (type && tfm->exit) in crypto_exit_ops()
367 tfm->exit(tfm); in crypto_exit_ops()
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()
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
404 int err = -ENOMEM; in __crypto_alloc_tfmgfp()
406 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfmgfp()
411 tfm->__crt_alg = alg; in __crypto_alloc_tfmgfp()
412 refcount_set(&tfm->refcnt, 1); in __crypto_alloc_tfmgfp()
414 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfmgfp()
421 if (err == -EAGAIN) 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()
439 * crypto_alloc_base - Locate algorithm and allocate transform
441 * @type: Type of algorithm
442 * @mask: Mask for type comparison
454 * The returned transform is of a non-determinate type. Most people
460 struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask) in crypto_alloc_base() argument
468 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
474 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
482 if (err != -EAGAIN) in crypto_alloc_base()
485 err = -EINTR; in crypto_alloc_base()
501 char *mem; in crypto_alloc_tfmmem() local
503 tfmsize = frontend->tfmsize; in crypto_alloc_tfmmem()
504 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_alloc_tfmmem()
506 mem = kzalloc_node(total, gfp, node); in crypto_alloc_tfmmem()
507 if (mem == NULL) in crypto_alloc_tfmmem()
508 return ERR_PTR(-ENOMEM); in crypto_alloc_tfmmem()
510 tfm = (struct crypto_tfm *)(mem + tfmsize); in crypto_alloc_tfmmem()
511 tfm->__crt_alg = alg; in crypto_alloc_tfmmem()
512 tfm->node = node; in crypto_alloc_tfmmem()
513 refcount_set(&tfm->refcnt, 1); in crypto_alloc_tfmmem()
515 return mem; in crypto_alloc_tfmmem()
523 char *mem; in crypto_create_tfm_node() local
526 mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL); in crypto_create_tfm_node()
527 if (IS_ERR(mem)) in crypto_create_tfm_node()
530 tfm = (struct crypto_tfm *)(mem + frontend->tfmsize); in crypto_create_tfm_node()
532 err = frontend->init_tfm(tfm); in crypto_create_tfm_node()
536 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
544 if (err == -EAGAIN) in crypto_create_tfm_node()
546 kfree(mem); in crypto_create_tfm_node()
547 mem = ERR_PTR(err); in crypto_create_tfm_node()
549 return mem; in crypto_create_tfm_node()
556 struct crypto_alg *alg = otfm->__crt_alg; in crypto_clone_tfm()
558 char *mem; in crypto_clone_tfm() local
560 mem = ERR_PTR(-ESTALE); in crypto_clone_tfm()
564 mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC); in crypto_clone_tfm()
565 if (IS_ERR(mem)) { in crypto_clone_tfm()
570 tfm = (struct crypto_tfm *)(mem + frontend->tfmsize); in crypto_clone_tfm()
571 tfm->crt_flags = otfm->crt_flags; in crypto_clone_tfm()
572 tfm->exit = otfm->exit; in crypto_clone_tfm()
575 return mem; in crypto_clone_tfm()
581 u32 type, u32 mask) in crypto_find_alg() argument
584 type &= frontend->maskclear; in crypto_find_alg()
585 mask &= frontend->maskclear; in crypto_find_alg()
586 type |= frontend->type; in crypto_find_alg()
587 mask |= frontend->maskset; in crypto_find_alg()
590 return crypto_alg_mod_lookup(alg_name, type, mask); in crypto_find_alg()
595 * crypto_alloc_tfm_node - Locate algorithm and allocate transform
597 * @frontend: Frontend algorithm type
598 * @type: Type of algorithm
599 * @mask: Mask for type comparison
610 * The returned transform is of a non-determinate type. Most people
618 const struct crypto_type *frontend, u32 type, u32 mask, in crypto_alloc_tfm_node() argument
627 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
641 if (err != -EAGAIN) in crypto_alloc_tfm_node()
644 err = -EINTR; in crypto_alloc_tfm_node()
654 * crypto_destroy_tfm - Free crypto transform
655 * @mem: Start of tfm slab
661 void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm) in crypto_destroy_tfm() argument
665 if (IS_ERR_OR_NULL(mem)) in crypto_destroy_tfm()
668 if (!refcount_dec_and_test(&tfm->refcnt)) in crypto_destroy_tfm()
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()
676 kfree_sensitive(mem); in crypto_destroy_tfm()
680 int crypto_has_alg(const char *name, u32 type, u32 mask) in crypto_has_alg() argument
683 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg()
698 if (err == -EINPROGRESS) in crypto_req_done()
701 wait->err = err; in crypto_req_done()
702 complete(&wait->completion); in crypto_req_done()
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()