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 GCM tests
17 * 2007-11-13 Added AEAD support
18 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
19 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
20 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
21 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
25 #include <linux/err.h>
26 #include <linux/init.h>
27 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/crypto.h>
33 #include <linux/highmem.h>
34 #include <linux/moduleparam.h>
35 #include <linux/jiffies.h>
36 #include <linux/timex.h>
37 #include <linux/interrupt.h>
41 * Need to kmalloc() memory for testing kmap().
43 #define TVMEMSIZE 16384
44 #define XBUFSIZE 32768
47 * Indexes into the xbuf to simulate cross-page access.
59 * Used by test_cipher()
64 struct tcrypt_result {
65 struct completion completion;
69 static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };
72 * Used by test_cipher_speed()
74 static unsigned int sec;
81 static char *check[] = {
82 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
83 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
84 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
85 "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
86 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
87 "camellia", "seed", "salsa20", NULL
90 static void hexdump(unsigned char *buf, unsigned int len)
93 printk("%02x", *buf++);
98 static void tcrypt_complete(struct crypto_async_request *req, int err)
100 struct tcrypt_result *res = req->data;
102 if (err == -EINPROGRESS)
106 complete(&res->completion);
109 static void test_hash(char *algo, struct hash_testvec *template,
112 unsigned int i, j, k, temp;
113 struct scatterlist sg[8];
115 struct crypto_hash *tfm;
116 struct hash_desc desc;
117 struct hash_testvec *hash_tv;
121 printk("\ntesting %s\n", algo);
123 tsize = sizeof(struct hash_testvec);
126 if (tsize > TVMEMSIZE) {
127 printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
131 memcpy(tvmem, template, tsize);
132 hash_tv = (void *)tvmem;
134 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
136 printk("failed to load transform for %s: %ld\n", algo,
144 for (i = 0; i < tcount; i++) {
145 printk("test %u:\n", i + 1);
146 memset(result, 0, 64);
148 sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
150 if (hash_tv[i].ksize) {
151 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
154 printk("setkey() failed ret=%d\n", ret);
159 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
161 printk("digest () failed ret=%d\n", ret);
165 hexdump(result, crypto_hash_digestsize(tfm));
167 memcmp(result, hash_tv[i].digest,
168 crypto_hash_digestsize(tfm)) ?
172 printk("testing %s across pages\n", algo);
174 /* setup the dummy buffer first */
175 memset(xbuf, 0, XBUFSIZE);
176 memset(axbuf, 0, XBUFSIZE);
179 for (i = 0; i < tcount; i++) {
182 printk("test %u:\n", j);
183 memset(result, 0, 64);
186 sg_init_table(sg, hash_tv[i].np);
187 for (k = 0; k < hash_tv[i].np; k++) {
188 memcpy(&xbuf[IDX[k]],
189 hash_tv[i].plaintext + temp,
191 temp += hash_tv[i].tap[k];
192 sg_set_buf(&sg[k], &xbuf[IDX[k]],
196 if (hash_tv[i].ksize) {
197 ret = crypto_hash_setkey(tfm, hash_tv[i].key,
201 printk("setkey() failed ret=%d\n", ret);
206 ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
209 printk("digest () failed ret=%d\n", ret);
213 hexdump(result, crypto_hash_digestsize(tfm));
215 memcmp(result, hash_tv[i].digest,
216 crypto_hash_digestsize(tfm)) ?
222 crypto_free_hash(tfm);
225 static void test_aead(char *algo, int enc, struct aead_testvec *template,
228 unsigned int ret, i, j, k, temp;
231 struct crypto_aead *tfm;
233 struct aead_testvec *aead_tv;
234 struct aead_request *req;
235 struct scatterlist sg[8];
236 struct scatterlist asg[8];
238 struct tcrypt_result result;
245 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
247 tsize = sizeof(struct aead_testvec);
250 if (tsize > TVMEMSIZE) {
251 printk(KERN_INFO "template (%u) too big for tvmem (%u)\n",
256 memcpy(tvmem, template, tsize);
257 aead_tv = (void *)tvmem;
259 init_completion(&result.completion);
261 tfm = crypto_alloc_aead(algo, 0, 0);
264 printk(KERN_INFO "failed to load transform for %s: %ld\n",
269 req = aead_request_alloc(tfm, GFP_KERNEL);
271 printk(KERN_INFO "failed to allocate request for %s\n", algo);
275 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
276 tcrypt_complete, &result);
278 for (i = 0, j = 0; i < tcount; i++) {
279 if (!aead_tv[i].np) {
280 printk(KERN_INFO "test %u (%d bit key):\n",
281 ++j, aead_tv[i].klen * 8);
283 crypto_aead_clear_flags(tfm, ~0);
285 crypto_aead_set_flags(
286 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
287 key = aead_tv[i].key;
289 ret = crypto_aead_setkey(tfm, key,
292 printk(KERN_INFO "setkey() failed flags=%x\n",
293 crypto_aead_get_flags(tfm));
295 if (!aead_tv[i].fail)
299 sg_init_one(&sg[0], aead_tv[i].input,
302 sg_init_one(&asg[0], aead_tv[i].assoc,
305 aead_request_set_crypt(req, sg, sg,
309 aead_request_set_assoc(req, asg, aead_tv[i].alen);
312 ret = crypto_aead_encrypt(req);
314 memcpy(req->__ctx, aead_tv[i].tag,
316 ret = crypto_aead_decrypt(req);
324 ret = wait_for_completion_interruptible(
326 if (!ret && !(ret = result.err)) {
327 INIT_COMPLETION(result.completion);
332 printk(KERN_INFO "%s () failed err=%d\n",
337 q = kmap(sg_page(&sg[0])) + sg[0].offset;
338 hexdump(q, aead_tv[i].rlen);
339 printk(KERN_INFO "auth tag: ");
340 hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen);
342 printk(KERN_INFO "enc/dec: %s\n",
343 memcmp(q, aead_tv[i].result,
344 aead_tv[i].rlen) ? "fail" : "pass");
346 printk(KERN_INFO "auth tag: %s\n",
347 memcmp(req->__ctx, aead_tv[i].tag,
348 aead_tv[i].tlen) ? "fail" : "pass");
352 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
353 memset(xbuf, 0, XBUFSIZE);
355 for (i = 0, j = 0; i < tcount; i++) {
357 printk(KERN_INFO "test %u (%d bit key):\n",
358 ++j, aead_tv[i].klen * 8);
360 crypto_aead_clear_flags(tfm, ~0);
362 crypto_aead_set_flags(
363 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
364 key = aead_tv[i].key;
366 ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen);
368 printk(KERN_INFO "setkey() failed flags=%x\n",
369 crypto_aead_get_flags(tfm));
371 if (!aead_tv[i].fail)
375 sg_init_table(sg, aead_tv[i].np);
376 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
377 memcpy(&xbuf[IDX[k]],
378 aead_tv[i].input + temp,
380 temp += aead_tv[i].tap[k];
381 sg_set_buf(&sg[k], &xbuf[IDX[k]],
385 sg_init_table(asg, aead_tv[i].anp);
386 for (k = 0, temp = 0; k < aead_tv[i].anp; k++) {
387 memcpy(&axbuf[IDX[k]],
388 aead_tv[i].assoc + temp,
390 temp += aead_tv[i].atap[k];
391 sg_set_buf(&asg[k], &axbuf[IDX[k]],
395 aead_request_set_crypt(req, sg, sg,
399 aead_request_set_assoc(req, asg, aead_tv[i].alen);
402 ret = crypto_aead_encrypt(req);
404 memcpy(req->__ctx, aead_tv[i].tag,
406 ret = crypto_aead_decrypt(req);
414 ret = wait_for_completion_interruptible(
416 if (!ret && !(ret = result.err)) {
417 INIT_COMPLETION(result.completion);
422 printk(KERN_INFO "%s () failed err=%d\n",
427 for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
428 printk(KERN_INFO "page %u\n", k);
429 q = kmap(sg_page(&sg[k])) + sg[k].offset;
430 hexdump(q, aead_tv[i].tap[k]);
431 printk(KERN_INFO "%s\n",
432 memcmp(q, aead_tv[i].result + temp,
436 temp += aead_tv[i].tap[k];
438 printk(KERN_INFO "auth tag: ");
439 hexdump((unsigned char *)req->__ctx, aead_tv[i].tlen);
441 printk(KERN_INFO "auth tag: %s\n",
442 memcmp(req->__ctx, aead_tv[i].tag,
443 aead_tv[i].tlen) ? "fail" : "pass");
448 crypto_free_aead(tfm);
449 aead_request_free(req);
452 static void test_cipher(char *algo, int enc,
453 struct cipher_testvec *template, unsigned int tcount)
455 unsigned int ret, i, j, k, temp;
458 struct crypto_ablkcipher *tfm;
460 struct cipher_testvec *cipher_tv;
461 struct ablkcipher_request *req;
462 struct scatterlist sg[8];
464 struct tcrypt_result result;
471 printk("\ntesting %s %s\n", algo, e);
473 tsize = sizeof (struct cipher_testvec);
476 if (tsize > TVMEMSIZE) {
477 printk("template (%u) too big for tvmem (%u)\n", tsize,
482 memcpy(tvmem, template, tsize);
483 cipher_tv = (void *)tvmem;
485 init_completion(&result.completion);
487 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
490 printk("failed to load transform for %s: %ld\n", algo,
495 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
497 printk("failed to allocate request for %s\n", algo);
501 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
502 tcrypt_complete, &result);
505 for (i = 0; i < tcount; i++) {
506 if (!(cipher_tv[i].np)) {
508 printk("test %u (%d bit key):\n",
509 j, cipher_tv[i].klen * 8);
511 crypto_ablkcipher_clear_flags(tfm, ~0);
513 crypto_ablkcipher_set_flags(
514 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
515 key = cipher_tv[i].key;
517 ret = crypto_ablkcipher_setkey(tfm, key,
520 printk("setkey() failed flags=%x\n",
521 crypto_ablkcipher_get_flags(tfm));
523 if (!cipher_tv[i].fail)
527 sg_init_one(&sg[0], cipher_tv[i].input,
530 ablkcipher_request_set_crypt(req, sg, sg,
535 crypto_ablkcipher_encrypt(req) :
536 crypto_ablkcipher_decrypt(req);
543 ret = wait_for_completion_interruptible(
545 if (!ret && !((ret = result.err))) {
546 INIT_COMPLETION(result.completion);
551 printk("%s () failed err=%d\n", e, -ret);
555 q = kmap(sg_page(&sg[0])) + sg[0].offset;
556 hexdump(q, cipher_tv[i].rlen);
559 memcmp(q, cipher_tv[i].result,
560 cipher_tv[i].rlen) ? "fail" : "pass");
564 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
565 memset(xbuf, 0, XBUFSIZE);
568 for (i = 0; i < tcount; i++) {
569 if (cipher_tv[i].np) {
571 printk("test %u (%d bit key):\n",
572 j, cipher_tv[i].klen * 8);
574 crypto_ablkcipher_clear_flags(tfm, ~0);
576 crypto_ablkcipher_set_flags(
577 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
578 key = cipher_tv[i].key;
580 ret = crypto_ablkcipher_setkey(tfm, key,
583 printk("setkey() failed flags=%x\n",
584 crypto_ablkcipher_get_flags(tfm));
586 if (!cipher_tv[i].fail)
591 sg_init_table(sg, cipher_tv[i].np);
592 for (k = 0; k < cipher_tv[i].np; k++) {
593 memcpy(&xbuf[IDX[k]],
594 cipher_tv[i].input + temp,
595 cipher_tv[i].tap[k]);
596 temp += cipher_tv[i].tap[k];
597 sg_set_buf(&sg[k], &xbuf[IDX[k]],
598 cipher_tv[i].tap[k]);
601 ablkcipher_request_set_crypt(req, sg, sg,
606 crypto_ablkcipher_encrypt(req) :
607 crypto_ablkcipher_decrypt(req);
614 ret = wait_for_completion_interruptible(
616 if (!ret && !((ret = result.err))) {
617 INIT_COMPLETION(result.completion);
622 printk("%s () failed err=%d\n", e, -ret);
627 for (k = 0; k < cipher_tv[i].np; k++) {
628 printk("page %u\n", k);
629 q = kmap(sg_page(&sg[k])) + sg[k].offset;
630 hexdump(q, cipher_tv[i].tap[k]);
632 memcmp(q, cipher_tv[i].result + temp,
633 cipher_tv[i].tap[k]) ? "fail" :
635 temp += cipher_tv[i].tap[k];
641 crypto_free_ablkcipher(tfm);
642 ablkcipher_request_free(req);
645 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
648 struct scatterlist sg[1];
649 unsigned long start, end;
653 sg_init_one(sg, p, blen);
655 for (start = jiffies, end = start + sec * HZ, bcount = 0;
656 time_before(jiffies, end); bcount++) {
658 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
660 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
666 printk("%d operations in %d seconds (%ld bytes)\n",
667 bcount, sec, (long)bcount * blen);
671 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
674 struct scatterlist sg[1];
675 unsigned long cycles = 0;
679 sg_init_one(sg, p, blen);
685 for (i = 0; i < 4; i++) {
687 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
689 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
695 /* The real thing. */
696 for (i = 0; i < 8; i++) {
699 start = get_cycles();
701 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
703 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
709 cycles += end - start;
717 printk("1 operation in %lu cycles (%d bytes)\n",
718 (cycles + 4) / 8, blen);
723 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
724 struct cipher_testvec *template,
725 unsigned int tcount, struct cipher_speed *speed)
727 unsigned int ret, i, j, iv_len;
728 unsigned char *key, *p, iv[128];
729 struct crypto_blkcipher *tfm;
730 struct blkcipher_desc desc;
738 printk("\ntesting speed of %s %s\n", algo, e);
740 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
743 printk("failed to load transform for %s: %ld\n", algo,
750 for (i = 0; speed[i].klen != 0; i++) {
751 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
752 printk("template (%u) too big for tvmem (%u)\n",
753 speed[i].blen + speed[i].klen, TVMEMSIZE);
757 printk("test %u (%d bit key, %d byte blocks): ", i,
758 speed[i].klen * 8, speed[i].blen);
760 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
762 /* set key, plain text and IV */
763 key = (unsigned char *)tvmem;
764 for (j = 0; j < tcount; j++) {
765 if (template[j].klen == speed[i].klen) {
766 key = template[j].key;
770 p = (unsigned char *)tvmem + speed[i].klen;
772 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
774 printk("setkey() failed flags=%x\n",
775 crypto_blkcipher_get_flags(tfm));
779 iv_len = crypto_blkcipher_ivsize(tfm);
781 memset(&iv, 0xff, iv_len);
782 crypto_blkcipher_set_iv(tfm, iv, iv_len);
786 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
789 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
792 printk("%s() failed flags=%x\n", e, desc.flags);
798 crypto_free_blkcipher(tfm);
801 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
804 struct scatterlist sg[1];
805 unsigned long start, end;
809 sg_init_table(sg, 1);
811 for (start = jiffies, end = start + sec * HZ, bcount = 0;
812 time_before(jiffies, end); bcount++) {
813 sg_set_buf(sg, p, blen);
814 ret = crypto_hash_digest(desc, sg, blen, out);
819 printk("%6u opers/sec, %9lu bytes/sec\n",
820 bcount / sec, ((long)bcount * blen) / sec);
825 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
826 int plen, char *out, int sec)
828 struct scatterlist sg[1];
829 unsigned long start, end;
834 return test_hash_jiffies_digest(desc, p, blen, out, sec);
836 sg_init_table(sg, 1);
838 for (start = jiffies, end = start + sec * HZ, bcount = 0;
839 time_before(jiffies, end); bcount++) {
840 ret = crypto_hash_init(desc);
843 for (pcount = 0; pcount < blen; pcount += plen) {
844 sg_set_buf(sg, p + pcount, plen);
845 ret = crypto_hash_update(desc, sg, plen);
849 /* we assume there is enough space in 'out' for the result */
850 ret = crypto_hash_final(desc, out);
855 printk("%6u opers/sec, %9lu bytes/sec\n",
856 bcount / sec, ((long)bcount * blen) / sec);
861 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
864 struct scatterlist sg[1];
865 unsigned long cycles = 0;
869 sg_init_table(sg, 1);
875 for (i = 0; i < 4; i++) {
876 sg_set_buf(sg, p, blen);
877 ret = crypto_hash_digest(desc, sg, blen, out);
882 /* The real thing. */
883 for (i = 0; i < 8; i++) {
886 start = get_cycles();
888 sg_set_buf(sg, p, blen);
889 ret = crypto_hash_digest(desc, sg, blen, out);
895 cycles += end - start;
905 printk("%6lu cycles/operation, %4lu cycles/byte\n",
906 cycles / 8, cycles / (8 * blen));
911 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
914 struct scatterlist sg[1];
915 unsigned long cycles = 0;
920 return test_hash_cycles_digest(desc, p, blen, out);
922 sg_init_table(sg, 1);
928 for (i = 0; i < 4; i++) {
929 ret = crypto_hash_init(desc);
932 for (pcount = 0; pcount < blen; pcount += plen) {
933 sg_set_buf(sg, p + pcount, plen);
934 ret = crypto_hash_update(desc, sg, plen);
938 ret = crypto_hash_final(desc, out);
943 /* The real thing. */
944 for (i = 0; i < 8; i++) {
947 start = get_cycles();
949 ret = crypto_hash_init(desc);
952 for (pcount = 0; pcount < blen; pcount += plen) {
953 sg_set_buf(sg, p + pcount, plen);
954 ret = crypto_hash_update(desc, sg, plen);
958 ret = crypto_hash_final(desc, out);
964 cycles += end - start;
974 printk("%6lu cycles/operation, %4lu cycles/byte\n",
975 cycles / 8, cycles / (8 * blen));
980 static void test_hash_speed(char *algo, unsigned int sec,
981 struct hash_speed *speed)
983 struct crypto_hash *tfm;
984 struct hash_desc desc;
989 printk("\ntesting speed of %s\n", algo);
991 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
994 printk("failed to load transform for %s: %ld\n", algo,
1002 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1003 printk("digestsize(%u) > outputbuffer(%zu)\n",
1004 crypto_hash_digestsize(tfm), sizeof(output));
1008 for (i = 0; speed[i].blen != 0; i++) {
1009 if (speed[i].blen > TVMEMSIZE) {
1010 printk("template (%u) too big for tvmem (%u)\n",
1011 speed[i].blen, TVMEMSIZE);
1015 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1016 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1018 memset(tvmem, 0xff, speed[i].blen);
1021 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1022 speed[i].plen, output, sec);
1024 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1025 speed[i].plen, output);
1028 printk("hashing failed ret=%d\n", ret);
1034 crypto_free_hash(tfm);
1037 static void test_deflate(void)
1040 char result[COMP_BUF_SIZE];
1041 struct crypto_comp *tfm;
1042 struct comp_testvec *tv;
1045 printk("\ntesting deflate compression\n");
1047 tsize = sizeof (deflate_comp_tv_template);
1048 if (tsize > TVMEMSIZE) {
1049 printk("template (%u) too big for tvmem (%u)\n", tsize,
1054 memcpy(tvmem, deflate_comp_tv_template, tsize);
1057 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
1059 printk("failed to load transform for deflate\n");
1063 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
1064 int ilen, ret, dlen = COMP_BUF_SIZE;
1066 printk("test %u:\n", i + 1);
1067 memset(result, 0, sizeof (result));
1070 ret = crypto_comp_compress(tfm, tv[i].input,
1071 ilen, result, &dlen);
1073 printk("fail: ret=%d\n", ret);
1076 hexdump(result, dlen);
1077 printk("%s (ratio %d:%d)\n",
1078 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1082 printk("\ntesting deflate decompression\n");
1084 tsize = sizeof (deflate_decomp_tv_template);
1085 if (tsize > TVMEMSIZE) {
1086 printk("template (%u) too big for tvmem (%u)\n", tsize,
1091 memcpy(tvmem, deflate_decomp_tv_template, tsize);
1094 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
1095 int ilen, ret, dlen = COMP_BUF_SIZE;
1097 printk("test %u:\n", i + 1);
1098 memset(result, 0, sizeof (result));
1101 ret = crypto_comp_decompress(tfm, tv[i].input,
1102 ilen, result, &dlen);
1104 printk("fail: ret=%d\n", ret);
1107 hexdump(result, dlen);
1108 printk("%s (ratio %d:%d)\n",
1109 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1113 crypto_free_comp(tfm);
1116 static void test_available(void)
1118 char **name = check;
1121 printk("alg %s ", *name);
1122 printk(crypto_has_alg(*name, 0, 0) ?
1123 "found\n" : "not found\n");
1128 static void do_test(void)
1133 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1135 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1138 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1139 DES_ENC_TEST_VECTORS);
1140 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1141 DES_DEC_TEST_VECTORS);
1142 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1143 DES_CBC_ENC_TEST_VECTORS);
1144 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1145 DES_CBC_DEC_TEST_VECTORS);
1148 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1149 DES3_EDE_ENC_TEST_VECTORS);
1150 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1151 DES3_EDE_DEC_TEST_VECTORS);
1153 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1155 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1157 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1160 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1161 BF_ENC_TEST_VECTORS);
1162 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1163 BF_DEC_TEST_VECTORS);
1164 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1165 BF_CBC_ENC_TEST_VECTORS);
1166 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1167 BF_CBC_DEC_TEST_VECTORS);
1170 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1171 TF_ENC_TEST_VECTORS);
1172 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1173 TF_DEC_TEST_VECTORS);
1174 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1175 TF_CBC_ENC_TEST_VECTORS);
1176 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1177 TF_CBC_DEC_TEST_VECTORS);
1180 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1181 SERPENT_ENC_TEST_VECTORS);
1182 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1183 SERPENT_DEC_TEST_VECTORS);
1186 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1187 TNEPRES_ENC_TEST_VECTORS);
1188 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1189 TNEPRES_DEC_TEST_VECTORS);
1192 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1193 AES_ENC_TEST_VECTORS);
1194 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1195 AES_DEC_TEST_VECTORS);
1196 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1197 AES_CBC_ENC_TEST_VECTORS);
1198 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1199 AES_CBC_DEC_TEST_VECTORS);
1200 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1201 AES_LRW_ENC_TEST_VECTORS);
1202 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1203 AES_LRW_DEC_TEST_VECTORS);
1204 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1205 AES_XTS_ENC_TEST_VECTORS);
1206 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1207 AES_XTS_DEC_TEST_VECTORS);
1208 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1209 AES_CTR_ENC_TEST_VECTORS);
1210 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1211 AES_CTR_DEC_TEST_VECTORS);
1212 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1213 AES_GCM_ENC_TEST_VECTORS);
1214 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1215 AES_GCM_DEC_TEST_VECTORS);
1218 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1219 CAST5_ENC_TEST_VECTORS);
1220 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1221 CAST5_DEC_TEST_VECTORS);
1224 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1225 CAST6_ENC_TEST_VECTORS);
1226 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1227 CAST6_DEC_TEST_VECTORS);
1230 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1231 ARC4_ENC_TEST_VECTORS);
1232 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1233 ARC4_DEC_TEST_VECTORS);
1236 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1237 TEA_ENC_TEST_VECTORS);
1238 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1239 TEA_DEC_TEST_VECTORS);
1243 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1244 XTEA_ENC_TEST_VECTORS);
1245 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1246 XTEA_DEC_TEST_VECTORS);
1249 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1250 KHAZAD_ENC_TEST_VECTORS);
1251 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1252 KHAZAD_DEC_TEST_VECTORS);
1255 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1256 ANUBIS_ENC_TEST_VECTORS);
1257 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1258 ANUBIS_DEC_TEST_VECTORS);
1259 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1260 ANUBIS_CBC_ENC_TEST_VECTORS);
1261 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1262 ANUBIS_CBC_ENC_TEST_VECTORS);
1265 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1266 XETA_ENC_TEST_VECTORS);
1267 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1268 XETA_DEC_TEST_VECTORS);
1271 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1272 FCRYPT_ENC_TEST_VECTORS);
1273 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1274 FCRYPT_DEC_TEST_VECTORS);
1277 test_cipher("ecb(camellia)", ENCRYPT,
1278 camellia_enc_tv_template,
1279 CAMELLIA_ENC_TEST_VECTORS);
1280 test_cipher("ecb(camellia)", DECRYPT,
1281 camellia_dec_tv_template,
1282 CAMELLIA_DEC_TEST_VECTORS);
1283 test_cipher("cbc(camellia)", ENCRYPT,
1284 camellia_cbc_enc_tv_template,
1285 CAMELLIA_CBC_ENC_TEST_VECTORS);
1286 test_cipher("cbc(camellia)", DECRYPT,
1287 camellia_cbc_dec_tv_template,
1288 CAMELLIA_CBC_DEC_TEST_VECTORS);
1291 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1292 SEED_ENC_TEST_VECTORS);
1293 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1294 SEED_DEC_TEST_VECTORS);
1296 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1297 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1298 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1299 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1300 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1301 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1302 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1303 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1305 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1306 test_hash("hmac(md5)", hmac_md5_tv_template,
1307 HMAC_MD5_TEST_VECTORS);
1308 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1309 HMAC_SHA1_TEST_VECTORS);
1310 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1311 HMAC_SHA224_TEST_VECTORS);
1312 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1313 HMAC_SHA256_TEST_VECTORS);
1314 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1315 HMAC_SHA384_TEST_VECTORS);
1316 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1317 HMAC_SHA512_TEST_VECTORS);
1319 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1320 XCBC_AES_TEST_VECTORS);
1322 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1326 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1330 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1334 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1335 DES_ENC_TEST_VECTORS);
1336 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1337 DES_DEC_TEST_VECTORS);
1338 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1339 DES_CBC_ENC_TEST_VECTORS);
1340 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1341 DES_CBC_DEC_TEST_VECTORS);
1345 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1346 DES3_EDE_ENC_TEST_VECTORS);
1347 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1348 DES3_EDE_DEC_TEST_VECTORS);
1352 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1356 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1360 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1361 BF_ENC_TEST_VECTORS);
1362 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1363 BF_DEC_TEST_VECTORS);
1364 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1365 BF_CBC_ENC_TEST_VECTORS);
1366 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1367 BF_CBC_DEC_TEST_VECTORS);
1371 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1372 TF_ENC_TEST_VECTORS);
1373 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1374 TF_DEC_TEST_VECTORS);
1375 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1376 TF_CBC_ENC_TEST_VECTORS);
1377 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1378 TF_CBC_DEC_TEST_VECTORS);
1382 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1383 SERPENT_ENC_TEST_VECTORS);
1384 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1385 SERPENT_DEC_TEST_VECTORS);
1389 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1390 AES_ENC_TEST_VECTORS);
1391 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1392 AES_DEC_TEST_VECTORS);
1393 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1394 AES_CBC_ENC_TEST_VECTORS);
1395 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1396 AES_CBC_DEC_TEST_VECTORS);
1397 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1398 AES_LRW_ENC_TEST_VECTORS);
1399 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1400 AES_LRW_DEC_TEST_VECTORS);
1401 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1402 AES_XTS_ENC_TEST_VECTORS);
1403 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1404 AES_XTS_DEC_TEST_VECTORS);
1405 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1406 AES_CTR_ENC_TEST_VECTORS);
1407 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1408 AES_CTR_DEC_TEST_VECTORS);
1412 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1416 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1424 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1425 CAST5_ENC_TEST_VECTORS);
1426 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1427 CAST5_DEC_TEST_VECTORS);
1431 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1432 CAST6_ENC_TEST_VECTORS);
1433 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1434 CAST6_DEC_TEST_VECTORS);
1438 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1439 ARC4_ENC_TEST_VECTORS);
1440 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1441 ARC4_DEC_TEST_VECTORS);
1445 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1449 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1453 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1454 TEA_ENC_TEST_VECTORS);
1455 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1456 TEA_DEC_TEST_VECTORS);
1460 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1461 XTEA_ENC_TEST_VECTORS);
1462 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1463 XTEA_DEC_TEST_VECTORS);
1467 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1468 KHAZAD_ENC_TEST_VECTORS);
1469 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1470 KHAZAD_DEC_TEST_VECTORS);
1474 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1478 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1482 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1486 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1487 TNEPRES_ENC_TEST_VECTORS);
1488 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1489 TNEPRES_DEC_TEST_VECTORS);
1493 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1494 ANUBIS_ENC_TEST_VECTORS);
1495 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1496 ANUBIS_DEC_TEST_VECTORS);
1497 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1498 ANUBIS_CBC_ENC_TEST_VECTORS);
1499 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1500 ANUBIS_CBC_ENC_TEST_VECTORS);
1504 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1509 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1513 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1517 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1518 XETA_ENC_TEST_VECTORS);
1519 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1520 XETA_DEC_TEST_VECTORS);
1524 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1525 FCRYPT_ENC_TEST_VECTORS);
1526 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1527 FCRYPT_DEC_TEST_VECTORS);
1531 test_cipher("ecb(camellia)", ENCRYPT,
1532 camellia_enc_tv_template,
1533 CAMELLIA_ENC_TEST_VECTORS);
1534 test_cipher("ecb(camellia)", DECRYPT,
1535 camellia_dec_tv_template,
1536 CAMELLIA_DEC_TEST_VECTORS);
1537 test_cipher("cbc(camellia)", ENCRYPT,
1538 camellia_cbc_enc_tv_template,
1539 CAMELLIA_CBC_ENC_TEST_VECTORS);
1540 test_cipher("cbc(camellia)", DECRYPT,
1541 camellia_cbc_dec_tv_template,
1542 CAMELLIA_CBC_DEC_TEST_VECTORS);
1545 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1549 test_cipher("salsa20", ENCRYPT,
1550 salsa20_stream_enc_tv_template,
1551 SALSA20_STREAM_ENC_TEST_VECTORS);
1555 test_hash("hmac(md5)", hmac_md5_tv_template,
1556 HMAC_MD5_TEST_VECTORS);
1560 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1561 HMAC_SHA1_TEST_VECTORS);
1565 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1566 HMAC_SHA256_TEST_VECTORS);
1570 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1571 HMAC_SHA384_TEST_VECTORS);
1575 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1576 HMAC_SHA512_TEST_VECTORS);
1579 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1580 HMAC_SHA224_TEST_VECTORS);
1584 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1585 aes_speed_template);
1586 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1587 aes_speed_template);
1588 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1589 aes_speed_template);
1590 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1591 aes_speed_template);
1592 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1593 aes_lrw_speed_template);
1594 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1595 aes_lrw_speed_template);
1596 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1597 aes_xts_speed_template);
1598 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1599 aes_xts_speed_template);
1603 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1604 des3_ede_enc_tv_template,
1605 DES3_EDE_ENC_TEST_VECTORS,
1606 des3_ede_speed_template);
1607 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1608 des3_ede_dec_tv_template,
1609 DES3_EDE_DEC_TEST_VECTORS,
1610 des3_ede_speed_template);
1611 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1612 des3_ede_enc_tv_template,
1613 DES3_EDE_ENC_TEST_VECTORS,
1614 des3_ede_speed_template);
1615 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1616 des3_ede_dec_tv_template,
1617 DES3_EDE_DEC_TEST_VECTORS,
1618 des3_ede_speed_template);
1622 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1623 twofish_speed_template);
1624 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1625 twofish_speed_template);
1626 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1627 twofish_speed_template);
1628 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1629 twofish_speed_template);
1633 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1634 blowfish_speed_template);
1635 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1636 blowfish_speed_template);
1637 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1638 blowfish_speed_template);
1639 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1640 blowfish_speed_template);
1644 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1645 des_speed_template);
1646 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1647 des_speed_template);
1648 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1649 des_speed_template);
1650 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1651 des_speed_template);
1655 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1656 camellia_speed_template);
1657 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1658 camellia_speed_template);
1659 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1660 camellia_speed_template);
1661 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1662 camellia_speed_template);
1669 test_hash_speed("md4", sec, generic_hash_speed_template);
1670 if (mode > 300 && mode < 400) break;
1673 test_hash_speed("md5", sec, generic_hash_speed_template);
1674 if (mode > 300 && mode < 400) break;
1677 test_hash_speed("sha1", sec, generic_hash_speed_template);
1678 if (mode > 300 && mode < 400) break;
1681 test_hash_speed("sha256", sec, generic_hash_speed_template);
1682 if (mode > 300 && mode < 400) break;
1685 test_hash_speed("sha384", sec, generic_hash_speed_template);
1686 if (mode > 300 && mode < 400) break;
1689 test_hash_speed("sha512", sec, generic_hash_speed_template);
1690 if (mode > 300 && mode < 400) break;
1693 test_hash_speed("wp256", sec, generic_hash_speed_template);
1694 if (mode > 300 && mode < 400) break;
1697 test_hash_speed("wp384", sec, generic_hash_speed_template);
1698 if (mode > 300 && mode < 400) break;
1701 test_hash_speed("wp512", sec, generic_hash_speed_template);
1702 if (mode > 300 && mode < 400) break;
1705 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1706 if (mode > 300 && mode < 400) break;
1709 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1710 if (mode > 300 && mode < 400) break;
1713 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1714 if (mode > 300 && mode < 400) break;
1717 test_hash_speed("sha224", sec, generic_hash_speed_template);
1718 if (mode > 300 && mode < 400) break;
1728 /* useful for debugging */
1729 printk("not testing anything\n");
1734 static int __init init(void)
1738 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1742 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1746 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1752 /* We intentionaly return -EAGAIN to prevent keeping
1753 * the module. It does all its work from init()
1754 * and doesn't offer any runtime functionality
1755 * => we don't need it in the memory, do we?
1770 * If an init function is provided, an exit function must also be provided
1771 * to allow module unload.
1773 static void __exit fini(void) { }
1778 module_param(mode, int, 0);
1779 module_param(sec, uint, 0);
1780 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1781 "(defaults to zero which uses CPU cycles instead)");
1783 MODULE_LICENSE("GPL");
1784 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1785 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");