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);
189 if (WARN_ON(template[i].psize > PAGE_SIZE))
192 memcpy(hash_buff, template[i].plaintext, template[i].psize);
193 sg_init_one(&sg[0], hash_buff, template[i].psize);
195 if (template[i].ksize) {
196 crypto_ahash_clear_flags(tfm, ~0);
197 ret = crypto_ahash_setkey(tfm, template[i].key,
200 printk(KERN_ERR "alg: hash: setkey failed on "
201 "test %d for %s: ret=%d\n", i + 1, algo,
207 ahash_request_set_crypt(req, sg, result, template[i].psize);
208 ret = crypto_ahash_digest(req);
214 ret = wait_for_completion_interruptible(
215 &tresult.completion);
216 if (!ret && !(ret = tresult.err)) {
217 INIT_COMPLETION(tresult.completion);
222 printk(KERN_ERR "alg: hash: digest failed on test %d "
223 "for %s: ret=%d\n", i + 1, algo, -ret);
227 if (memcmp(result, template[i].digest,
228 crypto_ahash_digestsize(tfm))) {
229 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
231 hexdump(result, crypto_ahash_digestsize(tfm));
238 for (i = 0; i < tcount; i++) {
239 if (template[i].np) {
241 memset(result, 0, 64);
244 sg_init_table(sg, template[i].np);
246 for (k = 0; k < template[i].np; k++) {
247 if (WARN_ON(offset_in_page(IDX[k]) +
248 template[i].tap[k] > PAGE_SIZE))
251 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
252 offset_in_page(IDX[k]),
253 template[i].plaintext + temp,
256 temp += template[i].tap[k];
259 if (template[i].ksize) {
260 crypto_ahash_clear_flags(tfm, ~0);
261 ret = crypto_ahash_setkey(tfm, template[i].key,
265 printk(KERN_ERR "alg: hash: setkey "
266 "failed on chunking test %d "
267 "for %s: ret=%d\n", j, algo,
273 ahash_request_set_crypt(req, sg, result,
275 ret = crypto_ahash_digest(req);
281 ret = wait_for_completion_interruptible(
282 &tresult.completion);
283 if (!ret && !(ret = tresult.err)) {
284 INIT_COMPLETION(tresult.completion);
289 printk(KERN_ERR "alg: hash: digest failed "
290 "on chunking test %d for %s: "
291 "ret=%d\n", j, algo, -ret);
295 if (memcmp(result, template[i].digest,
296 crypto_ahash_digestsize(tfm))) {
297 printk(KERN_ERR "alg: hash: Chunking test %d "
298 "failed for %s\n", j, algo);
299 hexdump(result, crypto_ahash_digestsize(tfm));
309 ahash_request_free(req);
311 testmgr_free_buf(xbuf);
316 static int test_aead(struct crypto_aead *tfm, int enc,
317 struct aead_testvec *template, unsigned int tcount)
319 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
320 unsigned int i, j, k, n, temp;
324 struct aead_request *req;
325 struct scatterlist sg[8];
326 struct scatterlist asg[8];
328 struct tcrypt_result result;
329 unsigned int authsize;
333 char *xbuf[XBUFSIZE];
334 char *axbuf[XBUFSIZE];
336 if (testmgr_alloc_buf(xbuf))
338 if (testmgr_alloc_buf(axbuf))
346 init_completion(&result.completion);
348 req = aead_request_alloc(tfm, GFP_KERNEL);
350 printk(KERN_ERR "alg: aead: Failed to allocate request for "
355 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
356 tcrypt_complete, &result);
358 for (i = 0, j = 0; i < tcount; i++) {
359 if (!template[i].np) {
362 /* some tepmplates have no input data but they will
369 if (WARN_ON(template[i].ilen > PAGE_SIZE ||
370 template[i].alen > PAGE_SIZE))
373 memcpy(input, template[i].input, template[i].ilen);
374 memcpy(assoc, template[i].assoc, template[i].alen);
376 memcpy(iv, template[i].iv, MAX_IVLEN);
378 memset(iv, 0, MAX_IVLEN);
380 crypto_aead_clear_flags(tfm, ~0);
382 crypto_aead_set_flags(
383 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
385 key = template[i].key;
387 ret = crypto_aead_setkey(tfm, key,
389 if (!ret == template[i].fail) {
390 printk(KERN_ERR "alg: aead: setkey failed on "
391 "test %d for %s: flags=%x\n", j, algo,
392 crypto_aead_get_flags(tfm));
397 authsize = abs(template[i].rlen - template[i].ilen);
398 ret = crypto_aead_setauthsize(tfm, authsize);
400 printk(KERN_ERR "alg: aead: Failed to set "
401 "authsize to %u on test %d for %s\n",
406 sg_init_one(&sg[0], input,
407 template[i].ilen + (enc ? authsize : 0));
409 sg_init_one(&asg[0], assoc, template[i].alen);
411 aead_request_set_crypt(req, sg, sg,
412 template[i].ilen, iv);
414 aead_request_set_assoc(req, asg, template[i].alen);
417 crypto_aead_encrypt(req) :
418 crypto_aead_decrypt(req);
422 if (template[i].novrfy) {
423 /* verification was supposed to fail */
424 printk(KERN_ERR "alg: aead: %s failed "
425 "on test %d for %s: ret was 0, "
426 "expected -EBADMSG\n",
428 /* so really, we got a bad message */
435 ret = wait_for_completion_interruptible(
437 if (!ret && !(ret = result.err)) {
438 INIT_COMPLETION(result.completion);
442 if (template[i].novrfy)
443 /* verification failure was expected */
447 printk(KERN_ERR "alg: aead: %s failed on test "
448 "%d for %s: ret=%d\n", e, j, algo, -ret);
453 if (memcmp(q, template[i].result, template[i].rlen)) {
454 printk(KERN_ERR "alg: aead: Test %d failed on "
455 "%s for %s\n", j, e, algo);
456 hexdump(q, template[i].rlen);
463 for (i = 0, j = 0; i < tcount; i++) {
464 if (template[i].np) {
468 memcpy(iv, template[i].iv, MAX_IVLEN);
470 memset(iv, 0, MAX_IVLEN);
472 crypto_aead_clear_flags(tfm, ~0);
474 crypto_aead_set_flags(
475 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
476 key = template[i].key;
478 ret = crypto_aead_setkey(tfm, key, template[i].klen);
479 if (!ret == template[i].fail) {
480 printk(KERN_ERR "alg: aead: setkey failed on "
481 "chunk test %d for %s: flags=%x\n", j,
482 algo, crypto_aead_get_flags(tfm));
487 authsize = abs(template[i].rlen - template[i].ilen);
490 sg_init_table(sg, template[i].np);
491 for (k = 0, temp = 0; k < template[i].np; k++) {
492 if (WARN_ON(offset_in_page(IDX[k]) +
493 template[i].tap[k] > PAGE_SIZE))
496 q = xbuf[IDX[k] >> PAGE_SHIFT] +
497 offset_in_page(IDX[k]);
499 memcpy(q, template[i].input + temp,
502 n = template[i].tap[k];
503 if (k == template[i].np - 1 && enc)
505 if (offset_in_page(q) + n < PAGE_SIZE)
508 sg_set_buf(&sg[k], q, template[i].tap[k]);
509 temp += template[i].tap[k];
512 ret = crypto_aead_setauthsize(tfm, authsize);
514 printk(KERN_ERR "alg: aead: Failed to set "
515 "authsize to %u on chunk test %d for "
516 "%s\n", authsize, j, algo);
521 if (WARN_ON(sg[k - 1].offset +
522 sg[k - 1].length + authsize >
528 sg[k - 1].length += authsize;
531 sg_init_table(asg, template[i].anp);
533 for (k = 0, temp = 0; k < template[i].anp; k++) {
534 if (WARN_ON(offset_in_page(IDX[k]) +
535 template[i].atap[k] > PAGE_SIZE))
538 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
539 offset_in_page(IDX[k]),
540 template[i].assoc + temp,
541 template[i].atap[k]),
542 template[i].atap[k]);
543 temp += template[i].atap[k];
546 aead_request_set_crypt(req, sg, sg,
550 aead_request_set_assoc(req, asg, template[i].alen);
553 crypto_aead_encrypt(req) :
554 crypto_aead_decrypt(req);
558 if (template[i].novrfy) {
559 /* verification was supposed to fail */
560 printk(KERN_ERR "alg: aead: %s failed "
561 "on chunk test %d for %s: ret "
562 "was 0, expected -EBADMSG\n",
564 /* so really, we got a bad message */
571 ret = wait_for_completion_interruptible(
573 if (!ret && !(ret = result.err)) {
574 INIT_COMPLETION(result.completion);
578 if (template[i].novrfy)
579 /* verification failure was expected */
583 printk(KERN_ERR "alg: aead: %s failed on "
584 "chunk test %d for %s: ret=%d\n", e, j,
590 for (k = 0, temp = 0; k < template[i].np; k++) {
591 q = xbuf[IDX[k] >> PAGE_SHIFT] +
592 offset_in_page(IDX[k]);
594 n = template[i].tap[k];
595 if (k == template[i].np - 1)
596 n += enc ? authsize : -authsize;
598 if (memcmp(q, template[i].result + temp, n)) {
599 printk(KERN_ERR "alg: aead: Chunk "
600 "test %d failed on %s at page "
601 "%u for %s\n", j, e, k, algo);
607 if (k == template[i].np - 1 && !enc) {
608 if (memcmp(q, template[i].input +
614 for (n = 0; offset_in_page(q + n) &&
619 printk(KERN_ERR "alg: aead: Result "
620 "buffer corruption in chunk "
621 "test %d on %s at page %u for "
622 "%s: %u bytes:\n", j, e, k,
628 temp += template[i].tap[k];
636 aead_request_free(req);
637 testmgr_free_buf(axbuf);
639 testmgr_free_buf(xbuf);
644 static int test_cipher(struct crypto_cipher *tfm, int enc,
645 struct cipher_testvec *template, unsigned int tcount)
647 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
648 unsigned int i, j, k;
652 char *xbuf[XBUFSIZE];
655 if (testmgr_alloc_buf(xbuf))
664 for (i = 0; i < tcount; i++) {
671 if (WARN_ON(template[i].ilen > PAGE_SIZE))
675 memcpy(data, template[i].input, template[i].ilen);
677 crypto_cipher_clear_flags(tfm, ~0);
679 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
681 ret = crypto_cipher_setkey(tfm, template[i].key,
683 if (!ret == template[i].fail) {
684 printk(KERN_ERR "alg: cipher: setkey failed "
685 "on test %d for %s: flags=%x\n", j,
686 algo, crypto_cipher_get_flags(tfm));
691 for (k = 0; k < template[i].ilen;
692 k += crypto_cipher_blocksize(tfm)) {
694 crypto_cipher_encrypt_one(tfm, data + k,
697 crypto_cipher_decrypt_one(tfm, data + k,
702 if (memcmp(q, template[i].result, template[i].rlen)) {
703 printk(KERN_ERR "alg: cipher: Test %d failed "
704 "on %s for %s\n", j, e, algo);
705 hexdump(q, template[i].rlen);
714 testmgr_free_buf(xbuf);
719 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
720 struct cipher_testvec *template, unsigned int tcount)
723 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
724 unsigned int i, j, k, n, temp;
726 struct ablkcipher_request *req;
727 struct scatterlist sg[8];
729 struct tcrypt_result result;
732 char *xbuf[XBUFSIZE];
735 if (testmgr_alloc_buf(xbuf))
743 init_completion(&result.completion);
745 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
747 printk(KERN_ERR "alg: skcipher: Failed to allocate request "
752 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
753 tcrypt_complete, &result);
756 for (i = 0; i < tcount; i++) {
758 memcpy(iv, template[i].iv, MAX_IVLEN);
760 memset(iv, 0, MAX_IVLEN);
762 if (!(template[i].np)) {
766 if (WARN_ON(template[i].ilen > PAGE_SIZE))
770 memcpy(data, template[i].input, template[i].ilen);
772 crypto_ablkcipher_clear_flags(tfm, ~0);
774 crypto_ablkcipher_set_flags(
775 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
777 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
779 if (!ret == template[i].fail) {
780 printk(KERN_ERR "alg: skcipher: setkey failed "
781 "on test %d for %s: flags=%x\n", j,
782 algo, crypto_ablkcipher_get_flags(tfm));
787 sg_init_one(&sg[0], data, template[i].ilen);
789 ablkcipher_request_set_crypt(req, sg, sg,
790 template[i].ilen, iv);
792 crypto_ablkcipher_encrypt(req) :
793 crypto_ablkcipher_decrypt(req);
800 ret = wait_for_completion_interruptible(
802 if (!ret && !((ret = result.err))) {
803 INIT_COMPLETION(result.completion);
808 printk(KERN_ERR "alg: skcipher: %s failed on "
809 "test %d for %s: ret=%d\n", e, j, algo,
815 if (memcmp(q, template[i].result, template[i].rlen)) {
816 printk(KERN_ERR "alg: skcipher: Test %d "
817 "failed on %s for %s\n", j, e, algo);
818 hexdump(q, template[i].rlen);
826 for (i = 0; i < tcount; i++) {
829 memcpy(iv, template[i].iv, MAX_IVLEN);
831 memset(iv, 0, MAX_IVLEN);
833 if (template[i].np) {
836 crypto_ablkcipher_clear_flags(tfm, ~0);
838 crypto_ablkcipher_set_flags(
839 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
841 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
843 if (!ret == template[i].fail) {
844 printk(KERN_ERR "alg: skcipher: setkey failed "
845 "on chunk test %d for %s: flags=%x\n",
847 crypto_ablkcipher_get_flags(tfm));
854 sg_init_table(sg, template[i].np);
855 for (k = 0; k < template[i].np; k++) {
856 if (WARN_ON(offset_in_page(IDX[k]) +
857 template[i].tap[k] > PAGE_SIZE))
860 q = xbuf[IDX[k] >> PAGE_SHIFT] +
861 offset_in_page(IDX[k]);
863 memcpy(q, template[i].input + temp,
866 if (offset_in_page(q) + template[i].tap[k] <
868 q[template[i].tap[k]] = 0;
870 sg_set_buf(&sg[k], q, template[i].tap[k]);
872 temp += template[i].tap[k];
875 ablkcipher_request_set_crypt(req, sg, sg,
876 template[i].ilen, iv);
879 crypto_ablkcipher_encrypt(req) :
880 crypto_ablkcipher_decrypt(req);
887 ret = wait_for_completion_interruptible(
889 if (!ret && !((ret = result.err))) {
890 INIT_COMPLETION(result.completion);
895 printk(KERN_ERR "alg: skcipher: %s failed on "
896 "chunk test %d for %s: ret=%d\n", e, j,
903 for (k = 0; k < template[i].np; k++) {
904 q = xbuf[IDX[k] >> PAGE_SHIFT] +
905 offset_in_page(IDX[k]);
907 if (memcmp(q, template[i].result + temp,
908 template[i].tap[k])) {
909 printk(KERN_ERR "alg: skcipher: Chunk "
910 "test %d failed on %s at page "
911 "%u for %s\n", j, e, k, algo);
912 hexdump(q, template[i].tap[k]);
916 q += template[i].tap[k];
917 for (n = 0; offset_in_page(q + n) && q[n]; n++)
920 printk(KERN_ERR "alg: skcipher: "
921 "Result buffer corruption in "
922 "chunk test %d on %s at page "
923 "%u for %s: %u bytes:\n", j, e,
928 temp += template[i].tap[k];
936 ablkcipher_request_free(req);
937 testmgr_free_buf(xbuf);
942 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
943 struct comp_testvec *dtemplate, int ctcount, int dtcount)
945 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
947 char result[COMP_BUF_SIZE];
950 for (i = 0; i < ctcount; i++) {
952 unsigned int dlen = COMP_BUF_SIZE;
954 memset(result, 0, sizeof (result));
956 ilen = ctemplate[i].inlen;
957 ret = crypto_comp_compress(tfm, ctemplate[i].input,
958 ilen, result, &dlen);
960 printk(KERN_ERR "alg: comp: compression failed "
961 "on test %d for %s: ret=%d\n", i + 1, algo,
966 if (dlen != ctemplate[i].outlen) {
967 printk(KERN_ERR "alg: comp: Compression test %d "
968 "failed for %s: output len = %d\n", i + 1, algo,
974 if (memcmp(result, ctemplate[i].output, dlen)) {
975 printk(KERN_ERR "alg: comp: Compression test %d "
976 "failed for %s\n", i + 1, algo);
977 hexdump(result, dlen);
983 for (i = 0; i < dtcount; i++) {
985 unsigned int dlen = COMP_BUF_SIZE;
987 memset(result, 0, sizeof (result));
989 ilen = dtemplate[i].inlen;
990 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
991 ilen, result, &dlen);
993 printk(KERN_ERR "alg: comp: decompression failed "
994 "on test %d for %s: ret=%d\n", i + 1, algo,
999 if (dlen != dtemplate[i].outlen) {
1000 printk(KERN_ERR "alg: comp: Decompression test %d "
1001 "failed for %s: output len = %d\n", i + 1, algo,
1007 if (memcmp(result, dtemplate[i].output, dlen)) {
1008 printk(KERN_ERR "alg: comp: Decompression test %d "
1009 "failed for %s\n", i + 1, algo);
1010 hexdump(result, dlen);
1022 static int test_pcomp(struct crypto_pcomp *tfm,
1023 struct pcomp_testvec *ctemplate,
1024 struct pcomp_testvec *dtemplate, int ctcount,
1027 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1029 char result[COMP_BUF_SIZE];
1032 for (i = 0; i < ctcount; i++) {
1033 struct comp_request req;
1034 unsigned int produced = 0;
1036 res = crypto_compress_setup(tfm, ctemplate[i].params,
1037 ctemplate[i].paramsize);
1039 pr_err("alg: pcomp: compression setup failed on test "
1040 "%d for %s: error=%d\n", i + 1, algo, res);
1044 res = crypto_compress_init(tfm);
1046 pr_err("alg: pcomp: compression init failed on test "
1047 "%d for %s: error=%d\n", i + 1, algo, res);
1051 memset(result, 0, sizeof(result));
1053 req.next_in = ctemplate[i].input;
1054 req.avail_in = ctemplate[i].inlen / 2;
1055 req.next_out = result;
1056 req.avail_out = ctemplate[i].outlen / 2;
1058 res = crypto_compress_update(tfm, &req);
1059 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1060 pr_err("alg: pcomp: compression update failed on test "
1061 "%d for %s: error=%d\n", i + 1, algo, res);
1067 /* Add remaining input data */
1068 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1070 res = crypto_compress_update(tfm, &req);
1071 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1072 pr_err("alg: pcomp: compression update failed on test "
1073 "%d for %s: error=%d\n", i + 1, algo, res);
1079 /* Provide remaining output space */
1080 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1082 res = crypto_compress_final(tfm, &req);
1084 pr_err("alg: pcomp: compression final failed on test "
1085 "%d for %s: error=%d\n", i + 1, algo, res);
1090 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1091 pr_err("alg: comp: Compression test %d failed for %s: "
1092 "output len = %d (expected %d)\n", i + 1, algo,
1093 COMP_BUF_SIZE - req.avail_out,
1094 ctemplate[i].outlen);
1098 if (produced != ctemplate[i].outlen) {
1099 pr_err("alg: comp: Compression test %d failed for %s: "
1100 "returned len = %u (expected %d)\n", i + 1,
1101 algo, produced, ctemplate[i].outlen);
1105 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1106 pr_err("alg: pcomp: Compression test %d failed for "
1107 "%s\n", i + 1, algo);
1108 hexdump(result, ctemplate[i].outlen);
1113 for (i = 0; i < dtcount; i++) {
1114 struct comp_request req;
1115 unsigned int produced = 0;
1117 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1118 dtemplate[i].paramsize);
1120 pr_err("alg: pcomp: decompression setup failed on "
1121 "test %d for %s: error=%d\n", i + 1, algo, res);
1125 res = crypto_decompress_init(tfm);
1127 pr_err("alg: pcomp: decompression init failed on test "
1128 "%d for %s: error=%d\n", i + 1, algo, res);
1132 memset(result, 0, sizeof(result));
1134 req.next_in = dtemplate[i].input;
1135 req.avail_in = dtemplate[i].inlen / 2;
1136 req.next_out = result;
1137 req.avail_out = dtemplate[i].outlen / 2;
1139 res = crypto_decompress_update(tfm, &req);
1140 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1141 pr_err("alg: pcomp: decompression update failed on "
1142 "test %d for %s: error=%d\n", i + 1, algo, res);
1148 /* Add remaining input data */
1149 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1151 res = crypto_decompress_update(tfm, &req);
1152 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1153 pr_err("alg: pcomp: decompression update failed on "
1154 "test %d for %s: error=%d\n", i + 1, algo, res);
1160 /* Provide remaining output space */
1161 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1163 res = crypto_decompress_final(tfm, &req);
1164 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1165 pr_err("alg: pcomp: decompression final failed on "
1166 "test %d for %s: error=%d\n", i + 1, algo, res);
1172 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1173 pr_err("alg: comp: Decompression test %d failed for "
1174 "%s: output len = %d (expected %d)\n", i + 1,
1175 algo, COMP_BUF_SIZE - req.avail_out,
1176 dtemplate[i].outlen);
1180 if (produced != dtemplate[i].outlen) {
1181 pr_err("alg: comp: Decompression test %d failed for "
1182 "%s: returned len = %u (expected %d)\n", i + 1,
1183 algo, produced, dtemplate[i].outlen);
1187 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1188 pr_err("alg: pcomp: Decompression test %d failed for "
1189 "%s\n", i + 1, algo);
1190 hexdump(result, dtemplate[i].outlen);
1199 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1200 unsigned int tcount)
1202 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1203 int err, i, j, seedsize;
1207 seedsize = crypto_rng_seedsize(tfm);
1209 seed = kmalloc(seedsize, GFP_KERNEL);
1211 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1216 for (i = 0; i < tcount; i++) {
1217 memset(result, 0, 32);
1219 memcpy(seed, template[i].v, template[i].vlen);
1220 memcpy(seed + template[i].vlen, template[i].key,
1222 memcpy(seed + template[i].vlen + template[i].klen,
1223 template[i].dt, template[i].dtlen);
1225 err = crypto_rng_reset(tfm, seed, seedsize);
1227 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1232 for (j = 0; j < template[i].loops; j++) {
1233 err = crypto_rng_get_bytes(tfm, result,
1235 if (err != template[i].rlen) {
1236 printk(KERN_ERR "alg: cprng: Failed to obtain "
1237 "the correct amount of random data for "
1238 "%s (requested %d, got %d)\n", algo,
1239 template[i].rlen, err);
1244 err = memcmp(result, template[i].result,
1247 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1249 hexdump(result, template[i].rlen);
1260 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1263 struct crypto_aead *tfm;
1266 tfm = crypto_alloc_aead(driver, type, mask);
1268 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1269 "%ld\n", driver, PTR_ERR(tfm));
1270 return PTR_ERR(tfm);
1273 if (desc->suite.aead.enc.vecs) {
1274 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1275 desc->suite.aead.enc.count);
1280 if (!err && desc->suite.aead.dec.vecs)
1281 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1282 desc->suite.aead.dec.count);
1285 crypto_free_aead(tfm);
1289 static int alg_test_cipher(const struct alg_test_desc *desc,
1290 const char *driver, u32 type, u32 mask)
1292 struct crypto_cipher *tfm;
1295 tfm = crypto_alloc_cipher(driver, type, mask);
1297 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1298 "%s: %ld\n", driver, PTR_ERR(tfm));
1299 return PTR_ERR(tfm);
1302 if (desc->suite.cipher.enc.vecs) {
1303 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1304 desc->suite.cipher.enc.count);
1309 if (desc->suite.cipher.dec.vecs)
1310 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1311 desc->suite.cipher.dec.count);
1314 crypto_free_cipher(tfm);
1318 static int alg_test_skcipher(const struct alg_test_desc *desc,
1319 const char *driver, u32 type, u32 mask)
1321 struct crypto_ablkcipher *tfm;
1324 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1326 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1327 "%s: %ld\n", driver, PTR_ERR(tfm));
1328 return PTR_ERR(tfm);
1331 if (desc->suite.cipher.enc.vecs) {
1332 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1333 desc->suite.cipher.enc.count);
1338 if (desc->suite.cipher.dec.vecs)
1339 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1340 desc->suite.cipher.dec.count);
1343 crypto_free_ablkcipher(tfm);
1347 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1350 struct crypto_comp *tfm;
1353 tfm = crypto_alloc_comp(driver, type, mask);
1355 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1356 "%ld\n", driver, PTR_ERR(tfm));
1357 return PTR_ERR(tfm);
1360 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1361 desc->suite.comp.decomp.vecs,
1362 desc->suite.comp.comp.count,
1363 desc->suite.comp.decomp.count);
1365 crypto_free_comp(tfm);
1369 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1372 struct crypto_pcomp *tfm;
1375 tfm = crypto_alloc_pcomp(driver, type, mask);
1377 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1378 driver, PTR_ERR(tfm));
1379 return PTR_ERR(tfm);
1382 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1383 desc->suite.pcomp.decomp.vecs,
1384 desc->suite.pcomp.comp.count,
1385 desc->suite.pcomp.decomp.count);
1387 crypto_free_pcomp(tfm);
1391 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1394 struct crypto_ahash *tfm;
1397 tfm = crypto_alloc_ahash(driver, type, mask);
1399 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1400 "%ld\n", driver, PTR_ERR(tfm));
1401 return PTR_ERR(tfm);
1404 err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
1406 crypto_free_ahash(tfm);
1410 static int alg_test_crc32c(const struct alg_test_desc *desc,
1411 const char *driver, u32 type, u32 mask)
1413 struct crypto_shash *tfm;
1417 err = alg_test_hash(desc, driver, type, mask);
1421 tfm = crypto_alloc_shash(driver, type, mask);
1423 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1424 "%ld\n", driver, PTR_ERR(tfm));
1431 struct shash_desc shash;
1432 char ctx[crypto_shash_descsize(tfm)];
1435 sdesc.shash.tfm = tfm;
1436 sdesc.shash.flags = 0;
1438 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1439 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1441 printk(KERN_ERR "alg: crc32c: Operation failed for "
1442 "%s: %d\n", driver, err);
1446 if (val != ~420553207) {
1447 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1448 "%d\n", driver, val);
1453 crypto_free_shash(tfm);
1459 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1462 struct crypto_rng *rng;
1465 rng = crypto_alloc_rng(driver, type, mask);
1467 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1468 "%ld\n", driver, PTR_ERR(rng));
1469 return PTR_ERR(rng);
1472 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1474 crypto_free_rng(rng);
1479 /* Please keep this list sorted by algorithm name. */
1480 static const struct alg_test_desc alg_test_descs[] = {
1482 .alg = "ansi_cprng",
1483 .test = alg_test_cprng,
1487 .vecs = ansi_cprng_aes_tv_template,
1488 .count = ANSI_CPRNG_AES_TEST_VECTORS
1493 .test = alg_test_skcipher,
1498 .vecs = aes_cbc_enc_tv_template,
1499 .count = AES_CBC_ENC_TEST_VECTORS
1502 .vecs = aes_cbc_dec_tv_template,
1503 .count = AES_CBC_DEC_TEST_VECTORS
1508 .alg = "cbc(anubis)",
1509 .test = alg_test_skcipher,
1513 .vecs = anubis_cbc_enc_tv_template,
1514 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1517 .vecs = anubis_cbc_dec_tv_template,
1518 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1523 .alg = "cbc(blowfish)",
1524 .test = alg_test_skcipher,
1528 .vecs = bf_cbc_enc_tv_template,
1529 .count = BF_CBC_ENC_TEST_VECTORS
1532 .vecs = bf_cbc_dec_tv_template,
1533 .count = BF_CBC_DEC_TEST_VECTORS
1538 .alg = "cbc(camellia)",
1539 .test = alg_test_skcipher,
1543 .vecs = camellia_cbc_enc_tv_template,
1544 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1547 .vecs = camellia_cbc_dec_tv_template,
1548 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1554 .test = alg_test_skcipher,
1558 .vecs = des_cbc_enc_tv_template,
1559 .count = DES_CBC_ENC_TEST_VECTORS
1562 .vecs = des_cbc_dec_tv_template,
1563 .count = DES_CBC_DEC_TEST_VECTORS
1568 .alg = "cbc(des3_ede)",
1569 .test = alg_test_skcipher,
1574 .vecs = des3_ede_cbc_enc_tv_template,
1575 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1578 .vecs = des3_ede_cbc_dec_tv_template,
1579 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1584 .alg = "cbc(twofish)",
1585 .test = alg_test_skcipher,
1589 .vecs = tf_cbc_enc_tv_template,
1590 .count = TF_CBC_ENC_TEST_VECTORS
1593 .vecs = tf_cbc_dec_tv_template,
1594 .count = TF_CBC_DEC_TEST_VECTORS
1600 .test = alg_test_aead,
1605 .vecs = aes_ccm_enc_tv_template,
1606 .count = AES_CCM_ENC_TEST_VECTORS
1609 .vecs = aes_ccm_dec_tv_template,
1610 .count = AES_CCM_DEC_TEST_VECTORS
1616 .test = alg_test_crc32c,
1620 .vecs = crc32c_tv_template,
1621 .count = CRC32C_TEST_VECTORS
1626 .test = alg_test_skcipher,
1631 .vecs = aes_ctr_enc_tv_template,
1632 .count = AES_CTR_ENC_TEST_VECTORS
1635 .vecs = aes_ctr_dec_tv_template,
1636 .count = AES_CTR_DEC_TEST_VECTORS
1641 .alg = "cts(cbc(aes))",
1642 .test = alg_test_skcipher,
1646 .vecs = cts_mode_enc_tv_template,
1647 .count = CTS_MODE_ENC_TEST_VECTORS
1650 .vecs = cts_mode_dec_tv_template,
1651 .count = CTS_MODE_DEC_TEST_VECTORS
1657 .test = alg_test_comp,
1661 .vecs = deflate_comp_tv_template,
1662 .count = DEFLATE_COMP_TEST_VECTORS
1665 .vecs = deflate_decomp_tv_template,
1666 .count = DEFLATE_DECOMP_TEST_VECTORS
1672 .test = alg_test_skcipher,
1677 .vecs = aes_enc_tv_template,
1678 .count = AES_ENC_TEST_VECTORS
1681 .vecs = aes_dec_tv_template,
1682 .count = AES_DEC_TEST_VECTORS
1687 .alg = "ecb(anubis)",
1688 .test = alg_test_skcipher,
1692 .vecs = anubis_enc_tv_template,
1693 .count = ANUBIS_ENC_TEST_VECTORS
1696 .vecs = anubis_dec_tv_template,
1697 .count = ANUBIS_DEC_TEST_VECTORS
1703 .test = alg_test_skcipher,
1707 .vecs = arc4_enc_tv_template,
1708 .count = ARC4_ENC_TEST_VECTORS
1711 .vecs = arc4_dec_tv_template,
1712 .count = ARC4_DEC_TEST_VECTORS
1717 .alg = "ecb(blowfish)",
1718 .test = alg_test_skcipher,
1722 .vecs = bf_enc_tv_template,
1723 .count = BF_ENC_TEST_VECTORS
1726 .vecs = bf_dec_tv_template,
1727 .count = BF_DEC_TEST_VECTORS
1732 .alg = "ecb(camellia)",
1733 .test = alg_test_skcipher,
1737 .vecs = camellia_enc_tv_template,
1738 .count = CAMELLIA_ENC_TEST_VECTORS
1741 .vecs = camellia_dec_tv_template,
1742 .count = CAMELLIA_DEC_TEST_VECTORS
1747 .alg = "ecb(cast5)",
1748 .test = alg_test_skcipher,
1752 .vecs = cast5_enc_tv_template,
1753 .count = CAST5_ENC_TEST_VECTORS
1756 .vecs = cast5_dec_tv_template,
1757 .count = CAST5_DEC_TEST_VECTORS
1762 .alg = "ecb(cast6)",
1763 .test = alg_test_skcipher,
1767 .vecs = cast6_enc_tv_template,
1768 .count = CAST6_ENC_TEST_VECTORS
1771 .vecs = cast6_dec_tv_template,
1772 .count = CAST6_DEC_TEST_VECTORS
1778 .test = alg_test_skcipher,
1783 .vecs = des_enc_tv_template,
1784 .count = DES_ENC_TEST_VECTORS
1787 .vecs = des_dec_tv_template,
1788 .count = DES_DEC_TEST_VECTORS
1793 .alg = "ecb(des3_ede)",
1794 .test = alg_test_skcipher,
1799 .vecs = des3_ede_enc_tv_template,
1800 .count = DES3_EDE_ENC_TEST_VECTORS
1803 .vecs = des3_ede_dec_tv_template,
1804 .count = DES3_EDE_DEC_TEST_VECTORS
1809 .alg = "ecb(khazad)",
1810 .test = alg_test_skcipher,
1814 .vecs = khazad_enc_tv_template,
1815 .count = KHAZAD_ENC_TEST_VECTORS
1818 .vecs = khazad_dec_tv_template,
1819 .count = KHAZAD_DEC_TEST_VECTORS
1825 .test = alg_test_skcipher,
1829 .vecs = seed_enc_tv_template,
1830 .count = SEED_ENC_TEST_VECTORS
1833 .vecs = seed_dec_tv_template,
1834 .count = SEED_DEC_TEST_VECTORS
1839 .alg = "ecb(serpent)",
1840 .test = alg_test_skcipher,
1844 .vecs = serpent_enc_tv_template,
1845 .count = SERPENT_ENC_TEST_VECTORS
1848 .vecs = serpent_dec_tv_template,
1849 .count = SERPENT_DEC_TEST_VECTORS
1855 .test = alg_test_skcipher,
1859 .vecs = tea_enc_tv_template,
1860 .count = TEA_ENC_TEST_VECTORS
1863 .vecs = tea_dec_tv_template,
1864 .count = TEA_DEC_TEST_VECTORS
1869 .alg = "ecb(tnepres)",
1870 .test = alg_test_skcipher,
1874 .vecs = tnepres_enc_tv_template,
1875 .count = TNEPRES_ENC_TEST_VECTORS
1878 .vecs = tnepres_dec_tv_template,
1879 .count = TNEPRES_DEC_TEST_VECTORS
1884 .alg = "ecb(twofish)",
1885 .test = alg_test_skcipher,
1889 .vecs = tf_enc_tv_template,
1890 .count = TF_ENC_TEST_VECTORS
1893 .vecs = tf_dec_tv_template,
1894 .count = TF_DEC_TEST_VECTORS
1900 .test = alg_test_skcipher,
1904 .vecs = xeta_enc_tv_template,
1905 .count = XETA_ENC_TEST_VECTORS
1908 .vecs = xeta_dec_tv_template,
1909 .count = XETA_DEC_TEST_VECTORS
1915 .test = alg_test_skcipher,
1919 .vecs = xtea_enc_tv_template,
1920 .count = XTEA_ENC_TEST_VECTORS
1923 .vecs = xtea_dec_tv_template,
1924 .count = XTEA_DEC_TEST_VECTORS
1930 .test = alg_test_aead,
1935 .vecs = aes_gcm_enc_tv_template,
1936 .count = AES_GCM_ENC_TEST_VECTORS
1939 .vecs = aes_gcm_dec_tv_template,
1940 .count = AES_GCM_DEC_TEST_VECTORS
1946 .test = alg_test_hash,
1949 .vecs = hmac_md5_tv_template,
1950 .count = HMAC_MD5_TEST_VECTORS
1954 .alg = "hmac(rmd128)",
1955 .test = alg_test_hash,
1958 .vecs = hmac_rmd128_tv_template,
1959 .count = HMAC_RMD128_TEST_VECTORS
1963 .alg = "hmac(rmd160)",
1964 .test = alg_test_hash,
1967 .vecs = hmac_rmd160_tv_template,
1968 .count = HMAC_RMD160_TEST_VECTORS
1972 .alg = "hmac(sha1)",
1973 .test = alg_test_hash,
1977 .vecs = hmac_sha1_tv_template,
1978 .count = HMAC_SHA1_TEST_VECTORS
1982 .alg = "hmac(sha224)",
1983 .test = alg_test_hash,
1987 .vecs = hmac_sha224_tv_template,
1988 .count = HMAC_SHA224_TEST_VECTORS
1992 .alg = "hmac(sha256)",
1993 .test = alg_test_hash,
1997 .vecs = hmac_sha256_tv_template,
1998 .count = HMAC_SHA256_TEST_VECTORS
2002 .alg = "hmac(sha384)",
2003 .test = alg_test_hash,
2007 .vecs = hmac_sha384_tv_template,
2008 .count = HMAC_SHA384_TEST_VECTORS
2012 .alg = "hmac(sha512)",
2013 .test = alg_test_hash,
2017 .vecs = hmac_sha512_tv_template,
2018 .count = HMAC_SHA512_TEST_VECTORS
2023 .test = alg_test_skcipher,
2027 .vecs = aes_lrw_enc_tv_template,
2028 .count = AES_LRW_ENC_TEST_VECTORS
2031 .vecs = aes_lrw_dec_tv_template,
2032 .count = AES_LRW_DEC_TEST_VECTORS
2038 .test = alg_test_comp,
2042 .vecs = lzo_comp_tv_template,
2043 .count = LZO_COMP_TEST_VECTORS
2046 .vecs = lzo_decomp_tv_template,
2047 .count = LZO_DECOMP_TEST_VECTORS
2053 .test = alg_test_hash,
2056 .vecs = md4_tv_template,
2057 .count = MD4_TEST_VECTORS
2062 .test = alg_test_hash,
2065 .vecs = md5_tv_template,
2066 .count = MD5_TEST_VECTORS
2070 .alg = "michael_mic",
2071 .test = alg_test_hash,
2074 .vecs = michael_mic_tv_template,
2075 .count = MICHAEL_MIC_TEST_VECTORS
2079 .alg = "pcbc(fcrypt)",
2080 .test = alg_test_skcipher,
2084 .vecs = fcrypt_pcbc_enc_tv_template,
2085 .count = FCRYPT_ENC_TEST_VECTORS
2088 .vecs = fcrypt_pcbc_dec_tv_template,
2089 .count = FCRYPT_DEC_TEST_VECTORS
2094 .alg = "rfc3686(ctr(aes))",
2095 .test = alg_test_skcipher,
2100 .vecs = aes_ctr_rfc3686_enc_tv_template,
2101 .count = AES_CTR_3686_ENC_TEST_VECTORS
2104 .vecs = aes_ctr_rfc3686_dec_tv_template,
2105 .count = AES_CTR_3686_DEC_TEST_VECTORS
2110 .alg = "rfc4309(ccm(aes))",
2111 .test = alg_test_aead,
2116 .vecs = aes_ccm_rfc4309_enc_tv_template,
2117 .count = AES_CCM_4309_ENC_TEST_VECTORS
2120 .vecs = aes_ccm_rfc4309_dec_tv_template,
2121 .count = AES_CCM_4309_DEC_TEST_VECTORS
2127 .test = alg_test_hash,
2130 .vecs = rmd128_tv_template,
2131 .count = RMD128_TEST_VECTORS
2136 .test = alg_test_hash,
2139 .vecs = rmd160_tv_template,
2140 .count = RMD160_TEST_VECTORS
2145 .test = alg_test_hash,
2148 .vecs = rmd256_tv_template,
2149 .count = RMD256_TEST_VECTORS
2154 .test = alg_test_hash,
2157 .vecs = rmd320_tv_template,
2158 .count = RMD320_TEST_VECTORS
2163 .test = alg_test_skcipher,
2167 .vecs = salsa20_stream_enc_tv_template,
2168 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2174 .test = alg_test_hash,
2178 .vecs = sha1_tv_template,
2179 .count = SHA1_TEST_VECTORS
2184 .test = alg_test_hash,
2188 .vecs = sha224_tv_template,
2189 .count = SHA224_TEST_VECTORS
2194 .test = alg_test_hash,
2198 .vecs = sha256_tv_template,
2199 .count = SHA256_TEST_VECTORS
2204 .test = alg_test_hash,
2208 .vecs = sha384_tv_template,
2209 .count = SHA384_TEST_VECTORS
2214 .test = alg_test_hash,
2218 .vecs = sha512_tv_template,
2219 .count = SHA512_TEST_VECTORS
2224 .test = alg_test_hash,
2227 .vecs = tgr128_tv_template,
2228 .count = TGR128_TEST_VECTORS
2233 .test = alg_test_hash,
2236 .vecs = tgr160_tv_template,
2237 .count = TGR160_TEST_VECTORS
2242 .test = alg_test_hash,
2245 .vecs = tgr192_tv_template,
2246 .count = TGR192_TEST_VECTORS
2251 .test = alg_test_hash,
2254 .vecs = wp256_tv_template,
2255 .count = WP256_TEST_VECTORS
2260 .test = alg_test_hash,
2263 .vecs = wp384_tv_template,
2264 .count = WP384_TEST_VECTORS
2269 .test = alg_test_hash,
2272 .vecs = wp512_tv_template,
2273 .count = WP512_TEST_VECTORS
2278 .test = alg_test_hash,
2281 .vecs = aes_xcbc128_tv_template,
2282 .count = XCBC_AES_TEST_VECTORS
2287 .test = alg_test_skcipher,
2291 .vecs = aes_xts_enc_tv_template,
2292 .count = AES_XTS_ENC_TEST_VECTORS
2295 .vecs = aes_xts_dec_tv_template,
2296 .count = AES_XTS_DEC_TEST_VECTORS
2302 .test = alg_test_pcomp,
2306 .vecs = zlib_comp_tv_template,
2307 .count = ZLIB_COMP_TEST_VECTORS
2310 .vecs = zlib_decomp_tv_template,
2311 .count = ZLIB_DECOMP_TEST_VECTORS
2318 static int alg_find_test(const char *alg)
2321 int end = ARRAY_SIZE(alg_test_descs);
2323 while (start < end) {
2324 int i = (start + end) / 2;
2325 int diff = strcmp(alg_test_descs[i].alg, alg);
2343 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2348 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
2349 char nalg[CRYPTO_MAX_ALG_NAME];
2351 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
2353 return -ENAMETOOLONG;
2355 i = alg_find_test(nalg);
2359 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2362 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2366 i = alg_find_test(alg);
2370 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2373 rc = alg_test_descs[i].test(alg_test_descs + i, driver,
2376 if (fips_enabled && rc)
2377 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2379 if (fips_enabled && !rc)
2380 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2386 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2391 EXPORT_SYMBOL_GPL(alg_test);