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 wait_for_completion(&tr->completion);
185 reinit_completion(&tr->completion);
191 static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
192 unsigned int tcount, bool use_digest,
193 const int align_offset)
195 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
196 unsigned int i, j, k, temp;
197 struct scatterlist sg[8];
200 struct ahash_request *req;
201 struct tcrypt_result tresult;
203 char *xbuf[XBUFSIZE];
206 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
209 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
212 if (testmgr_alloc_buf(xbuf))
215 init_completion(&tresult.completion);
217 req = ahash_request_alloc(tfm, GFP_KERNEL);
219 printk(KERN_ERR "alg: hash: Failed to allocate request for "
223 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
224 tcrypt_complete, &tresult);
227 for (i = 0; i < tcount; i++) {
232 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
236 memset(result, 0, MAX_DIGEST_SIZE);
239 hash_buff += align_offset;
241 memcpy(hash_buff, template[i].plaintext, template[i].psize);
242 sg_init_one(&sg[0], hash_buff, template[i].psize);
244 if (template[i].ksize) {
245 crypto_ahash_clear_flags(tfm, ~0);
246 if (template[i].ksize > MAX_KEYLEN) {
247 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
248 j, algo, template[i].ksize, MAX_KEYLEN);
252 memcpy(key, template[i].key, template[i].ksize);
253 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
255 printk(KERN_ERR "alg: hash: setkey failed on "
256 "test %d for %s: ret=%d\n", j, algo,
262 ahash_request_set_crypt(req, sg, result, template[i].psize);
264 ret = wait_async_op(&tresult, crypto_ahash_digest(req));
266 pr_err("alg: hash: digest failed on test %d "
267 "for %s: ret=%d\n", j, algo, -ret);
271 ret = wait_async_op(&tresult, crypto_ahash_init(req));
273 pr_err("alt: hash: init failed on test %d "
274 "for %s: ret=%d\n", j, algo, -ret);
277 ret = wait_async_op(&tresult, crypto_ahash_update(req));
279 pr_err("alt: hash: update failed on test %d "
280 "for %s: ret=%d\n", j, algo, -ret);
283 ret = wait_async_op(&tresult, crypto_ahash_final(req));
285 pr_err("alt: hash: final failed on test %d "
286 "for %s: ret=%d\n", j, algo, -ret);
291 if (memcmp(result, template[i].digest,
292 crypto_ahash_digestsize(tfm))) {
293 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
295 hexdump(result, crypto_ahash_digestsize(tfm));
302 for (i = 0; i < tcount; i++) {
303 /* alignment tests are only done with continuous buffers */
304 if (align_offset != 0)
311 memset(result, 0, MAX_DIGEST_SIZE);
314 sg_init_table(sg, template[i].np);
316 for (k = 0; k < template[i].np; k++) {
317 if (WARN_ON(offset_in_page(IDX[k]) +
318 template[i].tap[k] > PAGE_SIZE))
321 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
322 offset_in_page(IDX[k]),
323 template[i].plaintext + temp,
326 temp += template[i].tap[k];
329 if (template[i].ksize) {
330 if (template[i].ksize > MAX_KEYLEN) {
331 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
332 j, algo, template[i].ksize, MAX_KEYLEN);
336 crypto_ahash_clear_flags(tfm, ~0);
337 memcpy(key, template[i].key, template[i].ksize);
338 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
341 printk(KERN_ERR "alg: hash: setkey "
342 "failed on chunking test %d "
343 "for %s: ret=%d\n", j, algo, -ret);
348 ahash_request_set_crypt(req, sg, result, template[i].psize);
349 ret = crypto_ahash_digest(req);
355 wait_for_completion(&tresult.completion);
356 reinit_completion(&tresult.completion);
362 printk(KERN_ERR "alg: hash: digest failed "
363 "on chunking test %d for %s: "
364 "ret=%d\n", j, algo, -ret);
368 if (memcmp(result, template[i].digest,
369 crypto_ahash_digestsize(tfm))) {
370 printk(KERN_ERR "alg: hash: Chunking test %d "
371 "failed for %s\n", j, algo);
372 hexdump(result, crypto_ahash_digestsize(tfm));
381 ahash_request_free(req);
383 testmgr_free_buf(xbuf);
390 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
391 unsigned int tcount, bool use_digest)
393 unsigned int alignmask;
396 ret = __test_hash(tfm, template, tcount, use_digest, 0);
400 /* test unaligned buffers, check with one byte offset */
401 ret = __test_hash(tfm, template, tcount, use_digest, 1);
405 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
407 /* Check if alignment mask for tfm is correctly set. */
408 ret = __test_hash(tfm, template, tcount, use_digest,
417 static int __test_aead(struct crypto_aead *tfm, int enc,
418 struct aead_testvec *template, unsigned int tcount,
419 const bool diff_dst, const int align_offset)
421 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
422 unsigned int i, j, k, n, temp;
426 struct aead_request *req;
427 struct scatterlist *sg;
428 struct scatterlist *asg;
429 struct scatterlist *sgout;
431 struct tcrypt_result result;
432 unsigned int authsize, iv_len;
437 char *xbuf[XBUFSIZE];
438 char *xoutbuf[XBUFSIZE];
439 char *axbuf[XBUFSIZE];
441 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
444 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
447 if (testmgr_alloc_buf(xbuf))
449 if (testmgr_alloc_buf(axbuf))
451 if (diff_dst && testmgr_alloc_buf(xoutbuf))
454 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
455 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
471 init_completion(&result.completion);
473 req = aead_request_alloc(tfm, GFP_KERNEL);
475 pr_err("alg: aead%s: Failed to allocate request for %s\n",
480 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
481 tcrypt_complete, &result);
483 for (i = 0, j = 0; i < tcount; i++) {
489 /* some templates have no input data but they will
493 input += align_offset;
497 if (WARN_ON(align_offset + template[i].ilen >
498 PAGE_SIZE || template[i].alen > PAGE_SIZE))
501 memcpy(input, template[i].input, template[i].ilen);
502 memcpy(assoc, template[i].assoc, template[i].alen);
503 iv_len = crypto_aead_ivsize(tfm);
505 memcpy(iv, template[i].iv, iv_len);
507 memset(iv, 0, iv_len);
509 crypto_aead_clear_flags(tfm, ~0);
511 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
513 if (template[i].klen > MAX_KEYLEN) {
514 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
515 d, j, algo, template[i].klen,
520 memcpy(key, template[i].key, template[i].klen);
522 ret = crypto_aead_setkey(tfm, key, template[i].klen);
523 if (!ret == template[i].fail) {
524 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
525 d, j, algo, crypto_aead_get_flags(tfm));
530 authsize = abs(template[i].rlen - template[i].ilen);
531 ret = crypto_aead_setauthsize(tfm, authsize);
533 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
534 d, authsize, j, algo);
540 output += align_offset;
541 sg_init_one(&sg[0], input, template[i].ilen);
542 sg_init_one(&sgout[0], output, template[i].rlen);
544 sg_init_one(&sg[0], input,
545 template[i].ilen + (enc ? authsize : 0));
549 sg_init_one(&asg[0], assoc, template[i].alen);
551 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
552 template[i].ilen, iv);
554 aead_request_set_assoc(req, asg, template[i].alen);
556 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
560 if (template[i].novrfy) {
561 /* verification was supposed to fail */
562 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
564 /* so really, we got a bad message */
571 wait_for_completion(&result.completion);
572 reinit_completion(&result.completion);
577 if (template[i].novrfy)
578 /* verification failure was expected */
582 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
583 d, e, j, algo, -ret);
588 if (memcmp(q, template[i].result, template[i].rlen)) {
589 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
591 hexdump(q, template[i].rlen);
597 for (i = 0, j = 0; i < tcount; i++) {
598 /* alignment tests are only done with continuous buffers */
599 if (align_offset != 0)
608 memcpy(iv, template[i].iv, MAX_IVLEN);
610 memset(iv, 0, MAX_IVLEN);
612 crypto_aead_clear_flags(tfm, ~0);
614 crypto_aead_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
615 if (template[i].klen > MAX_KEYLEN) {
616 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
617 d, j, algo, template[i].klen, MAX_KEYLEN);
621 memcpy(key, template[i].key, template[i].klen);
623 ret = crypto_aead_setkey(tfm, key, template[i].klen);
624 if (!ret == template[i].fail) {
625 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
626 d, j, algo, crypto_aead_get_flags(tfm));
631 authsize = abs(template[i].rlen - template[i].ilen);
634 sg_init_table(sg, template[i].np);
636 sg_init_table(sgout, template[i].np);
637 for (k = 0, temp = 0; k < template[i].np; k++) {
638 if (WARN_ON(offset_in_page(IDX[k]) +
639 template[i].tap[k] > PAGE_SIZE))
642 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
643 memcpy(q, template[i].input + temp, template[i].tap[k]);
644 sg_set_buf(&sg[k], q, template[i].tap[k]);
647 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
648 offset_in_page(IDX[k]);
650 memset(q, 0, template[i].tap[k]);
652 sg_set_buf(&sgout[k], q, template[i].tap[k]);
655 n = template[i].tap[k];
656 if (k == template[i].np - 1 && enc)
658 if (offset_in_page(q) + n < PAGE_SIZE)
661 temp += template[i].tap[k];
664 ret = crypto_aead_setauthsize(tfm, authsize);
666 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
667 d, authsize, j, algo);
672 if (WARN_ON(sg[k - 1].offset +
673 sg[k - 1].length + authsize >
680 sgout[k - 1].length += authsize;
682 sg[k - 1].length += authsize;
685 sg_init_table(asg, template[i].anp);
687 for (k = 0, temp = 0; k < template[i].anp; k++) {
688 if (WARN_ON(offset_in_page(IDX[k]) +
689 template[i].atap[k] > PAGE_SIZE))
692 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
693 offset_in_page(IDX[k]),
694 template[i].assoc + temp,
695 template[i].atap[k]),
696 template[i].atap[k]);
697 temp += template[i].atap[k];
700 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
704 aead_request_set_assoc(req, asg, template[i].alen);
706 ret = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);
710 if (template[i].novrfy) {
711 /* verification was supposed to fail */
712 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
714 /* so really, we got a bad message */
721 wait_for_completion(&result.completion);
722 reinit_completion(&result.completion);
727 if (template[i].novrfy)
728 /* verification failure was expected */
732 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
733 d, e, j, algo, -ret);
738 for (k = 0, temp = 0; k < template[i].np; k++) {
740 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
741 offset_in_page(IDX[k]);
743 q = xbuf[IDX[k] >> PAGE_SHIFT] +
744 offset_in_page(IDX[k]);
746 n = template[i].tap[k];
747 if (k == template[i].np - 1)
748 n += enc ? authsize : -authsize;
750 if (memcmp(q, template[i].result + temp, n)) {
751 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
758 if (k == template[i].np - 1 && !enc) {
760 memcmp(q, template[i].input +
766 for (n = 0; offset_in_page(q + n) && q[n]; n++)
770 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
771 d, j, e, k, algo, n);
776 temp += template[i].tap[k];
783 aead_request_free(req);
787 testmgr_free_buf(xoutbuf);
789 testmgr_free_buf(axbuf);
791 testmgr_free_buf(xbuf);
798 static int test_aead(struct crypto_aead *tfm, int enc,
799 struct aead_testvec *template, unsigned int tcount)
801 unsigned int alignmask;
804 /* test 'dst == src' case */
805 ret = __test_aead(tfm, enc, template, tcount, false, 0);
809 /* test 'dst != src' case */
810 ret = __test_aead(tfm, enc, template, tcount, true, 0);
814 /* test unaligned buffers, check with one byte offset */
815 ret = __test_aead(tfm, enc, template, tcount, true, 1);
819 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
821 /* Check if alignment mask for tfm is correctly set. */
822 ret = __test_aead(tfm, enc, template, tcount, true,
831 static int test_cipher(struct crypto_cipher *tfm, int enc,
832 struct cipher_testvec *template, unsigned int tcount)
834 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
835 unsigned int i, j, k;
839 char *xbuf[XBUFSIZE];
842 if (testmgr_alloc_buf(xbuf))
851 for (i = 0; i < tcount; i++) {
858 if (WARN_ON(template[i].ilen > PAGE_SIZE))
862 memcpy(data, template[i].input, template[i].ilen);
864 crypto_cipher_clear_flags(tfm, ~0);
866 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
868 ret = crypto_cipher_setkey(tfm, template[i].key,
870 if (!ret == template[i].fail) {
871 printk(KERN_ERR "alg: cipher: setkey failed "
872 "on test %d for %s: flags=%x\n", j,
873 algo, crypto_cipher_get_flags(tfm));
878 for (k = 0; k < template[i].ilen;
879 k += crypto_cipher_blocksize(tfm)) {
881 crypto_cipher_encrypt_one(tfm, data + k,
884 crypto_cipher_decrypt_one(tfm, data + k,
889 if (memcmp(q, template[i].result, template[i].rlen)) {
890 printk(KERN_ERR "alg: cipher: Test %d failed "
891 "on %s for %s\n", j, e, algo);
892 hexdump(q, template[i].rlen);
901 testmgr_free_buf(xbuf);
906 static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
907 struct cipher_testvec *template, unsigned int tcount,
908 const bool diff_dst, const int align_offset)
911 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
912 unsigned int i, j, k, n, temp;
914 struct ablkcipher_request *req;
915 struct scatterlist sg[8];
916 struct scatterlist sgout[8];
918 struct tcrypt_result result;
921 char *xbuf[XBUFSIZE];
922 char *xoutbuf[XBUFSIZE];
925 if (testmgr_alloc_buf(xbuf))
928 if (diff_dst && testmgr_alloc_buf(xoutbuf))
941 init_completion(&result.completion);
943 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
945 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
950 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
951 tcrypt_complete, &result);
954 for (i = 0; i < tcount; i++) {
955 if (template[i].np && !template[i].also_non_np)
959 memcpy(iv, template[i].iv, MAX_IVLEN);
961 memset(iv, 0, MAX_IVLEN);
965 if (WARN_ON(align_offset + template[i].ilen > PAGE_SIZE))
969 data += align_offset;
970 memcpy(data, template[i].input, template[i].ilen);
972 crypto_ablkcipher_clear_flags(tfm, ~0);
974 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
976 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
978 if (!ret == template[i].fail) {
979 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
980 d, j, algo, crypto_ablkcipher_get_flags(tfm));
985 sg_init_one(&sg[0], data, template[i].ilen);
988 data += align_offset;
989 sg_init_one(&sgout[0], data, template[i].ilen);
992 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
993 template[i].ilen, iv);
994 ret = enc ? crypto_ablkcipher_encrypt(req) :
995 crypto_ablkcipher_decrypt(req);
1002 wait_for_completion(&result.completion);
1003 reinit_completion(&result.completion);
1009 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1010 d, e, j, algo, -ret);
1015 if (memcmp(q, template[i].result, template[i].rlen)) {
1016 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1018 hexdump(q, template[i].rlen);
1025 for (i = 0; i < tcount; i++) {
1026 /* alignment tests are only done with continuous buffers */
1027 if (align_offset != 0)
1030 if (!template[i].np)
1034 memcpy(iv, template[i].iv, MAX_IVLEN);
1036 memset(iv, 0, MAX_IVLEN);
1039 crypto_ablkcipher_clear_flags(tfm, ~0);
1041 crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1043 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1045 if (!ret == template[i].fail) {
1046 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1047 d, j, algo, crypto_ablkcipher_get_flags(tfm));
1054 sg_init_table(sg, template[i].np);
1056 sg_init_table(sgout, template[i].np);
1057 for (k = 0; k < template[i].np; k++) {
1058 if (WARN_ON(offset_in_page(IDX[k]) +
1059 template[i].tap[k] > PAGE_SIZE))
1062 q = xbuf[IDX[k] >> PAGE_SHIFT] + offset_in_page(IDX[k]);
1064 memcpy(q, template[i].input + temp, template[i].tap[k]);
1066 if (offset_in_page(q) + template[i].tap[k] < PAGE_SIZE)
1067 q[template[i].tap[k]] = 0;
1069 sg_set_buf(&sg[k], q, template[i].tap[k]);
1071 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1072 offset_in_page(IDX[k]);
1074 sg_set_buf(&sgout[k], q, template[i].tap[k]);
1076 memset(q, 0, template[i].tap[k]);
1077 if (offset_in_page(q) +
1078 template[i].tap[k] < PAGE_SIZE)
1079 q[template[i].tap[k]] = 0;
1082 temp += template[i].tap[k];
1085 ablkcipher_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
1086 template[i].ilen, iv);
1088 ret = enc ? crypto_ablkcipher_encrypt(req) :
1089 crypto_ablkcipher_decrypt(req);
1096 wait_for_completion(&result.completion);
1097 reinit_completion(&result.completion);
1103 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1104 d, e, j, algo, -ret);
1110 for (k = 0; k < template[i].np; k++) {
1112 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1113 offset_in_page(IDX[k]);
1115 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1116 offset_in_page(IDX[k]);
1118 if (memcmp(q, template[i].result + temp,
1119 template[i].tap[k])) {
1120 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1122 hexdump(q, template[i].tap[k]);
1126 q += template[i].tap[k];
1127 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1130 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1131 d, j, e, k, algo, n);
1135 temp += template[i].tap[k];
1142 ablkcipher_request_free(req);
1144 testmgr_free_buf(xoutbuf);
1146 testmgr_free_buf(xbuf);
1151 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1152 struct cipher_testvec *template, unsigned int tcount)
1154 unsigned int alignmask;
1157 /* test 'dst == src' case */
1158 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
1162 /* test 'dst != src' case */
1163 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1167 /* test unaligned buffers, check with one byte offset */
1168 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1172 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1174 /* Check if alignment mask for tfm is correctly set. */
1175 ret = __test_skcipher(tfm, enc, template, tcount, true,
1184 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1185 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1187 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1189 char result[COMP_BUF_SIZE];
1192 for (i = 0; i < ctcount; i++) {
1194 unsigned int dlen = COMP_BUF_SIZE;
1196 memset(result, 0, sizeof (result));
1198 ilen = ctemplate[i].inlen;
1199 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1200 ilen, result, &dlen);
1202 printk(KERN_ERR "alg: comp: compression failed "
1203 "on test %d for %s: ret=%d\n", i + 1, algo,
1208 if (dlen != ctemplate[i].outlen) {
1209 printk(KERN_ERR "alg: comp: Compression test %d "
1210 "failed for %s: output len = %d\n", i + 1, algo,
1216 if (memcmp(result, ctemplate[i].output, dlen)) {
1217 printk(KERN_ERR "alg: comp: Compression test %d "
1218 "failed for %s\n", i + 1, algo);
1219 hexdump(result, dlen);
1225 for (i = 0; i < dtcount; i++) {
1227 unsigned int dlen = COMP_BUF_SIZE;
1229 memset(result, 0, sizeof (result));
1231 ilen = dtemplate[i].inlen;
1232 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1233 ilen, result, &dlen);
1235 printk(KERN_ERR "alg: comp: decompression failed "
1236 "on test %d for %s: ret=%d\n", i + 1, algo,
1241 if (dlen != dtemplate[i].outlen) {
1242 printk(KERN_ERR "alg: comp: Decompression test %d "
1243 "failed for %s: output len = %d\n", i + 1, algo,
1249 if (memcmp(result, dtemplate[i].output, dlen)) {
1250 printk(KERN_ERR "alg: comp: Decompression test %d "
1251 "failed for %s\n", i + 1, algo);
1252 hexdump(result, dlen);
1264 static int test_pcomp(struct crypto_pcomp *tfm,
1265 struct pcomp_testvec *ctemplate,
1266 struct pcomp_testvec *dtemplate, int ctcount,
1269 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1271 char result[COMP_BUF_SIZE];
1274 for (i = 0; i < ctcount; i++) {
1275 struct comp_request req;
1276 unsigned int produced = 0;
1278 res = crypto_compress_setup(tfm, ctemplate[i].params,
1279 ctemplate[i].paramsize);
1281 pr_err("alg: pcomp: compression setup failed on test "
1282 "%d for %s: error=%d\n", i + 1, algo, res);
1286 res = crypto_compress_init(tfm);
1288 pr_err("alg: pcomp: compression init failed on test "
1289 "%d for %s: error=%d\n", i + 1, algo, res);
1293 memset(result, 0, sizeof(result));
1295 req.next_in = ctemplate[i].input;
1296 req.avail_in = ctemplate[i].inlen / 2;
1297 req.next_out = result;
1298 req.avail_out = ctemplate[i].outlen / 2;
1300 res = crypto_compress_update(tfm, &req);
1301 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1302 pr_err("alg: pcomp: compression update failed on test "
1303 "%d for %s: error=%d\n", i + 1, algo, res);
1309 /* Add remaining input data */
1310 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1312 res = crypto_compress_update(tfm, &req);
1313 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1314 pr_err("alg: pcomp: compression update failed on test "
1315 "%d for %s: error=%d\n", i + 1, algo, res);
1321 /* Provide remaining output space */
1322 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1324 res = crypto_compress_final(tfm, &req);
1326 pr_err("alg: pcomp: compression final failed on test "
1327 "%d for %s: error=%d\n", i + 1, algo, res);
1332 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1333 pr_err("alg: comp: Compression test %d failed for %s: "
1334 "output len = %d (expected %d)\n", i + 1, algo,
1335 COMP_BUF_SIZE - req.avail_out,
1336 ctemplate[i].outlen);
1340 if (produced != ctemplate[i].outlen) {
1341 pr_err("alg: comp: Compression test %d failed for %s: "
1342 "returned len = %u (expected %d)\n", i + 1,
1343 algo, produced, ctemplate[i].outlen);
1347 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1348 pr_err("alg: pcomp: Compression test %d failed for "
1349 "%s\n", i + 1, algo);
1350 hexdump(result, ctemplate[i].outlen);
1355 for (i = 0; i < dtcount; i++) {
1356 struct comp_request req;
1357 unsigned int produced = 0;
1359 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1360 dtemplate[i].paramsize);
1362 pr_err("alg: pcomp: decompression setup failed on "
1363 "test %d for %s: error=%d\n", i + 1, algo, res);
1367 res = crypto_decompress_init(tfm);
1369 pr_err("alg: pcomp: decompression init failed on test "
1370 "%d for %s: error=%d\n", i + 1, algo, res);
1374 memset(result, 0, sizeof(result));
1376 req.next_in = dtemplate[i].input;
1377 req.avail_in = dtemplate[i].inlen / 2;
1378 req.next_out = result;
1379 req.avail_out = dtemplate[i].outlen / 2;
1381 res = crypto_decompress_update(tfm, &req);
1382 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1383 pr_err("alg: pcomp: decompression update failed on "
1384 "test %d for %s: error=%d\n", i + 1, algo, res);
1390 /* Add remaining input data */
1391 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1393 res = crypto_decompress_update(tfm, &req);
1394 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1395 pr_err("alg: pcomp: decompression update failed on "
1396 "test %d for %s: error=%d\n", i + 1, algo, res);
1402 /* Provide remaining output space */
1403 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1405 res = crypto_decompress_final(tfm, &req);
1406 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1407 pr_err("alg: pcomp: decompression final failed on "
1408 "test %d for %s: error=%d\n", i + 1, algo, res);
1414 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1415 pr_err("alg: comp: Decompression test %d failed for "
1416 "%s: output len = %d (expected %d)\n", i + 1,
1417 algo, COMP_BUF_SIZE - req.avail_out,
1418 dtemplate[i].outlen);
1422 if (produced != dtemplate[i].outlen) {
1423 pr_err("alg: comp: Decompression test %d failed for "
1424 "%s: returned len = %u (expected %d)\n", i + 1,
1425 algo, produced, dtemplate[i].outlen);
1429 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1430 pr_err("alg: pcomp: Decompression test %d failed for "
1431 "%s\n", i + 1, algo);
1432 hexdump(result, dtemplate[i].outlen);
1441 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1442 unsigned int tcount)
1444 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1445 int err = 0, i, j, seedsize;
1449 seedsize = crypto_rng_seedsize(tfm);
1451 seed = kmalloc(seedsize, GFP_KERNEL);
1453 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1458 for (i = 0; i < tcount; i++) {
1459 memset(result, 0, 32);
1461 memcpy(seed, template[i].v, template[i].vlen);
1462 memcpy(seed + template[i].vlen, template[i].key,
1464 memcpy(seed + template[i].vlen + template[i].klen,
1465 template[i].dt, template[i].dtlen);
1467 err = crypto_rng_reset(tfm, seed, seedsize);
1469 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1474 for (j = 0; j < template[i].loops; j++) {
1475 err = crypto_rng_get_bytes(tfm, result,
1478 printk(KERN_ERR "alg: cprng: Failed to obtain "
1479 "the correct amount of random data for "
1480 "%s (requested %d)\n", algo,
1486 err = memcmp(result, template[i].result,
1489 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1491 hexdump(result, template[i].rlen);
1502 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1505 struct crypto_aead *tfm;
1508 tfm = crypto_alloc_aead(driver, type | CRYPTO_ALG_INTERNAL, mask);
1510 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1511 "%ld\n", driver, PTR_ERR(tfm));
1512 return PTR_ERR(tfm);
1515 if (desc->suite.aead.enc.vecs) {
1516 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1517 desc->suite.aead.enc.count);
1522 if (!err && desc->suite.aead.dec.vecs)
1523 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1524 desc->suite.aead.dec.count);
1527 crypto_free_aead(tfm);
1531 static int alg_test_cipher(const struct alg_test_desc *desc,
1532 const char *driver, u32 type, u32 mask)
1534 struct crypto_cipher *tfm;
1537 tfm = crypto_alloc_cipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1539 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1540 "%s: %ld\n", driver, PTR_ERR(tfm));
1541 return PTR_ERR(tfm);
1544 if (desc->suite.cipher.enc.vecs) {
1545 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1546 desc->suite.cipher.enc.count);
1551 if (desc->suite.cipher.dec.vecs)
1552 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1553 desc->suite.cipher.dec.count);
1556 crypto_free_cipher(tfm);
1560 static int alg_test_skcipher(const struct alg_test_desc *desc,
1561 const char *driver, u32 type, u32 mask)
1563 struct crypto_ablkcipher *tfm;
1566 tfm = crypto_alloc_ablkcipher(driver, type | CRYPTO_ALG_INTERNAL, mask);
1568 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1569 "%s: %ld\n", driver, PTR_ERR(tfm));
1570 return PTR_ERR(tfm);
1573 if (desc->suite.cipher.enc.vecs) {
1574 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1575 desc->suite.cipher.enc.count);
1580 if (desc->suite.cipher.dec.vecs)
1581 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1582 desc->suite.cipher.dec.count);
1585 crypto_free_ablkcipher(tfm);
1589 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1592 struct crypto_comp *tfm;
1595 tfm = crypto_alloc_comp(driver, type, mask);
1597 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1598 "%ld\n", driver, PTR_ERR(tfm));
1599 return PTR_ERR(tfm);
1602 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1603 desc->suite.comp.decomp.vecs,
1604 desc->suite.comp.comp.count,
1605 desc->suite.comp.decomp.count);
1607 crypto_free_comp(tfm);
1611 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1614 struct crypto_pcomp *tfm;
1617 tfm = crypto_alloc_pcomp(driver, type, mask);
1619 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1620 driver, PTR_ERR(tfm));
1621 return PTR_ERR(tfm);
1624 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1625 desc->suite.pcomp.decomp.vecs,
1626 desc->suite.pcomp.comp.count,
1627 desc->suite.pcomp.decomp.count);
1629 crypto_free_pcomp(tfm);
1633 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1636 struct crypto_ahash *tfm;
1639 tfm = crypto_alloc_ahash(driver, type | CRYPTO_ALG_INTERNAL, mask);
1641 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1642 "%ld\n", driver, PTR_ERR(tfm));
1643 return PTR_ERR(tfm);
1646 err = test_hash(tfm, desc->suite.hash.vecs,
1647 desc->suite.hash.count, true);
1649 err = test_hash(tfm, desc->suite.hash.vecs,
1650 desc->suite.hash.count, false);
1652 crypto_free_ahash(tfm);
1656 static int alg_test_crc32c(const struct alg_test_desc *desc,
1657 const char *driver, u32 type, u32 mask)
1659 struct crypto_shash *tfm;
1663 err = alg_test_hash(desc, driver, type, mask);
1667 tfm = crypto_alloc_shash(driver, type | CRYPTO_ALG_INTERNAL, mask);
1669 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1670 "%ld\n", driver, PTR_ERR(tfm));
1676 SHASH_DESC_ON_STACK(shash, tfm);
1677 u32 *ctx = (u32 *)shash_desc_ctx(shash);
1682 *ctx = le32_to_cpu(420553207);
1683 err = crypto_shash_final(shash, (u8 *)&val);
1685 printk(KERN_ERR "alg: crc32c: Operation failed for "
1686 "%s: %d\n", driver, err);
1690 if (val != ~420553207) {
1691 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1692 "%d\n", driver, val);
1697 crypto_free_shash(tfm);
1703 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1706 struct crypto_rng *rng;
1709 rng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
1711 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1712 "%ld\n", driver, PTR_ERR(rng));
1713 return PTR_ERR(rng);
1716 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1718 crypto_free_rng(rng);
1724 static int drbg_cavs_test(struct drbg_testvec *test, int pr,
1725 const char *driver, u32 type, u32 mask)
1728 struct crypto_rng *drng;
1729 struct drbg_test_data test_data;
1730 struct drbg_string addtl, pers, testentropy;
1731 unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
1736 drng = crypto_alloc_rng(driver, type | CRYPTO_ALG_INTERNAL, mask);
1738 printk(KERN_ERR "alg: drbg: could not allocate DRNG handle for "
1744 test_data.testentropy = &testentropy;
1745 drbg_string_fill(&testentropy, test->entropy, test->entropylen);
1746 drbg_string_fill(&pers, test->pers, test->perslen);
1747 ret = crypto_drbg_reset_test(drng, &pers, &test_data);
1749 printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
1753 drbg_string_fill(&addtl, test->addtla, test->addtllen);
1755 drbg_string_fill(&testentropy, test->entpra, test->entprlen);
1756 ret = crypto_drbg_get_bytes_addtl_test(drng,
1757 buf, test->expectedlen, &addtl, &test_data);
1759 ret = crypto_drbg_get_bytes_addtl(drng,
1760 buf, test->expectedlen, &addtl);
1763 printk(KERN_ERR "alg: drbg: could not obtain random data for "
1764 "driver %s\n", driver);
1768 drbg_string_fill(&addtl, test->addtlb, test->addtllen);
1770 drbg_string_fill(&testentropy, test->entprb, test->entprlen);
1771 ret = crypto_drbg_get_bytes_addtl_test(drng,
1772 buf, test->expectedlen, &addtl, &test_data);
1774 ret = crypto_drbg_get_bytes_addtl(drng,
1775 buf, test->expectedlen, &addtl);
1778 printk(KERN_ERR "alg: drbg: could not obtain random data for "
1779 "driver %s\n", driver);
1783 ret = memcmp(test->expected, buf, test->expectedlen);
1786 crypto_free_rng(drng);
1792 static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
1798 struct drbg_testvec *template = desc->suite.drbg.vecs;
1799 unsigned int tcount = desc->suite.drbg.count;
1801 if (0 == memcmp(driver, "drbg_pr_", 8))
1804 for (i = 0; i < tcount; i++) {
1805 err = drbg_cavs_test(&template[i], pr, driver, type, mask);
1807 printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
1817 static int alg_test_null(const struct alg_test_desc *desc,
1818 const char *driver, u32 type, u32 mask)
1823 /* Please keep this list sorted by algorithm name. */
1824 static const struct alg_test_desc alg_test_descs[] = {
1826 .alg = "__cbc-cast5-avx",
1827 .test = alg_test_null,
1829 .alg = "__cbc-cast6-avx",
1830 .test = alg_test_null,
1832 .alg = "__cbc-serpent-avx",
1833 .test = alg_test_null,
1835 .alg = "__cbc-serpent-avx2",
1836 .test = alg_test_null,
1838 .alg = "__cbc-serpent-sse2",
1839 .test = alg_test_null,
1841 .alg = "__cbc-twofish-avx",
1842 .test = alg_test_null,
1844 .alg = "__driver-cbc-aes-aesni",
1845 .test = alg_test_null,
1848 .alg = "__driver-cbc-camellia-aesni",
1849 .test = alg_test_null,
1851 .alg = "__driver-cbc-camellia-aesni-avx2",
1852 .test = alg_test_null,
1854 .alg = "__driver-cbc-cast5-avx",
1855 .test = alg_test_null,
1857 .alg = "__driver-cbc-cast6-avx",
1858 .test = alg_test_null,
1860 .alg = "__driver-cbc-serpent-avx",
1861 .test = alg_test_null,
1863 .alg = "__driver-cbc-serpent-avx2",
1864 .test = alg_test_null,
1866 .alg = "__driver-cbc-serpent-sse2",
1867 .test = alg_test_null,
1869 .alg = "__driver-cbc-twofish-avx",
1870 .test = alg_test_null,
1872 .alg = "__driver-ecb-aes-aesni",
1873 .test = alg_test_null,
1876 .alg = "__driver-ecb-camellia-aesni",
1877 .test = alg_test_null,
1879 .alg = "__driver-ecb-camellia-aesni-avx2",
1880 .test = alg_test_null,
1882 .alg = "__driver-ecb-cast5-avx",
1883 .test = alg_test_null,
1885 .alg = "__driver-ecb-cast6-avx",
1886 .test = alg_test_null,
1888 .alg = "__driver-ecb-serpent-avx",
1889 .test = alg_test_null,
1891 .alg = "__driver-ecb-serpent-avx2",
1892 .test = alg_test_null,
1894 .alg = "__driver-ecb-serpent-sse2",
1895 .test = alg_test_null,
1897 .alg = "__driver-ecb-twofish-avx",
1898 .test = alg_test_null,
1900 .alg = "__ghash-pclmulqdqni",
1901 .test = alg_test_null,
1904 .alg = "ansi_cprng",
1905 .test = alg_test_cprng,
1909 .vecs = ansi_cprng_aes_tv_template,
1910 .count = ANSI_CPRNG_AES_TEST_VECTORS
1914 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1915 .test = alg_test_aead,
1920 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1921 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1924 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1925 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1930 .alg = "authenc(hmac(sha1),cbc(aes))",
1931 .test = alg_test_aead,
1937 hmac_sha1_aes_cbc_enc_tv_temp,
1939 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1944 .alg = "authenc(hmac(sha1),cbc(des))",
1945 .test = alg_test_aead,
1951 hmac_sha1_des_cbc_enc_tv_temp,
1953 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1958 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1959 .test = alg_test_aead,
1965 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1967 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
1972 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1973 .test = alg_test_aead,
1979 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1981 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
1985 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1987 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1992 .alg = "authenc(hmac(sha224),cbc(des))",
1993 .test = alg_test_aead,
1999 hmac_sha224_des_cbc_enc_tv_temp,
2001 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
2006 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
2007 .test = alg_test_aead,
2013 hmac_sha224_des3_ede_cbc_enc_tv_temp,
2015 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
2020 .alg = "authenc(hmac(sha256),cbc(aes))",
2021 .test = alg_test_aead,
2027 hmac_sha256_aes_cbc_enc_tv_temp,
2029 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
2034 .alg = "authenc(hmac(sha256),cbc(des))",
2035 .test = alg_test_aead,
2041 hmac_sha256_des_cbc_enc_tv_temp,
2043 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
2048 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
2049 .test = alg_test_aead,
2055 hmac_sha256_des3_ede_cbc_enc_tv_temp,
2057 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
2062 .alg = "authenc(hmac(sha384),cbc(des))",
2063 .test = alg_test_aead,
2069 hmac_sha384_des_cbc_enc_tv_temp,
2071 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
2076 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
2077 .test = alg_test_aead,
2083 hmac_sha384_des3_ede_cbc_enc_tv_temp,
2085 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
2090 .alg = "authenc(hmac(sha512),cbc(aes))",
2091 .test = alg_test_aead,
2097 hmac_sha512_aes_cbc_enc_tv_temp,
2099 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2104 .alg = "authenc(hmac(sha512),cbc(des))",
2105 .test = alg_test_aead,
2111 hmac_sha512_des_cbc_enc_tv_temp,
2113 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2118 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2119 .test = alg_test_aead,
2125 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2127 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2133 .test = alg_test_skcipher,
2138 .vecs = aes_cbc_enc_tv_template,
2139 .count = AES_CBC_ENC_TEST_VECTORS
2142 .vecs = aes_cbc_dec_tv_template,
2143 .count = AES_CBC_DEC_TEST_VECTORS
2148 .alg = "cbc(anubis)",
2149 .test = alg_test_skcipher,
2153 .vecs = anubis_cbc_enc_tv_template,
2154 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2157 .vecs = anubis_cbc_dec_tv_template,
2158 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2163 .alg = "cbc(blowfish)",
2164 .test = alg_test_skcipher,
2168 .vecs = bf_cbc_enc_tv_template,
2169 .count = BF_CBC_ENC_TEST_VECTORS
2172 .vecs = bf_cbc_dec_tv_template,
2173 .count = BF_CBC_DEC_TEST_VECTORS
2178 .alg = "cbc(camellia)",
2179 .test = alg_test_skcipher,
2183 .vecs = camellia_cbc_enc_tv_template,
2184 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2187 .vecs = camellia_cbc_dec_tv_template,
2188 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2193 .alg = "cbc(cast5)",
2194 .test = alg_test_skcipher,
2198 .vecs = cast5_cbc_enc_tv_template,
2199 .count = CAST5_CBC_ENC_TEST_VECTORS
2202 .vecs = cast5_cbc_dec_tv_template,
2203 .count = CAST5_CBC_DEC_TEST_VECTORS
2208 .alg = "cbc(cast6)",
2209 .test = alg_test_skcipher,
2213 .vecs = cast6_cbc_enc_tv_template,
2214 .count = CAST6_CBC_ENC_TEST_VECTORS
2217 .vecs = cast6_cbc_dec_tv_template,
2218 .count = CAST6_CBC_DEC_TEST_VECTORS
2224 .test = alg_test_skcipher,
2228 .vecs = des_cbc_enc_tv_template,
2229 .count = DES_CBC_ENC_TEST_VECTORS
2232 .vecs = des_cbc_dec_tv_template,
2233 .count = DES_CBC_DEC_TEST_VECTORS
2238 .alg = "cbc(des3_ede)",
2239 .test = alg_test_skcipher,
2244 .vecs = des3_ede_cbc_enc_tv_template,
2245 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2248 .vecs = des3_ede_cbc_dec_tv_template,
2249 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2254 .alg = "cbc(serpent)",
2255 .test = alg_test_skcipher,
2259 .vecs = serpent_cbc_enc_tv_template,
2260 .count = SERPENT_CBC_ENC_TEST_VECTORS
2263 .vecs = serpent_cbc_dec_tv_template,
2264 .count = SERPENT_CBC_DEC_TEST_VECTORS
2269 .alg = "cbc(twofish)",
2270 .test = alg_test_skcipher,
2274 .vecs = tf_cbc_enc_tv_template,
2275 .count = TF_CBC_ENC_TEST_VECTORS
2278 .vecs = tf_cbc_dec_tv_template,
2279 .count = TF_CBC_DEC_TEST_VECTORS
2285 .test = alg_test_aead,
2290 .vecs = aes_ccm_enc_tv_template,
2291 .count = AES_CCM_ENC_TEST_VECTORS
2294 .vecs = aes_ccm_dec_tv_template,
2295 .count = AES_CCM_DEC_TEST_VECTORS
2301 .test = alg_test_hash,
2304 .vecs = aes_cmac128_tv_template,
2305 .count = CMAC_AES_TEST_VECTORS
2309 .alg = "cmac(des3_ede)",
2310 .test = alg_test_hash,
2313 .vecs = des3_ede_cmac64_tv_template,
2314 .count = CMAC_DES3_EDE_TEST_VECTORS
2318 .alg = "compress_null",
2319 .test = alg_test_null,
2322 .test = alg_test_crc32c,
2326 .vecs = crc32c_tv_template,
2327 .count = CRC32C_TEST_VECTORS
2332 .test = alg_test_hash,
2336 .vecs = crct10dif_tv_template,
2337 .count = CRCT10DIF_TEST_VECTORS
2341 .alg = "cryptd(__driver-cbc-aes-aesni)",
2342 .test = alg_test_null,
2345 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2346 .test = alg_test_null,
2348 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2349 .test = alg_test_null,
2351 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2352 .test = alg_test_null,
2354 .alg = "cryptd(__driver-ecb-aes-aesni)",
2355 .test = alg_test_null,
2358 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2359 .test = alg_test_null,
2361 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2362 .test = alg_test_null,
2364 .alg = "cryptd(__driver-ecb-cast5-avx)",
2365 .test = alg_test_null,
2367 .alg = "cryptd(__driver-ecb-cast6-avx)",
2368 .test = alg_test_null,
2370 .alg = "cryptd(__driver-ecb-serpent-avx)",
2371 .test = alg_test_null,
2373 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2374 .test = alg_test_null,
2376 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2377 .test = alg_test_null,
2379 .alg = "cryptd(__driver-ecb-twofish-avx)",
2380 .test = alg_test_null,
2382 .alg = "cryptd(__driver-gcm-aes-aesni)",
2383 .test = alg_test_null,
2386 .alg = "cryptd(__ghash-pclmulqdqni)",
2387 .test = alg_test_null,
2391 .test = alg_test_skcipher,
2396 .vecs = aes_ctr_enc_tv_template,
2397 .count = AES_CTR_ENC_TEST_VECTORS
2400 .vecs = aes_ctr_dec_tv_template,
2401 .count = AES_CTR_DEC_TEST_VECTORS
2406 .alg = "ctr(blowfish)",
2407 .test = alg_test_skcipher,
2411 .vecs = bf_ctr_enc_tv_template,
2412 .count = BF_CTR_ENC_TEST_VECTORS
2415 .vecs = bf_ctr_dec_tv_template,
2416 .count = BF_CTR_DEC_TEST_VECTORS
2421 .alg = "ctr(camellia)",
2422 .test = alg_test_skcipher,
2426 .vecs = camellia_ctr_enc_tv_template,
2427 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2430 .vecs = camellia_ctr_dec_tv_template,
2431 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2436 .alg = "ctr(cast5)",
2437 .test = alg_test_skcipher,
2441 .vecs = cast5_ctr_enc_tv_template,
2442 .count = CAST5_CTR_ENC_TEST_VECTORS
2445 .vecs = cast5_ctr_dec_tv_template,
2446 .count = CAST5_CTR_DEC_TEST_VECTORS
2451 .alg = "ctr(cast6)",
2452 .test = alg_test_skcipher,
2456 .vecs = cast6_ctr_enc_tv_template,
2457 .count = CAST6_CTR_ENC_TEST_VECTORS
2460 .vecs = cast6_ctr_dec_tv_template,
2461 .count = CAST6_CTR_DEC_TEST_VECTORS
2467 .test = alg_test_skcipher,
2471 .vecs = des_ctr_enc_tv_template,
2472 .count = DES_CTR_ENC_TEST_VECTORS
2475 .vecs = des_ctr_dec_tv_template,
2476 .count = DES_CTR_DEC_TEST_VECTORS
2481 .alg = "ctr(des3_ede)",
2482 .test = alg_test_skcipher,
2486 .vecs = des3_ede_ctr_enc_tv_template,
2487 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2490 .vecs = des3_ede_ctr_dec_tv_template,
2491 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2496 .alg = "ctr(serpent)",
2497 .test = alg_test_skcipher,
2501 .vecs = serpent_ctr_enc_tv_template,
2502 .count = SERPENT_CTR_ENC_TEST_VECTORS
2505 .vecs = serpent_ctr_dec_tv_template,
2506 .count = SERPENT_CTR_DEC_TEST_VECTORS
2511 .alg = "ctr(twofish)",
2512 .test = alg_test_skcipher,
2516 .vecs = tf_ctr_enc_tv_template,
2517 .count = TF_CTR_ENC_TEST_VECTORS
2520 .vecs = tf_ctr_dec_tv_template,
2521 .count = TF_CTR_DEC_TEST_VECTORS
2526 .alg = "cts(cbc(aes))",
2527 .test = alg_test_skcipher,
2531 .vecs = cts_mode_enc_tv_template,
2532 .count = CTS_MODE_ENC_TEST_VECTORS
2535 .vecs = cts_mode_dec_tv_template,
2536 .count = CTS_MODE_DEC_TEST_VECTORS
2542 .test = alg_test_comp,
2547 .vecs = deflate_comp_tv_template,
2548 .count = DEFLATE_COMP_TEST_VECTORS
2551 .vecs = deflate_decomp_tv_template,
2552 .count = DEFLATE_DECOMP_TEST_VECTORS
2557 .alg = "digest_null",
2558 .test = alg_test_null,
2560 .alg = "drbg_nopr_ctr_aes128",
2561 .test = alg_test_drbg,
2565 .vecs = drbg_nopr_ctr_aes128_tv_template,
2566 .count = ARRAY_SIZE(drbg_nopr_ctr_aes128_tv_template)
2570 .alg = "drbg_nopr_ctr_aes192",
2571 .test = alg_test_drbg,
2575 .vecs = drbg_nopr_ctr_aes192_tv_template,
2576 .count = ARRAY_SIZE(drbg_nopr_ctr_aes192_tv_template)
2580 .alg = "drbg_nopr_ctr_aes256",
2581 .test = alg_test_drbg,
2585 .vecs = drbg_nopr_ctr_aes256_tv_template,
2586 .count = ARRAY_SIZE(drbg_nopr_ctr_aes256_tv_template)
2591 * There is no need to specifically test the DRBG with every
2592 * backend cipher -- covered by drbg_nopr_hmac_sha256 test
2594 .alg = "drbg_nopr_hmac_sha1",
2596 .test = alg_test_null,
2598 .alg = "drbg_nopr_hmac_sha256",
2599 .test = alg_test_drbg,
2603 .vecs = drbg_nopr_hmac_sha256_tv_template,
2605 ARRAY_SIZE(drbg_nopr_hmac_sha256_tv_template)
2609 /* covered by drbg_nopr_hmac_sha256 test */
2610 .alg = "drbg_nopr_hmac_sha384",
2612 .test = alg_test_null,
2614 .alg = "drbg_nopr_hmac_sha512",
2615 .test = alg_test_null,
2618 .alg = "drbg_nopr_sha1",
2620 .test = alg_test_null,
2622 .alg = "drbg_nopr_sha256",
2623 .test = alg_test_drbg,
2627 .vecs = drbg_nopr_sha256_tv_template,
2628 .count = ARRAY_SIZE(drbg_nopr_sha256_tv_template)
2632 /* covered by drbg_nopr_sha256 test */
2633 .alg = "drbg_nopr_sha384",
2635 .test = alg_test_null,
2637 .alg = "drbg_nopr_sha512",
2639 .test = alg_test_null,
2641 .alg = "drbg_pr_ctr_aes128",
2642 .test = alg_test_drbg,
2646 .vecs = drbg_pr_ctr_aes128_tv_template,
2647 .count = ARRAY_SIZE(drbg_pr_ctr_aes128_tv_template)
2651 /* covered by drbg_pr_ctr_aes128 test */
2652 .alg = "drbg_pr_ctr_aes192",
2654 .test = alg_test_null,
2656 .alg = "drbg_pr_ctr_aes256",
2658 .test = alg_test_null,
2660 .alg = "drbg_pr_hmac_sha1",
2662 .test = alg_test_null,
2664 .alg = "drbg_pr_hmac_sha256",
2665 .test = alg_test_drbg,
2669 .vecs = drbg_pr_hmac_sha256_tv_template,
2670 .count = ARRAY_SIZE(drbg_pr_hmac_sha256_tv_template)
2674 /* covered by drbg_pr_hmac_sha256 test */
2675 .alg = "drbg_pr_hmac_sha384",
2677 .test = alg_test_null,
2679 .alg = "drbg_pr_hmac_sha512",
2680 .test = alg_test_null,
2683 .alg = "drbg_pr_sha1",
2685 .test = alg_test_null,
2687 .alg = "drbg_pr_sha256",
2688 .test = alg_test_drbg,
2692 .vecs = drbg_pr_sha256_tv_template,
2693 .count = ARRAY_SIZE(drbg_pr_sha256_tv_template)
2697 /* covered by drbg_pr_sha256 test */
2698 .alg = "drbg_pr_sha384",
2700 .test = alg_test_null,
2702 .alg = "drbg_pr_sha512",
2704 .test = alg_test_null,
2706 .alg = "ecb(__aes-aesni)",
2707 .test = alg_test_null,
2711 .test = alg_test_skcipher,
2716 .vecs = aes_enc_tv_template,
2717 .count = AES_ENC_TEST_VECTORS
2720 .vecs = aes_dec_tv_template,
2721 .count = AES_DEC_TEST_VECTORS
2726 .alg = "ecb(anubis)",
2727 .test = alg_test_skcipher,
2731 .vecs = anubis_enc_tv_template,
2732 .count = ANUBIS_ENC_TEST_VECTORS
2735 .vecs = anubis_dec_tv_template,
2736 .count = ANUBIS_DEC_TEST_VECTORS
2742 .test = alg_test_skcipher,
2746 .vecs = arc4_enc_tv_template,
2747 .count = ARC4_ENC_TEST_VECTORS
2750 .vecs = arc4_dec_tv_template,
2751 .count = ARC4_DEC_TEST_VECTORS
2756 .alg = "ecb(blowfish)",
2757 .test = alg_test_skcipher,
2761 .vecs = bf_enc_tv_template,
2762 .count = BF_ENC_TEST_VECTORS
2765 .vecs = bf_dec_tv_template,
2766 .count = BF_DEC_TEST_VECTORS
2771 .alg = "ecb(camellia)",
2772 .test = alg_test_skcipher,
2776 .vecs = camellia_enc_tv_template,
2777 .count = CAMELLIA_ENC_TEST_VECTORS
2780 .vecs = camellia_dec_tv_template,
2781 .count = CAMELLIA_DEC_TEST_VECTORS
2786 .alg = "ecb(cast5)",
2787 .test = alg_test_skcipher,
2791 .vecs = cast5_enc_tv_template,
2792 .count = CAST5_ENC_TEST_VECTORS
2795 .vecs = cast5_dec_tv_template,
2796 .count = CAST5_DEC_TEST_VECTORS
2801 .alg = "ecb(cast6)",
2802 .test = alg_test_skcipher,
2806 .vecs = cast6_enc_tv_template,
2807 .count = CAST6_ENC_TEST_VECTORS
2810 .vecs = cast6_dec_tv_template,
2811 .count = CAST6_DEC_TEST_VECTORS
2816 .alg = "ecb(cipher_null)",
2817 .test = alg_test_null,
2820 .test = alg_test_skcipher,
2825 .vecs = des_enc_tv_template,
2826 .count = DES_ENC_TEST_VECTORS
2829 .vecs = des_dec_tv_template,
2830 .count = DES_DEC_TEST_VECTORS
2835 .alg = "ecb(des3_ede)",
2836 .test = alg_test_skcipher,
2841 .vecs = des3_ede_enc_tv_template,
2842 .count = DES3_EDE_ENC_TEST_VECTORS
2845 .vecs = des3_ede_dec_tv_template,
2846 .count = DES3_EDE_DEC_TEST_VECTORS
2851 .alg = "ecb(fcrypt)",
2852 .test = alg_test_skcipher,
2856 .vecs = fcrypt_pcbc_enc_tv_template,
2860 .vecs = fcrypt_pcbc_dec_tv_template,
2866 .alg = "ecb(khazad)",
2867 .test = alg_test_skcipher,
2871 .vecs = khazad_enc_tv_template,
2872 .count = KHAZAD_ENC_TEST_VECTORS
2875 .vecs = khazad_dec_tv_template,
2876 .count = KHAZAD_DEC_TEST_VECTORS
2882 .test = alg_test_skcipher,
2886 .vecs = seed_enc_tv_template,
2887 .count = SEED_ENC_TEST_VECTORS
2890 .vecs = seed_dec_tv_template,
2891 .count = SEED_DEC_TEST_VECTORS
2896 .alg = "ecb(serpent)",
2897 .test = alg_test_skcipher,
2901 .vecs = serpent_enc_tv_template,
2902 .count = SERPENT_ENC_TEST_VECTORS
2905 .vecs = serpent_dec_tv_template,
2906 .count = SERPENT_DEC_TEST_VECTORS
2912 .test = alg_test_skcipher,
2916 .vecs = tea_enc_tv_template,
2917 .count = TEA_ENC_TEST_VECTORS
2920 .vecs = tea_dec_tv_template,
2921 .count = TEA_DEC_TEST_VECTORS
2926 .alg = "ecb(tnepres)",
2927 .test = alg_test_skcipher,
2931 .vecs = tnepres_enc_tv_template,
2932 .count = TNEPRES_ENC_TEST_VECTORS
2935 .vecs = tnepres_dec_tv_template,
2936 .count = TNEPRES_DEC_TEST_VECTORS
2941 .alg = "ecb(twofish)",
2942 .test = alg_test_skcipher,
2946 .vecs = tf_enc_tv_template,
2947 .count = TF_ENC_TEST_VECTORS
2950 .vecs = tf_dec_tv_template,
2951 .count = TF_DEC_TEST_VECTORS
2957 .test = alg_test_skcipher,
2961 .vecs = xeta_enc_tv_template,
2962 .count = XETA_ENC_TEST_VECTORS
2965 .vecs = xeta_dec_tv_template,
2966 .count = XETA_DEC_TEST_VECTORS
2972 .test = alg_test_skcipher,
2976 .vecs = xtea_enc_tv_template,
2977 .count = XTEA_ENC_TEST_VECTORS
2980 .vecs = xtea_dec_tv_template,
2981 .count = XTEA_DEC_TEST_VECTORS
2987 .test = alg_test_aead,
2992 .vecs = aes_gcm_enc_tv_template,
2993 .count = AES_GCM_ENC_TEST_VECTORS
2996 .vecs = aes_gcm_dec_tv_template,
2997 .count = AES_GCM_DEC_TEST_VECTORS
3003 .test = alg_test_hash,
3007 .vecs = ghash_tv_template,
3008 .count = GHASH_TEST_VECTORS
3012 .alg = "hmac(crc32)",
3013 .test = alg_test_hash,
3016 .vecs = bfin_crc_tv_template,
3017 .count = BFIN_CRC_TEST_VECTORS
3022 .test = alg_test_hash,
3025 .vecs = hmac_md5_tv_template,
3026 .count = HMAC_MD5_TEST_VECTORS
3030 .alg = "hmac(rmd128)",
3031 .test = alg_test_hash,
3034 .vecs = hmac_rmd128_tv_template,
3035 .count = HMAC_RMD128_TEST_VECTORS
3039 .alg = "hmac(rmd160)",
3040 .test = alg_test_hash,
3043 .vecs = hmac_rmd160_tv_template,
3044 .count = HMAC_RMD160_TEST_VECTORS
3048 .alg = "hmac(sha1)",
3049 .test = alg_test_hash,
3053 .vecs = hmac_sha1_tv_template,
3054 .count = HMAC_SHA1_TEST_VECTORS
3058 .alg = "hmac(sha224)",
3059 .test = alg_test_hash,
3063 .vecs = hmac_sha224_tv_template,
3064 .count = HMAC_SHA224_TEST_VECTORS
3068 .alg = "hmac(sha256)",
3069 .test = alg_test_hash,
3073 .vecs = hmac_sha256_tv_template,
3074 .count = HMAC_SHA256_TEST_VECTORS
3078 .alg = "hmac(sha384)",
3079 .test = alg_test_hash,
3083 .vecs = hmac_sha384_tv_template,
3084 .count = HMAC_SHA384_TEST_VECTORS
3088 .alg = "hmac(sha512)",
3089 .test = alg_test_hash,
3093 .vecs = hmac_sha512_tv_template,
3094 .count = HMAC_SHA512_TEST_VECTORS
3099 .test = alg_test_skcipher,
3103 .vecs = aes_lrw_enc_tv_template,
3104 .count = AES_LRW_ENC_TEST_VECTORS
3107 .vecs = aes_lrw_dec_tv_template,
3108 .count = AES_LRW_DEC_TEST_VECTORS
3113 .alg = "lrw(camellia)",
3114 .test = alg_test_skcipher,
3118 .vecs = camellia_lrw_enc_tv_template,
3119 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
3122 .vecs = camellia_lrw_dec_tv_template,
3123 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
3128 .alg = "lrw(cast6)",
3129 .test = alg_test_skcipher,
3133 .vecs = cast6_lrw_enc_tv_template,
3134 .count = CAST6_LRW_ENC_TEST_VECTORS
3137 .vecs = cast6_lrw_dec_tv_template,
3138 .count = CAST6_LRW_DEC_TEST_VECTORS
3143 .alg = "lrw(serpent)",
3144 .test = alg_test_skcipher,
3148 .vecs = serpent_lrw_enc_tv_template,
3149 .count = SERPENT_LRW_ENC_TEST_VECTORS
3152 .vecs = serpent_lrw_dec_tv_template,
3153 .count = SERPENT_LRW_DEC_TEST_VECTORS
3158 .alg = "lrw(twofish)",
3159 .test = alg_test_skcipher,
3163 .vecs = tf_lrw_enc_tv_template,
3164 .count = TF_LRW_ENC_TEST_VECTORS
3167 .vecs = tf_lrw_dec_tv_template,
3168 .count = TF_LRW_DEC_TEST_VECTORS
3174 .test = alg_test_comp,
3179 .vecs = lz4_comp_tv_template,
3180 .count = LZ4_COMP_TEST_VECTORS
3183 .vecs = lz4_decomp_tv_template,
3184 .count = LZ4_DECOMP_TEST_VECTORS
3190 .test = alg_test_comp,
3195 .vecs = lz4hc_comp_tv_template,
3196 .count = LZ4HC_COMP_TEST_VECTORS
3199 .vecs = lz4hc_decomp_tv_template,
3200 .count = LZ4HC_DECOMP_TEST_VECTORS
3206 .test = alg_test_comp,
3211 .vecs = lzo_comp_tv_template,
3212 .count = LZO_COMP_TEST_VECTORS
3215 .vecs = lzo_decomp_tv_template,
3216 .count = LZO_DECOMP_TEST_VECTORS
3222 .test = alg_test_hash,
3225 .vecs = md4_tv_template,
3226 .count = MD4_TEST_VECTORS
3231 .test = alg_test_hash,
3234 .vecs = md5_tv_template,
3235 .count = MD5_TEST_VECTORS
3239 .alg = "michael_mic",
3240 .test = alg_test_hash,
3243 .vecs = michael_mic_tv_template,
3244 .count = MICHAEL_MIC_TEST_VECTORS
3249 .test = alg_test_skcipher,
3254 .vecs = aes_ofb_enc_tv_template,
3255 .count = AES_OFB_ENC_TEST_VECTORS
3258 .vecs = aes_ofb_dec_tv_template,
3259 .count = AES_OFB_DEC_TEST_VECTORS
3264 .alg = "pcbc(fcrypt)",
3265 .test = alg_test_skcipher,
3269 .vecs = fcrypt_pcbc_enc_tv_template,
3270 .count = FCRYPT_ENC_TEST_VECTORS
3273 .vecs = fcrypt_pcbc_dec_tv_template,
3274 .count = FCRYPT_DEC_TEST_VECTORS
3279 .alg = "rfc3686(ctr(aes))",
3280 .test = alg_test_skcipher,
3285 .vecs = aes_ctr_rfc3686_enc_tv_template,
3286 .count = AES_CTR_3686_ENC_TEST_VECTORS
3289 .vecs = aes_ctr_rfc3686_dec_tv_template,
3290 .count = AES_CTR_3686_DEC_TEST_VECTORS
3295 .alg = "rfc4106(gcm(aes))",
3296 .test = alg_test_aead,
3301 .vecs = aes_gcm_rfc4106_enc_tv_template,
3302 .count = AES_GCM_4106_ENC_TEST_VECTORS
3305 .vecs = aes_gcm_rfc4106_dec_tv_template,
3306 .count = AES_GCM_4106_DEC_TEST_VECTORS
3311 .alg = "rfc4309(ccm(aes))",
3312 .test = alg_test_aead,
3317 .vecs = aes_ccm_rfc4309_enc_tv_template,
3318 .count = AES_CCM_4309_ENC_TEST_VECTORS
3321 .vecs = aes_ccm_rfc4309_dec_tv_template,
3322 .count = AES_CCM_4309_DEC_TEST_VECTORS
3327 .alg = "rfc4543(gcm(aes))",
3328 .test = alg_test_aead,
3332 .vecs = aes_gcm_rfc4543_enc_tv_template,
3333 .count = AES_GCM_4543_ENC_TEST_VECTORS
3336 .vecs = aes_gcm_rfc4543_dec_tv_template,
3337 .count = AES_GCM_4543_DEC_TEST_VECTORS
3343 .test = alg_test_hash,
3346 .vecs = rmd128_tv_template,
3347 .count = RMD128_TEST_VECTORS
3352 .test = alg_test_hash,
3355 .vecs = rmd160_tv_template,
3356 .count = RMD160_TEST_VECTORS
3361 .test = alg_test_hash,
3364 .vecs = rmd256_tv_template,
3365 .count = RMD256_TEST_VECTORS
3370 .test = alg_test_hash,
3373 .vecs = rmd320_tv_template,
3374 .count = RMD320_TEST_VECTORS
3379 .test = alg_test_skcipher,
3383 .vecs = salsa20_stream_enc_tv_template,
3384 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3390 .test = alg_test_hash,
3394 .vecs = sha1_tv_template,
3395 .count = SHA1_TEST_VECTORS
3400 .test = alg_test_hash,
3404 .vecs = sha224_tv_template,
3405 .count = SHA224_TEST_VECTORS
3410 .test = alg_test_hash,
3414 .vecs = sha256_tv_template,
3415 .count = SHA256_TEST_VECTORS
3420 .test = alg_test_hash,
3424 .vecs = sha384_tv_template,
3425 .count = SHA384_TEST_VECTORS
3430 .test = alg_test_hash,
3434 .vecs = sha512_tv_template,
3435 .count = SHA512_TEST_VECTORS
3440 .test = alg_test_hash,
3443 .vecs = tgr128_tv_template,
3444 .count = TGR128_TEST_VECTORS
3449 .test = alg_test_hash,
3452 .vecs = tgr160_tv_template,
3453 .count = TGR160_TEST_VECTORS
3458 .test = alg_test_hash,
3461 .vecs = tgr192_tv_template,
3462 .count = TGR192_TEST_VECTORS
3467 .test = alg_test_hash,
3470 .vecs = aes_vmac128_tv_template,
3471 .count = VMAC_AES_TEST_VECTORS
3476 .test = alg_test_hash,
3479 .vecs = wp256_tv_template,
3480 .count = WP256_TEST_VECTORS
3485 .test = alg_test_hash,
3488 .vecs = wp384_tv_template,
3489 .count = WP384_TEST_VECTORS
3494 .test = alg_test_hash,
3497 .vecs = wp512_tv_template,
3498 .count = WP512_TEST_VECTORS
3503 .test = alg_test_hash,
3506 .vecs = aes_xcbc128_tv_template,
3507 .count = XCBC_AES_TEST_VECTORS
3512 .test = alg_test_skcipher,
3517 .vecs = aes_xts_enc_tv_template,
3518 .count = AES_XTS_ENC_TEST_VECTORS
3521 .vecs = aes_xts_dec_tv_template,
3522 .count = AES_XTS_DEC_TEST_VECTORS
3527 .alg = "xts(camellia)",
3528 .test = alg_test_skcipher,
3532 .vecs = camellia_xts_enc_tv_template,
3533 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3536 .vecs = camellia_xts_dec_tv_template,
3537 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3542 .alg = "xts(cast6)",
3543 .test = alg_test_skcipher,
3547 .vecs = cast6_xts_enc_tv_template,
3548 .count = CAST6_XTS_ENC_TEST_VECTORS
3551 .vecs = cast6_xts_dec_tv_template,
3552 .count = CAST6_XTS_DEC_TEST_VECTORS
3557 .alg = "xts(serpent)",
3558 .test = alg_test_skcipher,
3562 .vecs = serpent_xts_enc_tv_template,
3563 .count = SERPENT_XTS_ENC_TEST_VECTORS
3566 .vecs = serpent_xts_dec_tv_template,
3567 .count = SERPENT_XTS_DEC_TEST_VECTORS
3572 .alg = "xts(twofish)",
3573 .test = alg_test_skcipher,
3577 .vecs = tf_xts_enc_tv_template,
3578 .count = TF_XTS_ENC_TEST_VECTORS
3581 .vecs = tf_xts_dec_tv_template,
3582 .count = TF_XTS_DEC_TEST_VECTORS
3588 .test = alg_test_pcomp,
3593 .vecs = zlib_comp_tv_template,
3594 .count = ZLIB_COMP_TEST_VECTORS
3597 .vecs = zlib_decomp_tv_template,
3598 .count = ZLIB_DECOMP_TEST_VECTORS
3605 static bool alg_test_descs_checked;
3607 static void alg_test_descs_check_order(void)
3611 /* only check once */
3612 if (alg_test_descs_checked)
3615 alg_test_descs_checked = true;
3617 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3618 int diff = strcmp(alg_test_descs[i - 1].alg,
3619 alg_test_descs[i].alg);
3621 if (WARN_ON(diff > 0)) {
3622 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3623 alg_test_descs[i - 1].alg,
3624 alg_test_descs[i].alg);
3627 if (WARN_ON(diff == 0)) {
3628 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3629 alg_test_descs[i].alg);
3634 static int alg_find_test(const char *alg)
3637 int end = ARRAY_SIZE(alg_test_descs);
3639 while (start < end) {
3640 int i = (start + end) / 2;
3641 int diff = strcmp(alg_test_descs[i].alg, alg);
3659 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3665 alg_test_descs_check_order();
3667 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3668 char nalg[CRYPTO_MAX_ALG_NAME];
3670 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3672 return -ENAMETOOLONG;
3674 i = alg_find_test(nalg);
3678 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3681 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3685 i = alg_find_test(alg);
3686 j = alg_find_test(driver);
3690 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3691 (j >= 0 && !alg_test_descs[j].fips_allowed)))
3696 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3698 if (j >= 0 && j != i)
3699 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3703 if (fips_enabled && rc)
3704 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3706 if (fips_enabled && !rc)
3707 pr_info("alg: self-tests for %s (%s) passed\n", driver, alg);
3712 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3718 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3720 EXPORT_SYMBOL_GPL(alg_test);