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 <asm/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>
33 * Need to kmalloc() memory for testing kmap().
35 #define TVMEMSIZE 16384
36 #define XBUFSIZE 32768
39 * Indexes into the xbuf to simulate cross-page access.
51 * Used by test_cipher()
58 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
61 * Used by test_cipher_speed()
63 static unsigned int sec = 10;
69 static char *check[] = {
70 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
71 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
72 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
73 "khazad", "wp512", "wp384", "wp256", "tnepres", NULL
76 static void hexdump(unsigned char *buf, unsigned int len)
79 printk("%02x", *buf++);
84 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 p = hash_tv[i].plaintext;
118 sg[0].page = virt_to_page(p);
119 sg[0].offset = offset_in_page(p);
120 sg[0].length = hash_tv[i].psize;
122 crypto_digest_init(tfm);
123 if (tfm->crt_u.digest.dit_setkey) {
124 crypto_digest_setkey(tfm, hash_tv[i].key,
127 crypto_digest_update(tfm, sg, 1);
128 crypto_digest_final(tfm, result);
130 hexdump(result, crypto_tfm_alg_digestsize(tfm));
132 memcmp(result, hash_tv[i].digest,
133 crypto_tfm_alg_digestsize(tfm)) ?
137 printk("testing %s across pages\n", algo);
139 /* setup the dummy buffer first */
140 memset(xbuf, 0, XBUFSIZE);
143 for (i = 0; i < tcount; i++) {
146 printk("test %u:\n", j);
147 memset(result, 0, 64);
150 for (k = 0; k < hash_tv[i].np; k++) {
151 memcpy(&xbuf[IDX[k]],
152 hash_tv[i].plaintext + temp,
154 temp += hash_tv[i].tap[k];
156 sg[k].page = virt_to_page(p);
157 sg[k].offset = offset_in_page(p);
158 sg[k].length = hash_tv[i].tap[k];
161 crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
163 hexdump(result, crypto_tfm_alg_digestsize(tfm));
165 memcmp(result, hash_tv[i].digest,
166 crypto_tfm_alg_digestsize(tfm)) ?
171 crypto_free_tfm(tfm);
175 #ifdef CONFIG_CRYPTO_HMAC
177 static void test_hmac(char *algo, struct hmac_testvec *template,
181 unsigned int i, j, k, temp;
182 struct scatterlist sg[8];
184 struct crypto_tfm *tfm;
185 struct hmac_testvec *hmac_tv;
186 unsigned int tsize, klen;
188 tfm = crypto_alloc_tfm(algo, 0);
190 printk("failed to load transform for %s\n", algo);
194 printk("\ntesting hmac_%s\n", algo);
196 tsize = sizeof(struct hmac_testvec);
198 if (tsize > TVMEMSIZE) {
199 printk("template (%u) too big for tvmem (%u)\n", tsize,
204 memcpy(tvmem, template, tsize);
205 hmac_tv = (void *)tvmem;
207 for (i = 0; i < tcount; i++) {
208 printk("test %u:\n", i + 1);
209 memset(result, 0, sizeof (result));
211 p = hmac_tv[i].plaintext;
212 klen = hmac_tv[i].ksize;
213 sg[0].page = virt_to_page(p);
214 sg[0].offset = offset_in_page(p);
215 sg[0].length = hmac_tv[i].psize;
217 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
219 hexdump(result, crypto_tfm_alg_digestsize(tfm));
221 memcmp(result, hmac_tv[i].digest,
222 crypto_tfm_alg_digestsize(tfm)) ? "fail" :
226 printk("\ntesting hmac_%s across pages\n", algo);
228 memset(xbuf, 0, XBUFSIZE);
231 for (i = 0; i < tcount; i++) {
234 printk("test %u:\n",j);
235 memset(result, 0, 64);
238 klen = hmac_tv[i].ksize;
239 for (k = 0; k < hmac_tv[i].np; k++) {
240 memcpy(&xbuf[IDX[k]],
241 hmac_tv[i].plaintext + temp,
243 temp += hmac_tv[i].tap[k];
245 sg[k].page = virt_to_page(p);
246 sg[k].offset = offset_in_page(p);
247 sg[k].length = hmac_tv[i].tap[k];
250 crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
251 hmac_tv[i].np, result);
252 hexdump(result, crypto_tfm_alg_digestsize(tfm));
255 memcmp(result, hmac_tv[i].digest,
256 crypto_tfm_alg_digestsize(tfm)) ?
261 crypto_free_tfm(tfm);
264 #endif /* CONFIG_CRYPTO_HMAC */
266 static void test_cipher(char *algo, int mode, int enc,
267 struct cipher_testvec *template, unsigned int tcount)
269 unsigned int ret, i, j, k, temp;
272 struct crypto_tfm *tfm;
274 struct cipher_testvec *cipher_tv;
275 struct scatterlist sg[8];
282 if (mode == MODE_ECB)
287 printk("\ntesting %s %s %s\n", algo, m, e);
289 tsize = sizeof (struct cipher_testvec);
292 if (tsize > TVMEMSIZE) {
293 printk("template (%u) too big for tvmem (%u)\n", tsize,
298 memcpy(tvmem, template, tsize);
299 cipher_tv = (void *)tvmem;
302 tfm = crypto_alloc_tfm(algo, 0);
304 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
307 printk("failed to load transform for %s %s\n", algo, m);
312 for (i = 0; i < tcount; i++) {
313 if (!(cipher_tv[i].np)) {
315 printk("test %u (%d bit key):\n",
316 j, cipher_tv[i].klen * 8);
320 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
321 key = cipher_tv[i].key;
323 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
325 printk("setkey() failed flags=%x\n", tfm->crt_flags);
327 if (!cipher_tv[i].fail)
331 p = cipher_tv[i].input;
332 sg[0].page = virt_to_page(p);
333 sg[0].offset = offset_in_page(p);
334 sg[0].length = cipher_tv[i].ilen;
337 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
338 crypto_tfm_alg_ivsize(tfm));
342 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
344 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
348 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
352 q = kmap(sg[0].page) + sg[0].offset;
353 hexdump(q, cipher_tv[i].rlen);
356 memcmp(q, cipher_tv[i].result,
357 cipher_tv[i].rlen) ? "fail" : "pass");
361 printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e);
362 memset(xbuf, 0, XBUFSIZE);
365 for (i = 0; i < tcount; i++) {
366 if (cipher_tv[i].np) {
368 printk("test %u (%d bit key):\n",
369 j, cipher_tv[i].klen * 8);
373 tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY;
374 key = cipher_tv[i].key;
376 ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen);
378 printk("setkey() failed flags=%x\n", tfm->crt_flags);
380 if (!cipher_tv[i].fail)
385 for (k = 0; k < cipher_tv[i].np; k++) {
386 memcpy(&xbuf[IDX[k]],
387 cipher_tv[i].input + temp,
388 cipher_tv[i].tap[k]);
389 temp += cipher_tv[i].tap[k];
391 sg[k].page = virt_to_page(p);
392 sg[k].offset = offset_in_page(p);
393 sg[k].length = cipher_tv[i].tap[k];
397 crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
398 crypto_tfm_alg_ivsize(tfm));
402 ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen);
404 ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen);
407 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
412 for (k = 0; k < cipher_tv[i].np; k++) {
413 printk("page %u\n", k);
414 q = kmap(sg[k].page) + sg[k].offset;
415 hexdump(q, cipher_tv[i].tap[k]);
417 memcmp(q, cipher_tv[i].result + temp,
418 cipher_tv[i].tap[k]) ? "fail" :
420 temp += cipher_tv[i].tap[k];
426 crypto_free_tfm(tfm);
429 static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec,
430 struct cipher_testvec *template,
431 unsigned int tcount, struct cipher_speed *speed)
433 unsigned int ret, i, j, iv_len;
434 unsigned char *key, *p, iv[128];
435 struct crypto_tfm *tfm;
436 struct scatterlist sg[8];
437 unsigned long start, bcount;
444 if (mode == MODE_ECB)
449 printk("\ntesting speed of %s %s %s\n", algo, m, e);
452 tfm = crypto_alloc_tfm(algo, 0);
454 tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC);
457 printk("failed to load transform for %s %s\n", algo, m);
461 for (i = 0; speed[i].klen != 0; i++) {
462 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
463 printk("template (%u) too big for tvmem (%u)\n",
464 speed[i].blen + speed[i].klen, TVMEMSIZE);
468 printk("test %u (%d bit key, %d byte blocks): ", i,
469 speed[i].klen * 8, speed[i].blen);
471 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
473 /* set key, plain text and IV */
474 key = (unsigned char *)tvmem;
475 for (j = 0; j < tcount; j++) {
476 if (template[j].klen == speed[i].klen) {
477 key = template[j].key;
481 p = (unsigned char *)tvmem + speed[i].klen;
483 ret = crypto_cipher_setkey(tfm, key, speed[i].klen);
485 printk("setkey() failed flags=%x\n", tfm->crt_flags);
490 iv_len = crypto_tfm_alg_ivsize(tfm);
491 memset(&iv, 0xff, iv_len);
492 crypto_cipher_set_iv(tfm, iv, iv_len);
495 for (start = jiffies, bcount = 0;
496 ((jiffies - start) / HZ) < sec; bcount++) {
497 sg[0].page = virt_to_page(p);
498 sg[0].offset = offset_in_page(p);
499 sg[0].length = speed[i].blen;
502 ret = crypto_cipher_encrypt(tfm, sg, sg, speed[i].blen);
504 ret = crypto_cipher_decrypt(tfm, sg, sg, speed[i].blen);
507 printk("%s () failed flags=%x\n", e, tfm->crt_flags);
512 printk("%lu operations in %u seconds (%lu bytes)\n",
513 bcount, sec, bcount * speed[i].blen);
517 crypto_free_tfm(tfm);
520 static void test_deflate(void)
523 char result[COMP_BUF_SIZE];
524 struct crypto_tfm *tfm;
525 struct comp_testvec *tv;
528 printk("\ntesting deflate compression\n");
530 tsize = sizeof (deflate_comp_tv_template);
531 if (tsize > TVMEMSIZE) {
532 printk("template (%u) too big for tvmem (%u)\n", tsize,
537 memcpy(tvmem, deflate_comp_tv_template, tsize);
540 tfm = crypto_alloc_tfm("deflate", 0);
542 printk("failed to load transform for deflate\n");
546 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
547 int ilen, ret, dlen = COMP_BUF_SIZE;
549 printk("test %u:\n", i + 1);
550 memset(result, 0, sizeof (result));
553 ret = crypto_comp_compress(tfm, tv[i].input,
554 ilen, result, &dlen);
556 printk("fail: ret=%d\n", ret);
559 hexdump(result, dlen);
560 printk("%s (ratio %d:%d)\n",
561 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
565 printk("\ntesting deflate decompression\n");
567 tsize = sizeof (deflate_decomp_tv_template);
568 if (tsize > TVMEMSIZE) {
569 printk("template (%u) too big for tvmem (%u)\n", tsize,
574 memcpy(tvmem, deflate_decomp_tv_template, tsize);
577 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
578 int ilen, ret, dlen = COMP_BUF_SIZE;
580 printk("test %u:\n", i + 1);
581 memset(result, 0, sizeof (result));
584 ret = crypto_comp_decompress(tfm, tv[i].input,
585 ilen, result, &dlen);
587 printk("fail: ret=%d\n", ret);
590 hexdump(result, dlen);
591 printk("%s (ratio %d:%d)\n",
592 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
596 crypto_free_tfm(tfm);
599 static void test_crc32c(void)
606 u8 b, test_vec[NUMVEC][VECSIZE];
607 static u32 vec_results[NUMVEC] = {
608 0x0e2c157f, 0xe980ebf6, 0xde74bded,
609 0xd579c862, 0xba979ad0, 0x2b29d913
611 static u32 tot_vec_results = 0x24c5d375;
613 struct scatterlist sg[NUMVEC];
614 struct crypto_tfm *tfm;
615 char *fmtdata = "testing crc32c initialized to %08x: %s\n";
616 #define SEEDTESTVAL 0xedcba987
619 printk("\ntesting crc32c\n");
621 tfm = crypto_alloc_tfm("crc32c", 0);
623 printk("failed to load transform for crc32c\n");
627 crypto_digest_init(tfm);
628 crypto_digest_final(tfm, (u8*)&crc);
629 printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR");
632 * stuff test_vec with known values, simple incrementing
636 for (i = 0; i < NUMVEC; i++) {
637 for (j = 0; j < VECSIZE; j++)
638 test_vec[i][j] = ++b;
639 sg[i].page = virt_to_page(test_vec[i]);
640 sg[i].offset = offset_in_page(test_vec[i]);
641 sg[i].length = VECSIZE;
645 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
646 crypto_digest_final(tfm, (u8*)&crc);
647 printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ?
650 printk("testing crc32c using update/final:\n");
652 pass = 1; /* assume all is well */
654 for (i = 0; i < NUMVEC; i++) {
656 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
657 crypto_digest_update(tfm, &sg[i], 1);
658 crypto_digest_final(tfm, (u8*)&crc);
659 if (crc == vec_results[i]) {
660 printk(" %08x:OK", crc);
662 printk(" %08x:BAD, wanted %08x\n", crc, vec_results[i]);
667 printk("\ntesting crc32c using incremental accumulator:\n");
669 for (i = 0; i < NUMVEC; i++) {
670 seed = (crc ^ ~(u32)0);
671 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
672 crypto_digest_update(tfm, &sg[i], 1);
673 crypto_digest_final(tfm, (u8*)&crc);
675 if (crc == tot_vec_results) {
676 printk(" %08x:OK", crc);
678 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
682 printk("\ntesting crc32c using digest:\n");
684 (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32));
685 crypto_digest_digest(tfm, sg, NUMVEC, (u8*)&crc);
686 if (crc == tot_vec_results) {
687 printk(" %08x:OK", crc);
689 printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results);
693 printk("\n%s\n", pass ? "pass" : "ERROR");
695 crypto_free_tfm(tfm);
696 printk("crc32c test complete\n");
699 static void test_available(void)
704 printk("alg %s ", *name);
705 printk((crypto_alg_available(*name, 0)) ?
706 "found\n" : "not found\n");
711 static void do_test(void)
716 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
718 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
721 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
722 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
723 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
724 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
727 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
728 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
730 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
732 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
735 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
736 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
737 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
738 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
741 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
742 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
743 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
744 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
747 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
748 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
751 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
752 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
755 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
756 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
759 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
760 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
763 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
764 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
767 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
768 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
771 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
772 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
776 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
777 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
780 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
781 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
784 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
785 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
786 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
787 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
789 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
790 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
791 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
792 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
793 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
794 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
795 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
796 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
799 #ifdef CONFIG_CRYPTO_HMAC
800 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
801 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
802 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
805 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
809 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
813 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
817 test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS);
818 test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS);
819 test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS);
820 test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS);
824 test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS);
825 test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS);
829 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
833 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
837 test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS);
838 test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS);
839 test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS);
840 test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS);
844 test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS);
845 test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS);
846 test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS);
847 test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS);
851 test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS);
852 test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS);
856 test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS);
857 test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS);
861 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
865 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
873 test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS);
874 test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS);
878 test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS);
879 test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS);
883 test_cipher ("arc4", MODE_ECB, ENCRYPT, arc4_enc_tv_template, ARC4_ENC_TEST_VECTORS);
884 test_cipher ("arc4", MODE_ECB, DECRYPT, arc4_dec_tv_template, ARC4_DEC_TEST_VECTORS);
888 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
896 test_cipher ("tea", MODE_ECB, ENCRYPT, tea_enc_tv_template, TEA_ENC_TEST_VECTORS);
897 test_cipher ("tea", MODE_ECB, DECRYPT, tea_dec_tv_template, TEA_DEC_TEST_VECTORS);
901 test_cipher ("xtea", MODE_ECB, ENCRYPT, xtea_enc_tv_template, XTEA_ENC_TEST_VECTORS);
902 test_cipher ("xtea", MODE_ECB, DECRYPT, xtea_dec_tv_template, XTEA_DEC_TEST_VECTORS);
906 test_cipher ("khazad", MODE_ECB, ENCRYPT, khazad_enc_tv_template, KHAZAD_ENC_TEST_VECTORS);
907 test_cipher ("khazad", MODE_ECB, DECRYPT, khazad_dec_tv_template, KHAZAD_DEC_TEST_VECTORS);
911 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
915 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
919 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
923 test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS);
924 test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS);
928 test_cipher ("anubis", MODE_ECB, ENCRYPT, anubis_enc_tv_template, ANUBIS_ENC_TEST_VECTORS);
929 test_cipher ("anubis", MODE_ECB, DECRYPT, anubis_dec_tv_template, ANUBIS_DEC_TEST_VECTORS);
930 test_cipher ("anubis", MODE_CBC, ENCRYPT, anubis_cbc_enc_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
931 test_cipher ("anubis", MODE_CBC, DECRYPT, anubis_cbc_dec_tv_template, ANUBIS_CBC_ENC_TEST_VECTORS);
935 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
940 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
944 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
947 #ifdef CONFIG_CRYPTO_HMAC
949 test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS);
953 test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS);
957 test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS);
963 test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0,
965 test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0,
967 test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, NULL, 0,
969 test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0,
974 test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec,
975 des3_ede_enc_tv_template,
976 DES3_EDE_ENC_TEST_VECTORS,
977 des3_ede_speed_template);
978 test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec,
979 des3_ede_dec_tv_template,
980 DES3_EDE_DEC_TEST_VECTORS,
981 des3_ede_speed_template);
982 test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec,
983 des3_ede_enc_tv_template,
984 DES3_EDE_ENC_TEST_VECTORS,
985 des3_ede_speed_template);
986 test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec,
987 des3_ede_dec_tv_template,
988 DES3_EDE_DEC_TEST_VECTORS,
989 des3_ede_speed_template);
993 test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0,
994 twofish_speed_template);
995 test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0,
996 twofish_speed_template);
997 test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, NULL, 0,
998 twofish_speed_template);
999 test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0,
1000 twofish_speed_template);
1004 test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0,
1005 blowfish_speed_template);
1006 test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0,
1007 blowfish_speed_template);
1008 test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, NULL, 0,
1009 blowfish_speed_template);
1010 test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0,
1011 blowfish_speed_template);
1015 test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0,
1016 des_speed_template);
1017 test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0,
1018 des_speed_template);
1019 test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, NULL, 0,
1020 des_speed_template);
1021 test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0,
1022 des_speed_template);
1030 /* useful for debugging */
1031 printk("not testing anything\n");
1036 static int __init init(void)
1038 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1042 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1056 * If an init function is provided, an exit function must also be provided
1057 * to allow module unload.
1059 static void __exit fini(void) { }
1064 module_param(mode, int, 0);
1065 module_param(sec, uint, 0);
1066 MODULE_PARM_DESC(sec, "Length in seconds of speed tests");
1068 MODULE_LICENSE("GPL");
1069 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1070 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");