Lines Matching refs:alg

28 static inline int crypto_set_driver_name(struct crypto_alg *alg)  in crypto_set_driver_name()  argument
31 char *driver_name = alg->cra_driver_name; in crypto_set_driver_name()
37 len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); in crypto_set_driver_name()
52 static int crypto_check_alg(struct crypto_alg *alg) in crypto_check_alg() argument
54 crypto_check_module_sig(alg->cra_module); in crypto_check_alg()
56 if (alg->cra_alignmask & (alg->cra_alignmask + 1)) in crypto_check_alg()
59 if (alg->cra_blocksize > PAGE_SIZE / 8) in crypto_check_alg()
62 if (alg->cra_priority < 0) in crypto_check_alg()
65 atomic_set(&alg->cra_refcnt, 1); in crypto_check_alg()
67 return crypto_set_driver_name(alg); in crypto_check_alg()
72 if (!inst->alg.cra_type->free) { in crypto_free_instance()
77 inst->alg.cra_type->free(inst); in crypto_free_instance()
80 static void crypto_destroy_instance(struct crypto_alg *alg) in crypto_destroy_instance() argument
82 struct crypto_instance *inst = (void *)alg; in crypto_destroy_instance()
89 static struct list_head *crypto_more_spawns(struct crypto_alg *alg, in crypto_more_spawns() argument
102 if (spawn->alg && &n->list != stack && !n->alg) in crypto_more_spawns()
103 n->alg = (n->list.next == stack) ? alg : in crypto_more_spawns()
105 list)->inst->alg; in crypto_more_spawns()
109 return &n->list == stack ? top : &n->inst->alg.cra_users; in crypto_more_spawns()
117 if (crypto_is_dead(&inst->alg)) in crypto_remove_instance()
120 inst->alg.cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_instance()
127 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, &inst->alg); in crypto_remove_instance()
128 list_move(&inst->alg.cra_list, list); in crypto_remove_instance()
130 inst->alg.cra_destroy = crypto_destroy_instance; in crypto_remove_instance()
132 BUG_ON(!list_empty(&inst->alg.cra_users)); in crypto_remove_instance()
135 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, in crypto_remove_spawns() argument
138 u32 new_type = (nalg ?: alg)->cra_flags; in crypto_remove_spawns()
145 spawns = &alg->cra_users; in crypto_remove_spawns()
147 if ((spawn->alg->cra_flags ^ new_type) & spawn->mask) in crypto_remove_spawns()
162 BUG_ON(&inst->alg == alg); in crypto_remove_spawns()
166 if (&inst->alg == nalg) in crypto_remove_spawns()
169 spawn->alg = NULL; in crypto_remove_spawns()
170 spawns = &inst->alg.cra_users; in crypto_remove_spawns()
172 } while ((spawns = crypto_more_spawns(alg, &stack, &top, in crypto_remove_spawns()
176 if (spawn->alg) in crypto_remove_spawns()
177 list_move(&spawn->list, &spawn->alg->cra_users); in crypto_remove_spawns()
184 static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) in __crypto_register_alg() argument
190 if (crypto_is_dead(alg)) in __crypto_register_alg()
193 INIT_LIST_HEAD(&alg->cra_users); in __crypto_register_alg()
196 alg->cra_flags &= ~CRYPTO_ALG_TESTED; in __crypto_register_alg()
201 if (q == alg) in __crypto_register_alg()
208 if (!strcmp(alg->cra_driver_name, q->cra_driver_name)) in __crypto_register_alg()
213 if (!strcmp(q->cra_driver_name, alg->cra_name) || in __crypto_register_alg()
214 !strcmp(q->cra_name, alg->cra_driver_name)) in __crypto_register_alg()
218 larval = crypto_larval_alloc(alg->cra_name, in __crypto_register_alg()
219 alg->cra_flags | CRYPTO_ALG_TESTED, 0); in __crypto_register_alg()
224 larval->adult = crypto_mod_get(alg); in __crypto_register_alg()
228 atomic_set(&larval->alg.cra_refcnt, 1); in __crypto_register_alg()
229 memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, in __crypto_register_alg()
231 larval->alg.cra_priority = alg->cra_priority; in __crypto_register_alg()
233 list_add(&alg->cra_list, &crypto_alg_list); in __crypto_register_alg()
234 list_add(&larval->alg.cra_list, &crypto_alg_list); in __crypto_register_alg()
249 struct crypto_alg *alg; in crypto_alg_tested() local
269 alg = test->adult; in crypto_alg_tested()
270 if (err || list_empty(&alg->cra_list)) in crypto_alg_tested()
273 alg->cra_flags |= CRYPTO_ALG_TESTED; in crypto_alg_tested()
276 if (q == alg) in crypto_alg_tested()
290 if (strcmp(alg->cra_name, q->cra_name) && in crypto_alg_tested()
291 strcmp(alg->cra_driver_name, q->cra_name)) in crypto_alg_tested()
296 if ((q->cra_flags ^ alg->cra_flags) & larval->mask) in crypto_alg_tested()
298 if (!crypto_mod_get(alg)) in crypto_alg_tested()
301 larval->adult = alg; in crypto_alg_tested()
305 if (strcmp(alg->cra_name, q->cra_name)) in crypto_alg_tested()
308 if (strcmp(alg->cra_driver_name, q->cra_driver_name) && in crypto_alg_tested()
309 q->cra_priority > alg->cra_priority) in crypto_alg_tested()
312 crypto_remove_spawns(q, &list, alg); in crypto_alg_tested()
327 struct crypto_alg *alg; in crypto_remove_final() local
330 list_for_each_entry_safe(alg, n, list, cra_list) { in crypto_remove_final()
331 list_del_init(&alg->cra_list); in crypto_remove_final()
332 crypto_alg_put(alg); in crypto_remove_final()
345 crypto_alg_tested(larval->alg.cra_driver_name, 0); in crypto_wait_for_test()
352 crypto_larval_kill(&larval->alg); in crypto_wait_for_test()
355 int crypto_register_alg(struct crypto_alg *alg) in crypto_register_alg() argument
360 err = crypto_check_alg(alg); in crypto_register_alg()
365 larval = __crypto_register_alg(alg); in crypto_register_alg()
376 static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list) in crypto_remove_alg() argument
378 if (unlikely(list_empty(&alg->cra_list))) in crypto_remove_alg()
381 alg->cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_alg()
383 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, alg); in crypto_remove_alg()
384 list_del_init(&alg->cra_list); in crypto_remove_alg()
385 crypto_remove_spawns(alg, list, NULL); in crypto_remove_alg()
390 int crypto_unregister_alg(struct crypto_alg *alg) in crypto_unregister_alg() argument
396 ret = crypto_remove_alg(alg, &list); in crypto_unregister_alg()
402 BUG_ON(atomic_read(&alg->cra_refcnt) != 1); in crypto_unregister_alg()
403 if (alg->cra_destroy) in crypto_unregister_alg()
404 alg->cra_destroy(alg); in crypto_unregister_alg()
483 int err = crypto_remove_alg(&inst->alg, &users); in crypto_unregister_template()
493 BUG_ON(atomic_read(&inst->alg.cra_refcnt) != 1); in crypto_unregister_template()
532 err = crypto_check_alg(&inst->alg); in crypto_register_instance()
536 inst->alg.cra_module = tmpl->module; in crypto_register_instance()
537 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; in crypto_register_instance()
539 if (unlikely(!crypto_mod_get(&inst->alg))) in crypto_register_instance()
544 larval = __crypto_register_alg(&inst->alg); in crypto_register_instance()
561 if (!(inst->alg.cra_flags & CRYPTO_ALG_TESTED)) in crypto_register_instance()
566 crypto_mod_put(&inst->alg); in crypto_register_instance()
577 crypto_remove_spawns(&inst->alg, &list, NULL); in crypto_unregister_instance()
588 int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, in crypto_init_spawn() argument
597 if (!crypto_is_moribund(alg)) { in crypto_init_spawn()
598 list_add(&spawn->list, &alg->cra_users); in crypto_init_spawn()
599 spawn->alg = alg; in crypto_init_spawn()
608 int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg, in crypto_init_spawn2() argument
614 if ((alg->cra_flags ^ frontend->type) & frontend->maskset) in crypto_init_spawn2()
618 err = crypto_init_spawn(spawn, alg, inst, frontend->maskset); in crypto_init_spawn2()
628 struct crypto_alg *alg; in crypto_grab_spawn() local
631 alg = crypto_find_alg(name, spawn->frontend, type, mask); in crypto_grab_spawn()
632 if (IS_ERR(alg)) in crypto_grab_spawn()
633 return PTR_ERR(alg); in crypto_grab_spawn()
635 err = crypto_init_spawn(spawn, alg, spawn->inst, mask); in crypto_grab_spawn()
636 crypto_mod_put(alg); in crypto_grab_spawn()
643 if (!spawn->alg) in crypto_drop_spawn()
654 struct crypto_alg *alg; in crypto_spawn_alg() local
658 alg = spawn->alg; in crypto_spawn_alg()
659 alg2 = alg; in crypto_spawn_alg()
665 if (alg) in crypto_spawn_alg()
666 crypto_shoot_alg(alg); in crypto_spawn_alg()
670 return alg; in crypto_spawn_alg()
676 struct crypto_alg *alg; in crypto_spawn_tfm() local
679 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm()
680 if (IS_ERR(alg)) in crypto_spawn_tfm()
681 return ERR_CAST(alg); in crypto_spawn_tfm()
684 if (unlikely((alg->cra_flags ^ type) & mask)) in crypto_spawn_tfm()
687 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_spawn_tfm()
694 crypto_mod_put(alg); in crypto_spawn_tfm()
701 struct crypto_alg *alg; in crypto_spawn_tfm2() local
704 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm2()
705 if (IS_ERR(alg)) in crypto_spawn_tfm2()
706 return ERR_CAST(alg); in crypto_spawn_tfm2()
708 tfm = crypto_create_tfm(alg, spawn->frontend); in crypto_spawn_tfm2()
715 crypto_mod_put(alg); in crypto_spawn_tfm2()
815 void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg, in crypto_alloc_instance2() argument
830 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, in crypto_alloc_instance2()
831 alg->cra_name) >= CRYPTO_MAX_ALG_NAME) in crypto_alloc_instance2()
834 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", in crypto_alloc_instance2()
835 name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) in crypto_alloc_instance2()
847 struct crypto_alg *alg) in crypto_alloc_instance() argument
853 inst = crypto_alloc_instance2(name, alg, 0); in crypto_alloc_instance()
858 err = crypto_init_spawn(spawn, alg, inst, in crypto_alloc_instance()
984 unsigned int crypto_alg_extsize(struct crypto_alg *alg) in crypto_alg_extsize() argument
986 return alg->cra_ctxsize + in crypto_alg_extsize()
987 (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1)); in crypto_alg_extsize()