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;
1009 unsigned int produced = 0;
1011 res = crypto_compress_setup(tfm, ctemplate[i].params,
1012 ctemplate[i].paramsize);
1014 pr_err("alg: pcomp: compression setup failed on test "
1015 "%d for %s: error=%d\n", i + 1, algo, res);
1019 res = crypto_compress_init(tfm);
1021 pr_err("alg: pcomp: compression init failed on test "
1022 "%d for %s: error=%d\n", i + 1, algo, res);
1026 memset(result, 0, sizeof(result));
1028 req.next_in = ctemplate[i].input;
1029 req.avail_in = ctemplate[i].inlen / 2;
1030 req.next_out = result;
1031 req.avail_out = ctemplate[i].outlen / 2;
1033 res = crypto_compress_update(tfm, &req);
1034 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1035 pr_err("alg: pcomp: compression update failed on test "
1036 "%d for %s: error=%d\n", i + 1, algo, res);
1042 /* Add remaining input data */
1043 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1045 res = crypto_compress_update(tfm, &req);
1046 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1047 pr_err("alg: pcomp: compression update failed on test "
1048 "%d for %s: error=%d\n", i + 1, algo, res);
1054 /* Provide remaining output space */
1055 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1057 res = crypto_compress_final(tfm, &req);
1059 pr_err("alg: pcomp: compression final failed on test "
1060 "%d for %s: error=%d\n", i + 1, algo, res);
1065 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1066 pr_err("alg: comp: Compression test %d failed for %s: "
1067 "output len = %d (expected %d)\n", i + 1, algo,
1068 COMP_BUF_SIZE - req.avail_out,
1069 ctemplate[i].outlen);
1073 if (produced != ctemplate[i].outlen) {
1074 pr_err("alg: comp: Compression test %d failed for %s: "
1075 "returned len = %u (expected %d)\n", i + 1,
1076 algo, produced, ctemplate[i].outlen);
1080 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1081 pr_err("alg: pcomp: Compression test %d failed for "
1082 "%s\n", i + 1, algo);
1083 hexdump(result, ctemplate[i].outlen);
1088 for (i = 0; i < dtcount; i++) {
1089 struct comp_request req;
1090 unsigned int produced = 0;
1092 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1093 dtemplate[i].paramsize);
1095 pr_err("alg: pcomp: decompression setup failed on "
1096 "test %d for %s: error=%d\n", i + 1, algo, res);
1100 res = crypto_decompress_init(tfm);
1102 pr_err("alg: pcomp: decompression init failed on test "
1103 "%d for %s: error=%d\n", i + 1, algo, res);
1107 memset(result, 0, sizeof(result));
1109 req.next_in = dtemplate[i].input;
1110 req.avail_in = dtemplate[i].inlen / 2;
1111 req.next_out = result;
1112 req.avail_out = dtemplate[i].outlen / 2;
1114 res = crypto_decompress_update(tfm, &req);
1115 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1116 pr_err("alg: pcomp: decompression update failed on "
1117 "test %d for %s: error=%d\n", i + 1, algo, res);
1123 /* Add remaining input data */
1124 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1126 res = crypto_decompress_update(tfm, &req);
1127 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1128 pr_err("alg: pcomp: decompression update failed on "
1129 "test %d for %s: error=%d\n", i + 1, algo, res);
1135 /* Provide remaining output space */
1136 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1138 res = crypto_decompress_final(tfm, &req);
1139 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1140 pr_err("alg: pcomp: decompression final failed on "
1141 "test %d for %s: error=%d\n", i + 1, algo, res);
1147 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1148 pr_err("alg: comp: Decompression test %d failed for "
1149 "%s: output len = %d (expected %d)\n", i + 1,
1150 algo, COMP_BUF_SIZE - req.avail_out,
1151 dtemplate[i].outlen);
1155 if (produced != dtemplate[i].outlen) {
1156 pr_err("alg: comp: Decompression test %d failed for "
1157 "%s: returned len = %u (expected %d)\n", i + 1,
1158 algo, produced, dtemplate[i].outlen);
1162 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1163 pr_err("alg: pcomp: Decompression test %d failed for "
1164 "%s\n", i + 1, algo);
1165 hexdump(result, dtemplate[i].outlen);
1174 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1175 unsigned int tcount)
1177 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1178 int err, i, j, seedsize;
1182 seedsize = crypto_rng_seedsize(tfm);
1184 seed = kmalloc(seedsize, GFP_KERNEL);
1186 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1191 for (i = 0; i < tcount; i++) {
1192 memset(result, 0, 32);
1194 memcpy(seed, template[i].v, template[i].vlen);
1195 memcpy(seed + template[i].vlen, template[i].key,
1197 memcpy(seed + template[i].vlen + template[i].klen,
1198 template[i].dt, template[i].dtlen);
1200 err = crypto_rng_reset(tfm, seed, seedsize);
1202 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1207 for (j = 0; j < template[i].loops; j++) {
1208 err = crypto_rng_get_bytes(tfm, result,
1210 if (err != template[i].rlen) {
1211 printk(KERN_ERR "alg: cprng: Failed to obtain "
1212 "the correct amount of random data for "
1213 "%s (requested %d, got %d)\n", algo,
1214 template[i].rlen, err);
1219 err = memcmp(result, template[i].result,
1222 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1224 hexdump(result, template[i].rlen);
1235 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1238 struct crypto_aead *tfm;
1241 tfm = crypto_alloc_aead(driver, type, mask);
1243 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1244 "%ld\n", driver, PTR_ERR(tfm));
1245 return PTR_ERR(tfm);
1248 if (desc->suite.aead.enc.vecs) {
1249 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1250 desc->suite.aead.enc.count);
1255 if (!err && desc->suite.aead.dec.vecs)
1256 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1257 desc->suite.aead.dec.count);
1260 crypto_free_aead(tfm);
1264 static int alg_test_cipher(const struct alg_test_desc *desc,
1265 const char *driver, u32 type, u32 mask)
1267 struct crypto_cipher *tfm;
1270 tfm = crypto_alloc_cipher(driver, type, mask);
1272 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1273 "%s: %ld\n", driver, PTR_ERR(tfm));
1274 return PTR_ERR(tfm);
1277 if (desc->suite.cipher.enc.vecs) {
1278 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1279 desc->suite.cipher.enc.count);
1284 if (desc->suite.cipher.dec.vecs)
1285 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1286 desc->suite.cipher.dec.count);
1289 crypto_free_cipher(tfm);
1293 static int alg_test_skcipher(const struct alg_test_desc *desc,
1294 const char *driver, u32 type, u32 mask)
1296 struct crypto_ablkcipher *tfm;
1299 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1301 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1302 "%s: %ld\n", driver, PTR_ERR(tfm));
1303 return PTR_ERR(tfm);
1306 if (desc->suite.cipher.enc.vecs) {
1307 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1308 desc->suite.cipher.enc.count);
1313 if (desc->suite.cipher.dec.vecs)
1314 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1315 desc->suite.cipher.dec.count);
1318 crypto_free_ablkcipher(tfm);
1322 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1325 struct crypto_comp *tfm;
1328 tfm = crypto_alloc_comp(driver, type, mask);
1330 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1331 "%ld\n", driver, PTR_ERR(tfm));
1332 return PTR_ERR(tfm);
1335 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1336 desc->suite.comp.decomp.vecs,
1337 desc->suite.comp.comp.count,
1338 desc->suite.comp.decomp.count);
1340 crypto_free_comp(tfm);
1344 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1347 struct crypto_pcomp *tfm;
1350 tfm = crypto_alloc_pcomp(driver, type, mask);
1352 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1353 driver, PTR_ERR(tfm));
1354 return PTR_ERR(tfm);
1357 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1358 desc->suite.pcomp.decomp.vecs,
1359 desc->suite.pcomp.comp.count,
1360 desc->suite.pcomp.decomp.count);
1362 crypto_free_pcomp(tfm);
1366 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1369 struct crypto_ahash *tfm;
1372 tfm = crypto_alloc_ahash(driver, type, mask);
1374 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1375 "%ld\n", driver, PTR_ERR(tfm));
1376 return PTR_ERR(tfm);
1379 err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
1381 crypto_free_ahash(tfm);
1385 static int alg_test_crc32c(const struct alg_test_desc *desc,
1386 const char *driver, u32 type, u32 mask)
1388 struct crypto_shash *tfm;
1392 err = alg_test_hash(desc, driver, type, mask);
1396 tfm = crypto_alloc_shash(driver, type, mask);
1398 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1399 "%ld\n", driver, PTR_ERR(tfm));
1406 struct shash_desc shash;
1407 char ctx[crypto_shash_descsize(tfm)];
1410 sdesc.shash.tfm = tfm;
1411 sdesc.shash.flags = 0;
1413 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1414 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1416 printk(KERN_ERR "alg: crc32c: Operation failed for "
1417 "%s: %d\n", driver, err);
1421 if (val != ~420553207) {
1422 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1423 "%d\n", driver, val);
1428 crypto_free_shash(tfm);
1434 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1437 struct crypto_rng *rng;
1440 rng = crypto_alloc_rng(driver, type, mask);
1442 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1443 "%ld\n", driver, PTR_ERR(rng));
1444 return PTR_ERR(rng);
1447 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1449 crypto_free_rng(rng);
1454 /* Please keep this list sorted by algorithm name. */
1455 static const struct alg_test_desc alg_test_descs[] = {
1457 .alg = "ansi_cprng",
1458 .test = alg_test_cprng,
1462 .vecs = ansi_cprng_aes_tv_template,
1463 .count = ANSI_CPRNG_AES_TEST_VECTORS
1468 .test = alg_test_skcipher,
1473 .vecs = aes_cbc_enc_tv_template,
1474 .count = AES_CBC_ENC_TEST_VECTORS
1477 .vecs = aes_cbc_dec_tv_template,
1478 .count = AES_CBC_DEC_TEST_VECTORS
1483 .alg = "cbc(anubis)",
1484 .test = alg_test_skcipher,
1488 .vecs = anubis_cbc_enc_tv_template,
1489 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1492 .vecs = anubis_cbc_dec_tv_template,
1493 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1498 .alg = "cbc(blowfish)",
1499 .test = alg_test_skcipher,
1503 .vecs = bf_cbc_enc_tv_template,
1504 .count = BF_CBC_ENC_TEST_VECTORS
1507 .vecs = bf_cbc_dec_tv_template,
1508 .count = BF_CBC_DEC_TEST_VECTORS
1513 .alg = "cbc(camellia)",
1514 .test = alg_test_skcipher,
1518 .vecs = camellia_cbc_enc_tv_template,
1519 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1522 .vecs = camellia_cbc_dec_tv_template,
1523 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1529 .test = alg_test_skcipher,
1533 .vecs = des_cbc_enc_tv_template,
1534 .count = DES_CBC_ENC_TEST_VECTORS
1537 .vecs = des_cbc_dec_tv_template,
1538 .count = DES_CBC_DEC_TEST_VECTORS
1543 .alg = "cbc(des3_ede)",
1544 .test = alg_test_skcipher,
1549 .vecs = des3_ede_cbc_enc_tv_template,
1550 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1553 .vecs = des3_ede_cbc_dec_tv_template,
1554 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1559 .alg = "cbc(twofish)",
1560 .test = alg_test_skcipher,
1564 .vecs = tf_cbc_enc_tv_template,
1565 .count = TF_CBC_ENC_TEST_VECTORS
1568 .vecs = tf_cbc_dec_tv_template,
1569 .count = TF_CBC_DEC_TEST_VECTORS
1575 .test = alg_test_aead,
1580 .vecs = aes_ccm_enc_tv_template,
1581 .count = AES_CCM_ENC_TEST_VECTORS
1584 .vecs = aes_ccm_dec_tv_template,
1585 .count = AES_CCM_DEC_TEST_VECTORS
1591 .test = alg_test_crc32c,
1595 .vecs = crc32c_tv_template,
1596 .count = CRC32C_TEST_VECTORS
1601 .test = alg_test_skcipher,
1606 .vecs = aes_ctr_enc_tv_template,
1607 .count = AES_CTR_ENC_TEST_VECTORS
1610 .vecs = aes_ctr_dec_tv_template,
1611 .count = AES_CTR_DEC_TEST_VECTORS
1616 .alg = "cts(cbc(aes))",
1617 .test = alg_test_skcipher,
1621 .vecs = cts_mode_enc_tv_template,
1622 .count = CTS_MODE_ENC_TEST_VECTORS
1625 .vecs = cts_mode_dec_tv_template,
1626 .count = CTS_MODE_DEC_TEST_VECTORS
1632 .test = alg_test_comp,
1636 .vecs = deflate_comp_tv_template,
1637 .count = DEFLATE_COMP_TEST_VECTORS
1640 .vecs = deflate_decomp_tv_template,
1641 .count = DEFLATE_DECOMP_TEST_VECTORS
1647 .test = alg_test_skcipher,
1652 .vecs = aes_enc_tv_template,
1653 .count = AES_ENC_TEST_VECTORS
1656 .vecs = aes_dec_tv_template,
1657 .count = AES_DEC_TEST_VECTORS
1662 .alg = "ecb(anubis)",
1663 .test = alg_test_skcipher,
1667 .vecs = anubis_enc_tv_template,
1668 .count = ANUBIS_ENC_TEST_VECTORS
1671 .vecs = anubis_dec_tv_template,
1672 .count = ANUBIS_DEC_TEST_VECTORS
1678 .test = alg_test_skcipher,
1682 .vecs = arc4_enc_tv_template,
1683 .count = ARC4_ENC_TEST_VECTORS
1686 .vecs = arc4_dec_tv_template,
1687 .count = ARC4_DEC_TEST_VECTORS
1692 .alg = "ecb(blowfish)",
1693 .test = alg_test_skcipher,
1697 .vecs = bf_enc_tv_template,
1698 .count = BF_ENC_TEST_VECTORS
1701 .vecs = bf_dec_tv_template,
1702 .count = BF_DEC_TEST_VECTORS
1707 .alg = "ecb(camellia)",
1708 .test = alg_test_skcipher,
1712 .vecs = camellia_enc_tv_template,
1713 .count = CAMELLIA_ENC_TEST_VECTORS
1716 .vecs = camellia_dec_tv_template,
1717 .count = CAMELLIA_DEC_TEST_VECTORS
1722 .alg = "ecb(cast5)",
1723 .test = alg_test_skcipher,
1727 .vecs = cast5_enc_tv_template,
1728 .count = CAST5_ENC_TEST_VECTORS
1731 .vecs = cast5_dec_tv_template,
1732 .count = CAST5_DEC_TEST_VECTORS
1737 .alg = "ecb(cast6)",
1738 .test = alg_test_skcipher,
1742 .vecs = cast6_enc_tv_template,
1743 .count = CAST6_ENC_TEST_VECTORS
1746 .vecs = cast6_dec_tv_template,
1747 .count = CAST6_DEC_TEST_VECTORS
1753 .test = alg_test_skcipher,
1758 .vecs = des_enc_tv_template,
1759 .count = DES_ENC_TEST_VECTORS
1762 .vecs = des_dec_tv_template,
1763 .count = DES_DEC_TEST_VECTORS
1768 .alg = "ecb(des3_ede)",
1769 .test = alg_test_skcipher,
1774 .vecs = des3_ede_enc_tv_template,
1775 .count = DES3_EDE_ENC_TEST_VECTORS
1778 .vecs = des3_ede_dec_tv_template,
1779 .count = DES3_EDE_DEC_TEST_VECTORS
1784 .alg = "ecb(khazad)",
1785 .test = alg_test_skcipher,
1789 .vecs = khazad_enc_tv_template,
1790 .count = KHAZAD_ENC_TEST_VECTORS
1793 .vecs = khazad_dec_tv_template,
1794 .count = KHAZAD_DEC_TEST_VECTORS
1800 .test = alg_test_skcipher,
1804 .vecs = seed_enc_tv_template,
1805 .count = SEED_ENC_TEST_VECTORS
1808 .vecs = seed_dec_tv_template,
1809 .count = SEED_DEC_TEST_VECTORS
1814 .alg = "ecb(serpent)",
1815 .test = alg_test_skcipher,
1819 .vecs = serpent_enc_tv_template,
1820 .count = SERPENT_ENC_TEST_VECTORS
1823 .vecs = serpent_dec_tv_template,
1824 .count = SERPENT_DEC_TEST_VECTORS
1830 .test = alg_test_skcipher,
1834 .vecs = tea_enc_tv_template,
1835 .count = TEA_ENC_TEST_VECTORS
1838 .vecs = tea_dec_tv_template,
1839 .count = TEA_DEC_TEST_VECTORS
1844 .alg = "ecb(tnepres)",
1845 .test = alg_test_skcipher,
1849 .vecs = tnepres_enc_tv_template,
1850 .count = TNEPRES_ENC_TEST_VECTORS
1853 .vecs = tnepres_dec_tv_template,
1854 .count = TNEPRES_DEC_TEST_VECTORS
1859 .alg = "ecb(twofish)",
1860 .test = alg_test_skcipher,
1864 .vecs = tf_enc_tv_template,
1865 .count = TF_ENC_TEST_VECTORS
1868 .vecs = tf_dec_tv_template,
1869 .count = TF_DEC_TEST_VECTORS
1875 .test = alg_test_skcipher,
1879 .vecs = xeta_enc_tv_template,
1880 .count = XETA_ENC_TEST_VECTORS
1883 .vecs = xeta_dec_tv_template,
1884 .count = XETA_DEC_TEST_VECTORS
1890 .test = alg_test_skcipher,
1894 .vecs = xtea_enc_tv_template,
1895 .count = XTEA_ENC_TEST_VECTORS
1898 .vecs = xtea_dec_tv_template,
1899 .count = XTEA_DEC_TEST_VECTORS
1905 .test = alg_test_aead,
1910 .vecs = aes_gcm_enc_tv_template,
1911 .count = AES_GCM_ENC_TEST_VECTORS
1914 .vecs = aes_gcm_dec_tv_template,
1915 .count = AES_GCM_DEC_TEST_VECTORS
1921 .test = alg_test_hash,
1924 .vecs = hmac_md5_tv_template,
1925 .count = HMAC_MD5_TEST_VECTORS
1929 .alg = "hmac(rmd128)",
1930 .test = alg_test_hash,
1933 .vecs = hmac_rmd128_tv_template,
1934 .count = HMAC_RMD128_TEST_VECTORS
1938 .alg = "hmac(rmd160)",
1939 .test = alg_test_hash,
1942 .vecs = hmac_rmd160_tv_template,
1943 .count = HMAC_RMD160_TEST_VECTORS
1947 .alg = "hmac(sha1)",
1948 .test = alg_test_hash,
1952 .vecs = hmac_sha1_tv_template,
1953 .count = HMAC_SHA1_TEST_VECTORS
1957 .alg = "hmac(sha224)",
1958 .test = alg_test_hash,
1962 .vecs = hmac_sha224_tv_template,
1963 .count = HMAC_SHA224_TEST_VECTORS
1967 .alg = "hmac(sha256)",
1968 .test = alg_test_hash,
1972 .vecs = hmac_sha256_tv_template,
1973 .count = HMAC_SHA256_TEST_VECTORS
1977 .alg = "hmac(sha384)",
1978 .test = alg_test_hash,
1982 .vecs = hmac_sha384_tv_template,
1983 .count = HMAC_SHA384_TEST_VECTORS
1987 .alg = "hmac(sha512)",
1988 .test = alg_test_hash,
1992 .vecs = hmac_sha512_tv_template,
1993 .count = HMAC_SHA512_TEST_VECTORS
1998 .test = alg_test_skcipher,
2002 .vecs = aes_lrw_enc_tv_template,
2003 .count = AES_LRW_ENC_TEST_VECTORS
2006 .vecs = aes_lrw_dec_tv_template,
2007 .count = AES_LRW_DEC_TEST_VECTORS
2013 .test = alg_test_comp,
2017 .vecs = lzo_comp_tv_template,
2018 .count = LZO_COMP_TEST_VECTORS
2021 .vecs = lzo_decomp_tv_template,
2022 .count = LZO_DECOMP_TEST_VECTORS
2028 .test = alg_test_hash,
2031 .vecs = md4_tv_template,
2032 .count = MD4_TEST_VECTORS
2037 .test = alg_test_hash,
2040 .vecs = md5_tv_template,
2041 .count = MD5_TEST_VECTORS
2045 .alg = "michael_mic",
2046 .test = alg_test_hash,
2049 .vecs = michael_mic_tv_template,
2050 .count = MICHAEL_MIC_TEST_VECTORS
2054 .alg = "pcbc(fcrypt)",
2055 .test = alg_test_skcipher,
2059 .vecs = fcrypt_pcbc_enc_tv_template,
2060 .count = FCRYPT_ENC_TEST_VECTORS
2063 .vecs = fcrypt_pcbc_dec_tv_template,
2064 .count = FCRYPT_DEC_TEST_VECTORS
2069 .alg = "rfc3686(ctr(aes))",
2070 .test = alg_test_skcipher,
2075 .vecs = aes_ctr_rfc3686_enc_tv_template,
2076 .count = AES_CTR_3686_ENC_TEST_VECTORS
2079 .vecs = aes_ctr_rfc3686_dec_tv_template,
2080 .count = AES_CTR_3686_DEC_TEST_VECTORS
2085 .alg = "rfc4309(ccm(aes))",
2086 .test = alg_test_aead,
2091 .vecs = aes_ccm_rfc4309_enc_tv_template,
2092 .count = AES_CCM_4309_ENC_TEST_VECTORS
2095 .vecs = aes_ccm_rfc4309_dec_tv_template,
2096 .count = AES_CCM_4309_DEC_TEST_VECTORS
2102 .test = alg_test_hash,
2105 .vecs = rmd128_tv_template,
2106 .count = RMD128_TEST_VECTORS
2111 .test = alg_test_hash,
2114 .vecs = rmd160_tv_template,
2115 .count = RMD160_TEST_VECTORS
2120 .test = alg_test_hash,
2123 .vecs = rmd256_tv_template,
2124 .count = RMD256_TEST_VECTORS
2129 .test = alg_test_hash,
2132 .vecs = rmd320_tv_template,
2133 .count = RMD320_TEST_VECTORS
2138 .test = alg_test_skcipher,
2142 .vecs = salsa20_stream_enc_tv_template,
2143 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2149 .test = alg_test_hash,
2153 .vecs = sha1_tv_template,
2154 .count = SHA1_TEST_VECTORS
2159 .test = alg_test_hash,
2163 .vecs = sha224_tv_template,
2164 .count = SHA224_TEST_VECTORS
2169 .test = alg_test_hash,
2173 .vecs = sha256_tv_template,
2174 .count = SHA256_TEST_VECTORS
2179 .test = alg_test_hash,
2183 .vecs = sha384_tv_template,
2184 .count = SHA384_TEST_VECTORS
2189 .test = alg_test_hash,
2193 .vecs = sha512_tv_template,
2194 .count = SHA512_TEST_VECTORS
2199 .test = alg_test_hash,
2202 .vecs = tgr128_tv_template,
2203 .count = TGR128_TEST_VECTORS
2208 .test = alg_test_hash,
2211 .vecs = tgr160_tv_template,
2212 .count = TGR160_TEST_VECTORS
2217 .test = alg_test_hash,
2220 .vecs = tgr192_tv_template,
2221 .count = TGR192_TEST_VECTORS
2226 .test = alg_test_hash,
2229 .vecs = wp256_tv_template,
2230 .count = WP256_TEST_VECTORS
2235 .test = alg_test_hash,
2238 .vecs = wp384_tv_template,
2239 .count = WP384_TEST_VECTORS
2244 .test = alg_test_hash,
2247 .vecs = wp512_tv_template,
2248 .count = WP512_TEST_VECTORS
2253 .test = alg_test_hash,
2256 .vecs = aes_xcbc128_tv_template,
2257 .count = XCBC_AES_TEST_VECTORS
2262 .test = alg_test_skcipher,
2266 .vecs = aes_xts_enc_tv_template,
2267 .count = AES_XTS_ENC_TEST_VECTORS
2270 .vecs = aes_xts_dec_tv_template,
2271 .count = AES_XTS_DEC_TEST_VECTORS
2277 .test = alg_test_pcomp,
2281 .vecs = zlib_comp_tv_template,
2282 .count = ZLIB_COMP_TEST_VECTORS
2285 .vecs = zlib_decomp_tv_template,
2286 .count = ZLIB_DECOMP_TEST_VECTORS
2293 static int alg_find_test(const char *alg)
2296 int end = ARRAY_SIZE(alg_test_descs);
2298 while (start < end) {
2299 int i = (start + end) / 2;
2300 int diff = strcmp(alg_test_descs[i].alg, alg);
2318 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2323 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
2324 char nalg[CRYPTO_MAX_ALG_NAME];
2326 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
2328 return -ENAMETOOLONG;
2330 i = alg_find_test(nalg);
2334 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2337 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2341 i = alg_find_test(alg);
2345 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2348 rc = alg_test_descs[i].test(alg_test_descs + i, driver,
2351 if (fips_enabled && rc)
2352 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2354 if (fips_enabled && !rc)
2355 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2361 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2366 EXPORT_SYMBOL_GPL(alg_test);