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>
33 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
36 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
46 * Need slab memory for testing (size in number of pages).
51 * Indexes into the xbuf to simulate cross-page access.
63 * Used by test_cipher()
68 struct tcrypt_result {
69 struct completion completion;
73 struct aead_test_suite {
75 struct aead_testvec *vecs;
80 struct cipher_test_suite {
82 struct cipher_testvec *vecs;
87 struct comp_test_suite {
89 struct comp_testvec *vecs;
94 struct pcomp_test_suite {
96 struct pcomp_testvec *vecs;
101 struct hash_test_suite {
102 struct hash_testvec *vecs;
106 struct cprng_test_suite {
107 struct cprng_testvec *vecs;
111 struct alg_test_desc {
113 int (*test)(const struct alg_test_desc *desc, const char *driver,
115 int fips_allowed; /* set if alg is allowed in fips mode */
118 struct aead_test_suite aead;
119 struct cipher_test_suite cipher;
120 struct comp_test_suite comp;
121 struct pcomp_test_suite pcomp;
122 struct hash_test_suite hash;
123 struct cprng_test_suite cprng;
127 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
129 static void hexdump(unsigned char *buf, unsigned int len)
131 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
136 static void tcrypt_complete(struct crypto_async_request *req, int err)
138 struct tcrypt_result *res = req->data;
140 if (err == -EINPROGRESS)
144 complete(&res->completion);
147 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
151 for (i = 0; i < XBUFSIZE; i++) {
152 buf[i] = (void *)__get_free_page(GFP_KERNEL);
161 free_page((unsigned long)buf[i]);
166 static void testmgr_free_buf(char *buf[XBUFSIZE])
170 for (i = 0; i < XBUFSIZE; i++)
171 free_page((unsigned long)buf[i]);
174 static int do_one_async_hash_op(struct ahash_request *req,
175 struct tcrypt_result *tr,
178 if (ret == -EINPROGRESS || ret == -EBUSY) {
179 ret = wait_for_completion_interruptible(&tr->completion);
182 reinit_completion(&tr->completion);
187 static int __test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
188 unsigned int tcount, bool use_digest,
189 const int align_offset)
191 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
192 unsigned int i, j, k, temp;
193 struct scatterlist sg[8];
196 struct ahash_request *req;
197 struct tcrypt_result tresult;
199 char *xbuf[XBUFSIZE];
202 result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
205 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
208 if (testmgr_alloc_buf(xbuf))
211 init_completion(&tresult.completion);
213 req = ahash_request_alloc(tfm, GFP_KERNEL);
215 printk(KERN_ERR "alg: hash: Failed to allocate request for "
219 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
220 tcrypt_complete, &tresult);
223 for (i = 0; i < tcount; i++) {
228 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
232 memset(result, 0, MAX_DIGEST_SIZE);
235 hash_buff += align_offset;
237 memcpy(hash_buff, template[i].plaintext, template[i].psize);
238 sg_init_one(&sg[0], hash_buff, template[i].psize);
240 if (template[i].ksize) {
241 crypto_ahash_clear_flags(tfm, ~0);
242 if (template[i].ksize > MAX_KEYLEN) {
243 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
244 j, algo, template[i].ksize, MAX_KEYLEN);
248 memcpy(key, template[i].key, template[i].ksize);
249 ret = crypto_ahash_setkey(tfm, key, template[i].ksize);
251 printk(KERN_ERR "alg: hash: setkey failed on "
252 "test %d for %s: ret=%d\n", j, algo,
258 ahash_request_set_crypt(req, sg, result, template[i].psize);
260 ret = do_one_async_hash_op(req, &tresult,
261 crypto_ahash_digest(req));
263 pr_err("alg: hash: digest failed on test %d "
264 "for %s: ret=%d\n", j, algo, -ret);
268 ret = do_one_async_hash_op(req, &tresult,
269 crypto_ahash_init(req));
271 pr_err("alt: hash: init failed on test %d "
272 "for %s: ret=%d\n", j, algo, -ret);
275 ret = do_one_async_hash_op(req, &tresult,
276 crypto_ahash_update(req));
278 pr_err("alt: hash: update failed on test %d "
279 "for %s: ret=%d\n", j, algo, -ret);
282 ret = do_one_async_hash_op(req, &tresult,
283 crypto_ahash_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)
307 if (template[i].np) {
309 memset(result, 0, MAX_DIGEST_SIZE);
312 sg_init_table(sg, template[i].np);
314 for (k = 0; k < template[i].np; k++) {
315 if (WARN_ON(offset_in_page(IDX[k]) +
316 template[i].tap[k] > PAGE_SIZE))
319 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
320 offset_in_page(IDX[k]),
321 template[i].plaintext + temp,
324 temp += template[i].tap[k];
327 if (template[i].ksize) {
328 if (template[i].ksize > MAX_KEYLEN) {
329 pr_err("alg: hash: setkey failed on test %d for %s: key size %d > %d\n",
330 j, algo, template[i].ksize,
335 crypto_ahash_clear_flags(tfm, ~0);
336 memcpy(key, template[i].key, template[i].ksize);
337 ret = crypto_ahash_setkey(tfm, key,
341 printk(KERN_ERR "alg: hash: setkey "
342 "failed on chunking test %d "
343 "for %s: ret=%d\n", j, algo,
349 ahash_request_set_crypt(req, sg, result,
351 ret = crypto_ahash_digest(req);
357 ret = wait_for_completion_interruptible(
358 &tresult.completion);
359 if (!ret && !(ret = tresult.err)) {
360 reinit_completion(&tresult.completion);
365 printk(KERN_ERR "alg: hash: digest failed "
366 "on chunking test %d for %s: "
367 "ret=%d\n", j, algo, -ret);
371 if (memcmp(result, template[i].digest,
372 crypto_ahash_digestsize(tfm))) {
373 printk(KERN_ERR "alg: hash: Chunking test %d "
374 "failed for %s\n", j, algo);
375 hexdump(result, crypto_ahash_digestsize(tfm));
385 ahash_request_free(req);
387 testmgr_free_buf(xbuf);
394 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
395 unsigned int tcount, bool use_digest)
397 unsigned int alignmask;
400 ret = __test_hash(tfm, template, tcount, use_digest, 0);
404 /* test unaligned buffers, check with one byte offset */
405 ret = __test_hash(tfm, template, tcount, use_digest, 1);
409 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
411 /* Check if alignment mask for tfm is correctly set. */
412 ret = __test_hash(tfm, template, tcount, use_digest,
421 static int __test_aead(struct crypto_aead *tfm, int enc,
422 struct aead_testvec *template, unsigned int tcount,
423 const bool diff_dst, const int align_offset)
425 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
426 unsigned int i, j, k, n, temp;
430 struct aead_request *req;
431 struct scatterlist *sg;
432 struct scatterlist *asg;
433 struct scatterlist *sgout;
435 struct tcrypt_result result;
436 unsigned int authsize;
441 char *xbuf[XBUFSIZE];
442 char *xoutbuf[XBUFSIZE];
443 char *axbuf[XBUFSIZE];
445 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
448 key = kmalloc(MAX_KEYLEN, GFP_KERNEL);
451 if (testmgr_alloc_buf(xbuf))
453 if (testmgr_alloc_buf(axbuf))
455 if (diff_dst && testmgr_alloc_buf(xoutbuf))
458 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
459 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
475 init_completion(&result.completion);
477 req = aead_request_alloc(tfm, GFP_KERNEL);
479 pr_err("alg: aead%s: Failed to allocate request for %s\n",
484 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
485 tcrypt_complete, &result);
487 for (i = 0, j = 0; i < tcount; i++) {
488 if (!template[i].np) {
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(
513 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
515 if (template[i].klen > MAX_KEYLEN) {
516 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
517 d, j, algo, template[i].klen,
522 memcpy(key, template[i].key, template[i].klen);
524 ret = crypto_aead_setkey(tfm, key,
526 if (!ret == template[i].fail) {
527 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
528 d, j, algo, crypto_aead_get_flags(tfm));
533 authsize = abs(template[i].rlen - template[i].ilen);
534 ret = crypto_aead_setauthsize(tfm, authsize);
536 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
537 d, authsize, j, algo);
543 output += align_offset;
544 sg_init_one(&sg[0], input, template[i].ilen);
545 sg_init_one(&sgout[0], output,
548 sg_init_one(&sg[0], input,
550 (enc ? authsize : 0));
554 sg_init_one(&asg[0], assoc, template[i].alen);
556 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
557 template[i].ilen, iv);
559 aead_request_set_assoc(req, asg, template[i].alen);
562 crypto_aead_encrypt(req) :
563 crypto_aead_decrypt(req);
567 if (template[i].novrfy) {
568 /* verification was supposed to fail */
569 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
571 /* so really, we got a bad message */
578 ret = wait_for_completion_interruptible(
580 if (!ret && !(ret = result.err)) {
581 reinit_completion(&result.completion);
585 if (template[i].novrfy)
586 /* verification failure was expected */
590 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
591 d, e, j, algo, -ret);
596 if (memcmp(q, template[i].result, template[i].rlen)) {
597 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
599 hexdump(q, template[i].rlen);
606 for (i = 0, j = 0; i < tcount; i++) {
607 /* alignment tests are only done with continuous buffers */
608 if (align_offset != 0)
611 if (template[i].np) {
615 memcpy(iv, template[i].iv, MAX_IVLEN);
617 memset(iv, 0, MAX_IVLEN);
619 crypto_aead_clear_flags(tfm, ~0);
621 crypto_aead_set_flags(
622 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
623 if (template[i].klen > MAX_KEYLEN) {
624 pr_err("alg: aead%s: setkey failed on test %d for %s: key size %d > %d\n",
625 d, j, algo, template[i].klen,
630 memcpy(key, template[i].key, template[i].klen);
632 ret = crypto_aead_setkey(tfm, key, template[i].klen);
633 if (!ret == template[i].fail) {
634 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
635 d, j, algo, crypto_aead_get_flags(tfm));
640 authsize = abs(template[i].rlen - template[i].ilen);
643 sg_init_table(sg, template[i].np);
645 sg_init_table(sgout, template[i].np);
646 for (k = 0, temp = 0; k < template[i].np; k++) {
647 if (WARN_ON(offset_in_page(IDX[k]) +
648 template[i].tap[k] > PAGE_SIZE))
651 q = xbuf[IDX[k] >> PAGE_SHIFT] +
652 offset_in_page(IDX[k]);
654 memcpy(q, template[i].input + temp,
657 sg_set_buf(&sg[k], q, template[i].tap[k]);
660 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
661 offset_in_page(IDX[k]);
663 memset(q, 0, template[i].tap[k]);
665 sg_set_buf(&sgout[k], q,
669 n = template[i].tap[k];
670 if (k == template[i].np - 1 && enc)
672 if (offset_in_page(q) + n < PAGE_SIZE)
675 temp += template[i].tap[k];
678 ret = crypto_aead_setauthsize(tfm, authsize);
680 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
681 d, authsize, j, algo);
686 if (WARN_ON(sg[k - 1].offset +
687 sg[k - 1].length + authsize >
694 sgout[k - 1].length += authsize;
696 sg[k - 1].length += authsize;
699 sg_init_table(asg, template[i].anp);
701 for (k = 0, temp = 0; k < template[i].anp; k++) {
702 if (WARN_ON(offset_in_page(IDX[k]) +
703 template[i].atap[k] > PAGE_SIZE))
706 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
707 offset_in_page(IDX[k]),
708 template[i].assoc + temp,
709 template[i].atap[k]),
710 template[i].atap[k]);
711 temp += template[i].atap[k];
714 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
718 aead_request_set_assoc(req, asg, template[i].alen);
721 crypto_aead_encrypt(req) :
722 crypto_aead_decrypt(req);
726 if (template[i].novrfy) {
727 /* verification was supposed to fail */
728 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
730 /* so really, we got a bad message */
737 ret = wait_for_completion_interruptible(
739 if (!ret && !(ret = result.err)) {
740 reinit_completion(&result.completion);
744 if (template[i].novrfy)
745 /* verification failure was expected */
749 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
750 d, e, j, algo, -ret);
755 for (k = 0, temp = 0; k < template[i].np; k++) {
757 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
758 offset_in_page(IDX[k]);
760 q = xbuf[IDX[k] >> PAGE_SHIFT] +
761 offset_in_page(IDX[k]);
763 n = template[i].tap[k];
764 if (k == template[i].np - 1)
765 n += enc ? authsize : -authsize;
767 if (memcmp(q, template[i].result + temp, n)) {
768 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
775 if (k == template[i].np - 1 && !enc) {
777 memcmp(q, template[i].input +
783 for (n = 0; offset_in_page(q + n) &&
788 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
789 d, j, e, k, algo, n);
794 temp += template[i].tap[k];
802 aead_request_free(req);
806 testmgr_free_buf(xoutbuf);
808 testmgr_free_buf(axbuf);
810 testmgr_free_buf(xbuf);
817 static int test_aead(struct crypto_aead *tfm, int enc,
818 struct aead_testvec *template, unsigned int tcount)
820 unsigned int alignmask;
823 /* test 'dst == src' case */
824 ret = __test_aead(tfm, enc, template, tcount, false, 0);
828 /* test 'dst != src' case */
829 ret = __test_aead(tfm, enc, template, tcount, true, 0);
833 /* test unaligned buffers, check with one byte offset */
834 ret = __test_aead(tfm, enc, template, tcount, true, 1);
838 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
840 /* Check if alignment mask for tfm is correctly set. */
841 ret = __test_aead(tfm, enc, template, tcount, true,
850 static int test_cipher(struct crypto_cipher *tfm, int enc,
851 struct cipher_testvec *template, unsigned int tcount)
853 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
854 unsigned int i, j, k;
858 char *xbuf[XBUFSIZE];
861 if (testmgr_alloc_buf(xbuf))
870 for (i = 0; i < tcount; i++) {
877 if (WARN_ON(template[i].ilen > PAGE_SIZE))
881 memcpy(data, template[i].input, template[i].ilen);
883 crypto_cipher_clear_flags(tfm, ~0);
885 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
887 ret = crypto_cipher_setkey(tfm, template[i].key,
889 if (!ret == template[i].fail) {
890 printk(KERN_ERR "alg: cipher: setkey failed "
891 "on test %d for %s: flags=%x\n", j,
892 algo, crypto_cipher_get_flags(tfm));
897 for (k = 0; k < template[i].ilen;
898 k += crypto_cipher_blocksize(tfm)) {
900 crypto_cipher_encrypt_one(tfm, data + k,
903 crypto_cipher_decrypt_one(tfm, data + k,
908 if (memcmp(q, template[i].result, template[i].rlen)) {
909 printk(KERN_ERR "alg: cipher: Test %d failed "
910 "on %s for %s\n", j, e, algo);
911 hexdump(q, template[i].rlen);
920 testmgr_free_buf(xbuf);
925 static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
926 struct cipher_testvec *template, unsigned int tcount,
927 const bool diff_dst, const int align_offset)
930 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
931 unsigned int i, j, k, n, temp;
933 struct ablkcipher_request *req;
934 struct scatterlist sg[8];
935 struct scatterlist sgout[8];
937 struct tcrypt_result result;
940 char *xbuf[XBUFSIZE];
941 char *xoutbuf[XBUFSIZE];
944 if (testmgr_alloc_buf(xbuf))
947 if (diff_dst && testmgr_alloc_buf(xoutbuf))
960 init_completion(&result.completion);
962 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
964 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
969 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
970 tcrypt_complete, &result);
973 for (i = 0; i < tcount; i++) {
975 memcpy(iv, template[i].iv, MAX_IVLEN);
977 memset(iv, 0, MAX_IVLEN);
979 if (!(template[i].np) || (template[i].also_non_np)) {
983 if (WARN_ON(align_offset + template[i].ilen >
988 data += align_offset;
989 memcpy(data, template[i].input, template[i].ilen);
991 crypto_ablkcipher_clear_flags(tfm, ~0);
993 crypto_ablkcipher_set_flags(
994 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
996 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
998 if (!ret == template[i].fail) {
999 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
1001 crypto_ablkcipher_get_flags(tfm));
1006 sg_init_one(&sg[0], data, template[i].ilen);
1009 data += align_offset;
1010 sg_init_one(&sgout[0], data, template[i].ilen);
1013 ablkcipher_request_set_crypt(req, sg,
1014 (diff_dst) ? sgout : sg,
1015 template[i].ilen, iv);
1017 crypto_ablkcipher_encrypt(req) :
1018 crypto_ablkcipher_decrypt(req);
1025 ret = wait_for_completion_interruptible(
1026 &result.completion);
1027 if (!ret && !((ret = result.err))) {
1028 reinit_completion(&result.completion);
1033 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
1034 d, e, j, algo, -ret);
1039 if (memcmp(q, template[i].result, template[i].rlen)) {
1040 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1042 hexdump(q, template[i].rlen);
1050 for (i = 0; i < tcount; i++) {
1051 /* alignment tests are only done with continuous buffers */
1052 if (align_offset != 0)
1056 memcpy(iv, template[i].iv, MAX_IVLEN);
1058 memset(iv, 0, MAX_IVLEN);
1060 if (template[i].np) {
1063 crypto_ablkcipher_clear_flags(tfm, ~0);
1065 crypto_ablkcipher_set_flags(
1066 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1068 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1070 if (!ret == template[i].fail) {
1071 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1073 crypto_ablkcipher_get_flags(tfm));
1080 sg_init_table(sg, template[i].np);
1082 sg_init_table(sgout, template[i].np);
1083 for (k = 0; k < template[i].np; k++) {
1084 if (WARN_ON(offset_in_page(IDX[k]) +
1085 template[i].tap[k] > PAGE_SIZE))
1088 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1089 offset_in_page(IDX[k]);
1091 memcpy(q, template[i].input + temp,
1092 template[i].tap[k]);
1094 if (offset_in_page(q) + template[i].tap[k] <
1096 q[template[i].tap[k]] = 0;
1098 sg_set_buf(&sg[k], q, template[i].tap[k]);
1100 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1101 offset_in_page(IDX[k]);
1103 sg_set_buf(&sgout[k], q,
1104 template[i].tap[k]);
1106 memset(q, 0, template[i].tap[k]);
1107 if (offset_in_page(q) +
1108 template[i].tap[k] < PAGE_SIZE)
1109 q[template[i].tap[k]] = 0;
1112 temp += template[i].tap[k];
1115 ablkcipher_request_set_crypt(req, sg,
1116 (diff_dst) ? sgout : sg,
1117 template[i].ilen, iv);
1120 crypto_ablkcipher_encrypt(req) :
1121 crypto_ablkcipher_decrypt(req);
1128 ret = wait_for_completion_interruptible(
1129 &result.completion);
1130 if (!ret && !((ret = result.err))) {
1131 reinit_completion(&result.completion);
1136 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1137 d, e, j, algo, -ret);
1143 for (k = 0; k < template[i].np; k++) {
1145 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1146 offset_in_page(IDX[k]);
1148 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1149 offset_in_page(IDX[k]);
1151 if (memcmp(q, template[i].result + temp,
1152 template[i].tap[k])) {
1153 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1155 hexdump(q, template[i].tap[k]);
1159 q += template[i].tap[k];
1160 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1163 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1164 d, j, e, k, algo, n);
1168 temp += template[i].tap[k];
1176 ablkcipher_request_free(req);
1178 testmgr_free_buf(xoutbuf);
1180 testmgr_free_buf(xbuf);
1185 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1186 struct cipher_testvec *template, unsigned int tcount)
1188 unsigned int alignmask;
1191 /* test 'dst == src' case */
1192 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
1196 /* test 'dst != src' case */
1197 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1201 /* test unaligned buffers, check with one byte offset */
1202 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1206 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1208 /* Check if alignment mask for tfm is correctly set. */
1209 ret = __test_skcipher(tfm, enc, template, tcount, true,
1218 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1219 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1221 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1223 char result[COMP_BUF_SIZE];
1226 for (i = 0; i < ctcount; i++) {
1228 unsigned int dlen = COMP_BUF_SIZE;
1230 memset(result, 0, sizeof (result));
1232 ilen = ctemplate[i].inlen;
1233 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1234 ilen, result, &dlen);
1236 printk(KERN_ERR "alg: comp: compression failed "
1237 "on test %d for %s: ret=%d\n", i + 1, algo,
1242 if (dlen != ctemplate[i].outlen) {
1243 printk(KERN_ERR "alg: comp: Compression test %d "
1244 "failed for %s: output len = %d\n", i + 1, algo,
1250 if (memcmp(result, ctemplate[i].output, dlen)) {
1251 printk(KERN_ERR "alg: comp: Compression test %d "
1252 "failed for %s\n", i + 1, algo);
1253 hexdump(result, dlen);
1259 for (i = 0; i < dtcount; i++) {
1261 unsigned int dlen = COMP_BUF_SIZE;
1263 memset(result, 0, sizeof (result));
1265 ilen = dtemplate[i].inlen;
1266 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1267 ilen, result, &dlen);
1269 printk(KERN_ERR "alg: comp: decompression failed "
1270 "on test %d for %s: ret=%d\n", i + 1, algo,
1275 if (dlen != dtemplate[i].outlen) {
1276 printk(KERN_ERR "alg: comp: Decompression test %d "
1277 "failed for %s: output len = %d\n", i + 1, algo,
1283 if (memcmp(result, dtemplate[i].output, dlen)) {
1284 printk(KERN_ERR "alg: comp: Decompression test %d "
1285 "failed for %s\n", i + 1, algo);
1286 hexdump(result, dlen);
1298 static int test_pcomp(struct crypto_pcomp *tfm,
1299 struct pcomp_testvec *ctemplate,
1300 struct pcomp_testvec *dtemplate, int ctcount,
1303 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1305 char result[COMP_BUF_SIZE];
1308 for (i = 0; i < ctcount; i++) {
1309 struct comp_request req;
1310 unsigned int produced = 0;
1312 res = crypto_compress_setup(tfm, ctemplate[i].params,
1313 ctemplate[i].paramsize);
1315 pr_err("alg: pcomp: compression setup failed on test "
1316 "%d for %s: error=%d\n", i + 1, algo, res);
1320 res = crypto_compress_init(tfm);
1322 pr_err("alg: pcomp: compression init failed on test "
1323 "%d for %s: error=%d\n", i + 1, algo, res);
1327 memset(result, 0, sizeof(result));
1329 req.next_in = ctemplate[i].input;
1330 req.avail_in = ctemplate[i].inlen / 2;
1331 req.next_out = result;
1332 req.avail_out = ctemplate[i].outlen / 2;
1334 res = crypto_compress_update(tfm, &req);
1335 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1336 pr_err("alg: pcomp: compression update failed on test "
1337 "%d for %s: error=%d\n", i + 1, algo, res);
1343 /* Add remaining input data */
1344 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1346 res = crypto_compress_update(tfm, &req);
1347 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1348 pr_err("alg: pcomp: compression update failed on test "
1349 "%d for %s: error=%d\n", i + 1, algo, res);
1355 /* Provide remaining output space */
1356 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1358 res = crypto_compress_final(tfm, &req);
1360 pr_err("alg: pcomp: compression final failed on test "
1361 "%d for %s: error=%d\n", i + 1, algo, res);
1366 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1367 pr_err("alg: comp: Compression test %d failed for %s: "
1368 "output len = %d (expected %d)\n", i + 1, algo,
1369 COMP_BUF_SIZE - req.avail_out,
1370 ctemplate[i].outlen);
1374 if (produced != ctemplate[i].outlen) {
1375 pr_err("alg: comp: Compression test %d failed for %s: "
1376 "returned len = %u (expected %d)\n", i + 1,
1377 algo, produced, ctemplate[i].outlen);
1381 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1382 pr_err("alg: pcomp: Compression test %d failed for "
1383 "%s\n", i + 1, algo);
1384 hexdump(result, ctemplate[i].outlen);
1389 for (i = 0; i < dtcount; i++) {
1390 struct comp_request req;
1391 unsigned int produced = 0;
1393 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1394 dtemplate[i].paramsize);
1396 pr_err("alg: pcomp: decompression setup failed on "
1397 "test %d for %s: error=%d\n", i + 1, algo, res);
1401 res = crypto_decompress_init(tfm);
1403 pr_err("alg: pcomp: decompression init failed on test "
1404 "%d for %s: error=%d\n", i + 1, algo, res);
1408 memset(result, 0, sizeof(result));
1410 req.next_in = dtemplate[i].input;
1411 req.avail_in = dtemplate[i].inlen / 2;
1412 req.next_out = result;
1413 req.avail_out = dtemplate[i].outlen / 2;
1415 res = crypto_decompress_update(tfm, &req);
1416 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1417 pr_err("alg: pcomp: decompression update failed on "
1418 "test %d for %s: error=%d\n", i + 1, algo, res);
1424 /* Add remaining input data */
1425 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1427 res = crypto_decompress_update(tfm, &req);
1428 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1429 pr_err("alg: pcomp: decompression update failed on "
1430 "test %d for %s: error=%d\n", i + 1, algo, res);
1436 /* Provide remaining output space */
1437 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1439 res = crypto_decompress_final(tfm, &req);
1440 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1441 pr_err("alg: pcomp: decompression final failed on "
1442 "test %d for %s: error=%d\n", i + 1, algo, res);
1448 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1449 pr_err("alg: comp: Decompression test %d failed for "
1450 "%s: output len = %d (expected %d)\n", i + 1,
1451 algo, COMP_BUF_SIZE - req.avail_out,
1452 dtemplate[i].outlen);
1456 if (produced != dtemplate[i].outlen) {
1457 pr_err("alg: comp: Decompression test %d failed for "
1458 "%s: returned len = %u (expected %d)\n", i + 1,
1459 algo, produced, dtemplate[i].outlen);
1463 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1464 pr_err("alg: pcomp: Decompression test %d failed for "
1465 "%s\n", i + 1, algo);
1466 hexdump(result, dtemplate[i].outlen);
1475 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1476 unsigned int tcount)
1478 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1479 int err = 0, i, j, seedsize;
1483 seedsize = crypto_rng_seedsize(tfm);
1485 seed = kmalloc(seedsize, GFP_KERNEL);
1487 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1492 for (i = 0; i < tcount; i++) {
1493 memset(result, 0, 32);
1495 memcpy(seed, template[i].v, template[i].vlen);
1496 memcpy(seed + template[i].vlen, template[i].key,
1498 memcpy(seed + template[i].vlen + template[i].klen,
1499 template[i].dt, template[i].dtlen);
1501 err = crypto_rng_reset(tfm, seed, seedsize);
1503 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1508 for (j = 0; j < template[i].loops; j++) {
1509 err = crypto_rng_get_bytes(tfm, result,
1511 if (err != template[i].rlen) {
1512 printk(KERN_ERR "alg: cprng: Failed to obtain "
1513 "the correct amount of random data for "
1514 "%s (requested %d, got %d)\n", algo,
1515 template[i].rlen, err);
1520 err = memcmp(result, template[i].result,
1523 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1525 hexdump(result, template[i].rlen);
1536 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1539 struct crypto_aead *tfm;
1542 tfm = crypto_alloc_aead(driver, type, mask);
1544 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1545 "%ld\n", driver, PTR_ERR(tfm));
1546 return PTR_ERR(tfm);
1549 if (desc->suite.aead.enc.vecs) {
1550 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1551 desc->suite.aead.enc.count);
1556 if (!err && desc->suite.aead.dec.vecs)
1557 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1558 desc->suite.aead.dec.count);
1561 crypto_free_aead(tfm);
1565 static int alg_test_cipher(const struct alg_test_desc *desc,
1566 const char *driver, u32 type, u32 mask)
1568 struct crypto_cipher *tfm;
1571 tfm = crypto_alloc_cipher(driver, type, mask);
1573 printk(KERN_ERR "alg: cipher: 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_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1580 desc->suite.cipher.enc.count);
1585 if (desc->suite.cipher.dec.vecs)
1586 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1587 desc->suite.cipher.dec.count);
1590 crypto_free_cipher(tfm);
1594 static int alg_test_skcipher(const struct alg_test_desc *desc,
1595 const char *driver, u32 type, u32 mask)
1597 struct crypto_ablkcipher *tfm;
1600 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1602 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1603 "%s: %ld\n", driver, PTR_ERR(tfm));
1604 return PTR_ERR(tfm);
1607 if (desc->suite.cipher.enc.vecs) {
1608 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1609 desc->suite.cipher.enc.count);
1614 if (desc->suite.cipher.dec.vecs)
1615 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1616 desc->suite.cipher.dec.count);
1619 crypto_free_ablkcipher(tfm);
1623 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1626 struct crypto_comp *tfm;
1629 tfm = crypto_alloc_comp(driver, type, mask);
1631 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1632 "%ld\n", driver, PTR_ERR(tfm));
1633 return PTR_ERR(tfm);
1636 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1637 desc->suite.comp.decomp.vecs,
1638 desc->suite.comp.comp.count,
1639 desc->suite.comp.decomp.count);
1641 crypto_free_comp(tfm);
1645 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1648 struct crypto_pcomp *tfm;
1651 tfm = crypto_alloc_pcomp(driver, type, mask);
1653 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1654 driver, PTR_ERR(tfm));
1655 return PTR_ERR(tfm);
1658 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1659 desc->suite.pcomp.decomp.vecs,
1660 desc->suite.pcomp.comp.count,
1661 desc->suite.pcomp.decomp.count);
1663 crypto_free_pcomp(tfm);
1667 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1670 struct crypto_ahash *tfm;
1673 tfm = crypto_alloc_ahash(driver, type, mask);
1675 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1676 "%ld\n", driver, PTR_ERR(tfm));
1677 return PTR_ERR(tfm);
1680 err = test_hash(tfm, desc->suite.hash.vecs,
1681 desc->suite.hash.count, true);
1683 err = test_hash(tfm, desc->suite.hash.vecs,
1684 desc->suite.hash.count, false);
1686 crypto_free_ahash(tfm);
1690 static int alg_test_crc32c(const struct alg_test_desc *desc,
1691 const char *driver, u32 type, u32 mask)
1693 struct crypto_shash *tfm;
1697 err = alg_test_hash(desc, driver, type, mask);
1701 tfm = crypto_alloc_shash(driver, type, mask);
1703 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1704 "%ld\n", driver, PTR_ERR(tfm));
1711 struct shash_desc shash;
1712 char ctx[crypto_shash_descsize(tfm)];
1715 sdesc.shash.tfm = tfm;
1716 sdesc.shash.flags = 0;
1718 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1719 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1721 printk(KERN_ERR "alg: crc32c: Operation failed for "
1722 "%s: %d\n", driver, err);
1726 if (val != ~420553207) {
1727 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1728 "%d\n", driver, val);
1733 crypto_free_shash(tfm);
1739 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1742 struct crypto_rng *rng;
1745 rng = crypto_alloc_rng(driver, type, mask);
1747 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1748 "%ld\n", driver, PTR_ERR(rng));
1749 return PTR_ERR(rng);
1752 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1754 crypto_free_rng(rng);
1759 static int alg_test_null(const struct alg_test_desc *desc,
1760 const char *driver, u32 type, u32 mask)
1765 /* Please keep this list sorted by algorithm name. */
1766 static const struct alg_test_desc alg_test_descs[] = {
1768 .alg = "__cbc-cast5-avx",
1769 .test = alg_test_null,
1771 .alg = "__cbc-cast6-avx",
1772 .test = alg_test_null,
1774 .alg = "__cbc-serpent-avx",
1775 .test = alg_test_null,
1777 .alg = "__cbc-serpent-avx2",
1778 .test = alg_test_null,
1780 .alg = "__cbc-serpent-sse2",
1781 .test = alg_test_null,
1783 .alg = "__cbc-twofish-avx",
1784 .test = alg_test_null,
1786 .alg = "__driver-cbc-aes-aesni",
1787 .test = alg_test_null,
1790 .alg = "__driver-cbc-camellia-aesni",
1791 .test = alg_test_null,
1793 .alg = "__driver-cbc-camellia-aesni-avx2",
1794 .test = alg_test_null,
1796 .alg = "__driver-cbc-cast5-avx",
1797 .test = alg_test_null,
1799 .alg = "__driver-cbc-cast6-avx",
1800 .test = alg_test_null,
1802 .alg = "__driver-cbc-serpent-avx",
1803 .test = alg_test_null,
1805 .alg = "__driver-cbc-serpent-avx2",
1806 .test = alg_test_null,
1808 .alg = "__driver-cbc-serpent-sse2",
1809 .test = alg_test_null,
1811 .alg = "__driver-cbc-twofish-avx",
1812 .test = alg_test_null,
1814 .alg = "__driver-ecb-aes-aesni",
1815 .test = alg_test_null,
1818 .alg = "__driver-ecb-camellia-aesni",
1819 .test = alg_test_null,
1821 .alg = "__driver-ecb-camellia-aesni-avx2",
1822 .test = alg_test_null,
1824 .alg = "__driver-ecb-cast5-avx",
1825 .test = alg_test_null,
1827 .alg = "__driver-ecb-cast6-avx",
1828 .test = alg_test_null,
1830 .alg = "__driver-ecb-serpent-avx",
1831 .test = alg_test_null,
1833 .alg = "__driver-ecb-serpent-avx2",
1834 .test = alg_test_null,
1836 .alg = "__driver-ecb-serpent-sse2",
1837 .test = alg_test_null,
1839 .alg = "__driver-ecb-twofish-avx",
1840 .test = alg_test_null,
1842 .alg = "__ghash-pclmulqdqni",
1843 .test = alg_test_null,
1846 .alg = "ansi_cprng",
1847 .test = alg_test_cprng,
1851 .vecs = ansi_cprng_aes_tv_template,
1852 .count = ANSI_CPRNG_AES_TEST_VECTORS
1856 .alg = "authenc(hmac(sha1),cbc(aes))",
1857 .test = alg_test_aead,
1862 .vecs = hmac_sha1_aes_cbc_enc_tv_template,
1863 .count = HMAC_SHA1_AES_CBC_ENC_TEST_VECTORS
1868 .alg = "authenc(hmac(sha256),cbc(aes))",
1869 .test = alg_test_aead,
1874 .vecs = hmac_sha256_aes_cbc_enc_tv_template,
1875 .count = HMAC_SHA256_AES_CBC_ENC_TEST_VECTORS
1880 .alg = "authenc(hmac(sha512),cbc(aes))",
1881 .test = alg_test_aead,
1886 .vecs = hmac_sha512_aes_cbc_enc_tv_template,
1887 .count = HMAC_SHA512_AES_CBC_ENC_TEST_VECTORS
1892 .alg = "authenc(hmac(md5),cbc(aes))",
1893 .test = alg_test_aead,
1898 .vecs = hmac_md5_aes_cbc_enc_tv_template,
1899 .count = HMAC_MD5_AES_CBC_ENC_TEST_VECTORS
1904 .alg = "authenc(hmac(sha1),cbc(des))",
1905 .test = alg_test_aead,
1910 .vecs = hmac_sha1_des_cbc_enc_tv_template,
1911 .count = HMAC_SHA1_DES_CBC_ENC_TEST_VECTORS
1916 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1917 .test = alg_test_aead,
1922 .vecs = hmac_sha1_des3_ede_cbc_enc_tv_template,
1923 .count = HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VECTORS
1928 .alg = "authenc(hmac(sha224),cbc(des))",
1929 .test = alg_test_aead,
1934 .vecs = hmac_sha224_des_cbc_enc_tv_template,
1935 .count = HMAC_SHA224_DES_CBC_ENC_TEST_VECTORS
1940 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
1941 .test = alg_test_aead,
1946 .vecs = hmac_sha224_des3_ede_cbc_enc_tv_template,
1947 .count = HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VECTORS
1952 .alg = "authenc(hmac(sha256),cbc(des))",
1953 .test = alg_test_aead,
1958 .vecs = hmac_sha256_des_cbc_enc_tv_template,
1959 .count = HMAC_SHA256_DES_CBC_ENC_TEST_VECTORS
1964 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
1965 .test = alg_test_aead,
1970 .vecs = hmac_sha256_des3_ede_cbc_enc_tv_template,
1971 .count = HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VECTORS
1976 .alg = "authenc(hmac(sha384),cbc(des))",
1977 .test = alg_test_aead,
1982 .vecs = hmac_sha384_des_cbc_enc_tv_template,
1983 .count = HMAC_SHA384_DES_CBC_ENC_TEST_VECTORS
1988 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
1989 .test = alg_test_aead,
1994 .vecs = hmac_sha384_des3_ede_cbc_enc_tv_template,
1995 .count = HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VECTORS
2000 .alg = "authenc(hmac(sha512),cbc(des))",
2001 .test = alg_test_aead,
2006 .vecs = hmac_sha512_des_cbc_enc_tv_template,
2007 .count = HMAC_SHA512_DES_CBC_ENC_TEST_VECTORS
2012 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2013 .test = alg_test_aead,
2018 .vecs = hmac_sha512_des3_ede_cbc_enc_tv_template,
2019 .count = HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VECTORS
2025 .test = alg_test_skcipher,
2030 .vecs = aes_cbc_enc_tv_template,
2031 .count = AES_CBC_ENC_TEST_VECTORS
2034 .vecs = aes_cbc_dec_tv_template,
2035 .count = AES_CBC_DEC_TEST_VECTORS
2040 .alg = "cbc(anubis)",
2041 .test = alg_test_skcipher,
2045 .vecs = anubis_cbc_enc_tv_template,
2046 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2049 .vecs = anubis_cbc_dec_tv_template,
2050 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2055 .alg = "cbc(blowfish)",
2056 .test = alg_test_skcipher,
2060 .vecs = bf_cbc_enc_tv_template,
2061 .count = BF_CBC_ENC_TEST_VECTORS
2064 .vecs = bf_cbc_dec_tv_template,
2065 .count = BF_CBC_DEC_TEST_VECTORS
2070 .alg = "cbc(camellia)",
2071 .test = alg_test_skcipher,
2075 .vecs = camellia_cbc_enc_tv_template,
2076 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2079 .vecs = camellia_cbc_dec_tv_template,
2080 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2085 .alg = "cbc(cast5)",
2086 .test = alg_test_skcipher,
2090 .vecs = cast5_cbc_enc_tv_template,
2091 .count = CAST5_CBC_ENC_TEST_VECTORS
2094 .vecs = cast5_cbc_dec_tv_template,
2095 .count = CAST5_CBC_DEC_TEST_VECTORS
2100 .alg = "cbc(cast6)",
2101 .test = alg_test_skcipher,
2105 .vecs = cast6_cbc_enc_tv_template,
2106 .count = CAST6_CBC_ENC_TEST_VECTORS
2109 .vecs = cast6_cbc_dec_tv_template,
2110 .count = CAST6_CBC_DEC_TEST_VECTORS
2116 .test = alg_test_skcipher,
2120 .vecs = des_cbc_enc_tv_template,
2121 .count = DES_CBC_ENC_TEST_VECTORS
2124 .vecs = des_cbc_dec_tv_template,
2125 .count = DES_CBC_DEC_TEST_VECTORS
2130 .alg = "cbc(des3_ede)",
2131 .test = alg_test_skcipher,
2136 .vecs = des3_ede_cbc_enc_tv_template,
2137 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2140 .vecs = des3_ede_cbc_dec_tv_template,
2141 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2146 .alg = "cbc(serpent)",
2147 .test = alg_test_skcipher,
2151 .vecs = serpent_cbc_enc_tv_template,
2152 .count = SERPENT_CBC_ENC_TEST_VECTORS
2155 .vecs = serpent_cbc_dec_tv_template,
2156 .count = SERPENT_CBC_DEC_TEST_VECTORS
2161 .alg = "cbc(twofish)",
2162 .test = alg_test_skcipher,
2166 .vecs = tf_cbc_enc_tv_template,
2167 .count = TF_CBC_ENC_TEST_VECTORS
2170 .vecs = tf_cbc_dec_tv_template,
2171 .count = TF_CBC_DEC_TEST_VECTORS
2177 .test = alg_test_aead,
2182 .vecs = aes_ccm_enc_tv_template,
2183 .count = AES_CCM_ENC_TEST_VECTORS
2186 .vecs = aes_ccm_dec_tv_template,
2187 .count = AES_CCM_DEC_TEST_VECTORS
2193 .test = alg_test_hash,
2196 .vecs = aes_cmac128_tv_template,
2197 .count = CMAC_AES_TEST_VECTORS
2201 .alg = "cmac(des3_ede)",
2202 .test = alg_test_hash,
2205 .vecs = des3_ede_cmac64_tv_template,
2206 .count = CMAC_DES3_EDE_TEST_VECTORS
2210 .alg = "compress_null",
2211 .test = alg_test_null,
2214 .test = alg_test_crc32c,
2218 .vecs = crc32c_tv_template,
2219 .count = CRC32C_TEST_VECTORS
2224 .test = alg_test_hash,
2228 .vecs = crct10dif_tv_template,
2229 .count = CRCT10DIF_TEST_VECTORS
2233 .alg = "cryptd(__driver-cbc-aes-aesni)",
2234 .test = alg_test_null,
2237 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2238 .test = alg_test_null,
2240 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2241 .test = alg_test_null,
2243 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2244 .test = alg_test_null,
2246 .alg = "cryptd(__driver-ecb-aes-aesni)",
2247 .test = alg_test_null,
2250 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2251 .test = alg_test_null,
2253 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2254 .test = alg_test_null,
2256 .alg = "cryptd(__driver-ecb-cast5-avx)",
2257 .test = alg_test_null,
2259 .alg = "cryptd(__driver-ecb-cast6-avx)",
2260 .test = alg_test_null,
2262 .alg = "cryptd(__driver-ecb-serpent-avx)",
2263 .test = alg_test_null,
2265 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2266 .test = alg_test_null,
2268 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2269 .test = alg_test_null,
2271 .alg = "cryptd(__driver-ecb-twofish-avx)",
2272 .test = alg_test_null,
2274 .alg = "cryptd(__driver-gcm-aes-aesni)",
2275 .test = alg_test_null,
2278 .alg = "cryptd(__ghash-pclmulqdqni)",
2279 .test = alg_test_null,
2283 .test = alg_test_skcipher,
2288 .vecs = aes_ctr_enc_tv_template,
2289 .count = AES_CTR_ENC_TEST_VECTORS
2292 .vecs = aes_ctr_dec_tv_template,
2293 .count = AES_CTR_DEC_TEST_VECTORS
2298 .alg = "ctr(blowfish)",
2299 .test = alg_test_skcipher,
2303 .vecs = bf_ctr_enc_tv_template,
2304 .count = BF_CTR_ENC_TEST_VECTORS
2307 .vecs = bf_ctr_dec_tv_template,
2308 .count = BF_CTR_DEC_TEST_VECTORS
2313 .alg = "ctr(camellia)",
2314 .test = alg_test_skcipher,
2318 .vecs = camellia_ctr_enc_tv_template,
2319 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2322 .vecs = camellia_ctr_dec_tv_template,
2323 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2328 .alg = "ctr(cast5)",
2329 .test = alg_test_skcipher,
2333 .vecs = cast5_ctr_enc_tv_template,
2334 .count = CAST5_CTR_ENC_TEST_VECTORS
2337 .vecs = cast5_ctr_dec_tv_template,
2338 .count = CAST5_CTR_DEC_TEST_VECTORS
2343 .alg = "ctr(cast6)",
2344 .test = alg_test_skcipher,
2348 .vecs = cast6_ctr_enc_tv_template,
2349 .count = CAST6_CTR_ENC_TEST_VECTORS
2352 .vecs = cast6_ctr_dec_tv_template,
2353 .count = CAST6_CTR_DEC_TEST_VECTORS
2359 .test = alg_test_skcipher,
2363 .vecs = des_ctr_enc_tv_template,
2364 .count = DES_CTR_ENC_TEST_VECTORS
2367 .vecs = des_ctr_dec_tv_template,
2368 .count = DES_CTR_DEC_TEST_VECTORS
2373 .alg = "ctr(des3_ede)",
2374 .test = alg_test_skcipher,
2378 .vecs = des3_ede_ctr_enc_tv_template,
2379 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2382 .vecs = des3_ede_ctr_dec_tv_template,
2383 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2388 .alg = "ctr(serpent)",
2389 .test = alg_test_skcipher,
2393 .vecs = serpent_ctr_enc_tv_template,
2394 .count = SERPENT_CTR_ENC_TEST_VECTORS
2397 .vecs = serpent_ctr_dec_tv_template,
2398 .count = SERPENT_CTR_DEC_TEST_VECTORS
2403 .alg = "ctr(twofish)",
2404 .test = alg_test_skcipher,
2408 .vecs = tf_ctr_enc_tv_template,
2409 .count = TF_CTR_ENC_TEST_VECTORS
2412 .vecs = tf_ctr_dec_tv_template,
2413 .count = TF_CTR_DEC_TEST_VECTORS
2418 .alg = "cts(cbc(aes))",
2419 .test = alg_test_skcipher,
2423 .vecs = cts_mode_enc_tv_template,
2424 .count = CTS_MODE_ENC_TEST_VECTORS
2427 .vecs = cts_mode_dec_tv_template,
2428 .count = CTS_MODE_DEC_TEST_VECTORS
2434 .test = alg_test_comp,
2439 .vecs = deflate_comp_tv_template,
2440 .count = DEFLATE_COMP_TEST_VECTORS
2443 .vecs = deflate_decomp_tv_template,
2444 .count = DEFLATE_DECOMP_TEST_VECTORS
2449 .alg = "digest_null",
2450 .test = alg_test_null,
2452 .alg = "ecb(__aes-aesni)",
2453 .test = alg_test_null,
2457 .test = alg_test_skcipher,
2462 .vecs = aes_enc_tv_template,
2463 .count = AES_ENC_TEST_VECTORS
2466 .vecs = aes_dec_tv_template,
2467 .count = AES_DEC_TEST_VECTORS
2472 .alg = "ecb(anubis)",
2473 .test = alg_test_skcipher,
2477 .vecs = anubis_enc_tv_template,
2478 .count = ANUBIS_ENC_TEST_VECTORS
2481 .vecs = anubis_dec_tv_template,
2482 .count = ANUBIS_DEC_TEST_VECTORS
2488 .test = alg_test_skcipher,
2492 .vecs = arc4_enc_tv_template,
2493 .count = ARC4_ENC_TEST_VECTORS
2496 .vecs = arc4_dec_tv_template,
2497 .count = ARC4_DEC_TEST_VECTORS
2502 .alg = "ecb(blowfish)",
2503 .test = alg_test_skcipher,
2507 .vecs = bf_enc_tv_template,
2508 .count = BF_ENC_TEST_VECTORS
2511 .vecs = bf_dec_tv_template,
2512 .count = BF_DEC_TEST_VECTORS
2517 .alg = "ecb(camellia)",
2518 .test = alg_test_skcipher,
2522 .vecs = camellia_enc_tv_template,
2523 .count = CAMELLIA_ENC_TEST_VECTORS
2526 .vecs = camellia_dec_tv_template,
2527 .count = CAMELLIA_DEC_TEST_VECTORS
2532 .alg = "ecb(cast5)",
2533 .test = alg_test_skcipher,
2537 .vecs = cast5_enc_tv_template,
2538 .count = CAST5_ENC_TEST_VECTORS
2541 .vecs = cast5_dec_tv_template,
2542 .count = CAST5_DEC_TEST_VECTORS
2547 .alg = "ecb(cast6)",
2548 .test = alg_test_skcipher,
2552 .vecs = cast6_enc_tv_template,
2553 .count = CAST6_ENC_TEST_VECTORS
2556 .vecs = cast6_dec_tv_template,
2557 .count = CAST6_DEC_TEST_VECTORS
2562 .alg = "ecb(cipher_null)",
2563 .test = alg_test_null,
2566 .test = alg_test_skcipher,
2571 .vecs = des_enc_tv_template,
2572 .count = DES_ENC_TEST_VECTORS
2575 .vecs = des_dec_tv_template,
2576 .count = DES_DEC_TEST_VECTORS
2581 .alg = "ecb(des3_ede)",
2582 .test = alg_test_skcipher,
2587 .vecs = des3_ede_enc_tv_template,
2588 .count = DES3_EDE_ENC_TEST_VECTORS
2591 .vecs = des3_ede_dec_tv_template,
2592 .count = DES3_EDE_DEC_TEST_VECTORS
2597 .alg = "ecb(fcrypt)",
2598 .test = alg_test_skcipher,
2602 .vecs = fcrypt_pcbc_enc_tv_template,
2606 .vecs = fcrypt_pcbc_dec_tv_template,
2612 .alg = "ecb(khazad)",
2613 .test = alg_test_skcipher,
2617 .vecs = khazad_enc_tv_template,
2618 .count = KHAZAD_ENC_TEST_VECTORS
2621 .vecs = khazad_dec_tv_template,
2622 .count = KHAZAD_DEC_TEST_VECTORS
2628 .test = alg_test_skcipher,
2632 .vecs = seed_enc_tv_template,
2633 .count = SEED_ENC_TEST_VECTORS
2636 .vecs = seed_dec_tv_template,
2637 .count = SEED_DEC_TEST_VECTORS
2642 .alg = "ecb(serpent)",
2643 .test = alg_test_skcipher,
2647 .vecs = serpent_enc_tv_template,
2648 .count = SERPENT_ENC_TEST_VECTORS
2651 .vecs = serpent_dec_tv_template,
2652 .count = SERPENT_DEC_TEST_VECTORS
2658 .test = alg_test_skcipher,
2662 .vecs = tea_enc_tv_template,
2663 .count = TEA_ENC_TEST_VECTORS
2666 .vecs = tea_dec_tv_template,
2667 .count = TEA_DEC_TEST_VECTORS
2672 .alg = "ecb(tnepres)",
2673 .test = alg_test_skcipher,
2677 .vecs = tnepres_enc_tv_template,
2678 .count = TNEPRES_ENC_TEST_VECTORS
2681 .vecs = tnepres_dec_tv_template,
2682 .count = TNEPRES_DEC_TEST_VECTORS
2687 .alg = "ecb(twofish)",
2688 .test = alg_test_skcipher,
2692 .vecs = tf_enc_tv_template,
2693 .count = TF_ENC_TEST_VECTORS
2696 .vecs = tf_dec_tv_template,
2697 .count = TF_DEC_TEST_VECTORS
2703 .test = alg_test_skcipher,
2707 .vecs = xeta_enc_tv_template,
2708 .count = XETA_ENC_TEST_VECTORS
2711 .vecs = xeta_dec_tv_template,
2712 .count = XETA_DEC_TEST_VECTORS
2718 .test = alg_test_skcipher,
2722 .vecs = xtea_enc_tv_template,
2723 .count = XTEA_ENC_TEST_VECTORS
2726 .vecs = xtea_dec_tv_template,
2727 .count = XTEA_DEC_TEST_VECTORS
2733 .test = alg_test_aead,
2738 .vecs = aes_gcm_enc_tv_template,
2739 .count = AES_GCM_ENC_TEST_VECTORS
2742 .vecs = aes_gcm_dec_tv_template,
2743 .count = AES_GCM_DEC_TEST_VECTORS
2749 .test = alg_test_hash,
2753 .vecs = ghash_tv_template,
2754 .count = GHASH_TEST_VECTORS
2758 .alg = "hmac(crc32)",
2759 .test = alg_test_hash,
2762 .vecs = bfin_crc_tv_template,
2763 .count = BFIN_CRC_TEST_VECTORS
2768 .test = alg_test_hash,
2771 .vecs = hmac_md5_tv_template,
2772 .count = HMAC_MD5_TEST_VECTORS
2776 .alg = "hmac(rmd128)",
2777 .test = alg_test_hash,
2780 .vecs = hmac_rmd128_tv_template,
2781 .count = HMAC_RMD128_TEST_VECTORS
2785 .alg = "hmac(rmd160)",
2786 .test = alg_test_hash,
2789 .vecs = hmac_rmd160_tv_template,
2790 .count = HMAC_RMD160_TEST_VECTORS
2794 .alg = "hmac(sha1)",
2795 .test = alg_test_hash,
2799 .vecs = hmac_sha1_tv_template,
2800 .count = HMAC_SHA1_TEST_VECTORS
2804 .alg = "hmac(sha224)",
2805 .test = alg_test_hash,
2809 .vecs = hmac_sha224_tv_template,
2810 .count = HMAC_SHA224_TEST_VECTORS
2814 .alg = "hmac(sha256)",
2815 .test = alg_test_hash,
2819 .vecs = hmac_sha256_tv_template,
2820 .count = HMAC_SHA256_TEST_VECTORS
2824 .alg = "hmac(sha384)",
2825 .test = alg_test_hash,
2829 .vecs = hmac_sha384_tv_template,
2830 .count = HMAC_SHA384_TEST_VECTORS
2834 .alg = "hmac(sha512)",
2835 .test = alg_test_hash,
2839 .vecs = hmac_sha512_tv_template,
2840 .count = HMAC_SHA512_TEST_VECTORS
2845 .test = alg_test_skcipher,
2849 .vecs = aes_lrw_enc_tv_template,
2850 .count = AES_LRW_ENC_TEST_VECTORS
2853 .vecs = aes_lrw_dec_tv_template,
2854 .count = AES_LRW_DEC_TEST_VECTORS
2859 .alg = "lrw(camellia)",
2860 .test = alg_test_skcipher,
2864 .vecs = camellia_lrw_enc_tv_template,
2865 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
2868 .vecs = camellia_lrw_dec_tv_template,
2869 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
2874 .alg = "lrw(cast6)",
2875 .test = alg_test_skcipher,
2879 .vecs = cast6_lrw_enc_tv_template,
2880 .count = CAST6_LRW_ENC_TEST_VECTORS
2883 .vecs = cast6_lrw_dec_tv_template,
2884 .count = CAST6_LRW_DEC_TEST_VECTORS
2889 .alg = "lrw(serpent)",
2890 .test = alg_test_skcipher,
2894 .vecs = serpent_lrw_enc_tv_template,
2895 .count = SERPENT_LRW_ENC_TEST_VECTORS
2898 .vecs = serpent_lrw_dec_tv_template,
2899 .count = SERPENT_LRW_DEC_TEST_VECTORS
2904 .alg = "lrw(twofish)",
2905 .test = alg_test_skcipher,
2909 .vecs = tf_lrw_enc_tv_template,
2910 .count = TF_LRW_ENC_TEST_VECTORS
2913 .vecs = tf_lrw_dec_tv_template,
2914 .count = TF_LRW_DEC_TEST_VECTORS
2920 .test = alg_test_comp,
2925 .vecs = lzo_comp_tv_template,
2926 .count = LZO_COMP_TEST_VECTORS
2929 .vecs = lzo_decomp_tv_template,
2930 .count = LZO_DECOMP_TEST_VECTORS
2936 .test = alg_test_hash,
2939 .vecs = md4_tv_template,
2940 .count = MD4_TEST_VECTORS
2945 .test = alg_test_hash,
2948 .vecs = md5_tv_template,
2949 .count = MD5_TEST_VECTORS
2953 .alg = "michael_mic",
2954 .test = alg_test_hash,
2957 .vecs = michael_mic_tv_template,
2958 .count = MICHAEL_MIC_TEST_VECTORS
2963 .test = alg_test_skcipher,
2968 .vecs = aes_ofb_enc_tv_template,
2969 .count = AES_OFB_ENC_TEST_VECTORS
2972 .vecs = aes_ofb_dec_tv_template,
2973 .count = AES_OFB_DEC_TEST_VECTORS
2978 .alg = "pcbc(fcrypt)",
2979 .test = alg_test_skcipher,
2983 .vecs = fcrypt_pcbc_enc_tv_template,
2984 .count = FCRYPT_ENC_TEST_VECTORS
2987 .vecs = fcrypt_pcbc_dec_tv_template,
2988 .count = FCRYPT_DEC_TEST_VECTORS
2993 .alg = "rfc3686(ctr(aes))",
2994 .test = alg_test_skcipher,
2999 .vecs = aes_ctr_rfc3686_enc_tv_template,
3000 .count = AES_CTR_3686_ENC_TEST_VECTORS
3003 .vecs = aes_ctr_rfc3686_dec_tv_template,
3004 .count = AES_CTR_3686_DEC_TEST_VECTORS
3009 .alg = "rfc4106(gcm(aes))",
3010 .test = alg_test_aead,
3014 .vecs = aes_gcm_rfc4106_enc_tv_template,
3015 .count = AES_GCM_4106_ENC_TEST_VECTORS
3018 .vecs = aes_gcm_rfc4106_dec_tv_template,
3019 .count = AES_GCM_4106_DEC_TEST_VECTORS
3024 .alg = "rfc4309(ccm(aes))",
3025 .test = alg_test_aead,
3030 .vecs = aes_ccm_rfc4309_enc_tv_template,
3031 .count = AES_CCM_4309_ENC_TEST_VECTORS
3034 .vecs = aes_ccm_rfc4309_dec_tv_template,
3035 .count = AES_CCM_4309_DEC_TEST_VECTORS
3040 .alg = "rfc4543(gcm(aes))",
3041 .test = alg_test_aead,
3045 .vecs = aes_gcm_rfc4543_enc_tv_template,
3046 .count = AES_GCM_4543_ENC_TEST_VECTORS
3049 .vecs = aes_gcm_rfc4543_dec_tv_template,
3050 .count = AES_GCM_4543_DEC_TEST_VECTORS
3056 .test = alg_test_hash,
3059 .vecs = rmd128_tv_template,
3060 .count = RMD128_TEST_VECTORS
3065 .test = alg_test_hash,
3068 .vecs = rmd160_tv_template,
3069 .count = RMD160_TEST_VECTORS
3074 .test = alg_test_hash,
3077 .vecs = rmd256_tv_template,
3078 .count = RMD256_TEST_VECTORS
3083 .test = alg_test_hash,
3086 .vecs = rmd320_tv_template,
3087 .count = RMD320_TEST_VECTORS
3092 .test = alg_test_skcipher,
3096 .vecs = salsa20_stream_enc_tv_template,
3097 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3103 .test = alg_test_hash,
3107 .vecs = sha1_tv_template,
3108 .count = SHA1_TEST_VECTORS
3113 .test = alg_test_hash,
3117 .vecs = sha224_tv_template,
3118 .count = SHA224_TEST_VECTORS
3123 .test = alg_test_hash,
3127 .vecs = sha256_tv_template,
3128 .count = SHA256_TEST_VECTORS
3133 .test = alg_test_hash,
3137 .vecs = sha384_tv_template,
3138 .count = SHA384_TEST_VECTORS
3143 .test = alg_test_hash,
3147 .vecs = sha512_tv_template,
3148 .count = SHA512_TEST_VECTORS
3153 .test = alg_test_hash,
3156 .vecs = tgr128_tv_template,
3157 .count = TGR128_TEST_VECTORS
3162 .test = alg_test_hash,
3165 .vecs = tgr160_tv_template,
3166 .count = TGR160_TEST_VECTORS
3171 .test = alg_test_hash,
3174 .vecs = tgr192_tv_template,
3175 .count = TGR192_TEST_VECTORS
3180 .test = alg_test_hash,
3183 .vecs = aes_vmac128_tv_template,
3184 .count = VMAC_AES_TEST_VECTORS
3189 .test = alg_test_hash,
3192 .vecs = wp256_tv_template,
3193 .count = WP256_TEST_VECTORS
3198 .test = alg_test_hash,
3201 .vecs = wp384_tv_template,
3202 .count = WP384_TEST_VECTORS
3207 .test = alg_test_hash,
3210 .vecs = wp512_tv_template,
3211 .count = WP512_TEST_VECTORS
3216 .test = alg_test_hash,
3219 .vecs = aes_xcbc128_tv_template,
3220 .count = XCBC_AES_TEST_VECTORS
3225 .test = alg_test_skcipher,
3230 .vecs = aes_xts_enc_tv_template,
3231 .count = AES_XTS_ENC_TEST_VECTORS
3234 .vecs = aes_xts_dec_tv_template,
3235 .count = AES_XTS_DEC_TEST_VECTORS
3240 .alg = "xts(camellia)",
3241 .test = alg_test_skcipher,
3245 .vecs = camellia_xts_enc_tv_template,
3246 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3249 .vecs = camellia_xts_dec_tv_template,
3250 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3255 .alg = "xts(cast6)",
3256 .test = alg_test_skcipher,
3260 .vecs = cast6_xts_enc_tv_template,
3261 .count = CAST6_XTS_ENC_TEST_VECTORS
3264 .vecs = cast6_xts_dec_tv_template,
3265 .count = CAST6_XTS_DEC_TEST_VECTORS
3270 .alg = "xts(serpent)",
3271 .test = alg_test_skcipher,
3275 .vecs = serpent_xts_enc_tv_template,
3276 .count = SERPENT_XTS_ENC_TEST_VECTORS
3279 .vecs = serpent_xts_dec_tv_template,
3280 .count = SERPENT_XTS_DEC_TEST_VECTORS
3285 .alg = "xts(twofish)",
3286 .test = alg_test_skcipher,
3290 .vecs = tf_xts_enc_tv_template,
3291 .count = TF_XTS_ENC_TEST_VECTORS
3294 .vecs = tf_xts_dec_tv_template,
3295 .count = TF_XTS_DEC_TEST_VECTORS
3301 .test = alg_test_pcomp,
3306 .vecs = zlib_comp_tv_template,
3307 .count = ZLIB_COMP_TEST_VECTORS
3310 .vecs = zlib_decomp_tv_template,
3311 .count = ZLIB_DECOMP_TEST_VECTORS
3318 static bool alg_test_descs_checked;
3320 static void alg_test_descs_check_order(void)
3324 /* only check once */
3325 if (alg_test_descs_checked)
3328 alg_test_descs_checked = true;
3330 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3331 int diff = strcmp(alg_test_descs[i - 1].alg,
3332 alg_test_descs[i].alg);
3334 if (WARN_ON(diff > 0)) {
3335 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3336 alg_test_descs[i - 1].alg,
3337 alg_test_descs[i].alg);
3340 if (WARN_ON(diff == 0)) {
3341 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3342 alg_test_descs[i].alg);
3347 static int alg_find_test(const char *alg)
3350 int end = ARRAY_SIZE(alg_test_descs);
3352 while (start < end) {
3353 int i = (start + end) / 2;
3354 int diff = strcmp(alg_test_descs[i].alg, alg);
3372 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3378 alg_test_descs_check_order();
3380 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3381 char nalg[CRYPTO_MAX_ALG_NAME];
3383 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3385 return -ENAMETOOLONG;
3387 i = alg_find_test(nalg);
3391 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3394 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3398 i = alg_find_test(alg);
3399 j = alg_find_test(driver);
3403 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3404 (j >= 0 && !alg_test_descs[j].fips_allowed)))
3409 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3411 if (j >= 0 && j != i)
3412 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3416 if (fips_enabled && rc)
3417 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3419 if (fips_enabled && !rc)
3420 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3426 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3432 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3434 EXPORT_SYMBOL_GPL(alg_test);