Lines Matching refs:alg
37 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
39 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) in crypto_mod_get() argument
41 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
45 void crypto_mod_put(struct crypto_alg *alg) in crypto_mod_put() argument
47 struct module *module = alg->cra_module; in crypto_mod_put()
49 crypto_alg_put(alg); in crypto_mod_put()
57 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()
113 larval->alg.cra_flags = CRYPTO_ALG_LARVAL | type; in crypto_larval_alloc()
114 larval->alg.cra_priority = -1; in crypto_larval_alloc()
115 larval->alg.cra_destroy = crypto_larval_destroy; in crypto_larval_alloc()
117 strscpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME); in crypto_larval_alloc()
127 struct crypto_alg *alg; in crypto_larval_add() local
134 refcount_set(&larval->alg.cra_refcnt, 2); in crypto_larval_add()
137 alg = __crypto_alg_lookup(name, type, mask); in crypto_larval_add()
138 if (!alg) { in crypto_larval_add()
139 alg = &larval->alg; in crypto_larval_add()
140 list_add(&alg->cra_list, &crypto_alg_list); in crypto_larval_add()
144 if (alg != &larval->alg) { in crypto_larval_add()
146 if (crypto_is_larval(alg)) in crypto_larval_add()
147 alg = crypto_larval_wait(alg); in crypto_larval_add()
150 return alg; in crypto_larval_add()
153 void crypto_larval_kill(struct crypto_alg *alg) in crypto_larval_kill() argument
155 struct crypto_larval *larval = (void *)alg; in crypto_larval_kill()
158 list_del(&alg->cra_list); in crypto_larval_kill()
161 crypto_alg_put(alg); in crypto_larval_kill()
179 crypto_larval_kill(&larval->alg); in crypto_wait_for_test()
203 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg) in crypto_larval_wait() argument
205 struct crypto_larval *larval = (void *)alg; in crypto_larval_wait()
214 alg = larval->adult; in crypto_larval_wait()
216 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
218 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
219 else if (!alg) in crypto_larval_wait()
220 alg = ERR_PTR(-ENOENT); in crypto_larval_wait()
221 else if (IS_ERR(alg)) in crypto_larval_wait()
224 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
225 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
226 else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) in crypto_larval_wait()
227 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
228 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
229 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
230 crypto_mod_put(&larval->alg); in crypto_larval_wait()
232 return alg; in crypto_larval_wait()
239 struct crypto_alg *alg; in crypto_alg_lookup() local
246 alg = __crypto_alg_lookup(name, (type | test) & ~fips, in crypto_alg_lookup()
248 if (alg) { in crypto_alg_lookup()
253 if (!crypto_is_larval(alg) && in crypto_alg_lookup()
254 ((type ^ alg->cra_flags) & mask)) { in crypto_alg_lookup()
256 crypto_mod_put(alg); in crypto_alg_lookup()
257 alg = ERR_PTR(-ENOENT); in crypto_alg_lookup()
260 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
261 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
263 crypto_mod_put(alg); in crypto_alg_lookup()
264 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
269 return alg; in crypto_alg_lookup()
275 struct crypto_alg *alg; in crypto_larval_lookup() local
283 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
284 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
291 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
294 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
295 alg = crypto_larval_wait(alg); in crypto_larval_lookup()
296 else if (!alg) in crypto_larval_lookup()
297 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
299 return alg; in crypto_larval_lookup()
318 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
339 alg = crypto_larval_wait(larval); in crypto_alg_mod_lookup()
342 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
345 return alg; in crypto_alg_mod_lookup()
366 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
368 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
371 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
373 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
375 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
380 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
384 len += crypto_compress_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_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
406 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfm()
411 tfm->__crt_alg = alg; in __crypto_alloc_tfm()
417 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfm()
426 crypto_shoot_alg(alg); in __crypto_alloc_tfm()
463 struct crypto_alg *alg; in crypto_alloc_base() local
465 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
466 if (IS_ERR(alg)) { in crypto_alloc_base()
467 err = PTR_ERR(alg); in crypto_alloc_base()
471 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
475 crypto_mod_put(alg); in crypto_alloc_base()
491 void *crypto_create_tfm_node(struct crypto_alg *alg, in crypto_create_tfm_node() argument
502 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_create_tfm_node()
509 tfm->__crt_alg = alg; in crypto_create_tfm_node()
516 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm_node()
525 crypto_shoot_alg(alg); in crypto_create_tfm_node()
580 struct crypto_alg *alg; in crypto_alloc_tfm_node() local
582 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm_node()
583 if (IS_ERR(alg)) { in crypto_alloc_tfm_node()
584 err = PTR_ERR(alg); in crypto_alloc_tfm_node()
588 tfm = crypto_create_tfm_node(alg, frontend, node); in crypto_alloc_tfm_node()
592 crypto_mod_put(alg); in crypto_alloc_tfm_node()
618 struct crypto_alg *alg; in crypto_destroy_tfm() local
623 alg = tfm->__crt_alg; in crypto_destroy_tfm()
625 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
626 alg->cra_exit(tfm); in crypto_destroy_tfm()
628 crypto_mod_put(alg); in crypto_destroy_tfm()
636 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
638 if (!IS_ERR(alg)) { in crypto_has_alg()
639 crypto_mod_put(alg); in crypto_has_alg()