e1000e: cleanup unnecessary line wrap
[linux/fpc-iii.git] / crypto / tcrypt.c
blob7ae2130e1b002890900907fc415b1eb51094e8a7
1 /*
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 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
18 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
20 * Software Foundation; either version 2 of the License, or (at your option)
21 * any later version.
25 #include <crypto/hash.h>
26 #include <linux/err.h>
27 #include <linux/init.h>
28 #include <linux/gfp.h>
29 #include <linux/module.h>
30 #include <linux/scatterlist.h>
31 #include <linux/string.h>
32 #include <linux/moduleparam.h>
33 #include <linux/jiffies.h>
34 #include <linux/timex.h>
35 #include <linux/interrupt.h>
36 #include "tcrypt.h"
37 #include "internal.h"
40 * Need slab memory for testing (size in number of pages).
42 #define TVMEMSIZE 4
45 * Used by test_cipher_speed()
47 #define ENCRYPT 1
48 #define DECRYPT 0
51 * Used by test_cipher_speed()
53 static unsigned int sec;
55 static char *alg = NULL;
56 static u32 type;
57 static u32 mask;
58 static int mode;
59 static char *tvmem[TVMEMSIZE];
61 static char *check[] = {
62 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
63 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
64 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
65 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
66 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
67 "lzo", "cts", "zlib", NULL
70 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
71 struct scatterlist *sg, int blen, int sec)
73 unsigned long start, end;
74 int bcount;
75 int ret;
77 for (start = jiffies, end = start + sec * HZ, bcount = 0;
78 time_before(jiffies, end); bcount++) {
79 if (enc)
80 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
81 else
82 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
84 if (ret)
85 return ret;
88 printk("%d operations in %d seconds (%ld bytes)\n",
89 bcount, sec, (long)bcount * blen);
90 return 0;
93 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
94 struct scatterlist *sg, int blen)
96 unsigned long cycles = 0;
97 int ret = 0;
98 int i;
100 local_irq_disable();
102 /* Warm-up run. */
103 for (i = 0; i < 4; i++) {
104 if (enc)
105 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
106 else
107 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
109 if (ret)
110 goto out;
113 /* The real thing. */
114 for (i = 0; i < 8; i++) {
115 cycles_t start, end;
117 start = get_cycles();
118 if (enc)
119 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
120 else
121 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
122 end = get_cycles();
124 if (ret)
125 goto out;
127 cycles += end - start;
130 out:
131 local_irq_enable();
133 if (ret == 0)
134 printk("1 operation in %lu cycles (%d bytes)\n",
135 (cycles + 4) / 8, blen);
137 return ret;
140 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
142 static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
143 struct cipher_speed_template *template,
144 unsigned int tcount, u8 *keysize)
146 unsigned int ret, i, j, iv_len;
147 const char *key;
148 char iv[128];
149 struct crypto_blkcipher *tfm;
150 struct blkcipher_desc desc;
151 const char *e;
152 u32 *b_size;
154 if (enc == ENCRYPT)
155 e = "encryption";
156 else
157 e = "decryption";
159 printk("\ntesting speed of %s %s\n", algo, e);
161 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
163 if (IS_ERR(tfm)) {
164 printk("failed to load transform for %s: %ld\n", algo,
165 PTR_ERR(tfm));
166 return;
168 desc.tfm = tfm;
169 desc.flags = 0;
171 i = 0;
172 do {
174 b_size = block_sizes;
175 do {
176 struct scatterlist sg[TVMEMSIZE];
178 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
179 printk("template (%u) too big for "
180 "tvmem (%lu)\n", *keysize + *b_size,
181 TVMEMSIZE * PAGE_SIZE);
182 goto out;
185 printk("test %u (%d bit key, %d byte blocks): ", i,
186 *keysize * 8, *b_size);
188 memset(tvmem[0], 0xff, PAGE_SIZE);
190 /* set key, plain text and IV */
191 key = tvmem[0];
192 for (j = 0; j < tcount; j++) {
193 if (template[j].klen == *keysize) {
194 key = template[j].key;
195 break;
199 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
200 if (ret) {
201 printk("setkey() failed flags=%x\n",
202 crypto_blkcipher_get_flags(tfm));
203 goto out;
206 sg_init_table(sg, TVMEMSIZE);
207 sg_set_buf(sg, tvmem[0] + *keysize,
208 PAGE_SIZE - *keysize);
209 for (j = 1; j < TVMEMSIZE; j++) {
210 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
211 memset (tvmem[j], 0xff, PAGE_SIZE);
214 iv_len = crypto_blkcipher_ivsize(tfm);
215 if (iv_len) {
216 memset(&iv, 0xff, iv_len);
217 crypto_blkcipher_set_iv(tfm, iv, iv_len);
220 if (sec)
221 ret = test_cipher_jiffies(&desc, enc, sg,
222 *b_size, sec);
223 else
224 ret = test_cipher_cycles(&desc, enc, sg,
225 *b_size);
227 if (ret) {
228 printk("%s() failed flags=%x\n", e, desc.flags);
229 break;
231 b_size++;
232 i++;
233 } while (*b_size);
234 keysize++;
235 } while (*keysize);
237 out:
238 crypto_free_blkcipher(tfm);
241 static int test_hash_jiffies_digest(struct hash_desc *desc,
242 struct scatterlist *sg, int blen,
243 char *out, int sec)
245 unsigned long start, end;
246 int bcount;
247 int ret;
249 for (start = jiffies, end = start + sec * HZ, bcount = 0;
250 time_before(jiffies, end); bcount++) {
251 ret = crypto_hash_digest(desc, sg, blen, out);
252 if (ret)
253 return ret;
256 printk("%6u opers/sec, %9lu bytes/sec\n",
257 bcount / sec, ((long)bcount * blen) / sec);
259 return 0;
262 static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
263 int blen, int plen, char *out, int sec)
265 unsigned long start, end;
266 int bcount, pcount;
267 int ret;
269 if (plen == blen)
270 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
272 for (start = jiffies, end = start + sec * HZ, bcount = 0;
273 time_before(jiffies, end); bcount++) {
274 ret = crypto_hash_init(desc);
275 if (ret)
276 return ret;
277 for (pcount = 0; pcount < blen; pcount += plen) {
278 ret = crypto_hash_update(desc, sg, plen);
279 if (ret)
280 return ret;
282 /* we assume there is enough space in 'out' for the result */
283 ret = crypto_hash_final(desc, out);
284 if (ret)
285 return ret;
288 printk("%6u opers/sec, %9lu bytes/sec\n",
289 bcount / sec, ((long)bcount * blen) / sec);
291 return 0;
294 static int test_hash_cycles_digest(struct hash_desc *desc,
295 struct scatterlist *sg, int blen, char *out)
297 unsigned long cycles = 0;
298 int i;
299 int ret;
301 local_irq_disable();
303 /* Warm-up run. */
304 for (i = 0; i < 4; i++) {
305 ret = crypto_hash_digest(desc, sg, blen, out);
306 if (ret)
307 goto out;
310 /* The real thing. */
311 for (i = 0; i < 8; i++) {
312 cycles_t start, end;
314 start = get_cycles();
316 ret = crypto_hash_digest(desc, sg, blen, out);
317 if (ret)
318 goto out;
320 end = get_cycles();
322 cycles += end - start;
325 out:
326 local_irq_enable();
328 if (ret)
329 return ret;
331 printk("%6lu cycles/operation, %4lu cycles/byte\n",
332 cycles / 8, cycles / (8 * blen));
334 return 0;
337 static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
338 int blen, int plen, char *out)
340 unsigned long cycles = 0;
341 int i, pcount;
342 int ret;
344 if (plen == blen)
345 return test_hash_cycles_digest(desc, sg, blen, out);
347 local_irq_disable();
349 /* Warm-up run. */
350 for (i = 0; i < 4; i++) {
351 ret = crypto_hash_init(desc);
352 if (ret)
353 goto out;
354 for (pcount = 0; pcount < blen; pcount += plen) {
355 ret = crypto_hash_update(desc, sg, plen);
356 if (ret)
357 goto out;
359 ret = crypto_hash_final(desc, out);
360 if (ret)
361 goto out;
364 /* The real thing. */
365 for (i = 0; i < 8; i++) {
366 cycles_t start, end;
368 start = get_cycles();
370 ret = crypto_hash_init(desc);
371 if (ret)
372 goto out;
373 for (pcount = 0; pcount < blen; pcount += plen) {
374 ret = crypto_hash_update(desc, sg, plen);
375 if (ret)
376 goto out;
378 ret = crypto_hash_final(desc, out);
379 if (ret)
380 goto out;
382 end = get_cycles();
384 cycles += end - start;
387 out:
388 local_irq_enable();
390 if (ret)
391 return ret;
393 printk("%6lu cycles/operation, %4lu cycles/byte\n",
394 cycles / 8, cycles / (8 * blen));
396 return 0;
399 static void test_hash_sg_init(struct scatterlist *sg)
401 int i;
403 sg_init_table(sg, TVMEMSIZE);
404 for (i = 0; i < TVMEMSIZE; i++) {
405 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
406 memset(tvmem[i], 0xff, PAGE_SIZE);
410 static void test_hash_speed(const char *algo, unsigned int sec,
411 struct hash_speed *speed)
413 struct scatterlist sg[TVMEMSIZE];
414 struct crypto_hash *tfm;
415 struct hash_desc desc;
416 static char output[1024];
417 int i;
418 int ret;
420 printk(KERN_INFO "\ntesting speed of %s\n", algo);
422 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
424 if (IS_ERR(tfm)) {
425 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
426 PTR_ERR(tfm));
427 return;
430 desc.tfm = tfm;
431 desc.flags = 0;
433 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
434 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
435 crypto_hash_digestsize(tfm), sizeof(output));
436 goto out;
439 test_hash_sg_init(sg);
440 for (i = 0; speed[i].blen != 0; i++) {
441 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
442 printk(KERN_ERR
443 "template (%u) too big for tvmem (%lu)\n",
444 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
445 goto out;
448 if (speed[i].klen)
449 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
451 printk(KERN_INFO "test%3u "
452 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
453 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
455 if (sec)
456 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
457 speed[i].plen, output, sec);
458 else
459 ret = test_hash_cycles(&desc, sg, speed[i].blen,
460 speed[i].plen, output);
462 if (ret) {
463 printk(KERN_ERR "hashing failed ret=%d\n", ret);
464 break;
468 out:
469 crypto_free_hash(tfm);
472 struct tcrypt_result {
473 struct completion completion;
474 int err;
477 static void tcrypt_complete(struct crypto_async_request *req, int err)
479 struct tcrypt_result *res = req->data;
481 if (err == -EINPROGRESS)
482 return;
484 res->err = err;
485 complete(&res->completion);
488 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
490 if (ret == -EINPROGRESS || ret == -EBUSY) {
491 struct tcrypt_result *tr = req->base.data;
493 ret = wait_for_completion_interruptible(&tr->completion);
494 if (!ret)
495 ret = tr->err;
496 INIT_COMPLETION(tr->completion);
498 return ret;
501 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
502 char *out, int sec)
504 unsigned long start, end;
505 int bcount;
506 int ret;
508 for (start = jiffies, end = start + sec * HZ, bcount = 0;
509 time_before(jiffies, end); bcount++) {
510 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
511 if (ret)
512 return ret;
515 printk("%6u opers/sec, %9lu bytes/sec\n",
516 bcount / sec, ((long)bcount * blen) / sec);
518 return 0;
521 static int test_ahash_jiffies(struct ahash_request *req, int blen,
522 int plen, char *out, int sec)
524 unsigned long start, end;
525 int bcount, pcount;
526 int ret;
528 if (plen == blen)
529 return test_ahash_jiffies_digest(req, blen, out, sec);
531 for (start = jiffies, end = start + sec * HZ, bcount = 0;
532 time_before(jiffies, end); bcount++) {
533 ret = crypto_ahash_init(req);
534 if (ret)
535 return ret;
536 for (pcount = 0; pcount < blen; pcount += plen) {
537 ret = do_one_ahash_op(req, crypto_ahash_update(req));
538 if (ret)
539 return ret;
541 /* we assume there is enough space in 'out' for the result */
542 ret = do_one_ahash_op(req, crypto_ahash_final(req));
543 if (ret)
544 return ret;
547 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
548 bcount / sec, ((long)bcount * blen) / sec);
550 return 0;
553 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
554 char *out)
556 unsigned long cycles = 0;
557 int ret, i;
559 /* Warm-up run. */
560 for (i = 0; i < 4; i++) {
561 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
562 if (ret)
563 goto out;
566 /* The real thing. */
567 for (i = 0; i < 8; i++) {
568 cycles_t start, end;
570 start = get_cycles();
572 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
573 if (ret)
574 goto out;
576 end = get_cycles();
578 cycles += end - start;
581 out:
582 if (ret)
583 return ret;
585 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
586 cycles / 8, cycles / (8 * blen));
588 return 0;
591 static int test_ahash_cycles(struct ahash_request *req, int blen,
592 int plen, char *out)
594 unsigned long cycles = 0;
595 int i, pcount, ret;
597 if (plen == blen)
598 return test_ahash_cycles_digest(req, blen, out);
600 /* Warm-up run. */
601 for (i = 0; i < 4; i++) {
602 ret = crypto_ahash_init(req);
603 if (ret)
604 goto out;
605 for (pcount = 0; pcount < blen; pcount += plen) {
606 ret = do_one_ahash_op(req, crypto_ahash_update(req));
607 if (ret)
608 goto out;
610 ret = do_one_ahash_op(req, crypto_ahash_final(req));
611 if (ret)
612 goto out;
615 /* The real thing. */
616 for (i = 0; i < 8; i++) {
617 cycles_t start, end;
619 start = get_cycles();
621 ret = crypto_ahash_init(req);
622 if (ret)
623 goto out;
624 for (pcount = 0; pcount < blen; pcount += plen) {
625 ret = do_one_ahash_op(req, crypto_ahash_update(req));
626 if (ret)
627 goto out;
629 ret = do_one_ahash_op(req, crypto_ahash_final(req));
630 if (ret)
631 goto out;
633 end = get_cycles();
635 cycles += end - start;
638 out:
639 if (ret)
640 return ret;
642 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
643 cycles / 8, cycles / (8 * blen));
645 return 0;
648 static void test_ahash_speed(const char *algo, unsigned int sec,
649 struct hash_speed *speed)
651 struct scatterlist sg[TVMEMSIZE];
652 struct tcrypt_result tresult;
653 struct ahash_request *req;
654 struct crypto_ahash *tfm;
655 static char output[1024];
656 int i, ret;
658 printk(KERN_INFO "\ntesting speed of async %s\n", algo);
660 tfm = crypto_alloc_ahash(algo, 0, 0);
661 if (IS_ERR(tfm)) {
662 pr_err("failed to load transform for %s: %ld\n",
663 algo, PTR_ERR(tfm));
664 return;
667 if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
668 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
669 crypto_ahash_digestsize(tfm), sizeof(output));
670 goto out;
673 test_hash_sg_init(sg);
674 req = ahash_request_alloc(tfm, GFP_KERNEL);
675 if (!req) {
676 pr_err("ahash request allocation failure\n");
677 goto out;
680 init_completion(&tresult.completion);
681 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
682 tcrypt_complete, &tresult);
684 for (i = 0; speed[i].blen != 0; i++) {
685 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
686 pr_err("template (%u) too big for tvmem (%lu)\n",
687 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
688 break;
691 pr_info("test%3u "
692 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
693 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
695 ahash_request_set_crypt(req, sg, output, speed[i].plen);
697 if (sec)
698 ret = test_ahash_jiffies(req, speed[i].blen,
699 speed[i].plen, output, sec);
700 else
701 ret = test_ahash_cycles(req, speed[i].blen,
702 speed[i].plen, output);
704 if (ret) {
705 pr_err("hashing failed ret=%d\n", ret);
706 break;
710 ahash_request_free(req);
712 out:
713 crypto_free_ahash(tfm);
716 static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
718 if (ret == -EINPROGRESS || ret == -EBUSY) {
719 struct tcrypt_result *tr = req->base.data;
721 ret = wait_for_completion_interruptible(&tr->completion);
722 if (!ret)
723 ret = tr->err;
724 INIT_COMPLETION(tr->completion);
727 return ret;
730 static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
731 int blen, int sec)
733 unsigned long start, end;
734 int bcount;
735 int ret;
737 for (start = jiffies, end = start + sec * HZ, bcount = 0;
738 time_before(jiffies, end); bcount++) {
739 if (enc)
740 ret = do_one_acipher_op(req,
741 crypto_ablkcipher_encrypt(req));
742 else
743 ret = do_one_acipher_op(req,
744 crypto_ablkcipher_decrypt(req));
746 if (ret)
747 return ret;
750 pr_cont("%d operations in %d seconds (%ld bytes)\n",
751 bcount, sec, (long)bcount * blen);
752 return 0;
755 static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
756 int blen)
758 unsigned long cycles = 0;
759 int ret = 0;
760 int i;
762 /* Warm-up run. */
763 for (i = 0; i < 4; i++) {
764 if (enc)
765 ret = do_one_acipher_op(req,
766 crypto_ablkcipher_encrypt(req));
767 else
768 ret = do_one_acipher_op(req,
769 crypto_ablkcipher_decrypt(req));
771 if (ret)
772 goto out;
775 /* The real thing. */
776 for (i = 0; i < 8; i++) {
777 cycles_t start, end;
779 start = get_cycles();
780 if (enc)
781 ret = do_one_acipher_op(req,
782 crypto_ablkcipher_encrypt(req));
783 else
784 ret = do_one_acipher_op(req,
785 crypto_ablkcipher_decrypt(req));
786 end = get_cycles();
788 if (ret)
789 goto out;
791 cycles += end - start;
794 out:
795 if (ret == 0)
796 pr_cont("1 operation in %lu cycles (%d bytes)\n",
797 (cycles + 4) / 8, blen);
799 return ret;
802 static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
803 struct cipher_speed_template *template,
804 unsigned int tcount, u8 *keysize)
806 unsigned int ret, i, j, k, iv_len;
807 struct tcrypt_result tresult;
808 const char *key;
809 char iv[128];
810 struct ablkcipher_request *req;
811 struct crypto_ablkcipher *tfm;
812 const char *e;
813 u32 *b_size;
815 if (enc == ENCRYPT)
816 e = "encryption";
817 else
818 e = "decryption";
820 pr_info("\ntesting speed of async %s %s\n", algo, e);
822 init_completion(&tresult.completion);
824 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
826 if (IS_ERR(tfm)) {
827 pr_err("failed to load transform for %s: %ld\n", algo,
828 PTR_ERR(tfm));
829 return;
832 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
833 if (!req) {
834 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
835 algo);
836 goto out;
839 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
840 tcrypt_complete, &tresult);
842 i = 0;
843 do {
844 b_size = block_sizes;
846 do {
847 struct scatterlist sg[TVMEMSIZE];
849 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
850 pr_err("template (%u) too big for "
851 "tvmem (%lu)\n", *keysize + *b_size,
852 TVMEMSIZE * PAGE_SIZE);
853 goto out_free_req;
856 pr_info("test %u (%d bit key, %d byte blocks): ", i,
857 *keysize * 8, *b_size);
859 memset(tvmem[0], 0xff, PAGE_SIZE);
861 /* set key, plain text and IV */
862 key = tvmem[0];
863 for (j = 0; j < tcount; j++) {
864 if (template[j].klen == *keysize) {
865 key = template[j].key;
866 break;
870 crypto_ablkcipher_clear_flags(tfm, ~0);
872 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
873 if (ret) {
874 pr_err("setkey() failed flags=%x\n",
875 crypto_ablkcipher_get_flags(tfm));
876 goto out_free_req;
879 sg_init_table(sg, TVMEMSIZE);
881 k = *keysize + *b_size;
882 if (k > PAGE_SIZE) {
883 sg_set_buf(sg, tvmem[0] + *keysize,
884 PAGE_SIZE - *keysize);
885 k -= PAGE_SIZE;
886 j = 1;
887 while (k > PAGE_SIZE) {
888 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
889 memset(tvmem[j], 0xff, PAGE_SIZE);
890 j++;
891 k -= PAGE_SIZE;
893 sg_set_buf(sg + j, tvmem[j], k);
894 memset(tvmem[j], 0xff, k);
895 } else {
896 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
899 iv_len = crypto_ablkcipher_ivsize(tfm);
900 if (iv_len)
901 memset(&iv, 0xff, iv_len);
903 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
905 if (sec)
906 ret = test_acipher_jiffies(req, enc,
907 *b_size, sec);
908 else
909 ret = test_acipher_cycles(req, enc,
910 *b_size);
912 if (ret) {
913 pr_err("%s() failed flags=%x\n", e,
914 crypto_ablkcipher_get_flags(tfm));
915 break;
917 b_size++;
918 i++;
919 } while (*b_size);
920 keysize++;
921 } while (*keysize);
923 out_free_req:
924 ablkcipher_request_free(req);
925 out:
926 crypto_free_ablkcipher(tfm);
929 static void test_available(void)
931 char **name = check;
933 while (*name) {
934 printk("alg %s ", *name);
935 printk(crypto_has_alg(*name, 0, 0) ?
936 "found\n" : "not found\n");
937 name++;
941 static inline int tcrypt_test(const char *alg)
943 int ret;
945 ret = alg_test(alg, alg, 0, 0);
946 /* non-fips algs return -EINVAL in fips mode */
947 if (fips_enabled && ret == -EINVAL)
948 ret = 0;
949 return ret;
952 static int do_test(int m)
954 int i;
955 int ret = 0;
957 switch (m) {
958 case 0:
959 for (i = 1; i < 200; i++)
960 ret += do_test(i);
961 break;
963 case 1:
964 ret += tcrypt_test("md5");
965 break;
967 case 2:
968 ret += tcrypt_test("sha1");
969 break;
971 case 3:
972 ret += tcrypt_test("ecb(des)");
973 ret += tcrypt_test("cbc(des)");
974 ret += tcrypt_test("ctr(des)");
975 break;
977 case 4:
978 ret += tcrypt_test("ecb(des3_ede)");
979 ret += tcrypt_test("cbc(des3_ede)");
980 ret += tcrypt_test("ctr(des3_ede)");
981 break;
983 case 5:
984 ret += tcrypt_test("md4");
985 break;
987 case 6:
988 ret += tcrypt_test("sha256");
989 break;
991 case 7:
992 ret += tcrypt_test("ecb(blowfish)");
993 ret += tcrypt_test("cbc(blowfish)");
994 ret += tcrypt_test("ctr(blowfish)");
995 break;
997 case 8:
998 ret += tcrypt_test("ecb(twofish)");
999 ret += tcrypt_test("cbc(twofish)");
1000 ret += tcrypt_test("ctr(twofish)");
1001 ret += tcrypt_test("lrw(twofish)");
1002 ret += tcrypt_test("xts(twofish)");
1003 break;
1005 case 9:
1006 ret += tcrypt_test("ecb(serpent)");
1007 ret += tcrypt_test("cbc(serpent)");
1008 ret += tcrypt_test("ctr(serpent)");
1009 ret += tcrypt_test("lrw(serpent)");
1010 ret += tcrypt_test("xts(serpent)");
1011 break;
1013 case 10:
1014 ret += tcrypt_test("ecb(aes)");
1015 ret += tcrypt_test("cbc(aes)");
1016 ret += tcrypt_test("lrw(aes)");
1017 ret += tcrypt_test("xts(aes)");
1018 ret += tcrypt_test("ctr(aes)");
1019 ret += tcrypt_test("rfc3686(ctr(aes))");
1020 break;
1022 case 11:
1023 ret += tcrypt_test("sha384");
1024 break;
1026 case 12:
1027 ret += tcrypt_test("sha512");
1028 break;
1030 case 13:
1031 ret += tcrypt_test("deflate");
1032 break;
1034 case 14:
1035 ret += tcrypt_test("ecb(cast5)");
1036 ret += tcrypt_test("cbc(cast5)");
1037 ret += tcrypt_test("ctr(cast5)");
1038 break;
1040 case 15:
1041 ret += tcrypt_test("ecb(cast6)");
1042 ret += tcrypt_test("cbc(cast6)");
1043 ret += tcrypt_test("ctr(cast6)");
1044 ret += tcrypt_test("lrw(cast6)");
1045 ret += tcrypt_test("xts(cast6)");
1046 break;
1048 case 16:
1049 ret += tcrypt_test("ecb(arc4)");
1050 break;
1052 case 17:
1053 ret += tcrypt_test("michael_mic");
1054 break;
1056 case 18:
1057 ret += tcrypt_test("crc32c");
1058 break;
1060 case 19:
1061 ret += tcrypt_test("ecb(tea)");
1062 break;
1064 case 20:
1065 ret += tcrypt_test("ecb(xtea)");
1066 break;
1068 case 21:
1069 ret += tcrypt_test("ecb(khazad)");
1070 break;
1072 case 22:
1073 ret += tcrypt_test("wp512");
1074 break;
1076 case 23:
1077 ret += tcrypt_test("wp384");
1078 break;
1080 case 24:
1081 ret += tcrypt_test("wp256");
1082 break;
1084 case 25:
1085 ret += tcrypt_test("ecb(tnepres)");
1086 break;
1088 case 26:
1089 ret += tcrypt_test("ecb(anubis)");
1090 ret += tcrypt_test("cbc(anubis)");
1091 break;
1093 case 27:
1094 ret += tcrypt_test("tgr192");
1095 break;
1097 case 28:
1099 ret += tcrypt_test("tgr160");
1100 break;
1102 case 29:
1103 ret += tcrypt_test("tgr128");
1104 break;
1106 case 30:
1107 ret += tcrypt_test("ecb(xeta)");
1108 break;
1110 case 31:
1111 ret += tcrypt_test("pcbc(fcrypt)");
1112 break;
1114 case 32:
1115 ret += tcrypt_test("ecb(camellia)");
1116 ret += tcrypt_test("cbc(camellia)");
1117 ret += tcrypt_test("ctr(camellia)");
1118 ret += tcrypt_test("lrw(camellia)");
1119 ret += tcrypt_test("xts(camellia)");
1120 break;
1121 case 33:
1122 ret += tcrypt_test("sha224");
1123 break;
1125 case 34:
1126 ret += tcrypt_test("salsa20");
1127 break;
1129 case 35:
1130 ret += tcrypt_test("gcm(aes)");
1131 break;
1133 case 36:
1134 ret += tcrypt_test("lzo");
1135 break;
1137 case 37:
1138 ret += tcrypt_test("ccm(aes)");
1139 break;
1141 case 38:
1142 ret += tcrypt_test("cts(cbc(aes))");
1143 break;
1145 case 39:
1146 ret += tcrypt_test("rmd128");
1147 break;
1149 case 40:
1150 ret += tcrypt_test("rmd160");
1151 break;
1153 case 41:
1154 ret += tcrypt_test("rmd256");
1155 break;
1157 case 42:
1158 ret += tcrypt_test("rmd320");
1159 break;
1161 case 43:
1162 ret += tcrypt_test("ecb(seed)");
1163 break;
1165 case 44:
1166 ret += tcrypt_test("zlib");
1167 break;
1169 case 45:
1170 ret += tcrypt_test("rfc4309(ccm(aes))");
1171 break;
1173 case 46:
1174 ret += tcrypt_test("ghash");
1175 break;
1177 case 100:
1178 ret += tcrypt_test("hmac(md5)");
1179 break;
1181 case 101:
1182 ret += tcrypt_test("hmac(sha1)");
1183 break;
1185 case 102:
1186 ret += tcrypt_test("hmac(sha256)");
1187 break;
1189 case 103:
1190 ret += tcrypt_test("hmac(sha384)");
1191 break;
1193 case 104:
1194 ret += tcrypt_test("hmac(sha512)");
1195 break;
1197 case 105:
1198 ret += tcrypt_test("hmac(sha224)");
1199 break;
1201 case 106:
1202 ret += tcrypt_test("xcbc(aes)");
1203 break;
1205 case 107:
1206 ret += tcrypt_test("hmac(rmd128)");
1207 break;
1209 case 108:
1210 ret += tcrypt_test("hmac(rmd160)");
1211 break;
1213 case 109:
1214 ret += tcrypt_test("vmac(aes)");
1215 break;
1216 case 110:
1217 ret += tcrypt_test("hmac(crc32)");
1218 break;
1220 case 150:
1221 ret += tcrypt_test("ansi_cprng");
1222 break;
1224 case 151:
1225 ret += tcrypt_test("rfc4106(gcm(aes))");
1226 break;
1228 case 200:
1229 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1230 speed_template_16_24_32);
1231 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1232 speed_template_16_24_32);
1233 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1234 speed_template_16_24_32);
1235 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1236 speed_template_16_24_32);
1237 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1238 speed_template_32_40_48);
1239 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1240 speed_template_32_40_48);
1241 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1242 speed_template_32_48_64);
1243 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1244 speed_template_32_48_64);
1245 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1246 speed_template_16_24_32);
1247 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1248 speed_template_16_24_32);
1249 break;
1251 case 201:
1252 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1253 des3_speed_template, DES3_SPEED_VECTORS,
1254 speed_template_24);
1255 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1256 des3_speed_template, DES3_SPEED_VECTORS,
1257 speed_template_24);
1258 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1259 des3_speed_template, DES3_SPEED_VECTORS,
1260 speed_template_24);
1261 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1262 des3_speed_template, DES3_SPEED_VECTORS,
1263 speed_template_24);
1264 break;
1266 case 202:
1267 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1268 speed_template_16_24_32);
1269 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1270 speed_template_16_24_32);
1271 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1272 speed_template_16_24_32);
1273 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1274 speed_template_16_24_32);
1275 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1276 speed_template_16_24_32);
1277 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1278 speed_template_16_24_32);
1279 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1280 speed_template_32_40_48);
1281 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1282 speed_template_32_40_48);
1283 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1284 speed_template_32_48_64);
1285 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1286 speed_template_32_48_64);
1287 break;
1289 case 203:
1290 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1291 speed_template_8_32);
1292 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1293 speed_template_8_32);
1294 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1295 speed_template_8_32);
1296 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1297 speed_template_8_32);
1298 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1299 speed_template_8_32);
1300 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1301 speed_template_8_32);
1302 break;
1304 case 204:
1305 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1306 speed_template_8);
1307 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1308 speed_template_8);
1309 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1310 speed_template_8);
1311 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1312 speed_template_8);
1313 break;
1315 case 205:
1316 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1317 speed_template_16_24_32);
1318 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1319 speed_template_16_24_32);
1320 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1321 speed_template_16_24_32);
1322 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1323 speed_template_16_24_32);
1324 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1325 speed_template_16_24_32);
1326 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1327 speed_template_16_24_32);
1328 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1329 speed_template_32_40_48);
1330 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1331 speed_template_32_40_48);
1332 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1333 speed_template_32_48_64);
1334 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1335 speed_template_32_48_64);
1336 break;
1338 case 206:
1339 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1340 speed_template_16_32);
1341 break;
1343 case 207:
1344 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1345 speed_template_16_32);
1346 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1347 speed_template_16_32);
1348 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1349 speed_template_16_32);
1350 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1351 speed_template_16_32);
1352 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1353 speed_template_16_32);
1354 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1355 speed_template_16_32);
1356 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1357 speed_template_32_48);
1358 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1359 speed_template_32_48);
1360 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1361 speed_template_32_64);
1362 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1363 speed_template_32_64);
1364 break;
1366 case 208:
1367 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1368 speed_template_8);
1369 break;
1371 case 209:
1372 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1373 speed_template_8_16);
1374 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1375 speed_template_8_16);
1376 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1377 speed_template_8_16);
1378 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1379 speed_template_8_16);
1380 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1381 speed_template_8_16);
1382 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1383 speed_template_8_16);
1384 break;
1386 case 210:
1387 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1388 speed_template_16_32);
1389 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1390 speed_template_16_32);
1391 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1392 speed_template_16_32);
1393 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1394 speed_template_16_32);
1395 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1396 speed_template_16_32);
1397 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1398 speed_template_16_32);
1399 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1400 speed_template_32_48);
1401 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1402 speed_template_32_48);
1403 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1404 speed_template_32_64);
1405 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1406 speed_template_32_64);
1407 break;
1409 case 300:
1410 /* fall through */
1412 case 301:
1413 test_hash_speed("md4", sec, generic_hash_speed_template);
1414 if (mode > 300 && mode < 400) break;
1416 case 302:
1417 test_hash_speed("md5", sec, generic_hash_speed_template);
1418 if (mode > 300 && mode < 400) break;
1420 case 303:
1421 test_hash_speed("sha1", sec, generic_hash_speed_template);
1422 if (mode > 300 && mode < 400) break;
1424 case 304:
1425 test_hash_speed("sha256", sec, generic_hash_speed_template);
1426 if (mode > 300 && mode < 400) break;
1428 case 305:
1429 test_hash_speed("sha384", sec, generic_hash_speed_template);
1430 if (mode > 300 && mode < 400) break;
1432 case 306:
1433 test_hash_speed("sha512", sec, generic_hash_speed_template);
1434 if (mode > 300 && mode < 400) break;
1436 case 307:
1437 test_hash_speed("wp256", sec, generic_hash_speed_template);
1438 if (mode > 300 && mode < 400) break;
1440 case 308:
1441 test_hash_speed("wp384", sec, generic_hash_speed_template);
1442 if (mode > 300 && mode < 400) break;
1444 case 309:
1445 test_hash_speed("wp512", sec, generic_hash_speed_template);
1446 if (mode > 300 && mode < 400) break;
1448 case 310:
1449 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1450 if (mode > 300 && mode < 400) break;
1452 case 311:
1453 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1454 if (mode > 300 && mode < 400) break;
1456 case 312:
1457 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1458 if (mode > 300 && mode < 400) break;
1460 case 313:
1461 test_hash_speed("sha224", sec, generic_hash_speed_template);
1462 if (mode > 300 && mode < 400) break;
1464 case 314:
1465 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1466 if (mode > 300 && mode < 400) break;
1468 case 315:
1469 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1470 if (mode > 300 && mode < 400) break;
1472 case 316:
1473 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1474 if (mode > 300 && mode < 400) break;
1476 case 317:
1477 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1478 if (mode > 300 && mode < 400) break;
1480 case 318:
1481 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1482 if (mode > 300 && mode < 400) break;
1484 case 319:
1485 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1486 if (mode > 300 && mode < 400) break;
1488 case 399:
1489 break;
1491 case 400:
1492 /* fall through */
1494 case 401:
1495 test_ahash_speed("md4", sec, generic_hash_speed_template);
1496 if (mode > 400 && mode < 500) break;
1498 case 402:
1499 test_ahash_speed("md5", sec, generic_hash_speed_template);
1500 if (mode > 400 && mode < 500) break;
1502 case 403:
1503 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1504 if (mode > 400 && mode < 500) break;
1506 case 404:
1507 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1508 if (mode > 400 && mode < 500) break;
1510 case 405:
1511 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1512 if (mode > 400 && mode < 500) break;
1514 case 406:
1515 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1516 if (mode > 400 && mode < 500) break;
1518 case 407:
1519 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1520 if (mode > 400 && mode < 500) break;
1522 case 408:
1523 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1524 if (mode > 400 && mode < 500) break;
1526 case 409:
1527 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1528 if (mode > 400 && mode < 500) break;
1530 case 410:
1531 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1532 if (mode > 400 && mode < 500) break;
1534 case 411:
1535 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1536 if (mode > 400 && mode < 500) break;
1538 case 412:
1539 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1540 if (mode > 400 && mode < 500) break;
1542 case 413:
1543 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1544 if (mode > 400 && mode < 500) break;
1546 case 414:
1547 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1548 if (mode > 400 && mode < 500) break;
1550 case 415:
1551 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1552 if (mode > 400 && mode < 500) break;
1554 case 416:
1555 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1556 if (mode > 400 && mode < 500) break;
1558 case 417:
1559 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1560 if (mode > 400 && mode < 500) break;
1562 case 499:
1563 break;
1565 case 500:
1566 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1567 speed_template_16_24_32);
1568 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1569 speed_template_16_24_32);
1570 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1571 speed_template_16_24_32);
1572 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1573 speed_template_16_24_32);
1574 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1575 speed_template_32_40_48);
1576 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1577 speed_template_32_40_48);
1578 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1579 speed_template_32_48_64);
1580 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1581 speed_template_32_48_64);
1582 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1583 speed_template_16_24_32);
1584 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1585 speed_template_16_24_32);
1586 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1587 speed_template_16_24_32);
1588 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1589 speed_template_16_24_32);
1590 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1591 speed_template_16_24_32);
1592 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1593 speed_template_16_24_32);
1594 break;
1596 case 501:
1597 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1598 des3_speed_template, DES3_SPEED_VECTORS,
1599 speed_template_24);
1600 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1601 des3_speed_template, DES3_SPEED_VECTORS,
1602 speed_template_24);
1603 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1604 des3_speed_template, DES3_SPEED_VECTORS,
1605 speed_template_24);
1606 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1607 des3_speed_template, DES3_SPEED_VECTORS,
1608 speed_template_24);
1609 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1610 des3_speed_template, DES3_SPEED_VECTORS,
1611 speed_template_24);
1612 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1613 des3_speed_template, DES3_SPEED_VECTORS,
1614 speed_template_24);
1615 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1616 des3_speed_template, DES3_SPEED_VECTORS,
1617 speed_template_24);
1618 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1619 des3_speed_template, DES3_SPEED_VECTORS,
1620 speed_template_24);
1621 break;
1623 case 502:
1624 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1625 speed_template_8);
1626 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1627 speed_template_8);
1628 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1629 speed_template_8);
1630 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1631 speed_template_8);
1632 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1633 speed_template_8);
1634 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1635 speed_template_8);
1636 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1637 speed_template_8);
1638 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1639 speed_template_8);
1640 break;
1642 case 503:
1643 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1644 speed_template_16_32);
1645 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1646 speed_template_16_32);
1647 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1648 speed_template_16_32);
1649 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1650 speed_template_16_32);
1651 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1652 speed_template_16_32);
1653 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1654 speed_template_16_32);
1655 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1656 speed_template_32_48);
1657 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1658 speed_template_32_48);
1659 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1660 speed_template_32_64);
1661 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1662 speed_template_32_64);
1663 break;
1665 case 504:
1666 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1667 speed_template_16_24_32);
1668 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1669 speed_template_16_24_32);
1670 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1671 speed_template_16_24_32);
1672 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1673 speed_template_16_24_32);
1674 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1675 speed_template_16_24_32);
1676 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1677 speed_template_16_24_32);
1678 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1679 speed_template_32_40_48);
1680 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1681 speed_template_32_40_48);
1682 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1683 speed_template_32_48_64);
1684 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1685 speed_template_32_48_64);
1686 break;
1688 case 505:
1689 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1690 speed_template_8);
1691 break;
1693 case 506:
1694 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1695 speed_template_8_16);
1696 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1697 speed_template_8_16);
1698 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1699 speed_template_8_16);
1700 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1701 speed_template_8_16);
1702 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1703 speed_template_8_16);
1704 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1705 speed_template_8_16);
1706 break;
1708 case 507:
1709 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1710 speed_template_16_32);
1711 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1712 speed_template_16_32);
1713 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1714 speed_template_16_32);
1715 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1716 speed_template_16_32);
1717 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1718 speed_template_16_32);
1719 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1720 speed_template_16_32);
1721 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1722 speed_template_32_48);
1723 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1724 speed_template_32_48);
1725 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1726 speed_template_32_64);
1727 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1728 speed_template_32_64);
1729 break;
1731 case 508:
1732 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1733 speed_template_16_32);
1734 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1735 speed_template_16_32);
1736 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1737 speed_template_16_32);
1738 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1739 speed_template_16_32);
1740 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1741 speed_template_16_32);
1742 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1743 speed_template_16_32);
1744 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1745 speed_template_32_48);
1746 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1747 speed_template_32_48);
1748 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1749 speed_template_32_64);
1750 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1751 speed_template_32_64);
1752 break;
1754 case 1000:
1755 test_available();
1756 break;
1759 return ret;
1762 static int do_alg_test(const char *alg, u32 type, u32 mask)
1764 return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
1765 0 : -ENOENT;
1768 static int __init tcrypt_mod_init(void)
1770 int err = -ENOMEM;
1771 int i;
1773 for (i = 0; i < TVMEMSIZE; i++) {
1774 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
1775 if (!tvmem[i])
1776 goto err_free_tv;
1779 if (alg)
1780 err = do_alg_test(alg, type, mask);
1781 else
1782 err = do_test(mode);
1784 if (err) {
1785 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
1786 goto err_free_tv;
1789 /* We intentionaly return -EAGAIN to prevent keeping the module,
1790 * unless we're running in fips mode. It does all its work from
1791 * init() and doesn't offer any runtime functionality, but in
1792 * the fips case, checking for a successful load is helpful.
1793 * => we don't need it in the memory, do we?
1794 * -- mludvig
1796 if (!fips_enabled)
1797 err = -EAGAIN;
1799 err_free_tv:
1800 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
1801 free_page((unsigned long)tvmem[i]);
1803 return err;
1807 * If an init function is provided, an exit function must also be provided
1808 * to allow module unload.
1810 static void __exit tcrypt_mod_fini(void) { }
1812 module_init(tcrypt_mod_init);
1813 module_exit(tcrypt_mod_fini);
1815 module_param(alg, charp, 0);
1816 module_param(type, uint, 0);
1817 module_param(mask, uint, 0);
1818 module_param(mode, int, 0);
1819 module_param(sec, uint, 0);
1820 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1821 "(defaults to zero which uses CPU cycles instead)");
1823 MODULE_LICENSE("GPL");
1824 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1825 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");