2 * Cryptographic API for algorithms (i.e., low-level API).
4 * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <linux/err.h>
14 #include <linux/errno.h>
15 #include <linux/fips.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/list.h>
19 #include <linux/module.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/slab.h>
22 #include <linux/string.h>
26 static LIST_HEAD(crypto_template_list
);
28 static inline int crypto_set_driver_name(struct crypto_alg
*alg
)
30 static const char suffix
[] = "-generic";
31 char *driver_name
= alg
->cra_driver_name
;
37 len
= strlcpy(driver_name
, alg
->cra_name
, CRYPTO_MAX_ALG_NAME
);
38 if (len
+ sizeof(suffix
) > CRYPTO_MAX_ALG_NAME
)
41 memcpy(driver_name
+ len
, suffix
, sizeof(suffix
));
45 static inline void crypto_check_module_sig(struct module
*mod
)
47 if (fips_enabled
&& mod
&& !module_sig_ok(mod
))
48 panic("Module %s signature verification failed in FIPS mode\n",
52 static int crypto_check_alg(struct crypto_alg
*alg
)
54 crypto_check_module_sig(alg
->cra_module
);
56 if (alg
->cra_alignmask
& (alg
->cra_alignmask
+ 1))
59 if (alg
->cra_blocksize
> PAGE_SIZE
/ 8)
62 if (alg
->cra_priority
< 0)
65 atomic_set(&alg
->cra_refcnt
, 1);
67 return crypto_set_driver_name(alg
);
70 static void crypto_free_instance(struct crypto_instance
*inst
)
72 if (!inst
->alg
.cra_type
->free
) {
73 inst
->tmpl
->free(inst
);
77 inst
->alg
.cra_type
->free(inst
);
80 static void crypto_destroy_instance(struct crypto_alg
*alg
)
82 struct crypto_instance
*inst
= (void *)alg
;
83 struct crypto_template
*tmpl
= inst
->tmpl
;
85 crypto_free_instance(inst
);
86 crypto_tmpl_put(tmpl
);
89 static struct list_head
*crypto_more_spawns(struct crypto_alg
*alg
,
90 struct list_head
*stack
,
91 struct list_head
*top
,
92 struct list_head
*secondary_spawns
)
94 struct crypto_spawn
*spawn
, *n
;
96 if (list_empty(stack
))
99 spawn
= list_first_entry(stack
, struct crypto_spawn
, list
);
100 n
= list_entry(spawn
->list
.next
, struct crypto_spawn
, list
);
102 if (spawn
->alg
&& &n
->list
!= stack
&& !n
->alg
)
103 n
->alg
= (n
->list
.next
== stack
) ? alg
:
104 &list_entry(n
->list
.next
, struct crypto_spawn
,
107 list_move(&spawn
->list
, secondary_spawns
);
109 return &n
->list
== stack
? top
: &n
->inst
->alg
.cra_users
;
112 static void crypto_remove_instance(struct crypto_instance
*inst
,
113 struct list_head
*list
)
115 struct crypto_template
*tmpl
= inst
->tmpl
;
117 if (crypto_is_dead(&inst
->alg
))
120 inst
->alg
.cra_flags
|= CRYPTO_ALG_DEAD
;
121 if (hlist_unhashed(&inst
->list
))
124 if (!tmpl
|| !crypto_tmpl_get(tmpl
))
127 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER
, &inst
->alg
);
128 list_move(&inst
->alg
.cra_list
, list
);
129 hlist_del(&inst
->list
);
130 inst
->alg
.cra_destroy
= crypto_destroy_instance
;
132 BUG_ON(!list_empty(&inst
->alg
.cra_users
));
135 void crypto_remove_spawns(struct crypto_alg
*alg
, struct list_head
*list
,
136 struct crypto_alg
*nalg
)
138 u32 new_type
= (nalg
?: alg
)->cra_flags
;
139 struct crypto_spawn
*spawn
, *n
;
140 LIST_HEAD(secondary_spawns
);
141 struct list_head
*spawns
;
145 spawns
= &alg
->cra_users
;
146 list_for_each_entry_safe(spawn
, n
, spawns
, list
) {
147 if ((spawn
->alg
->cra_flags
^ new_type
) & spawn
->mask
)
150 list_move(&spawn
->list
, &top
);
155 while (!list_empty(spawns
)) {
156 struct crypto_instance
*inst
;
158 spawn
= list_first_entry(spawns
, struct crypto_spawn
,
162 BUG_ON(&inst
->alg
== alg
);
164 list_move(&spawn
->list
, &stack
);
166 if (&inst
->alg
== nalg
)
170 spawns
= &inst
->alg
.cra_users
;
173 * We may encounter an unregistered instance here, since
174 * an instance's spawns are set up prior to the instance
175 * being registered. An unregistered instance will have
176 * NULL ->cra_users.next, since ->cra_users isn't
177 * properly initialized until registration. But an
178 * unregistered instance cannot have any users, so treat
179 * it the same as ->cra_users being empty.
181 if (spawns
->next
== NULL
)
184 } while ((spawns
= crypto_more_spawns(alg
, &stack
, &top
,
185 &secondary_spawns
)));
187 list_for_each_entry_safe(spawn
, n
, &secondary_spawns
, list
) {
189 list_move(&spawn
->list
, &spawn
->alg
->cra_users
);
191 crypto_remove_instance(spawn
->inst
, list
);
194 EXPORT_SYMBOL_GPL(crypto_remove_spawns
);
196 static struct crypto_larval
*__crypto_register_alg(struct crypto_alg
*alg
)
198 struct crypto_alg
*q
;
199 struct crypto_larval
*larval
;
202 if (crypto_is_dead(alg
))
205 INIT_LIST_HEAD(&alg
->cra_users
);
208 alg
->cra_flags
&= ~CRYPTO_ALG_TESTED
;
212 list_for_each_entry(q
, &crypto_alg_list
, cra_list
) {
216 if (crypto_is_moribund(q
))
219 if (crypto_is_larval(q
)) {
220 if (!strcmp(alg
->cra_driver_name
, q
->cra_driver_name
))
225 if (!strcmp(q
->cra_driver_name
, alg
->cra_name
) ||
226 !strcmp(q
->cra_name
, alg
->cra_driver_name
))
230 larval
= crypto_larval_alloc(alg
->cra_name
,
231 alg
->cra_flags
| CRYPTO_ALG_TESTED
, 0);
236 larval
->adult
= crypto_mod_get(alg
);
240 atomic_set(&larval
->alg
.cra_refcnt
, 1);
241 memcpy(larval
->alg
.cra_driver_name
, alg
->cra_driver_name
,
242 CRYPTO_MAX_ALG_NAME
);
243 larval
->alg
.cra_priority
= alg
->cra_priority
;
245 list_add(&alg
->cra_list
, &crypto_alg_list
);
246 list_add(&larval
->alg
.cra_list
, &crypto_alg_list
);
254 larval
= ERR_PTR(ret
);
258 void crypto_alg_tested(const char *name
, int err
)
260 struct crypto_larval
*test
;
261 struct crypto_alg
*alg
;
262 struct crypto_alg
*q
;
265 down_write(&crypto_alg_sem
);
266 list_for_each_entry(q
, &crypto_alg_list
, cra_list
) {
267 if (crypto_is_moribund(q
) || !crypto_is_larval(q
))
270 test
= (struct crypto_larval
*)q
;
272 if (!strcmp(q
->cra_driver_name
, name
))
276 printk(KERN_ERR
"alg: Unexpected test result for %s: %d\n", name
, err
);
280 q
->cra_flags
|= CRYPTO_ALG_DEAD
;
282 if (err
|| list_empty(&alg
->cra_list
))
285 alg
->cra_flags
|= CRYPTO_ALG_TESTED
;
287 list_for_each_entry(q
, &crypto_alg_list
, cra_list
) {
291 if (crypto_is_moribund(q
))
294 if (crypto_is_larval(q
)) {
295 struct crypto_larval
*larval
= (void *)q
;
298 * Check to see if either our generic name or
299 * specific name can satisfy the name requested
300 * by the larval entry q.
302 if (strcmp(alg
->cra_name
, q
->cra_name
) &&
303 strcmp(alg
->cra_driver_name
, q
->cra_name
))
308 if ((q
->cra_flags
^ alg
->cra_flags
) & larval
->mask
)
310 if (!crypto_mod_get(alg
))
317 if (strcmp(alg
->cra_name
, q
->cra_name
))
320 if (strcmp(alg
->cra_driver_name
, q
->cra_driver_name
) &&
321 q
->cra_priority
> alg
->cra_priority
)
324 crypto_remove_spawns(q
, &list
, alg
);
328 complete_all(&test
->completion
);
331 up_write(&crypto_alg_sem
);
333 crypto_remove_final(&list
);
335 EXPORT_SYMBOL_GPL(crypto_alg_tested
);
337 void crypto_remove_final(struct list_head
*list
)
339 struct crypto_alg
*alg
;
340 struct crypto_alg
*n
;
342 list_for_each_entry_safe(alg
, n
, list
, cra_list
) {
343 list_del_init(&alg
->cra_list
);
347 EXPORT_SYMBOL_GPL(crypto_remove_final
);
349 static void crypto_wait_for_test(struct crypto_larval
*larval
)
353 err
= crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER
, larval
->adult
);
354 if (err
!= NOTIFY_STOP
) {
355 if (WARN_ON(err
!= NOTIFY_DONE
))
357 crypto_alg_tested(larval
->alg
.cra_driver_name
, 0);
360 err
= wait_for_completion_killable(&larval
->completion
);
364 crypto_larval_kill(&larval
->alg
);
367 int crypto_register_alg(struct crypto_alg
*alg
)
369 struct crypto_larval
*larval
;
372 alg
->cra_flags
&= ~CRYPTO_ALG_DEAD
;
373 err
= crypto_check_alg(alg
);
377 down_write(&crypto_alg_sem
);
378 larval
= __crypto_register_alg(alg
);
379 up_write(&crypto_alg_sem
);
382 return PTR_ERR(larval
);
384 crypto_wait_for_test(larval
);
387 EXPORT_SYMBOL_GPL(crypto_register_alg
);
389 static int crypto_remove_alg(struct crypto_alg
*alg
, struct list_head
*list
)
391 if (unlikely(list_empty(&alg
->cra_list
)))
394 alg
->cra_flags
|= CRYPTO_ALG_DEAD
;
396 crypto_notify(CRYPTO_MSG_ALG_UNREGISTER
, alg
);
397 list_del_init(&alg
->cra_list
);
398 crypto_remove_spawns(alg
, list
, NULL
);
403 int crypto_unregister_alg(struct crypto_alg
*alg
)
408 down_write(&crypto_alg_sem
);
409 ret
= crypto_remove_alg(alg
, &list
);
410 up_write(&crypto_alg_sem
);
415 BUG_ON(atomic_read(&alg
->cra_refcnt
) != 1);
416 if (alg
->cra_destroy
)
417 alg
->cra_destroy(alg
);
419 crypto_remove_final(&list
);
422 EXPORT_SYMBOL_GPL(crypto_unregister_alg
);
424 int crypto_register_algs(struct crypto_alg
*algs
, int count
)
428 for (i
= 0; i
< count
; i
++) {
429 ret
= crypto_register_alg(&algs
[i
]);
437 for (--i
; i
>= 0; --i
)
438 crypto_unregister_alg(&algs
[i
]);
442 EXPORT_SYMBOL_GPL(crypto_register_algs
);
444 int crypto_unregister_algs(struct crypto_alg
*algs
, int count
)
448 for (i
= 0; i
< count
; i
++) {
449 ret
= crypto_unregister_alg(&algs
[i
]);
451 pr_err("Failed to unregister %s %s: %d\n",
452 algs
[i
].cra_driver_name
, algs
[i
].cra_name
, ret
);
457 EXPORT_SYMBOL_GPL(crypto_unregister_algs
);
459 int crypto_register_template(struct crypto_template
*tmpl
)
461 struct crypto_template
*q
;
464 down_write(&crypto_alg_sem
);
466 crypto_check_module_sig(tmpl
->module
);
468 list_for_each_entry(q
, &crypto_template_list
, list
) {
473 list_add(&tmpl
->list
, &crypto_template_list
);
474 crypto_notify(CRYPTO_MSG_TMPL_REGISTER
, tmpl
);
477 up_write(&crypto_alg_sem
);
480 EXPORT_SYMBOL_GPL(crypto_register_template
);
482 void crypto_unregister_template(struct crypto_template
*tmpl
)
484 struct crypto_instance
*inst
;
485 struct hlist_node
*n
;
486 struct hlist_head
*list
;
489 down_write(&crypto_alg_sem
);
491 BUG_ON(list_empty(&tmpl
->list
));
492 list_del_init(&tmpl
->list
);
494 list
= &tmpl
->instances
;
495 hlist_for_each_entry(inst
, list
, list
) {
496 int err
= crypto_remove_alg(&inst
->alg
, &users
);
501 crypto_notify(CRYPTO_MSG_TMPL_UNREGISTER
, tmpl
);
503 up_write(&crypto_alg_sem
);
505 hlist_for_each_entry_safe(inst
, n
, list
, list
) {
506 BUG_ON(atomic_read(&inst
->alg
.cra_refcnt
) != 1);
507 crypto_free_instance(inst
);
509 crypto_remove_final(&users
);
511 EXPORT_SYMBOL_GPL(crypto_unregister_template
);
513 static struct crypto_template
*__crypto_lookup_template(const char *name
)
515 struct crypto_template
*q
, *tmpl
= NULL
;
517 down_read(&crypto_alg_sem
);
518 list_for_each_entry(q
, &crypto_template_list
, list
) {
519 if (strcmp(q
->name
, name
))
521 if (unlikely(!crypto_tmpl_get(q
)))
527 up_read(&crypto_alg_sem
);
532 struct crypto_template
*crypto_lookup_template(const char *name
)
534 return try_then_request_module(__crypto_lookup_template(name
),
537 EXPORT_SYMBOL_GPL(crypto_lookup_template
);
539 int crypto_register_instance(struct crypto_template
*tmpl
,
540 struct crypto_instance
*inst
)
542 struct crypto_larval
*larval
;
545 err
= crypto_check_alg(&inst
->alg
);
549 inst
->alg
.cra_module
= tmpl
->module
;
550 inst
->alg
.cra_flags
|= CRYPTO_ALG_INSTANCE
;
552 if (unlikely(!crypto_mod_get(&inst
->alg
)))
555 down_write(&crypto_alg_sem
);
557 larval
= __crypto_register_alg(&inst
->alg
);
561 hlist_add_head(&inst
->list
, &tmpl
->instances
);
565 up_write(&crypto_alg_sem
);
567 err
= PTR_ERR(larval
);
571 crypto_wait_for_test(larval
);
573 /* Remove instance if test failed */
574 if (!(inst
->alg
.cra_flags
& CRYPTO_ALG_TESTED
))
575 crypto_unregister_instance(inst
);
579 crypto_mod_put(&inst
->alg
);
582 EXPORT_SYMBOL_GPL(crypto_register_instance
);
584 int crypto_unregister_instance(struct crypto_instance
*inst
)
588 down_write(&crypto_alg_sem
);
590 crypto_remove_spawns(&inst
->alg
, &list
, NULL
);
591 crypto_remove_instance(inst
, &list
);
593 up_write(&crypto_alg_sem
);
595 crypto_remove_final(&list
);
599 EXPORT_SYMBOL_GPL(crypto_unregister_instance
);
601 int crypto_init_spawn(struct crypto_spawn
*spawn
, struct crypto_alg
*alg
,
602 struct crypto_instance
*inst
, u32 mask
)
609 down_write(&crypto_alg_sem
);
610 if (!crypto_is_moribund(alg
)) {
611 list_add(&spawn
->list
, &alg
->cra_users
);
615 up_write(&crypto_alg_sem
);
619 EXPORT_SYMBOL_GPL(crypto_init_spawn
);
621 int crypto_init_spawn2(struct crypto_spawn
*spawn
, struct crypto_alg
*alg
,
622 struct crypto_instance
*inst
,
623 const struct crypto_type
*frontend
)
627 if ((alg
->cra_flags
^ frontend
->type
) & frontend
->maskset
)
630 spawn
->frontend
= frontend
;
631 err
= crypto_init_spawn(spawn
, alg
, inst
, frontend
->maskset
);
636 EXPORT_SYMBOL_GPL(crypto_init_spawn2
);
638 int crypto_grab_spawn(struct crypto_spawn
*spawn
, const char *name
,
641 struct crypto_alg
*alg
;
644 alg
= crypto_find_alg(name
, spawn
->frontend
, type
, mask
);
648 err
= crypto_init_spawn(spawn
, alg
, spawn
->inst
, mask
);
652 EXPORT_SYMBOL_GPL(crypto_grab_spawn
);
654 void crypto_drop_spawn(struct crypto_spawn
*spawn
)
659 down_write(&crypto_alg_sem
);
660 list_del(&spawn
->list
);
661 up_write(&crypto_alg_sem
);
663 EXPORT_SYMBOL_GPL(crypto_drop_spawn
);
665 static struct crypto_alg
*crypto_spawn_alg(struct crypto_spawn
*spawn
)
667 struct crypto_alg
*alg
;
668 struct crypto_alg
*alg2
;
670 down_read(&crypto_alg_sem
);
674 alg2
= crypto_mod_get(alg2
);
675 up_read(&crypto_alg_sem
);
679 crypto_shoot_alg(alg
);
680 return ERR_PTR(-EAGAIN
);
686 struct crypto_tfm
*crypto_spawn_tfm(struct crypto_spawn
*spawn
, u32 type
,
689 struct crypto_alg
*alg
;
690 struct crypto_tfm
*tfm
;
692 alg
= crypto_spawn_alg(spawn
);
694 return ERR_CAST(alg
);
696 tfm
= ERR_PTR(-EINVAL
);
697 if (unlikely((alg
->cra_flags
^ type
) & mask
))
700 tfm
= __crypto_alloc_tfm(alg
, type
, mask
);
710 EXPORT_SYMBOL_GPL(crypto_spawn_tfm
);
712 void *crypto_spawn_tfm2(struct crypto_spawn
*spawn
)
714 struct crypto_alg
*alg
;
715 struct crypto_tfm
*tfm
;
717 alg
= crypto_spawn_alg(spawn
);
719 return ERR_CAST(alg
);
721 tfm
= crypto_create_tfm(alg
, spawn
->frontend
);
731 EXPORT_SYMBOL_GPL(crypto_spawn_tfm2
);
733 int crypto_register_notifier(struct notifier_block
*nb
)
735 return blocking_notifier_chain_register(&crypto_chain
, nb
);
737 EXPORT_SYMBOL_GPL(crypto_register_notifier
);
739 int crypto_unregister_notifier(struct notifier_block
*nb
)
741 return blocking_notifier_chain_unregister(&crypto_chain
, nb
);
743 EXPORT_SYMBOL_GPL(crypto_unregister_notifier
);
745 struct crypto_attr_type
*crypto_get_attr_type(struct rtattr
**tb
)
747 struct rtattr
*rta
= tb
[0];
748 struct crypto_attr_type
*algt
;
751 return ERR_PTR(-ENOENT
);
752 if (RTA_PAYLOAD(rta
) < sizeof(*algt
))
753 return ERR_PTR(-EINVAL
);
754 if (rta
->rta_type
!= CRYPTOA_TYPE
)
755 return ERR_PTR(-EINVAL
);
757 algt
= RTA_DATA(rta
);
761 EXPORT_SYMBOL_GPL(crypto_get_attr_type
);
763 int crypto_check_attr_type(struct rtattr
**tb
, u32 type
)
765 struct crypto_attr_type
*algt
;
767 algt
= crypto_get_attr_type(tb
);
769 return PTR_ERR(algt
);
771 if ((algt
->type
^ type
) & algt
->mask
)
776 EXPORT_SYMBOL_GPL(crypto_check_attr_type
);
778 const char *crypto_attr_alg_name(struct rtattr
*rta
)
780 struct crypto_attr_alg
*alga
;
783 return ERR_PTR(-ENOENT
);
784 if (RTA_PAYLOAD(rta
) < sizeof(*alga
))
785 return ERR_PTR(-EINVAL
);
786 if (rta
->rta_type
!= CRYPTOA_ALG
)
787 return ERR_PTR(-EINVAL
);
789 alga
= RTA_DATA(rta
);
790 alga
->name
[CRYPTO_MAX_ALG_NAME
- 1] = 0;
794 EXPORT_SYMBOL_GPL(crypto_attr_alg_name
);
796 struct crypto_alg
*crypto_attr_alg2(struct rtattr
*rta
,
797 const struct crypto_type
*frontend
,
802 name
= crypto_attr_alg_name(rta
);
804 return ERR_CAST(name
);
806 return crypto_find_alg(name
, frontend
, type
, mask
);
808 EXPORT_SYMBOL_GPL(crypto_attr_alg2
);
810 int crypto_attr_u32(struct rtattr
*rta
, u32
*num
)
812 struct crypto_attr_u32
*nu32
;
816 if (RTA_PAYLOAD(rta
) < sizeof(*nu32
))
818 if (rta
->rta_type
!= CRYPTOA_U32
)
821 nu32
= RTA_DATA(rta
);
826 EXPORT_SYMBOL_GPL(crypto_attr_u32
);
828 void *crypto_alloc_instance2(const char *name
, struct crypto_alg
*alg
,
831 struct crypto_instance
*inst
;
835 p
= kzalloc(head
+ sizeof(*inst
) + sizeof(struct crypto_spawn
),
838 return ERR_PTR(-ENOMEM
);
840 inst
= (void *)(p
+ head
);
843 if (snprintf(inst
->alg
.cra_name
, CRYPTO_MAX_ALG_NAME
, "%s(%s)", name
,
844 alg
->cra_name
) >= CRYPTO_MAX_ALG_NAME
)
847 if (snprintf(inst
->alg
.cra_driver_name
, CRYPTO_MAX_ALG_NAME
, "%s(%s)",
848 name
, alg
->cra_driver_name
) >= CRYPTO_MAX_ALG_NAME
)
857 EXPORT_SYMBOL_GPL(crypto_alloc_instance2
);
859 struct crypto_instance
*crypto_alloc_instance(const char *name
,
860 struct crypto_alg
*alg
)
862 struct crypto_instance
*inst
;
863 struct crypto_spawn
*spawn
;
866 inst
= crypto_alloc_instance2(name
, alg
, 0);
870 spawn
= crypto_instance_ctx(inst
);
871 err
= crypto_init_spawn(spawn
, alg
, inst
,
872 CRYPTO_ALG_TYPE_MASK
| CRYPTO_ALG_ASYNC
);
886 EXPORT_SYMBOL_GPL(crypto_alloc_instance
);
888 void crypto_init_queue(struct crypto_queue
*queue
, unsigned int max_qlen
)
890 INIT_LIST_HEAD(&queue
->list
);
891 queue
->backlog
= &queue
->list
;
893 queue
->max_qlen
= max_qlen
;
895 EXPORT_SYMBOL_GPL(crypto_init_queue
);
897 int crypto_enqueue_request(struct crypto_queue
*queue
,
898 struct crypto_async_request
*request
)
900 int err
= -EINPROGRESS
;
902 if (unlikely(queue
->qlen
>= queue
->max_qlen
)) {
904 if (!(request
->flags
& CRYPTO_TFM_REQ_MAY_BACKLOG
))
906 if (queue
->backlog
== &queue
->list
)
907 queue
->backlog
= &request
->list
;
911 list_add_tail(&request
->list
, &queue
->list
);
916 EXPORT_SYMBOL_GPL(crypto_enqueue_request
);
918 struct crypto_async_request
*crypto_dequeue_request(struct crypto_queue
*queue
)
920 struct list_head
*request
;
922 if (unlikely(!queue
->qlen
))
927 if (queue
->backlog
!= &queue
->list
)
928 queue
->backlog
= queue
->backlog
->next
;
930 request
= queue
->list
.next
;
933 return list_entry(request
, struct crypto_async_request
, list
);
935 EXPORT_SYMBOL_GPL(crypto_dequeue_request
);
937 int crypto_tfm_in_queue(struct crypto_queue
*queue
, struct crypto_tfm
*tfm
)
939 struct crypto_async_request
*req
;
941 list_for_each_entry(req
, &queue
->list
, list
) {
948 EXPORT_SYMBOL_GPL(crypto_tfm_in_queue
);
950 static inline void crypto_inc_byte(u8
*a
, unsigned int size
)
955 for (; size
; size
--) {
963 void crypto_inc(u8
*a
, unsigned int size
)
965 __be32
*b
= (__be32
*)(a
+ size
);
968 for (; size
>= 4; size
-= 4) {
969 c
= be32_to_cpu(*--b
) + 1;
975 crypto_inc_byte(a
, size
);
977 EXPORT_SYMBOL_GPL(crypto_inc
);
979 static inline void crypto_xor_byte(u8
*a
, const u8
*b
, unsigned int size
)
985 void crypto_xor(u8
*dst
, const u8
*src
, unsigned int size
)
990 for (; size
>= 4; size
-= 4)
993 crypto_xor_byte((u8
*)a
, (u8
*)b
, size
);
995 EXPORT_SYMBOL_GPL(crypto_xor
);
997 unsigned int crypto_alg_extsize(struct crypto_alg
*alg
)
999 return alg
->cra_ctxsize
+
1000 (alg
->cra_alignmask
& ~(crypto_tfm_ctx_alignment() - 1));
1002 EXPORT_SYMBOL_GPL(crypto_alg_extsize
);
1004 static int __init
crypto_algapi_init(void)
1010 static void __exit
crypto_algapi_exit(void)
1015 module_init(crypto_algapi_init
);
1016 module_exit(crypto_algapi_exit
);
1018 MODULE_LICENSE("GPL");
1019 MODULE_DESCRIPTION("Cryptographic algorithms API");