crypto: testmgr - Fix test disabling option
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / crypto / testmgr.c
blobfa8c8f78c8d4c1838d121e6131b05162858b2802
1 /*
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 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
16 #include <crypto/hash.h>
17 #include <linux/err.h>
18 #include <linux/module.h>
19 #include <linux/scatterlist.h>
20 #include <linux/slab.h>
21 #include <linux/string.h>
22 #include <crypto/rng.h>
24 #include "internal.h"
26 #ifdef CONFIG_CRYPTO_MANAGER_DISABLE_TESTS
28 /* a perfect nop */
29 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
31 return 0;
34 #else
36 #include "testmgr.h"
39 * Need slab memory for testing (size in number of pages).
41 #define XBUFSIZE 8
44 * Indexes into the xbuf to simulate cross-page access.
46 #define IDX1 32
47 #define IDX2 32400
48 #define IDX3 1
49 #define IDX4 8193
50 #define IDX5 22222
51 #define IDX6 17101
52 #define IDX7 27333
53 #define IDX8 3000
56 * Used by test_cipher()
58 #define ENCRYPT 1
59 #define DECRYPT 0
61 struct tcrypt_result {
62 struct completion completion;
63 int err;
66 struct aead_test_suite {
67 struct {
68 struct aead_testvec *vecs;
69 unsigned int count;
70 } enc, dec;
73 struct cipher_test_suite {
74 struct {
75 struct cipher_testvec *vecs;
76 unsigned int count;
77 } enc, dec;
80 struct comp_test_suite {
81 struct {
82 struct comp_testvec *vecs;
83 unsigned int count;
84 } comp, decomp;
87 struct pcomp_test_suite {
88 struct {
89 struct pcomp_testvec *vecs;
90 unsigned int count;
91 } comp, decomp;
94 struct hash_test_suite {
95 struct hash_testvec *vecs;
96 unsigned int count;
99 struct cprng_test_suite {
100 struct cprng_testvec *vecs;
101 unsigned int count;
104 struct alg_test_desc {
105 const char *alg;
106 int (*test)(const struct alg_test_desc *desc, const char *driver,
107 u32 type, u32 mask);
108 int fips_allowed; /* set if alg is allowed in fips mode */
110 union {
111 struct aead_test_suite aead;
112 struct cipher_test_suite cipher;
113 struct comp_test_suite comp;
114 struct pcomp_test_suite pcomp;
115 struct hash_test_suite hash;
116 struct cprng_test_suite cprng;
117 } suite;
120 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
122 static void hexdump(unsigned char *buf, unsigned int len)
124 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
125 16, 1,
126 buf, len, false);
129 static void tcrypt_complete(struct crypto_async_request *req, int err)
131 struct tcrypt_result *res = req->data;
133 if (err == -EINPROGRESS)
134 return;
136 res->err = err;
137 complete(&res->completion);
140 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
142 int i;
144 for (i = 0; i < XBUFSIZE; i++) {
145 buf[i] = (void *)__get_free_page(GFP_KERNEL);
146 if (!buf[i])
147 goto err_free_buf;
150 return 0;
152 err_free_buf:
153 while (i-- > 0)
154 free_page((unsigned long)buf[i]);
156 return -ENOMEM;
159 static void testmgr_free_buf(char *buf[XBUFSIZE])
161 int i;
163 for (i = 0; i < XBUFSIZE; i++)
164 free_page((unsigned long)buf[i]);
167 static int do_one_async_hash_op(struct ahash_request *req,
168 struct tcrypt_result *tr,
169 int ret)
171 if (ret == -EINPROGRESS || ret == -EBUSY) {
172 ret = wait_for_completion_interruptible(&tr->completion);
173 if (!ret)
174 ret = tr->err;
175 INIT_COMPLETION(tr->completion);
177 return ret;
180 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
181 unsigned int tcount, bool use_digest)
183 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
184 unsigned int i, j, k, temp;
185 struct scatterlist sg[8];
186 char result[64];
187 struct ahash_request *req;
188 struct tcrypt_result tresult;
189 void *hash_buff;
190 char *xbuf[XBUFSIZE];
191 int ret = -ENOMEM;
193 if (testmgr_alloc_buf(xbuf))
194 goto out_nobuf;
196 init_completion(&tresult.completion);
198 req = ahash_request_alloc(tfm, GFP_KERNEL);
199 if (!req) {
200 printk(KERN_ERR "alg: hash: Failed to allocate request for "
201 "%s\n", algo);
202 goto out_noreq;
204 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
205 tcrypt_complete, &tresult);
207 j = 0;
208 for (i = 0; i < tcount; i++) {
209 if (template[i].np)
210 continue;
212 j++;
213 memset(result, 0, 64);
215 hash_buff = xbuf[0];
217 memcpy(hash_buff, template[i].plaintext, template[i].psize);
218 sg_init_one(&sg[0], hash_buff, template[i].psize);
220 if (template[i].ksize) {
221 crypto_ahash_clear_flags(tfm, ~0);
222 ret = crypto_ahash_setkey(tfm, template[i].key,
223 template[i].ksize);
224 if (ret) {
225 printk(KERN_ERR "alg: hash: setkey failed on "
226 "test %d for %s: ret=%d\n", j, algo,
227 -ret);
228 goto out;
232 ahash_request_set_crypt(req, sg, result, template[i].psize);
233 if (use_digest) {
234 ret = do_one_async_hash_op(req, &tresult,
235 crypto_ahash_digest(req));
236 if (ret) {
237 pr_err("alg: hash: digest failed on test %d "
238 "for %s: ret=%d\n", j, algo, -ret);
239 goto out;
241 } else {
242 ret = do_one_async_hash_op(req, &tresult,
243 crypto_ahash_init(req));
244 if (ret) {
245 pr_err("alt: hash: init failed on test %d "
246 "for %s: ret=%d\n", j, algo, -ret);
247 goto out;
249 ret = do_one_async_hash_op(req, &tresult,
250 crypto_ahash_update(req));
251 if (ret) {
252 pr_err("alt: hash: update failed on test %d "
253 "for %s: ret=%d\n", j, algo, -ret);
254 goto out;
256 ret = do_one_async_hash_op(req, &tresult,
257 crypto_ahash_final(req));
258 if (ret) {
259 pr_err("alt: hash: final failed on test %d "
260 "for %s: ret=%d\n", j, algo, -ret);
261 goto out;
265 if (memcmp(result, template[i].digest,
266 crypto_ahash_digestsize(tfm))) {
267 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
268 j, algo);
269 hexdump(result, crypto_ahash_digestsize(tfm));
270 ret = -EINVAL;
271 goto out;
275 j = 0;
276 for (i = 0; i < tcount; i++) {
277 if (template[i].np) {
278 j++;
279 memset(result, 0, 64);
281 temp = 0;
282 sg_init_table(sg, template[i].np);
283 ret = -EINVAL;
284 for (k = 0; k < template[i].np; k++) {
285 if (WARN_ON(offset_in_page(IDX[k]) +
286 template[i].tap[k] > PAGE_SIZE))
287 goto out;
288 sg_set_buf(&sg[k],
289 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
290 offset_in_page(IDX[k]),
291 template[i].plaintext + temp,
292 template[i].tap[k]),
293 template[i].tap[k]);
294 temp += template[i].tap[k];
297 if (template[i].ksize) {
298 crypto_ahash_clear_flags(tfm, ~0);
299 ret = crypto_ahash_setkey(tfm, template[i].key,
300 template[i].ksize);
302 if (ret) {
303 printk(KERN_ERR "alg: hash: setkey "
304 "failed on chunking test %d "
305 "for %s: ret=%d\n", j, algo,
306 -ret);
307 goto out;
311 ahash_request_set_crypt(req, sg, result,
312 template[i].psize);
313 ret = crypto_ahash_digest(req);
314 switch (ret) {
315 case 0:
316 break;
317 case -EINPROGRESS:
318 case -EBUSY:
319 ret = wait_for_completion_interruptible(
320 &tresult.completion);
321 if (!ret && !(ret = tresult.err)) {
322 INIT_COMPLETION(tresult.completion);
323 break;
325 /* fall through */
326 default:
327 printk(KERN_ERR "alg: hash: digest failed "
328 "on chunking test %d for %s: "
329 "ret=%d\n", j, algo, -ret);
330 goto out;
333 if (memcmp(result, template[i].digest,
334 crypto_ahash_digestsize(tfm))) {
335 printk(KERN_ERR "alg: hash: Chunking test %d "
336 "failed for %s\n", j, algo);
337 hexdump(result, crypto_ahash_digestsize(tfm));
338 ret = -EINVAL;
339 goto out;
344 ret = 0;
346 out:
347 ahash_request_free(req);
348 out_noreq:
349 testmgr_free_buf(xbuf);
350 out_nobuf:
351 return ret;
354 static int test_aead(struct crypto_aead *tfm, int enc,
355 struct aead_testvec *template, unsigned int tcount)
357 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
358 unsigned int i, j, k, n, temp;
359 int ret = -ENOMEM;
360 char *q;
361 char *key;
362 struct aead_request *req;
363 struct scatterlist sg[8];
364 struct scatterlist asg[8];
365 const char *e;
366 struct tcrypt_result result;
367 unsigned int authsize;
368 void *input;
369 void *assoc;
370 char iv[MAX_IVLEN];
371 char *xbuf[XBUFSIZE];
372 char *axbuf[XBUFSIZE];
374 if (testmgr_alloc_buf(xbuf))
375 goto out_noxbuf;
376 if (testmgr_alloc_buf(axbuf))
377 goto out_noaxbuf;
379 if (enc == ENCRYPT)
380 e = "encryption";
381 else
382 e = "decryption";
384 init_completion(&result.completion);
386 req = aead_request_alloc(tfm, GFP_KERNEL);
387 if (!req) {
388 printk(KERN_ERR "alg: aead: Failed to allocate request for "
389 "%s\n", algo);
390 goto out;
393 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
394 tcrypt_complete, &result);
396 for (i = 0, j = 0; i < tcount; i++) {
397 if (!template[i].np) {
398 j++;
400 /* some tepmplates have no input data but they will
401 * touch input
403 input = xbuf[0];
404 assoc = axbuf[0];
406 ret = -EINVAL;
407 if (WARN_ON(template[i].ilen > PAGE_SIZE ||
408 template[i].alen > PAGE_SIZE))
409 goto out;
411 memcpy(input, template[i].input, template[i].ilen);
412 memcpy(assoc, template[i].assoc, template[i].alen);
413 if (template[i].iv)
414 memcpy(iv, template[i].iv, MAX_IVLEN);
415 else
416 memset(iv, 0, MAX_IVLEN);
418 crypto_aead_clear_flags(tfm, ~0);
419 if (template[i].wk)
420 crypto_aead_set_flags(
421 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
423 key = template[i].key;
425 ret = crypto_aead_setkey(tfm, key,
426 template[i].klen);
427 if (!ret == template[i].fail) {
428 printk(KERN_ERR "alg: aead: setkey failed on "
429 "test %d for %s: flags=%x\n", j, algo,
430 crypto_aead_get_flags(tfm));
431 goto out;
432 } else if (ret)
433 continue;
435 authsize = abs(template[i].rlen - template[i].ilen);
436 ret = crypto_aead_setauthsize(tfm, authsize);
437 if (ret) {
438 printk(KERN_ERR "alg: aead: Failed to set "
439 "authsize to %u on test %d for %s\n",
440 authsize, j, algo);
441 goto out;
444 sg_init_one(&sg[0], input,
445 template[i].ilen + (enc ? authsize : 0));
447 sg_init_one(&asg[0], assoc, template[i].alen);
449 aead_request_set_crypt(req, sg, sg,
450 template[i].ilen, iv);
452 aead_request_set_assoc(req, asg, template[i].alen);
454 ret = enc ?
455 crypto_aead_encrypt(req) :
456 crypto_aead_decrypt(req);
458 switch (ret) {
459 case 0:
460 if (template[i].novrfy) {
461 /* verification was supposed to fail */
462 printk(KERN_ERR "alg: aead: %s failed "
463 "on test %d for %s: ret was 0, "
464 "expected -EBADMSG\n",
465 e, j, algo);
466 /* so really, we got a bad message */
467 ret = -EBADMSG;
468 goto out;
470 break;
471 case -EINPROGRESS:
472 case -EBUSY:
473 ret = wait_for_completion_interruptible(
474 &result.completion);
475 if (!ret && !(ret = result.err)) {
476 INIT_COMPLETION(result.completion);
477 break;
479 case -EBADMSG:
480 if (template[i].novrfy)
481 /* verification failure was expected */
482 continue;
483 /* fall through */
484 default:
485 printk(KERN_ERR "alg: aead: %s failed on test "
486 "%d for %s: ret=%d\n", e, j, algo, -ret);
487 goto out;
490 q = input;
491 if (memcmp(q, template[i].result, template[i].rlen)) {
492 printk(KERN_ERR "alg: aead: Test %d failed on "
493 "%s for %s\n", j, e, algo);
494 hexdump(q, template[i].rlen);
495 ret = -EINVAL;
496 goto out;
501 for (i = 0, j = 0; i < tcount; i++) {
502 if (template[i].np) {
503 j++;
505 if (template[i].iv)
506 memcpy(iv, template[i].iv, MAX_IVLEN);
507 else
508 memset(iv, 0, MAX_IVLEN);
510 crypto_aead_clear_flags(tfm, ~0);
511 if (template[i].wk)
512 crypto_aead_set_flags(
513 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
514 key = template[i].key;
516 ret = crypto_aead_setkey(tfm, key, template[i].klen);
517 if (!ret == template[i].fail) {
518 printk(KERN_ERR "alg: aead: setkey failed on "
519 "chunk test %d for %s: flags=%x\n", j,
520 algo, crypto_aead_get_flags(tfm));
521 goto out;
522 } else if (ret)
523 continue;
525 authsize = abs(template[i].rlen - template[i].ilen);
527 ret = -EINVAL;
528 sg_init_table(sg, template[i].np);
529 for (k = 0, temp = 0; k < template[i].np; k++) {
530 if (WARN_ON(offset_in_page(IDX[k]) +
531 template[i].tap[k] > PAGE_SIZE))
532 goto out;
534 q = xbuf[IDX[k] >> PAGE_SHIFT] +
535 offset_in_page(IDX[k]);
537 memcpy(q, template[i].input + temp,
538 template[i].tap[k]);
540 n = template[i].tap[k];
541 if (k == template[i].np - 1 && enc)
542 n += authsize;
543 if (offset_in_page(q) + n < PAGE_SIZE)
544 q[n] = 0;
546 sg_set_buf(&sg[k], q, template[i].tap[k]);
547 temp += template[i].tap[k];
550 ret = crypto_aead_setauthsize(tfm, authsize);
551 if (ret) {
552 printk(KERN_ERR "alg: aead: Failed to set "
553 "authsize to %u on chunk test %d for "
554 "%s\n", authsize, j, algo);
555 goto out;
558 if (enc) {
559 if (WARN_ON(sg[k - 1].offset +
560 sg[k - 1].length + authsize >
561 PAGE_SIZE)) {
562 ret = -EINVAL;
563 goto out;
566 sg[k - 1].length += authsize;
569 sg_init_table(asg, template[i].anp);
570 ret = -EINVAL;
571 for (k = 0, temp = 0; k < template[i].anp; k++) {
572 if (WARN_ON(offset_in_page(IDX[k]) +
573 template[i].atap[k] > PAGE_SIZE))
574 goto out;
575 sg_set_buf(&asg[k],
576 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
577 offset_in_page(IDX[k]),
578 template[i].assoc + temp,
579 template[i].atap[k]),
580 template[i].atap[k]);
581 temp += template[i].atap[k];
584 aead_request_set_crypt(req, sg, sg,
585 template[i].ilen,
586 iv);
588 aead_request_set_assoc(req, asg, template[i].alen);
590 ret = enc ?
591 crypto_aead_encrypt(req) :
592 crypto_aead_decrypt(req);
594 switch (ret) {
595 case 0:
596 if (template[i].novrfy) {
597 /* verification was supposed to fail */
598 printk(KERN_ERR "alg: aead: %s failed "
599 "on chunk test %d for %s: ret "
600 "was 0, expected -EBADMSG\n",
601 e, j, algo);
602 /* so really, we got a bad message */
603 ret = -EBADMSG;
604 goto out;
606 break;
607 case -EINPROGRESS:
608 case -EBUSY:
609 ret = wait_for_completion_interruptible(
610 &result.completion);
611 if (!ret && !(ret = result.err)) {
612 INIT_COMPLETION(result.completion);
613 break;
615 case -EBADMSG:
616 if (template[i].novrfy)
617 /* verification failure was expected */
618 continue;
619 /* fall through */
620 default:
621 printk(KERN_ERR "alg: aead: %s failed on "
622 "chunk test %d for %s: ret=%d\n", e, j,
623 algo, -ret);
624 goto out;
627 ret = -EINVAL;
628 for (k = 0, temp = 0; k < template[i].np; k++) {
629 q = xbuf[IDX[k] >> PAGE_SHIFT] +
630 offset_in_page(IDX[k]);
632 n = template[i].tap[k];
633 if (k == template[i].np - 1)
634 n += enc ? authsize : -authsize;
636 if (memcmp(q, template[i].result + temp, n)) {
637 printk(KERN_ERR "alg: aead: Chunk "
638 "test %d failed on %s at page "
639 "%u for %s\n", j, e, k, algo);
640 hexdump(q, n);
641 goto out;
644 q += n;
645 if (k == template[i].np - 1 && !enc) {
646 if (memcmp(q, template[i].input +
647 temp + n, authsize))
648 n = authsize;
649 else
650 n = 0;
651 } else {
652 for (n = 0; offset_in_page(q + n) &&
653 q[n]; n++)
656 if (n) {
657 printk(KERN_ERR "alg: aead: Result "
658 "buffer corruption in chunk "
659 "test %d on %s at page %u for "
660 "%s: %u bytes:\n", j, e, k,
661 algo, n);
662 hexdump(q, n);
663 goto out;
666 temp += template[i].tap[k];
671 ret = 0;
673 out:
674 aead_request_free(req);
675 testmgr_free_buf(axbuf);
676 out_noaxbuf:
677 testmgr_free_buf(xbuf);
678 out_noxbuf:
679 return ret;
682 static int test_cipher(struct crypto_cipher *tfm, int enc,
683 struct cipher_testvec *template, unsigned int tcount)
685 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
686 unsigned int i, j, k;
687 char *q;
688 const char *e;
689 void *data;
690 char *xbuf[XBUFSIZE];
691 int ret = -ENOMEM;
693 if (testmgr_alloc_buf(xbuf))
694 goto out_nobuf;
696 if (enc == ENCRYPT)
697 e = "encryption";
698 else
699 e = "decryption";
701 j = 0;
702 for (i = 0; i < tcount; i++) {
703 if (template[i].np)
704 continue;
706 j++;
708 ret = -EINVAL;
709 if (WARN_ON(template[i].ilen > PAGE_SIZE))
710 goto out;
712 data = xbuf[0];
713 memcpy(data, template[i].input, template[i].ilen);
715 crypto_cipher_clear_flags(tfm, ~0);
716 if (template[i].wk)
717 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
719 ret = crypto_cipher_setkey(tfm, template[i].key,
720 template[i].klen);
721 if (!ret == template[i].fail) {
722 printk(KERN_ERR "alg: cipher: setkey failed "
723 "on test %d for %s: flags=%x\n", j,
724 algo, crypto_cipher_get_flags(tfm));
725 goto out;
726 } else if (ret)
727 continue;
729 for (k = 0; k < template[i].ilen;
730 k += crypto_cipher_blocksize(tfm)) {
731 if (enc)
732 crypto_cipher_encrypt_one(tfm, data + k,
733 data + k);
734 else
735 crypto_cipher_decrypt_one(tfm, data + k,
736 data + k);
739 q = data;
740 if (memcmp(q, template[i].result, template[i].rlen)) {
741 printk(KERN_ERR "alg: cipher: Test %d failed "
742 "on %s for %s\n", j, e, algo);
743 hexdump(q, template[i].rlen);
744 ret = -EINVAL;
745 goto out;
749 ret = 0;
751 out:
752 testmgr_free_buf(xbuf);
753 out_nobuf:
754 return ret;
757 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
758 struct cipher_testvec *template, unsigned int tcount)
760 const char *algo =
761 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
762 unsigned int i, j, k, n, temp;
763 char *q;
764 struct ablkcipher_request *req;
765 struct scatterlist sg[8];
766 const char *e;
767 struct tcrypt_result result;
768 void *data;
769 char iv[MAX_IVLEN];
770 char *xbuf[XBUFSIZE];
771 int ret = -ENOMEM;
773 if (testmgr_alloc_buf(xbuf))
774 goto out_nobuf;
776 if (enc == ENCRYPT)
777 e = "encryption";
778 else
779 e = "decryption";
781 init_completion(&result.completion);
783 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
784 if (!req) {
785 printk(KERN_ERR "alg: skcipher: Failed to allocate request "
786 "for %s\n", algo);
787 goto out;
790 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
791 tcrypt_complete, &result);
793 j = 0;
794 for (i = 0; i < tcount; i++) {
795 if (template[i].iv)
796 memcpy(iv, template[i].iv, MAX_IVLEN);
797 else
798 memset(iv, 0, MAX_IVLEN);
800 if (!(template[i].np)) {
801 j++;
803 ret = -EINVAL;
804 if (WARN_ON(template[i].ilen > PAGE_SIZE))
805 goto out;
807 data = xbuf[0];
808 memcpy(data, template[i].input, template[i].ilen);
810 crypto_ablkcipher_clear_flags(tfm, ~0);
811 if (template[i].wk)
812 crypto_ablkcipher_set_flags(
813 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
815 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
816 template[i].klen);
817 if (!ret == template[i].fail) {
818 printk(KERN_ERR "alg: skcipher: setkey failed "
819 "on test %d for %s: flags=%x\n", j,
820 algo, crypto_ablkcipher_get_flags(tfm));
821 goto out;
822 } else if (ret)
823 continue;
825 sg_init_one(&sg[0], data, template[i].ilen);
827 ablkcipher_request_set_crypt(req, sg, sg,
828 template[i].ilen, iv);
829 ret = enc ?
830 crypto_ablkcipher_encrypt(req) :
831 crypto_ablkcipher_decrypt(req);
833 switch (ret) {
834 case 0:
835 break;
836 case -EINPROGRESS:
837 case -EBUSY:
838 ret = wait_for_completion_interruptible(
839 &result.completion);
840 if (!ret && !((ret = result.err))) {
841 INIT_COMPLETION(result.completion);
842 break;
844 /* fall through */
845 default:
846 printk(KERN_ERR "alg: skcipher: %s failed on "
847 "test %d for %s: ret=%d\n", e, j, algo,
848 -ret);
849 goto out;
852 q = data;
853 if (memcmp(q, template[i].result, template[i].rlen)) {
854 printk(KERN_ERR "alg: skcipher: Test %d "
855 "failed on %s for %s\n", j, e, algo);
856 hexdump(q, template[i].rlen);
857 ret = -EINVAL;
858 goto out;
863 j = 0;
864 for (i = 0; i < tcount; i++) {
866 if (template[i].iv)
867 memcpy(iv, template[i].iv, MAX_IVLEN);
868 else
869 memset(iv, 0, MAX_IVLEN);
871 if (template[i].np) {
872 j++;
874 crypto_ablkcipher_clear_flags(tfm, ~0);
875 if (template[i].wk)
876 crypto_ablkcipher_set_flags(
877 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
879 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
880 template[i].klen);
881 if (!ret == template[i].fail) {
882 printk(KERN_ERR "alg: skcipher: setkey failed "
883 "on chunk test %d for %s: flags=%x\n",
884 j, algo,
885 crypto_ablkcipher_get_flags(tfm));
886 goto out;
887 } else if (ret)
888 continue;
890 temp = 0;
891 ret = -EINVAL;
892 sg_init_table(sg, template[i].np);
893 for (k = 0; k < template[i].np; k++) {
894 if (WARN_ON(offset_in_page(IDX[k]) +
895 template[i].tap[k] > PAGE_SIZE))
896 goto out;
898 q = xbuf[IDX[k] >> PAGE_SHIFT] +
899 offset_in_page(IDX[k]);
901 memcpy(q, template[i].input + temp,
902 template[i].tap[k]);
904 if (offset_in_page(q) + template[i].tap[k] <
905 PAGE_SIZE)
906 q[template[i].tap[k]] = 0;
908 sg_set_buf(&sg[k], q, template[i].tap[k]);
910 temp += template[i].tap[k];
913 ablkcipher_request_set_crypt(req, sg, sg,
914 template[i].ilen, iv);
916 ret = enc ?
917 crypto_ablkcipher_encrypt(req) :
918 crypto_ablkcipher_decrypt(req);
920 switch (ret) {
921 case 0:
922 break;
923 case -EINPROGRESS:
924 case -EBUSY:
925 ret = wait_for_completion_interruptible(
926 &result.completion);
927 if (!ret && !((ret = result.err))) {
928 INIT_COMPLETION(result.completion);
929 break;
931 /* fall through */
932 default:
933 printk(KERN_ERR "alg: skcipher: %s failed on "
934 "chunk test %d for %s: ret=%d\n", e, j,
935 algo, -ret);
936 goto out;
939 temp = 0;
940 ret = -EINVAL;
941 for (k = 0; k < template[i].np; k++) {
942 q = xbuf[IDX[k] >> PAGE_SHIFT] +
943 offset_in_page(IDX[k]);
945 if (memcmp(q, template[i].result + temp,
946 template[i].tap[k])) {
947 printk(KERN_ERR "alg: skcipher: Chunk "
948 "test %d failed on %s at page "
949 "%u for %s\n", j, e, k, algo);
950 hexdump(q, template[i].tap[k]);
951 goto out;
954 q += template[i].tap[k];
955 for (n = 0; offset_in_page(q + n) && q[n]; n++)
957 if (n) {
958 printk(KERN_ERR "alg: skcipher: "
959 "Result buffer corruption in "
960 "chunk test %d on %s at page "
961 "%u for %s: %u bytes:\n", j, e,
962 k, algo, n);
963 hexdump(q, n);
964 goto out;
966 temp += template[i].tap[k];
971 ret = 0;
973 out:
974 ablkcipher_request_free(req);
975 testmgr_free_buf(xbuf);
976 out_nobuf:
977 return ret;
980 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
981 struct comp_testvec *dtemplate, int ctcount, int dtcount)
983 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
984 unsigned int i;
985 char result[COMP_BUF_SIZE];
986 int ret;
988 for (i = 0; i < ctcount; i++) {
989 int ilen;
990 unsigned int dlen = COMP_BUF_SIZE;
992 memset(result, 0, sizeof (result));
994 ilen = ctemplate[i].inlen;
995 ret = crypto_comp_compress(tfm, ctemplate[i].input,
996 ilen, result, &dlen);
997 if (ret) {
998 printk(KERN_ERR "alg: comp: compression failed "
999 "on test %d for %s: ret=%d\n", i + 1, algo,
1000 -ret);
1001 goto out;
1004 if (dlen != ctemplate[i].outlen) {
1005 printk(KERN_ERR "alg: comp: Compression test %d "
1006 "failed for %s: output len = %d\n", i + 1, algo,
1007 dlen);
1008 ret = -EINVAL;
1009 goto out;
1012 if (memcmp(result, ctemplate[i].output, dlen)) {
1013 printk(KERN_ERR "alg: comp: Compression test %d "
1014 "failed for %s\n", i + 1, algo);
1015 hexdump(result, dlen);
1016 ret = -EINVAL;
1017 goto out;
1021 for (i = 0; i < dtcount; i++) {
1022 int ilen;
1023 unsigned int dlen = COMP_BUF_SIZE;
1025 memset(result, 0, sizeof (result));
1027 ilen = dtemplate[i].inlen;
1028 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1029 ilen, result, &dlen);
1030 if (ret) {
1031 printk(KERN_ERR "alg: comp: decompression failed "
1032 "on test %d for %s: ret=%d\n", i + 1, algo,
1033 -ret);
1034 goto out;
1037 if (dlen != dtemplate[i].outlen) {
1038 printk(KERN_ERR "alg: comp: Decompression test %d "
1039 "failed for %s: output len = %d\n", i + 1, algo,
1040 dlen);
1041 ret = -EINVAL;
1042 goto out;
1045 if (memcmp(result, dtemplate[i].output, dlen)) {
1046 printk(KERN_ERR "alg: comp: Decompression test %d "
1047 "failed for %s\n", i + 1, algo);
1048 hexdump(result, dlen);
1049 ret = -EINVAL;
1050 goto out;
1054 ret = 0;
1056 out:
1057 return ret;
1060 static int test_pcomp(struct crypto_pcomp *tfm,
1061 struct pcomp_testvec *ctemplate,
1062 struct pcomp_testvec *dtemplate, int ctcount,
1063 int dtcount)
1065 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1066 unsigned int i;
1067 char result[COMP_BUF_SIZE];
1068 int res;
1070 for (i = 0; i < ctcount; i++) {
1071 struct comp_request req;
1072 unsigned int produced = 0;
1074 res = crypto_compress_setup(tfm, ctemplate[i].params,
1075 ctemplate[i].paramsize);
1076 if (res) {
1077 pr_err("alg: pcomp: compression setup failed on test "
1078 "%d for %s: error=%d\n", i + 1, algo, res);
1079 return res;
1082 res = crypto_compress_init(tfm);
1083 if (res) {
1084 pr_err("alg: pcomp: compression init failed on test "
1085 "%d for %s: error=%d\n", i + 1, algo, res);
1086 return res;
1089 memset(result, 0, sizeof(result));
1091 req.next_in = ctemplate[i].input;
1092 req.avail_in = ctemplate[i].inlen / 2;
1093 req.next_out = result;
1094 req.avail_out = ctemplate[i].outlen / 2;
1096 res = crypto_compress_update(tfm, &req);
1097 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1098 pr_err("alg: pcomp: compression update failed on test "
1099 "%d for %s: error=%d\n", i + 1, algo, res);
1100 return res;
1102 if (res > 0)
1103 produced += res;
1105 /* Add remaining input data */
1106 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1108 res = crypto_compress_update(tfm, &req);
1109 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1110 pr_err("alg: pcomp: compression update failed on test "
1111 "%d for %s: error=%d\n", i + 1, algo, res);
1112 return res;
1114 if (res > 0)
1115 produced += res;
1117 /* Provide remaining output space */
1118 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1120 res = crypto_compress_final(tfm, &req);
1121 if (res < 0) {
1122 pr_err("alg: pcomp: compression final failed on test "
1123 "%d for %s: error=%d\n", i + 1, algo, res);
1124 return res;
1126 produced += res;
1128 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1129 pr_err("alg: comp: Compression test %d failed for %s: "
1130 "output len = %d (expected %d)\n", i + 1, algo,
1131 COMP_BUF_SIZE - req.avail_out,
1132 ctemplate[i].outlen);
1133 return -EINVAL;
1136 if (produced != ctemplate[i].outlen) {
1137 pr_err("alg: comp: Compression test %d failed for %s: "
1138 "returned len = %u (expected %d)\n", i + 1,
1139 algo, produced, ctemplate[i].outlen);
1140 return -EINVAL;
1143 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1144 pr_err("alg: pcomp: Compression test %d failed for "
1145 "%s\n", i + 1, algo);
1146 hexdump(result, ctemplate[i].outlen);
1147 return -EINVAL;
1151 for (i = 0; i < dtcount; i++) {
1152 struct comp_request req;
1153 unsigned int produced = 0;
1155 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1156 dtemplate[i].paramsize);
1157 if (res) {
1158 pr_err("alg: pcomp: decompression setup failed on "
1159 "test %d for %s: error=%d\n", i + 1, algo, res);
1160 return res;
1163 res = crypto_decompress_init(tfm);
1164 if (res) {
1165 pr_err("alg: pcomp: decompression init failed on test "
1166 "%d for %s: error=%d\n", i + 1, algo, res);
1167 return res;
1170 memset(result, 0, sizeof(result));
1172 req.next_in = dtemplate[i].input;
1173 req.avail_in = dtemplate[i].inlen / 2;
1174 req.next_out = result;
1175 req.avail_out = dtemplate[i].outlen / 2;
1177 res = crypto_decompress_update(tfm, &req);
1178 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1179 pr_err("alg: pcomp: decompression update failed on "
1180 "test %d for %s: error=%d\n", i + 1, algo, res);
1181 return res;
1183 if (res > 0)
1184 produced += res;
1186 /* Add remaining input data */
1187 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1189 res = crypto_decompress_update(tfm, &req);
1190 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1191 pr_err("alg: pcomp: decompression update failed on "
1192 "test %d for %s: error=%d\n", i + 1, algo, res);
1193 return res;
1195 if (res > 0)
1196 produced += res;
1198 /* Provide remaining output space */
1199 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1201 res = crypto_decompress_final(tfm, &req);
1202 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1203 pr_err("alg: pcomp: decompression final failed on "
1204 "test %d for %s: error=%d\n", i + 1, algo, res);
1205 return res;
1207 if (res > 0)
1208 produced += res;
1210 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1211 pr_err("alg: comp: Decompression test %d failed for "
1212 "%s: output len = %d (expected %d)\n", i + 1,
1213 algo, COMP_BUF_SIZE - req.avail_out,
1214 dtemplate[i].outlen);
1215 return -EINVAL;
1218 if (produced != dtemplate[i].outlen) {
1219 pr_err("alg: comp: Decompression test %d failed for "
1220 "%s: returned len = %u (expected %d)\n", i + 1,
1221 algo, produced, dtemplate[i].outlen);
1222 return -EINVAL;
1225 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1226 pr_err("alg: pcomp: Decompression test %d failed for "
1227 "%s\n", i + 1, algo);
1228 hexdump(result, dtemplate[i].outlen);
1229 return -EINVAL;
1233 return 0;
1237 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1238 unsigned int tcount)
1240 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1241 int err = 0, i, j, seedsize;
1242 u8 *seed;
1243 char result[32];
1245 seedsize = crypto_rng_seedsize(tfm);
1247 seed = kmalloc(seedsize, GFP_KERNEL);
1248 if (!seed) {
1249 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1250 "for %s\n", algo);
1251 return -ENOMEM;
1254 for (i = 0; i < tcount; i++) {
1255 memset(result, 0, 32);
1257 memcpy(seed, template[i].v, template[i].vlen);
1258 memcpy(seed + template[i].vlen, template[i].key,
1259 template[i].klen);
1260 memcpy(seed + template[i].vlen + template[i].klen,
1261 template[i].dt, template[i].dtlen);
1263 err = crypto_rng_reset(tfm, seed, seedsize);
1264 if (err) {
1265 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1266 "for %s\n", algo);
1267 goto out;
1270 for (j = 0; j < template[i].loops; j++) {
1271 err = crypto_rng_get_bytes(tfm, result,
1272 template[i].rlen);
1273 if (err != template[i].rlen) {
1274 printk(KERN_ERR "alg: cprng: Failed to obtain "
1275 "the correct amount of random data for "
1276 "%s (requested %d, got %d)\n", algo,
1277 template[i].rlen, err);
1278 goto out;
1282 err = memcmp(result, template[i].result,
1283 template[i].rlen);
1284 if (err) {
1285 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1286 i, algo);
1287 hexdump(result, template[i].rlen);
1288 err = -EINVAL;
1289 goto out;
1293 out:
1294 kfree(seed);
1295 return err;
1298 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1299 u32 type, u32 mask)
1301 struct crypto_aead *tfm;
1302 int err = 0;
1304 tfm = crypto_alloc_aead(driver, type, mask);
1305 if (IS_ERR(tfm)) {
1306 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1307 "%ld\n", driver, PTR_ERR(tfm));
1308 return PTR_ERR(tfm);
1311 if (desc->suite.aead.enc.vecs) {
1312 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1313 desc->suite.aead.enc.count);
1314 if (err)
1315 goto out;
1318 if (!err && desc->suite.aead.dec.vecs)
1319 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1320 desc->suite.aead.dec.count);
1322 out:
1323 crypto_free_aead(tfm);
1324 return err;
1327 static int alg_test_cipher(const struct alg_test_desc *desc,
1328 const char *driver, u32 type, u32 mask)
1330 struct crypto_cipher *tfm;
1331 int err = 0;
1333 tfm = crypto_alloc_cipher(driver, type, mask);
1334 if (IS_ERR(tfm)) {
1335 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1336 "%s: %ld\n", driver, PTR_ERR(tfm));
1337 return PTR_ERR(tfm);
1340 if (desc->suite.cipher.enc.vecs) {
1341 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1342 desc->suite.cipher.enc.count);
1343 if (err)
1344 goto out;
1347 if (desc->suite.cipher.dec.vecs)
1348 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1349 desc->suite.cipher.dec.count);
1351 out:
1352 crypto_free_cipher(tfm);
1353 return err;
1356 static int alg_test_skcipher(const struct alg_test_desc *desc,
1357 const char *driver, u32 type, u32 mask)
1359 struct crypto_ablkcipher *tfm;
1360 int err = 0;
1362 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1363 if (IS_ERR(tfm)) {
1364 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1365 "%s: %ld\n", driver, PTR_ERR(tfm));
1366 return PTR_ERR(tfm);
1369 if (desc->suite.cipher.enc.vecs) {
1370 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1371 desc->suite.cipher.enc.count);
1372 if (err)
1373 goto out;
1376 if (desc->suite.cipher.dec.vecs)
1377 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1378 desc->suite.cipher.dec.count);
1380 out:
1381 crypto_free_ablkcipher(tfm);
1382 return err;
1385 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1386 u32 type, u32 mask)
1388 struct crypto_comp *tfm;
1389 int err;
1391 tfm = crypto_alloc_comp(driver, type, mask);
1392 if (IS_ERR(tfm)) {
1393 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1394 "%ld\n", driver, PTR_ERR(tfm));
1395 return PTR_ERR(tfm);
1398 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1399 desc->suite.comp.decomp.vecs,
1400 desc->suite.comp.comp.count,
1401 desc->suite.comp.decomp.count);
1403 crypto_free_comp(tfm);
1404 return err;
1407 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1408 u32 type, u32 mask)
1410 struct crypto_pcomp *tfm;
1411 int err;
1413 tfm = crypto_alloc_pcomp(driver, type, mask);
1414 if (IS_ERR(tfm)) {
1415 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1416 driver, PTR_ERR(tfm));
1417 return PTR_ERR(tfm);
1420 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1421 desc->suite.pcomp.decomp.vecs,
1422 desc->suite.pcomp.comp.count,
1423 desc->suite.pcomp.decomp.count);
1425 crypto_free_pcomp(tfm);
1426 return err;
1429 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1430 u32 type, u32 mask)
1432 struct crypto_ahash *tfm;
1433 int err;
1435 tfm = crypto_alloc_ahash(driver, type, mask);
1436 if (IS_ERR(tfm)) {
1437 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1438 "%ld\n", driver, PTR_ERR(tfm));
1439 return PTR_ERR(tfm);
1442 err = test_hash(tfm, desc->suite.hash.vecs,
1443 desc->suite.hash.count, true);
1444 if (!err)
1445 err = test_hash(tfm, desc->suite.hash.vecs,
1446 desc->suite.hash.count, false);
1448 crypto_free_ahash(tfm);
1449 return err;
1452 static int alg_test_crc32c(const struct alg_test_desc *desc,
1453 const char *driver, u32 type, u32 mask)
1455 struct crypto_shash *tfm;
1456 u32 val;
1457 int err;
1459 err = alg_test_hash(desc, driver, type, mask);
1460 if (err)
1461 goto out;
1463 tfm = crypto_alloc_shash(driver, type, mask);
1464 if (IS_ERR(tfm)) {
1465 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1466 "%ld\n", driver, PTR_ERR(tfm));
1467 err = PTR_ERR(tfm);
1468 goto out;
1471 do {
1472 struct {
1473 struct shash_desc shash;
1474 char ctx[crypto_shash_descsize(tfm)];
1475 } sdesc;
1477 sdesc.shash.tfm = tfm;
1478 sdesc.shash.flags = 0;
1480 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1481 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1482 if (err) {
1483 printk(KERN_ERR "alg: crc32c: Operation failed for "
1484 "%s: %d\n", driver, err);
1485 break;
1488 if (val != ~420553207) {
1489 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1490 "%d\n", driver, val);
1491 err = -EINVAL;
1493 } while (0);
1495 crypto_free_shash(tfm);
1497 out:
1498 return err;
1501 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1502 u32 type, u32 mask)
1504 struct crypto_rng *rng;
1505 int err;
1507 rng = crypto_alloc_rng(driver, type, mask);
1508 if (IS_ERR(rng)) {
1509 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1510 "%ld\n", driver, PTR_ERR(rng));
1511 return PTR_ERR(rng);
1514 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1516 crypto_free_rng(rng);
1518 return err;
1521 static int alg_test_null(const struct alg_test_desc *desc,
1522 const char *driver, u32 type, u32 mask)
1524 return 0;
1527 /* Please keep this list sorted by algorithm name. */
1528 static const struct alg_test_desc alg_test_descs[] = {
1530 .alg = "__driver-cbc-aes-aesni",
1531 .test = alg_test_null,
1532 .suite = {
1533 .cipher = {
1534 .enc = {
1535 .vecs = NULL,
1536 .count = 0
1538 .dec = {
1539 .vecs = NULL,
1540 .count = 0
1544 }, {
1545 .alg = "__driver-ecb-aes-aesni",
1546 .test = alg_test_null,
1547 .suite = {
1548 .cipher = {
1549 .enc = {
1550 .vecs = NULL,
1551 .count = 0
1553 .dec = {
1554 .vecs = NULL,
1555 .count = 0
1559 }, {
1560 .alg = "__ghash-pclmulqdqni",
1561 .test = alg_test_null,
1562 .suite = {
1563 .hash = {
1564 .vecs = NULL,
1565 .count = 0
1568 }, {
1569 .alg = "ansi_cprng",
1570 .test = alg_test_cprng,
1571 .fips_allowed = 1,
1572 .suite = {
1573 .cprng = {
1574 .vecs = ansi_cprng_aes_tv_template,
1575 .count = ANSI_CPRNG_AES_TEST_VECTORS
1578 }, {
1579 .alg = "cbc(aes)",
1580 .test = alg_test_skcipher,
1581 .fips_allowed = 1,
1582 .suite = {
1583 .cipher = {
1584 .enc = {
1585 .vecs = aes_cbc_enc_tv_template,
1586 .count = AES_CBC_ENC_TEST_VECTORS
1588 .dec = {
1589 .vecs = aes_cbc_dec_tv_template,
1590 .count = AES_CBC_DEC_TEST_VECTORS
1594 }, {
1595 .alg = "cbc(anubis)",
1596 .test = alg_test_skcipher,
1597 .suite = {
1598 .cipher = {
1599 .enc = {
1600 .vecs = anubis_cbc_enc_tv_template,
1601 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1603 .dec = {
1604 .vecs = anubis_cbc_dec_tv_template,
1605 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1609 }, {
1610 .alg = "cbc(blowfish)",
1611 .test = alg_test_skcipher,
1612 .suite = {
1613 .cipher = {
1614 .enc = {
1615 .vecs = bf_cbc_enc_tv_template,
1616 .count = BF_CBC_ENC_TEST_VECTORS
1618 .dec = {
1619 .vecs = bf_cbc_dec_tv_template,
1620 .count = BF_CBC_DEC_TEST_VECTORS
1624 }, {
1625 .alg = "cbc(camellia)",
1626 .test = alg_test_skcipher,
1627 .suite = {
1628 .cipher = {
1629 .enc = {
1630 .vecs = camellia_cbc_enc_tv_template,
1631 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1633 .dec = {
1634 .vecs = camellia_cbc_dec_tv_template,
1635 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1639 }, {
1640 .alg = "cbc(des)",
1641 .test = alg_test_skcipher,
1642 .suite = {
1643 .cipher = {
1644 .enc = {
1645 .vecs = des_cbc_enc_tv_template,
1646 .count = DES_CBC_ENC_TEST_VECTORS
1648 .dec = {
1649 .vecs = des_cbc_dec_tv_template,
1650 .count = DES_CBC_DEC_TEST_VECTORS
1654 }, {
1655 .alg = "cbc(des3_ede)",
1656 .test = alg_test_skcipher,
1657 .fips_allowed = 1,
1658 .suite = {
1659 .cipher = {
1660 .enc = {
1661 .vecs = des3_ede_cbc_enc_tv_template,
1662 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1664 .dec = {
1665 .vecs = des3_ede_cbc_dec_tv_template,
1666 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1670 }, {
1671 .alg = "cbc(twofish)",
1672 .test = alg_test_skcipher,
1673 .suite = {
1674 .cipher = {
1675 .enc = {
1676 .vecs = tf_cbc_enc_tv_template,
1677 .count = TF_CBC_ENC_TEST_VECTORS
1679 .dec = {
1680 .vecs = tf_cbc_dec_tv_template,
1681 .count = TF_CBC_DEC_TEST_VECTORS
1685 }, {
1686 .alg = "ccm(aes)",
1687 .test = alg_test_aead,
1688 .fips_allowed = 1,
1689 .suite = {
1690 .aead = {
1691 .enc = {
1692 .vecs = aes_ccm_enc_tv_template,
1693 .count = AES_CCM_ENC_TEST_VECTORS
1695 .dec = {
1696 .vecs = aes_ccm_dec_tv_template,
1697 .count = AES_CCM_DEC_TEST_VECTORS
1701 }, {
1702 .alg = "crc32c",
1703 .test = alg_test_crc32c,
1704 .fips_allowed = 1,
1705 .suite = {
1706 .hash = {
1707 .vecs = crc32c_tv_template,
1708 .count = CRC32C_TEST_VECTORS
1711 }, {
1712 .alg = "cryptd(__driver-ecb-aes-aesni)",
1713 .test = alg_test_null,
1714 .suite = {
1715 .cipher = {
1716 .enc = {
1717 .vecs = NULL,
1718 .count = 0
1720 .dec = {
1721 .vecs = NULL,
1722 .count = 0
1726 }, {
1727 .alg = "cryptd(__ghash-pclmulqdqni)",
1728 .test = alg_test_null,
1729 .suite = {
1730 .hash = {
1731 .vecs = NULL,
1732 .count = 0
1735 }, {
1736 .alg = "ctr(aes)",
1737 .test = alg_test_skcipher,
1738 .fips_allowed = 1,
1739 .suite = {
1740 .cipher = {
1741 .enc = {
1742 .vecs = aes_ctr_enc_tv_template,
1743 .count = AES_CTR_ENC_TEST_VECTORS
1745 .dec = {
1746 .vecs = aes_ctr_dec_tv_template,
1747 .count = AES_CTR_DEC_TEST_VECTORS
1751 }, {
1752 .alg = "cts(cbc(aes))",
1753 .test = alg_test_skcipher,
1754 .suite = {
1755 .cipher = {
1756 .enc = {
1757 .vecs = cts_mode_enc_tv_template,
1758 .count = CTS_MODE_ENC_TEST_VECTORS
1760 .dec = {
1761 .vecs = cts_mode_dec_tv_template,
1762 .count = CTS_MODE_DEC_TEST_VECTORS
1766 }, {
1767 .alg = "deflate",
1768 .test = alg_test_comp,
1769 .suite = {
1770 .comp = {
1771 .comp = {
1772 .vecs = deflate_comp_tv_template,
1773 .count = DEFLATE_COMP_TEST_VECTORS
1775 .decomp = {
1776 .vecs = deflate_decomp_tv_template,
1777 .count = DEFLATE_DECOMP_TEST_VECTORS
1781 }, {
1782 .alg = "ecb(__aes-aesni)",
1783 .test = alg_test_null,
1784 .suite = {
1785 .cipher = {
1786 .enc = {
1787 .vecs = NULL,
1788 .count = 0
1790 .dec = {
1791 .vecs = NULL,
1792 .count = 0
1796 }, {
1797 .alg = "ecb(aes)",
1798 .test = alg_test_skcipher,
1799 .fips_allowed = 1,
1800 .suite = {
1801 .cipher = {
1802 .enc = {
1803 .vecs = aes_enc_tv_template,
1804 .count = AES_ENC_TEST_VECTORS
1806 .dec = {
1807 .vecs = aes_dec_tv_template,
1808 .count = AES_DEC_TEST_VECTORS
1812 }, {
1813 .alg = "ecb(anubis)",
1814 .test = alg_test_skcipher,
1815 .suite = {
1816 .cipher = {
1817 .enc = {
1818 .vecs = anubis_enc_tv_template,
1819 .count = ANUBIS_ENC_TEST_VECTORS
1821 .dec = {
1822 .vecs = anubis_dec_tv_template,
1823 .count = ANUBIS_DEC_TEST_VECTORS
1827 }, {
1828 .alg = "ecb(arc4)",
1829 .test = alg_test_skcipher,
1830 .suite = {
1831 .cipher = {
1832 .enc = {
1833 .vecs = arc4_enc_tv_template,
1834 .count = ARC4_ENC_TEST_VECTORS
1836 .dec = {
1837 .vecs = arc4_dec_tv_template,
1838 .count = ARC4_DEC_TEST_VECTORS
1842 }, {
1843 .alg = "ecb(blowfish)",
1844 .test = alg_test_skcipher,
1845 .suite = {
1846 .cipher = {
1847 .enc = {
1848 .vecs = bf_enc_tv_template,
1849 .count = BF_ENC_TEST_VECTORS
1851 .dec = {
1852 .vecs = bf_dec_tv_template,
1853 .count = BF_DEC_TEST_VECTORS
1857 }, {
1858 .alg = "ecb(camellia)",
1859 .test = alg_test_skcipher,
1860 .suite = {
1861 .cipher = {
1862 .enc = {
1863 .vecs = camellia_enc_tv_template,
1864 .count = CAMELLIA_ENC_TEST_VECTORS
1866 .dec = {
1867 .vecs = camellia_dec_tv_template,
1868 .count = CAMELLIA_DEC_TEST_VECTORS
1872 }, {
1873 .alg = "ecb(cast5)",
1874 .test = alg_test_skcipher,
1875 .suite = {
1876 .cipher = {
1877 .enc = {
1878 .vecs = cast5_enc_tv_template,
1879 .count = CAST5_ENC_TEST_VECTORS
1881 .dec = {
1882 .vecs = cast5_dec_tv_template,
1883 .count = CAST5_DEC_TEST_VECTORS
1887 }, {
1888 .alg = "ecb(cast6)",
1889 .test = alg_test_skcipher,
1890 .suite = {
1891 .cipher = {
1892 .enc = {
1893 .vecs = cast6_enc_tv_template,
1894 .count = CAST6_ENC_TEST_VECTORS
1896 .dec = {
1897 .vecs = cast6_dec_tv_template,
1898 .count = CAST6_DEC_TEST_VECTORS
1902 }, {
1903 .alg = "ecb(des)",
1904 .test = alg_test_skcipher,
1905 .fips_allowed = 1,
1906 .suite = {
1907 .cipher = {
1908 .enc = {
1909 .vecs = des_enc_tv_template,
1910 .count = DES_ENC_TEST_VECTORS
1912 .dec = {
1913 .vecs = des_dec_tv_template,
1914 .count = DES_DEC_TEST_VECTORS
1918 }, {
1919 .alg = "ecb(des3_ede)",
1920 .test = alg_test_skcipher,
1921 .fips_allowed = 1,
1922 .suite = {
1923 .cipher = {
1924 .enc = {
1925 .vecs = des3_ede_enc_tv_template,
1926 .count = DES3_EDE_ENC_TEST_VECTORS
1928 .dec = {
1929 .vecs = des3_ede_dec_tv_template,
1930 .count = DES3_EDE_DEC_TEST_VECTORS
1934 }, {
1935 .alg = "ecb(khazad)",
1936 .test = alg_test_skcipher,
1937 .suite = {
1938 .cipher = {
1939 .enc = {
1940 .vecs = khazad_enc_tv_template,
1941 .count = KHAZAD_ENC_TEST_VECTORS
1943 .dec = {
1944 .vecs = khazad_dec_tv_template,
1945 .count = KHAZAD_DEC_TEST_VECTORS
1949 }, {
1950 .alg = "ecb(seed)",
1951 .test = alg_test_skcipher,
1952 .suite = {
1953 .cipher = {
1954 .enc = {
1955 .vecs = seed_enc_tv_template,
1956 .count = SEED_ENC_TEST_VECTORS
1958 .dec = {
1959 .vecs = seed_dec_tv_template,
1960 .count = SEED_DEC_TEST_VECTORS
1964 }, {
1965 .alg = "ecb(serpent)",
1966 .test = alg_test_skcipher,
1967 .suite = {
1968 .cipher = {
1969 .enc = {
1970 .vecs = serpent_enc_tv_template,
1971 .count = SERPENT_ENC_TEST_VECTORS
1973 .dec = {
1974 .vecs = serpent_dec_tv_template,
1975 .count = SERPENT_DEC_TEST_VECTORS
1979 }, {
1980 .alg = "ecb(tea)",
1981 .test = alg_test_skcipher,
1982 .suite = {
1983 .cipher = {
1984 .enc = {
1985 .vecs = tea_enc_tv_template,
1986 .count = TEA_ENC_TEST_VECTORS
1988 .dec = {
1989 .vecs = tea_dec_tv_template,
1990 .count = TEA_DEC_TEST_VECTORS
1994 }, {
1995 .alg = "ecb(tnepres)",
1996 .test = alg_test_skcipher,
1997 .suite = {
1998 .cipher = {
1999 .enc = {
2000 .vecs = tnepres_enc_tv_template,
2001 .count = TNEPRES_ENC_TEST_VECTORS
2003 .dec = {
2004 .vecs = tnepres_dec_tv_template,
2005 .count = TNEPRES_DEC_TEST_VECTORS
2009 }, {
2010 .alg = "ecb(twofish)",
2011 .test = alg_test_skcipher,
2012 .suite = {
2013 .cipher = {
2014 .enc = {
2015 .vecs = tf_enc_tv_template,
2016 .count = TF_ENC_TEST_VECTORS
2018 .dec = {
2019 .vecs = tf_dec_tv_template,
2020 .count = TF_DEC_TEST_VECTORS
2024 }, {
2025 .alg = "ecb(xeta)",
2026 .test = alg_test_skcipher,
2027 .suite = {
2028 .cipher = {
2029 .enc = {
2030 .vecs = xeta_enc_tv_template,
2031 .count = XETA_ENC_TEST_VECTORS
2033 .dec = {
2034 .vecs = xeta_dec_tv_template,
2035 .count = XETA_DEC_TEST_VECTORS
2039 }, {
2040 .alg = "ecb(xtea)",
2041 .test = alg_test_skcipher,
2042 .suite = {
2043 .cipher = {
2044 .enc = {
2045 .vecs = xtea_enc_tv_template,
2046 .count = XTEA_ENC_TEST_VECTORS
2048 .dec = {
2049 .vecs = xtea_dec_tv_template,
2050 .count = XTEA_DEC_TEST_VECTORS
2054 }, {
2055 .alg = "gcm(aes)",
2056 .test = alg_test_aead,
2057 .fips_allowed = 1,
2058 .suite = {
2059 .aead = {
2060 .enc = {
2061 .vecs = aes_gcm_enc_tv_template,
2062 .count = AES_GCM_ENC_TEST_VECTORS
2064 .dec = {
2065 .vecs = aes_gcm_dec_tv_template,
2066 .count = AES_GCM_DEC_TEST_VECTORS
2070 }, {
2071 .alg = "ghash",
2072 .test = alg_test_hash,
2073 .suite = {
2074 .hash = {
2075 .vecs = ghash_tv_template,
2076 .count = GHASH_TEST_VECTORS
2079 }, {
2080 .alg = "hmac(md5)",
2081 .test = alg_test_hash,
2082 .suite = {
2083 .hash = {
2084 .vecs = hmac_md5_tv_template,
2085 .count = HMAC_MD5_TEST_VECTORS
2088 }, {
2089 .alg = "hmac(rmd128)",
2090 .test = alg_test_hash,
2091 .suite = {
2092 .hash = {
2093 .vecs = hmac_rmd128_tv_template,
2094 .count = HMAC_RMD128_TEST_VECTORS
2097 }, {
2098 .alg = "hmac(rmd160)",
2099 .test = alg_test_hash,
2100 .suite = {
2101 .hash = {
2102 .vecs = hmac_rmd160_tv_template,
2103 .count = HMAC_RMD160_TEST_VECTORS
2106 }, {
2107 .alg = "hmac(sha1)",
2108 .test = alg_test_hash,
2109 .fips_allowed = 1,
2110 .suite = {
2111 .hash = {
2112 .vecs = hmac_sha1_tv_template,
2113 .count = HMAC_SHA1_TEST_VECTORS
2116 }, {
2117 .alg = "hmac(sha224)",
2118 .test = alg_test_hash,
2119 .fips_allowed = 1,
2120 .suite = {
2121 .hash = {
2122 .vecs = hmac_sha224_tv_template,
2123 .count = HMAC_SHA224_TEST_VECTORS
2126 }, {
2127 .alg = "hmac(sha256)",
2128 .test = alg_test_hash,
2129 .fips_allowed = 1,
2130 .suite = {
2131 .hash = {
2132 .vecs = hmac_sha256_tv_template,
2133 .count = HMAC_SHA256_TEST_VECTORS
2136 }, {
2137 .alg = "hmac(sha384)",
2138 .test = alg_test_hash,
2139 .fips_allowed = 1,
2140 .suite = {
2141 .hash = {
2142 .vecs = hmac_sha384_tv_template,
2143 .count = HMAC_SHA384_TEST_VECTORS
2146 }, {
2147 .alg = "hmac(sha512)",
2148 .test = alg_test_hash,
2149 .fips_allowed = 1,
2150 .suite = {
2151 .hash = {
2152 .vecs = hmac_sha512_tv_template,
2153 .count = HMAC_SHA512_TEST_VECTORS
2156 }, {
2157 .alg = "lrw(aes)",
2158 .test = alg_test_skcipher,
2159 .suite = {
2160 .cipher = {
2161 .enc = {
2162 .vecs = aes_lrw_enc_tv_template,
2163 .count = AES_LRW_ENC_TEST_VECTORS
2165 .dec = {
2166 .vecs = aes_lrw_dec_tv_template,
2167 .count = AES_LRW_DEC_TEST_VECTORS
2171 }, {
2172 .alg = "lzo",
2173 .test = alg_test_comp,
2174 .suite = {
2175 .comp = {
2176 .comp = {
2177 .vecs = lzo_comp_tv_template,
2178 .count = LZO_COMP_TEST_VECTORS
2180 .decomp = {
2181 .vecs = lzo_decomp_tv_template,
2182 .count = LZO_DECOMP_TEST_VECTORS
2186 }, {
2187 .alg = "md4",
2188 .test = alg_test_hash,
2189 .suite = {
2190 .hash = {
2191 .vecs = md4_tv_template,
2192 .count = MD4_TEST_VECTORS
2195 }, {
2196 .alg = "md5",
2197 .test = alg_test_hash,
2198 .suite = {
2199 .hash = {
2200 .vecs = md5_tv_template,
2201 .count = MD5_TEST_VECTORS
2204 }, {
2205 .alg = "michael_mic",
2206 .test = alg_test_hash,
2207 .suite = {
2208 .hash = {
2209 .vecs = michael_mic_tv_template,
2210 .count = MICHAEL_MIC_TEST_VECTORS
2213 }, {
2214 .alg = "pcbc(fcrypt)",
2215 .test = alg_test_skcipher,
2216 .suite = {
2217 .cipher = {
2218 .enc = {
2219 .vecs = fcrypt_pcbc_enc_tv_template,
2220 .count = FCRYPT_ENC_TEST_VECTORS
2222 .dec = {
2223 .vecs = fcrypt_pcbc_dec_tv_template,
2224 .count = FCRYPT_DEC_TEST_VECTORS
2228 }, {
2229 .alg = "rfc3686(ctr(aes))",
2230 .test = alg_test_skcipher,
2231 .fips_allowed = 1,
2232 .suite = {
2233 .cipher = {
2234 .enc = {
2235 .vecs = aes_ctr_rfc3686_enc_tv_template,
2236 .count = AES_CTR_3686_ENC_TEST_VECTORS
2238 .dec = {
2239 .vecs = aes_ctr_rfc3686_dec_tv_template,
2240 .count = AES_CTR_3686_DEC_TEST_VECTORS
2244 }, {
2245 .alg = "rfc4309(ccm(aes))",
2246 .test = alg_test_aead,
2247 .fips_allowed = 1,
2248 .suite = {
2249 .aead = {
2250 .enc = {
2251 .vecs = aes_ccm_rfc4309_enc_tv_template,
2252 .count = AES_CCM_4309_ENC_TEST_VECTORS
2254 .dec = {
2255 .vecs = aes_ccm_rfc4309_dec_tv_template,
2256 .count = AES_CCM_4309_DEC_TEST_VECTORS
2260 }, {
2261 .alg = "rmd128",
2262 .test = alg_test_hash,
2263 .suite = {
2264 .hash = {
2265 .vecs = rmd128_tv_template,
2266 .count = RMD128_TEST_VECTORS
2269 }, {
2270 .alg = "rmd160",
2271 .test = alg_test_hash,
2272 .suite = {
2273 .hash = {
2274 .vecs = rmd160_tv_template,
2275 .count = RMD160_TEST_VECTORS
2278 }, {
2279 .alg = "rmd256",
2280 .test = alg_test_hash,
2281 .suite = {
2282 .hash = {
2283 .vecs = rmd256_tv_template,
2284 .count = RMD256_TEST_VECTORS
2287 }, {
2288 .alg = "rmd320",
2289 .test = alg_test_hash,
2290 .suite = {
2291 .hash = {
2292 .vecs = rmd320_tv_template,
2293 .count = RMD320_TEST_VECTORS
2296 }, {
2297 .alg = "salsa20",
2298 .test = alg_test_skcipher,
2299 .suite = {
2300 .cipher = {
2301 .enc = {
2302 .vecs = salsa20_stream_enc_tv_template,
2303 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2307 }, {
2308 .alg = "sha1",
2309 .test = alg_test_hash,
2310 .fips_allowed = 1,
2311 .suite = {
2312 .hash = {
2313 .vecs = sha1_tv_template,
2314 .count = SHA1_TEST_VECTORS
2317 }, {
2318 .alg = "sha224",
2319 .test = alg_test_hash,
2320 .fips_allowed = 1,
2321 .suite = {
2322 .hash = {
2323 .vecs = sha224_tv_template,
2324 .count = SHA224_TEST_VECTORS
2327 }, {
2328 .alg = "sha256",
2329 .test = alg_test_hash,
2330 .fips_allowed = 1,
2331 .suite = {
2332 .hash = {
2333 .vecs = sha256_tv_template,
2334 .count = SHA256_TEST_VECTORS
2337 }, {
2338 .alg = "sha384",
2339 .test = alg_test_hash,
2340 .fips_allowed = 1,
2341 .suite = {
2342 .hash = {
2343 .vecs = sha384_tv_template,
2344 .count = SHA384_TEST_VECTORS
2347 }, {
2348 .alg = "sha512",
2349 .test = alg_test_hash,
2350 .fips_allowed = 1,
2351 .suite = {
2352 .hash = {
2353 .vecs = sha512_tv_template,
2354 .count = SHA512_TEST_VECTORS
2357 }, {
2358 .alg = "tgr128",
2359 .test = alg_test_hash,
2360 .suite = {
2361 .hash = {
2362 .vecs = tgr128_tv_template,
2363 .count = TGR128_TEST_VECTORS
2366 }, {
2367 .alg = "tgr160",
2368 .test = alg_test_hash,
2369 .suite = {
2370 .hash = {
2371 .vecs = tgr160_tv_template,
2372 .count = TGR160_TEST_VECTORS
2375 }, {
2376 .alg = "tgr192",
2377 .test = alg_test_hash,
2378 .suite = {
2379 .hash = {
2380 .vecs = tgr192_tv_template,
2381 .count = TGR192_TEST_VECTORS
2384 }, {
2385 .alg = "vmac(aes)",
2386 .test = alg_test_hash,
2387 .suite = {
2388 .hash = {
2389 .vecs = aes_vmac128_tv_template,
2390 .count = VMAC_AES_TEST_VECTORS
2393 }, {
2394 .alg = "wp256",
2395 .test = alg_test_hash,
2396 .suite = {
2397 .hash = {
2398 .vecs = wp256_tv_template,
2399 .count = WP256_TEST_VECTORS
2402 }, {
2403 .alg = "wp384",
2404 .test = alg_test_hash,
2405 .suite = {
2406 .hash = {
2407 .vecs = wp384_tv_template,
2408 .count = WP384_TEST_VECTORS
2411 }, {
2412 .alg = "wp512",
2413 .test = alg_test_hash,
2414 .suite = {
2415 .hash = {
2416 .vecs = wp512_tv_template,
2417 .count = WP512_TEST_VECTORS
2420 }, {
2421 .alg = "xcbc(aes)",
2422 .test = alg_test_hash,
2423 .suite = {
2424 .hash = {
2425 .vecs = aes_xcbc128_tv_template,
2426 .count = XCBC_AES_TEST_VECTORS
2429 }, {
2430 .alg = "xts(aes)",
2431 .test = alg_test_skcipher,
2432 .suite = {
2433 .cipher = {
2434 .enc = {
2435 .vecs = aes_xts_enc_tv_template,
2436 .count = AES_XTS_ENC_TEST_VECTORS
2438 .dec = {
2439 .vecs = aes_xts_dec_tv_template,
2440 .count = AES_XTS_DEC_TEST_VECTORS
2444 }, {
2445 .alg = "zlib",
2446 .test = alg_test_pcomp,
2447 .suite = {
2448 .pcomp = {
2449 .comp = {
2450 .vecs = zlib_comp_tv_template,
2451 .count = ZLIB_COMP_TEST_VECTORS
2453 .decomp = {
2454 .vecs = zlib_decomp_tv_template,
2455 .count = ZLIB_DECOMP_TEST_VECTORS
2462 static int alg_find_test(const char *alg)
2464 int start = 0;
2465 int end = ARRAY_SIZE(alg_test_descs);
2467 while (start < end) {
2468 int i = (start + end) / 2;
2469 int diff = strcmp(alg_test_descs[i].alg, alg);
2471 if (diff > 0) {
2472 end = i;
2473 continue;
2476 if (diff < 0) {
2477 start = i + 1;
2478 continue;
2481 return i;
2484 return -1;
2487 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2489 int i;
2490 int j;
2491 int rc;
2493 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
2494 char nalg[CRYPTO_MAX_ALG_NAME];
2496 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
2497 sizeof(nalg))
2498 return -ENAMETOOLONG;
2500 i = alg_find_test(nalg);
2501 if (i < 0)
2502 goto notest;
2504 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2505 goto non_fips_alg;
2507 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2508 goto test_done;
2511 i = alg_find_test(alg);
2512 j = alg_find_test(driver);
2513 if (i < 0 && j < 0)
2514 goto notest;
2516 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
2517 (j >= 0 && !alg_test_descs[j].fips_allowed)))
2518 goto non_fips_alg;
2520 rc = 0;
2521 if (i >= 0)
2522 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
2523 type, mask);
2524 if (j >= 0)
2525 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
2526 type, mask);
2528 test_done:
2529 if (fips_enabled && rc)
2530 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2532 if (fips_enabled && !rc)
2533 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2534 driver, alg);
2536 return rc;
2538 notest:
2539 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2540 return 0;
2541 non_fips_alg:
2542 return -EINVAL;
2545 #endif /* CONFIG_CRYPTO_MANAGER_DISABLE_TESTS */
2547 EXPORT_SYMBOL_GPL(alg_test);