14 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/list.h>
18 #include <linux/module.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/slab.h>
21 #include <linux/string.h>
27 static inline int crypto_set_driver_name(
struct crypto_alg *alg)
29 static const char suffix[] =
"-generic";
40 memcpy(driver_name + len, suffix,
sizeof(suffix));
44 static int crypto_check_alg(
struct crypto_alg *alg)
55 return crypto_set_driver_name(alg);
58 static void crypto_destroy_instance(
struct crypto_alg *alg)
64 crypto_tmpl_put(tmpl);
74 if (list_empty(stack))
80 if (spawn->
alg && &n->
list != stack && !n->
alg)
85 list_move(&spawn->
list, secondary_spawns);
87 return &n->
list == stack ? top : &n->
inst->alg.cra_users;
90 static void crypto_remove_spawn(
struct crypto_spawn *spawn,
96 if (crypto_is_dead(&inst->
alg))
100 if (hlist_unhashed(&inst->
list))
103 if (!tmpl || !crypto_tmpl_get(tmpl))
107 list_move(&inst->
alg.cra_list, list);
108 hlist_del(&inst->
list);
109 inst->
alg.cra_destroy = crypto_destroy_instance;
111 BUG_ON(!list_empty(&inst->
alg.cra_users));
117 u32 new_type = (nalg ?: alg)->cra_flags;
126 if ((spawn->
alg->cra_flags ^ new_type) & spawn->
mask)
129 list_move(&spawn->
list, &top);
134 while (!list_empty(spawns)) {
143 list_move(&spawn->
list, &stack);
145 if (&inst->
alg == nalg)
149 spawns = &inst->
alg.cra_users;
151 }
while ((spawns = crypto_more_spawns(alg, &stack, &top,
152 &secondary_spawns)));
156 list_move(&spawn->
list, &spawn->
alg->cra_users);
158 crypto_remove_spawn(spawn, list);
169 if (crypto_is_dead(alg))
184 if (crypto_is_moribund(q))
187 if (crypto_is_larval(q)) {
213 list_add(&alg->
cra_list, &crypto_alg_list);
214 list_add(&larval->
alg.cra_list, &crypto_alg_list);
222 larval = ERR_PTR(ret);
235 if (crypto_is_moribund(q) || !crypto_is_larval(q))
244 printk(
KERN_ERR "alg: Unexpected test result for %s: %d\n", name, err);
250 if (err || list_empty(&alg->
cra_list))
259 if (crypto_is_moribund(q))
262 if (crypto_is_larval(q)) {
317 static void crypto_wait_for_test(
struct crypto_larval *larval)
322 if (err != NOTIFY_STOP) {
323 if (
WARN_ON(err != NOTIFY_DONE))
340 err = crypto_check_alg(alg);
345 larval = __crypto_register_alg(alg);
349 return PTR_ERR(larval);
351 crypto_wait_for_test(larval);
376 ret = crypto_remove_alg(alg, &list);
395 for (i = 0; i <
count; i++) {
404 for (--i; i >= 0; --
i)
415 for (i = 0; i <
count; i++) {
418 pr_err(
"Failed to unregister %s %s: %d\n",
419 algs[i].cra_driver_name, algs[i].cra_name, ret);
438 list_add(&tmpl->
list, &crypto_template_list);
457 list_del_init(&tmpl->
list);
461 int err = crypto_remove_alg(&inst->
alg, &users);
508 err = crypto_check_alg(&inst->
alg);
517 larval = __crypto_register_alg(&inst->
alg);
527 err = PTR_ERR(larval);
531 crypto_wait_for_test(larval);
553 hlist_del_init(&inst->
list);
554 err = crypto_remove_alg(alg, &users);
577 if (!crypto_is_moribund(alg)) {
643 alg = crypto_spawn_alg(spawn);
645 return ERR_CAST(alg);
668 alg = crypto_spawn_alg(spawn);
670 return ERR_CAST(alg);
698 struct rtattr *rta = tb[0];
720 return PTR_ERR(algt);
722 if ((algt->
type ^ type) & algt->
mask)
788 p = kzalloc(head +
sizeof(*inst) +
sizeof(
struct crypto_spawn),
793 inst = (
void *)(p + head);
823 spawn = crypto_instance_ctx(inst);
843 INIT_LIST_HEAD(&queue->
list);
883 request = queue->
list.next;
910 static inline void crypto_inc_byte(
u8 *
a,
unsigned int size)
915 for (;
size; size--) {
928 for (; size >= 4; size -= 4) {
935 crypto_inc_byte(a, size);
939 static inline void crypto_xor_byte(
u8 *a,
const u8 *b,
unsigned int size)
950 for (; size >= 4; size -= 4)
953 crypto_xor_byte((
u8 *)a, (
u8 *)b, size);
957 static int __init crypto_algapi_init(
void)
963 static void __exit crypto_algapi_exit(
void)