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