Lines Matching refs:alg

27 static inline int crypto_set_driver_name(struct crypto_alg *alg)  in crypto_set_driver_name()  argument
30 char *driver_name = alg->cra_driver_name; in crypto_set_driver_name()
36 len = strlcpy(driver_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); in crypto_set_driver_name()
54 static int crypto_check_alg(struct crypto_alg *alg) in crypto_check_alg() argument
56 crypto_check_module_sig(alg->cra_module); in crypto_check_alg()
58 if (alg->cra_alignmask & (alg->cra_alignmask + 1)) in crypto_check_alg()
61 if (alg->cra_blocksize > PAGE_SIZE / 8) in crypto_check_alg()
64 if (alg->cra_priority < 0) in crypto_check_alg()
67 atomic_set(&alg->cra_refcnt, 1); in crypto_check_alg()
69 return crypto_set_driver_name(alg); in crypto_check_alg()
72 static void crypto_destroy_instance(struct crypto_alg *alg) in crypto_destroy_instance() argument
74 struct crypto_instance *inst = (void *)alg; in crypto_destroy_instance()
81 static struct list_head *crypto_more_spawns(struct crypto_alg *alg, in crypto_more_spawns() argument
94 if (spawn->alg && &n->list != stack && !n->alg) in crypto_more_spawns()
95 n->alg = (n->list.next == stack) ? alg : in crypto_more_spawns()
97 list)->inst->alg; in crypto_more_spawns()
101 return &n->list == stack ? top : &n->inst->alg.cra_users; in crypto_more_spawns()
109 if (crypto_is_dead(&inst->alg)) in crypto_remove_instance()
112 inst->alg.cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_instance()
119 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, &inst->alg); in crypto_remove_instance()
120 list_move(&inst->alg.cra_list, list); in crypto_remove_instance()
122 inst->alg.cra_destroy = crypto_destroy_instance; in crypto_remove_instance()
124 BUG_ON(!list_empty(&inst->alg.cra_users)); in crypto_remove_instance()
127 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, in crypto_remove_spawns() argument
130 u32 new_type = (nalg ?: alg)->cra_flags; in crypto_remove_spawns()
137 spawns = &alg->cra_users; in crypto_remove_spawns()
139 if ((spawn->alg->cra_flags ^ new_type) & spawn->mask) in crypto_remove_spawns()
154 BUG_ON(&inst->alg == alg); in crypto_remove_spawns()
158 if (&inst->alg == nalg) in crypto_remove_spawns()
161 spawn->alg = NULL; in crypto_remove_spawns()
162 spawns = &inst->alg.cra_users; in crypto_remove_spawns()
164 } while ((spawns = crypto_more_spawns(alg, &stack, &top, in crypto_remove_spawns()
168 if (spawn->alg) in crypto_remove_spawns()
169 list_move(&spawn->list, &spawn->alg->cra_users); in crypto_remove_spawns()
176 static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg) in __crypto_register_alg() argument
182 if (crypto_is_dead(alg)) in __crypto_register_alg()
185 INIT_LIST_HEAD(&alg->cra_users); in __crypto_register_alg()
188 alg->cra_flags &= ~CRYPTO_ALG_TESTED; in __crypto_register_alg()
193 if (q == alg) in __crypto_register_alg()
200 if (!strcmp(alg->cra_driver_name, q->cra_driver_name)) in __crypto_register_alg()
205 if (!strcmp(q->cra_driver_name, alg->cra_name) || in __crypto_register_alg()
206 !strcmp(q->cra_name, alg->cra_driver_name)) in __crypto_register_alg()
210 larval = crypto_larval_alloc(alg->cra_name, in __crypto_register_alg()
211 alg->cra_flags | CRYPTO_ALG_TESTED, 0); in __crypto_register_alg()
216 larval->adult = crypto_mod_get(alg); in __crypto_register_alg()
220 atomic_set(&larval->alg.cra_refcnt, 1); in __crypto_register_alg()
221 memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, in __crypto_register_alg()
223 larval->alg.cra_priority = alg->cra_priority; in __crypto_register_alg()
225 list_add(&alg->cra_list, &crypto_alg_list); in __crypto_register_alg()
226 list_add(&larval->alg.cra_list, &crypto_alg_list); in __crypto_register_alg()
241 struct crypto_alg *alg; in crypto_alg_tested() local
261 alg = test->adult; in crypto_alg_tested()
262 if (err || list_empty(&alg->cra_list)) in crypto_alg_tested()
265 alg->cra_flags |= CRYPTO_ALG_TESTED; in crypto_alg_tested()
268 if (q == alg) in crypto_alg_tested()
282 if (strcmp(alg->cra_name, q->cra_name) && in crypto_alg_tested()
283 strcmp(alg->cra_driver_name, q->cra_name)) in crypto_alg_tested()
288 if ((q->cra_flags ^ alg->cra_flags) & larval->mask) in crypto_alg_tested()
290 if (!crypto_mod_get(alg)) in crypto_alg_tested()
293 larval->adult = alg; in crypto_alg_tested()
297 if (strcmp(alg->cra_name, q->cra_name)) in crypto_alg_tested()
300 if (strcmp(alg->cra_driver_name, q->cra_driver_name) && in crypto_alg_tested()
301 q->cra_priority > alg->cra_priority) in crypto_alg_tested()
304 crypto_remove_spawns(q, &list, alg); in crypto_alg_tested()
319 struct crypto_alg *alg; in crypto_remove_final() local
322 list_for_each_entry_safe(alg, n, list, cra_list) { in crypto_remove_final()
323 list_del_init(&alg->cra_list); in crypto_remove_final()
324 crypto_alg_put(alg); in crypto_remove_final()
337 crypto_alg_tested(larval->alg.cra_driver_name, 0); in crypto_wait_for_test()
344 crypto_larval_kill(&larval->alg); in crypto_wait_for_test()
347 int crypto_register_alg(struct crypto_alg *alg) in crypto_register_alg() argument
352 err = crypto_check_alg(alg); in crypto_register_alg()
357 larval = __crypto_register_alg(alg); in crypto_register_alg()
368 static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list) in crypto_remove_alg() argument
370 if (unlikely(list_empty(&alg->cra_list))) in crypto_remove_alg()
373 alg->cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_alg()
375 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER, alg); in crypto_remove_alg()
376 list_del_init(&alg->cra_list); in crypto_remove_alg()
377 crypto_remove_spawns(alg, list, NULL); in crypto_remove_alg()
382 int crypto_unregister_alg(struct crypto_alg *alg) in crypto_unregister_alg() argument
388 ret = crypto_remove_alg(alg, &list); in crypto_unregister_alg()
394 BUG_ON(atomic_read(&alg->cra_refcnt) != 1); in crypto_unregister_alg()
395 if (alg->cra_destroy) in crypto_unregister_alg()
396 alg->cra_destroy(alg); in crypto_unregister_alg()
475 int err = crypto_remove_alg(&inst->alg, &users); in crypto_unregister_template()
485 BUG_ON(atomic_read(&inst->alg.cra_refcnt) != 1); in crypto_unregister_template()
524 err = crypto_check_alg(&inst->alg); in crypto_register_instance()
528 inst->alg.cra_module = tmpl->module; in crypto_register_instance()
529 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; in crypto_register_instance()
531 if (unlikely(!crypto_mod_get(&inst->alg))) in crypto_register_instance()
536 larval = __crypto_register_alg(&inst->alg); in crypto_register_instance()
553 if (!(inst->alg.cra_flags & CRYPTO_ALG_TESTED)) in crypto_register_instance()
558 crypto_mod_put(&inst->alg); in crypto_register_instance()
569 crypto_remove_spawns(&inst->alg, &list, NULL); in crypto_unregister_instance()
580 int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, in crypto_init_spawn() argument
589 if (!crypto_is_moribund(alg)) { in crypto_init_spawn()
590 list_add(&spawn->list, &alg->cra_users); in crypto_init_spawn()
591 spawn->alg = alg; in crypto_init_spawn()
600 int crypto_init_spawn2(struct crypto_spawn *spawn, struct crypto_alg *alg, in crypto_init_spawn2() argument
606 if ((alg->cra_flags ^ frontend->type) & frontend->maskset) in crypto_init_spawn2()
610 err = crypto_init_spawn(spawn, alg, inst, frontend->maskset); in crypto_init_spawn2()
619 if (!spawn->alg) in crypto_drop_spawn()
630 struct crypto_alg *alg; in crypto_spawn_alg() local
634 alg = spawn->alg; in crypto_spawn_alg()
635 alg2 = alg; in crypto_spawn_alg()
641 if (alg) in crypto_spawn_alg()
642 crypto_shoot_alg(alg); in crypto_spawn_alg()
646 return alg; in crypto_spawn_alg()
652 struct crypto_alg *alg; in crypto_spawn_tfm() local
655 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm()
656 if (IS_ERR(alg)) in crypto_spawn_tfm()
657 return ERR_CAST(alg); in crypto_spawn_tfm()
660 if (unlikely((alg->cra_flags ^ type) & mask)) in crypto_spawn_tfm()
663 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_spawn_tfm()
670 crypto_mod_put(alg); in crypto_spawn_tfm()
677 struct crypto_alg *alg; in crypto_spawn_tfm2() local
680 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm2()
681 if (IS_ERR(alg)) in crypto_spawn_tfm2()
682 return ERR_CAST(alg); in crypto_spawn_tfm2()
684 tfm = crypto_create_tfm(alg, spawn->frontend); in crypto_spawn_tfm2()
691 crypto_mod_put(alg); in crypto_spawn_tfm2()
791 void *crypto_alloc_instance2(const char *name, struct crypto_alg *alg, in crypto_alloc_instance2() argument
806 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, in crypto_alloc_instance2()
807 alg->cra_name) >= CRYPTO_MAX_ALG_NAME) in crypto_alloc_instance2()
810 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", in crypto_alloc_instance2()
811 name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) in crypto_alloc_instance2()
823 struct crypto_alg *alg) in crypto_alloc_instance() argument
829 inst = crypto_alloc_instance2(name, alg, 0); in crypto_alloc_instance()
834 err = crypto_init_spawn(spawn, alg, inst, in crypto_alloc_instance()