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 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
16 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
20 #include <linux/err.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/scatterlist.h>
26 #include <linux/string.h>
27 #include <linux/crypto.h>
28 #include <linux/highmem.h>
29 #include <linux/moduleparam.h>
30 #include <linux/jiffies.h>
31 #include <linux/timex.h>
32 #include <linux/interrupt.h>
36 * Need to kmalloc() memory for testing kmap().
38 #define TVMEMSIZE 16384
39 #define XBUFSIZE 32768
42 * Indexes into the xbuf to simulate cross-page access.
54 * Used by test_cipher()
59 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
62 * Used by test_cipher_speed()
64 static unsigned int sec;
70 static char *check[] = {
71 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
72 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
73 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
74 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
77 static void hexdump(unsigned char *buf, unsigned int len)
80 printk("%02x", *buf++);
85 static void test_hash(char *algo, struct hash_testvec *template,
88 unsigned int i, j, k, temp;
89 struct scatterlist sg[8];
91 struct crypto_hash *tfm;
92 struct hash_desc desc;
93 struct hash_testvec *hash_tv;
97 printk("\ntesting %s\n", algo);
99 tsize = sizeof(struct hash_testvec);
102 if (tsize > TVMEMSIZE) {
103 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
107 memcpy(tvmem, template, tsize);
108 hash_tv = (void *)tvmem;
110 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
112 printk("failed to load transform for %s: %ld\n", algo,
120 for (i = 0; i < tcount; i++) {
121 printk("test %u:\n", i + 1);
122 memset(result, 0, 64);
124 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
126 if (hash_tv[i].ksize) {
127 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
130 printk("setkey() failed ret=%d\n", ret);
135 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
137 printk("digest () failed ret=%d\n", ret);
141 hexdump(result, crypto_hash_digestsize(tfm));
143 memcmp(result, hash_tv[i].digest,
144 crypto_hash_digestsize(tfm)) ?
148 printk("testing %s across pages\n", algo);
150 /* setup the dummy buffer first */
151 memset(xbuf, 0, XBUFSIZE);
154 for (i = 0; i < tcount; i++) {
157 printk("test %u:\n", j);
158 memset(result, 0, 64);
161 for (k = 0; k < hash_tv[i].np; k++) {
162 memcpy(&xbuf[IDX[k]],
163 hash_tv[i].plaintext + temp,
165 temp += hash_tv[i].tap[k];
166 sg_set_buf(&sg[k], &xbuf[IDX[k]],
170 if (hash_tv[i].ksize) {
171 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
175 printk("setkey() failed ret=%d\n", ret);
180 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
183 printk("digest () failed ret=%d\n", ret);
187 hexdump(result, crypto_hash_digestsize(tfm));
189 memcmp(result, hash_tv[i].digest,
190 crypto_hash_digestsize(tfm)) ?
196 crypto_free_hash(tfm);
199 static void test_cipher(char *algo, int enc,
200 struct cipher_testvec *template, unsigned int tcount)
202 unsigned int ret, i, j, k, temp;
207 struct crypto_blkcipher *tfm;
209 struct cipher_testvec *cipher_tv;
210 struct blkcipher_desc desc;
211 struct scatterlist sg[8];
219 printk("\ntesting %s %s\n", algo, e);
221 tsize = sizeof (struct cipher_testvec);
224 if (tsize > TVMEMSIZE) {
225 printk("template (%u) too big for tvmem (%u)\n", tsize,
230 memcpy(tvmem, template, tsize);
231 cipher_tv = (void *)tvmem;
233 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
236 printk("failed to load transform for %s: %ld\n", algo,
244 for (i = 0; i < tcount; i++) {
245 if (!(cipher_tv[i].np)) {
247 printk("test %u (%d bit key):\n",
248 j, cipher_tv[i].klen * 8);
250 crypto_blkcipher_clear_flags(tfm, ~0);
252 crypto_blkcipher_set_flags(
253 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
254 key = cipher_tv[i].key;
256 ret = crypto_blkcipher_setkey(tfm, key,
259 printk("setkey() failed flags=%x\n",
260 crypto_blkcipher_get_flags(tfm));
262 if (!cipher_tv[i].fail)
266 sg_set_buf(&sg[0], cipher_tv[i].input,
269 iv_len = crypto_blkcipher_ivsize(tfm);
271 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
274 len = cipher_tv[i].ilen;
276 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
277 crypto_blkcipher_decrypt(&desc, sg, sg, len);
280 printk("%s () failed flags=%x\n", e,
285 q = kmap(sg[0].page) + sg[0].offset;
286 hexdump(q, cipher_tv[i].rlen);
289 memcmp(q, cipher_tv[i].result,
290 cipher_tv[i].rlen) ? "fail" : "pass");
294 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
295 memset(xbuf, 0, XBUFSIZE);
298 for (i = 0; i < tcount; i++) {
299 if (cipher_tv[i].np) {
301 printk("test %u (%d bit key):\n",
302 j, cipher_tv[i].klen * 8);
304 crypto_blkcipher_clear_flags(tfm, ~0);
306 crypto_blkcipher_set_flags(
307 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
308 key = cipher_tv[i].key;
310 ret = crypto_blkcipher_setkey(tfm, key,
313 printk("setkey() failed flags=%x\n",
314 crypto_blkcipher_get_flags(tfm));
316 if (!cipher_tv[i].fail)
321 for (k = 0; k < cipher_tv[i].np; k++) {
322 memcpy(&xbuf[IDX[k]],
323 cipher_tv[i].input + temp,
324 cipher_tv[i].tap[k]);
325 temp += cipher_tv[i].tap[k];
326 sg_set_buf(&sg[k], &xbuf[IDX[k]],
327 cipher_tv[i].tap[k]);
330 iv_len = crypto_blkcipher_ivsize(tfm);
332 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
335 len = cipher_tv[i].ilen;
337 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
338 crypto_blkcipher_decrypt(&desc, sg, sg, len);
341 printk("%s () failed flags=%x\n", e,
347 for (k = 0; k < cipher_tv[i].np; k++) {
348 printk("page %u\n", k);
349 q = kmap(sg[k].page) + sg[k].offset;
350 hexdump(q, cipher_tv[i].tap[k]);
352 memcmp(q, cipher_tv[i].result + temp,
353 cipher_tv[i].tap[k]) ? "fail" :
355 temp += cipher_tv[i].tap[k];
361 crypto_free_blkcipher(tfm);
364 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
367 struct scatterlist sg[1];
368 unsigned long start, end;
372 sg_set_buf(sg, p, blen);
374 for (start = jiffies, end = start + sec * HZ, bcount = 0;
375 time_before(jiffies, end); bcount++) {
377 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
379 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
385 printk("%d operations in %d seconds (%ld bytes)\n",
386 bcount, sec, (long)bcount * blen);
390 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
393 struct scatterlist sg[1];
394 unsigned long cycles = 0;
398 sg_set_buf(sg, p, blen);
404 for (i = 0; i < 4; i++) {
406 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
408 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
414 /* The real thing. */
415 for (i = 0; i < 8; i++) {
418 start = get_cycles();
420 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
422 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
428 cycles += end - start;
436 printk("1 operation in %lu cycles (%d bytes)\n",
437 (cycles + 4) / 8, blen);
442 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
443 struct cipher_testvec *template,
444 unsigned int tcount, struct cipher_speed *speed)
446 unsigned int ret, i, j, iv_len;
447 unsigned char *key, *p, iv[128];
448 struct crypto_blkcipher *tfm;
449 struct blkcipher_desc desc;
457 printk("\ntesting speed of %s %s\n", algo, e);
459 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
462 printk("failed to load transform for %s: %ld\n", algo,
469 for (i = 0; speed[i].klen != 0; i++) {
470 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
471 printk("template (%u) too big for tvmem (%u)\n",
472 speed[i].blen + speed[i].klen, TVMEMSIZE);
476 printk("test %u (%d bit key, %d byte blocks): ", i,
477 speed[i].klen * 8, speed[i].blen);
479 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
481 /* set key, plain text and IV */
482 key = (unsigned char *)tvmem;
483 for (j = 0; j < tcount; j++) {
484 if (template[j].klen == speed[i].klen) {
485 key = template[j].key;
489 p = (unsigned char *)tvmem + speed[i].klen;
491 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
493 printk("setkey() failed flags=%x\n",
494 crypto_blkcipher_get_flags(tfm));
498 iv_len = crypto_blkcipher_ivsize(tfm);
500 memset(&iv, 0xff, iv_len);
501 crypto_blkcipher_set_iv(tfm, iv, iv_len);
505 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
508 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
511 printk("%s() failed flags=%x\n", e, desc.flags);
517 crypto_free_blkcipher(tfm);
520 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
523 struct scatterlist sg[1];
524 unsigned long start, end;
528 for (start = jiffies, end = start + sec * HZ, bcount = 0;
529 time_before(jiffies, end); bcount++) {
530 sg_set_buf(sg, p, blen);
531 ret = crypto_hash_digest(desc, sg, blen, out);
536 printk("%6u opers/sec, %9lu bytes/sec\n",
537 bcount / sec, ((long)bcount * blen) / sec);
542 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
543 int plen, char *out, int sec)
545 struct scatterlist sg[1];
546 unsigned long start, end;
551 return test_hash_jiffies_digest(desc, p, blen, out, sec);
553 for (start = jiffies, end = start + sec * HZ, bcount = 0;
554 time_before(jiffies, end); bcount++) {
555 ret = crypto_hash_init(desc);
558 for (pcount = 0; pcount < blen; pcount += plen) {
559 sg_set_buf(sg, p + pcount, plen);
560 ret = crypto_hash_update(desc, sg, plen);
564 /* we assume there is enough space in 'out' for the result */
565 ret = crypto_hash_final(desc, out);
570 printk("%6u opers/sec, %9lu bytes/sec\n",
571 bcount / sec, ((long)bcount * blen) / sec);
576 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
579 struct scatterlist sg[1];
580 unsigned long cycles = 0;
588 for (i = 0; i < 4; i++) {
589 sg_set_buf(sg, p, blen);
590 ret = crypto_hash_digest(desc, sg, blen, out);
595 /* The real thing. */
596 for (i = 0; i < 8; i++) {
599 start = get_cycles();
601 sg_set_buf(sg, p, blen);
602 ret = crypto_hash_digest(desc, sg, blen, out);
608 cycles += end - start;
618 printk("%6lu cycles/operation, %4lu cycles/byte\n",
619 cycles / 8, cycles / (8 * blen));
624 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
627 struct scatterlist sg[1];
628 unsigned long cycles = 0;
633 return test_hash_cycles_digest(desc, p, blen, out);
639 for (i = 0; i < 4; i++) {
640 ret = crypto_hash_init(desc);
643 for (pcount = 0; pcount < blen; pcount += plen) {
644 sg_set_buf(sg, p + pcount, plen);
645 ret = crypto_hash_update(desc, sg, plen);
649 crypto_hash_final(desc, out);
654 /* The real thing. */
655 for (i = 0; i < 8; i++) {
658 start = get_cycles();
660 ret = crypto_hash_init(desc);
663 for (pcount = 0; pcount < blen; pcount += plen) {
664 sg_set_buf(sg, p + pcount, plen);
665 ret = crypto_hash_update(desc, sg, plen);
669 ret = crypto_hash_final(desc, out);
675 cycles += end - start;
685 printk("%6lu cycles/operation, %4lu cycles/byte\n",
686 cycles / 8, cycles / (8 * blen));
691 static void test_hash_speed(char *algo, unsigned int sec,
692 struct hash_speed *speed)
694 struct crypto_hash *tfm;
695 struct hash_desc desc;
700 printk("\ntesting speed of %s\n", algo);
702 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
705 printk("failed to load transform for %s: %ld\n", algo,
713 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
714 printk("digestsize(%u) > outputbuffer(%zu)\n",
715 crypto_hash_digestsize(tfm), sizeof(output));
719 for (i = 0; speed[i].blen != 0; i++) {
720 if (speed[i].blen > TVMEMSIZE) {
721 printk("template (%u) too big for tvmem (%u)\n",
722 speed[i].blen, TVMEMSIZE);
726 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
727 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
729 memset(tvmem, 0xff, speed[i].blen);
732 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
733 speed[i].plen, output, sec);
735 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
736 speed[i].plen, output);
739 printk("hashing failed ret=%d\n", ret);
745 crypto_free_hash(tfm);
748 static void test_deflate(void)
751 char result[COMP_BUF_SIZE];
752 struct crypto_comp *tfm;
753 struct comp_testvec *tv;
756 printk("\ntesting deflate compression\n");
758 tsize = sizeof (deflate_comp_tv_template);
759 if (tsize > TVMEMSIZE) {
760 printk("template (%u) too big for tvmem (%u)\n", tsize,
765 memcpy(tvmem, deflate_comp_tv_template, tsize);
768 tfm = crypto_alloc_tfm("deflate", 0);
770 printk("failed to load transform for deflate\n");
774 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
775 int ilen, ret, dlen = COMP_BUF_SIZE;
777 printk("test %u:\n", i + 1);
778 memset(result, 0, sizeof (result));
781 ret = crypto_comp_compress(tfm, tv[i].input,
782 ilen, result, &dlen);
784 printk("fail: ret=%d\n", ret);
787 hexdump(result, dlen);
788 printk("%s (ratio %d:%d)\n",
789 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
793 printk("\ntesting deflate decompression\n");
795 tsize = sizeof (deflate_decomp_tv_template);
796 if (tsize > TVMEMSIZE) {
797 printk("template (%u) too big for tvmem (%u)\n", tsize,
802 memcpy(tvmem, deflate_decomp_tv_template, tsize);
805 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
806 int ilen, ret, dlen = COMP_BUF_SIZE;
808 printk("test %u:\n", i + 1);
809 memset(result, 0, sizeof (result));
812 ret = crypto_comp_decompress(tfm, tv[i].input,
813 ilen, result, &dlen);
815 printk("fail: ret=%d\n", ret);
818 hexdump(result, dlen);
819 printk("%s (ratio %d:%d)\n",
820 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
824 crypto_free_comp(tfm);
827 static void test_available(void)
832 printk("alg %s ", *name);
833 printk(crypto_has_alg(*name, 0, CRYPTO_ALG_ASYNC) ?
834 "found\n" : "not found\n");
839 static void do_test(void)
844 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
846 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
849 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
850 DES_ENC_TEST_VECTORS);
851 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
852 DES_DEC_TEST_VECTORS);
853 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
854 DES_CBC_ENC_TEST_VECTORS);
855 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
856 DES_CBC_DEC_TEST_VECTORS);
859 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
860 DES3_EDE_ENC_TEST_VECTORS);
861 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
862 DES3_EDE_DEC_TEST_VECTORS);
864 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
866 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
869 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
870 BF_ENC_TEST_VECTORS);
871 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
872 BF_DEC_TEST_VECTORS);
873 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
874 BF_CBC_ENC_TEST_VECTORS);
875 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
876 BF_CBC_DEC_TEST_VECTORS);
879 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
880 TF_ENC_TEST_VECTORS);
881 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
882 TF_DEC_TEST_VECTORS);
883 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
884 TF_CBC_ENC_TEST_VECTORS);
885 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
886 TF_CBC_DEC_TEST_VECTORS);
889 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
890 SERPENT_ENC_TEST_VECTORS);
891 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
892 SERPENT_DEC_TEST_VECTORS);
895 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
896 TNEPRES_ENC_TEST_VECTORS);
897 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
898 TNEPRES_DEC_TEST_VECTORS);
901 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
902 AES_ENC_TEST_VECTORS);
903 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
904 AES_DEC_TEST_VECTORS);
905 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
906 AES_CBC_ENC_TEST_VECTORS);
907 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
908 AES_CBC_DEC_TEST_VECTORS);
911 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
912 CAST5_ENC_TEST_VECTORS);
913 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
914 CAST5_DEC_TEST_VECTORS);
917 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
918 CAST6_ENC_TEST_VECTORS);
919 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
920 CAST6_DEC_TEST_VECTORS);
923 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
924 ARC4_ENC_TEST_VECTORS);
925 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
926 ARC4_DEC_TEST_VECTORS);
929 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
930 TEA_ENC_TEST_VECTORS);
931 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
932 TEA_DEC_TEST_VECTORS);
936 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
937 XTEA_ENC_TEST_VECTORS);
938 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
939 XTEA_DEC_TEST_VECTORS);
942 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
943 KHAZAD_ENC_TEST_VECTORS);
944 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
945 KHAZAD_DEC_TEST_VECTORS);
948 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
949 ANUBIS_ENC_TEST_VECTORS);
950 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
951 ANUBIS_DEC_TEST_VECTORS);
952 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
953 ANUBIS_CBC_ENC_TEST_VECTORS);
954 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
955 ANUBIS_CBC_ENC_TEST_VECTORS);
958 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
959 XETA_ENC_TEST_VECTORS);
960 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
961 XETA_DEC_TEST_VECTORS);
963 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
964 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
965 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
966 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
967 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
968 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
969 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
970 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
972 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
973 test_hash("hmac(md5)", hmac_md5_tv_template,
974 HMAC_MD5_TEST_VECTORS);
975 test_hash("hmac(sha1)", hmac_sha1_tv_template,
976 HMAC_SHA1_TEST_VECTORS);
977 test_hash("hmac(sha256)", hmac_sha256_tv_template,
978 HMAC_SHA256_TEST_VECTORS);
980 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
981 XCBC_AES_TEST_VECTORS);
983 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
987 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
991 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
995 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
996 DES_ENC_TEST_VECTORS);
997 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
998 DES_DEC_TEST_VECTORS);
999 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1000 DES_CBC_ENC_TEST_VECTORS);
1001 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1002 DES_CBC_DEC_TEST_VECTORS);
1006 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1007 DES3_EDE_ENC_TEST_VECTORS);
1008 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1009 DES3_EDE_DEC_TEST_VECTORS);
1013 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1017 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1021 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1022 BF_ENC_TEST_VECTORS);
1023 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1024 BF_DEC_TEST_VECTORS);
1025 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1026 BF_CBC_ENC_TEST_VECTORS);
1027 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1028 BF_CBC_DEC_TEST_VECTORS);
1032 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1033 TF_ENC_TEST_VECTORS);
1034 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1035 TF_DEC_TEST_VECTORS);
1036 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1037 TF_CBC_ENC_TEST_VECTORS);
1038 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1039 TF_CBC_DEC_TEST_VECTORS);
1043 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1044 SERPENT_ENC_TEST_VECTORS);
1045 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1046 SERPENT_DEC_TEST_VECTORS);
1050 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1051 AES_ENC_TEST_VECTORS);
1052 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1053 AES_DEC_TEST_VECTORS);
1054 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1055 AES_CBC_ENC_TEST_VECTORS);
1056 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1057 AES_CBC_DEC_TEST_VECTORS);
1061 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1065 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1073 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1074 CAST5_ENC_TEST_VECTORS);
1075 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1076 CAST5_DEC_TEST_VECTORS);
1080 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1081 CAST6_ENC_TEST_VECTORS);
1082 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1083 CAST6_DEC_TEST_VECTORS);
1087 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1088 ARC4_ENC_TEST_VECTORS);
1089 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1090 ARC4_DEC_TEST_VECTORS);
1094 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1098 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1102 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1103 TEA_ENC_TEST_VECTORS);
1104 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1105 TEA_DEC_TEST_VECTORS);
1109 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1110 XTEA_ENC_TEST_VECTORS);
1111 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1112 XTEA_DEC_TEST_VECTORS);
1116 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1117 KHAZAD_ENC_TEST_VECTORS);
1118 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1119 KHAZAD_DEC_TEST_VECTORS);
1123 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1127 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1131 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1135 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1136 TNEPRES_ENC_TEST_VECTORS);
1137 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1138 TNEPRES_DEC_TEST_VECTORS);
1142 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1143 ANUBIS_ENC_TEST_VECTORS);
1144 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1145 ANUBIS_DEC_TEST_VECTORS);
1146 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1147 ANUBIS_CBC_ENC_TEST_VECTORS);
1148 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1149 ANUBIS_CBC_ENC_TEST_VECTORS);
1153 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1158 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1162 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1166 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1167 XETA_ENC_TEST_VECTORS);
1168 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1169 XETA_DEC_TEST_VECTORS);
1173 test_hash("hmac(md5)", hmac_md5_tv_template,
1174 HMAC_MD5_TEST_VECTORS);
1178 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1179 HMAC_SHA1_TEST_VECTORS);
1183 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1184 HMAC_SHA256_TEST_VECTORS);
1189 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1190 aes_speed_template);
1191 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1192 aes_speed_template);
1193 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1194 aes_speed_template);
1195 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1196 aes_speed_template);
1200 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1201 des3_ede_enc_tv_template,
1202 DES3_EDE_ENC_TEST_VECTORS,
1203 des3_ede_speed_template);
1204 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1205 des3_ede_dec_tv_template,
1206 DES3_EDE_DEC_TEST_VECTORS,
1207 des3_ede_speed_template);
1208 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1209 des3_ede_enc_tv_template,
1210 DES3_EDE_ENC_TEST_VECTORS,
1211 des3_ede_speed_template);
1212 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1213 des3_ede_dec_tv_template,
1214 DES3_EDE_DEC_TEST_VECTORS,
1215 des3_ede_speed_template);
1219 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1220 twofish_speed_template);
1221 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1222 twofish_speed_template);
1223 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1224 twofish_speed_template);
1225 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1226 twofish_speed_template);
1230 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1231 blowfish_speed_template);
1232 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1233 blowfish_speed_template);
1234 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1235 blowfish_speed_template);
1236 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1237 blowfish_speed_template);
1241 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1242 des_speed_template);
1243 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1244 des_speed_template);
1245 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1246 des_speed_template);
1247 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1248 des_speed_template);
1255 test_hash_speed("md4", sec, generic_hash_speed_template);
1256 if (mode > 300 && mode < 400) break;
1259 test_hash_speed("md5", sec, generic_hash_speed_template);
1260 if (mode > 300 && mode < 400) break;
1263 test_hash_speed("sha1", sec, generic_hash_speed_template);
1264 if (mode > 300 && mode < 400) break;
1267 test_hash_speed("sha256", sec, generic_hash_speed_template);
1268 if (mode > 300 && mode < 400) break;
1271 test_hash_speed("sha384", sec, generic_hash_speed_template);
1272 if (mode > 300 && mode < 400) break;
1275 test_hash_speed("sha512", sec, generic_hash_speed_template);
1276 if (mode > 300 && mode < 400) break;
1279 test_hash_speed("wp256", sec, generic_hash_speed_template);
1280 if (mode > 300 && mode < 400) break;
1283 test_hash_speed("wp384", sec, generic_hash_speed_template);
1284 if (mode > 300 && mode < 400) break;
1287 test_hash_speed("wp512", sec, generic_hash_speed_template);
1288 if (mode > 300 && mode < 400) break;
1291 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1292 if (mode > 300 && mode < 400) break;
1295 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1296 if (mode > 300 && mode < 400) break;
1299 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1300 if (mode > 300 && mode < 400) break;
1310 /* useful for debugging */
1311 printk("not testing anything\n");
1316 static int __init init(void)
1318 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1322 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1333 /* We intentionaly return -EAGAIN to prevent keeping
1334 * the module. It does all its work from init()
1335 * and doesn't offer any runtime functionality
1336 * => we don't need it in the memory, do we?
1343 * If an init function is provided, an exit function must also be provided
1344 * to allow module unload.
1346 static void __exit fini(void) { }
1351 module_param(mode, int, 0);
1352 module_param(sec, uint, 0);
1353 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1354 "(defaults to zero which uses CPU cycles instead)");
1356 MODULE_LICENSE("GPL");
1357 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1358 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");