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)
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>
28 * Need slab memory for testing (size in number of pages).
33 * Indexes into the xbuf to simulate cross-page access.
45 * Used by test_cipher()
50 struct tcrypt_result {
51 struct completion completion;
55 struct aead_test_suite {
57 struct aead_testvec *vecs;
62 struct cipher_test_suite {
64 struct cipher_testvec *vecs;
69 struct comp_test_suite {
71 struct comp_testvec *vecs;
76 struct pcomp_test_suite {
78 struct pcomp_testvec *vecs;
83 struct hash_test_suite {
84 struct hash_testvec *vecs;
88 struct cprng_test_suite {
89 struct cprng_testvec *vecs;
93 struct alg_test_desc {
95 int (*test)(const struct alg_test_desc *desc, const char *driver,
97 int fips_allowed; /* set if alg is allowed in fips mode */
100 struct aead_test_suite aead;
101 struct cipher_test_suite cipher;
102 struct comp_test_suite comp;
103 struct pcomp_test_suite pcomp;
104 struct hash_test_suite hash;
105 struct cprng_test_suite cprng;
109 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
111 static void hexdump(unsigned char *buf, unsigned int len)
113 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
118 static void tcrypt_complete(struct crypto_async_request *req, int err)
120 struct tcrypt_result *res = req->data;
122 if (err == -EINPROGRESS)
126 complete(&res->completion);
129 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
133 for (i = 0; i < XBUFSIZE; i++) {
134 buf[i] = (void *)__get_free_page(GFP_KERNEL);
143 free_page((unsigned long)buf[i]);
148 static void testmgr_free_buf(char *buf[XBUFSIZE])
152 for (i = 0; i < XBUFSIZE; i++)
153 free_page((unsigned long)buf[i]);
156 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
159 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
160 unsigned int i, j, k, temp;
161 struct scatterlist sg[8];
163 struct ahash_request *req;
164 struct tcrypt_result tresult;
166 char *xbuf[XBUFSIZE];
169 if (testmgr_alloc_buf(xbuf))
172 init_completion(&tresult.completion);
174 req = ahash_request_alloc(tfm, GFP_KERNEL);
176 printk(KERN_ERR "alg: hash: Failed to allocate request for "
180 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
181 tcrypt_complete, &tresult);
183 for (i = 0; i < tcount; i++) {
184 memset(result, 0, 64);
188 memcpy(hash_buff, template[i].plaintext, template[i].psize);
189 sg_init_one(&sg[0], hash_buff, template[i].psize);
191 if (template[i].ksize) {
192 crypto_ahash_clear_flags(tfm, ~0);
193 ret = crypto_ahash_setkey(tfm, template[i].key,
196 printk(KERN_ERR "alg: hash: setkey failed on "
197 "test %d for %s: ret=%d\n", i + 1, algo,
203 ahash_request_set_crypt(req, sg, result, template[i].psize);
204 ret = crypto_ahash_digest(req);
210 ret = wait_for_completion_interruptible(
211 &tresult.completion);
212 if (!ret && !(ret = tresult.err)) {
213 INIT_COMPLETION(tresult.completion);
218 printk(KERN_ERR "alg: hash: digest failed on test %d "
219 "for %s: ret=%d\n", i + 1, algo, -ret);
223 if (memcmp(result, template[i].digest,
224 crypto_ahash_digestsize(tfm))) {
225 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
227 hexdump(result, crypto_ahash_digestsize(tfm));
234 for (i = 0; i < tcount; i++) {
235 if (template[i].np) {
237 memset(result, 0, 64);
240 sg_init_table(sg, template[i].np);
241 for (k = 0; k < template[i].np; k++) {
243 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
244 offset_in_page(IDX[k]),
245 template[i].plaintext + temp,
248 temp += template[i].tap[k];
251 if (template[i].ksize) {
252 crypto_ahash_clear_flags(tfm, ~0);
253 ret = crypto_ahash_setkey(tfm, template[i].key,
257 printk(KERN_ERR "alg: hash: setkey "
258 "failed on chunking test %d "
259 "for %s: ret=%d\n", j, algo,
265 ahash_request_set_crypt(req, sg, result,
267 ret = crypto_ahash_digest(req);
273 ret = wait_for_completion_interruptible(
274 &tresult.completion);
275 if (!ret && !(ret = tresult.err)) {
276 INIT_COMPLETION(tresult.completion);
281 printk(KERN_ERR "alg: hash: digest failed "
282 "on chunking test %d for %s: "
283 "ret=%d\n", j, algo, -ret);
287 if (memcmp(result, template[i].digest,
288 crypto_ahash_digestsize(tfm))) {
289 printk(KERN_ERR "alg: hash: Chunking test %d "
290 "failed for %s\n", j, algo);
291 hexdump(result, crypto_ahash_digestsize(tfm));
301 ahash_request_free(req);
303 testmgr_free_buf(xbuf);
308 static int test_aead(struct crypto_aead *tfm, int enc,
309 struct aead_testvec *template, unsigned int tcount)
311 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
312 unsigned int i, j, k, n, temp;
316 struct aead_request *req;
317 struct scatterlist sg[8];
318 struct scatterlist asg[8];
320 struct tcrypt_result result;
321 unsigned int authsize;
325 char *xbuf[XBUFSIZE];
326 char *axbuf[XBUFSIZE];
328 if (testmgr_alloc_buf(xbuf))
330 if (testmgr_alloc_buf(axbuf))
338 init_completion(&result.completion);
340 req = aead_request_alloc(tfm, GFP_KERNEL);
342 printk(KERN_ERR "alg: aead: Failed to allocate request for "
347 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
348 tcrypt_complete, &result);
350 for (i = 0, j = 0; i < tcount; i++) {
351 if (!template[i].np) {
354 /* some tepmplates have no input data but they will
360 memcpy(input, template[i].input, template[i].ilen);
361 memcpy(assoc, template[i].assoc, template[i].alen);
363 memcpy(iv, template[i].iv, MAX_IVLEN);
365 memset(iv, 0, MAX_IVLEN);
367 crypto_aead_clear_flags(tfm, ~0);
369 crypto_aead_set_flags(
370 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
372 key = template[i].key;
374 ret = crypto_aead_setkey(tfm, key,
376 if (!ret == template[i].fail) {
377 printk(KERN_ERR "alg: aead: setkey failed on "
378 "test %d for %s: flags=%x\n", j, algo,
379 crypto_aead_get_flags(tfm));
384 authsize = abs(template[i].rlen - template[i].ilen);
385 ret = crypto_aead_setauthsize(tfm, authsize);
387 printk(KERN_ERR "alg: aead: Failed to set "
388 "authsize to %u on test %d for %s\n",
393 sg_init_one(&sg[0], input,
394 template[i].ilen + (enc ? authsize : 0));
396 sg_init_one(&asg[0], assoc, template[i].alen);
398 aead_request_set_crypt(req, sg, sg,
399 template[i].ilen, iv);
401 aead_request_set_assoc(req, asg, template[i].alen);
404 crypto_aead_encrypt(req) :
405 crypto_aead_decrypt(req);
409 if (template[i].novrfy) {
410 /* verification was supposed to fail */
411 printk(KERN_ERR "alg: aead: %s failed "
412 "on test %d for %s: ret was 0, "
413 "expected -EBADMSG\n",
415 /* so really, we got a bad message */
422 ret = wait_for_completion_interruptible(
424 if (!ret && !(ret = result.err)) {
425 INIT_COMPLETION(result.completion);
429 if (template[i].novrfy)
430 /* verification failure was expected */
434 printk(KERN_ERR "alg: aead: %s failed on test "
435 "%d for %s: ret=%d\n", e, j, algo, -ret);
440 if (memcmp(q, template[i].result, template[i].rlen)) {
441 printk(KERN_ERR "alg: aead: Test %d failed on "
442 "%s for %s\n", j, e, algo);
443 hexdump(q, template[i].rlen);
450 for (i = 0, j = 0; i < tcount; i++) {
451 if (template[i].np) {
455 memcpy(iv, template[i].iv, MAX_IVLEN);
457 memset(iv, 0, MAX_IVLEN);
459 crypto_aead_clear_flags(tfm, ~0);
461 crypto_aead_set_flags(
462 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
463 key = template[i].key;
465 ret = crypto_aead_setkey(tfm, key, template[i].klen);
466 if (!ret == template[i].fail) {
467 printk(KERN_ERR "alg: aead: setkey failed on "
468 "chunk test %d for %s: flags=%x\n", j,
469 algo, crypto_aead_get_flags(tfm));
474 authsize = abs(template[i].rlen - template[i].ilen);
477 sg_init_table(sg, template[i].np);
478 for (k = 0, temp = 0; k < template[i].np; k++) {
479 if (WARN_ON(offset_in_page(IDX[k]) +
480 template[i].tap[k] > PAGE_SIZE))
483 q = xbuf[IDX[k] >> PAGE_SHIFT] +
484 offset_in_page(IDX[k]);
486 memcpy(q, template[i].input + temp,
489 n = template[i].tap[k];
490 if (k == template[i].np - 1 && enc)
492 if (offset_in_page(q) + n < PAGE_SIZE)
495 sg_set_buf(&sg[k], q, template[i].tap[k]);
496 temp += template[i].tap[k];
499 ret = crypto_aead_setauthsize(tfm, authsize);
501 printk(KERN_ERR "alg: aead: Failed to set "
502 "authsize to %u on chunk test %d for "
503 "%s\n", authsize, j, algo);
508 if (WARN_ON(sg[k - 1].offset +
509 sg[k - 1].length + authsize >
515 sg[k - 1].length += authsize;
518 sg_init_table(asg, template[i].anp);
519 for (k = 0, temp = 0; k < template[i].anp; k++) {
521 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
522 offset_in_page(IDX[k]),
523 template[i].assoc + temp,
524 template[i].atap[k]),
525 template[i].atap[k]);
526 temp += template[i].atap[k];
529 aead_request_set_crypt(req, sg, sg,
533 aead_request_set_assoc(req, asg, template[i].alen);
536 crypto_aead_encrypt(req) :
537 crypto_aead_decrypt(req);
541 if (template[i].novrfy) {
542 /* verification was supposed to fail */
543 printk(KERN_ERR "alg: aead: %s failed "
544 "on chunk test %d for %s: ret "
545 "was 0, expected -EBADMSG\n",
547 /* so really, we got a bad message */
554 ret = wait_for_completion_interruptible(
556 if (!ret && !(ret = result.err)) {
557 INIT_COMPLETION(result.completion);
561 if (template[i].novrfy)
562 /* verification failure was expected */
566 printk(KERN_ERR "alg: aead: %s failed on "
567 "chunk test %d for %s: ret=%d\n", e, j,
573 for (k = 0, temp = 0; k < template[i].np; k++) {
574 q = xbuf[IDX[k] >> PAGE_SHIFT] +
575 offset_in_page(IDX[k]);
577 n = template[i].tap[k];
578 if (k == template[i].np - 1)
579 n += enc ? authsize : -authsize;
581 if (memcmp(q, template[i].result + temp, n)) {
582 printk(KERN_ERR "alg: aead: Chunk "
583 "test %d failed on %s at page "
584 "%u for %s\n", j, e, k, algo);
590 if (k == template[i].np - 1 && !enc) {
591 if (memcmp(q, template[i].input +
597 for (n = 0; offset_in_page(q + n) &&
602 printk(KERN_ERR "alg: aead: Result "
603 "buffer corruption in chunk "
604 "test %d on %s at page %u for "
605 "%s: %u bytes:\n", j, e, k,
611 temp += template[i].tap[k];
619 aead_request_free(req);
620 testmgr_free_buf(axbuf);
622 testmgr_free_buf(xbuf);
627 static int test_cipher(struct crypto_cipher *tfm, int enc,
628 struct cipher_testvec *template, unsigned int tcount)
630 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
631 unsigned int i, j, k;
635 char *xbuf[XBUFSIZE];
638 if (testmgr_alloc_buf(xbuf))
647 for (i = 0; i < tcount; i++) {
654 memcpy(data, template[i].input, template[i].ilen);
656 crypto_cipher_clear_flags(tfm, ~0);
658 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
660 ret = crypto_cipher_setkey(tfm, template[i].key,
662 if (!ret == template[i].fail) {
663 printk(KERN_ERR "alg: cipher: setkey failed "
664 "on test %d for %s: flags=%x\n", j,
665 algo, crypto_cipher_get_flags(tfm));
670 for (k = 0; k < template[i].ilen;
671 k += crypto_cipher_blocksize(tfm)) {
673 crypto_cipher_encrypt_one(tfm, data + k,
676 crypto_cipher_decrypt_one(tfm, data + k,
681 if (memcmp(q, template[i].result, template[i].rlen)) {
682 printk(KERN_ERR "alg: cipher: Test %d failed "
683 "on %s for %s\n", j, e, algo);
684 hexdump(q, template[i].rlen);
693 testmgr_free_buf(xbuf);
698 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
699 struct cipher_testvec *template, unsigned int tcount)
702 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
703 unsigned int i, j, k, n, temp;
705 struct ablkcipher_request *req;
706 struct scatterlist sg[8];
708 struct tcrypt_result result;
711 char *xbuf[XBUFSIZE];
714 if (testmgr_alloc_buf(xbuf))
722 init_completion(&result.completion);
724 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
726 printk(KERN_ERR "alg: skcipher: Failed to allocate request "
731 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
732 tcrypt_complete, &result);
735 for (i = 0; i < tcount; i++) {
737 memcpy(iv, template[i].iv, MAX_IVLEN);
739 memset(iv, 0, MAX_IVLEN);
741 if (!(template[i].np)) {
745 memcpy(data, template[i].input, template[i].ilen);
747 crypto_ablkcipher_clear_flags(tfm, ~0);
749 crypto_ablkcipher_set_flags(
750 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
752 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
754 if (!ret == template[i].fail) {
755 printk(KERN_ERR "alg: skcipher: setkey failed "
756 "on test %d for %s: flags=%x\n", j,
757 algo, crypto_ablkcipher_get_flags(tfm));
762 sg_init_one(&sg[0], data, template[i].ilen);
764 ablkcipher_request_set_crypt(req, sg, sg,
765 template[i].ilen, iv);
767 crypto_ablkcipher_encrypt(req) :
768 crypto_ablkcipher_decrypt(req);
775 ret = wait_for_completion_interruptible(
777 if (!ret && !((ret = result.err))) {
778 INIT_COMPLETION(result.completion);
783 printk(KERN_ERR "alg: skcipher: %s failed on "
784 "test %d for %s: ret=%d\n", e, j, algo,
790 if (memcmp(q, template[i].result, template[i].rlen)) {
791 printk(KERN_ERR "alg: skcipher: Test %d "
792 "failed on %s for %s\n", j, e, algo);
793 hexdump(q, template[i].rlen);
801 for (i = 0; i < tcount; i++) {
804 memcpy(iv, template[i].iv, MAX_IVLEN);
806 memset(iv, 0, MAX_IVLEN);
808 if (template[i].np) {
811 crypto_ablkcipher_clear_flags(tfm, ~0);
813 crypto_ablkcipher_set_flags(
814 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
816 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
818 if (!ret == template[i].fail) {
819 printk(KERN_ERR "alg: skcipher: setkey failed "
820 "on chunk test %d for %s: flags=%x\n",
822 crypto_ablkcipher_get_flags(tfm));
829 sg_init_table(sg, template[i].np);
830 for (k = 0; k < template[i].np; k++) {
831 if (WARN_ON(offset_in_page(IDX[k]) +
832 template[i].tap[k] > PAGE_SIZE))
835 q = xbuf[IDX[k] >> PAGE_SHIFT] +
836 offset_in_page(IDX[k]);
838 memcpy(q, template[i].input + temp,
841 if (offset_in_page(q) + template[i].tap[k] <
843 q[template[i].tap[k]] = 0;
845 sg_set_buf(&sg[k], q, template[i].tap[k]);
847 temp += template[i].tap[k];
850 ablkcipher_request_set_crypt(req, sg, sg,
851 template[i].ilen, iv);
854 crypto_ablkcipher_encrypt(req) :
855 crypto_ablkcipher_decrypt(req);
862 ret = wait_for_completion_interruptible(
864 if (!ret && !((ret = result.err))) {
865 INIT_COMPLETION(result.completion);
870 printk(KERN_ERR "alg: skcipher: %s failed on "
871 "chunk test %d for %s: ret=%d\n", e, j,
878 for (k = 0; k < template[i].np; k++) {
879 q = xbuf[IDX[k] >> PAGE_SHIFT] +
880 offset_in_page(IDX[k]);
882 if (memcmp(q, template[i].result + temp,
883 template[i].tap[k])) {
884 printk(KERN_ERR "alg: skcipher: Chunk "
885 "test %d failed on %s at page "
886 "%u for %s\n", j, e, k, algo);
887 hexdump(q, template[i].tap[k]);
891 q += template[i].tap[k];
892 for (n = 0; offset_in_page(q + n) && q[n]; n++)
895 printk(KERN_ERR "alg: skcipher: "
896 "Result buffer corruption in "
897 "chunk test %d on %s at page "
898 "%u for %s: %u bytes:\n", j, e,
903 temp += template[i].tap[k];
911 ablkcipher_request_free(req);
912 testmgr_free_buf(xbuf);
917 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
918 struct comp_testvec *dtemplate, int ctcount, int dtcount)
920 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
922 char result[COMP_BUF_SIZE];
925 for (i = 0; i < ctcount; i++) {
927 unsigned int dlen = COMP_BUF_SIZE;
929 memset(result, 0, sizeof (result));
931 ilen = ctemplate[i].inlen;
932 ret = crypto_comp_compress(tfm, ctemplate[i].input,
933 ilen, result, &dlen);
935 printk(KERN_ERR "alg: comp: compression failed "
936 "on test %d for %s: ret=%d\n", i + 1, algo,
941 if (dlen != ctemplate[i].outlen) {
942 printk(KERN_ERR "alg: comp: Compression test %d "
943 "failed for %s: output len = %d\n", i + 1, algo,
949 if (memcmp(result, ctemplate[i].output, dlen)) {
950 printk(KERN_ERR "alg: comp: Compression test %d "
951 "failed for %s\n", i + 1, algo);
952 hexdump(result, dlen);
958 for (i = 0; i < dtcount; i++) {
960 unsigned int dlen = COMP_BUF_SIZE;
962 memset(result, 0, sizeof (result));
964 ilen = dtemplate[i].inlen;
965 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
966 ilen, result, &dlen);
968 printk(KERN_ERR "alg: comp: decompression failed "
969 "on test %d for %s: ret=%d\n", i + 1, algo,
974 if (dlen != dtemplate[i].outlen) {
975 printk(KERN_ERR "alg: comp: Decompression test %d "
976 "failed for %s: output len = %d\n", i + 1, algo,
982 if (memcmp(result, dtemplate[i].output, dlen)) {
983 printk(KERN_ERR "alg: comp: Decompression test %d "
984 "failed for %s\n", i + 1, algo);
985 hexdump(result, dlen);
997 static int test_pcomp(struct crypto_pcomp *tfm,
998 struct pcomp_testvec *ctemplate,
999 struct pcomp_testvec *dtemplate, int ctcount,
1002 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1004 char result[COMP_BUF_SIZE];
1007 for (i = 0; i < ctcount; i++) {
1008 struct comp_request req;
1010 error = crypto_compress_setup(tfm, ctemplate[i].params,
1011 ctemplate[i].paramsize);
1013 pr_err("alg: pcomp: compression setup failed on test "
1014 "%d for %s: error=%d\n", i + 1, algo, error);
1018 error = crypto_compress_init(tfm);
1020 pr_err("alg: pcomp: compression init failed on test "
1021 "%d for %s: error=%d\n", i + 1, algo, error);
1025 memset(result, 0, sizeof(result));
1027 req.next_in = ctemplate[i].input;
1028 req.avail_in = ctemplate[i].inlen / 2;
1029 req.next_out = result;
1030 req.avail_out = ctemplate[i].outlen / 2;
1032 error = crypto_compress_update(tfm, &req);
1033 if (error && (error != -EAGAIN || req.avail_in)) {
1034 pr_err("alg: pcomp: compression update failed on test "
1035 "%d for %s: error=%d\n", i + 1, algo, error);
1039 /* Add remaining input data */
1040 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1042 error = crypto_compress_update(tfm, &req);
1043 if (error && (error != -EAGAIN || req.avail_in)) {
1044 pr_err("alg: pcomp: compression update failed on test "
1045 "%d for %s: error=%d\n", i + 1, algo, error);
1049 /* Provide remaining output space */
1050 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1052 error = crypto_compress_final(tfm, &req);
1054 pr_err("alg: pcomp: compression final failed on test "
1055 "%d for %s: error=%d\n", i + 1, algo, error);
1059 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1060 pr_err("alg: comp: Compression test %d failed for %s: "
1061 "output len = %d (expected %d)\n", i + 1, algo,
1062 COMP_BUF_SIZE - req.avail_out,
1063 ctemplate[i].outlen);
1067 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1068 pr_err("alg: pcomp: Compression test %d failed for "
1069 "%s\n", i + 1, algo);
1070 hexdump(result, ctemplate[i].outlen);
1075 for (i = 0; i < dtcount; i++) {
1076 struct comp_request req;
1078 error = crypto_decompress_setup(tfm, dtemplate[i].params,
1079 dtemplate[i].paramsize);
1081 pr_err("alg: pcomp: decompression setup failed on "
1082 "test %d for %s: error=%d\n", i + 1, algo,
1087 error = crypto_decompress_init(tfm);
1089 pr_err("alg: pcomp: decompression init failed on test "
1090 "%d for %s: error=%d\n", i + 1, algo, error);
1094 memset(result, 0, sizeof(result));
1096 req.next_in = dtemplate[i].input;
1097 req.avail_in = dtemplate[i].inlen / 2;
1098 req.next_out = result;
1099 req.avail_out = dtemplate[i].outlen / 2;
1101 error = crypto_decompress_update(tfm, &req);
1102 if (error && (error != -EAGAIN || req.avail_in)) {
1103 pr_err("alg: pcomp: decompression update failed on "
1104 "test %d for %s: error=%d\n", i + 1, algo,
1109 /* Add remaining input data */
1110 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1112 error = crypto_decompress_update(tfm, &req);
1113 if (error && (error != -EAGAIN || req.avail_in)) {
1114 pr_err("alg: pcomp: decompression update failed on "
1115 "test %d for %s: error=%d\n", i + 1, algo,
1120 /* Provide remaining output space */
1121 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1123 error = crypto_decompress_final(tfm, &req);
1124 if (error && (error != -EAGAIN || req.avail_in)) {
1125 pr_err("alg: pcomp: decompression final failed on "
1126 "test %d for %s: error=%d\n", i + 1, algo,
1131 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1132 pr_err("alg: comp: Decompression test %d failed for "
1133 "%s: output len = %d (expected %d)\n", i + 1,
1134 algo, COMP_BUF_SIZE - req.avail_out,
1135 dtemplate[i].outlen);
1139 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1140 pr_err("alg: pcomp: Decompression test %d failed for "
1141 "%s\n", i + 1, algo);
1142 hexdump(result, dtemplate[i].outlen);
1151 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1152 unsigned int tcount)
1154 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1155 int err, i, j, seedsize;
1159 seedsize = crypto_rng_seedsize(tfm);
1161 seed = kmalloc(seedsize, GFP_KERNEL);
1163 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1168 for (i = 0; i < tcount; i++) {
1169 memset(result, 0, 32);
1171 memcpy(seed, template[i].v, template[i].vlen);
1172 memcpy(seed + template[i].vlen, template[i].key,
1174 memcpy(seed + template[i].vlen + template[i].klen,
1175 template[i].dt, template[i].dtlen);
1177 err = crypto_rng_reset(tfm, seed, seedsize);
1179 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1184 for (j = 0; j < template[i].loops; j++) {
1185 err = crypto_rng_get_bytes(tfm, result,
1187 if (err != template[i].rlen) {
1188 printk(KERN_ERR "alg: cprng: Failed to obtain "
1189 "the correct amount of random data for "
1190 "%s (requested %d, got %d)\n", algo,
1191 template[i].rlen, err);
1196 err = memcmp(result, template[i].result,
1199 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1201 hexdump(result, template[i].rlen);
1212 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1215 struct crypto_aead *tfm;
1218 tfm = crypto_alloc_aead(driver, type, mask);
1220 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1221 "%ld\n", driver, PTR_ERR(tfm));
1222 return PTR_ERR(tfm);
1225 if (desc->suite.aead.enc.vecs) {
1226 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1227 desc->suite.aead.enc.count);
1232 if (!err && desc->suite.aead.dec.vecs)
1233 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1234 desc->suite.aead.dec.count);
1237 crypto_free_aead(tfm);
1241 static int alg_test_cipher(const struct alg_test_desc *desc,
1242 const char *driver, u32 type, u32 mask)
1244 struct crypto_cipher *tfm;
1247 tfm = crypto_alloc_cipher(driver, type, mask);
1249 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1250 "%s: %ld\n", driver, PTR_ERR(tfm));
1251 return PTR_ERR(tfm);
1254 if (desc->suite.cipher.enc.vecs) {
1255 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1256 desc->suite.cipher.enc.count);
1261 if (desc->suite.cipher.dec.vecs)
1262 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1263 desc->suite.cipher.dec.count);
1266 crypto_free_cipher(tfm);
1270 static int alg_test_skcipher(const struct alg_test_desc *desc,
1271 const char *driver, u32 type, u32 mask)
1273 struct crypto_ablkcipher *tfm;
1276 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1278 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1279 "%s: %ld\n", driver, PTR_ERR(tfm));
1280 return PTR_ERR(tfm);
1283 if (desc->suite.cipher.enc.vecs) {
1284 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1285 desc->suite.cipher.enc.count);
1290 if (desc->suite.cipher.dec.vecs)
1291 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1292 desc->suite.cipher.dec.count);
1295 crypto_free_ablkcipher(tfm);
1299 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1302 struct crypto_comp *tfm;
1305 tfm = crypto_alloc_comp(driver, type, mask);
1307 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1308 "%ld\n", driver, PTR_ERR(tfm));
1309 return PTR_ERR(tfm);
1312 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1313 desc->suite.comp.decomp.vecs,
1314 desc->suite.comp.comp.count,
1315 desc->suite.comp.decomp.count);
1317 crypto_free_comp(tfm);
1321 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1324 struct crypto_pcomp *tfm;
1327 tfm = crypto_alloc_pcomp(driver, type, mask);
1329 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1330 driver, PTR_ERR(tfm));
1331 return PTR_ERR(tfm);
1334 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1335 desc->suite.pcomp.decomp.vecs,
1336 desc->suite.pcomp.comp.count,
1337 desc->suite.pcomp.decomp.count);
1339 crypto_free_pcomp(tfm);
1343 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1346 struct crypto_ahash *tfm;
1349 tfm = crypto_alloc_ahash(driver, type, mask);
1351 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1352 "%ld\n", driver, PTR_ERR(tfm));
1353 return PTR_ERR(tfm);
1356 err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
1358 crypto_free_ahash(tfm);
1362 static int alg_test_crc32c(const struct alg_test_desc *desc,
1363 const char *driver, u32 type, u32 mask)
1365 struct crypto_shash *tfm;
1369 err = alg_test_hash(desc, driver, type, mask);
1373 tfm = crypto_alloc_shash(driver, type, mask);
1375 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1376 "%ld\n", driver, PTR_ERR(tfm));
1383 struct shash_desc shash;
1384 char ctx[crypto_shash_descsize(tfm)];
1387 sdesc.shash.tfm = tfm;
1388 sdesc.shash.flags = 0;
1390 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1391 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1393 printk(KERN_ERR "alg: crc32c: Operation failed for "
1394 "%s: %d\n", driver, err);
1398 if (val != ~420553207) {
1399 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1400 "%d\n", driver, val);
1405 crypto_free_shash(tfm);
1411 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1414 struct crypto_rng *rng;
1417 rng = crypto_alloc_rng(driver, type, mask);
1419 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1420 "%ld\n", driver, PTR_ERR(rng));
1421 return PTR_ERR(rng);
1424 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1426 crypto_free_rng(rng);
1431 /* Please keep this list sorted by algorithm name. */
1432 static const struct alg_test_desc alg_test_descs[] = {
1434 .alg = "ansi_cprng",
1435 .test = alg_test_cprng,
1439 .vecs = ansi_cprng_aes_tv_template,
1440 .count = ANSI_CPRNG_AES_TEST_VECTORS
1445 .test = alg_test_skcipher,
1450 .vecs = aes_cbc_enc_tv_template,
1451 .count = AES_CBC_ENC_TEST_VECTORS
1454 .vecs = aes_cbc_dec_tv_template,
1455 .count = AES_CBC_DEC_TEST_VECTORS
1460 .alg = "cbc(anubis)",
1461 .test = alg_test_skcipher,
1465 .vecs = anubis_cbc_enc_tv_template,
1466 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1469 .vecs = anubis_cbc_dec_tv_template,
1470 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1475 .alg = "cbc(blowfish)",
1476 .test = alg_test_skcipher,
1480 .vecs = bf_cbc_enc_tv_template,
1481 .count = BF_CBC_ENC_TEST_VECTORS
1484 .vecs = bf_cbc_dec_tv_template,
1485 .count = BF_CBC_DEC_TEST_VECTORS
1490 .alg = "cbc(camellia)",
1491 .test = alg_test_skcipher,
1495 .vecs = camellia_cbc_enc_tv_template,
1496 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1499 .vecs = camellia_cbc_dec_tv_template,
1500 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1506 .test = alg_test_skcipher,
1510 .vecs = des_cbc_enc_tv_template,
1511 .count = DES_CBC_ENC_TEST_VECTORS
1514 .vecs = des_cbc_dec_tv_template,
1515 .count = DES_CBC_DEC_TEST_VECTORS
1520 .alg = "cbc(des3_ede)",
1521 .test = alg_test_skcipher,
1526 .vecs = des3_ede_cbc_enc_tv_template,
1527 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1530 .vecs = des3_ede_cbc_dec_tv_template,
1531 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1536 .alg = "cbc(twofish)",
1537 .test = alg_test_skcipher,
1541 .vecs = tf_cbc_enc_tv_template,
1542 .count = TF_CBC_ENC_TEST_VECTORS
1545 .vecs = tf_cbc_dec_tv_template,
1546 .count = TF_CBC_DEC_TEST_VECTORS
1552 .test = alg_test_aead,
1557 .vecs = aes_ccm_enc_tv_template,
1558 .count = AES_CCM_ENC_TEST_VECTORS
1561 .vecs = aes_ccm_dec_tv_template,
1562 .count = AES_CCM_DEC_TEST_VECTORS
1568 .test = alg_test_crc32c,
1572 .vecs = crc32c_tv_template,
1573 .count = CRC32C_TEST_VECTORS
1578 .test = alg_test_skcipher,
1583 .vecs = aes_ctr_enc_tv_template,
1584 .count = AES_CTR_ENC_TEST_VECTORS
1587 .vecs = aes_ctr_dec_tv_template,
1588 .count = AES_CTR_DEC_TEST_VECTORS
1593 .alg = "cts(cbc(aes))",
1594 .test = alg_test_skcipher,
1598 .vecs = cts_mode_enc_tv_template,
1599 .count = CTS_MODE_ENC_TEST_VECTORS
1602 .vecs = cts_mode_dec_tv_template,
1603 .count = CTS_MODE_DEC_TEST_VECTORS
1609 .test = alg_test_comp,
1613 .vecs = deflate_comp_tv_template,
1614 .count = DEFLATE_COMP_TEST_VECTORS
1617 .vecs = deflate_decomp_tv_template,
1618 .count = DEFLATE_DECOMP_TEST_VECTORS
1624 .test = alg_test_skcipher,
1629 .vecs = aes_enc_tv_template,
1630 .count = AES_ENC_TEST_VECTORS
1633 .vecs = aes_dec_tv_template,
1634 .count = AES_DEC_TEST_VECTORS
1639 .alg = "ecb(anubis)",
1640 .test = alg_test_skcipher,
1644 .vecs = anubis_enc_tv_template,
1645 .count = ANUBIS_ENC_TEST_VECTORS
1648 .vecs = anubis_dec_tv_template,
1649 .count = ANUBIS_DEC_TEST_VECTORS
1655 .test = alg_test_skcipher,
1659 .vecs = arc4_enc_tv_template,
1660 .count = ARC4_ENC_TEST_VECTORS
1663 .vecs = arc4_dec_tv_template,
1664 .count = ARC4_DEC_TEST_VECTORS
1669 .alg = "ecb(blowfish)",
1670 .test = alg_test_skcipher,
1674 .vecs = bf_enc_tv_template,
1675 .count = BF_ENC_TEST_VECTORS
1678 .vecs = bf_dec_tv_template,
1679 .count = BF_DEC_TEST_VECTORS
1684 .alg = "ecb(camellia)",
1685 .test = alg_test_skcipher,
1689 .vecs = camellia_enc_tv_template,
1690 .count = CAMELLIA_ENC_TEST_VECTORS
1693 .vecs = camellia_dec_tv_template,
1694 .count = CAMELLIA_DEC_TEST_VECTORS
1699 .alg = "ecb(cast5)",
1700 .test = alg_test_skcipher,
1704 .vecs = cast5_enc_tv_template,
1705 .count = CAST5_ENC_TEST_VECTORS
1708 .vecs = cast5_dec_tv_template,
1709 .count = CAST5_DEC_TEST_VECTORS
1714 .alg = "ecb(cast6)",
1715 .test = alg_test_skcipher,
1719 .vecs = cast6_enc_tv_template,
1720 .count = CAST6_ENC_TEST_VECTORS
1723 .vecs = cast6_dec_tv_template,
1724 .count = CAST6_DEC_TEST_VECTORS
1730 .test = alg_test_skcipher,
1735 .vecs = des_enc_tv_template,
1736 .count = DES_ENC_TEST_VECTORS
1739 .vecs = des_dec_tv_template,
1740 .count = DES_DEC_TEST_VECTORS
1745 .alg = "ecb(des3_ede)",
1746 .test = alg_test_skcipher,
1751 .vecs = des3_ede_enc_tv_template,
1752 .count = DES3_EDE_ENC_TEST_VECTORS
1755 .vecs = des3_ede_dec_tv_template,
1756 .count = DES3_EDE_DEC_TEST_VECTORS
1761 .alg = "ecb(khazad)",
1762 .test = alg_test_skcipher,
1766 .vecs = khazad_enc_tv_template,
1767 .count = KHAZAD_ENC_TEST_VECTORS
1770 .vecs = khazad_dec_tv_template,
1771 .count = KHAZAD_DEC_TEST_VECTORS
1777 .test = alg_test_skcipher,
1781 .vecs = seed_enc_tv_template,
1782 .count = SEED_ENC_TEST_VECTORS
1785 .vecs = seed_dec_tv_template,
1786 .count = SEED_DEC_TEST_VECTORS
1791 .alg = "ecb(serpent)",
1792 .test = alg_test_skcipher,
1796 .vecs = serpent_enc_tv_template,
1797 .count = SERPENT_ENC_TEST_VECTORS
1800 .vecs = serpent_dec_tv_template,
1801 .count = SERPENT_DEC_TEST_VECTORS
1807 .test = alg_test_skcipher,
1811 .vecs = tea_enc_tv_template,
1812 .count = TEA_ENC_TEST_VECTORS
1815 .vecs = tea_dec_tv_template,
1816 .count = TEA_DEC_TEST_VECTORS
1821 .alg = "ecb(tnepres)",
1822 .test = alg_test_skcipher,
1826 .vecs = tnepres_enc_tv_template,
1827 .count = TNEPRES_ENC_TEST_VECTORS
1830 .vecs = tnepres_dec_tv_template,
1831 .count = TNEPRES_DEC_TEST_VECTORS
1836 .alg = "ecb(twofish)",
1837 .test = alg_test_skcipher,
1841 .vecs = tf_enc_tv_template,
1842 .count = TF_ENC_TEST_VECTORS
1845 .vecs = tf_dec_tv_template,
1846 .count = TF_DEC_TEST_VECTORS
1852 .test = alg_test_skcipher,
1856 .vecs = xeta_enc_tv_template,
1857 .count = XETA_ENC_TEST_VECTORS
1860 .vecs = xeta_dec_tv_template,
1861 .count = XETA_DEC_TEST_VECTORS
1867 .test = alg_test_skcipher,
1871 .vecs = xtea_enc_tv_template,
1872 .count = XTEA_ENC_TEST_VECTORS
1875 .vecs = xtea_dec_tv_template,
1876 .count = XTEA_DEC_TEST_VECTORS
1882 .test = alg_test_aead,
1887 .vecs = aes_gcm_enc_tv_template,
1888 .count = AES_GCM_ENC_TEST_VECTORS
1891 .vecs = aes_gcm_dec_tv_template,
1892 .count = AES_GCM_DEC_TEST_VECTORS
1898 .test = alg_test_hash,
1901 .vecs = hmac_md5_tv_template,
1902 .count = HMAC_MD5_TEST_VECTORS
1906 .alg = "hmac(rmd128)",
1907 .test = alg_test_hash,
1910 .vecs = hmac_rmd128_tv_template,
1911 .count = HMAC_RMD128_TEST_VECTORS
1915 .alg = "hmac(rmd160)",
1916 .test = alg_test_hash,
1919 .vecs = hmac_rmd160_tv_template,
1920 .count = HMAC_RMD160_TEST_VECTORS
1924 .alg = "hmac(sha1)",
1925 .test = alg_test_hash,
1929 .vecs = hmac_sha1_tv_template,
1930 .count = HMAC_SHA1_TEST_VECTORS
1934 .alg = "hmac(sha224)",
1935 .test = alg_test_hash,
1939 .vecs = hmac_sha224_tv_template,
1940 .count = HMAC_SHA224_TEST_VECTORS
1944 .alg = "hmac(sha256)",
1945 .test = alg_test_hash,
1949 .vecs = hmac_sha256_tv_template,
1950 .count = HMAC_SHA256_TEST_VECTORS
1954 .alg = "hmac(sha384)",
1955 .test = alg_test_hash,
1959 .vecs = hmac_sha384_tv_template,
1960 .count = HMAC_SHA384_TEST_VECTORS
1964 .alg = "hmac(sha512)",
1965 .test = alg_test_hash,
1969 .vecs = hmac_sha512_tv_template,
1970 .count = HMAC_SHA512_TEST_VECTORS
1975 .test = alg_test_skcipher,
1979 .vecs = aes_lrw_enc_tv_template,
1980 .count = AES_LRW_ENC_TEST_VECTORS
1983 .vecs = aes_lrw_dec_tv_template,
1984 .count = AES_LRW_DEC_TEST_VECTORS
1990 .test = alg_test_comp,
1994 .vecs = lzo_comp_tv_template,
1995 .count = LZO_COMP_TEST_VECTORS
1998 .vecs = lzo_decomp_tv_template,
1999 .count = LZO_DECOMP_TEST_VECTORS
2005 .test = alg_test_hash,
2008 .vecs = md4_tv_template,
2009 .count = MD4_TEST_VECTORS
2014 .test = alg_test_hash,
2017 .vecs = md5_tv_template,
2018 .count = MD5_TEST_VECTORS
2022 .alg = "michael_mic",
2023 .test = alg_test_hash,
2026 .vecs = michael_mic_tv_template,
2027 .count = MICHAEL_MIC_TEST_VECTORS
2031 .alg = "pcbc(fcrypt)",
2032 .test = alg_test_skcipher,
2036 .vecs = fcrypt_pcbc_enc_tv_template,
2037 .count = FCRYPT_ENC_TEST_VECTORS
2040 .vecs = fcrypt_pcbc_dec_tv_template,
2041 .count = FCRYPT_DEC_TEST_VECTORS
2046 .alg = "rfc3686(ctr(aes))",
2047 .test = alg_test_skcipher,
2052 .vecs = aes_ctr_rfc3686_enc_tv_template,
2053 .count = AES_CTR_3686_ENC_TEST_VECTORS
2056 .vecs = aes_ctr_rfc3686_dec_tv_template,
2057 .count = AES_CTR_3686_DEC_TEST_VECTORS
2062 .alg = "rfc4309(ccm(aes))",
2063 .test = alg_test_aead,
2068 .vecs = aes_ccm_rfc4309_enc_tv_template,
2069 .count = AES_CCM_4309_ENC_TEST_VECTORS
2072 .vecs = aes_ccm_rfc4309_dec_tv_template,
2073 .count = AES_CCM_4309_DEC_TEST_VECTORS
2079 .test = alg_test_hash,
2082 .vecs = rmd128_tv_template,
2083 .count = RMD128_TEST_VECTORS
2088 .test = alg_test_hash,
2091 .vecs = rmd160_tv_template,
2092 .count = RMD160_TEST_VECTORS
2097 .test = alg_test_hash,
2100 .vecs = rmd256_tv_template,
2101 .count = RMD256_TEST_VECTORS
2106 .test = alg_test_hash,
2109 .vecs = rmd320_tv_template,
2110 .count = RMD320_TEST_VECTORS
2115 .test = alg_test_skcipher,
2119 .vecs = salsa20_stream_enc_tv_template,
2120 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2126 .test = alg_test_hash,
2130 .vecs = sha1_tv_template,
2131 .count = SHA1_TEST_VECTORS
2136 .test = alg_test_hash,
2140 .vecs = sha224_tv_template,
2141 .count = SHA224_TEST_VECTORS
2146 .test = alg_test_hash,
2150 .vecs = sha256_tv_template,
2151 .count = SHA256_TEST_VECTORS
2156 .test = alg_test_hash,
2160 .vecs = sha384_tv_template,
2161 .count = SHA384_TEST_VECTORS
2166 .test = alg_test_hash,
2170 .vecs = sha512_tv_template,
2171 .count = SHA512_TEST_VECTORS
2176 .test = alg_test_hash,
2179 .vecs = tgr128_tv_template,
2180 .count = TGR128_TEST_VECTORS
2185 .test = alg_test_hash,
2188 .vecs = tgr160_tv_template,
2189 .count = TGR160_TEST_VECTORS
2194 .test = alg_test_hash,
2197 .vecs = tgr192_tv_template,
2198 .count = TGR192_TEST_VECTORS
2203 .test = alg_test_hash,
2206 .vecs = wp256_tv_template,
2207 .count = WP256_TEST_VECTORS
2212 .test = alg_test_hash,
2215 .vecs = wp384_tv_template,
2216 .count = WP384_TEST_VECTORS
2221 .test = alg_test_hash,
2224 .vecs = wp512_tv_template,
2225 .count = WP512_TEST_VECTORS
2230 .test = alg_test_hash,
2233 .vecs = aes_xcbc128_tv_template,
2234 .count = XCBC_AES_TEST_VECTORS
2239 .test = alg_test_skcipher,
2243 .vecs = aes_xts_enc_tv_template,
2244 .count = AES_XTS_ENC_TEST_VECTORS
2247 .vecs = aes_xts_dec_tv_template,
2248 .count = AES_XTS_DEC_TEST_VECTORS
2254 .test = alg_test_pcomp,
2258 .vecs = zlib_comp_tv_template,
2259 .count = ZLIB_COMP_TEST_VECTORS
2262 .vecs = zlib_decomp_tv_template,
2263 .count = ZLIB_DECOMP_TEST_VECTORS
2270 static int alg_find_test(const char *alg)
2273 int end = ARRAY_SIZE(alg_test_descs);
2275 while (start < end) {
2276 int i = (start + end) / 2;
2277 int diff = strcmp(alg_test_descs[i].alg, alg);
2295 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2300 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
2301 char nalg[CRYPTO_MAX_ALG_NAME];
2303 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
2305 return -ENAMETOOLONG;
2307 i = alg_find_test(nalg);
2311 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2314 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2318 i = alg_find_test(alg);
2322 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2325 rc = alg_test_descs[i].test(alg_test_descs + i, driver,
2328 if (fips_enabled && rc)
2329 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2331 if (fips_enabled && !rc)
2332 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2338 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2343 EXPORT_SYMBOL_GPL(alg_test);