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 pcomp_test_suite {
101 struct pcomp_testvec *vecs;
106 struct hash_test_suite {
107 struct hash_testvec *vecs;
111 struct cprng_test_suite {
112 struct cprng_testvec *vecs;
116 struct drbg_test_suite {
117 struct drbg_testvec *vecs;
121 struct akcipher_test_suite {
122 struct akcipher_testvec *vecs;
126 struct alg_test_desc {
128 int (*test)(const struct alg_test_desc *desc, const char *driver,
130 int fips_allowed; /* set if alg is allowed in fips mode */
133 struct aead_test_suite aead;
134 struct cipher_test_suite cipher;
135 struct comp_test_suite comp;
136 struct pcomp_test_suite pcomp;
137 struct hash_test_suite hash;
138 struct cprng_test_suite cprng;
139 struct drbg_test_suite drbg;
140 struct akcipher_test_suite akcipher;
144 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
146 static void hexdump(unsigned char *buf, unsigned int len)
148 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
153 static void tcrypt_complete(struct crypto_async_request *req, int err)
155 struct tcrypt_result *res = req->data;
157 if (err == -EINPROGRESS)
161 complete(&res->completion);
164 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
168 for (i = 0; i < XBUFSIZE; i++) {
169 buf[i] = (void *)__get_free_page(GFP_KERNEL);
178 free_page((unsigned long)buf[i]);
183 static void testmgr_free_buf(char *buf[XBUFSIZE])
187 for (i = 0; i < XBUFSIZE; i++)
188 free_page((unsigned long)buf[i]);
191 static int wait_async_op(struct tcrypt_result *tr, int ret)
193 if (ret == -EINPROGRESS || ret == -EBUSY) {
194 wait_for_completion(&tr->completion);
195 reinit_completion(&tr->completion);
201 static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
202 unsigned int tcount, bool use_digest,
203 const int align_offset)
205 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
206 unsigned int i, j, k, temp;
207 struct scatterlist sg[8];
210 struct ahash_request *req;
211 struct tcrypt_result tresult;
213 char *xbuf[XBUFSIZE];
216 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
219 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
222 if (testmgr_alloc_buf(xbuf))
225 init_completion(&tresult.completion);
227 req = ahash_request_alloc(tfm, GFP_KERNEL);
229 printk(KERN_ERR "alg: hash: Failed to allocate request for "
233 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
234 tcrypt_complete, &tresult);
237 for (i = 0; i < tcount; i++) {
242 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
246 memset(result, 0, MAX_DIGEST_SIZE);
249 hash_buff += align_offset;
251 memcpy(hash_buff, template[i].plaintext, template[i].psize);
252 sg_init_one(&sg[0], hash_buff, template[i].psize);
254 if (template[i].ksize) {
255 crypto_ahash_clear_flags(tfm, ~0);
256 if (template[i].ksize > MAX_KEYLEN) {
257 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
258 j, algo, template[i].ksize, MAX_KEYLEN);
262 memcpy(key, template[i].key, template[i].ksize);
263 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
265 printk(KERN_ERR "alg: hash: setkey failed on "
266 "test %d for %s: ret=%d\n", j, algo,
272 ahash_request_set_crypt(req, sg, result, template[i].psize);
274 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
276 pr_err("alg: hash: digest failed on test %d "
277 "for %s: ret=%d\n", j, algo, -ret);
281 ret = wait_async_op(&tresult, crypto_ahash_init(req));
283 pr_err("alt: hash: init failed on test %d "
284 "for %s: ret=%d\n", j, algo, -ret);
287 ret = wait_async_op(&tresult, crypto_ahash_update(req));
289 pr_err("alt: hash: update failed on test %d "
290 "for %s: ret=%d\n", j, algo, -ret);
293 ret = wait_async_op(&tresult, crypto_ahash_final(req));
295 pr_err("alt: hash: final failed on test %d "
296 "for %s: ret=%d\n", j, algo, -ret);
301 if (memcmp(result, template[i].digest,
302 crypto_ahash_digestsize(tfm))) {
303 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
305 hexdump(result, crypto_ahash_digestsize(tfm));
312 for (i = 0; i < tcount; i++) {
313 /* alignment tests are only done with continuous buffers */
314 if (align_offset != 0)
321 memset(result, 0, MAX_DIGEST_SIZE);
324 sg_init_table(sg, template[i].np);
326 for (k = 0; k < template[i].np; k++) {
327 if (WARN_ON(offset_in_page(IDX[k]) +
328 template[i].tap[k] > PAGE_SIZE))
331 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
332 offset_in_page(IDX[k]),
333 template[i].plaintext + temp,
336 temp += template[i].tap[k];
339 if (template[i].ksize) {
340 if (template[i].ksize > MAX_KEYLEN) {
341 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
342 j, algo, template[i].ksize, MAX_KEYLEN);
346 crypto_ahash_clear_flags(tfm, ~0);
347 memcpy(key, template[i].key, template[i].ksize);
348 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
351 printk(KERN_ERR "alg: hash: setkey "
352 "failed on chunking test %d "
353 "for %s: ret=%d\n", j, algo, -ret);
358 ahash_request_set_crypt(req, sg, result, template[i].psize);
359 ret = crypto_ahash_digest(req);
365 wait_for_completion(&tresult.completion);
366 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));
391 ahash_request_free(req);
393 testmgr_free_buf(xbuf);
400 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
401 unsigned int tcount, bool use_digest)
403 unsigned int alignmask;
406 ret = __test_hash(tfm, template, tcount, use_digest, 0);
410 /* test unaligned buffers, check with one byte offset */
411 ret = __test_hash(tfm, template, tcount, use_digest, 1);
415 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
417 /* Check if alignment mask for tfm is correctly set. */
418 ret = __test_hash(tfm, template, tcount, use_digest,
427 static int __test_aead(struct crypto_aead *tfm, int enc,
428 struct aead_testvec *template, unsigned int tcount,
429 const bool diff_dst, const int align_offset)
431 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
432 unsigned int i, j, k, n, temp;
436 struct aead_request *req;
437 struct scatterlist *sg;
438 struct scatterlist *sgout;
440 struct tcrypt_result result;
441 unsigned int authsize, iv_len;
446 char *xbuf[XBUFSIZE];
447 char *xoutbuf[XBUFSIZE];
448 char *axbuf[XBUFSIZE];
450 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
453 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
456 if (testmgr_alloc_buf(xbuf))
458 if (testmgr_alloc_buf(axbuf))
460 if (diff_dst && testmgr_alloc_buf(xoutbuf))
463 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
464 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 4 : 2), GFP_KERNEL);
479 init_completion(&result.completion);
481 req = aead_request_alloc(tfm, GFP_KERNEL);
483 pr_err("alg: aead%s: Failed to allocate request for %s\n",
488 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
489 tcrypt_complete, &result);
491 for (i = 0, j = 0; i < tcount; i++) {
497 /* some templates have no input data but they will
501 input += align_offset;
505 if (WARN_ON(align_offset + template[i].ilen >
506 PAGE_SIZE || template[i].alen > PAGE_SIZE))
509 memcpy(input, template[i].input, template[i].ilen);
510 memcpy(assoc, template[i].assoc, template[i].alen);
511 iv_len = crypto_aead_ivsize(tfm);
513 memcpy(iv, template[i].iv, iv_len);
515 memset(iv, 0, iv_len);
517 crypto_aead_clear_flags(tfm, ~0);
519 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
521 if (template[i].klen > MAX_KEYLEN) {
522 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
523 d, j, algo, template[i].klen,
528 memcpy(key, template[i].key, template[i].klen);
530 ret = crypto_aead_setkey(tfm, key, template[i].klen);
531 if (!ret == template[i].fail) {
532 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
533 d, j, algo, crypto_aead_get_flags(tfm));
538 authsize = abs(template[i].rlen - template[i].ilen);
539 ret = crypto_aead_setauthsize(tfm, authsize);
541 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
542 d, authsize, j, algo);
546 k = !!template[i].alen;
547 sg_init_table(sg, k + 1);
548 sg_set_buf(&sg[0], assoc, template[i].alen);
549 sg_set_buf(&sg[k], input,
550 template[i].ilen + (enc ? authsize : 0));
554 sg_init_table(sgout, k + 1);
555 sg_set_buf(&sgout[0], assoc, template[i].alen);
558 output += align_offset;
559 sg_set_buf(&sgout[k], output,
560 template[i].rlen + (enc ? 0 : authsize));
563 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
564 template[i].ilen, iv);
566 aead_request_set_ad(req, template[i].alen);
568 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
572 if (template[i].novrfy) {
573 /* verification was supposed to fail */
574 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
576 /* so really, we got a bad message */
583 wait_for_completion(&result.completion);
584 reinit_completion(&result.completion);
589 if (template[i].novrfy)
590 /* verification failure was expected */
594 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
595 d, e, j, algo, -ret);
600 if (memcmp(q, template[i].result, template[i].rlen)) {
601 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
603 hexdump(q, template[i].rlen);
609 for (i = 0, j = 0; i < tcount; i++) {
610 /* alignment tests are only done with continuous buffers */
611 if (align_offset != 0)
620 memcpy(iv, template[i].iv, MAX_IVLEN);
622 memset(iv, 0, MAX_IVLEN);
624 crypto_aead_clear_flags(tfm, ~0);
626 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
627 if (template[i].klen > MAX_KEYLEN) {
628 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
629 d, j, algo, template[i].klen, MAX_KEYLEN);
633 memcpy(key, template[i].key, template[i].klen);
635 ret = crypto_aead_setkey(tfm, key, template[i].klen);
636 if (!ret == template[i].fail) {
637 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
638 d, j, algo, crypto_aead_get_flags(tfm));
643 authsize = abs(template[i].rlen - template[i].ilen);
646 sg_init_table(sg, template[i].anp + template[i].np);
648 sg_init_table(sgout, template[i].anp + template[i].np);
651 for (k = 0, temp = 0; k < template[i].anp; k++) {
652 if (WARN_ON(offset_in_page(IDX[k]) +
653 template[i].atap[k] > PAGE_SIZE))
656 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
657 offset_in_page(IDX[k]),
658 template[i].assoc + temp,
659 template[i].atap[k]),
660 template[i].atap[k]);
662 sg_set_buf(&sgout[k],
663 axbuf[IDX[k] >> PAGE_SHIFT] +
664 offset_in_page(IDX[k]),
665 template[i].atap[k]);
666 temp += template[i].atap[k];
669 for (k = 0, temp = 0; k < template[i].np; k++) {
670 if (WARN_ON(offset_in_page(IDX[k]) +
671 template[i].tap[k] > PAGE_SIZE))
674 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
675 memcpy(q, template[i].input + temp, template[i].tap[k]);
676 sg_set_buf(&sg[template[i].anp + k],
677 q, template[i].tap[k]);
680 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
681 offset_in_page(IDX[k]);
683 memset(q, 0, template[i].tap[k]);
685 sg_set_buf(&sgout[template[i].anp + k],
686 q, template[i].tap[k]);
689 n = template[i].tap[k];
690 if (k == template[i].np - 1 && enc)
692 if (offset_in_page(q) + n < PAGE_SIZE)
695 temp += template[i].tap[k];
698 ret = crypto_aead_setauthsize(tfm, authsize);
700 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
701 d, authsize, j, algo);
706 if (WARN_ON(sg[template[i].anp + k - 1].offset +
707 sg[template[i].anp + k - 1].length +
708 authsize > PAGE_SIZE)) {
714 sgout[template[i].anp + k - 1].length +=
716 sg[template[i].anp + k - 1].length += authsize;
719 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
723 aead_request_set_ad(req, template[i].alen);
725 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
729 if (template[i].novrfy) {
730 /* verification was supposed to fail */
731 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
733 /* so really, we got a bad message */
740 wait_for_completion(&result.completion);
741 reinit_completion(&result.completion);
746 if (template[i].novrfy)
747 /* verification failure was expected */
751 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
752 d, e, j, algo, -ret);
757 for (k = 0, temp = 0; k < template[i].np; k++) {
759 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
760 offset_in_page(IDX[k]);
762 q = xbuf[IDX[k] >> PAGE_SHIFT] +
763 offset_in_page(IDX[k]);
765 n = template[i].tap[k];
766 if (k == template[i].np - 1)
767 n += enc ? authsize : -authsize;
769 if (memcmp(q, template[i].result + temp, n)) {
770 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
777 if (k == template[i].np - 1 && !enc) {
779 memcmp(q, template[i].input +
785 for (n = 0; offset_in_page(q + n) && q[n]; n++)
789 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
790 d, j, e, k, algo, n);
795 temp += template[i].tap[k];
802 aead_request_free(req);
806 testmgr_free_buf(xoutbuf);
808 testmgr_free_buf(axbuf);
810 testmgr_free_buf(xbuf);
817 static int test_aead(struct crypto_aead *tfm, int enc,
818 struct aead_testvec *template, unsigned int tcount)
820 unsigned int alignmask;
823 /* test 'dst == src' case */
824 ret = __test_aead(tfm, enc, template, tcount, false, 0);
828 /* test 'dst != src' case */
829 ret = __test_aead(tfm, enc, template, tcount, true, 0);
833 /* test unaligned buffers, check with one byte offset */
834 ret = __test_aead(tfm, enc, template, tcount, true, 1);
838 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
840 /* Check if alignment mask for tfm is correctly set. */
841 ret = __test_aead(tfm, enc, template, tcount, true,
850 static int test_cipher(struct crypto_cipher *tfm, int enc,
851 struct cipher_testvec *template, unsigned int tcount)
853 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
854 unsigned int i, j, k;
858 char *xbuf[XBUFSIZE];
861 if (testmgr_alloc_buf(xbuf))
870 for (i = 0; i < tcount; i++) {
877 if (WARN_ON(template[i].ilen > PAGE_SIZE))
881 memcpy(data, template[i].input, template[i].ilen);
883 crypto_cipher_clear_flags(tfm, ~0);
885 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
887 ret = crypto_cipher_setkey(tfm, template[i].key,
889 if (!ret == template[i].fail) {
890 printk(KERN_ERR "alg: cipher: setkey failed "
891 "on test %d for %s: flags=%x\n", j,
892 algo, crypto_cipher_get_flags(tfm));
897 for (k = 0; k < template[i].ilen;
898 k += crypto_cipher_blocksize(tfm)) {
900 crypto_cipher_encrypt_one(tfm, data + k,
903 crypto_cipher_decrypt_one(tfm, data + k,
908 if (memcmp(q, template[i].result, template[i].rlen)) {
909 printk(KERN_ERR "alg: cipher: Test %d failed "
910 "on %s for %s\n", j, e, algo);
911 hexdump(q, template[i].rlen);
920 testmgr_free_buf(xbuf);
925 static int __test_skcipher(struct crypto_skcipher *tfm, int enc,
926 struct cipher_testvec *template, unsigned int tcount,
927 const bool diff_dst, const int align_offset)
930 crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
931 unsigned int i, j, k, n, temp;
933 struct skcipher_request *req;
934 struct scatterlist sg[8];
935 struct scatterlist sgout[8];
937 struct tcrypt_result result;
940 char *xbuf[XBUFSIZE];
941 char *xoutbuf[XBUFSIZE];
943 unsigned int ivsize = crypto_skcipher_ivsize(tfm);
945 if (testmgr_alloc_buf(xbuf))
948 if (diff_dst && testmgr_alloc_buf(xoutbuf))
961 init_completion(&result.completion);
963 req = skcipher_request_alloc(tfm, GFP_KERNEL);
965 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
970 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
971 tcrypt_complete, &result);
974 for (i = 0; i < tcount; i++) {
975 if (template[i].np && !template[i].also_non_np)
979 memcpy(iv, template[i].iv, ivsize);
981 memset(iv, 0, MAX_IVLEN);
985 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
989 data += align_offset;
990 memcpy(data, template[i].input, template[i].ilen);
992 crypto_skcipher_clear_flags(tfm, ~0);
994 crypto_skcipher_set_flags(tfm,
995 CRYPTO_TFM_REQ_WEAK_KEY);
997 ret = crypto_skcipher_setkey(tfm, template[i].key,
999 if (!ret == template[i].fail) {
1000 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
1001 d, j, algo, crypto_skcipher_get_flags(tfm));
1006 sg_init_one(&sg[0], data, template[i].ilen);
1009 data += align_offset;
1010 sg_init_one(&sgout[0], data, template[i].ilen);
1013 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1014 template[i].ilen, iv);
1015 ret = enc ? crypto_skcipher_encrypt(req) :
1016 crypto_skcipher_decrypt(req);
1023 wait_for_completion(&result.completion);
1024 reinit_completion(&result.completion);
1030 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1031 d, e, j, algo, -ret);
1036 if (memcmp(q, template[i].result, template[i].rlen)) {
1037 pr_err("alg: skcipher%s: Test %d failed (invalid result) on %s for %s\n",
1039 hexdump(q, template[i].rlen);
1044 if (template[i].iv_out &&
1045 memcmp(iv, template[i].iv_out,
1046 crypto_skcipher_ivsize(tfm))) {
1047 pr_err("alg: skcipher%s: Test %d failed (invalid output IV) on %s for %s\n",
1049 hexdump(iv, crypto_skcipher_ivsize(tfm));
1056 for (i = 0; i < tcount; i++) {
1057 /* alignment tests are only done with continuous buffers */
1058 if (align_offset != 0)
1061 if (!template[i].np)
1065 memcpy(iv, template[i].iv, ivsize);
1067 memset(iv, 0, MAX_IVLEN);
1070 crypto_skcipher_clear_flags(tfm, ~0);
1072 crypto_skcipher_set_flags(tfm,
1073 CRYPTO_TFM_REQ_WEAK_KEY);
1075 ret = crypto_skcipher_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",
1079 d, j, algo, crypto_skcipher_get_flags(tfm));
1086 sg_init_table(sg, template[i].np);
1088 sg_init_table(sgout, template[i].np);
1089 for (k = 0; k < template[i].np; k++) {
1090 if (WARN_ON(offset_in_page(IDX[k]) +
1091 template[i].tap[k] > PAGE_SIZE))
1094 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1096 memcpy(q, template[i].input + temp, template[i].tap[k]);
1098 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1099 q[template[i].tap[k]] = 0;
1101 sg_set_buf(&sg[k], q, template[i].tap[k]);
1103 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1104 offset_in_page(IDX[k]);
1106 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1108 memset(q, 0, template[i].tap[k]);
1109 if (offset_in_page(q) +
1110 template[i].tap[k] < PAGE_SIZE)
1111 q[template[i].tap[k]] = 0;
1114 temp += template[i].tap[k];
1117 skcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1118 template[i].ilen, iv);
1120 ret = enc ? crypto_skcipher_encrypt(req) :
1121 crypto_skcipher_decrypt(req);
1128 wait_for_completion(&result.completion);
1129 reinit_completion(&result.completion);
1135 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1136 d, e, j, algo, -ret);
1142 for (k = 0; k < template[i].np; k++) {
1144 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1145 offset_in_page(IDX[k]);
1147 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1148 offset_in_page(IDX[k]);
1150 if (memcmp(q, template[i].result + temp,
1151 template[i].tap[k])) {
1152 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1154 hexdump(q, template[i].tap[k]);
1158 q += template[i].tap[k];
1159 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1162 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1163 d, j, e, k, algo, n);
1167 temp += template[i].tap[k];
1174 skcipher_request_free(req);
1176 testmgr_free_buf(xoutbuf);
1178 testmgr_free_buf(xbuf);
1183 static int test_skcipher(struct crypto_skcipher *tfm, int enc,
1184 struct cipher_testvec *template, unsigned int tcount)
1186 unsigned int alignmask;
1189 /* test 'dst == src' case */
1190 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
1194 /* test 'dst != src' case */
1195 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1199 /* test unaligned buffers, check with one byte offset */
1200 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1204 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1206 /* Check if alignment mask for tfm is correctly set. */
1207 ret = __test_skcipher(tfm, enc, template, tcount, true,
1216 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1217 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1219 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1221 char result[COMP_BUF_SIZE];
1224 for (i = 0; i < ctcount; i++) {
1226 unsigned int dlen = COMP_BUF_SIZE;
1228 memset(result, 0, sizeof (result));
1230 ilen = ctemplate[i].inlen;
1231 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1232 ilen, result, &dlen);
1234 printk(KERN_ERR "alg: comp: compression failed "
1235 "on test %d for %s: ret=%d\n", i + 1, algo,
1240 if (dlen != ctemplate[i].outlen) {
1241 printk(KERN_ERR "alg: comp: Compression test %d "
1242 "failed for %s: output len = %d\n", i + 1, algo,
1248 if (memcmp(result, ctemplate[i].output, dlen)) {
1249 printk(KERN_ERR "alg: comp: Compression test %d "
1250 "failed for %s\n", i + 1, algo);
1251 hexdump(result, dlen);
1257 for (i = 0; i < dtcount; i++) {
1259 unsigned int dlen = COMP_BUF_SIZE;
1261 memset(result, 0, sizeof (result));
1263 ilen = dtemplate[i].inlen;
1264 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1265 ilen, result, &dlen);
1267 printk(KERN_ERR "alg: comp: decompression failed "
1268 "on test %d for %s: ret=%d\n", i + 1, algo,
1273 if (dlen != dtemplate[i].outlen) {
1274 printk(KERN_ERR "alg: comp: Decompression test %d "
1275 "failed for %s: output len = %d\n", i + 1, algo,
1281 if (memcmp(result, dtemplate[i].output, dlen)) {
1282 printk(KERN_ERR "alg: comp: Decompression test %d "
1283 "failed for %s\n", i + 1, algo);
1284 hexdump(result, dlen);
1296 static int test_pcomp(struct crypto_pcomp *tfm,
1297 struct pcomp_testvec *ctemplate,
1298 struct pcomp_testvec *dtemplate, int ctcount,
1301 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1303 char result[COMP_BUF_SIZE];
1306 for (i = 0; i < ctcount; i++) {
1307 struct comp_request req;
1308 unsigned int produced = 0;
1310 res = crypto_compress_setup(tfm, ctemplate[i].params,
1311 ctemplate[i].paramsize);
1313 pr_err("alg: pcomp: compression setup failed on test "
1314 "%d for %s: error=%d\n", i + 1, algo, res);
1318 res = crypto_compress_init(tfm);
1320 pr_err("alg: pcomp: compression init failed on test "
1321 "%d for %s: error=%d\n", i + 1, algo, res);
1325 memset(result, 0, sizeof(result));
1327 req.next_in = ctemplate[i].input;
1328 req.avail_in = ctemplate[i].inlen / 2;
1329 req.next_out = result;
1330 req.avail_out = ctemplate[i].outlen / 2;
1332 res = crypto_compress_update(tfm, &req);
1333 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1334 pr_err("alg: pcomp: compression update failed on test "
1335 "%d for %s: error=%d\n", i + 1, algo, res);
1341 /* Add remaining input data */
1342 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1344 res = crypto_compress_update(tfm, &req);
1345 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1346 pr_err("alg: pcomp: compression update failed on test "
1347 "%d for %s: error=%d\n", i + 1, algo, res);
1353 /* Provide remaining output space */
1354 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1356 res = crypto_compress_final(tfm, &req);
1358 pr_err("alg: pcomp: compression final failed on test "
1359 "%d for %s: error=%d\n", i + 1, algo, res);
1364 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1365 pr_err("alg: comp: Compression test %d failed for %s: "
1366 "output len = %d (expected %d)\n", i + 1, algo,
1367 COMP_BUF_SIZE - req.avail_out,
1368 ctemplate[i].outlen);
1372 if (produced != ctemplate[i].outlen) {
1373 pr_err("alg: comp: Compression test %d failed for %s: "
1374 "returned len = %u (expected %d)\n", i + 1,
1375 algo, produced, ctemplate[i].outlen);
1379 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1380 pr_err("alg: pcomp: Compression test %d failed for "
1381 "%s\n", i + 1, algo);
1382 hexdump(result, ctemplate[i].outlen);
1387 for (i = 0; i < dtcount; i++) {
1388 struct comp_request req;
1389 unsigned int produced = 0;
1391 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1392 dtemplate[i].paramsize);
1394 pr_err("alg: pcomp: decompression setup failed on "
1395 "test %d for %s: error=%d\n", i + 1, algo, res);
1399 res = crypto_decompress_init(tfm);
1401 pr_err("alg: pcomp: decompression init failed on test "
1402 "%d for %s: error=%d\n", i + 1, algo, res);
1406 memset(result, 0, sizeof(result));
1408 req.next_in = dtemplate[i].input;
1409 req.avail_in = dtemplate[i].inlen / 2;
1410 req.next_out = result;
1411 req.avail_out = dtemplate[i].outlen / 2;
1413 res = crypto_decompress_update(tfm, &req);
1414 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1415 pr_err("alg: pcomp: decompression update failed on "
1416 "test %d for %s: error=%d\n", i + 1, algo, res);
1422 /* Add remaining input data */
1423 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1425 res = crypto_decompress_update(tfm, &req);
1426 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1427 pr_err("alg: pcomp: decompression update failed on "
1428 "test %d for %s: error=%d\n", i + 1, algo, res);
1434 /* Provide remaining output space */
1435 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1437 res = crypto_decompress_final(tfm, &req);
1438 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1439 pr_err("alg: pcomp: decompression final failed on "
1440 "test %d for %s: error=%d\n", i + 1, algo, res);
1446 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1447 pr_err("alg: comp: Decompression test %d failed for "
1448 "%s: output len = %d (expected %d)\n", i + 1,
1449 algo, COMP_BUF_SIZE - req.avail_out,
1450 dtemplate[i].outlen);
1454 if (produced != dtemplate[i].outlen) {
1455 pr_err("alg: comp: Decompression test %d failed for "
1456 "%s: returned len = %u (expected %d)\n", i + 1,
1457 algo, produced, dtemplate[i].outlen);
1461 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1462 pr_err("alg: pcomp: Decompression test %d failed for "
1463 "%s\n", i + 1, algo);
1464 hexdump(result, dtemplate[i].outlen);
1473 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1474 unsigned int tcount)
1476 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1477 int err = 0, i, j, seedsize;
1481 seedsize = crypto_rng_seedsize(tfm);
1483 seed = kmalloc(seedsize, GFP_KERNEL);
1485 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1490 for (i = 0; i < tcount; i++) {
1491 memset(result, 0, 32);
1493 memcpy(seed, template[i].v, template[i].vlen);
1494 memcpy(seed + template[i].vlen, template[i].key,
1496 memcpy(seed + template[i].vlen + template[i].klen,
1497 template[i].dt, template[i].dtlen);
1499 err = crypto_rng_reset(tfm, seed, seedsize);
1501 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1506 for (j = 0; j < template[i].loops; j++) {
1507 err = crypto_rng_get_bytes(tfm, result,
1510 printk(KERN_ERR "alg: cprng: Failed to obtain "
1511 "the correct amount of random data for "
1512 "%s (requested %d)\n", algo,
1518 err = memcmp(result, template[i].result,
1521 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1523 hexdump(result, template[i].rlen);
1534 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1537 struct crypto_aead *tfm;
1540 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
1542 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1543 "%ld\n", driver, PTR_ERR(tfm));
1544 return PTR_ERR(tfm);
1547 if (desc->suite.aead.enc.vecs) {
1548 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1549 desc->suite.aead.enc.count);
1554 if (!err && desc->suite.aead.dec.vecs)
1555 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1556 desc->suite.aead.dec.count);
1559 crypto_free_aead(tfm);
1563 static int alg_test_cipher(const struct alg_test_desc *desc,
1564 const char *driver, u32 type, u32 mask)
1566 struct crypto_cipher *tfm;
1569 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1571 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1572 "%s: %ld\n", driver, PTR_ERR(tfm));
1573 return PTR_ERR(tfm);
1576 if (desc->suite.cipher.enc.vecs) {
1577 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1578 desc->suite.cipher.enc.count);
1583 if (desc->suite.cipher.dec.vecs)
1584 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1585 desc->suite.cipher.dec.count);
1588 crypto_free_cipher(tfm);
1592 static int alg_test_skcipher(const struct alg_test_desc *desc,
1593 const char *driver, u32 type, u32 mask)
1595 struct crypto_skcipher *tfm;
1598 tfm = crypto_alloc_skcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1600 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1601 "%s: %ld\n", driver, PTR_ERR(tfm));
1602 return PTR_ERR(tfm);
1605 if (desc->suite.cipher.enc.vecs) {
1606 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1607 desc->suite.cipher.enc.count);
1612 if (desc->suite.cipher.dec.vecs)
1613 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1614 desc->suite.cipher.dec.count);
1617 crypto_free_skcipher(tfm);
1621 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1624 struct crypto_comp *tfm;
1627 tfm = crypto_alloc_comp(driver, type, mask);
1629 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1630 "%ld\n", driver, PTR_ERR(tfm));
1631 return PTR_ERR(tfm);
1634 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1635 desc->suite.comp.decomp.vecs,
1636 desc->suite.comp.comp.count,
1637 desc->suite.comp.decomp.count);
1639 crypto_free_comp(tfm);
1643 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1646 struct crypto_pcomp *tfm;
1649 tfm = crypto_alloc_pcomp(driver, type, mask);
1651 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1652 driver, PTR_ERR(tfm));
1653 return PTR_ERR(tfm);
1656 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1657 desc->suite.pcomp.decomp.vecs,
1658 desc->suite.pcomp.comp.count,
1659 desc->suite.pcomp.decomp.count);
1661 crypto_free_pcomp(tfm);
1665 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1668 struct crypto_ahash *tfm;
1671 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
1673 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1674 "%ld\n", driver, PTR_ERR(tfm));
1675 return PTR_ERR(tfm);
1678 err = test_hash(tfm, desc->suite.hash.vecs,
1679 desc->suite.hash.count, true);
1681 err = test_hash(tfm, desc->suite.hash.vecs,
1682 desc->suite.hash.count, false);
1684 crypto_free_ahash(tfm);
1688 static int alg_test_crc32c(const struct alg_test_desc *desc,
1689 const char *driver, u32 type, u32 mask)
1691 struct crypto_shash *tfm;
1695 err = alg_test_hash(desc, driver, type, mask);
1699 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
1701 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1702 "%ld\n", driver, PTR_ERR(tfm));
1708 SHASH_DESC_ON_STACK(shash, tfm);
1709 u32 *ctx = (u32 *)shash_desc_ctx(shash);
1714 *ctx = le32_to_cpu(420553207);
1715 err = crypto_shash_final(shash, (u8 *)&val);
1717 printk(KERN_ERR "alg: crc32c: Operation failed for "
1718 "%s: %d\n", driver, err);
1722 if (val != ~420553207) {
1723 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1724 "%d\n", driver, val);
1729 crypto_free_shash(tfm);
1735 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1738 struct crypto_rng *rng;
1741 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
1743 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1744 "%ld\n", driver, PTR_ERR(rng));
1745 return PTR_ERR(rng);
1748 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1750 crypto_free_rng(rng);
1756 static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1757 const char *driver, u32 type, u32 mask)
1760 struct crypto_rng *drng;
1761 struct drbg_test_data test_data;
1762 struct drbg_string addtl, pers, testentropy;
1763 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1768 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
1770 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
1776 test_data.testentropy = &testentropy;
1777 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1778 drbg_string_fill(&pers, test->pers, test->perslen);
1779 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1781 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1785 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1787 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1788 ret = crypto_drbg_get_bytes_addtl_test(drng,
1789 buf, test->expectedlen, &addtl, &test_data);
1791 ret = crypto_drbg_get_bytes_addtl(drng,
1792 buf, test->expectedlen, &addtl);
1795 printk(KERN_ERR "alg: drbg: could not obtain random data for "
1796 "driver %s\n", driver);
1800 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1802 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1803 ret = crypto_drbg_get_bytes_addtl_test(drng,
1804 buf, test->expectedlen, &addtl, &test_data);
1806 ret = crypto_drbg_get_bytes_addtl(drng,
1807 buf, test->expectedlen, &addtl);
1810 printk(KERN_ERR "alg: drbg: could not obtain random data for "
1811 "driver %s\n", driver);
1815 ret = memcmp(test->expected, buf, test->expectedlen);
1818 crypto_free_rng(drng);
1824 static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1830 struct drbg_testvec *template = desc->suite.drbg.vecs;
1831 unsigned int tcount = desc->suite.drbg.count;
1833 if (0 == memcmp(driver, "drbg_pr_", 8))
1836 for (i = 0; i < tcount; i++) {
1837 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1839 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1849 static int do_test_rsa(struct crypto_akcipher *tfm,
1850 struct akcipher_testvec *vecs)
1852 char *xbuf[XBUFSIZE];
1853 struct akcipher_request *req;
1854 void *outbuf_enc = NULL;
1855 void *outbuf_dec = NULL;
1856 struct tcrypt_result result;
1857 unsigned int out_len_max, out_len = 0;
1859 struct scatterlist src, dst, src_tab[2];
1861 if (testmgr_alloc_buf(xbuf))
1864 req = akcipher_request_alloc(tfm, GFP_KERNEL);
1868 init_completion(&result.completion);
1870 if (vecs->public_key_vec)
1871 err = crypto_akcipher_set_pub_key(tfm, vecs->key,
1874 err = crypto_akcipher_set_priv_key(tfm, vecs->key,
1879 out_len_max = crypto_akcipher_maxsize(tfm);
1880 outbuf_enc = kzalloc(out_len_max, GFP_KERNEL);
1884 if (WARN_ON(vecs->m_size > PAGE_SIZE))
1887 memcpy(xbuf[0], vecs->m, vecs->m_size);
1889 sg_init_table(src_tab, 2);
1890 sg_set_buf(&src_tab[0], xbuf[0], 8);
1891 sg_set_buf(&src_tab[1], xbuf[0] + 8, vecs->m_size - 8);
1892 sg_init_one(&dst, outbuf_enc, out_len_max);
1893 akcipher_request_set_crypt(req, src_tab, &dst, vecs->m_size,
1895 akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1896 tcrypt_complete, &result);
1898 /* Run RSA encrypt - c = m^e mod n;*/
1899 err = wait_async_op(&result, crypto_akcipher_encrypt(req));
1901 pr_err("alg: rsa: encrypt test failed. err %d\n", err);
1904 if (req->dst_len != vecs->c_size) {
1905 pr_err("alg: rsa: encrypt test failed. Invalid output len\n");
1909 /* verify that encrypted message is equal to expected */
1910 if (memcmp(vecs->c, outbuf_enc, vecs->c_size)) {
1911 pr_err("alg: rsa: encrypt test failed. Invalid output\n");
1915 /* Don't invoke decrypt for vectors with public key */
1916 if (vecs->public_key_vec) {
1920 outbuf_dec = kzalloc(out_len_max, GFP_KERNEL);
1926 if (WARN_ON(vecs->c_size > PAGE_SIZE))
1929 memcpy(xbuf[0], vecs->c, vecs->c_size);
1931 sg_init_one(&src, xbuf[0], vecs->c_size);
1932 sg_init_one(&dst, outbuf_dec, out_len_max);
1933 init_completion(&result.completion);
1934 akcipher_request_set_crypt(req, &src, &dst, vecs->c_size, out_len_max);
1936 /* Run RSA decrypt - m = c^d mod n;*/
1937 err = wait_async_op(&result, crypto_akcipher_decrypt(req));
1939 pr_err("alg: rsa: decrypt test failed. err %d\n", err);
1942 out_len = req->dst_len;
1943 if (out_len != vecs->m_size) {
1944 pr_err("alg: rsa: decrypt test failed. Invalid output len\n");
1948 /* verify that decrypted message is equal to the original msg */
1949 if (memcmp(vecs->m, outbuf_dec, vecs->m_size)) {
1950 pr_err("alg: rsa: decrypt test failed. Invalid output\n");
1957 akcipher_request_free(req);
1959 testmgr_free_buf(xbuf);
1963 static int test_rsa(struct crypto_akcipher *tfm, struct akcipher_testvec *vecs,
1964 unsigned int tcount)
1968 for (i = 0; i < tcount; i++) {
1969 ret = do_test_rsa(tfm, vecs++);
1971 pr_err("alg: rsa: test failed on vector %d, err=%d\n",
1979 static int test_akcipher(struct crypto_akcipher *tfm, const char *alg,
1980 struct akcipher_testvec *vecs, unsigned int tcount)
1982 if (strncmp(alg, "rsa", 3) == 0)
1983 return test_rsa(tfm, vecs, tcount);
1988 static int alg_test_akcipher(const struct alg_test_desc *desc,
1989 const char *driver, u32 type, u32 mask)
1991 struct crypto_akcipher *tfm;
1994 tfm = crypto_alloc_akcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1996 pr_err("alg: akcipher: Failed to load tfm for %s: %ld\n",
1997 driver, PTR_ERR(tfm));
1998 return PTR_ERR(tfm);
2000 if (desc->suite.akcipher.vecs)
2001 err = test_akcipher(tfm, desc->alg, desc->suite.akcipher.vecs,
2002 desc->suite.akcipher.count);
2004 crypto_free_akcipher(tfm);
2008 static int alg_test_null(const struct alg_test_desc *desc,
2009 const char *driver, u32 type, u32 mask)
2014 /* Please keep this list sorted by algorithm name. */
2015 static const struct alg_test_desc alg_test_descs[] = {
2017 .alg = "__cbc-cast5-avx",
2018 .test = alg_test_null,
2020 .alg = "__cbc-cast6-avx",
2021 .test = alg_test_null,
2023 .alg = "__cbc-serpent-avx",
2024 .test = alg_test_null,
2026 .alg = "__cbc-serpent-avx2",
2027 .test = alg_test_null,
2029 .alg = "__cbc-serpent-sse2",
2030 .test = alg_test_null,
2032 .alg = "__cbc-twofish-avx",
2033 .test = alg_test_null,
2035 .alg = "__driver-cbc-aes-aesni",
2036 .test = alg_test_null,
2039 .alg = "__driver-cbc-camellia-aesni",
2040 .test = alg_test_null,
2042 .alg = "__driver-cbc-camellia-aesni-avx2",
2043 .test = alg_test_null,
2045 .alg = "__driver-cbc-cast5-avx",
2046 .test = alg_test_null,
2048 .alg = "__driver-cbc-cast6-avx",
2049 .test = alg_test_null,
2051 .alg = "__driver-cbc-serpent-avx",
2052 .test = alg_test_null,
2054 .alg = "__driver-cbc-serpent-avx2",
2055 .test = alg_test_null,
2057 .alg = "__driver-cbc-serpent-sse2",
2058 .test = alg_test_null,
2060 .alg = "__driver-cbc-twofish-avx",
2061 .test = alg_test_null,
2063 .alg = "__driver-ecb-aes-aesni",
2064 .test = alg_test_null,
2067 .alg = "__driver-ecb-camellia-aesni",
2068 .test = alg_test_null,
2070 .alg = "__driver-ecb-camellia-aesni-avx2",
2071 .test = alg_test_null,
2073 .alg = "__driver-ecb-cast5-avx",
2074 .test = alg_test_null,
2076 .alg = "__driver-ecb-cast6-avx",
2077 .test = alg_test_null,
2079 .alg = "__driver-ecb-serpent-avx",
2080 .test = alg_test_null,
2082 .alg = "__driver-ecb-serpent-avx2",
2083 .test = alg_test_null,
2085 .alg = "__driver-ecb-serpent-sse2",
2086 .test = alg_test_null,
2088 .alg = "__driver-ecb-twofish-avx",
2089 .test = alg_test_null,
2091 .alg = "__driver-gcm-aes-aesni",
2092 .test = alg_test_null,
2095 .alg = "__ghash-pclmulqdqni",
2096 .test = alg_test_null,
2099 .alg = "ansi_cprng",
2100 .test = alg_test_cprng,
2104 .vecs = ansi_cprng_aes_tv_template,
2105 .count = ANSI_CPRNG_AES_TEST_VECTORS
2109 .alg = "authenc(hmac(md5),ecb(cipher_null))",
2110 .test = alg_test_aead,
2114 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
2115 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
2118 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
2119 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
2124 .alg = "authenc(hmac(sha1),cbc(aes))",
2125 .test = alg_test_aead,
2130 hmac_sha1_aes_cbc_enc_tv_temp,
2132 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
2137 .alg = "authenc(hmac(sha1),cbc(des))",
2138 .test = alg_test_aead,
2143 hmac_sha1_des_cbc_enc_tv_temp,
2145 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
2150 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
2151 .test = alg_test_aead,
2156 hmac_sha1_des3_ede_cbc_enc_tv_temp,
2158 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
2163 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
2164 .test = alg_test_aead,
2169 hmac_sha1_ecb_cipher_null_enc_tv_temp,
2171 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
2175 hmac_sha1_ecb_cipher_null_dec_tv_temp,
2177 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
2182 .alg = "authenc(hmac(sha224),cbc(des))",
2183 .test = alg_test_aead,
2188 hmac_sha224_des_cbc_enc_tv_temp,
2190 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2195 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2196 .test = alg_test_aead,
2201 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2203 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2208 .alg = "authenc(hmac(sha256),cbc(aes))",
2209 .test = alg_test_aead,
2214 hmac_sha256_aes_cbc_enc_tv_temp,
2216 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2221 .alg = "authenc(hmac(sha256),cbc(des))",
2222 .test = alg_test_aead,
2227 hmac_sha256_des_cbc_enc_tv_temp,
2229 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2234 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2235 .test = alg_test_aead,
2240 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2242 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2247 .alg = "authenc(hmac(sha384),cbc(des))",
2248 .test = alg_test_aead,
2253 hmac_sha384_des_cbc_enc_tv_temp,
2255 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2260 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2261 .test = alg_test_aead,
2266 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2268 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2273 .alg = "authenc(hmac(sha512),cbc(aes))",
2274 .test = alg_test_aead,
2279 hmac_sha512_aes_cbc_enc_tv_temp,
2281 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2286 .alg = "authenc(hmac(sha512),cbc(des))",
2287 .test = alg_test_aead,
2292 hmac_sha512_des_cbc_enc_tv_temp,
2294 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2299 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2300 .test = alg_test_aead,
2305 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2307 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2313 .test = alg_test_skcipher,
2318 .vecs = aes_cbc_enc_tv_template,
2319 .count = AES_CBC_ENC_TEST_VECTORS
2322 .vecs = aes_cbc_dec_tv_template,
2323 .count = AES_CBC_DEC_TEST_VECTORS
2328 .alg = "cbc(anubis)",
2329 .test = alg_test_skcipher,
2333 .vecs = anubis_cbc_enc_tv_template,
2334 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2337 .vecs = anubis_cbc_dec_tv_template,
2338 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2343 .alg = "cbc(blowfish)",
2344 .test = alg_test_skcipher,
2348 .vecs = bf_cbc_enc_tv_template,
2349 .count = BF_CBC_ENC_TEST_VECTORS
2352 .vecs = bf_cbc_dec_tv_template,
2353 .count = BF_CBC_DEC_TEST_VECTORS
2358 .alg = "cbc(camellia)",
2359 .test = alg_test_skcipher,
2363 .vecs = camellia_cbc_enc_tv_template,
2364 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2367 .vecs = camellia_cbc_dec_tv_template,
2368 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2373 .alg = "cbc(cast5)",
2374 .test = alg_test_skcipher,
2378 .vecs = cast5_cbc_enc_tv_template,
2379 .count = CAST5_CBC_ENC_TEST_VECTORS
2382 .vecs = cast5_cbc_dec_tv_template,
2383 .count = CAST5_CBC_DEC_TEST_VECTORS
2388 .alg = "cbc(cast6)",
2389 .test = alg_test_skcipher,
2393 .vecs = cast6_cbc_enc_tv_template,
2394 .count = CAST6_CBC_ENC_TEST_VECTORS
2397 .vecs = cast6_cbc_dec_tv_template,
2398 .count = CAST6_CBC_DEC_TEST_VECTORS
2404 .test = alg_test_skcipher,
2408 .vecs = des_cbc_enc_tv_template,
2409 .count = DES_CBC_ENC_TEST_VECTORS
2412 .vecs = des_cbc_dec_tv_template,
2413 .count = DES_CBC_DEC_TEST_VECTORS
2418 .alg = "cbc(des3_ede)",
2419 .test = alg_test_skcipher,
2424 .vecs = des3_ede_cbc_enc_tv_template,
2425 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2428 .vecs = des3_ede_cbc_dec_tv_template,
2429 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2434 .alg = "cbc(serpent)",
2435 .test = alg_test_skcipher,
2439 .vecs = serpent_cbc_enc_tv_template,
2440 .count = SERPENT_CBC_ENC_TEST_VECTORS
2443 .vecs = serpent_cbc_dec_tv_template,
2444 .count = SERPENT_CBC_DEC_TEST_VECTORS
2449 .alg = "cbc(twofish)",
2450 .test = alg_test_skcipher,
2454 .vecs = tf_cbc_enc_tv_template,
2455 .count = TF_CBC_ENC_TEST_VECTORS
2458 .vecs = tf_cbc_dec_tv_template,
2459 .count = TF_CBC_DEC_TEST_VECTORS
2465 .test = alg_test_aead,
2470 .vecs = aes_ccm_enc_tv_template,
2471 .count = AES_CCM_ENC_TEST_VECTORS
2474 .vecs = aes_ccm_dec_tv_template,
2475 .count = AES_CCM_DEC_TEST_VECTORS
2481 .test = alg_test_skcipher,
2485 .vecs = chacha20_enc_tv_template,
2486 .count = CHACHA20_ENC_TEST_VECTORS
2489 .vecs = chacha20_enc_tv_template,
2490 .count = CHACHA20_ENC_TEST_VECTORS
2497 .test = alg_test_hash,
2500 .vecs = aes_cmac128_tv_template,
2501 .count = CMAC_AES_TEST_VECTORS
2505 .alg = "cmac(des3_ede)",
2507 .test = alg_test_hash,
2510 .vecs = des3_ede_cmac64_tv_template,
2511 .count = CMAC_DES3_EDE_TEST_VECTORS
2515 .alg = "compress_null",
2516 .test = alg_test_null,
2519 .test = alg_test_hash,
2522 .vecs = crc32_tv_template,
2523 .count = CRC32_TEST_VECTORS
2528 .test = alg_test_crc32c,
2532 .vecs = crc32c_tv_template,
2533 .count = CRC32C_TEST_VECTORS
2538 .test = alg_test_hash,
2542 .vecs = crct10dif_tv_template,
2543 .count = CRCT10DIF_TEST_VECTORS
2547 .alg = "cryptd(__driver-cbc-aes-aesni)",
2548 .test = alg_test_null,
2551 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2552 .test = alg_test_null,
2554 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2555 .test = alg_test_null,
2557 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2558 .test = alg_test_null,
2560 .alg = "cryptd(__driver-ecb-aes-aesni)",
2561 .test = alg_test_null,
2564 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2565 .test = alg_test_null,
2567 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2568 .test = alg_test_null,
2570 .alg = "cryptd(__driver-ecb-cast5-avx)",
2571 .test = alg_test_null,
2573 .alg = "cryptd(__driver-ecb-cast6-avx)",
2574 .test = alg_test_null,
2576 .alg = "cryptd(__driver-ecb-serpent-avx)",
2577 .test = alg_test_null,
2579 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2580 .test = alg_test_null,
2582 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2583 .test = alg_test_null,
2585 .alg = "cryptd(__driver-ecb-twofish-avx)",
2586 .test = alg_test_null,
2588 .alg = "cryptd(__driver-gcm-aes-aesni)",
2589 .test = alg_test_null,
2592 .alg = "cryptd(__ghash-pclmulqdqni)",
2593 .test = alg_test_null,
2597 .test = alg_test_skcipher,
2602 .vecs = aes_ctr_enc_tv_template,
2603 .count = AES_CTR_ENC_TEST_VECTORS
2606 .vecs = aes_ctr_dec_tv_template,
2607 .count = AES_CTR_DEC_TEST_VECTORS
2612 .alg = "ctr(blowfish)",
2613 .test = alg_test_skcipher,
2617 .vecs = bf_ctr_enc_tv_template,
2618 .count = BF_CTR_ENC_TEST_VECTORS
2621 .vecs = bf_ctr_dec_tv_template,
2622 .count = BF_CTR_DEC_TEST_VECTORS
2627 .alg = "ctr(camellia)",
2628 .test = alg_test_skcipher,
2632 .vecs = camellia_ctr_enc_tv_template,
2633 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2636 .vecs = camellia_ctr_dec_tv_template,
2637 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2642 .alg = "ctr(cast5)",
2643 .test = alg_test_skcipher,
2647 .vecs = cast5_ctr_enc_tv_template,
2648 .count = CAST5_CTR_ENC_TEST_VECTORS
2651 .vecs = cast5_ctr_dec_tv_template,
2652 .count = CAST5_CTR_DEC_TEST_VECTORS
2657 .alg = "ctr(cast6)",
2658 .test = alg_test_skcipher,
2662 .vecs = cast6_ctr_enc_tv_template,
2663 .count = CAST6_CTR_ENC_TEST_VECTORS
2666 .vecs = cast6_ctr_dec_tv_template,
2667 .count = CAST6_CTR_DEC_TEST_VECTORS
2673 .test = alg_test_skcipher,
2677 .vecs = des_ctr_enc_tv_template,
2678 .count = DES_CTR_ENC_TEST_VECTORS
2681 .vecs = des_ctr_dec_tv_template,
2682 .count = DES_CTR_DEC_TEST_VECTORS
2687 .alg = "ctr(des3_ede)",
2688 .test = alg_test_skcipher,
2692 .vecs = des3_ede_ctr_enc_tv_template,
2693 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2696 .vecs = des3_ede_ctr_dec_tv_template,
2697 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2702 .alg = "ctr(serpent)",
2703 .test = alg_test_skcipher,
2707 .vecs = serpent_ctr_enc_tv_template,
2708 .count = SERPENT_CTR_ENC_TEST_VECTORS
2711 .vecs = serpent_ctr_dec_tv_template,
2712 .count = SERPENT_CTR_DEC_TEST_VECTORS
2717 .alg = "ctr(twofish)",
2718 .test = alg_test_skcipher,
2722 .vecs = tf_ctr_enc_tv_template,
2723 .count = TF_CTR_ENC_TEST_VECTORS
2726 .vecs = tf_ctr_dec_tv_template,
2727 .count = TF_CTR_DEC_TEST_VECTORS
2732 .alg = "cts(cbc(aes))",
2733 .test = alg_test_skcipher,
2737 .vecs = cts_mode_enc_tv_template,
2738 .count = CTS_MODE_ENC_TEST_VECTORS
2741 .vecs = cts_mode_dec_tv_template,
2742 .count = CTS_MODE_DEC_TEST_VECTORS
2748 .test = alg_test_comp,
2753 .vecs = deflate_comp_tv_template,
2754 .count = DEFLATE_COMP_TEST_VECTORS
2757 .vecs = deflate_decomp_tv_template,
2758 .count = DEFLATE_DECOMP_TEST_VECTORS
2763 .alg = "digest_null",
2764 .test = alg_test_null,
2766 .alg = "drbg_nopr_ctr_aes128",
2767 .test = alg_test_drbg,
2771 .vecs = drbg_nopr_ctr_aes128_tv_template,
2772 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2776 .alg = "drbg_nopr_ctr_aes192",
2777 .test = alg_test_drbg,
2781 .vecs = drbg_nopr_ctr_aes192_tv_template,
2782 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2786 .alg = "drbg_nopr_ctr_aes256",
2787 .test = alg_test_drbg,
2791 .vecs = drbg_nopr_ctr_aes256_tv_template,
2792 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2797 * There is no need to specifically test the DRBG with every
2798 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2800 .alg = "drbg_nopr_hmac_sha1",
2802 .test = alg_test_null,
2804 .alg = "drbg_nopr_hmac_sha256",
2805 .test = alg_test_drbg,
2809 .vecs = drbg_nopr_hmac_sha256_tv_template,
2811 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2815 /* covered by drbg_nopr_hmac_sha256 test */
2816 .alg = "drbg_nopr_hmac_sha384",
2818 .test = alg_test_null,
2820 .alg = "drbg_nopr_hmac_sha512",
2821 .test = alg_test_null,
2824 .alg = "drbg_nopr_sha1",
2826 .test = alg_test_null,
2828 .alg = "drbg_nopr_sha256",
2829 .test = alg_test_drbg,
2833 .vecs = drbg_nopr_sha256_tv_template,
2834 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2838 /* covered by drbg_nopr_sha256 test */
2839 .alg = "drbg_nopr_sha384",
2841 .test = alg_test_null,
2843 .alg = "drbg_nopr_sha512",
2845 .test = alg_test_null,
2847 .alg = "drbg_pr_ctr_aes128",
2848 .test = alg_test_drbg,
2852 .vecs = drbg_pr_ctr_aes128_tv_template,
2853 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2857 /* covered by drbg_pr_ctr_aes128 test */
2858 .alg = "drbg_pr_ctr_aes192",
2860 .test = alg_test_null,
2862 .alg = "drbg_pr_ctr_aes256",
2864 .test = alg_test_null,
2866 .alg = "drbg_pr_hmac_sha1",
2868 .test = alg_test_null,
2870 .alg = "drbg_pr_hmac_sha256",
2871 .test = alg_test_drbg,
2875 .vecs = drbg_pr_hmac_sha256_tv_template,
2876 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2880 /* covered by drbg_pr_hmac_sha256 test */
2881 .alg = "drbg_pr_hmac_sha384",
2883 .test = alg_test_null,
2885 .alg = "drbg_pr_hmac_sha512",
2886 .test = alg_test_null,
2889 .alg = "drbg_pr_sha1",
2891 .test = alg_test_null,
2893 .alg = "drbg_pr_sha256",
2894 .test = alg_test_drbg,
2898 .vecs = drbg_pr_sha256_tv_template,
2899 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2903 /* covered by drbg_pr_sha256 test */
2904 .alg = "drbg_pr_sha384",
2906 .test = alg_test_null,
2908 .alg = "drbg_pr_sha512",
2910 .test = alg_test_null,
2912 .alg = "ecb(__aes-aesni)",
2913 .test = alg_test_null,
2917 .test = alg_test_skcipher,
2922 .vecs = aes_enc_tv_template,
2923 .count = AES_ENC_TEST_VECTORS
2926 .vecs = aes_dec_tv_template,
2927 .count = AES_DEC_TEST_VECTORS
2932 .alg = "ecb(anubis)",
2933 .test = alg_test_skcipher,
2937 .vecs = anubis_enc_tv_template,
2938 .count = ANUBIS_ENC_TEST_VECTORS
2941 .vecs = anubis_dec_tv_template,
2942 .count = ANUBIS_DEC_TEST_VECTORS
2948 .test = alg_test_skcipher,
2952 .vecs = arc4_enc_tv_template,
2953 .count = ARC4_ENC_TEST_VECTORS
2956 .vecs = arc4_dec_tv_template,
2957 .count = ARC4_DEC_TEST_VECTORS
2962 .alg = "ecb(blowfish)",
2963 .test = alg_test_skcipher,
2967 .vecs = bf_enc_tv_template,
2968 .count = BF_ENC_TEST_VECTORS
2971 .vecs = bf_dec_tv_template,
2972 .count = BF_DEC_TEST_VECTORS
2977 .alg = "ecb(camellia)",
2978 .test = alg_test_skcipher,
2982 .vecs = camellia_enc_tv_template,
2983 .count = CAMELLIA_ENC_TEST_VECTORS
2986 .vecs = camellia_dec_tv_template,
2987 .count = CAMELLIA_DEC_TEST_VECTORS
2992 .alg = "ecb(cast5)",
2993 .test = alg_test_skcipher,
2997 .vecs = cast5_enc_tv_template,
2998 .count = CAST5_ENC_TEST_VECTORS
3001 .vecs = cast5_dec_tv_template,
3002 .count = CAST5_DEC_TEST_VECTORS
3007 .alg = "ecb(cast6)",
3008 .test = alg_test_skcipher,
3012 .vecs = cast6_enc_tv_template,
3013 .count = CAST6_ENC_TEST_VECTORS
3016 .vecs = cast6_dec_tv_template,
3017 .count = CAST6_DEC_TEST_VECTORS
3022 .alg = "ecb(cipher_null)",
3023 .test = alg_test_null,
3026 .test = alg_test_skcipher,
3030 .vecs = des_enc_tv_template,
3031 .count = DES_ENC_TEST_VECTORS
3034 .vecs = des_dec_tv_template,
3035 .count = DES_DEC_TEST_VECTORS
3040 .alg = "ecb(des3_ede)",
3041 .test = alg_test_skcipher,
3046 .vecs = des3_ede_enc_tv_template,
3047 .count = DES3_EDE_ENC_TEST_VECTORS
3050 .vecs = des3_ede_dec_tv_template,
3051 .count = DES3_EDE_DEC_TEST_VECTORS
3056 .alg = "ecb(fcrypt)",
3057 .test = alg_test_skcipher,
3061 .vecs = fcrypt_pcbc_enc_tv_template,
3065 .vecs = fcrypt_pcbc_dec_tv_template,
3071 .alg = "ecb(khazad)",
3072 .test = alg_test_skcipher,
3076 .vecs = khazad_enc_tv_template,
3077 .count = KHAZAD_ENC_TEST_VECTORS
3080 .vecs = khazad_dec_tv_template,
3081 .count = KHAZAD_DEC_TEST_VECTORS
3087 .test = alg_test_skcipher,
3091 .vecs = seed_enc_tv_template,
3092 .count = SEED_ENC_TEST_VECTORS
3095 .vecs = seed_dec_tv_template,
3096 .count = SEED_DEC_TEST_VECTORS
3101 .alg = "ecb(serpent)",
3102 .test = alg_test_skcipher,
3106 .vecs = serpent_enc_tv_template,
3107 .count = SERPENT_ENC_TEST_VECTORS
3110 .vecs = serpent_dec_tv_template,
3111 .count = SERPENT_DEC_TEST_VECTORS
3117 .test = alg_test_skcipher,
3121 .vecs = tea_enc_tv_template,
3122 .count = TEA_ENC_TEST_VECTORS
3125 .vecs = tea_dec_tv_template,
3126 .count = TEA_DEC_TEST_VECTORS
3131 .alg = "ecb(tnepres)",
3132 .test = alg_test_skcipher,
3136 .vecs = tnepres_enc_tv_template,
3137 .count = TNEPRES_ENC_TEST_VECTORS
3140 .vecs = tnepres_dec_tv_template,
3141 .count = TNEPRES_DEC_TEST_VECTORS
3146 .alg = "ecb(twofish)",
3147 .test = alg_test_skcipher,
3151 .vecs = tf_enc_tv_template,
3152 .count = TF_ENC_TEST_VECTORS
3155 .vecs = tf_dec_tv_template,
3156 .count = TF_DEC_TEST_VECTORS
3162 .test = alg_test_skcipher,
3166 .vecs = xeta_enc_tv_template,
3167 .count = XETA_ENC_TEST_VECTORS
3170 .vecs = xeta_dec_tv_template,
3171 .count = XETA_DEC_TEST_VECTORS
3177 .test = alg_test_skcipher,
3181 .vecs = xtea_enc_tv_template,
3182 .count = XTEA_ENC_TEST_VECTORS
3185 .vecs = xtea_dec_tv_template,
3186 .count = XTEA_DEC_TEST_VECTORS
3192 .test = alg_test_aead,
3197 .vecs = aes_gcm_enc_tv_template,
3198 .count = AES_GCM_ENC_TEST_VECTORS
3201 .vecs = aes_gcm_dec_tv_template,
3202 .count = AES_GCM_DEC_TEST_VECTORS
3208 .test = alg_test_hash,
3212 .vecs = ghash_tv_template,
3213 .count = GHASH_TEST_VECTORS
3217 .alg = "hmac(crc32)",
3218 .test = alg_test_hash,
3221 .vecs = bfin_crc_tv_template,
3222 .count = BFIN_CRC_TEST_VECTORS
3227 .test = alg_test_hash,
3230 .vecs = hmac_md5_tv_template,
3231 .count = HMAC_MD5_TEST_VECTORS
3235 .alg = "hmac(rmd128)",
3236 .test = alg_test_hash,
3239 .vecs = hmac_rmd128_tv_template,
3240 .count = HMAC_RMD128_TEST_VECTORS
3244 .alg = "hmac(rmd160)",
3245 .test = alg_test_hash,
3248 .vecs = hmac_rmd160_tv_template,
3249 .count = HMAC_RMD160_TEST_VECTORS
3253 .alg = "hmac(sha1)",
3254 .test = alg_test_hash,
3258 .vecs = hmac_sha1_tv_template,
3259 .count = HMAC_SHA1_TEST_VECTORS
3263 .alg = "hmac(sha224)",
3264 .test = alg_test_hash,
3268 .vecs = hmac_sha224_tv_template,
3269 .count = HMAC_SHA224_TEST_VECTORS
3273 .alg = "hmac(sha256)",
3274 .test = alg_test_hash,
3278 .vecs = hmac_sha256_tv_template,
3279 .count = HMAC_SHA256_TEST_VECTORS
3283 .alg = "hmac(sha384)",
3284 .test = alg_test_hash,
3288 .vecs = hmac_sha384_tv_template,
3289 .count = HMAC_SHA384_TEST_VECTORS
3293 .alg = "hmac(sha512)",
3294 .test = alg_test_hash,
3298 .vecs = hmac_sha512_tv_template,
3299 .count = HMAC_SHA512_TEST_VECTORS
3303 .alg = "jitterentropy_rng",
3305 .test = alg_test_null,
3308 .test = alg_test_skcipher,
3313 .vecs = aes_kw_enc_tv_template,
3314 .count = ARRAY_SIZE(aes_kw_enc_tv_template)
3317 .vecs = aes_kw_dec_tv_template,
3318 .count = ARRAY_SIZE(aes_kw_dec_tv_template)
3324 .test = alg_test_skcipher,
3328 .vecs = aes_lrw_enc_tv_template,
3329 .count = AES_LRW_ENC_TEST_VECTORS
3332 .vecs = aes_lrw_dec_tv_template,
3333 .count = AES_LRW_DEC_TEST_VECTORS
3338 .alg = "lrw(camellia)",
3339 .test = alg_test_skcipher,
3343 .vecs = camellia_lrw_enc_tv_template,
3344 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3347 .vecs = camellia_lrw_dec_tv_template,
3348 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3353 .alg = "lrw(cast6)",
3354 .test = alg_test_skcipher,
3358 .vecs = cast6_lrw_enc_tv_template,
3359 .count = CAST6_LRW_ENC_TEST_VECTORS
3362 .vecs = cast6_lrw_dec_tv_template,
3363 .count = CAST6_LRW_DEC_TEST_VECTORS
3368 .alg = "lrw(serpent)",
3369 .test = alg_test_skcipher,
3373 .vecs = serpent_lrw_enc_tv_template,
3374 .count = SERPENT_LRW_ENC_TEST_VECTORS
3377 .vecs = serpent_lrw_dec_tv_template,
3378 .count = SERPENT_LRW_DEC_TEST_VECTORS
3383 .alg = "lrw(twofish)",
3384 .test = alg_test_skcipher,
3388 .vecs = tf_lrw_enc_tv_template,
3389 .count = TF_LRW_ENC_TEST_VECTORS
3392 .vecs = tf_lrw_dec_tv_template,
3393 .count = TF_LRW_DEC_TEST_VECTORS
3399 .test = alg_test_comp,
3404 .vecs = lz4_comp_tv_template,
3405 .count = LZ4_COMP_TEST_VECTORS
3408 .vecs = lz4_decomp_tv_template,
3409 .count = LZ4_DECOMP_TEST_VECTORS
3415 .test = alg_test_comp,
3420 .vecs = lz4hc_comp_tv_template,
3421 .count = LZ4HC_COMP_TEST_VECTORS
3424 .vecs = lz4hc_decomp_tv_template,
3425 .count = LZ4HC_DECOMP_TEST_VECTORS
3431 .test = alg_test_comp,
3436 .vecs = lzo_comp_tv_template,
3437 .count = LZO_COMP_TEST_VECTORS
3440 .vecs = lzo_decomp_tv_template,
3441 .count = LZO_DECOMP_TEST_VECTORS
3447 .test = alg_test_hash,
3450 .vecs = md4_tv_template,
3451 .count = MD4_TEST_VECTORS
3456 .test = alg_test_hash,
3459 .vecs = md5_tv_template,
3460 .count = MD5_TEST_VECTORS
3464 .alg = "michael_mic",
3465 .test = alg_test_hash,
3468 .vecs = michael_mic_tv_template,
3469 .count = MICHAEL_MIC_TEST_VECTORS
3474 .test = alg_test_skcipher,
3479 .vecs = aes_ofb_enc_tv_template,
3480 .count = AES_OFB_ENC_TEST_VECTORS
3483 .vecs = aes_ofb_dec_tv_template,
3484 .count = AES_OFB_DEC_TEST_VECTORS
3489 .alg = "pcbc(fcrypt)",
3490 .test = alg_test_skcipher,
3494 .vecs = fcrypt_pcbc_enc_tv_template,
3495 .count = FCRYPT_ENC_TEST_VECTORS
3498 .vecs = fcrypt_pcbc_dec_tv_template,
3499 .count = FCRYPT_DEC_TEST_VECTORS
3505 .test = alg_test_hash,
3508 .vecs = poly1305_tv_template,
3509 .count = POLY1305_TEST_VECTORS
3513 .alg = "rfc3686(ctr(aes))",
3514 .test = alg_test_skcipher,
3519 .vecs = aes_ctr_rfc3686_enc_tv_template,
3520 .count = AES_CTR_3686_ENC_TEST_VECTORS
3523 .vecs = aes_ctr_rfc3686_dec_tv_template,
3524 .count = AES_CTR_3686_DEC_TEST_VECTORS
3529 .alg = "rfc4106(gcm(aes))",
3530 .test = alg_test_aead,
3535 .vecs = aes_gcm_rfc4106_enc_tv_template,
3536 .count = AES_GCM_4106_ENC_TEST_VECTORS
3539 .vecs = aes_gcm_rfc4106_dec_tv_template,
3540 .count = AES_GCM_4106_DEC_TEST_VECTORS
3545 .alg = "rfc4309(ccm(aes))",
3546 .test = alg_test_aead,
3551 .vecs = aes_ccm_rfc4309_enc_tv_template,
3552 .count = AES_CCM_4309_ENC_TEST_VECTORS
3555 .vecs = aes_ccm_rfc4309_dec_tv_template,
3556 .count = AES_CCM_4309_DEC_TEST_VECTORS
3561 .alg = "rfc4543(gcm(aes))",
3562 .test = alg_test_aead,
3566 .vecs = aes_gcm_rfc4543_enc_tv_template,
3567 .count = AES_GCM_4543_ENC_TEST_VECTORS
3570 .vecs = aes_gcm_rfc4543_dec_tv_template,
3571 .count = AES_GCM_4543_DEC_TEST_VECTORS
3576 .alg = "rfc7539(chacha20,poly1305)",
3577 .test = alg_test_aead,
3581 .vecs = rfc7539_enc_tv_template,
3582 .count = RFC7539_ENC_TEST_VECTORS
3585 .vecs = rfc7539_dec_tv_template,
3586 .count = RFC7539_DEC_TEST_VECTORS
3591 .alg = "rfc7539esp(chacha20,poly1305)",
3592 .test = alg_test_aead,
3596 .vecs = rfc7539esp_enc_tv_template,
3597 .count = RFC7539ESP_ENC_TEST_VECTORS
3600 .vecs = rfc7539esp_dec_tv_template,
3601 .count = RFC7539ESP_DEC_TEST_VECTORS
3607 .test = alg_test_hash,
3610 .vecs = rmd128_tv_template,
3611 .count = RMD128_TEST_VECTORS
3616 .test = alg_test_hash,
3619 .vecs = rmd160_tv_template,
3620 .count = RMD160_TEST_VECTORS
3625 .test = alg_test_hash,
3628 .vecs = rmd256_tv_template,
3629 .count = RMD256_TEST_VECTORS
3634 .test = alg_test_hash,
3637 .vecs = rmd320_tv_template,
3638 .count = RMD320_TEST_VECTORS
3643 .test = alg_test_akcipher,
3647 .vecs = rsa_tv_template,
3648 .count = RSA_TEST_VECTORS
3653 .test = alg_test_skcipher,
3657 .vecs = salsa20_stream_enc_tv_template,
3658 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3664 .test = alg_test_hash,
3668 .vecs = sha1_tv_template,
3669 .count = SHA1_TEST_VECTORS
3674 .test = alg_test_hash,
3678 .vecs = sha224_tv_template,
3679 .count = SHA224_TEST_VECTORS
3684 .test = alg_test_hash,
3688 .vecs = sha256_tv_template,
3689 .count = SHA256_TEST_VECTORS
3694 .test = alg_test_hash,
3698 .vecs = sha384_tv_template,
3699 .count = SHA384_TEST_VECTORS
3704 .test = alg_test_hash,
3708 .vecs = sha512_tv_template,
3709 .count = SHA512_TEST_VECTORS
3714 .test = alg_test_hash,
3717 .vecs = tgr128_tv_template,
3718 .count = TGR128_TEST_VECTORS
3723 .test = alg_test_hash,
3726 .vecs = tgr160_tv_template,
3727 .count = TGR160_TEST_VECTORS
3732 .test = alg_test_hash,
3735 .vecs = tgr192_tv_template,
3736 .count = TGR192_TEST_VECTORS
3741 .test = alg_test_hash,
3744 .vecs = aes_vmac128_tv_template,
3745 .count = VMAC_AES_TEST_VECTORS
3750 .test = alg_test_hash,
3753 .vecs = wp256_tv_template,
3754 .count = WP256_TEST_VECTORS
3759 .test = alg_test_hash,
3762 .vecs = wp384_tv_template,
3763 .count = WP384_TEST_VECTORS
3768 .test = alg_test_hash,
3771 .vecs = wp512_tv_template,
3772 .count = WP512_TEST_VECTORS
3777 .test = alg_test_hash,
3780 .vecs = aes_xcbc128_tv_template,
3781 .count = XCBC_AES_TEST_VECTORS
3786 .test = alg_test_skcipher,
3791 .vecs = aes_xts_enc_tv_template,
3792 .count = AES_XTS_ENC_TEST_VECTORS
3795 .vecs = aes_xts_dec_tv_template,
3796 .count = AES_XTS_DEC_TEST_VECTORS
3801 .alg = "xts(camellia)",
3802 .test = alg_test_skcipher,
3806 .vecs = camellia_xts_enc_tv_template,
3807 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3810 .vecs = camellia_xts_dec_tv_template,
3811 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3816 .alg = "xts(cast6)",
3817 .test = alg_test_skcipher,
3821 .vecs = cast6_xts_enc_tv_template,
3822 .count = CAST6_XTS_ENC_TEST_VECTORS
3825 .vecs = cast6_xts_dec_tv_template,
3826 .count = CAST6_XTS_DEC_TEST_VECTORS
3831 .alg = "xts(serpent)",
3832 .test = alg_test_skcipher,
3836 .vecs = serpent_xts_enc_tv_template,
3837 .count = SERPENT_XTS_ENC_TEST_VECTORS
3840 .vecs = serpent_xts_dec_tv_template,
3841 .count = SERPENT_XTS_DEC_TEST_VECTORS
3846 .alg = "xts(twofish)",
3847 .test = alg_test_skcipher,
3851 .vecs = tf_xts_enc_tv_template,
3852 .count = TF_XTS_ENC_TEST_VECTORS
3855 .vecs = tf_xts_dec_tv_template,
3856 .count = TF_XTS_DEC_TEST_VECTORS
3862 .test = alg_test_pcomp,
3867 .vecs = zlib_comp_tv_template,
3868 .count = ZLIB_COMP_TEST_VECTORS
3871 .vecs = zlib_decomp_tv_template,
3872 .count = ZLIB_DECOMP_TEST_VECTORS
3879 static bool alg_test_descs_checked;
3881 static void alg_test_descs_check_order(void)
3885 /* only check once */
3886 if (alg_test_descs_checked)
3889 alg_test_descs_checked = true;
3891 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3892 int diff = strcmp(alg_test_descs[i - 1].alg,
3893 alg_test_descs[i].alg);
3895 if (WARN_ON(diff > 0)) {
3896 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3897 alg_test_descs[i - 1].alg,
3898 alg_test_descs[i].alg);
3901 if (WARN_ON(diff == 0)) {
3902 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3903 alg_test_descs[i].alg);
3908 static int alg_find_test(const char *alg)
3911 int end = ARRAY_SIZE(alg_test_descs);
3913 while (start < end) {
3914 int i = (start + end) / 2;
3915 int diff = strcmp(alg_test_descs[i].alg, alg);
3933 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3939 alg_test_descs_check_order();
3941 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3942 char nalg[CRYPTO_MAX_ALG_NAME];
3944 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3946 return -ENAMETOOLONG;
3948 i = alg_find_test(nalg);
3952 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3955 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3959 i = alg_find_test(alg);
3960 j = alg_find_test(driver);
3964 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3965 (j >= 0 && !alg_test_descs[j].fips_allowed)))
3970 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3972 if (j >= 0 && j != i)
3973 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3977 if (fips_enabled && rc)
3978 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3980 if (fips_enabled && !rc)
3981 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
3986 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3992 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3994 EXPORT_SYMBOL_GPL(alg_test);