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>
9 * Copyright (c) 2007 Nokia Siemens Networks
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
16 * 2007-11-13 Added AEAD support
17 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
18 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
19 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
20 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
24 #include <linux/err.h>
25 #include <linux/init.h>
26 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <linux/scatterlist.h>
30 #include <linux/string.h>
31 #include <linux/crypto.h>
32 #include <linux/highmem.h>
33 #include <linux/moduleparam.h>
34 #include <linux/jiffies.h>
35 #include <linux/timex.h>
36 #include <linux/interrupt.h>
40 * Need to kmalloc() memory for testing kmap().
42 #define TVMEMSIZE 16384
43 #define XBUFSIZE 32768
46 * Indexes into the xbuf to simulate cross-page access.
58 * Used by test_cipher()
63 struct tcrypt_result {
64 struct completion completion;
68 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
71 * Used by test_cipher_speed()
73 static unsigned int sec;
80 static char *check[] = {
81 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
82 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
83 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
84 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
85 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
86 "camellia", "seed", "salsa20", NULL
89 static void hexdump(unsigned char *buf, unsigned int len)
92 printk("%02x", *buf++);
97 static void tcrypt_complete(struct crypto_async_request *req, int err)
99 struct tcrypt_result *res = req->data;
101 if (err == -EINPROGRESS)
105 complete(&res->completion);
108 static void test_hash(char *algo, struct hash_testvec *template,
111 unsigned int i, j, k, temp;
112 struct scatterlist sg[8];
114 struct crypto_hash *tfm;
115 struct hash_desc desc;
116 struct hash_testvec *hash_tv;
120 printk("\ntesting %s\n", algo);
122 tsize = sizeof(struct hash_testvec);
125 if (tsize > TVMEMSIZE) {
126 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
130 memcpy(tvmem, template, tsize);
131 hash_tv = (void *)tvmem;
133 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
135 printk("failed to load transform for %s: %ld\n", algo,
143 for (i = 0; i < tcount; i++) {
144 printk("test %u:\n", i + 1);
145 memset(result, 0, 64);
147 sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
149 if (hash_tv[i].ksize) {
150 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
153 printk("setkey() failed ret=%d\n", ret);
158 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
160 printk("digest () failed ret=%d\n", ret);
164 hexdump(result, crypto_hash_digestsize(tfm));
166 memcmp(result, hash_tv[i].digest,
167 crypto_hash_digestsize(tfm)) ?
171 printk("testing %s across pages\n", algo);
173 /* setup the dummy buffer first */
174 memset(xbuf, 0, XBUFSIZE);
175 memset(axbuf, 0, XBUFSIZE);
178 for (i = 0; i < tcount; i++) {
181 printk("test %u:\n", j);
182 memset(result, 0, 64);
185 sg_init_table(sg, hash_tv[i].np);
186 for (k = 0; k < hash_tv[i].np; k++) {
187 memcpy(&xbuf[IDX[k]],
188 hash_tv[i].plaintext + temp,
190 temp += hash_tv[i].tap[k];
191 sg_set_buf(&sg[k], &xbuf[IDX[k]],
195 if (hash_tv[i].ksize) {
196 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
200 printk("setkey() failed ret=%d\n", ret);
205 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
208 printk("digest () failed ret=%d\n", ret);
212 hexdump(result, crypto_hash_digestsize(tfm));
214 memcmp(result, hash_tv[i].digest,
215 crypto_hash_digestsize(tfm)) ?
221 crypto_free_hash(tfm);
224 static void test_aead(char *algo, int enc, struct aead_testvec *template,
227 unsigned int ret, i, j, k, temp;
230 struct crypto_aead *tfm;
232 struct aead_testvec *aead_tv;
233 struct aead_request *req;
234 struct scatterlist sg[8];
235 struct scatterlist asg[8];
237 struct tcrypt_result result;
244 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
246 tsize = sizeof(struct aead_testvec);
249 if (tsize > TVMEMSIZE) {
250 printk(KERN_INFO "template (%u) too big for tvmem (%u)\n",
255 memcpy(tvmem, template, tsize);
256 aead_tv = (void *)tvmem;
258 init_completion(&result.completion);
260 tfm = crypto_alloc_aead(algo, 0, 0);
263 printk(KERN_INFO "failed to load transform for %s: %ld\n",
268 req = aead_request_alloc(tfm, GFP_KERNEL);
270 printk(KERN_INFO "failed to allocate request for %s\n", algo);
274 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
275 tcrypt_complete, &result);
277 for (i = 0, j = 0; i < tcount; i++) {
278 if (!aead_tv[i].np) {
279 printk(KERN_INFO "test %u (%d bit key):\n",
280 ++j, aead_tv[i].klen * 8);
282 crypto_aead_clear_flags(tfm, ~0);
284 crypto_aead_set_flags(
285 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
286 key = aead_tv[i].key;
288 ret = crypto_aead_setkey(tfm, key,
291 printk(KERN_INFO "setkey() failed flags=%x\n",
292 crypto_aead_get_flags(tfm));
294 if (!aead_tv[i].fail)
298 sg_init_one(&sg[0], aead_tv[i].input,
301 sg_init_one(&asg[0], aead_tv[i].assoc,
304 aead_request_set_crypt(req, sg, sg,
308 aead_request_set_assoc(req, asg, aead_tv[i].alen);
311 ret = crypto_aead_encrypt(req);
313 memcpy(req->__ctx, aead_tv[i].tag,
315 ret = crypto_aead_decrypt(req);
323 ret = wait_for_completion_interruptible(
325 if (!ret && !(ret = result.err)) {
326 INIT_COMPLETION(result.completion);
331 printk(KERN_INFO "%s () failed err=%d\n",
336 q = kmap(sg_page(&sg[0])) + sg[0].offset;
337 hexdump(q, aead_tv[i].rlen);
338 printk(KERN_INFO "auth tag: ");
339 hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen);
341 printk(KERN_INFO "enc/dec: %s\n",
342 memcmp(q, aead_tv[i].result,
343 aead_tv[i].rlen) ? "fail" : "pass");
345 printk(KERN_INFO "auth tag: %s\n",
346 memcmp(req->__ctx, aead_tv[i].tag,
347 aead_tv[i].tlen) ? "fail" : "pass");
351 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
352 memset(xbuf, 0, XBUFSIZE);
354 for (i = 0, j = 0; i < tcount; i++) {
356 printk(KERN_INFO "test %u (%d bit key):\n",
357 ++j, aead_tv[i].klen * 8);
359 crypto_aead_clear_flags(tfm, ~0);
361 crypto_aead_set_flags(
362 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
363 key = aead_tv[i].key;
365 ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen);
367 printk(KERN_INFO "setkey() failed flags=%x\n",
368 crypto_aead_get_flags(tfm));
370 if (!aead_tv[i].fail)
374 sg_init_table(sg, aead_tv[i].np);
375 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
376 memcpy(&xbuf[IDX[k]],
377 aead_tv[i].input + temp,
379 temp += aead_tv[i].tap[k];
380 sg_set_buf(&sg[k], &xbuf[IDX[k]],
384 sg_init_table(asg, aead_tv[i].anp);
385 for (k = 0, temp = 0; k < aead_tv[i].anp; k++) {
386 memcpy(&axbuf[IDX[k]],
387 aead_tv[i].assoc + temp,
389 temp += aead_tv[i].atap[k];
390 sg_set_buf(&asg[k], &axbuf[IDX[k]],
394 aead_request_set_crypt(req, sg, sg,
398 aead_request_set_assoc(req, asg, aead_tv[i].alen);
401 ret = crypto_aead_encrypt(req);
403 memcpy(req->__ctx, aead_tv[i].tag,
405 ret = crypto_aead_decrypt(req);
413 ret = wait_for_completion_interruptible(
415 if (!ret && !(ret = result.err)) {
416 INIT_COMPLETION(result.completion);
421 printk(KERN_INFO "%s () failed err=%d\n",
426 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
427 printk(KERN_INFO "page %u\n", k);
428 q = kmap(sg_page(&sg[k])) + sg[k].offset;
429 hexdump(q, aead_tv[i].tap[k]);
430 printk(KERN_INFO "%s\n",
431 memcmp(q, aead_tv[i].result + temp,
435 temp += aead_tv[i].tap[k];
437 printk(KERN_INFO "auth tag: ");
438 hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen);
440 printk(KERN_INFO "auth tag: %s\n",
441 memcmp(req->__ctx, aead_tv[i].tag,
442 aead_tv[i].tlen) ? "fail" : "pass");
447 crypto_free_aead(tfm);
448 aead_request_free(req);
451 static void test_cipher(char *algo, int enc,
452 struct cipher_testvec *template, unsigned int tcount)
454 unsigned int ret, i, j, k, temp;
457 struct crypto_ablkcipher *tfm;
459 struct cipher_testvec *cipher_tv;
460 struct ablkcipher_request *req;
461 struct scatterlist sg[8];
463 struct tcrypt_result result;
470 printk("\ntesting %s %s\n", algo, e);
472 tsize = sizeof (struct cipher_testvec);
475 if (tsize > TVMEMSIZE) {
476 printk("template (%u) too big for tvmem (%u)\n", tsize,
481 memcpy(tvmem, template, tsize);
482 cipher_tv = (void *)tvmem;
484 init_completion(&result.completion);
486 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
489 printk("failed to load transform for %s: %ld\n", algo,
494 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
496 printk("failed to allocate request for %s\n", algo);
500 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
501 tcrypt_complete, &result);
504 for (i = 0; i < tcount; i++) {
505 if (!(cipher_tv[i].np)) {
507 printk("test %u (%d bit key):\n",
508 j, cipher_tv[i].klen * 8);
510 crypto_ablkcipher_clear_flags(tfm, ~0);
512 crypto_ablkcipher_set_flags(
513 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
514 key = cipher_tv[i].key;
516 ret = crypto_ablkcipher_setkey(tfm, key,
519 printk("setkey() failed flags=%x\n",
520 crypto_ablkcipher_get_flags(tfm));
522 if (!cipher_tv[i].fail)
526 sg_init_one(&sg[0], cipher_tv[i].input,
529 ablkcipher_request_set_crypt(req, sg, sg,
534 crypto_ablkcipher_encrypt(req) :
535 crypto_ablkcipher_decrypt(req);
542 ret = wait_for_completion_interruptible(
544 if (!ret && !((ret = result.err))) {
545 INIT_COMPLETION(result.completion);
550 printk("%s () failed err=%d\n", e, -ret);
554 q = kmap(sg_page(&sg[0])) + sg[0].offset;
555 hexdump(q, cipher_tv[i].rlen);
558 memcmp(q, cipher_tv[i].result,
559 cipher_tv[i].rlen) ? "fail" : "pass");
563 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
564 memset(xbuf, 0, XBUFSIZE);
567 for (i = 0; i < tcount; i++) {
568 if (cipher_tv[i].np) {
570 printk("test %u (%d bit key):\n",
571 j, cipher_tv[i].klen * 8);
573 crypto_ablkcipher_clear_flags(tfm, ~0);
575 crypto_ablkcipher_set_flags(
576 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
577 key = cipher_tv[i].key;
579 ret = crypto_ablkcipher_setkey(tfm, key,
582 printk("setkey() failed flags=%x\n",
583 crypto_ablkcipher_get_flags(tfm));
585 if (!cipher_tv[i].fail)
590 sg_init_table(sg, cipher_tv[i].np);
591 for (k = 0; k < cipher_tv[i].np; k++) {
592 memcpy(&xbuf[IDX[k]],
593 cipher_tv[i].input + temp,
594 cipher_tv[i].tap[k]);
595 temp += cipher_tv[i].tap[k];
596 sg_set_buf(&sg[k], &xbuf[IDX[k]],
597 cipher_tv[i].tap[k]);
600 ablkcipher_request_set_crypt(req, sg, sg,
605 crypto_ablkcipher_encrypt(req) :
606 crypto_ablkcipher_decrypt(req);
613 ret = wait_for_completion_interruptible(
615 if (!ret && !((ret = result.err))) {
616 INIT_COMPLETION(result.completion);
621 printk("%s () failed err=%d\n", e, -ret);
626 for (k = 0; k < cipher_tv[i].np; k++) {
627 printk("page %u\n", k);
628 q = kmap(sg_page(&sg[k])) + sg[k].offset;
629 hexdump(q, cipher_tv[i].tap[k]);
631 memcmp(q, cipher_tv[i].result + temp,
632 cipher_tv[i].tap[k]) ? "fail" :
634 temp += cipher_tv[i].tap[k];
640 crypto_free_ablkcipher(tfm);
641 ablkcipher_request_free(req);
644 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
647 struct scatterlist sg[1];
648 unsigned long start, end;
652 sg_init_one(sg, p, blen);
654 for (start = jiffies, end = start + sec * HZ, bcount = 0;
655 time_before(jiffies, end); bcount++) {
657 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
659 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
665 printk("%d operations in %d seconds (%ld bytes)\n",
666 bcount, sec, (long)bcount * blen);
670 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
673 struct scatterlist sg[1];
674 unsigned long cycles = 0;
678 sg_init_one(sg, p, blen);
684 for (i = 0; i < 4; i++) {
686 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
688 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
694 /* The real thing. */
695 for (i = 0; i < 8; i++) {
698 start = get_cycles();
700 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
702 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
708 cycles += end - start;
716 printk("1 operation in %lu cycles (%d bytes)\n",
717 (cycles + 4) / 8, blen);
722 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
723 struct cipher_testvec *template,
724 unsigned int tcount, struct cipher_speed *speed)
726 unsigned int ret, i, j, iv_len;
727 unsigned char *key, *p, iv[128];
728 struct crypto_blkcipher *tfm;
729 struct blkcipher_desc desc;
737 printk("\ntesting speed of %s %s\n", algo, e);
739 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
742 printk("failed to load transform for %s: %ld\n", algo,
749 for (i = 0; speed[i].klen != 0; i++) {
750 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
751 printk("template (%u) too big for tvmem (%u)\n",
752 speed[i].blen + speed[i].klen, TVMEMSIZE);
756 printk("test %u (%d bit key, %d byte blocks): ", i,
757 speed[i].klen * 8, speed[i].blen);
759 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
761 /* set key, plain text and IV */
762 key = (unsigned char *)tvmem;
763 for (j = 0; j < tcount; j++) {
764 if (template[j].klen == speed[i].klen) {
765 key = template[j].key;
769 p = (unsigned char *)tvmem + speed[i].klen;
771 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
773 printk("setkey() failed flags=%x\n",
774 crypto_blkcipher_get_flags(tfm));
778 iv_len = crypto_blkcipher_ivsize(tfm);
780 memset(&iv, 0xff, iv_len);
781 crypto_blkcipher_set_iv(tfm, iv, iv_len);
785 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
788 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
791 printk("%s() failed flags=%x\n", e, desc.flags);
797 crypto_free_blkcipher(tfm);
800 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
803 struct scatterlist sg[1];
804 unsigned long start, end;
808 sg_init_table(sg, 1);
810 for (start = jiffies, end = start + sec * HZ, bcount = 0;
811 time_before(jiffies, end); bcount++) {
812 sg_set_buf(sg, p, blen);
813 ret = crypto_hash_digest(desc, sg, blen, out);
818 printk("%6u opers/sec, %9lu bytes/sec\n",
819 bcount / sec, ((long)bcount * blen) / sec);
824 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
825 int plen, char *out, int sec)
827 struct scatterlist sg[1];
828 unsigned long start, end;
833 return test_hash_jiffies_digest(desc, p, blen, out, sec);
835 sg_init_table(sg, 1);
837 for (start = jiffies, end = start + sec * HZ, bcount = 0;
838 time_before(jiffies, end); bcount++) {
839 ret = crypto_hash_init(desc);
842 for (pcount = 0; pcount < blen; pcount += plen) {
843 sg_set_buf(sg, p + pcount, plen);
844 ret = crypto_hash_update(desc, sg, plen);
848 /* we assume there is enough space in 'out' for the result */
849 ret = crypto_hash_final(desc, out);
854 printk("%6u opers/sec, %9lu bytes/sec\n",
855 bcount / sec, ((long)bcount * blen) / sec);
860 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
863 struct scatterlist sg[1];
864 unsigned long cycles = 0;
868 sg_init_table(sg, 1);
874 for (i = 0; i < 4; i++) {
875 sg_set_buf(sg, p, blen);
876 ret = crypto_hash_digest(desc, sg, blen, out);
881 /* The real thing. */
882 for (i = 0; i < 8; i++) {
885 start = get_cycles();
887 sg_set_buf(sg, p, blen);
888 ret = crypto_hash_digest(desc, sg, blen, out);
894 cycles += end - start;
904 printk("%6lu cycles/operation, %4lu cycles/byte\n",
905 cycles / 8, cycles / (8 * blen));
910 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
913 struct scatterlist sg[1];
914 unsigned long cycles = 0;
919 return test_hash_cycles_digest(desc, p, blen, out);
921 sg_init_table(sg, 1);
927 for (i = 0; i < 4; i++) {
928 ret = crypto_hash_init(desc);
931 for (pcount = 0; pcount < blen; pcount += plen) {
932 sg_set_buf(sg, p + pcount, plen);
933 ret = crypto_hash_update(desc, sg, plen);
937 ret = crypto_hash_final(desc, out);
942 /* The real thing. */
943 for (i = 0; i < 8; i++) {
946 start = get_cycles();
948 ret = crypto_hash_init(desc);
951 for (pcount = 0; pcount < blen; pcount += plen) {
952 sg_set_buf(sg, p + pcount, plen);
953 ret = crypto_hash_update(desc, sg, plen);
957 ret = crypto_hash_final(desc, out);
963 cycles += end - start;
973 printk("%6lu cycles/operation, %4lu cycles/byte\n",
974 cycles / 8, cycles / (8 * blen));
979 static void test_hash_speed(char *algo, unsigned int sec,
980 struct hash_speed *speed)
982 struct crypto_hash *tfm;
983 struct hash_desc desc;
988 printk("\ntesting speed of %s\n", algo);
990 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
993 printk("failed to load transform for %s: %ld\n", algo,
1001 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1002 printk("digestsize(%u) > outputbuffer(%zu)\n",
1003 crypto_hash_digestsize(tfm), sizeof(output));
1007 for (i = 0; speed[i].blen != 0; i++) {
1008 if (speed[i].blen > TVMEMSIZE) {
1009 printk("template (%u) too big for tvmem (%u)\n",
1010 speed[i].blen, TVMEMSIZE);
1014 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1015 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1017 memset(tvmem, 0xff, speed[i].blen);
1020 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1021 speed[i].plen, output, sec);
1023 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1024 speed[i].plen, output);
1027 printk("hashing failed ret=%d\n", ret);
1033 crypto_free_hash(tfm);
1036 static void test_deflate(void)
1039 char result[COMP_BUF_SIZE];
1040 struct crypto_comp *tfm;
1041 struct comp_testvec *tv;
1044 printk("\ntesting deflate compression\n");
1046 tsize = sizeof (deflate_comp_tv_template);
1047 if (tsize > TVMEMSIZE) {
1048 printk("template (%u) too big for tvmem (%u)\n", tsize,
1053 memcpy(tvmem, deflate_comp_tv_template, tsize);
1056 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
1058 printk("failed to load transform for deflate\n");
1062 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
1063 int ilen, ret, dlen = COMP_BUF_SIZE;
1065 printk("test %u:\n", i + 1);
1066 memset(result, 0, sizeof (result));
1069 ret = crypto_comp_compress(tfm, tv[i].input,
1070 ilen, result, &dlen);
1072 printk("fail: ret=%d\n", ret);
1075 hexdump(result, dlen);
1076 printk("%s (ratio %d:%d)\n",
1077 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1081 printk("\ntesting deflate decompression\n");
1083 tsize = sizeof (deflate_decomp_tv_template);
1084 if (tsize > TVMEMSIZE) {
1085 printk("template (%u) too big for tvmem (%u)\n", tsize,
1090 memcpy(tvmem, deflate_decomp_tv_template, tsize);
1093 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
1094 int ilen, ret, dlen = COMP_BUF_SIZE;
1096 printk("test %u:\n", i + 1);
1097 memset(result, 0, sizeof (result));
1100 ret = crypto_comp_decompress(tfm, tv[i].input,
1101 ilen, result, &dlen);
1103 printk("fail: ret=%d\n", ret);
1106 hexdump(result, dlen);
1107 printk("%s (ratio %d:%d)\n",
1108 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1112 crypto_free_comp(tfm);
1115 static void test_available(void)
1117 char **name = check;
1120 printk("alg %s ", *name);
1121 printk(crypto_has_alg(*name, 0, 0) ?
1122 "found\n" : "not found\n");
1127 static void do_test(void)
1132 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1134 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1137 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1138 DES_ENC_TEST_VECTORS);
1139 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1140 DES_DEC_TEST_VECTORS);
1141 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1142 DES_CBC_ENC_TEST_VECTORS);
1143 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1144 DES_CBC_DEC_TEST_VECTORS);
1147 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1148 DES3_EDE_ENC_TEST_VECTORS);
1149 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1150 DES3_EDE_DEC_TEST_VECTORS);
1152 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1154 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1156 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1159 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1160 BF_ENC_TEST_VECTORS);
1161 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1162 BF_DEC_TEST_VECTORS);
1163 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1164 BF_CBC_ENC_TEST_VECTORS);
1165 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1166 BF_CBC_DEC_TEST_VECTORS);
1169 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1170 TF_ENC_TEST_VECTORS);
1171 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1172 TF_DEC_TEST_VECTORS);
1173 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1174 TF_CBC_ENC_TEST_VECTORS);
1175 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1176 TF_CBC_DEC_TEST_VECTORS);
1179 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1180 SERPENT_ENC_TEST_VECTORS);
1181 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1182 SERPENT_DEC_TEST_VECTORS);
1185 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1186 TNEPRES_ENC_TEST_VECTORS);
1187 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1188 TNEPRES_DEC_TEST_VECTORS);
1191 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1192 AES_ENC_TEST_VECTORS);
1193 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1194 AES_DEC_TEST_VECTORS);
1195 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1196 AES_CBC_ENC_TEST_VECTORS);
1197 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1198 AES_CBC_DEC_TEST_VECTORS);
1199 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1200 AES_LRW_ENC_TEST_VECTORS);
1201 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1202 AES_LRW_DEC_TEST_VECTORS);
1203 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1204 AES_XTS_ENC_TEST_VECTORS);
1205 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1206 AES_XTS_DEC_TEST_VECTORS);
1207 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1208 AES_CTR_ENC_TEST_VECTORS);
1209 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1210 AES_CTR_DEC_TEST_VECTORS);
1213 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1214 CAST5_ENC_TEST_VECTORS);
1215 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1216 CAST5_DEC_TEST_VECTORS);
1219 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1220 CAST6_ENC_TEST_VECTORS);
1221 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1222 CAST6_DEC_TEST_VECTORS);
1225 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1226 ARC4_ENC_TEST_VECTORS);
1227 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1228 ARC4_DEC_TEST_VECTORS);
1231 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1232 TEA_ENC_TEST_VECTORS);
1233 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1234 TEA_DEC_TEST_VECTORS);
1238 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1239 XTEA_ENC_TEST_VECTORS);
1240 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1241 XTEA_DEC_TEST_VECTORS);
1244 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1245 KHAZAD_ENC_TEST_VECTORS);
1246 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1247 KHAZAD_DEC_TEST_VECTORS);
1250 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1251 ANUBIS_ENC_TEST_VECTORS);
1252 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1253 ANUBIS_DEC_TEST_VECTORS);
1254 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1255 ANUBIS_CBC_ENC_TEST_VECTORS);
1256 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1257 ANUBIS_CBC_ENC_TEST_VECTORS);
1260 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1261 XETA_ENC_TEST_VECTORS);
1262 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1263 XETA_DEC_TEST_VECTORS);
1266 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1267 FCRYPT_ENC_TEST_VECTORS);
1268 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1269 FCRYPT_DEC_TEST_VECTORS);
1272 test_cipher("ecb(camellia)", ENCRYPT,
1273 camellia_enc_tv_template,
1274 CAMELLIA_ENC_TEST_VECTORS);
1275 test_cipher("ecb(camellia)", DECRYPT,
1276 camellia_dec_tv_template,
1277 CAMELLIA_DEC_TEST_VECTORS);
1278 test_cipher("cbc(camellia)", ENCRYPT,
1279 camellia_cbc_enc_tv_template,
1280 CAMELLIA_CBC_ENC_TEST_VECTORS);
1281 test_cipher("cbc(camellia)", DECRYPT,
1282 camellia_cbc_dec_tv_template,
1283 CAMELLIA_CBC_DEC_TEST_VECTORS);
1286 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1287 SEED_ENC_TEST_VECTORS);
1288 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1289 SEED_DEC_TEST_VECTORS);
1291 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1292 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1293 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1294 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1295 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1296 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1297 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1298 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1300 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1301 test_hash("hmac(md5)", hmac_md5_tv_template,
1302 HMAC_MD5_TEST_VECTORS);
1303 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1304 HMAC_SHA1_TEST_VECTORS);
1305 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1306 HMAC_SHA224_TEST_VECTORS);
1307 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1308 HMAC_SHA256_TEST_VECTORS);
1309 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1310 HMAC_SHA384_TEST_VECTORS);
1311 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1312 HMAC_SHA512_TEST_VECTORS);
1314 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1315 XCBC_AES_TEST_VECTORS);
1317 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1321 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1325 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1329 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1330 DES_ENC_TEST_VECTORS);
1331 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1332 DES_DEC_TEST_VECTORS);
1333 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1334 DES_CBC_ENC_TEST_VECTORS);
1335 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1336 DES_CBC_DEC_TEST_VECTORS);
1340 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1341 DES3_EDE_ENC_TEST_VECTORS);
1342 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1343 DES3_EDE_DEC_TEST_VECTORS);
1347 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1351 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1355 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1356 BF_ENC_TEST_VECTORS);
1357 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1358 BF_DEC_TEST_VECTORS);
1359 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1360 BF_CBC_ENC_TEST_VECTORS);
1361 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1362 BF_CBC_DEC_TEST_VECTORS);
1366 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1367 TF_ENC_TEST_VECTORS);
1368 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1369 TF_DEC_TEST_VECTORS);
1370 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1371 TF_CBC_ENC_TEST_VECTORS);
1372 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1373 TF_CBC_DEC_TEST_VECTORS);
1377 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1378 SERPENT_ENC_TEST_VECTORS);
1379 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1380 SERPENT_DEC_TEST_VECTORS);
1384 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1385 AES_ENC_TEST_VECTORS);
1386 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1387 AES_DEC_TEST_VECTORS);
1388 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1389 AES_CBC_ENC_TEST_VECTORS);
1390 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1391 AES_CBC_DEC_TEST_VECTORS);
1392 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1393 AES_LRW_ENC_TEST_VECTORS);
1394 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1395 AES_LRW_DEC_TEST_VECTORS);
1396 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1397 AES_XTS_ENC_TEST_VECTORS);
1398 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1399 AES_XTS_DEC_TEST_VECTORS);
1400 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1401 AES_CTR_ENC_TEST_VECTORS);
1402 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1403 AES_CTR_DEC_TEST_VECTORS);
1407 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1411 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1419 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1420 CAST5_ENC_TEST_VECTORS);
1421 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1422 CAST5_DEC_TEST_VECTORS);
1426 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1427 CAST6_ENC_TEST_VECTORS);
1428 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1429 CAST6_DEC_TEST_VECTORS);
1433 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1434 ARC4_ENC_TEST_VECTORS);
1435 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1436 ARC4_DEC_TEST_VECTORS);
1440 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1444 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1448 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1449 TEA_ENC_TEST_VECTORS);
1450 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1451 TEA_DEC_TEST_VECTORS);
1455 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1456 XTEA_ENC_TEST_VECTORS);
1457 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1458 XTEA_DEC_TEST_VECTORS);
1462 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1463 KHAZAD_ENC_TEST_VECTORS);
1464 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1465 KHAZAD_DEC_TEST_VECTORS);
1469 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1473 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1477 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1481 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1482 TNEPRES_ENC_TEST_VECTORS);
1483 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1484 TNEPRES_DEC_TEST_VECTORS);
1488 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1489 ANUBIS_ENC_TEST_VECTORS);
1490 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1491 ANUBIS_DEC_TEST_VECTORS);
1492 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1493 ANUBIS_CBC_ENC_TEST_VECTORS);
1494 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1495 ANUBIS_CBC_ENC_TEST_VECTORS);
1499 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1504 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1508 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1512 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1513 XETA_ENC_TEST_VECTORS);
1514 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1515 XETA_DEC_TEST_VECTORS);
1519 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1520 FCRYPT_ENC_TEST_VECTORS);
1521 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1522 FCRYPT_DEC_TEST_VECTORS);
1526 test_cipher("ecb(camellia)", ENCRYPT,
1527 camellia_enc_tv_template,
1528 CAMELLIA_ENC_TEST_VECTORS);
1529 test_cipher("ecb(camellia)", DECRYPT,
1530 camellia_dec_tv_template,
1531 CAMELLIA_DEC_TEST_VECTORS);
1532 test_cipher("cbc(camellia)", ENCRYPT,
1533 camellia_cbc_enc_tv_template,
1534 CAMELLIA_CBC_ENC_TEST_VECTORS);
1535 test_cipher("cbc(camellia)", DECRYPT,
1536 camellia_cbc_dec_tv_template,
1537 CAMELLIA_CBC_DEC_TEST_VECTORS);
1540 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1544 test_cipher("salsa20", ENCRYPT,
1545 salsa20_stream_enc_tv_template,
1546 SALSA20_STREAM_ENC_TEST_VECTORS);
1550 test_hash("hmac(md5)", hmac_md5_tv_template,
1551 HMAC_MD5_TEST_VECTORS);
1555 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1556 HMAC_SHA1_TEST_VECTORS);
1560 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1561 HMAC_SHA256_TEST_VECTORS);
1565 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1566 HMAC_SHA384_TEST_VECTORS);
1570 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1571 HMAC_SHA512_TEST_VECTORS);
1574 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1575 HMAC_SHA224_TEST_VECTORS);
1579 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1580 aes_speed_template);
1581 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1582 aes_speed_template);
1583 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1584 aes_speed_template);
1585 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1586 aes_speed_template);
1587 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1588 aes_lrw_speed_template);
1589 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1590 aes_lrw_speed_template);
1591 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1592 aes_xts_speed_template);
1593 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1594 aes_xts_speed_template);
1598 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1599 des3_ede_enc_tv_template,
1600 DES3_EDE_ENC_TEST_VECTORS,
1601 des3_ede_speed_template);
1602 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1603 des3_ede_dec_tv_template,
1604 DES3_EDE_DEC_TEST_VECTORS,
1605 des3_ede_speed_template);
1606 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1607 des3_ede_enc_tv_template,
1608 DES3_EDE_ENC_TEST_VECTORS,
1609 des3_ede_speed_template);
1610 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1611 des3_ede_dec_tv_template,
1612 DES3_EDE_DEC_TEST_VECTORS,
1613 des3_ede_speed_template);
1617 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1618 twofish_speed_template);
1619 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1620 twofish_speed_template);
1621 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1622 twofish_speed_template);
1623 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1624 twofish_speed_template);
1628 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1629 blowfish_speed_template);
1630 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1631 blowfish_speed_template);
1632 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1633 blowfish_speed_template);
1634 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1635 blowfish_speed_template);
1639 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1640 des_speed_template);
1641 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1642 des_speed_template);
1643 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1644 des_speed_template);
1645 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1646 des_speed_template);
1650 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1651 camellia_speed_template);
1652 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1653 camellia_speed_template);
1654 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1655 camellia_speed_template);
1656 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1657 camellia_speed_template);
1664 test_hash_speed("md4", sec, generic_hash_speed_template);
1665 if (mode > 300 && mode < 400) break;
1668 test_hash_speed("md5", sec, generic_hash_speed_template);
1669 if (mode > 300 && mode < 400) break;
1672 test_hash_speed("sha1", sec, generic_hash_speed_template);
1673 if (mode > 300 && mode < 400) break;
1676 test_hash_speed("sha256", sec, generic_hash_speed_template);
1677 if (mode > 300 && mode < 400) break;
1680 test_hash_speed("sha384", sec, generic_hash_speed_template);
1681 if (mode > 300 && mode < 400) break;
1684 test_hash_speed("sha512", sec, generic_hash_speed_template);
1685 if (mode > 300 && mode < 400) break;
1688 test_hash_speed("wp256", sec, generic_hash_speed_template);
1689 if (mode > 300 && mode < 400) break;
1692 test_hash_speed("wp384", sec, generic_hash_speed_template);
1693 if (mode > 300 && mode < 400) break;
1696 test_hash_speed("wp512", sec, generic_hash_speed_template);
1697 if (mode > 300 && mode < 400) break;
1700 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1701 if (mode > 300 && mode < 400) break;
1704 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1705 if (mode > 300 && mode < 400) break;
1708 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1709 if (mode > 300 && mode < 400) break;
1712 test_hash_speed("sha224", sec, generic_hash_speed_template);
1713 if (mode > 300 && mode < 400) break;
1723 /* useful for debugging */
1724 printk("not testing anything\n");
1729 static int __init init(void)
1733 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1737 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1741 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1747 /* We intentionaly return -EAGAIN to prevent keeping
1748 * the module. It does all its work from init()
1749 * and doesn't offer any runtime functionality
1750 * => we don't need it in the memory, do we?
1765 * If an init function is provided, an exit function must also be provided
1766 * to allow module unload.
1768 static void __exit fini(void) { }
1773 module_param(mode, int, 0);
1774 module_param(sec, uint, 0);
1775 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1776 "(defaults to zero which uses CPU cycles instead)");
1778 MODULE_LICENSE("GPL");
1779 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1780 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");