Lines Matching refs:alg

38 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
40 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg) in crypto_mod_get() argument
42 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL; in crypto_mod_get()
46 void crypto_mod_put(struct crypto_alg *alg) in crypto_mod_put() argument
48 struct module *module = alg->cra_module; in crypto_mod_put()
50 crypto_alg_put(alg); in crypto_mod_put()
57 return larval->alg.cra_driver_name[0]; in crypto_is_test_larval()
63 struct crypto_alg *q, *alg = NULL; in __crypto_alg_lookup() local
89 if (alg) in __crypto_alg_lookup()
90 crypto_mod_put(alg); in __crypto_alg_lookup()
91 alg = q; in __crypto_alg_lookup()
97 return alg; in __crypto_alg_lookup()
100 static void crypto_larval_destroy(struct crypto_alg *alg) in crypto_larval_destroy() argument
102 struct crypto_larval *larval = (void *)alg; in crypto_larval_destroy()
104 BUG_ON(!crypto_is_larval(alg)); in crypto_larval_destroy()
119 larval->alg.cra_flags = CRYPTO_ALG_LARVAL | type; in crypto_larval_alloc()
120 larval->alg.cra_priority = -1; in crypto_larval_alloc()
121 larval->alg.cra_destroy = crypto_larval_destroy; in crypto_larval_alloc()
123 strlcpy(larval->alg.cra_name, name, CRYPTO_MAX_ALG_NAME); in crypto_larval_alloc()
133 struct crypto_alg *alg; in crypto_larval_add() local
140 refcount_set(&larval->alg.cra_refcnt, 2); in crypto_larval_add()
143 alg = __crypto_alg_lookup(name, type, mask); in crypto_larval_add()
144 if (!alg) { in crypto_larval_add()
145 alg = &larval->alg; in crypto_larval_add()
146 list_add(&alg->cra_list, &crypto_alg_list); in crypto_larval_add()
150 if (alg != &larval->alg) { in crypto_larval_add()
152 if (crypto_is_larval(alg)) in crypto_larval_add()
153 alg = crypto_larval_wait(alg); in crypto_larval_add()
156 return alg; in crypto_larval_add()
159 void crypto_larval_kill(struct crypto_alg *alg) in crypto_larval_kill() argument
161 struct crypto_larval *larval = (void *)alg; in crypto_larval_kill()
164 list_del(&alg->cra_list); in crypto_larval_kill()
167 crypto_alg_put(alg); in crypto_larval_kill()
171 static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg) in crypto_larval_wait() argument
173 struct crypto_larval *larval = (void *)alg; in crypto_larval_wait()
179 alg = larval->adult; in crypto_larval_wait()
181 alg = ERR_PTR(-EINTR); in crypto_larval_wait()
183 alg = ERR_PTR(-ETIMEDOUT); in crypto_larval_wait()
184 else if (!alg) in crypto_larval_wait()
185 alg = ERR_PTR(-ENOENT); in crypto_larval_wait()
187 !(alg->cra_flags & CRYPTO_ALG_TESTED)) in crypto_larval_wait()
188 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
189 else if (!crypto_mod_get(alg)) in crypto_larval_wait()
190 alg = ERR_PTR(-EAGAIN); in crypto_larval_wait()
191 crypto_mod_put(&larval->alg); in crypto_larval_wait()
193 return alg; in crypto_larval_wait()
199 struct crypto_alg *alg; in crypto_alg_lookup() local
206 alg = __crypto_alg_lookup(name, type | test, mask | test); in crypto_alg_lookup()
207 if (!alg && test) { in crypto_alg_lookup()
208 alg = __crypto_alg_lookup(name, type, mask); in crypto_alg_lookup()
209 if (alg && !crypto_is_larval(alg)) { in crypto_alg_lookup()
211 crypto_mod_put(alg); in crypto_alg_lookup()
212 alg = ERR_PTR(-ELIBBAD); in crypto_alg_lookup()
217 return alg; in crypto_alg_lookup()
223 struct crypto_alg *alg; in crypto_larval_lookup() local
231 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
232 if (!alg && !(mask & CRYPTO_NOLOAD)) { in crypto_larval_lookup()
239 alg = crypto_alg_lookup(name, type, mask); in crypto_larval_lookup()
242 if (!IS_ERR_OR_NULL(alg) && crypto_is_larval(alg)) in crypto_larval_lookup()
243 alg = crypto_larval_wait(alg); in crypto_larval_lookup()
244 else if (!alg) in crypto_larval_lookup()
245 alg = crypto_larval_add(name, type, mask); in crypto_larval_lookup()
247 return alg; in crypto_larval_lookup()
266 struct crypto_alg *alg; in crypto_alg_mod_lookup() local
287 alg = crypto_larval_wait(larval); in crypto_alg_mod_lookup()
290 alg = ERR_PTR(-ENOENT); in crypto_alg_mod_lookup()
293 return alg; in crypto_alg_mod_lookup()
327 static unsigned int crypto_ctxsize(struct crypto_alg *alg, u32 type, u32 mask) in crypto_ctxsize() argument
329 const struct crypto_type *type_obj = alg->cra_type; in crypto_ctxsize()
332 len = alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1); in crypto_ctxsize()
334 return len + type_obj->ctxsize(alg, type, mask); in crypto_ctxsize()
336 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { in crypto_ctxsize()
341 len += crypto_cipher_ctxsize(alg); in crypto_ctxsize()
345 len += crypto_compress_ctxsize(alg); in crypto_ctxsize()
352 void crypto_shoot_alg(struct crypto_alg *alg) in crypto_shoot_alg() argument
355 alg->cra_flags |= CRYPTO_ALG_DYING; in crypto_shoot_alg()
360 struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, in __crypto_alloc_tfm() argument
367 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, type, mask); in __crypto_alloc_tfm()
372 tfm->__crt_alg = alg; in __crypto_alloc_tfm()
378 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in __crypto_alloc_tfm()
387 crypto_shoot_alg(alg); in __crypto_alloc_tfm()
424 struct crypto_alg *alg; in crypto_alloc_base() local
426 alg = crypto_alg_mod_lookup(alg_name, type, mask); in crypto_alloc_base()
427 if (IS_ERR(alg)) { in crypto_alloc_base()
428 err = PTR_ERR(alg); in crypto_alloc_base()
432 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_alloc_base()
436 crypto_mod_put(alg); in crypto_alloc_base()
452 void *crypto_create_tfm(struct crypto_alg *alg, in crypto_create_tfm() argument
462 total = tfmsize + sizeof(*tfm) + frontend->extsize(alg); in crypto_create_tfm()
469 tfm->__crt_alg = alg; in crypto_create_tfm()
475 if (!tfm->exit && alg->cra_init && (err = alg->cra_init(tfm))) in crypto_create_tfm()
484 crypto_shoot_alg(alg); in crypto_create_tfm()
535 struct crypto_alg *alg; in crypto_alloc_tfm() local
537 alg = crypto_find_alg(alg_name, frontend, type, mask); in crypto_alloc_tfm()
538 if (IS_ERR(alg)) { in crypto_alloc_tfm()
539 err = PTR_ERR(alg); in crypto_alloc_tfm()
543 tfm = crypto_create_tfm(alg, frontend); in crypto_alloc_tfm()
547 crypto_mod_put(alg); in crypto_alloc_tfm()
573 struct crypto_alg *alg; in crypto_destroy_tfm() local
578 alg = tfm->__crt_alg; in crypto_destroy_tfm()
580 if (!tfm->exit && alg->cra_exit) in crypto_destroy_tfm()
581 alg->cra_exit(tfm); in crypto_destroy_tfm()
583 crypto_mod_put(alg); in crypto_destroy_tfm()
591 struct crypto_alg *alg = crypto_alg_mod_lookup(name, type, mask); in crypto_has_alg() local
593 if (!IS_ERR(alg)) { in crypto_has_alg()
594 crypto_mod_put(alg); in crypto_has_alg()