Lines Matching refs:alg

32 static int crypto_check_alg(struct crypto_alg *alg)  in crypto_check_alg()  argument
34 crypto_check_module_sig(alg->cra_module); in crypto_check_alg()
36 if (!alg->cra_name[0] || !alg->cra_driver_name[0]) in crypto_check_alg()
39 if (alg->cra_alignmask & (alg->cra_alignmask + 1)) in crypto_check_alg()
43 if (alg->cra_alignmask > MAX_ALGAPI_ALIGNMASK) in crypto_check_alg()
46 if (alg->cra_blocksize > MAX_ALGAPI_BLOCKSIZE) in crypto_check_alg()
50 if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) == in crypto_check_alg()
52 if (alg->cra_alignmask > MAX_CIPHER_ALIGNMASK) in crypto_check_alg()
55 if (alg->cra_blocksize > MAX_CIPHER_BLOCKSIZE) in crypto_check_alg()
59 if (alg->cra_priority < 0) in crypto_check_alg()
62 refcount_set(&alg->cra_refcnt, 1); in crypto_check_alg()
69 inst->alg.cra_type->free(inst); in crypto_free_instance()
82 static void crypto_destroy_instance(struct crypto_alg *alg) in crypto_destroy_instance() argument
84 struct crypto_instance *inst = container_of(alg, in crypto_destroy_instance()
86 alg); in crypto_destroy_instance()
101 static struct list_head *crypto_more_spawns(struct crypto_alg *alg, in crypto_more_spawns() argument
122 return &n->inst->alg.cra_users; in crypto_more_spawns()
130 if (crypto_is_dead(&inst->alg)) in crypto_remove_instance()
133 inst->alg.cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_instance()
138 list_move(&inst->alg.cra_list, list); in crypto_remove_instance()
140 inst->alg.cra_destroy = crypto_destroy_instance; in crypto_remove_instance()
142 BUG_ON(!list_empty(&inst->alg.cra_users)); in crypto_remove_instance()
151 void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, in crypto_remove_spawns() argument
154 u32 new_type = (nalg ?: alg)->cra_flags; in crypto_remove_spawns()
161 spawns = &alg->cra_users; in crypto_remove_spawns()
163 if ((spawn->alg->cra_flags ^ new_type) & spawn->mask) in crypto_remove_spawns()
184 spawn->dead = !spawn->registered || &inst->alg != nalg; in crypto_remove_spawns()
189 BUG_ON(&inst->alg == alg); in crypto_remove_spawns()
191 if (&inst->alg == nalg) in crypto_remove_spawns()
194 spawns = &inst->alg.cra_users; in crypto_remove_spawns()
214 } while ((spawns = crypto_more_spawns(alg, &stack, &top, in crypto_remove_spawns()
224 list_move(&spawn->list, &spawn->alg->cra_users); in crypto_remove_spawns()
231 static void crypto_alg_finish_registration(struct crypto_alg *alg, in crypto_alg_finish_registration() argument
237 if (q == alg) in crypto_alg_finish_registration()
246 if (strcmp(alg->cra_name, q->cra_name)) in crypto_alg_finish_registration()
249 if (strcmp(alg->cra_driver_name, q->cra_driver_name) && in crypto_alg_finish_registration()
250 q->cra_priority > alg->cra_priority) in crypto_alg_finish_registration()
253 crypto_remove_spawns(q, algs_to_put, alg); in crypto_alg_finish_registration()
256 crypto_notify(CRYPTO_MSG_ALG_LOADED, alg); in crypto_alg_finish_registration()
259 static struct crypto_larval *crypto_alloc_test_larval(struct crypto_alg *alg) in crypto_alloc_test_larval() argument
265 (alg->cra_flags & CRYPTO_ALG_INTERNAL)) in crypto_alloc_test_larval()
268 larval = crypto_larval_alloc(alg->cra_name, in crypto_alloc_test_larval()
269 alg->cra_flags | CRYPTO_ALG_TESTED, 0); in crypto_alloc_test_larval()
273 larval->adult = crypto_mod_get(alg); in crypto_alloc_test_larval()
279 refcount_set(&larval->alg.cra_refcnt, 1); in crypto_alloc_test_larval()
280 memcpy(larval->alg.cra_driver_name, alg->cra_driver_name, in crypto_alloc_test_larval()
282 larval->alg.cra_priority = alg->cra_priority; in crypto_alloc_test_larval()
288 __crypto_register_alg(struct crypto_alg *alg, struct list_head *algs_to_put) in __crypto_register_alg() argument
294 if (crypto_is_dead(alg)) in __crypto_register_alg()
297 INIT_LIST_HEAD(&alg->cra_users); in __crypto_register_alg()
302 if (q == alg) in __crypto_register_alg()
309 if (!strcmp(alg->cra_driver_name, q->cra_driver_name)) in __crypto_register_alg()
314 if (!strcmp(q->cra_driver_name, alg->cra_name) || in __crypto_register_alg()
315 !strcmp(q->cra_driver_name, alg->cra_driver_name) || in __crypto_register_alg()
316 !strcmp(q->cra_name, alg->cra_driver_name)) in __crypto_register_alg()
320 larval = crypto_alloc_test_larval(alg); in __crypto_register_alg()
324 list_add(&alg->cra_list, &crypto_alg_list); in __crypto_register_alg()
328 alg->cra_flags &= ~CRYPTO_ALG_TESTED; in __crypto_register_alg()
330 list_add(&larval->alg.cra_list, &crypto_alg_list); in __crypto_register_alg()
332 alg->cra_flags |= CRYPTO_ALG_TESTED; in __crypto_register_alg()
333 crypto_alg_finish_registration(alg, algs_to_put); in __crypto_register_alg()
347 struct crypto_alg *alg; in crypto_alg_tested() local
368 alg = test->adult; in crypto_alg_tested()
370 if (crypto_is_dead(alg)) in crypto_alg_tested()
374 alg->cra_flags |= CRYPTO_ALG_FIPS_INTERNAL; in crypto_alg_tested()
378 alg->cra_flags &= ~CRYPTO_ALG_FIPS_INTERNAL; in crypto_alg_tested()
380 alg->cra_flags |= CRYPTO_ALG_TESTED; in crypto_alg_tested()
382 crypto_alg_finish_registration(alg, &list); in crypto_alg_tested()
385 list_del_init(&test->alg.cra_list); in crypto_alg_tested()
390 crypto_alg_put(&test->alg); in crypto_alg_tested()
397 struct crypto_alg *alg; in crypto_remove_final() local
400 list_for_each_entry_safe(alg, n, list, cra_list) { in crypto_remove_final()
401 list_del_init(&alg->cra_list); in crypto_remove_final()
402 crypto_alg_put(alg); in crypto_remove_final()
407 int crypto_register_alg(struct crypto_alg *alg) in crypto_register_alg() argument
413 alg->cra_flags &= ~CRYPTO_ALG_DEAD; in crypto_register_alg()
414 err = crypto_check_alg(alg); in crypto_register_alg()
419 larval = __crypto_register_alg(alg, &algs_to_put); in crypto_register_alg()
436 static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list) in crypto_remove_alg() argument
438 if (unlikely(list_empty(&alg->cra_list))) in crypto_remove_alg()
441 alg->cra_flags |= CRYPTO_ALG_DEAD; in crypto_remove_alg()
443 list_del_init(&alg->cra_list); in crypto_remove_alg()
444 crypto_remove_spawns(alg, list, NULL); in crypto_remove_alg()
449 void crypto_unregister_alg(struct crypto_alg *alg) in crypto_unregister_alg() argument
455 ret = crypto_remove_alg(alg, &list); in crypto_unregister_alg()
458 if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name)) in crypto_unregister_alg()
461 if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1)) in crypto_unregister_alg()
464 if (alg->cra_destroy) in crypto_unregister_alg()
465 alg->cra_destroy(alg); in crypto_unregister_alg()
554 int err = crypto_remove_alg(&inst->alg, &users); in crypto_unregister_template()
562 BUG_ON(refcount_read(&inst->alg.cra_refcnt) != 1); in crypto_unregister_template()
613 err = crypto_check_alg(&inst->alg); in crypto_register_instance()
617 inst->alg.cra_module = tmpl->module; in crypto_register_instance()
618 inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE; in crypto_register_instance()
633 fips_internal |= spawn->alg->cra_flags; in crypto_register_instance()
635 crypto_mod_put(spawn->alg); in crypto_register_instance()
640 inst->alg.cra_flags |= (fips_internal & CRYPTO_ALG_FIPS_INTERNAL); in crypto_register_instance()
642 larval = __crypto_register_alg(&inst->alg, &algs_to_put); in crypto_register_instance()
669 crypto_remove_spawns(&inst->alg, &list, NULL); in crypto_unregister_instance()
681 struct crypto_alg *alg; in crypto_grab_spawn() local
691 alg = crypto_find_alg(name, spawn->frontend, in crypto_grab_spawn()
693 if (IS_ERR(alg)) in crypto_grab_spawn()
694 return PTR_ERR(alg); in crypto_grab_spawn()
697 if (!crypto_is_moribund(alg)) { in crypto_grab_spawn()
698 list_add(&spawn->list, &alg->cra_users); in crypto_grab_spawn()
699 spawn->alg = alg; in crypto_grab_spawn()
703 inst->alg.cra_flags |= in crypto_grab_spawn()
704 (alg->cra_flags & CRYPTO_ALG_INHERITED_FLAGS); in crypto_grab_spawn()
709 crypto_mod_put(alg); in crypto_grab_spawn()
716 if (!spawn->alg) /* not yet initialized? */ in crypto_drop_spawn()
725 crypto_mod_put(spawn->alg); in crypto_drop_spawn()
731 struct crypto_alg *alg = ERR_PTR(-EAGAIN); in crypto_spawn_alg() local
737 alg = spawn->alg; in crypto_spawn_alg()
738 if (!crypto_mod_get(alg)) { in crypto_spawn_alg()
739 target = crypto_alg_get(alg); in crypto_spawn_alg()
741 alg = ERR_PTR(-EAGAIN); in crypto_spawn_alg()
751 return alg; in crypto_spawn_alg()
757 struct crypto_alg *alg; in crypto_spawn_tfm() local
760 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm()
761 if (IS_ERR(alg)) in crypto_spawn_tfm()
762 return ERR_CAST(alg); in crypto_spawn_tfm()
765 if (unlikely((alg->cra_flags ^ type) & mask)) in crypto_spawn_tfm()
768 tfm = __crypto_alloc_tfm(alg, type, mask); in crypto_spawn_tfm()
775 crypto_mod_put(alg); in crypto_spawn_tfm()
782 struct crypto_alg *alg; in crypto_spawn_tfm2() local
785 alg = crypto_spawn_alg(spawn); in crypto_spawn_tfm2()
786 if (IS_ERR(alg)) in crypto_spawn_tfm2()
787 return ERR_CAST(alg); in crypto_spawn_tfm2()
789 tfm = crypto_create_tfm(alg, spawn->frontend); in crypto_spawn_tfm2()
796 crypto_mod_put(alg); in crypto_spawn_tfm2()
882 struct crypto_alg *alg) in crypto_inst_setname() argument
884 if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name, in crypto_inst_setname()
885 alg->cra_name) >= CRYPTO_MAX_ALG_NAME) in crypto_inst_setname()
888 if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", in crypto_inst_setname()
889 name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME) in crypto_inst_setname()
989 unsigned int crypto_alg_extsize(struct crypto_alg *alg) in crypto_alg_extsize() argument
991 return alg->cra_ctxsize + in crypto_alg_extsize()
992 (alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1)); in crypto_alg_extsize()
1000 struct crypto_alg *alg = crypto_find_alg(name, frontend, type, mask); in crypto_type_has_alg() local
1002 if (!IS_ERR(alg)) { in crypto_type_has_alg()
1003 crypto_mod_put(alg); in crypto_type_has_alg()