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);
474 if (tsize > TVMEMSIZE) {
475 printk("template (%u) too big for tvmem (%u)\n", tsize,
479 cipher_tv = (void *)tvmem;
481 init_completion(&result.completion);
483 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
486 printk("failed to load transform for %s: %ld\n", algo,
491 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
493 printk("failed to allocate request for %s\n", algo);
497 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
498 tcrypt_complete, &result);
501 for (i = 0; i < tcount; i++) {
502 memcpy(cipher_tv, &template[i], tsize);
503 if (!(cipher_tv->np)) {
505 printk("test %u (%d bit key):\n",
506 j, cipher_tv->klen * 8);
508 crypto_ablkcipher_clear_flags(tfm, ~0);
510 crypto_ablkcipher_set_flags(
511 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
512 key = cipher_tv->key;
514 ret = crypto_ablkcipher_setkey(tfm, key,
517 printk("setkey() failed flags=%x\n",
518 crypto_ablkcipher_get_flags(tfm));
520 if (!cipher_tv->fail)
524 sg_init_one(&sg[0], cipher_tv->input,
527 ablkcipher_request_set_crypt(req, sg, sg,
532 crypto_ablkcipher_encrypt(req) :
533 crypto_ablkcipher_decrypt(req);
540 ret = wait_for_completion_interruptible(
542 if (!ret && !((ret = result.err))) {
543 INIT_COMPLETION(result.completion);
548 printk("%s () failed err=%d\n", e, -ret);
552 q = kmap(sg_page(&sg[0])) + sg[0].offset;
553 hexdump(q, cipher_tv->rlen);
556 memcmp(q, cipher_tv->result,
557 cipher_tv->rlen) ? "fail" : "pass");
561 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
562 memset(xbuf, 0, XBUFSIZE);
565 for (i = 0; i < tcount; i++) {
566 memcpy(cipher_tv, &template[i], tsize);
569 printk("test %u (%d bit key):\n",
570 j, cipher_tv->klen * 8);
572 crypto_ablkcipher_clear_flags(tfm, ~0);
574 crypto_ablkcipher_set_flags(
575 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
576 key = cipher_tv->key;
578 ret = crypto_ablkcipher_setkey(tfm, key,
581 printk("setkey() failed flags=%x\n",
582 crypto_ablkcipher_get_flags(tfm));
584 if (!cipher_tv->fail)
589 sg_init_table(sg, cipher_tv->np);
590 for (k = 0; k < cipher_tv->np; k++) {
591 memcpy(&xbuf[IDX[k]],
592 cipher_tv->input + temp,
594 temp += cipher_tv->tap[k];
595 sg_set_buf(&sg[k], &xbuf[IDX[k]],
599 ablkcipher_request_set_crypt(req, sg, sg,
604 crypto_ablkcipher_encrypt(req) :
605 crypto_ablkcipher_decrypt(req);
612 ret = wait_for_completion_interruptible(
614 if (!ret && !((ret = result.err))) {
615 INIT_COMPLETION(result.completion);
620 printk("%s () failed err=%d\n", e, -ret);
625 for (k = 0; k < cipher_tv->np; k++) {
626 printk("page %u\n", k);
627 q = kmap(sg_page(&sg[k])) + sg[k].offset;
628 hexdump(q, cipher_tv->tap[k]);
630 memcmp(q, cipher_tv->result + temp,
631 cipher_tv->tap[k]) ? "fail" :
633 temp += cipher_tv->tap[k];
639 crypto_free_ablkcipher(tfm);
640 ablkcipher_request_free(req);
643 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
646 struct scatterlist sg[1];
647 unsigned long start, end;
651 sg_init_one(sg, p, blen);
653 for (start = jiffies, end = start + sec * HZ, bcount = 0;
654 time_before(jiffies, end); bcount++) {
656 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
658 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
664 printk("%d operations in %d seconds (%ld bytes)\n",
665 bcount, sec, (long)bcount * blen);
669 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
672 struct scatterlist sg[1];
673 unsigned long cycles = 0;
677 sg_init_one(sg, p, blen);
683 for (i = 0; i < 4; i++) {
685 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
687 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
693 /* The real thing. */
694 for (i = 0; i < 8; i++) {
697 start = get_cycles();
699 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
701 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
707 cycles += end - start;
715 printk("1 operation in %lu cycles (%d bytes)\n",
716 (cycles + 4) / 8, blen);
721 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
722 struct cipher_testvec *template,
723 unsigned int tcount, struct cipher_speed *speed)
725 unsigned int ret, i, j, iv_len;
726 unsigned char *key, *p, iv[128];
727 struct crypto_blkcipher *tfm;
728 struct blkcipher_desc desc;
736 printk("\ntesting speed of %s %s\n", algo, e);
738 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
741 printk("failed to load transform for %s: %ld\n", algo,
748 for (i = 0; speed[i].klen != 0; i++) {
749 if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) {
750 printk("template (%u) too big for tvmem (%u)\n",
751 speed[i].blen + speed[i].klen, TVMEMSIZE);
755 printk("test %u (%d bit key, %d byte blocks): ", i,
756 speed[i].klen * 8, speed[i].blen);
758 memset(tvmem, 0xff, speed[i].klen + speed[i].blen);
760 /* set key, plain text and IV */
761 key = (unsigned char *)tvmem;
762 for (j = 0; j < tcount; j++) {
763 if (template[j].klen == speed[i].klen) {
764 key = template[j].key;
768 p = (unsigned char *)tvmem + speed[i].klen;
770 ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
772 printk("setkey() failed flags=%x\n",
773 crypto_blkcipher_get_flags(tfm));
777 iv_len = crypto_blkcipher_ivsize(tfm);
779 memset(&iv, 0xff, iv_len);
780 crypto_blkcipher_set_iv(tfm, iv, iv_len);
784 ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
787 ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
790 printk("%s() failed flags=%x\n", e, desc.flags);
796 crypto_free_blkcipher(tfm);
799 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
802 struct scatterlist sg[1];
803 unsigned long start, end;
807 sg_init_table(sg, 1);
809 for (start = jiffies, end = start + sec * HZ, bcount = 0;
810 time_before(jiffies, end); bcount++) {
811 sg_set_buf(sg, p, blen);
812 ret = crypto_hash_digest(desc, sg, blen, out);
817 printk("%6u opers/sec, %9lu bytes/sec\n",
818 bcount / sec, ((long)bcount * blen) / sec);
823 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
824 int plen, char *out, int sec)
826 struct scatterlist sg[1];
827 unsigned long start, end;
832 return test_hash_jiffies_digest(desc, p, blen, out, sec);
834 sg_init_table(sg, 1);
836 for (start = jiffies, end = start + sec * HZ, bcount = 0;
837 time_before(jiffies, end); bcount++) {
838 ret = crypto_hash_init(desc);
841 for (pcount = 0; pcount < blen; pcount += plen) {
842 sg_set_buf(sg, p + pcount, plen);
843 ret = crypto_hash_update(desc, sg, plen);
847 /* we assume there is enough space in 'out' for the result */
848 ret = crypto_hash_final(desc, out);
853 printk("%6u opers/sec, %9lu bytes/sec\n",
854 bcount / sec, ((long)bcount * blen) / sec);
859 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
862 struct scatterlist sg[1];
863 unsigned long cycles = 0;
867 sg_init_table(sg, 1);
873 for (i = 0; i < 4; i++) {
874 sg_set_buf(sg, p, blen);
875 ret = crypto_hash_digest(desc, sg, blen, out);
880 /* The real thing. */
881 for (i = 0; i < 8; i++) {
884 start = get_cycles();
886 sg_set_buf(sg, p, blen);
887 ret = crypto_hash_digest(desc, sg, blen, out);
893 cycles += end - start;
903 printk("%6lu cycles/operation, %4lu cycles/byte\n",
904 cycles / 8, cycles / (8 * blen));
909 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
912 struct scatterlist sg[1];
913 unsigned long cycles = 0;
918 return test_hash_cycles_digest(desc, p, blen, out);
920 sg_init_table(sg, 1);
926 for (i = 0; i < 4; i++) {
927 ret = crypto_hash_init(desc);
930 for (pcount = 0; pcount < blen; pcount += plen) {
931 sg_set_buf(sg, p + pcount, plen);
932 ret = crypto_hash_update(desc, sg, plen);
936 ret = crypto_hash_final(desc, out);
941 /* The real thing. */
942 for (i = 0; i < 8; i++) {
945 start = get_cycles();
947 ret = crypto_hash_init(desc);
950 for (pcount = 0; pcount < blen; pcount += plen) {
951 sg_set_buf(sg, p + pcount, plen);
952 ret = crypto_hash_update(desc, sg, plen);
956 ret = crypto_hash_final(desc, out);
962 cycles += end - start;
972 printk("%6lu cycles/operation, %4lu cycles/byte\n",
973 cycles / 8, cycles / (8 * blen));
978 static void test_hash_speed(char *algo, unsigned int sec,
979 struct hash_speed *speed)
981 struct crypto_hash *tfm;
982 struct hash_desc desc;
987 printk("\ntesting speed of %s\n", algo);
989 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
992 printk("failed to load transform for %s: %ld\n", algo,
1000 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1001 printk("digestsize(%u) > outputbuffer(%zu)\n",
1002 crypto_hash_digestsize(tfm), sizeof(output));
1006 for (i = 0; speed[i].blen != 0; i++) {
1007 if (speed[i].blen > TVMEMSIZE) {
1008 printk("template (%u) too big for tvmem (%u)\n",
1009 speed[i].blen, TVMEMSIZE);
1013 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1014 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1016 memset(tvmem, 0xff, speed[i].blen);
1019 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1020 speed[i].plen, output, sec);
1022 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1023 speed[i].plen, output);
1026 printk("hashing failed ret=%d\n", ret);
1032 crypto_free_hash(tfm);
1035 static void test_deflate(void)
1038 char result[COMP_BUF_SIZE];
1039 struct crypto_comp *tfm;
1040 struct comp_testvec *tv;
1043 printk("\ntesting deflate compression\n");
1045 tsize = sizeof (deflate_comp_tv_template);
1046 if (tsize > TVMEMSIZE) {
1047 printk("template (%u) too big for tvmem (%u)\n", tsize,
1052 memcpy(tvmem, deflate_comp_tv_template, tsize);
1055 tfm = crypto_alloc_comp("deflate", 0, CRYPTO_ALG_ASYNC);
1057 printk("failed to load transform for deflate\n");
1061 for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) {
1062 int ilen, ret, dlen = COMP_BUF_SIZE;
1064 printk("test %u:\n", i + 1);
1065 memset(result, 0, sizeof (result));
1068 ret = crypto_comp_compress(tfm, tv[i].input,
1069 ilen, result, &dlen);
1071 printk("fail: ret=%d\n", ret);
1074 hexdump(result, dlen);
1075 printk("%s (ratio %d:%d)\n",
1076 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1080 printk("\ntesting deflate decompression\n");
1082 tsize = sizeof (deflate_decomp_tv_template);
1083 if (tsize > TVMEMSIZE) {
1084 printk("template (%u) too big for tvmem (%u)\n", tsize,
1089 memcpy(tvmem, deflate_decomp_tv_template, tsize);
1092 for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) {
1093 int ilen, ret, dlen = COMP_BUF_SIZE;
1095 printk("test %u:\n", i + 1);
1096 memset(result, 0, sizeof (result));
1099 ret = crypto_comp_decompress(tfm, tv[i].input,
1100 ilen, result, &dlen);
1102 printk("fail: ret=%d\n", ret);
1105 hexdump(result, dlen);
1106 printk("%s (ratio %d:%d)\n",
1107 memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
1111 crypto_free_comp(tfm);
1114 static void test_available(void)
1116 char **name = check;
1119 printk("alg %s ", *name);
1120 printk(crypto_has_alg(*name, 0, 0) ?
1121 "found\n" : "not found\n");
1126 static void do_test(void)
1131 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1133 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1136 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1137 DES_ENC_TEST_VECTORS);
1138 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1139 DES_DEC_TEST_VECTORS);
1140 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1141 DES_CBC_ENC_TEST_VECTORS);
1142 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1143 DES_CBC_DEC_TEST_VECTORS);
1146 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1147 DES3_EDE_ENC_TEST_VECTORS);
1148 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1149 DES3_EDE_DEC_TEST_VECTORS);
1151 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1153 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1155 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1158 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1159 BF_ENC_TEST_VECTORS);
1160 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1161 BF_DEC_TEST_VECTORS);
1162 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1163 BF_CBC_ENC_TEST_VECTORS);
1164 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1165 BF_CBC_DEC_TEST_VECTORS);
1168 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1169 TF_ENC_TEST_VECTORS);
1170 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1171 TF_DEC_TEST_VECTORS);
1172 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1173 TF_CBC_ENC_TEST_VECTORS);
1174 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1175 TF_CBC_DEC_TEST_VECTORS);
1178 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1179 SERPENT_ENC_TEST_VECTORS);
1180 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1181 SERPENT_DEC_TEST_VECTORS);
1184 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1185 TNEPRES_ENC_TEST_VECTORS);
1186 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1187 TNEPRES_DEC_TEST_VECTORS);
1190 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1191 AES_ENC_TEST_VECTORS);
1192 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1193 AES_DEC_TEST_VECTORS);
1194 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1195 AES_CBC_ENC_TEST_VECTORS);
1196 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1197 AES_CBC_DEC_TEST_VECTORS);
1198 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1199 AES_LRW_ENC_TEST_VECTORS);
1200 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1201 AES_LRW_DEC_TEST_VECTORS);
1202 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1203 AES_XTS_ENC_TEST_VECTORS);
1204 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1205 AES_XTS_DEC_TEST_VECTORS);
1206 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1207 AES_CTR_ENC_TEST_VECTORS);
1208 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1209 AES_CTR_DEC_TEST_VECTORS);
1210 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1211 AES_GCM_ENC_TEST_VECTORS);
1212 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1213 AES_GCM_DEC_TEST_VECTORS);
1216 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1217 CAST5_ENC_TEST_VECTORS);
1218 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1219 CAST5_DEC_TEST_VECTORS);
1222 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1223 CAST6_ENC_TEST_VECTORS);
1224 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1225 CAST6_DEC_TEST_VECTORS);
1228 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1229 ARC4_ENC_TEST_VECTORS);
1230 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1231 ARC4_DEC_TEST_VECTORS);
1234 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1235 TEA_ENC_TEST_VECTORS);
1236 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1237 TEA_DEC_TEST_VECTORS);
1241 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1242 XTEA_ENC_TEST_VECTORS);
1243 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1244 XTEA_DEC_TEST_VECTORS);
1247 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1248 KHAZAD_ENC_TEST_VECTORS);
1249 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1250 KHAZAD_DEC_TEST_VECTORS);
1253 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1254 ANUBIS_ENC_TEST_VECTORS);
1255 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1256 ANUBIS_DEC_TEST_VECTORS);
1257 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1258 ANUBIS_CBC_ENC_TEST_VECTORS);
1259 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1260 ANUBIS_CBC_ENC_TEST_VECTORS);
1263 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1264 XETA_ENC_TEST_VECTORS);
1265 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1266 XETA_DEC_TEST_VECTORS);
1269 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1270 FCRYPT_ENC_TEST_VECTORS);
1271 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1272 FCRYPT_DEC_TEST_VECTORS);
1275 test_cipher("ecb(camellia)", ENCRYPT,
1276 camellia_enc_tv_template,
1277 CAMELLIA_ENC_TEST_VECTORS);
1278 test_cipher("ecb(camellia)", DECRYPT,
1279 camellia_dec_tv_template,
1280 CAMELLIA_DEC_TEST_VECTORS);
1281 test_cipher("cbc(camellia)", ENCRYPT,
1282 camellia_cbc_enc_tv_template,
1283 CAMELLIA_CBC_ENC_TEST_VECTORS);
1284 test_cipher("cbc(camellia)", DECRYPT,
1285 camellia_cbc_dec_tv_template,
1286 CAMELLIA_CBC_DEC_TEST_VECTORS);
1289 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1290 SEED_ENC_TEST_VECTORS);
1291 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1292 SEED_DEC_TEST_VECTORS);
1294 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1295 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1296 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1297 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1298 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1299 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1300 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1301 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1303 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1304 test_hash("hmac(md5)", hmac_md5_tv_template,
1305 HMAC_MD5_TEST_VECTORS);
1306 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1307 HMAC_SHA1_TEST_VECTORS);
1308 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1309 HMAC_SHA224_TEST_VECTORS);
1310 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1311 HMAC_SHA256_TEST_VECTORS);
1312 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1313 HMAC_SHA384_TEST_VECTORS);
1314 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1315 HMAC_SHA512_TEST_VECTORS);
1317 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1318 XCBC_AES_TEST_VECTORS);
1320 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1324 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1328 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1332 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1333 DES_ENC_TEST_VECTORS);
1334 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1335 DES_DEC_TEST_VECTORS);
1336 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1337 DES_CBC_ENC_TEST_VECTORS);
1338 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1339 DES_CBC_DEC_TEST_VECTORS);
1343 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1344 DES3_EDE_ENC_TEST_VECTORS);
1345 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1346 DES3_EDE_DEC_TEST_VECTORS);
1350 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1354 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1358 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1359 BF_ENC_TEST_VECTORS);
1360 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1361 BF_DEC_TEST_VECTORS);
1362 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1363 BF_CBC_ENC_TEST_VECTORS);
1364 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1365 BF_CBC_DEC_TEST_VECTORS);
1369 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1370 TF_ENC_TEST_VECTORS);
1371 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1372 TF_DEC_TEST_VECTORS);
1373 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1374 TF_CBC_ENC_TEST_VECTORS);
1375 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1376 TF_CBC_DEC_TEST_VECTORS);
1380 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1381 SERPENT_ENC_TEST_VECTORS);
1382 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1383 SERPENT_DEC_TEST_VECTORS);
1387 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1388 AES_ENC_TEST_VECTORS);
1389 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1390 AES_DEC_TEST_VECTORS);
1391 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1392 AES_CBC_ENC_TEST_VECTORS);
1393 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1394 AES_CBC_DEC_TEST_VECTORS);
1395 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1396 AES_LRW_ENC_TEST_VECTORS);
1397 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1398 AES_LRW_DEC_TEST_VECTORS);
1399 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1400 AES_XTS_ENC_TEST_VECTORS);
1401 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1402 AES_XTS_DEC_TEST_VECTORS);
1403 test_cipher("ctr(aes,4,8,4)", ENCRYPT, aes_ctr_enc_tv_template,
1404 AES_CTR_ENC_TEST_VECTORS);
1405 test_cipher("ctr(aes,4,8,4)", DECRYPT, aes_ctr_dec_tv_template,
1406 AES_CTR_DEC_TEST_VECTORS);
1410 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1414 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1422 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1423 CAST5_ENC_TEST_VECTORS);
1424 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1425 CAST5_DEC_TEST_VECTORS);
1429 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1430 CAST6_ENC_TEST_VECTORS);
1431 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1432 CAST6_DEC_TEST_VECTORS);
1436 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1437 ARC4_ENC_TEST_VECTORS);
1438 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1439 ARC4_DEC_TEST_VECTORS);
1443 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1447 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1451 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1452 TEA_ENC_TEST_VECTORS);
1453 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1454 TEA_DEC_TEST_VECTORS);
1458 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1459 XTEA_ENC_TEST_VECTORS);
1460 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1461 XTEA_DEC_TEST_VECTORS);
1465 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1466 KHAZAD_ENC_TEST_VECTORS);
1467 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1468 KHAZAD_DEC_TEST_VECTORS);
1472 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1476 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1480 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1484 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1485 TNEPRES_ENC_TEST_VECTORS);
1486 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1487 TNEPRES_DEC_TEST_VECTORS);
1491 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1492 ANUBIS_ENC_TEST_VECTORS);
1493 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1494 ANUBIS_DEC_TEST_VECTORS);
1495 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1496 ANUBIS_CBC_ENC_TEST_VECTORS);
1497 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1498 ANUBIS_CBC_ENC_TEST_VECTORS);
1502 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1507 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1511 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1515 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1516 XETA_ENC_TEST_VECTORS);
1517 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1518 XETA_DEC_TEST_VECTORS);
1522 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1523 FCRYPT_ENC_TEST_VECTORS);
1524 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1525 FCRYPT_DEC_TEST_VECTORS);
1529 test_cipher("ecb(camellia)", ENCRYPT,
1530 camellia_enc_tv_template,
1531 CAMELLIA_ENC_TEST_VECTORS);
1532 test_cipher("ecb(camellia)", DECRYPT,
1533 camellia_dec_tv_template,
1534 CAMELLIA_DEC_TEST_VECTORS);
1535 test_cipher("cbc(camellia)", ENCRYPT,
1536 camellia_cbc_enc_tv_template,
1537 CAMELLIA_CBC_ENC_TEST_VECTORS);
1538 test_cipher("cbc(camellia)", DECRYPT,
1539 camellia_cbc_dec_tv_template,
1540 CAMELLIA_CBC_DEC_TEST_VECTORS);
1543 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1547 test_cipher("salsa20", ENCRYPT,
1548 salsa20_stream_enc_tv_template,
1549 SALSA20_STREAM_ENC_TEST_VECTORS);
1553 test_hash("hmac(md5)", hmac_md5_tv_template,
1554 HMAC_MD5_TEST_VECTORS);
1558 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1559 HMAC_SHA1_TEST_VECTORS);
1563 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1564 HMAC_SHA256_TEST_VECTORS);
1568 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1569 HMAC_SHA384_TEST_VECTORS);
1573 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1574 HMAC_SHA512_TEST_VECTORS);
1577 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1578 HMAC_SHA224_TEST_VECTORS);
1582 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1583 aes_speed_template);
1584 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1585 aes_speed_template);
1586 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1587 aes_speed_template);
1588 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1589 aes_speed_template);
1590 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1591 aes_lrw_speed_template);
1592 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1593 aes_lrw_speed_template);
1594 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1595 aes_xts_speed_template);
1596 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1597 aes_xts_speed_template);
1601 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1602 des3_ede_enc_tv_template,
1603 DES3_EDE_ENC_TEST_VECTORS,
1604 des3_ede_speed_template);
1605 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1606 des3_ede_dec_tv_template,
1607 DES3_EDE_DEC_TEST_VECTORS,
1608 des3_ede_speed_template);
1609 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1610 des3_ede_enc_tv_template,
1611 DES3_EDE_ENC_TEST_VECTORS,
1612 des3_ede_speed_template);
1613 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1614 des3_ede_dec_tv_template,
1615 DES3_EDE_DEC_TEST_VECTORS,
1616 des3_ede_speed_template);
1620 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1621 twofish_speed_template);
1622 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1623 twofish_speed_template);
1624 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1625 twofish_speed_template);
1626 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1627 twofish_speed_template);
1631 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1632 blowfish_speed_template);
1633 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1634 blowfish_speed_template);
1635 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1636 blowfish_speed_template);
1637 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1638 blowfish_speed_template);
1642 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1643 des_speed_template);
1644 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1645 des_speed_template);
1646 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1647 des_speed_template);
1648 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1649 des_speed_template);
1653 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1654 camellia_speed_template);
1655 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1656 camellia_speed_template);
1657 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1658 camellia_speed_template);
1659 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1660 camellia_speed_template);
1667 test_hash_speed("md4", sec, generic_hash_speed_template);
1668 if (mode > 300 && mode < 400) break;
1671 test_hash_speed("md5", sec, generic_hash_speed_template);
1672 if (mode > 300 && mode < 400) break;
1675 test_hash_speed("sha1", sec, generic_hash_speed_template);
1676 if (mode > 300 && mode < 400) break;
1679 test_hash_speed("sha256", sec, generic_hash_speed_template);
1680 if (mode > 300 && mode < 400) break;
1683 test_hash_speed("sha384", sec, generic_hash_speed_template);
1684 if (mode > 300 && mode < 400) break;
1687 test_hash_speed("sha512", sec, generic_hash_speed_template);
1688 if (mode > 300 && mode < 400) break;
1691 test_hash_speed("wp256", sec, generic_hash_speed_template);
1692 if (mode > 300 && mode < 400) break;
1695 test_hash_speed("wp384", sec, generic_hash_speed_template);
1696 if (mode > 300 && mode < 400) break;
1699 test_hash_speed("wp512", sec, generic_hash_speed_template);
1700 if (mode > 300 && mode < 400) break;
1703 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1704 if (mode > 300 && mode < 400) break;
1707 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1708 if (mode > 300 && mode < 400) break;
1711 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1712 if (mode > 300 && mode < 400) break;
1715 test_hash_speed("sha224", sec, generic_hash_speed_template);
1716 if (mode > 300 && mode < 400) break;
1726 /* useful for debugging */
1727 printk("not testing anything\n");
1732 static int __init init(void)
1736 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1740 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1744 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1750 /* We intentionaly return -EAGAIN to prevent keeping
1751 * the module. It does all its work from init()
1752 * and doesn't offer any runtime functionality
1753 * => we don't need it in the memory, do we?
1768 * If an init function is provided, an exit function must also be provided
1769 * to allow module unload.
1771 static void __exit fini(void) { }
1776 module_param(mode, int, 0);
1777 module_param(sec, uint, 0);
1778 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1779 "(defaults to zero which uses CPU cycles instead)");
1781 MODULE_LICENSE("GPL");
1782 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1783 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");