2 * Algorithm testing framework and tests.
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
6 * Copyright (c) 2007 Nokia Siemens Networks
7 * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
16 #include <crypto/hash.h>
17 #include <linux/err.h>
18 #include <linux/module.h>
19 #include <linux/scatterlist.h>
20 #include <linux/slab.h>
21 #include <linux/string.h>
22 #include <crypto/rng.h>
28 * Need slab memory for testing (size in number of pages).
33 * Indexes into the xbuf to simulate cross-page access.
45 * Used by test_cipher()
50 struct tcrypt_result
{
51 struct completion completion
;
55 struct aead_test_suite
{
57 struct aead_testvec
*vecs
;
62 struct cipher_test_suite
{
64 struct cipher_testvec
*vecs
;
69 struct comp_test_suite
{
71 struct comp_testvec
*vecs
;
76 struct pcomp_test_suite
{
78 struct pcomp_testvec
*vecs
;
83 struct hash_test_suite
{
84 struct hash_testvec
*vecs
;
88 struct cprng_test_suite
{
89 struct cprng_testvec
*vecs
;
93 struct alg_test_desc
{
95 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
99 struct aead_test_suite aead
;
100 struct cipher_test_suite cipher
;
101 struct comp_test_suite comp
;
102 struct pcomp_test_suite pcomp
;
103 struct hash_test_suite hash
;
104 struct cprng_test_suite cprng
;
108 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
110 static char *xbuf
[XBUFSIZE
];
111 static char *axbuf
[XBUFSIZE
];
113 static void hexdump(unsigned char *buf
, unsigned int len
)
115 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
120 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
122 struct tcrypt_result
*res
= req
->data
;
124 if (err
== -EINPROGRESS
)
128 complete(&res
->completion
);
131 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
134 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
135 unsigned int i
, j
, k
, temp
;
136 struct scatterlist sg
[8];
138 struct ahash_request
*req
;
139 struct tcrypt_result tresult
;
143 init_completion(&tresult
.completion
);
145 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
147 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
152 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
153 tcrypt_complete
, &tresult
);
155 for (i
= 0; i
< tcount
; i
++) {
156 memset(result
, 0, 64);
160 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
161 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
163 if (template[i
].ksize
) {
164 crypto_ahash_clear_flags(tfm
, ~0);
165 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
168 printk(KERN_ERR
"alg: hash: setkey failed on "
169 "test %d for %s: ret=%d\n", i
+ 1, algo
,
175 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
176 ret
= crypto_ahash_digest(req
);
182 ret
= wait_for_completion_interruptible(
183 &tresult
.completion
);
184 if (!ret
&& !(ret
= tresult
.err
)) {
185 INIT_COMPLETION(tresult
.completion
);
190 printk(KERN_ERR
"alg: hash: digest failed on test %d "
191 "for %s: ret=%d\n", i
+ 1, algo
, -ret
);
195 if (memcmp(result
, template[i
].digest
,
196 crypto_ahash_digestsize(tfm
))) {
197 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
199 hexdump(result
, crypto_ahash_digestsize(tfm
));
206 for (i
= 0; i
< tcount
; i
++) {
207 if (template[i
].np
) {
209 memset(result
, 0, 64);
212 sg_init_table(sg
, template[i
].np
);
213 for (k
= 0; k
< template[i
].np
; k
++) {
215 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
216 offset_in_page(IDX
[k
]),
217 template[i
].plaintext
+ temp
,
220 temp
+= template[i
].tap
[k
];
223 if (template[i
].ksize
) {
224 crypto_ahash_clear_flags(tfm
, ~0);
225 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
229 printk(KERN_ERR
"alg: hash: setkey "
230 "failed on chunking test %d "
231 "for %s: ret=%d\n", j
, algo
,
237 ahash_request_set_crypt(req
, sg
, result
,
239 ret
= crypto_ahash_digest(req
);
245 ret
= wait_for_completion_interruptible(
246 &tresult
.completion
);
247 if (!ret
&& !(ret
= tresult
.err
)) {
248 INIT_COMPLETION(tresult
.completion
);
253 printk(KERN_ERR
"alg: hash: digest failed "
254 "on chunking test %d for %s: "
255 "ret=%d\n", j
, algo
, -ret
);
259 if (memcmp(result
, template[i
].digest
,
260 crypto_ahash_digestsize(tfm
))) {
261 printk(KERN_ERR
"alg: hash: Chunking test %d "
262 "failed for %s\n", j
, algo
);
263 hexdump(result
, crypto_ahash_digestsize(tfm
));
273 ahash_request_free(req
);
278 static int test_aead(struct crypto_aead
*tfm
, int enc
,
279 struct aead_testvec
*template, unsigned int tcount
)
281 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
282 unsigned int i
, j
, k
, n
, temp
;
286 struct aead_request
*req
;
287 struct scatterlist sg
[8];
288 struct scatterlist asg
[8];
290 struct tcrypt_result result
;
291 unsigned int authsize
;
301 init_completion(&result
.completion
);
303 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
305 printk(KERN_ERR
"alg: aead: Failed to allocate request for "
311 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
312 tcrypt_complete
, &result
);
314 for (i
= 0, j
= 0; i
< tcount
; i
++) {
315 if (!template[i
].np
) {
318 /* some tepmplates have no input data but they will
324 memcpy(input
, template[i
].input
, template[i
].ilen
);
325 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
327 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
329 memset(iv
, 0, MAX_IVLEN
);
331 crypto_aead_clear_flags(tfm
, ~0);
333 crypto_aead_set_flags(
334 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
336 key
= template[i
].key
;
338 ret
= crypto_aead_setkey(tfm
, key
,
340 if (!ret
== template[i
].fail
) {
341 printk(KERN_ERR
"alg: aead: setkey failed on "
342 "test %d for %s: flags=%x\n", j
, algo
,
343 crypto_aead_get_flags(tfm
));
348 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
349 ret
= crypto_aead_setauthsize(tfm
, authsize
);
351 printk(KERN_ERR
"alg: aead: Failed to set "
352 "authsize to %u on test %d for %s\n",
357 sg_init_one(&sg
[0], input
,
358 template[i
].ilen
+ (enc
? authsize
: 0));
360 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
362 aead_request_set_crypt(req
, sg
, sg
,
363 template[i
].ilen
, iv
);
365 aead_request_set_assoc(req
, asg
, template[i
].alen
);
368 crypto_aead_encrypt(req
) :
369 crypto_aead_decrypt(req
);
373 if (template[i
].novrfy
) {
374 /* verification was supposed to fail */
375 printk(KERN_ERR
"alg: aead: %s failed "
376 "on test %d for %s: ret was 0, "
377 "expected -EBADMSG\n",
379 /* so really, we got a bad message */
386 ret
= wait_for_completion_interruptible(
388 if (!ret
&& !(ret
= result
.err
)) {
389 INIT_COMPLETION(result
.completion
);
393 if (template[i
].novrfy
)
394 /* verification failure was expected */
398 printk(KERN_ERR
"alg: aead: %s failed on test "
399 "%d for %s: ret=%d\n", e
, j
, algo
, -ret
);
404 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
405 printk(KERN_ERR
"alg: aead: Test %d failed on "
406 "%s for %s\n", j
, e
, algo
);
407 hexdump(q
, template[i
].rlen
);
414 for (i
= 0, j
= 0; i
< tcount
; i
++) {
415 if (template[i
].np
) {
419 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
421 memset(iv
, 0, MAX_IVLEN
);
423 crypto_aead_clear_flags(tfm
, ~0);
425 crypto_aead_set_flags(
426 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
427 key
= template[i
].key
;
429 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
430 if (!ret
== template[i
].fail
) {
431 printk(KERN_ERR
"alg: aead: setkey failed on "
432 "chunk test %d for %s: flags=%x\n", j
,
433 algo
, crypto_aead_get_flags(tfm
));
438 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
441 sg_init_table(sg
, template[i
].np
);
442 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
443 if (WARN_ON(offset_in_page(IDX
[k
]) +
444 template[i
].tap
[k
] > PAGE_SIZE
))
447 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
448 offset_in_page(IDX
[k
]);
450 memcpy(q
, template[i
].input
+ temp
,
453 n
= template[i
].tap
[k
];
454 if (k
== template[i
].np
- 1 && enc
)
456 if (offset_in_page(q
) + n
< PAGE_SIZE
)
459 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
460 temp
+= template[i
].tap
[k
];
463 ret
= crypto_aead_setauthsize(tfm
, authsize
);
465 printk(KERN_ERR
"alg: aead: Failed to set "
466 "authsize to %u on chunk test %d for "
467 "%s\n", authsize
, j
, algo
);
472 if (WARN_ON(sg
[k
- 1].offset
+
473 sg
[k
- 1].length
+ authsize
>
479 sg
[k
- 1].length
+= authsize
;
482 sg_init_table(asg
, template[i
].anp
);
483 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
485 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
486 offset_in_page(IDX
[k
]),
487 template[i
].assoc
+ temp
,
488 template[i
].atap
[k
]),
489 template[i
].atap
[k
]);
490 temp
+= template[i
].atap
[k
];
493 aead_request_set_crypt(req
, sg
, sg
,
497 aead_request_set_assoc(req
, asg
, template[i
].alen
);
500 crypto_aead_encrypt(req
) :
501 crypto_aead_decrypt(req
);
505 if (template[i
].novrfy
) {
506 /* verification was supposed to fail */
507 printk(KERN_ERR
"alg: aead: %s failed "
508 "on chunk test %d for %s: ret "
509 "was 0, expected -EBADMSG\n",
511 /* so really, we got a bad message */
518 ret
= wait_for_completion_interruptible(
520 if (!ret
&& !(ret
= result
.err
)) {
521 INIT_COMPLETION(result
.completion
);
525 if (template[i
].novrfy
)
526 /* verification failure was expected */
530 printk(KERN_ERR
"alg: aead: %s failed on "
531 "chunk test %d for %s: ret=%d\n", e
, j
,
537 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
538 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
539 offset_in_page(IDX
[k
]);
541 n
= template[i
].tap
[k
];
542 if (k
== template[i
].np
- 1)
543 n
+= enc
? authsize
: -authsize
;
545 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
546 printk(KERN_ERR
"alg: aead: Chunk "
547 "test %d failed on %s at page "
548 "%u for %s\n", j
, e
, k
, algo
);
554 if (k
== template[i
].np
- 1 && !enc
) {
555 if (memcmp(q
, template[i
].input
+
561 for (n
= 0; offset_in_page(q
+ n
) &&
566 printk(KERN_ERR
"alg: aead: Result "
567 "buffer corruption in chunk "
568 "test %d on %s at page %u for "
569 "%s: %u bytes:\n", j
, e
, k
,
575 temp
+= template[i
].tap
[k
];
583 aead_request_free(req
);
587 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
588 struct cipher_testvec
*template, unsigned int tcount
)
590 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
591 unsigned int i
, j
, k
;
603 for (i
= 0; i
< tcount
; i
++) {
610 memcpy(data
, template[i
].input
, template[i
].ilen
);
612 crypto_cipher_clear_flags(tfm
, ~0);
614 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
616 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
618 if (!ret
== template[i
].fail
) {
619 printk(KERN_ERR
"alg: cipher: setkey failed "
620 "on test %d for %s: flags=%x\n", j
,
621 algo
, crypto_cipher_get_flags(tfm
));
626 for (k
= 0; k
< template[i
].ilen
;
627 k
+= crypto_cipher_blocksize(tfm
)) {
629 crypto_cipher_encrypt_one(tfm
, data
+ k
,
632 crypto_cipher_decrypt_one(tfm
, data
+ k
,
637 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
638 printk(KERN_ERR
"alg: cipher: Test %d failed "
639 "on %s for %s\n", j
, e
, algo
);
640 hexdump(q
, template[i
].rlen
);
652 static int test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
653 struct cipher_testvec
*template, unsigned int tcount
)
656 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm
));
657 unsigned int i
, j
, k
, n
, temp
;
660 struct ablkcipher_request
*req
;
661 struct scatterlist sg
[8];
663 struct tcrypt_result result
;
672 init_completion(&result
.completion
);
674 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
676 printk(KERN_ERR
"alg: skcipher: Failed to allocate request "
682 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
683 tcrypt_complete
, &result
);
686 for (i
= 0; i
< tcount
; i
++) {
688 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
690 memset(iv
, 0, MAX_IVLEN
);
692 if (!(template[i
].np
)) {
696 memcpy(data
, template[i
].input
, template[i
].ilen
);
698 crypto_ablkcipher_clear_flags(tfm
, ~0);
700 crypto_ablkcipher_set_flags(
701 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
703 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
705 if (!ret
== template[i
].fail
) {
706 printk(KERN_ERR
"alg: skcipher: setkey failed "
707 "on test %d for %s: flags=%x\n", j
,
708 algo
, crypto_ablkcipher_get_flags(tfm
));
713 sg_init_one(&sg
[0], data
, template[i
].ilen
);
715 ablkcipher_request_set_crypt(req
, sg
, sg
,
716 template[i
].ilen
, iv
);
718 crypto_ablkcipher_encrypt(req
) :
719 crypto_ablkcipher_decrypt(req
);
726 ret
= wait_for_completion_interruptible(
728 if (!ret
&& !((ret
= result
.err
))) {
729 INIT_COMPLETION(result
.completion
);
734 printk(KERN_ERR
"alg: skcipher: %s failed on "
735 "test %d for %s: ret=%d\n", e
, j
, algo
,
741 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
742 printk(KERN_ERR
"alg: skcipher: Test %d "
743 "failed on %s for %s\n", j
, e
, algo
);
744 hexdump(q
, template[i
].rlen
);
752 for (i
= 0; i
< tcount
; i
++) {
755 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
757 memset(iv
, 0, MAX_IVLEN
);
759 if (template[i
].np
) {
762 crypto_ablkcipher_clear_flags(tfm
, ~0);
764 crypto_ablkcipher_set_flags(
765 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
767 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
769 if (!ret
== template[i
].fail
) {
770 printk(KERN_ERR
"alg: skcipher: setkey failed "
771 "on chunk test %d for %s: flags=%x\n",
773 crypto_ablkcipher_get_flags(tfm
));
780 sg_init_table(sg
, template[i
].np
);
781 for (k
= 0; k
< template[i
].np
; k
++) {
782 if (WARN_ON(offset_in_page(IDX
[k
]) +
783 template[i
].tap
[k
] > PAGE_SIZE
))
786 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
787 offset_in_page(IDX
[k
]);
789 memcpy(q
, template[i
].input
+ temp
,
792 if (offset_in_page(q
) + template[i
].tap
[k
] <
794 q
[template[i
].tap
[k
]] = 0;
796 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
798 temp
+= template[i
].tap
[k
];
801 ablkcipher_request_set_crypt(req
, sg
, sg
,
802 template[i
].ilen
, iv
);
805 crypto_ablkcipher_encrypt(req
) :
806 crypto_ablkcipher_decrypt(req
);
813 ret
= wait_for_completion_interruptible(
815 if (!ret
&& !((ret
= result
.err
))) {
816 INIT_COMPLETION(result
.completion
);
821 printk(KERN_ERR
"alg: skcipher: %s failed on "
822 "chunk test %d for %s: ret=%d\n", e
, j
,
829 for (k
= 0; k
< template[i
].np
; k
++) {
830 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
831 offset_in_page(IDX
[k
]);
833 if (memcmp(q
, template[i
].result
+ temp
,
834 template[i
].tap
[k
])) {
835 printk(KERN_ERR
"alg: skcipher: Chunk "
836 "test %d failed on %s at page "
837 "%u for %s\n", j
, e
, k
, algo
);
838 hexdump(q
, template[i
].tap
[k
]);
842 q
+= template[i
].tap
[k
];
843 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
846 printk(KERN_ERR
"alg: skcipher: "
847 "Result buffer corruption in "
848 "chunk test %d on %s at page "
849 "%u for %s: %u bytes:\n", j
, e
,
854 temp
+= template[i
].tap
[k
];
862 ablkcipher_request_free(req
);
866 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
867 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
869 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
871 char result
[COMP_BUF_SIZE
];
874 for (i
= 0; i
< ctcount
; i
++) {
876 unsigned int dlen
= COMP_BUF_SIZE
;
878 memset(result
, 0, sizeof (result
));
880 ilen
= ctemplate
[i
].inlen
;
881 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
882 ilen
, result
, &dlen
);
884 printk(KERN_ERR
"alg: comp: compression failed "
885 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
890 if (dlen
!= ctemplate
[i
].outlen
) {
891 printk(KERN_ERR
"alg: comp: Compression test %d "
892 "failed for %s: output len = %d\n", i
+ 1, algo
,
898 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
899 printk(KERN_ERR
"alg: comp: Compression test %d "
900 "failed for %s\n", i
+ 1, algo
);
901 hexdump(result
, dlen
);
907 for (i
= 0; i
< dtcount
; i
++) {
909 unsigned int dlen
= COMP_BUF_SIZE
;
911 memset(result
, 0, sizeof (result
));
913 ilen
= dtemplate
[i
].inlen
;
914 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
915 ilen
, result
, &dlen
);
917 printk(KERN_ERR
"alg: comp: decompression failed "
918 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
923 if (dlen
!= dtemplate
[i
].outlen
) {
924 printk(KERN_ERR
"alg: comp: Decompression test %d "
925 "failed for %s: output len = %d\n", i
+ 1, algo
,
931 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
932 printk(KERN_ERR
"alg: comp: Decompression test %d "
933 "failed for %s\n", i
+ 1, algo
);
934 hexdump(result
, dlen
);
946 static int test_pcomp(struct crypto_pcomp
*tfm
,
947 struct pcomp_testvec
*ctemplate
,
948 struct pcomp_testvec
*dtemplate
, int ctcount
,
951 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
953 char result
[COMP_BUF_SIZE
];
956 for (i
= 0; i
< ctcount
; i
++) {
957 struct comp_request req
;
959 error
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
960 ctemplate
[i
].paramsize
);
962 pr_err("alg: pcomp: compression setup failed on test "
963 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
967 error
= crypto_compress_init(tfm
);
969 pr_err("alg: pcomp: compression init failed on test "
970 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
974 memset(result
, 0, sizeof(result
));
976 req
.next_in
= ctemplate
[i
].input
;
977 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
978 req
.next_out
= result
;
979 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
981 error
= crypto_compress_update(tfm
, &req
);
982 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
983 pr_err("alg: pcomp: compression update failed on test "
984 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
988 /* Add remaining input data */
989 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
991 error
= crypto_compress_update(tfm
, &req
);
992 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
993 pr_err("alg: pcomp: compression update failed on test "
994 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
998 /* Provide remaining output space */
999 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1001 error
= crypto_compress_final(tfm
, &req
);
1003 pr_err("alg: pcomp: compression final failed on test "
1004 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1008 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1009 pr_err("alg: comp: Compression test %d failed for %s: "
1010 "output len = %d (expected %d)\n", i
+ 1, algo
,
1011 COMP_BUF_SIZE
- req
.avail_out
,
1012 ctemplate
[i
].outlen
);
1016 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1017 pr_err("alg: pcomp: Compression test %d failed for "
1018 "%s\n", i
+ 1, algo
);
1019 hexdump(result
, ctemplate
[i
].outlen
);
1024 for (i
= 0; i
< dtcount
; i
++) {
1025 struct comp_request req
;
1027 error
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1028 dtemplate
[i
].paramsize
);
1030 pr_err("alg: pcomp: decompression setup failed on "
1031 "test %d for %s: error=%d\n", i
+ 1, algo
,
1036 error
= crypto_decompress_init(tfm
);
1038 pr_err("alg: pcomp: decompression init failed on test "
1039 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1043 memset(result
, 0, sizeof(result
));
1045 req
.next_in
= dtemplate
[i
].input
;
1046 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1047 req
.next_out
= result
;
1048 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1050 error
= crypto_decompress_update(tfm
, &req
);
1051 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1052 pr_err("alg: pcomp: decompression update failed on "
1053 "test %d for %s: error=%d\n", i
+ 1, algo
,
1058 /* Add remaining input data */
1059 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1061 error
= crypto_decompress_update(tfm
, &req
);
1062 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1063 pr_err("alg: pcomp: decompression update failed on "
1064 "test %d for %s: error=%d\n", i
+ 1, algo
,
1069 /* Provide remaining output space */
1070 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1072 error
= crypto_decompress_final(tfm
, &req
);
1073 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1074 pr_err("alg: pcomp: decompression final failed on "
1075 "test %d for %s: error=%d\n", i
+ 1, algo
,
1080 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1081 pr_err("alg: comp: Decompression test %d failed for "
1082 "%s: output len = %d (expected %d)\n", i
+ 1,
1083 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1084 dtemplate
[i
].outlen
);
1088 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1089 pr_err("alg: pcomp: Decompression test %d failed for "
1090 "%s\n", i
+ 1, algo
);
1091 hexdump(result
, dtemplate
[i
].outlen
);
1100 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1101 unsigned int tcount
)
1103 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1104 int err
, i
, j
, seedsize
;
1108 seedsize
= crypto_rng_seedsize(tfm
);
1110 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1112 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1117 for (i
= 0; i
< tcount
; i
++) {
1118 memset(result
, 0, 32);
1120 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1121 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1123 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1124 template[i
].dt
, template[i
].dtlen
);
1126 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1128 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1133 for (j
= 0; j
< template[i
].loops
; j
++) {
1134 err
= crypto_rng_get_bytes(tfm
, result
,
1136 if (err
!= template[i
].rlen
) {
1137 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1138 "the correct amount of random data for "
1139 "%s (requested %d, got %d)\n", algo
,
1140 template[i
].rlen
, err
);
1145 err
= memcmp(result
, template[i
].result
,
1148 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1150 hexdump(result
, template[i
].rlen
);
1161 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1164 struct crypto_aead
*tfm
;
1167 tfm
= crypto_alloc_aead(driver
, type
, mask
);
1169 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1170 "%ld\n", driver
, PTR_ERR(tfm
));
1171 return PTR_ERR(tfm
);
1174 if (desc
->suite
.aead
.enc
.vecs
) {
1175 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1176 desc
->suite
.aead
.enc
.count
);
1181 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1182 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1183 desc
->suite
.aead
.dec
.count
);
1186 crypto_free_aead(tfm
);
1190 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1191 const char *driver
, u32 type
, u32 mask
)
1193 struct crypto_cipher
*tfm
;
1196 tfm
= crypto_alloc_cipher(driver
, type
, mask
);
1198 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1199 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1200 return PTR_ERR(tfm
);
1203 if (desc
->suite
.cipher
.enc
.vecs
) {
1204 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1205 desc
->suite
.cipher
.enc
.count
);
1210 if (desc
->suite
.cipher
.dec
.vecs
)
1211 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1212 desc
->suite
.cipher
.dec
.count
);
1215 crypto_free_cipher(tfm
);
1219 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1220 const char *driver
, u32 type
, u32 mask
)
1222 struct crypto_ablkcipher
*tfm
;
1225 tfm
= crypto_alloc_ablkcipher(driver
, type
, mask
);
1227 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1228 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1229 return PTR_ERR(tfm
);
1232 if (desc
->suite
.cipher
.enc
.vecs
) {
1233 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1234 desc
->suite
.cipher
.enc
.count
);
1239 if (desc
->suite
.cipher
.dec
.vecs
)
1240 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1241 desc
->suite
.cipher
.dec
.count
);
1244 crypto_free_ablkcipher(tfm
);
1248 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1251 struct crypto_comp
*tfm
;
1254 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1256 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1257 "%ld\n", driver
, PTR_ERR(tfm
));
1258 return PTR_ERR(tfm
);
1261 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1262 desc
->suite
.comp
.decomp
.vecs
,
1263 desc
->suite
.comp
.comp
.count
,
1264 desc
->suite
.comp
.decomp
.count
);
1266 crypto_free_comp(tfm
);
1270 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1273 struct crypto_pcomp
*tfm
;
1276 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1278 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1279 driver
, PTR_ERR(tfm
));
1280 return PTR_ERR(tfm
);
1283 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1284 desc
->suite
.pcomp
.decomp
.vecs
,
1285 desc
->suite
.pcomp
.comp
.count
,
1286 desc
->suite
.pcomp
.decomp
.count
);
1288 crypto_free_pcomp(tfm
);
1292 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1295 struct crypto_ahash
*tfm
;
1298 tfm
= crypto_alloc_ahash(driver
, type
, mask
);
1300 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1301 "%ld\n", driver
, PTR_ERR(tfm
));
1302 return PTR_ERR(tfm
);
1305 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
, desc
->suite
.hash
.count
);
1307 crypto_free_ahash(tfm
);
1311 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1312 const char *driver
, u32 type
, u32 mask
)
1314 struct crypto_shash
*tfm
;
1318 err
= alg_test_hash(desc
, driver
, type
, mask
);
1322 tfm
= crypto_alloc_shash(driver
, type
, mask
);
1324 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1325 "%ld\n", driver
, PTR_ERR(tfm
));
1332 struct shash_desc shash
;
1333 char ctx
[crypto_shash_descsize(tfm
)];
1336 sdesc
.shash
.tfm
= tfm
;
1337 sdesc
.shash
.flags
= 0;
1339 *(u32
*)sdesc
.ctx
= le32_to_cpu(420553207);
1340 err
= crypto_shash_final(&sdesc
.shash
, (u8
*)&val
);
1342 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1343 "%s: %d\n", driver
, err
);
1347 if (val
!= ~420553207) {
1348 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1349 "%d\n", driver
, val
);
1354 crypto_free_shash(tfm
);
1360 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1363 struct crypto_rng
*rng
;
1366 rng
= crypto_alloc_rng(driver
, type
, mask
);
1368 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1369 "%ld\n", driver
, PTR_ERR(rng
));
1370 return PTR_ERR(rng
);
1373 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1375 crypto_free_rng(rng
);
1380 /* Please keep this list sorted by algorithm name. */
1381 static const struct alg_test_desc alg_test_descs
[] = {
1383 .alg
= "ansi_cprng",
1384 .test
= alg_test_cprng
,
1387 .vecs
= ansi_cprng_aes_tv_template
,
1388 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1393 .test
= alg_test_skcipher
,
1397 .vecs
= aes_cbc_enc_tv_template
,
1398 .count
= AES_CBC_ENC_TEST_VECTORS
1401 .vecs
= aes_cbc_dec_tv_template
,
1402 .count
= AES_CBC_DEC_TEST_VECTORS
1407 .alg
= "cbc(anubis)",
1408 .test
= alg_test_skcipher
,
1412 .vecs
= anubis_cbc_enc_tv_template
,
1413 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
1416 .vecs
= anubis_cbc_dec_tv_template
,
1417 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
1422 .alg
= "cbc(blowfish)",
1423 .test
= alg_test_skcipher
,
1427 .vecs
= bf_cbc_enc_tv_template
,
1428 .count
= BF_CBC_ENC_TEST_VECTORS
1431 .vecs
= bf_cbc_dec_tv_template
,
1432 .count
= BF_CBC_DEC_TEST_VECTORS
1437 .alg
= "cbc(camellia)",
1438 .test
= alg_test_skcipher
,
1442 .vecs
= camellia_cbc_enc_tv_template
,
1443 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
1446 .vecs
= camellia_cbc_dec_tv_template
,
1447 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
1453 .test
= alg_test_skcipher
,
1457 .vecs
= des_cbc_enc_tv_template
,
1458 .count
= DES_CBC_ENC_TEST_VECTORS
1461 .vecs
= des_cbc_dec_tv_template
,
1462 .count
= DES_CBC_DEC_TEST_VECTORS
1467 .alg
= "cbc(des3_ede)",
1468 .test
= alg_test_skcipher
,
1472 .vecs
= des3_ede_cbc_enc_tv_template
,
1473 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
1476 .vecs
= des3_ede_cbc_dec_tv_template
,
1477 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
1482 .alg
= "cbc(twofish)",
1483 .test
= alg_test_skcipher
,
1487 .vecs
= tf_cbc_enc_tv_template
,
1488 .count
= TF_CBC_ENC_TEST_VECTORS
1491 .vecs
= tf_cbc_dec_tv_template
,
1492 .count
= TF_CBC_DEC_TEST_VECTORS
1498 .test
= alg_test_aead
,
1502 .vecs
= aes_ccm_enc_tv_template
,
1503 .count
= AES_CCM_ENC_TEST_VECTORS
1506 .vecs
= aes_ccm_dec_tv_template
,
1507 .count
= AES_CCM_DEC_TEST_VECTORS
1513 .test
= alg_test_crc32c
,
1516 .vecs
= crc32c_tv_template
,
1517 .count
= CRC32C_TEST_VECTORS
1521 .alg
= "cts(cbc(aes))",
1522 .test
= alg_test_skcipher
,
1526 .vecs
= cts_mode_enc_tv_template
,
1527 .count
= CTS_MODE_ENC_TEST_VECTORS
1530 .vecs
= cts_mode_dec_tv_template
,
1531 .count
= CTS_MODE_DEC_TEST_VECTORS
1537 .test
= alg_test_comp
,
1541 .vecs
= deflate_comp_tv_template
,
1542 .count
= DEFLATE_COMP_TEST_VECTORS
1545 .vecs
= deflate_decomp_tv_template
,
1546 .count
= DEFLATE_DECOMP_TEST_VECTORS
1552 .test
= alg_test_skcipher
,
1556 .vecs
= aes_enc_tv_template
,
1557 .count
= AES_ENC_TEST_VECTORS
1560 .vecs
= aes_dec_tv_template
,
1561 .count
= AES_DEC_TEST_VECTORS
1566 .alg
= "ecb(anubis)",
1567 .test
= alg_test_skcipher
,
1571 .vecs
= anubis_enc_tv_template
,
1572 .count
= ANUBIS_ENC_TEST_VECTORS
1575 .vecs
= anubis_dec_tv_template
,
1576 .count
= ANUBIS_DEC_TEST_VECTORS
1582 .test
= alg_test_skcipher
,
1586 .vecs
= arc4_enc_tv_template
,
1587 .count
= ARC4_ENC_TEST_VECTORS
1590 .vecs
= arc4_dec_tv_template
,
1591 .count
= ARC4_DEC_TEST_VECTORS
1596 .alg
= "ecb(blowfish)",
1597 .test
= alg_test_skcipher
,
1601 .vecs
= bf_enc_tv_template
,
1602 .count
= BF_ENC_TEST_VECTORS
1605 .vecs
= bf_dec_tv_template
,
1606 .count
= BF_DEC_TEST_VECTORS
1611 .alg
= "ecb(camellia)",
1612 .test
= alg_test_skcipher
,
1616 .vecs
= camellia_enc_tv_template
,
1617 .count
= CAMELLIA_ENC_TEST_VECTORS
1620 .vecs
= camellia_dec_tv_template
,
1621 .count
= CAMELLIA_DEC_TEST_VECTORS
1626 .alg
= "ecb(cast5)",
1627 .test
= alg_test_skcipher
,
1631 .vecs
= cast5_enc_tv_template
,
1632 .count
= CAST5_ENC_TEST_VECTORS
1635 .vecs
= cast5_dec_tv_template
,
1636 .count
= CAST5_DEC_TEST_VECTORS
1641 .alg
= "ecb(cast6)",
1642 .test
= alg_test_skcipher
,
1646 .vecs
= cast6_enc_tv_template
,
1647 .count
= CAST6_ENC_TEST_VECTORS
1650 .vecs
= cast6_dec_tv_template
,
1651 .count
= CAST6_DEC_TEST_VECTORS
1657 .test
= alg_test_skcipher
,
1661 .vecs
= des_enc_tv_template
,
1662 .count
= DES_ENC_TEST_VECTORS
1665 .vecs
= des_dec_tv_template
,
1666 .count
= DES_DEC_TEST_VECTORS
1671 .alg
= "ecb(des3_ede)",
1672 .test
= alg_test_skcipher
,
1676 .vecs
= des3_ede_enc_tv_template
,
1677 .count
= DES3_EDE_ENC_TEST_VECTORS
1680 .vecs
= des3_ede_dec_tv_template
,
1681 .count
= DES3_EDE_DEC_TEST_VECTORS
1686 .alg
= "ecb(khazad)",
1687 .test
= alg_test_skcipher
,
1691 .vecs
= khazad_enc_tv_template
,
1692 .count
= KHAZAD_ENC_TEST_VECTORS
1695 .vecs
= khazad_dec_tv_template
,
1696 .count
= KHAZAD_DEC_TEST_VECTORS
1702 .test
= alg_test_skcipher
,
1706 .vecs
= seed_enc_tv_template
,
1707 .count
= SEED_ENC_TEST_VECTORS
1710 .vecs
= seed_dec_tv_template
,
1711 .count
= SEED_DEC_TEST_VECTORS
1716 .alg
= "ecb(serpent)",
1717 .test
= alg_test_skcipher
,
1721 .vecs
= serpent_enc_tv_template
,
1722 .count
= SERPENT_ENC_TEST_VECTORS
1725 .vecs
= serpent_dec_tv_template
,
1726 .count
= SERPENT_DEC_TEST_VECTORS
1732 .test
= alg_test_skcipher
,
1736 .vecs
= tea_enc_tv_template
,
1737 .count
= TEA_ENC_TEST_VECTORS
1740 .vecs
= tea_dec_tv_template
,
1741 .count
= TEA_DEC_TEST_VECTORS
1746 .alg
= "ecb(tnepres)",
1747 .test
= alg_test_skcipher
,
1751 .vecs
= tnepres_enc_tv_template
,
1752 .count
= TNEPRES_ENC_TEST_VECTORS
1755 .vecs
= tnepres_dec_tv_template
,
1756 .count
= TNEPRES_DEC_TEST_VECTORS
1761 .alg
= "ecb(twofish)",
1762 .test
= alg_test_skcipher
,
1766 .vecs
= tf_enc_tv_template
,
1767 .count
= TF_ENC_TEST_VECTORS
1770 .vecs
= tf_dec_tv_template
,
1771 .count
= TF_DEC_TEST_VECTORS
1777 .test
= alg_test_skcipher
,
1781 .vecs
= xeta_enc_tv_template
,
1782 .count
= XETA_ENC_TEST_VECTORS
1785 .vecs
= xeta_dec_tv_template
,
1786 .count
= XETA_DEC_TEST_VECTORS
1792 .test
= alg_test_skcipher
,
1796 .vecs
= xtea_enc_tv_template
,
1797 .count
= XTEA_ENC_TEST_VECTORS
1800 .vecs
= xtea_dec_tv_template
,
1801 .count
= XTEA_DEC_TEST_VECTORS
1807 .test
= alg_test_aead
,
1811 .vecs
= aes_gcm_enc_tv_template
,
1812 .count
= AES_GCM_ENC_TEST_VECTORS
1815 .vecs
= aes_gcm_dec_tv_template
,
1816 .count
= AES_GCM_DEC_TEST_VECTORS
1822 .test
= alg_test_hash
,
1825 .vecs
= hmac_md5_tv_template
,
1826 .count
= HMAC_MD5_TEST_VECTORS
1830 .alg
= "hmac(rmd128)",
1831 .test
= alg_test_hash
,
1834 .vecs
= hmac_rmd128_tv_template
,
1835 .count
= HMAC_RMD128_TEST_VECTORS
1839 .alg
= "hmac(rmd160)",
1840 .test
= alg_test_hash
,
1843 .vecs
= hmac_rmd160_tv_template
,
1844 .count
= HMAC_RMD160_TEST_VECTORS
1848 .alg
= "hmac(sha1)",
1849 .test
= alg_test_hash
,
1852 .vecs
= hmac_sha1_tv_template
,
1853 .count
= HMAC_SHA1_TEST_VECTORS
1857 .alg
= "hmac(sha224)",
1858 .test
= alg_test_hash
,
1861 .vecs
= hmac_sha224_tv_template
,
1862 .count
= HMAC_SHA224_TEST_VECTORS
1866 .alg
= "hmac(sha256)",
1867 .test
= alg_test_hash
,
1870 .vecs
= hmac_sha256_tv_template
,
1871 .count
= HMAC_SHA256_TEST_VECTORS
1875 .alg
= "hmac(sha384)",
1876 .test
= alg_test_hash
,
1879 .vecs
= hmac_sha384_tv_template
,
1880 .count
= HMAC_SHA384_TEST_VECTORS
1884 .alg
= "hmac(sha512)",
1885 .test
= alg_test_hash
,
1888 .vecs
= hmac_sha512_tv_template
,
1889 .count
= HMAC_SHA512_TEST_VECTORS
1894 .test
= alg_test_skcipher
,
1898 .vecs
= aes_lrw_enc_tv_template
,
1899 .count
= AES_LRW_ENC_TEST_VECTORS
1902 .vecs
= aes_lrw_dec_tv_template
,
1903 .count
= AES_LRW_DEC_TEST_VECTORS
1909 .test
= alg_test_comp
,
1913 .vecs
= lzo_comp_tv_template
,
1914 .count
= LZO_COMP_TEST_VECTORS
1917 .vecs
= lzo_decomp_tv_template
,
1918 .count
= LZO_DECOMP_TEST_VECTORS
1924 .test
= alg_test_hash
,
1927 .vecs
= md4_tv_template
,
1928 .count
= MD4_TEST_VECTORS
1933 .test
= alg_test_hash
,
1936 .vecs
= md5_tv_template
,
1937 .count
= MD5_TEST_VECTORS
1941 .alg
= "michael_mic",
1942 .test
= alg_test_hash
,
1945 .vecs
= michael_mic_tv_template
,
1946 .count
= MICHAEL_MIC_TEST_VECTORS
1950 .alg
= "pcbc(fcrypt)",
1951 .test
= alg_test_skcipher
,
1955 .vecs
= fcrypt_pcbc_enc_tv_template
,
1956 .count
= FCRYPT_ENC_TEST_VECTORS
1959 .vecs
= fcrypt_pcbc_dec_tv_template
,
1960 .count
= FCRYPT_DEC_TEST_VECTORS
1965 .alg
= "rfc3686(ctr(aes))",
1966 .test
= alg_test_skcipher
,
1970 .vecs
= aes_ctr_enc_tv_template
,
1971 .count
= AES_CTR_ENC_TEST_VECTORS
1974 .vecs
= aes_ctr_dec_tv_template
,
1975 .count
= AES_CTR_DEC_TEST_VECTORS
1980 .alg
= "rfc4309(ccm(aes))",
1981 .test
= alg_test_aead
,
1985 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
1986 .count
= AES_CCM_4309_ENC_TEST_VECTORS
1989 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
1990 .count
= AES_CCM_4309_DEC_TEST_VECTORS
1996 .test
= alg_test_hash
,
1999 .vecs
= rmd128_tv_template
,
2000 .count
= RMD128_TEST_VECTORS
2005 .test
= alg_test_hash
,
2008 .vecs
= rmd160_tv_template
,
2009 .count
= RMD160_TEST_VECTORS
2014 .test
= alg_test_hash
,
2017 .vecs
= rmd256_tv_template
,
2018 .count
= RMD256_TEST_VECTORS
2023 .test
= alg_test_hash
,
2026 .vecs
= rmd320_tv_template
,
2027 .count
= RMD320_TEST_VECTORS
2032 .test
= alg_test_skcipher
,
2036 .vecs
= salsa20_stream_enc_tv_template
,
2037 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
2043 .test
= alg_test_hash
,
2046 .vecs
= sha1_tv_template
,
2047 .count
= SHA1_TEST_VECTORS
2052 .test
= alg_test_hash
,
2055 .vecs
= sha224_tv_template
,
2056 .count
= SHA224_TEST_VECTORS
2061 .test
= alg_test_hash
,
2064 .vecs
= sha256_tv_template
,
2065 .count
= SHA256_TEST_VECTORS
2070 .test
= alg_test_hash
,
2073 .vecs
= sha384_tv_template
,
2074 .count
= SHA384_TEST_VECTORS
2079 .test
= alg_test_hash
,
2082 .vecs
= sha512_tv_template
,
2083 .count
= SHA512_TEST_VECTORS
2088 .test
= alg_test_hash
,
2091 .vecs
= tgr128_tv_template
,
2092 .count
= TGR128_TEST_VECTORS
2097 .test
= alg_test_hash
,
2100 .vecs
= tgr160_tv_template
,
2101 .count
= TGR160_TEST_VECTORS
2106 .test
= alg_test_hash
,
2109 .vecs
= tgr192_tv_template
,
2110 .count
= TGR192_TEST_VECTORS
2115 .test
= alg_test_hash
,
2118 .vecs
= wp256_tv_template
,
2119 .count
= WP256_TEST_VECTORS
2124 .test
= alg_test_hash
,
2127 .vecs
= wp384_tv_template
,
2128 .count
= WP384_TEST_VECTORS
2133 .test
= alg_test_hash
,
2136 .vecs
= wp512_tv_template
,
2137 .count
= WP512_TEST_VECTORS
2142 .test
= alg_test_hash
,
2145 .vecs
= aes_xcbc128_tv_template
,
2146 .count
= XCBC_AES_TEST_VECTORS
2151 .test
= alg_test_skcipher
,
2155 .vecs
= aes_xts_enc_tv_template
,
2156 .count
= AES_XTS_ENC_TEST_VECTORS
2159 .vecs
= aes_xts_dec_tv_template
,
2160 .count
= AES_XTS_DEC_TEST_VECTORS
2166 .test
= alg_test_pcomp
,
2170 .vecs
= zlib_comp_tv_template
,
2171 .count
= ZLIB_COMP_TEST_VECTORS
2174 .vecs
= zlib_decomp_tv_template
,
2175 .count
= ZLIB_DECOMP_TEST_VECTORS
2182 static int alg_find_test(const char *alg
)
2185 int end
= ARRAY_SIZE(alg_test_descs
);
2187 while (start
< end
) {
2188 int i
= (start
+ end
) / 2;
2189 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
2207 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
2212 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
2213 char nalg
[CRYPTO_MAX_ALG_NAME
];
2215 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
2217 return -ENAMETOOLONG
;
2219 i
= alg_find_test(nalg
);
2223 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
2227 i
= alg_find_test(alg
);
2231 rc
= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
2234 if (fips_enabled
&& rc
)
2235 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
2240 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
2243 EXPORT_SYMBOL_GPL(alg_test
);
2245 int __init
testmgr_init(void)
2249 for (i
= 0; i
< XBUFSIZE
; i
++) {
2250 xbuf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2255 for (i
= 0; i
< XBUFSIZE
; i
++) {
2256 axbuf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
2258 goto err_free_axbuf
;
2264 for (i
= 0; i
< XBUFSIZE
&& axbuf
[i
]; i
++)
2265 free_page((unsigned long)axbuf
[i
]);
2267 for (i
= 0; i
< XBUFSIZE
&& xbuf
[i
]; i
++)
2268 free_page((unsigned long)xbuf
[i
]);
2273 void testmgr_exit(void)
2277 for (i
= 0; i
< XBUFSIZE
; i
++)
2278 free_page((unsigned long)axbuf
[i
]);
2279 for (i
= 0; i
< XBUFSIZE
; i
++)
2280 free_page((unsigned long)xbuf
[i
]);