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", "lzo", NULL
90 static void hexdump(unsigned char *buf, unsigned int len)
92 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
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;
119 printk("\ntesting %s\n", algo);
121 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
123 printk("failed to load transform for %s: %ld\n", algo,
131 for (i = 0; i < tcount; i++) {
132 printk("test %u:\n", i + 1);
133 memset(result, 0, 64);
135 hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
139 memcpy(hash_buff, template[i].plaintext, template[i].psize);
140 sg_init_one(&sg[0], hash_buff, template[i].psize);
142 if (template[i].ksize) {
143 ret = crypto_hash_setkey(tfm, template[i].key,
146 printk("setkey() failed ret=%d\n", ret);
152 ret = crypto_hash_digest(&desc, sg, template[i].psize, result);
154 printk("digest () failed ret=%d\n", ret);
159 hexdump(result, crypto_hash_digestsize(tfm));
161 memcmp(result, template[i].digest,
162 crypto_hash_digestsize(tfm)) ?
167 printk("testing %s across pages\n", algo);
169 /* setup the dummy buffer first */
170 memset(xbuf, 0, XBUFSIZE);
173 for (i = 0; i < tcount; i++) {
174 if (template[i].np) {
176 printk("test %u:\n", j);
177 memset(result, 0, 64);
180 sg_init_table(sg, template[i].np);
181 for (k = 0; k < template[i].np; k++) {
182 memcpy(&xbuf[IDX[k]],
183 template[i].plaintext + temp,
185 temp += template[i].tap[k];
186 sg_set_buf(&sg[k], &xbuf[IDX[k]],
190 if (template[i].ksize) {
191 ret = crypto_hash_setkey(tfm, template[i].key,
195 printk("setkey() failed ret=%d\n", ret);
200 ret = crypto_hash_digest(&desc, sg, template[i].psize,
203 printk("digest () failed ret=%d\n", ret);
207 hexdump(result, crypto_hash_digestsize(tfm));
209 memcmp(result, template[i].digest,
210 crypto_hash_digestsize(tfm)) ?
216 crypto_free_hash(tfm);
219 static void test_aead(char *algo, int enc, struct aead_testvec *template,
222 unsigned int ret, i, j, k, temp;
224 struct crypto_aead *tfm;
226 struct aead_request *req;
227 struct scatterlist sg[8];
228 struct scatterlist asg[8];
230 struct tcrypt_result result;
231 unsigned int authsize;
241 printk(KERN_INFO "\ntesting %s %s\n", algo, e);
243 init_completion(&result.completion);
245 tfm = crypto_alloc_aead(algo, 0, 0);
248 printk(KERN_INFO "failed to load transform for %s: %ld\n",
253 req = aead_request_alloc(tfm, GFP_KERNEL);
255 printk(KERN_INFO "failed to allocate request for %s\n", algo);
259 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
260 tcrypt_complete, &result);
262 for (i = 0, j = 0; i < tcount; i++) {
263 if (!template[i].np) {
264 printk(KERN_INFO "test %u (%d bit key):\n",
265 ++j, template[i].klen * 8);
267 /* some tepmplates have no input data but they will
270 input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
274 assoc = kzalloc(template[i].alen, GFP_KERNEL);
280 memcpy(input, template[i].input, template[i].ilen);
281 memcpy(assoc, template[i].assoc, template[i].alen);
283 memcpy(iv, template[i].iv, MAX_IVLEN);
285 memset(iv, 0, MAX_IVLEN);
287 crypto_aead_clear_flags(tfm, ~0);
289 crypto_aead_set_flags(
290 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
293 key = template[i].key;
295 key = kzalloc(template[i].klen, GFP_KERNEL);
297 ret = crypto_aead_setkey(tfm, key,
300 printk(KERN_INFO "setkey() failed flags=%x\n",
301 crypto_aead_get_flags(tfm));
303 if (!template[i].fail)
307 authsize = abs(template[i].rlen - template[i].ilen);
308 ret = crypto_aead_setauthsize(tfm, authsize);
311 "failed to set authsize = %u\n",
316 sg_init_one(&sg[0], input,
317 template[i].ilen + (enc ? authsize : 0));
319 sg_init_one(&asg[0], assoc, template[i].alen);
321 aead_request_set_crypt(req, sg, sg,
322 template[i].ilen, iv);
324 aead_request_set_assoc(req, asg, template[i].alen);
327 crypto_aead_encrypt(req) :
328 crypto_aead_decrypt(req);
335 ret = wait_for_completion_interruptible(
337 if (!ret && !(ret = result.err)) {
338 INIT_COMPLETION(result.completion);
343 printk(KERN_INFO "%s () failed err=%d\n",
348 q = kmap(sg_page(&sg[0])) + sg[0].offset;
349 hexdump(q, template[i].rlen);
351 printk(KERN_INFO "enc/dec: %s\n",
352 memcmp(q, template[i].result,
353 template[i].rlen) ? "fail" : "pass");
354 kunmap(sg_page(&sg[0]));
356 if (!template[i].key)
363 printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
364 memset(xbuf, 0, XBUFSIZE);
365 memset(axbuf, 0, XBUFSIZE);
367 for (i = 0, j = 0; i < tcount; i++) {
368 if (template[i].np) {
369 printk(KERN_INFO "test %u (%d bit key):\n",
370 ++j, template[i].klen * 8);
373 memcpy(iv, template[i].iv, MAX_IVLEN);
375 memset(iv, 0, MAX_IVLEN);
377 crypto_aead_clear_flags(tfm, ~0);
379 crypto_aead_set_flags(
380 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
381 key = template[i].key;
383 ret = crypto_aead_setkey(tfm, key, template[i].klen);
385 printk(KERN_INFO "setkey() failed flags=%x\n",
386 crypto_aead_get_flags(tfm));
388 if (!template[i].fail)
392 sg_init_table(sg, template[i].np);
393 for (k = 0, temp = 0; k < template[i].np; k++) {
394 memcpy(&xbuf[IDX[k]],
395 template[i].input + temp,
397 temp += template[i].tap[k];
398 sg_set_buf(&sg[k], &xbuf[IDX[k]],
402 authsize = abs(template[i].rlen - template[i].ilen);
403 ret = crypto_aead_setauthsize(tfm, authsize);
406 "failed to set authsize = %u\n",
412 sg[k - 1].length += authsize;
414 sg_init_table(asg, template[i].anp);
415 for (k = 0, temp = 0; k < template[i].anp; k++) {
416 memcpy(&axbuf[IDX[k]],
417 template[i].assoc + temp,
418 template[i].atap[k]);
419 temp += template[i].atap[k];
420 sg_set_buf(&asg[k], &axbuf[IDX[k]],
421 template[i].atap[k]);
424 aead_request_set_crypt(req, sg, sg,
428 aead_request_set_assoc(req, asg, template[i].alen);
431 crypto_aead_encrypt(req) :
432 crypto_aead_decrypt(req);
439 ret = wait_for_completion_interruptible(
441 if (!ret && !(ret = result.err)) {
442 INIT_COMPLETION(result.completion);
447 printk(KERN_INFO "%s () failed err=%d\n",
452 for (k = 0, temp = 0; k < template[i].np; k++) {
453 printk(KERN_INFO "page %u\n", k);
454 q = kmap(sg_page(&sg[k])) + sg[k].offset;
455 hexdump(q, template[i].tap[k]);
456 printk(KERN_INFO "%s\n",
457 memcmp(q, template[i].result + temp,
459 (k < template[i].np - 1 || enc ?
463 temp += template[i].tap[k];
464 kunmap(sg_page(&sg[k]));
470 crypto_free_aead(tfm);
471 aead_request_free(req);
474 static void test_cipher(char *algo, int enc,
475 struct cipher_testvec *template, unsigned int tcount)
477 unsigned int ret, i, j, k, temp;
479 struct crypto_ablkcipher *tfm;
480 struct ablkcipher_request *req;
481 struct scatterlist sg[8];
483 struct tcrypt_result result;
492 printk("\ntesting %s %s\n", algo, e);
494 init_completion(&result.completion);
495 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
498 printk("failed to load transform for %s: %ld\n", algo,
503 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
505 printk("failed to allocate request for %s\n", algo);
509 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
510 tcrypt_complete, &result);
513 for (i = 0; i < tcount; i++) {
515 data = kzalloc(template[i].ilen, GFP_KERNEL);
519 memcpy(data, template[i].input, template[i].ilen);
521 memcpy(iv, template[i].iv, MAX_IVLEN);
523 memset(iv, 0, MAX_IVLEN);
525 if (!(template[i].np)) {
527 printk("test %u (%d bit key):\n",
528 j, template[i].klen * 8);
530 crypto_ablkcipher_clear_flags(tfm, ~0);
532 crypto_ablkcipher_set_flags(
533 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
535 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
538 printk("setkey() failed flags=%x\n",
539 crypto_ablkcipher_get_flags(tfm));
541 if (!template[i].fail) {
547 sg_init_one(&sg[0], data, template[i].ilen);
549 ablkcipher_request_set_crypt(req, sg, sg,
550 template[i].ilen, iv);
552 crypto_ablkcipher_encrypt(req) :
553 crypto_ablkcipher_decrypt(req);
560 ret = wait_for_completion_interruptible(
562 if (!ret && !((ret = result.err))) {
563 INIT_COMPLETION(result.completion);
568 printk("%s () failed err=%d\n", e, -ret);
573 q = kmap(sg_page(&sg[0])) + sg[0].offset;
574 hexdump(q, template[i].rlen);
577 memcmp(q, template[i].result,
578 template[i].rlen) ? "fail" : "pass");
579 kunmap(sg_page(&sg[0]));
584 printk("\ntesting %s %s across pages (chunking)\n", algo, e);
585 memset(xbuf, 0, XBUFSIZE);
588 for (i = 0; i < tcount; i++) {
590 data = kzalloc(template[i].ilen, GFP_KERNEL);
594 memcpy(data, template[i].input, template[i].ilen);
597 memcpy(iv, template[i].iv, MAX_IVLEN);
599 memset(iv, 0, MAX_IVLEN);
601 if (template[i].np) {
603 printk("test %u (%d bit key):\n",
604 j, template[i].klen * 8);
606 crypto_ablkcipher_clear_flags(tfm, ~0);
608 crypto_ablkcipher_set_flags(
609 tfm, CRYPTO_TFM_REQ_WEAK_KEY);
611 ret = crypto_ablkcipher_setkey(tfm, template[i].key,
614 printk("setkey() failed flags=%x\n",
615 crypto_ablkcipher_get_flags(tfm));
617 if (!template[i].fail) {
624 sg_init_table(sg, template[i].np);
625 for (k = 0; k < template[i].np; k++) {
626 memcpy(&xbuf[IDX[k]],
627 template[i].input + temp,
629 temp += template[i].tap[k];
630 sg_set_buf(&sg[k], &xbuf[IDX[k]],
634 ablkcipher_request_set_crypt(req, sg, sg,
635 template[i].ilen, iv);
638 crypto_ablkcipher_encrypt(req) :
639 crypto_ablkcipher_decrypt(req);
646 ret = wait_for_completion_interruptible(
648 if (!ret && !((ret = result.err))) {
649 INIT_COMPLETION(result.completion);
654 printk("%s () failed err=%d\n", e, -ret);
659 for (k = 0; k < template[i].np; k++) {
660 printk("page %u\n", k);
661 q = kmap(sg_page(&sg[k])) + sg[k].offset;
662 hexdump(q, template[i].tap[k]);
664 memcmp(q, template[i].result + temp,
665 template[i].tap[k]) ? "fail" :
667 temp += template[i].tap[k];
668 kunmap(sg_page(&sg[k]));
673 crypto_free_ablkcipher(tfm);
674 ablkcipher_request_free(req);
677 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
680 struct scatterlist sg[1];
681 unsigned long start, end;
685 sg_init_one(sg, p, blen);
687 for (start = jiffies, end = start + sec * HZ, bcount = 0;
688 time_before(jiffies, end); bcount++) {
690 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
692 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
698 printk("%d operations in %d seconds (%ld bytes)\n",
699 bcount, sec, (long)bcount * blen);
703 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
706 struct scatterlist sg[1];
707 unsigned long cycles = 0;
711 sg_init_one(sg, p, blen);
717 for (i = 0; i < 4; i++) {
719 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
721 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
727 /* The real thing. */
728 for (i = 0; i < 8; i++) {
731 start = get_cycles();
733 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
735 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
741 cycles += end - start;
749 printk("1 operation in %lu cycles (%d bytes)\n",
750 (cycles + 4) / 8, blen);
755 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
757 static void test_cipher_speed(char *algo, int enc, unsigned int sec,
758 struct cipher_testvec *template,
759 unsigned int tcount, u8 *keysize)
761 unsigned int ret, i, j, iv_len;
762 unsigned char *key, *p, iv[128];
763 struct crypto_blkcipher *tfm;
764 struct blkcipher_desc desc;
773 printk("\ntesting speed of %s %s\n", algo, e);
775 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
778 printk("failed to load transform for %s: %ld\n", algo,
788 b_size = block_sizes;
791 if ((*keysize + *b_size) > TVMEMSIZE) {
792 printk("template (%u) too big for tvmem (%u)\n",
793 *keysize + *b_size, TVMEMSIZE);
797 printk("test %u (%d bit key, %d byte blocks): ", i,
798 *keysize * 8, *b_size);
800 memset(tvmem, 0xff, *keysize + *b_size);
802 /* set key, plain text and IV */
803 key = (unsigned char *)tvmem;
804 for (j = 0; j < tcount; j++) {
805 if (template[j].klen == *keysize) {
806 key = template[j].key;
810 p = (unsigned char *)tvmem + *keysize;
812 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
814 printk("setkey() failed flags=%x\n",
815 crypto_blkcipher_get_flags(tfm));
819 iv_len = crypto_blkcipher_ivsize(tfm);
821 memset(&iv, 0xff, iv_len);
822 crypto_blkcipher_set_iv(tfm, iv, iv_len);
826 ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
828 ret = test_cipher_cycles(&desc, enc, p, *b_size);
831 printk("%s() failed flags=%x\n", e, desc.flags);
841 crypto_free_blkcipher(tfm);
844 static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
847 struct scatterlist sg[1];
848 unsigned long start, end;
852 sg_init_table(sg, 1);
854 for (start = jiffies, end = start + sec * HZ, bcount = 0;
855 time_before(jiffies, end); bcount++) {
856 sg_set_buf(sg, p, blen);
857 ret = crypto_hash_digest(desc, sg, blen, out);
862 printk("%6u opers/sec, %9lu bytes/sec\n",
863 bcount / sec, ((long)bcount * blen) / sec);
868 static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
869 int plen, char *out, int sec)
871 struct scatterlist sg[1];
872 unsigned long start, end;
877 return test_hash_jiffies_digest(desc, p, blen, out, sec);
879 sg_init_table(sg, 1);
881 for (start = jiffies, end = start + sec * HZ, bcount = 0;
882 time_before(jiffies, end); bcount++) {
883 ret = crypto_hash_init(desc);
886 for (pcount = 0; pcount < blen; pcount += plen) {
887 sg_set_buf(sg, p + pcount, plen);
888 ret = crypto_hash_update(desc, sg, plen);
892 /* we assume there is enough space in 'out' for the result */
893 ret = crypto_hash_final(desc, out);
898 printk("%6u opers/sec, %9lu bytes/sec\n",
899 bcount / sec, ((long)bcount * blen) / sec);
904 static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
907 struct scatterlist sg[1];
908 unsigned long cycles = 0;
912 sg_init_table(sg, 1);
918 for (i = 0; i < 4; i++) {
919 sg_set_buf(sg, p, blen);
920 ret = crypto_hash_digest(desc, sg, blen, out);
925 /* The real thing. */
926 for (i = 0; i < 8; i++) {
929 start = get_cycles();
931 sg_set_buf(sg, p, blen);
932 ret = crypto_hash_digest(desc, sg, blen, out);
938 cycles += end - start;
948 printk("%6lu cycles/operation, %4lu cycles/byte\n",
949 cycles / 8, cycles / (8 * blen));
954 static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
957 struct scatterlist sg[1];
958 unsigned long cycles = 0;
963 return test_hash_cycles_digest(desc, p, blen, out);
965 sg_init_table(sg, 1);
971 for (i = 0; i < 4; i++) {
972 ret = crypto_hash_init(desc);
975 for (pcount = 0; pcount < blen; pcount += plen) {
976 sg_set_buf(sg, p + pcount, plen);
977 ret = crypto_hash_update(desc, sg, plen);
981 ret = crypto_hash_final(desc, out);
986 /* The real thing. */
987 for (i = 0; i < 8; i++) {
990 start = get_cycles();
992 ret = crypto_hash_init(desc);
995 for (pcount = 0; pcount < blen; pcount += plen) {
996 sg_set_buf(sg, p + pcount, plen);
997 ret = crypto_hash_update(desc, sg, plen);
1001 ret = crypto_hash_final(desc, out);
1007 cycles += end - start;
1017 printk("%6lu cycles/operation, %4lu cycles/byte\n",
1018 cycles / 8, cycles / (8 * blen));
1023 static void test_hash_speed(char *algo, unsigned int sec,
1024 struct hash_speed *speed)
1026 struct crypto_hash *tfm;
1027 struct hash_desc desc;
1032 printk("\ntesting speed of %s\n", algo);
1034 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
1037 printk("failed to load transform for %s: %ld\n", algo,
1045 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1046 printk("digestsize(%u) > outputbuffer(%zu)\n",
1047 crypto_hash_digestsize(tfm), sizeof(output));
1051 for (i = 0; speed[i].blen != 0; i++) {
1052 if (speed[i].blen > TVMEMSIZE) {
1053 printk("template (%u) too big for tvmem (%u)\n",
1054 speed[i].blen, TVMEMSIZE);
1058 printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ",
1059 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1061 memset(tvmem, 0xff, speed[i].blen);
1064 ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
1065 speed[i].plen, output, sec);
1067 ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
1068 speed[i].plen, output);
1071 printk("hashing failed ret=%d\n", ret);
1077 crypto_free_hash(tfm);
1080 static void test_comp(char *algo, struct comp_testvec *ctemplate,
1081 struct comp_testvec *dtemplate, int ctcount, int dtcount)
1084 char result[COMP_BUF_SIZE];
1085 struct crypto_comp *tfm;
1088 printk("\ntesting %s compression\n", algo);
1090 tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1092 printk("failed to load transform for %s\n", algo);
1096 for (i = 0; i < ctcount; i++) {
1097 int ilen, ret, dlen = COMP_BUF_SIZE;
1099 printk("test %u:\n", i + 1);
1100 memset(result, 0, sizeof (result));
1102 ilen = ctemplate[i].inlen;
1103 ret = crypto_comp_compress(tfm, ctemplate[i].input,
1104 ilen, result, &dlen);
1106 printk("fail: ret=%d\n", ret);
1109 hexdump(result, dlen);
1110 printk("%s (ratio %d:%d)\n",
1111 memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
1115 printk("\ntesting %s decompression\n", algo);
1117 tsize = sizeof(struct comp_testvec);
1119 if (tsize > TVMEMSIZE) {
1120 printk("template (%u) too big for tvmem (%u)\n", tsize,
1125 for (i = 0; i < dtcount; i++) {
1126 int ilen, ret, dlen = COMP_BUF_SIZE;
1128 printk("test %u:\n", i + 1);
1129 memset(result, 0, sizeof (result));
1131 ilen = dtemplate[i].inlen;
1132 ret = crypto_comp_decompress(tfm, dtemplate[i].input,
1133 ilen, result, &dlen);
1135 printk("fail: ret=%d\n", ret);
1138 hexdump(result, dlen);
1139 printk("%s (ratio %d:%d)\n",
1140 memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
1144 crypto_free_comp(tfm);
1147 static void test_available(void)
1149 char **name = check;
1152 printk("alg %s ", *name);
1153 printk(crypto_has_alg(*name, 0, 0) ?
1154 "found\n" : "not found\n");
1159 static void do_test(void)
1164 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1166 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1169 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1170 DES_ENC_TEST_VECTORS);
1171 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1172 DES_DEC_TEST_VECTORS);
1173 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1174 DES_CBC_ENC_TEST_VECTORS);
1175 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1176 DES_CBC_DEC_TEST_VECTORS);
1179 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1180 DES3_EDE_ENC_TEST_VECTORS);
1181 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1182 DES3_EDE_DEC_TEST_VECTORS);
1184 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1186 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1188 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1191 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1192 BF_ENC_TEST_VECTORS);
1193 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1194 BF_DEC_TEST_VECTORS);
1195 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1196 BF_CBC_ENC_TEST_VECTORS);
1197 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1198 BF_CBC_DEC_TEST_VECTORS);
1201 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1202 TF_ENC_TEST_VECTORS);
1203 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1204 TF_DEC_TEST_VECTORS);
1205 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1206 TF_CBC_ENC_TEST_VECTORS);
1207 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1208 TF_CBC_DEC_TEST_VECTORS);
1211 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1212 SERPENT_ENC_TEST_VECTORS);
1213 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1214 SERPENT_DEC_TEST_VECTORS);
1217 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1218 TNEPRES_ENC_TEST_VECTORS);
1219 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1220 TNEPRES_DEC_TEST_VECTORS);
1223 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1224 AES_ENC_TEST_VECTORS);
1225 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1226 AES_DEC_TEST_VECTORS);
1227 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1228 AES_CBC_ENC_TEST_VECTORS);
1229 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1230 AES_CBC_DEC_TEST_VECTORS);
1231 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1232 AES_LRW_ENC_TEST_VECTORS);
1233 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1234 AES_LRW_DEC_TEST_VECTORS);
1235 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1236 AES_XTS_ENC_TEST_VECTORS);
1237 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1238 AES_XTS_DEC_TEST_VECTORS);
1239 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1240 AES_CTR_ENC_TEST_VECTORS);
1241 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1242 AES_CTR_DEC_TEST_VECTORS);
1243 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1244 AES_GCM_ENC_TEST_VECTORS);
1245 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1246 AES_GCM_DEC_TEST_VECTORS);
1247 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1248 AES_CCM_ENC_TEST_VECTORS);
1249 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1250 AES_CCM_DEC_TEST_VECTORS);
1253 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1254 CAST5_ENC_TEST_VECTORS);
1255 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1256 CAST5_DEC_TEST_VECTORS);
1259 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1260 CAST6_ENC_TEST_VECTORS);
1261 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1262 CAST6_DEC_TEST_VECTORS);
1265 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1266 ARC4_ENC_TEST_VECTORS);
1267 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1268 ARC4_DEC_TEST_VECTORS);
1271 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1272 TEA_ENC_TEST_VECTORS);
1273 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1274 TEA_DEC_TEST_VECTORS);
1278 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1279 XTEA_ENC_TEST_VECTORS);
1280 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1281 XTEA_DEC_TEST_VECTORS);
1284 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1285 KHAZAD_ENC_TEST_VECTORS);
1286 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1287 KHAZAD_DEC_TEST_VECTORS);
1290 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1291 ANUBIS_ENC_TEST_VECTORS);
1292 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1293 ANUBIS_DEC_TEST_VECTORS);
1294 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1295 ANUBIS_CBC_ENC_TEST_VECTORS);
1296 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1297 ANUBIS_CBC_ENC_TEST_VECTORS);
1300 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1301 XETA_ENC_TEST_VECTORS);
1302 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1303 XETA_DEC_TEST_VECTORS);
1306 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1307 FCRYPT_ENC_TEST_VECTORS);
1308 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1309 FCRYPT_DEC_TEST_VECTORS);
1312 test_cipher("ecb(camellia)", ENCRYPT,
1313 camellia_enc_tv_template,
1314 CAMELLIA_ENC_TEST_VECTORS);
1315 test_cipher("ecb(camellia)", DECRYPT,
1316 camellia_dec_tv_template,
1317 CAMELLIA_DEC_TEST_VECTORS);
1318 test_cipher("cbc(camellia)", ENCRYPT,
1319 camellia_cbc_enc_tv_template,
1320 CAMELLIA_CBC_ENC_TEST_VECTORS);
1321 test_cipher("cbc(camellia)", DECRYPT,
1322 camellia_cbc_dec_tv_template,
1323 CAMELLIA_CBC_DEC_TEST_VECTORS);
1326 test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
1327 SEED_ENC_TEST_VECTORS);
1328 test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
1329 SEED_DEC_TEST_VECTORS);
1331 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1332 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1333 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1334 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1335 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1336 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1337 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1338 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1339 test_comp("deflate", deflate_comp_tv_template,
1340 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1341 DEFLATE_DECOMP_TEST_VECTORS);
1342 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1343 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1344 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1345 test_hash("hmac(md5)", hmac_md5_tv_template,
1346 HMAC_MD5_TEST_VECTORS);
1347 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1348 HMAC_SHA1_TEST_VECTORS);
1349 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1350 HMAC_SHA224_TEST_VECTORS);
1351 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1352 HMAC_SHA256_TEST_VECTORS);
1353 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1354 HMAC_SHA384_TEST_VECTORS);
1355 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1356 HMAC_SHA512_TEST_VECTORS);
1358 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1359 XCBC_AES_TEST_VECTORS);
1361 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1365 test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1369 test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1373 test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
1374 DES_ENC_TEST_VECTORS);
1375 test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
1376 DES_DEC_TEST_VECTORS);
1377 test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
1378 DES_CBC_ENC_TEST_VECTORS);
1379 test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
1380 DES_CBC_DEC_TEST_VECTORS);
1384 test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
1385 DES3_EDE_ENC_TEST_VECTORS);
1386 test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
1387 DES3_EDE_DEC_TEST_VECTORS);
1391 test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1395 test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1399 test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
1400 BF_ENC_TEST_VECTORS);
1401 test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
1402 BF_DEC_TEST_VECTORS);
1403 test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
1404 BF_CBC_ENC_TEST_VECTORS);
1405 test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
1406 BF_CBC_DEC_TEST_VECTORS);
1410 test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
1411 TF_ENC_TEST_VECTORS);
1412 test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
1413 TF_DEC_TEST_VECTORS);
1414 test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
1415 TF_CBC_ENC_TEST_VECTORS);
1416 test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
1417 TF_CBC_DEC_TEST_VECTORS);
1421 test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
1422 SERPENT_ENC_TEST_VECTORS);
1423 test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
1424 SERPENT_DEC_TEST_VECTORS);
1428 test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
1429 AES_ENC_TEST_VECTORS);
1430 test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
1431 AES_DEC_TEST_VECTORS);
1432 test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
1433 AES_CBC_ENC_TEST_VECTORS);
1434 test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
1435 AES_CBC_DEC_TEST_VECTORS);
1436 test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
1437 AES_LRW_ENC_TEST_VECTORS);
1438 test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
1439 AES_LRW_DEC_TEST_VECTORS);
1440 test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
1441 AES_XTS_ENC_TEST_VECTORS);
1442 test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
1443 AES_XTS_DEC_TEST_VECTORS);
1444 test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1445 AES_CTR_ENC_TEST_VECTORS);
1446 test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1447 AES_CTR_DEC_TEST_VECTORS);
1451 test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
1455 test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
1459 test_comp("deflate", deflate_comp_tv_template,
1460 deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
1461 DEFLATE_DECOMP_TEST_VECTORS);
1465 test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
1466 CAST5_ENC_TEST_VECTORS);
1467 test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
1468 CAST5_DEC_TEST_VECTORS);
1472 test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
1473 CAST6_ENC_TEST_VECTORS);
1474 test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
1475 CAST6_DEC_TEST_VECTORS);
1479 test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
1480 ARC4_ENC_TEST_VECTORS);
1481 test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
1482 ARC4_DEC_TEST_VECTORS);
1486 test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
1490 test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1494 test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
1495 TEA_ENC_TEST_VECTORS);
1496 test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
1497 TEA_DEC_TEST_VECTORS);
1501 test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
1502 XTEA_ENC_TEST_VECTORS);
1503 test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
1504 XTEA_DEC_TEST_VECTORS);
1508 test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
1509 KHAZAD_ENC_TEST_VECTORS);
1510 test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
1511 KHAZAD_DEC_TEST_VECTORS);
1515 test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
1519 test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
1523 test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
1527 test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
1528 TNEPRES_ENC_TEST_VECTORS);
1529 test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
1530 TNEPRES_DEC_TEST_VECTORS);
1534 test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
1535 ANUBIS_ENC_TEST_VECTORS);
1536 test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
1537 ANUBIS_DEC_TEST_VECTORS);
1538 test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
1539 ANUBIS_CBC_ENC_TEST_VECTORS);
1540 test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
1541 ANUBIS_CBC_ENC_TEST_VECTORS);
1545 test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
1550 test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
1554 test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1558 test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
1559 XETA_ENC_TEST_VECTORS);
1560 test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
1561 XETA_DEC_TEST_VECTORS);
1565 test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
1566 FCRYPT_ENC_TEST_VECTORS);
1567 test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
1568 FCRYPT_DEC_TEST_VECTORS);
1572 test_cipher("ecb(camellia)", ENCRYPT,
1573 camellia_enc_tv_template,
1574 CAMELLIA_ENC_TEST_VECTORS);
1575 test_cipher("ecb(camellia)", DECRYPT,
1576 camellia_dec_tv_template,
1577 CAMELLIA_DEC_TEST_VECTORS);
1578 test_cipher("cbc(camellia)", ENCRYPT,
1579 camellia_cbc_enc_tv_template,
1580 CAMELLIA_CBC_ENC_TEST_VECTORS);
1581 test_cipher("cbc(camellia)", DECRYPT,
1582 camellia_cbc_dec_tv_template,
1583 CAMELLIA_CBC_DEC_TEST_VECTORS);
1586 test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
1590 test_cipher("salsa20", ENCRYPT,
1591 salsa20_stream_enc_tv_template,
1592 SALSA20_STREAM_ENC_TEST_VECTORS);
1596 test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
1597 AES_GCM_ENC_TEST_VECTORS);
1598 test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
1599 AES_GCM_DEC_TEST_VECTORS);
1603 test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
1604 LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1608 test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
1609 AES_CCM_ENC_TEST_VECTORS);
1610 test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
1611 AES_CCM_DEC_TEST_VECTORS);
1615 test_hash("hmac(md5)", hmac_md5_tv_template,
1616 HMAC_MD5_TEST_VECTORS);
1620 test_hash("hmac(sha1)", hmac_sha1_tv_template,
1621 HMAC_SHA1_TEST_VECTORS);
1625 test_hash("hmac(sha256)", hmac_sha256_tv_template,
1626 HMAC_SHA256_TEST_VECTORS);
1630 test_hash("hmac(sha384)", hmac_sha384_tv_template,
1631 HMAC_SHA384_TEST_VECTORS);
1635 test_hash("hmac(sha512)", hmac_sha512_tv_template,
1636 HMAC_SHA512_TEST_VECTORS);
1640 test_hash("hmac(sha224)", hmac_sha224_tv_template,
1641 HMAC_SHA224_TEST_VECTORS);
1645 test_hash("xcbc(aes)", aes_xcbc128_tv_template,
1646 XCBC_AES_TEST_VECTORS);
1650 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1651 speed_template_16_24_32);
1652 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1653 speed_template_16_24_32);
1654 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1655 speed_template_16_24_32);
1656 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1657 speed_template_16_24_32);
1658 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1659 speed_template_32_40_48);
1660 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1661 speed_template_32_40_48);
1662 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1663 speed_template_32_48_64);
1664 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1665 speed_template_32_48_64);
1669 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1670 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1672 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1673 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1675 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1676 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1678 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1679 des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
1684 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1685 speed_template_16_24_32);
1686 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1687 speed_template_16_24_32);
1688 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1689 speed_template_16_24_32);
1690 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1691 speed_template_16_24_32);
1695 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1696 speed_template_8_32);
1697 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1698 speed_template_8_32);
1699 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1700 speed_template_8_32);
1701 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1702 speed_template_8_32);
1706 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1708 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1710 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1712 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1717 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1718 speed_template_16_24_32);
1719 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1720 speed_template_16_24_32);
1721 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1722 speed_template_16_24_32);
1723 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1724 speed_template_16_24_32);
1728 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1729 speed_template_16_32);
1736 test_hash_speed("md4", sec, generic_hash_speed_template);
1737 if (mode > 300 && mode < 400) break;
1740 test_hash_speed("md5", sec, generic_hash_speed_template);
1741 if (mode > 300 && mode < 400) break;
1744 test_hash_speed("sha1", sec, generic_hash_speed_template);
1745 if (mode > 300 && mode < 400) break;
1748 test_hash_speed("sha256", sec, generic_hash_speed_template);
1749 if (mode > 300 && mode < 400) break;
1752 test_hash_speed("sha384", sec, generic_hash_speed_template);
1753 if (mode > 300 && mode < 400) break;
1756 test_hash_speed("sha512", sec, generic_hash_speed_template);
1757 if (mode > 300 && mode < 400) break;
1760 test_hash_speed("wp256", sec, generic_hash_speed_template);
1761 if (mode > 300 && mode < 400) break;
1764 test_hash_speed("wp384", sec, generic_hash_speed_template);
1765 if (mode > 300 && mode < 400) break;
1768 test_hash_speed("wp512", sec, generic_hash_speed_template);
1769 if (mode > 300 && mode < 400) break;
1772 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1773 if (mode > 300 && mode < 400) break;
1776 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1777 if (mode > 300 && mode < 400) break;
1780 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1781 if (mode > 300 && mode < 400) break;
1784 test_hash_speed("sha224", sec, generic_hash_speed_template);
1785 if (mode > 300 && mode < 400) break;
1795 /* useful for debugging */
1796 printk("not testing anything\n");
1801 static int __init init(void)
1805 tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
1809 xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1813 axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1819 /* We intentionaly return -EAGAIN to prevent keeping
1820 * the module. It does all its work from init()
1821 * and doesn't offer any runtime functionality
1822 * => we don't need it in the memory, do we?
1837 * If an init function is provided, an exit function must also be provided
1838 * to allow module unload.
1840 static void __exit fini(void) { }
1845 module_param(mode, int, 0);
1846 module_param(sec, uint, 0);
1847 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1848 "(defaults to zero which uses CPU cycles instead)");
1850 MODULE_LICENSE("GPL");
1851 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1852 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");