2 * Quick & dirty crypto testing module.
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
15 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
16 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
17 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
18 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
22 #include <linux/err.h>
23 #include <linux/init.h>
24 #include <linux/module.h>
26 #include <linux/slab.h>
27 #include <linux/scatterlist.h>
28 #include <linux/string.h>
29 #include <linux/crypto.h>
30 #include <linux/highmem.h>
31 #include <linux/moduleparam.h>
32 #include <linux/jiffies.h>
33 #include <linux/timex.h>
34 #include <linux/interrupt.h>
38 * Need to kmalloc() memory for testing kmap().
40 #define TVMEMSIZE 16384
41 #define XBUFSIZE 32768
44 * Indexes into the xbuf to simulate cross-page access.
56 * Used by test_cipher()
61 struct tcrypt_result {
62 struct completion completion;
66 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
69 * Used by test_cipher_speed()
71 static unsigned int sec;
77 static char *check[] = {
78 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
79 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
80 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
81 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
82 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
83 "camellia", "seed", NULL
86 static void hexdump(unsigned char *buf, unsigned int len)
89 printk("%02x", *buf++);
94 static void tcrypt_complete(struct crypto_async_request *req, int err)
96 struct tcrypt_result *res = req->data;
98 if (err == -EINPROGRESS)
102 complete(&res->completion);
105 static void test_hash(char *algo, struct hash_testvec *template,
108 unsigned int i, j, k, temp;
109 struct scatterlist sg[8];
111 struct crypto_hash *tfm;
112 struct hash_desc desc;
113 struct hash_testvec *hash_tv;
117 printk("\ntesting %s\n", algo);
119 tsize = sizeof(struct hash_testvec);
122 if (tsize > TVMEMSIZE) {
123 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
127 memcpy(tvmem, template, tsize);
128 hash_tv = (void *)tvmem;
130 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
132 printk("failed to load transform for %s: %ld\n", algo,
140 for (i = 0; i < tcount; i++) {
141 printk("test %u:\n", i + 1);
142 memset(result, 0, 64);
144 sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
146 if (hash_tv[i].ksize) {
147 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
150 printk("setkey() failed ret=%d\n", ret);
155 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
157 printk("digest () failed ret=%d\n", ret);
161 hexdump(result, crypto_hash_digestsize(tfm));
163 memcmp(result, hash_tv[i].digest,
164 crypto_hash_digestsize(tfm)) ?
168 printk("testing %s across pages\n", algo);
170 /* setup the dummy buffer first */
171 memset(xbuf, 0, XBUFSIZE);
174 for (i = 0; i < tcount; i++) {
177 printk("test %u:\n", j);
178 memset(result, 0, 64);
181 sg_init_table(sg, hash_tv[i].np);
182 for (k = 0; k < hash_tv[i].np; k++) {
183 memcpy(&xbuf[IDX[k]],
184 hash_tv[i].plaintext + temp,
186 temp += hash_tv[i].tap[k];
187 sg_set_buf(&sg[k], &xbuf[IDX[k]],
191 if (hash_tv[i].ksize) {
192 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
196 printk("setkey() failed ret=%d\n", ret);
201 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
204 printk("digest () failed ret=%d\n", ret);
208 hexdump(result, crypto_hash_digestsize(tfm));
210 memcmp(result, hash_tv[i].digest,
211 crypto_hash_digestsize(tfm)) ?
217 crypto_free_hash(tfm);
220 static void test_cipher(char *algo, int enc,
221 struct cipher_testvec *template, unsigned int tcount)
223 unsigned int ret, i, j, k, temp;
226 struct crypto_ablkcipher *tfm;
228 struct cipher_testvec *cipher_tv;
229 struct ablkcipher_request *req;
230 struct scatterlist sg[8];
232 struct tcrypt_result result;
239 printk("\ntesting %s %s\n", algo, e);
241 tsize = sizeof (struct cipher_testvec);
244 if (tsize > TVMEMSIZE) {
245 printk("template (%u) too big for tvmem (%u)\n", tsize,
250 memcpy(tvmem, template, tsize);
251 cipher_tv = (void *)tvmem;
253 init_completion(&result.completion);
255 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
258 printk("failed to load transform for %s: %ld\n", algo,
263 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
265 printk("failed to allocate request for %s\n", algo);
269 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
270 tcrypt_complete, &result);
273 for (i = 0; i < tcount; i++) {
274 if (!(cipher_tv[i].np)) {
276 printk("test %u (%d bit key):\n",
277 j, cipher_tv[i].klen * 8);
279 crypto_ablkcipher_clear_flags(tfm, ~0);
281 crypto_ablkcipher_set_flags(
282 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
283 key = cipher_tv[i].key;
285 ret = crypto_ablkcipher_setkey(tfm, key,
288 printk("setkey() failed flags=%x\n",
289 crypto_ablkcipher_get_flags(tfm));
291 if (!cipher_tv[i].fail)
295 sg_init_one(&sg[0], cipher_tv[i].input,
298 ablkcipher_request_set_crypt(req, sg, sg,
303 crypto_ablkcipher_encrypt(req) :
304 crypto_ablkcipher_decrypt(req);
311 ret = wait_for_completion_interruptible(
313 if (!ret && !((ret = result.err))) {
314 INIT_COMPLETION(result.completion);
319 printk("%s () failed err=%d\n", e, -ret);
323 q = kmap(sg_page(&sg[0])) + sg[0].offset;
324 hexdump(q, cipher_tv[i].rlen);
327 memcmp(q, cipher_tv[i].result,
328 cipher_tv[i].rlen) ? "fail" : "pass");
332 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
333 memset(xbuf, 0, XBUFSIZE);
336 for (i = 0; i < tcount; i++) {
337 if (cipher_tv[i].np) {
339 printk("test %u (%d bit key):\n",
340 j, cipher_tv[i].klen * 8);
342 crypto_ablkcipher_clear_flags(tfm, ~0);
344 crypto_ablkcipher_set_flags(
345 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
346 key = cipher_tv[i].key;
348 ret = crypto_ablkcipher_setkey(tfm, key,
351 printk("setkey() failed flags=%x\n",
352 crypto_ablkcipher_get_flags(tfm));
354 if (!cipher_tv[i].fail)
359 sg_init_table(sg, cipher_tv[i].np);
360 for (k = 0; k < cipher_tv[i].np; k++) {
361 memcpy(&xbuf[IDX[k]],
362 cipher_tv[i].input + temp,
363 cipher_tv[i].tap[k]);
364 temp += cipher_tv[i].tap[k];
365 sg_set_buf(&sg[k], &xbuf[IDX[k]],
366 cipher_tv[i].tap[k]);
369 ablkcipher_request_set_crypt(req, sg, sg,
374 crypto_ablkcipher_encrypt(req) :
375 crypto_ablkcipher_decrypt(req);
382 ret = wait_for_completion_interruptible(
384 if (!ret && !((ret = result.err))) {
385 INIT_COMPLETION(result.completion);
390 printk("%s () failed err=%d\n", e, -ret);
395 for (k = 0; k < cipher_tv[i].np; k++) {
396 printk("page %u\n", k);
397 q = kmap(sg_page(&sg[k])) + sg[k].offset;
398 hexdump(q, cipher_tv[i].tap[k]);
400 memcmp(q, cipher_tv[i].result + temp,
401 cipher_tv[i].tap[k]) ? "fail" :
403 temp += cipher_tv[i].tap[k];
409 crypto_free_ablkcipher(tfm);
410 ablkcipher_request_free(req);
413 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
416 struct scatterlist sg[1];
417 unsigned long start, end;
421 sg_init_one(sg, p, blen);
423 for (start = jiffies, end = start + sec * HZ, bcount = 0;
424 time_before(jiffies, end); bcount++) {
426 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
428 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
434 printk("%d operations in %d seconds (%ld bytes)\n",
435 bcount, sec, (long)bcount * blen);
439 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
442 struct scatterlist sg[1];
443 unsigned long cycles = 0;
447 sg_init_one(sg, p, blen);
453 for (i = 0; i < 4; i++) {
455 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
457 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
463 /* The real thing. */
464 for (i = 0; i < 8; i++) {
467 start = get_cycles();
469 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
471 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
477 cycles += end - start;
485 printk("1 operation in %lu cycles (%d bytes)\n",
486 (cycles + 4) / 8, blen);
491 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
492 struct cipher_testvec *template,
493 unsigned int tcount, struct cipher_speed *speed)
495 unsigned int ret, i, j, iv_len;
496 unsigned char *key, *p, iv[128];
497 struct crypto_blkcipher *tfm;
498 struct blkcipher_desc desc;
506 printk("\ntesting speed of %s %s\n", algo, e);
508 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
511 printk("failed to load transform for %s: %ld\n", algo,
518 for (i = 0; speed[i].klen != 0; i++) {
519 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
520 printk("template (%u) too big for tvmem (%u)\n",
521 speed[i].blen + speed[i].klen, TVMEMSIZE);
525 printk("test %u (%d bit key, %d byte blocks): ", i,
526 speed[i].klen * 8, speed[i].blen);
528 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
530 /* set key, plain text and IV */
531 key = (unsigned char *)tvmem;
532 for (j = 0; j < tcount; j++) {
533 if (template[j].klen == speed[i].klen) {
534 key = template[j].key;
538 p = (unsigned char *)tvmem + speed[i].klen;
540 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
542 printk("setkey() failed flags=%x\n",
543 crypto_blkcipher_get_flags(tfm));
547 iv_len = crypto_blkcipher_ivsize(tfm);
549 memset(&iv, 0xff, iv_len);
550 crypto_blkcipher_set_iv(tfm, iv, iv_len);
554 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
557 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
560 printk("%s() failed flags=%x\n", e, desc.flags);
566 crypto_free_blkcipher(tfm);
569 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
572 struct scatterlist sg[1];
573 unsigned long start, end;
577 sg_init_table(sg, 1);
579 for (start = jiffies, end = start + sec * HZ, bcount = 0;
580 time_before(jiffies, end); bcount++) {
581 sg_set_buf(sg, p, blen);
582 ret = crypto_hash_digest(desc, sg, blen, out);
587 printk("%6u opers/sec, %9lu bytes/sec\n",
588 bcount / sec, ((long)bcount * blen) / sec);
593 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
594 int plen, char *out, int sec)
596 struct scatterlist sg[1];
597 unsigned long start, end;
602 return test_hash_jiffies_digest(desc, p, blen, out, sec);
604 sg_init_table(sg, 1);
606 for (start = jiffies, end = start + sec * HZ, bcount = 0;
607 time_before(jiffies, end); bcount++) {
608 ret = crypto_hash_init(desc);
611 for (pcount = 0; pcount < blen; pcount += plen) {
612 sg_set_buf(sg, p + pcount, plen);
613 ret = crypto_hash_update(desc, sg, plen);
617 /* we assume there is enough space in 'out' for the result */
618 ret = crypto_hash_final(desc, out);
623 printk("%6u opers/sec, %9lu bytes/sec\n",
624 bcount / sec, ((long)bcount * blen) / sec);
629 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
632 struct scatterlist sg[1];
633 unsigned long cycles = 0;
637 sg_init_table(sg, 1);
643 for (i = 0; i < 4; i++) {
644 sg_set_buf(sg, p, blen);
645 ret = crypto_hash_digest(desc, sg, blen, out);
650 /* The real thing. */
651 for (i = 0; i < 8; i++) {
654 start = get_cycles();
656 sg_set_buf(sg, p, blen);
657 ret = crypto_hash_digest(desc, sg, blen, out);
663 cycles += end - start;
673 printk("%6lu cycles/operation, %4lu cycles/byte\n",
674 cycles / 8, cycles / (8 * blen));
679 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
682 struct scatterlist sg[1];
683 unsigned long cycles = 0;
688 return test_hash_cycles_digest(desc, p, blen, out);
690 sg_init_table(sg, 1);
696 for (i = 0; i < 4; i++) {
697 ret = crypto_hash_init(desc);
700 for (pcount = 0; pcount < blen; pcount += plen) {
701 sg_set_buf(sg, p + pcount, plen);
702 ret = crypto_hash_update(desc, sg, plen);
706 ret = crypto_hash_final(desc, out);
711 /* The real thing. */
712 for (i = 0; i < 8; i++) {
715 start = get_cycles();
717 ret = crypto_hash_init(desc);
720 for (pcount = 0; pcount < blen; pcount += plen) {
721 sg_set_buf(sg, p + pcount, plen);
722 ret = crypto_hash_update(desc, sg, plen);
726 ret = crypto_hash_final(desc, out);
732 cycles += end - start;
742 printk("%6lu cycles/operation, %4lu cycles/byte\n",
743 cycles / 8, cycles / (8 * blen));
748 static void test_hash_speed(char *algo, unsigned int sec,
749 struct hash_speed *speed)
751 struct crypto_hash *tfm;
752 struct hash_desc desc;
757 printk("\ntesting speed of %s\n", algo);
759 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
762 printk("failed to load transform for %s: %ld\n", algo,
770 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
771 printk("digestsize(%u) > outputbuffer(%zu)\n",
772 crypto_hash_digestsize(tfm), sizeof(output));
776 for (i = 0; speed[i].blen != 0; i++) {
777 if (speed[i].blen > TVMEMSIZE) {
778 printk("template (%u) too big for tvmem (%u)\n",
779 speed[i].blen, TVMEMSIZE);
783 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
784 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
786 memset(tvmem, 0xff, speed[i].blen);
789 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
790 speed[i].plen, output, sec);
792 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
793 speed[i].plen, output);
796 printk("hashing failed ret=%d\n", ret);
802 crypto_free_hash(tfm);
805 static void test_deflate(void)
808 char result[COMP_BUF_SIZE];
809 struct crypto_comp *tfm;
810 struct comp_testvec *tv;
813 printk("\ntesting deflate compression\n");
815 tsize = sizeof (deflate_comp_tv_template);
816 if (tsize > TVMEMSIZE) {
817 printk("template (%u) too big for tvmem (%u)\n", tsize,
822 memcpy(tvmem, deflate_comp_tv_template, tsize);
825 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
827 printk("failed to load transform for deflate\n");
831 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
832 int ilen, ret, dlen = COMP_BUF_SIZE;
834 printk("test %u:\n", i + 1);
835 memset(result, 0, sizeof (result));
838 ret = crypto_comp_compress(tfm, tv[i].input,
839 ilen, result, &dlen);
841 printk("fail: ret=%d\n", ret);
844 hexdump(result, dlen);
845 printk("%s (ratio %d:%d)\n",
846 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
850 printk("\ntesting deflate decompression\n");
852 tsize = sizeof (deflate_decomp_tv_template);
853 if (tsize > TVMEMSIZE) {
854 printk("template (%u) too big for tvmem (%u)\n", tsize,
859 memcpy(tvmem, deflate_decomp_tv_template, tsize);
862 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
863 int ilen, ret, dlen = COMP_BUF_SIZE;
865 printk("test %u:\n", i + 1);
866 memset(result, 0, sizeof (result));
869 ret = crypto_comp_decompress(tfm, tv[i].input,
870 ilen, result, &dlen);
872 printk("fail: ret=%d\n", ret);
875 hexdump(result, dlen);
876 printk("%s (ratio %d:%d)\n",
877 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
881 crypto_free_comp(tfm);
884 static void test_available(void)
889 printk("alg %s ", *name);
890 printk(crypto_has_alg(*name, 0, 0) ?
891 "found\n" : "not found\n");
896 static void do_test(void)
901 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
903 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
906 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
907 DES_ENC_TEST_VECTORS);
908 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
909 DES_DEC_TEST_VECTORS);
910 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
911 DES_CBC_ENC_TEST_VECTORS);
912 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
913 DES_CBC_DEC_TEST_VECTORS);
916 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
917 DES3_EDE_ENC_TEST_VECTORS);
918 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
919 DES3_EDE_DEC_TEST_VECTORS);
921 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
923 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
925 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
928 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
929 BF_ENC_TEST_VECTORS);
930 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
931 BF_DEC_TEST_VECTORS);
932 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
933 BF_CBC_ENC_TEST_VECTORS);
934 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
935 BF_CBC_DEC_TEST_VECTORS);
938 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
939 TF_ENC_TEST_VECTORS);
940 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
941 TF_DEC_TEST_VECTORS);
942 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
943 TF_CBC_ENC_TEST_VECTORS);
944 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
945 TF_CBC_DEC_TEST_VECTORS);
948 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
949 SERPENT_ENC_TEST_VECTORS);
950 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
951 SERPENT_DEC_TEST_VECTORS);
954 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
955 TNEPRES_ENC_TEST_VECTORS);
956 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
957 TNEPRES_DEC_TEST_VECTORS);
960 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
961 AES_ENC_TEST_VECTORS);
962 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
963 AES_DEC_TEST_VECTORS);
964 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
965 AES_CBC_ENC_TEST_VECTORS);
966 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
967 AES_CBC_DEC_TEST_VECTORS);
968 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
969 AES_LRW_ENC_TEST_VECTORS);
970 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
971 AES_LRW_DEC_TEST_VECTORS);
972 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
973 AES_XTS_ENC_TEST_VECTORS);
974 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
975 AES_XTS_DEC_TEST_VECTORS);
976 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
977 AES_CTR_ENC_TEST_VECTORS);
978 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
979 AES_CTR_DEC_TEST_VECTORS);
982 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
983 CAST5_ENC_TEST_VECTORS);
984 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
985 CAST5_DEC_TEST_VECTORS);
988 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
989 CAST6_ENC_TEST_VECTORS);
990 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
991 CAST6_DEC_TEST_VECTORS);
994 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
995 ARC4_ENC_TEST_VECTORS);
996 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
997 ARC4_DEC_TEST_VECTORS);
1000 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1001 TEA_ENC_TEST_VECTORS);
1002 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1003 TEA_DEC_TEST_VECTORS);
1007 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1008 XTEA_ENC_TEST_VECTORS);
1009 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1010 XTEA_DEC_TEST_VECTORS);
1013 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1014 KHAZAD_ENC_TEST_VECTORS);
1015 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1016 KHAZAD_DEC_TEST_VECTORS);
1019 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1020 ANUBIS_ENC_TEST_VECTORS);
1021 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1022 ANUBIS_DEC_TEST_VECTORS);
1023 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1024 ANUBIS_CBC_ENC_TEST_VECTORS);
1025 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1026 ANUBIS_CBC_ENC_TEST_VECTORS);
1029 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1030 XETA_ENC_TEST_VECTORS);
1031 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1032 XETA_DEC_TEST_VECTORS);
1035 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1036 FCRYPT_ENC_TEST_VECTORS);
1037 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1038 FCRYPT_DEC_TEST_VECTORS);
1041 test_cipher("ecb(camellia)", ENCRYPT,
1042 camellia_enc_tv_template,
1043 CAMELLIA_ENC_TEST_VECTORS);
1044 test_cipher("ecb(camellia)", DECRYPT,
1045 camellia_dec_tv_template,
1046 CAMELLIA_DEC_TEST_VECTORS);
1047 test_cipher("cbc(camellia)", ENCRYPT,
1048 camellia_cbc_enc_tv_template,
1049 CAMELLIA_CBC_ENC_TEST_VECTORS);
1050 test_cipher("cbc(camellia)", DECRYPT,
1051 camellia_cbc_dec_tv_template,
1052 CAMELLIA_CBC_DEC_TEST_VECTORS);
1055 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1056 SEED_ENC_TEST_VECTORS);
1057 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1058 SEED_DEC_TEST_VECTORS);
1060 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1061 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1062 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1063 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1064 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1065 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1066 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1067 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1069 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1070 test_hash("hmac(md5)", hmac_md5_tv_template,
1071 HMAC_MD5_TEST_VECTORS);
1072 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1073 HMAC_SHA1_TEST_VECTORS);
1074 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1075 HMAC_SHA224_TEST_VECTORS);
1076 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1077 HMAC_SHA256_TEST_VECTORS);
1078 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1079 HMAC_SHA384_TEST_VECTORS);
1080 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1081 HMAC_SHA512_TEST_VECTORS);
1083 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1084 XCBC_AES_TEST_VECTORS);
1086 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1090 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1094 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1098 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1099 DES_ENC_TEST_VECTORS);
1100 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1101 DES_DEC_TEST_VECTORS);
1102 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1103 DES_CBC_ENC_TEST_VECTORS);
1104 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1105 DES_CBC_DEC_TEST_VECTORS);
1109 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1110 DES3_EDE_ENC_TEST_VECTORS);
1111 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1112 DES3_EDE_DEC_TEST_VECTORS);
1116 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1120 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1124 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1125 BF_ENC_TEST_VECTORS);
1126 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1127 BF_DEC_TEST_VECTORS);
1128 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1129 BF_CBC_ENC_TEST_VECTORS);
1130 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1131 BF_CBC_DEC_TEST_VECTORS);
1135 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1136 TF_ENC_TEST_VECTORS);
1137 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1138 TF_DEC_TEST_VECTORS);
1139 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1140 TF_CBC_ENC_TEST_VECTORS);
1141 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1142 TF_CBC_DEC_TEST_VECTORS);
1146 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1147 SERPENT_ENC_TEST_VECTORS);
1148 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1149 SERPENT_DEC_TEST_VECTORS);
1153 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1154 AES_ENC_TEST_VECTORS);
1155 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1156 AES_DEC_TEST_VECTORS);
1157 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1158 AES_CBC_ENC_TEST_VECTORS);
1159 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1160 AES_CBC_DEC_TEST_VECTORS);
1161 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1162 AES_LRW_ENC_TEST_VECTORS);
1163 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1164 AES_LRW_DEC_TEST_VECTORS);
1165 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1166 AES_XTS_ENC_TEST_VECTORS);
1167 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1168 AES_XTS_DEC_TEST_VECTORS);
1169 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1170 AES_CTR_ENC_TEST_VECTORS);
1171 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1172 AES_CTR_DEC_TEST_VECTORS);
1176 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1180 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1188 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1189 CAST5_ENC_TEST_VECTORS);
1190 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1191 CAST5_DEC_TEST_VECTORS);
1195 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1196 CAST6_ENC_TEST_VECTORS);
1197 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1198 CAST6_DEC_TEST_VECTORS);
1202 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1203 ARC4_ENC_TEST_VECTORS);
1204 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1205 ARC4_DEC_TEST_VECTORS);
1209 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1213 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1217 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1218 TEA_ENC_TEST_VECTORS);
1219 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1220 TEA_DEC_TEST_VECTORS);
1224 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1225 XTEA_ENC_TEST_VECTORS);
1226 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1227 XTEA_DEC_TEST_VECTORS);
1231 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1232 KHAZAD_ENC_TEST_VECTORS);
1233 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1234 KHAZAD_DEC_TEST_VECTORS);
1238 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1242 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1246 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1250 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1251 TNEPRES_ENC_TEST_VECTORS);
1252 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1253 TNEPRES_DEC_TEST_VECTORS);
1257 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1258 ANUBIS_ENC_TEST_VECTORS);
1259 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1260 ANUBIS_DEC_TEST_VECTORS);
1261 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1262 ANUBIS_CBC_ENC_TEST_VECTORS);
1263 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1264 ANUBIS_CBC_ENC_TEST_VECTORS);
1268 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1273 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1277 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1281 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1282 XETA_ENC_TEST_VECTORS);
1283 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1284 XETA_DEC_TEST_VECTORS);
1288 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1289 FCRYPT_ENC_TEST_VECTORS);
1290 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1291 FCRYPT_DEC_TEST_VECTORS);
1295 test_cipher("ecb(camellia)", ENCRYPT,
1296 camellia_enc_tv_template,
1297 CAMELLIA_ENC_TEST_VECTORS);
1298 test_cipher("ecb(camellia)", DECRYPT,
1299 camellia_dec_tv_template,
1300 CAMELLIA_DEC_TEST_VECTORS);
1301 test_cipher("cbc(camellia)", ENCRYPT,
1302 camellia_cbc_enc_tv_template,
1303 CAMELLIA_CBC_ENC_TEST_VECTORS);
1304 test_cipher("cbc(camellia)", DECRYPT,
1305 camellia_cbc_dec_tv_template,
1306 CAMELLIA_CBC_DEC_TEST_VECTORS);
1309 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1313 test_hash("hmac(md5)", hmac_md5_tv_template,
1314 HMAC_MD5_TEST_VECTORS);
1318 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1319 HMAC_SHA1_TEST_VECTORS);
1323 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1324 HMAC_SHA256_TEST_VECTORS);
1328 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1329 HMAC_SHA384_TEST_VECTORS);
1333 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1334 HMAC_SHA512_TEST_VECTORS);
1337 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1338 HMAC_SHA224_TEST_VECTORS);
1342 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1343 aes_speed_template);
1344 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1345 aes_speed_template);
1346 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1347 aes_speed_template);
1348 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1349 aes_speed_template);
1350 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1351 aes_lrw_speed_template);
1352 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1353 aes_lrw_speed_template);
1354 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1355 aes_xts_speed_template);
1356 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1357 aes_xts_speed_template);
1361 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1362 des3_ede_enc_tv_template,
1363 DES3_EDE_ENC_TEST_VECTORS,
1364 des3_ede_speed_template);
1365 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1366 des3_ede_dec_tv_template,
1367 DES3_EDE_DEC_TEST_VECTORS,
1368 des3_ede_speed_template);
1369 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1370 des3_ede_enc_tv_template,
1371 DES3_EDE_ENC_TEST_VECTORS,
1372 des3_ede_speed_template);
1373 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1374 des3_ede_dec_tv_template,
1375 DES3_EDE_DEC_TEST_VECTORS,
1376 des3_ede_speed_template);
1380 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1381 twofish_speed_template);
1382 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1383 twofish_speed_template);
1384 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1385 twofish_speed_template);
1386 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1387 twofish_speed_template);
1391 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1392 blowfish_speed_template);
1393 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1394 blowfish_speed_template);
1395 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1396 blowfish_speed_template);
1397 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1398 blowfish_speed_template);
1402 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1403 des_speed_template);
1404 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1405 des_speed_template);
1406 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1407 des_speed_template);
1408 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1409 des_speed_template);
1413 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1414 camellia_speed_template);
1415 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1416 camellia_speed_template);
1417 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1418 camellia_speed_template);
1419 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1420 camellia_speed_template);
1427 test_hash_speed("md4", sec, generic_hash_speed_template);
1428 if (mode > 300 && mode < 400) break;
1431 test_hash_speed("md5", sec, generic_hash_speed_template);
1432 if (mode > 300 && mode < 400) break;
1435 test_hash_speed("sha1", sec, generic_hash_speed_template);
1436 if (mode > 300 && mode < 400) break;
1439 test_hash_speed("sha256", sec, generic_hash_speed_template);
1440 if (mode > 300 && mode < 400) break;
1443 test_hash_speed("sha384", sec, generic_hash_speed_template);
1444 if (mode > 300 && mode < 400) break;
1447 test_hash_speed("sha512", sec, generic_hash_speed_template);
1448 if (mode > 300 && mode < 400) break;
1451 test_hash_speed("wp256", sec, generic_hash_speed_template);
1452 if (mode > 300 && mode < 400) break;
1455 test_hash_speed("wp384", sec, generic_hash_speed_template);
1456 if (mode > 300 && mode < 400) break;
1459 test_hash_speed("wp512", sec, generic_hash_speed_template);
1460 if (mode > 300 && mode < 400) break;
1463 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1464 if (mode > 300 && mode < 400) break;
1467 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1468 if (mode > 300 && mode < 400) break;
1471 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1472 if (mode > 300 && mode < 400) break;
1475 test_hash_speed("sha224", sec, generic_hash_speed_template);
1476 if (mode > 300 && mode < 400) break;
1486 /* useful for debugging */
1487 printk("not testing anything\n");
1492 static int __init init(void)
1494 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1498 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1509 /* We intentionaly return -EAGAIN to prevent keeping
1510 * the module. It does all its work from init()
1511 * and doesn't offer any runtime functionality
1512 * => we don't need it in the memory, do we?
1519 * If an init function is provided, an exit function must also be provided
1520 * to allow module unload.
1522 static void __exit fini(void) { }
1527 module_param(mode, int, 0);
1528 module_param(sec, uint, 0);
1529 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1530 "(defaults to zero which uses CPU cycles instead)");
1532 MODULE_LICENSE("GPL");
1533 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1534 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");