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
,
97 int fips_allowed
; /* set if alg is allowed in fips mode */
100 struct aead_test_suite aead
;
101 struct cipher_test_suite cipher
;
102 struct comp_test_suite comp
;
103 struct pcomp_test_suite pcomp
;
104 struct hash_test_suite hash
;
105 struct cprng_test_suite cprng
;
109 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
111 static void hexdump(unsigned char *buf
, unsigned int len
)
113 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
118 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
120 struct tcrypt_result
*res
= req
->data
;
122 if (err
== -EINPROGRESS
)
126 complete(&res
->completion
);
129 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
133 for (i
= 0; i
< XBUFSIZE
; i
++) {
134 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
143 free_page((unsigned long)buf
[i
]);
148 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
152 for (i
= 0; i
< XBUFSIZE
; i
++)
153 free_page((unsigned long)buf
[i
]);
156 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
159 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
160 unsigned int i
, j
, k
, temp
;
161 struct scatterlist sg
[8];
163 struct ahash_request
*req
;
164 struct tcrypt_result tresult
;
166 char *xbuf
[XBUFSIZE
];
169 if (testmgr_alloc_buf(xbuf
))
172 init_completion(&tresult
.completion
);
174 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
176 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
180 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
181 tcrypt_complete
, &tresult
);
184 for (i
= 0; i
< tcount
; i
++) {
189 memset(result
, 0, 64);
193 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
194 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
196 if (template[i
].ksize
) {
197 crypto_ahash_clear_flags(tfm
, ~0);
198 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
201 printk(KERN_ERR
"alg: hash: setkey failed on "
202 "test %d for %s: ret=%d\n", j
, algo
,
208 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
209 ret
= crypto_ahash_digest(req
);
215 ret
= wait_for_completion_interruptible(
216 &tresult
.completion
);
217 if (!ret
&& !(ret
= tresult
.err
)) {
218 INIT_COMPLETION(tresult
.completion
);
223 printk(KERN_ERR
"alg: hash: digest failed on test %d "
224 "for %s: ret=%d\n", j
, algo
, -ret
);
228 if (memcmp(result
, template[i
].digest
,
229 crypto_ahash_digestsize(tfm
))) {
230 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
232 hexdump(result
, crypto_ahash_digestsize(tfm
));
239 for (i
= 0; i
< tcount
; i
++) {
240 if (template[i
].np
) {
242 memset(result
, 0, 64);
245 sg_init_table(sg
, template[i
].np
);
247 for (k
= 0; k
< template[i
].np
; k
++) {
248 if (WARN_ON(offset_in_page(IDX
[k
]) +
249 template[i
].tap
[k
] > PAGE_SIZE
))
252 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
253 offset_in_page(IDX
[k
]),
254 template[i
].plaintext
+ temp
,
257 temp
+= template[i
].tap
[k
];
260 if (template[i
].ksize
) {
261 crypto_ahash_clear_flags(tfm
, ~0);
262 ret
= crypto_ahash_setkey(tfm
, template[i
].key
,
266 printk(KERN_ERR
"alg: hash: setkey "
267 "failed on chunking test %d "
268 "for %s: ret=%d\n", j
, algo
,
274 ahash_request_set_crypt(req
, sg
, result
,
276 ret
= crypto_ahash_digest(req
);
282 ret
= wait_for_completion_interruptible(
283 &tresult
.completion
);
284 if (!ret
&& !(ret
= tresult
.err
)) {
285 INIT_COMPLETION(tresult
.completion
);
290 printk(KERN_ERR
"alg: hash: digest failed "
291 "on chunking test %d for %s: "
292 "ret=%d\n", j
, algo
, -ret
);
296 if (memcmp(result
, template[i
].digest
,
297 crypto_ahash_digestsize(tfm
))) {
298 printk(KERN_ERR
"alg: hash: Chunking test %d "
299 "failed for %s\n", j
, algo
);
300 hexdump(result
, crypto_ahash_digestsize(tfm
));
310 ahash_request_free(req
);
312 testmgr_free_buf(xbuf
);
317 static int test_aead(struct crypto_aead
*tfm
, int enc
,
318 struct aead_testvec
*template, unsigned int tcount
)
320 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
321 unsigned int i
, j
, k
, n
, temp
;
325 struct aead_request
*req
;
326 struct scatterlist sg
[8];
327 struct scatterlist asg
[8];
329 struct tcrypt_result result
;
330 unsigned int authsize
;
334 char *xbuf
[XBUFSIZE
];
335 char *axbuf
[XBUFSIZE
];
337 if (testmgr_alloc_buf(xbuf
))
339 if (testmgr_alloc_buf(axbuf
))
347 init_completion(&result
.completion
);
349 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
351 printk(KERN_ERR
"alg: aead: Failed to allocate request for "
356 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
357 tcrypt_complete
, &result
);
359 for (i
= 0, j
= 0; i
< tcount
; i
++) {
360 if (!template[i
].np
) {
363 /* some tepmplates have no input data but they will
370 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
||
371 template[i
].alen
> PAGE_SIZE
))
374 memcpy(input
, template[i
].input
, template[i
].ilen
);
375 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
377 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
379 memset(iv
, 0, MAX_IVLEN
);
381 crypto_aead_clear_flags(tfm
, ~0);
383 crypto_aead_set_flags(
384 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
386 key
= template[i
].key
;
388 ret
= crypto_aead_setkey(tfm
, key
,
390 if (!ret
== template[i
].fail
) {
391 printk(KERN_ERR
"alg: aead: setkey failed on "
392 "test %d for %s: flags=%x\n", j
, algo
,
393 crypto_aead_get_flags(tfm
));
398 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
399 ret
= crypto_aead_setauthsize(tfm
, authsize
);
401 printk(KERN_ERR
"alg: aead: Failed to set "
402 "authsize to %u on test %d for %s\n",
407 sg_init_one(&sg
[0], input
,
408 template[i
].ilen
+ (enc
? authsize
: 0));
410 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
412 aead_request_set_crypt(req
, sg
, sg
,
413 template[i
].ilen
, iv
);
415 aead_request_set_assoc(req
, asg
, template[i
].alen
);
418 crypto_aead_encrypt(req
) :
419 crypto_aead_decrypt(req
);
423 if (template[i
].novrfy
) {
424 /* verification was supposed to fail */
425 printk(KERN_ERR
"alg: aead: %s failed "
426 "on test %d for %s: ret was 0, "
427 "expected -EBADMSG\n",
429 /* so really, we got a bad message */
436 ret
= wait_for_completion_interruptible(
438 if (!ret
&& !(ret
= result
.err
)) {
439 INIT_COMPLETION(result
.completion
);
443 if (template[i
].novrfy
)
444 /* verification failure was expected */
448 printk(KERN_ERR
"alg: aead: %s failed on test "
449 "%d for %s: ret=%d\n", e
, j
, algo
, -ret
);
454 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
455 printk(KERN_ERR
"alg: aead: Test %d failed on "
456 "%s for %s\n", j
, e
, algo
);
457 hexdump(q
, template[i
].rlen
);
464 for (i
= 0, j
= 0; i
< tcount
; i
++) {
465 if (template[i
].np
) {
469 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
471 memset(iv
, 0, MAX_IVLEN
);
473 crypto_aead_clear_flags(tfm
, ~0);
475 crypto_aead_set_flags(
476 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
477 key
= template[i
].key
;
479 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
480 if (!ret
== template[i
].fail
) {
481 printk(KERN_ERR
"alg: aead: setkey failed on "
482 "chunk test %d for %s: flags=%x\n", j
,
483 algo
, crypto_aead_get_flags(tfm
));
488 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
491 sg_init_table(sg
, template[i
].np
);
492 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
493 if (WARN_ON(offset_in_page(IDX
[k
]) +
494 template[i
].tap
[k
] > PAGE_SIZE
))
497 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
498 offset_in_page(IDX
[k
]);
500 memcpy(q
, template[i
].input
+ temp
,
503 n
= template[i
].tap
[k
];
504 if (k
== template[i
].np
- 1 && enc
)
506 if (offset_in_page(q
) + n
< PAGE_SIZE
)
509 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
510 temp
+= template[i
].tap
[k
];
513 ret
= crypto_aead_setauthsize(tfm
, authsize
);
515 printk(KERN_ERR
"alg: aead: Failed to set "
516 "authsize to %u on chunk test %d for "
517 "%s\n", authsize
, j
, algo
);
522 if (WARN_ON(sg
[k
- 1].offset
+
523 sg
[k
- 1].length
+ authsize
>
529 sg
[k
- 1].length
+= authsize
;
532 sg_init_table(asg
, template[i
].anp
);
534 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
535 if (WARN_ON(offset_in_page(IDX
[k
]) +
536 template[i
].atap
[k
] > PAGE_SIZE
))
539 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
540 offset_in_page(IDX
[k
]),
541 template[i
].assoc
+ temp
,
542 template[i
].atap
[k
]),
543 template[i
].atap
[k
]);
544 temp
+= template[i
].atap
[k
];
547 aead_request_set_crypt(req
, sg
, sg
,
551 aead_request_set_assoc(req
, asg
, template[i
].alen
);
554 crypto_aead_encrypt(req
) :
555 crypto_aead_decrypt(req
);
559 if (template[i
].novrfy
) {
560 /* verification was supposed to fail */
561 printk(KERN_ERR
"alg: aead: %s failed "
562 "on chunk test %d for %s: ret "
563 "was 0, expected -EBADMSG\n",
565 /* so really, we got a bad message */
572 ret
= wait_for_completion_interruptible(
574 if (!ret
&& !(ret
= result
.err
)) {
575 INIT_COMPLETION(result
.completion
);
579 if (template[i
].novrfy
)
580 /* verification failure was expected */
584 printk(KERN_ERR
"alg: aead: %s failed on "
585 "chunk test %d for %s: ret=%d\n", e
, j
,
591 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
592 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
593 offset_in_page(IDX
[k
]);
595 n
= template[i
].tap
[k
];
596 if (k
== template[i
].np
- 1)
597 n
+= enc
? authsize
: -authsize
;
599 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
600 printk(KERN_ERR
"alg: aead: Chunk "
601 "test %d failed on %s at page "
602 "%u for %s\n", j
, e
, k
, algo
);
608 if (k
== template[i
].np
- 1 && !enc
) {
609 if (memcmp(q
, template[i
].input
+
615 for (n
= 0; offset_in_page(q
+ n
) &&
620 printk(KERN_ERR
"alg: aead: Result "
621 "buffer corruption in chunk "
622 "test %d on %s at page %u for "
623 "%s: %u bytes:\n", j
, e
, k
,
629 temp
+= template[i
].tap
[k
];
637 aead_request_free(req
);
638 testmgr_free_buf(axbuf
);
640 testmgr_free_buf(xbuf
);
645 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
646 struct cipher_testvec
*template, unsigned int tcount
)
648 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
649 unsigned int i
, j
, k
;
653 char *xbuf
[XBUFSIZE
];
656 if (testmgr_alloc_buf(xbuf
))
665 for (i
= 0; i
< tcount
; i
++) {
672 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
676 memcpy(data
, template[i
].input
, template[i
].ilen
);
678 crypto_cipher_clear_flags(tfm
, ~0);
680 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
682 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
684 if (!ret
== template[i
].fail
) {
685 printk(KERN_ERR
"alg: cipher: setkey failed "
686 "on test %d for %s: flags=%x\n", j
,
687 algo
, crypto_cipher_get_flags(tfm
));
692 for (k
= 0; k
< template[i
].ilen
;
693 k
+= crypto_cipher_blocksize(tfm
)) {
695 crypto_cipher_encrypt_one(tfm
, data
+ k
,
698 crypto_cipher_decrypt_one(tfm
, data
+ k
,
703 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
704 printk(KERN_ERR
"alg: cipher: Test %d failed "
705 "on %s for %s\n", j
, e
, algo
);
706 hexdump(q
, template[i
].rlen
);
715 testmgr_free_buf(xbuf
);
720 static int test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
721 struct cipher_testvec
*template, unsigned int tcount
)
724 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm
));
725 unsigned int i
, j
, k
, n
, temp
;
727 struct ablkcipher_request
*req
;
728 struct scatterlist sg
[8];
730 struct tcrypt_result result
;
733 char *xbuf
[XBUFSIZE
];
736 if (testmgr_alloc_buf(xbuf
))
744 init_completion(&result
.completion
);
746 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
748 printk(KERN_ERR
"alg: skcipher: Failed to allocate request "
753 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
754 tcrypt_complete
, &result
);
757 for (i
= 0; i
< tcount
; i
++) {
759 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
761 memset(iv
, 0, MAX_IVLEN
);
763 if (!(template[i
].np
)) {
767 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
771 memcpy(data
, template[i
].input
, template[i
].ilen
);
773 crypto_ablkcipher_clear_flags(tfm
, ~0);
775 crypto_ablkcipher_set_flags(
776 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
778 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
780 if (!ret
== template[i
].fail
) {
781 printk(KERN_ERR
"alg: skcipher: setkey failed "
782 "on test %d for %s: flags=%x\n", j
,
783 algo
, crypto_ablkcipher_get_flags(tfm
));
788 sg_init_one(&sg
[0], data
, template[i
].ilen
);
790 ablkcipher_request_set_crypt(req
, sg
, sg
,
791 template[i
].ilen
, iv
);
793 crypto_ablkcipher_encrypt(req
) :
794 crypto_ablkcipher_decrypt(req
);
801 ret
= wait_for_completion_interruptible(
803 if (!ret
&& !((ret
= result
.err
))) {
804 INIT_COMPLETION(result
.completion
);
809 printk(KERN_ERR
"alg: skcipher: %s failed on "
810 "test %d for %s: ret=%d\n", e
, j
, algo
,
816 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
817 printk(KERN_ERR
"alg: skcipher: Test %d "
818 "failed on %s for %s\n", j
, e
, algo
);
819 hexdump(q
, template[i
].rlen
);
827 for (i
= 0; i
< tcount
; i
++) {
830 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
832 memset(iv
, 0, MAX_IVLEN
);
834 if (template[i
].np
) {
837 crypto_ablkcipher_clear_flags(tfm
, ~0);
839 crypto_ablkcipher_set_flags(
840 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
842 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
844 if (!ret
== template[i
].fail
) {
845 printk(KERN_ERR
"alg: skcipher: setkey failed "
846 "on chunk test %d for %s: flags=%x\n",
848 crypto_ablkcipher_get_flags(tfm
));
855 sg_init_table(sg
, template[i
].np
);
856 for (k
= 0; k
< template[i
].np
; k
++) {
857 if (WARN_ON(offset_in_page(IDX
[k
]) +
858 template[i
].tap
[k
] > PAGE_SIZE
))
861 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
862 offset_in_page(IDX
[k
]);
864 memcpy(q
, template[i
].input
+ temp
,
867 if (offset_in_page(q
) + template[i
].tap
[k
] <
869 q
[template[i
].tap
[k
]] = 0;
871 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
873 temp
+= template[i
].tap
[k
];
876 ablkcipher_request_set_crypt(req
, sg
, sg
,
877 template[i
].ilen
, iv
);
880 crypto_ablkcipher_encrypt(req
) :
881 crypto_ablkcipher_decrypt(req
);
888 ret
= wait_for_completion_interruptible(
890 if (!ret
&& !((ret
= result
.err
))) {
891 INIT_COMPLETION(result
.completion
);
896 printk(KERN_ERR
"alg: skcipher: %s failed on "
897 "chunk test %d for %s: ret=%d\n", e
, j
,
904 for (k
= 0; k
< template[i
].np
; k
++) {
905 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
906 offset_in_page(IDX
[k
]);
908 if (memcmp(q
, template[i
].result
+ temp
,
909 template[i
].tap
[k
])) {
910 printk(KERN_ERR
"alg: skcipher: Chunk "
911 "test %d failed on %s at page "
912 "%u for %s\n", j
, e
, k
, algo
);
913 hexdump(q
, template[i
].tap
[k
]);
917 q
+= template[i
].tap
[k
];
918 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
921 printk(KERN_ERR
"alg: skcipher: "
922 "Result buffer corruption in "
923 "chunk test %d on %s at page "
924 "%u for %s: %u bytes:\n", j
, e
,
929 temp
+= template[i
].tap
[k
];
937 ablkcipher_request_free(req
);
938 testmgr_free_buf(xbuf
);
943 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
944 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
946 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
948 char result
[COMP_BUF_SIZE
];
951 for (i
= 0; i
< ctcount
; i
++) {
953 unsigned int dlen
= COMP_BUF_SIZE
;
955 memset(result
, 0, sizeof (result
));
957 ilen
= ctemplate
[i
].inlen
;
958 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
959 ilen
, result
, &dlen
);
961 printk(KERN_ERR
"alg: comp: compression failed "
962 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
967 if (dlen
!= ctemplate
[i
].outlen
) {
968 printk(KERN_ERR
"alg: comp: Compression test %d "
969 "failed for %s: output len = %d\n", i
+ 1, algo
,
975 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
976 printk(KERN_ERR
"alg: comp: Compression test %d "
977 "failed for %s\n", i
+ 1, algo
);
978 hexdump(result
, dlen
);
984 for (i
= 0; i
< dtcount
; i
++) {
986 unsigned int dlen
= COMP_BUF_SIZE
;
988 memset(result
, 0, sizeof (result
));
990 ilen
= dtemplate
[i
].inlen
;
991 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
992 ilen
, result
, &dlen
);
994 printk(KERN_ERR
"alg: comp: decompression failed "
995 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1000 if (dlen
!= dtemplate
[i
].outlen
) {
1001 printk(KERN_ERR
"alg: comp: Decompression test %d "
1002 "failed for %s: output len = %d\n", i
+ 1, algo
,
1008 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1009 printk(KERN_ERR
"alg: comp: Decompression test %d "
1010 "failed for %s\n", i
+ 1, algo
);
1011 hexdump(result
, dlen
);
1023 static int test_pcomp(struct crypto_pcomp
*tfm
,
1024 struct pcomp_testvec
*ctemplate
,
1025 struct pcomp_testvec
*dtemplate
, int ctcount
,
1028 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
1030 char result
[COMP_BUF_SIZE
];
1033 for (i
= 0; i
< ctcount
; i
++) {
1034 struct comp_request req
;
1035 unsigned int produced
= 0;
1037 res
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
1038 ctemplate
[i
].paramsize
);
1040 pr_err("alg: pcomp: compression setup failed on test "
1041 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1045 res
= crypto_compress_init(tfm
);
1047 pr_err("alg: pcomp: compression init failed on test "
1048 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1052 memset(result
, 0, sizeof(result
));
1054 req
.next_in
= ctemplate
[i
].input
;
1055 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
1056 req
.next_out
= result
;
1057 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
1059 res
= crypto_compress_update(tfm
, &req
);
1060 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1061 pr_err("alg: pcomp: compression update failed on test "
1062 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1068 /* Add remaining input data */
1069 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
1071 res
= crypto_compress_update(tfm
, &req
);
1072 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1073 pr_err("alg: pcomp: compression update failed on test "
1074 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1080 /* Provide remaining output space */
1081 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1083 res
= crypto_compress_final(tfm
, &req
);
1085 pr_err("alg: pcomp: compression final failed on test "
1086 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1091 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1092 pr_err("alg: comp: Compression test %d failed for %s: "
1093 "output len = %d (expected %d)\n", i
+ 1, algo
,
1094 COMP_BUF_SIZE
- req
.avail_out
,
1095 ctemplate
[i
].outlen
);
1099 if (produced
!= ctemplate
[i
].outlen
) {
1100 pr_err("alg: comp: Compression test %d failed for %s: "
1101 "returned len = %u (expected %d)\n", i
+ 1,
1102 algo
, produced
, ctemplate
[i
].outlen
);
1106 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1107 pr_err("alg: pcomp: Compression test %d failed for "
1108 "%s\n", i
+ 1, algo
);
1109 hexdump(result
, ctemplate
[i
].outlen
);
1114 for (i
= 0; i
< dtcount
; i
++) {
1115 struct comp_request req
;
1116 unsigned int produced
= 0;
1118 res
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1119 dtemplate
[i
].paramsize
);
1121 pr_err("alg: pcomp: decompression setup failed on "
1122 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1126 res
= crypto_decompress_init(tfm
);
1128 pr_err("alg: pcomp: decompression init failed on test "
1129 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1133 memset(result
, 0, sizeof(result
));
1135 req
.next_in
= dtemplate
[i
].input
;
1136 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1137 req
.next_out
= result
;
1138 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1140 res
= crypto_decompress_update(tfm
, &req
);
1141 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1142 pr_err("alg: pcomp: decompression update failed on "
1143 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1149 /* Add remaining input data */
1150 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1152 res
= crypto_decompress_update(tfm
, &req
);
1153 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1154 pr_err("alg: pcomp: decompression update failed on "
1155 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1161 /* Provide remaining output space */
1162 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1164 res
= crypto_decompress_final(tfm
, &req
);
1165 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1166 pr_err("alg: pcomp: decompression final failed on "
1167 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1173 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1174 pr_err("alg: comp: Decompression test %d failed for "
1175 "%s: output len = %d (expected %d)\n", i
+ 1,
1176 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1177 dtemplate
[i
].outlen
);
1181 if (produced
!= dtemplate
[i
].outlen
) {
1182 pr_err("alg: comp: Decompression test %d failed for "
1183 "%s: returned len = %u (expected %d)\n", i
+ 1,
1184 algo
, produced
, dtemplate
[i
].outlen
);
1188 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1189 pr_err("alg: pcomp: Decompression test %d failed for "
1190 "%s\n", i
+ 1, algo
);
1191 hexdump(result
, dtemplate
[i
].outlen
);
1200 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1201 unsigned int tcount
)
1203 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1204 int err
= 0, i
, j
, seedsize
;
1208 seedsize
= crypto_rng_seedsize(tfm
);
1210 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1212 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1217 for (i
= 0; i
< tcount
; i
++) {
1218 memset(result
, 0, 32);
1220 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1221 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1223 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1224 template[i
].dt
, template[i
].dtlen
);
1226 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1228 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1233 for (j
= 0; j
< template[i
].loops
; j
++) {
1234 err
= crypto_rng_get_bytes(tfm
, result
,
1236 if (err
!= template[i
].rlen
) {
1237 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1238 "the correct amount of random data for "
1239 "%s (requested %d, got %d)\n", algo
,
1240 template[i
].rlen
, err
);
1245 err
= memcmp(result
, template[i
].result
,
1248 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1250 hexdump(result
, template[i
].rlen
);
1261 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1264 struct crypto_aead
*tfm
;
1267 tfm
= crypto_alloc_aead(driver
, type
, mask
);
1269 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1270 "%ld\n", driver
, PTR_ERR(tfm
));
1271 return PTR_ERR(tfm
);
1274 if (desc
->suite
.aead
.enc
.vecs
) {
1275 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1276 desc
->suite
.aead
.enc
.count
);
1281 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1282 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1283 desc
->suite
.aead
.dec
.count
);
1286 crypto_free_aead(tfm
);
1290 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1291 const char *driver
, u32 type
, u32 mask
)
1293 struct crypto_cipher
*tfm
;
1296 tfm
= crypto_alloc_cipher(driver
, type
, mask
);
1298 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1299 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1300 return PTR_ERR(tfm
);
1303 if (desc
->suite
.cipher
.enc
.vecs
) {
1304 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1305 desc
->suite
.cipher
.enc
.count
);
1310 if (desc
->suite
.cipher
.dec
.vecs
)
1311 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1312 desc
->suite
.cipher
.dec
.count
);
1315 crypto_free_cipher(tfm
);
1319 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1320 const char *driver
, u32 type
, u32 mask
)
1322 struct crypto_ablkcipher
*tfm
;
1325 tfm
= crypto_alloc_ablkcipher(driver
, type
, mask
);
1327 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1328 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1329 return PTR_ERR(tfm
);
1332 if (desc
->suite
.cipher
.enc
.vecs
) {
1333 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1334 desc
->suite
.cipher
.enc
.count
);
1339 if (desc
->suite
.cipher
.dec
.vecs
)
1340 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1341 desc
->suite
.cipher
.dec
.count
);
1344 crypto_free_ablkcipher(tfm
);
1348 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1351 struct crypto_comp
*tfm
;
1354 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1356 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1357 "%ld\n", driver
, PTR_ERR(tfm
));
1358 return PTR_ERR(tfm
);
1361 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1362 desc
->suite
.comp
.decomp
.vecs
,
1363 desc
->suite
.comp
.comp
.count
,
1364 desc
->suite
.comp
.decomp
.count
);
1366 crypto_free_comp(tfm
);
1370 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1373 struct crypto_pcomp
*tfm
;
1376 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1378 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1379 driver
, PTR_ERR(tfm
));
1380 return PTR_ERR(tfm
);
1383 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1384 desc
->suite
.pcomp
.decomp
.vecs
,
1385 desc
->suite
.pcomp
.comp
.count
,
1386 desc
->suite
.pcomp
.decomp
.count
);
1388 crypto_free_pcomp(tfm
);
1392 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1395 struct crypto_ahash
*tfm
;
1398 tfm
= crypto_alloc_ahash(driver
, type
, mask
);
1400 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1401 "%ld\n", driver
, PTR_ERR(tfm
));
1402 return PTR_ERR(tfm
);
1405 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
, desc
->suite
.hash
.count
);
1407 crypto_free_ahash(tfm
);
1411 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1412 const char *driver
, u32 type
, u32 mask
)
1414 struct crypto_shash
*tfm
;
1418 err
= alg_test_hash(desc
, driver
, type
, mask
);
1422 tfm
= crypto_alloc_shash(driver
, type
, mask
);
1424 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1425 "%ld\n", driver
, PTR_ERR(tfm
));
1432 struct shash_desc shash
;
1433 char ctx
[crypto_shash_descsize(tfm
)];
1436 sdesc
.shash
.tfm
= tfm
;
1437 sdesc
.shash
.flags
= 0;
1439 *(u32
*)sdesc
.ctx
= le32_to_cpu(420553207);
1440 err
= crypto_shash_final(&sdesc
.shash
, (u8
*)&val
);
1442 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1443 "%s: %d\n", driver
, err
);
1447 if (val
!= ~420553207) {
1448 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1449 "%d\n", driver
, val
);
1454 crypto_free_shash(tfm
);
1460 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1463 struct crypto_rng
*rng
;
1466 rng
= crypto_alloc_rng(driver
, type
, mask
);
1468 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1469 "%ld\n", driver
, PTR_ERR(rng
));
1470 return PTR_ERR(rng
);
1473 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1475 crypto_free_rng(rng
);
1480 static int alg_test_null(const struct alg_test_desc
*desc
,
1481 const char *driver
, u32 type
, u32 mask
)
1486 /* Please keep this list sorted by algorithm name. */
1487 static const struct alg_test_desc alg_test_descs
[] = {
1489 .alg
= "__driver-cbc-aes-aesni",
1490 .test
= alg_test_null
,
1504 .alg
= "__driver-ecb-aes-aesni",
1505 .test
= alg_test_null
,
1519 .alg
= "__ghash-pclmulqdqni",
1520 .test
= alg_test_null
,
1528 .alg
= "ansi_cprng",
1529 .test
= alg_test_cprng
,
1533 .vecs
= ansi_cprng_aes_tv_template
,
1534 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1539 .test
= alg_test_skcipher
,
1544 .vecs
= aes_cbc_enc_tv_template
,
1545 .count
= AES_CBC_ENC_TEST_VECTORS
1548 .vecs
= aes_cbc_dec_tv_template
,
1549 .count
= AES_CBC_DEC_TEST_VECTORS
1554 .alg
= "cbc(anubis)",
1555 .test
= alg_test_skcipher
,
1559 .vecs
= anubis_cbc_enc_tv_template
,
1560 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
1563 .vecs
= anubis_cbc_dec_tv_template
,
1564 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
1569 .alg
= "cbc(blowfish)",
1570 .test
= alg_test_skcipher
,
1574 .vecs
= bf_cbc_enc_tv_template
,
1575 .count
= BF_CBC_ENC_TEST_VECTORS
1578 .vecs
= bf_cbc_dec_tv_template
,
1579 .count
= BF_CBC_DEC_TEST_VECTORS
1584 .alg
= "cbc(camellia)",
1585 .test
= alg_test_skcipher
,
1589 .vecs
= camellia_cbc_enc_tv_template
,
1590 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
1593 .vecs
= camellia_cbc_dec_tv_template
,
1594 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
1600 .test
= alg_test_skcipher
,
1604 .vecs
= des_cbc_enc_tv_template
,
1605 .count
= DES_CBC_ENC_TEST_VECTORS
1608 .vecs
= des_cbc_dec_tv_template
,
1609 .count
= DES_CBC_DEC_TEST_VECTORS
1614 .alg
= "cbc(des3_ede)",
1615 .test
= alg_test_skcipher
,
1620 .vecs
= des3_ede_cbc_enc_tv_template
,
1621 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
1624 .vecs
= des3_ede_cbc_dec_tv_template
,
1625 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
1630 .alg
= "cbc(twofish)",
1631 .test
= alg_test_skcipher
,
1635 .vecs
= tf_cbc_enc_tv_template
,
1636 .count
= TF_CBC_ENC_TEST_VECTORS
1639 .vecs
= tf_cbc_dec_tv_template
,
1640 .count
= TF_CBC_DEC_TEST_VECTORS
1646 .test
= alg_test_aead
,
1651 .vecs
= aes_ccm_enc_tv_template
,
1652 .count
= AES_CCM_ENC_TEST_VECTORS
1655 .vecs
= aes_ccm_dec_tv_template
,
1656 .count
= AES_CCM_DEC_TEST_VECTORS
1662 .test
= alg_test_crc32c
,
1666 .vecs
= crc32c_tv_template
,
1667 .count
= CRC32C_TEST_VECTORS
1671 .alg
= "cryptd(__driver-ecb-aes-aesni)",
1672 .test
= alg_test_null
,
1686 .alg
= "cryptd(__ghash-pclmulqdqni)",
1687 .test
= alg_test_null
,
1696 .test
= alg_test_skcipher
,
1701 .vecs
= aes_ctr_enc_tv_template
,
1702 .count
= AES_CTR_ENC_TEST_VECTORS
1705 .vecs
= aes_ctr_dec_tv_template
,
1706 .count
= AES_CTR_DEC_TEST_VECTORS
1711 .alg
= "cts(cbc(aes))",
1712 .test
= alg_test_skcipher
,
1716 .vecs
= cts_mode_enc_tv_template
,
1717 .count
= CTS_MODE_ENC_TEST_VECTORS
1720 .vecs
= cts_mode_dec_tv_template
,
1721 .count
= CTS_MODE_DEC_TEST_VECTORS
1727 .test
= alg_test_comp
,
1731 .vecs
= deflate_comp_tv_template
,
1732 .count
= DEFLATE_COMP_TEST_VECTORS
1735 .vecs
= deflate_decomp_tv_template
,
1736 .count
= DEFLATE_DECOMP_TEST_VECTORS
1741 .alg
= "ecb(__aes-aesni)",
1742 .test
= alg_test_null
,
1757 .test
= alg_test_skcipher
,
1762 .vecs
= aes_enc_tv_template
,
1763 .count
= AES_ENC_TEST_VECTORS
1766 .vecs
= aes_dec_tv_template
,
1767 .count
= AES_DEC_TEST_VECTORS
1772 .alg
= "ecb(anubis)",
1773 .test
= alg_test_skcipher
,
1777 .vecs
= anubis_enc_tv_template
,
1778 .count
= ANUBIS_ENC_TEST_VECTORS
1781 .vecs
= anubis_dec_tv_template
,
1782 .count
= ANUBIS_DEC_TEST_VECTORS
1788 .test
= alg_test_skcipher
,
1792 .vecs
= arc4_enc_tv_template
,
1793 .count
= ARC4_ENC_TEST_VECTORS
1796 .vecs
= arc4_dec_tv_template
,
1797 .count
= ARC4_DEC_TEST_VECTORS
1802 .alg
= "ecb(blowfish)",
1803 .test
= alg_test_skcipher
,
1807 .vecs
= bf_enc_tv_template
,
1808 .count
= BF_ENC_TEST_VECTORS
1811 .vecs
= bf_dec_tv_template
,
1812 .count
= BF_DEC_TEST_VECTORS
1817 .alg
= "ecb(camellia)",
1818 .test
= alg_test_skcipher
,
1822 .vecs
= camellia_enc_tv_template
,
1823 .count
= CAMELLIA_ENC_TEST_VECTORS
1826 .vecs
= camellia_dec_tv_template
,
1827 .count
= CAMELLIA_DEC_TEST_VECTORS
1832 .alg
= "ecb(cast5)",
1833 .test
= alg_test_skcipher
,
1837 .vecs
= cast5_enc_tv_template
,
1838 .count
= CAST5_ENC_TEST_VECTORS
1841 .vecs
= cast5_dec_tv_template
,
1842 .count
= CAST5_DEC_TEST_VECTORS
1847 .alg
= "ecb(cast6)",
1848 .test
= alg_test_skcipher
,
1852 .vecs
= cast6_enc_tv_template
,
1853 .count
= CAST6_ENC_TEST_VECTORS
1856 .vecs
= cast6_dec_tv_template
,
1857 .count
= CAST6_DEC_TEST_VECTORS
1863 .test
= alg_test_skcipher
,
1868 .vecs
= des_enc_tv_template
,
1869 .count
= DES_ENC_TEST_VECTORS
1872 .vecs
= des_dec_tv_template
,
1873 .count
= DES_DEC_TEST_VECTORS
1878 .alg
= "ecb(des3_ede)",
1879 .test
= alg_test_skcipher
,
1884 .vecs
= des3_ede_enc_tv_template
,
1885 .count
= DES3_EDE_ENC_TEST_VECTORS
1888 .vecs
= des3_ede_dec_tv_template
,
1889 .count
= DES3_EDE_DEC_TEST_VECTORS
1894 .alg
= "ecb(khazad)",
1895 .test
= alg_test_skcipher
,
1899 .vecs
= khazad_enc_tv_template
,
1900 .count
= KHAZAD_ENC_TEST_VECTORS
1903 .vecs
= khazad_dec_tv_template
,
1904 .count
= KHAZAD_DEC_TEST_VECTORS
1910 .test
= alg_test_skcipher
,
1914 .vecs
= seed_enc_tv_template
,
1915 .count
= SEED_ENC_TEST_VECTORS
1918 .vecs
= seed_dec_tv_template
,
1919 .count
= SEED_DEC_TEST_VECTORS
1924 .alg
= "ecb(serpent)",
1925 .test
= alg_test_skcipher
,
1929 .vecs
= serpent_enc_tv_template
,
1930 .count
= SERPENT_ENC_TEST_VECTORS
1933 .vecs
= serpent_dec_tv_template
,
1934 .count
= SERPENT_DEC_TEST_VECTORS
1940 .test
= alg_test_skcipher
,
1944 .vecs
= tea_enc_tv_template
,
1945 .count
= TEA_ENC_TEST_VECTORS
1948 .vecs
= tea_dec_tv_template
,
1949 .count
= TEA_DEC_TEST_VECTORS
1954 .alg
= "ecb(tnepres)",
1955 .test
= alg_test_skcipher
,
1959 .vecs
= tnepres_enc_tv_template
,
1960 .count
= TNEPRES_ENC_TEST_VECTORS
1963 .vecs
= tnepres_dec_tv_template
,
1964 .count
= TNEPRES_DEC_TEST_VECTORS
1969 .alg
= "ecb(twofish)",
1970 .test
= alg_test_skcipher
,
1974 .vecs
= tf_enc_tv_template
,
1975 .count
= TF_ENC_TEST_VECTORS
1978 .vecs
= tf_dec_tv_template
,
1979 .count
= TF_DEC_TEST_VECTORS
1985 .test
= alg_test_skcipher
,
1989 .vecs
= xeta_enc_tv_template
,
1990 .count
= XETA_ENC_TEST_VECTORS
1993 .vecs
= xeta_dec_tv_template
,
1994 .count
= XETA_DEC_TEST_VECTORS
2000 .test
= alg_test_skcipher
,
2004 .vecs
= xtea_enc_tv_template
,
2005 .count
= XTEA_ENC_TEST_VECTORS
2008 .vecs
= xtea_dec_tv_template
,
2009 .count
= XTEA_DEC_TEST_VECTORS
2015 .test
= alg_test_aead
,
2020 .vecs
= aes_gcm_enc_tv_template
,
2021 .count
= AES_GCM_ENC_TEST_VECTORS
2024 .vecs
= aes_gcm_dec_tv_template
,
2025 .count
= AES_GCM_DEC_TEST_VECTORS
2031 .test
= alg_test_hash
,
2034 .vecs
= ghash_tv_template
,
2035 .count
= GHASH_TEST_VECTORS
2040 .test
= alg_test_hash
,
2043 .vecs
= hmac_md5_tv_template
,
2044 .count
= HMAC_MD5_TEST_VECTORS
2048 .alg
= "hmac(rmd128)",
2049 .test
= alg_test_hash
,
2052 .vecs
= hmac_rmd128_tv_template
,
2053 .count
= HMAC_RMD128_TEST_VECTORS
2057 .alg
= "hmac(rmd160)",
2058 .test
= alg_test_hash
,
2061 .vecs
= hmac_rmd160_tv_template
,
2062 .count
= HMAC_RMD160_TEST_VECTORS
2066 .alg
= "hmac(sha1)",
2067 .test
= alg_test_hash
,
2071 .vecs
= hmac_sha1_tv_template
,
2072 .count
= HMAC_SHA1_TEST_VECTORS
2076 .alg
= "hmac(sha224)",
2077 .test
= alg_test_hash
,
2081 .vecs
= hmac_sha224_tv_template
,
2082 .count
= HMAC_SHA224_TEST_VECTORS
2086 .alg
= "hmac(sha256)",
2087 .test
= alg_test_hash
,
2091 .vecs
= hmac_sha256_tv_template
,
2092 .count
= HMAC_SHA256_TEST_VECTORS
2096 .alg
= "hmac(sha384)",
2097 .test
= alg_test_hash
,
2101 .vecs
= hmac_sha384_tv_template
,
2102 .count
= HMAC_SHA384_TEST_VECTORS
2106 .alg
= "hmac(sha512)",
2107 .test
= alg_test_hash
,
2111 .vecs
= hmac_sha512_tv_template
,
2112 .count
= HMAC_SHA512_TEST_VECTORS
2117 .test
= alg_test_skcipher
,
2121 .vecs
= aes_lrw_enc_tv_template
,
2122 .count
= AES_LRW_ENC_TEST_VECTORS
2125 .vecs
= aes_lrw_dec_tv_template
,
2126 .count
= AES_LRW_DEC_TEST_VECTORS
2132 .test
= alg_test_comp
,
2136 .vecs
= lzo_comp_tv_template
,
2137 .count
= LZO_COMP_TEST_VECTORS
2140 .vecs
= lzo_decomp_tv_template
,
2141 .count
= LZO_DECOMP_TEST_VECTORS
2147 .test
= alg_test_hash
,
2150 .vecs
= md4_tv_template
,
2151 .count
= MD4_TEST_VECTORS
2156 .test
= alg_test_hash
,
2159 .vecs
= md5_tv_template
,
2160 .count
= MD5_TEST_VECTORS
2164 .alg
= "michael_mic",
2165 .test
= alg_test_hash
,
2168 .vecs
= michael_mic_tv_template
,
2169 .count
= MICHAEL_MIC_TEST_VECTORS
2173 .alg
= "pcbc(fcrypt)",
2174 .test
= alg_test_skcipher
,
2178 .vecs
= fcrypt_pcbc_enc_tv_template
,
2179 .count
= FCRYPT_ENC_TEST_VECTORS
2182 .vecs
= fcrypt_pcbc_dec_tv_template
,
2183 .count
= FCRYPT_DEC_TEST_VECTORS
2188 .alg
= "rfc3686(ctr(aes))",
2189 .test
= alg_test_skcipher
,
2194 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
2195 .count
= AES_CTR_3686_ENC_TEST_VECTORS
2198 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
2199 .count
= AES_CTR_3686_DEC_TEST_VECTORS
2204 .alg
= "rfc4309(ccm(aes))",
2205 .test
= alg_test_aead
,
2210 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
2211 .count
= AES_CCM_4309_ENC_TEST_VECTORS
2214 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
2215 .count
= AES_CCM_4309_DEC_TEST_VECTORS
2221 .test
= alg_test_hash
,
2224 .vecs
= rmd128_tv_template
,
2225 .count
= RMD128_TEST_VECTORS
2230 .test
= alg_test_hash
,
2233 .vecs
= rmd160_tv_template
,
2234 .count
= RMD160_TEST_VECTORS
2239 .test
= alg_test_hash
,
2242 .vecs
= rmd256_tv_template
,
2243 .count
= RMD256_TEST_VECTORS
2248 .test
= alg_test_hash
,
2251 .vecs
= rmd320_tv_template
,
2252 .count
= RMD320_TEST_VECTORS
2257 .test
= alg_test_skcipher
,
2261 .vecs
= salsa20_stream_enc_tv_template
,
2262 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
2268 .test
= alg_test_hash
,
2272 .vecs
= sha1_tv_template
,
2273 .count
= SHA1_TEST_VECTORS
2278 .test
= alg_test_hash
,
2282 .vecs
= sha224_tv_template
,
2283 .count
= SHA224_TEST_VECTORS
2288 .test
= alg_test_hash
,
2292 .vecs
= sha256_tv_template
,
2293 .count
= SHA256_TEST_VECTORS
2298 .test
= alg_test_hash
,
2302 .vecs
= sha384_tv_template
,
2303 .count
= SHA384_TEST_VECTORS
2308 .test
= alg_test_hash
,
2312 .vecs
= sha512_tv_template
,
2313 .count
= SHA512_TEST_VECTORS
2318 .test
= alg_test_hash
,
2321 .vecs
= tgr128_tv_template
,
2322 .count
= TGR128_TEST_VECTORS
2327 .test
= alg_test_hash
,
2330 .vecs
= tgr160_tv_template
,
2331 .count
= TGR160_TEST_VECTORS
2336 .test
= alg_test_hash
,
2339 .vecs
= tgr192_tv_template
,
2340 .count
= TGR192_TEST_VECTORS
2345 .test
= alg_test_hash
,
2348 .vecs
= aes_vmac128_tv_template
,
2349 .count
= VMAC_AES_TEST_VECTORS
2354 .test
= alg_test_hash
,
2357 .vecs
= wp256_tv_template
,
2358 .count
= WP256_TEST_VECTORS
2363 .test
= alg_test_hash
,
2366 .vecs
= wp384_tv_template
,
2367 .count
= WP384_TEST_VECTORS
2372 .test
= alg_test_hash
,
2375 .vecs
= wp512_tv_template
,
2376 .count
= WP512_TEST_VECTORS
2381 .test
= alg_test_hash
,
2384 .vecs
= aes_xcbc128_tv_template
,
2385 .count
= XCBC_AES_TEST_VECTORS
2390 .test
= alg_test_skcipher
,
2394 .vecs
= aes_xts_enc_tv_template
,
2395 .count
= AES_XTS_ENC_TEST_VECTORS
2398 .vecs
= aes_xts_dec_tv_template
,
2399 .count
= AES_XTS_DEC_TEST_VECTORS
2405 .test
= alg_test_pcomp
,
2409 .vecs
= zlib_comp_tv_template
,
2410 .count
= ZLIB_COMP_TEST_VECTORS
2413 .vecs
= zlib_decomp_tv_template
,
2414 .count
= ZLIB_DECOMP_TEST_VECTORS
2421 static int alg_find_test(const char *alg
)
2424 int end
= ARRAY_SIZE(alg_test_descs
);
2426 while (start
< end
) {
2427 int i
= (start
+ end
) / 2;
2428 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
2446 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
2452 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
2453 char nalg
[CRYPTO_MAX_ALG_NAME
];
2455 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
2457 return -ENAMETOOLONG
;
2459 i
= alg_find_test(nalg
);
2463 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
2466 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
2470 i
= alg_find_test(alg
);
2471 j
= alg_find_test(driver
);
2475 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
2476 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
2481 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
2484 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
2488 if (fips_enabled
&& rc
)
2489 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
2491 if (fips_enabled
&& !rc
)
2492 printk(KERN_INFO
"alg: self-tests for %s (%s) passed\n",
2498 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
2503 EXPORT_SYMBOL_GPL(alg_test
);