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 * Updated RFC4106 AES-GCM testing.
10 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
11 * Adrian Hoban <adrian.hoban@intel.com>
12 * Gabriele Paoloni <gabriele.paoloni@intel.com>
13 * Tadeusz Struk (tadeusz.struk@intel.com)
14 * Copyright (c) 2010, Intel Corporation.
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at your option)
23 #include <crypto/aead.h>
24 #include <crypto/hash.h>
25 #include <crypto/skcipher.h>
26 #include <linux/err.h>
27 #include <linux/fips.h>
28 #include <linux/module.h>
29 #include <linux/scatterlist.h>
30 #include <linux/slab.h>
31 #include <linux/string.h>
32 #include <crypto/rng.h>
33 #include <crypto/drbg.h>
34 #include <crypto/akcipher.h>
38 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
41 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
51 * Need slab memory for testing (size in number of pages).
56 * Indexes into the xbuf to simulate cross-page access.
68 * Used by test_cipher()
73 struct tcrypt_result
{
74 struct completion completion
;
78 struct aead_test_suite
{
80 struct aead_testvec
*vecs
;
85 struct cipher_test_suite
{
87 struct cipher_testvec
*vecs
;
92 struct comp_test_suite
{
94 struct comp_testvec
*vecs
;
99 struct hash_test_suite
{
100 struct hash_testvec
*vecs
;
104 struct cprng_test_suite
{
105 struct cprng_testvec
*vecs
;
109 struct drbg_test_suite
{
110 struct drbg_testvec
*vecs
;
114 struct akcipher_test_suite
{
115 struct akcipher_testvec
*vecs
;
119 struct alg_test_desc
{
121 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
123 int fips_allowed
; /* set if alg is allowed in fips mode */
126 struct aead_test_suite aead
;
127 struct cipher_test_suite cipher
;
128 struct comp_test_suite comp
;
129 struct hash_test_suite hash
;
130 struct cprng_test_suite cprng
;
131 struct drbg_test_suite drbg
;
132 struct akcipher_test_suite akcipher
;
136 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
138 static void hexdump(unsigned char *buf
, unsigned int len
)
140 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
145 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
147 struct tcrypt_result
*res
= req
->data
;
149 if (err
== -EINPROGRESS
)
153 complete(&res
->completion
);
156 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
160 for (i
= 0; i
< XBUFSIZE
; i
++) {
161 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
170 free_page((unsigned long)buf
[i
]);
175 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
179 for (i
= 0; i
< XBUFSIZE
; i
++)
180 free_page((unsigned long)buf
[i
]);
183 static int wait_async_op(struct tcrypt_result
*tr
, int ret
)
185 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
186 wait_for_completion(&tr
->completion
);
187 reinit_completion(&tr
->completion
);
193 static int __test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
194 unsigned int tcount
, bool use_digest
,
195 const int align_offset
)
197 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
198 unsigned int i
, j
, k
, temp
;
199 struct scatterlist sg
[8];
202 struct ahash_request
*req
;
203 struct tcrypt_result tresult
;
205 char *xbuf
[XBUFSIZE
];
208 result
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
211 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
214 if (testmgr_alloc_buf(xbuf
))
217 init_completion(&tresult
.completion
);
219 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
221 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
225 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
226 tcrypt_complete
, &tresult
);
229 for (i
= 0; i
< tcount
; i
++) {
234 if (WARN_ON(align_offset
+ template[i
].psize
> PAGE_SIZE
))
238 memset(result
, 0, MAX_DIGEST_SIZE
);
241 hash_buff
+= align_offset
;
243 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
244 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
246 if (template[i
].ksize
) {
247 crypto_ahash_clear_flags(tfm
, ~0);
248 if (template[i
].ksize
> MAX_KEYLEN
) {
249 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
250 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
254 memcpy(key
, template[i
].key
, template[i
].ksize
);
255 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
257 printk(KERN_ERR
"alg: hash: setkey failed on "
258 "test %d for %s: ret=%d\n", j
, algo
,
264 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
266 ret
= wait_async_op(&tresult
, crypto_ahash_digest(req
));
268 pr_err("alg: hash: digest failed on test %d "
269 "for %s: ret=%d\n", j
, algo
, -ret
);
273 ret
= wait_async_op(&tresult
, crypto_ahash_init(req
));
275 pr_err("alt: hash: init failed on test %d "
276 "for %s: ret=%d\n", j
, algo
, -ret
);
279 ret
= wait_async_op(&tresult
, crypto_ahash_update(req
));
281 pr_err("alt: hash: update failed on test %d "
282 "for %s: ret=%d\n", j
, algo
, -ret
);
285 ret
= wait_async_op(&tresult
, crypto_ahash_final(req
));
287 pr_err("alt: hash: final failed on test %d "
288 "for %s: ret=%d\n", j
, algo
, -ret
);
293 if (memcmp(result
, template[i
].digest
,
294 crypto_ahash_digestsize(tfm
))) {
295 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
297 hexdump(result
, crypto_ahash_digestsize(tfm
));
304 for (i
= 0; i
< tcount
; i
++) {
305 /* alignment tests are only done with continuous buffers */
306 if (align_offset
!= 0)
313 memset(result
, 0, MAX_DIGEST_SIZE
);
316 sg_init_table(sg
, template[i
].np
);
318 for (k
= 0; k
< template[i
].np
; k
++) {
319 if (WARN_ON(offset_in_page(IDX
[k
]) +
320 template[i
].tap
[k
] > PAGE_SIZE
))
323 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
324 offset_in_page(IDX
[k
]),
325 template[i
].plaintext
+ temp
,
328 temp
+= template[i
].tap
[k
];
331 if (template[i
].ksize
) {
332 if (template[i
].ksize
> MAX_KEYLEN
) {
333 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
334 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
338 crypto_ahash_clear_flags(tfm
, ~0);
339 memcpy(key
, template[i
].key
, template[i
].ksize
);
340 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
343 printk(KERN_ERR
"alg: hash: setkey "
344 "failed on chunking test %d "
345 "for %s: ret=%d\n", j
, algo
, -ret
);
350 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
351 ret
= crypto_ahash_digest(req
);
357 wait_for_completion(&tresult
.completion
);
358 reinit_completion(&tresult
.completion
);
364 printk(KERN_ERR
"alg: hash: digest failed "
365 "on chunking test %d for %s: "
366 "ret=%d\n", j
, algo
, -ret
);
370 if (memcmp(result
, template[i
].digest
,
371 crypto_ahash_digestsize(tfm
))) {
372 printk(KERN_ERR
"alg: hash: Chunking test %d "
373 "failed for %s\n", j
, algo
);
374 hexdump(result
, crypto_ahash_digestsize(tfm
));
383 ahash_request_free(req
);
385 testmgr_free_buf(xbuf
);
392 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
393 unsigned int tcount
, bool use_digest
)
395 unsigned int alignmask
;
398 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 0);
402 /* test unaligned buffers, check with one byte offset */
403 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 1);
407 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
409 /* Check if alignment mask for tfm is correctly set. */
410 ret
= __test_hash(tfm
, template, tcount
, use_digest
,
419 static int __test_aead(struct crypto_aead
*tfm
, int enc
,
420 struct aead_testvec
*template, unsigned int tcount
,
421 const bool diff_dst
, const int align_offset
)
423 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
424 unsigned int i
, j
, k
, n
, temp
;
428 struct aead_request
*req
;
429 struct scatterlist
*sg
;
430 struct scatterlist
*sgout
;
432 struct tcrypt_result result
;
433 unsigned int authsize
, iv_len
;
438 char *xbuf
[XBUFSIZE
];
439 char *xoutbuf
[XBUFSIZE
];
440 char *axbuf
[XBUFSIZE
];
442 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
445 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
448 if (testmgr_alloc_buf(xbuf
))
450 if (testmgr_alloc_buf(axbuf
))
452 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
455 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
456 sg
= kmalloc(sizeof(*sg
) * 8 * (diff_dst
? 4 : 2), GFP_KERNEL
);
471 init_completion(&result
.completion
);
473 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
475 pr_err("alg: aead%s: Failed to allocate request for %s\n",
480 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
481 tcrypt_complete
, &result
);
483 for (i
= 0, j
= 0; i
< tcount
; i
++) {
489 /* some templates have no input data but they will
493 input
+= align_offset
;
497 if (WARN_ON(align_offset
+ template[i
].ilen
>
498 PAGE_SIZE
|| template[i
].alen
> PAGE_SIZE
))
501 memcpy(input
, template[i
].input
, template[i
].ilen
);
502 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
503 iv_len
= crypto_aead_ivsize(tfm
);
505 memcpy(iv
, template[i
].iv
, iv_len
);
507 memset(iv
, 0, iv_len
);
509 crypto_aead_clear_flags(tfm
, ~0);
511 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
513 if (template[i
].klen
> MAX_KEYLEN
) {
514 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
515 d
, j
, algo
, template[i
].klen
,
520 memcpy(key
, template[i
].key
, template[i
].klen
);
522 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
523 if (!ret
== template[i
].fail
) {
524 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
525 d
, j
, algo
, crypto_aead_get_flags(tfm
));
530 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
531 ret
= crypto_aead_setauthsize(tfm
, authsize
);
533 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
534 d
, authsize
, j
, algo
);
538 k
= !!template[i
].alen
;
539 sg_init_table(sg
, k
+ 1);
540 sg_set_buf(&sg
[0], assoc
, template[i
].alen
);
541 sg_set_buf(&sg
[k
], input
,
542 template[i
].ilen
+ (enc
? authsize
: 0));
546 sg_init_table(sgout
, k
+ 1);
547 sg_set_buf(&sgout
[0], assoc
, template[i
].alen
);
550 output
+= align_offset
;
551 sg_set_buf(&sgout
[k
], output
,
552 template[i
].rlen
+ (enc
? 0 : authsize
));
555 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
556 template[i
].ilen
, iv
);
558 aead_request_set_ad(req
, template[i
].alen
);
560 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
564 if (template[i
].novrfy
) {
565 /* verification was supposed to fail */
566 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
568 /* so really, we got a bad message */
575 wait_for_completion(&result
.completion
);
576 reinit_completion(&result
.completion
);
581 if (template[i
].novrfy
)
582 /* verification failure was expected */
586 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
587 d
, e
, j
, algo
, -ret
);
592 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
593 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
595 hexdump(q
, template[i
].rlen
);
601 for (i
= 0, j
= 0; i
< tcount
; i
++) {
602 /* alignment tests are only done with continuous buffers */
603 if (align_offset
!= 0)
612 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
614 memset(iv
, 0, MAX_IVLEN
);
616 crypto_aead_clear_flags(tfm
, ~0);
618 crypto_aead_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
619 if (template[i
].klen
> MAX_KEYLEN
) {
620 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
621 d
, j
, algo
, template[i
].klen
, MAX_KEYLEN
);
625 memcpy(key
, template[i
].key
, template[i
].klen
);
627 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
628 if (!ret
== template[i
].fail
) {
629 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
630 d
, j
, algo
, crypto_aead_get_flags(tfm
));
635 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
638 sg_init_table(sg
, template[i
].anp
+ template[i
].np
);
640 sg_init_table(sgout
, template[i
].anp
+ template[i
].np
);
643 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
644 if (WARN_ON(offset_in_page(IDX
[k
]) +
645 template[i
].atap
[k
] > PAGE_SIZE
))
648 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
649 offset_in_page(IDX
[k
]),
650 template[i
].assoc
+ temp
,
651 template[i
].atap
[k
]),
652 template[i
].atap
[k
]);
654 sg_set_buf(&sgout
[k
],
655 axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
656 offset_in_page(IDX
[k
]),
657 template[i
].atap
[k
]);
658 temp
+= template[i
].atap
[k
];
661 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
662 if (WARN_ON(offset_in_page(IDX
[k
]) +
663 template[i
].tap
[k
] > PAGE_SIZE
))
666 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
667 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
668 sg_set_buf(&sg
[template[i
].anp
+ k
],
669 q
, template[i
].tap
[k
]);
672 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
673 offset_in_page(IDX
[k
]);
675 memset(q
, 0, template[i
].tap
[k
]);
677 sg_set_buf(&sgout
[template[i
].anp
+ k
],
678 q
, template[i
].tap
[k
]);
681 n
= template[i
].tap
[k
];
682 if (k
== template[i
].np
- 1 && enc
)
684 if (offset_in_page(q
) + n
< PAGE_SIZE
)
687 temp
+= template[i
].tap
[k
];
690 ret
= crypto_aead_setauthsize(tfm
, authsize
);
692 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
693 d
, authsize
, j
, algo
);
698 if (WARN_ON(sg
[template[i
].anp
+ k
- 1].offset
+
699 sg
[template[i
].anp
+ k
- 1].length
+
700 authsize
> PAGE_SIZE
)) {
706 sgout
[template[i
].anp
+ k
- 1].length
+=
708 sg
[template[i
].anp
+ k
- 1].length
+= authsize
;
711 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
715 aead_request_set_ad(req
, template[i
].alen
);
717 ret
= enc
? crypto_aead_encrypt(req
) : crypto_aead_decrypt(req
);
721 if (template[i
].novrfy
) {
722 /* verification was supposed to fail */
723 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
725 /* so really, we got a bad message */
732 wait_for_completion(&result
.completion
);
733 reinit_completion(&result
.completion
);
738 if (template[i
].novrfy
)
739 /* verification failure was expected */
743 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
744 d
, e
, j
, algo
, -ret
);
749 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
751 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
752 offset_in_page(IDX
[k
]);
754 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
755 offset_in_page(IDX
[k
]);
757 n
= template[i
].tap
[k
];
758 if (k
== template[i
].np
- 1)
759 n
+= enc
? authsize
: -authsize
;
761 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
762 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
769 if (k
== template[i
].np
- 1 && !enc
) {
771 memcmp(q
, template[i
].input
+
777 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
781 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
782 d
, j
, e
, k
, algo
, n
);
787 temp
+= template[i
].tap
[k
];
794 aead_request_free(req
);
798 testmgr_free_buf(xoutbuf
);
800 testmgr_free_buf(axbuf
);
802 testmgr_free_buf(xbuf
);
809 static int test_aead(struct crypto_aead
*tfm
, int enc
,
810 struct aead_testvec
*template, unsigned int tcount
)
812 unsigned int alignmask
;
815 /* test 'dst == src' case */
816 ret
= __test_aead(tfm
, enc
, template, tcount
, false, 0);
820 /* test 'dst != src' case */
821 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 0);
825 /* test unaligned buffers, check with one byte offset */
826 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 1);
830 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
832 /* Check if alignment mask for tfm is correctly set. */
833 ret
= __test_aead(tfm
, enc
, template, tcount
, true,
842 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
843 struct cipher_testvec
*template, unsigned int tcount
)
845 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
846 unsigned int i
, j
, k
;
850 char *xbuf
[XBUFSIZE
];
853 if (testmgr_alloc_buf(xbuf
))
862 for (i
= 0; i
< tcount
; i
++) {
869 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
873 memcpy(data
, template[i
].input
, template[i
].ilen
);
875 crypto_cipher_clear_flags(tfm
, ~0);
877 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
879 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
881 if (!ret
== template[i
].fail
) {
882 printk(KERN_ERR
"alg: cipher: setkey failed "
883 "on test %d for %s: flags=%x\n", j
,
884 algo
, crypto_cipher_get_flags(tfm
));
889 for (k
= 0; k
< template[i
].ilen
;
890 k
+= crypto_cipher_blocksize(tfm
)) {
892 crypto_cipher_encrypt_one(tfm
, data
+ k
,
895 crypto_cipher_decrypt_one(tfm
, data
+ k
,
900 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
901 printk(KERN_ERR
"alg: cipher: Test %d failed "
902 "on %s for %s\n", j
, e
, algo
);
903 hexdump(q
, template[i
].rlen
);
912 testmgr_free_buf(xbuf
);
917 static int __test_skcipher(struct crypto_skcipher
*tfm
, int enc
,
918 struct cipher_testvec
*template, unsigned int tcount
,
919 const bool diff_dst
, const int align_offset
)
922 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm
));
923 unsigned int i
, j
, k
, n
, temp
;
925 struct skcipher_request
*req
;
926 struct scatterlist sg
[8];
927 struct scatterlist sgout
[8];
929 struct tcrypt_result result
;
932 char *xbuf
[XBUFSIZE
];
933 char *xoutbuf
[XBUFSIZE
];
935 unsigned int ivsize
= crypto_skcipher_ivsize(tfm
);
937 if (testmgr_alloc_buf(xbuf
))
940 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
953 init_completion(&result
.completion
);
955 req
= skcipher_request_alloc(tfm
, GFP_KERNEL
);
957 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
962 skcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
963 tcrypt_complete
, &result
);
966 for (i
= 0; i
< tcount
; i
++) {
967 if (template[i
].np
&& !template[i
].also_non_np
)
971 memcpy(iv
, template[i
].iv
, ivsize
);
973 memset(iv
, 0, MAX_IVLEN
);
977 if (WARN_ON(align_offset
+ template[i
].ilen
> PAGE_SIZE
))
981 data
+= align_offset
;
982 memcpy(data
, template[i
].input
, template[i
].ilen
);
984 crypto_skcipher_clear_flags(tfm
, ~0);
986 crypto_skcipher_set_flags(tfm
,
987 CRYPTO_TFM_REQ_WEAK_KEY
);
989 ret
= crypto_skcipher_setkey(tfm
, template[i
].key
,
991 if (!ret
== template[i
].fail
) {
992 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
993 d
, j
, algo
, crypto_skcipher_get_flags(tfm
));
998 sg_init_one(&sg
[0], data
, template[i
].ilen
);
1001 data
+= align_offset
;
1002 sg_init_one(&sgout
[0], data
, template[i
].ilen
);
1005 skcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1006 template[i
].ilen
, iv
);
1007 ret
= enc
? crypto_skcipher_encrypt(req
) :
1008 crypto_skcipher_decrypt(req
);
1015 wait_for_completion(&result
.completion
);
1016 reinit_completion(&result
.completion
);
1022 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1023 d
, e
, j
, algo
, -ret
);
1028 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
1029 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
1031 hexdump(q
, template[i
].rlen
);
1036 if (template[i
].iv_out
&&
1037 memcmp(iv
, template[i
].iv_out
,
1038 crypto_skcipher_ivsize(tfm
))) {
1039 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1041 hexdump(iv
, crypto_skcipher_ivsize(tfm
));
1048 for (i
= 0; i
< tcount
; i
++) {
1049 /* alignment tests are only done with continuous buffers */
1050 if (align_offset
!= 0)
1053 if (!template[i
].np
)
1057 memcpy(iv
, template[i
].iv
, ivsize
);
1059 memset(iv
, 0, MAX_IVLEN
);
1062 crypto_skcipher_clear_flags(tfm
, ~0);
1064 crypto_skcipher_set_flags(tfm
,
1065 CRYPTO_TFM_REQ_WEAK_KEY
);
1067 ret
= crypto_skcipher_setkey(tfm
, template[i
].key
,
1069 if (!ret
== template[i
].fail
) {
1070 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1071 d
, j
, algo
, crypto_skcipher_get_flags(tfm
));
1078 sg_init_table(sg
, template[i
].np
);
1080 sg_init_table(sgout
, template[i
].np
);
1081 for (k
= 0; k
< template[i
].np
; k
++) {
1082 if (WARN_ON(offset_in_page(IDX
[k
]) +
1083 template[i
].tap
[k
] > PAGE_SIZE
))
1086 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] + offset_in_page(IDX
[k
]);
1088 memcpy(q
, template[i
].input
+ temp
, template[i
].tap
[k
]);
1090 if (offset_in_page(q
) + template[i
].tap
[k
] < PAGE_SIZE
)
1091 q
[template[i
].tap
[k
]] = 0;
1093 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
1095 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1096 offset_in_page(IDX
[k
]);
1098 sg_set_buf(&sgout
[k
], q
, template[i
].tap
[k
]);
1100 memset(q
, 0, template[i
].tap
[k
]);
1101 if (offset_in_page(q
) +
1102 template[i
].tap
[k
] < PAGE_SIZE
)
1103 q
[template[i
].tap
[k
]] = 0;
1106 temp
+= template[i
].tap
[k
];
1109 skcipher_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
1110 template[i
].ilen
, iv
);
1112 ret
= enc
? crypto_skcipher_encrypt(req
) :
1113 crypto_skcipher_decrypt(req
);
1120 wait_for_completion(&result
.completion
);
1121 reinit_completion(&result
.completion
);
1127 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1128 d
, e
, j
, algo
, -ret
);
1134 for (k
= 0; k
< template[i
].np
; k
++) {
1136 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1137 offset_in_page(IDX
[k
]);
1139 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1140 offset_in_page(IDX
[k
]);
1142 if (memcmp(q
, template[i
].result
+ temp
,
1143 template[i
].tap
[k
])) {
1144 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1146 hexdump(q
, template[i
].tap
[k
]);
1150 q
+= template[i
].tap
[k
];
1151 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
1154 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1155 d
, j
, e
, k
, algo
, n
);
1159 temp
+= template[i
].tap
[k
];
1166 skcipher_request_free(req
);
1168 testmgr_free_buf(xoutbuf
);
1170 testmgr_free_buf(xbuf
);
1175 static int test_skcipher(struct crypto_skcipher
*tfm
, int enc
,
1176 struct cipher_testvec
*template, unsigned int tcount
)
1178 unsigned int alignmask
;
1181 /* test 'dst == src' case */
1182 ret
= __test_skcipher(tfm
, enc
, template, tcount
, false, 0);
1186 /* test 'dst != src' case */
1187 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 0);
1191 /* test unaligned buffers, check with one byte offset */
1192 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 1);
1196 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
1198 /* Check if alignment mask for tfm is correctly set. */
1199 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true,
1208 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
1209 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1211 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
1213 char result
[COMP_BUF_SIZE
];
1216 for (i
= 0; i
< ctcount
; i
++) {
1218 unsigned int dlen
= COMP_BUF_SIZE
;
1220 memset(result
, 0, sizeof (result
));
1222 ilen
= ctemplate
[i
].inlen
;
1223 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1224 ilen
, result
, &dlen
);
1226 printk(KERN_ERR
"alg: comp: compression failed "
1227 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1232 if (dlen
!= ctemplate
[i
].outlen
) {
1233 printk(KERN_ERR
"alg: comp: Compression test %d "
1234 "failed for %s: output len = %d\n", i
+ 1, algo
,
1240 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
1241 printk(KERN_ERR
"alg: comp: Compression test %d "
1242 "failed for %s\n", i
+ 1, algo
);
1243 hexdump(result
, dlen
);
1249 for (i
= 0; i
< dtcount
; i
++) {
1251 unsigned int dlen
= COMP_BUF_SIZE
;
1253 memset(result
, 0, sizeof (result
));
1255 ilen
= dtemplate
[i
].inlen
;
1256 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1257 ilen
, result
, &dlen
);
1259 printk(KERN_ERR
"alg: comp: decompression failed "
1260 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1265 if (dlen
!= dtemplate
[i
].outlen
) {
1266 printk(KERN_ERR
"alg: comp: Decompression test %d "
1267 "failed for %s: output len = %d\n", i
+ 1, algo
,
1273 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1274 printk(KERN_ERR
"alg: comp: Decompression test %d "
1275 "failed for %s\n", i
+ 1, algo
);
1276 hexdump(result
, dlen
);
1288 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1289 unsigned int tcount
)
1291 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1292 int err
= 0, i
, j
, seedsize
;
1296 seedsize
= crypto_rng_seedsize(tfm
);
1298 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1300 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1305 for (i
= 0; i
< tcount
; i
++) {
1306 memset(result
, 0, 32);
1308 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1309 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1311 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1312 template[i
].dt
, template[i
].dtlen
);
1314 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1316 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1321 for (j
= 0; j
< template[i
].loops
; j
++) {
1322 err
= crypto_rng_get_bytes(tfm
, result
,
1325 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1326 "the correct amount of random data for "
1327 "%s (requested %d)\n", algo
,
1333 err
= memcmp(result
, template[i
].result
,
1336 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1338 hexdump(result
, template[i
].rlen
);
1349 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1352 struct crypto_aead
*tfm
;
1355 tfm
= crypto_alloc_aead(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1357 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1358 "%ld\n", driver
, PTR_ERR(tfm
));
1359 return PTR_ERR(tfm
);
1362 if (desc
->suite
.aead
.enc
.vecs
) {
1363 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1364 desc
->suite
.aead
.enc
.count
);
1369 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1370 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1371 desc
->suite
.aead
.dec
.count
);
1374 crypto_free_aead(tfm
);
1378 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1379 const char *driver
, u32 type
, u32 mask
)
1381 struct crypto_cipher
*tfm
;
1384 tfm
= crypto_alloc_cipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1386 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1387 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1388 return PTR_ERR(tfm
);
1391 if (desc
->suite
.cipher
.enc
.vecs
) {
1392 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1393 desc
->suite
.cipher
.enc
.count
);
1398 if (desc
->suite
.cipher
.dec
.vecs
)
1399 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1400 desc
->suite
.cipher
.dec
.count
);
1403 crypto_free_cipher(tfm
);
1407 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1408 const char *driver
, u32 type
, u32 mask
)
1410 struct crypto_skcipher
*tfm
;
1413 tfm
= crypto_alloc_skcipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1415 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1416 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1417 return PTR_ERR(tfm
);
1420 if (desc
->suite
.cipher
.enc
.vecs
) {
1421 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1422 desc
->suite
.cipher
.enc
.count
);
1427 if (desc
->suite
.cipher
.dec
.vecs
)
1428 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1429 desc
->suite
.cipher
.dec
.count
);
1432 crypto_free_skcipher(tfm
);
1436 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1439 struct crypto_comp
*tfm
;
1442 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1444 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1445 "%ld\n", driver
, PTR_ERR(tfm
));
1446 return PTR_ERR(tfm
);
1449 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1450 desc
->suite
.comp
.decomp
.vecs
,
1451 desc
->suite
.comp
.comp
.count
,
1452 desc
->suite
.comp
.decomp
.count
);
1454 crypto_free_comp(tfm
);
1458 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1461 struct crypto_ahash
*tfm
;
1464 tfm
= crypto_alloc_ahash(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1466 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1467 "%ld\n", driver
, PTR_ERR(tfm
));
1468 return PTR_ERR(tfm
);
1471 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1472 desc
->suite
.hash
.count
, true);
1474 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1475 desc
->suite
.hash
.count
, false);
1477 crypto_free_ahash(tfm
);
1481 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1482 const char *driver
, u32 type
, u32 mask
)
1484 struct crypto_shash
*tfm
;
1488 err
= alg_test_hash(desc
, driver
, type
, mask
);
1492 tfm
= crypto_alloc_shash(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1494 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1495 "%ld\n", driver
, PTR_ERR(tfm
));
1501 SHASH_DESC_ON_STACK(shash
, tfm
);
1502 u32
*ctx
= (u32
*)shash_desc_ctx(shash
);
1507 *ctx
= le32_to_cpu(420553207);
1508 err
= crypto_shash_final(shash
, (u8
*)&val
);
1510 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1511 "%s: %d\n", driver
, err
);
1515 if (val
!= ~420553207) {
1516 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1517 "%d\n", driver
, val
);
1522 crypto_free_shash(tfm
);
1528 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1531 struct crypto_rng
*rng
;
1534 rng
= crypto_alloc_rng(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1536 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1537 "%ld\n", driver
, PTR_ERR(rng
));
1538 return PTR_ERR(rng
);
1541 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1543 crypto_free_rng(rng
);
1549 static int drbg_cavs_test(struct drbg_testvec
*test
, int pr
,
1550 const char *driver
, u32 type
, u32 mask
)
1553 struct crypto_rng
*drng
;
1554 struct drbg_test_data test_data
;
1555 struct drbg_string addtl
, pers
, testentropy
;
1556 unsigned char *buf
= kzalloc(test
->expectedlen
, GFP_KERNEL
);
1561 drng
= crypto_alloc_rng(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1563 printk(KERN_ERR
"alg: drbg: could not allocate DRNG handle for "
1569 test_data
.testentropy
= &testentropy
;
1570 drbg_string_fill(&testentropy
, test
->entropy
, test
->entropylen
);
1571 drbg_string_fill(&pers
, test
->pers
, test
->perslen
);
1572 ret
= crypto_drbg_reset_test(drng
, &pers
, &test_data
);
1574 printk(KERN_ERR
"alg: drbg: Failed to reset rng\n");
1578 drbg_string_fill(&addtl
, test
->addtla
, test
->addtllen
);
1580 drbg_string_fill(&testentropy
, test
->entpra
, test
->entprlen
);
1581 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1582 buf
, test
->expectedlen
, &addtl
, &test_data
);
1584 ret
= crypto_drbg_get_bytes_addtl(drng
,
1585 buf
, test
->expectedlen
, &addtl
);
1588 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1589 "driver %s\n", driver
);
1593 drbg_string_fill(&addtl
, test
->addtlb
, test
->addtllen
);
1595 drbg_string_fill(&testentropy
, test
->entprb
, test
->entprlen
);
1596 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1597 buf
, test
->expectedlen
, &addtl
, &test_data
);
1599 ret
= crypto_drbg_get_bytes_addtl(drng
,
1600 buf
, test
->expectedlen
, &addtl
);
1603 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1604 "driver %s\n", driver
);
1608 ret
= memcmp(test
->expected
, buf
, test
->expectedlen
);
1611 crypto_free_rng(drng
);
1617 static int alg_test_drbg(const struct alg_test_desc
*desc
, const char *driver
,
1623 struct drbg_testvec
*template = desc
->suite
.drbg
.vecs
;
1624 unsigned int tcount
= desc
->suite
.drbg
.count
;
1626 if (0 == memcmp(driver
, "drbg_pr_", 8))
1629 for (i
= 0; i
< tcount
; i
++) {
1630 err
= drbg_cavs_test(&template[i
], pr
, driver
, type
, mask
);
1632 printk(KERN_ERR
"alg: drbg: Test %d failed for %s\n",
1642 static int do_test_rsa(struct crypto_akcipher
*tfm
,
1643 struct akcipher_testvec
*vecs
)
1645 struct akcipher_request
*req
;
1646 void *outbuf_enc
= NULL
;
1647 void *outbuf_dec
= NULL
;
1648 struct tcrypt_result result
;
1649 unsigned int out_len_max
, out_len
= 0;
1651 struct scatterlist src
, dst
, src_tab
[2];
1653 req
= akcipher_request_alloc(tfm
, GFP_KERNEL
);
1657 init_completion(&result
.completion
);
1659 if (vecs
->public_key_vec
)
1660 err
= crypto_akcipher_set_pub_key(tfm
, vecs
->key
,
1663 err
= crypto_akcipher_set_priv_key(tfm
, vecs
->key
,
1668 out_len_max
= crypto_akcipher_maxsize(tfm
);
1669 outbuf_enc
= kzalloc(out_len_max
, GFP_KERNEL
);
1673 sg_init_table(src_tab
, 2);
1674 sg_set_buf(&src_tab
[0], vecs
->m
, 8);
1675 sg_set_buf(&src_tab
[1], vecs
->m
+ 8, vecs
->m_size
- 8);
1676 sg_init_one(&dst
, outbuf_enc
, out_len_max
);
1677 akcipher_request_set_crypt(req
, src_tab
, &dst
, vecs
->m_size
,
1679 akcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
1680 tcrypt_complete
, &result
);
1682 /* Run RSA encrypt - c = m^e mod n;*/
1683 err
= wait_async_op(&result
, crypto_akcipher_encrypt(req
));
1685 pr_err("alg: rsa: encrypt test failed. err %d\n", err
);
1688 if (req
->dst_len
!= vecs
->c_size
) {
1689 pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
1693 /* verify that encrypted message is equal to expected */
1694 if (memcmp(vecs
->c
, sg_virt(req
->dst
), vecs
->c_size
)) {
1695 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
1699 /* Don't invoke decrypt for vectors with public key */
1700 if (vecs
->public_key_vec
) {
1704 outbuf_dec
= kzalloc(out_len_max
, GFP_KERNEL
);
1709 sg_init_one(&src
, vecs
->c
, vecs
->c_size
);
1710 sg_init_one(&dst
, outbuf_dec
, out_len_max
);
1711 init_completion(&result
.completion
);
1712 akcipher_request_set_crypt(req
, &src
, &dst
, vecs
->c_size
, out_len_max
);
1714 /* Run RSA decrypt - m = c^d mod n;*/
1715 err
= wait_async_op(&result
, crypto_akcipher_decrypt(req
));
1717 pr_err("alg: rsa: decrypt test failed. err %d\n", err
);
1720 out_len
= req
->dst_len
;
1721 if (out_len
!= vecs
->m_size
) {
1722 pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
1726 /* verify that decrypted message is equal to the original msg */
1727 if (memcmp(vecs
->m
, outbuf_dec
, vecs
->m_size
)) {
1728 pr_err("alg: rsa: decrypt test failed. Invalid output\n");
1735 akcipher_request_free(req
);
1739 static int test_rsa(struct crypto_akcipher
*tfm
, struct akcipher_testvec
*vecs
,
1740 unsigned int tcount
)
1744 for (i
= 0; i
< tcount
; i
++) {
1745 ret
= do_test_rsa(tfm
, vecs
++);
1747 pr_err("alg: rsa: test failed on vector %d, err=%d\n",
1755 static int test_akcipher(struct crypto_akcipher
*tfm
, const char *alg
,
1756 struct akcipher_testvec
*vecs
, unsigned int tcount
)
1758 if (strncmp(alg
, "rsa", 3) == 0)
1759 return test_rsa(tfm
, vecs
, tcount
);
1764 static int alg_test_akcipher(const struct alg_test_desc
*desc
,
1765 const char *driver
, u32 type
, u32 mask
)
1767 struct crypto_akcipher
*tfm
;
1770 tfm
= crypto_alloc_akcipher(driver
, type
| CRYPTO_ALG_INTERNAL
, mask
);
1772 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
1773 driver
, PTR_ERR(tfm
));
1774 return PTR_ERR(tfm
);
1776 if (desc
->suite
.akcipher
.vecs
)
1777 err
= test_akcipher(tfm
, desc
->alg
, desc
->suite
.akcipher
.vecs
,
1778 desc
->suite
.akcipher
.count
);
1780 crypto_free_akcipher(tfm
);
1784 static int alg_test_null(const struct alg_test_desc
*desc
,
1785 const char *driver
, u32 type
, u32 mask
)
1790 /* Please keep this list sorted by algorithm name. */
1791 static const struct alg_test_desc alg_test_descs
[] = {
1793 .alg
= "__cbc-cast5-avx",
1794 .test
= alg_test_null
,
1796 .alg
= "__cbc-cast6-avx",
1797 .test
= alg_test_null
,
1799 .alg
= "__cbc-serpent-avx",
1800 .test
= alg_test_null
,
1802 .alg
= "__cbc-serpent-avx2",
1803 .test
= alg_test_null
,
1805 .alg
= "__cbc-serpent-sse2",
1806 .test
= alg_test_null
,
1808 .alg
= "__cbc-twofish-avx",
1809 .test
= alg_test_null
,
1811 .alg
= "__driver-cbc-aes-aesni",
1812 .test
= alg_test_null
,
1815 .alg
= "__driver-cbc-camellia-aesni",
1816 .test
= alg_test_null
,
1818 .alg
= "__driver-cbc-camellia-aesni-avx2",
1819 .test
= alg_test_null
,
1821 .alg
= "__driver-cbc-cast5-avx",
1822 .test
= alg_test_null
,
1824 .alg
= "__driver-cbc-cast6-avx",
1825 .test
= alg_test_null
,
1827 .alg
= "__driver-cbc-serpent-avx",
1828 .test
= alg_test_null
,
1830 .alg
= "__driver-cbc-serpent-avx2",
1831 .test
= alg_test_null
,
1833 .alg
= "__driver-cbc-serpent-sse2",
1834 .test
= alg_test_null
,
1836 .alg
= "__driver-cbc-twofish-avx",
1837 .test
= alg_test_null
,
1839 .alg
= "__driver-ecb-aes-aesni",
1840 .test
= alg_test_null
,
1843 .alg
= "__driver-ecb-camellia-aesni",
1844 .test
= alg_test_null
,
1846 .alg
= "__driver-ecb-camellia-aesni-avx2",
1847 .test
= alg_test_null
,
1849 .alg
= "__driver-ecb-cast5-avx",
1850 .test
= alg_test_null
,
1852 .alg
= "__driver-ecb-cast6-avx",
1853 .test
= alg_test_null
,
1855 .alg
= "__driver-ecb-serpent-avx",
1856 .test
= alg_test_null
,
1858 .alg
= "__driver-ecb-serpent-avx2",
1859 .test
= alg_test_null
,
1861 .alg
= "__driver-ecb-serpent-sse2",
1862 .test
= alg_test_null
,
1864 .alg
= "__driver-ecb-twofish-avx",
1865 .test
= alg_test_null
,
1867 .alg
= "__driver-gcm-aes-aesni",
1868 .test
= alg_test_null
,
1871 .alg
= "__ghash-pclmulqdqni",
1872 .test
= alg_test_null
,
1875 .alg
= "ansi_cprng",
1876 .test
= alg_test_cprng
,
1879 .vecs
= ansi_cprng_aes_tv_template
,
1880 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1884 .alg
= "authenc(hmac(md5),ecb(cipher_null))",
1885 .test
= alg_test_aead
,
1889 .vecs
= hmac_md5_ecb_cipher_null_enc_tv_template
,
1890 .count
= HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1893 .vecs
= hmac_md5_ecb_cipher_null_dec_tv_template
,
1894 .count
= HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1899 .alg
= "authenc(hmac(sha1),cbc(aes))",
1900 .test
= alg_test_aead
,
1905 hmac_sha1_aes_cbc_enc_tv_temp
,
1907 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1912 .alg
= "authenc(hmac(sha1),cbc(des))",
1913 .test
= alg_test_aead
,
1918 hmac_sha1_des_cbc_enc_tv_temp
,
1920 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1925 .alg
= "authenc(hmac(sha1),cbc(des3_ede))",
1926 .test
= alg_test_aead
,
1931 hmac_sha1_des3_ede_cbc_enc_tv_temp
,
1933 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
1938 .alg
= "authenc(hmac(sha1),ecb(cipher_null))",
1939 .test
= alg_test_aead
,
1944 hmac_sha1_ecb_cipher_null_enc_tv_temp
,
1946 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
1950 hmac_sha1_ecb_cipher_null_dec_tv_temp
,
1952 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1957 .alg
= "authenc(hmac(sha224),cbc(des))",
1958 .test
= alg_test_aead
,
1963 hmac_sha224_des_cbc_enc_tv_temp
,
1965 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
1970 .alg
= "authenc(hmac(sha224),cbc(des3_ede))",
1971 .test
= alg_test_aead
,
1976 hmac_sha224_des3_ede_cbc_enc_tv_temp
,
1978 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
1983 .alg
= "authenc(hmac(sha256),cbc(aes))",
1984 .test
= alg_test_aead
,
1989 hmac_sha256_aes_cbc_enc_tv_temp
,
1991 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
1996 .alg
= "authenc(hmac(sha256),cbc(des))",
1997 .test
= alg_test_aead
,
2002 hmac_sha256_des_cbc_enc_tv_temp
,
2004 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2009 .alg
= "authenc(hmac(sha256),cbc(des3_ede))",
2010 .test
= alg_test_aead
,
2015 hmac_sha256_des3_ede_cbc_enc_tv_temp
,
2017 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2022 .alg
= "authenc(hmac(sha384),cbc(des))",
2023 .test
= alg_test_aead
,
2028 hmac_sha384_des_cbc_enc_tv_temp
,
2030 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2035 .alg
= "authenc(hmac(sha384),cbc(des3_ede))",
2036 .test
= alg_test_aead
,
2041 hmac_sha384_des3_ede_cbc_enc_tv_temp
,
2043 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2048 .alg
= "authenc(hmac(sha512),cbc(aes))",
2049 .test
= alg_test_aead
,
2054 hmac_sha512_aes_cbc_enc_tv_temp
,
2056 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2061 .alg
= "authenc(hmac(sha512),cbc(des))",
2062 .test
= alg_test_aead
,
2067 hmac_sha512_des_cbc_enc_tv_temp
,
2069 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2074 .alg
= "authenc(hmac(sha512),cbc(des3_ede))",
2075 .test
= alg_test_aead
,
2080 hmac_sha512_des3_ede_cbc_enc_tv_temp
,
2082 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2088 .test
= alg_test_skcipher
,
2093 .vecs
= aes_cbc_enc_tv_template
,
2094 .count
= AES_CBC_ENC_TEST_VECTORS
2097 .vecs
= aes_cbc_dec_tv_template
,
2098 .count
= AES_CBC_DEC_TEST_VECTORS
2103 .alg
= "cbc(anubis)",
2104 .test
= alg_test_skcipher
,
2108 .vecs
= anubis_cbc_enc_tv_template
,
2109 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
2112 .vecs
= anubis_cbc_dec_tv_template
,
2113 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
2118 .alg
= "cbc(blowfish)",
2119 .test
= alg_test_skcipher
,
2123 .vecs
= bf_cbc_enc_tv_template
,
2124 .count
= BF_CBC_ENC_TEST_VECTORS
2127 .vecs
= bf_cbc_dec_tv_template
,
2128 .count
= BF_CBC_DEC_TEST_VECTORS
2133 .alg
= "cbc(camellia)",
2134 .test
= alg_test_skcipher
,
2138 .vecs
= camellia_cbc_enc_tv_template
,
2139 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
2142 .vecs
= camellia_cbc_dec_tv_template
,
2143 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
2148 .alg
= "cbc(cast5)",
2149 .test
= alg_test_skcipher
,
2153 .vecs
= cast5_cbc_enc_tv_template
,
2154 .count
= CAST5_CBC_ENC_TEST_VECTORS
2157 .vecs
= cast5_cbc_dec_tv_template
,
2158 .count
= CAST5_CBC_DEC_TEST_VECTORS
2163 .alg
= "cbc(cast6)",
2164 .test
= alg_test_skcipher
,
2168 .vecs
= cast6_cbc_enc_tv_template
,
2169 .count
= CAST6_CBC_ENC_TEST_VECTORS
2172 .vecs
= cast6_cbc_dec_tv_template
,
2173 .count
= CAST6_CBC_DEC_TEST_VECTORS
2179 .test
= alg_test_skcipher
,
2183 .vecs
= des_cbc_enc_tv_template
,
2184 .count
= DES_CBC_ENC_TEST_VECTORS
2187 .vecs
= des_cbc_dec_tv_template
,
2188 .count
= DES_CBC_DEC_TEST_VECTORS
2193 .alg
= "cbc(des3_ede)",
2194 .test
= alg_test_skcipher
,
2199 .vecs
= des3_ede_cbc_enc_tv_template
,
2200 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
2203 .vecs
= des3_ede_cbc_dec_tv_template
,
2204 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
2209 .alg
= "cbc(serpent)",
2210 .test
= alg_test_skcipher
,
2214 .vecs
= serpent_cbc_enc_tv_template
,
2215 .count
= SERPENT_CBC_ENC_TEST_VECTORS
2218 .vecs
= serpent_cbc_dec_tv_template
,
2219 .count
= SERPENT_CBC_DEC_TEST_VECTORS
2224 .alg
= "cbc(twofish)",
2225 .test
= alg_test_skcipher
,
2229 .vecs
= tf_cbc_enc_tv_template
,
2230 .count
= TF_CBC_ENC_TEST_VECTORS
2233 .vecs
= tf_cbc_dec_tv_template
,
2234 .count
= TF_CBC_DEC_TEST_VECTORS
2240 .test
= alg_test_aead
,
2245 .vecs
= aes_ccm_enc_tv_template
,
2246 .count
= AES_CCM_ENC_TEST_VECTORS
2249 .vecs
= aes_ccm_dec_tv_template
,
2250 .count
= AES_CCM_DEC_TEST_VECTORS
2256 .test
= alg_test_skcipher
,
2260 .vecs
= chacha20_enc_tv_template
,
2261 .count
= CHACHA20_ENC_TEST_VECTORS
2264 .vecs
= chacha20_enc_tv_template
,
2265 .count
= CHACHA20_ENC_TEST_VECTORS
2272 .test
= alg_test_hash
,
2275 .vecs
= aes_cmac128_tv_template
,
2276 .count
= CMAC_AES_TEST_VECTORS
2280 .alg
= "cmac(des3_ede)",
2282 .test
= alg_test_hash
,
2285 .vecs
= des3_ede_cmac64_tv_template
,
2286 .count
= CMAC_DES3_EDE_TEST_VECTORS
2290 .alg
= "compress_null",
2291 .test
= alg_test_null
,
2294 .test
= alg_test_hash
,
2297 .vecs
= crc32_tv_template
,
2298 .count
= CRC32_TEST_VECTORS
2303 .test
= alg_test_crc32c
,
2307 .vecs
= crc32c_tv_template
,
2308 .count
= CRC32C_TEST_VECTORS
2313 .test
= alg_test_hash
,
2317 .vecs
= crct10dif_tv_template
,
2318 .count
= CRCT10DIF_TEST_VECTORS
2322 .alg
= "cryptd(__driver-cbc-aes-aesni)",
2323 .test
= alg_test_null
,
2326 .alg
= "cryptd(__driver-cbc-camellia-aesni)",
2327 .test
= alg_test_null
,
2329 .alg
= "cryptd(__driver-cbc-camellia-aesni-avx2)",
2330 .test
= alg_test_null
,
2332 .alg
= "cryptd(__driver-cbc-serpent-avx2)",
2333 .test
= alg_test_null
,
2335 .alg
= "cryptd(__driver-ecb-aes-aesni)",
2336 .test
= alg_test_null
,
2339 .alg
= "cryptd(__driver-ecb-camellia-aesni)",
2340 .test
= alg_test_null
,
2342 .alg
= "cryptd(__driver-ecb-camellia-aesni-avx2)",
2343 .test
= alg_test_null
,
2345 .alg
= "cryptd(__driver-ecb-cast5-avx)",
2346 .test
= alg_test_null
,
2348 .alg
= "cryptd(__driver-ecb-cast6-avx)",
2349 .test
= alg_test_null
,
2351 .alg
= "cryptd(__driver-ecb-serpent-avx)",
2352 .test
= alg_test_null
,
2354 .alg
= "cryptd(__driver-ecb-serpent-avx2)",
2355 .test
= alg_test_null
,
2357 .alg
= "cryptd(__driver-ecb-serpent-sse2)",
2358 .test
= alg_test_null
,
2360 .alg
= "cryptd(__driver-ecb-twofish-avx)",
2361 .test
= alg_test_null
,
2363 .alg
= "cryptd(__driver-gcm-aes-aesni)",
2364 .test
= alg_test_null
,
2367 .alg
= "cryptd(__ghash-pclmulqdqni)",
2368 .test
= alg_test_null
,
2372 .test
= alg_test_skcipher
,
2377 .vecs
= aes_ctr_enc_tv_template
,
2378 .count
= AES_CTR_ENC_TEST_VECTORS
2381 .vecs
= aes_ctr_dec_tv_template
,
2382 .count
= AES_CTR_DEC_TEST_VECTORS
2387 .alg
= "ctr(blowfish)",
2388 .test
= alg_test_skcipher
,
2392 .vecs
= bf_ctr_enc_tv_template
,
2393 .count
= BF_CTR_ENC_TEST_VECTORS
2396 .vecs
= bf_ctr_dec_tv_template
,
2397 .count
= BF_CTR_DEC_TEST_VECTORS
2402 .alg
= "ctr(camellia)",
2403 .test
= alg_test_skcipher
,
2407 .vecs
= camellia_ctr_enc_tv_template
,
2408 .count
= CAMELLIA_CTR_ENC_TEST_VECTORS
2411 .vecs
= camellia_ctr_dec_tv_template
,
2412 .count
= CAMELLIA_CTR_DEC_TEST_VECTORS
2417 .alg
= "ctr(cast5)",
2418 .test
= alg_test_skcipher
,
2422 .vecs
= cast5_ctr_enc_tv_template
,
2423 .count
= CAST5_CTR_ENC_TEST_VECTORS
2426 .vecs
= cast5_ctr_dec_tv_template
,
2427 .count
= CAST5_CTR_DEC_TEST_VECTORS
2432 .alg
= "ctr(cast6)",
2433 .test
= alg_test_skcipher
,
2437 .vecs
= cast6_ctr_enc_tv_template
,
2438 .count
= CAST6_CTR_ENC_TEST_VECTORS
2441 .vecs
= cast6_ctr_dec_tv_template
,
2442 .count
= CAST6_CTR_DEC_TEST_VECTORS
2448 .test
= alg_test_skcipher
,
2452 .vecs
= des_ctr_enc_tv_template
,
2453 .count
= DES_CTR_ENC_TEST_VECTORS
2456 .vecs
= des_ctr_dec_tv_template
,
2457 .count
= DES_CTR_DEC_TEST_VECTORS
2462 .alg
= "ctr(des3_ede)",
2463 .test
= alg_test_skcipher
,
2467 .vecs
= des3_ede_ctr_enc_tv_template
,
2468 .count
= DES3_EDE_CTR_ENC_TEST_VECTORS
2471 .vecs
= des3_ede_ctr_dec_tv_template
,
2472 .count
= DES3_EDE_CTR_DEC_TEST_VECTORS
2477 .alg
= "ctr(serpent)",
2478 .test
= alg_test_skcipher
,
2482 .vecs
= serpent_ctr_enc_tv_template
,
2483 .count
= SERPENT_CTR_ENC_TEST_VECTORS
2486 .vecs
= serpent_ctr_dec_tv_template
,
2487 .count
= SERPENT_CTR_DEC_TEST_VECTORS
2492 .alg
= "ctr(twofish)",
2493 .test
= alg_test_skcipher
,
2497 .vecs
= tf_ctr_enc_tv_template
,
2498 .count
= TF_CTR_ENC_TEST_VECTORS
2501 .vecs
= tf_ctr_dec_tv_template
,
2502 .count
= TF_CTR_DEC_TEST_VECTORS
2507 .alg
= "cts(cbc(aes))",
2508 .test
= alg_test_skcipher
,
2512 .vecs
= cts_mode_enc_tv_template
,
2513 .count
= CTS_MODE_ENC_TEST_VECTORS
2516 .vecs
= cts_mode_dec_tv_template
,
2517 .count
= CTS_MODE_DEC_TEST_VECTORS
2523 .test
= alg_test_comp
,
2528 .vecs
= deflate_comp_tv_template
,
2529 .count
= DEFLATE_COMP_TEST_VECTORS
2532 .vecs
= deflate_decomp_tv_template
,
2533 .count
= DEFLATE_DECOMP_TEST_VECTORS
2538 .alg
= "digest_null",
2539 .test
= alg_test_null
,
2541 .alg
= "drbg_nopr_ctr_aes128",
2542 .test
= alg_test_drbg
,
2546 .vecs
= drbg_nopr_ctr_aes128_tv_template
,
2547 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template
)
2551 .alg
= "drbg_nopr_ctr_aes192",
2552 .test
= alg_test_drbg
,
2556 .vecs
= drbg_nopr_ctr_aes192_tv_template
,
2557 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template
)
2561 .alg
= "drbg_nopr_ctr_aes256",
2562 .test
= alg_test_drbg
,
2566 .vecs
= drbg_nopr_ctr_aes256_tv_template
,
2567 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template
)
2572 * There is no need to specifically test the DRBG with every
2573 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2575 .alg
= "drbg_nopr_hmac_sha1",
2577 .test
= alg_test_null
,
2579 .alg
= "drbg_nopr_hmac_sha256",
2580 .test
= alg_test_drbg
,
2584 .vecs
= drbg_nopr_hmac_sha256_tv_template
,
2586 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template
)
2590 /* covered by drbg_nopr_hmac_sha256 test */
2591 .alg
= "drbg_nopr_hmac_sha384",
2593 .test
= alg_test_null
,
2595 .alg
= "drbg_nopr_hmac_sha512",
2596 .test
= alg_test_null
,
2599 .alg
= "drbg_nopr_sha1",
2601 .test
= alg_test_null
,
2603 .alg
= "drbg_nopr_sha256",
2604 .test
= alg_test_drbg
,
2608 .vecs
= drbg_nopr_sha256_tv_template
,
2609 .count
= ARRAY_SIZE(drbg_nopr_sha256_tv_template
)
2613 /* covered by drbg_nopr_sha256 test */
2614 .alg
= "drbg_nopr_sha384",
2616 .test
= alg_test_null
,
2618 .alg
= "drbg_nopr_sha512",
2620 .test
= alg_test_null
,
2622 .alg
= "drbg_pr_ctr_aes128",
2623 .test
= alg_test_drbg
,
2627 .vecs
= drbg_pr_ctr_aes128_tv_template
,
2628 .count
= ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template
)
2632 /* covered by drbg_pr_ctr_aes128 test */
2633 .alg
= "drbg_pr_ctr_aes192",
2635 .test
= alg_test_null
,
2637 .alg
= "drbg_pr_ctr_aes256",
2639 .test
= alg_test_null
,
2641 .alg
= "drbg_pr_hmac_sha1",
2643 .test
= alg_test_null
,
2645 .alg
= "drbg_pr_hmac_sha256",
2646 .test
= alg_test_drbg
,
2650 .vecs
= drbg_pr_hmac_sha256_tv_template
,
2651 .count
= ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template
)
2655 /* covered by drbg_pr_hmac_sha256 test */
2656 .alg
= "drbg_pr_hmac_sha384",
2658 .test
= alg_test_null
,
2660 .alg
= "drbg_pr_hmac_sha512",
2661 .test
= alg_test_null
,
2664 .alg
= "drbg_pr_sha1",
2666 .test
= alg_test_null
,
2668 .alg
= "drbg_pr_sha256",
2669 .test
= alg_test_drbg
,
2673 .vecs
= drbg_pr_sha256_tv_template
,
2674 .count
= ARRAY_SIZE(drbg_pr_sha256_tv_template
)
2678 /* covered by drbg_pr_sha256 test */
2679 .alg
= "drbg_pr_sha384",
2681 .test
= alg_test_null
,
2683 .alg
= "drbg_pr_sha512",
2685 .test
= alg_test_null
,
2687 .alg
= "ecb(__aes-aesni)",
2688 .test
= alg_test_null
,
2692 .test
= alg_test_skcipher
,
2697 .vecs
= aes_enc_tv_template
,
2698 .count
= AES_ENC_TEST_VECTORS
2701 .vecs
= aes_dec_tv_template
,
2702 .count
= AES_DEC_TEST_VECTORS
2707 .alg
= "ecb(anubis)",
2708 .test
= alg_test_skcipher
,
2712 .vecs
= anubis_enc_tv_template
,
2713 .count
= ANUBIS_ENC_TEST_VECTORS
2716 .vecs
= anubis_dec_tv_template
,
2717 .count
= ANUBIS_DEC_TEST_VECTORS
2723 .test
= alg_test_skcipher
,
2727 .vecs
= arc4_enc_tv_template
,
2728 .count
= ARC4_ENC_TEST_VECTORS
2731 .vecs
= arc4_dec_tv_template
,
2732 .count
= ARC4_DEC_TEST_VECTORS
2737 .alg
= "ecb(blowfish)",
2738 .test
= alg_test_skcipher
,
2742 .vecs
= bf_enc_tv_template
,
2743 .count
= BF_ENC_TEST_VECTORS
2746 .vecs
= bf_dec_tv_template
,
2747 .count
= BF_DEC_TEST_VECTORS
2752 .alg
= "ecb(camellia)",
2753 .test
= alg_test_skcipher
,
2757 .vecs
= camellia_enc_tv_template
,
2758 .count
= CAMELLIA_ENC_TEST_VECTORS
2761 .vecs
= camellia_dec_tv_template
,
2762 .count
= CAMELLIA_DEC_TEST_VECTORS
2767 .alg
= "ecb(cast5)",
2768 .test
= alg_test_skcipher
,
2772 .vecs
= cast5_enc_tv_template
,
2773 .count
= CAST5_ENC_TEST_VECTORS
2776 .vecs
= cast5_dec_tv_template
,
2777 .count
= CAST5_DEC_TEST_VECTORS
2782 .alg
= "ecb(cast6)",
2783 .test
= alg_test_skcipher
,
2787 .vecs
= cast6_enc_tv_template
,
2788 .count
= CAST6_ENC_TEST_VECTORS
2791 .vecs
= cast6_dec_tv_template
,
2792 .count
= CAST6_DEC_TEST_VECTORS
2797 .alg
= "ecb(cipher_null)",
2798 .test
= alg_test_null
,
2801 .test
= alg_test_skcipher
,
2805 .vecs
= des_enc_tv_template
,
2806 .count
= DES_ENC_TEST_VECTORS
2809 .vecs
= des_dec_tv_template
,
2810 .count
= DES_DEC_TEST_VECTORS
2815 .alg
= "ecb(des3_ede)",
2816 .test
= alg_test_skcipher
,
2821 .vecs
= des3_ede_enc_tv_template
,
2822 .count
= DES3_EDE_ENC_TEST_VECTORS
2825 .vecs
= des3_ede_dec_tv_template
,
2826 .count
= DES3_EDE_DEC_TEST_VECTORS
2831 .alg
= "ecb(fcrypt)",
2832 .test
= alg_test_skcipher
,
2836 .vecs
= fcrypt_pcbc_enc_tv_template
,
2840 .vecs
= fcrypt_pcbc_dec_tv_template
,
2846 .alg
= "ecb(khazad)",
2847 .test
= alg_test_skcipher
,
2851 .vecs
= khazad_enc_tv_template
,
2852 .count
= KHAZAD_ENC_TEST_VECTORS
2855 .vecs
= khazad_dec_tv_template
,
2856 .count
= KHAZAD_DEC_TEST_VECTORS
2862 .test
= alg_test_skcipher
,
2866 .vecs
= seed_enc_tv_template
,
2867 .count
= SEED_ENC_TEST_VECTORS
2870 .vecs
= seed_dec_tv_template
,
2871 .count
= SEED_DEC_TEST_VECTORS
2876 .alg
= "ecb(serpent)",
2877 .test
= alg_test_skcipher
,
2881 .vecs
= serpent_enc_tv_template
,
2882 .count
= SERPENT_ENC_TEST_VECTORS
2885 .vecs
= serpent_dec_tv_template
,
2886 .count
= SERPENT_DEC_TEST_VECTORS
2892 .test
= alg_test_skcipher
,
2896 .vecs
= tea_enc_tv_template
,
2897 .count
= TEA_ENC_TEST_VECTORS
2900 .vecs
= tea_dec_tv_template
,
2901 .count
= TEA_DEC_TEST_VECTORS
2906 .alg
= "ecb(tnepres)",
2907 .test
= alg_test_skcipher
,
2911 .vecs
= tnepres_enc_tv_template
,
2912 .count
= TNEPRES_ENC_TEST_VECTORS
2915 .vecs
= tnepres_dec_tv_template
,
2916 .count
= TNEPRES_DEC_TEST_VECTORS
2921 .alg
= "ecb(twofish)",
2922 .test
= alg_test_skcipher
,
2926 .vecs
= tf_enc_tv_template
,
2927 .count
= TF_ENC_TEST_VECTORS
2930 .vecs
= tf_dec_tv_template
,
2931 .count
= TF_DEC_TEST_VECTORS
2937 .test
= alg_test_skcipher
,
2941 .vecs
= xeta_enc_tv_template
,
2942 .count
= XETA_ENC_TEST_VECTORS
2945 .vecs
= xeta_dec_tv_template
,
2946 .count
= XETA_DEC_TEST_VECTORS
2952 .test
= alg_test_skcipher
,
2956 .vecs
= xtea_enc_tv_template
,
2957 .count
= XTEA_ENC_TEST_VECTORS
2960 .vecs
= xtea_dec_tv_template
,
2961 .count
= XTEA_DEC_TEST_VECTORS
2967 .test
= alg_test_aead
,
2972 .vecs
= aes_gcm_enc_tv_template
,
2973 .count
= AES_GCM_ENC_TEST_VECTORS
2976 .vecs
= aes_gcm_dec_tv_template
,
2977 .count
= AES_GCM_DEC_TEST_VECTORS
2983 .test
= alg_test_hash
,
2987 .vecs
= ghash_tv_template
,
2988 .count
= GHASH_TEST_VECTORS
2992 .alg
= "hmac(crc32)",
2993 .test
= alg_test_hash
,
2996 .vecs
= bfin_crc_tv_template
,
2997 .count
= BFIN_CRC_TEST_VECTORS
3002 .test
= alg_test_hash
,
3005 .vecs
= hmac_md5_tv_template
,
3006 .count
= HMAC_MD5_TEST_VECTORS
3010 .alg
= "hmac(rmd128)",
3011 .test
= alg_test_hash
,
3014 .vecs
= hmac_rmd128_tv_template
,
3015 .count
= HMAC_RMD128_TEST_VECTORS
3019 .alg
= "hmac(rmd160)",
3020 .test
= alg_test_hash
,
3023 .vecs
= hmac_rmd160_tv_template
,
3024 .count
= HMAC_RMD160_TEST_VECTORS
3028 .alg
= "hmac(sha1)",
3029 .test
= alg_test_hash
,
3033 .vecs
= hmac_sha1_tv_template
,
3034 .count
= HMAC_SHA1_TEST_VECTORS
3038 .alg
= "hmac(sha224)",
3039 .test
= alg_test_hash
,
3043 .vecs
= hmac_sha224_tv_template
,
3044 .count
= HMAC_SHA224_TEST_VECTORS
3048 .alg
= "hmac(sha256)",
3049 .test
= alg_test_hash
,
3053 .vecs
= hmac_sha256_tv_template
,
3054 .count
= HMAC_SHA256_TEST_VECTORS
3058 .alg
= "hmac(sha384)",
3059 .test
= alg_test_hash
,
3063 .vecs
= hmac_sha384_tv_template
,
3064 .count
= HMAC_SHA384_TEST_VECTORS
3068 .alg
= "hmac(sha512)",
3069 .test
= alg_test_hash
,
3073 .vecs
= hmac_sha512_tv_template
,
3074 .count
= HMAC_SHA512_TEST_VECTORS
3078 .alg
= "jitterentropy_rng",
3080 .test
= alg_test_null
,
3083 .test
= alg_test_skcipher
,
3088 .vecs
= aes_kw_enc_tv_template
,
3089 .count
= ARRAY_SIZE(aes_kw_enc_tv_template
)
3092 .vecs
= aes_kw_dec_tv_template
,
3093 .count
= ARRAY_SIZE(aes_kw_dec_tv_template
)
3099 .test
= alg_test_skcipher
,
3103 .vecs
= aes_lrw_enc_tv_template
,
3104 .count
= AES_LRW_ENC_TEST_VECTORS
3107 .vecs
= aes_lrw_dec_tv_template
,
3108 .count
= AES_LRW_DEC_TEST_VECTORS
3113 .alg
= "lrw(camellia)",
3114 .test
= alg_test_skcipher
,
3118 .vecs
= camellia_lrw_enc_tv_template
,
3119 .count
= CAMELLIA_LRW_ENC_TEST_VECTORS
3122 .vecs
= camellia_lrw_dec_tv_template
,
3123 .count
= CAMELLIA_LRW_DEC_TEST_VECTORS
3128 .alg
= "lrw(cast6)",
3129 .test
= alg_test_skcipher
,
3133 .vecs
= cast6_lrw_enc_tv_template
,
3134 .count
= CAST6_LRW_ENC_TEST_VECTORS
3137 .vecs
= cast6_lrw_dec_tv_template
,
3138 .count
= CAST6_LRW_DEC_TEST_VECTORS
3143 .alg
= "lrw(serpent)",
3144 .test
= alg_test_skcipher
,
3148 .vecs
= serpent_lrw_enc_tv_template
,
3149 .count
= SERPENT_LRW_ENC_TEST_VECTORS
3152 .vecs
= serpent_lrw_dec_tv_template
,
3153 .count
= SERPENT_LRW_DEC_TEST_VECTORS
3158 .alg
= "lrw(twofish)",
3159 .test
= alg_test_skcipher
,
3163 .vecs
= tf_lrw_enc_tv_template
,
3164 .count
= TF_LRW_ENC_TEST_VECTORS
3167 .vecs
= tf_lrw_dec_tv_template
,
3168 .count
= TF_LRW_DEC_TEST_VECTORS
3174 .test
= alg_test_comp
,
3179 .vecs
= lz4_comp_tv_template
,
3180 .count
= LZ4_COMP_TEST_VECTORS
3183 .vecs
= lz4_decomp_tv_template
,
3184 .count
= LZ4_DECOMP_TEST_VECTORS
3190 .test
= alg_test_comp
,
3195 .vecs
= lz4hc_comp_tv_template
,
3196 .count
= LZ4HC_COMP_TEST_VECTORS
3199 .vecs
= lz4hc_decomp_tv_template
,
3200 .count
= LZ4HC_DECOMP_TEST_VECTORS
3206 .test
= alg_test_comp
,
3211 .vecs
= lzo_comp_tv_template
,
3212 .count
= LZO_COMP_TEST_VECTORS
3215 .vecs
= lzo_decomp_tv_template
,
3216 .count
= LZO_DECOMP_TEST_VECTORS
3222 .test
= alg_test_hash
,
3225 .vecs
= md4_tv_template
,
3226 .count
= MD4_TEST_VECTORS
3231 .test
= alg_test_hash
,
3234 .vecs
= md5_tv_template
,
3235 .count
= MD5_TEST_VECTORS
3239 .alg
= "michael_mic",
3240 .test
= alg_test_hash
,
3243 .vecs
= michael_mic_tv_template
,
3244 .count
= MICHAEL_MIC_TEST_VECTORS
3249 .test
= alg_test_skcipher
,
3254 .vecs
= aes_ofb_enc_tv_template
,
3255 .count
= AES_OFB_ENC_TEST_VECTORS
3258 .vecs
= aes_ofb_dec_tv_template
,
3259 .count
= AES_OFB_DEC_TEST_VECTORS
3264 .alg
= "pcbc(fcrypt)",
3265 .test
= alg_test_skcipher
,
3269 .vecs
= fcrypt_pcbc_enc_tv_template
,
3270 .count
= FCRYPT_ENC_TEST_VECTORS
3273 .vecs
= fcrypt_pcbc_dec_tv_template
,
3274 .count
= FCRYPT_DEC_TEST_VECTORS
3280 .test
= alg_test_hash
,
3283 .vecs
= poly1305_tv_template
,
3284 .count
= POLY1305_TEST_VECTORS
3288 .alg
= "rfc3686(ctr(aes))",
3289 .test
= alg_test_skcipher
,
3294 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
3295 .count
= AES_CTR_3686_ENC_TEST_VECTORS
3298 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
3299 .count
= AES_CTR_3686_DEC_TEST_VECTORS
3304 .alg
= "rfc4106(gcm(aes))",
3305 .test
= alg_test_aead
,
3310 .vecs
= aes_gcm_rfc4106_enc_tv_template
,
3311 .count
= AES_GCM_4106_ENC_TEST_VECTORS
3314 .vecs
= aes_gcm_rfc4106_dec_tv_template
,
3315 .count
= AES_GCM_4106_DEC_TEST_VECTORS
3320 .alg
= "rfc4309(ccm(aes))",
3321 .test
= alg_test_aead
,
3326 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
3327 .count
= AES_CCM_4309_ENC_TEST_VECTORS
3330 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
3331 .count
= AES_CCM_4309_DEC_TEST_VECTORS
3336 .alg
= "rfc4543(gcm(aes))",
3337 .test
= alg_test_aead
,
3341 .vecs
= aes_gcm_rfc4543_enc_tv_template
,
3342 .count
= AES_GCM_4543_ENC_TEST_VECTORS
3345 .vecs
= aes_gcm_rfc4543_dec_tv_template
,
3346 .count
= AES_GCM_4543_DEC_TEST_VECTORS
3351 .alg
= "rfc7539(chacha20,poly1305)",
3352 .test
= alg_test_aead
,
3356 .vecs
= rfc7539_enc_tv_template
,
3357 .count
= RFC7539_ENC_TEST_VECTORS
3360 .vecs
= rfc7539_dec_tv_template
,
3361 .count
= RFC7539_DEC_TEST_VECTORS
3366 .alg
= "rfc7539esp(chacha20,poly1305)",
3367 .test
= alg_test_aead
,
3371 .vecs
= rfc7539esp_enc_tv_template
,
3372 .count
= RFC7539ESP_ENC_TEST_VECTORS
3375 .vecs
= rfc7539esp_dec_tv_template
,
3376 .count
= RFC7539ESP_DEC_TEST_VECTORS
3382 .test
= alg_test_hash
,
3385 .vecs
= rmd128_tv_template
,
3386 .count
= RMD128_TEST_VECTORS
3391 .test
= alg_test_hash
,
3394 .vecs
= rmd160_tv_template
,
3395 .count
= RMD160_TEST_VECTORS
3400 .test
= alg_test_hash
,
3403 .vecs
= rmd256_tv_template
,
3404 .count
= RMD256_TEST_VECTORS
3409 .test
= alg_test_hash
,
3412 .vecs
= rmd320_tv_template
,
3413 .count
= RMD320_TEST_VECTORS
3418 .test
= alg_test_akcipher
,
3422 .vecs
= rsa_tv_template
,
3423 .count
= RSA_TEST_VECTORS
3428 .test
= alg_test_skcipher
,
3432 .vecs
= salsa20_stream_enc_tv_template
,
3433 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
3439 .test
= alg_test_hash
,
3443 .vecs
= sha1_tv_template
,
3444 .count
= SHA1_TEST_VECTORS
3449 .test
= alg_test_hash
,
3453 .vecs
= sha224_tv_template
,
3454 .count
= SHA224_TEST_VECTORS
3459 .test
= alg_test_hash
,
3463 .vecs
= sha256_tv_template
,
3464 .count
= SHA256_TEST_VECTORS
3469 .test
= alg_test_hash
,
3473 .vecs
= sha384_tv_template
,
3474 .count
= SHA384_TEST_VECTORS
3479 .test
= alg_test_hash
,
3483 .vecs
= sha512_tv_template
,
3484 .count
= SHA512_TEST_VECTORS
3489 .test
= alg_test_hash
,
3492 .vecs
= tgr128_tv_template
,
3493 .count
= TGR128_TEST_VECTORS
3498 .test
= alg_test_hash
,
3501 .vecs
= tgr160_tv_template
,
3502 .count
= TGR160_TEST_VECTORS
3507 .test
= alg_test_hash
,
3510 .vecs
= tgr192_tv_template
,
3511 .count
= TGR192_TEST_VECTORS
3516 .test
= alg_test_hash
,
3519 .vecs
= aes_vmac128_tv_template
,
3520 .count
= VMAC_AES_TEST_VECTORS
3525 .test
= alg_test_hash
,
3528 .vecs
= wp256_tv_template
,
3529 .count
= WP256_TEST_VECTORS
3534 .test
= alg_test_hash
,
3537 .vecs
= wp384_tv_template
,
3538 .count
= WP384_TEST_VECTORS
3543 .test
= alg_test_hash
,
3546 .vecs
= wp512_tv_template
,
3547 .count
= WP512_TEST_VECTORS
3552 .test
= alg_test_hash
,
3555 .vecs
= aes_xcbc128_tv_template
,
3556 .count
= XCBC_AES_TEST_VECTORS
3561 .test
= alg_test_skcipher
,
3566 .vecs
= aes_xts_enc_tv_template
,
3567 .count
= AES_XTS_ENC_TEST_VECTORS
3570 .vecs
= aes_xts_dec_tv_template
,
3571 .count
= AES_XTS_DEC_TEST_VECTORS
3576 .alg
= "xts(camellia)",
3577 .test
= alg_test_skcipher
,
3581 .vecs
= camellia_xts_enc_tv_template
,
3582 .count
= CAMELLIA_XTS_ENC_TEST_VECTORS
3585 .vecs
= camellia_xts_dec_tv_template
,
3586 .count
= CAMELLIA_XTS_DEC_TEST_VECTORS
3591 .alg
= "xts(cast6)",
3592 .test
= alg_test_skcipher
,
3596 .vecs
= cast6_xts_enc_tv_template
,
3597 .count
= CAST6_XTS_ENC_TEST_VECTORS
3600 .vecs
= cast6_xts_dec_tv_template
,
3601 .count
= CAST6_XTS_DEC_TEST_VECTORS
3606 .alg
= "xts(serpent)",
3607 .test
= alg_test_skcipher
,
3611 .vecs
= serpent_xts_enc_tv_template
,
3612 .count
= SERPENT_XTS_ENC_TEST_VECTORS
3615 .vecs
= serpent_xts_dec_tv_template
,
3616 .count
= SERPENT_XTS_DEC_TEST_VECTORS
3621 .alg
= "xts(twofish)",
3622 .test
= alg_test_skcipher
,
3626 .vecs
= tf_xts_enc_tv_template
,
3627 .count
= TF_XTS_ENC_TEST_VECTORS
3630 .vecs
= tf_xts_dec_tv_template
,
3631 .count
= TF_XTS_DEC_TEST_VECTORS
3638 static bool alg_test_descs_checked
;
3640 static void alg_test_descs_check_order(void)
3644 /* only check once */
3645 if (alg_test_descs_checked
)
3648 alg_test_descs_checked
= true;
3650 for (i
= 1; i
< ARRAY_SIZE(alg_test_descs
); i
++) {
3651 int diff
= strcmp(alg_test_descs
[i
- 1].alg
,
3652 alg_test_descs
[i
].alg
);
3654 if (WARN_ON(diff
> 0)) {
3655 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3656 alg_test_descs
[i
- 1].alg
,
3657 alg_test_descs
[i
].alg
);
3660 if (WARN_ON(diff
== 0)) {
3661 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3662 alg_test_descs
[i
].alg
);
3667 static int alg_find_test(const char *alg
)
3670 int end
= ARRAY_SIZE(alg_test_descs
);
3672 while (start
< end
) {
3673 int i
= (start
+ end
) / 2;
3674 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
3692 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
3698 alg_test_descs_check_order();
3700 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
3701 char nalg
[CRYPTO_MAX_ALG_NAME
];
3703 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
3705 return -ENAMETOOLONG
;
3707 i
= alg_find_test(nalg
);
3711 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
3714 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
3718 i
= alg_find_test(alg
);
3719 j
= alg_find_test(driver
);
3723 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
3724 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
3729 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
3731 if (j
>= 0 && j
!= i
)
3732 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
3736 if (fips_enabled
&& rc
)
3737 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
3739 if (fips_enabled
&& !rc
)
3740 pr_info("alg: self-tests for %s (%s) passed\n", driver
, alg
);
3745 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
3751 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3753 EXPORT_SYMBOL_GPL(alg_test
);