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>
27 * Need slab memory for testing (size in number of pages).
32 * Indexes into the xbuf to simulate cross-page access.
44 * Used by test_cipher()
49 struct tcrypt_result {
50 struct completion completion;
54 struct aead_test_suite {
56 struct aead_testvec *vecs;
61 struct cipher_test_suite {
63 struct cipher_testvec *vecs;
68 struct comp_test_suite {
70 struct comp_testvec *vecs;
75 struct hash_test_suite {
76 struct hash_testvec *vecs;
80 struct alg_test_desc {
82 int (*test)(const struct alg_test_desc *desc, const char *driver,
86 struct aead_test_suite aead;
87 struct cipher_test_suite cipher;
88 struct comp_test_suite comp;
89 struct hash_test_suite hash;
93 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
95 static char *xbuf[XBUFSIZE];
96 static char *axbuf[XBUFSIZE];
98 static void hexdump(unsigned char *buf, unsigned int len)
100 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
105 static void tcrypt_complete(struct crypto_async_request *req, int err)
107 struct tcrypt_result *res = req->data;
109 if (err == -EINPROGRESS)
113 complete(&res->completion);
116 static int test_hash(struct crypto_ahash *tfm, struct hash_testvec *template,
119 const char *algo = crypto_tfm_alg_driver_name(crypto_ahash_tfm(tfm));
120 unsigned int i, j, k, temp;
121 struct scatterlist sg[8];
123 struct ahash_request *req;
124 struct tcrypt_result tresult;
128 init_completion(&tresult.completion);
130 req = ahash_request_alloc(tfm, GFP_KERNEL);
132 printk(KERN_ERR "alg: hash: Failed to allocate request for "
137 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
138 tcrypt_complete, &tresult);
140 for (i = 0; i < tcount; i++) {
141 memset(result, 0, 64);
145 memcpy(hash_buff, template[i].plaintext, template[i].psize);
146 sg_init_one(&sg[0], hash_buff, template[i].psize);
148 if (template[i].ksize) {
149 crypto_ahash_clear_flags(tfm, ~0);
150 ret = crypto_ahash_setkey(tfm, template[i].key,
153 printk(KERN_ERR "alg: hash: setkey failed on "
154 "test %d for %s: ret=%d\n", i + 1, algo,
160 ahash_request_set_crypt(req, sg, result, template[i].psize);
161 ret = crypto_ahash_digest(req);
167 ret = wait_for_completion_interruptible(
168 &tresult.completion);
169 if (!ret && !(ret = tresult.err)) {
170 INIT_COMPLETION(tresult.completion);
175 printk(KERN_ERR "alg: hash: digest failed on test %d "
176 "for %s: ret=%d\n", i + 1, algo, -ret);
180 if (memcmp(result, template[i].digest,
181 crypto_ahash_digestsize(tfm))) {
182 printk(KERN_ERR "alg: hash: Test %d failed for %s\n",
184 hexdump(result, crypto_ahash_digestsize(tfm));
191 for (i = 0; i < tcount; i++) {
192 if (template[i].np) {
194 memset(result, 0, 64);
197 sg_init_table(sg, template[i].np);
198 for (k = 0; k < template[i].np; k++) {
200 memcpy(xbuf[IDX[k] >> PAGE_SHIFT] +
201 offset_in_page(IDX[k]),
202 template[i].plaintext + temp,
205 temp += template[i].tap[k];
208 if (template[i].ksize) {
209 crypto_ahash_clear_flags(tfm, ~0);
210 ret = crypto_ahash_setkey(tfm, template[i].key,
214 printk(KERN_ERR "alg: hash: setkey "
215 "failed on chunking test %d "
216 "for %s: ret=%d\n", j, algo,
222 ahash_request_set_crypt(req, sg, result,
224 ret = crypto_ahash_digest(req);
230 ret = wait_for_completion_interruptible(
231 &tresult.completion);
232 if (!ret && !(ret = tresult.err)) {
233 INIT_COMPLETION(tresult.completion);
238 printk(KERN_ERR "alg: hash: digest failed "
239 "on chunking test %d for %s: "
240 "ret=%d\n", j, algo, -ret);
244 if (memcmp(result, template[i].digest,
245 crypto_ahash_digestsize(tfm))) {
246 printk(KERN_ERR "alg: hash: Chunking test %d "
247 "failed for %s\n", j, algo);
248 hexdump(result, crypto_ahash_digestsize(tfm));
258 ahash_request_free(req);
263 static int test_aead(struct crypto_aead *tfm, int enc,
264 struct aead_testvec *template, unsigned int tcount)
266 const char *algo = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
267 unsigned int i, j, k, n, temp;
271 struct aead_request *req;
272 struct scatterlist sg[8];
273 struct scatterlist asg[8];
275 struct tcrypt_result result;
276 unsigned int authsize;
286 init_completion(&result.completion);
288 req = aead_request_alloc(tfm, GFP_KERNEL);
290 printk(KERN_ERR "alg: aead: Failed to allocate request for "
296 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
297 tcrypt_complete, &result);
299 for (i = 0, j = 0; i < tcount; i++) {
300 if (!template[i].np) {
303 /* some tepmplates have no input data but they will
309 memcpy(input, template[i].input, template[i].ilen);
310 memcpy(assoc, template[i].assoc, template[i].alen);
312 memcpy(iv, template[i].iv, MAX_IVLEN);
314 memset(iv, 0, MAX_IVLEN);
316 crypto_aead_clear_flags(tfm, ~0);
318 crypto_aead_set_flags(
319 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
321 key = template[i].key;
323 ret = crypto_aead_setkey(tfm, key,
325 if (!ret == template[i].fail) {
326 printk(KERN_ERR "alg: aead: setkey failed on "
327 "test %d for %s: flags=%x\n", j, algo,
328 crypto_aead_get_flags(tfm));
333 authsize = abs(template[i].rlen - template[i].ilen);
334 ret = crypto_aead_setauthsize(tfm, authsize);
336 printk(KERN_ERR "alg: aead: Failed to set "
337 "authsize to %u on test %d for %s\n",
342 sg_init_one(&sg[0], input,
343 template[i].ilen + (enc ? authsize : 0));
345 sg_init_one(&asg[0], assoc, template[i].alen);
347 aead_request_set_crypt(req, sg, sg,
348 template[i].ilen, iv);
350 aead_request_set_assoc(req, asg, template[i].alen);
353 crypto_aead_encrypt(req) :
354 crypto_aead_decrypt(req);
361 ret = wait_for_completion_interruptible(
363 if (!ret && !(ret = result.err)) {
364 INIT_COMPLETION(result.completion);
369 printk(KERN_ERR "alg: aead: %s failed on test "
370 "%d for %s: ret=%d\n", e, j, algo, -ret);
375 if (memcmp(q, template[i].result, template[i].rlen)) {
376 printk(KERN_ERR "alg: aead: Test %d failed on "
377 "%s for %s\n", j, e, algo);
378 hexdump(q, template[i].rlen);
385 for (i = 0, j = 0; i < tcount; i++) {
386 if (template[i].np) {
390 memcpy(iv, template[i].iv, MAX_IVLEN);
392 memset(iv, 0, MAX_IVLEN);
394 crypto_aead_clear_flags(tfm, ~0);
396 crypto_aead_set_flags(
397 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
398 key = template[i].key;
400 ret = crypto_aead_setkey(tfm, key, template[i].klen);
401 if (!ret == template[i].fail) {
402 printk(KERN_ERR "alg: aead: setkey failed on "
403 "chunk test %d for %s: flags=%x\n", j,
404 algo, crypto_aead_get_flags(tfm));
409 authsize = abs(template[i].rlen - template[i].ilen);
412 sg_init_table(sg, template[i].np);
413 for (k = 0, temp = 0; k < template[i].np; k++) {
414 if (WARN_ON(offset_in_page(IDX[k]) +
415 template[i].tap[k] > PAGE_SIZE))
418 q = xbuf[IDX[k] >> PAGE_SHIFT] +
419 offset_in_page(IDX[k]);
421 memcpy(q, template[i].input + temp,
424 n = template[i].tap[k];
425 if (k == template[i].np - 1 && enc)
427 if (offset_in_page(q) + n < PAGE_SIZE)
430 sg_set_buf(&sg[k], q, template[i].tap[k]);
431 temp += template[i].tap[k];
434 ret = crypto_aead_setauthsize(tfm, authsize);
436 printk(KERN_ERR "alg: aead: Failed to set "
437 "authsize to %u on chunk test %d for "
438 "%s\n", authsize, j, algo);
443 if (WARN_ON(sg[k - 1].offset +
444 sg[k - 1].length + authsize >
450 sg[k - 1].length += authsize;
453 sg_init_table(asg, template[i].anp);
454 for (k = 0, temp = 0; k < template[i].anp; k++) {
456 memcpy(axbuf[IDX[k] >> PAGE_SHIFT] +
457 offset_in_page(IDX[k]),
458 template[i].assoc + temp,
459 template[i].atap[k]),
460 template[i].atap[k]);
461 temp += template[i].atap[k];
464 aead_request_set_crypt(req, sg, sg,
468 aead_request_set_assoc(req, asg, template[i].alen);
471 crypto_aead_encrypt(req) :
472 crypto_aead_decrypt(req);
479 ret = wait_for_completion_interruptible(
481 if (!ret && !(ret = result.err)) {
482 INIT_COMPLETION(result.completion);
487 printk(KERN_ERR "alg: aead: %s failed on "
488 "chunk test %d for %s: ret=%d\n", e, j,
494 for (k = 0, temp = 0; k < template[i].np; k++) {
495 q = xbuf[IDX[k] >> PAGE_SHIFT] +
496 offset_in_page(IDX[k]);
498 n = template[i].tap[k];
499 if (k == template[i].np - 1)
500 n += enc ? authsize : -authsize;
502 if (memcmp(q, template[i].result + temp, n)) {
503 printk(KERN_ERR "alg: aead: Chunk "
504 "test %d failed on %s at page "
505 "%u for %s\n", j, e, k, algo);
511 if (k == template[i].np - 1 && !enc) {
512 if (memcmp(q, template[i].input +
518 for (n = 0; offset_in_page(q + n) &&
523 printk(KERN_ERR "alg: aead: Result "
524 "buffer corruption in chunk "
525 "test %d on %s at page %u for "
526 "%s: %u bytes:\n", j, e, k,
532 temp += template[i].tap[k];
540 aead_request_free(req);
544 static int test_cipher(struct crypto_cipher *tfm, int enc,
545 struct cipher_testvec *template, unsigned int tcount)
547 const char *algo = crypto_tfm_alg_driver_name(crypto_cipher_tfm(tfm));
548 unsigned int i, j, k;
560 for (i = 0; i < tcount; i++) {
567 memcpy(data, template[i].input, template[i].ilen);
569 crypto_cipher_clear_flags(tfm, ~0);
571 crypto_cipher_set_flags(tfm, CRYPTO_TFM_REQ_WEAK_KEY);
573 ret = crypto_cipher_setkey(tfm, template[i].key,
575 if (!ret == template[i].fail) {
576 printk(KERN_ERR "alg: cipher: setkey failed "
577 "on test %d for %s: flags=%x\n", j,
578 algo, crypto_cipher_get_flags(tfm));
583 for (k = 0; k < template[i].ilen;
584 k += crypto_cipher_blocksize(tfm)) {
586 crypto_cipher_encrypt_one(tfm, data + k,
589 crypto_cipher_decrypt_one(tfm, data + k,
594 if (memcmp(q, template[i].result, template[i].rlen)) {
595 printk(KERN_ERR "alg: cipher: Test %d failed "
596 "on %s for %s\n", j, e, algo);
597 hexdump(q, template[i].rlen);
609 static int test_skcipher(struct crypto_ablkcipher *tfm, int enc,
610 struct cipher_testvec *template, unsigned int tcount)
613 crypto_tfm_alg_driver_name(crypto_ablkcipher_tfm(tfm));
614 unsigned int i, j, k, n, temp;
617 struct ablkcipher_request *req;
618 struct scatterlist sg[8];
620 struct tcrypt_result result;
629 init_completion(&result.completion);
631 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
633 printk(KERN_ERR "alg: skcipher: Failed to allocate request "
639 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
640 tcrypt_complete, &result);
643 for (i = 0; i < tcount; i++) {
645 memcpy(iv, template[i].iv, MAX_IVLEN);
647 memset(iv, 0, MAX_IVLEN);
649 if (!(template[i].np)) {
653 memcpy(data, template[i].input, template[i].ilen);
655 crypto_ablkcipher_clear_flags(tfm, ~0);
657 crypto_ablkcipher_set_flags(
658 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
660 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
662 if (!ret == template[i].fail) {
663 printk(KERN_ERR "alg: skcipher: setkey failed "
664 "on test %d for %s: flags=%x\n", j,
665 algo, crypto_ablkcipher_get_flags(tfm));
670 sg_init_one(&sg[0], data, template[i].ilen);
672 ablkcipher_request_set_crypt(req, sg, sg,
673 template[i].ilen, iv);
675 crypto_ablkcipher_encrypt(req) :
676 crypto_ablkcipher_decrypt(req);
683 ret = wait_for_completion_interruptible(
685 if (!ret && !((ret = result.err))) {
686 INIT_COMPLETION(result.completion);
691 printk(KERN_ERR "alg: skcipher: %s failed on "
692 "test %d for %s: ret=%d\n", e, j, algo,
698 if (memcmp(q, template[i].result, template[i].rlen)) {
699 printk(KERN_ERR "alg: skcipher: Test %d "
700 "failed on %s for %s\n", j, e, algo);
701 hexdump(q, template[i].rlen);
709 for (i = 0; i < tcount; i++) {
712 memcpy(iv, template[i].iv, MAX_IVLEN);
714 memset(iv, 0, MAX_IVLEN);
716 if (template[i].np) {
719 crypto_ablkcipher_clear_flags(tfm, ~0);
721 crypto_ablkcipher_set_flags(
722 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
724 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
726 if (!ret == template[i].fail) {
727 printk(KERN_ERR "alg: skcipher: setkey failed "
728 "on chunk test %d for %s: flags=%x\n",
730 crypto_ablkcipher_get_flags(tfm));
737 sg_init_table(sg, template[i].np);
738 for (k = 0; k < template[i].np; k++) {
739 if (WARN_ON(offset_in_page(IDX[k]) +
740 template[i].tap[k] > PAGE_SIZE))
743 q = xbuf[IDX[k] >> PAGE_SHIFT] +
744 offset_in_page(IDX[k]);
746 memcpy(q, template[i].input + temp,
749 if (offset_in_page(q) + template[i].tap[k] <
751 q[template[i].tap[k]] = 0;
753 sg_set_buf(&sg[k], q, template[i].tap[k]);
755 temp += template[i].tap[k];
758 ablkcipher_request_set_crypt(req, sg, sg,
759 template[i].ilen, iv);
762 crypto_ablkcipher_encrypt(req) :
763 crypto_ablkcipher_decrypt(req);
770 ret = wait_for_completion_interruptible(
772 if (!ret && !((ret = result.err))) {
773 INIT_COMPLETION(result.completion);
778 printk(KERN_ERR "alg: skcipher: %s failed on "
779 "chunk test %d for %s: ret=%d\n", e, j,
786 for (k = 0; k < template[i].np; k++) {
787 q = xbuf[IDX[k] >> PAGE_SHIFT] +
788 offset_in_page(IDX[k]);
790 if (memcmp(q, template[i].result + temp,
791 template[i].tap[k])) {
792 printk(KERN_ERR "alg: skcipher: Chunk "
793 "test %d failed on %s at page "
794 "%u for %s\n", j, e, k, algo);
795 hexdump(q, template[i].tap[k]);
799 q += template[i].tap[k];
800 for (n = 0; offset_in_page(q + n) && q[n]; n++)
803 printk(KERN_ERR "alg: skcipher: "
804 "Result buffer corruption in "
805 "chunk test %d on %s at page "
806 "%u for %s: %u bytes:\n", j, e,
811 temp += template[i].tap[k];
819 ablkcipher_request_free(req);
823 static int test_comp(struct crypto_comp *tfm, struct comp_testvec *ctemplate,
824 struct comp_testvec *dtemplate, int ctcount, int dtcount)
826 const char *algo = crypto_tfm_alg_driver_name(crypto_comp_tfm(tfm));
828 char result[COMP_BUF_SIZE];
831 for (i = 0; i < ctcount; i++) {
832 int ilen, dlen = COMP_BUF_SIZE;
834 memset(result, 0, sizeof (result));
836 ilen = ctemplate[i].inlen;
837 ret = crypto_comp_compress(tfm, ctemplate[i].input,
838 ilen, result, &dlen);
840 printk(KERN_ERR "alg: comp: compression failed "
841 "on test %d for %s: ret=%d\n", i + 1, algo,
846 if (dlen != ctemplate[i].outlen) {
847 printk(KERN_ERR "alg: comp: Compression test %d "
848 "failed for %s: output len = %d\n", i + 1, algo,
854 if (memcmp(result, ctemplate[i].output, dlen)) {
855 printk(KERN_ERR "alg: comp: Compression test %d "
856 "failed for %s\n", i + 1, algo);
857 hexdump(result, dlen);
863 for (i = 0; i < dtcount; i++) {
864 int ilen, dlen = COMP_BUF_SIZE;
866 memset(result, 0, sizeof (result));
868 ilen = dtemplate[i].inlen;
869 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
870 ilen, result, &dlen);
872 printk(KERN_ERR "alg: comp: decompression failed "
873 "on test %d for %s: ret=%d\n", i + 1, algo,
878 if (dlen != dtemplate[i].outlen) {
879 printk(KERN_ERR "alg: comp: Decompression test %d "
880 "failed for %s: output len = %d\n", i + 1, algo,
886 if (memcmp(result, dtemplate[i].output, dlen)) {
887 printk(KERN_ERR "alg: comp: Decompression test %d "
888 "failed for %s\n", i + 1, algo);
889 hexdump(result, dlen);
901 static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
904 struct crypto_aead *tfm;
907 tfm = crypto_alloc_aead(driver, type, mask);
909 printk(KERN_ERR "alg: aead: Failed to load transform for %s: "
910 "%ld\n", driver, PTR_ERR(tfm));
914 if (desc->suite.aead.enc.vecs) {
915 err = test_aead(tfm, ENCRYPT, desc->suite.aead.enc.vecs,
916 desc->suite.aead.enc.count);
921 if (!err && desc->suite.aead.dec.vecs)
922 err = test_aead(tfm, DECRYPT, desc->suite.aead.dec.vecs,
923 desc->suite.aead.dec.count);
926 crypto_free_aead(tfm);
930 static int alg_test_cipher(const struct alg_test_desc *desc,
931 const char *driver, u32 type, u32 mask)
933 struct crypto_cipher *tfm;
936 tfm = crypto_alloc_cipher(driver, type, mask);
938 printk(KERN_ERR "alg: cipher: Failed to load transform for "
939 "%s: %ld\n", driver, PTR_ERR(tfm));
943 if (desc->suite.cipher.enc.vecs) {
944 err = test_cipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
945 desc->suite.cipher.enc.count);
950 if (desc->suite.cipher.dec.vecs)
951 err = test_cipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
952 desc->suite.cipher.dec.count);
955 crypto_free_cipher(tfm);
959 static int alg_test_skcipher(const struct alg_test_desc *desc,
960 const char *driver, u32 type, u32 mask)
962 struct crypto_ablkcipher *tfm;
965 tfm = crypto_alloc_ablkcipher(driver, type, mask);
967 printk(KERN_ERR "alg: skcipher: Failed to load transform for "
968 "%s: %ld\n", driver, PTR_ERR(tfm));
972 if (desc->suite.cipher.enc.vecs) {
973 err = test_skcipher(tfm, ENCRYPT, desc->suite.cipher.enc.vecs,
974 desc->suite.cipher.enc.count);
979 if (desc->suite.cipher.dec.vecs)
980 err = test_skcipher(tfm, DECRYPT, desc->suite.cipher.dec.vecs,
981 desc->suite.cipher.dec.count);
984 crypto_free_ablkcipher(tfm);
988 static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
991 struct crypto_comp *tfm;
994 tfm = crypto_alloc_comp(driver, type, mask);
996 printk(KERN_ERR "alg: comp: Failed to load transform for %s: "
997 "%ld\n", driver, PTR_ERR(tfm));
1001 err = test_comp(tfm, desc->suite.comp.comp.vecs,
1002 desc->suite.comp.decomp.vecs,
1003 desc->suite.comp.comp.count,
1004 desc->suite.comp.decomp.count);
1006 crypto_free_comp(tfm);
1010 static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1013 struct crypto_ahash *tfm;
1016 tfm = crypto_alloc_ahash(driver, type, mask);
1018 printk(KERN_ERR "alg: hash: Failed to load transform for %s: "
1019 "%ld\n", driver, PTR_ERR(tfm));
1020 return PTR_ERR(tfm);
1023 err = test_hash(tfm, desc->suite.hash.vecs, desc->suite.hash.count);
1025 crypto_free_ahash(tfm);
1029 static int alg_test_crc32c(const struct alg_test_desc *desc,
1030 const char *driver, u32 type, u32 mask)
1032 struct crypto_shash *tfm;
1036 err = alg_test_hash(desc, driver, type, mask);
1040 tfm = crypto_alloc_shash(driver, type, mask);
1042 printk(KERN_ERR "alg: crc32c: Failed to load transform for %s: "
1043 "%ld\n", driver, PTR_ERR(tfm));
1050 struct shash_desc shash;
1051 char ctx[crypto_shash_descsize(tfm)];
1054 sdesc.shash.tfm = tfm;
1055 sdesc.shash.flags = 0;
1057 *(u32 *)sdesc.ctx = le32_to_cpu(420553207);
1058 err = crypto_shash_final(&sdesc.shash, (u8 *)&val);
1060 printk(KERN_ERR "alg: crc32c: Operation failed for "
1061 "%s: %d\n", driver, err);
1065 if (val != ~420553207) {
1066 printk(KERN_ERR "alg: crc32c: Test failed for %s: "
1067 "%d\n", driver, val);
1072 crypto_free_shash(tfm);
1078 /* Please keep this list sorted by algorithm name. */
1079 static const struct alg_test_desc alg_test_descs[] = {
1082 .test = alg_test_skcipher,
1086 .vecs = aes_cbc_enc_tv_template,
1087 .count = AES_CBC_ENC_TEST_VECTORS
1090 .vecs = aes_cbc_dec_tv_template,
1091 .count = AES_CBC_DEC_TEST_VECTORS
1096 .alg = "cbc(anubis)",
1097 .test = alg_test_skcipher,
1101 .vecs = anubis_cbc_enc_tv_template,
1102 .count = ANUBIS_CBC_ENC_TEST_VECTORS
1105 .vecs = anubis_cbc_dec_tv_template,
1106 .count = ANUBIS_CBC_DEC_TEST_VECTORS
1111 .alg = "cbc(blowfish)",
1112 .test = alg_test_skcipher,
1116 .vecs = bf_cbc_enc_tv_template,
1117 .count = BF_CBC_ENC_TEST_VECTORS
1120 .vecs = bf_cbc_dec_tv_template,
1121 .count = BF_CBC_DEC_TEST_VECTORS
1126 .alg = "cbc(camellia)",
1127 .test = alg_test_skcipher,
1131 .vecs = camellia_cbc_enc_tv_template,
1132 .count = CAMELLIA_CBC_ENC_TEST_VECTORS
1135 .vecs = camellia_cbc_dec_tv_template,
1136 .count = CAMELLIA_CBC_DEC_TEST_VECTORS
1142 .test = alg_test_skcipher,
1146 .vecs = des_cbc_enc_tv_template,
1147 .count = DES_CBC_ENC_TEST_VECTORS
1150 .vecs = des_cbc_dec_tv_template,
1151 .count = DES_CBC_DEC_TEST_VECTORS
1156 .alg = "cbc(des3_ede)",
1157 .test = alg_test_skcipher,
1161 .vecs = des3_ede_cbc_enc_tv_template,
1162 .count = DES3_EDE_CBC_ENC_TEST_VECTORS
1165 .vecs = des3_ede_cbc_dec_tv_template,
1166 .count = DES3_EDE_CBC_DEC_TEST_VECTORS
1171 .alg = "cbc(twofish)",
1172 .test = alg_test_skcipher,
1176 .vecs = tf_cbc_enc_tv_template,
1177 .count = TF_CBC_ENC_TEST_VECTORS
1180 .vecs = tf_cbc_dec_tv_template,
1181 .count = TF_CBC_DEC_TEST_VECTORS
1187 .test = alg_test_aead,
1191 .vecs = aes_ccm_enc_tv_template,
1192 .count = AES_CCM_ENC_TEST_VECTORS
1195 .vecs = aes_ccm_dec_tv_template,
1196 .count = AES_CCM_DEC_TEST_VECTORS
1202 .test = alg_test_crc32c,
1205 .vecs = crc32c_tv_template,
1206 .count = CRC32C_TEST_VECTORS
1210 .alg = "cts(cbc(aes))",
1211 .test = alg_test_skcipher,
1215 .vecs = cts_mode_enc_tv_template,
1216 .count = CTS_MODE_ENC_TEST_VECTORS
1219 .vecs = cts_mode_dec_tv_template,
1220 .count = CTS_MODE_DEC_TEST_VECTORS
1226 .test = alg_test_comp,
1230 .vecs = deflate_comp_tv_template,
1231 .count = DEFLATE_COMP_TEST_VECTORS
1234 .vecs = deflate_decomp_tv_template,
1235 .count = DEFLATE_DECOMP_TEST_VECTORS
1241 .test = alg_test_skcipher,
1245 .vecs = aes_enc_tv_template,
1246 .count = AES_ENC_TEST_VECTORS
1249 .vecs = aes_dec_tv_template,
1250 .count = AES_DEC_TEST_VECTORS
1255 .alg = "ecb(anubis)",
1256 .test = alg_test_skcipher,
1260 .vecs = anubis_enc_tv_template,
1261 .count = ANUBIS_ENC_TEST_VECTORS
1264 .vecs = anubis_dec_tv_template,
1265 .count = ANUBIS_DEC_TEST_VECTORS
1271 .test = alg_test_skcipher,
1275 .vecs = arc4_enc_tv_template,
1276 .count = ARC4_ENC_TEST_VECTORS
1279 .vecs = arc4_dec_tv_template,
1280 .count = ARC4_DEC_TEST_VECTORS
1285 .alg = "ecb(blowfish)",
1286 .test = alg_test_skcipher,
1290 .vecs = bf_enc_tv_template,
1291 .count = BF_ENC_TEST_VECTORS
1294 .vecs = bf_dec_tv_template,
1295 .count = BF_DEC_TEST_VECTORS
1300 .alg = "ecb(camellia)",
1301 .test = alg_test_skcipher,
1305 .vecs = camellia_enc_tv_template,
1306 .count = CAMELLIA_ENC_TEST_VECTORS
1309 .vecs = camellia_dec_tv_template,
1310 .count = CAMELLIA_DEC_TEST_VECTORS
1315 .alg = "ecb(cast5)",
1316 .test = alg_test_skcipher,
1320 .vecs = cast5_enc_tv_template,
1321 .count = CAST5_ENC_TEST_VECTORS
1324 .vecs = cast5_dec_tv_template,
1325 .count = CAST5_DEC_TEST_VECTORS
1330 .alg = "ecb(cast6)",
1331 .test = alg_test_skcipher,
1335 .vecs = cast6_enc_tv_template,
1336 .count = CAST6_ENC_TEST_VECTORS
1339 .vecs = cast6_dec_tv_template,
1340 .count = CAST6_DEC_TEST_VECTORS
1346 .test = alg_test_skcipher,
1350 .vecs = des_enc_tv_template,
1351 .count = DES_ENC_TEST_VECTORS
1354 .vecs = des_dec_tv_template,
1355 .count = DES_DEC_TEST_VECTORS
1360 .alg = "ecb(des3_ede)",
1361 .test = alg_test_skcipher,
1365 .vecs = des3_ede_enc_tv_template,
1366 .count = DES3_EDE_ENC_TEST_VECTORS
1369 .vecs = des3_ede_dec_tv_template,
1370 .count = DES3_EDE_DEC_TEST_VECTORS
1375 .alg = "ecb(khazad)",
1376 .test = alg_test_skcipher,
1380 .vecs = khazad_enc_tv_template,
1381 .count = KHAZAD_ENC_TEST_VECTORS
1384 .vecs = khazad_dec_tv_template,
1385 .count = KHAZAD_DEC_TEST_VECTORS
1391 .test = alg_test_skcipher,
1395 .vecs = seed_enc_tv_template,
1396 .count = SEED_ENC_TEST_VECTORS
1399 .vecs = seed_dec_tv_template,
1400 .count = SEED_DEC_TEST_VECTORS
1405 .alg = "ecb(serpent)",
1406 .test = alg_test_skcipher,
1410 .vecs = serpent_enc_tv_template,
1411 .count = SERPENT_ENC_TEST_VECTORS
1414 .vecs = serpent_dec_tv_template,
1415 .count = SERPENT_DEC_TEST_VECTORS
1421 .test = alg_test_skcipher,
1425 .vecs = tea_enc_tv_template,
1426 .count = TEA_ENC_TEST_VECTORS
1429 .vecs = tea_dec_tv_template,
1430 .count = TEA_DEC_TEST_VECTORS
1435 .alg = "ecb(tnepres)",
1436 .test = alg_test_skcipher,
1440 .vecs = tnepres_enc_tv_template,
1441 .count = TNEPRES_ENC_TEST_VECTORS
1444 .vecs = tnepres_dec_tv_template,
1445 .count = TNEPRES_DEC_TEST_VECTORS
1450 .alg = "ecb(twofish)",
1451 .test = alg_test_skcipher,
1455 .vecs = tf_enc_tv_template,
1456 .count = TF_ENC_TEST_VECTORS
1459 .vecs = tf_dec_tv_template,
1460 .count = TF_DEC_TEST_VECTORS
1466 .test = alg_test_skcipher,
1470 .vecs = xeta_enc_tv_template,
1471 .count = XETA_ENC_TEST_VECTORS
1474 .vecs = xeta_dec_tv_template,
1475 .count = XETA_DEC_TEST_VECTORS
1481 .test = alg_test_skcipher,
1485 .vecs = xtea_enc_tv_template,
1486 .count = XTEA_ENC_TEST_VECTORS
1489 .vecs = xtea_dec_tv_template,
1490 .count = XTEA_DEC_TEST_VECTORS
1496 .test = alg_test_aead,
1500 .vecs = aes_gcm_enc_tv_template,
1501 .count = AES_GCM_ENC_TEST_VECTORS
1504 .vecs = aes_gcm_dec_tv_template,
1505 .count = AES_GCM_DEC_TEST_VECTORS
1511 .test = alg_test_hash,
1514 .vecs = hmac_md5_tv_template,
1515 .count = HMAC_MD5_TEST_VECTORS
1519 .alg = "hmac(rmd128)",
1520 .test = alg_test_hash,
1523 .vecs = hmac_rmd128_tv_template,
1524 .count = HMAC_RMD128_TEST_VECTORS
1528 .alg = "hmac(rmd160)",
1529 .test = alg_test_hash,
1532 .vecs = hmac_rmd160_tv_template,
1533 .count = HMAC_RMD160_TEST_VECTORS
1537 .alg = "hmac(sha1)",
1538 .test = alg_test_hash,
1541 .vecs = hmac_sha1_tv_template,
1542 .count = HMAC_SHA1_TEST_VECTORS
1546 .alg = "hmac(sha224)",
1547 .test = alg_test_hash,
1550 .vecs = hmac_sha224_tv_template,
1551 .count = HMAC_SHA224_TEST_VECTORS
1555 .alg = "hmac(sha256)",
1556 .test = alg_test_hash,
1559 .vecs = hmac_sha256_tv_template,
1560 .count = HMAC_SHA256_TEST_VECTORS
1564 .alg = "hmac(sha384)",
1565 .test = alg_test_hash,
1568 .vecs = hmac_sha384_tv_template,
1569 .count = HMAC_SHA384_TEST_VECTORS
1573 .alg = "hmac(sha512)",
1574 .test = alg_test_hash,
1577 .vecs = hmac_sha512_tv_template,
1578 .count = HMAC_SHA512_TEST_VECTORS
1583 .test = alg_test_skcipher,
1587 .vecs = aes_lrw_enc_tv_template,
1588 .count = AES_LRW_ENC_TEST_VECTORS
1591 .vecs = aes_lrw_dec_tv_template,
1592 .count = AES_LRW_DEC_TEST_VECTORS
1598 .test = alg_test_comp,
1602 .vecs = lzo_comp_tv_template,
1603 .count = LZO_COMP_TEST_VECTORS
1606 .vecs = lzo_decomp_tv_template,
1607 .count = LZO_DECOMP_TEST_VECTORS
1613 .test = alg_test_hash,
1616 .vecs = md4_tv_template,
1617 .count = MD4_TEST_VECTORS
1622 .test = alg_test_hash,
1625 .vecs = md5_tv_template,
1626 .count = MD5_TEST_VECTORS
1630 .alg = "michael_mic",
1631 .test = alg_test_hash,
1634 .vecs = michael_mic_tv_template,
1635 .count = MICHAEL_MIC_TEST_VECTORS
1639 .alg = "pcbc(fcrypt)",
1640 .test = alg_test_skcipher,
1644 .vecs = fcrypt_pcbc_enc_tv_template,
1645 .count = FCRYPT_ENC_TEST_VECTORS
1648 .vecs = fcrypt_pcbc_dec_tv_template,
1649 .count = FCRYPT_DEC_TEST_VECTORS
1654 .alg = "rfc3686(ctr(aes))",
1655 .test = alg_test_skcipher,
1659 .vecs = aes_ctr_enc_tv_template,
1660 .count = AES_CTR_ENC_TEST_VECTORS
1663 .vecs = aes_ctr_dec_tv_template,
1664 .count = AES_CTR_DEC_TEST_VECTORS
1670 .test = alg_test_hash,
1673 .vecs = rmd128_tv_template,
1674 .count = RMD128_TEST_VECTORS
1679 .test = alg_test_hash,
1682 .vecs = rmd160_tv_template,
1683 .count = RMD160_TEST_VECTORS
1688 .test = alg_test_hash,
1691 .vecs = rmd256_tv_template,
1692 .count = RMD256_TEST_VECTORS
1697 .test = alg_test_hash,
1700 .vecs = rmd320_tv_template,
1701 .count = RMD320_TEST_VECTORS
1706 .test = alg_test_skcipher,
1710 .vecs = salsa20_stream_enc_tv_template,
1711 .count = SALSA20_STREAM_ENC_TEST_VECTORS
1717 .test = alg_test_hash,
1720 .vecs = sha1_tv_template,
1721 .count = SHA1_TEST_VECTORS
1726 .test = alg_test_hash,
1729 .vecs = sha224_tv_template,
1730 .count = SHA224_TEST_VECTORS
1735 .test = alg_test_hash,
1738 .vecs = sha256_tv_template,
1739 .count = SHA256_TEST_VECTORS
1744 .test = alg_test_hash,
1747 .vecs = sha384_tv_template,
1748 .count = SHA384_TEST_VECTORS
1753 .test = alg_test_hash,
1756 .vecs = sha512_tv_template,
1757 .count = SHA512_TEST_VECTORS
1762 .test = alg_test_hash,
1765 .vecs = tgr128_tv_template,
1766 .count = TGR128_TEST_VECTORS
1771 .test = alg_test_hash,
1774 .vecs = tgr160_tv_template,
1775 .count = TGR160_TEST_VECTORS
1780 .test = alg_test_hash,
1783 .vecs = tgr192_tv_template,
1784 .count = TGR192_TEST_VECTORS
1789 .test = alg_test_hash,
1792 .vecs = wp256_tv_template,
1793 .count = WP256_TEST_VECTORS
1798 .test = alg_test_hash,
1801 .vecs = wp384_tv_template,
1802 .count = WP384_TEST_VECTORS
1807 .test = alg_test_hash,
1810 .vecs = wp512_tv_template,
1811 .count = WP512_TEST_VECTORS
1816 .test = alg_test_hash,
1819 .vecs = aes_xcbc128_tv_template,
1820 .count = XCBC_AES_TEST_VECTORS
1825 .test = alg_test_skcipher,
1829 .vecs = aes_xts_enc_tv_template,
1830 .count = AES_XTS_ENC_TEST_VECTORS
1833 .vecs = aes_xts_dec_tv_template,
1834 .count = AES_XTS_DEC_TEST_VECTORS
1841 static int alg_find_test(const char *alg)
1844 int end = ARRAY_SIZE(alg_test_descs);
1846 while (start < end) {
1847 int i = (start + end) / 2;
1848 int diff = strcmp(alg_test_descs[i].alg, alg);
1866 int alg_test(const char *driver, const char *alg, u32 type, u32 mask)
1871 if ((type & CRYPTO_ALG_TYPE_MASK) == CRYPTO_ALG_TYPE_CIPHER) {
1872 char nalg[CRYPTO_MAX_ALG_NAME];
1874 if (snprintf(nalg, sizeof(nalg), "ecb(%s)", alg) >=
1876 return -ENAMETOOLONG;
1878 i = alg_find_test(nalg);
1882 return alg_test_cipher(alg_test_descs + i, driver, type, mask);
1885 i = alg_find_test(alg);
1889 rc = alg_test_descs[i].test(alg_test_descs + i, driver,
1891 if (fips_enabled && rc)
1892 panic("%s: %s alg self test failed in fips mode!\n", driver, alg);
1897 printk(KERN_INFO "alg: No test for %s (%s)\n", alg, driver);
1900 EXPORT_SYMBOL_GPL(alg_test);
1902 int __init testmgr_init(void)
1906 for (i = 0; i < XBUFSIZE; i++) {
1907 xbuf[i] = (void *)__get_free_page(GFP_KERNEL);
1912 for (i = 0; i < XBUFSIZE; i++) {
1913 axbuf[i] = (void *)__get_free_page(GFP_KERNEL);
1915 goto err_free_axbuf;
1921 for (i = 0; i < XBUFSIZE && axbuf[i]; i++)
1922 free_page((unsigned long)axbuf[i]);
1924 for (i = 0; i < XBUFSIZE && xbuf[i]; i++)
1925 free_page((unsigned long)xbuf[i]);
1930 void testmgr_exit(void)
1934 for (i = 0; i < XBUFSIZE; i++)
1935 free_page((unsigned long)axbuf[i]);
1936 for (i = 0; i < XBUFSIZE; i++)
1937 free_page((unsigned long)xbuf[i]);