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 void hexdump(unsigned char *buf
, unsigned int len
)
112 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
117 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
119 struct tcrypt_result
*res
= req
->data
;
121 if (err
== -EINPROGRESS
)
125 complete(&res
->completion
);
128 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
132 for (i
= 0; i
< XBUFSIZE
; i
++) {
133 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
142 free_page((unsigned long)buf
[i
]);
147 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
151 for (i
= 0; i
< XBUFSIZE
; i
++)
152 free_page((unsigned long)buf
[i
]);
155 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
158 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
159 unsigned int i
, j
, k
, temp
;
160 struct scatterlist sg
[8];
162 struct ahash_request
*req
;
163 struct tcrypt_result tresult
;
165 char *xbuf
[XBUFSIZE
];
168 if (testmgr_alloc_buf(xbuf
))
171 init_completion(&tresult
.completion
);
173 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
175 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
179 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
180 tcrypt_complete
, &tresult
);
182 for (i
= 0; i
< tcount
; i
++) {
183 memset(result
, 0, 64);
187 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
188 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
190 if (template[i
].ksize
) {
191 crypto_ahash_clear_flags(tfm
, ~0);
192 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
195 printk(KERN_ERR
"alg: hash: setkey failed on "
196 "test %d for %s: ret=%d\n", i
+ 1, algo
,
202 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
203 ret
= crypto_ahash_digest(req
);
209 ret
= wait_for_completion_interruptible(
210 &tresult
.completion
);
211 if (!ret
&& !(ret
= tresult
.err
)) {
212 INIT_COMPLETION(tresult
.completion
);
217 printk(KERN_ERR
"alg: hash: digest failed on test %d "
218 "for %s: ret=%d\n", i
+ 1, algo
, -ret
);
222 if (memcmp(result
, template[i
].digest
,
223 crypto_ahash_digestsize(tfm
))) {
224 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
226 hexdump(result
, crypto_ahash_digestsize(tfm
));
233 for (i
= 0; i
< tcount
; i
++) {
234 if (template[i
].np
) {
236 memset(result
, 0, 64);
239 sg_init_table(sg
, template[i
].np
);
240 for (k
= 0; k
< template[i
].np
; k
++) {
242 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
243 offset_in_page(IDX
[k
]),
244 template[i
].plaintext
+ temp
,
247 temp
+= template[i
].tap
[k
];
250 if (template[i
].ksize
) {
251 crypto_ahash_clear_flags(tfm
, ~0);
252 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
256 printk(KERN_ERR
"alg: hash: setkey "
257 "failed on chunking test %d "
258 "for %s: ret=%d\n", j
, algo
,
264 ahash_request_set_crypt(req
, sg
, result
,
266 ret
= crypto_ahash_digest(req
);
272 ret
= wait_for_completion_interruptible(
273 &tresult
.completion
);
274 if (!ret
&& !(ret
= tresult
.err
)) {
275 INIT_COMPLETION(tresult
.completion
);
280 printk(KERN_ERR
"alg: hash: digest failed "
281 "on chunking test %d for %s: "
282 "ret=%d\n", j
, algo
, -ret
);
286 if (memcmp(result
, template[i
].digest
,
287 crypto_ahash_digestsize(tfm
))) {
288 printk(KERN_ERR
"alg: hash: Chunking test %d "
289 "failed for %s\n", j
, algo
);
290 hexdump(result
, crypto_ahash_digestsize(tfm
));
300 ahash_request_free(req
);
302 testmgr_free_buf(xbuf
);
307 static int test_aead(struct crypto_aead
*tfm
, int enc
,
308 struct aead_testvec
*template, unsigned int tcount
)
310 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
311 unsigned int i
, j
, k
, n
, temp
;
315 struct aead_request
*req
;
316 struct scatterlist sg
[8];
317 struct scatterlist asg
[8];
319 struct tcrypt_result result
;
320 unsigned int authsize
;
324 char *xbuf
[XBUFSIZE
];
325 char *axbuf
[XBUFSIZE
];
327 if (testmgr_alloc_buf(xbuf
))
329 if (testmgr_alloc_buf(axbuf
))
337 init_completion(&result
.completion
);
339 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
341 printk(KERN_ERR
"alg: aead: Failed to allocate request for "
346 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
347 tcrypt_complete
, &result
);
349 for (i
= 0, j
= 0; i
< tcount
; i
++) {
350 if (!template[i
].np
) {
353 /* some tepmplates have no input data but they will
359 memcpy(input
, template[i
].input
, template[i
].ilen
);
360 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
362 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
364 memset(iv
, 0, MAX_IVLEN
);
366 crypto_aead_clear_flags(tfm
, ~0);
368 crypto_aead_set_flags(
369 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
371 key
= template[i
].key
;
373 ret
= crypto_aead_setkey(tfm
, key
,
375 if (!ret
== template[i
].fail
) {
376 printk(KERN_ERR
"alg: aead: setkey failed on "
377 "test %d for %s: flags=%x\n", j
, algo
,
378 crypto_aead_get_flags(tfm
));
383 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
384 ret
= crypto_aead_setauthsize(tfm
, authsize
);
386 printk(KERN_ERR
"alg: aead: Failed to set "
387 "authsize to %u on test %d for %s\n",
392 sg_init_one(&sg
[0], input
,
393 template[i
].ilen
+ (enc
? authsize
: 0));
395 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
397 aead_request_set_crypt(req
, sg
, sg
,
398 template[i
].ilen
, iv
);
400 aead_request_set_assoc(req
, asg
, template[i
].alen
);
403 crypto_aead_encrypt(req
) :
404 crypto_aead_decrypt(req
);
408 if (template[i
].novrfy
) {
409 /* verification was supposed to fail */
410 printk(KERN_ERR
"alg: aead: %s failed "
411 "on test %d for %s: ret was 0, "
412 "expected -EBADMSG\n",
414 /* so really, we got a bad message */
421 ret
= wait_for_completion_interruptible(
423 if (!ret
&& !(ret
= result
.err
)) {
424 INIT_COMPLETION(result
.completion
);
428 if (template[i
].novrfy
)
429 /* verification failure was expected */
433 printk(KERN_ERR
"alg: aead: %s failed on test "
434 "%d for %s: ret=%d\n", e
, j
, algo
, -ret
);
439 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
440 printk(KERN_ERR
"alg: aead: Test %d failed on "
441 "%s for %s\n", j
, e
, algo
);
442 hexdump(q
, template[i
].rlen
);
449 for (i
= 0, j
= 0; i
< tcount
; i
++) {
450 if (template[i
].np
) {
454 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
456 memset(iv
, 0, MAX_IVLEN
);
458 crypto_aead_clear_flags(tfm
, ~0);
460 crypto_aead_set_flags(
461 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
462 key
= template[i
].key
;
464 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
465 if (!ret
== template[i
].fail
) {
466 printk(KERN_ERR
"alg: aead: setkey failed on "
467 "chunk test %d for %s: flags=%x\n", j
,
468 algo
, crypto_aead_get_flags(tfm
));
473 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
476 sg_init_table(sg
, template[i
].np
);
477 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
478 if (WARN_ON(offset_in_page(IDX
[k
]) +
479 template[i
].tap
[k
] > PAGE_SIZE
))
482 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
483 offset_in_page(IDX
[k
]);
485 memcpy(q
, template[i
].input
+ temp
,
488 n
= template[i
].tap
[k
];
489 if (k
== template[i
].np
- 1 && enc
)
491 if (offset_in_page(q
) + n
< PAGE_SIZE
)
494 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
495 temp
+= template[i
].tap
[k
];
498 ret
= crypto_aead_setauthsize(tfm
, authsize
);
500 printk(KERN_ERR
"alg: aead: Failed to set "
501 "authsize to %u on chunk test %d for "
502 "%s\n", authsize
, j
, algo
);
507 if (WARN_ON(sg
[k
- 1].offset
+
508 sg
[k
- 1].length
+ authsize
>
514 sg
[k
- 1].length
+= authsize
;
517 sg_init_table(asg
, template[i
].anp
);
518 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
520 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
521 offset_in_page(IDX
[k
]),
522 template[i
].assoc
+ temp
,
523 template[i
].atap
[k
]),
524 template[i
].atap
[k
]);
525 temp
+= template[i
].atap
[k
];
528 aead_request_set_crypt(req
, sg
, sg
,
532 aead_request_set_assoc(req
, asg
, template[i
].alen
);
535 crypto_aead_encrypt(req
) :
536 crypto_aead_decrypt(req
);
540 if (template[i
].novrfy
) {
541 /* verification was supposed to fail */
542 printk(KERN_ERR
"alg: aead: %s failed "
543 "on chunk test %d for %s: ret "
544 "was 0, expected -EBADMSG\n",
546 /* so really, we got a bad message */
553 ret
= wait_for_completion_interruptible(
555 if (!ret
&& !(ret
= result
.err
)) {
556 INIT_COMPLETION(result
.completion
);
560 if (template[i
].novrfy
)
561 /* verification failure was expected */
565 printk(KERN_ERR
"alg: aead: %s failed on "
566 "chunk test %d for %s: ret=%d\n", e
, j
,
572 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
573 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
574 offset_in_page(IDX
[k
]);
576 n
= template[i
].tap
[k
];
577 if (k
== template[i
].np
- 1)
578 n
+= enc
? authsize
: -authsize
;
580 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
581 printk(KERN_ERR
"alg: aead: Chunk "
582 "test %d failed on %s at page "
583 "%u for %s\n", j
, e
, k
, algo
);
589 if (k
== template[i
].np
- 1 && !enc
) {
590 if (memcmp(q
, template[i
].input
+
596 for (n
= 0; offset_in_page(q
+ n
) &&
601 printk(KERN_ERR
"alg: aead: Result "
602 "buffer corruption in chunk "
603 "test %d on %s at page %u for "
604 "%s: %u bytes:\n", j
, e
, k
,
610 temp
+= template[i
].tap
[k
];
618 aead_request_free(req
);
619 testmgr_free_buf(axbuf
);
621 testmgr_free_buf(xbuf
);
626 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
627 struct cipher_testvec
*template, unsigned int tcount
)
629 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
630 unsigned int i
, j
, k
;
634 char *xbuf
[XBUFSIZE
];
637 if (testmgr_alloc_buf(xbuf
))
646 for (i
= 0; i
< tcount
; i
++) {
653 memcpy(data
, template[i
].input
, template[i
].ilen
);
655 crypto_cipher_clear_flags(tfm
, ~0);
657 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
659 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
661 if (!ret
== template[i
].fail
) {
662 printk(KERN_ERR
"alg: cipher: setkey failed "
663 "on test %d for %s: flags=%x\n", j
,
664 algo
, crypto_cipher_get_flags(tfm
));
669 for (k
= 0; k
< template[i
].ilen
;
670 k
+= crypto_cipher_blocksize(tfm
)) {
672 crypto_cipher_encrypt_one(tfm
, data
+ k
,
675 crypto_cipher_decrypt_one(tfm
, data
+ k
,
680 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
681 printk(KERN_ERR
"alg: cipher: Test %d failed "
682 "on %s for %s\n", j
, e
, algo
);
683 hexdump(q
, template[i
].rlen
);
692 testmgr_free_buf(xbuf
);
697 static int test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
698 struct cipher_testvec
*template, unsigned int tcount
)
701 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm
));
702 unsigned int i
, j
, k
, n
, temp
;
704 struct ablkcipher_request
*req
;
705 struct scatterlist sg
[8];
707 struct tcrypt_result result
;
710 char *xbuf
[XBUFSIZE
];
713 if (testmgr_alloc_buf(xbuf
))
721 init_completion(&result
.completion
);
723 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
725 printk(KERN_ERR
"alg: skcipher: Failed to allocate request "
730 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
731 tcrypt_complete
, &result
);
734 for (i
= 0; i
< tcount
; i
++) {
736 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
738 memset(iv
, 0, MAX_IVLEN
);
740 if (!(template[i
].np
)) {
744 memcpy(data
, template[i
].input
, template[i
].ilen
);
746 crypto_ablkcipher_clear_flags(tfm
, ~0);
748 crypto_ablkcipher_set_flags(
749 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
751 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
753 if (!ret
== template[i
].fail
) {
754 printk(KERN_ERR
"alg: skcipher: setkey failed "
755 "on test %d for %s: flags=%x\n", j
,
756 algo
, crypto_ablkcipher_get_flags(tfm
));
761 sg_init_one(&sg
[0], data
, template[i
].ilen
);
763 ablkcipher_request_set_crypt(req
, sg
, sg
,
764 template[i
].ilen
, iv
);
766 crypto_ablkcipher_encrypt(req
) :
767 crypto_ablkcipher_decrypt(req
);
774 ret
= wait_for_completion_interruptible(
776 if (!ret
&& !((ret
= result
.err
))) {
777 INIT_COMPLETION(result
.completion
);
782 printk(KERN_ERR
"alg: skcipher: %s failed on "
783 "test %d for %s: ret=%d\n", e
, j
, algo
,
789 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
790 printk(KERN_ERR
"alg: skcipher: Test %d "
791 "failed on %s for %s\n", j
, e
, algo
);
792 hexdump(q
, template[i
].rlen
);
800 for (i
= 0; i
< tcount
; i
++) {
803 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
805 memset(iv
, 0, MAX_IVLEN
);
807 if (template[i
].np
) {
810 crypto_ablkcipher_clear_flags(tfm
, ~0);
812 crypto_ablkcipher_set_flags(
813 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
815 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
817 if (!ret
== template[i
].fail
) {
818 printk(KERN_ERR
"alg: skcipher: setkey failed "
819 "on chunk test %d for %s: flags=%x\n",
821 crypto_ablkcipher_get_flags(tfm
));
828 sg_init_table(sg
, template[i
].np
);
829 for (k
= 0; k
< template[i
].np
; k
++) {
830 if (WARN_ON(offset_in_page(IDX
[k
]) +
831 template[i
].tap
[k
] > PAGE_SIZE
))
834 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
835 offset_in_page(IDX
[k
]);
837 memcpy(q
, template[i
].input
+ temp
,
840 if (offset_in_page(q
) + template[i
].tap
[k
] <
842 q
[template[i
].tap
[k
]] = 0;
844 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
846 temp
+= template[i
].tap
[k
];
849 ablkcipher_request_set_crypt(req
, sg
, sg
,
850 template[i
].ilen
, iv
);
853 crypto_ablkcipher_encrypt(req
) :
854 crypto_ablkcipher_decrypt(req
);
861 ret
= wait_for_completion_interruptible(
863 if (!ret
&& !((ret
= result
.err
))) {
864 INIT_COMPLETION(result
.completion
);
869 printk(KERN_ERR
"alg: skcipher: %s failed on "
870 "chunk test %d for %s: ret=%d\n", e
, j
,
877 for (k
= 0; k
< template[i
].np
; k
++) {
878 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
879 offset_in_page(IDX
[k
]);
881 if (memcmp(q
, template[i
].result
+ temp
,
882 template[i
].tap
[k
])) {
883 printk(KERN_ERR
"alg: skcipher: Chunk "
884 "test %d failed on %s at page "
885 "%u for %s\n", j
, e
, k
, algo
);
886 hexdump(q
, template[i
].tap
[k
]);
890 q
+= template[i
].tap
[k
];
891 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
894 printk(KERN_ERR
"alg: skcipher: "
895 "Result buffer corruption in "
896 "chunk test %d on %s at page "
897 "%u for %s: %u bytes:\n", j
, e
,
902 temp
+= template[i
].tap
[k
];
910 ablkcipher_request_free(req
);
911 testmgr_free_buf(xbuf
);
916 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
917 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
919 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
921 char result
[COMP_BUF_SIZE
];
924 for (i
= 0; i
< ctcount
; i
++) {
926 unsigned int dlen
= COMP_BUF_SIZE
;
928 memset(result
, 0, sizeof (result
));
930 ilen
= ctemplate
[i
].inlen
;
931 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
932 ilen
, result
, &dlen
);
934 printk(KERN_ERR
"alg: comp: compression failed "
935 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
940 if (dlen
!= ctemplate
[i
].outlen
) {
941 printk(KERN_ERR
"alg: comp: Compression test %d "
942 "failed for %s: output len = %d\n", i
+ 1, algo
,
948 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
949 printk(KERN_ERR
"alg: comp: Compression test %d "
950 "failed for %s\n", i
+ 1, algo
);
951 hexdump(result
, dlen
);
957 for (i
= 0; i
< dtcount
; i
++) {
959 unsigned int dlen
= COMP_BUF_SIZE
;
961 memset(result
, 0, sizeof (result
));
963 ilen
= dtemplate
[i
].inlen
;
964 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
965 ilen
, result
, &dlen
);
967 printk(KERN_ERR
"alg: comp: decompression failed "
968 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
973 if (dlen
!= dtemplate
[i
].outlen
) {
974 printk(KERN_ERR
"alg: comp: Decompression test %d "
975 "failed for %s: output len = %d\n", i
+ 1, algo
,
981 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
982 printk(KERN_ERR
"alg: comp: Decompression test %d "
983 "failed for %s\n", i
+ 1, algo
);
984 hexdump(result
, dlen
);
996 static int test_pcomp(struct crypto_pcomp
*tfm
,
997 struct pcomp_testvec
*ctemplate
,
998 struct pcomp_testvec
*dtemplate
, int ctcount
,
1001 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
1003 char result
[COMP_BUF_SIZE
];
1006 for (i
= 0; i
< ctcount
; i
++) {
1007 struct comp_request req
;
1009 error
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
1010 ctemplate
[i
].paramsize
);
1012 pr_err("alg: pcomp: compression setup failed on test "
1013 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1017 error
= crypto_compress_init(tfm
);
1019 pr_err("alg: pcomp: compression init failed on test "
1020 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1024 memset(result
, 0, sizeof(result
));
1026 req
.next_in
= ctemplate
[i
].input
;
1027 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
1028 req
.next_out
= result
;
1029 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
1031 error
= crypto_compress_update(tfm
, &req
);
1032 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1033 pr_err("alg: pcomp: compression update failed on test "
1034 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1038 /* Add remaining input data */
1039 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
1041 error
= crypto_compress_update(tfm
, &req
);
1042 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1043 pr_err("alg: pcomp: compression update failed on test "
1044 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1048 /* Provide remaining output space */
1049 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1051 error
= crypto_compress_final(tfm
, &req
);
1053 pr_err("alg: pcomp: compression final failed on test "
1054 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1058 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1059 pr_err("alg: comp: Compression test %d failed for %s: "
1060 "output len = %d (expected %d)\n", i
+ 1, algo
,
1061 COMP_BUF_SIZE
- req
.avail_out
,
1062 ctemplate
[i
].outlen
);
1066 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1067 pr_err("alg: pcomp: Compression test %d failed for "
1068 "%s\n", i
+ 1, algo
);
1069 hexdump(result
, ctemplate
[i
].outlen
);
1074 for (i
= 0; i
< dtcount
; i
++) {
1075 struct comp_request req
;
1077 error
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1078 dtemplate
[i
].paramsize
);
1080 pr_err("alg: pcomp: decompression setup failed on "
1081 "test %d for %s: error=%d\n", i
+ 1, algo
,
1086 error
= crypto_decompress_init(tfm
);
1088 pr_err("alg: pcomp: decompression init failed on test "
1089 "%d for %s: error=%d\n", i
+ 1, algo
, error
);
1093 memset(result
, 0, sizeof(result
));
1095 req
.next_in
= dtemplate
[i
].input
;
1096 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1097 req
.next_out
= result
;
1098 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1100 error
= crypto_decompress_update(tfm
, &req
);
1101 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1102 pr_err("alg: pcomp: decompression update failed on "
1103 "test %d for %s: error=%d\n", i
+ 1, algo
,
1108 /* Add remaining input data */
1109 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1111 error
= crypto_decompress_update(tfm
, &req
);
1112 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1113 pr_err("alg: pcomp: decompression update failed on "
1114 "test %d for %s: error=%d\n", i
+ 1, algo
,
1119 /* Provide remaining output space */
1120 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1122 error
= crypto_decompress_final(tfm
, &req
);
1123 if (error
&& (error
!= -EAGAIN
|| req
.avail_in
)) {
1124 pr_err("alg: pcomp: decompression final failed on "
1125 "test %d for %s: error=%d\n", i
+ 1, algo
,
1130 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1131 pr_err("alg: comp: Decompression test %d failed for "
1132 "%s: output len = %d (expected %d)\n", i
+ 1,
1133 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1134 dtemplate
[i
].outlen
);
1138 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1139 pr_err("alg: pcomp: Decompression test %d failed for "
1140 "%s\n", i
+ 1, algo
);
1141 hexdump(result
, dtemplate
[i
].outlen
);
1150 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1151 unsigned int tcount
)
1153 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1154 int err
, i
, j
, seedsize
;
1158 seedsize
= crypto_rng_seedsize(tfm
);
1160 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1162 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1167 for (i
= 0; i
< tcount
; i
++) {
1168 memset(result
, 0, 32);
1170 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1171 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1173 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1174 template[i
].dt
, template[i
].dtlen
);
1176 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1178 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1183 for (j
= 0; j
< template[i
].loops
; j
++) {
1184 err
= crypto_rng_get_bytes(tfm
, result
,
1186 if (err
!= template[i
].rlen
) {
1187 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1188 "the correct amount of random data for "
1189 "%s (requested %d, got %d)\n", algo
,
1190 template[i
].rlen
, err
);
1195 err
= memcmp(result
, template[i
].result
,
1198 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1200 hexdump(result
, template[i
].rlen
);
1211 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1214 struct crypto_aead
*tfm
;
1217 tfm
= crypto_alloc_aead(driver
, type
, mask
);
1219 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1220 "%ld\n", driver
, PTR_ERR(tfm
));
1221 return PTR_ERR(tfm
);
1224 if (desc
->suite
.aead
.enc
.vecs
) {
1225 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1226 desc
->suite
.aead
.enc
.count
);
1231 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1232 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1233 desc
->suite
.aead
.dec
.count
);
1236 crypto_free_aead(tfm
);
1240 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1241 const char *driver
, u32 type
, u32 mask
)
1243 struct crypto_cipher
*tfm
;
1246 tfm
= crypto_alloc_cipher(driver
, type
, mask
);
1248 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1249 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1250 return PTR_ERR(tfm
);
1253 if (desc
->suite
.cipher
.enc
.vecs
) {
1254 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1255 desc
->suite
.cipher
.enc
.count
);
1260 if (desc
->suite
.cipher
.dec
.vecs
)
1261 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1262 desc
->suite
.cipher
.dec
.count
);
1265 crypto_free_cipher(tfm
);
1269 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1270 const char *driver
, u32 type
, u32 mask
)
1272 struct crypto_ablkcipher
*tfm
;
1275 tfm
= crypto_alloc_ablkcipher(driver
, type
, mask
);
1277 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1278 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1279 return PTR_ERR(tfm
);
1282 if (desc
->suite
.cipher
.enc
.vecs
) {
1283 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1284 desc
->suite
.cipher
.enc
.count
);
1289 if (desc
->suite
.cipher
.dec
.vecs
)
1290 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1291 desc
->suite
.cipher
.dec
.count
);
1294 crypto_free_ablkcipher(tfm
);
1298 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1301 struct crypto_comp
*tfm
;
1304 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1306 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1307 "%ld\n", driver
, PTR_ERR(tfm
));
1308 return PTR_ERR(tfm
);
1311 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1312 desc
->suite
.comp
.decomp
.vecs
,
1313 desc
->suite
.comp
.comp
.count
,
1314 desc
->suite
.comp
.decomp
.count
);
1316 crypto_free_comp(tfm
);
1320 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1323 struct crypto_pcomp
*tfm
;
1326 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1328 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1329 driver
, PTR_ERR(tfm
));
1330 return PTR_ERR(tfm
);
1333 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1334 desc
->suite
.pcomp
.decomp
.vecs
,
1335 desc
->suite
.pcomp
.comp
.count
,
1336 desc
->suite
.pcomp
.decomp
.count
);
1338 crypto_free_pcomp(tfm
);
1342 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1345 struct crypto_ahash
*tfm
;
1348 tfm
= crypto_alloc_ahash(driver
, type
, mask
);
1350 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1351 "%ld\n", driver
, PTR_ERR(tfm
));
1352 return PTR_ERR(tfm
);
1355 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
, desc
->suite
.hash
.count
);
1357 crypto_free_ahash(tfm
);
1361 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1362 const char *driver
, u32 type
, u32 mask
)
1364 struct crypto_shash
*tfm
;
1368 err
= alg_test_hash(desc
, driver
, type
, mask
);
1372 tfm
= crypto_alloc_shash(driver
, type
, mask
);
1374 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1375 "%ld\n", driver
, PTR_ERR(tfm
));
1382 struct shash_desc shash
;
1383 char ctx
[crypto_shash_descsize(tfm
)];
1386 sdesc
.shash
.tfm
= tfm
;
1387 sdesc
.shash
.flags
= 0;
1389 *(u32
*)sdesc
.ctx
= le32_to_cpu(420553207);
1390 err
= crypto_shash_final(&sdesc
.shash
, (u8
*)&val
);
1392 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1393 "%s: %d\n", driver
, err
);
1397 if (val
!= ~420553207) {
1398 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1399 "%d\n", driver
, val
);
1404 crypto_free_shash(tfm
);
1410 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1413 struct crypto_rng
*rng
;
1416 rng
= crypto_alloc_rng(driver
, type
, mask
);
1418 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1419 "%ld\n", driver
, PTR_ERR(rng
));
1420 return PTR_ERR(rng
);
1423 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1425 crypto_free_rng(rng
);
1430 /* Please keep this list sorted by algorithm name. */
1431 static const struct alg_test_desc alg_test_descs
[] = {
1433 .alg
= "ansi_cprng",
1434 .test
= alg_test_cprng
,
1437 .vecs
= ansi_cprng_aes_tv_template
,
1438 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1443 .test
= alg_test_skcipher
,
1447 .vecs
= aes_cbc_enc_tv_template
,
1448 .count
= AES_CBC_ENC_TEST_VECTORS
1451 .vecs
= aes_cbc_dec_tv_template
,
1452 .count
= AES_CBC_DEC_TEST_VECTORS
1457 .alg
= "cbc(anubis)",
1458 .test
= alg_test_skcipher
,
1462 .vecs
= anubis_cbc_enc_tv_template
,
1463 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
1466 .vecs
= anubis_cbc_dec_tv_template
,
1467 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
1472 .alg
= "cbc(blowfish)",
1473 .test
= alg_test_skcipher
,
1477 .vecs
= bf_cbc_enc_tv_template
,
1478 .count
= BF_CBC_ENC_TEST_VECTORS
1481 .vecs
= bf_cbc_dec_tv_template
,
1482 .count
= BF_CBC_DEC_TEST_VECTORS
1487 .alg
= "cbc(camellia)",
1488 .test
= alg_test_skcipher
,
1492 .vecs
= camellia_cbc_enc_tv_template
,
1493 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
1496 .vecs
= camellia_cbc_dec_tv_template
,
1497 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
1503 .test
= alg_test_skcipher
,
1507 .vecs
= des_cbc_enc_tv_template
,
1508 .count
= DES_CBC_ENC_TEST_VECTORS
1511 .vecs
= des_cbc_dec_tv_template
,
1512 .count
= DES_CBC_DEC_TEST_VECTORS
1517 .alg
= "cbc(des3_ede)",
1518 .test
= alg_test_skcipher
,
1522 .vecs
= des3_ede_cbc_enc_tv_template
,
1523 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
1526 .vecs
= des3_ede_cbc_dec_tv_template
,
1527 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
1532 .alg
= "cbc(twofish)",
1533 .test
= alg_test_skcipher
,
1537 .vecs
= tf_cbc_enc_tv_template
,
1538 .count
= TF_CBC_ENC_TEST_VECTORS
1541 .vecs
= tf_cbc_dec_tv_template
,
1542 .count
= TF_CBC_DEC_TEST_VECTORS
1548 .test
= alg_test_aead
,
1552 .vecs
= aes_ccm_enc_tv_template
,
1553 .count
= AES_CCM_ENC_TEST_VECTORS
1556 .vecs
= aes_ccm_dec_tv_template
,
1557 .count
= AES_CCM_DEC_TEST_VECTORS
1563 .test
= alg_test_crc32c
,
1566 .vecs
= crc32c_tv_template
,
1567 .count
= CRC32C_TEST_VECTORS
1572 .test
= alg_test_skcipher
,
1576 .vecs
= aes_ctr_enc_tv_template
,
1577 .count
= AES_CTR_ENC_TEST_VECTORS
1580 .vecs
= aes_ctr_dec_tv_template
,
1581 .count
= AES_CTR_DEC_TEST_VECTORS
1586 .alg
= "cts(cbc(aes))",
1587 .test
= alg_test_skcipher
,
1591 .vecs
= cts_mode_enc_tv_template
,
1592 .count
= CTS_MODE_ENC_TEST_VECTORS
1595 .vecs
= cts_mode_dec_tv_template
,
1596 .count
= CTS_MODE_DEC_TEST_VECTORS
1602 .test
= alg_test_comp
,
1606 .vecs
= deflate_comp_tv_template
,
1607 .count
= DEFLATE_COMP_TEST_VECTORS
1610 .vecs
= deflate_decomp_tv_template
,
1611 .count
= DEFLATE_DECOMP_TEST_VECTORS
1617 .test
= alg_test_skcipher
,
1621 .vecs
= aes_enc_tv_template
,
1622 .count
= AES_ENC_TEST_VECTORS
1625 .vecs
= aes_dec_tv_template
,
1626 .count
= AES_DEC_TEST_VECTORS
1631 .alg
= "ecb(anubis)",
1632 .test
= alg_test_skcipher
,
1636 .vecs
= anubis_enc_tv_template
,
1637 .count
= ANUBIS_ENC_TEST_VECTORS
1640 .vecs
= anubis_dec_tv_template
,
1641 .count
= ANUBIS_DEC_TEST_VECTORS
1647 .test
= alg_test_skcipher
,
1651 .vecs
= arc4_enc_tv_template
,
1652 .count
= ARC4_ENC_TEST_VECTORS
1655 .vecs
= arc4_dec_tv_template
,
1656 .count
= ARC4_DEC_TEST_VECTORS
1661 .alg
= "ecb(blowfish)",
1662 .test
= alg_test_skcipher
,
1666 .vecs
= bf_enc_tv_template
,
1667 .count
= BF_ENC_TEST_VECTORS
1670 .vecs
= bf_dec_tv_template
,
1671 .count
= BF_DEC_TEST_VECTORS
1676 .alg
= "ecb(camellia)",
1677 .test
= alg_test_skcipher
,
1681 .vecs
= camellia_enc_tv_template
,
1682 .count
= CAMELLIA_ENC_TEST_VECTORS
1685 .vecs
= camellia_dec_tv_template
,
1686 .count
= CAMELLIA_DEC_TEST_VECTORS
1691 .alg
= "ecb(cast5)",
1692 .test
= alg_test_skcipher
,
1696 .vecs
= cast5_enc_tv_template
,
1697 .count
= CAST5_ENC_TEST_VECTORS
1700 .vecs
= cast5_dec_tv_template
,
1701 .count
= CAST5_DEC_TEST_VECTORS
1706 .alg
= "ecb(cast6)",
1707 .test
= alg_test_skcipher
,
1711 .vecs
= cast6_enc_tv_template
,
1712 .count
= CAST6_ENC_TEST_VECTORS
1715 .vecs
= cast6_dec_tv_template
,
1716 .count
= CAST6_DEC_TEST_VECTORS
1722 .test
= alg_test_skcipher
,
1726 .vecs
= des_enc_tv_template
,
1727 .count
= DES_ENC_TEST_VECTORS
1730 .vecs
= des_dec_tv_template
,
1731 .count
= DES_DEC_TEST_VECTORS
1736 .alg
= "ecb(des3_ede)",
1737 .test
= alg_test_skcipher
,
1741 .vecs
= des3_ede_enc_tv_template
,
1742 .count
= DES3_EDE_ENC_TEST_VECTORS
1745 .vecs
= des3_ede_dec_tv_template
,
1746 .count
= DES3_EDE_DEC_TEST_VECTORS
1751 .alg
= "ecb(khazad)",
1752 .test
= alg_test_skcipher
,
1756 .vecs
= khazad_enc_tv_template
,
1757 .count
= KHAZAD_ENC_TEST_VECTORS
1760 .vecs
= khazad_dec_tv_template
,
1761 .count
= KHAZAD_DEC_TEST_VECTORS
1767 .test
= alg_test_skcipher
,
1771 .vecs
= seed_enc_tv_template
,
1772 .count
= SEED_ENC_TEST_VECTORS
1775 .vecs
= seed_dec_tv_template
,
1776 .count
= SEED_DEC_TEST_VECTORS
1781 .alg
= "ecb(serpent)",
1782 .test
= alg_test_skcipher
,
1786 .vecs
= serpent_enc_tv_template
,
1787 .count
= SERPENT_ENC_TEST_VECTORS
1790 .vecs
= serpent_dec_tv_template
,
1791 .count
= SERPENT_DEC_TEST_VECTORS
1797 .test
= alg_test_skcipher
,
1801 .vecs
= tea_enc_tv_template
,
1802 .count
= TEA_ENC_TEST_VECTORS
1805 .vecs
= tea_dec_tv_template
,
1806 .count
= TEA_DEC_TEST_VECTORS
1811 .alg
= "ecb(tnepres)",
1812 .test
= alg_test_skcipher
,
1816 .vecs
= tnepres_enc_tv_template
,
1817 .count
= TNEPRES_ENC_TEST_VECTORS
1820 .vecs
= tnepres_dec_tv_template
,
1821 .count
= TNEPRES_DEC_TEST_VECTORS
1826 .alg
= "ecb(twofish)",
1827 .test
= alg_test_skcipher
,
1831 .vecs
= tf_enc_tv_template
,
1832 .count
= TF_ENC_TEST_VECTORS
1835 .vecs
= tf_dec_tv_template
,
1836 .count
= TF_DEC_TEST_VECTORS
1842 .test
= alg_test_skcipher
,
1846 .vecs
= xeta_enc_tv_template
,
1847 .count
= XETA_ENC_TEST_VECTORS
1850 .vecs
= xeta_dec_tv_template
,
1851 .count
= XETA_DEC_TEST_VECTORS
1857 .test
= alg_test_skcipher
,
1861 .vecs
= xtea_enc_tv_template
,
1862 .count
= XTEA_ENC_TEST_VECTORS
1865 .vecs
= xtea_dec_tv_template
,
1866 .count
= XTEA_DEC_TEST_VECTORS
1872 .test
= alg_test_aead
,
1876 .vecs
= aes_gcm_enc_tv_template
,
1877 .count
= AES_GCM_ENC_TEST_VECTORS
1880 .vecs
= aes_gcm_dec_tv_template
,
1881 .count
= AES_GCM_DEC_TEST_VECTORS
1887 .test
= alg_test_hash
,
1890 .vecs
= hmac_md5_tv_template
,
1891 .count
= HMAC_MD5_TEST_VECTORS
1895 .alg
= "hmac(rmd128)",
1896 .test
= alg_test_hash
,
1899 .vecs
= hmac_rmd128_tv_template
,
1900 .count
= HMAC_RMD128_TEST_VECTORS
1904 .alg
= "hmac(rmd160)",
1905 .test
= alg_test_hash
,
1908 .vecs
= hmac_rmd160_tv_template
,
1909 .count
= HMAC_RMD160_TEST_VECTORS
1913 .alg
= "hmac(sha1)",
1914 .test
= alg_test_hash
,
1917 .vecs
= hmac_sha1_tv_template
,
1918 .count
= HMAC_SHA1_TEST_VECTORS
1922 .alg
= "hmac(sha224)",
1923 .test
= alg_test_hash
,
1926 .vecs
= hmac_sha224_tv_template
,
1927 .count
= HMAC_SHA224_TEST_VECTORS
1931 .alg
= "hmac(sha256)",
1932 .test
= alg_test_hash
,
1935 .vecs
= hmac_sha256_tv_template
,
1936 .count
= HMAC_SHA256_TEST_VECTORS
1940 .alg
= "hmac(sha384)",
1941 .test
= alg_test_hash
,
1944 .vecs
= hmac_sha384_tv_template
,
1945 .count
= HMAC_SHA384_TEST_VECTORS
1949 .alg
= "hmac(sha512)",
1950 .test
= alg_test_hash
,
1953 .vecs
= hmac_sha512_tv_template
,
1954 .count
= HMAC_SHA512_TEST_VECTORS
1959 .test
= alg_test_skcipher
,
1963 .vecs
= aes_lrw_enc_tv_template
,
1964 .count
= AES_LRW_ENC_TEST_VECTORS
1967 .vecs
= aes_lrw_dec_tv_template
,
1968 .count
= AES_LRW_DEC_TEST_VECTORS
1974 .test
= alg_test_comp
,
1978 .vecs
= lzo_comp_tv_template
,
1979 .count
= LZO_COMP_TEST_VECTORS
1982 .vecs
= lzo_decomp_tv_template
,
1983 .count
= LZO_DECOMP_TEST_VECTORS
1989 .test
= alg_test_hash
,
1992 .vecs
= md4_tv_template
,
1993 .count
= MD4_TEST_VECTORS
1998 .test
= alg_test_hash
,
2001 .vecs
= md5_tv_template
,
2002 .count
= MD5_TEST_VECTORS
2006 .alg
= "michael_mic",
2007 .test
= alg_test_hash
,
2010 .vecs
= michael_mic_tv_template
,
2011 .count
= MICHAEL_MIC_TEST_VECTORS
2015 .alg
= "pcbc(fcrypt)",
2016 .test
= alg_test_skcipher
,
2020 .vecs
= fcrypt_pcbc_enc_tv_template
,
2021 .count
= FCRYPT_ENC_TEST_VECTORS
2024 .vecs
= fcrypt_pcbc_dec_tv_template
,
2025 .count
= FCRYPT_DEC_TEST_VECTORS
2030 .alg
= "rfc3686(ctr(aes))",
2031 .test
= alg_test_skcipher
,
2035 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
2036 .count
= AES_CTR_3686_ENC_TEST_VECTORS
2039 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
2040 .count
= AES_CTR_3686_DEC_TEST_VECTORS
2045 .alg
= "rfc4309(ccm(aes))",
2046 .test
= alg_test_aead
,
2050 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
2051 .count
= AES_CCM_4309_ENC_TEST_VECTORS
2054 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
2055 .count
= AES_CCM_4309_DEC_TEST_VECTORS
2061 .test
= alg_test_hash
,
2064 .vecs
= rmd128_tv_template
,
2065 .count
= RMD128_TEST_VECTORS
2070 .test
= alg_test_hash
,
2073 .vecs
= rmd160_tv_template
,
2074 .count
= RMD160_TEST_VECTORS
2079 .test
= alg_test_hash
,
2082 .vecs
= rmd256_tv_template
,
2083 .count
= RMD256_TEST_VECTORS
2088 .test
= alg_test_hash
,
2091 .vecs
= rmd320_tv_template
,
2092 .count
= RMD320_TEST_VECTORS
2097 .test
= alg_test_skcipher
,
2101 .vecs
= salsa20_stream_enc_tv_template
,
2102 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
2108 .test
= alg_test_hash
,
2111 .vecs
= sha1_tv_template
,
2112 .count
= SHA1_TEST_VECTORS
2117 .test
= alg_test_hash
,
2120 .vecs
= sha224_tv_template
,
2121 .count
= SHA224_TEST_VECTORS
2126 .test
= alg_test_hash
,
2129 .vecs
= sha256_tv_template
,
2130 .count
= SHA256_TEST_VECTORS
2135 .test
= alg_test_hash
,
2138 .vecs
= sha384_tv_template
,
2139 .count
= SHA384_TEST_VECTORS
2144 .test
= alg_test_hash
,
2147 .vecs
= sha512_tv_template
,
2148 .count
= SHA512_TEST_VECTORS
2153 .test
= alg_test_hash
,
2156 .vecs
= tgr128_tv_template
,
2157 .count
= TGR128_TEST_VECTORS
2162 .test
= alg_test_hash
,
2165 .vecs
= tgr160_tv_template
,
2166 .count
= TGR160_TEST_VECTORS
2171 .test
= alg_test_hash
,
2174 .vecs
= tgr192_tv_template
,
2175 .count
= TGR192_TEST_VECTORS
2180 .test
= alg_test_hash
,
2183 .vecs
= wp256_tv_template
,
2184 .count
= WP256_TEST_VECTORS
2189 .test
= alg_test_hash
,
2192 .vecs
= wp384_tv_template
,
2193 .count
= WP384_TEST_VECTORS
2198 .test
= alg_test_hash
,
2201 .vecs
= wp512_tv_template
,
2202 .count
= WP512_TEST_VECTORS
2207 .test
= alg_test_hash
,
2210 .vecs
= aes_xcbc128_tv_template
,
2211 .count
= XCBC_AES_TEST_VECTORS
2216 .test
= alg_test_skcipher
,
2220 .vecs
= aes_xts_enc_tv_template
,
2221 .count
= AES_XTS_ENC_TEST_VECTORS
2224 .vecs
= aes_xts_dec_tv_template
,
2225 .count
= AES_XTS_DEC_TEST_VECTORS
2231 .test
= alg_test_pcomp
,
2235 .vecs
= zlib_comp_tv_template
,
2236 .count
= ZLIB_COMP_TEST_VECTORS
2239 .vecs
= zlib_decomp_tv_template
,
2240 .count
= ZLIB_DECOMP_TEST_VECTORS
2247 static int alg_find_test(const char *alg
)
2250 int end
= ARRAY_SIZE(alg_test_descs
);
2252 while (start
< end
) {
2253 int i
= (start
+ end
) / 2;
2254 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
2272 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
2277 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
2278 char nalg
[CRYPTO_MAX_ALG_NAME
];
2280 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
2282 return -ENAMETOOLONG
;
2284 i
= alg_find_test(nalg
);
2288 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
2292 i
= alg_find_test(alg
);
2296 rc
= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
2299 if (fips_enabled
&& rc
)
2300 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
2302 if (fips_enabled
&& !rc
)
2303 printk(KERN_INFO
"alg: self-tests for %s (%s) passed\n",
2309 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
2312 EXPORT_SYMBOL_GPL(alg_test
);