Lines Matching refs:alg
33 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
35 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) in crypto_mod_get() argument
37 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
41 void crypto_mod_put(struct crypto_alg *alg) in crypto_mod_put() argument
43 struct module *module = alg->cra_module; in crypto_mod_put()
45 crypto_alg_put(alg); in crypto_mod_put()
52 return larval->alg.cra_driver_name[0]; in crypto_is_test_larval()
58 struct crypto_alg *q, *alg = NULL; in __crypto_alg_lookup() local
84 if (alg) in __crypto_alg_lookup()
85 crypto_mod_put(alg); in __crypto_alg_lookup()
86 alg = q; in __crypto_alg_lookup()
92 return alg; in __crypto_alg_lookup()
95 static void crypto_larval_destroy(struct crypto_alg *alg) in crypto_larval_destroy() argument
97 struct crypto_larval *larval = (void *)alg; in crypto_larval_destroy()
99 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 strlcpy(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()
154 void crypto_larval_kill(struct crypto_alg *alg) in crypto_larval_kill() argument
156 struct crypto_larval *larval = (void *)alg; in crypto_larval_kill()
159 list_del(&alg->cra_list); in crypto_larval_kill()
162 crypto_alg_put(alg); in crypto_larval_kill()
166 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg) in crypto_larval_wait() argument
168 struct crypto_larval *larval = (void *)alg; in crypto_larval_wait()
174 alg = larval->adult; in crypto_larval_wait()
176 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
178 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
179 else if (!alg) in crypto_larval_wait()
180 alg = ERR_PTR(-ENOENT); in crypto_larval_wait()
182 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
183 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
184 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
185 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
186 crypto_mod_put(&larval->alg); in crypto_larval_wait()
188 return alg; in crypto_larval_wait()
194 struct crypto_alg *alg; in crypto_alg_lookup() local
201 alg = __crypto_alg_lookup(name, type | test, mask | test); in crypto_alg_lookup()
202 if (!alg && test) { in crypto_alg_lookup()
203 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
204 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
206 crypto_mod_put(alg); in crypto_alg_lookup()
207 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
212 return alg; in crypto_alg_lookup()
218 struct crypto_alg *alg; in crypto_larval_lookup() local
226 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
227 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
234 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
237 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
238 alg = crypto_larval_wait(alg); in crypto_larval_lookup()
239 else if (!alg) in crypto_larval_lookup()
240 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
242 return alg; in crypto_larval_lookup()
261 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
282 alg = crypto_larval_wait(larval); in crypto_alg_mod_lookup()
285 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
288 return alg; in crypto_alg_mod_lookup()
322 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
324 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
327 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
329 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
331 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
336 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
340 len += crypto_compress_ctxsize(alg); in crypto_ctxsize()
347 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
350 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
355 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
362 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfm()
367 tfm->__crt_alg = alg; in __crypto_alloc_tfm()
373 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfm()
382 crypto_shoot_alg(alg); in __crypto_alloc_tfm()
419 struct crypto_alg *alg; in crypto_alloc_base() local
421 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
422 if (IS_ERR(alg)) { in crypto_alloc_base()
423 err = PTR_ERR(alg); in crypto_alloc_base()
427 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
431 crypto_mod_put(alg); in crypto_alloc_base()
447 void *crypto_create_tfm(struct crypto_alg *alg, in crypto_create_tfm() argument
457 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_create_tfm()
464 tfm->__crt_alg = alg; in crypto_create_tfm()
470 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm()
479 crypto_shoot_alg(alg); in crypto_create_tfm()
530 struct crypto_alg *alg; in crypto_alloc_tfm() local
532 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm()
533 if (IS_ERR(alg)) { in crypto_alloc_tfm()
534 err = PTR_ERR(alg); in crypto_alloc_tfm()
538 tfm = crypto_create_tfm(alg, frontend); in crypto_alloc_tfm()
542 crypto_mod_put(alg); in crypto_alloc_tfm()
568 struct crypto_alg *alg; in crypto_destroy_tfm() local
573 alg = tfm->__crt_alg; in crypto_destroy_tfm()
575 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
576 alg->cra_exit(tfm); in crypto_destroy_tfm()
578 crypto_mod_put(alg); in crypto_destroy_tfm()
586 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
588 if (!IS_ERR(alg)) { in crypto_has_alg()
589 crypto_mod_put(alg); in crypto_has_alg()