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/hash.h>
24 #include <linux/err.h>
25 #include <linux/module.h>
26 #include <linux/scatterlist.h>
27 #include <linux/slab.h>
28 #include <linux/string.h>
29 #include <crypto/rng.h>
30 #include <crypto/drbg.h>
34 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
37 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
47 * Need slab memory for testing (size in number of pages).
52 * Indexes into the xbuf to simulate cross-page access.
64 * Used by test_cipher()
69 struct tcrypt_result
{
70 struct completion completion
;
74 struct aead_test_suite
{
76 struct aead_testvec
*vecs
;
81 struct cipher_test_suite
{
83 struct cipher_testvec
*vecs
;
88 struct comp_test_suite
{
90 struct comp_testvec
*vecs
;
95 struct pcomp_test_suite
{
97 struct pcomp_testvec
*vecs
;
102 struct hash_test_suite
{
103 struct hash_testvec
*vecs
;
107 struct cprng_test_suite
{
108 struct cprng_testvec
*vecs
;
112 struct drbg_test_suite
{
113 struct drbg_testvec
*vecs
;
117 struct alg_test_desc
{
119 int (*test
)(const struct alg_test_desc
*desc
, const char *driver
,
121 int fips_allowed
; /* set if alg is allowed in fips mode */
124 struct aead_test_suite aead
;
125 struct cipher_test_suite cipher
;
126 struct comp_test_suite comp
;
127 struct pcomp_test_suite pcomp
;
128 struct hash_test_suite hash
;
129 struct cprng_test_suite cprng
;
130 struct drbg_test_suite drbg
;
134 static unsigned int IDX
[8] = { IDX1
, IDX2
, IDX3
, IDX4
, IDX5
, IDX6
, IDX7
, IDX8
};
136 static void hexdump(unsigned char *buf
, unsigned int len
)
138 print_hex_dump(KERN_CONT
, "", DUMP_PREFIX_OFFSET
,
143 static void tcrypt_complete(struct crypto_async_request
*req
, int err
)
145 struct tcrypt_result
*res
= req
->data
;
147 if (err
== -EINPROGRESS
)
151 complete(&res
->completion
);
154 static int testmgr_alloc_buf(char *buf
[XBUFSIZE
])
158 for (i
= 0; i
< XBUFSIZE
; i
++) {
159 buf
[i
] = (void *)__get_free_page(GFP_KERNEL
);
168 free_page((unsigned long)buf
[i
]);
173 static void testmgr_free_buf(char *buf
[XBUFSIZE
])
177 for (i
= 0; i
< XBUFSIZE
; i
++)
178 free_page((unsigned long)buf
[i
]);
181 static int do_one_async_hash_op(struct ahash_request
*req
,
182 struct tcrypt_result
*tr
,
185 if (ret
== -EINPROGRESS
|| ret
== -EBUSY
) {
186 ret
= wait_for_completion_interruptible(&tr
->completion
);
189 reinit_completion(&tr
->completion
);
194 static int __test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
195 unsigned int tcount
, bool use_digest
,
196 const int align_offset
)
198 const char *algo
= crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm
));
199 unsigned int i
, j
, k
, temp
;
200 struct scatterlist sg
[8];
203 struct ahash_request
*req
;
204 struct tcrypt_result tresult
;
206 char *xbuf
[XBUFSIZE
];
209 result
= kmalloc(MAX_DIGEST_SIZE
, GFP_KERNEL
);
212 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
215 if (testmgr_alloc_buf(xbuf
))
218 init_completion(&tresult
.completion
);
220 req
= ahash_request_alloc(tfm
, GFP_KERNEL
);
222 printk(KERN_ERR
"alg: hash: Failed to allocate request for "
226 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
227 tcrypt_complete
, &tresult
);
230 for (i
= 0; i
< tcount
; i
++) {
235 if (WARN_ON(align_offset
+ template[i
].psize
> PAGE_SIZE
))
239 memset(result
, 0, MAX_DIGEST_SIZE
);
242 hash_buff
+= align_offset
;
244 memcpy(hash_buff
, template[i
].plaintext
, template[i
].psize
);
245 sg_init_one(&sg
[0], hash_buff
, template[i
].psize
);
247 if (template[i
].ksize
) {
248 crypto_ahash_clear_flags(tfm
, ~0);
249 if (template[i
].ksize
> MAX_KEYLEN
) {
250 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
251 j
, algo
, template[i
].ksize
, MAX_KEYLEN
);
255 memcpy(key
, template[i
].key
, template[i
].ksize
);
256 ret
= crypto_ahash_setkey(tfm
, key
, template[i
].ksize
);
258 printk(KERN_ERR
"alg: hash: setkey failed on "
259 "test %d for %s: ret=%d\n", j
, algo
,
265 ahash_request_set_crypt(req
, sg
, result
, template[i
].psize
);
267 ret
= do_one_async_hash_op(req
, &tresult
,
268 crypto_ahash_digest(req
));
270 pr_err("alg: hash: digest failed on test %d "
271 "for %s: ret=%d\n", j
, algo
, -ret
);
275 ret
= do_one_async_hash_op(req
, &tresult
,
276 crypto_ahash_init(req
));
278 pr_err("alt: hash: init failed on test %d "
279 "for %s: ret=%d\n", j
, algo
, -ret
);
282 ret
= do_one_async_hash_op(req
, &tresult
,
283 crypto_ahash_update(req
));
285 pr_err("alt: hash: update failed on test %d "
286 "for %s: ret=%d\n", j
, algo
, -ret
);
289 ret
= do_one_async_hash_op(req
, &tresult
,
290 crypto_ahash_final(req
));
292 pr_err("alt: hash: final failed on test %d "
293 "for %s: ret=%d\n", j
, algo
, -ret
);
298 if (memcmp(result
, template[i
].digest
,
299 crypto_ahash_digestsize(tfm
))) {
300 printk(KERN_ERR
"alg: hash: Test %d failed for %s\n",
302 hexdump(result
, crypto_ahash_digestsize(tfm
));
309 for (i
= 0; i
< tcount
; i
++) {
310 /* alignment tests are only done with continuous buffers */
311 if (align_offset
!= 0)
314 if (template[i
].np
) {
316 memset(result
, 0, MAX_DIGEST_SIZE
);
319 sg_init_table(sg
, template[i
].np
);
321 for (k
= 0; k
< template[i
].np
; k
++) {
322 if (WARN_ON(offset_in_page(IDX
[k
]) +
323 template[i
].tap
[k
] > PAGE_SIZE
))
326 memcpy(xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
327 offset_in_page(IDX
[k
]),
328 template[i
].plaintext
+ temp
,
331 temp
+= template[i
].tap
[k
];
334 if (template[i
].ksize
) {
335 if (template[i
].ksize
> MAX_KEYLEN
) {
336 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
337 j
, algo
, template[i
].ksize
,
342 crypto_ahash_clear_flags(tfm
, ~0);
343 memcpy(key
, template[i
].key
, template[i
].ksize
);
344 ret
= crypto_ahash_setkey(tfm
, key
,
348 printk(KERN_ERR
"alg: hash: setkey "
349 "failed on chunking test %d "
350 "for %s: ret=%d\n", j
, algo
,
356 ahash_request_set_crypt(req
, sg
, result
,
358 ret
= crypto_ahash_digest(req
);
364 ret
= wait_for_completion_interruptible(
365 &tresult
.completion
);
366 if (!ret
&& !(ret
= tresult
.err
)) {
367 reinit_completion(&tresult
.completion
);
372 printk(KERN_ERR
"alg: hash: digest failed "
373 "on chunking test %d for %s: "
374 "ret=%d\n", j
, algo
, -ret
);
378 if (memcmp(result
, template[i
].digest
,
379 crypto_ahash_digestsize(tfm
))) {
380 printk(KERN_ERR
"alg: hash: Chunking test %d "
381 "failed for %s\n", j
, algo
);
382 hexdump(result
, crypto_ahash_digestsize(tfm
));
392 ahash_request_free(req
);
394 testmgr_free_buf(xbuf
);
401 static int test_hash(struct crypto_ahash
*tfm
, struct hash_testvec
*template,
402 unsigned int tcount
, bool use_digest
)
404 unsigned int alignmask
;
407 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 0);
411 /* test unaligned buffers, check with one byte offset */
412 ret
= __test_hash(tfm
, template, tcount
, use_digest
, 1);
416 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
418 /* Check if alignment mask for tfm is correctly set. */
419 ret
= __test_hash(tfm
, template, tcount
, use_digest
,
428 static int __test_aead(struct crypto_aead
*tfm
, int enc
,
429 struct aead_testvec
*template, unsigned int tcount
,
430 const bool diff_dst
, const int align_offset
)
432 const char *algo
= crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm
));
433 unsigned int i
, j
, k
, n
, temp
;
437 struct aead_request
*req
;
438 struct scatterlist
*sg
;
439 struct scatterlist
*asg
;
440 struct scatterlist
*sgout
;
442 struct tcrypt_result result
;
443 unsigned int authsize
;
448 char *xbuf
[XBUFSIZE
];
449 char *xoutbuf
[XBUFSIZE
];
450 char *axbuf
[XBUFSIZE
];
452 iv
= kzalloc(MAX_IVLEN
, GFP_KERNEL
);
455 key
= kmalloc(MAX_KEYLEN
, GFP_KERNEL
);
458 if (testmgr_alloc_buf(xbuf
))
460 if (testmgr_alloc_buf(axbuf
))
462 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
465 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
466 sg
= kmalloc(sizeof(*sg
) * 8 * (diff_dst
? 3 : 2), GFP_KERNEL
);
482 init_completion(&result
.completion
);
484 req
= aead_request_alloc(tfm
, GFP_KERNEL
);
486 pr_err("alg: aead%s: Failed to allocate request for %s\n",
491 aead_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
492 tcrypt_complete
, &result
);
494 for (i
= 0, j
= 0; i
< tcount
; i
++) {
495 if (!template[i
].np
) {
498 /* some templates have no input data but they will
502 input
+= align_offset
;
506 if (WARN_ON(align_offset
+ template[i
].ilen
>
507 PAGE_SIZE
|| template[i
].alen
> PAGE_SIZE
))
510 memcpy(input
, template[i
].input
, template[i
].ilen
);
511 memcpy(assoc
, template[i
].assoc
, template[i
].alen
);
513 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
515 memset(iv
, 0, MAX_IVLEN
);
517 crypto_aead_clear_flags(tfm
, ~0);
519 crypto_aead_set_flags(
520 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
522 if (template[i
].klen
> MAX_KEYLEN
) {
523 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
524 d
, j
, algo
, template[i
].klen
,
529 memcpy(key
, template[i
].key
, template[i
].klen
);
531 ret
= crypto_aead_setkey(tfm
, key
,
533 if (!ret
== template[i
].fail
) {
534 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
535 d
, j
, algo
, crypto_aead_get_flags(tfm
));
540 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
541 ret
= crypto_aead_setauthsize(tfm
, authsize
);
543 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
544 d
, authsize
, j
, algo
);
550 output
+= align_offset
;
551 sg_init_one(&sg
[0], input
, template[i
].ilen
);
552 sg_init_one(&sgout
[0], output
,
555 sg_init_one(&sg
[0], input
,
557 (enc
? authsize
: 0));
561 sg_init_one(&asg
[0], assoc
, template[i
].alen
);
563 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
564 template[i
].ilen
, iv
);
566 aead_request_set_assoc(req
, asg
, template[i
].alen
);
569 crypto_aead_encrypt(req
) :
570 crypto_aead_decrypt(req
);
574 if (template[i
].novrfy
) {
575 /* verification was supposed to fail */
576 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
578 /* so really, we got a bad message */
585 ret
= wait_for_completion_interruptible(
587 if (!ret
&& !(ret
= result
.err
)) {
588 reinit_completion(&result
.completion
);
592 if (template[i
].novrfy
)
593 /* verification failure was expected */
597 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
598 d
, e
, j
, algo
, -ret
);
603 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
604 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
606 hexdump(q
, template[i
].rlen
);
613 for (i
= 0, j
= 0; i
< tcount
; i
++) {
614 /* alignment tests are only done with continuous buffers */
615 if (align_offset
!= 0)
618 if (template[i
].np
) {
622 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
624 memset(iv
, 0, MAX_IVLEN
);
626 crypto_aead_clear_flags(tfm
, ~0);
628 crypto_aead_set_flags(
629 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
630 if (template[i
].klen
> MAX_KEYLEN
) {
631 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
632 d
, j
, algo
, template[i
].klen
,
637 memcpy(key
, template[i
].key
, template[i
].klen
);
639 ret
= crypto_aead_setkey(tfm
, key
, template[i
].klen
);
640 if (!ret
== template[i
].fail
) {
641 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
642 d
, j
, algo
, crypto_aead_get_flags(tfm
));
647 authsize
= abs(template[i
].rlen
- template[i
].ilen
);
650 sg_init_table(sg
, template[i
].np
);
652 sg_init_table(sgout
, template[i
].np
);
653 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
654 if (WARN_ON(offset_in_page(IDX
[k
]) +
655 template[i
].tap
[k
] > PAGE_SIZE
))
658 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
659 offset_in_page(IDX
[k
]);
661 memcpy(q
, template[i
].input
+ temp
,
664 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
667 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
668 offset_in_page(IDX
[k
]);
670 memset(q
, 0, template[i
].tap
[k
]);
672 sg_set_buf(&sgout
[k
], q
,
676 n
= template[i
].tap
[k
];
677 if (k
== template[i
].np
- 1 && enc
)
679 if (offset_in_page(q
) + n
< PAGE_SIZE
)
682 temp
+= template[i
].tap
[k
];
685 ret
= crypto_aead_setauthsize(tfm
, authsize
);
687 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
688 d
, authsize
, j
, algo
);
693 if (WARN_ON(sg
[k
- 1].offset
+
694 sg
[k
- 1].length
+ authsize
>
701 sgout
[k
- 1].length
+= authsize
;
703 sg
[k
- 1].length
+= authsize
;
706 sg_init_table(asg
, template[i
].anp
);
708 for (k
= 0, temp
= 0; k
< template[i
].anp
; k
++) {
709 if (WARN_ON(offset_in_page(IDX
[k
]) +
710 template[i
].atap
[k
] > PAGE_SIZE
))
713 memcpy(axbuf
[IDX
[k
] >> PAGE_SHIFT
] +
714 offset_in_page(IDX
[k
]),
715 template[i
].assoc
+ temp
,
716 template[i
].atap
[k
]),
717 template[i
].atap
[k
]);
718 temp
+= template[i
].atap
[k
];
721 aead_request_set_crypt(req
, sg
, (diff_dst
) ? sgout
: sg
,
725 aead_request_set_assoc(req
, asg
, template[i
].alen
);
728 crypto_aead_encrypt(req
) :
729 crypto_aead_decrypt(req
);
733 if (template[i
].novrfy
) {
734 /* verification was supposed to fail */
735 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
737 /* so really, we got a bad message */
744 ret
= wait_for_completion_interruptible(
746 if (!ret
&& !(ret
= result
.err
)) {
747 reinit_completion(&result
.completion
);
751 if (template[i
].novrfy
)
752 /* verification failure was expected */
756 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
757 d
, e
, j
, algo
, -ret
);
762 for (k
= 0, temp
= 0; k
< template[i
].np
; k
++) {
764 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
765 offset_in_page(IDX
[k
]);
767 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
768 offset_in_page(IDX
[k
]);
770 n
= template[i
].tap
[k
];
771 if (k
== template[i
].np
- 1)
772 n
+= enc
? authsize
: -authsize
;
774 if (memcmp(q
, template[i
].result
+ temp
, n
)) {
775 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
782 if (k
== template[i
].np
- 1 && !enc
) {
784 memcmp(q
, template[i
].input
+
790 for (n
= 0; offset_in_page(q
+ n
) &&
795 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
796 d
, j
, e
, k
, algo
, n
);
801 temp
+= template[i
].tap
[k
];
809 aead_request_free(req
);
813 testmgr_free_buf(xoutbuf
);
815 testmgr_free_buf(axbuf
);
817 testmgr_free_buf(xbuf
);
824 static int test_aead(struct crypto_aead
*tfm
, int enc
,
825 struct aead_testvec
*template, unsigned int tcount
)
827 unsigned int alignmask
;
830 /* test 'dst == src' case */
831 ret
= __test_aead(tfm
, enc
, template, tcount
, false, 0);
835 /* test 'dst != src' case */
836 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 0);
840 /* test unaligned buffers, check with one byte offset */
841 ret
= __test_aead(tfm
, enc
, template, tcount
, true, 1);
845 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
847 /* Check if alignment mask for tfm is correctly set. */
848 ret
= __test_aead(tfm
, enc
, template, tcount
, true,
857 static int test_cipher(struct crypto_cipher
*tfm
, int enc
,
858 struct cipher_testvec
*template, unsigned int tcount
)
860 const char *algo
= crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm
));
861 unsigned int i
, j
, k
;
865 char *xbuf
[XBUFSIZE
];
868 if (testmgr_alloc_buf(xbuf
))
877 for (i
= 0; i
< tcount
; i
++) {
884 if (WARN_ON(template[i
].ilen
> PAGE_SIZE
))
888 memcpy(data
, template[i
].input
, template[i
].ilen
);
890 crypto_cipher_clear_flags(tfm
, ~0);
892 crypto_cipher_set_flags(tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
894 ret
= crypto_cipher_setkey(tfm
, template[i
].key
,
896 if (!ret
== template[i
].fail
) {
897 printk(KERN_ERR
"alg: cipher: setkey failed "
898 "on test %d for %s: flags=%x\n", j
,
899 algo
, crypto_cipher_get_flags(tfm
));
904 for (k
= 0; k
< template[i
].ilen
;
905 k
+= crypto_cipher_blocksize(tfm
)) {
907 crypto_cipher_encrypt_one(tfm
, data
+ k
,
910 crypto_cipher_decrypt_one(tfm
, data
+ k
,
915 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
916 printk(KERN_ERR
"alg: cipher: Test %d failed "
917 "on %s for %s\n", j
, e
, algo
);
918 hexdump(q
, template[i
].rlen
);
927 testmgr_free_buf(xbuf
);
932 static int __test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
933 struct cipher_testvec
*template, unsigned int tcount
,
934 const bool diff_dst
, const int align_offset
)
937 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm
));
938 unsigned int i
, j
, k
, n
, temp
;
940 struct ablkcipher_request
*req
;
941 struct scatterlist sg
[8];
942 struct scatterlist sgout
[8];
944 struct tcrypt_result result
;
947 char *xbuf
[XBUFSIZE
];
948 char *xoutbuf
[XBUFSIZE
];
951 if (testmgr_alloc_buf(xbuf
))
954 if (diff_dst
&& testmgr_alloc_buf(xoutbuf
))
967 init_completion(&result
.completion
);
969 req
= ablkcipher_request_alloc(tfm
, GFP_KERNEL
);
971 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
976 ablkcipher_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
977 tcrypt_complete
, &result
);
980 for (i
= 0; i
< tcount
; i
++) {
982 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
984 memset(iv
, 0, MAX_IVLEN
);
986 if (!(template[i
].np
) || (template[i
].also_non_np
)) {
990 if (WARN_ON(align_offset
+ template[i
].ilen
>
995 data
+= align_offset
;
996 memcpy(data
, template[i
].input
, template[i
].ilen
);
998 crypto_ablkcipher_clear_flags(tfm
, ~0);
1000 crypto_ablkcipher_set_flags(
1001 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
1003 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
1005 if (!ret
== template[i
].fail
) {
1006 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
1008 crypto_ablkcipher_get_flags(tfm
));
1013 sg_init_one(&sg
[0], data
, template[i
].ilen
);
1016 data
+= align_offset
;
1017 sg_init_one(&sgout
[0], data
, template[i
].ilen
);
1020 ablkcipher_request_set_crypt(req
, sg
,
1021 (diff_dst
) ? sgout
: sg
,
1022 template[i
].ilen
, iv
);
1024 crypto_ablkcipher_encrypt(req
) :
1025 crypto_ablkcipher_decrypt(req
);
1032 ret
= wait_for_completion_interruptible(
1033 &result
.completion
);
1034 if (!ret
&& !((ret
= result
.err
))) {
1035 reinit_completion(&result
.completion
);
1040 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1041 d
, e
, j
, algo
, -ret
);
1046 if (memcmp(q
, template[i
].result
, template[i
].rlen
)) {
1047 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1049 hexdump(q
, template[i
].rlen
);
1057 for (i
= 0; i
< tcount
; i
++) {
1058 /* alignment tests are only done with continuous buffers */
1059 if (align_offset
!= 0)
1063 memcpy(iv
, template[i
].iv
, MAX_IVLEN
);
1065 memset(iv
, 0, MAX_IVLEN
);
1067 if (template[i
].np
) {
1070 crypto_ablkcipher_clear_flags(tfm
, ~0);
1072 crypto_ablkcipher_set_flags(
1073 tfm
, CRYPTO_TFM_REQ_WEAK_KEY
);
1075 ret
= crypto_ablkcipher_setkey(tfm
, template[i
].key
,
1077 if (!ret
== template[i
].fail
) {
1078 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1080 crypto_ablkcipher_get_flags(tfm
));
1087 sg_init_table(sg
, template[i
].np
);
1089 sg_init_table(sgout
, template[i
].np
);
1090 for (k
= 0; k
< template[i
].np
; k
++) {
1091 if (WARN_ON(offset_in_page(IDX
[k
]) +
1092 template[i
].tap
[k
] > PAGE_SIZE
))
1095 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1096 offset_in_page(IDX
[k
]);
1098 memcpy(q
, template[i
].input
+ temp
,
1099 template[i
].tap
[k
]);
1101 if (offset_in_page(q
) + template[i
].tap
[k
] <
1103 q
[template[i
].tap
[k
]] = 0;
1105 sg_set_buf(&sg
[k
], q
, template[i
].tap
[k
]);
1107 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1108 offset_in_page(IDX
[k
]);
1110 sg_set_buf(&sgout
[k
], q
,
1111 template[i
].tap
[k
]);
1113 memset(q
, 0, template[i
].tap
[k
]);
1114 if (offset_in_page(q
) +
1115 template[i
].tap
[k
] < PAGE_SIZE
)
1116 q
[template[i
].tap
[k
]] = 0;
1119 temp
+= template[i
].tap
[k
];
1122 ablkcipher_request_set_crypt(req
, sg
,
1123 (diff_dst
) ? sgout
: sg
,
1124 template[i
].ilen
, iv
);
1127 crypto_ablkcipher_encrypt(req
) :
1128 crypto_ablkcipher_decrypt(req
);
1135 ret
= wait_for_completion_interruptible(
1136 &result
.completion
);
1137 if (!ret
&& !((ret
= result
.err
))) {
1138 reinit_completion(&result
.completion
);
1143 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1144 d
, e
, j
, algo
, -ret
);
1150 for (k
= 0; k
< template[i
].np
; k
++) {
1152 q
= xoutbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1153 offset_in_page(IDX
[k
]);
1155 q
= xbuf
[IDX
[k
] >> PAGE_SHIFT
] +
1156 offset_in_page(IDX
[k
]);
1158 if (memcmp(q
, template[i
].result
+ temp
,
1159 template[i
].tap
[k
])) {
1160 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1162 hexdump(q
, template[i
].tap
[k
]);
1166 q
+= template[i
].tap
[k
];
1167 for (n
= 0; offset_in_page(q
+ n
) && q
[n
]; n
++)
1170 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1171 d
, j
, e
, k
, algo
, n
);
1175 temp
+= template[i
].tap
[k
];
1183 ablkcipher_request_free(req
);
1185 testmgr_free_buf(xoutbuf
);
1187 testmgr_free_buf(xbuf
);
1192 static int test_skcipher(struct crypto_ablkcipher
*tfm
, int enc
,
1193 struct cipher_testvec
*template, unsigned int tcount
)
1195 unsigned int alignmask
;
1198 /* test 'dst == src' case */
1199 ret
= __test_skcipher(tfm
, enc
, template, tcount
, false, 0);
1203 /* test 'dst != src' case */
1204 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 0);
1208 /* test unaligned buffers, check with one byte offset */
1209 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true, 1);
1213 alignmask
= crypto_tfm_alg_alignmask(&tfm
->base
);
1215 /* Check if alignment mask for tfm is correctly set. */
1216 ret
= __test_skcipher(tfm
, enc
, template, tcount
, true,
1225 static int test_comp(struct crypto_comp
*tfm
, struct comp_testvec
*ctemplate
,
1226 struct comp_testvec
*dtemplate
, int ctcount
, int dtcount
)
1228 const char *algo
= crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm
));
1230 char result
[COMP_BUF_SIZE
];
1233 for (i
= 0; i
< ctcount
; i
++) {
1235 unsigned int dlen
= COMP_BUF_SIZE
;
1237 memset(result
, 0, sizeof (result
));
1239 ilen
= ctemplate
[i
].inlen
;
1240 ret
= crypto_comp_compress(tfm
, ctemplate
[i
].input
,
1241 ilen
, result
, &dlen
);
1243 printk(KERN_ERR
"alg: comp: compression failed "
1244 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1249 if (dlen
!= ctemplate
[i
].outlen
) {
1250 printk(KERN_ERR
"alg: comp: Compression test %d "
1251 "failed for %s: output len = %d\n", i
+ 1, algo
,
1257 if (memcmp(result
, ctemplate
[i
].output
, dlen
)) {
1258 printk(KERN_ERR
"alg: comp: Compression test %d "
1259 "failed for %s\n", i
+ 1, algo
);
1260 hexdump(result
, dlen
);
1266 for (i
= 0; i
< dtcount
; i
++) {
1268 unsigned int dlen
= COMP_BUF_SIZE
;
1270 memset(result
, 0, sizeof (result
));
1272 ilen
= dtemplate
[i
].inlen
;
1273 ret
= crypto_comp_decompress(tfm
, dtemplate
[i
].input
,
1274 ilen
, result
, &dlen
);
1276 printk(KERN_ERR
"alg: comp: decompression failed "
1277 "on test %d for %s: ret=%d\n", i
+ 1, algo
,
1282 if (dlen
!= dtemplate
[i
].outlen
) {
1283 printk(KERN_ERR
"alg: comp: Decompression test %d "
1284 "failed for %s: output len = %d\n", i
+ 1, algo
,
1290 if (memcmp(result
, dtemplate
[i
].output
, dlen
)) {
1291 printk(KERN_ERR
"alg: comp: Decompression test %d "
1292 "failed for %s\n", i
+ 1, algo
);
1293 hexdump(result
, dlen
);
1305 static int test_pcomp(struct crypto_pcomp
*tfm
,
1306 struct pcomp_testvec
*ctemplate
,
1307 struct pcomp_testvec
*dtemplate
, int ctcount
,
1310 const char *algo
= crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm
));
1312 char result
[COMP_BUF_SIZE
];
1315 for (i
= 0; i
< ctcount
; i
++) {
1316 struct comp_request req
;
1317 unsigned int produced
= 0;
1319 res
= crypto_compress_setup(tfm
, ctemplate
[i
].params
,
1320 ctemplate
[i
].paramsize
);
1322 pr_err("alg: pcomp: compression setup failed on test "
1323 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1327 res
= crypto_compress_init(tfm
);
1329 pr_err("alg: pcomp: compression init failed on test "
1330 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1334 memset(result
, 0, sizeof(result
));
1336 req
.next_in
= ctemplate
[i
].input
;
1337 req
.avail_in
= ctemplate
[i
].inlen
/ 2;
1338 req
.next_out
= result
;
1339 req
.avail_out
= ctemplate
[i
].outlen
/ 2;
1341 res
= crypto_compress_update(tfm
, &req
);
1342 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1343 pr_err("alg: pcomp: compression update failed on test "
1344 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1350 /* Add remaining input data */
1351 req
.avail_in
+= (ctemplate
[i
].inlen
+ 1) / 2;
1353 res
= crypto_compress_update(tfm
, &req
);
1354 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1355 pr_err("alg: pcomp: compression update failed on test "
1356 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1362 /* Provide remaining output space */
1363 req
.avail_out
+= COMP_BUF_SIZE
- ctemplate
[i
].outlen
/ 2;
1365 res
= crypto_compress_final(tfm
, &req
);
1367 pr_err("alg: pcomp: compression final failed on test "
1368 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1373 if (COMP_BUF_SIZE
- req
.avail_out
!= ctemplate
[i
].outlen
) {
1374 pr_err("alg: comp: Compression test %d failed for %s: "
1375 "output len = %d (expected %d)\n", i
+ 1, algo
,
1376 COMP_BUF_SIZE
- req
.avail_out
,
1377 ctemplate
[i
].outlen
);
1381 if (produced
!= ctemplate
[i
].outlen
) {
1382 pr_err("alg: comp: Compression test %d failed for %s: "
1383 "returned len = %u (expected %d)\n", i
+ 1,
1384 algo
, produced
, ctemplate
[i
].outlen
);
1388 if (memcmp(result
, ctemplate
[i
].output
, ctemplate
[i
].outlen
)) {
1389 pr_err("alg: pcomp: Compression test %d failed for "
1390 "%s\n", i
+ 1, algo
);
1391 hexdump(result
, ctemplate
[i
].outlen
);
1396 for (i
= 0; i
< dtcount
; i
++) {
1397 struct comp_request req
;
1398 unsigned int produced
= 0;
1400 res
= crypto_decompress_setup(tfm
, dtemplate
[i
].params
,
1401 dtemplate
[i
].paramsize
);
1403 pr_err("alg: pcomp: decompression setup failed on "
1404 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1408 res
= crypto_decompress_init(tfm
);
1410 pr_err("alg: pcomp: decompression init failed on test "
1411 "%d for %s: error=%d\n", i
+ 1, algo
, res
);
1415 memset(result
, 0, sizeof(result
));
1417 req
.next_in
= dtemplate
[i
].input
;
1418 req
.avail_in
= dtemplate
[i
].inlen
/ 2;
1419 req
.next_out
= result
;
1420 req
.avail_out
= dtemplate
[i
].outlen
/ 2;
1422 res
= crypto_decompress_update(tfm
, &req
);
1423 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1424 pr_err("alg: pcomp: decompression update failed on "
1425 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1431 /* Add remaining input data */
1432 req
.avail_in
+= (dtemplate
[i
].inlen
+ 1) / 2;
1434 res
= crypto_decompress_update(tfm
, &req
);
1435 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1436 pr_err("alg: pcomp: decompression update failed on "
1437 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1443 /* Provide remaining output space */
1444 req
.avail_out
+= COMP_BUF_SIZE
- dtemplate
[i
].outlen
/ 2;
1446 res
= crypto_decompress_final(tfm
, &req
);
1447 if (res
< 0 && (res
!= -EAGAIN
|| req
.avail_in
)) {
1448 pr_err("alg: pcomp: decompression final failed on "
1449 "test %d for %s: error=%d\n", i
+ 1, algo
, res
);
1455 if (COMP_BUF_SIZE
- req
.avail_out
!= dtemplate
[i
].outlen
) {
1456 pr_err("alg: comp: Decompression test %d failed for "
1457 "%s: output len = %d (expected %d)\n", i
+ 1,
1458 algo
, COMP_BUF_SIZE
- req
.avail_out
,
1459 dtemplate
[i
].outlen
);
1463 if (produced
!= dtemplate
[i
].outlen
) {
1464 pr_err("alg: comp: Decompression test %d failed for "
1465 "%s: returned len = %u (expected %d)\n", i
+ 1,
1466 algo
, produced
, dtemplate
[i
].outlen
);
1470 if (memcmp(result
, dtemplate
[i
].output
, dtemplate
[i
].outlen
)) {
1471 pr_err("alg: pcomp: Decompression test %d failed for "
1472 "%s\n", i
+ 1, algo
);
1473 hexdump(result
, dtemplate
[i
].outlen
);
1482 static int test_cprng(struct crypto_rng
*tfm
, struct cprng_testvec
*template,
1483 unsigned int tcount
)
1485 const char *algo
= crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm
));
1486 int err
= 0, i
, j
, seedsize
;
1490 seedsize
= crypto_rng_seedsize(tfm
);
1492 seed
= kmalloc(seedsize
, GFP_KERNEL
);
1494 printk(KERN_ERR
"alg: cprng: Failed to allocate seed space "
1499 for (i
= 0; i
< tcount
; i
++) {
1500 memset(result
, 0, 32);
1502 memcpy(seed
, template[i
].v
, template[i
].vlen
);
1503 memcpy(seed
+ template[i
].vlen
, template[i
].key
,
1505 memcpy(seed
+ template[i
].vlen
+ template[i
].klen
,
1506 template[i
].dt
, template[i
].dtlen
);
1508 err
= crypto_rng_reset(tfm
, seed
, seedsize
);
1510 printk(KERN_ERR
"alg: cprng: Failed to reset rng "
1515 for (j
= 0; j
< template[i
].loops
; j
++) {
1516 err
= crypto_rng_get_bytes(tfm
, result
,
1518 if (err
!= template[i
].rlen
) {
1519 printk(KERN_ERR
"alg: cprng: Failed to obtain "
1520 "the correct amount of random data for "
1521 "%s (requested %d, got %d)\n", algo
,
1522 template[i
].rlen
, err
);
1527 err
= memcmp(result
, template[i
].result
,
1530 printk(KERN_ERR
"alg: cprng: Test %d failed for %s\n",
1532 hexdump(result
, template[i
].rlen
);
1543 static int alg_test_aead(const struct alg_test_desc
*desc
, const char *driver
,
1546 struct crypto_aead
*tfm
;
1549 tfm
= crypto_alloc_aead(driver
, type
, mask
);
1551 printk(KERN_ERR
"alg: aead: Failed to load transform for %s: "
1552 "%ld\n", driver
, PTR_ERR(tfm
));
1553 return PTR_ERR(tfm
);
1556 if (desc
->suite
.aead
.enc
.vecs
) {
1557 err
= test_aead(tfm
, ENCRYPT
, desc
->suite
.aead
.enc
.vecs
,
1558 desc
->suite
.aead
.enc
.count
);
1563 if (!err
&& desc
->suite
.aead
.dec
.vecs
)
1564 err
= test_aead(tfm
, DECRYPT
, desc
->suite
.aead
.dec
.vecs
,
1565 desc
->suite
.aead
.dec
.count
);
1568 crypto_free_aead(tfm
);
1572 static int alg_test_cipher(const struct alg_test_desc
*desc
,
1573 const char *driver
, u32 type
, u32 mask
)
1575 struct crypto_cipher
*tfm
;
1578 tfm
= crypto_alloc_cipher(driver
, type
, mask
);
1580 printk(KERN_ERR
"alg: cipher: Failed to load transform for "
1581 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1582 return PTR_ERR(tfm
);
1585 if (desc
->suite
.cipher
.enc
.vecs
) {
1586 err
= test_cipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1587 desc
->suite
.cipher
.enc
.count
);
1592 if (desc
->suite
.cipher
.dec
.vecs
)
1593 err
= test_cipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1594 desc
->suite
.cipher
.dec
.count
);
1597 crypto_free_cipher(tfm
);
1601 static int alg_test_skcipher(const struct alg_test_desc
*desc
,
1602 const char *driver
, u32 type
, u32 mask
)
1604 struct crypto_ablkcipher
*tfm
;
1607 tfm
= crypto_alloc_ablkcipher(driver
, type
, mask
);
1609 printk(KERN_ERR
"alg: skcipher: Failed to load transform for "
1610 "%s: %ld\n", driver
, PTR_ERR(tfm
));
1611 return PTR_ERR(tfm
);
1614 if (desc
->suite
.cipher
.enc
.vecs
) {
1615 err
= test_skcipher(tfm
, ENCRYPT
, desc
->suite
.cipher
.enc
.vecs
,
1616 desc
->suite
.cipher
.enc
.count
);
1621 if (desc
->suite
.cipher
.dec
.vecs
)
1622 err
= test_skcipher(tfm
, DECRYPT
, desc
->suite
.cipher
.dec
.vecs
,
1623 desc
->suite
.cipher
.dec
.count
);
1626 crypto_free_ablkcipher(tfm
);
1630 static int alg_test_comp(const struct alg_test_desc
*desc
, const char *driver
,
1633 struct crypto_comp
*tfm
;
1636 tfm
= crypto_alloc_comp(driver
, type
, mask
);
1638 printk(KERN_ERR
"alg: comp: Failed to load transform for %s: "
1639 "%ld\n", driver
, PTR_ERR(tfm
));
1640 return PTR_ERR(tfm
);
1643 err
= test_comp(tfm
, desc
->suite
.comp
.comp
.vecs
,
1644 desc
->suite
.comp
.decomp
.vecs
,
1645 desc
->suite
.comp
.comp
.count
,
1646 desc
->suite
.comp
.decomp
.count
);
1648 crypto_free_comp(tfm
);
1652 static int alg_test_pcomp(const struct alg_test_desc
*desc
, const char *driver
,
1655 struct crypto_pcomp
*tfm
;
1658 tfm
= crypto_alloc_pcomp(driver
, type
, mask
);
1660 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1661 driver
, PTR_ERR(tfm
));
1662 return PTR_ERR(tfm
);
1665 err
= test_pcomp(tfm
, desc
->suite
.pcomp
.comp
.vecs
,
1666 desc
->suite
.pcomp
.decomp
.vecs
,
1667 desc
->suite
.pcomp
.comp
.count
,
1668 desc
->suite
.pcomp
.decomp
.count
);
1670 crypto_free_pcomp(tfm
);
1674 static int alg_test_hash(const struct alg_test_desc
*desc
, const char *driver
,
1677 struct crypto_ahash
*tfm
;
1680 tfm
= crypto_alloc_ahash(driver
, type
, mask
);
1682 printk(KERN_ERR
"alg: hash: Failed to load transform for %s: "
1683 "%ld\n", driver
, PTR_ERR(tfm
));
1684 return PTR_ERR(tfm
);
1687 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1688 desc
->suite
.hash
.count
, true);
1690 err
= test_hash(tfm
, desc
->suite
.hash
.vecs
,
1691 desc
->suite
.hash
.count
, false);
1693 crypto_free_ahash(tfm
);
1697 static int alg_test_crc32c(const struct alg_test_desc
*desc
,
1698 const char *driver
, u32 type
, u32 mask
)
1700 struct crypto_shash
*tfm
;
1704 err
= alg_test_hash(desc
, driver
, type
, mask
);
1708 tfm
= crypto_alloc_shash(driver
, type
, mask
);
1710 printk(KERN_ERR
"alg: crc32c: Failed to load transform for %s: "
1711 "%ld\n", driver
, PTR_ERR(tfm
));
1718 struct shash_desc shash
;
1719 char ctx
[crypto_shash_descsize(tfm
)];
1722 sdesc
.shash
.tfm
= tfm
;
1723 sdesc
.shash
.flags
= 0;
1725 *(u32
*)sdesc
.ctx
= le32_to_cpu(420553207);
1726 err
= crypto_shash_final(&sdesc
.shash
, (u8
*)&val
);
1728 printk(KERN_ERR
"alg: crc32c: Operation failed for "
1729 "%s: %d\n", driver
, err
);
1733 if (val
!= ~420553207) {
1734 printk(KERN_ERR
"alg: crc32c: Test failed for %s: "
1735 "%d\n", driver
, val
);
1740 crypto_free_shash(tfm
);
1746 static int alg_test_cprng(const struct alg_test_desc
*desc
, const char *driver
,
1749 struct crypto_rng
*rng
;
1752 rng
= crypto_alloc_rng(driver
, type
, mask
);
1754 printk(KERN_ERR
"alg: cprng: Failed to load transform for %s: "
1755 "%ld\n", driver
, PTR_ERR(rng
));
1756 return PTR_ERR(rng
);
1759 err
= test_cprng(rng
, desc
->suite
.cprng
.vecs
, desc
->suite
.cprng
.count
);
1761 crypto_free_rng(rng
);
1767 static int drbg_cavs_test(struct drbg_testvec
*test
, int pr
,
1768 const char *driver
, u32 type
, u32 mask
)
1771 struct crypto_rng
*drng
;
1772 struct drbg_test_data test_data
;
1773 struct drbg_string addtl
, pers
, testentropy
;
1774 unsigned char *buf
= kzalloc(test
->expectedlen
, GFP_KERNEL
);
1779 drng
= crypto_alloc_rng(driver
, type
, mask
);
1781 printk(KERN_ERR
"alg: drbg: could not allocate DRNG handle for "
1787 test_data
.testentropy
= &testentropy
;
1788 drbg_string_fill(&testentropy
, test
->entropy
, test
->entropylen
);
1789 drbg_string_fill(&pers
, test
->pers
, test
->perslen
);
1790 ret
= crypto_drbg_reset_test(drng
, &pers
, &test_data
);
1792 printk(KERN_ERR
"alg: drbg: Failed to reset rng\n");
1796 drbg_string_fill(&addtl
, test
->addtla
, test
->addtllen
);
1798 drbg_string_fill(&testentropy
, test
->entpra
, test
->entprlen
);
1799 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1800 buf
, test
->expectedlen
, &addtl
, &test_data
);
1802 ret
= crypto_drbg_get_bytes_addtl(drng
,
1803 buf
, test
->expectedlen
, &addtl
);
1806 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1807 "driver %s\n", driver
);
1811 drbg_string_fill(&addtl
, test
->addtlb
, test
->addtllen
);
1813 drbg_string_fill(&testentropy
, test
->entprb
, test
->entprlen
);
1814 ret
= crypto_drbg_get_bytes_addtl_test(drng
,
1815 buf
, test
->expectedlen
, &addtl
, &test_data
);
1817 ret
= crypto_drbg_get_bytes_addtl(drng
,
1818 buf
, test
->expectedlen
, &addtl
);
1821 printk(KERN_ERR
"alg: drbg: could not obtain random data for "
1822 "driver %s\n", driver
);
1826 ret
= memcmp(test
->expected
, buf
, test
->expectedlen
);
1829 crypto_free_rng(drng
);
1835 static int alg_test_drbg(const struct alg_test_desc
*desc
, const char *driver
,
1841 struct drbg_testvec
*template = desc
->suite
.drbg
.vecs
;
1842 unsigned int tcount
= desc
->suite
.drbg
.count
;
1844 if (0 == memcmp(driver
, "drbg_pr_", 8))
1847 for (i
= 0; i
< tcount
; i
++) {
1848 err
= drbg_cavs_test(&template[i
], pr
, driver
, type
, mask
);
1850 printk(KERN_ERR
"alg: drbg: Test %d failed for %s\n",
1860 static int alg_test_null(const struct alg_test_desc
*desc
,
1861 const char *driver
, u32 type
, u32 mask
)
1866 /* Please keep this list sorted by algorithm name. */
1867 static const struct alg_test_desc alg_test_descs
[] = {
1869 .alg
= "__cbc-cast5-avx",
1870 .test
= alg_test_null
,
1872 .alg
= "__cbc-cast6-avx",
1873 .test
= alg_test_null
,
1875 .alg
= "__cbc-serpent-avx",
1876 .test
= alg_test_null
,
1878 .alg
= "__cbc-serpent-avx2",
1879 .test
= alg_test_null
,
1881 .alg
= "__cbc-serpent-sse2",
1882 .test
= alg_test_null
,
1884 .alg
= "__cbc-twofish-avx",
1885 .test
= alg_test_null
,
1887 .alg
= "__driver-cbc-aes-aesni",
1888 .test
= alg_test_null
,
1891 .alg
= "__driver-cbc-camellia-aesni",
1892 .test
= alg_test_null
,
1894 .alg
= "__driver-cbc-camellia-aesni-avx2",
1895 .test
= alg_test_null
,
1897 .alg
= "__driver-cbc-cast5-avx",
1898 .test
= alg_test_null
,
1900 .alg
= "__driver-cbc-cast6-avx",
1901 .test
= alg_test_null
,
1903 .alg
= "__driver-cbc-serpent-avx",
1904 .test
= alg_test_null
,
1906 .alg
= "__driver-cbc-serpent-avx2",
1907 .test
= alg_test_null
,
1909 .alg
= "__driver-cbc-serpent-sse2",
1910 .test
= alg_test_null
,
1912 .alg
= "__driver-cbc-twofish-avx",
1913 .test
= alg_test_null
,
1915 .alg
= "__driver-ecb-aes-aesni",
1916 .test
= alg_test_null
,
1919 .alg
= "__driver-ecb-camellia-aesni",
1920 .test
= alg_test_null
,
1922 .alg
= "__driver-ecb-camellia-aesni-avx2",
1923 .test
= alg_test_null
,
1925 .alg
= "__driver-ecb-cast5-avx",
1926 .test
= alg_test_null
,
1928 .alg
= "__driver-ecb-cast6-avx",
1929 .test
= alg_test_null
,
1931 .alg
= "__driver-ecb-serpent-avx",
1932 .test
= alg_test_null
,
1934 .alg
= "__driver-ecb-serpent-avx2",
1935 .test
= alg_test_null
,
1937 .alg
= "__driver-ecb-serpent-sse2",
1938 .test
= alg_test_null
,
1940 .alg
= "__driver-ecb-twofish-avx",
1941 .test
= alg_test_null
,
1943 .alg
= "__ghash-pclmulqdqni",
1944 .test
= alg_test_null
,
1947 .alg
= "ansi_cprng",
1948 .test
= alg_test_cprng
,
1952 .vecs
= ansi_cprng_aes_tv_template
,
1953 .count
= ANSI_CPRNG_AES_TEST_VECTORS
1957 .alg
= "authenc(hmac(md5),ecb(cipher_null))",
1958 .test
= alg_test_aead
,
1963 .vecs
= hmac_md5_ecb_cipher_null_enc_tv_template
,
1964 .count
= HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1967 .vecs
= hmac_md5_ecb_cipher_null_dec_tv_template
,
1968 .count
= HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1973 .alg
= "authenc(hmac(sha1),cbc(aes))",
1974 .test
= alg_test_aead
,
1980 hmac_sha1_aes_cbc_enc_tv_temp
,
1982 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1987 .alg
= "authenc(hmac(sha1),cbc(des))",
1988 .test
= alg_test_aead
,
1994 hmac_sha1_des_cbc_enc_tv_temp
,
1996 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2001 .alg
= "authenc(hmac(sha1),cbc(des3_ede))",
2002 .test
= alg_test_aead
,
2008 hmac_sha1_des3_ede_cbc_enc_tv_temp
,
2010 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
2015 .alg
= "authenc(hmac(sha1),ecb(cipher_null))",
2016 .test
= alg_test_aead
,
2022 hmac_sha1_ecb_cipher_null_enc_tv_temp
,
2024 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
2028 hmac_sha1_ecb_cipher_null_dec_tv_temp
,
2030 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2035 .alg
= "authenc(hmac(sha224),cbc(des))",
2036 .test
= alg_test_aead
,
2042 hmac_sha224_des_cbc_enc_tv_temp
,
2044 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2049 .alg
= "authenc(hmac(sha224),cbc(des3_ede))",
2050 .test
= alg_test_aead
,
2056 hmac_sha224_des3_ede_cbc_enc_tv_temp
,
2058 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2063 .alg
= "authenc(hmac(sha256),cbc(aes))",
2064 .test
= alg_test_aead
,
2070 hmac_sha256_aes_cbc_enc_tv_temp
,
2072 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2077 .alg
= "authenc(hmac(sha256),cbc(des))",
2078 .test
= alg_test_aead
,
2084 hmac_sha256_des_cbc_enc_tv_temp
,
2086 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2091 .alg
= "authenc(hmac(sha256),cbc(des3_ede))",
2092 .test
= alg_test_aead
,
2098 hmac_sha256_des3_ede_cbc_enc_tv_temp
,
2100 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2105 .alg
= "authenc(hmac(sha384),cbc(des))",
2106 .test
= alg_test_aead
,
2112 hmac_sha384_des_cbc_enc_tv_temp
,
2114 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2119 .alg
= "authenc(hmac(sha384),cbc(des3_ede))",
2120 .test
= alg_test_aead
,
2126 hmac_sha384_des3_ede_cbc_enc_tv_temp
,
2128 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2133 .alg
= "authenc(hmac(sha512),cbc(aes))",
2134 .test
= alg_test_aead
,
2140 hmac_sha512_aes_cbc_enc_tv_temp
,
2142 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2147 .alg
= "authenc(hmac(sha512),cbc(des))",
2148 .test
= alg_test_aead
,
2154 hmac_sha512_des_cbc_enc_tv_temp
,
2156 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2161 .alg
= "authenc(hmac(sha512),cbc(des3_ede))",
2162 .test
= alg_test_aead
,
2168 hmac_sha512_des3_ede_cbc_enc_tv_temp
,
2170 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2176 .test
= alg_test_skcipher
,
2181 .vecs
= aes_cbc_enc_tv_template
,
2182 .count
= AES_CBC_ENC_TEST_VECTORS
2185 .vecs
= aes_cbc_dec_tv_template
,
2186 .count
= AES_CBC_DEC_TEST_VECTORS
2191 .alg
= "cbc(anubis)",
2192 .test
= alg_test_skcipher
,
2196 .vecs
= anubis_cbc_enc_tv_template
,
2197 .count
= ANUBIS_CBC_ENC_TEST_VECTORS
2200 .vecs
= anubis_cbc_dec_tv_template
,
2201 .count
= ANUBIS_CBC_DEC_TEST_VECTORS
2206 .alg
= "cbc(blowfish)",
2207 .test
= alg_test_skcipher
,
2211 .vecs
= bf_cbc_enc_tv_template
,
2212 .count
= BF_CBC_ENC_TEST_VECTORS
2215 .vecs
= bf_cbc_dec_tv_template
,
2216 .count
= BF_CBC_DEC_TEST_VECTORS
2221 .alg
= "cbc(camellia)",
2222 .test
= alg_test_skcipher
,
2226 .vecs
= camellia_cbc_enc_tv_template
,
2227 .count
= CAMELLIA_CBC_ENC_TEST_VECTORS
2230 .vecs
= camellia_cbc_dec_tv_template
,
2231 .count
= CAMELLIA_CBC_DEC_TEST_VECTORS
2236 .alg
= "cbc(cast5)",
2237 .test
= alg_test_skcipher
,
2241 .vecs
= cast5_cbc_enc_tv_template
,
2242 .count
= CAST5_CBC_ENC_TEST_VECTORS
2245 .vecs
= cast5_cbc_dec_tv_template
,
2246 .count
= CAST5_CBC_DEC_TEST_VECTORS
2251 .alg
= "cbc(cast6)",
2252 .test
= alg_test_skcipher
,
2256 .vecs
= cast6_cbc_enc_tv_template
,
2257 .count
= CAST6_CBC_ENC_TEST_VECTORS
2260 .vecs
= cast6_cbc_dec_tv_template
,
2261 .count
= CAST6_CBC_DEC_TEST_VECTORS
2267 .test
= alg_test_skcipher
,
2271 .vecs
= des_cbc_enc_tv_template
,
2272 .count
= DES_CBC_ENC_TEST_VECTORS
2275 .vecs
= des_cbc_dec_tv_template
,
2276 .count
= DES_CBC_DEC_TEST_VECTORS
2281 .alg
= "cbc(des3_ede)",
2282 .test
= alg_test_skcipher
,
2287 .vecs
= des3_ede_cbc_enc_tv_template
,
2288 .count
= DES3_EDE_CBC_ENC_TEST_VECTORS
2291 .vecs
= des3_ede_cbc_dec_tv_template
,
2292 .count
= DES3_EDE_CBC_DEC_TEST_VECTORS
2297 .alg
= "cbc(serpent)",
2298 .test
= alg_test_skcipher
,
2302 .vecs
= serpent_cbc_enc_tv_template
,
2303 .count
= SERPENT_CBC_ENC_TEST_VECTORS
2306 .vecs
= serpent_cbc_dec_tv_template
,
2307 .count
= SERPENT_CBC_DEC_TEST_VECTORS
2312 .alg
= "cbc(twofish)",
2313 .test
= alg_test_skcipher
,
2317 .vecs
= tf_cbc_enc_tv_template
,
2318 .count
= TF_CBC_ENC_TEST_VECTORS
2321 .vecs
= tf_cbc_dec_tv_template
,
2322 .count
= TF_CBC_DEC_TEST_VECTORS
2328 .test
= alg_test_aead
,
2333 .vecs
= aes_ccm_enc_tv_template
,
2334 .count
= AES_CCM_ENC_TEST_VECTORS
2337 .vecs
= aes_ccm_dec_tv_template
,
2338 .count
= AES_CCM_DEC_TEST_VECTORS
2344 .test
= alg_test_hash
,
2347 .vecs
= aes_cmac128_tv_template
,
2348 .count
= CMAC_AES_TEST_VECTORS
2352 .alg
= "cmac(des3_ede)",
2353 .test
= alg_test_hash
,
2356 .vecs
= des3_ede_cmac64_tv_template
,
2357 .count
= CMAC_DES3_EDE_TEST_VECTORS
2361 .alg
= "compress_null",
2362 .test
= alg_test_null
,
2365 .test
= alg_test_crc32c
,
2369 .vecs
= crc32c_tv_template
,
2370 .count
= CRC32C_TEST_VECTORS
2375 .test
= alg_test_hash
,
2379 .vecs
= crct10dif_tv_template
,
2380 .count
= CRCT10DIF_TEST_VECTORS
2384 .alg
= "cryptd(__driver-cbc-aes-aesni)",
2385 .test
= alg_test_null
,
2388 .alg
= "cryptd(__driver-cbc-camellia-aesni)",
2389 .test
= alg_test_null
,
2391 .alg
= "cryptd(__driver-cbc-camellia-aesni-avx2)",
2392 .test
= alg_test_null
,
2394 .alg
= "cryptd(__driver-cbc-serpent-avx2)",
2395 .test
= alg_test_null
,
2397 .alg
= "cryptd(__driver-ecb-aes-aesni)",
2398 .test
= alg_test_null
,
2401 .alg
= "cryptd(__driver-ecb-camellia-aesni)",
2402 .test
= alg_test_null
,
2404 .alg
= "cryptd(__driver-ecb-camellia-aesni-avx2)",
2405 .test
= alg_test_null
,
2407 .alg
= "cryptd(__driver-ecb-cast5-avx)",
2408 .test
= alg_test_null
,
2410 .alg
= "cryptd(__driver-ecb-cast6-avx)",
2411 .test
= alg_test_null
,
2413 .alg
= "cryptd(__driver-ecb-serpent-avx)",
2414 .test
= alg_test_null
,
2416 .alg
= "cryptd(__driver-ecb-serpent-avx2)",
2417 .test
= alg_test_null
,
2419 .alg
= "cryptd(__driver-ecb-serpent-sse2)",
2420 .test
= alg_test_null
,
2422 .alg
= "cryptd(__driver-ecb-twofish-avx)",
2423 .test
= alg_test_null
,
2425 .alg
= "cryptd(__driver-gcm-aes-aesni)",
2426 .test
= alg_test_null
,
2429 .alg
= "cryptd(__ghash-pclmulqdqni)",
2430 .test
= alg_test_null
,
2434 .test
= alg_test_skcipher
,
2439 .vecs
= aes_ctr_enc_tv_template
,
2440 .count
= AES_CTR_ENC_TEST_VECTORS
2443 .vecs
= aes_ctr_dec_tv_template
,
2444 .count
= AES_CTR_DEC_TEST_VECTORS
2449 .alg
= "ctr(blowfish)",
2450 .test
= alg_test_skcipher
,
2454 .vecs
= bf_ctr_enc_tv_template
,
2455 .count
= BF_CTR_ENC_TEST_VECTORS
2458 .vecs
= bf_ctr_dec_tv_template
,
2459 .count
= BF_CTR_DEC_TEST_VECTORS
2464 .alg
= "ctr(camellia)",
2465 .test
= alg_test_skcipher
,
2469 .vecs
= camellia_ctr_enc_tv_template
,
2470 .count
= CAMELLIA_CTR_ENC_TEST_VECTORS
2473 .vecs
= camellia_ctr_dec_tv_template
,
2474 .count
= CAMELLIA_CTR_DEC_TEST_VECTORS
2479 .alg
= "ctr(cast5)",
2480 .test
= alg_test_skcipher
,
2484 .vecs
= cast5_ctr_enc_tv_template
,
2485 .count
= CAST5_CTR_ENC_TEST_VECTORS
2488 .vecs
= cast5_ctr_dec_tv_template
,
2489 .count
= CAST5_CTR_DEC_TEST_VECTORS
2494 .alg
= "ctr(cast6)",
2495 .test
= alg_test_skcipher
,
2499 .vecs
= cast6_ctr_enc_tv_template
,
2500 .count
= CAST6_CTR_ENC_TEST_VECTORS
2503 .vecs
= cast6_ctr_dec_tv_template
,
2504 .count
= CAST6_CTR_DEC_TEST_VECTORS
2510 .test
= alg_test_skcipher
,
2514 .vecs
= des_ctr_enc_tv_template
,
2515 .count
= DES_CTR_ENC_TEST_VECTORS
2518 .vecs
= des_ctr_dec_tv_template
,
2519 .count
= DES_CTR_DEC_TEST_VECTORS
2524 .alg
= "ctr(des3_ede)",
2525 .test
= alg_test_skcipher
,
2529 .vecs
= des3_ede_ctr_enc_tv_template
,
2530 .count
= DES3_EDE_CTR_ENC_TEST_VECTORS
2533 .vecs
= des3_ede_ctr_dec_tv_template
,
2534 .count
= DES3_EDE_CTR_DEC_TEST_VECTORS
2539 .alg
= "ctr(serpent)",
2540 .test
= alg_test_skcipher
,
2544 .vecs
= serpent_ctr_enc_tv_template
,
2545 .count
= SERPENT_CTR_ENC_TEST_VECTORS
2548 .vecs
= serpent_ctr_dec_tv_template
,
2549 .count
= SERPENT_CTR_DEC_TEST_VECTORS
2554 .alg
= "ctr(twofish)",
2555 .test
= alg_test_skcipher
,
2559 .vecs
= tf_ctr_enc_tv_template
,
2560 .count
= TF_CTR_ENC_TEST_VECTORS
2563 .vecs
= tf_ctr_dec_tv_template
,
2564 .count
= TF_CTR_DEC_TEST_VECTORS
2569 .alg
= "cts(cbc(aes))",
2570 .test
= alg_test_skcipher
,
2574 .vecs
= cts_mode_enc_tv_template
,
2575 .count
= CTS_MODE_ENC_TEST_VECTORS
2578 .vecs
= cts_mode_dec_tv_template
,
2579 .count
= CTS_MODE_DEC_TEST_VECTORS
2585 .test
= alg_test_comp
,
2590 .vecs
= deflate_comp_tv_template
,
2591 .count
= DEFLATE_COMP_TEST_VECTORS
2594 .vecs
= deflate_decomp_tv_template
,
2595 .count
= DEFLATE_DECOMP_TEST_VECTORS
2600 .alg
= "digest_null",
2601 .test
= alg_test_null
,
2603 .alg
= "drbg_nopr_ctr_aes128",
2604 .test
= alg_test_drbg
,
2608 .vecs
= drbg_nopr_ctr_aes128_tv_template
,
2609 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template
)
2613 .alg
= "drbg_nopr_ctr_aes192",
2614 .test
= alg_test_drbg
,
2618 .vecs
= drbg_nopr_ctr_aes192_tv_template
,
2619 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template
)
2623 .alg
= "drbg_nopr_ctr_aes256",
2624 .test
= alg_test_drbg
,
2628 .vecs
= drbg_nopr_ctr_aes256_tv_template
,
2629 .count
= ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template
)
2634 * There is no need to specifically test the DRBG with every
2635 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2637 .alg
= "drbg_nopr_hmac_sha1",
2639 .test
= alg_test_null
,
2641 .alg
= "drbg_nopr_hmac_sha256",
2642 .test
= alg_test_drbg
,
2646 .vecs
= drbg_nopr_hmac_sha256_tv_template
,
2648 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template
)
2652 /* covered by drbg_nopr_hmac_sha256 test */
2653 .alg
= "drbg_nopr_hmac_sha384",
2655 .test
= alg_test_null
,
2657 .alg
= "drbg_nopr_hmac_sha512",
2658 .test
= alg_test_null
,
2661 .alg
= "drbg_nopr_sha1",
2663 .test
= alg_test_null
,
2665 .alg
= "drbg_nopr_sha256",
2666 .test
= alg_test_drbg
,
2670 .vecs
= drbg_nopr_sha256_tv_template
,
2671 .count
= ARRAY_SIZE(drbg_nopr_sha256_tv_template
)
2675 /* covered by drbg_nopr_sha256 test */
2676 .alg
= "drbg_nopr_sha384",
2678 .test
= alg_test_null
,
2680 .alg
= "drbg_nopr_sha512",
2682 .test
= alg_test_null
,
2684 .alg
= "drbg_pr_ctr_aes128",
2685 .test
= alg_test_drbg
,
2689 .vecs
= drbg_pr_ctr_aes128_tv_template
,
2690 .count
= ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template
)
2694 /* covered by drbg_pr_ctr_aes128 test */
2695 .alg
= "drbg_pr_ctr_aes192",
2697 .test
= alg_test_null
,
2699 .alg
= "drbg_pr_ctr_aes256",
2701 .test
= alg_test_null
,
2703 .alg
= "drbg_pr_hmac_sha1",
2705 .test
= alg_test_null
,
2707 .alg
= "drbg_pr_hmac_sha256",
2708 .test
= alg_test_drbg
,
2712 .vecs
= drbg_pr_hmac_sha256_tv_template
,
2713 .count
= ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template
)
2717 /* covered by drbg_pr_hmac_sha256 test */
2718 .alg
= "drbg_pr_hmac_sha384",
2720 .test
= alg_test_null
,
2722 .alg
= "drbg_pr_hmac_sha512",
2723 .test
= alg_test_null
,
2726 .alg
= "drbg_pr_sha1",
2728 .test
= alg_test_null
,
2730 .alg
= "drbg_pr_sha256",
2731 .test
= alg_test_drbg
,
2735 .vecs
= drbg_pr_sha256_tv_template
,
2736 .count
= ARRAY_SIZE(drbg_pr_sha256_tv_template
)
2740 /* covered by drbg_pr_sha256 test */
2741 .alg
= "drbg_pr_sha384",
2743 .test
= alg_test_null
,
2745 .alg
= "drbg_pr_sha512",
2747 .test
= alg_test_null
,
2749 .alg
= "ecb(__aes-aesni)",
2750 .test
= alg_test_null
,
2754 .test
= alg_test_skcipher
,
2759 .vecs
= aes_enc_tv_template
,
2760 .count
= AES_ENC_TEST_VECTORS
2763 .vecs
= aes_dec_tv_template
,
2764 .count
= AES_DEC_TEST_VECTORS
2769 .alg
= "ecb(anubis)",
2770 .test
= alg_test_skcipher
,
2774 .vecs
= anubis_enc_tv_template
,
2775 .count
= ANUBIS_ENC_TEST_VECTORS
2778 .vecs
= anubis_dec_tv_template
,
2779 .count
= ANUBIS_DEC_TEST_VECTORS
2785 .test
= alg_test_skcipher
,
2789 .vecs
= arc4_enc_tv_template
,
2790 .count
= ARC4_ENC_TEST_VECTORS
2793 .vecs
= arc4_dec_tv_template
,
2794 .count
= ARC4_DEC_TEST_VECTORS
2799 .alg
= "ecb(blowfish)",
2800 .test
= alg_test_skcipher
,
2804 .vecs
= bf_enc_tv_template
,
2805 .count
= BF_ENC_TEST_VECTORS
2808 .vecs
= bf_dec_tv_template
,
2809 .count
= BF_DEC_TEST_VECTORS
2814 .alg
= "ecb(camellia)",
2815 .test
= alg_test_skcipher
,
2819 .vecs
= camellia_enc_tv_template
,
2820 .count
= CAMELLIA_ENC_TEST_VECTORS
2823 .vecs
= camellia_dec_tv_template
,
2824 .count
= CAMELLIA_DEC_TEST_VECTORS
2829 .alg
= "ecb(cast5)",
2830 .test
= alg_test_skcipher
,
2834 .vecs
= cast5_enc_tv_template
,
2835 .count
= CAST5_ENC_TEST_VECTORS
2838 .vecs
= cast5_dec_tv_template
,
2839 .count
= CAST5_DEC_TEST_VECTORS
2844 .alg
= "ecb(cast6)",
2845 .test
= alg_test_skcipher
,
2849 .vecs
= cast6_enc_tv_template
,
2850 .count
= CAST6_ENC_TEST_VECTORS
2853 .vecs
= cast6_dec_tv_template
,
2854 .count
= CAST6_DEC_TEST_VECTORS
2859 .alg
= "ecb(cipher_null)",
2860 .test
= alg_test_null
,
2863 .test
= alg_test_skcipher
,
2868 .vecs
= des_enc_tv_template
,
2869 .count
= DES_ENC_TEST_VECTORS
2872 .vecs
= des_dec_tv_template
,
2873 .count
= DES_DEC_TEST_VECTORS
2878 .alg
= "ecb(des3_ede)",
2879 .test
= alg_test_skcipher
,
2884 .vecs
= des3_ede_enc_tv_template
,
2885 .count
= DES3_EDE_ENC_TEST_VECTORS
2888 .vecs
= des3_ede_dec_tv_template
,
2889 .count
= DES3_EDE_DEC_TEST_VECTORS
2894 .alg
= "ecb(fcrypt)",
2895 .test
= alg_test_skcipher
,
2899 .vecs
= fcrypt_pcbc_enc_tv_template
,
2903 .vecs
= fcrypt_pcbc_dec_tv_template
,
2909 .alg
= "ecb(khazad)",
2910 .test
= alg_test_skcipher
,
2914 .vecs
= khazad_enc_tv_template
,
2915 .count
= KHAZAD_ENC_TEST_VECTORS
2918 .vecs
= khazad_dec_tv_template
,
2919 .count
= KHAZAD_DEC_TEST_VECTORS
2925 .test
= alg_test_skcipher
,
2929 .vecs
= seed_enc_tv_template
,
2930 .count
= SEED_ENC_TEST_VECTORS
2933 .vecs
= seed_dec_tv_template
,
2934 .count
= SEED_DEC_TEST_VECTORS
2939 .alg
= "ecb(serpent)",
2940 .test
= alg_test_skcipher
,
2944 .vecs
= serpent_enc_tv_template
,
2945 .count
= SERPENT_ENC_TEST_VECTORS
2948 .vecs
= serpent_dec_tv_template
,
2949 .count
= SERPENT_DEC_TEST_VECTORS
2955 .test
= alg_test_skcipher
,
2959 .vecs
= tea_enc_tv_template
,
2960 .count
= TEA_ENC_TEST_VECTORS
2963 .vecs
= tea_dec_tv_template
,
2964 .count
= TEA_DEC_TEST_VECTORS
2969 .alg
= "ecb(tnepres)",
2970 .test
= alg_test_skcipher
,
2974 .vecs
= tnepres_enc_tv_template
,
2975 .count
= TNEPRES_ENC_TEST_VECTORS
2978 .vecs
= tnepres_dec_tv_template
,
2979 .count
= TNEPRES_DEC_TEST_VECTORS
2984 .alg
= "ecb(twofish)",
2985 .test
= alg_test_skcipher
,
2989 .vecs
= tf_enc_tv_template
,
2990 .count
= TF_ENC_TEST_VECTORS
2993 .vecs
= tf_dec_tv_template
,
2994 .count
= TF_DEC_TEST_VECTORS
3000 .test
= alg_test_skcipher
,
3004 .vecs
= xeta_enc_tv_template
,
3005 .count
= XETA_ENC_TEST_VECTORS
3008 .vecs
= xeta_dec_tv_template
,
3009 .count
= XETA_DEC_TEST_VECTORS
3015 .test
= alg_test_skcipher
,
3019 .vecs
= xtea_enc_tv_template
,
3020 .count
= XTEA_ENC_TEST_VECTORS
3023 .vecs
= xtea_dec_tv_template
,
3024 .count
= XTEA_DEC_TEST_VECTORS
3030 .test
= alg_test_aead
,
3035 .vecs
= aes_gcm_enc_tv_template
,
3036 .count
= AES_GCM_ENC_TEST_VECTORS
3039 .vecs
= aes_gcm_dec_tv_template
,
3040 .count
= AES_GCM_DEC_TEST_VECTORS
3046 .test
= alg_test_hash
,
3050 .vecs
= ghash_tv_template
,
3051 .count
= GHASH_TEST_VECTORS
3055 .alg
= "hmac(crc32)",
3056 .test
= alg_test_hash
,
3059 .vecs
= bfin_crc_tv_template
,
3060 .count
= BFIN_CRC_TEST_VECTORS
3065 .test
= alg_test_hash
,
3068 .vecs
= hmac_md5_tv_template
,
3069 .count
= HMAC_MD5_TEST_VECTORS
3073 .alg
= "hmac(rmd128)",
3074 .test
= alg_test_hash
,
3077 .vecs
= hmac_rmd128_tv_template
,
3078 .count
= HMAC_RMD128_TEST_VECTORS
3082 .alg
= "hmac(rmd160)",
3083 .test
= alg_test_hash
,
3086 .vecs
= hmac_rmd160_tv_template
,
3087 .count
= HMAC_RMD160_TEST_VECTORS
3091 .alg
= "hmac(sha1)",
3092 .test
= alg_test_hash
,
3096 .vecs
= hmac_sha1_tv_template
,
3097 .count
= HMAC_SHA1_TEST_VECTORS
3101 .alg
= "hmac(sha224)",
3102 .test
= alg_test_hash
,
3106 .vecs
= hmac_sha224_tv_template
,
3107 .count
= HMAC_SHA224_TEST_VECTORS
3111 .alg
= "hmac(sha256)",
3112 .test
= alg_test_hash
,
3116 .vecs
= hmac_sha256_tv_template
,
3117 .count
= HMAC_SHA256_TEST_VECTORS
3121 .alg
= "hmac(sha384)",
3122 .test
= alg_test_hash
,
3126 .vecs
= hmac_sha384_tv_template
,
3127 .count
= HMAC_SHA384_TEST_VECTORS
3131 .alg
= "hmac(sha512)",
3132 .test
= alg_test_hash
,
3136 .vecs
= hmac_sha512_tv_template
,
3137 .count
= HMAC_SHA512_TEST_VECTORS
3142 .test
= alg_test_skcipher
,
3146 .vecs
= aes_lrw_enc_tv_template
,
3147 .count
= AES_LRW_ENC_TEST_VECTORS
3150 .vecs
= aes_lrw_dec_tv_template
,
3151 .count
= AES_LRW_DEC_TEST_VECTORS
3156 .alg
= "lrw(camellia)",
3157 .test
= alg_test_skcipher
,
3161 .vecs
= camellia_lrw_enc_tv_template
,
3162 .count
= CAMELLIA_LRW_ENC_TEST_VECTORS
3165 .vecs
= camellia_lrw_dec_tv_template
,
3166 .count
= CAMELLIA_LRW_DEC_TEST_VECTORS
3171 .alg
= "lrw(cast6)",
3172 .test
= alg_test_skcipher
,
3176 .vecs
= cast6_lrw_enc_tv_template
,
3177 .count
= CAST6_LRW_ENC_TEST_VECTORS
3180 .vecs
= cast6_lrw_dec_tv_template
,
3181 .count
= CAST6_LRW_DEC_TEST_VECTORS
3186 .alg
= "lrw(serpent)",
3187 .test
= alg_test_skcipher
,
3191 .vecs
= serpent_lrw_enc_tv_template
,
3192 .count
= SERPENT_LRW_ENC_TEST_VECTORS
3195 .vecs
= serpent_lrw_dec_tv_template
,
3196 .count
= SERPENT_LRW_DEC_TEST_VECTORS
3201 .alg
= "lrw(twofish)",
3202 .test
= alg_test_skcipher
,
3206 .vecs
= tf_lrw_enc_tv_template
,
3207 .count
= TF_LRW_ENC_TEST_VECTORS
3210 .vecs
= tf_lrw_dec_tv_template
,
3211 .count
= TF_LRW_DEC_TEST_VECTORS
3217 .test
= alg_test_comp
,
3222 .vecs
= lzo_comp_tv_template
,
3223 .count
= LZO_COMP_TEST_VECTORS
3226 .vecs
= lzo_decomp_tv_template
,
3227 .count
= LZO_DECOMP_TEST_VECTORS
3233 .test
= alg_test_hash
,
3236 .vecs
= md4_tv_template
,
3237 .count
= MD4_TEST_VECTORS
3242 .test
= alg_test_hash
,
3245 .vecs
= md5_tv_template
,
3246 .count
= MD5_TEST_VECTORS
3250 .alg
= "michael_mic",
3251 .test
= alg_test_hash
,
3254 .vecs
= michael_mic_tv_template
,
3255 .count
= MICHAEL_MIC_TEST_VECTORS
3260 .test
= alg_test_skcipher
,
3265 .vecs
= aes_ofb_enc_tv_template
,
3266 .count
= AES_OFB_ENC_TEST_VECTORS
3269 .vecs
= aes_ofb_dec_tv_template
,
3270 .count
= AES_OFB_DEC_TEST_VECTORS
3275 .alg
= "pcbc(fcrypt)",
3276 .test
= alg_test_skcipher
,
3280 .vecs
= fcrypt_pcbc_enc_tv_template
,
3281 .count
= FCRYPT_ENC_TEST_VECTORS
3284 .vecs
= fcrypt_pcbc_dec_tv_template
,
3285 .count
= FCRYPT_DEC_TEST_VECTORS
3290 .alg
= "rfc3686(ctr(aes))",
3291 .test
= alg_test_skcipher
,
3296 .vecs
= aes_ctr_rfc3686_enc_tv_template
,
3297 .count
= AES_CTR_3686_ENC_TEST_VECTORS
3300 .vecs
= aes_ctr_rfc3686_dec_tv_template
,
3301 .count
= AES_CTR_3686_DEC_TEST_VECTORS
3306 .alg
= "rfc4106(gcm(aes))",
3307 .test
= alg_test_aead
,
3311 .vecs
= aes_gcm_rfc4106_enc_tv_template
,
3312 .count
= AES_GCM_4106_ENC_TEST_VECTORS
3315 .vecs
= aes_gcm_rfc4106_dec_tv_template
,
3316 .count
= AES_GCM_4106_DEC_TEST_VECTORS
3321 .alg
= "rfc4309(ccm(aes))",
3322 .test
= alg_test_aead
,
3327 .vecs
= aes_ccm_rfc4309_enc_tv_template
,
3328 .count
= AES_CCM_4309_ENC_TEST_VECTORS
3331 .vecs
= aes_ccm_rfc4309_dec_tv_template
,
3332 .count
= AES_CCM_4309_DEC_TEST_VECTORS
3337 .alg
= "rfc4543(gcm(aes))",
3338 .test
= alg_test_aead
,
3342 .vecs
= aes_gcm_rfc4543_enc_tv_template
,
3343 .count
= AES_GCM_4543_ENC_TEST_VECTORS
3346 .vecs
= aes_gcm_rfc4543_dec_tv_template
,
3347 .count
= AES_GCM_4543_DEC_TEST_VECTORS
3353 .test
= alg_test_hash
,
3356 .vecs
= rmd128_tv_template
,
3357 .count
= RMD128_TEST_VECTORS
3362 .test
= alg_test_hash
,
3365 .vecs
= rmd160_tv_template
,
3366 .count
= RMD160_TEST_VECTORS
3371 .test
= alg_test_hash
,
3374 .vecs
= rmd256_tv_template
,
3375 .count
= RMD256_TEST_VECTORS
3380 .test
= alg_test_hash
,
3383 .vecs
= rmd320_tv_template
,
3384 .count
= RMD320_TEST_VECTORS
3389 .test
= alg_test_skcipher
,
3393 .vecs
= salsa20_stream_enc_tv_template
,
3394 .count
= SALSA20_STREAM_ENC_TEST_VECTORS
3400 .test
= alg_test_hash
,
3404 .vecs
= sha1_tv_template
,
3405 .count
= SHA1_TEST_VECTORS
3410 .test
= alg_test_hash
,
3414 .vecs
= sha224_tv_template
,
3415 .count
= SHA224_TEST_VECTORS
3420 .test
= alg_test_hash
,
3424 .vecs
= sha256_tv_template
,
3425 .count
= SHA256_TEST_VECTORS
3430 .test
= alg_test_hash
,
3434 .vecs
= sha384_tv_template
,
3435 .count
= SHA384_TEST_VECTORS
3440 .test
= alg_test_hash
,
3444 .vecs
= sha512_tv_template
,
3445 .count
= SHA512_TEST_VECTORS
3450 .test
= alg_test_hash
,
3453 .vecs
= tgr128_tv_template
,
3454 .count
= TGR128_TEST_VECTORS
3459 .test
= alg_test_hash
,
3462 .vecs
= tgr160_tv_template
,
3463 .count
= TGR160_TEST_VECTORS
3468 .test
= alg_test_hash
,
3471 .vecs
= tgr192_tv_template
,
3472 .count
= TGR192_TEST_VECTORS
3477 .test
= alg_test_hash
,
3480 .vecs
= aes_vmac128_tv_template
,
3481 .count
= VMAC_AES_TEST_VECTORS
3486 .test
= alg_test_hash
,
3489 .vecs
= wp256_tv_template
,
3490 .count
= WP256_TEST_VECTORS
3495 .test
= alg_test_hash
,
3498 .vecs
= wp384_tv_template
,
3499 .count
= WP384_TEST_VECTORS
3504 .test
= alg_test_hash
,
3507 .vecs
= wp512_tv_template
,
3508 .count
= WP512_TEST_VECTORS
3513 .test
= alg_test_hash
,
3516 .vecs
= aes_xcbc128_tv_template
,
3517 .count
= XCBC_AES_TEST_VECTORS
3522 .test
= alg_test_skcipher
,
3527 .vecs
= aes_xts_enc_tv_template
,
3528 .count
= AES_XTS_ENC_TEST_VECTORS
3531 .vecs
= aes_xts_dec_tv_template
,
3532 .count
= AES_XTS_DEC_TEST_VECTORS
3537 .alg
= "xts(camellia)",
3538 .test
= alg_test_skcipher
,
3542 .vecs
= camellia_xts_enc_tv_template
,
3543 .count
= CAMELLIA_XTS_ENC_TEST_VECTORS
3546 .vecs
= camellia_xts_dec_tv_template
,
3547 .count
= CAMELLIA_XTS_DEC_TEST_VECTORS
3552 .alg
= "xts(cast6)",
3553 .test
= alg_test_skcipher
,
3557 .vecs
= cast6_xts_enc_tv_template
,
3558 .count
= CAST6_XTS_ENC_TEST_VECTORS
3561 .vecs
= cast6_xts_dec_tv_template
,
3562 .count
= CAST6_XTS_DEC_TEST_VECTORS
3567 .alg
= "xts(serpent)",
3568 .test
= alg_test_skcipher
,
3572 .vecs
= serpent_xts_enc_tv_template
,
3573 .count
= SERPENT_XTS_ENC_TEST_VECTORS
3576 .vecs
= serpent_xts_dec_tv_template
,
3577 .count
= SERPENT_XTS_DEC_TEST_VECTORS
3582 .alg
= "xts(twofish)",
3583 .test
= alg_test_skcipher
,
3587 .vecs
= tf_xts_enc_tv_template
,
3588 .count
= TF_XTS_ENC_TEST_VECTORS
3591 .vecs
= tf_xts_dec_tv_template
,
3592 .count
= TF_XTS_DEC_TEST_VECTORS
3598 .test
= alg_test_pcomp
,
3603 .vecs
= zlib_comp_tv_template
,
3604 .count
= ZLIB_COMP_TEST_VECTORS
3607 .vecs
= zlib_decomp_tv_template
,
3608 .count
= ZLIB_DECOMP_TEST_VECTORS
3615 static bool alg_test_descs_checked
;
3617 static void alg_test_descs_check_order(void)
3621 /* only check once */
3622 if (alg_test_descs_checked
)
3625 alg_test_descs_checked
= true;
3627 for (i
= 1; i
< ARRAY_SIZE(alg_test_descs
); i
++) {
3628 int diff
= strcmp(alg_test_descs
[i
- 1].alg
,
3629 alg_test_descs
[i
].alg
);
3631 if (WARN_ON(diff
> 0)) {
3632 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3633 alg_test_descs
[i
- 1].alg
,
3634 alg_test_descs
[i
].alg
);
3637 if (WARN_ON(diff
== 0)) {
3638 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3639 alg_test_descs
[i
].alg
);
3644 static int alg_find_test(const char *alg
)
3647 int end
= ARRAY_SIZE(alg_test_descs
);
3649 while (start
< end
) {
3650 int i
= (start
+ end
) / 2;
3651 int diff
= strcmp(alg_test_descs
[i
].alg
, alg
);
3669 int alg_test(const char *driver
, const char *alg
, u32 type
, u32 mask
)
3675 alg_test_descs_check_order();
3677 if ((type
& CRYPTO_ALG_TYPE_MASK
) == CRYPTO_ALG_TYPE_CIPHER
) {
3678 char nalg
[CRYPTO_MAX_ALG_NAME
];
3680 if (snprintf(nalg
, sizeof(nalg
), "ecb(%s)", alg
) >=
3682 return -ENAMETOOLONG
;
3684 i
= alg_find_test(nalg
);
3688 if (fips_enabled
&& !alg_test_descs
[i
].fips_allowed
)
3691 rc
= alg_test_cipher(alg_test_descs
+ i
, driver
, type
, mask
);
3695 i
= alg_find_test(alg
);
3696 j
= alg_find_test(driver
);
3700 if (fips_enabled
&& ((i
>= 0 && !alg_test_descs
[i
].fips_allowed
) ||
3701 (j
>= 0 && !alg_test_descs
[j
].fips_allowed
)))
3706 rc
|= alg_test_descs
[i
].test(alg_test_descs
+ i
, driver
,
3708 if (j
>= 0 && j
!= i
)
3709 rc
|= alg_test_descs
[j
].test(alg_test_descs
+ j
, driver
,
3713 if (fips_enabled
&& rc
)
3714 panic("%s: %s alg self test failed in fips mode!\n", driver
, alg
);
3716 if (fips_enabled
&& !rc
)
3717 pr_info(KERN_INFO
"alg: self-tests for %s (%s) passed\n",
3723 printk(KERN_INFO
"alg: No test for %s (%s)\n", alg
, driver
);
3729 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3731 EXPORT_SYMBOL_GPL(alg_test
);