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 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
16 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
17 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
21 #include <linux/err.h>
22 #include <linux/init.h>
23 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/scatterlist.h>
27 #include <linux/string.h>
28 #include <linux/crypto.h>
29 #include <linux/highmem.h>
30 #include <linux/moduleparam.h>
31 #include <linux/jiffies.h>
32 #include <linux/timex.h>
33 #include <linux/interrupt.h>
37 * Need to kmalloc() memory for testing kmap().
39 #define TVMEMSIZE 16384
40 #define XBUFSIZE 32768
43 * Indexes into the xbuf to simulate cross-page access.
55 * Used by test_cipher()
60 struct tcrypt_result {
61 struct completion completion;
65 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
68 * Used by test_cipher_speed()
70 static unsigned int sec;
76 static char *check[] = {
77 "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish",
78 "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6",
79 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
80 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
84 static void hexdump(unsigned char *buf, unsigned int len)
87 printk("%02x", *buf++);
92 static void tcrypt_complete(struct crypto_async_request *req, int err)
94 struct tcrypt_result *res = req->data;
96 if (err == -EINPROGRESS)
100 complete(&res->completion);
103 static void test_hash(char *algo, struct hash_testvec *template,
106 unsigned int i, j, k, temp;
107 struct scatterlist sg[8];
109 struct crypto_hash *tfm;
110 struct hash_desc desc;
111 struct hash_testvec *hash_tv;
115 printk("\ntesting %s\n", algo);
117 tsize = sizeof(struct hash_testvec);
120 if (tsize > TVMEMSIZE) {
121 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
125 memcpy(tvmem, template, tsize);
126 hash_tv = (void *)tvmem;
128 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
130 printk("failed to load transform for %s: %ld\n", algo,
138 for (i = 0; i < tcount; i++) {
139 printk("test %u:\n", i + 1);
140 memset(result, 0, 64);
142 sg_set_buf(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
144 if (hash_tv[i].ksize) {
145 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
148 printk("setkey() failed ret=%d\n", ret);
153 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
155 printk("digest () failed ret=%d\n", ret);
159 hexdump(result, crypto_hash_digestsize(tfm));
161 memcmp(result, hash_tv[i].digest,
162 crypto_hash_digestsize(tfm)) ?
166 printk("testing %s across pages\n", algo);
168 /* setup the dummy buffer first */
169 memset(xbuf, 0, XBUFSIZE);
172 for (i = 0; i < tcount; i++) {
175 printk("test %u:\n", j);
176 memset(result, 0, 64);
179 for (k = 0; k < hash_tv[i].np; k++) {
180 memcpy(&xbuf[IDX[k]],
181 hash_tv[i].plaintext + temp,
183 temp += hash_tv[i].tap[k];
184 sg_set_buf(&sg[k], &xbuf[IDX[k]],
188 if (hash_tv[i].ksize) {
189 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
193 printk("setkey() failed ret=%d\n", ret);
198 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
201 printk("digest () failed ret=%d\n", ret);
205 hexdump(result, crypto_hash_digestsize(tfm));
207 memcmp(result, hash_tv[i].digest,
208 crypto_hash_digestsize(tfm)) ?
214 crypto_free_hash(tfm);
217 static void test_cipher(char *algo, int enc,
218 struct cipher_testvec *template, unsigned int tcount)
220 unsigned int ret, i, j, k, temp;
223 struct crypto_ablkcipher *tfm;
225 struct cipher_testvec *cipher_tv;
226 struct ablkcipher_request *req;
227 struct scatterlist sg[8];
229 struct tcrypt_result result;
236 printk("\ntesting %s %s\n", algo, e);
238 tsize = sizeof (struct cipher_testvec);
241 if (tsize > TVMEMSIZE) {
242 printk("template (%u) too big for tvmem (%u)\n", tsize,
247 memcpy(tvmem, template, tsize);
248 cipher_tv = (void *)tvmem;
250 init_completion(&result.completion);
252 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
255 printk("failed to load transform for %s: %ld\n", algo,
260 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
262 printk("failed to allocate request for %s\n", algo);
266 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
267 tcrypt_complete, &result);
270 for (i = 0; i < tcount; i++) {
271 if (!(cipher_tv[i].np)) {
273 printk("test %u (%d bit key):\n",
274 j, cipher_tv[i].klen * 8);
276 crypto_ablkcipher_clear_flags(tfm, ~0);
278 crypto_ablkcipher_set_flags(
279 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
280 key = cipher_tv[i].key;
282 ret = crypto_ablkcipher_setkey(tfm, key,
285 printk("setkey() failed flags=%x\n",
286 crypto_ablkcipher_get_flags(tfm));
288 if (!cipher_tv[i].fail)
292 sg_set_buf(&sg[0], cipher_tv[i].input,
295 ablkcipher_request_set_crypt(req, sg, sg,
300 crypto_ablkcipher_encrypt(req) :
301 crypto_ablkcipher_decrypt(req);
308 ret = wait_for_completion_interruptible(
310 if (!ret && !((ret = result.err))) {
311 INIT_COMPLETION(result.completion);
316 printk("%s () failed err=%d\n", e, -ret);
320 q = kmap(sg[0].page) + sg[0].offset;
321 hexdump(q, cipher_tv[i].rlen);
324 memcmp(q, cipher_tv[i].result,
325 cipher_tv[i].rlen) ? "fail" : "pass");
329 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
330 memset(xbuf, 0, XBUFSIZE);
333 for (i = 0; i < tcount; i++) {
334 if (cipher_tv[i].np) {
336 printk("test %u (%d bit key):\n",
337 j, cipher_tv[i].klen * 8);
339 crypto_ablkcipher_clear_flags(tfm, ~0);
341 crypto_ablkcipher_set_flags(
342 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
343 key = cipher_tv[i].key;
345 ret = crypto_ablkcipher_setkey(tfm, key,
348 printk("setkey() failed flags=%x\n",
349 crypto_ablkcipher_get_flags(tfm));
351 if (!cipher_tv[i].fail)
356 for (k = 0; k < cipher_tv[i].np; k++) {
357 memcpy(&xbuf[IDX[k]],
358 cipher_tv[i].input + temp,
359 cipher_tv[i].tap[k]);
360 temp += cipher_tv[i].tap[k];
361 sg_set_buf(&sg[k], &xbuf[IDX[k]],
362 cipher_tv[i].tap[k]);
365 ablkcipher_request_set_crypt(req, sg, sg,
370 crypto_ablkcipher_encrypt(req) :
371 crypto_ablkcipher_decrypt(req);
378 ret = wait_for_completion_interruptible(
380 if (!ret && !((ret = result.err))) {
381 INIT_COMPLETION(result.completion);
386 printk("%s () failed err=%d\n", e, -ret);
391 for (k = 0; k < cipher_tv[i].np; k++) {
392 printk("page %u\n", k);
393 q = kmap(sg[k].page) + sg[k].offset;
394 hexdump(q, cipher_tv[i].tap[k]);
396 memcmp(q, cipher_tv[i].result + temp,
397 cipher_tv[i].tap[k]) ? "fail" :
399 temp += cipher_tv[i].tap[k];
405 crypto_free_ablkcipher(tfm);
406 ablkcipher_request_free(req);
409 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
412 struct scatterlist sg[1];
413 unsigned long start, end;
417 sg_set_buf(sg, p, blen);
419 for (start = jiffies, end = start + sec * HZ, bcount = 0;
420 time_before(jiffies, end); bcount++) {
422 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
424 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
430 printk("%d operations in %d seconds (%ld bytes)\n",
431 bcount, sec, (long)bcount * blen);
435 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
438 struct scatterlist sg[1];
439 unsigned long cycles = 0;
443 sg_set_buf(sg, p, blen);
449 for (i = 0; i < 4; i++) {
451 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
453 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
459 /* The real thing. */
460 for (i = 0; i < 8; i++) {
463 start = get_cycles();
465 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
467 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
473 cycles += end - start;
481 printk("1 operation in %lu cycles (%d bytes)\n",
482 (cycles + 4) / 8, blen);
487 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
488 struct cipher_testvec *template,
489 unsigned int tcount, struct cipher_speed *speed)
491 unsigned int ret, i, j, iv_len;
492 unsigned char *key, *p, iv[128];
493 struct crypto_blkcipher *tfm;
494 struct blkcipher_desc desc;
502 printk("\ntesting speed of %s %s\n", algo, e);
504 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
507 printk("failed to load transform for %s: %ld\n", algo,
514 for (i = 0; speed[i].klen != 0; i++) {
515 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
516 printk("template (%u) too big for tvmem (%u)\n",
517 speed[i].blen + speed[i].klen, TVMEMSIZE);
521 printk("test %u (%d bit key, %d byte blocks): ", i,
522 speed[i].klen * 8, speed[i].blen);
524 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
526 /* set key, plain text and IV */
527 key = (unsigned char *)tvmem;
528 for (j = 0; j < tcount; j++) {
529 if (template[j].klen == speed[i].klen) {
530 key = template[j].key;
534 p = (unsigned char *)tvmem + speed[i].klen;
536 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
538 printk("setkey() failed flags=%x\n",
539 crypto_blkcipher_get_flags(tfm));
543 iv_len = crypto_blkcipher_ivsize(tfm);
545 memset(&iv, 0xff, iv_len);
546 crypto_blkcipher_set_iv(tfm, iv, iv_len);
550 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
553 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
556 printk("%s() failed flags=%x\n", e, desc.flags);
562 crypto_free_blkcipher(tfm);
565 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
568 struct scatterlist sg[1];
569 unsigned long start, end;
573 for (start = jiffies, end = start + sec * HZ, bcount = 0;
574 time_before(jiffies, end); bcount++) {
575 sg_set_buf(sg, p, blen);
576 ret = crypto_hash_digest(desc, sg, blen, out);
581 printk("%6u opers/sec, %9lu bytes/sec\n",
582 bcount / sec, ((long)bcount * blen) / sec);
587 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
588 int plen, char *out, int sec)
590 struct scatterlist sg[1];
591 unsigned long start, end;
596 return test_hash_jiffies_digest(desc, p, blen, out, sec);
598 for (start = jiffies, end = start + sec * HZ, bcount = 0;
599 time_before(jiffies, end); bcount++) {
600 ret = crypto_hash_init(desc);
603 for (pcount = 0; pcount < blen; pcount += plen) {
604 sg_set_buf(sg, p + pcount, plen);
605 ret = crypto_hash_update(desc, sg, plen);
609 /* we assume there is enough space in 'out' for the result */
610 ret = crypto_hash_final(desc, out);
615 printk("%6u opers/sec, %9lu bytes/sec\n",
616 bcount / sec, ((long)bcount * blen) / sec);
621 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
624 struct scatterlist sg[1];
625 unsigned long cycles = 0;
633 for (i = 0; i < 4; i++) {
634 sg_set_buf(sg, p, blen);
635 ret = crypto_hash_digest(desc, sg, blen, out);
640 /* The real thing. */
641 for (i = 0; i < 8; i++) {
644 start = get_cycles();
646 sg_set_buf(sg, p, blen);
647 ret = crypto_hash_digest(desc, sg, blen, out);
653 cycles += end - start;
663 printk("%6lu cycles/operation, %4lu cycles/byte\n",
664 cycles / 8, cycles / (8 * blen));
669 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
672 struct scatterlist sg[1];
673 unsigned long cycles = 0;
678 return test_hash_cycles_digest(desc, p, blen, out);
684 for (i = 0; i < 4; i++) {
685 ret = crypto_hash_init(desc);
688 for (pcount = 0; pcount < blen; pcount += plen) {
689 sg_set_buf(sg, p + pcount, plen);
690 ret = crypto_hash_update(desc, sg, plen);
694 ret = crypto_hash_final(desc, out);
699 /* The real thing. */
700 for (i = 0; i < 8; i++) {
703 start = get_cycles();
705 ret = crypto_hash_init(desc);
708 for (pcount = 0; pcount < blen; pcount += plen) {
709 sg_set_buf(sg, p + pcount, plen);
710 ret = crypto_hash_update(desc, sg, plen);
714 ret = crypto_hash_final(desc, out);
720 cycles += end - start;
730 printk("%6lu cycles/operation, %4lu cycles/byte\n",
731 cycles / 8, cycles / (8 * blen));
736 static void test_hash_speed(char *algo, unsigned int sec,
737 struct hash_speed *speed)
739 struct crypto_hash *tfm;
740 struct hash_desc desc;
745 printk("\ntesting speed of %s\n", algo);
747 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
750 printk("failed to load transform for %s: %ld\n", algo,
758 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
759 printk("digestsize(%u) > outputbuffer(%zu)\n",
760 crypto_hash_digestsize(tfm), sizeof(output));
764 for (i = 0; speed[i].blen != 0; i++) {
765 if (speed[i].blen > TVMEMSIZE) {
766 printk("template (%u) too big for tvmem (%u)\n",
767 speed[i].blen, TVMEMSIZE);
771 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
772 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
774 memset(tvmem, 0xff, speed[i].blen);
777 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
778 speed[i].plen, output, sec);
780 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
781 speed[i].plen, output);
784 printk("hashing failed ret=%d\n", ret);
790 crypto_free_hash(tfm);
793 static void test_deflate(void)
796 char result[COMP_BUF_SIZE];
797 struct crypto_comp *tfm;
798 struct comp_testvec *tv;
801 printk("\ntesting deflate compression\n");
803 tsize = sizeof (deflate_comp_tv_template);
804 if (tsize > TVMEMSIZE) {
805 printk("template (%u) too big for tvmem (%u)\n", tsize,
810 memcpy(tvmem, deflate_comp_tv_template, tsize);
813 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
815 printk("failed to load transform for deflate\n");
819 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
820 int ilen, ret, dlen = COMP_BUF_SIZE;
822 printk("test %u:\n", i + 1);
823 memset(result, 0, sizeof (result));
826 ret = crypto_comp_compress(tfm, tv[i].input,
827 ilen, result, &dlen);
829 printk("fail: ret=%d\n", ret);
832 hexdump(result, dlen);
833 printk("%s (ratio %d:%d)\n",
834 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
838 printk("\ntesting deflate decompression\n");
840 tsize = sizeof (deflate_decomp_tv_template);
841 if (tsize > TVMEMSIZE) {
842 printk("template (%u) too big for tvmem (%u)\n", tsize,
847 memcpy(tvmem, deflate_decomp_tv_template, tsize);
850 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
851 int ilen, ret, dlen = COMP_BUF_SIZE;
853 printk("test %u:\n", i + 1);
854 memset(result, 0, sizeof (result));
857 ret = crypto_comp_decompress(tfm, tv[i].input,
858 ilen, result, &dlen);
860 printk("fail: ret=%d\n", ret);
863 hexdump(result, dlen);
864 printk("%s (ratio %d:%d)\n",
865 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
869 crypto_free_comp(tfm);
872 static void test_available(void)
877 printk("alg %s ", *name);
878 printk(crypto_has_alg(*name, 0, 0) ?
879 "found\n" : "not found\n");
884 static void do_test(void)
889 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
891 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
894 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
895 DES_ENC_TEST_VECTORS);
896 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
897 DES_DEC_TEST_VECTORS);
898 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
899 DES_CBC_ENC_TEST_VECTORS);
900 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
901 DES_CBC_DEC_TEST_VECTORS);
904 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
905 DES3_EDE_ENC_TEST_VECTORS);
906 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
907 DES3_EDE_DEC_TEST_VECTORS);
909 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
911 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
914 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
915 BF_ENC_TEST_VECTORS);
916 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
917 BF_DEC_TEST_VECTORS);
918 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
919 BF_CBC_ENC_TEST_VECTORS);
920 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
921 BF_CBC_DEC_TEST_VECTORS);
924 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
925 TF_ENC_TEST_VECTORS);
926 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
927 TF_DEC_TEST_VECTORS);
928 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
929 TF_CBC_ENC_TEST_VECTORS);
930 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
931 TF_CBC_DEC_TEST_VECTORS);
934 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
935 SERPENT_ENC_TEST_VECTORS);
936 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
937 SERPENT_DEC_TEST_VECTORS);
940 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
941 TNEPRES_ENC_TEST_VECTORS);
942 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
943 TNEPRES_DEC_TEST_VECTORS);
946 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
947 AES_ENC_TEST_VECTORS);
948 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
949 AES_DEC_TEST_VECTORS);
950 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
951 AES_CBC_ENC_TEST_VECTORS);
952 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
953 AES_CBC_DEC_TEST_VECTORS);
954 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
955 AES_LRW_ENC_TEST_VECTORS);
956 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
957 AES_LRW_DEC_TEST_VECTORS);
960 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
961 CAST5_ENC_TEST_VECTORS);
962 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
963 CAST5_DEC_TEST_VECTORS);
966 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
967 CAST6_ENC_TEST_VECTORS);
968 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
969 CAST6_DEC_TEST_VECTORS);
972 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
973 ARC4_ENC_TEST_VECTORS);
974 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
975 ARC4_DEC_TEST_VECTORS);
978 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
979 TEA_ENC_TEST_VECTORS);
980 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
981 TEA_DEC_TEST_VECTORS);
985 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
986 XTEA_ENC_TEST_VECTORS);
987 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
988 XTEA_DEC_TEST_VECTORS);
991 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
992 KHAZAD_ENC_TEST_VECTORS);
993 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
994 KHAZAD_DEC_TEST_VECTORS);
997 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
998 ANUBIS_ENC_TEST_VECTORS);
999 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1000 ANUBIS_DEC_TEST_VECTORS);
1001 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1002 ANUBIS_CBC_ENC_TEST_VECTORS);
1003 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1004 ANUBIS_CBC_ENC_TEST_VECTORS);
1007 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1008 XETA_ENC_TEST_VECTORS);
1009 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1010 XETA_DEC_TEST_VECTORS);
1013 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1014 FCRYPT_ENC_TEST_VECTORS);
1015 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1016 FCRYPT_DEC_TEST_VECTORS);
1019 test_cipher("ecb(camellia)", ENCRYPT,
1020 camellia_enc_tv_template,
1021 CAMELLIA_ENC_TEST_VECTORS);
1022 test_cipher("ecb(camellia)", DECRYPT,
1023 camellia_dec_tv_template,
1024 CAMELLIA_DEC_TEST_VECTORS);
1025 test_cipher("cbc(camellia)", ENCRYPT,
1026 camellia_cbc_enc_tv_template,
1027 CAMELLIA_CBC_ENC_TEST_VECTORS);
1028 test_cipher("cbc(camellia)", DECRYPT,
1029 camellia_cbc_dec_tv_template,
1030 CAMELLIA_CBC_DEC_TEST_VECTORS);
1032 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1033 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1034 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1035 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1036 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1037 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1038 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1039 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1041 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1042 test_hash("hmac(md5)", hmac_md5_tv_template,
1043 HMAC_MD5_TEST_VECTORS);
1044 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1045 HMAC_SHA1_TEST_VECTORS);
1046 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1047 HMAC_SHA256_TEST_VECTORS);
1048 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1049 HMAC_SHA384_TEST_VECTORS);
1050 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1051 HMAC_SHA512_TEST_VECTORS);
1053 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1054 XCBC_AES_TEST_VECTORS);
1056 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1060 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1064 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1068 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1069 DES_ENC_TEST_VECTORS);
1070 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1071 DES_DEC_TEST_VECTORS);
1072 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1073 DES_CBC_ENC_TEST_VECTORS);
1074 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1075 DES_CBC_DEC_TEST_VECTORS);
1079 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1080 DES3_EDE_ENC_TEST_VECTORS);
1081 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1082 DES3_EDE_DEC_TEST_VECTORS);
1086 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1090 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1094 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1095 BF_ENC_TEST_VECTORS);
1096 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1097 BF_DEC_TEST_VECTORS);
1098 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1099 BF_CBC_ENC_TEST_VECTORS);
1100 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1101 BF_CBC_DEC_TEST_VECTORS);
1105 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1106 TF_ENC_TEST_VECTORS);
1107 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1108 TF_DEC_TEST_VECTORS);
1109 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1110 TF_CBC_ENC_TEST_VECTORS);
1111 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1112 TF_CBC_DEC_TEST_VECTORS);
1116 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1117 SERPENT_ENC_TEST_VECTORS);
1118 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1119 SERPENT_DEC_TEST_VECTORS);
1123 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1124 AES_ENC_TEST_VECTORS);
1125 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1126 AES_DEC_TEST_VECTORS);
1127 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1128 AES_CBC_ENC_TEST_VECTORS);
1129 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1130 AES_CBC_DEC_TEST_VECTORS);
1131 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1132 AES_LRW_ENC_TEST_VECTORS);
1133 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1134 AES_LRW_DEC_TEST_VECTORS);
1138 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1142 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1150 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1151 CAST5_ENC_TEST_VECTORS);
1152 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1153 CAST5_DEC_TEST_VECTORS);
1157 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1158 CAST6_ENC_TEST_VECTORS);
1159 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1160 CAST6_DEC_TEST_VECTORS);
1164 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1165 ARC4_ENC_TEST_VECTORS);
1166 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1167 ARC4_DEC_TEST_VECTORS);
1171 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1175 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1179 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1180 TEA_ENC_TEST_VECTORS);
1181 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1182 TEA_DEC_TEST_VECTORS);
1186 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1187 XTEA_ENC_TEST_VECTORS);
1188 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1189 XTEA_DEC_TEST_VECTORS);
1193 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1194 KHAZAD_ENC_TEST_VECTORS);
1195 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1196 KHAZAD_DEC_TEST_VECTORS);
1200 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1204 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1208 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1212 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1213 TNEPRES_ENC_TEST_VECTORS);
1214 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1215 TNEPRES_DEC_TEST_VECTORS);
1219 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1220 ANUBIS_ENC_TEST_VECTORS);
1221 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1222 ANUBIS_DEC_TEST_VECTORS);
1223 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1224 ANUBIS_CBC_ENC_TEST_VECTORS);
1225 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1226 ANUBIS_CBC_ENC_TEST_VECTORS);
1230 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1235 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1239 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1243 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1244 XETA_ENC_TEST_VECTORS);
1245 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1246 XETA_DEC_TEST_VECTORS);
1250 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1251 FCRYPT_ENC_TEST_VECTORS);
1252 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1253 FCRYPT_DEC_TEST_VECTORS);
1257 test_cipher("ecb(camellia)", ENCRYPT,
1258 camellia_enc_tv_template,
1259 CAMELLIA_ENC_TEST_VECTORS);
1260 test_cipher("ecb(camellia)", DECRYPT,
1261 camellia_dec_tv_template,
1262 CAMELLIA_DEC_TEST_VECTORS);
1263 test_cipher("cbc(camellia)", ENCRYPT,
1264 camellia_cbc_enc_tv_template,
1265 CAMELLIA_CBC_ENC_TEST_VECTORS);
1266 test_cipher("cbc(camellia)", DECRYPT,
1267 camellia_cbc_dec_tv_template,
1268 CAMELLIA_CBC_DEC_TEST_VECTORS);
1272 test_hash("hmac(md5)", hmac_md5_tv_template,
1273 HMAC_MD5_TEST_VECTORS);
1277 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1278 HMAC_SHA1_TEST_VECTORS);
1282 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1283 HMAC_SHA256_TEST_VECTORS);
1287 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1288 HMAC_SHA384_TEST_VECTORS);
1292 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1293 HMAC_SHA512_TEST_VECTORS);
1298 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1299 aes_speed_template);
1300 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1301 aes_speed_template);
1302 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1303 aes_speed_template);
1304 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1305 aes_speed_template);
1306 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1307 aes_lrw_speed_template);
1308 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1309 aes_lrw_speed_template);
1313 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1314 des3_ede_enc_tv_template,
1315 DES3_EDE_ENC_TEST_VECTORS,
1316 des3_ede_speed_template);
1317 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1318 des3_ede_dec_tv_template,
1319 DES3_EDE_DEC_TEST_VECTORS,
1320 des3_ede_speed_template);
1321 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1322 des3_ede_enc_tv_template,
1323 DES3_EDE_ENC_TEST_VECTORS,
1324 des3_ede_speed_template);
1325 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1326 des3_ede_dec_tv_template,
1327 DES3_EDE_DEC_TEST_VECTORS,
1328 des3_ede_speed_template);
1332 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1333 twofish_speed_template);
1334 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1335 twofish_speed_template);
1336 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1337 twofish_speed_template);
1338 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1339 twofish_speed_template);
1343 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1344 blowfish_speed_template);
1345 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1346 blowfish_speed_template);
1347 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1348 blowfish_speed_template);
1349 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1350 blowfish_speed_template);
1354 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1355 des_speed_template);
1356 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1357 des_speed_template);
1358 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1359 des_speed_template);
1360 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1361 des_speed_template);
1365 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1366 camellia_speed_template);
1367 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1368 camellia_speed_template);
1369 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1370 camellia_speed_template);
1371 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1372 camellia_speed_template);
1379 test_hash_speed("md4", sec, generic_hash_speed_template);
1380 if (mode > 300 && mode < 400) break;
1383 test_hash_speed("md5", sec, generic_hash_speed_template);
1384 if (mode > 300 && mode < 400) break;
1387 test_hash_speed("sha1", sec, generic_hash_speed_template);
1388 if (mode > 300 && mode < 400) break;
1391 test_hash_speed("sha256", sec, generic_hash_speed_template);
1392 if (mode > 300 && mode < 400) break;
1395 test_hash_speed("sha384", sec, generic_hash_speed_template);
1396 if (mode > 300 && mode < 400) break;
1399 test_hash_speed("sha512", sec, generic_hash_speed_template);
1400 if (mode > 300 && mode < 400) break;
1403 test_hash_speed("wp256", sec, generic_hash_speed_template);
1404 if (mode > 300 && mode < 400) break;
1407 test_hash_speed("wp384", sec, generic_hash_speed_template);
1408 if (mode > 300 && mode < 400) break;
1411 test_hash_speed("wp512", sec, generic_hash_speed_template);
1412 if (mode > 300 && mode < 400) break;
1415 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1416 if (mode > 300 && mode < 400) break;
1419 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1420 if (mode > 300 && mode < 400) break;
1423 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1424 if (mode > 300 && mode < 400) break;
1434 /* useful for debugging */
1435 printk("not testing anything\n");
1440 static int __init init(void)
1442 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1446 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1457 /* We intentionaly return -EAGAIN to prevent keeping
1458 * the module. It does all its work from init()
1459 * and doesn't offer any runtime functionality
1460 * => we don't need it in the memory, do we?
1467 * If an init function is provided, an exit function must also be provided
1468 * to allow module unload.
1470 static void __exit fini(void) { }
1475 module_param(mode, int, 0);
1476 module_param(sec, uint, 0);
1477 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1478 "(defaults to zero which uses CPU cycles instead)");
1480 MODULE_LICENSE("GPL");
1481 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1482 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");