Lines Matching refs:alg

39 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
41 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) in crypto_mod_get() argument
43 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
47 void crypto_mod_put(struct crypto_alg *alg) in crypto_mod_put() argument
49 struct module *module = alg->cra_module; in crypto_mod_put()
51 crypto_alg_put(alg); in crypto_mod_put()
59 struct crypto_alg *q, *alg = NULL; in __crypto_alg_lookup() local
85 if (alg) in __crypto_alg_lookup()
86 crypto_mod_put(alg); in __crypto_alg_lookup()
87 alg = q; in __crypto_alg_lookup()
93 return alg; in __crypto_alg_lookup()
96 static void crypto_larval_destroy(struct crypto_alg *alg) in crypto_larval_destroy() argument
98 struct crypto_larval *larval = (void *)alg; in crypto_larval_destroy()
100 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); in crypto_larval_add()
152 return alg; in crypto_larval_add()
155 void crypto_larval_kill(struct crypto_alg *alg) in crypto_larval_kill() argument
157 struct crypto_larval *larval = (void *)alg; in crypto_larval_kill()
160 list_del(&alg->cra_list); in crypto_larval_kill()
163 crypto_alg_put(alg); in crypto_larval_kill()
178 crypto_larval_kill(&larval->alg); in crypto_wait_for_test()
202 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg) in crypto_larval_wait() argument
204 struct crypto_larval *larval = (void *)alg; in crypto_larval_wait()
213 alg = larval->adult; in crypto_larval_wait()
215 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
217 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
218 else if (!alg) in crypto_larval_wait()
219 alg = ERR_PTR(-ENOENT); in crypto_larval_wait()
220 else if (IS_ERR(alg)) in crypto_larval_wait()
223 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
224 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
225 else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) in crypto_larval_wait()
226 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
227 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
228 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
229 crypto_mod_put(&larval->alg); in crypto_larval_wait()
231 return alg; in crypto_larval_wait()
238 struct crypto_alg *alg; in crypto_alg_lookup() local
245 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
247 if (alg) { in crypto_alg_lookup()
252 if (!crypto_is_larval(alg) && in crypto_alg_lookup()
253 ((type ^ alg->cra_flags) & mask)) { in crypto_alg_lookup()
255 crypto_mod_put(alg); in crypto_alg_lookup()
256 alg = ERR_PTR(-ENOENT); in crypto_alg_lookup()
259 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
260 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
262 crypto_mod_put(alg); in crypto_alg_lookup()
263 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
268 return alg; in crypto_alg_lookup()
274 struct crypto_alg *alg; in crypto_larval_lookup() local
282 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
283 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
290 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
293 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
294 alg = crypto_larval_wait(alg); in crypto_larval_lookup()
295 else if (!alg) in crypto_larval_lookup()
296 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
298 return alg; in crypto_larval_lookup()
317 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
338 alg = crypto_larval_wait(larval); in crypto_alg_mod_lookup()
341 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
344 return alg; in crypto_alg_mod_lookup()
356 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
358 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
361 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
363 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
365 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
370 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
374 len += crypto_compress_ctxsize(alg); in crypto_ctxsize()
381 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
384 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
389 struct crypto_tfm *__crypto_alloc_tfmgfp(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfmgfp() argument
396 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfmgfp()
401 tfm->__crt_alg = alg; in __crypto_alloc_tfmgfp()
404 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfmgfp()
412 crypto_shoot_alg(alg); in __crypto_alloc_tfmgfp()
421 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
424 return __crypto_alloc_tfmgfp(alg, type, mask, GFP_KERNEL); in __crypto_alloc_tfm()
456 struct crypto_alg *alg; in crypto_alloc_base() local
458 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
459 if (IS_ERR(alg)) { in crypto_alloc_base()
460 err = PTR_ERR(alg); in crypto_alloc_base()
464 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
468 crypto_mod_put(alg); in crypto_alloc_base()
484 static void *crypto_alloc_tfmmem(struct crypto_alg *alg, in crypto_alloc_tfmmem() argument
494 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_alloc_tfmmem()
501 tfm->__crt_alg = alg; in crypto_alloc_tfmmem()
508 void *crypto_create_tfm_node(struct crypto_alg *alg, in crypto_create_tfm_node() argument
516 mem = crypto_alloc_tfmmem(alg, frontend, node, GFP_KERNEL); in crypto_create_tfm_node()
526 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
535 crypto_shoot_alg(alg); in crypto_create_tfm_node()
546 struct crypto_alg *alg = otfm->__crt_alg; in crypto_clone_tfm() local
551 if (unlikely(!crypto_mod_get(alg))) in crypto_clone_tfm()
554 mem = crypto_alloc_tfmmem(alg, frontend, otfm->node, GFP_ATOMIC); in crypto_clone_tfm()
556 crypto_mod_put(alg); in crypto_clone_tfm()
615 struct crypto_alg *alg; in crypto_alloc_tfm_node() local
617 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
618 if (IS_ERR(alg)) { in crypto_alloc_tfm_node()
619 err = PTR_ERR(alg); in crypto_alloc_tfm_node()
623 tfm = crypto_create_tfm_node(alg, frontend, node); in crypto_alloc_tfm_node()
627 crypto_mod_put(alg); in crypto_alloc_tfm_node()
653 struct crypto_alg *alg; in crypto_destroy_tfm() local
660 alg = tfm->__crt_alg; in crypto_destroy_tfm()
662 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
663 alg->cra_exit(tfm); in crypto_destroy_tfm()
665 crypto_mod_put(alg); in crypto_destroy_tfm()
673 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
675 if (!IS_ERR(alg)) { in crypto_has_alg()
676 crypto_mod_put(alg); in crypto_has_alg()