2 * Algorithm testing framework and tests.
6 * Copyright (c) 2007 Nokia Siemens Networks
9 * Updated RFC4106 AES-GCM testing.
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];
195 struct ahash_request *req;
196 struct tcrypt_result tresult;
198 char *xbuf[XBUFSIZE];
201 if (testmgr_alloc_buf(xbuf))
204 init_completion(&tresult.completion);
206 req = ahash_request_alloc(tfm, GFP_KERNEL);
208 printk(KERN_ERR "alg: hash: Failed to allocate request for "
212 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
213 tcrypt_complete, &tresult);
216 for (i = 0; i < tcount; i++) {
221 if (WARN_ON(align_offset + template[i].psize > PAGE_SIZE))
225 memset(result, 0, 64);
228 hash_buff += align_offset;
230 memcpy(hash_buff, template[i].plaintext, template[i].psize);
231 sg_init_one(&sg[0], hash_buff, template[i].psize);
233 if (template[i].ksize) {
234 crypto_ahash_clear_flags(tfm, ~0);
235 ret = crypto_ahash_setkey(tfm, template[i].key,
238 printk(KERN_ERR "alg: hash: setkey failed on "
239 "test %d for %s: ret=%d\n", j, algo,
245 ahash_request_set_crypt(req, sg, result, template[i].psize);
247 ret = do_one_async_hash_op(req, &tresult,
248 crypto_ahash_digest(req));
250 pr_err("alg: hash: digest failed on test %d "
251 "for %s: ret=%d\n", j, algo, -ret);
255 ret = do_one_async_hash_op(req, &tresult,
256 crypto_ahash_init(req));
258 pr_err("alt: hash: init failed on test %d "
259 "for %s: ret=%d\n", j, algo, -ret);
262 ret = do_one_async_hash_op(req, &tresult,
263 crypto_ahash_update(req));
265 pr_err("alt: hash: update failed on test %d "
266 "for %s: ret=%d\n", j, algo, -ret);
269 ret = do_one_async_hash_op(req, &tresult,
270 crypto_ahash_final(req));
272 pr_err("alt: hash: final failed on test %d "
273 "for %s: ret=%d\n", j, algo, -ret);
278 if (memcmp(result, template[i].digest,
279 crypto_ahash_digestsize(tfm))) {
280 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
282 hexdump(result, crypto_ahash_digestsize(tfm));
289 for (i = 0; i < tcount; i++) {
290 /* alignment tests are only done with continuous buffers */
291 if (align_offset != 0)
294 if (template[i].np) {
296 memset(result, 0, 64);
299 sg_init_table(sg, template[i].np);
301 for (k = 0; k < template[i].np; k++) {
302 if (WARN_ON(offset_in_page(IDX[k]) +
303 template[i].tap[k] > PAGE_SIZE))
306 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
307 offset_in_page(IDX[k]),
308 template[i].plaintext + temp,
311 temp += template[i].tap[k];
314 if (template[i].ksize) {
315 crypto_ahash_clear_flags(tfm, ~0);
316 ret = crypto_ahash_setkey(tfm, template[i].key,
320 printk(KERN_ERR "alg: hash: setkey "
321 "failed on chunking test %d "
322 "for %s: ret=%d\n", j, algo,
328 ahash_request_set_crypt(req, sg, result,
330 ret = crypto_ahash_digest(req);
336 ret = wait_for_completion_interruptible(
337 &tresult.completion);
338 if (!ret && !(ret = tresult.err)) {
339 reinit_completion(&tresult.completion);
344 printk(KERN_ERR "alg: hash: digest failed "
345 "on chunking test %d for %s: "
346 "ret=%d\n", j, algo, -ret);
350 if (memcmp(result, template[i].digest,
351 crypto_ahash_digestsize(tfm))) {
352 printk(KERN_ERR "alg: hash: Chunking test %d "
353 "failed for %s\n", j, algo);
354 hexdump(result, crypto_ahash_digestsize(tfm));
364 ahash_request_free(req);
366 testmgr_free_buf(xbuf);
371 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
372 unsigned int tcount, bool use_digest)
374 unsigned int alignmask;
377 ret = __test_hash(tfm, template, tcount, use_digest, 0);
381 /* test unaligned buffers, check with one byte offset */
382 ret = __test_hash(tfm, template, tcount, use_digest, 1);
386 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
388 /* Check if alignment mask for tfm is correctly set. */
389 ret = __test_hash(tfm, template, tcount, use_digest,
398 static int __test_aead(struct crypto_aead *tfm, int enc,
399 struct aead_testvec *template, unsigned int tcount,
400 const bool diff_dst, const int align_offset)
402 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
403 unsigned int i, j, k, n, temp;
407 struct aead_request *req;
408 struct scatterlist *sg;
409 struct scatterlist *asg;
410 struct scatterlist *sgout;
412 struct tcrypt_result result;
413 unsigned int authsize;
418 char *xbuf[XBUFSIZE];
419 char *xoutbuf[XBUFSIZE];
420 char *axbuf[XBUFSIZE];
422 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
425 if (testmgr_alloc_buf(xbuf))
427 if (testmgr_alloc_buf(axbuf))
429 if (diff_dst && testmgr_alloc_buf(xoutbuf))
432 /* avoid "the frame size is larger than 1024 bytes" compiler warning */
433 sg = kmalloc(sizeof(*sg) * 8 * (diff_dst ? 3 : 2), GFP_KERNEL);
449 init_completion(&result.completion);
451 req = aead_request_alloc(tfm, GFP_KERNEL);
453 pr_err("alg: aead%s: Failed to allocate request for %s\n",
458 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
459 tcrypt_complete, &result);
461 for (i = 0, j = 0; i < tcount; i++) {
462 if (!template[i].np) {
465 /* some templates have no input data but they will
469 input += align_offset;
473 if (WARN_ON(align_offset + template[i].ilen >
474 PAGE_SIZE || template[i].alen > PAGE_SIZE))
477 memcpy(input, template[i].input, template[i].ilen);
478 memcpy(assoc, template[i].assoc, template[i].alen);
480 memcpy(iv, template[i].iv, MAX_IVLEN);
482 memset(iv, 0, MAX_IVLEN);
484 crypto_aead_clear_flags(tfm, ~0);
486 crypto_aead_set_flags(
487 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
489 key = template[i].key;
491 ret = crypto_aead_setkey(tfm, key,
493 if (!ret == template[i].fail) {
494 pr_err("alg: aead%s: setkey failed on test %d for %s: flags=%x\n",
495 d, j, algo, crypto_aead_get_flags(tfm));
500 authsize = abs(template[i].rlen - template[i].ilen);
501 ret = crypto_aead_setauthsize(tfm, authsize);
503 pr_err("alg: aead%s: Failed to set authsize to %u on test %d for %s\n",
504 d, authsize, j, algo);
510 output += align_offset;
511 sg_init_one(&sg[0], input, template[i].ilen);
512 sg_init_one(&sgout[0], output,
515 sg_init_one(&sg[0], input,
517 (enc ? authsize : 0));
521 sg_init_one(&asg[0], assoc, template[i].alen);
523 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
524 template[i].ilen, iv);
526 aead_request_set_assoc(req, asg, template[i].alen);
529 crypto_aead_encrypt(req) :
530 crypto_aead_decrypt(req);
534 if (template[i].novrfy) {
535 /* verification was supposed to fail */
536 pr_err("alg: aead%s: %s failed on test %d for %s: ret was 0, expected -EBADMSG\n",
538 /* so really, we got a bad message */
545 ret = wait_for_completion_interruptible(
547 if (!ret && !(ret = result.err)) {
548 reinit_completion(&result.completion);
552 if (template[i].novrfy)
553 /* verification failure was expected */
557 pr_err("alg: aead%s: %s failed on test %d for %s: ret=%d\n",
558 d, e, j, algo, -ret);
563 if (memcmp(q, template[i].result, template[i].rlen)) {
564 pr_err("alg: aead%s: Test %d failed on %s for %s\n",
566 hexdump(q, template[i].rlen);
573 for (i = 0, j = 0; i < tcount; i++) {
574 /* alignment tests are only done with continuous buffers */
575 if (align_offset != 0)
578 if (template[i].np) {
582 memcpy(iv, template[i].iv, MAX_IVLEN);
584 memset(iv, 0, MAX_IVLEN);
586 crypto_aead_clear_flags(tfm, ~0);
588 crypto_aead_set_flags(
589 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
590 key = template[i].key;
592 ret = crypto_aead_setkey(tfm, key, template[i].klen);
593 if (!ret == template[i].fail) {
594 pr_err("alg: aead%s: setkey failed on chunk test %d for %s: flags=%x\n",
595 d, j, algo, crypto_aead_get_flags(tfm));
600 authsize = abs(template[i].rlen - template[i].ilen);
603 sg_init_table(sg, template[i].np);
605 sg_init_table(sgout, template[i].np);
606 for (k = 0, temp = 0; k < template[i].np; k++) {
607 if (WARN_ON(offset_in_page(IDX[k]) +
608 template[i].tap[k] > PAGE_SIZE))
611 q = xbuf[IDX[k] >> PAGE_SHIFT] +
612 offset_in_page(IDX[k]);
614 memcpy(q, template[i].input + temp,
617 sg_set_buf(&sg[k], q, template[i].tap[k]);
620 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
621 offset_in_page(IDX[k]);
623 memset(q, 0, template[i].tap[k]);
625 sg_set_buf(&sgout[k], q,
629 n = template[i].tap[k];
630 if (k == template[i].np - 1 && enc)
632 if (offset_in_page(q) + n < PAGE_SIZE)
635 temp += template[i].tap[k];
638 ret = crypto_aead_setauthsize(tfm, authsize);
640 pr_err("alg: aead%s: Failed to set authsize to %u on chunk test %d for %s\n",
641 d, authsize, j, algo);
646 if (WARN_ON(sg[k - 1].offset +
647 sg[k - 1].length + authsize >
654 sgout[k - 1].length += authsize;
656 sg[k - 1].length += authsize;
659 sg_init_table(asg, template[i].anp);
661 for (k = 0, temp = 0; k < template[i].anp; k++) {
662 if (WARN_ON(offset_in_page(IDX[k]) +
663 template[i].atap[k] > PAGE_SIZE))
666 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
667 offset_in_page(IDX[k]),
668 template[i].assoc + temp,
669 template[i].atap[k]),
670 template[i].atap[k]);
671 temp += template[i].atap[k];
674 aead_request_set_crypt(req, sg, (diff_dst) ? sgout : sg,
678 aead_request_set_assoc(req, asg, template[i].alen);
681 crypto_aead_encrypt(req) :
682 crypto_aead_decrypt(req);
686 if (template[i].novrfy) {
687 /* verification was supposed to fail */
688 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret was 0, expected -EBADMSG\n",
690 /* so really, we got a bad message */
697 ret = wait_for_completion_interruptible(
699 if (!ret && !(ret = result.err)) {
700 reinit_completion(&result.completion);
704 if (template[i].novrfy)
705 /* verification failure was expected */
709 pr_err("alg: aead%s: %s failed on chunk test %d for %s: ret=%d\n",
710 d, e, j, algo, -ret);
715 for (k = 0, temp = 0; k < template[i].np; k++) {
717 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
718 offset_in_page(IDX[k]);
720 q = xbuf[IDX[k] >> PAGE_SHIFT] +
721 offset_in_page(IDX[k]);
723 n = template[i].tap[k];
724 if (k == template[i].np - 1)
725 n += enc ? authsize : -authsize;
727 if (memcmp(q, template[i].result + temp, n)) {
728 pr_err("alg: aead%s: Chunk test %d failed on %s at page %u for %s\n",
735 if (k == template[i].np - 1 && !enc) {
737 memcmp(q, template[i].input +
743 for (n = 0; offset_in_page(q + n) &&
748 pr_err("alg: aead%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
749 d, j, e, k, algo, n);
754 temp += template[i].tap[k];
762 aead_request_free(req);
766 testmgr_free_buf(xoutbuf);
768 testmgr_free_buf(axbuf);
770 testmgr_free_buf(xbuf);
776 static int test_aead(struct crypto_aead *tfm, int enc,
777 struct aead_testvec *template, unsigned int tcount)
779 unsigned int alignmask;
782 /* test 'dst == src' case */
783 ret = __test_aead(tfm, enc, template, tcount, false, 0);
787 /* test 'dst != src' case */
788 ret = __test_aead(tfm, enc, template, tcount, true, 0);
792 /* test unaligned buffers, check with one byte offset */
793 ret = __test_aead(tfm, enc, template, tcount, true, 1);
797 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
799 /* Check if alignment mask for tfm is correctly set. */
800 ret = __test_aead(tfm, enc, template, tcount, true,
809 static int test_cipher(struct crypto_cipher *tfm, int enc,
810 struct cipher_testvec *template, unsigned int tcount)
812 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
813 unsigned int i, j, k;
817 char *xbuf[XBUFSIZE];
820 if (testmgr_alloc_buf(xbuf))
829 for (i = 0; i < tcount; i++) {
836 if (WARN_ON(template[i].ilen > PAGE_SIZE))
840 memcpy(data, template[i].input, template[i].ilen);
842 crypto_cipher_clear_flags(tfm, ~0);
844 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
846 ret = crypto_cipher_setkey(tfm, template[i].key,
848 if (!ret == template[i].fail) {
849 printk(KERN_ERR "alg: cipher: setkey failed "
850 "on test %d for %s: flags=%x\n", j,
851 algo, crypto_cipher_get_flags(tfm));
856 for (k = 0; k < template[i].ilen;
857 k += crypto_cipher_blocksize(tfm)) {
859 crypto_cipher_encrypt_one(tfm, data + k,
862 crypto_cipher_decrypt_one(tfm, data + k,
867 if (memcmp(q, template[i].result, template[i].rlen)) {
868 printk(KERN_ERR "alg: cipher: Test %d failed "
869 "on %s for %s\n", j, e, algo);
870 hexdump(q, template[i].rlen);
879 testmgr_free_buf(xbuf);
884 static int __test_skcipher(struct crypto_ablkcipher *tfm, int enc,
885 struct cipher_testvec *template, unsigned int tcount,
886 const bool diff_dst, const int align_offset)
889 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
890 unsigned int i, j, k, n, temp;
892 struct ablkcipher_request *req;
893 struct scatterlist sg[8];
894 struct scatterlist sgout[8];
896 struct tcrypt_result result;
899 char *xbuf[XBUFSIZE];
900 char *xoutbuf[XBUFSIZE];
903 if (testmgr_alloc_buf(xbuf))
906 if (diff_dst && testmgr_alloc_buf(xoutbuf))
919 init_completion(&result.completion);
921 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
923 pr_err("alg: skcipher%s: Failed to allocate request for %s\n",
928 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
929 tcrypt_complete, &result);
932 for (i = 0; i < tcount; i++) {
934 memcpy(iv, template[i].iv, MAX_IVLEN);
936 memset(iv, 0, MAX_IVLEN);
938 if (!(template[i].np) || (template[i].also_non_np)) {
942 if (WARN_ON(align_offset + template[i].ilen >
947 data += align_offset;
948 memcpy(data, template[i].input, template[i].ilen);
950 crypto_ablkcipher_clear_flags(tfm, ~0);
952 crypto_ablkcipher_set_flags(
953 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
955 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
957 if (!ret == template[i].fail) {
958 pr_err("alg: skcipher%s: setkey failed on test %d for %s: flags=%x\n",
960 crypto_ablkcipher_get_flags(tfm));
965 sg_init_one(&sg[0], data, template[i].ilen);
968 data += align_offset;
969 sg_init_one(&sgout[0], data, template[i].ilen);
972 ablkcipher_request_set_crypt(req, sg,
973 (diff_dst) ? sgout : sg,
974 template[i].ilen, iv);
976 crypto_ablkcipher_encrypt(req) :
977 crypto_ablkcipher_decrypt(req);
984 ret = wait_for_completion_interruptible(
986 if (!ret && !((ret = result.err))) {
987 reinit_completion(&result.completion);
992 pr_err("alg: skcipher%s: %s failed on test %d for %s: ret=%d\n",
993 d, e, j, algo, -ret);
998 if (memcmp(q, template[i].result, template[i].rlen)) {
999 pr_err("alg: skcipher%s: Test %d failed on %s for %s\n",
1001 hexdump(q, template[i].rlen);
1009 for (i = 0; i < tcount; i++) {
1010 /* alignment tests are only done with continuous buffers */
1011 if (align_offset != 0)
1015 memcpy(iv, template[i].iv, MAX_IVLEN);
1017 memset(iv, 0, MAX_IVLEN);
1019 if (template[i].np) {
1022 crypto_ablkcipher_clear_flags(tfm, ~0);
1024 crypto_ablkcipher_set_flags(
1025 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
1027 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
1029 if (!ret == template[i].fail) {
1030 pr_err("alg: skcipher%s: setkey failed on chunk test %d for %s: flags=%x\n",
1032 crypto_ablkcipher_get_flags(tfm));
1039 sg_init_table(sg, template[i].np);
1041 sg_init_table(sgout, template[i].np);
1042 for (k = 0; k < template[i].np; k++) {
1043 if (WARN_ON(offset_in_page(IDX[k]) +
1044 template[i].tap[k] > PAGE_SIZE))
1047 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1048 offset_in_page(IDX[k]);
1050 memcpy(q, template[i].input + temp,
1051 template[i].tap[k]);
1053 if (offset_in_page(q) + template[i].tap[k] <
1055 q[template[i].tap[k]] = 0;
1057 sg_set_buf(&sg[k], q, template[i].tap[k]);
1059 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1060 offset_in_page(IDX[k]);
1062 sg_set_buf(&sgout[k], q,
1063 template[i].tap[k]);
1065 memset(q, 0, template[i].tap[k]);
1066 if (offset_in_page(q) +
1067 template[i].tap[k] < PAGE_SIZE)
1068 q[template[i].tap[k]] = 0;
1071 temp += template[i].tap[k];
1074 ablkcipher_request_set_crypt(req, sg,
1075 (diff_dst) ? sgout : sg,
1076 template[i].ilen, iv);
1079 crypto_ablkcipher_encrypt(req) :
1080 crypto_ablkcipher_decrypt(req);
1087 ret = wait_for_completion_interruptible(
1088 &result.completion);
1089 if (!ret && !((ret = result.err))) {
1090 reinit_completion(&result.completion);
1095 pr_err("alg: skcipher%s: %s failed on chunk test %d for %s: ret=%d\n",
1096 d, e, j, algo, -ret);
1102 for (k = 0; k < template[i].np; k++) {
1104 q = xoutbuf[IDX[k] >> PAGE_SHIFT] +
1105 offset_in_page(IDX[k]);
1107 q = xbuf[IDX[k] >> PAGE_SHIFT] +
1108 offset_in_page(IDX[k]);
1110 if (memcmp(q, template[i].result + temp,
1111 template[i].tap[k])) {
1112 pr_err("alg: skcipher%s: Chunk test %d failed on %s at page %u for %s\n",
1114 hexdump(q, template[i].tap[k]);
1118 q += template[i].tap[k];
1119 for (n = 0; offset_in_page(q + n) && q[n]; n++)
1122 pr_err("alg: skcipher%s: Result buffer corruption in chunk test %d on %s at page %u for %s: %u bytes:\n",
1123 d, j, e, k, algo, n);
1127 temp += template[i].tap[k];
1135 ablkcipher_request_free(req);
1137 testmgr_free_buf(xoutbuf);
1139 testmgr_free_buf(xbuf);
1144 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
1145 struct cipher_testvec *template, unsigned int tcount)
1147 unsigned int alignmask;
1150 /* test 'dst == src' case */
1151 ret = __test_skcipher(tfm, enc, template, tcount, false, 0);
1155 /* test 'dst != src' case */
1156 ret = __test_skcipher(tfm, enc, template, tcount, true, 0);
1160 /* test unaligned buffers, check with one byte offset */
1161 ret = __test_skcipher(tfm, enc, template, tcount, true, 1);
1165 alignmask = crypto_tfm_alg_alignmask(&tfm->base);
1167 /* Check if alignment mask for tfm is correctly set. */
1168 ret = __test_skcipher(tfm, enc, template, tcount, true,
1177 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
1178 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1180 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
1182 char result[COMP_BUF_SIZE];
1185 for (i = 0; i < ctcount; i++) {
1187 unsigned int dlen = COMP_BUF_SIZE;
1189 memset(result, 0, sizeof (result));
1191 ilen = ctemplate[i].inlen;
1192 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1193 ilen, result, &dlen);
1195 printk(KERN_ERR "alg: comp: compression failed "
1196 "on test %d for %s: ret=%d\n", i + 1, algo,
1201 if (dlen != ctemplate[i].outlen) {
1202 printk(KERN_ERR "alg: comp: Compression test %d "
1203 "failed for %s: output len = %d\n", i + 1, algo,
1209 if (memcmp(result, ctemplate[i].output, dlen)) {
1210 printk(KERN_ERR "alg: comp: Compression test %d "
1211 "failed for %s\n", i + 1, algo);
1212 hexdump(result, dlen);
1218 for (i = 0; i < dtcount; i++) {
1220 unsigned int dlen = COMP_BUF_SIZE;
1222 memset(result, 0, sizeof (result));
1224 ilen = dtemplate[i].inlen;
1225 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1226 ilen, result, &dlen);
1228 printk(KERN_ERR "alg: comp: decompression failed "
1229 "on test %d for %s: ret=%d\n", i + 1, algo,
1234 if (dlen != dtemplate[i].outlen) {
1235 printk(KERN_ERR "alg: comp: Decompression test %d "
1236 "failed for %s: output len = %d\n", i + 1, algo,
1242 if (memcmp(result, dtemplate[i].output, dlen)) {
1243 printk(KERN_ERR "alg: comp: Decompression test %d "
1244 "failed for %s\n", i + 1, algo);
1245 hexdump(result, dlen);
1257 static int test_pcomp(struct crypto_pcomp *tfm,
1258 struct pcomp_testvec *ctemplate,
1259 struct pcomp_testvec *dtemplate, int ctcount,
1262 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1264 char result[COMP_BUF_SIZE];
1267 for (i = 0; i < ctcount; i++) {
1268 struct comp_request req;
1269 unsigned int produced = 0;
1271 res = crypto_compress_setup(tfm, ctemplate[i].params,
1272 ctemplate[i].paramsize);
1274 pr_err("alg: pcomp: compression setup failed on test "
1275 "%d for %s: error=%d\n", i + 1, algo, res);
1279 res = crypto_compress_init(tfm);
1281 pr_err("alg: pcomp: compression init failed on test "
1282 "%d for %s: error=%d\n", i + 1, algo, res);
1286 memset(result, 0, sizeof(result));
1288 req.next_in = ctemplate[i].input;
1289 req.avail_in = ctemplate[i].inlen / 2;
1290 req.next_out = result;
1291 req.avail_out = ctemplate[i].outlen / 2;
1293 res = crypto_compress_update(tfm, &req);
1294 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1295 pr_err("alg: pcomp: compression update failed on test "
1296 "%d for %s: error=%d\n", i + 1, algo, res);
1302 /* Add remaining input data */
1303 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1305 res = crypto_compress_update(tfm, &req);
1306 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1307 pr_err("alg: pcomp: compression update failed on test "
1308 "%d for %s: error=%d\n", i + 1, algo, res);
1314 /* Provide remaining output space */
1315 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1317 res = crypto_compress_final(tfm, &req);
1319 pr_err("alg: pcomp: compression final failed on test "
1320 "%d for %s: error=%d\n", i + 1, algo, res);
1325 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1326 pr_err("alg: comp: Compression test %d failed for %s: "
1327 "output len = %d (expected %d)\n", i + 1, algo,
1328 COMP_BUF_SIZE - req.avail_out,
1329 ctemplate[i].outlen);
1333 if (produced != ctemplate[i].outlen) {
1334 pr_err("alg: comp: Compression test %d failed for %s: "
1335 "returned len = %u (expected %d)\n", i + 1,
1336 algo, produced, ctemplate[i].outlen);
1340 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1341 pr_err("alg: pcomp: Compression test %d failed for "
1342 "%s\n", i + 1, algo);
1343 hexdump(result, ctemplate[i].outlen);
1348 for (i = 0; i < dtcount; i++) {
1349 struct comp_request req;
1350 unsigned int produced = 0;
1352 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1353 dtemplate[i].paramsize);
1355 pr_err("alg: pcomp: decompression setup failed on "
1356 "test %d for %s: error=%d\n", i + 1, algo, res);
1360 res = crypto_decompress_init(tfm);
1362 pr_err("alg: pcomp: decompression init failed on test "
1363 "%d for %s: error=%d\n", i + 1, algo, res);
1367 memset(result, 0, sizeof(result));
1369 req.next_in = dtemplate[i].input;
1370 req.avail_in = dtemplate[i].inlen / 2;
1371 req.next_out = result;
1372 req.avail_out = dtemplate[i].outlen / 2;
1374 res = crypto_decompress_update(tfm, &req);
1375 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1376 pr_err("alg: pcomp: decompression update failed on "
1377 "test %d for %s: error=%d\n", i + 1, algo, res);
1383 /* Add remaining input data */
1384 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1386 res = crypto_decompress_update(tfm, &req);
1387 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1388 pr_err("alg: pcomp: decompression update failed on "
1389 "test %d for %s: error=%d\n", i + 1, algo, res);
1395 /* Provide remaining output space */
1396 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1398 res = crypto_decompress_final(tfm, &req);
1399 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1400 pr_err("alg: pcomp: decompression final failed on "
1401 "test %d for %s: error=%d\n", i + 1, algo, res);
1407 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1408 pr_err("alg: comp: Decompression test %d failed for "
1409 "%s: output len = %d (expected %d)\n", i + 1,
1410 algo, COMP_BUF_SIZE - req.avail_out,
1411 dtemplate[i].outlen);
1415 if (produced != dtemplate[i].outlen) {
1416 pr_err("alg: comp: Decompression test %d failed for "
1417 "%s: returned len = %u (expected %d)\n", i + 1,
1418 algo, produced, dtemplate[i].outlen);
1422 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1423 pr_err("alg: pcomp: Decompression test %d failed for "
1424 "%s\n", i + 1, algo);
1425 hexdump(result, dtemplate[i].outlen);
1434 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1435 unsigned int tcount)
1437 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1438 int err = 0, i, j, seedsize;
1442 seedsize = crypto_rng_seedsize(tfm);
1444 seed = kmalloc(seedsize, GFP_KERNEL);
1446 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1451 for (i = 0; i < tcount; i++) {
1452 memset(result, 0, 32);
1454 memcpy(seed, template[i].v, template[i].vlen);
1455 memcpy(seed + template[i].vlen, template[i].key,
1457 memcpy(seed + template[i].vlen + template[i].klen,
1458 template[i].dt, template[i].dtlen);
1460 err = crypto_rng_reset(tfm, seed, seedsize);
1462 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1467 for (j = 0; j < template[i].loops; j++) {
1468 err = crypto_rng_get_bytes(tfm, result,
1470 if (err != template[i].rlen) {
1471 printk(KERN_ERR "alg: cprng: Failed to obtain "
1472 "the correct amount of random data for "
1473 "%s (requested %d, got %d)\n", algo,
1474 template[i].rlen, err);
1479 err = memcmp(result, template[i].result,
1482 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1484 hexdump(result, template[i].rlen);
1495 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1498 struct crypto_aead *tfm;
1501 tfm = crypto_alloc_aead(driver, type, mask);
1503 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1504 "%ld\n", driver, PTR_ERR(tfm));
1505 return PTR_ERR(tfm);
1508 if (desc->suite.aead.enc.vecs) {
1509 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1510 desc->suite.aead.enc.count);
1515 if (!err && desc->suite.aead.dec.vecs)
1516 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1517 desc->suite.aead.dec.count);
1520 crypto_free_aead(tfm);
1524 static int alg_test_cipher(const struct alg_test_desc *desc,
1525 const char *driver, u32 type, u32 mask)
1527 struct crypto_cipher *tfm;
1530 tfm = crypto_alloc_cipher(driver, type, mask);
1532 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1533 "%s: %ld\n", driver, PTR_ERR(tfm));
1534 return PTR_ERR(tfm);
1537 if (desc->suite.cipher.enc.vecs) {
1538 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1539 desc->suite.cipher.enc.count);
1544 if (desc->suite.cipher.dec.vecs)
1545 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1546 desc->suite.cipher.dec.count);
1549 crypto_free_cipher(tfm);
1553 static int alg_test_skcipher(const struct alg_test_desc *desc,
1554 const char *driver, u32 type, u32 mask)
1556 struct crypto_ablkcipher *tfm;
1559 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1561 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1562 "%s: %ld\n", driver, PTR_ERR(tfm));
1563 return PTR_ERR(tfm);
1566 if (desc->suite.cipher.enc.vecs) {
1567 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1568 desc->suite.cipher.enc.count);
1573 if (desc->suite.cipher.dec.vecs)
1574 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1575 desc->suite.cipher.dec.count);
1578 crypto_free_ablkcipher(tfm);
1582 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1585 struct crypto_comp *tfm;
1588 tfm = crypto_alloc_comp(driver, type, mask);
1590 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1591 "%ld\n", driver, PTR_ERR(tfm));
1592 return PTR_ERR(tfm);
1595 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1596 desc->suite.comp.decomp.vecs,
1597 desc->suite.comp.comp.count,
1598 desc->suite.comp.decomp.count);
1600 crypto_free_comp(tfm);
1604 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1607 struct crypto_pcomp *tfm;
1610 tfm = crypto_alloc_pcomp(driver, type, mask);
1612 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1613 driver, PTR_ERR(tfm));
1614 return PTR_ERR(tfm);
1617 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1618 desc->suite.pcomp.decomp.vecs,
1619 desc->suite.pcomp.comp.count,
1620 desc->suite.pcomp.decomp.count);
1622 crypto_free_pcomp(tfm);
1626 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1629 struct crypto_ahash *tfm;
1632 tfm = crypto_alloc_ahash(driver, type, mask);
1634 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1635 "%ld\n", driver, PTR_ERR(tfm));
1636 return PTR_ERR(tfm);
1639 err = test_hash(tfm, desc->suite.hash.vecs,
1640 desc->suite.hash.count, true);
1642 err = test_hash(tfm, desc->suite.hash.vecs,
1643 desc->suite.hash.count, false);
1645 crypto_free_ahash(tfm);
1649 static int alg_test_crc32c(const struct alg_test_desc *desc,
1650 const char *driver, u32 type, u32 mask)
1652 struct crypto_shash *tfm;
1656 err = alg_test_hash(desc, driver, type, mask);
1660 tfm = crypto_alloc_shash(driver, type, mask);
1662 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1663 "%ld\n", driver, PTR_ERR(tfm));
1670 struct shash_desc shash;
1671 char ctx[crypto_shash_descsize(tfm)];
1674 sdesc.shash.tfm = tfm;
1675 sdesc.shash.flags = 0;
1677 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1678 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1680 printk(KERN_ERR "alg: crc32c: Operation failed for "
1681 "%s: %d\n", driver, err);
1685 if (val != ~420553207) {
1686 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1687 "%d\n", driver, val);
1692 crypto_free_shash(tfm);
1698 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1701 struct crypto_rng *rng;
1704 rng = crypto_alloc_rng(driver, type, mask);
1706 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1707 "%ld\n", driver, PTR_ERR(rng));
1708 return PTR_ERR(rng);
1711 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1713 crypto_free_rng(rng);
1718 static int alg_test_null(const struct alg_test_desc *desc,
1719 const char *driver, u32 type, u32 mask)
1724 /* Please keep this list sorted by algorithm name. */
1725 static const struct alg_test_desc alg_test_descs[] = {
1727 .alg = "__cbc-cast5-avx",
1728 .test = alg_test_null,
1730 .alg = "__cbc-cast6-avx",
1731 .test = alg_test_null,
1733 .alg = "__cbc-serpent-avx",
1734 .test = alg_test_null,
1736 .alg = "__cbc-serpent-avx2",
1737 .test = alg_test_null,
1739 .alg = "__cbc-serpent-sse2",
1740 .test = alg_test_null,
1742 .alg = "__cbc-twofish-avx",
1743 .test = alg_test_null,
1745 .alg = "__driver-cbc-aes-aesni",
1746 .test = alg_test_null,
1749 .alg = "__driver-cbc-camellia-aesni",
1750 .test = alg_test_null,
1752 .alg = "__driver-cbc-camellia-aesni-avx2",
1753 .test = alg_test_null,
1755 .alg = "__driver-cbc-cast5-avx",
1756 .test = alg_test_null,
1758 .alg = "__driver-cbc-cast6-avx",
1759 .test = alg_test_null,
1761 .alg = "__driver-cbc-serpent-avx",
1762 .test = alg_test_null,
1764 .alg = "__driver-cbc-serpent-avx2",
1765 .test = alg_test_null,
1767 .alg = "__driver-cbc-serpent-sse2",
1768 .test = alg_test_null,
1770 .alg = "__driver-cbc-twofish-avx",
1771 .test = alg_test_null,
1773 .alg = "__driver-ecb-aes-aesni",
1774 .test = alg_test_null,
1777 .alg = "__driver-ecb-camellia-aesni",
1778 .test = alg_test_null,
1780 .alg = "__driver-ecb-camellia-aesni-avx2",
1781 .test = alg_test_null,
1783 .alg = "__driver-ecb-cast5-avx",
1784 .test = alg_test_null,
1786 .alg = "__driver-ecb-cast6-avx",
1787 .test = alg_test_null,
1789 .alg = "__driver-ecb-serpent-avx",
1790 .test = alg_test_null,
1792 .alg = "__driver-ecb-serpent-avx2",
1793 .test = alg_test_null,
1795 .alg = "__driver-ecb-serpent-sse2",
1796 .test = alg_test_null,
1798 .alg = "__driver-ecb-twofish-avx",
1799 .test = alg_test_null,
1801 .alg = "__ghash-pclmulqdqni",
1802 .test = alg_test_null,
1805 .alg = "ansi_cprng",
1806 .test = alg_test_cprng,
1810 .vecs = ansi_cprng_aes_tv_template,
1811 .count = ANSI_CPRNG_AES_TEST_VECTORS
1815 .alg = "authenc(hmac(md5),ecb(cipher_null))",
1816 .test = alg_test_aead,
1821 .vecs = hmac_md5_ecb_cipher_null_enc_tv_template,
1822 .count = HMAC_MD5_ECB_CIPHER_NULL_ENC_TEST_VECTORS
1825 .vecs = hmac_md5_ecb_cipher_null_dec_tv_template,
1826 .count = HMAC_MD5_ECB_CIPHER_NULL_DEC_TEST_VECTORS
1831 .alg = "authenc(hmac(sha1),cbc(aes))",
1832 .test = alg_test_aead,
1838 hmac_sha1_aes_cbc_enc_tv_temp,
1840 HMAC_SHA1_AES_CBC_ENC_TEST_VEC
1845 .alg = "authenc(hmac(sha1),cbc(des))",
1846 .test = alg_test_aead,
1852 hmac_sha1_des_cbc_enc_tv_temp,
1854 HMAC_SHA1_DES_CBC_ENC_TEST_VEC
1859 .alg = "authenc(hmac(sha1),cbc(des3_ede))",
1860 .test = alg_test_aead,
1866 hmac_sha1_des3_ede_cbc_enc_tv_temp,
1868 HMAC_SHA1_DES3_EDE_CBC_ENC_TEST_VEC
1873 .alg = "authenc(hmac(sha1),ecb(cipher_null))",
1874 .test = alg_test_aead,
1880 hmac_sha1_ecb_cipher_null_enc_tv_temp,
1882 HMAC_SHA1_ECB_CIPHER_NULL_ENC_TEST_VEC
1886 hmac_sha1_ecb_cipher_null_dec_tv_temp,
1888 HMAC_SHA1_ECB_CIPHER_NULL_DEC_TEST_VEC
1893 .alg = "authenc(hmac(sha224),cbc(des))",
1894 .test = alg_test_aead,
1900 hmac_sha224_des_cbc_enc_tv_temp,
1902 HMAC_SHA224_DES_CBC_ENC_TEST_VEC
1907 .alg = "authenc(hmac(sha224),cbc(des3_ede))",
1908 .test = alg_test_aead,
1914 hmac_sha224_des3_ede_cbc_enc_tv_temp,
1916 HMAC_SHA224_DES3_EDE_CBC_ENC_TEST_VEC
1921 .alg = "authenc(hmac(sha256),cbc(aes))",
1922 .test = alg_test_aead,
1928 hmac_sha256_aes_cbc_enc_tv_temp,
1930 HMAC_SHA256_AES_CBC_ENC_TEST_VEC
1935 .alg = "authenc(hmac(sha256),cbc(des))",
1936 .test = alg_test_aead,
1942 hmac_sha256_des_cbc_enc_tv_temp,
1944 HMAC_SHA256_DES_CBC_ENC_TEST_VEC
1949 .alg = "authenc(hmac(sha256),cbc(des3_ede))",
1950 .test = alg_test_aead,
1956 hmac_sha256_des3_ede_cbc_enc_tv_temp,
1958 HMAC_SHA256_DES3_EDE_CBC_ENC_TEST_VEC
1963 .alg = "authenc(hmac(sha384),cbc(des))",
1964 .test = alg_test_aead,
1970 hmac_sha384_des_cbc_enc_tv_temp,
1972 HMAC_SHA384_DES_CBC_ENC_TEST_VEC
1977 .alg = "authenc(hmac(sha384),cbc(des3_ede))",
1978 .test = alg_test_aead,
1984 hmac_sha384_des3_ede_cbc_enc_tv_temp,
1986 HMAC_SHA384_DES3_EDE_CBC_ENC_TEST_VEC
1991 .alg = "authenc(hmac(sha512),cbc(aes))",
1992 .test = alg_test_aead,
1998 hmac_sha512_aes_cbc_enc_tv_temp,
2000 HMAC_SHA512_AES_CBC_ENC_TEST_VEC
2005 .alg = "authenc(hmac(sha512),cbc(des))",
2006 .test = alg_test_aead,
2012 hmac_sha512_des_cbc_enc_tv_temp,
2014 HMAC_SHA512_DES_CBC_ENC_TEST_VEC
2019 .alg = "authenc(hmac(sha512),cbc(des3_ede))",
2020 .test = alg_test_aead,
2026 hmac_sha512_des3_ede_cbc_enc_tv_temp,
2028 HMAC_SHA512_DES3_EDE_CBC_ENC_TEST_VEC
2034 .test = alg_test_skcipher,
2039 .vecs = aes_cbc_enc_tv_template,
2040 .count = AES_CBC_ENC_TEST_VECTORS
2043 .vecs = aes_cbc_dec_tv_template,
2044 .count = AES_CBC_DEC_TEST_VECTORS
2049 .alg = "cbc(anubis)",
2050 .test = alg_test_skcipher,
2054 .vecs = anubis_cbc_enc_tv_template,
2055 .count = ANUBIS_CBC_ENC_TEST_VECTORS
2058 .vecs = anubis_cbc_dec_tv_template,
2059 .count = ANUBIS_CBC_DEC_TEST_VECTORS
2064 .alg = "cbc(blowfish)",
2065 .test = alg_test_skcipher,
2069 .vecs = bf_cbc_enc_tv_template,
2070 .count = BF_CBC_ENC_TEST_VECTORS
2073 .vecs = bf_cbc_dec_tv_template,
2074 .count = BF_CBC_DEC_TEST_VECTORS
2079 .alg = "cbc(camellia)",
2080 .test = alg_test_skcipher,
2084 .vecs = camellia_cbc_enc_tv_template,
2085 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
2088 .vecs = camellia_cbc_dec_tv_template,
2089 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
2094 .alg = "cbc(cast5)",
2095 .test = alg_test_skcipher,
2099 .vecs = cast5_cbc_enc_tv_template,
2100 .count = CAST5_CBC_ENC_TEST_VECTORS
2103 .vecs = cast5_cbc_dec_tv_template,
2104 .count = CAST5_CBC_DEC_TEST_VECTORS
2109 .alg = "cbc(cast6)",
2110 .test = alg_test_skcipher,
2114 .vecs = cast6_cbc_enc_tv_template,
2115 .count = CAST6_CBC_ENC_TEST_VECTORS
2118 .vecs = cast6_cbc_dec_tv_template,
2119 .count = CAST6_CBC_DEC_TEST_VECTORS
2125 .test = alg_test_skcipher,
2129 .vecs = des_cbc_enc_tv_template,
2130 .count = DES_CBC_ENC_TEST_VECTORS
2133 .vecs = des_cbc_dec_tv_template,
2134 .count = DES_CBC_DEC_TEST_VECTORS
2139 .alg = "cbc(des3_ede)",
2140 .test = alg_test_skcipher,
2145 .vecs = des3_ede_cbc_enc_tv_template,
2146 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
2149 .vecs = des3_ede_cbc_dec_tv_template,
2150 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
2155 .alg = "cbc(serpent)",
2156 .test = alg_test_skcipher,
2160 .vecs = serpent_cbc_enc_tv_template,
2161 .count = SERPENT_CBC_ENC_TEST_VECTORS
2164 .vecs = serpent_cbc_dec_tv_template,
2165 .count = SERPENT_CBC_DEC_TEST_VECTORS
2170 .alg = "cbc(twofish)",
2171 .test = alg_test_skcipher,
2175 .vecs = tf_cbc_enc_tv_template,
2176 .count = TF_CBC_ENC_TEST_VECTORS
2179 .vecs = tf_cbc_dec_tv_template,
2180 .count = TF_CBC_DEC_TEST_VECTORS
2186 .test = alg_test_aead,
2191 .vecs = aes_ccm_enc_tv_template,
2192 .count = AES_CCM_ENC_TEST_VECTORS
2195 .vecs = aes_ccm_dec_tv_template,
2196 .count = AES_CCM_DEC_TEST_VECTORS
2202 .test = alg_test_hash,
2205 .vecs = aes_cmac128_tv_template,
2206 .count = CMAC_AES_TEST_VECTORS
2210 .alg = "cmac(des3_ede)",
2211 .test = alg_test_hash,
2214 .vecs = des3_ede_cmac64_tv_template,
2215 .count = CMAC_DES3_EDE_TEST_VECTORS
2219 .alg = "compress_null",
2220 .test = alg_test_null,
2223 .test = alg_test_crc32c,
2227 .vecs = crc32c_tv_template,
2228 .count = CRC32C_TEST_VECTORS
2233 .test = alg_test_hash,
2237 .vecs = crct10dif_tv_template,
2238 .count = CRCT10DIF_TEST_VECTORS
2242 .alg = "cryptd(__driver-cbc-aes-aesni)",
2243 .test = alg_test_null,
2246 .alg = "cryptd(__driver-cbc-camellia-aesni)",
2247 .test = alg_test_null,
2249 .alg = "cryptd(__driver-cbc-camellia-aesni-avx2)",
2250 .test = alg_test_null,
2252 .alg = "cryptd(__driver-cbc-serpent-avx2)",
2253 .test = alg_test_null,
2255 .alg = "cryptd(__driver-ecb-aes-aesni)",
2256 .test = alg_test_null,
2259 .alg = "cryptd(__driver-ecb-camellia-aesni)",
2260 .test = alg_test_null,
2262 .alg = "cryptd(__driver-ecb-camellia-aesni-avx2)",
2263 .test = alg_test_null,
2265 .alg = "cryptd(__driver-ecb-cast5-avx)",
2266 .test = alg_test_null,
2268 .alg = "cryptd(__driver-ecb-cast6-avx)",
2269 .test = alg_test_null,
2271 .alg = "cryptd(__driver-ecb-serpent-avx)",
2272 .test = alg_test_null,
2274 .alg = "cryptd(__driver-ecb-serpent-avx2)",
2275 .test = alg_test_null,
2277 .alg = "cryptd(__driver-ecb-serpent-sse2)",
2278 .test = alg_test_null,
2280 .alg = "cryptd(__driver-ecb-twofish-avx)",
2281 .test = alg_test_null,
2283 .alg = "cryptd(__driver-gcm-aes-aesni)",
2284 .test = alg_test_null,
2287 .alg = "cryptd(__ghash-pclmulqdqni)",
2288 .test = alg_test_null,
2292 .test = alg_test_skcipher,
2297 .vecs = aes_ctr_enc_tv_template,
2298 .count = AES_CTR_ENC_TEST_VECTORS
2301 .vecs = aes_ctr_dec_tv_template,
2302 .count = AES_CTR_DEC_TEST_VECTORS
2307 .alg = "ctr(blowfish)",
2308 .test = alg_test_skcipher,
2312 .vecs = bf_ctr_enc_tv_template,
2313 .count = BF_CTR_ENC_TEST_VECTORS
2316 .vecs = bf_ctr_dec_tv_template,
2317 .count = BF_CTR_DEC_TEST_VECTORS
2322 .alg = "ctr(camellia)",
2323 .test = alg_test_skcipher,
2327 .vecs = camellia_ctr_enc_tv_template,
2328 .count = CAMELLIA_CTR_ENC_TEST_VECTORS
2331 .vecs = camellia_ctr_dec_tv_template,
2332 .count = CAMELLIA_CTR_DEC_TEST_VECTORS
2337 .alg = "ctr(cast5)",
2338 .test = alg_test_skcipher,
2342 .vecs = cast5_ctr_enc_tv_template,
2343 .count = CAST5_CTR_ENC_TEST_VECTORS
2346 .vecs = cast5_ctr_dec_tv_template,
2347 .count = CAST5_CTR_DEC_TEST_VECTORS
2352 .alg = "ctr(cast6)",
2353 .test = alg_test_skcipher,
2357 .vecs = cast6_ctr_enc_tv_template,
2358 .count = CAST6_CTR_ENC_TEST_VECTORS
2361 .vecs = cast6_ctr_dec_tv_template,
2362 .count = CAST6_CTR_DEC_TEST_VECTORS
2368 .test = alg_test_skcipher,
2372 .vecs = des_ctr_enc_tv_template,
2373 .count = DES_CTR_ENC_TEST_VECTORS
2376 .vecs = des_ctr_dec_tv_template,
2377 .count = DES_CTR_DEC_TEST_VECTORS
2382 .alg = "ctr(des3_ede)",
2383 .test = alg_test_skcipher,
2387 .vecs = des3_ede_ctr_enc_tv_template,
2388 .count = DES3_EDE_CTR_ENC_TEST_VECTORS
2391 .vecs = des3_ede_ctr_dec_tv_template,
2392 .count = DES3_EDE_CTR_DEC_TEST_VECTORS
2397 .alg = "ctr(serpent)",
2398 .test = alg_test_skcipher,
2402 .vecs = serpent_ctr_enc_tv_template,
2403 .count = SERPENT_CTR_ENC_TEST_VECTORS
2406 .vecs = serpent_ctr_dec_tv_template,
2407 .count = SERPENT_CTR_DEC_TEST_VECTORS
2412 .alg = "ctr(twofish)",
2413 .test = alg_test_skcipher,
2417 .vecs = tf_ctr_enc_tv_template,
2418 .count = TF_CTR_ENC_TEST_VECTORS
2421 .vecs = tf_ctr_dec_tv_template,
2422 .count = TF_CTR_DEC_TEST_VECTORS
2427 .alg = "cts(cbc(aes))",
2428 .test = alg_test_skcipher,
2432 .vecs = cts_mode_enc_tv_template,
2433 .count = CTS_MODE_ENC_TEST_VECTORS
2436 .vecs = cts_mode_dec_tv_template,
2437 .count = CTS_MODE_DEC_TEST_VECTORS
2443 .test = alg_test_comp,
2448 .vecs = deflate_comp_tv_template,
2449 .count = DEFLATE_COMP_TEST_VECTORS
2452 .vecs = deflate_decomp_tv_template,
2453 .count = DEFLATE_DECOMP_TEST_VECTORS
2458 .alg = "digest_null",
2459 .test = alg_test_null,
2461 .alg = "ecb(__aes-aesni)",
2462 .test = alg_test_null,
2466 .test = alg_test_skcipher,
2471 .vecs = aes_enc_tv_template,
2472 .count = AES_ENC_TEST_VECTORS
2475 .vecs = aes_dec_tv_template,
2476 .count = AES_DEC_TEST_VECTORS
2481 .alg = "ecb(anubis)",
2482 .test = alg_test_skcipher,
2486 .vecs = anubis_enc_tv_template,
2487 .count = ANUBIS_ENC_TEST_VECTORS
2490 .vecs = anubis_dec_tv_template,
2491 .count = ANUBIS_DEC_TEST_VECTORS
2497 .test = alg_test_skcipher,
2501 .vecs = arc4_enc_tv_template,
2502 .count = ARC4_ENC_TEST_VECTORS
2505 .vecs = arc4_dec_tv_template,
2506 .count = ARC4_DEC_TEST_VECTORS
2511 .alg = "ecb(blowfish)",
2512 .test = alg_test_skcipher,
2516 .vecs = bf_enc_tv_template,
2517 .count = BF_ENC_TEST_VECTORS
2520 .vecs = bf_dec_tv_template,
2521 .count = BF_DEC_TEST_VECTORS
2526 .alg = "ecb(camellia)",
2527 .test = alg_test_skcipher,
2531 .vecs = camellia_enc_tv_template,
2532 .count = CAMELLIA_ENC_TEST_VECTORS
2535 .vecs = camellia_dec_tv_template,
2536 .count = CAMELLIA_DEC_TEST_VECTORS
2541 .alg = "ecb(cast5)",
2542 .test = alg_test_skcipher,
2546 .vecs = cast5_enc_tv_template,
2547 .count = CAST5_ENC_TEST_VECTORS
2550 .vecs = cast5_dec_tv_template,
2551 .count = CAST5_DEC_TEST_VECTORS
2556 .alg = "ecb(cast6)",
2557 .test = alg_test_skcipher,
2561 .vecs = cast6_enc_tv_template,
2562 .count = CAST6_ENC_TEST_VECTORS
2565 .vecs = cast6_dec_tv_template,
2566 .count = CAST6_DEC_TEST_VECTORS
2571 .alg = "ecb(cipher_null)",
2572 .test = alg_test_null,
2575 .test = alg_test_skcipher,
2580 .vecs = des_enc_tv_template,
2581 .count = DES_ENC_TEST_VECTORS
2584 .vecs = des_dec_tv_template,
2585 .count = DES_DEC_TEST_VECTORS
2590 .alg = "ecb(des3_ede)",
2591 .test = alg_test_skcipher,
2596 .vecs = des3_ede_enc_tv_template,
2597 .count = DES3_EDE_ENC_TEST_VECTORS
2600 .vecs = des3_ede_dec_tv_template,
2601 .count = DES3_EDE_DEC_TEST_VECTORS
2606 .alg = "ecb(fcrypt)",
2607 .test = alg_test_skcipher,
2611 .vecs = fcrypt_pcbc_enc_tv_template,
2615 .vecs = fcrypt_pcbc_dec_tv_template,
2621 .alg = "ecb(khazad)",
2622 .test = alg_test_skcipher,
2626 .vecs = khazad_enc_tv_template,
2627 .count = KHAZAD_ENC_TEST_VECTORS
2630 .vecs = khazad_dec_tv_template,
2631 .count = KHAZAD_DEC_TEST_VECTORS
2637 .test = alg_test_skcipher,
2641 .vecs = seed_enc_tv_template,
2642 .count = SEED_ENC_TEST_VECTORS
2645 .vecs = seed_dec_tv_template,
2646 .count = SEED_DEC_TEST_VECTORS
2651 .alg = "ecb(serpent)",
2652 .test = alg_test_skcipher,
2656 .vecs = serpent_enc_tv_template,
2657 .count = SERPENT_ENC_TEST_VECTORS
2660 .vecs = serpent_dec_tv_template,
2661 .count = SERPENT_DEC_TEST_VECTORS
2667 .test = alg_test_skcipher,
2671 .vecs = tea_enc_tv_template,
2672 .count = TEA_ENC_TEST_VECTORS
2675 .vecs = tea_dec_tv_template,
2676 .count = TEA_DEC_TEST_VECTORS
2681 .alg = "ecb(tnepres)",
2682 .test = alg_test_skcipher,
2686 .vecs = tnepres_enc_tv_template,
2687 .count = TNEPRES_ENC_TEST_VECTORS
2690 .vecs = tnepres_dec_tv_template,
2691 .count = TNEPRES_DEC_TEST_VECTORS
2696 .alg = "ecb(twofish)",
2697 .test = alg_test_skcipher,
2701 .vecs = tf_enc_tv_template,
2702 .count = TF_ENC_TEST_VECTORS
2705 .vecs = tf_dec_tv_template,
2706 .count = TF_DEC_TEST_VECTORS
2712 .test = alg_test_skcipher,
2716 .vecs = xeta_enc_tv_template,
2717 .count = XETA_ENC_TEST_VECTORS
2720 .vecs = xeta_dec_tv_template,
2721 .count = XETA_DEC_TEST_VECTORS
2727 .test = alg_test_skcipher,
2731 .vecs = xtea_enc_tv_template,
2732 .count = XTEA_ENC_TEST_VECTORS
2735 .vecs = xtea_dec_tv_template,
2736 .count = XTEA_DEC_TEST_VECTORS
2742 .test = alg_test_aead,
2747 .vecs = aes_gcm_enc_tv_template,
2748 .count = AES_GCM_ENC_TEST_VECTORS
2751 .vecs = aes_gcm_dec_tv_template,
2752 .count = AES_GCM_DEC_TEST_VECTORS
2758 .test = alg_test_hash,
2762 .vecs = ghash_tv_template,
2763 .count = GHASH_TEST_VECTORS
2767 .alg = "hmac(crc32)",
2768 .test = alg_test_hash,
2771 .vecs = bfin_crc_tv_template,
2772 .count = BFIN_CRC_TEST_VECTORS
2777 .test = alg_test_hash,
2780 .vecs = hmac_md5_tv_template,
2781 .count = HMAC_MD5_TEST_VECTORS
2785 .alg = "hmac(rmd128)",
2786 .test = alg_test_hash,
2789 .vecs = hmac_rmd128_tv_template,
2790 .count = HMAC_RMD128_TEST_VECTORS
2794 .alg = "hmac(rmd160)",
2795 .test = alg_test_hash,
2798 .vecs = hmac_rmd160_tv_template,
2799 .count = HMAC_RMD160_TEST_VECTORS
2803 .alg = "hmac(sha1)",
2804 .test = alg_test_hash,
2808 .vecs = hmac_sha1_tv_template,
2809 .count = HMAC_SHA1_TEST_VECTORS
2813 .alg = "hmac(sha224)",
2814 .test = alg_test_hash,
2818 .vecs = hmac_sha224_tv_template,
2819 .count = HMAC_SHA224_TEST_VECTORS
2823 .alg = "hmac(sha256)",
2824 .test = alg_test_hash,
2828 .vecs = hmac_sha256_tv_template,
2829 .count = HMAC_SHA256_TEST_VECTORS
2833 .alg = "hmac(sha384)",
2834 .test = alg_test_hash,
2838 .vecs = hmac_sha384_tv_template,
2839 .count = HMAC_SHA384_TEST_VECTORS
2843 .alg = "hmac(sha512)",
2844 .test = alg_test_hash,
2848 .vecs = hmac_sha512_tv_template,
2849 .count = HMAC_SHA512_TEST_VECTORS
2854 .test = alg_test_skcipher,
2858 .vecs = aes_lrw_enc_tv_template,
2859 .count = AES_LRW_ENC_TEST_VECTORS
2862 .vecs = aes_lrw_dec_tv_template,
2863 .count = AES_LRW_DEC_TEST_VECTORS
2868 .alg = "lrw(camellia)",
2869 .test = alg_test_skcipher,
2873 .vecs = camellia_lrw_enc_tv_template,
2874 .count = CAMELLIA_LRW_ENC_TEST_VECTORS
2877 .vecs = camellia_lrw_dec_tv_template,
2878 .count = CAMELLIA_LRW_DEC_TEST_VECTORS
2883 .alg = "lrw(cast6)",
2884 .test = alg_test_skcipher,
2888 .vecs = cast6_lrw_enc_tv_template,
2889 .count = CAST6_LRW_ENC_TEST_VECTORS
2892 .vecs = cast6_lrw_dec_tv_template,
2893 .count = CAST6_LRW_DEC_TEST_VECTORS
2898 .alg = "lrw(serpent)",
2899 .test = alg_test_skcipher,
2903 .vecs = serpent_lrw_enc_tv_template,
2904 .count = SERPENT_LRW_ENC_TEST_VECTORS
2907 .vecs = serpent_lrw_dec_tv_template,
2908 .count = SERPENT_LRW_DEC_TEST_VECTORS
2913 .alg = "lrw(twofish)",
2914 .test = alg_test_skcipher,
2918 .vecs = tf_lrw_enc_tv_template,
2919 .count = TF_LRW_ENC_TEST_VECTORS
2922 .vecs = tf_lrw_dec_tv_template,
2923 .count = TF_LRW_DEC_TEST_VECTORS
2929 .test = alg_test_comp,
2934 .vecs = lzo_comp_tv_template,
2935 .count = LZO_COMP_TEST_VECTORS
2938 .vecs = lzo_decomp_tv_template,
2939 .count = LZO_DECOMP_TEST_VECTORS
2945 .test = alg_test_hash,
2948 .vecs = md4_tv_template,
2949 .count = MD4_TEST_VECTORS
2954 .test = alg_test_hash,
2957 .vecs = md5_tv_template,
2958 .count = MD5_TEST_VECTORS
2962 .alg = "michael_mic",
2963 .test = alg_test_hash,
2966 .vecs = michael_mic_tv_template,
2967 .count = MICHAEL_MIC_TEST_VECTORS
2972 .test = alg_test_skcipher,
2977 .vecs = aes_ofb_enc_tv_template,
2978 .count = AES_OFB_ENC_TEST_VECTORS
2981 .vecs = aes_ofb_dec_tv_template,
2982 .count = AES_OFB_DEC_TEST_VECTORS
2987 .alg = "pcbc(fcrypt)",
2988 .test = alg_test_skcipher,
2992 .vecs = fcrypt_pcbc_enc_tv_template,
2993 .count = FCRYPT_ENC_TEST_VECTORS
2996 .vecs = fcrypt_pcbc_dec_tv_template,
2997 .count = FCRYPT_DEC_TEST_VECTORS
3002 .alg = "rfc3686(ctr(aes))",
3003 .test = alg_test_skcipher,
3008 .vecs = aes_ctr_rfc3686_enc_tv_template,
3009 .count = AES_CTR_3686_ENC_TEST_VECTORS
3012 .vecs = aes_ctr_rfc3686_dec_tv_template,
3013 .count = AES_CTR_3686_DEC_TEST_VECTORS
3018 .alg = "rfc4106(gcm(aes))",
3019 .test = alg_test_aead,
3023 .vecs = aes_gcm_rfc4106_enc_tv_template,
3024 .count = AES_GCM_4106_ENC_TEST_VECTORS
3027 .vecs = aes_gcm_rfc4106_dec_tv_template,
3028 .count = AES_GCM_4106_DEC_TEST_VECTORS
3033 .alg = "rfc4309(ccm(aes))",
3034 .test = alg_test_aead,
3039 .vecs = aes_ccm_rfc4309_enc_tv_template,
3040 .count = AES_CCM_4309_ENC_TEST_VECTORS
3043 .vecs = aes_ccm_rfc4309_dec_tv_template,
3044 .count = AES_CCM_4309_DEC_TEST_VECTORS
3049 .alg = "rfc4543(gcm(aes))",
3050 .test = alg_test_aead,
3054 .vecs = aes_gcm_rfc4543_enc_tv_template,
3055 .count = AES_GCM_4543_ENC_TEST_VECTORS
3058 .vecs = aes_gcm_rfc4543_dec_tv_template,
3059 .count = AES_GCM_4543_DEC_TEST_VECTORS
3065 .test = alg_test_hash,
3068 .vecs = rmd128_tv_template,
3069 .count = RMD128_TEST_VECTORS
3074 .test = alg_test_hash,
3077 .vecs = rmd160_tv_template,
3078 .count = RMD160_TEST_VECTORS
3083 .test = alg_test_hash,
3086 .vecs = rmd256_tv_template,
3087 .count = RMD256_TEST_VECTORS
3092 .test = alg_test_hash,
3095 .vecs = rmd320_tv_template,
3096 .count = RMD320_TEST_VECTORS
3101 .test = alg_test_skcipher,
3105 .vecs = salsa20_stream_enc_tv_template,
3106 .count = SALSA20_STREAM_ENC_TEST_VECTORS
3112 .test = alg_test_hash,
3116 .vecs = sha1_tv_template,
3117 .count = SHA1_TEST_VECTORS
3122 .test = alg_test_hash,
3126 .vecs = sha224_tv_template,
3127 .count = SHA224_TEST_VECTORS
3132 .test = alg_test_hash,
3136 .vecs = sha256_tv_template,
3137 .count = SHA256_TEST_VECTORS
3142 .test = alg_test_hash,
3146 .vecs = sha384_tv_template,
3147 .count = SHA384_TEST_VECTORS
3152 .test = alg_test_hash,
3156 .vecs = sha512_tv_template,
3157 .count = SHA512_TEST_VECTORS
3162 .test = alg_test_hash,
3165 .vecs = tgr128_tv_template,
3166 .count = TGR128_TEST_VECTORS
3171 .test = alg_test_hash,
3174 .vecs = tgr160_tv_template,
3175 .count = TGR160_TEST_VECTORS
3180 .test = alg_test_hash,
3183 .vecs = tgr192_tv_template,
3184 .count = TGR192_TEST_VECTORS
3189 .test = alg_test_hash,
3192 .vecs = aes_vmac128_tv_template,
3193 .count = VMAC_AES_TEST_VECTORS
3198 .test = alg_test_hash,
3201 .vecs = wp256_tv_template,
3202 .count = WP256_TEST_VECTORS
3207 .test = alg_test_hash,
3210 .vecs = wp384_tv_template,
3211 .count = WP384_TEST_VECTORS
3216 .test = alg_test_hash,
3219 .vecs = wp512_tv_template,
3220 .count = WP512_TEST_VECTORS
3225 .test = alg_test_hash,
3228 .vecs = aes_xcbc128_tv_template,
3229 .count = XCBC_AES_TEST_VECTORS
3234 .test = alg_test_skcipher,
3239 .vecs = aes_xts_enc_tv_template,
3240 .count = AES_XTS_ENC_TEST_VECTORS
3243 .vecs = aes_xts_dec_tv_template,
3244 .count = AES_XTS_DEC_TEST_VECTORS
3249 .alg = "xts(camellia)",
3250 .test = alg_test_skcipher,
3254 .vecs = camellia_xts_enc_tv_template,
3255 .count = CAMELLIA_XTS_ENC_TEST_VECTORS
3258 .vecs = camellia_xts_dec_tv_template,
3259 .count = CAMELLIA_XTS_DEC_TEST_VECTORS
3264 .alg = "xts(cast6)",
3265 .test = alg_test_skcipher,
3269 .vecs = cast6_xts_enc_tv_template,
3270 .count = CAST6_XTS_ENC_TEST_VECTORS
3273 .vecs = cast6_xts_dec_tv_template,
3274 .count = CAST6_XTS_DEC_TEST_VECTORS
3279 .alg = "xts(serpent)",
3280 .test = alg_test_skcipher,
3284 .vecs = serpent_xts_enc_tv_template,
3285 .count = SERPENT_XTS_ENC_TEST_VECTORS
3288 .vecs = serpent_xts_dec_tv_template,
3289 .count = SERPENT_XTS_DEC_TEST_VECTORS
3294 .alg = "xts(twofish)",
3295 .test = alg_test_skcipher,
3299 .vecs = tf_xts_enc_tv_template,
3300 .count = TF_XTS_ENC_TEST_VECTORS
3303 .vecs = tf_xts_dec_tv_template,
3304 .count = TF_XTS_DEC_TEST_VECTORS
3310 .test = alg_test_pcomp,
3315 .vecs = zlib_comp_tv_template,
3316 .count = ZLIB_COMP_TEST_VECTORS
3319 .vecs = zlib_decomp_tv_template,
3320 .count = ZLIB_DECOMP_TEST_VECTORS
3327 static bool alg_test_descs_checked;
3329 static void alg_test_descs_check_order(void)
3333 /* only check once */
3334 if (alg_test_descs_checked)
3337 alg_test_descs_checked = true;
3339 for (i = 1; i < ARRAY_SIZE(alg_test_descs); i++) {
3340 int diff = strcmp(alg_test_descs[i - 1].alg,
3341 alg_test_descs[i].alg);
3343 if (WARN_ON(diff > 0)) {
3344 pr_warn("testmgr: alg_test_descs entries in wrong order: '%s' before '%s'\n",
3345 alg_test_descs[i - 1].alg,
3346 alg_test_descs[i].alg);
3349 if (WARN_ON(diff == 0)) {
3350 pr_warn("testmgr: duplicate alg_test_descs entry: '%s'\n",
3351 alg_test_descs[i].alg);
3356 static int alg_find_test(const char *alg)
3359 int end = ARRAY_SIZE(alg_test_descs);
3361 while (start < end) {
3362 int i = (start + end) / 2;
3363 int diff = strcmp(alg_test_descs[i].alg, alg);
3381 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
3387 alg_test_descs_check_order();
3389 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
3390 char nalg[CRYPTO_MAX_ALG_NAME];
3392 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
3394 return -ENAMETOOLONG;
3396 i = alg_find_test(nalg);
3400 if (fips_enabled && !alg_test_descs[i].fips_allowed)
3403 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
3407 i = alg_find_test(alg);
3408 j = alg_find_test(driver);
3412 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
3413 (j >= 0 && !alg_test_descs[j].fips_allowed)))
3418 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
3420 if (j >= 0 && j != i)
3421 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
3425 if (fips_enabled && rc)
3426 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
3428 if (fips_enabled && !rc)
3429 pr_info(KERN_INFO "alg: self-tests for %s (%s) passed\n",
3435 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
3441 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
3443 EXPORT_SYMBOL_GPL(alg_test);