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 wait_async_op(struct tcrypt_result *tr, int ret)
183 if (ret == -EINPROGRESS || ret == -EBUSY) {
184 ret = wait_for_completion_interruptible(&tr->completion);
187 reinit_completion(&tr->completion);
192 static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
193 unsigned int tcount, bool use_digest,
194 const int align_offset)
196 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
197 unsigned int i, j, k, temp;
198 struct scatterlist sg[8];
201 struct ahash_request *req;
202 struct tcrypt_result tresult;
204 char *xbuf[XBUFSIZE];
207 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
210 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
213 if (testmgr_alloc_buf(xbuf))
216 init_completion(&tresult.completion);
218 req = ahash_request_alloc(tfm, GFP_KERNEL);
220 printk(KERN_ERR "alg: hash: Failed to allocate request for "
224 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
225 tcrypt_complete, &tresult);
228 for (i = 0; i < tcount; i++) {
233 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
237 memset(result, 0, MAX_DIGEST_SIZE);
240 hash_buff += align_offset;
242 memcpy(hash_buff, template[i].plaintext, template[i].psize);
243 sg_init_one(&sg[0], hash_buff, template[i].psize);
245 if (template[i].ksize) {
246 crypto_ahash_clear_flags(tfm, ~0);
247 if (template[i].ksize > MAX_KEYLEN) {
248 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
249 j, algo, template[i].ksize, MAX_KEYLEN);
253 memcpy(key, template[i].key, template[i].ksize);
254 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
256 printk(KERN_ERR "alg: hash: setkey failed on "
257 "test %d for %s: ret=%d\n", j, algo,
263 ahash_request_set_crypt(req, sg, result, template[i].psize);
265 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
267 pr_err("alg: hash: digest failed on test %d "
268 "for %s: ret=%d\n", j, algo, -ret);
272 ret = wait_async_op(&tresult, crypto_ahash_init(req));
274 pr_err("alt: hash: init failed on test %d "
275 "for %s: ret=%d\n", j, algo, -ret);
278 ret = wait_async_op(&tresult, crypto_ahash_update(req));
280 pr_err("alt: hash: update failed on test %d "
281 "for %s: ret=%d\n", j, algo, -ret);
284 ret = wait_async_op(&tresult, crypto_ahash_final(req));
286 pr_err("alt: hash: final failed on test %d "
287 "for %s: ret=%d\n", j, algo, -ret);
292 if (memcmp(result, template[i].digest,
293 crypto_ahash_digestsize(tfm))) {
294 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
296 hexdump(result, crypto_ahash_digestsize(tfm));
303 for (i = 0; i < tcount; i++) {
304 /* alignment tests are only done with continuous buffers */
305 if (align_offset != 0)
312 memset(result, 0, MAX_DIGEST_SIZE);
315 sg_init_table(sg, template[i].np);
317 for (k = 0; k < template[i].np; k++) {
318 if (WARN_ON(offset_in_page(IDX[k]) +
319 template[i].tap[k] > PAGE_SIZE))
322 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
323 offset_in_page(IDX[k]),
324 template[i].plaintext + temp,
327 temp += template[i].tap[k];
330 if (template[i].ksize) {
331 if (template[i].ksize > MAX_KEYLEN) {
332 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
333 j, algo, template[i].ksize, MAX_KEYLEN);
337 crypto_ahash_clear_flags(tfm, ~0);
338 memcpy(key, template[i].key, template[i].ksize);
339 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
342 printk(KERN_ERR "alg: hash: setkey "
343 "failed on chunking test %d "
344 "for %s: ret=%d\n", j, algo, -ret);
349 ahash_request_set_crypt(req, sg, result, template[i].psize);
350 ret = crypto_ahash_digest(req);
356 ret = wait_for_completion_interruptible(
357 &tresult.completion);
358 if (!ret && !(ret = tresult.err)) {
359 reinit_completion(&tresult.completion);
364 printk(KERN_ERR "alg: hash: digest failed "
365 "on chunking test %d for %s: "
366 "ret=%d\n", j, algo, -ret);
370 if (memcmp(result, template[i].digest,
371 crypto_ahash_digestsize(tfm))) {
372 printk(KERN_ERR "alg: hash: Chunking test %d "
373 "failed for %s\n", j, algo);
374 hexdump(result, crypto_ahash_digestsize(tfm));
383 ahash_request_free(req);
385 testmgr_free_buf(xbuf);
392 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
393 unsigned int tcount, bool use_digest)
395 unsigned int alignmask;
398 ret = __test_hash(tfm, template, tcount, use_digest, 0);
402 /* test unaligned buffers, check with one byte offset */
403 ret = __test_hash(tfm, template, tcount, use_digest, 1);
407 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
409 /* Check if alignment mask for tfm is correctly set. */
410 ret = __test_hash(tfm, template, tcount, use_digest,
419 static int __test_aead(struct crypto_aead *tfm, int enc,
420 struct aead_testvec *template, unsigned int tcount,
421 const bool diff_dst, const int align_offset)
423 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
424 unsigned int i, j, k, n, temp;
428 struct aead_request *req;
429 struct scatterlist *sg;
430 struct scatterlist *asg;
431 struct scatterlist *sgout;
433 struct tcrypt_result result;
434 unsigned int authsize;
439 char *xbuf[XBUFSIZE];
440 char *xoutbuf[XBUFSIZE];
441 char *axbuf[XBUFSIZE];
443 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
446 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
449 if (testmgr_alloc_buf(xbuf))
451 if (testmgr_alloc_buf(axbuf))
453 if (diff_dst && testmgr_alloc_buf(xoutbuf))
456 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
457 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
473 init_completion(&result.completion);
475 req = aead_request_alloc(tfm, GFP_KERNEL);
477 pr_err("alg: aead%s: Failed to allocate request for %s\n",
482 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
483 tcrypt_complete, &result);
485 for (i = 0, j = 0; i < tcount; i++) {
491 /* some templates have no input data but they will
495 input += align_offset;
499 if (WARN_ON(align_offset + template[i].ilen >
500 PAGE_SIZE || template[i].alen > PAGE_SIZE))
503 memcpy(input, template[i].input, template[i].ilen);
504 memcpy(assoc, template[i].assoc, template[i].alen);
506 memcpy(iv, template[i].iv, MAX_IVLEN);
508 memset(iv, 0, MAX_IVLEN);
510 crypto_aead_clear_flags(tfm, ~0);
512 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
514 if (template[i].klen > MAX_KEYLEN) {
515 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
516 d, j, algo, template[i].klen,
521 memcpy(key, template[i].key, template[i].klen);
523 ret = crypto_aead_setkey(tfm, key, template[i].klen);
524 if (!ret == template[i].fail) {
525 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
526 d, j, algo, crypto_aead_get_flags(tfm));
531 authsize = abs(template[i].rlen - template[i].ilen);
532 ret = crypto_aead_setauthsize(tfm, authsize);
534 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
535 d, authsize, j, algo);
541 output += align_offset;
542 sg_init_one(&sg[0], input, template[i].ilen);
543 sg_init_one(&sgout[0], output, template[i].rlen);
545 sg_init_one(&sg[0], input,
546 template[i].ilen + (enc ? authsize : 0));
550 sg_init_one(&asg[0], assoc, template[i].alen);
552 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
553 template[i].ilen, iv);
555 aead_request_set_assoc(req, asg, template[i].alen);
557 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
561 if (template[i].novrfy) {
562 /* verification was supposed to fail */
563 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
565 /* so really, we got a bad message */
572 ret = wait_for_completion_interruptible(
574 if (!ret && !(ret = result.err)) {
575 reinit_completion(&result.completion);
579 if (template[i].novrfy)
580 /* verification failure was expected */
584 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
585 d, e, j, algo, -ret);
590 if (memcmp(q, template[i].result, template[i].rlen)) {
591 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
593 hexdump(q, template[i].rlen);
599 for (i = 0, j = 0; i < tcount; i++) {
600 /* alignment tests are only done with continuous buffers */
601 if (align_offset != 0)
610 memcpy(iv, template[i].iv, MAX_IVLEN);
612 memset(iv, 0, MAX_IVLEN);
614 crypto_aead_clear_flags(tfm, ~0);
616 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
617 if (template[i].klen > MAX_KEYLEN) {
618 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
619 d, j, algo, template[i].klen, MAX_KEYLEN);
623 memcpy(key, template[i].key, template[i].klen);
625 ret = crypto_aead_setkey(tfm, key, template[i].klen);
626 if (!ret == template[i].fail) {
627 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
628 d, j, algo, crypto_aead_get_flags(tfm));
633 authsize = abs(template[i].rlen - template[i].ilen);
636 sg_init_table(sg, template[i].np);
638 sg_init_table(sgout, template[i].np);
639 for (k = 0, temp = 0; k < template[i].np; k++) {
640 if (WARN_ON(offset_in_page(IDX[k]) +
641 template[i].tap[k] > PAGE_SIZE))
644 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
645 memcpy(q, template[i].input + temp, template[i].tap[k]);
646 sg_set_buf(&sg[k], q, template[i].tap[k]);
649 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
650 offset_in_page(IDX[k]);
652 memset(q, 0, template[i].tap[k]);
654 sg_set_buf(&sgout[k], q, template[i].tap[k]);
657 n = template[i].tap[k];
658 if (k == template[i].np - 1 && enc)
660 if (offset_in_page(q) + n < PAGE_SIZE)
663 temp += template[i].tap[k];
666 ret = crypto_aead_setauthsize(tfm, authsize);
668 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
669 d, authsize, j, algo);
674 if (WARN_ON(sg[k - 1].offset +
675 sg[k - 1].length + authsize >
682 sgout[k - 1].length += authsize;
684 sg[k - 1].length += authsize;
687 sg_init_table(asg, template[i].anp);
689 for (k = 0, temp = 0; k < template[i].anp; k++) {
690 if (WARN_ON(offset_in_page(IDX[k]) +
691 template[i].atap[k] > PAGE_SIZE))
694 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
695 offset_in_page(IDX[k]),
696 template[i].assoc + temp,
697 template[i].atap[k]),
698 template[i].atap[k]);
699 temp += template[i].atap[k];
702 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
706 aead_request_set_assoc(req, asg, template[i].alen);
708 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
712 if (template[i].novrfy) {
713 /* verification was supposed to fail */
714 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
716 /* so really, we got a bad message */
723 ret = wait_for_completion_interruptible(
725 if (!ret && !(ret = result.err)) {
726 reinit_completion(&result.completion);
730 if (template[i].novrfy)
731 /* verification failure was expected */
735 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
736 d, e, j, algo, -ret);
741 for (k = 0, temp = 0; k < template[i].np; k++) {
743 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
744 offset_in_page(IDX[k]);
746 q = xbuf[IDX[k] >> PAGE_SHIFT] +
747 offset_in_page(IDX[k]);
749 n = template[i].tap[k];
750 if (k == template[i].np - 1)
751 n += enc ? authsize : -authsize;
753 if (memcmp(q, template[i].result + temp, n)) {
754 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
761 if (k == template[i].np - 1 && !enc) {
763 memcmp(q, template[i].input +
769 for (n = 0; offset_in_page(q + n) && q[n]; n++)
773 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
774 d, j, e, k, algo, n);
779 temp += template[i].tap[k];
786 aead_request_free(req);
790 testmgr_free_buf(xoutbuf);
792 testmgr_free_buf(axbuf);
794 testmgr_free_buf(xbuf);
801 static int test_aead(struct crypto_aead *tfm, int enc,
802 struct aead_testvec *template, unsigned int tcount)
804 unsigned int alignmask;
807 /* test 'dst == src' case */
808 ret = __test_aead(tfm, enc, template, tcount, false, 0);
812 /* test 'dst != src' case */
813 ret = __test_aead(tfm, enc, template, tcount, true, 0);
817 /* test unaligned buffers, check with one byte offset */
818 ret = __test_aead(tfm, enc, template, tcount, true, 1);
822 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
824 /* Check if alignment mask for tfm is correctly set. */
825 ret = __test_aead(tfm, enc, template, tcount, true,
834 static int test_cipher(struct crypto_cipher *tfm, int enc,
835 struct cipher_testvec *template, unsigned int tcount)
837 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
838 unsigned int i, j, k;
842 char *xbuf[XBUFSIZE];
845 if (testmgr_alloc_buf(xbuf))
854 for (i = 0; i < tcount; i++) {
861 if (WARN_ON(template[i].ilen > PAGE_SIZE))
865 memcpy(data, template[i].input, template[i].ilen);
867 crypto_cipher_clear_flags(tfm, ~0);
869 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
871 ret = crypto_cipher_setkey(tfm, template[i].key,
873 if (!ret == template[i].fail) {
874 printk(KERN_ERR "alg: cipher: setkey failed "
875 "on test %d for %s: flags=%x\n", j,
876 algo, crypto_cipher_get_flags(tfm));
881 for (k = 0; k < template[i].ilen;
882 k += crypto_cipher_blocksize(tfm)) {
884 crypto_cipher_encrypt_one(tfm, data + k,
887 crypto_cipher_decrypt_one(tfm, data + k,
892 if (memcmp(q, template[i].result, template[i].rlen)) {
893 printk(KERN_ERR "alg: cipher: Test %d failed "
894 "on %s for %s\n", j, e, algo);
895 hexdump(q, template[i].rlen);
904 testmgr_free_buf(xbuf);
909 static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
910 struct cipher_testvec *template, unsigned int tcount,
911 const bool diff_dst, const int align_offset)
914 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
915 unsigned int i, j, k, n, temp;
917 struct ablkcipher_request *req;
918 struct scatterlist sg[8];
919 struct scatterlist sgout[8];
921 struct tcrypt_result result;
924 char *xbuf[XBUFSIZE];
925 char *xoutbuf[XBUFSIZE];
928 if (testmgr_alloc_buf(xbuf))
931 if (diff_dst && testmgr_alloc_buf(xoutbuf))
944 init_completion(&result.completion);
946 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
948 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
953 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
954 tcrypt_complete, &result);
957 for (i = 0; i < tcount; i++) {
958 if (template[i].np && !template[i].also_non_np)
962 memcpy(iv, template[i].iv, MAX_IVLEN);
964 memset(iv, 0, MAX_IVLEN);
968 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
972 data += align_offset;
973 memcpy(data, template[i].input, template[i].ilen);
975 crypto_ablkcipher_clear_flags(tfm, ~0);
977 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
979 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
981 if (!ret == template[i].fail) {
982 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
983 d, j, algo, crypto_ablkcipher_get_flags(tfm));
988 sg_init_one(&sg[0], data, template[i].ilen);
991 data += align_offset;
992 sg_init_one(&sgout[0], data, template[i].ilen);
995 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
996 template[i].ilen, iv);
997 ret = enc ? crypto_ablkcipher_encrypt(req) :
998 crypto_ablkcipher_decrypt(req);
1005 ret = wait_for_completion_interruptible(
1006 &result.completion);
1007 if (!ret && !((ret = result.err))) {
1008 reinit_completion(&result.completion);
1013 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1014 d, e, j, algo, -ret);
1019 if (memcmp(q, template[i].result, template[i].rlen)) {
1020 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1022 hexdump(q, template[i].rlen);
1029 for (i = 0; i < tcount; i++) {
1030 /* alignment tests are only done with continuous buffers */
1031 if (align_offset != 0)
1034 if (!template[i].np)
1038 memcpy(iv, template[i].iv, MAX_IVLEN);
1040 memset(iv, 0, MAX_IVLEN);
1043 crypto_ablkcipher_clear_flags(tfm, ~0);
1045 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1047 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1049 if (!ret == template[i].fail) {
1050 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1051 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1058 sg_init_table(sg, template[i].np);
1060 sg_init_table(sgout, template[i].np);
1061 for (k = 0; k < template[i].np; k++) {
1062 if (WARN_ON(offset_in_page(IDX[k]) +
1063 template[i].tap[k] > PAGE_SIZE))
1066 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1068 memcpy(q, template[i].input + temp, template[i].tap[k]);
1070 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1071 q[template[i].tap[k]] = 0;
1073 sg_set_buf(&sg[k], q, template[i].tap[k]);
1075 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1076 offset_in_page(IDX[k]);
1078 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1080 memset(q, 0, template[i].tap[k]);
1081 if (offset_in_page(q) +
1082 template[i].tap[k] < PAGE_SIZE)
1083 q[template[i].tap[k]] = 0;
1086 temp += template[i].tap[k];
1089 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1090 template[i].ilen, iv);
1092 ret = enc ? crypto_ablkcipher_encrypt(req) :
1093 crypto_ablkcipher_decrypt(req);
1100 ret = wait_for_completion_interruptible(
1101 &result.completion);
1102 if (!ret && !((ret = result.err))) {
1103 reinit_completion(&result.completion);
1108 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1109 d, e, j, algo, -ret);
1115 for (k = 0; k < template[i].np; k++) {
1117 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1118 offset_in_page(IDX[k]);
1120 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1121 offset_in_page(IDX[k]);
1123 if (memcmp(q, template[i].result + temp,
1124 template[i].tap[k])) {
1125 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1127 hexdump(q, template[i].tap[k]);
1131 q += template[i].tap[k];
1132 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1135 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1136 d, j, e, k, algo, n);
1140 temp += template[i].tap[k];
1147 ablkcipher_request_free(req);
1149 testmgr_free_buf(xoutbuf);
1151 testmgr_free_buf(xbuf);
1156 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1157 struct cipher_testvec *template, unsigned int tcount)
1159 unsigned int alignmask;
1162 /* test 'dst == src' case */
1163 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
1167 /* test 'dst != src' case */
1168 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1172 /* test unaligned buffers, check with one byte offset */
1173 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1177 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1179 /* Check if alignment mask for tfm is correctly set. */
1180 ret = __test_skcipher(tfm, enc, template, tcount, true,
1189 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1190 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1192 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1194 char result[COMP_BUF_SIZE];
1197 for (i = 0; i < ctcount; i++) {
1199 unsigned int dlen = COMP_BUF_SIZE;
1201 memset(result, 0, sizeof (result));
1203 ilen = ctemplate[i].inlen;
1204 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1205 ilen, result, &dlen);
1207 printk(KERN_ERR "alg: comp: compression failed "
1208 "on test %d for %s: ret=%d\n", i + 1, algo,
1213 if (dlen != ctemplate[i].outlen) {
1214 printk(KERN_ERR "alg: comp: Compression test %d "
1215 "failed for %s: output len = %d\n", i + 1, algo,
1221 if (memcmp(result, ctemplate[i].output, dlen)) {
1222 printk(KERN_ERR "alg: comp: Compression test %d "
1223 "failed for %s\n", i + 1, algo);
1224 hexdump(result, dlen);
1230 for (i = 0; i < dtcount; i++) {
1232 unsigned int dlen = COMP_BUF_SIZE;
1234 memset(result, 0, sizeof (result));
1236 ilen = dtemplate[i].inlen;
1237 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1238 ilen, result, &dlen);
1240 printk(KERN_ERR "alg: comp: decompression failed "
1241 "on test %d for %s: ret=%d\n", i + 1, algo,
1246 if (dlen != dtemplate[i].outlen) {
1247 printk(KERN_ERR "alg: comp: Decompression test %d "
1248 "failed for %s: output len = %d\n", i + 1, algo,
1254 if (memcmp(result, dtemplate[i].output, dlen)) {
1255 printk(KERN_ERR "alg: comp: Decompression test %d "
1256 "failed for %s\n", i + 1, algo);
1257 hexdump(result, dlen);
1269 static int test_pcomp(struct crypto_pcomp *tfm,
1270 struct pcomp_testvec *ctemplate,
1271 struct pcomp_testvec *dtemplate, int ctcount,
1274 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1276 char result[COMP_BUF_SIZE];
1279 for (i = 0; i < ctcount; i++) {
1280 struct comp_request req;
1281 unsigned int produced = 0;
1283 res = crypto_compress_setup(tfm, ctemplate[i].params,
1284 ctemplate[i].paramsize);
1286 pr_err("alg: pcomp: compression setup failed on test "
1287 "%d for %s: error=%d\n", i + 1, algo, res);
1291 res = crypto_compress_init(tfm);
1293 pr_err("alg: pcomp: compression init failed on test "
1294 "%d for %s: error=%d\n", i + 1, algo, res);
1298 memset(result, 0, sizeof(result));
1300 req.next_in = ctemplate[i].input;
1301 req.avail_in = ctemplate[i].inlen / 2;
1302 req.next_out = result;
1303 req.avail_out = ctemplate[i].outlen / 2;
1305 res = crypto_compress_update(tfm, &req);
1306 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1307 pr_err("alg: pcomp: compression update failed on test "
1308 "%d for %s: error=%d\n", i + 1, algo, res);
1314 /* Add remaining input data */
1315 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1317 res = crypto_compress_update(tfm, &req);
1318 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1319 pr_err("alg: pcomp: compression update failed on test "
1320 "%d for %s: error=%d\n", i + 1, algo, res);
1326 /* Provide remaining output space */
1327 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1329 res = crypto_compress_final(tfm, &req);
1331 pr_err("alg: pcomp: compression final failed on test "
1332 "%d for %s: error=%d\n", i + 1, algo, res);
1337 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1338 pr_err("alg: comp: Compression test %d failed for %s: "
1339 "output len = %d (expected %d)\n", i + 1, algo,
1340 COMP_BUF_SIZE - req.avail_out,
1341 ctemplate[i].outlen);
1345 if (produced != ctemplate[i].outlen) {
1346 pr_err("alg: comp: Compression test %d failed for %s: "
1347 "returned len = %u (expected %d)\n", i + 1,
1348 algo, produced, ctemplate[i].outlen);
1352 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1353 pr_err("alg: pcomp: Compression test %d failed for "
1354 "%s\n", i + 1, algo);
1355 hexdump(result, ctemplate[i].outlen);
1360 for (i = 0; i < dtcount; i++) {
1361 struct comp_request req;
1362 unsigned int produced = 0;
1364 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1365 dtemplate[i].paramsize);
1367 pr_err("alg: pcomp: decompression setup failed on "
1368 "test %d for %s: error=%d\n", i + 1, algo, res);
1372 res = crypto_decompress_init(tfm);
1374 pr_err("alg: pcomp: decompression init failed on test "
1375 "%d for %s: error=%d\n", i + 1, algo, res);
1379 memset(result, 0, sizeof(result));
1381 req.next_in = dtemplate[i].input;
1382 req.avail_in = dtemplate[i].inlen / 2;
1383 req.next_out = result;
1384 req.avail_out = dtemplate[i].outlen / 2;
1386 res = crypto_decompress_update(tfm, &req);
1387 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1388 pr_err("alg: pcomp: decompression update failed on "
1389 "test %d for %s: error=%d\n", i + 1, algo, res);
1395 /* Add remaining input data */
1396 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1398 res = crypto_decompress_update(tfm, &req);
1399 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1400 pr_err("alg: pcomp: decompression update failed on "
1401 "test %d for %s: error=%d\n", i + 1, algo, res);
1407 /* Provide remaining output space */
1408 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1410 res = crypto_decompress_final(tfm, &req);
1411 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1412 pr_err("alg: pcomp: decompression final failed on "
1413 "test %d for %s: error=%d\n", i + 1, algo, res);
1419 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1420 pr_err("alg: comp: Decompression test %d failed for "
1421 "%s: output len = %d (expected %d)\n", i + 1,
1422 algo, COMP_BUF_SIZE - req.avail_out,
1423 dtemplate[i].outlen);
1427 if (produced != dtemplate[i].outlen) {
1428 pr_err("alg: comp: Decompression test %d failed for "
1429 "%s: returned len = %u (expected %d)\n", i + 1,
1430 algo, produced, dtemplate[i].outlen);
1434 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1435 pr_err("alg: pcomp: Decompression test %d failed for "
1436 "%s\n", i + 1, algo);
1437 hexdump(result, dtemplate[i].outlen);
1446 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1447 unsigned int tcount)
1449 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1450 int err = 0, i, j, seedsize;
1454 seedsize = crypto_rng_seedsize(tfm);
1456 seed = kmalloc(seedsize, GFP_KERNEL);
1458 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1463 for (i = 0; i < tcount; i++) {
1464 memset(result, 0, 32);
1466 memcpy(seed, template[i].v, template[i].vlen);
1467 memcpy(seed + template[i].vlen, template[i].key,
1469 memcpy(seed + template[i].vlen + template[i].klen,
1470 template[i].dt, template[i].dtlen);
1472 err = crypto_rng_reset(tfm, seed, seedsize);
1474 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1479 for (j = 0; j < template[i].loops; j++) {
1480 err = crypto_rng_get_bytes(tfm, result,
1482 if (err != template[i].rlen) {
1483 printk(KERN_ERR "alg: cprng: Failed to obtain "
1484 "the correct amount of random data for "
1485 "%s (requested %d, got %d)\n", algo,
1486 template[i].rlen, err);
1491 err = memcmp(result, template[i].result,
1494 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1496 hexdump(result, template[i].rlen);
1507 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1510 struct crypto_aead *tfm;
1513 tfm = crypto_alloc_aead(driver, type, mask);
1515 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1516 "%ld\n", driver, PTR_ERR(tfm));
1517 return PTR_ERR(tfm);
1520 if (desc->suite.aead.enc.vecs) {
1521 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1522 desc->suite.aead.enc.count);
1527 if (!err && desc->suite.aead.dec.vecs)
1528 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1529 desc->suite.aead.dec.count);
1532 crypto_free_aead(tfm);
1536 static int alg_test_cipher(const struct alg_test_desc *desc,
1537 const char *driver, u32 type, u32 mask)
1539 struct crypto_cipher *tfm;
1542 tfm = crypto_alloc_cipher(driver, type, mask);
1544 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1545 "%s: %ld\n", driver, PTR_ERR(tfm));
1546 return PTR_ERR(tfm);
1549 if (desc->suite.cipher.enc.vecs) {
1550 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1551 desc->suite.cipher.enc.count);
1556 if (desc->suite.cipher.dec.vecs)
1557 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1558 desc->suite.cipher.dec.count);
1561 crypto_free_cipher(tfm);
1565 static int alg_test_skcipher(const struct alg_test_desc *desc,
1566 const char *driver, u32 type, u32 mask)
1568 struct crypto_ablkcipher *tfm;
1571 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1573 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1574 "%s: %ld\n", driver, PTR_ERR(tfm));
1575 return PTR_ERR(tfm);
1578 if (desc->suite.cipher.enc.vecs) {
1579 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1580 desc->suite.cipher.enc.count);
1585 if (desc->suite.cipher.dec.vecs)
1586 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1587 desc->suite.cipher.dec.count);
1590 crypto_free_ablkcipher(tfm);
1594 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1597 struct crypto_comp *tfm;
1600 tfm = crypto_alloc_comp(driver, type, mask);
1602 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1603 "%ld\n", driver, PTR_ERR(tfm));
1604 return PTR_ERR(tfm);
1607 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1608 desc->suite.comp.decomp.vecs,
1609 desc->suite.comp.comp.count,
1610 desc->suite.comp.decomp.count);
1612 crypto_free_comp(tfm);
1616 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1619 struct crypto_pcomp *tfm;
1622 tfm = crypto_alloc_pcomp(driver, type, mask);
1624 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1625 driver, PTR_ERR(tfm));
1626 return PTR_ERR(tfm);
1629 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1630 desc->suite.pcomp.decomp.vecs,
1631 desc->suite.pcomp.comp.count,
1632 desc->suite.pcomp.decomp.count);
1634 crypto_free_pcomp(tfm);
1638 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1641 struct crypto_ahash *tfm;
1644 tfm = crypto_alloc_ahash(driver, type, mask);
1646 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1647 "%ld\n", driver, PTR_ERR(tfm));
1648 return PTR_ERR(tfm);
1651 err = test_hash(tfm, desc->suite.hash.vecs,
1652 desc->suite.hash.count, true);
1654 err = test_hash(tfm, desc->suite.hash.vecs,
1655 desc->suite.hash.count, false);
1657 crypto_free_ahash(tfm);
1661 static int alg_test_crc32c(const struct alg_test_desc *desc,
1662 const char *driver, u32 type, u32 mask)
1664 struct crypto_shash *tfm;
1668 err = alg_test_hash(desc, driver, type, mask);
1672 tfm = crypto_alloc_shash(driver, type, mask);
1674 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1675 "%ld\n", driver, PTR_ERR(tfm));
1681 SHASH_DESC_ON_STACK(shash, tfm);
1682 u32 *ctx = (u32 *)shash_desc_ctx(shash);
1687 *ctx = le32_to_cpu(420553207);
1688 err = crypto_shash_final(shash, (u8 *)&val);
1690 printk(KERN_ERR "alg: crc32c: Operation failed for "
1691 "%s: %d\n", driver, err);
1695 if (val != ~420553207) {
1696 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1697 "%d\n", driver, val);
1702 crypto_free_shash(tfm);
1708 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1711 struct crypto_rng *rng;
1714 rng = crypto_alloc_rng(driver, type, mask);
1716 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1717 "%ld\n", driver, PTR_ERR(rng));
1718 return PTR_ERR(rng);
1721 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1723 crypto_free_rng(rng);
1729 static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1730 const char *driver, u32 type, u32 mask)
1733 struct crypto_rng *drng;
1734 struct drbg_test_data test_data;
1735 struct drbg_string addtl, pers, testentropy;
1736 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1741 drng = crypto_alloc_rng(driver, type, mask);
1743 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
1749 test_data.testentropy = &testentropy;
1750 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1751 drbg_string_fill(&pers, test->pers, test->perslen);
1752 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1754 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1758 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1760 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1761 ret = crypto_drbg_get_bytes_addtl_test(drng,
1762 buf, test->expectedlen, &addtl, &test_data);
1764 ret = crypto_drbg_get_bytes_addtl(drng,
1765 buf, test->expectedlen, &addtl);
1768 printk(KERN_ERR "alg: drbg: could not obtain random data for "
1769 "driver %s\n", driver);
1773 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1775 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1776 ret = crypto_drbg_get_bytes_addtl_test(drng,
1777 buf, test->expectedlen, &addtl, &test_data);
1779 ret = crypto_drbg_get_bytes_addtl(drng,
1780 buf, test->expectedlen, &addtl);
1783 printk(KERN_ERR "alg: drbg: could not obtain random data for "
1784 "driver %s\n", driver);
1788 ret = memcmp(test->expected, buf, test->expectedlen);
1791 crypto_free_rng(drng);
1797 static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1803 struct drbg_testvec *template = desc->suite.drbg.vecs;
1804 unsigned int tcount = desc->suite.drbg.count;
1806 if (0 == memcmp(driver, "drbg_pr_", 8))
1809 for (i = 0; i < tcount; i++) {
1810 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1812 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1822 static int alg_test_null(const struct alg_test_desc *desc,
1823 const char *driver, u32 type, u32 mask)
1828 /* Please keep this list sorted by algorithm name. */
1829 static const struct alg_test_desc alg_test_descs[] = {
1831 .alg = "__cbc-cast5-avx",
1832 .test = alg_test_null,
1834 .alg = "__cbc-cast6-avx",
1835 .test = alg_test_null,
1837 .alg = "__cbc-serpent-avx",
1838 .test = alg_test_null,
1840 .alg = "__cbc-serpent-avx2",
1841 .test = alg_test_null,
1843 .alg = "__cbc-serpent-sse2",
1844 .test = alg_test_null,
1846 .alg = "__cbc-twofish-avx",
1847 .test = alg_test_null,
1849 .alg = "__driver-cbc-aes-aesni",
1850 .test = alg_test_null,
1853 .alg = "__driver-cbc-camellia-aesni",
1854 .test = alg_test_null,
1856 .alg = "__driver-cbc-camellia-aesni-avx2",
1857 .test = alg_test_null,
1859 .alg = "__driver-cbc-cast5-avx",
1860 .test = alg_test_null,
1862 .alg = "__driver-cbc-cast6-avx",
1863 .test = alg_test_null,
1865 .alg = "__driver-cbc-serpent-avx",
1866 .test = alg_test_null,
1868 .alg = "__driver-cbc-serpent-avx2",
1869 .test = alg_test_null,
1871 .alg = "__driver-cbc-serpent-sse2",
1872 .test = alg_test_null,
1874 .alg = "__driver-cbc-twofish-avx",
1875 .test = alg_test_null,
1877 .alg = "__driver-ecb-aes-aesni",
1878 .test = alg_test_null,
1881 .alg = "__driver-ecb-camellia-aesni",
1882 .test = alg_test_null,
1884 .alg = "__driver-ecb-camellia-aesni-avx2",
1885 .test = alg_test_null,
1887 .alg = "__driver-ecb-cast5-avx",
1888 .test = alg_test_null,
1890 .alg = "__driver-ecb-cast6-avx",
1891 .test = alg_test_null,
1893 .alg = "__driver-ecb-serpent-avx",
1894 .test = alg_test_null,
1896 .alg = "__driver-ecb-serpent-avx2",
1897 .test = alg_test_null,
1899 .alg = "__driver-ecb-serpent-sse2",
1900 .test = alg_test_null,
1902 .alg = "__driver-ecb-twofish-avx",
1903 .test = alg_test_null,
1905 .alg = "__ghash-pclmulqdqni",
1906 .test = alg_test_null,
1909 .alg = "ansi_cprng",
1910 .test = alg_test_cprng,
1914 .vecs = ansi_cprng_aes_tv_template,
1915 .count = ANSI_CPRNG_AES_TEST_VECTORS
1919 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1920 .test = alg_test_aead,
1925 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1926 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1929 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1930 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1935 .alg = "authenc(hmac(sha1),cbc(aes))",
1936 .test = alg_test_aead,
1942 hmac_sha1_aes_cbc_enc_tv_temp,
1944 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1949 .alg = "authenc(hmac(sha1),cbc(des))",
1950 .test = alg_test_aead,
1956 hmac_sha1_des_cbc_enc_tv_temp,
1958 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1963 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1964 .test = alg_test_aead,
1970 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1972 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
1977 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1978 .test = alg_test_aead,
1984 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1986 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
1990 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1992 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1997 .alg = "authenc(hmac(sha224),cbc(des))",
1998 .test = alg_test_aead,
2004 hmac_sha224_des_cbc_enc_tv_temp,
2006 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2011 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2012 .test = alg_test_aead,
2018 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2020 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2025 .alg = "authenc(hmac(sha256),cbc(aes))",
2026 .test = alg_test_aead,
2032 hmac_sha256_aes_cbc_enc_tv_temp,
2034 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2039 .alg = "authenc(hmac(sha256),cbc(des))",
2040 .test = alg_test_aead,
2046 hmac_sha256_des_cbc_enc_tv_temp,
2048 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2053 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2054 .test = alg_test_aead,
2060 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2062 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2067 .alg = "authenc(hmac(sha384),cbc(des))",
2068 .test = alg_test_aead,
2074 hmac_sha384_des_cbc_enc_tv_temp,
2076 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2081 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2082 .test = alg_test_aead,
2088 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2090 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2095 .alg = "authenc(hmac(sha512),cbc(aes))",
2096 .test = alg_test_aead,
2102 hmac_sha512_aes_cbc_enc_tv_temp,
2104 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2109 .alg = "authenc(hmac(sha512),cbc(des))",
2110 .test = alg_test_aead,
2116 hmac_sha512_des_cbc_enc_tv_temp,
2118 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2123 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2124 .test = alg_test_aead,
2130 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2132 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2138 .test = alg_test_skcipher,
2143 .vecs = aes_cbc_enc_tv_template,
2144 .count = AES_CBC_ENC_TEST_VECTORS
2147 .vecs = aes_cbc_dec_tv_template,
2148 .count = AES_CBC_DEC_TEST_VECTORS
2153 .alg = "cbc(anubis)",
2154 .test = alg_test_skcipher,
2158 .vecs = anubis_cbc_enc_tv_template,
2159 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2162 .vecs = anubis_cbc_dec_tv_template,
2163 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2168 .alg = "cbc(blowfish)",
2169 .test = alg_test_skcipher,
2173 .vecs = bf_cbc_enc_tv_template,
2174 .count = BF_CBC_ENC_TEST_VECTORS
2177 .vecs = bf_cbc_dec_tv_template,
2178 .count = BF_CBC_DEC_TEST_VECTORS
2183 .alg = "cbc(camellia)",
2184 .test = alg_test_skcipher,
2188 .vecs = camellia_cbc_enc_tv_template,
2189 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2192 .vecs = camellia_cbc_dec_tv_template,
2193 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2198 .alg = "cbc(cast5)",
2199 .test = alg_test_skcipher,
2203 .vecs = cast5_cbc_enc_tv_template,
2204 .count = CAST5_CBC_ENC_TEST_VECTORS
2207 .vecs = cast5_cbc_dec_tv_template,
2208 .count = CAST5_CBC_DEC_TEST_VECTORS
2213 .alg = "cbc(cast6)",
2214 .test = alg_test_skcipher,
2218 .vecs = cast6_cbc_enc_tv_template,
2219 .count = CAST6_CBC_ENC_TEST_VECTORS
2222 .vecs = cast6_cbc_dec_tv_template,
2223 .count = CAST6_CBC_DEC_TEST_VECTORS
2229 .test = alg_test_skcipher,
2233 .vecs = des_cbc_enc_tv_template,
2234 .count = DES_CBC_ENC_TEST_VECTORS
2237 .vecs = des_cbc_dec_tv_template,
2238 .count = DES_CBC_DEC_TEST_VECTORS
2243 .alg = "cbc(des3_ede)",
2244 .test = alg_test_skcipher,
2249 .vecs = des3_ede_cbc_enc_tv_template,
2250 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2253 .vecs = des3_ede_cbc_dec_tv_template,
2254 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2259 .alg = "cbc(serpent)",
2260 .test = alg_test_skcipher,
2264 .vecs = serpent_cbc_enc_tv_template,
2265 .count = SERPENT_CBC_ENC_TEST_VECTORS
2268 .vecs = serpent_cbc_dec_tv_template,
2269 .count = SERPENT_CBC_DEC_TEST_VECTORS
2274 .alg = "cbc(twofish)",
2275 .test = alg_test_skcipher,
2279 .vecs = tf_cbc_enc_tv_template,
2280 .count = TF_CBC_ENC_TEST_VECTORS
2283 .vecs = tf_cbc_dec_tv_template,
2284 .count = TF_CBC_DEC_TEST_VECTORS
2290 .test = alg_test_aead,
2295 .vecs = aes_ccm_enc_tv_template,
2296 .count = AES_CCM_ENC_TEST_VECTORS
2299 .vecs = aes_ccm_dec_tv_template,
2300 .count = AES_CCM_DEC_TEST_VECTORS
2306 .test = alg_test_hash,
2309 .vecs = aes_cmac128_tv_template,
2310 .count = CMAC_AES_TEST_VECTORS
2314 .alg = "cmac(des3_ede)",
2315 .test = alg_test_hash,
2318 .vecs = des3_ede_cmac64_tv_template,
2319 .count = CMAC_DES3_EDE_TEST_VECTORS
2323 .alg = "compress_null",
2324 .test = alg_test_null,
2327 .test = alg_test_crc32c,
2331 .vecs = crc32c_tv_template,
2332 .count = CRC32C_TEST_VECTORS
2337 .test = alg_test_hash,
2341 .vecs = crct10dif_tv_template,
2342 .count = CRCT10DIF_TEST_VECTORS
2346 .alg = "cryptd(__driver-cbc-aes-aesni)",
2347 .test = alg_test_null,
2350 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2351 .test = alg_test_null,
2353 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2354 .test = alg_test_null,
2356 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2357 .test = alg_test_null,
2359 .alg = "cryptd(__driver-ecb-aes-aesni)",
2360 .test = alg_test_null,
2363 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2364 .test = alg_test_null,
2366 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2367 .test = alg_test_null,
2369 .alg = "cryptd(__driver-ecb-cast5-avx)",
2370 .test = alg_test_null,
2372 .alg = "cryptd(__driver-ecb-cast6-avx)",
2373 .test = alg_test_null,
2375 .alg = "cryptd(__driver-ecb-serpent-avx)",
2376 .test = alg_test_null,
2378 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2379 .test = alg_test_null,
2381 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2382 .test = alg_test_null,
2384 .alg = "cryptd(__driver-ecb-twofish-avx)",
2385 .test = alg_test_null,
2387 .alg = "cryptd(__driver-gcm-aes-aesni)",
2388 .test = alg_test_null,
2391 .alg = "cryptd(__ghash-pclmulqdqni)",
2392 .test = alg_test_null,
2396 .test = alg_test_skcipher,
2401 .vecs = aes_ctr_enc_tv_template,
2402 .count = AES_CTR_ENC_TEST_VECTORS
2405 .vecs = aes_ctr_dec_tv_template,
2406 .count = AES_CTR_DEC_TEST_VECTORS
2411 .alg = "ctr(blowfish)",
2412 .test = alg_test_skcipher,
2416 .vecs = bf_ctr_enc_tv_template,
2417 .count = BF_CTR_ENC_TEST_VECTORS
2420 .vecs = bf_ctr_dec_tv_template,
2421 .count = BF_CTR_DEC_TEST_VECTORS
2426 .alg = "ctr(camellia)",
2427 .test = alg_test_skcipher,
2431 .vecs = camellia_ctr_enc_tv_template,
2432 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2435 .vecs = camellia_ctr_dec_tv_template,
2436 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2441 .alg = "ctr(cast5)",
2442 .test = alg_test_skcipher,
2446 .vecs = cast5_ctr_enc_tv_template,
2447 .count = CAST5_CTR_ENC_TEST_VECTORS
2450 .vecs = cast5_ctr_dec_tv_template,
2451 .count = CAST5_CTR_DEC_TEST_VECTORS
2456 .alg = "ctr(cast6)",
2457 .test = alg_test_skcipher,
2461 .vecs = cast6_ctr_enc_tv_template,
2462 .count = CAST6_CTR_ENC_TEST_VECTORS
2465 .vecs = cast6_ctr_dec_tv_template,
2466 .count = CAST6_CTR_DEC_TEST_VECTORS
2472 .test = alg_test_skcipher,
2476 .vecs = des_ctr_enc_tv_template,
2477 .count = DES_CTR_ENC_TEST_VECTORS
2480 .vecs = des_ctr_dec_tv_template,
2481 .count = DES_CTR_DEC_TEST_VECTORS
2486 .alg = "ctr(des3_ede)",
2487 .test = alg_test_skcipher,
2491 .vecs = des3_ede_ctr_enc_tv_template,
2492 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2495 .vecs = des3_ede_ctr_dec_tv_template,
2496 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2501 .alg = "ctr(serpent)",
2502 .test = alg_test_skcipher,
2506 .vecs = serpent_ctr_enc_tv_template,
2507 .count = SERPENT_CTR_ENC_TEST_VECTORS
2510 .vecs = serpent_ctr_dec_tv_template,
2511 .count = SERPENT_CTR_DEC_TEST_VECTORS
2516 .alg = "ctr(twofish)",
2517 .test = alg_test_skcipher,
2521 .vecs = tf_ctr_enc_tv_template,
2522 .count = TF_CTR_ENC_TEST_VECTORS
2525 .vecs = tf_ctr_dec_tv_template,
2526 .count = TF_CTR_DEC_TEST_VECTORS
2531 .alg = "cts(cbc(aes))",
2532 .test = alg_test_skcipher,
2536 .vecs = cts_mode_enc_tv_template,
2537 .count = CTS_MODE_ENC_TEST_VECTORS
2540 .vecs = cts_mode_dec_tv_template,
2541 .count = CTS_MODE_DEC_TEST_VECTORS
2547 .test = alg_test_comp,
2552 .vecs = deflate_comp_tv_template,
2553 .count = DEFLATE_COMP_TEST_VECTORS
2556 .vecs = deflate_decomp_tv_template,
2557 .count = DEFLATE_DECOMP_TEST_VECTORS
2562 .alg = "digest_null",
2563 .test = alg_test_null,
2565 .alg = "drbg_nopr_ctr_aes128",
2566 .test = alg_test_drbg,
2570 .vecs = drbg_nopr_ctr_aes128_tv_template,
2571 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2575 .alg = "drbg_nopr_ctr_aes192",
2576 .test = alg_test_drbg,
2580 .vecs = drbg_nopr_ctr_aes192_tv_template,
2581 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2585 .alg = "drbg_nopr_ctr_aes256",
2586 .test = alg_test_drbg,
2590 .vecs = drbg_nopr_ctr_aes256_tv_template,
2591 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2596 * There is no need to specifically test the DRBG with every
2597 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2599 .alg = "drbg_nopr_hmac_sha1",
2601 .test = alg_test_null,
2603 .alg = "drbg_nopr_hmac_sha256",
2604 .test = alg_test_drbg,
2608 .vecs = drbg_nopr_hmac_sha256_tv_template,
2610 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2614 /* covered by drbg_nopr_hmac_sha256 test */
2615 .alg = "drbg_nopr_hmac_sha384",
2617 .test = alg_test_null,
2619 .alg = "drbg_nopr_hmac_sha512",
2620 .test = alg_test_null,
2623 .alg = "drbg_nopr_sha1",
2625 .test = alg_test_null,
2627 .alg = "drbg_nopr_sha256",
2628 .test = alg_test_drbg,
2632 .vecs = drbg_nopr_sha256_tv_template,
2633 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2637 /* covered by drbg_nopr_sha256 test */
2638 .alg = "drbg_nopr_sha384",
2640 .test = alg_test_null,
2642 .alg = "drbg_nopr_sha512",
2644 .test = alg_test_null,
2646 .alg = "drbg_pr_ctr_aes128",
2647 .test = alg_test_drbg,
2651 .vecs = drbg_pr_ctr_aes128_tv_template,
2652 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2656 /* covered by drbg_pr_ctr_aes128 test */
2657 .alg = "drbg_pr_ctr_aes192",
2659 .test = alg_test_null,
2661 .alg = "drbg_pr_ctr_aes256",
2663 .test = alg_test_null,
2665 .alg = "drbg_pr_hmac_sha1",
2667 .test = alg_test_null,
2669 .alg = "drbg_pr_hmac_sha256",
2670 .test = alg_test_drbg,
2674 .vecs = drbg_pr_hmac_sha256_tv_template,
2675 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2679 /* covered by drbg_pr_hmac_sha256 test */
2680 .alg = "drbg_pr_hmac_sha384",
2682 .test = alg_test_null,
2684 .alg = "drbg_pr_hmac_sha512",
2685 .test = alg_test_null,
2688 .alg = "drbg_pr_sha1",
2690 .test = alg_test_null,
2692 .alg = "drbg_pr_sha256",
2693 .test = alg_test_drbg,
2697 .vecs = drbg_pr_sha256_tv_template,
2698 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2702 /* covered by drbg_pr_sha256 test */
2703 .alg = "drbg_pr_sha384",
2705 .test = alg_test_null,
2707 .alg = "drbg_pr_sha512",
2709 .test = alg_test_null,
2711 .alg = "ecb(__aes-aesni)",
2712 .test = alg_test_null,
2716 .test = alg_test_skcipher,
2721 .vecs = aes_enc_tv_template,
2722 .count = AES_ENC_TEST_VECTORS
2725 .vecs = aes_dec_tv_template,
2726 .count = AES_DEC_TEST_VECTORS
2731 .alg = "ecb(anubis)",
2732 .test = alg_test_skcipher,
2736 .vecs = anubis_enc_tv_template,
2737 .count = ANUBIS_ENC_TEST_VECTORS
2740 .vecs = anubis_dec_tv_template,
2741 .count = ANUBIS_DEC_TEST_VECTORS
2747 .test = alg_test_skcipher,
2751 .vecs = arc4_enc_tv_template,
2752 .count = ARC4_ENC_TEST_VECTORS
2755 .vecs = arc4_dec_tv_template,
2756 .count = ARC4_DEC_TEST_VECTORS
2761 .alg = "ecb(blowfish)",
2762 .test = alg_test_skcipher,
2766 .vecs = bf_enc_tv_template,
2767 .count = BF_ENC_TEST_VECTORS
2770 .vecs = bf_dec_tv_template,
2771 .count = BF_DEC_TEST_VECTORS
2776 .alg = "ecb(camellia)",
2777 .test = alg_test_skcipher,
2781 .vecs = camellia_enc_tv_template,
2782 .count = CAMELLIA_ENC_TEST_VECTORS
2785 .vecs = camellia_dec_tv_template,
2786 .count = CAMELLIA_DEC_TEST_VECTORS
2791 .alg = "ecb(cast5)",
2792 .test = alg_test_skcipher,
2796 .vecs = cast5_enc_tv_template,
2797 .count = CAST5_ENC_TEST_VECTORS
2800 .vecs = cast5_dec_tv_template,
2801 .count = CAST5_DEC_TEST_VECTORS
2806 .alg = "ecb(cast6)",
2807 .test = alg_test_skcipher,
2811 .vecs = cast6_enc_tv_template,
2812 .count = CAST6_ENC_TEST_VECTORS
2815 .vecs = cast6_dec_tv_template,
2816 .count = CAST6_DEC_TEST_VECTORS
2821 .alg = "ecb(cipher_null)",
2822 .test = alg_test_null,
2825 .test = alg_test_skcipher,
2830 .vecs = des_enc_tv_template,
2831 .count = DES_ENC_TEST_VECTORS
2834 .vecs = des_dec_tv_template,
2835 .count = DES_DEC_TEST_VECTORS
2840 .alg = "ecb(des3_ede)",
2841 .test = alg_test_skcipher,
2846 .vecs = des3_ede_enc_tv_template,
2847 .count = DES3_EDE_ENC_TEST_VECTORS
2850 .vecs = des3_ede_dec_tv_template,
2851 .count = DES3_EDE_DEC_TEST_VECTORS
2856 .alg = "ecb(fcrypt)",
2857 .test = alg_test_skcipher,
2861 .vecs = fcrypt_pcbc_enc_tv_template,
2865 .vecs = fcrypt_pcbc_dec_tv_template,
2871 .alg = "ecb(khazad)",
2872 .test = alg_test_skcipher,
2876 .vecs = khazad_enc_tv_template,
2877 .count = KHAZAD_ENC_TEST_VECTORS
2880 .vecs = khazad_dec_tv_template,
2881 .count = KHAZAD_DEC_TEST_VECTORS
2887 .test = alg_test_skcipher,
2891 .vecs = seed_enc_tv_template,
2892 .count = SEED_ENC_TEST_VECTORS
2895 .vecs = seed_dec_tv_template,
2896 .count = SEED_DEC_TEST_VECTORS
2901 .alg = "ecb(serpent)",
2902 .test = alg_test_skcipher,
2906 .vecs = serpent_enc_tv_template,
2907 .count = SERPENT_ENC_TEST_VECTORS
2910 .vecs = serpent_dec_tv_template,
2911 .count = SERPENT_DEC_TEST_VECTORS
2917 .test = alg_test_skcipher,
2921 .vecs = tea_enc_tv_template,
2922 .count = TEA_ENC_TEST_VECTORS
2925 .vecs = tea_dec_tv_template,
2926 .count = TEA_DEC_TEST_VECTORS
2931 .alg = "ecb(tnepres)",
2932 .test = alg_test_skcipher,
2936 .vecs = tnepres_enc_tv_template,
2937 .count = TNEPRES_ENC_TEST_VECTORS
2940 .vecs = tnepres_dec_tv_template,
2941 .count = TNEPRES_DEC_TEST_VECTORS
2946 .alg = "ecb(twofish)",
2947 .test = alg_test_skcipher,
2951 .vecs = tf_enc_tv_template,
2952 .count = TF_ENC_TEST_VECTORS
2955 .vecs = tf_dec_tv_template,
2956 .count = TF_DEC_TEST_VECTORS
2962 .test = alg_test_skcipher,
2966 .vecs = xeta_enc_tv_template,
2967 .count = XETA_ENC_TEST_VECTORS
2970 .vecs = xeta_dec_tv_template,
2971 .count = XETA_DEC_TEST_VECTORS
2977 .test = alg_test_skcipher,
2981 .vecs = xtea_enc_tv_template,
2982 .count = XTEA_ENC_TEST_VECTORS
2985 .vecs = xtea_dec_tv_template,
2986 .count = XTEA_DEC_TEST_VECTORS
2992 .test = alg_test_aead,
2997 .vecs = aes_gcm_enc_tv_template,
2998 .count = AES_GCM_ENC_TEST_VECTORS
3001 .vecs = aes_gcm_dec_tv_template,
3002 .count = AES_GCM_DEC_TEST_VECTORS
3008 .test = alg_test_hash,
3012 .vecs = ghash_tv_template,
3013 .count = GHASH_TEST_VECTORS
3017 .alg = "hmac(crc32)",
3018 .test = alg_test_hash,
3021 .vecs = bfin_crc_tv_template,
3022 .count = BFIN_CRC_TEST_VECTORS
3027 .test = alg_test_hash,
3030 .vecs = hmac_md5_tv_template,
3031 .count = HMAC_MD5_TEST_VECTORS
3035 .alg = "hmac(rmd128)",
3036 .test = alg_test_hash,
3039 .vecs = hmac_rmd128_tv_template,
3040 .count = HMAC_RMD128_TEST_VECTORS
3044 .alg = "hmac(rmd160)",
3045 .test = alg_test_hash,
3048 .vecs = hmac_rmd160_tv_template,
3049 .count = HMAC_RMD160_TEST_VECTORS
3053 .alg = "hmac(sha1)",
3054 .test = alg_test_hash,
3058 .vecs = hmac_sha1_tv_template,
3059 .count = HMAC_SHA1_TEST_VECTORS
3063 .alg = "hmac(sha224)",
3064 .test = alg_test_hash,
3068 .vecs = hmac_sha224_tv_template,
3069 .count = HMAC_SHA224_TEST_VECTORS
3073 .alg = "hmac(sha256)",
3074 .test = alg_test_hash,
3078 .vecs = hmac_sha256_tv_template,
3079 .count = HMAC_SHA256_TEST_VECTORS
3083 .alg = "hmac(sha384)",
3084 .test = alg_test_hash,
3088 .vecs = hmac_sha384_tv_template,
3089 .count = HMAC_SHA384_TEST_VECTORS
3093 .alg = "hmac(sha512)",
3094 .test = alg_test_hash,
3098 .vecs = hmac_sha512_tv_template,
3099 .count = HMAC_SHA512_TEST_VECTORS
3104 .test = alg_test_skcipher,
3108 .vecs = aes_lrw_enc_tv_template,
3109 .count = AES_LRW_ENC_TEST_VECTORS
3112 .vecs = aes_lrw_dec_tv_template,
3113 .count = AES_LRW_DEC_TEST_VECTORS
3118 .alg = "lrw(camellia)",
3119 .test = alg_test_skcipher,
3123 .vecs = camellia_lrw_enc_tv_template,
3124 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3127 .vecs = camellia_lrw_dec_tv_template,
3128 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3133 .alg = "lrw(cast6)",
3134 .test = alg_test_skcipher,
3138 .vecs = cast6_lrw_enc_tv_template,
3139 .count = CAST6_LRW_ENC_TEST_VECTORS
3142 .vecs = cast6_lrw_dec_tv_template,
3143 .count = CAST6_LRW_DEC_TEST_VECTORS
3148 .alg = "lrw(serpent)",
3149 .test = alg_test_skcipher,
3153 .vecs = serpent_lrw_enc_tv_template,
3154 .count = SERPENT_LRW_ENC_TEST_VECTORS
3157 .vecs = serpent_lrw_dec_tv_template,
3158 .count = SERPENT_LRW_DEC_TEST_VECTORS
3163 .alg = "lrw(twofish)",
3164 .test = alg_test_skcipher,
3168 .vecs = tf_lrw_enc_tv_template,
3169 .count = TF_LRW_ENC_TEST_VECTORS
3172 .vecs = tf_lrw_dec_tv_template,
3173 .count = TF_LRW_DEC_TEST_VECTORS
3179 .test = alg_test_comp,
3184 .vecs = lz4_comp_tv_template,
3185 .count = LZ4_COMP_TEST_VECTORS
3188 .vecs = lz4_decomp_tv_template,
3189 .count = LZ4_DECOMP_TEST_VECTORS
3195 .test = alg_test_comp,
3200 .vecs = lz4hc_comp_tv_template,
3201 .count = LZ4HC_COMP_TEST_VECTORS
3204 .vecs = lz4hc_decomp_tv_template,
3205 .count = LZ4HC_DECOMP_TEST_VECTORS
3211 .test = alg_test_comp,
3216 .vecs = lzo_comp_tv_template,
3217 .count = LZO_COMP_TEST_VECTORS
3220 .vecs = lzo_decomp_tv_template,
3221 .count = LZO_DECOMP_TEST_VECTORS
3227 .test = alg_test_hash,
3230 .vecs = md4_tv_template,
3231 .count = MD4_TEST_VECTORS
3236 .test = alg_test_hash,
3239 .vecs = md5_tv_template,
3240 .count = MD5_TEST_VECTORS
3244 .alg = "michael_mic",
3245 .test = alg_test_hash,
3248 .vecs = michael_mic_tv_template,
3249 .count = MICHAEL_MIC_TEST_VECTORS
3254 .test = alg_test_skcipher,
3259 .vecs = aes_ofb_enc_tv_template,
3260 .count = AES_OFB_ENC_TEST_VECTORS
3263 .vecs = aes_ofb_dec_tv_template,
3264 .count = AES_OFB_DEC_TEST_VECTORS
3269 .alg = "pcbc(fcrypt)",
3270 .test = alg_test_skcipher,
3274 .vecs = fcrypt_pcbc_enc_tv_template,
3275 .count = FCRYPT_ENC_TEST_VECTORS
3278 .vecs = fcrypt_pcbc_dec_tv_template,
3279 .count = FCRYPT_DEC_TEST_VECTORS
3284 .alg = "rfc3686(ctr(aes))",
3285 .test = alg_test_skcipher,
3290 .vecs = aes_ctr_rfc3686_enc_tv_template,
3291 .count = AES_CTR_3686_ENC_TEST_VECTORS
3294 .vecs = aes_ctr_rfc3686_dec_tv_template,
3295 .count = AES_CTR_3686_DEC_TEST_VECTORS
3300 .alg = "rfc4106(gcm(aes))",
3301 .test = alg_test_aead,
3305 .vecs = aes_gcm_rfc4106_enc_tv_template,
3306 .count = AES_GCM_4106_ENC_TEST_VECTORS
3309 .vecs = aes_gcm_rfc4106_dec_tv_template,
3310 .count = AES_GCM_4106_DEC_TEST_VECTORS
3315 .alg = "rfc4309(ccm(aes))",
3316 .test = alg_test_aead,
3321 .vecs = aes_ccm_rfc4309_enc_tv_template,
3322 .count = AES_CCM_4309_ENC_TEST_VECTORS
3325 .vecs = aes_ccm_rfc4309_dec_tv_template,
3326 .count = AES_CCM_4309_DEC_TEST_VECTORS
3331 .alg = "rfc4543(gcm(aes))",
3332 .test = alg_test_aead,
3336 .vecs = aes_gcm_rfc4543_enc_tv_template,
3337 .count = AES_GCM_4543_ENC_TEST_VECTORS
3340 .vecs = aes_gcm_rfc4543_dec_tv_template,
3341 .count = AES_GCM_4543_DEC_TEST_VECTORS
3347 .test = alg_test_hash,
3350 .vecs = rmd128_tv_template,
3351 .count = RMD128_TEST_VECTORS
3356 .test = alg_test_hash,
3359 .vecs = rmd160_tv_template,
3360 .count = RMD160_TEST_VECTORS
3365 .test = alg_test_hash,
3368 .vecs = rmd256_tv_template,
3369 .count = RMD256_TEST_VECTORS
3374 .test = alg_test_hash,
3377 .vecs = rmd320_tv_template,
3378 .count = RMD320_TEST_VECTORS
3383 .test = alg_test_skcipher,
3387 .vecs = salsa20_stream_enc_tv_template,
3388 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3394 .test = alg_test_hash,
3398 .vecs = sha1_tv_template,
3399 .count = SHA1_TEST_VECTORS
3404 .test = alg_test_hash,
3408 .vecs = sha224_tv_template,
3409 .count = SHA224_TEST_VECTORS
3414 .test = alg_test_hash,
3418 .vecs = sha256_tv_template,
3419 .count = SHA256_TEST_VECTORS
3424 .test = alg_test_hash,
3428 .vecs = sha384_tv_template,
3429 .count = SHA384_TEST_VECTORS
3434 .test = alg_test_hash,
3438 .vecs = sha512_tv_template,
3439 .count = SHA512_TEST_VECTORS
3444 .test = alg_test_hash,
3447 .vecs = tgr128_tv_template,
3448 .count = TGR128_TEST_VECTORS
3453 .test = alg_test_hash,
3456 .vecs = tgr160_tv_template,
3457 .count = TGR160_TEST_VECTORS
3462 .test = alg_test_hash,
3465 .vecs = tgr192_tv_template,
3466 .count = TGR192_TEST_VECTORS
3471 .test = alg_test_hash,
3474 .vecs = aes_vmac128_tv_template,
3475 .count = VMAC_AES_TEST_VECTORS
3480 .test = alg_test_hash,
3483 .vecs = wp256_tv_template,
3484 .count = WP256_TEST_VECTORS
3489 .test = alg_test_hash,
3492 .vecs = wp384_tv_template,
3493 .count = WP384_TEST_VECTORS
3498 .test = alg_test_hash,
3501 .vecs = wp512_tv_template,
3502 .count = WP512_TEST_VECTORS
3507 .test = alg_test_hash,
3510 .vecs = aes_xcbc128_tv_template,
3511 .count = XCBC_AES_TEST_VECTORS
3516 .test = alg_test_skcipher,
3521 .vecs = aes_xts_enc_tv_template,
3522 .count = AES_XTS_ENC_TEST_VECTORS
3525 .vecs = aes_xts_dec_tv_template,
3526 .count = AES_XTS_DEC_TEST_VECTORS
3531 .alg = "xts(camellia)",
3532 .test = alg_test_skcipher,
3536 .vecs = camellia_xts_enc_tv_template,
3537 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3540 .vecs = camellia_xts_dec_tv_template,
3541 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3546 .alg = "xts(cast6)",
3547 .test = alg_test_skcipher,
3551 .vecs = cast6_xts_enc_tv_template,
3552 .count = CAST6_XTS_ENC_TEST_VECTORS
3555 .vecs = cast6_xts_dec_tv_template,
3556 .count = CAST6_XTS_DEC_TEST_VECTORS
3561 .alg = "xts(serpent)",
3562 .test = alg_test_skcipher,
3566 .vecs = serpent_xts_enc_tv_template,
3567 .count = SERPENT_XTS_ENC_TEST_VECTORS
3570 .vecs = serpent_xts_dec_tv_template,
3571 .count = SERPENT_XTS_DEC_TEST_VECTORS
3576 .alg = "xts(twofish)",
3577 .test = alg_test_skcipher,
3581 .vecs = tf_xts_enc_tv_template,
3582 .count = TF_XTS_ENC_TEST_VECTORS
3585 .vecs = tf_xts_dec_tv_template,
3586 .count = TF_XTS_DEC_TEST_VECTORS
3592 .test = alg_test_pcomp,
3597 .vecs = zlib_comp_tv_template,
3598 .count = ZLIB_COMP_TEST_VECTORS
3601 .vecs = zlib_decomp_tv_template,
3602 .count = ZLIB_DECOMP_TEST_VECTORS
3609 static bool alg_test_descs_checked;
3611 static void alg_test_descs_check_order(void)
3615 /* only check once */
3616 if (alg_test_descs_checked)
3619 alg_test_descs_checked = true;
3621 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3622 int diff = strcmp(alg_test_descs[i - 1].alg,
3623 alg_test_descs[i].alg);
3625 if (WARN_ON(diff > 0)) {
3626 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3627 alg_test_descs[i - 1].alg,
3628 alg_test_descs[i].alg);
3631 if (WARN_ON(diff == 0)) {
3632 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3633 alg_test_descs[i].alg);
3638 static int alg_find_test(const char *alg)
3641 int end = ARRAY_SIZE(alg_test_descs);
3643 while (start < end) {
3644 int i = (start + end) / 2;
3645 int diff = strcmp(alg_test_descs[i].alg, alg);
3663 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3669 alg_test_descs_check_order();
3671 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3672 char nalg[CRYPTO_MAX_ALG_NAME];
3674 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3676 return -ENAMETOOLONG;
3678 i = alg_find_test(nalg);
3682 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3685 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3689 i = alg_find_test(alg);
3690 j = alg_find_test(driver);
3694 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3695 (j >= 0 && !alg_test_descs[j].fips_allowed)))
3700 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3702 if (j >= 0 && j != i)
3703 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3707 if (fips_enabled && rc)
3708 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3710 if (fips_enabled && !rc)
3711 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3717 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3723 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3725 EXPORT_SYMBOL_GPL(alg_test);