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/init.h>
21 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/scatterlist.h>
25 #include <linux/string.h>
26 #include <linux/crypto.h>
27 #include <linux/highmem.h>
28 #include <linux/moduleparam.h>
29 #include <linux/jiffies.h>
30 #include <linux/timex.h>
31 #include <linux/interrupt.h>
35 * Need to kmalloc() memory for testing kmap().
37 #define TVMEMSIZE 16384
38 #define XBUFSIZE 32768
41 * Indexes into the xbuf to simulate cross-page access.
53 * Used by test_cipher()
60 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
63 * Used by test_cipher_speed()
65 static unsigned int sec;
71 static char *check[] = {
72 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
73 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
74 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
75 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", NULL
78 static void hexdump(unsigned char *buf, unsigned int len)
81 printk("%02x", *buf++);
86 static void test_hash(char *algo, struct hash_testvec *template,
89 unsigned int i, j, k, temp;
90 struct scatterlist sg[8];
92 struct crypto_tfm *tfm;
93 struct hash_testvec *hash_tv;
96 printk("\ntesting %s\n", algo);
98 tsize = sizeof(struct hash_testvec);
101 if (tsize > TVMEMSIZE) {
102 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
106 memcpy(tvmem, template, tsize);
107 hash_tv = (void *)tvmem;
108 tfm = crypto_alloc_tfm(algo, 0);
110 printk("failed to load transform for %s\n", algo);
114 for (i = 0; i < tcount; i++) {
115 printk("test %u:\n", i + 1);
116 memset(result, 0, 64);
118 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
120 crypto_digest_init(tfm);
121 if (tfm->crt_u.digest.dit_setkey) {
122 crypto_digest_setkey(tfm, hash_tv[i].key,
125 crypto_digest_update(tfm, sg, 1);
126 crypto_digest_final(tfm, result);
128 hexdump(result, crypto_tfm_alg_digestsize(tfm));
130 memcmp(result, hash_tv[i].digest,
131 crypto_tfm_alg_digestsize(tfm)) ?
135 printk("testing %s across pages\n", algo);
137 /* setup the dummy buffer first */
138 memset(xbuf, 0, XBUFSIZE);
141 for (i = 0; i < tcount; i++) {
144 printk("test %u:\n", j);
145 memset(result, 0, 64);
148 for (k = 0; k < hash_tv[i].np; k++) {
149 memcpy(&xbuf[IDX[k]],
150 hash_tv[i].plaintext + temp,
152 temp += hash_tv[i].tap[k];
153 sg_set_buf(&sg[k], &xbuf[IDX[k]],
157 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
159 hexdump(result, crypto_tfm_alg_digestsize(tfm));
161 memcmp(result, hash_tv[i].digest,
162 crypto_tfm_alg_digestsize(tfm)) ?
167 crypto_free_tfm(tfm);
171 #ifdef CONFIG_CRYPTO_HMAC
173 static void test_hmac(char *algo, struct hmac_testvec *template,
176 unsigned int i, j, k, temp;
177 struct scatterlist sg[8];
179 struct crypto_tfm *tfm;
180 struct hmac_testvec *hmac_tv;
181 unsigned int tsize, klen;
183 tfm = crypto_alloc_tfm(algo, 0);
185 printk("failed to load transform for %s\n", algo);
189 printk("\ntesting hmac_%s\n", algo);
191 tsize = sizeof(struct hmac_testvec);
193 if (tsize > TVMEMSIZE) {
194 printk("template (%u) too big for tvmem (%u)\n", tsize,
199 memcpy(tvmem, template, tsize);
200 hmac_tv = (void *)tvmem;
202 for (i = 0; i < tcount; i++) {
203 printk("test %u:\n", i + 1);
204 memset(result, 0, sizeof (result));
206 klen = hmac_tv[i].ksize;
207 sg_set_buf(&sg[0], hmac_tv[i].plaintext, hmac_tv[i].psize);
209 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
211 hexdump(result, crypto_tfm_alg_digestsize(tfm));
213 memcmp(result, hmac_tv[i].digest,
214 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
218 printk("\ntesting hmac_%s across pages\n", algo);
220 memset(xbuf, 0, XBUFSIZE);
223 for (i = 0; i < tcount; i++) {
226 printk("test %u:\n",j);
227 memset(result, 0, 64);
230 klen = hmac_tv[i].ksize;
231 for (k = 0; k < hmac_tv[i].np; k++) {
232 memcpy(&xbuf[IDX[k]],
233 hmac_tv[i].plaintext + temp,
235 temp += hmac_tv[i].tap[k];
236 sg_set_buf(&sg[k], &xbuf[IDX[k]],
240 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
241 hmac_tv[i].np, result);
242 hexdump(result, crypto_tfm_alg_digestsize(tfm));
245 memcmp(result, hmac_tv[i].digest,
246 crypto_tfm_alg_digestsize(tfm)) ?
251 crypto_free_tfm(tfm);
254 #endif /* CONFIG_CRYPTO_HMAC */
256 static void test_cipher(char *algo, int mode, int enc,
257 struct cipher_testvec *template, unsigned int tcount)
259 unsigned int ret, i, j, k, temp;
262 struct crypto_tfm *tfm;
264 struct cipher_testvec *cipher_tv;
265 struct scatterlist sg[8];
272 if (mode == MODE_ECB)
277 printk("\ntesting %s %s %s\n", algo, m, e);
279 tsize = sizeof (struct cipher_testvec);
282 if (tsize > TVMEMSIZE) {
283 printk("template (%u) too big for tvmem (%u)\n", tsize,
288 memcpy(tvmem, template, tsize);
289 cipher_tv = (void *)tvmem;
292 tfm = crypto_alloc_tfm(algo, 0);
294 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
297 printk("failed to load transform for %s %s\n", algo, m);
302 for (i = 0; i < tcount; i++) {
303 if (!(cipher_tv[i].np)) {
305 printk("test %u (%d bit key):\n",
306 j, cipher_tv[i].klen * 8);
310 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
311 key = cipher_tv[i].key;
313 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
315 printk("setkey() failed flags=%x\n", tfm->crt_flags);
317 if (!cipher_tv[i].fail)
321 sg_set_buf(&sg[0], cipher_tv[i].input,
325 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
326 crypto_tfm_alg_ivsize(tfm));
330 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
332 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
336 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
340 q = kmap(sg[0].page) + sg[0].offset;
341 hexdump(q, cipher_tv[i].rlen);
344 memcmp(q, cipher_tv[i].result,
345 cipher_tv[i].rlen) ? "fail" : "pass");
349 printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e);
350 memset(xbuf, 0, XBUFSIZE);
353 for (i = 0; i < tcount; i++) {
354 if (cipher_tv[i].np) {
356 printk("test %u (%d bit key):\n",
357 j, cipher_tv[i].klen * 8);
361 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
362 key = cipher_tv[i].key;
364 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
366 printk("setkey() failed flags=%x\n", tfm->crt_flags);
368 if (!cipher_tv[i].fail)
373 for (k = 0; k < cipher_tv[i].np; k++) {
374 memcpy(&xbuf[IDX[k]],
375 cipher_tv[i].input + temp,
376 cipher_tv[i].tap[k]);
377 temp += cipher_tv[i].tap[k];
378 sg_set_buf(&sg[k], &xbuf[IDX[k]],
379 cipher_tv[i].tap[k]);
383 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
384 crypto_tfm_alg_ivsize(tfm));
388 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
390 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
393 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
398 for (k = 0; k < cipher_tv[i].np; k++) {
399 printk("page %u\n", k);
400 q = kmap(sg[k].page) + sg[k].offset;
401 hexdump(q, cipher_tv[i].tap[k]);
403 memcmp(q, cipher_tv[i].result + temp,
404 cipher_tv[i].tap[k]) ? "fail" :
406 temp += cipher_tv[i].tap[k];
412 crypto_free_tfm(tfm);
415 static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p,
418 struct scatterlist sg[1];
419 unsigned long start, end;
423 sg_set_buf(sg, p, blen);
425 for (start = jiffies, end = start + sec * HZ, bcount = 0;
426 time_before(jiffies, end); bcount++) {
428 ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
430 ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
436 printk("%d operations in %d seconds (%ld bytes)\n",
437 bcount, sec, (long)bcount * blen);
441 static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p,
444 struct scatterlist sg[1];
445 unsigned long cycles = 0;
449 sg_set_buf(sg, p, blen);
455 for (i = 0; i < 4; i++) {
457 ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
459 ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
465 /* The real thing. */
466 for (i = 0; i < 8; i++) {
469 start = get_cycles();
471 ret = crypto_cipher_encrypt(tfm, sg, sg, blen);
473 ret = crypto_cipher_decrypt(tfm, sg, sg, blen);
479 cycles += end - start;
487 printk("1 operation in %lu cycles (%d bytes)\n",
488 (cycles + 4) / 8, blen);
493 static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec,
494 struct cipher_testvec *template,
495 unsigned int tcount, struct cipher_speed *speed)
497 unsigned int ret, i, j, iv_len;
498 unsigned char *key, *p, iv[128];
499 struct crypto_tfm *tfm;
506 if (mode == MODE_ECB)
511 printk("\ntesting speed of %s %s %s\n", algo, m, e);
514 tfm = crypto_alloc_tfm(algo, 0);
516 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
519 printk("failed to load transform for %s %s\n", algo, m);
523 for (i = 0; speed[i].klen != 0; i++) {
524 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
525 printk("template (%u) too big for tvmem (%u)\n",
526 speed[i].blen + speed[i].klen, TVMEMSIZE);
530 printk("test %u (%d bit key, %d byte blocks): ", i,
531 speed[i].klen * 8, speed[i].blen);
533 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
535 /* set key, plain text and IV */
536 key = (unsigned char *)tvmem;
537 for (j = 0; j < tcount; j++) {
538 if (template[j].klen == speed[i].klen) {
539 key = template[j].key;
543 p = (unsigned char *)tvmem + speed[i].klen;
545 ret = crypto_cipher_setkey(tfm, key, speed[i].klen);
547 printk("setkey() failed flags=%x\n", tfm->crt_flags);
552 iv_len = crypto_tfm_alg_ivsize(tfm);
553 memset(&iv, 0xff, iv_len);
554 crypto_cipher_set_iv(tfm, iv, iv_len);
558 ret = test_cipher_jiffies(tfm, enc, p, speed[i].blen,
561 ret = test_cipher_cycles(tfm, enc, p, speed[i].blen);
564 printk("%s() failed flags=%x\n", e, tfm->crt_flags);
570 crypto_free_tfm(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_crc32c(void)
775 u8 b, test_vec[NUMVEC][VECSIZE];
776 static u32 vec_results[NUMVEC] = {
777 0x0e2c157f, 0xe980ebf6, 0xde74bded,
778 0xd579c862, 0xba979ad0, 0x2b29d913
780 static u32 tot_vec_results = 0x24c5d375;
782 struct scatterlist sg[NUMVEC];
783 struct crypto_tfm *tfm;
784 char *fmtdata = "testing crc32c initialized to %08x: %s\n";
785 #define SEEDTESTVAL 0xedcba987
788 printk("\ntesting crc32c\n");
790 tfm = crypto_alloc_tfm("crc32c", 0);
792 printk("failed to load transform for crc32c\n");
796 crypto_digest_init(tfm);
797 crypto_digest_final(tfm, (u8*)&crc);
798 printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR");
801 * stuff test_vec with known values, simple incrementing
805 for (i = 0; i < NUMVEC; i++) {
806 for (j = 0; j < VECSIZE; j++)
807 test_vec[i][j] = ++b;
808 sg_set_buf(&sg[i], test_vec[i], VECSIZE);
812 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
813 crypto_digest_final(tfm, (u8*)&crc);
814 printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ?
817 printk("testing crc32c using update/final:\n");
819 pass = 1; /* assume all is well */
821 for (i = 0; i < NUMVEC; i++) {
823 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
824 crypto_digest_update(tfm, &sg[i], 1);
825 crypto_digest_final(tfm, (u8*)&crc);
826 if (crc == vec_results[i]) {
827 printk(" %08x:OK", crc);
829 printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]);
834 printk("\ntesting crc32c using incremental accumulator:\n");
836 for (i = 0; i < NUMVEC; i++) {
837 seed = (crc ^ ~(u32)0);
838 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
839 crypto_digest_update(tfm, &sg[i], 1);
840 crypto_digest_final(tfm, (u8*)&crc);
842 if (crc == tot_vec_results) {
843 printk(" %08x:OK", crc);
845 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
849 printk("\ntesting crc32c using digest:\n");
851 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
852 crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc);
853 if (crc == tot_vec_results) {
854 printk(" %08x:OK", crc);
856 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
860 printk("\n%s\n", pass ? "pass" : "ERROR");
862 crypto_free_tfm(tfm);
863 printk("crc32c test complete\n");
866 static void test_available(void)
871 printk("alg %s ", *name);
872 printk((crypto_alg_available(*name, 0)) ?
873 "found\n" : "not found\n");
878 static void do_test(void)
883 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
885 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
888 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
889 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
890 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
891 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
894 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
895 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
897 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
899 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
902 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
903 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
904 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
905 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
908 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
909 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
910 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
911 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
914 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
915 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
918 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
919 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
922 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
923 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
924 test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
925 test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
928 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
929 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
932 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
933 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
936 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
937 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
940 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
941 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
945 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
946 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
949 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
950 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
953 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
954 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
955 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
956 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
959 test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
960 test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
962 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
963 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
964 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
965 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
966 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
967 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
968 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
969 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
972 #ifdef CONFIG_CRYPTO_HMAC
973 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
974 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
975 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
978 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
982 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
986 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
990 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
991 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
992 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
993 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
997 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
998 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
1002 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1006 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1010 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
1011 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
1012 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
1013 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
1017 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
1018 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
1019 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
1020 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
1024 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
1025 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
1029 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
1030 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
1031 test_cipher ("aes", MODE_CBC, ENCRYPT, aes_cbc_enc_tv_template, AES_CBC_ENC_TEST_VECTORS);
1032 test_cipher ("aes", MODE_CBC, DECRYPT, aes_cbc_dec_tv_template, AES_CBC_DEC_TEST_VECTORS);
1036 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1040 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1048 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
1049 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
1053 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
1054 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
1058 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
1059 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
1063 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1071 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
1072 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
1076 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
1077 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
1081 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
1082 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
1086 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1090 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1094 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1098 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
1099 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
1103 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
1104 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
1105 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
1106 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
1110 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1115 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1119 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1123 test_cipher ("xeta", MODE_ECB, ENCRYPT, xeta_enc_tv_template, XETA_ENC_TEST_VECTORS);
1124 test_cipher ("xeta", MODE_ECB, DECRYPT, xeta_dec_tv_template, XETA_DEC_TEST_VECTORS);
1127 #ifdef CONFIG_CRYPTO_HMAC
1129 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
1133 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
1137 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
1143 test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0,
1144 aes_speed_template);
1145 test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0,
1146 aes_speed_template);
1147 test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, NULL, 0,
1148 aes_speed_template);
1149 test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0,
1150 aes_speed_template);
1154 test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec,
1155 des3_ede_enc_tv_template,
1156 DES3_EDE_ENC_TEST_VECTORS,
1157 des3_ede_speed_template);
1158 test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec,
1159 des3_ede_dec_tv_template,
1160 DES3_EDE_DEC_TEST_VECTORS,
1161 des3_ede_speed_template);
1162 test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec,
1163 des3_ede_enc_tv_template,
1164 DES3_EDE_ENC_TEST_VECTORS,
1165 des3_ede_speed_template);
1166 test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec,
1167 des3_ede_dec_tv_template,
1168 DES3_EDE_DEC_TEST_VECTORS,
1169 des3_ede_speed_template);
1173 test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0,
1174 twofish_speed_template);
1175 test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0,
1176 twofish_speed_template);
1177 test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, NULL, 0,
1178 twofish_speed_template);
1179 test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0,
1180 twofish_speed_template);
1184 test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0,
1185 blowfish_speed_template);
1186 test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0,
1187 blowfish_speed_template);
1188 test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, NULL, 0,
1189 blowfish_speed_template);
1190 test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0,
1191 blowfish_speed_template);
1195 test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0,
1196 des_speed_template);
1197 test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0,
1198 des_speed_template);
1199 test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, NULL, 0,
1200 des_speed_template);
1201 test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0,
1202 des_speed_template);
1209 test_digest_speed("md4", sec, generic_digest_speed_template);
1210 if (mode > 300 && mode < 400) break;
1213 test_digest_speed("md5", sec, generic_digest_speed_template);
1214 if (mode > 300 && mode < 400) break;
1217 test_digest_speed("sha1", sec, generic_digest_speed_template);
1218 if (mode > 300 && mode < 400) break;
1221 test_digest_speed("sha256", sec, generic_digest_speed_template);
1222 if (mode > 300 && mode < 400) break;
1225 test_digest_speed("sha384", sec, generic_digest_speed_template);
1226 if (mode > 300 && mode < 400) break;
1229 test_digest_speed("sha512", sec, generic_digest_speed_template);
1230 if (mode > 300 && mode < 400) break;
1233 test_digest_speed("wp256", sec, generic_digest_speed_template);
1234 if (mode > 300 && mode < 400) break;
1237 test_digest_speed("wp384", sec, generic_digest_speed_template);
1238 if (mode > 300 && mode < 400) break;
1241 test_digest_speed("wp512", sec, generic_digest_speed_template);
1242 if (mode > 300 && mode < 400) break;
1245 test_digest_speed("tgr128", sec, generic_digest_speed_template);
1246 if (mode > 300 && mode < 400) break;
1249 test_digest_speed("tgr160", sec, generic_digest_speed_template);
1250 if (mode > 300 && mode < 400) break;
1253 test_digest_speed("tgr192", sec, generic_digest_speed_template);
1254 if (mode > 300 && mode < 400) break;
1264 /* useful for debugging */
1265 printk("not testing anything\n");
1270 static int __init init(void)
1272 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1276 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1287 /* We intentionaly return -EAGAIN to prevent keeping
1288 * the module. It does all its work from init()
1289 * and doesn't offer any runtime functionality
1290 * => we don't need it in the memory, do we?
1297 * If an init function is provided, an exit function must also be provided
1298 * to allow module unload.
1300 static void __exit fini(void) { }
1305 module_param(mode, int, 0);
1306 module_param(sec, uint, 0);
1307 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1308 "(defaults to zero which uses CPU cycles instead)");
1310 MODULE_LICENSE("GPL");
1311 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1312 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");