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);
184 for (i = 0; i < tcount; i++) {
189 memset(result, 0, 64);
193 memcpy(hash_buff, template[i].plaintext, template[i].psize);
194 sg_init_one(&sg[0], hash_buff, template[i].psize);
196 if (template[i].ksize) {
197 crypto_ahash_clear_flags(tfm, ~0);
198 ret = crypto_ahash_setkey(tfm, template[i].key,
201 printk(KERN_ERR "alg: hash: setkey failed on "
202 "test %d for %s: ret=%d\n", j, algo,
208 ahash_request_set_crypt(req, sg, result, template[i].psize);
209 ret = crypto_ahash_digest(req);
215 ret = wait_for_completion_interruptible(
216 &tresult.completion);
217 if (!ret && !(ret = tresult.err)) {
218 INIT_COMPLETION(tresult.completion);
223 printk(KERN_ERR "alg: hash: digest failed on test %d "
224 "for %s: ret=%d\n", j, algo, -ret);
228 if (memcmp(result, template[i].digest,
229 crypto_ahash_digestsize(tfm))) {
230 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
232 hexdump(result, crypto_ahash_digestsize(tfm));
239 for (i = 0; i < tcount; i++) {
240 if (template[i].np) {
242 memset(result, 0, 64);
245 sg_init_table(sg, template[i].np);
247 for (k = 0; k < template[i].np; k++) {
248 if (WARN_ON(offset_in_page(IDX[k]) +
249 template[i].tap[k] > PAGE_SIZE))
252 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
253 offset_in_page(IDX[k]),
254 template[i].plaintext + temp,
257 temp += template[i].tap[k];
260 if (template[i].ksize) {
261 crypto_ahash_clear_flags(tfm, ~0);
262 ret = crypto_ahash_setkey(tfm, template[i].key,
266 printk(KERN_ERR "alg: hash: setkey "
267 "failed on chunking test %d "
268 "for %s: ret=%d\n", j, algo,
274 ahash_request_set_crypt(req, sg, result,
276 ret = crypto_ahash_digest(req);
282 ret = wait_for_completion_interruptible(
283 &tresult.completion);
284 if (!ret && !(ret = tresult.err)) {
285 INIT_COMPLETION(tresult.completion);
290 printk(KERN_ERR "alg: hash: digest failed "
291 "on chunking test %d for %s: "
292 "ret=%d\n", j, algo, -ret);
296 if (memcmp(result, template[i].digest,
297 crypto_ahash_digestsize(tfm))) {
298 printk(KERN_ERR "alg: hash: Chunking test %d "
299 "failed for %s\n", j, algo);
300 hexdump(result, crypto_ahash_digestsize(tfm));
310 ahash_request_free(req);
312 testmgr_free_buf(xbuf);
317 static int test_aead(struct crypto_aead *tfm, int enc,
318 struct aead_testvec *template, unsigned int tcount)
320 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
321 unsigned int i, j, k, n, temp;
325 struct aead_request *req;
326 struct scatterlist sg[8];
327 struct scatterlist asg[8];
329 struct tcrypt_result result;
330 unsigned int authsize;
334 char *xbuf[XBUFSIZE];
335 char *axbuf[XBUFSIZE];
337 if (testmgr_alloc_buf(xbuf))
339 if (testmgr_alloc_buf(axbuf))
347 init_completion(&result.completion);
349 req = aead_request_alloc(tfm, GFP_KERNEL);
351 printk(KERN_ERR "alg: aead: Failed to allocate request for "
356 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
357 tcrypt_complete, &result);
359 for (i = 0, j = 0; i < tcount; i++) {
360 if (!template[i].np) {
363 /* some tepmplates have no input data but they will
370 if (WARN_ON(template[i].ilen > PAGE_SIZE ||
371 template[i].alen > PAGE_SIZE))
374 memcpy(input, template[i].input, template[i].ilen);
375 memcpy(assoc, template[i].assoc, template[i].alen);
377 memcpy(iv, template[i].iv, MAX_IVLEN);
379 memset(iv, 0, MAX_IVLEN);
381 crypto_aead_clear_flags(tfm, ~0);
383 crypto_aead_set_flags(
384 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
386 key = template[i].key;
388 ret = crypto_aead_setkey(tfm, key,
390 if (!ret == template[i].fail) {
391 printk(KERN_ERR "alg: aead: setkey failed on "
392 "test %d for %s: flags=%x\n", j, algo,
393 crypto_aead_get_flags(tfm));
398 authsize = abs(template[i].rlen - template[i].ilen);
399 ret = crypto_aead_setauthsize(tfm, authsize);
401 printk(KERN_ERR "alg: aead: Failed to set "
402 "authsize to %u on test %d for %s\n",
407 sg_init_one(&sg[0], input,
408 template[i].ilen + (enc ? authsize : 0));
410 sg_init_one(&asg[0], assoc, template[i].alen);
412 aead_request_set_crypt(req, sg, sg,
413 template[i].ilen, iv);
415 aead_request_set_assoc(req, asg, template[i].alen);
418 crypto_aead_encrypt(req) :
419 crypto_aead_decrypt(req);
423 if (template[i].novrfy) {
424 /* verification was supposed to fail */
425 printk(KERN_ERR "alg: aead: %s failed "
426 "on test %d for %s: ret was 0, "
427 "expected -EBADMSG\n",
429 /* so really, we got a bad message */
436 ret = wait_for_completion_interruptible(
438 if (!ret && !(ret = result.err)) {
439 INIT_COMPLETION(result.completion);
443 if (template[i].novrfy)
444 /* verification failure was expected */
448 printk(KERN_ERR "alg: aead: %s failed on test "
449 "%d for %s: ret=%d\n", e, j, algo, -ret);
454 if (memcmp(q, template[i].result, template[i].rlen)) {
455 printk(KERN_ERR "alg: aead: Test %d failed on "
456 "%s for %s\n", j, e, algo);
457 hexdump(q, template[i].rlen);
464 for (i = 0, j = 0; i < tcount; i++) {
465 if (template[i].np) {
469 memcpy(iv, template[i].iv, MAX_IVLEN);
471 memset(iv, 0, MAX_IVLEN);
473 crypto_aead_clear_flags(tfm, ~0);
475 crypto_aead_set_flags(
476 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
477 key = template[i].key;
479 ret = crypto_aead_setkey(tfm, key, template[i].klen);
480 if (!ret == template[i].fail) {
481 printk(KERN_ERR "alg: aead: setkey failed on "
482 "chunk test %d for %s: flags=%x\n", j,
483 algo, crypto_aead_get_flags(tfm));
488 authsize = abs(template[i].rlen - template[i].ilen);
491 sg_init_table(sg, template[i].np);
492 for (k = 0, temp = 0; k < template[i].np; k++) {
493 if (WARN_ON(offset_in_page(IDX[k]) +
494 template[i].tap[k] > PAGE_SIZE))
497 q = xbuf[IDX[k] >> PAGE_SHIFT] +
498 offset_in_page(IDX[k]);
500 memcpy(q, template[i].input + temp,
503 n = template[i].tap[k];
504 if (k == template[i].np - 1 && enc)
506 if (offset_in_page(q) + n < PAGE_SIZE)
509 sg_set_buf(&sg[k], q, template[i].tap[k]);
510 temp += template[i].tap[k];
513 ret = crypto_aead_setauthsize(tfm, authsize);
515 printk(KERN_ERR "alg: aead: Failed to set "
516 "authsize to %u on chunk test %d for "
517 "%s\n", authsize, j, algo);
522 if (WARN_ON(sg[k - 1].offset +
523 sg[k - 1].length + authsize >
529 sg[k - 1].length += authsize;
532 sg_init_table(asg, template[i].anp);
534 for (k = 0, temp = 0; k < template[i].anp; k++) {
535 if (WARN_ON(offset_in_page(IDX[k]) +
536 template[i].atap[k] > PAGE_SIZE))
539 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
540 offset_in_page(IDX[k]),
541 template[i].assoc + temp,
542 template[i].atap[k]),
543 template[i].atap[k]);
544 temp += template[i].atap[k];
547 aead_request_set_crypt(req, sg, sg,
551 aead_request_set_assoc(req, asg, template[i].alen);
554 crypto_aead_encrypt(req) :
555 crypto_aead_decrypt(req);
559 if (template[i].novrfy) {
560 /* verification was supposed to fail */
561 printk(KERN_ERR "alg: aead: %s failed "
562 "on chunk test %d for %s: ret "
563 "was 0, expected -EBADMSG\n",
565 /* so really, we got a bad message */
572 ret = wait_for_completion_interruptible(
574 if (!ret && !(ret = result.err)) {
575 INIT_COMPLETION(result.completion);
579 if (template[i].novrfy)
580 /* verification failure was expected */
584 printk(KERN_ERR "alg: aead: %s failed on "
585 "chunk test %d for %s: ret=%d\n", e, j,
591 for (k = 0, temp = 0; k < template[i].np; k++) {
592 q = xbuf[IDX[k] >> PAGE_SHIFT] +
593 offset_in_page(IDX[k]);
595 n = template[i].tap[k];
596 if (k == template[i].np - 1)
597 n += enc ? authsize : -authsize;
599 if (memcmp(q, template[i].result + temp, n)) {
600 printk(KERN_ERR "alg: aead: Chunk "
601 "test %d failed on %s at page "
602 "%u for %s\n", j, e, k, algo);
608 if (k == template[i].np - 1 && !enc) {
609 if (memcmp(q, template[i].input +
615 for (n = 0; offset_in_page(q + n) &&
620 printk(KERN_ERR "alg: aead: Result "
621 "buffer corruption in chunk "
622 "test %d on %s at page %u for "
623 "%s: %u bytes:\n", j, e, k,
629 temp += template[i].tap[k];
637 aead_request_free(req);
638 testmgr_free_buf(axbuf);
640 testmgr_free_buf(xbuf);
645 static int test_cipher(struct crypto_cipher *tfm, int enc,
646 struct cipher_testvec *template, unsigned int tcount)
648 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
649 unsigned int i, j, k;
653 char *xbuf[XBUFSIZE];
656 if (testmgr_alloc_buf(xbuf))
665 for (i = 0; i < tcount; i++) {
672 if (WARN_ON(template[i].ilen > PAGE_SIZE))
676 memcpy(data, template[i].input, template[i].ilen);
678 crypto_cipher_clear_flags(tfm, ~0);
680 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
682 ret = crypto_cipher_setkey(tfm, template[i].key,
684 if (!ret == template[i].fail) {
685 printk(KERN_ERR "alg: cipher: setkey failed "
686 "on test %d for %s: flags=%x\n", j,
687 algo, crypto_cipher_get_flags(tfm));
692 for (k = 0; k < template[i].ilen;
693 k += crypto_cipher_blocksize(tfm)) {
695 crypto_cipher_encrypt_one(tfm, data + k,
698 crypto_cipher_decrypt_one(tfm, data + k,
703 if (memcmp(q, template[i].result, template[i].rlen)) {
704 printk(KERN_ERR "alg: cipher: Test %d failed "
705 "on %s for %s\n", j, e, algo);
706 hexdump(q, template[i].rlen);
715 testmgr_free_buf(xbuf);
720 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
721 struct cipher_testvec *template, unsigned int tcount)
724 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
725 unsigned int i, j, k, n, temp;
727 struct ablkcipher_request *req;
728 struct scatterlist sg[8];
730 struct tcrypt_result result;
733 char *xbuf[XBUFSIZE];
736 if (testmgr_alloc_buf(xbuf))
744 init_completion(&result.completion);
746 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
748 printk(KERN_ERR "alg: skcipher: Failed to allocate request "
753 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
754 tcrypt_complete, &result);
757 for (i = 0; i < tcount; i++) {
759 memcpy(iv, template[i].iv, MAX_IVLEN);
761 memset(iv, 0, MAX_IVLEN);
763 if (!(template[i].np)) {
767 if (WARN_ON(template[i].ilen > PAGE_SIZE))
771 memcpy(data, template[i].input, template[i].ilen);
773 crypto_ablkcipher_clear_flags(tfm, ~0);
775 crypto_ablkcipher_set_flags(
776 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
778 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
780 if (!ret == template[i].fail) {
781 printk(KERN_ERR "alg: skcipher: setkey failed "
782 "on test %d for %s: flags=%x\n", j,
783 algo, crypto_ablkcipher_get_flags(tfm));
788 sg_init_one(&sg[0], data, template[i].ilen);
790 ablkcipher_request_set_crypt(req, sg, sg,
791 template[i].ilen, iv);
793 crypto_ablkcipher_encrypt(req) :
794 crypto_ablkcipher_decrypt(req);
801 ret = wait_for_completion_interruptible(
803 if (!ret && !((ret = result.err))) {
804 INIT_COMPLETION(result.completion);
809 printk(KERN_ERR "alg: skcipher: %s failed on "
810 "test %d for %s: ret=%d\n", e, j, algo,
816 if (memcmp(q, template[i].result, template[i].rlen)) {
817 printk(KERN_ERR "alg: skcipher: Test %d "
818 "failed on %s for %s\n", j, e, algo);
819 hexdump(q, template[i].rlen);
827 for (i = 0; i < tcount; i++) {
830 memcpy(iv, template[i].iv, MAX_IVLEN);
832 memset(iv, 0, MAX_IVLEN);
834 if (template[i].np) {
837 crypto_ablkcipher_clear_flags(tfm, ~0);
839 crypto_ablkcipher_set_flags(
840 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
842 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
844 if (!ret == template[i].fail) {
845 printk(KERN_ERR "alg: skcipher: setkey failed "
846 "on chunk test %d for %s: flags=%x\n",
848 crypto_ablkcipher_get_flags(tfm));
855 sg_init_table(sg, template[i].np);
856 for (k = 0; k < template[i].np; k++) {
857 if (WARN_ON(offset_in_page(IDX[k]) +
858 template[i].tap[k] > PAGE_SIZE))
861 q = xbuf[IDX[k] >> PAGE_SHIFT] +
862 offset_in_page(IDX[k]);
864 memcpy(q, template[i].input + temp,
867 if (offset_in_page(q) + template[i].tap[k] <
869 q[template[i].tap[k]] = 0;
871 sg_set_buf(&sg[k], q, template[i].tap[k]);
873 temp += template[i].tap[k];
876 ablkcipher_request_set_crypt(req, sg, sg,
877 template[i].ilen, iv);
880 crypto_ablkcipher_encrypt(req) :
881 crypto_ablkcipher_decrypt(req);
888 ret = wait_for_completion_interruptible(
890 if (!ret && !((ret = result.err))) {
891 INIT_COMPLETION(result.completion);
896 printk(KERN_ERR "alg: skcipher: %s failed on "
897 "chunk test %d for %s: ret=%d\n", e, j,
904 for (k = 0; k < template[i].np; k++) {
905 q = xbuf[IDX[k] >> PAGE_SHIFT] +
906 offset_in_page(IDX[k]);
908 if (memcmp(q, template[i].result + temp,
909 template[i].tap[k])) {
910 printk(KERN_ERR "alg: skcipher: Chunk "
911 "test %d failed on %s at page "
912 "%u for %s\n", j, e, k, algo);
913 hexdump(q, template[i].tap[k]);
917 q += template[i].tap[k];
918 for (n = 0; offset_in_page(q + n) && q[n]; n++)
921 printk(KERN_ERR "alg: skcipher: "
922 "Result buffer corruption in "
923 "chunk test %d on %s at page "
924 "%u for %s: %u bytes:\n", j, e,
929 temp += template[i].tap[k];
937 ablkcipher_request_free(req);
938 testmgr_free_buf(xbuf);
943 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
944 struct comp_testvec *dtemplate, int ctcount, int dtcount)
946 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
948 char result[COMP_BUF_SIZE];
951 for (i = 0; i < ctcount; i++) {
953 unsigned int dlen = COMP_BUF_SIZE;
955 memset(result, 0, sizeof (result));
957 ilen = ctemplate[i].inlen;
958 ret = crypto_comp_compress(tfm, ctemplate[i].input,
959 ilen, result, &dlen);
961 printk(KERN_ERR "alg: comp: compression failed "
962 "on test %d for %s: ret=%d\n", i + 1, algo,
967 if (dlen != ctemplate[i].outlen) {
968 printk(KERN_ERR "alg: comp: Compression test %d "
969 "failed for %s: output len = %d\n", i + 1, algo,
975 if (memcmp(result, ctemplate[i].output, dlen)) {
976 printk(KERN_ERR "alg: comp: Compression test %d "
977 "failed for %s\n", i + 1, algo);
978 hexdump(result, dlen);
984 for (i = 0; i < dtcount; i++) {
986 unsigned int dlen = COMP_BUF_SIZE;
988 memset(result, 0, sizeof (result));
990 ilen = dtemplate[i].inlen;
991 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
992 ilen, result, &dlen);
994 printk(KERN_ERR "alg: comp: decompression failed "
995 "on test %d for %s: ret=%d\n", i + 1, algo,
1000 if (dlen != dtemplate[i].outlen) {
1001 printk(KERN_ERR "alg: comp: Decompression test %d "
1002 "failed for %s: output len = %d\n", i + 1, algo,
1008 if (memcmp(result, dtemplate[i].output, dlen)) {
1009 printk(KERN_ERR "alg: comp: Decompression test %d "
1010 "failed for %s\n", i + 1, algo);
1011 hexdump(result, dlen);
1023 static int test_pcomp(struct crypto_pcomp *tfm,
1024 struct pcomp_testvec *ctemplate,
1025 struct pcomp_testvec *dtemplate, int ctcount,
1028 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
1030 char result[COMP_BUF_SIZE];
1033 for (i = 0; i < ctcount; i++) {
1034 struct comp_request req;
1035 unsigned int produced = 0;
1037 res = crypto_compress_setup(tfm, ctemplate[i].params,
1038 ctemplate[i].paramsize);
1040 pr_err("alg: pcomp: compression setup failed on test "
1041 "%d for %s: error=%d\n", i + 1, algo, res);
1045 res = crypto_compress_init(tfm);
1047 pr_err("alg: pcomp: compression init failed on test "
1048 "%d for %s: error=%d\n", i + 1, algo, res);
1052 memset(result, 0, sizeof(result));
1054 req.next_in = ctemplate[i].input;
1055 req.avail_in = ctemplate[i].inlen / 2;
1056 req.next_out = result;
1057 req.avail_out = ctemplate[i].outlen / 2;
1059 res = crypto_compress_update(tfm, &req);
1060 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1061 pr_err("alg: pcomp: compression update failed on test "
1062 "%d for %s: error=%d\n", i + 1, algo, res);
1068 /* Add remaining input data */
1069 req.avail_in += (ctemplate[i].inlen + 1) / 2;
1071 res = crypto_compress_update(tfm, &req);
1072 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1073 pr_err("alg: pcomp: compression update failed on test "
1074 "%d for %s: error=%d\n", i + 1, algo, res);
1080 /* Provide remaining output space */
1081 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
1083 res = crypto_compress_final(tfm, &req);
1085 pr_err("alg: pcomp: compression final failed on test "
1086 "%d for %s: error=%d\n", i + 1, algo, res);
1091 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
1092 pr_err("alg: comp: Compression test %d failed for %s: "
1093 "output len = %d (expected %d)\n", i + 1, algo,
1094 COMP_BUF_SIZE - req.avail_out,
1095 ctemplate[i].outlen);
1099 if (produced != ctemplate[i].outlen) {
1100 pr_err("alg: comp: Compression test %d failed for %s: "
1101 "returned len = %u (expected %d)\n", i + 1,
1102 algo, produced, ctemplate[i].outlen);
1106 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
1107 pr_err("alg: pcomp: Compression test %d failed for "
1108 "%s\n", i + 1, algo);
1109 hexdump(result, ctemplate[i].outlen);
1114 for (i = 0; i < dtcount; i++) {
1115 struct comp_request req;
1116 unsigned int produced = 0;
1118 res = crypto_decompress_setup(tfm, dtemplate[i].params,
1119 dtemplate[i].paramsize);
1121 pr_err("alg: pcomp: decompression setup failed on "
1122 "test %d for %s: error=%d\n", i + 1, algo, res);
1126 res = crypto_decompress_init(tfm);
1128 pr_err("alg: pcomp: decompression init failed on test "
1129 "%d for %s: error=%d\n", i + 1, algo, res);
1133 memset(result, 0, sizeof(result));
1135 req.next_in = dtemplate[i].input;
1136 req.avail_in = dtemplate[i].inlen / 2;
1137 req.next_out = result;
1138 req.avail_out = dtemplate[i].outlen / 2;
1140 res = crypto_decompress_update(tfm, &req);
1141 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1142 pr_err("alg: pcomp: decompression update failed on "
1143 "test %d for %s: error=%d\n", i + 1, algo, res);
1149 /* Add remaining input data */
1150 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1152 res = crypto_decompress_update(tfm, &req);
1153 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1154 pr_err("alg: pcomp: decompression update failed on "
1155 "test %d for %s: error=%d\n", i + 1, algo, res);
1161 /* Provide remaining output space */
1162 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1164 res = crypto_decompress_final(tfm, &req);
1165 if (res < 0 && (res != -EAGAIN || req.avail_in)) {
1166 pr_err("alg: pcomp: decompression final failed on "
1167 "test %d for %s: error=%d\n", i + 1, algo, res);
1173 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1174 pr_err("alg: comp: Decompression test %d failed for "
1175 "%s: output len = %d (expected %d)\n", i + 1,
1176 algo, COMP_BUF_SIZE - req.avail_out,
1177 dtemplate[i].outlen);
1181 if (produced != dtemplate[i].outlen) {
1182 pr_err("alg: comp: Decompression test %d failed for "
1183 "%s: returned len = %u (expected %d)\n", i + 1,
1184 algo, produced, dtemplate[i].outlen);
1188 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1189 pr_err("alg: pcomp: Decompression test %d failed for "
1190 "%s\n", i + 1, algo);
1191 hexdump(result, dtemplate[i].outlen);
1200 static int test_cprng(struct crypto_rng *tfm, struct cprng_testvec *template,
1201 unsigned int tcount)
1203 const char *algo = crypto_tfm_alg_driver_name(crypto_rng_tfm(tfm));
1204 int err, i, j, seedsize;
1208 seedsize = crypto_rng_seedsize(tfm);
1210 seed = kmalloc(seedsize, GFP_KERNEL);
1212 printk(KERN_ERR "alg: cprng: Failed to allocate seed space "
1217 for (i = 0; i < tcount; i++) {
1218 memset(result, 0, 32);
1220 memcpy(seed, template[i].v, template[i].vlen);
1221 memcpy(seed + template[i].vlen, template[i].key,
1223 memcpy(seed + template[i].vlen + template[i].klen,
1224 template[i].dt, template[i].dtlen);
1226 err = crypto_rng_reset(tfm, seed, seedsize);
1228 printk(KERN_ERR "alg: cprng: Failed to reset rng "
1233 for (j = 0; j < template[i].loops; j++) {
1234 err = crypto_rng_get_bytes(tfm, result,
1236 if (err != template[i].rlen) {
1237 printk(KERN_ERR "alg: cprng: Failed to obtain "
1238 "the correct amount of random data for "
1239 "%s (requested %d, got %d)\n", algo,
1240 template[i].rlen, err);
1245 err = memcmp(result, template[i].result,
1248 printk(KERN_ERR "alg: cprng: Test %d failed for %s\n",
1250 hexdump(result, template[i].rlen);
1261 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
1264 struct crypto_aead *tfm;
1267 tfm = crypto_alloc_aead(driver, type, mask);
1269 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
1270 "%ld\n", driver, PTR_ERR(tfm));
1271 return PTR_ERR(tfm);
1274 if (desc->suite.aead.enc.vecs) {
1275 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
1276 desc->suite.aead.enc.count);
1281 if (!err && desc->suite.aead.dec.vecs)
1282 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
1283 desc->suite.aead.dec.count);
1286 crypto_free_aead(tfm);
1290 static int alg_test_cipher(const struct alg_test_desc *desc,
1291 const char *driver, u32 type, u32 mask)
1293 struct crypto_cipher *tfm;
1296 tfm = crypto_alloc_cipher(driver, type, mask);
1298 printk(KERN_ERR "alg: cipher: Failed to load transform for "
1299 "%s: %ld\n", driver, PTR_ERR(tfm));
1300 return PTR_ERR(tfm);
1303 if (desc->suite.cipher.enc.vecs) {
1304 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1305 desc->suite.cipher.enc.count);
1310 if (desc->suite.cipher.dec.vecs)
1311 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1312 desc->suite.cipher.dec.count);
1315 crypto_free_cipher(tfm);
1319 static int alg_test_skcipher(const struct alg_test_desc *desc,
1320 const char *driver, u32 type, u32 mask)
1322 struct crypto_ablkcipher *tfm;
1325 tfm = crypto_alloc_ablkcipher(driver, type, mask);
1327 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
1328 "%s: %ld\n", driver, PTR_ERR(tfm));
1329 return PTR_ERR(tfm);
1332 if (desc->suite.cipher.enc.vecs) {
1333 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
1334 desc->suite.cipher.enc.count);
1339 if (desc->suite.cipher.dec.vecs)
1340 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
1341 desc->suite.cipher.dec.count);
1344 crypto_free_ablkcipher(tfm);
1348 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1351 struct crypto_comp *tfm;
1354 tfm = crypto_alloc_comp(driver, type, mask);
1356 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
1357 "%ld\n", driver, PTR_ERR(tfm));
1358 return PTR_ERR(tfm);
1361 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1362 desc->suite.comp.decomp.vecs,
1363 desc->suite.comp.comp.count,
1364 desc->suite.comp.decomp.count);
1366 crypto_free_comp(tfm);
1370 static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1373 struct crypto_pcomp *tfm;
1376 tfm = crypto_alloc_pcomp(driver, type, mask);
1378 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1379 driver, PTR_ERR(tfm));
1380 return PTR_ERR(tfm);
1383 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1384 desc->suite.pcomp.decomp.vecs,
1385 desc->suite.pcomp.comp.count,
1386 desc->suite.pcomp.decomp.count);
1388 crypto_free_pcomp(tfm);
1392 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1395 struct crypto_ahash *tfm;
1398 tfm = crypto_alloc_ahash(driver, type, mask);
1400 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1401 "%ld\n", driver, PTR_ERR(tfm));
1402 return PTR_ERR(tfm);
1405 err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
1407 crypto_free_ahash(tfm);
1411 static int alg_test_crc32c(const struct alg_test_desc *desc,
1412 const char *driver, u32 type, u32 mask)
1414 struct crypto_shash *tfm;
1418 err = alg_test_hash(desc, driver, type, mask);
1422 tfm = crypto_alloc_shash(driver, type, mask);
1424 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1425 "%ld\n", driver, PTR_ERR(tfm));
1432 struct shash_desc shash;
1433 char ctx[crypto_shash_descsize(tfm)];
1436 sdesc.shash.tfm = tfm;
1437 sdesc.shash.flags = 0;
1439 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1440 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1442 printk(KERN_ERR "alg: crc32c: Operation failed for "
1443 "%s: %d\n", driver, err);
1447 if (val != ~420553207) {
1448 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1449 "%d\n", driver, val);
1454 crypto_free_shash(tfm);
1460 static int alg_test_cprng(const struct alg_test_desc *desc, const char *driver,
1463 struct crypto_rng *rng;
1466 rng = crypto_alloc_rng(driver, type, mask);
1468 printk(KERN_ERR "alg: cprng: Failed to load transform for %s: "
1469 "%ld\n", driver, PTR_ERR(rng));
1470 return PTR_ERR(rng);
1473 err = test_cprng(rng, desc->suite.cprng.vecs, desc->suite.cprng.count);
1475 crypto_free_rng(rng);
1480 /* Please keep this list sorted by algorithm name. */
1481 static const struct alg_test_desc alg_test_descs[] = {
1483 .alg = "ansi_cprng",
1484 .test = alg_test_cprng,
1488 .vecs = ansi_cprng_aes_tv_template,
1489 .count = ANSI_CPRNG_AES_TEST_VECTORS
1494 .test = alg_test_skcipher,
1499 .vecs = aes_cbc_enc_tv_template,
1500 .count = AES_CBC_ENC_TEST_VECTORS
1503 .vecs = aes_cbc_dec_tv_template,
1504 .count = AES_CBC_DEC_TEST_VECTORS
1509 .alg = "cbc(anubis)",
1510 .test = alg_test_skcipher,
1514 .vecs = anubis_cbc_enc_tv_template,
1515 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1518 .vecs = anubis_cbc_dec_tv_template,
1519 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1524 .alg = "cbc(blowfish)",
1525 .test = alg_test_skcipher,
1529 .vecs = bf_cbc_enc_tv_template,
1530 .count = BF_CBC_ENC_TEST_VECTORS
1533 .vecs = bf_cbc_dec_tv_template,
1534 .count = BF_CBC_DEC_TEST_VECTORS
1539 .alg = "cbc(camellia)",
1540 .test = alg_test_skcipher,
1544 .vecs = camellia_cbc_enc_tv_template,
1545 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1548 .vecs = camellia_cbc_dec_tv_template,
1549 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1555 .test = alg_test_skcipher,
1559 .vecs = des_cbc_enc_tv_template,
1560 .count = DES_CBC_ENC_TEST_VECTORS
1563 .vecs = des_cbc_dec_tv_template,
1564 .count = DES_CBC_DEC_TEST_VECTORS
1569 .alg = "cbc(des3_ede)",
1570 .test = alg_test_skcipher,
1575 .vecs = des3_ede_cbc_enc_tv_template,
1576 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1579 .vecs = des3_ede_cbc_dec_tv_template,
1580 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1585 .alg = "cbc(twofish)",
1586 .test = alg_test_skcipher,
1590 .vecs = tf_cbc_enc_tv_template,
1591 .count = TF_CBC_ENC_TEST_VECTORS
1594 .vecs = tf_cbc_dec_tv_template,
1595 .count = TF_CBC_DEC_TEST_VECTORS
1601 .test = alg_test_aead,
1606 .vecs = aes_ccm_enc_tv_template,
1607 .count = AES_CCM_ENC_TEST_VECTORS
1610 .vecs = aes_ccm_dec_tv_template,
1611 .count = AES_CCM_DEC_TEST_VECTORS
1617 .test = alg_test_crc32c,
1621 .vecs = crc32c_tv_template,
1622 .count = CRC32C_TEST_VECTORS
1627 .test = alg_test_skcipher,
1632 .vecs = aes_ctr_enc_tv_template,
1633 .count = AES_CTR_ENC_TEST_VECTORS
1636 .vecs = aes_ctr_dec_tv_template,
1637 .count = AES_CTR_DEC_TEST_VECTORS
1642 .alg = "cts(cbc(aes))",
1643 .test = alg_test_skcipher,
1647 .vecs = cts_mode_enc_tv_template,
1648 .count = CTS_MODE_ENC_TEST_VECTORS
1651 .vecs = cts_mode_dec_tv_template,
1652 .count = CTS_MODE_DEC_TEST_VECTORS
1658 .test = alg_test_comp,
1662 .vecs = deflate_comp_tv_template,
1663 .count = DEFLATE_COMP_TEST_VECTORS
1666 .vecs = deflate_decomp_tv_template,
1667 .count = DEFLATE_DECOMP_TEST_VECTORS
1673 .test = alg_test_skcipher,
1678 .vecs = aes_enc_tv_template,
1679 .count = AES_ENC_TEST_VECTORS
1682 .vecs = aes_dec_tv_template,
1683 .count = AES_DEC_TEST_VECTORS
1688 .alg = "ecb(anubis)",
1689 .test = alg_test_skcipher,
1693 .vecs = anubis_enc_tv_template,
1694 .count = ANUBIS_ENC_TEST_VECTORS
1697 .vecs = anubis_dec_tv_template,
1698 .count = ANUBIS_DEC_TEST_VECTORS
1704 .test = alg_test_skcipher,
1708 .vecs = arc4_enc_tv_template,
1709 .count = ARC4_ENC_TEST_VECTORS
1712 .vecs = arc4_dec_tv_template,
1713 .count = ARC4_DEC_TEST_VECTORS
1718 .alg = "ecb(blowfish)",
1719 .test = alg_test_skcipher,
1723 .vecs = bf_enc_tv_template,
1724 .count = BF_ENC_TEST_VECTORS
1727 .vecs = bf_dec_tv_template,
1728 .count = BF_DEC_TEST_VECTORS
1733 .alg = "ecb(camellia)",
1734 .test = alg_test_skcipher,
1738 .vecs = camellia_enc_tv_template,
1739 .count = CAMELLIA_ENC_TEST_VECTORS
1742 .vecs = camellia_dec_tv_template,
1743 .count = CAMELLIA_DEC_TEST_VECTORS
1748 .alg = "ecb(cast5)",
1749 .test = alg_test_skcipher,
1753 .vecs = cast5_enc_tv_template,
1754 .count = CAST5_ENC_TEST_VECTORS
1757 .vecs = cast5_dec_tv_template,
1758 .count = CAST5_DEC_TEST_VECTORS
1763 .alg = "ecb(cast6)",
1764 .test = alg_test_skcipher,
1768 .vecs = cast6_enc_tv_template,
1769 .count = CAST6_ENC_TEST_VECTORS
1772 .vecs = cast6_dec_tv_template,
1773 .count = CAST6_DEC_TEST_VECTORS
1779 .test = alg_test_skcipher,
1784 .vecs = des_enc_tv_template,
1785 .count = DES_ENC_TEST_VECTORS
1788 .vecs = des_dec_tv_template,
1789 .count = DES_DEC_TEST_VECTORS
1794 .alg = "ecb(des3_ede)",
1795 .test = alg_test_skcipher,
1800 .vecs = des3_ede_enc_tv_template,
1801 .count = DES3_EDE_ENC_TEST_VECTORS
1804 .vecs = des3_ede_dec_tv_template,
1805 .count = DES3_EDE_DEC_TEST_VECTORS
1810 .alg = "ecb(khazad)",
1811 .test = alg_test_skcipher,
1815 .vecs = khazad_enc_tv_template,
1816 .count = KHAZAD_ENC_TEST_VECTORS
1819 .vecs = khazad_dec_tv_template,
1820 .count = KHAZAD_DEC_TEST_VECTORS
1826 .test = alg_test_skcipher,
1830 .vecs = seed_enc_tv_template,
1831 .count = SEED_ENC_TEST_VECTORS
1834 .vecs = seed_dec_tv_template,
1835 .count = SEED_DEC_TEST_VECTORS
1840 .alg = "ecb(serpent)",
1841 .test = alg_test_skcipher,
1845 .vecs = serpent_enc_tv_template,
1846 .count = SERPENT_ENC_TEST_VECTORS
1849 .vecs = serpent_dec_tv_template,
1850 .count = SERPENT_DEC_TEST_VECTORS
1856 .test = alg_test_skcipher,
1860 .vecs = tea_enc_tv_template,
1861 .count = TEA_ENC_TEST_VECTORS
1864 .vecs = tea_dec_tv_template,
1865 .count = TEA_DEC_TEST_VECTORS
1870 .alg = "ecb(tnepres)",
1871 .test = alg_test_skcipher,
1875 .vecs = tnepres_enc_tv_template,
1876 .count = TNEPRES_ENC_TEST_VECTORS
1879 .vecs = tnepres_dec_tv_template,
1880 .count = TNEPRES_DEC_TEST_VECTORS
1885 .alg = "ecb(twofish)",
1886 .test = alg_test_skcipher,
1890 .vecs = tf_enc_tv_template,
1891 .count = TF_ENC_TEST_VECTORS
1894 .vecs = tf_dec_tv_template,
1895 .count = TF_DEC_TEST_VECTORS
1901 .test = alg_test_skcipher,
1905 .vecs = xeta_enc_tv_template,
1906 .count = XETA_ENC_TEST_VECTORS
1909 .vecs = xeta_dec_tv_template,
1910 .count = XETA_DEC_TEST_VECTORS
1916 .test = alg_test_skcipher,
1920 .vecs = xtea_enc_tv_template,
1921 .count = XTEA_ENC_TEST_VECTORS
1924 .vecs = xtea_dec_tv_template,
1925 .count = XTEA_DEC_TEST_VECTORS
1931 .test = alg_test_aead,
1936 .vecs = aes_gcm_enc_tv_template,
1937 .count = AES_GCM_ENC_TEST_VECTORS
1940 .vecs = aes_gcm_dec_tv_template,
1941 .count = AES_GCM_DEC_TEST_VECTORS
1947 .test = alg_test_hash,
1950 .vecs = hmac_md5_tv_template,
1951 .count = HMAC_MD5_TEST_VECTORS
1955 .alg = "hmac(rmd128)",
1956 .test = alg_test_hash,
1959 .vecs = hmac_rmd128_tv_template,
1960 .count = HMAC_RMD128_TEST_VECTORS
1964 .alg = "hmac(rmd160)",
1965 .test = alg_test_hash,
1968 .vecs = hmac_rmd160_tv_template,
1969 .count = HMAC_RMD160_TEST_VECTORS
1973 .alg = "hmac(sha1)",
1974 .test = alg_test_hash,
1978 .vecs = hmac_sha1_tv_template,
1979 .count = HMAC_SHA1_TEST_VECTORS
1983 .alg = "hmac(sha224)",
1984 .test = alg_test_hash,
1988 .vecs = hmac_sha224_tv_template,
1989 .count = HMAC_SHA224_TEST_VECTORS
1993 .alg = "hmac(sha256)",
1994 .test = alg_test_hash,
1998 .vecs = hmac_sha256_tv_template,
1999 .count = HMAC_SHA256_TEST_VECTORS
2003 .alg = "hmac(sha384)",
2004 .test = alg_test_hash,
2008 .vecs = hmac_sha384_tv_template,
2009 .count = HMAC_SHA384_TEST_VECTORS
2013 .alg = "hmac(sha512)",
2014 .test = alg_test_hash,
2018 .vecs = hmac_sha512_tv_template,
2019 .count = HMAC_SHA512_TEST_VECTORS
2024 .test = alg_test_skcipher,
2028 .vecs = aes_lrw_enc_tv_template,
2029 .count = AES_LRW_ENC_TEST_VECTORS
2032 .vecs = aes_lrw_dec_tv_template,
2033 .count = AES_LRW_DEC_TEST_VECTORS
2039 .test = alg_test_comp,
2043 .vecs = lzo_comp_tv_template,
2044 .count = LZO_COMP_TEST_VECTORS
2047 .vecs = lzo_decomp_tv_template,
2048 .count = LZO_DECOMP_TEST_VECTORS
2054 .test = alg_test_hash,
2057 .vecs = md4_tv_template,
2058 .count = MD4_TEST_VECTORS
2063 .test = alg_test_hash,
2066 .vecs = md5_tv_template,
2067 .count = MD5_TEST_VECTORS
2071 .alg = "michael_mic",
2072 .test = alg_test_hash,
2075 .vecs = michael_mic_tv_template,
2076 .count = MICHAEL_MIC_TEST_VECTORS
2080 .alg = "pcbc(fcrypt)",
2081 .test = alg_test_skcipher,
2085 .vecs = fcrypt_pcbc_enc_tv_template,
2086 .count = FCRYPT_ENC_TEST_VECTORS
2089 .vecs = fcrypt_pcbc_dec_tv_template,
2090 .count = FCRYPT_DEC_TEST_VECTORS
2095 .alg = "rfc3686(ctr(aes))",
2096 .test = alg_test_skcipher,
2101 .vecs = aes_ctr_rfc3686_enc_tv_template,
2102 .count = AES_CTR_3686_ENC_TEST_VECTORS
2105 .vecs = aes_ctr_rfc3686_dec_tv_template,
2106 .count = AES_CTR_3686_DEC_TEST_VECTORS
2111 .alg = "rfc4309(ccm(aes))",
2112 .test = alg_test_aead,
2117 .vecs = aes_ccm_rfc4309_enc_tv_template,
2118 .count = AES_CCM_4309_ENC_TEST_VECTORS
2121 .vecs = aes_ccm_rfc4309_dec_tv_template,
2122 .count = AES_CCM_4309_DEC_TEST_VECTORS
2128 .test = alg_test_hash,
2131 .vecs = rmd128_tv_template,
2132 .count = RMD128_TEST_VECTORS
2137 .test = alg_test_hash,
2140 .vecs = rmd160_tv_template,
2141 .count = RMD160_TEST_VECTORS
2146 .test = alg_test_hash,
2149 .vecs = rmd256_tv_template,
2150 .count = RMD256_TEST_VECTORS
2155 .test = alg_test_hash,
2158 .vecs = rmd320_tv_template,
2159 .count = RMD320_TEST_VECTORS
2164 .test = alg_test_skcipher,
2168 .vecs = salsa20_stream_enc_tv_template,
2169 .count = SALSA20_STREAM_ENC_TEST_VECTORS
2175 .test = alg_test_hash,
2179 .vecs = sha1_tv_template,
2180 .count = SHA1_TEST_VECTORS
2185 .test = alg_test_hash,
2189 .vecs = sha224_tv_template,
2190 .count = SHA224_TEST_VECTORS
2195 .test = alg_test_hash,
2199 .vecs = sha256_tv_template,
2200 .count = SHA256_TEST_VECTORS
2205 .test = alg_test_hash,
2209 .vecs = sha384_tv_template,
2210 .count = SHA384_TEST_VECTORS
2215 .test = alg_test_hash,
2219 .vecs = sha512_tv_template,
2220 .count = SHA512_TEST_VECTORS
2225 .test = alg_test_hash,
2228 .vecs = tgr128_tv_template,
2229 .count = TGR128_TEST_VECTORS
2234 .test = alg_test_hash,
2237 .vecs = tgr160_tv_template,
2238 .count = TGR160_TEST_VECTORS
2243 .test = alg_test_hash,
2246 .vecs = tgr192_tv_template,
2247 .count = TGR192_TEST_VECTORS
2252 .test = alg_test_hash,
2255 .vecs = aes_vmac128_tv_template,
2256 .count = VMAC_AES_TEST_VECTORS
2261 .test = alg_test_hash,
2264 .vecs = wp256_tv_template,
2265 .count = WP256_TEST_VECTORS
2270 .test = alg_test_hash,
2273 .vecs = wp384_tv_template,
2274 .count = WP384_TEST_VECTORS
2279 .test = alg_test_hash,
2282 .vecs = wp512_tv_template,
2283 .count = WP512_TEST_VECTORS
2288 .test = alg_test_hash,
2291 .vecs = aes_xcbc128_tv_template,
2292 .count = XCBC_AES_TEST_VECTORS
2297 .test = alg_test_skcipher,
2301 .vecs = aes_xts_enc_tv_template,
2302 .count = AES_XTS_ENC_TEST_VECTORS
2305 .vecs = aes_xts_dec_tv_template,
2306 .count = AES_XTS_DEC_TEST_VECTORS
2312 .test = alg_test_pcomp,
2316 .vecs = zlib_comp_tv_template,
2317 .count = ZLIB_COMP_TEST_VECTORS
2320 .vecs = zlib_decomp_tv_template,
2321 .count = ZLIB_DECOMP_TEST_VECTORS
2328 static int alg_find_test(const char *alg)
2331 int end = ARRAY_SIZE(alg_test_descs);
2333 while (start < end) {
2334 int i = (start + end) / 2;
2335 int diff = strcmp(alg_test_descs[i].alg, alg);
2353 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
2359 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
2360 char nalg[CRYPTO_MAX_ALG_NAME];
2362 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
2364 return -ENAMETOOLONG;
2366 i = alg_find_test(nalg);
2370 if (fips_enabled && !alg_test_descs[i].fips_allowed)
2373 rc = alg_test_cipher(alg_test_descs + i, driver, type, mask);
2377 i = alg_find_test(alg);
2378 j = alg_find_test(driver);
2382 if (fips_enabled && ((i >= 0 && !alg_test_descs[i].fips_allowed) ||
2383 (j >= 0 && !alg_test_descs[j].fips_allowed)))
2388 rc |= alg_test_descs[i].test(alg_test_descs + i, driver,
2391 rc |= alg_test_descs[j].test(alg_test_descs + j, driver,
2395 if (fips_enabled && rc)
2396 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
2398 if (fips_enabled && !rc)
2399 printk(KERN_INFO "alg: self-tests for %s (%s) passed\n",
2405 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
2410 EXPORT_SYMBOL_GPL(alg_test);