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_tfm *tfm;
92 struct hash_testvec *hash_tv;
95 printk("\ntesting %s\n", algo);
97 tsize = sizeof(struct hash_testvec);
100 if (tsize > TVMEMSIZE) {
101 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
105 memcpy(tvmem, template, tsize);
106 hash_tv = (void *)tvmem;
107 tfm = crypto_alloc_tfm(algo, 0);
109 printk("failed to load transform for %s\n", algo);
113 for (i = 0; i < tcount; i++) {
114 printk("test %u:\n", i + 1);
115 memset(result, 0, 64);
117 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
119 crypto_digest_init(tfm);
120 crypto_digest_setkey(tfm, hash_tv[i].key, hash_tv[i].ksize);
121 crypto_digest_update(tfm, sg, 1);
122 crypto_digest_final(tfm, result);
124 hexdump(result, crypto_tfm_alg_digestsize(tfm));
126 memcmp(result, hash_tv[i].digest,
127 crypto_tfm_alg_digestsize(tfm)) ?
131 printk("testing %s across pages\n", algo);
133 /* setup the dummy buffer first */
134 memset(xbuf, 0, XBUFSIZE);
137 for (i = 0; i < tcount; i++) {
140 printk("test %u:\n", j);
141 memset(result, 0, 64);
144 for (k = 0; k < hash_tv[i].np; k++) {
145 memcpy(&xbuf[IDX[k]],
146 hash_tv[i].plaintext + temp,
148 temp += hash_tv[i].tap[k];
149 sg_set_buf(&sg[k], &xbuf[IDX[k]],
153 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
155 hexdump(result, crypto_tfm_alg_digestsize(tfm));
157 memcmp(result, hash_tv[i].digest,
158 crypto_tfm_alg_digestsize(tfm)) ?
163 crypto_free_tfm(tfm);
167 #ifdef CONFIG_CRYPTO_HMAC
169 static void test_hmac(char *algo, struct hmac_testvec *template,
172 unsigned int i, j, k, temp;
173 struct scatterlist sg[8];
175 struct crypto_tfm *tfm;
176 struct hmac_testvec *hmac_tv;
177 unsigned int tsize, klen;
179 tfm = crypto_alloc_tfm(algo, 0);
181 printk("failed to load transform for %s\n", algo);
185 printk("\ntesting hmac_%s\n", algo);
187 tsize = sizeof(struct hmac_testvec);
189 if (tsize > TVMEMSIZE) {
190 printk("template (%u) too big for tvmem (%u)\n", tsize,
195 memcpy(tvmem, template, tsize);
196 hmac_tv = (void *)tvmem;
198 for (i = 0; i < tcount; i++) {
199 printk("test %u:\n", i + 1);
200 memset(result, 0, sizeof (result));
202 klen = hmac_tv[i].ksize;
203 sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
205 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
207 hexdump(result, crypto_tfm_alg_digestsize(tfm));
209 memcmp(result, hmac_tv[i].digest,
210 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
214 printk("\ntesting hmac_%s across pages\n", algo);
216 memset(xbuf, 0, XBUFSIZE);
219 for (i = 0; i < tcount; i++) {
222 printk("test %u:\n",j);
223 memset(result, 0, 64);
226 klen = hmac_tv[i].ksize;
227 for (k = 0; k < hmac_tv[i].np; k++) {
228 memcpy(&xbuf[IDX[k]],
229 hmac_tv[i].plaintext + temp,
231 temp += hmac_tv[i].tap[k];
232 sg_set_buf(&sg[k], &xbuf[IDX[k]],
236 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
237 hmac_tv[i].np, result);
238 hexdump(result, crypto_tfm_alg_digestsize(tfm));
241 memcmp(result, hmac_tv[i].digest,
242 crypto_tfm_alg_digestsize(tfm)) ?
247 crypto_free_tfm(tfm);
250 #endif /* CONFIG_CRYPTO_HMAC */
252 static void test_cipher(char *algo, int enc,
253 struct cipher_testvec *template, unsigned int tcount)
255 unsigned int ret, i, j, k, temp;
260 struct crypto_blkcipher *tfm;
262 struct cipher_testvec *cipher_tv;
263 struct blkcipher_desc desc;
264 struct scatterlist sg[8];
272 printk("\ntesting %s %s\n", algo, e);
274 tsize = sizeof (struct cipher_testvec);
277 if (tsize > TVMEMSIZE) {
278 printk("template (%u) too big for tvmem (%u)\n", tsize,
283 memcpy(tvmem, template, tsize);
284 cipher_tv = (void *)tvmem;
286 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
289 printk("failed to load transform for %s: %ld\n", algo,
297 for (i = 0; i < tcount; i++) {
298 if (!(cipher_tv[i].np)) {
300 printk("test %u (%d bit key):\n",
301 j, cipher_tv[i].klen * 8);
303 crypto_blkcipher_clear_flags(tfm, ~0);
305 crypto_blkcipher_set_flags(
306 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
307 key = cipher_tv[i].key;
309 ret = crypto_blkcipher_setkey(tfm, key,
312 printk("setkey() failed flags=%x\n",
313 crypto_blkcipher_get_flags(tfm));
315 if (!cipher_tv[i].fail)
319 sg_set_buf(&sg[0], cipher_tv[i].input,
322 iv_len = crypto_blkcipher_ivsize(tfm);
324 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
327 len = cipher_tv[i].ilen;
329 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
330 crypto_blkcipher_decrypt(&desc, sg, sg, len);
333 printk("%s () failed flags=%x\n", e,
338 q = kmap(sg[0].page) + sg[0].offset;
339 hexdump(q, cipher_tv[i].rlen);
342 memcmp(q, cipher_tv[i].result,
343 cipher_tv[i].rlen) ? "fail" : "pass");
347 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
348 memset(xbuf, 0, XBUFSIZE);
351 for (i = 0; i < tcount; i++) {
352 if (cipher_tv[i].np) {
354 printk("test %u (%d bit key):\n",
355 j, cipher_tv[i].klen * 8);
357 crypto_blkcipher_clear_flags(tfm, ~0);
359 crypto_blkcipher_set_flags(
360 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
361 key = cipher_tv[i].key;
363 ret = crypto_blkcipher_setkey(tfm, key,
366 printk("setkey() failed flags=%x\n",
367 crypto_blkcipher_get_flags(tfm));
369 if (!cipher_tv[i].fail)
374 for (k = 0; k < cipher_tv[i].np; k++) {
375 memcpy(&xbuf[IDX[k]],
376 cipher_tv[i].input + temp,
377 cipher_tv[i].tap[k]);
378 temp += cipher_tv[i].tap[k];
379 sg_set_buf(&sg[k], &xbuf[IDX[k]],
380 cipher_tv[i].tap[k]);
383 iv_len = crypto_blkcipher_ivsize(tfm);
385 crypto_blkcipher_set_iv(tfm, cipher_tv[i].iv,
388 len = cipher_tv[i].ilen;
390 crypto_blkcipher_encrypt(&desc, sg, sg, len) :
391 crypto_blkcipher_decrypt(&desc, sg, sg, len);
394 printk("%s () failed flags=%x\n", e,
400 for (k = 0; k < cipher_tv[i].np; k++) {
401 printk("page %u\n", k);
402 q = kmap(sg[k].page) + sg[k].offset;
403 hexdump(q, cipher_tv[i].tap[k]);
405 memcmp(q, cipher_tv[i].result + temp,
406 cipher_tv[i].tap[k]) ? "fail" :
408 temp += cipher_tv[i].tap[k];
414 crypto_free_blkcipher(tfm);
417 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
420 struct scatterlist sg[1];
421 unsigned long start, end;
425 sg_set_buf(sg, p, blen);
427 for (start = jiffies, end = start + sec * HZ, bcount = 0;
428 time_before(jiffies, end); bcount++) {
430 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
432 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
438 printk("%d operations in %d seconds (%ld bytes)\n",
439 bcount, sec, (long)bcount * blen);
443 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
446 struct scatterlist sg[1];
447 unsigned long cycles = 0;
451 sg_set_buf(sg, p, blen);
457 for (i = 0; i < 4; i++) {
459 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
461 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
467 /* The real thing. */
468 for (i = 0; i < 8; i++) {
471 start = get_cycles();
473 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
475 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
481 cycles += end - start;
489 printk("1 operation in %lu cycles (%d bytes)\n",
490 (cycles + 4) / 8, blen);
495 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
496 struct cipher_testvec *template,
497 unsigned int tcount, struct cipher_speed *speed)
499 unsigned int ret, i, j, iv_len;
500 unsigned char *key, *p, iv[128];
501 struct crypto_blkcipher *tfm;
502 struct blkcipher_desc desc;
510 printk("\ntesting speed of %s %s\n", algo, e);
512 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
515 printk("failed to load transform for %s: %ld\n", algo,
522 for (i = 0; speed[i].klen != 0; i++) {
523 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
524 printk("template (%u) too big for tvmem (%u)\n",
525 speed[i].blen + speed[i].klen, TVMEMSIZE);
529 printk("test %u (%d bit key, %d byte blocks): ", i,
530 speed[i].klen * 8, speed[i].blen);
532 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
534 /* set key, plain text and IV */
535 key = (unsigned char *)tvmem;
536 for (j = 0; j < tcount; j++) {
537 if (template[j].klen == speed[i].klen) {
538 key = template[j].key;
542 p = (unsigned char *)tvmem + speed[i].klen;
544 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
546 printk("setkey() failed flags=%x\n",
547 crypto_blkcipher_get_flags(tfm));
551 iv_len = crypto_blkcipher_ivsize(tfm);
553 memset(&iv, 0xff, iv_len);
554 crypto_blkcipher_set_iv(tfm, iv, iv_len);
558 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
561 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
564 printk("%s() failed flags=%x\n", e, desc.flags);
570 crypto_free_blkcipher(tfm);
573 static void test_digest_jiffies(struct crypto_tfm *tfm, char *p, int blen,
574 int plen, char *out, int sec)
576 struct scatterlist sg[1];
577 unsigned long start, end;
580 for (start = jiffies, end = start + sec * HZ, bcount = 0;
581 time_before(jiffies, end); bcount++) {
582 crypto_digest_init(tfm);
583 for (pcount = 0; pcount < blen; pcount += plen) {
584 sg_set_buf(sg, p + pcount, plen);
585 crypto_digest_update(tfm, sg, 1);
587 /* we assume there is enough space in 'out' for the result */
588 crypto_digest_final(tfm, out);
591 printk("%6u opers/sec, %9lu bytes/sec\n",
592 bcount / sec, ((long)bcount * blen) / sec);
597 static void test_digest_cycles(struct crypto_tfm *tfm, char *p, int blen,
600 struct scatterlist sg[1];
601 unsigned long cycles = 0;
608 for (i = 0; i < 4; i++) {
609 crypto_digest_init(tfm);
610 for (pcount = 0; pcount < blen; pcount += plen) {
611 sg_set_buf(sg, p + pcount, plen);
612 crypto_digest_update(tfm, sg, 1);
614 crypto_digest_final(tfm, out);
617 /* The real thing. */
618 for (i = 0; i < 8; i++) {
621 crypto_digest_init(tfm);
623 start = get_cycles();
625 for (pcount = 0; pcount < blen; pcount += plen) {
626 sg_set_buf(sg, p + pcount, plen);
627 crypto_digest_update(tfm, sg, 1);
629 crypto_digest_final(tfm, out);
633 cycles += end - start;
639 printk("%6lu cycles/operation, %4lu cycles/byte\n",
640 cycles / 8, cycles / (8 * blen));
645 static void test_digest_speed(char *algo, unsigned int sec,
646 struct digest_speed *speed)
648 struct crypto_tfm *tfm;
652 printk("\ntesting speed of %s\n", algo);
654 tfm = crypto_alloc_tfm(algo, 0);
657 printk("failed to load transform for %s\n", algo);
661 if (crypto_tfm_alg_digestsize(tfm) > sizeof(output)) {
662 printk("digestsize(%u) > outputbuffer(%zu)\n",
663 crypto_tfm_alg_digestsize(tfm), sizeof(output));
667 for (i = 0; speed[i].blen != 0; i++) {
668 if (speed[i].blen > TVMEMSIZE) {
669 printk("template (%u) too big for tvmem (%u)\n",
670 speed[i].blen, TVMEMSIZE);
674 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
675 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
677 memset(tvmem, 0xff, speed[i].blen);
680 test_digest_jiffies(tfm, tvmem, speed[i].blen, speed[i].plen, output, sec);
682 test_digest_cycles(tfm, tvmem, speed[i].blen, speed[i].plen, output);
686 crypto_free_tfm(tfm);
689 static void test_deflate(void)
692 char result[COMP_BUF_SIZE];
693 struct crypto_tfm *tfm;
694 struct comp_testvec *tv;
697 printk("\ntesting deflate compression\n");
699 tsize = sizeof (deflate_comp_tv_template);
700 if (tsize > TVMEMSIZE) {
701 printk("template (%u) too big for tvmem (%u)\n", tsize,
706 memcpy(tvmem, deflate_comp_tv_template, tsize);
709 tfm = crypto_alloc_tfm("deflate", 0);
711 printk("failed to load transform for deflate\n");
715 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
716 int ilen, ret, dlen = COMP_BUF_SIZE;
718 printk("test %u:\n", i + 1);
719 memset(result, 0, sizeof (result));
722 ret = crypto_comp_compress(tfm, tv[i].input,
723 ilen, result, &dlen);
725 printk("fail: ret=%d\n", ret);
728 hexdump(result, dlen);
729 printk("%s (ratio %d:%d)\n",
730 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
734 printk("\ntesting deflate decompression\n");
736 tsize = sizeof (deflate_decomp_tv_template);
737 if (tsize > TVMEMSIZE) {
738 printk("template (%u) too big for tvmem (%u)\n", tsize,
743 memcpy(tvmem, deflate_decomp_tv_template, tsize);
746 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
747 int ilen, ret, dlen = COMP_BUF_SIZE;
749 printk("test %u:\n", i + 1);
750 memset(result, 0, sizeof (result));
753 ret = crypto_comp_decompress(tfm, tv[i].input,
754 ilen, result, &dlen);
756 printk("fail: ret=%d\n", ret);
759 hexdump(result, dlen);
760 printk("%s (ratio %d:%d)\n",
761 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
765 crypto_free_tfm(tfm);
768 static void test_available(void)
773 printk("alg %s ", *name);
774 printk((crypto_alg_available(*name, 0)) ?
775 "found\n" : "not found\n");
780 static void do_test(void)
785 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
787 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
790 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
791 DES_ENC_TEST_VECTORS);
792 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
793 DES_DEC_TEST_VECTORS);
794 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
795 DES_CBC_ENC_TEST_VECTORS);
796 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
797 DES_CBC_DEC_TEST_VECTORS);
800 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
801 DES3_EDE_ENC_TEST_VECTORS);
802 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
803 DES3_EDE_DEC_TEST_VECTORS);
805 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
807 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
810 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
811 BF_ENC_TEST_VECTORS);
812 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
813 BF_DEC_TEST_VECTORS);
814 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
815 BF_CBC_ENC_TEST_VECTORS);
816 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
817 BF_CBC_DEC_TEST_VECTORS);
820 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
821 TF_ENC_TEST_VECTORS);
822 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
823 TF_DEC_TEST_VECTORS);
824 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
825 TF_CBC_ENC_TEST_VECTORS);
826 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
827 TF_CBC_DEC_TEST_VECTORS);
830 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
831 SERPENT_ENC_TEST_VECTORS);
832 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
833 SERPENT_DEC_TEST_VECTORS);
836 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
837 TNEPRES_ENC_TEST_VECTORS);
838 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
839 TNEPRES_DEC_TEST_VECTORS);
842 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
843 AES_ENC_TEST_VECTORS);
844 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
845 AES_DEC_TEST_VECTORS);
846 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
847 AES_CBC_ENC_TEST_VECTORS);
848 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
849 AES_CBC_DEC_TEST_VECTORS);
852 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
853 CAST5_ENC_TEST_VECTORS);
854 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
855 CAST5_DEC_TEST_VECTORS);
858 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
859 CAST6_ENC_TEST_VECTORS);
860 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
861 CAST6_DEC_TEST_VECTORS);
864 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
865 ARC4_ENC_TEST_VECTORS);
866 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
867 ARC4_DEC_TEST_VECTORS);
870 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
871 TEA_ENC_TEST_VECTORS);
872 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
873 TEA_DEC_TEST_VECTORS);
877 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
878 XTEA_ENC_TEST_VECTORS);
879 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
880 XTEA_DEC_TEST_VECTORS);
883 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
884 KHAZAD_ENC_TEST_VECTORS);
885 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
886 KHAZAD_DEC_TEST_VECTORS);
889 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
890 ANUBIS_ENC_TEST_VECTORS);
891 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
892 ANUBIS_DEC_TEST_VECTORS);
893 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
894 ANUBIS_CBC_ENC_TEST_VECTORS);
895 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
896 ANUBIS_CBC_ENC_TEST_VECTORS);
899 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
900 XETA_ENC_TEST_VECTORS);
901 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
902 XETA_DEC_TEST_VECTORS);
904 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
905 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
906 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
907 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
908 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
909 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
910 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
911 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
913 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
914 #ifdef CONFIG_CRYPTO_HMAC
915 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
916 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
917 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
920 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
924 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
928 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
932 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
933 DES_ENC_TEST_VECTORS);
934 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
935 DES_DEC_TEST_VECTORS);
936 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
937 DES_CBC_ENC_TEST_VECTORS);
938 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
939 DES_CBC_DEC_TEST_VECTORS);
943 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
944 DES3_EDE_ENC_TEST_VECTORS);
945 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
946 DES3_EDE_DEC_TEST_VECTORS);
950 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
954 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
958 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
959 BF_ENC_TEST_VECTORS);
960 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
961 BF_DEC_TEST_VECTORS);
962 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
963 BF_CBC_ENC_TEST_VECTORS);
964 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
965 BF_CBC_DEC_TEST_VECTORS);
969 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
970 TF_ENC_TEST_VECTORS);
971 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
972 TF_DEC_TEST_VECTORS);
973 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
974 TF_CBC_ENC_TEST_VECTORS);
975 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
976 TF_CBC_DEC_TEST_VECTORS);
980 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
981 SERPENT_ENC_TEST_VECTORS);
982 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
983 SERPENT_DEC_TEST_VECTORS);
987 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
988 AES_ENC_TEST_VECTORS);
989 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
990 AES_DEC_TEST_VECTORS);
991 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
992 AES_CBC_ENC_TEST_VECTORS);
993 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
994 AES_CBC_DEC_TEST_VECTORS);
998 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1002 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1010 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1011 CAST5_ENC_TEST_VECTORS);
1012 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1013 CAST5_DEC_TEST_VECTORS);
1017 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1018 CAST6_ENC_TEST_VECTORS);
1019 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1020 CAST6_DEC_TEST_VECTORS);
1024 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1025 ARC4_ENC_TEST_VECTORS);
1026 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1027 ARC4_DEC_TEST_VECTORS);
1031 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1035 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1039 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1040 TEA_ENC_TEST_VECTORS);
1041 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1042 TEA_DEC_TEST_VECTORS);
1046 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1047 XTEA_ENC_TEST_VECTORS);
1048 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1049 XTEA_DEC_TEST_VECTORS);
1053 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1054 KHAZAD_ENC_TEST_VECTORS);
1055 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1056 KHAZAD_DEC_TEST_VECTORS);
1060 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1064 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1068 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1072 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1073 TNEPRES_ENC_TEST_VECTORS);
1074 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1075 TNEPRES_DEC_TEST_VECTORS);
1079 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1080 ANUBIS_ENC_TEST_VECTORS);
1081 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1082 ANUBIS_DEC_TEST_VECTORS);
1083 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1084 ANUBIS_CBC_ENC_TEST_VECTORS);
1085 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1086 ANUBIS_CBC_ENC_TEST_VECTORS);
1090 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1095 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1099 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1103 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1104 XETA_ENC_TEST_VECTORS);
1105 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1106 XETA_DEC_TEST_VECTORS);
1109 #ifdef CONFIG_CRYPTO_HMAC
1111 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
1115 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
1119 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
1125 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1126 aes_speed_template);
1127 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1128 aes_speed_template);
1129 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1130 aes_speed_template);
1131 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1132 aes_speed_template);
1136 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1137 des3_ede_enc_tv_template,
1138 DES3_EDE_ENC_TEST_VECTORS,
1139 des3_ede_speed_template);
1140 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1141 des3_ede_dec_tv_template,
1142 DES3_EDE_DEC_TEST_VECTORS,
1143 des3_ede_speed_template);
1144 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1145 des3_ede_enc_tv_template,
1146 DES3_EDE_ENC_TEST_VECTORS,
1147 des3_ede_speed_template);
1148 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1149 des3_ede_dec_tv_template,
1150 DES3_EDE_DEC_TEST_VECTORS,
1151 des3_ede_speed_template);
1155 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1156 twofish_speed_template);
1157 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1158 twofish_speed_template);
1159 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1160 twofish_speed_template);
1161 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1162 twofish_speed_template);
1166 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1167 blowfish_speed_template);
1168 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1169 blowfish_speed_template);
1170 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1171 blowfish_speed_template);
1172 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1173 blowfish_speed_template);
1177 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1178 des_speed_template);
1179 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1180 des_speed_template);
1181 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1182 des_speed_template);
1183 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1184 des_speed_template);
1191 test_digest_speed("md4", sec, generic_digest_speed_template);
1192 if (mode > 300 && mode < 400) break;
1195 test_digest_speed("md5", sec, generic_digest_speed_template);
1196 if (mode > 300 && mode < 400) break;
1199 test_digest_speed("sha1", sec, generic_digest_speed_template);
1200 if (mode > 300 && mode < 400) break;
1203 test_digest_speed("sha256", sec, generic_digest_speed_template);
1204 if (mode > 300 && mode < 400) break;
1207 test_digest_speed("sha384", sec, generic_digest_speed_template);
1208 if (mode > 300 && mode < 400) break;
1211 test_digest_speed("sha512", sec, generic_digest_speed_template);
1212 if (mode > 300 && mode < 400) break;
1215 test_digest_speed("wp256", sec, generic_digest_speed_template);
1216 if (mode > 300 && mode < 400) break;
1219 test_digest_speed("wp384", sec, generic_digest_speed_template);
1220 if (mode > 300 && mode < 400) break;
1223 test_digest_speed("wp512", sec, generic_digest_speed_template);
1224 if (mode > 300 && mode < 400) break;
1227 test_digest_speed("tgr128", sec, generic_digest_speed_template);
1228 if (mode > 300 && mode < 400) break;
1231 test_digest_speed("tgr160", sec, generic_digest_speed_template);
1232 if (mode > 300 && mode < 400) break;
1235 test_digest_speed("tgr192", sec, generic_digest_speed_template);
1236 if (mode > 300 && mode < 400) break;
1246 /* useful for debugging */
1247 printk("not testing anything\n");
1252 static int __init init(void)
1254 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1258 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1269 /* We intentionaly return -EAGAIN to prevent keeping
1270 * the module. It does all its work from init()
1271 * and doesn't offer any runtime functionality
1272 * => we don't need it in the memory, do we?
1279 * If an init function is provided, an exit function must also be provided
1280 * to allow module unload.
1282 static void __exit fini(void) { }
1287 module_param(mode, int, 0);
1288 module_param(sec, uint, 0);
1289 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1290 "(defaults to zero which uses CPU cycles instead)");
1292 MODULE_LICENSE("GPL");
1293 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1294 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");