coredump: get rid of coredump_params->written
[deliverable/linux.git] / crypto / tcrypt.c
1 /*
2 * Quick & dirty crypto testing module.
3 *
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
6 *
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
10 *
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.
17 *
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.
22 *
23 */
24
25 #include <crypto/aead.h>
26 #include <crypto/hash.h>
27 #include <linux/err.h>
28 #include <linux/fips.h>
29 #include <linux/init.h>
30 #include <linux/gfp.h>
31 #include <linux/module.h>
32 #include <linux/scatterlist.h>
33 #include <linux/string.h>
34 #include <linux/moduleparam.h>
35 #include <linux/jiffies.h>
36 #include <linux/timex.h>
37 #include <linux/interrupt.h>
38 #include "tcrypt.h"
39
40 /*
41 * Need slab memory for testing (size in number of pages).
42 */
43 #define TVMEMSIZE 4
44
45 /*
46 * Used by test_cipher_speed()
47 */
48 #define ENCRYPT 1
49 #define DECRYPT 0
50
51 #define MAX_DIGEST_SIZE 64
52
53 /*
54 * return a string with the driver name
55 */
56 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
57
58 /*
59 * Used by test_cipher_speed()
60 */
61 static unsigned int sec;
62
63 static char *alg = NULL;
64 static u32 type;
65 static u32 mask;
66 static int mode;
67 static char *tvmem[TVMEMSIZE];
68
69 static char *check[] = {
70 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
71 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
73 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
74 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
75 "lzo", "cts", "zlib", NULL
76 };
77
78 struct tcrypt_result {
79 struct completion completion;
80 int err;
81 };
82
83 static void tcrypt_complete(struct crypto_async_request *req, int err)
84 {
85 struct tcrypt_result *res = req->data;
86
87 if (err == -EINPROGRESS)
88 return;
89
90 res->err = err;
91 complete(&res->completion);
92 }
93
94 static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
95 struct scatterlist *sg, int blen, int secs)
96 {
97 unsigned long start, end;
98 int bcount;
99 int ret;
100
101 for (start = jiffies, end = start + secs * HZ, bcount = 0;
102 time_before(jiffies, end); bcount++) {
103 if (enc)
104 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
105 else
106 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
107
108 if (ret)
109 return ret;
110 }
111
112 printk("%d operations in %d seconds (%ld bytes)\n",
113 bcount, secs, (long)bcount * blen);
114 return 0;
115 }
116
117 static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
118 struct scatterlist *sg, int blen)
119 {
120 unsigned long cycles = 0;
121 int ret = 0;
122 int i;
123
124 local_irq_disable();
125
126 /* Warm-up run. */
127 for (i = 0; i < 4; i++) {
128 if (enc)
129 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
130 else
131 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
132
133 if (ret)
134 goto out;
135 }
136
137 /* The real thing. */
138 for (i = 0; i < 8; i++) {
139 cycles_t start, end;
140
141 start = get_cycles();
142 if (enc)
143 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
144 else
145 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
146 end = get_cycles();
147
148 if (ret)
149 goto out;
150
151 cycles += end - start;
152 }
153
154 out:
155 local_irq_enable();
156
157 if (ret == 0)
158 printk("1 operation in %lu cycles (%d bytes)\n",
159 (cycles + 4) / 8, blen);
160
161 return ret;
162 }
163
164 static inline int do_one_aead_op(struct aead_request *req, int ret)
165 {
166 if (ret == -EINPROGRESS || ret == -EBUSY) {
167 struct tcrypt_result *tr = req->base.data;
168
169 ret = wait_for_completion_interruptible(&tr->completion);
170 if (!ret)
171 ret = tr->err;
172 reinit_completion(&tr->completion);
173 }
174
175 return ret;
176 }
177
178 static int test_aead_jiffies(struct aead_request *req, int enc,
179 int blen, int secs)
180 {
181 unsigned long start, end;
182 int bcount;
183 int ret;
184
185 for (start = jiffies, end = start + secs * HZ, bcount = 0;
186 time_before(jiffies, end); bcount++) {
187 if (enc)
188 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
189 else
190 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
191
192 if (ret)
193 return ret;
194 }
195
196 printk("%d operations in %d seconds (%ld bytes)\n",
197 bcount, secs, (long)bcount * blen);
198 return 0;
199 }
200
201 static int test_aead_cycles(struct aead_request *req, int enc, int blen)
202 {
203 unsigned long cycles = 0;
204 int ret = 0;
205 int i;
206
207 local_irq_disable();
208
209 /* Warm-up run. */
210 for (i = 0; i < 4; i++) {
211 if (enc)
212 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
213 else
214 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
215
216 if (ret)
217 goto out;
218 }
219
220 /* The real thing. */
221 for (i = 0; i < 8; i++) {
222 cycles_t start, end;
223
224 start = get_cycles();
225 if (enc)
226 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
227 else
228 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
229 end = get_cycles();
230
231 if (ret)
232 goto out;
233
234 cycles += end - start;
235 }
236
237 out:
238 local_irq_enable();
239
240 if (ret == 0)
241 printk("1 operation in %lu cycles (%d bytes)\n",
242 (cycles + 4) / 8, blen);
243
244 return ret;
245 }
246
247 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
248 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
249
250 #define XBUFSIZE 8
251 #define MAX_IVLEN 32
252
253 static int testmgr_alloc_buf(char *buf[XBUFSIZE])
254 {
255 int i;
256
257 for (i = 0; i < XBUFSIZE; i++) {
258 buf[i] = (void *)__get_free_page(GFP_KERNEL);
259 if (!buf[i])
260 goto err_free_buf;
261 }
262
263 return 0;
264
265 err_free_buf:
266 while (i-- > 0)
267 free_page((unsigned long)buf[i]);
268
269 return -ENOMEM;
270 }
271
272 static void testmgr_free_buf(char *buf[XBUFSIZE])
273 {
274 int i;
275
276 for (i = 0; i < XBUFSIZE; i++)
277 free_page((unsigned long)buf[i]);
278 }
279
280 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
281 unsigned int buflen)
282 {
283 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
284 int k, rem;
285
286 if (np > XBUFSIZE) {
287 rem = PAGE_SIZE;
288 np = XBUFSIZE;
289 } else {
290 rem = buflen % PAGE_SIZE;
291 }
292
293 sg_init_table(sg, np + 1);
294 np--;
295 for (k = 0; k < np; k++)
296 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
297
298 sg_set_buf(&sg[k + 1], xbuf[k], rem);
299 }
300
301 static void test_aead_speed(const char *algo, int enc, unsigned int secs,
302 struct aead_speed_template *template,
303 unsigned int tcount, u8 authsize,
304 unsigned int aad_size, u8 *keysize)
305 {
306 unsigned int i, j;
307 struct crypto_aead *tfm;
308 int ret = -ENOMEM;
309 const char *key;
310 struct aead_request *req;
311 struct scatterlist *sg;
312 struct scatterlist *sgout;
313 const char *e;
314 void *assoc;
315 char *iv;
316 char *xbuf[XBUFSIZE];
317 char *xoutbuf[XBUFSIZE];
318 char *axbuf[XBUFSIZE];
319 unsigned int *b_size;
320 unsigned int iv_len;
321 struct tcrypt_result result;
322
323 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
324 if (!iv)
325 return;
326
327 if (aad_size >= PAGE_SIZE) {
328 pr_err("associate data length (%u) too big\n", aad_size);
329 goto out_noxbuf;
330 }
331
332 if (enc == ENCRYPT)
333 e = "encryption";
334 else
335 e = "decryption";
336
337 if (testmgr_alloc_buf(xbuf))
338 goto out_noxbuf;
339 if (testmgr_alloc_buf(axbuf))
340 goto out_noaxbuf;
341 if (testmgr_alloc_buf(xoutbuf))
342 goto out_nooutbuf;
343
344 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
345 if (!sg)
346 goto out_nosg;
347 sgout = &sg[9];
348
349 tfm = crypto_alloc_aead(algo, 0, 0);
350
351 if (IS_ERR(tfm)) {
352 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
353 PTR_ERR(tfm));
354 goto out_notfm;
355 }
356
357 init_completion(&result.completion);
358 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
359 get_driver_name(crypto_aead, tfm), e);
360
361 req = aead_request_alloc(tfm, GFP_KERNEL);
362 if (!req) {
363 pr_err("alg: aead: Failed to allocate request for %s\n",
364 algo);
365 goto out_noreq;
366 }
367
368 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
369 tcrypt_complete, &result);
370
371 i = 0;
372 do {
373 b_size = aead_sizes;
374 do {
375 assoc = axbuf[0];
376 memset(assoc, 0xff, aad_size);
377
378 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
379 pr_err("template (%u) too big for tvmem (%lu)\n",
380 *keysize + *b_size,
381 TVMEMSIZE * PAGE_SIZE);
382 goto out;
383 }
384
385 key = tvmem[0];
386 for (j = 0; j < tcount; j++) {
387 if (template[j].klen == *keysize) {
388 key = template[j].key;
389 break;
390 }
391 }
392 ret = crypto_aead_setkey(tfm, key, *keysize);
393 ret = crypto_aead_setauthsize(tfm, authsize);
394
395 iv_len = crypto_aead_ivsize(tfm);
396 if (iv_len)
397 memset(iv, 0xff, iv_len);
398
399 crypto_aead_clear_flags(tfm, ~0);
400 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
401 i, *keysize * 8, *b_size);
402
403
404 memset(tvmem[0], 0xff, PAGE_SIZE);
405
406 if (ret) {
407 pr_err("setkey() failed flags=%x\n",
408 crypto_aead_get_flags(tfm));
409 goto out;
410 }
411
412 sg_init_aead(sg, xbuf,
413 *b_size + (enc ? authsize : 0));
414
415 sg_init_aead(sgout, xoutbuf,
416 *b_size + (enc ? authsize : 0));
417
418 sg_set_buf(&sg[0], assoc, aad_size);
419 sg_set_buf(&sgout[0], assoc, aad_size);
420
421 aead_request_set_crypt(req, sg, sgout, *b_size, iv);
422 aead_request_set_ad(req, aad_size);
423
424 if (secs)
425 ret = test_aead_jiffies(req, enc, *b_size,
426 secs);
427 else
428 ret = test_aead_cycles(req, enc, *b_size);
429
430 if (ret) {
431 pr_err("%s() failed return code=%d\n", e, ret);
432 break;
433 }
434 b_size++;
435 i++;
436 } while (*b_size);
437 keysize++;
438 } while (*keysize);
439
440 out:
441 aead_request_free(req);
442 out_noreq:
443 crypto_free_aead(tfm);
444 out_notfm:
445 kfree(sg);
446 out_nosg:
447 testmgr_free_buf(xoutbuf);
448 out_nooutbuf:
449 testmgr_free_buf(axbuf);
450 out_noaxbuf:
451 testmgr_free_buf(xbuf);
452 out_noxbuf:
453 kfree(iv);
454 return;
455 }
456
457 static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
458 struct cipher_speed_template *template,
459 unsigned int tcount, u8 *keysize)
460 {
461 unsigned int ret, i, j, iv_len;
462 const char *key;
463 char iv[128];
464 struct crypto_blkcipher *tfm;
465 struct blkcipher_desc desc;
466 const char *e;
467 u32 *b_size;
468
469 if (enc == ENCRYPT)
470 e = "encryption";
471 else
472 e = "decryption";
473
474 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
475
476 if (IS_ERR(tfm)) {
477 printk("failed to load transform for %s: %ld\n", algo,
478 PTR_ERR(tfm));
479 return;
480 }
481 desc.tfm = tfm;
482 desc.flags = 0;
483
484 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
485 get_driver_name(crypto_blkcipher, tfm), e);
486
487 i = 0;
488 do {
489
490 b_size = block_sizes;
491 do {
492 struct scatterlist sg[TVMEMSIZE];
493
494 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
495 printk("template (%u) too big for "
496 "tvmem (%lu)\n", *keysize + *b_size,
497 TVMEMSIZE * PAGE_SIZE);
498 goto out;
499 }
500
501 printk("test %u (%d bit key, %d byte blocks): ", i,
502 *keysize * 8, *b_size);
503
504 memset(tvmem[0], 0xff, PAGE_SIZE);
505
506 /* set key, plain text and IV */
507 key = tvmem[0];
508 for (j = 0; j < tcount; j++) {
509 if (template[j].klen == *keysize) {
510 key = template[j].key;
511 break;
512 }
513 }
514
515 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
516 if (ret) {
517 printk("setkey() failed flags=%x\n",
518 crypto_blkcipher_get_flags(tfm));
519 goto out;
520 }
521
522 sg_init_table(sg, TVMEMSIZE);
523 sg_set_buf(sg, tvmem[0] + *keysize,
524 PAGE_SIZE - *keysize);
525 for (j = 1; j < TVMEMSIZE; j++) {
526 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
527 memset (tvmem[j], 0xff, PAGE_SIZE);
528 }
529
530 iv_len = crypto_blkcipher_ivsize(tfm);
531 if (iv_len) {
532 memset(&iv, 0xff, iv_len);
533 crypto_blkcipher_set_iv(tfm, iv, iv_len);
534 }
535
536 if (secs)
537 ret = test_cipher_jiffies(&desc, enc, sg,
538 *b_size, secs);
539 else
540 ret = test_cipher_cycles(&desc, enc, sg,
541 *b_size);
542
543 if (ret) {
544 printk("%s() failed flags=%x\n", e, desc.flags);
545 break;
546 }
547 b_size++;
548 i++;
549 } while (*b_size);
550 keysize++;
551 } while (*keysize);
552
553 out:
554 crypto_free_blkcipher(tfm);
555 }
556
557 static void test_hash_sg_init(struct scatterlist *sg)
558 {
559 int i;
560
561 sg_init_table(sg, TVMEMSIZE);
562 for (i = 0; i < TVMEMSIZE; i++) {
563 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
564 memset(tvmem[i], 0xff, PAGE_SIZE);
565 }
566 }
567
568 static inline int do_one_ahash_op(struct ahash_request *req, int ret)
569 {
570 if (ret == -EINPROGRESS || ret == -EBUSY) {
571 struct tcrypt_result *tr = req->base.data;
572
573 wait_for_completion(&tr->completion);
574 reinit_completion(&tr->completion);
575 ret = tr->err;
576 }
577 return ret;
578 }
579
580 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
581 char *out, int secs)
582 {
583 unsigned long start, end;
584 int bcount;
585 int ret;
586
587 for (start = jiffies, end = start + secs * HZ, bcount = 0;
588 time_before(jiffies, end); bcount++) {
589 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
590 if (ret)
591 return ret;
592 }
593
594 printk("%6u opers/sec, %9lu bytes/sec\n",
595 bcount / secs, ((long)bcount * blen) / secs);
596
597 return 0;
598 }
599
600 static int test_ahash_jiffies(struct ahash_request *req, int blen,
601 int plen, char *out, int secs)
602 {
603 unsigned long start, end;
604 int bcount, pcount;
605 int ret;
606
607 if (plen == blen)
608 return test_ahash_jiffies_digest(req, blen, out, secs);
609
610 for (start = jiffies, end = start + secs * HZ, bcount = 0;
611 time_before(jiffies, end); bcount++) {
612 ret = do_one_ahash_op(req, crypto_ahash_init(req));
613 if (ret)
614 return ret;
615 for (pcount = 0; pcount < blen; pcount += plen) {
616 ret = do_one_ahash_op(req, crypto_ahash_update(req));
617 if (ret)
618 return ret;
619 }
620 /* we assume there is enough space in 'out' for the result */
621 ret = do_one_ahash_op(req, crypto_ahash_final(req));
622 if (ret)
623 return ret;
624 }
625
626 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
627 bcount / secs, ((long)bcount * blen) / secs);
628
629 return 0;
630 }
631
632 static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
633 char *out)
634 {
635 unsigned long cycles = 0;
636 int ret, i;
637
638 /* Warm-up run. */
639 for (i = 0; i < 4; i++) {
640 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
641 if (ret)
642 goto out;
643 }
644
645 /* The real thing. */
646 for (i = 0; i < 8; i++) {
647 cycles_t start, end;
648
649 start = get_cycles();
650
651 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
652 if (ret)
653 goto out;
654
655 end = get_cycles();
656
657 cycles += end - start;
658 }
659
660 out:
661 if (ret)
662 return ret;
663
664 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
665 cycles / 8, cycles / (8 * blen));
666
667 return 0;
668 }
669
670 static int test_ahash_cycles(struct ahash_request *req, int blen,
671 int plen, char *out)
672 {
673 unsigned long cycles = 0;
674 int i, pcount, ret;
675
676 if (plen == blen)
677 return test_ahash_cycles_digest(req, blen, out);
678
679 /* Warm-up run. */
680 for (i = 0; i < 4; i++) {
681 ret = do_one_ahash_op(req, crypto_ahash_init(req));
682 if (ret)
683 goto out;
684 for (pcount = 0; pcount < blen; pcount += plen) {
685 ret = do_one_ahash_op(req, crypto_ahash_update(req));
686 if (ret)
687 goto out;
688 }
689 ret = do_one_ahash_op(req, crypto_ahash_final(req));
690 if (ret)
691 goto out;
692 }
693
694 /* The real thing. */
695 for (i = 0; i < 8; i++) {
696 cycles_t start, end;
697
698 start = get_cycles();
699
700 ret = do_one_ahash_op(req, crypto_ahash_init(req));
701 if (ret)
702 goto out;
703 for (pcount = 0; pcount < blen; pcount += plen) {
704 ret = do_one_ahash_op(req, crypto_ahash_update(req));
705 if (ret)
706 goto out;
707 }
708 ret = do_one_ahash_op(req, crypto_ahash_final(req));
709 if (ret)
710 goto out;
711
712 end = get_cycles();
713
714 cycles += end - start;
715 }
716
717 out:
718 if (ret)
719 return ret;
720
721 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
722 cycles / 8, cycles / (8 * blen));
723
724 return 0;
725 }
726
727 static void test_ahash_speed_common(const char *algo, unsigned int secs,
728 struct hash_speed *speed, unsigned mask)
729 {
730 struct scatterlist sg[TVMEMSIZE];
731 struct tcrypt_result tresult;
732 struct ahash_request *req;
733 struct crypto_ahash *tfm;
734 char *output;
735 int i, ret;
736
737 tfm = crypto_alloc_ahash(algo, 0, mask);
738 if (IS_ERR(tfm)) {
739 pr_err("failed to load transform for %s: %ld\n",
740 algo, PTR_ERR(tfm));
741 return;
742 }
743
744 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
745 get_driver_name(crypto_ahash, tfm));
746
747 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
748 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
749 MAX_DIGEST_SIZE);
750 goto out;
751 }
752
753 test_hash_sg_init(sg);
754 req = ahash_request_alloc(tfm, GFP_KERNEL);
755 if (!req) {
756 pr_err("ahash request allocation failure\n");
757 goto out;
758 }
759
760 init_completion(&tresult.completion);
761 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
762 tcrypt_complete, &tresult);
763
764 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
765 if (!output)
766 goto out_nomem;
767
768 for (i = 0; speed[i].blen != 0; i++) {
769 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
770 pr_err("template (%u) too big for tvmem (%lu)\n",
771 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
772 break;
773 }
774
775 pr_info("test%3u "
776 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
777 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
778
779 ahash_request_set_crypt(req, sg, output, speed[i].plen);
780
781 if (secs)
782 ret = test_ahash_jiffies(req, speed[i].blen,
783 speed[i].plen, output, secs);
784 else
785 ret = test_ahash_cycles(req, speed[i].blen,
786 speed[i].plen, output);
787
788 if (ret) {
789 pr_err("hashing failed ret=%d\n", ret);
790 break;
791 }
792 }
793
794 kfree(output);
795
796 out_nomem:
797 ahash_request_free(req);
798
799 out:
800 crypto_free_ahash(tfm);
801 }
802
803 static void test_ahash_speed(const char *algo, unsigned int secs,
804 struct hash_speed *speed)
805 {
806 return test_ahash_speed_common(algo, secs, speed, 0);
807 }
808
809 static void test_hash_speed(const char *algo, unsigned int secs,
810 struct hash_speed *speed)
811 {
812 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
813 }
814
815 static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
816 {
817 if (ret == -EINPROGRESS || ret == -EBUSY) {
818 struct tcrypt_result *tr = req->base.data;
819
820 wait_for_completion(&tr->completion);
821 reinit_completion(&tr->completion);
822 ret = tr->err;
823 }
824
825 return ret;
826 }
827
828 static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
829 int blen, int secs)
830 {
831 unsigned long start, end;
832 int bcount;
833 int ret;
834
835 for (start = jiffies, end = start + secs * HZ, bcount = 0;
836 time_before(jiffies, end); bcount++) {
837 if (enc)
838 ret = do_one_acipher_op(req,
839 crypto_ablkcipher_encrypt(req));
840 else
841 ret = do_one_acipher_op(req,
842 crypto_ablkcipher_decrypt(req));
843
844 if (ret)
845 return ret;
846 }
847
848 pr_cont("%d operations in %d seconds (%ld bytes)\n",
849 bcount, secs, (long)bcount * blen);
850 return 0;
851 }
852
853 static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
854 int blen)
855 {
856 unsigned long cycles = 0;
857 int ret = 0;
858 int i;
859
860 /* Warm-up run. */
861 for (i = 0; i < 4; i++) {
862 if (enc)
863 ret = do_one_acipher_op(req,
864 crypto_ablkcipher_encrypt(req));
865 else
866 ret = do_one_acipher_op(req,
867 crypto_ablkcipher_decrypt(req));
868
869 if (ret)
870 goto out;
871 }
872
873 /* The real thing. */
874 for (i = 0; i < 8; i++) {
875 cycles_t start, end;
876
877 start = get_cycles();
878 if (enc)
879 ret = do_one_acipher_op(req,
880 crypto_ablkcipher_encrypt(req));
881 else
882 ret = do_one_acipher_op(req,
883 crypto_ablkcipher_decrypt(req));
884 end = get_cycles();
885
886 if (ret)
887 goto out;
888
889 cycles += end - start;
890 }
891
892 out:
893 if (ret == 0)
894 pr_cont("1 operation in %lu cycles (%d bytes)\n",
895 (cycles + 4) / 8, blen);
896
897 return ret;
898 }
899
900 static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
901 struct cipher_speed_template *template,
902 unsigned int tcount, u8 *keysize)
903 {
904 unsigned int ret, i, j, k, iv_len;
905 struct tcrypt_result tresult;
906 const char *key;
907 char iv[128];
908 struct ablkcipher_request *req;
909 struct crypto_ablkcipher *tfm;
910 const char *e;
911 u32 *b_size;
912
913 if (enc == ENCRYPT)
914 e = "encryption";
915 else
916 e = "decryption";
917
918 init_completion(&tresult.completion);
919
920 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
921
922 if (IS_ERR(tfm)) {
923 pr_err("failed to load transform for %s: %ld\n", algo,
924 PTR_ERR(tfm));
925 return;
926 }
927
928 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
929 get_driver_name(crypto_ablkcipher, tfm), e);
930
931 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
932 if (!req) {
933 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
934 algo);
935 goto out;
936 }
937
938 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
939 tcrypt_complete, &tresult);
940
941 i = 0;
942 do {
943 b_size = block_sizes;
944
945 do {
946 struct scatterlist sg[TVMEMSIZE];
947
948 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
949 pr_err("template (%u) too big for "
950 "tvmem (%lu)\n", *keysize + *b_size,
951 TVMEMSIZE * PAGE_SIZE);
952 goto out_free_req;
953 }
954
955 pr_info("test %u (%d bit key, %d byte blocks): ", i,
956 *keysize * 8, *b_size);
957
958 memset(tvmem[0], 0xff, PAGE_SIZE);
959
960 /* set key, plain text and IV */
961 key = tvmem[0];
962 for (j = 0; j < tcount; j++) {
963 if (template[j].klen == *keysize) {
964 key = template[j].key;
965 break;
966 }
967 }
968
969 crypto_ablkcipher_clear_flags(tfm, ~0);
970
971 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
972 if (ret) {
973 pr_err("setkey() failed flags=%x\n",
974 crypto_ablkcipher_get_flags(tfm));
975 goto out_free_req;
976 }
977
978 k = *keysize + *b_size;
979 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
980
981 if (k > PAGE_SIZE) {
982 sg_set_buf(sg, tvmem[0] + *keysize,
983 PAGE_SIZE - *keysize);
984 k -= PAGE_SIZE;
985 j = 1;
986 while (k > PAGE_SIZE) {
987 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
988 memset(tvmem[j], 0xff, PAGE_SIZE);
989 j++;
990 k -= PAGE_SIZE;
991 }
992 sg_set_buf(sg + j, tvmem[j], k);
993 memset(tvmem[j], 0xff, k);
994 } else {
995 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
996 }
997
998 iv_len = crypto_ablkcipher_ivsize(tfm);
999 if (iv_len)
1000 memset(&iv, 0xff, iv_len);
1001
1002 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1003
1004 if (secs)
1005 ret = test_acipher_jiffies(req, enc,
1006 *b_size, secs);
1007 else
1008 ret = test_acipher_cycles(req, enc,
1009 *b_size);
1010
1011 if (ret) {
1012 pr_err("%s() failed flags=%x\n", e,
1013 crypto_ablkcipher_get_flags(tfm));
1014 break;
1015 }
1016 b_size++;
1017 i++;
1018 } while (*b_size);
1019 keysize++;
1020 } while (*keysize);
1021
1022 out_free_req:
1023 ablkcipher_request_free(req);
1024 out:
1025 crypto_free_ablkcipher(tfm);
1026 }
1027
1028 static void test_available(void)
1029 {
1030 char **name = check;
1031
1032 while (*name) {
1033 printk("alg %s ", *name);
1034 printk(crypto_has_alg(*name, 0, 0) ?
1035 "found\n" : "not found\n");
1036 name++;
1037 }
1038 }
1039
1040 static inline int tcrypt_test(const char *alg)
1041 {
1042 int ret;
1043
1044 ret = alg_test(alg, alg, 0, 0);
1045 /* non-fips algs return -EINVAL in fips mode */
1046 if (fips_enabled && ret == -EINVAL)
1047 ret = 0;
1048 return ret;
1049 }
1050
1051 static int do_test(const char *alg, u32 type, u32 mask, int m)
1052 {
1053 int i;
1054 int ret = 0;
1055
1056 switch (m) {
1057 case 0:
1058 if (alg) {
1059 if (!crypto_has_alg(alg, type,
1060 mask ?: CRYPTO_ALG_TYPE_MASK))
1061 ret = -ENOENT;
1062 break;
1063 }
1064
1065 for (i = 1; i < 200; i++)
1066 ret += do_test(NULL, 0, 0, i);
1067 break;
1068
1069 case 1:
1070 ret += tcrypt_test("md5");
1071 break;
1072
1073 case 2:
1074 ret += tcrypt_test("sha1");
1075 break;
1076
1077 case 3:
1078 ret += tcrypt_test("ecb(des)");
1079 ret += tcrypt_test("cbc(des)");
1080 ret += tcrypt_test("ctr(des)");
1081 break;
1082
1083 case 4:
1084 ret += tcrypt_test("ecb(des3_ede)");
1085 ret += tcrypt_test("cbc(des3_ede)");
1086 ret += tcrypt_test("ctr(des3_ede)");
1087 break;
1088
1089 case 5:
1090 ret += tcrypt_test("md4");
1091 break;
1092
1093 case 6:
1094 ret += tcrypt_test("sha256");
1095 break;
1096
1097 case 7:
1098 ret += tcrypt_test("ecb(blowfish)");
1099 ret += tcrypt_test("cbc(blowfish)");
1100 ret += tcrypt_test("ctr(blowfish)");
1101 break;
1102
1103 case 8:
1104 ret += tcrypt_test("ecb(twofish)");
1105 ret += tcrypt_test("cbc(twofish)");
1106 ret += tcrypt_test("ctr(twofish)");
1107 ret += tcrypt_test("lrw(twofish)");
1108 ret += tcrypt_test("xts(twofish)");
1109 break;
1110
1111 case 9:
1112 ret += tcrypt_test("ecb(serpent)");
1113 ret += tcrypt_test("cbc(serpent)");
1114 ret += tcrypt_test("ctr(serpent)");
1115 ret += tcrypt_test("lrw(serpent)");
1116 ret += tcrypt_test("xts(serpent)");
1117 break;
1118
1119 case 10:
1120 ret += tcrypt_test("ecb(aes)");
1121 ret += tcrypt_test("cbc(aes)");
1122 ret += tcrypt_test("lrw(aes)");
1123 ret += tcrypt_test("xts(aes)");
1124 ret += tcrypt_test("ctr(aes)");
1125 ret += tcrypt_test("rfc3686(ctr(aes))");
1126 break;
1127
1128 case 11:
1129 ret += tcrypt_test("sha384");
1130 break;
1131
1132 case 12:
1133 ret += tcrypt_test("sha512");
1134 break;
1135
1136 case 13:
1137 ret += tcrypt_test("deflate");
1138 break;
1139
1140 case 14:
1141 ret += tcrypt_test("ecb(cast5)");
1142 ret += tcrypt_test("cbc(cast5)");
1143 ret += tcrypt_test("ctr(cast5)");
1144 break;
1145
1146 case 15:
1147 ret += tcrypt_test("ecb(cast6)");
1148 ret += tcrypt_test("cbc(cast6)");
1149 ret += tcrypt_test("ctr(cast6)");
1150 ret += tcrypt_test("lrw(cast6)");
1151 ret += tcrypt_test("xts(cast6)");
1152 break;
1153
1154 case 16:
1155 ret += tcrypt_test("ecb(arc4)");
1156 break;
1157
1158 case 17:
1159 ret += tcrypt_test("michael_mic");
1160 break;
1161
1162 case 18:
1163 ret += tcrypt_test("crc32c");
1164 break;
1165
1166 case 19:
1167 ret += tcrypt_test("ecb(tea)");
1168 break;
1169
1170 case 20:
1171 ret += tcrypt_test("ecb(xtea)");
1172 break;
1173
1174 case 21:
1175 ret += tcrypt_test("ecb(khazad)");
1176 break;
1177
1178 case 22:
1179 ret += tcrypt_test("wp512");
1180 break;
1181
1182 case 23:
1183 ret += tcrypt_test("wp384");
1184 break;
1185
1186 case 24:
1187 ret += tcrypt_test("wp256");
1188 break;
1189
1190 case 25:
1191 ret += tcrypt_test("ecb(tnepres)");
1192 break;
1193
1194 case 26:
1195 ret += tcrypt_test("ecb(anubis)");
1196 ret += tcrypt_test("cbc(anubis)");
1197 break;
1198
1199 case 27:
1200 ret += tcrypt_test("tgr192");
1201 break;
1202
1203 case 28:
1204 ret += tcrypt_test("tgr160");
1205 break;
1206
1207 case 29:
1208 ret += tcrypt_test("tgr128");
1209 break;
1210
1211 case 30:
1212 ret += tcrypt_test("ecb(xeta)");
1213 break;
1214
1215 case 31:
1216 ret += tcrypt_test("pcbc(fcrypt)");
1217 break;
1218
1219 case 32:
1220 ret += tcrypt_test("ecb(camellia)");
1221 ret += tcrypt_test("cbc(camellia)");
1222 ret += tcrypt_test("ctr(camellia)");
1223 ret += tcrypt_test("lrw(camellia)");
1224 ret += tcrypt_test("xts(camellia)");
1225 break;
1226
1227 case 33:
1228 ret += tcrypt_test("sha224");
1229 break;
1230
1231 case 34:
1232 ret += tcrypt_test("salsa20");
1233 break;
1234
1235 case 35:
1236 ret += tcrypt_test("gcm(aes)");
1237 break;
1238
1239 case 36:
1240 ret += tcrypt_test("lzo");
1241 break;
1242
1243 case 37:
1244 ret += tcrypt_test("ccm(aes)");
1245 break;
1246
1247 case 38:
1248 ret += tcrypt_test("cts(cbc(aes))");
1249 break;
1250
1251 case 39:
1252 ret += tcrypt_test("rmd128");
1253 break;
1254
1255 case 40:
1256 ret += tcrypt_test("rmd160");
1257 break;
1258
1259 case 41:
1260 ret += tcrypt_test("rmd256");
1261 break;
1262
1263 case 42:
1264 ret += tcrypt_test("rmd320");
1265 break;
1266
1267 case 43:
1268 ret += tcrypt_test("ecb(seed)");
1269 break;
1270
1271 case 44:
1272 ret += tcrypt_test("zlib");
1273 break;
1274
1275 case 45:
1276 ret += tcrypt_test("rfc4309(ccm(aes))");
1277 break;
1278
1279 case 46:
1280 ret += tcrypt_test("ghash");
1281 break;
1282
1283 case 47:
1284 ret += tcrypt_test("crct10dif");
1285 break;
1286
1287 case 100:
1288 ret += tcrypt_test("hmac(md5)");
1289 break;
1290
1291 case 101:
1292 ret += tcrypt_test("hmac(sha1)");
1293 break;
1294
1295 case 102:
1296 ret += tcrypt_test("hmac(sha256)");
1297 break;
1298
1299 case 103:
1300 ret += tcrypt_test("hmac(sha384)");
1301 break;
1302
1303 case 104:
1304 ret += tcrypt_test("hmac(sha512)");
1305 break;
1306
1307 case 105:
1308 ret += tcrypt_test("hmac(sha224)");
1309 break;
1310
1311 case 106:
1312 ret += tcrypt_test("xcbc(aes)");
1313 break;
1314
1315 case 107:
1316 ret += tcrypt_test("hmac(rmd128)");
1317 break;
1318
1319 case 108:
1320 ret += tcrypt_test("hmac(rmd160)");
1321 break;
1322
1323 case 109:
1324 ret += tcrypt_test("vmac(aes)");
1325 break;
1326
1327 case 110:
1328 ret += tcrypt_test("hmac(crc32)");
1329 break;
1330
1331 case 150:
1332 ret += tcrypt_test("ansi_cprng");
1333 break;
1334
1335 case 151:
1336 ret += tcrypt_test("rfc4106(gcm(aes))");
1337 break;
1338
1339 case 152:
1340 ret += tcrypt_test("rfc4543(gcm(aes))");
1341 break;
1342
1343 case 153:
1344 ret += tcrypt_test("cmac(aes)");
1345 break;
1346
1347 case 154:
1348 ret += tcrypt_test("cmac(des3_ede)");
1349 break;
1350
1351 case 155:
1352 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1353 break;
1354
1355 case 156:
1356 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1357 break;
1358
1359 case 157:
1360 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1361 break;
1362 case 181:
1363 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1364 break;
1365 case 182:
1366 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1367 break;
1368 case 183:
1369 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1370 break;
1371 case 184:
1372 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1373 break;
1374 case 185:
1375 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1376 break;
1377 case 186:
1378 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1379 break;
1380 case 187:
1381 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1382 break;
1383 case 188:
1384 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1385 break;
1386 case 189:
1387 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1388 break;
1389 case 190:
1390 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1391 break;
1392 case 200:
1393 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1394 speed_template_16_24_32);
1395 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1396 speed_template_16_24_32);
1397 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1398 speed_template_16_24_32);
1399 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1400 speed_template_16_24_32);
1401 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1402 speed_template_32_40_48);
1403 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1404 speed_template_32_40_48);
1405 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1406 speed_template_32_48_64);
1407 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1408 speed_template_32_48_64);
1409 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1410 speed_template_16_24_32);
1411 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1412 speed_template_16_24_32);
1413 break;
1414
1415 case 201:
1416 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1417 des3_speed_template, DES3_SPEED_VECTORS,
1418 speed_template_24);
1419 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1420 des3_speed_template, DES3_SPEED_VECTORS,
1421 speed_template_24);
1422 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1423 des3_speed_template, DES3_SPEED_VECTORS,
1424 speed_template_24);
1425 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1426 des3_speed_template, DES3_SPEED_VECTORS,
1427 speed_template_24);
1428 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1429 des3_speed_template, DES3_SPEED_VECTORS,
1430 speed_template_24);
1431 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1432 des3_speed_template, DES3_SPEED_VECTORS,
1433 speed_template_24);
1434 break;
1435
1436 case 202:
1437 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1438 speed_template_16_24_32);
1439 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1440 speed_template_16_24_32);
1441 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1442 speed_template_16_24_32);
1443 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1444 speed_template_16_24_32);
1445 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1446 speed_template_16_24_32);
1447 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1448 speed_template_16_24_32);
1449 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1450 speed_template_32_40_48);
1451 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1452 speed_template_32_40_48);
1453 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1454 speed_template_32_48_64);
1455 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1456 speed_template_32_48_64);
1457 break;
1458
1459 case 203:
1460 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1461 speed_template_8_32);
1462 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1463 speed_template_8_32);
1464 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1465 speed_template_8_32);
1466 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1467 speed_template_8_32);
1468 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1469 speed_template_8_32);
1470 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1471 speed_template_8_32);
1472 break;
1473
1474 case 204:
1475 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1476 speed_template_8);
1477 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1478 speed_template_8);
1479 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1480 speed_template_8);
1481 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1482 speed_template_8);
1483 break;
1484
1485 case 205:
1486 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1487 speed_template_16_24_32);
1488 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1489 speed_template_16_24_32);
1490 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1491 speed_template_16_24_32);
1492 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1493 speed_template_16_24_32);
1494 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1495 speed_template_16_24_32);
1496 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1497 speed_template_16_24_32);
1498 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1499 speed_template_32_40_48);
1500 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1501 speed_template_32_40_48);
1502 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1503 speed_template_32_48_64);
1504 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1505 speed_template_32_48_64);
1506 break;
1507
1508 case 206:
1509 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1510 speed_template_16_32);
1511 break;
1512
1513 case 207:
1514 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1515 speed_template_16_32);
1516 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1517 speed_template_16_32);
1518 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1519 speed_template_16_32);
1520 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1521 speed_template_16_32);
1522 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1523 speed_template_16_32);
1524 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1525 speed_template_16_32);
1526 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1527 speed_template_32_48);
1528 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1529 speed_template_32_48);
1530 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1531 speed_template_32_64);
1532 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1533 speed_template_32_64);
1534 break;
1535
1536 case 208:
1537 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1538 speed_template_8);
1539 break;
1540
1541 case 209:
1542 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1543 speed_template_8_16);
1544 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1545 speed_template_8_16);
1546 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1547 speed_template_8_16);
1548 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1549 speed_template_8_16);
1550 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1551 speed_template_8_16);
1552 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1553 speed_template_8_16);
1554 break;
1555
1556 case 210:
1557 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1558 speed_template_16_32);
1559 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1560 speed_template_16_32);
1561 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1562 speed_template_16_32);
1563 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1564 speed_template_16_32);
1565 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1566 speed_template_16_32);
1567 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1568 speed_template_16_32);
1569 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1570 speed_template_32_48);
1571 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1572 speed_template_32_48);
1573 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1574 speed_template_32_64);
1575 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1576 speed_template_32_64);
1577 break;
1578
1579 case 211:
1580 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1581 NULL, 0, 16, 16, aead_speed_template_20);
1582 test_aead_speed("gcm(aes)", ENCRYPT, sec,
1583 NULL, 0, 16, 8, speed_template_16_24_32);
1584 break;
1585
1586 case 212:
1587 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
1588 NULL, 0, 16, 16, aead_speed_template_19);
1589 break;
1590
1591 case 213:
1592 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1593 NULL, 0, 16, 8, aead_speed_template_36);
1594 break;
1595
1596 case 214:
1597 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1598 speed_template_32);
1599 break;
1600
1601
1602 case 300:
1603 if (alg) {
1604 test_hash_speed(alg, sec, generic_hash_speed_template);
1605 break;
1606 }
1607
1608 /* fall through */
1609
1610 case 301:
1611 test_hash_speed("md4", sec, generic_hash_speed_template);
1612 if (mode > 300 && mode < 400) break;
1613
1614 case 302:
1615 test_hash_speed("md5", sec, generic_hash_speed_template);
1616 if (mode > 300 && mode < 400) break;
1617
1618 case 303:
1619 test_hash_speed("sha1", sec, generic_hash_speed_template);
1620 if (mode > 300 && mode < 400) break;
1621
1622 case 304:
1623 test_hash_speed("sha256", sec, generic_hash_speed_template);
1624 if (mode > 300 && mode < 400) break;
1625
1626 case 305:
1627 test_hash_speed("sha384", sec, generic_hash_speed_template);
1628 if (mode > 300 && mode < 400) break;
1629
1630 case 306:
1631 test_hash_speed("sha512", sec, generic_hash_speed_template);
1632 if (mode > 300 && mode < 400) break;
1633
1634 case 307:
1635 test_hash_speed("wp256", sec, generic_hash_speed_template);
1636 if (mode > 300 && mode < 400) break;
1637
1638 case 308:
1639 test_hash_speed("wp384", sec, generic_hash_speed_template);
1640 if (mode > 300 && mode < 400) break;
1641
1642 case 309:
1643 test_hash_speed("wp512", sec, generic_hash_speed_template);
1644 if (mode > 300 && mode < 400) break;
1645
1646 case 310:
1647 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1648 if (mode > 300 && mode < 400) break;
1649
1650 case 311:
1651 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1652 if (mode > 300 && mode < 400) break;
1653
1654 case 312:
1655 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1656 if (mode > 300 && mode < 400) break;
1657
1658 case 313:
1659 test_hash_speed("sha224", sec, generic_hash_speed_template);
1660 if (mode > 300 && mode < 400) break;
1661
1662 case 314:
1663 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1664 if (mode > 300 && mode < 400) break;
1665
1666 case 315:
1667 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1668 if (mode > 300 && mode < 400) break;
1669
1670 case 316:
1671 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1672 if (mode > 300 && mode < 400) break;
1673
1674 case 317:
1675 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1676 if (mode > 300 && mode < 400) break;
1677
1678 case 318:
1679 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1680 if (mode > 300 && mode < 400) break;
1681
1682 case 319:
1683 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1684 if (mode > 300 && mode < 400) break;
1685
1686 case 320:
1687 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1688 if (mode > 300 && mode < 400) break;
1689
1690 case 321:
1691 test_hash_speed("poly1305", sec, poly1305_speed_template);
1692 if (mode > 300 && mode < 400) break;
1693
1694 case 399:
1695 break;
1696
1697 case 400:
1698 if (alg) {
1699 test_ahash_speed(alg, sec, generic_hash_speed_template);
1700 break;
1701 }
1702
1703 /* fall through */
1704
1705 case 401:
1706 test_ahash_speed("md4", sec, generic_hash_speed_template);
1707 if (mode > 400 && mode < 500) break;
1708
1709 case 402:
1710 test_ahash_speed("md5", sec, generic_hash_speed_template);
1711 if (mode > 400 && mode < 500) break;
1712
1713 case 403:
1714 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1715 if (mode > 400 && mode < 500) break;
1716
1717 case 404:
1718 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1719 if (mode > 400 && mode < 500) break;
1720
1721 case 405:
1722 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1723 if (mode > 400 && mode < 500) break;
1724
1725 case 406:
1726 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1727 if (mode > 400 && mode < 500) break;
1728
1729 case 407:
1730 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1731 if (mode > 400 && mode < 500) break;
1732
1733 case 408:
1734 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1735 if (mode > 400 && mode < 500) break;
1736
1737 case 409:
1738 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1739 if (mode > 400 && mode < 500) break;
1740
1741 case 410:
1742 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1743 if (mode > 400 && mode < 500) break;
1744
1745 case 411:
1746 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1747 if (mode > 400 && mode < 500) break;
1748
1749 case 412:
1750 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1751 if (mode > 400 && mode < 500) break;
1752
1753 case 413:
1754 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1755 if (mode > 400 && mode < 500) break;
1756
1757 case 414:
1758 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1759 if (mode > 400 && mode < 500) break;
1760
1761 case 415:
1762 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1763 if (mode > 400 && mode < 500) break;
1764
1765 case 416:
1766 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1767 if (mode > 400 && mode < 500) break;
1768
1769 case 417:
1770 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1771 if (mode > 400 && mode < 500) break;
1772
1773 case 499:
1774 break;
1775
1776 case 500:
1777 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1778 speed_template_16_24_32);
1779 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1780 speed_template_16_24_32);
1781 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1782 speed_template_16_24_32);
1783 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1784 speed_template_16_24_32);
1785 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1786 speed_template_32_40_48);
1787 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1788 speed_template_32_40_48);
1789 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1790 speed_template_32_48_64);
1791 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1792 speed_template_32_48_64);
1793 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1794 speed_template_16_24_32);
1795 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1796 speed_template_16_24_32);
1797 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1798 speed_template_16_24_32);
1799 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1800 speed_template_16_24_32);
1801 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1802 speed_template_16_24_32);
1803 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1804 speed_template_16_24_32);
1805 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1806 speed_template_20_28_36);
1807 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1808 speed_template_20_28_36);
1809 break;
1810
1811 case 501:
1812 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1813 des3_speed_template, DES3_SPEED_VECTORS,
1814 speed_template_24);
1815 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1816 des3_speed_template, DES3_SPEED_VECTORS,
1817 speed_template_24);
1818 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1819 des3_speed_template, DES3_SPEED_VECTORS,
1820 speed_template_24);
1821 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1822 des3_speed_template, DES3_SPEED_VECTORS,
1823 speed_template_24);
1824 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1825 des3_speed_template, DES3_SPEED_VECTORS,
1826 speed_template_24);
1827 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1828 des3_speed_template, DES3_SPEED_VECTORS,
1829 speed_template_24);
1830 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1831 des3_speed_template, DES3_SPEED_VECTORS,
1832 speed_template_24);
1833 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1834 des3_speed_template, DES3_SPEED_VECTORS,
1835 speed_template_24);
1836 break;
1837
1838 case 502:
1839 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1840 speed_template_8);
1841 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1842 speed_template_8);
1843 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1844 speed_template_8);
1845 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1846 speed_template_8);
1847 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1848 speed_template_8);
1849 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1850 speed_template_8);
1851 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1852 speed_template_8);
1853 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1854 speed_template_8);
1855 break;
1856
1857 case 503:
1858 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1859 speed_template_16_32);
1860 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1861 speed_template_16_32);
1862 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1863 speed_template_16_32);
1864 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1865 speed_template_16_32);
1866 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1867 speed_template_16_32);
1868 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1869 speed_template_16_32);
1870 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1871 speed_template_32_48);
1872 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1873 speed_template_32_48);
1874 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1875 speed_template_32_64);
1876 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1877 speed_template_32_64);
1878 break;
1879
1880 case 504:
1881 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1882 speed_template_16_24_32);
1883 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1884 speed_template_16_24_32);
1885 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1886 speed_template_16_24_32);
1887 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1888 speed_template_16_24_32);
1889 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1890 speed_template_16_24_32);
1891 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1892 speed_template_16_24_32);
1893 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1894 speed_template_32_40_48);
1895 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1896 speed_template_32_40_48);
1897 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1898 speed_template_32_48_64);
1899 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1900 speed_template_32_48_64);
1901 break;
1902
1903 case 505:
1904 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1905 speed_template_8);
1906 break;
1907
1908 case 506:
1909 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1910 speed_template_8_16);
1911 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1912 speed_template_8_16);
1913 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1914 speed_template_8_16);
1915 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1916 speed_template_8_16);
1917 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1918 speed_template_8_16);
1919 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1920 speed_template_8_16);
1921 break;
1922
1923 case 507:
1924 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1925 speed_template_16_32);
1926 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1927 speed_template_16_32);
1928 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1929 speed_template_16_32);
1930 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1931 speed_template_16_32);
1932 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1933 speed_template_16_32);
1934 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1935 speed_template_16_32);
1936 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1937 speed_template_32_48);
1938 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1939 speed_template_32_48);
1940 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1941 speed_template_32_64);
1942 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1943 speed_template_32_64);
1944 break;
1945
1946 case 508:
1947 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1948 speed_template_16_32);
1949 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1950 speed_template_16_32);
1951 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1952 speed_template_16_32);
1953 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1954 speed_template_16_32);
1955 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1956 speed_template_16_32);
1957 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1958 speed_template_16_32);
1959 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1960 speed_template_32_48);
1961 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1962 speed_template_32_48);
1963 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1964 speed_template_32_64);
1965 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1966 speed_template_32_64);
1967 break;
1968
1969 case 509:
1970 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1971 speed_template_8_32);
1972 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1973 speed_template_8_32);
1974 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1975 speed_template_8_32);
1976 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1977 speed_template_8_32);
1978 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1979 speed_template_8_32);
1980 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1981 speed_template_8_32);
1982 break;
1983
1984 case 1000:
1985 test_available();
1986 break;
1987 }
1988
1989 return ret;
1990 }
1991
1992 static int __init tcrypt_mod_init(void)
1993 {
1994 int err = -ENOMEM;
1995 int i;
1996
1997 for (i = 0; i < TVMEMSIZE; i++) {
1998 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
1999 if (!tvmem[i])
2000 goto err_free_tv;
2001 }
2002
2003 err = do_test(alg, type, mask, mode);
2004
2005 if (err) {
2006 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2007 goto err_free_tv;
2008 }
2009
2010 /* We intentionaly return -EAGAIN to prevent keeping the module,
2011 * unless we're running in fips mode. It does all its work from
2012 * init() and doesn't offer any runtime functionality, but in
2013 * the fips case, checking for a successful load is helpful.
2014 * => we don't need it in the memory, do we?
2015 * -- mludvig
2016 */
2017 if (!fips_enabled)
2018 err = -EAGAIN;
2019
2020 err_free_tv:
2021 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2022 free_page((unsigned long)tvmem[i]);
2023
2024 return err;
2025 }
2026
2027 /*
2028 * If an init function is provided, an exit function must also be provided
2029 * to allow module unload.
2030 */
2031 static void __exit tcrypt_mod_fini(void) { }
2032
2033 module_init(tcrypt_mod_init);
2034 module_exit(tcrypt_mod_fini);
2035
2036 module_param(alg, charp, 0);
2037 module_param(type, uint, 0);
2038 module_param(mask, uint, 0);
2039 module_param(mode, int, 0);
2040 module_param(sec, uint, 0);
2041 MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2042 "(defaults to zero which uses CPU cycles instead)");
2043
2044 MODULE_LICENSE("GPL");
2045 MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2046 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
This page took 0.097769 seconds and 5 git commands to generate.