Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Quick & dirty crypto testing module.
4 *
5 * This will only exist until we have a better testing mechanism
6 * (e.g. a char device).
7 *
8 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
9 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
10 * Copyright (c) 2007 Nokia Siemens Networks
11 *
12 * Updated RFC4106 AES-GCM testing.
13 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
14 * Adrian Hoban <adrian.hoban@intel.com>
15 * Gabriele Paoloni <gabriele.paoloni@intel.com>
16 * Tadeusz Struk (tadeusz.struk@intel.com)
17 * Copyright (c) 2010, Intel Corporation.
18 */
19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
22#include <crypto/aead.h>
23#include <crypto/hash.h>
24#include <crypto/skcipher.h>
25#include <linux/err.h>
26#include <linux/fips.h>
27#include <linux/init.h>
28#include <linux/interrupt.h>
29#include <linux/jiffies.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/moduleparam.h>
33#include <linux/scatterlist.h>
34#include <linux/slab.h>
35#include <linux/string.h>
36#include <linux/timex.h>
37
38#include "internal.h"
39#include "tcrypt.h"
40
41/*
42 * Need slab memory for testing (size in number of pages).
43 */
44#define TVMEMSIZE 4
45
46/*
47* Used by test_cipher_speed()
48*/
49#define ENCRYPT 1
50#define DECRYPT 0
51
52#define MAX_DIGEST_SIZE 64
53
54/*
55 * return a string with the driver name
56 */
57#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
58
59/*
60 * Used by test_cipher_speed()
61 */
62static unsigned int sec;
63
64static char *alg;
65static u32 type;
66static u32 mask;
67static int mode;
68static u32 num_mb = 8;
69static unsigned int klen;
70static char *tvmem[TVMEMSIZE];
71
72static const int block_sizes[] = { 16, 64, 128, 256, 1024, 1420, 4096, 0 };
73static const int aead_sizes[] = { 16, 64, 256, 512, 1024, 1420, 4096, 8192, 0 };
74
75#define XBUFSIZE 8
76#define MAX_IVLEN 32
77
78static int testmgr_alloc_buf(char *buf[XBUFSIZE])
79{
80 int i;
81
82 for (i = 0; i < XBUFSIZE; i++) {
83 buf[i] = (void *)__get_free_page(GFP_KERNEL);
84 if (!buf[i])
85 goto err_free_buf;
86 }
87
88 return 0;
89
90err_free_buf:
91 while (i-- > 0)
92 free_page((unsigned long)buf[i]);
93
94 return -ENOMEM;
95}
96
97static void testmgr_free_buf(char *buf[XBUFSIZE])
98{
99 int i;
100
101 for (i = 0; i < XBUFSIZE; i++)
102 free_page((unsigned long)buf[i]);
103}
104
105static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
106 unsigned int buflen, const void *assoc,
107 unsigned int aad_size)
108{
109 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
110 int k, rem;
111
112 if (np > XBUFSIZE) {
113 rem = PAGE_SIZE;
114 np = XBUFSIZE;
115 } else {
116 rem = buflen % PAGE_SIZE;
117 }
118
119 sg_init_table(sg, np + 1);
120
121 sg_set_buf(&sg[0], assoc, aad_size);
122
123 if (rem)
124 np--;
125 for (k = 0; k < np; k++)
126 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
127
128 if (rem)
129 sg_set_buf(&sg[k + 1], xbuf[k], rem);
130}
131
132static inline int do_one_aead_op(struct aead_request *req, int ret)
133{
134 struct crypto_wait *wait = req->base.data;
135
136 return crypto_wait_req(ret, wait);
137}
138
139struct test_mb_aead_data {
140 struct scatterlist sg[XBUFSIZE];
141 struct scatterlist sgout[XBUFSIZE];
142 struct aead_request *req;
143 struct crypto_wait wait;
144 char *xbuf[XBUFSIZE];
145 char *xoutbuf[XBUFSIZE];
146 char *axbuf[XBUFSIZE];
147};
148
149static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
150 u32 num_mb, int *rc)
151{
152 int i, err = 0;
153
154 /* Fire up a bunch of concurrent requests */
155 for (i = 0; i < num_mb; i++) {
156 if (enc == ENCRYPT)
157 rc[i] = crypto_aead_encrypt(data[i].req);
158 else
159 rc[i] = crypto_aead_decrypt(data[i].req);
160 }
161
162 /* Wait for all requests to finish */
163 for (i = 0; i < num_mb; i++) {
164 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
165
166 if (rc[i]) {
167 pr_info("concurrent request %d error %d\n", i, rc[i]);
168 err = rc[i];
169 }
170 }
171
172 return err;
173}
174
175static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
176 int blen, int secs, u32 num_mb)
177{
178 unsigned long start, end;
179 int bcount;
180 int ret = 0;
181 int *rc;
182
183 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
184 if (!rc)
185 return -ENOMEM;
186
187 for (start = jiffies, end = start + secs * HZ, bcount = 0;
188 time_before(jiffies, end); bcount++) {
189 ret = do_mult_aead_op(data, enc, num_mb, rc);
190 if (ret)
191 goto out;
192 }
193
194 pr_cont("%d operations in %d seconds (%llu bytes)\n",
195 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
196
197out:
198 kfree(rc);
199 return ret;
200}
201
202static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
203 int blen, u32 num_mb)
204{
205 unsigned long cycles = 0;
206 int ret = 0;
207 int i;
208 int *rc;
209
210 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
211 if (!rc)
212 return -ENOMEM;
213
214 /* Warm-up run. */
215 for (i = 0; i < 4; i++) {
216 ret = do_mult_aead_op(data, enc, num_mb, rc);
217 if (ret)
218 goto out;
219 }
220
221 /* The real thing. */
222 for (i = 0; i < 8; i++) {
223 cycles_t start, end;
224
225 start = get_cycles();
226 ret = do_mult_aead_op(data, enc, num_mb, rc);
227 end = get_cycles();
228
229 if (ret)
230 goto out;
231
232 cycles += end - start;
233 }
234
235 pr_cont("1 operation in %lu cycles (%d bytes)\n",
236 (cycles + 4) / (8 * num_mb), blen);
237
238out:
239 kfree(rc);
240 return ret;
241}
242
243static void test_mb_aead_speed(const char *algo, int enc, int secs,
244 struct aead_speed_template *template,
245 unsigned int tcount, u8 authsize,
246 unsigned int aad_size, u8 *keysize, u32 num_mb)
247{
248 struct test_mb_aead_data *data;
249 struct crypto_aead *tfm;
250 unsigned int i, j, iv_len;
251 const int *b_size;
252 const char *key;
253 const char *e;
254 void *assoc;
255 char *iv;
256 int ret;
257
258
259 if (aad_size >= PAGE_SIZE) {
260 pr_err("associate data length (%u) too big\n", aad_size);
261 return;
262 }
263
264 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
265 if (!iv)
266 return;
267
268 if (enc == ENCRYPT)
269 e = "encryption";
270 else
271 e = "decryption";
272
273 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
274 if (!data)
275 goto out_free_iv;
276
277 tfm = crypto_alloc_aead(algo, 0, 0);
278 if (IS_ERR(tfm)) {
279 pr_err("failed to load transform for %s: %ld\n",
280 algo, PTR_ERR(tfm));
281 goto out_free_data;
282 }
283
284 ret = crypto_aead_setauthsize(tfm, authsize);
285 if (ret) {
286 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
287 ret);
288 goto out_free_tfm;
289 }
290
291 for (i = 0; i < num_mb; ++i)
292 if (testmgr_alloc_buf(data[i].xbuf)) {
293 while (i--)
294 testmgr_free_buf(data[i].xbuf);
295 goto out_free_tfm;
296 }
297
298 for (i = 0; i < num_mb; ++i)
299 if (testmgr_alloc_buf(data[i].axbuf)) {
300 while (i--)
301 testmgr_free_buf(data[i].axbuf);
302 goto out_free_xbuf;
303 }
304
305 for (i = 0; i < num_mb; ++i)
306 if (testmgr_alloc_buf(data[i].xoutbuf)) {
307 while (i--)
308 testmgr_free_buf(data[i].xoutbuf);
309 goto out_free_axbuf;
310 }
311
312 for (i = 0; i < num_mb; ++i) {
313 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
314 if (!data[i].req) {
315 pr_err("alg: aead: Failed to allocate request for %s\n",
316 algo);
317 while (i--)
318 aead_request_free(data[i].req);
319 goto out_free_xoutbuf;
320 }
321 }
322
323 for (i = 0; i < num_mb; ++i) {
324 crypto_init_wait(&data[i].wait);
325 aead_request_set_callback(data[i].req,
326 CRYPTO_TFM_REQ_MAY_BACKLOG,
327 crypto_req_done, &data[i].wait);
328 }
329
330 pr_info("testing speed of multibuffer %s (%s) %s\n", algo,
331 get_driver_name(crypto_aead, tfm), e);
332
333 i = 0;
334 do {
335 b_size = aead_sizes;
336 do {
337 int bs = round_up(*b_size, crypto_aead_blocksize(tfm));
338
339 if (bs + authsize > XBUFSIZE * PAGE_SIZE) {
340 pr_err("template (%u) too big for buffer (%lu)\n",
341 authsize + bs,
342 XBUFSIZE * PAGE_SIZE);
343 goto out;
344 }
345
346 pr_info("test %u (%d bit key, %d byte blocks): ", i,
347 *keysize * 8, bs);
348
349 /* Set up tfm global state, i.e. the key */
350
351 memset(tvmem[0], 0xff, PAGE_SIZE);
352 key = tvmem[0];
353 for (j = 0; j < tcount; j++) {
354 if (template[j].klen == *keysize) {
355 key = template[j].key;
356 break;
357 }
358 }
359
360 crypto_aead_clear_flags(tfm, ~0);
361
362 ret = crypto_aead_setkey(tfm, key, *keysize);
363 if (ret) {
364 pr_err("setkey() failed flags=%x\n",
365 crypto_aead_get_flags(tfm));
366 goto out;
367 }
368
369 iv_len = crypto_aead_ivsize(tfm);
370 if (iv_len)
371 memset(iv, 0xff, iv_len);
372
373 /* Now setup per request stuff, i.e. buffers */
374
375 for (j = 0; j < num_mb; ++j) {
376 struct test_mb_aead_data *cur = &data[j];
377
378 assoc = cur->axbuf[0];
379 memset(assoc, 0xff, aad_size);
380
381 sg_init_aead(cur->sg, cur->xbuf,
382 bs + (enc ? 0 : authsize),
383 assoc, aad_size);
384
385 sg_init_aead(cur->sgout, cur->xoutbuf,
386 bs + (enc ? authsize : 0),
387 assoc, aad_size);
388
389 aead_request_set_ad(cur->req, aad_size);
390
391 if (!enc) {
392
393 aead_request_set_crypt(cur->req,
394 cur->sgout,
395 cur->sg,
396 bs, iv);
397 ret = crypto_aead_encrypt(cur->req);
398 ret = do_one_aead_op(cur->req, ret);
399
400 if (ret) {
401 pr_err("calculating auth failed (%d)\n",
402 ret);
403 break;
404 }
405 }
406
407 aead_request_set_crypt(cur->req, cur->sg,
408 cur->sgout, bs +
409 (enc ? 0 : authsize),
410 iv);
411
412 }
413
414 if (secs) {
415 ret = test_mb_aead_jiffies(data, enc, bs,
416 secs, num_mb);
417 cond_resched();
418 } else {
419 ret = test_mb_aead_cycles(data, enc, bs,
420 num_mb);
421 }
422
423 if (ret) {
424 pr_err("%s() failed return code=%d\n", e, ret);
425 break;
426 }
427 b_size++;
428 i++;
429 } while (*b_size);
430 keysize++;
431 } while (*keysize);
432
433out:
434 for (i = 0; i < num_mb; ++i)
435 aead_request_free(data[i].req);
436out_free_xoutbuf:
437 for (i = 0; i < num_mb; ++i)
438 testmgr_free_buf(data[i].xoutbuf);
439out_free_axbuf:
440 for (i = 0; i < num_mb; ++i)
441 testmgr_free_buf(data[i].axbuf);
442out_free_xbuf:
443 for (i = 0; i < num_mb; ++i)
444 testmgr_free_buf(data[i].xbuf);
445out_free_tfm:
446 crypto_free_aead(tfm);
447out_free_data:
448 kfree(data);
449out_free_iv:
450 kfree(iv);
451}
452
453static int test_aead_jiffies(struct aead_request *req, int enc,
454 int blen, int secs)
455{
456 unsigned long start, end;
457 int bcount;
458 int ret;
459
460 for (start = jiffies, end = start + secs * HZ, bcount = 0;
461 time_before(jiffies, end); bcount++) {
462 if (enc)
463 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
464 else
465 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
466
467 if (ret)
468 return ret;
469 }
470
471 pr_cont("%d operations in %d seconds (%llu bytes)\n",
472 bcount, secs, (u64)bcount * blen);
473 return 0;
474}
475
476static int test_aead_cycles(struct aead_request *req, int enc, int blen)
477{
478 unsigned long cycles = 0;
479 int ret = 0;
480 int i;
481
482 /* Warm-up run. */
483 for (i = 0; i < 4; i++) {
484 if (enc)
485 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
486 else
487 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
488
489 if (ret)
490 goto out;
491 }
492
493 /* The real thing. */
494 for (i = 0; i < 8; i++) {
495 cycles_t start, end;
496
497 start = get_cycles();
498 if (enc)
499 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
500 else
501 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
502 end = get_cycles();
503
504 if (ret)
505 goto out;
506
507 cycles += end - start;
508 }
509
510out:
511 if (ret == 0)
512 pr_cont("1 operation in %lu cycles (%d bytes)\n",
513 (cycles + 4) / 8, blen);
514
515 return ret;
516}
517
518static void test_aead_speed(const char *algo, int enc, unsigned int secs,
519 struct aead_speed_template *template,
520 unsigned int tcount, u8 authsize,
521 unsigned int aad_size, u8 *keysize)
522{
523 unsigned int i, j;
524 struct crypto_aead *tfm;
525 int ret = -ENOMEM;
526 const char *key;
527 struct aead_request *req;
528 struct scatterlist *sg;
529 struct scatterlist *sgout;
530 const char *e;
531 void *assoc;
532 char *iv;
533 char *xbuf[XBUFSIZE];
534 char *xoutbuf[XBUFSIZE];
535 char *axbuf[XBUFSIZE];
536 const int *b_size;
537 unsigned int iv_len;
538 struct crypto_wait wait;
539
540 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
541 if (!iv)
542 return;
543
544 if (aad_size >= PAGE_SIZE) {
545 pr_err("associate data length (%u) too big\n", aad_size);
546 goto out_noxbuf;
547 }
548
549 if (enc == ENCRYPT)
550 e = "encryption";
551 else
552 e = "decryption";
553
554 if (testmgr_alloc_buf(xbuf))
555 goto out_noxbuf;
556 if (testmgr_alloc_buf(axbuf))
557 goto out_noaxbuf;
558 if (testmgr_alloc_buf(xoutbuf))
559 goto out_nooutbuf;
560
561 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
562 if (!sg)
563 goto out_nosg;
564 sgout = &sg[9];
565
566 tfm = crypto_alloc_aead(algo, 0, 0);
567 if (IS_ERR(tfm)) {
568 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
569 PTR_ERR(tfm));
570 goto out_notfm;
571 }
572
573 ret = crypto_aead_setauthsize(tfm, authsize);
574 if (ret) {
575 pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo,
576 ret);
577 goto out_noreq;
578 }
579
580 crypto_init_wait(&wait);
581 pr_info("testing speed of %s (%s) %s\n", algo,
582 get_driver_name(crypto_aead, tfm), e);
583
584 req = aead_request_alloc(tfm, GFP_KERNEL);
585 if (!req) {
586 pr_err("alg: aead: Failed to allocate request for %s\n",
587 algo);
588 goto out_noreq;
589 }
590
591 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
592 crypto_req_done, &wait);
593
594 i = 0;
595 do {
596 b_size = aead_sizes;
597 do {
598 u32 bs = round_up(*b_size, crypto_aead_blocksize(tfm));
599
600 assoc = axbuf[0];
601 memset(assoc, 0xff, aad_size);
602
603 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
604 pr_err("template (%u) too big for tvmem (%lu)\n",
605 *keysize + bs,
606 TVMEMSIZE * PAGE_SIZE);
607 goto out;
608 }
609
610 key = tvmem[0];
611 for (j = 0; j < tcount; j++) {
612 if (template[j].klen == *keysize) {
613 key = template[j].key;
614 break;
615 }
616 }
617
618 ret = crypto_aead_setkey(tfm, key, *keysize);
619 if (ret) {
620 pr_err("setkey() failed flags=%x: %d\n",
621 crypto_aead_get_flags(tfm), ret);
622 goto out;
623 }
624
625 iv_len = crypto_aead_ivsize(tfm);
626 if (iv_len)
627 memset(iv, 0xff, iv_len);
628
629 crypto_aead_clear_flags(tfm, ~0);
630 pr_info("test %u (%d bit key, %d byte blocks): ",
631 i, *keysize * 8, bs);
632
633 memset(tvmem[0], 0xff, PAGE_SIZE);
634
635 sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize),
636 assoc, aad_size);
637
638 sg_init_aead(sgout, xoutbuf,
639 bs + (enc ? authsize : 0), assoc,
640 aad_size);
641
642 aead_request_set_ad(req, aad_size);
643
644 if (!enc) {
645
646 /*
647 * For decryption we need a proper auth so
648 * we do the encryption path once with buffers
649 * reversed (input <-> output) to calculate it
650 */
651 aead_request_set_crypt(req, sgout, sg,
652 bs, iv);
653 ret = do_one_aead_op(req,
654 crypto_aead_encrypt(req));
655
656 if (ret) {
657 pr_err("calculating auth failed (%d)\n",
658 ret);
659 break;
660 }
661 }
662
663 aead_request_set_crypt(req, sg, sgout,
664 bs + (enc ? 0 : authsize),
665 iv);
666
667 if (secs) {
668 ret = test_aead_jiffies(req, enc, bs,
669 secs);
670 cond_resched();
671 } else {
672 ret = test_aead_cycles(req, enc, bs);
673 }
674
675 if (ret) {
676 pr_err("%s() failed return code=%d\n", e, ret);
677 break;
678 }
679 b_size++;
680 i++;
681 } while (*b_size);
682 keysize++;
683 } while (*keysize);
684
685out:
686 aead_request_free(req);
687out_noreq:
688 crypto_free_aead(tfm);
689out_notfm:
690 kfree(sg);
691out_nosg:
692 testmgr_free_buf(xoutbuf);
693out_nooutbuf:
694 testmgr_free_buf(axbuf);
695out_noaxbuf:
696 testmgr_free_buf(xbuf);
697out_noxbuf:
698 kfree(iv);
699}
700
701static void test_hash_sg_init(struct scatterlist *sg)
702{
703 int i;
704
705 sg_init_table(sg, TVMEMSIZE);
706 for (i = 0; i < TVMEMSIZE; i++) {
707 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
708 memset(tvmem[i], 0xff, PAGE_SIZE);
709 }
710}
711
712static inline int do_one_ahash_op(struct ahash_request *req, int ret)
713{
714 struct crypto_wait *wait = req->base.data;
715
716 return crypto_wait_req(ret, wait);
717}
718
719static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
720 char *out, int secs)
721{
722 unsigned long start, end;
723 int bcount;
724 int ret;
725
726 for (start = jiffies, end = start + secs * HZ, bcount = 0;
727 time_before(jiffies, end); bcount++) {
728 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
729 if (ret)
730 return ret;
731 }
732
733 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
734 bcount / secs, ((long)bcount * blen) / secs);
735
736 return 0;
737}
738
739static int test_ahash_jiffies(struct ahash_request *req, int blen,
740 int plen, char *out, int secs)
741{
742 unsigned long start, end;
743 int bcount, pcount;
744 int ret;
745
746 if (plen == blen)
747 return test_ahash_jiffies_digest(req, blen, out, secs);
748
749 for (start = jiffies, end = start + secs * HZ, bcount = 0;
750 time_before(jiffies, end); bcount++) {
751 ret = do_one_ahash_op(req, crypto_ahash_init(req));
752 if (ret)
753 return ret;
754 for (pcount = 0; pcount < blen; pcount += plen) {
755 ret = do_one_ahash_op(req, crypto_ahash_update(req));
756 if (ret)
757 return ret;
758 }
759 /* we assume there is enough space in 'out' for the result */
760 ret = do_one_ahash_op(req, crypto_ahash_final(req));
761 if (ret)
762 return ret;
763 }
764
765 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
766 bcount / secs, ((long)bcount * blen) / secs);
767
768 return 0;
769}
770
771static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
772 char *out)
773{
774 unsigned long cycles = 0;
775 int ret, i;
776
777 /* Warm-up run. */
778 for (i = 0; i < 4; i++) {
779 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
780 if (ret)
781 goto out;
782 }
783
784 /* The real thing. */
785 for (i = 0; i < 8; i++) {
786 cycles_t start, end;
787
788 start = get_cycles();
789
790 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
791 if (ret)
792 goto out;
793
794 end = get_cycles();
795
796 cycles += end - start;
797 }
798
799out:
800 if (ret)
801 return ret;
802
803 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
804 cycles / 8, cycles / (8 * blen));
805
806 return 0;
807}
808
809static int test_ahash_cycles(struct ahash_request *req, int blen,
810 int plen, char *out)
811{
812 unsigned long cycles = 0;
813 int i, pcount, ret;
814
815 if (plen == blen)
816 return test_ahash_cycles_digest(req, blen, out);
817
818 /* Warm-up run. */
819 for (i = 0; i < 4; i++) {
820 ret = do_one_ahash_op(req, crypto_ahash_init(req));
821 if (ret)
822 goto out;
823 for (pcount = 0; pcount < blen; pcount += plen) {
824 ret = do_one_ahash_op(req, crypto_ahash_update(req));
825 if (ret)
826 goto out;
827 }
828 ret = do_one_ahash_op(req, crypto_ahash_final(req));
829 if (ret)
830 goto out;
831 }
832
833 /* The real thing. */
834 for (i = 0; i < 8; i++) {
835 cycles_t start, end;
836
837 start = get_cycles();
838
839 ret = do_one_ahash_op(req, crypto_ahash_init(req));
840 if (ret)
841 goto out;
842 for (pcount = 0; pcount < blen; pcount += plen) {
843 ret = do_one_ahash_op(req, crypto_ahash_update(req));
844 if (ret)
845 goto out;
846 }
847 ret = do_one_ahash_op(req, crypto_ahash_final(req));
848 if (ret)
849 goto out;
850
851 end = get_cycles();
852
853 cycles += end - start;
854 }
855
856out:
857 if (ret)
858 return ret;
859
860 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
861 cycles / 8, cycles / (8 * blen));
862
863 return 0;
864}
865
866static void test_ahash_speed_common(const char *algo, unsigned int secs,
867 struct hash_speed *speed, unsigned mask)
868{
869 struct scatterlist sg[TVMEMSIZE];
870 struct crypto_wait wait;
871 struct ahash_request *req;
872 struct crypto_ahash *tfm;
873 char *output;
874 int i, ret;
875
876 tfm = crypto_alloc_ahash(algo, 0, mask);
877 if (IS_ERR(tfm)) {
878 pr_err("failed to load transform for %s: %ld\n",
879 algo, PTR_ERR(tfm));
880 return;
881 }
882
883 pr_info("testing speed of async %s (%s)\n", algo,
884 get_driver_name(crypto_ahash, tfm));
885
886 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
887 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
888 MAX_DIGEST_SIZE);
889 goto out;
890 }
891
892 test_hash_sg_init(sg);
893 req = ahash_request_alloc(tfm, GFP_KERNEL);
894 if (!req) {
895 pr_err("ahash request allocation failure\n");
896 goto out;
897 }
898
899 crypto_init_wait(&wait);
900 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
901 crypto_req_done, &wait);
902
903 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
904 if (!output)
905 goto out_nomem;
906
907 for (i = 0; speed[i].blen != 0; i++) {
908 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
909 pr_err("template (%u) too big for tvmem (%lu)\n",
910 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
911 break;
912 }
913
914 if (klen)
915 crypto_ahash_setkey(tfm, tvmem[0], klen);
916
917 pr_info("test%3u "
918 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
919 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
920
921 ahash_request_set_crypt(req, sg, output, speed[i].plen);
922
923 if (secs) {
924 ret = test_ahash_jiffies(req, speed[i].blen,
925 speed[i].plen, output, secs);
926 cond_resched();
927 } else {
928 ret = test_ahash_cycles(req, speed[i].blen,
929 speed[i].plen, output);
930 }
931
932 if (ret) {
933 pr_err("hashing failed ret=%d\n", ret);
934 break;
935 }
936 }
937
938 kfree(output);
939
940out_nomem:
941 ahash_request_free(req);
942
943out:
944 crypto_free_ahash(tfm);
945}
946
947static void test_ahash_speed(const char *algo, unsigned int secs,
948 struct hash_speed *speed)
949{
950 return test_ahash_speed_common(algo, secs, speed, 0);
951}
952
953static void test_hash_speed(const char *algo, unsigned int secs,
954 struct hash_speed *speed)
955{
956 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
957}
958
959struct test_mb_skcipher_data {
960 struct scatterlist sg[XBUFSIZE];
961 struct skcipher_request *req;
962 struct crypto_wait wait;
963 char *xbuf[XBUFSIZE];
964};
965
966static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
967 u32 num_mb, int *rc)
968{
969 int i, err = 0;
970
971 /* Fire up a bunch of concurrent requests */
972 for (i = 0; i < num_mb; i++) {
973 if (enc == ENCRYPT)
974 rc[i] = crypto_skcipher_encrypt(data[i].req);
975 else
976 rc[i] = crypto_skcipher_decrypt(data[i].req);
977 }
978
979 /* Wait for all requests to finish */
980 for (i = 0; i < num_mb; i++) {
981 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
982
983 if (rc[i]) {
984 pr_info("concurrent request %d error %d\n", i, rc[i]);
985 err = rc[i];
986 }
987 }
988
989 return err;
990}
991
992static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
993 int blen, int secs, u32 num_mb)
994{
995 unsigned long start, end;
996 int bcount;
997 int ret = 0;
998 int *rc;
999
1000 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1001 if (!rc)
1002 return -ENOMEM;
1003
1004 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1005 time_before(jiffies, end); bcount++) {
1006 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1007 if (ret)
1008 goto out;
1009 }
1010
1011 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1012 bcount * num_mb, secs, (u64)bcount * blen * num_mb);
1013
1014out:
1015 kfree(rc);
1016 return ret;
1017}
1018
1019static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1020 int blen, u32 num_mb)
1021{
1022 unsigned long cycles = 0;
1023 int ret = 0;
1024 int i;
1025 int *rc;
1026
1027 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1028 if (!rc)
1029 return -ENOMEM;
1030
1031 /* Warm-up run. */
1032 for (i = 0; i < 4; i++) {
1033 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1034 if (ret)
1035 goto out;
1036 }
1037
1038 /* The real thing. */
1039 for (i = 0; i < 8; i++) {
1040 cycles_t start, end;
1041
1042 start = get_cycles();
1043 ret = do_mult_acipher_op(data, enc, num_mb, rc);
1044 end = get_cycles();
1045
1046 if (ret)
1047 goto out;
1048
1049 cycles += end - start;
1050 }
1051
1052 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1053 (cycles + 4) / (8 * num_mb), blen);
1054
1055out:
1056 kfree(rc);
1057 return ret;
1058}
1059
1060static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1061 struct cipher_speed_template *template,
1062 unsigned int tcount, u8 *keysize, u32 num_mb)
1063{
1064 struct test_mb_skcipher_data *data;
1065 struct crypto_skcipher *tfm;
1066 unsigned int i, j, iv_len;
1067 const int *b_size;
1068 const char *key;
1069 const char *e;
1070 char iv[128];
1071 int ret;
1072
1073 if (enc == ENCRYPT)
1074 e = "encryption";
1075 else
1076 e = "decryption";
1077
1078 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1079 if (!data)
1080 return;
1081
1082 tfm = crypto_alloc_skcipher(algo, 0, 0);
1083 if (IS_ERR(tfm)) {
1084 pr_err("failed to load transform for %s: %ld\n",
1085 algo, PTR_ERR(tfm));
1086 goto out_free_data;
1087 }
1088
1089 for (i = 0; i < num_mb; ++i)
1090 if (testmgr_alloc_buf(data[i].xbuf)) {
1091 while (i--)
1092 testmgr_free_buf(data[i].xbuf);
1093 goto out_free_tfm;
1094 }
1095
1096 for (i = 0; i < num_mb; ++i) {
1097 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1098 if (!data[i].req) {
1099 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1100 algo);
1101 while (i--)
1102 skcipher_request_free(data[i].req);
1103 goto out_free_xbuf;
1104 }
1105 }
1106
1107 for (i = 0; i < num_mb; ++i) {
1108 skcipher_request_set_callback(data[i].req,
1109 CRYPTO_TFM_REQ_MAY_BACKLOG,
1110 crypto_req_done, &data[i].wait);
1111 crypto_init_wait(&data[i].wait);
1112 }
1113
1114 pr_info("testing speed of multibuffer %s (%s) %s\n", algo,
1115 get_driver_name(crypto_skcipher, tfm), e);
1116
1117 i = 0;
1118 do {
1119 b_size = block_sizes;
1120 do {
1121 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1122
1123 if (bs > XBUFSIZE * PAGE_SIZE) {
1124 pr_err("template (%u) too big for buffer (%lu)\n",
1125 bs, XBUFSIZE * PAGE_SIZE);
1126 goto out;
1127 }
1128
1129 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1130 *keysize * 8, bs);
1131
1132 /* Set up tfm global state, i.e. the key */
1133
1134 memset(tvmem[0], 0xff, PAGE_SIZE);
1135 key = tvmem[0];
1136 for (j = 0; j < tcount; j++) {
1137 if (template[j].klen == *keysize) {
1138 key = template[j].key;
1139 break;
1140 }
1141 }
1142
1143 crypto_skcipher_clear_flags(tfm, ~0);
1144
1145 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1146 if (ret) {
1147 pr_err("setkey() failed flags=%x\n",
1148 crypto_skcipher_get_flags(tfm));
1149 goto out;
1150 }
1151
1152 iv_len = crypto_skcipher_ivsize(tfm);
1153 if (iv_len)
1154 memset(&iv, 0xff, iv_len);
1155
1156 /* Now setup per request stuff, i.e. buffers */
1157
1158 for (j = 0; j < num_mb; ++j) {
1159 struct test_mb_skcipher_data *cur = &data[j];
1160 unsigned int k = bs;
1161 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1162 unsigned int p = 0;
1163
1164 sg_init_table(cur->sg, pages);
1165
1166 while (k > PAGE_SIZE) {
1167 sg_set_buf(cur->sg + p, cur->xbuf[p],
1168 PAGE_SIZE);
1169 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1170 p++;
1171 k -= PAGE_SIZE;
1172 }
1173
1174 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1175 memset(cur->xbuf[p], 0xff, k);
1176
1177 skcipher_request_set_crypt(cur->req, cur->sg,
1178 cur->sg, bs, iv);
1179 }
1180
1181 if (secs) {
1182 ret = test_mb_acipher_jiffies(data, enc,
1183 bs, secs,
1184 num_mb);
1185 cond_resched();
1186 } else {
1187 ret = test_mb_acipher_cycles(data, enc,
1188 bs, num_mb);
1189 }
1190
1191 if (ret) {
1192 pr_err("%s() failed flags=%x\n", e,
1193 crypto_skcipher_get_flags(tfm));
1194 break;
1195 }
1196 b_size++;
1197 i++;
1198 } while (*b_size);
1199 keysize++;
1200 } while (*keysize);
1201
1202out:
1203 for (i = 0; i < num_mb; ++i)
1204 skcipher_request_free(data[i].req);
1205out_free_xbuf:
1206 for (i = 0; i < num_mb; ++i)
1207 testmgr_free_buf(data[i].xbuf);
1208out_free_tfm:
1209 crypto_free_skcipher(tfm);
1210out_free_data:
1211 kfree(data);
1212}
1213
1214static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
1215{
1216 struct crypto_wait *wait = req->base.data;
1217
1218 return crypto_wait_req(ret, wait);
1219}
1220
1221static int test_acipher_jiffies(struct skcipher_request *req, int enc,
1222 int blen, int secs)
1223{
1224 unsigned long start, end;
1225 int bcount;
1226 int ret;
1227
1228 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1229 time_before(jiffies, end); bcount++) {
1230 if (enc)
1231 ret = do_one_acipher_op(req,
1232 crypto_skcipher_encrypt(req));
1233 else
1234 ret = do_one_acipher_op(req,
1235 crypto_skcipher_decrypt(req));
1236
1237 if (ret)
1238 return ret;
1239 }
1240
1241 pr_cont("%d operations in %d seconds (%llu bytes)\n",
1242 bcount, secs, (u64)bcount * blen);
1243 return 0;
1244}
1245
1246static int test_acipher_cycles(struct skcipher_request *req, int enc,
1247 int blen)
1248{
1249 unsigned long cycles = 0;
1250 int ret = 0;
1251 int i;
1252
1253 /* Warm-up run. */
1254 for (i = 0; i < 4; i++) {
1255 if (enc)
1256 ret = do_one_acipher_op(req,
1257 crypto_skcipher_encrypt(req));
1258 else
1259 ret = do_one_acipher_op(req,
1260 crypto_skcipher_decrypt(req));
1261
1262 if (ret)
1263 goto out;
1264 }
1265
1266 /* The real thing. */
1267 for (i = 0; i < 8; i++) {
1268 cycles_t start, end;
1269
1270 start = get_cycles();
1271 if (enc)
1272 ret = do_one_acipher_op(req,
1273 crypto_skcipher_encrypt(req));
1274 else
1275 ret = do_one_acipher_op(req,
1276 crypto_skcipher_decrypt(req));
1277 end = get_cycles();
1278
1279 if (ret)
1280 goto out;
1281
1282 cycles += end - start;
1283 }
1284
1285out:
1286 if (ret == 0)
1287 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1288 (cycles + 4) / 8, blen);
1289
1290 return ret;
1291}
1292
1293static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1294 struct cipher_speed_template *template,
1295 unsigned int tcount, u8 *keysize, bool async)
1296{
1297 unsigned int ret, i, j, k, iv_len;
1298 struct crypto_wait wait;
1299 const char *key;
1300 char iv[128];
1301 struct skcipher_request *req;
1302 struct crypto_skcipher *tfm;
1303 const int *b_size;
1304 const char *e;
1305
1306 if (enc == ENCRYPT)
1307 e = "encryption";
1308 else
1309 e = "decryption";
1310
1311 crypto_init_wait(&wait);
1312
1313 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
1314
1315 if (IS_ERR(tfm)) {
1316 pr_err("failed to load transform for %s: %ld\n", algo,
1317 PTR_ERR(tfm));
1318 return;
1319 }
1320
1321 pr_info("testing speed of %s %s (%s) %s\n", async ? "async" : "sync",
1322 algo, get_driver_name(crypto_skcipher, tfm), e);
1323
1324 req = skcipher_request_alloc(tfm, GFP_KERNEL);
1325 if (!req) {
1326 pr_err("skcipher: Failed to allocate request for %s\n", algo);
1327 goto out;
1328 }
1329
1330 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1331 crypto_req_done, &wait);
1332
1333 i = 0;
1334 do {
1335 b_size = block_sizes;
1336
1337 do {
1338 u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm));
1339 struct scatterlist sg[TVMEMSIZE];
1340
1341 if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) {
1342 pr_err("template (%u) too big for "
1343 "tvmem (%lu)\n", *keysize + bs,
1344 TVMEMSIZE * PAGE_SIZE);
1345 goto out_free_req;
1346 }
1347
1348 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1349 *keysize * 8, bs);
1350
1351 memset(tvmem[0], 0xff, PAGE_SIZE);
1352
1353 /* set key, plain text and IV */
1354 key = tvmem[0];
1355 for (j = 0; j < tcount; j++) {
1356 if (template[j].klen == *keysize) {
1357 key = template[j].key;
1358 break;
1359 }
1360 }
1361
1362 crypto_skcipher_clear_flags(tfm, ~0);
1363
1364 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1365 if (ret) {
1366 pr_err("setkey() failed flags=%x\n",
1367 crypto_skcipher_get_flags(tfm));
1368 goto out_free_req;
1369 }
1370
1371 k = *keysize + bs;
1372 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1373
1374 if (k > PAGE_SIZE) {
1375 sg_set_buf(sg, tvmem[0] + *keysize,
1376 PAGE_SIZE - *keysize);
1377 k -= PAGE_SIZE;
1378 j = 1;
1379 while (k > PAGE_SIZE) {
1380 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1381 memset(tvmem[j], 0xff, PAGE_SIZE);
1382 j++;
1383 k -= PAGE_SIZE;
1384 }
1385 sg_set_buf(sg + j, tvmem[j], k);
1386 memset(tvmem[j], 0xff, k);
1387 } else {
1388 sg_set_buf(sg, tvmem[0] + *keysize, bs);
1389 }
1390
1391 iv_len = crypto_skcipher_ivsize(tfm);
1392 if (iv_len)
1393 memset(&iv, 0xff, iv_len);
1394
1395 skcipher_request_set_crypt(req, sg, sg, bs, iv);
1396
1397 if (secs) {
1398 ret = test_acipher_jiffies(req, enc,
1399 bs, secs);
1400 cond_resched();
1401 } else {
1402 ret = test_acipher_cycles(req, enc,
1403 bs);
1404 }
1405
1406 if (ret) {
1407 pr_err("%s() failed flags=%x\n", e,
1408 crypto_skcipher_get_flags(tfm));
1409 break;
1410 }
1411 b_size++;
1412 i++;
1413 } while (*b_size);
1414 keysize++;
1415 } while (*keysize);
1416
1417out_free_req:
1418 skcipher_request_free(req);
1419out:
1420 crypto_free_skcipher(tfm);
1421}
1422
1423static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1424 struct cipher_speed_template *template,
1425 unsigned int tcount, u8 *keysize)
1426{
1427 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1428 true);
1429}
1430
1431static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1432 struct cipher_speed_template *template,
1433 unsigned int tcount, u8 *keysize)
1434{
1435 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1436 false);
1437}
1438
1439static inline int tcrypt_test(const char *alg)
1440{
1441 int ret;
1442
1443 pr_debug("testing %s\n", alg);
1444
1445 ret = alg_test(alg, alg, 0, 0);
1446 /* non-fips algs return -EINVAL or -ECANCELED in fips mode */
1447 if (fips_enabled && (ret == -EINVAL || ret == -ECANCELED))
1448 ret = 0;
1449 return ret;
1450}
1451
1452static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
1453{
1454 int i;
1455 int ret = 0;
1456
1457 switch (m) {
1458 case 0:
1459 if (alg) {
1460 if (!crypto_has_alg(alg, type,
1461 mask ?: CRYPTO_ALG_TYPE_MASK))
1462 ret = -ENOENT;
1463 break;
1464 }
1465
1466 for (i = 1; i < 200; i++)
1467 ret = min(ret, do_test(NULL, 0, 0, i, num_mb));
1468 break;
1469
1470 case 1:
1471 ret = min(ret, tcrypt_test("md5"));
1472 break;
1473
1474 case 2:
1475 ret = min(ret, tcrypt_test("sha1"));
1476 break;
1477
1478 case 3:
1479 ret = min(ret, tcrypt_test("ecb(des)"));
1480 ret = min(ret, tcrypt_test("cbc(des)"));
1481 ret = min(ret, tcrypt_test("ctr(des)"));
1482 break;
1483
1484 case 4:
1485 ret = min(ret, tcrypt_test("ecb(des3_ede)"));
1486 ret = min(ret, tcrypt_test("cbc(des3_ede)"));
1487 ret = min(ret, tcrypt_test("ctr(des3_ede)"));
1488 break;
1489
1490 case 5:
1491 ret = min(ret, tcrypt_test("md4"));
1492 break;
1493
1494 case 6:
1495 ret = min(ret, tcrypt_test("sha256"));
1496 break;
1497
1498 case 7:
1499 ret = min(ret, tcrypt_test("ecb(blowfish)"));
1500 ret = min(ret, tcrypt_test("cbc(blowfish)"));
1501 ret = min(ret, tcrypt_test("ctr(blowfish)"));
1502 break;
1503
1504 case 8:
1505 ret = min(ret, tcrypt_test("ecb(twofish)"));
1506 ret = min(ret, tcrypt_test("cbc(twofish)"));
1507 ret = min(ret, tcrypt_test("ctr(twofish)"));
1508 ret = min(ret, tcrypt_test("lrw(twofish)"));
1509 ret = min(ret, tcrypt_test("xts(twofish)"));
1510 break;
1511
1512 case 9:
1513 ret = min(ret, tcrypt_test("ecb(serpent)"));
1514 ret = min(ret, tcrypt_test("cbc(serpent)"));
1515 ret = min(ret, tcrypt_test("ctr(serpent)"));
1516 ret = min(ret, tcrypt_test("lrw(serpent)"));
1517 ret = min(ret, tcrypt_test("xts(serpent)"));
1518 break;
1519
1520 case 10:
1521 ret = min(ret, tcrypt_test("ecb(aes)"));
1522 ret = min(ret, tcrypt_test("cbc(aes)"));
1523 ret = min(ret, tcrypt_test("lrw(aes)"));
1524 ret = min(ret, tcrypt_test("xts(aes)"));
1525 ret = min(ret, tcrypt_test("ctr(aes)"));
1526 ret = min(ret, tcrypt_test("rfc3686(ctr(aes))"));
1527 ret = min(ret, tcrypt_test("xctr(aes)"));
1528 break;
1529
1530 case 11:
1531 ret = min(ret, tcrypt_test("sha384"));
1532 break;
1533
1534 case 12:
1535 ret = min(ret, tcrypt_test("sha512"));
1536 break;
1537
1538 case 13:
1539 ret = min(ret, tcrypt_test("deflate"));
1540 break;
1541
1542 case 14:
1543 ret = min(ret, tcrypt_test("ecb(cast5)"));
1544 ret = min(ret, tcrypt_test("cbc(cast5)"));
1545 ret = min(ret, tcrypt_test("ctr(cast5)"));
1546 break;
1547
1548 case 15:
1549 ret = min(ret, tcrypt_test("ecb(cast6)"));
1550 ret = min(ret, tcrypt_test("cbc(cast6)"));
1551 ret = min(ret, tcrypt_test("ctr(cast6)"));
1552 ret = min(ret, tcrypt_test("lrw(cast6)"));
1553 ret = min(ret, tcrypt_test("xts(cast6)"));
1554 break;
1555
1556 case 16:
1557 ret = min(ret, tcrypt_test("ecb(arc4)"));
1558 break;
1559
1560 case 17:
1561 ret = min(ret, tcrypt_test("michael_mic"));
1562 break;
1563
1564 case 18:
1565 ret = min(ret, tcrypt_test("crc32c"));
1566 break;
1567
1568 case 19:
1569 ret = min(ret, tcrypt_test("ecb(tea)"));
1570 break;
1571
1572 case 20:
1573 ret = min(ret, tcrypt_test("ecb(xtea)"));
1574 break;
1575
1576 case 21:
1577 ret = min(ret, tcrypt_test("ecb(khazad)"));
1578 break;
1579
1580 case 22:
1581 ret = min(ret, tcrypt_test("wp512"));
1582 break;
1583
1584 case 23:
1585 ret = min(ret, tcrypt_test("wp384"));
1586 break;
1587
1588 case 24:
1589 ret = min(ret, tcrypt_test("wp256"));
1590 break;
1591
1592 case 26:
1593 ret = min(ret, tcrypt_test("ecb(anubis)"));
1594 ret = min(ret, tcrypt_test("cbc(anubis)"));
1595 break;
1596
1597 case 30:
1598 ret = min(ret, tcrypt_test("ecb(xeta)"));
1599 break;
1600
1601 case 31:
1602 ret = min(ret, tcrypt_test("pcbc(fcrypt)"));
1603 break;
1604
1605 case 32:
1606 ret = min(ret, tcrypt_test("ecb(camellia)"));
1607 ret = min(ret, tcrypt_test("cbc(camellia)"));
1608 ret = min(ret, tcrypt_test("ctr(camellia)"));
1609 ret = min(ret, tcrypt_test("lrw(camellia)"));
1610 ret = min(ret, tcrypt_test("xts(camellia)"));
1611 break;
1612
1613 case 33:
1614 ret = min(ret, tcrypt_test("sha224"));
1615 break;
1616
1617 case 35:
1618 ret = min(ret, tcrypt_test("gcm(aes)"));
1619 break;
1620
1621 case 36:
1622 ret = min(ret, tcrypt_test("lzo"));
1623 break;
1624
1625 case 37:
1626 ret = min(ret, tcrypt_test("ccm(aes)"));
1627 break;
1628
1629 case 38:
1630 ret = min(ret, tcrypt_test("cts(cbc(aes))"));
1631 break;
1632
1633 case 39:
1634 ret = min(ret, tcrypt_test("xxhash64"));
1635 break;
1636
1637 case 40:
1638 ret = min(ret, tcrypt_test("rmd160"));
1639 break;
1640
1641 case 42:
1642 ret = min(ret, tcrypt_test("blake2b-512"));
1643 break;
1644
1645 case 43:
1646 ret = min(ret, tcrypt_test("ecb(seed)"));
1647 break;
1648
1649 case 45:
1650 ret = min(ret, tcrypt_test("rfc4309(ccm(aes))"));
1651 break;
1652
1653 case 46:
1654 ret = min(ret, tcrypt_test("ghash"));
1655 break;
1656
1657 case 47:
1658 ret = min(ret, tcrypt_test("crct10dif"));
1659 break;
1660
1661 case 48:
1662 ret = min(ret, tcrypt_test("sha3-224"));
1663 break;
1664
1665 case 49:
1666 ret = min(ret, tcrypt_test("sha3-256"));
1667 break;
1668
1669 case 50:
1670 ret = min(ret, tcrypt_test("sha3-384"));
1671 break;
1672
1673 case 51:
1674 ret = min(ret, tcrypt_test("sha3-512"));
1675 break;
1676
1677 case 52:
1678 ret = min(ret, tcrypt_test("sm3"));
1679 break;
1680
1681 case 53:
1682 ret = min(ret, tcrypt_test("streebog256"));
1683 break;
1684
1685 case 54:
1686 ret = min(ret, tcrypt_test("streebog512"));
1687 break;
1688
1689 case 55:
1690 ret = min(ret, tcrypt_test("gcm(sm4)"));
1691 break;
1692
1693 case 56:
1694 ret = min(ret, tcrypt_test("ccm(sm4)"));
1695 break;
1696
1697 case 57:
1698 ret = min(ret, tcrypt_test("polyval"));
1699 break;
1700
1701 case 58:
1702 ret = min(ret, tcrypt_test("gcm(aria)"));
1703 break;
1704
1705 case 59:
1706 ret = min(ret, tcrypt_test("cts(cbc(sm4))"));
1707 break;
1708
1709 case 100:
1710 ret = min(ret, tcrypt_test("hmac(md5)"));
1711 break;
1712
1713 case 101:
1714 ret = min(ret, tcrypt_test("hmac(sha1)"));
1715 break;
1716
1717 case 102:
1718 ret = min(ret, tcrypt_test("hmac(sha256)"));
1719 break;
1720
1721 case 103:
1722 ret = min(ret, tcrypt_test("hmac(sha384)"));
1723 break;
1724
1725 case 104:
1726 ret = min(ret, tcrypt_test("hmac(sha512)"));
1727 break;
1728
1729 case 105:
1730 ret = min(ret, tcrypt_test("hmac(sha224)"));
1731 break;
1732
1733 case 106:
1734 ret = min(ret, tcrypt_test("xcbc(aes)"));
1735 break;
1736
1737 case 108:
1738 ret = min(ret, tcrypt_test("hmac(rmd160)"));
1739 break;
1740
1741 case 109:
1742 ret = min(ret, tcrypt_test("vmac64(aes)"));
1743 break;
1744
1745 case 111:
1746 ret = min(ret, tcrypt_test("hmac(sha3-224)"));
1747 break;
1748
1749 case 112:
1750 ret = min(ret, tcrypt_test("hmac(sha3-256)"));
1751 break;
1752
1753 case 113:
1754 ret = min(ret, tcrypt_test("hmac(sha3-384)"));
1755 break;
1756
1757 case 114:
1758 ret = min(ret, tcrypt_test("hmac(sha3-512)"));
1759 break;
1760
1761 case 115:
1762 ret = min(ret, tcrypt_test("hmac(streebog256)"));
1763 break;
1764
1765 case 116:
1766 ret = min(ret, tcrypt_test("hmac(streebog512)"));
1767 break;
1768
1769 case 150:
1770 ret = min(ret, tcrypt_test("ansi_cprng"));
1771 break;
1772
1773 case 151:
1774 ret = min(ret, tcrypt_test("rfc4106(gcm(aes))"));
1775 break;
1776
1777 case 152:
1778 ret = min(ret, tcrypt_test("rfc4543(gcm(aes))"));
1779 break;
1780
1781 case 153:
1782 ret = min(ret, tcrypt_test("cmac(aes)"));
1783 break;
1784
1785 case 154:
1786 ret = min(ret, tcrypt_test("cmac(des3_ede)"));
1787 break;
1788
1789 case 155:
1790 ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(aes))"));
1791 break;
1792
1793 case 156:
1794 ret = min(ret, tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"));
1795 break;
1796
1797 case 157:
1798 ret = min(ret, tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"));
1799 break;
1800
1801 case 158:
1802 ret = min(ret, tcrypt_test("cbcmac(sm4)"));
1803 break;
1804
1805 case 159:
1806 ret = min(ret, tcrypt_test("cmac(sm4)"));
1807 break;
1808
1809 case 160:
1810 ret = min(ret, tcrypt_test("xcbc(sm4)"));
1811 break;
1812
1813 case 181:
1814 ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(des))"));
1815 break;
1816 case 182:
1817 ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"));
1818 break;
1819 case 183:
1820 ret = min(ret, tcrypt_test("authenc(hmac(sha224),cbc(des))"));
1821 break;
1822 case 184:
1823 ret = min(ret, tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"));
1824 break;
1825 case 185:
1826 ret = min(ret, tcrypt_test("authenc(hmac(sha256),cbc(des))"));
1827 break;
1828 case 186:
1829 ret = min(ret, tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"));
1830 break;
1831 case 187:
1832 ret = min(ret, tcrypt_test("authenc(hmac(sha384),cbc(des))"));
1833 break;
1834 case 188:
1835 ret = min(ret, tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"));
1836 break;
1837 case 189:
1838 ret = min(ret, tcrypt_test("authenc(hmac(sha512),cbc(des))"));
1839 break;
1840 case 190:
1841 ret = min(ret, tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"));
1842 break;
1843 case 191:
1844 ret = min(ret, tcrypt_test("ecb(sm4)"));
1845 ret = min(ret, tcrypt_test("cbc(sm4)"));
1846 ret = min(ret, tcrypt_test("ctr(sm4)"));
1847 ret = min(ret, tcrypt_test("xts(sm4)"));
1848 break;
1849 case 192:
1850 ret = min(ret, tcrypt_test("ecb(aria)"));
1851 ret = min(ret, tcrypt_test("cbc(aria)"));
1852 ret = min(ret, tcrypt_test("ctr(aria)"));
1853 break;
1854 case 200:
1855 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1856 speed_template_16_24_32);
1857 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1858 speed_template_16_24_32);
1859 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1860 speed_template_16_24_32);
1861 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1862 speed_template_16_24_32);
1863 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1864 speed_template_32_40_48);
1865 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1866 speed_template_32_40_48);
1867 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1868 speed_template_32_64);
1869 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1870 speed_template_32_64);
1871 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1872 speed_template_16_24_32);
1873 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1874 speed_template_16_24_32);
1875 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1876 speed_template_16_24_32);
1877 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1878 speed_template_16_24_32);
1879 break;
1880
1881 case 201:
1882 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1883 des3_speed_template, DES3_SPEED_VECTORS,
1884 speed_template_24);
1885 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1886 des3_speed_template, DES3_SPEED_VECTORS,
1887 speed_template_24);
1888 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1889 des3_speed_template, DES3_SPEED_VECTORS,
1890 speed_template_24);
1891 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1892 des3_speed_template, DES3_SPEED_VECTORS,
1893 speed_template_24);
1894 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1895 des3_speed_template, DES3_SPEED_VECTORS,
1896 speed_template_24);
1897 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1898 des3_speed_template, DES3_SPEED_VECTORS,
1899 speed_template_24);
1900 break;
1901
1902 case 202:
1903 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1904 speed_template_16_24_32);
1905 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1906 speed_template_16_24_32);
1907 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1908 speed_template_16_24_32);
1909 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1910 speed_template_16_24_32);
1911 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1912 speed_template_16_24_32);
1913 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1914 speed_template_16_24_32);
1915 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1916 speed_template_32_40_48);
1917 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1918 speed_template_32_40_48);
1919 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1920 speed_template_32_48_64);
1921 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1922 speed_template_32_48_64);
1923 break;
1924
1925 case 203:
1926 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1927 speed_template_8_32);
1928 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1929 speed_template_8_32);
1930 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1931 speed_template_8_32);
1932 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1933 speed_template_8_32);
1934 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1935 speed_template_8_32);
1936 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1937 speed_template_8_32);
1938 break;
1939
1940 case 204:
1941 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1942 speed_template_8);
1943 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1944 speed_template_8);
1945 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1946 speed_template_8);
1947 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1948 speed_template_8);
1949 break;
1950
1951 case 205:
1952 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1953 speed_template_16_24_32);
1954 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1955 speed_template_16_24_32);
1956 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1957 speed_template_16_24_32);
1958 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1959 speed_template_16_24_32);
1960 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1961 speed_template_16_24_32);
1962 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1963 speed_template_16_24_32);
1964 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1965 speed_template_32_40_48);
1966 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1967 speed_template_32_40_48);
1968 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1969 speed_template_32_48_64);
1970 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1971 speed_template_32_48_64);
1972 break;
1973
1974 case 207:
1975 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1976 speed_template_16_32);
1977 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1978 speed_template_16_32);
1979 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1980 speed_template_16_32);
1981 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1982 speed_template_16_32);
1983 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1984 speed_template_16_32);
1985 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1986 speed_template_16_32);
1987 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1988 speed_template_32_48);
1989 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1990 speed_template_32_48);
1991 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1992 speed_template_32_64);
1993 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1994 speed_template_32_64);
1995 break;
1996
1997 case 208:
1998 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1999 speed_template_8);
2000 break;
2001
2002 case 209:
2003 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2004 speed_template_8_16);
2005 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2006 speed_template_8_16);
2007 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2008 speed_template_8_16);
2009 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2010 speed_template_8_16);
2011 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2012 speed_template_8_16);
2013 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2014 speed_template_8_16);
2015 break;
2016
2017 case 210:
2018 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2019 speed_template_16_32);
2020 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2021 speed_template_16_32);
2022 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2023 speed_template_16_32);
2024 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2025 speed_template_16_32);
2026 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2027 speed_template_16_32);
2028 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2029 speed_template_16_32);
2030 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2031 speed_template_32_48);
2032 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2033 speed_template_32_48);
2034 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2035 speed_template_32_64);
2036 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2037 speed_template_32_64);
2038 break;
2039
2040 case 211:
2041 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
2042 NULL, 0, 16, 16, aead_speed_template_20_28_36);
2043 test_aead_speed("gcm(aes)", ENCRYPT, sec,
2044 NULL, 0, 16, 8, speed_template_16_24_32);
2045 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2046 NULL, 0, 16, 16, aead_speed_template_20_28_36);
2047 test_aead_speed("gcm(aes)", DECRYPT, sec,
2048 NULL, 0, 16, 8, speed_template_16_24_32);
2049 break;
2050
2051 case 212:
2052 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
2053 NULL, 0, 16, 16, aead_speed_template_19);
2054 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2055 NULL, 0, 16, 16, aead_speed_template_19);
2056 break;
2057
2058 case 213:
2059 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2060 NULL, 0, 16, 8, aead_speed_template_36);
2061 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2062 NULL, 0, 16, 8, aead_speed_template_36);
2063 break;
2064
2065 case 214:
2066 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2067 speed_template_32);
2068 break;
2069
2070 case 215:
2071 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2072 0, 16, 16, aead_speed_template_20_28_36, num_mb);
2073 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2074 speed_template_16_24_32, num_mb);
2075 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2076 0, 16, 16, aead_speed_template_20_28_36, num_mb);
2077 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2078 speed_template_16_24_32, num_mb);
2079 break;
2080
2081 case 216:
2082 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2083 16, 16, aead_speed_template_19, num_mb);
2084 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2085 16, 16, aead_speed_template_19, num_mb);
2086 break;
2087
2088 case 217:
2089 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2090 sec, NULL, 0, 16, 8, aead_speed_template_36,
2091 num_mb);
2092 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2093 sec, NULL, 0, 16, 8, aead_speed_template_36,
2094 num_mb);
2095 break;
2096
2097 case 218:
2098 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2099 speed_template_16);
2100 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2101 speed_template_16);
2102 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2103 speed_template_16);
2104 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2105 speed_template_16);
2106 test_cipher_speed("cts(cbc(sm4))", ENCRYPT, sec, NULL, 0,
2107 speed_template_16);
2108 test_cipher_speed("cts(cbc(sm4))", DECRYPT, sec, NULL, 0,
2109 speed_template_16);
2110 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2111 speed_template_16);
2112 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2113 speed_template_16);
2114 test_cipher_speed("xts(sm4)", ENCRYPT, sec, NULL, 0,
2115 speed_template_32);
2116 test_cipher_speed("xts(sm4)", DECRYPT, sec, NULL, 0,
2117 speed_template_32);
2118 break;
2119
2120 case 219:
2121 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2122 0, speed_template_32);
2123 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2124 0, speed_template_32);
2125 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2126 0, speed_template_32);
2127 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2128 0, speed_template_32);
2129 break;
2130
2131 case 220:
2132 test_acipher_speed("essiv(cbc(aes),sha256)",
2133 ENCRYPT, sec, NULL, 0,
2134 speed_template_16_24_32);
2135 test_acipher_speed("essiv(cbc(aes),sha256)",
2136 DECRYPT, sec, NULL, 0,
2137 speed_template_16_24_32);
2138 break;
2139
2140 case 221:
2141 test_aead_speed("aegis128", ENCRYPT, sec,
2142 NULL, 0, 16, 8, speed_template_16);
2143 test_aead_speed("aegis128", DECRYPT, sec,
2144 NULL, 0, 16, 8, speed_template_16);
2145 break;
2146
2147 case 222:
2148 test_aead_speed("gcm(sm4)", ENCRYPT, sec,
2149 NULL, 0, 16, 8, speed_template_16);
2150 test_aead_speed("gcm(sm4)", DECRYPT, sec,
2151 NULL, 0, 16, 8, speed_template_16);
2152 break;
2153
2154 case 223:
2155 test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec,
2156 NULL, 0, 16, 16, aead_speed_template_19);
2157 test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec,
2158 NULL, 0, 16, 16, aead_speed_template_19);
2159 break;
2160
2161 case 224:
2162 test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8,
2163 speed_template_16, num_mb);
2164 test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8,
2165 speed_template_16, num_mb);
2166 break;
2167
2168 case 225:
2169 test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0,
2170 16, 16, aead_speed_template_19, num_mb);
2171 test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0,
2172 16, 16, aead_speed_template_19, num_mb);
2173 break;
2174
2175 case 226:
2176 test_cipher_speed("hctr2(aes)", ENCRYPT, sec, NULL,
2177 0, speed_template_32);
2178 break;
2179
2180 case 227:
2181 test_cipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2182 speed_template_16_24_32);
2183 test_cipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2184 speed_template_16_24_32);
2185 test_cipher_speed("cbc(aria)", ENCRYPT, sec, NULL, 0,
2186 speed_template_16_24_32);
2187 test_cipher_speed("cbc(aria)", DECRYPT, sec, NULL, 0,
2188 speed_template_16_24_32);
2189 test_cipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2190 speed_template_16_24_32);
2191 test_cipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2192 speed_template_16_24_32);
2193 break;
2194
2195 case 228:
2196 test_aead_speed("gcm(aria)", ENCRYPT, sec,
2197 NULL, 0, 16, 8, speed_template_16_24_32);
2198 test_aead_speed("gcm(aria)", DECRYPT, sec,
2199 NULL, 0, 16, 8, speed_template_16_24_32);
2200 break;
2201
2202 case 229:
2203 test_mb_aead_speed("gcm(aria)", ENCRYPT, sec, NULL, 0, 16, 8,
2204 speed_template_16, num_mb);
2205 test_mb_aead_speed("gcm(aria)", DECRYPT, sec, NULL, 0, 16, 8,
2206 speed_template_16, num_mb);
2207 break;
2208
2209 case 300:
2210 if (alg) {
2211 test_hash_speed(alg, sec, generic_hash_speed_template);
2212 break;
2213 }
2214 fallthrough;
2215 case 301:
2216 test_hash_speed("md4", sec, generic_hash_speed_template);
2217 if (mode > 300 && mode < 400) break;
2218 fallthrough;
2219 case 302:
2220 test_hash_speed("md5", sec, generic_hash_speed_template);
2221 if (mode > 300 && mode < 400) break;
2222 fallthrough;
2223 case 303:
2224 test_hash_speed("sha1", sec, generic_hash_speed_template);
2225 if (mode > 300 && mode < 400) break;
2226 fallthrough;
2227 case 304:
2228 test_hash_speed("sha256", sec, generic_hash_speed_template);
2229 if (mode > 300 && mode < 400) break;
2230 fallthrough;
2231 case 305:
2232 test_hash_speed("sha384", sec, generic_hash_speed_template);
2233 if (mode > 300 && mode < 400) break;
2234 fallthrough;
2235 case 306:
2236 test_hash_speed("sha512", sec, generic_hash_speed_template);
2237 if (mode > 300 && mode < 400) break;
2238 fallthrough;
2239 case 307:
2240 test_hash_speed("wp256", sec, generic_hash_speed_template);
2241 if (mode > 300 && mode < 400) break;
2242 fallthrough;
2243 case 308:
2244 test_hash_speed("wp384", sec, generic_hash_speed_template);
2245 if (mode > 300 && mode < 400) break;
2246 fallthrough;
2247 case 309:
2248 test_hash_speed("wp512", sec, generic_hash_speed_template);
2249 if (mode > 300 && mode < 400) break;
2250 fallthrough;
2251 case 313:
2252 test_hash_speed("sha224", sec, generic_hash_speed_template);
2253 if (mode > 300 && mode < 400) break;
2254 fallthrough;
2255 case 314:
2256 test_hash_speed("xxhash64", sec, generic_hash_speed_template);
2257 if (mode > 300 && mode < 400) break;
2258 fallthrough;
2259 case 315:
2260 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2261 if (mode > 300 && mode < 400) break;
2262 fallthrough;
2263 case 317:
2264 test_hash_speed("blake2b-512", sec, generic_hash_speed_template);
2265 if (mode > 300 && mode < 400) break;
2266 fallthrough;
2267 case 318:
2268 klen = 16;
2269 test_hash_speed("ghash", sec, generic_hash_speed_template);
2270 if (mode > 300 && mode < 400) break;
2271 fallthrough;
2272 case 319:
2273 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2274 if (mode > 300 && mode < 400) break;
2275 fallthrough;
2276 case 320:
2277 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2278 if (mode > 300 && mode < 400) break;
2279 fallthrough;
2280 case 321:
2281 test_hash_speed("poly1305", sec, poly1305_speed_template);
2282 if (mode > 300 && mode < 400) break;
2283 fallthrough;
2284 case 322:
2285 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2286 if (mode > 300 && mode < 400) break;
2287 fallthrough;
2288 case 323:
2289 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2290 if (mode > 300 && mode < 400) break;
2291 fallthrough;
2292 case 324:
2293 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2294 if (mode > 300 && mode < 400) break;
2295 fallthrough;
2296 case 325:
2297 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2298 if (mode > 300 && mode < 400) break;
2299 fallthrough;
2300 case 326:
2301 test_hash_speed("sm3", sec, generic_hash_speed_template);
2302 if (mode > 300 && mode < 400) break;
2303 fallthrough;
2304 case 327:
2305 test_hash_speed("streebog256", sec,
2306 generic_hash_speed_template);
2307 if (mode > 300 && mode < 400) break;
2308 fallthrough;
2309 case 328:
2310 test_hash_speed("streebog512", sec,
2311 generic_hash_speed_template);
2312 if (mode > 300 && mode < 400) break;
2313 fallthrough;
2314 case 399:
2315 break;
2316
2317 case 400:
2318 if (alg) {
2319 test_ahash_speed(alg, sec, generic_hash_speed_template);
2320 break;
2321 }
2322 fallthrough;
2323 case 401:
2324 test_ahash_speed("md4", sec, generic_hash_speed_template);
2325 if (mode > 400 && mode < 500) break;
2326 fallthrough;
2327 case 402:
2328 test_ahash_speed("md5", sec, generic_hash_speed_template);
2329 if (mode > 400 && mode < 500) break;
2330 fallthrough;
2331 case 403:
2332 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2333 if (mode > 400 && mode < 500) break;
2334 fallthrough;
2335 case 404:
2336 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2337 if (mode > 400 && mode < 500) break;
2338 fallthrough;
2339 case 405:
2340 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2341 if (mode > 400 && mode < 500) break;
2342 fallthrough;
2343 case 406:
2344 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2345 if (mode > 400 && mode < 500) break;
2346 fallthrough;
2347 case 407:
2348 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2349 if (mode > 400 && mode < 500) break;
2350 fallthrough;
2351 case 408:
2352 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2353 if (mode > 400 && mode < 500) break;
2354 fallthrough;
2355 case 409:
2356 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2357 if (mode > 400 && mode < 500) break;
2358 fallthrough;
2359 case 413:
2360 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2361 if (mode > 400 && mode < 500) break;
2362 fallthrough;
2363 case 414:
2364 test_ahash_speed("xxhash64", sec, generic_hash_speed_template);
2365 if (mode > 400 && mode < 500) break;
2366 fallthrough;
2367 case 415:
2368 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2369 if (mode > 400 && mode < 500) break;
2370 fallthrough;
2371 case 417:
2372 test_ahash_speed("blake2b-512", sec, generic_hash_speed_template);
2373 if (mode > 400 && mode < 500) break;
2374 fallthrough;
2375 case 418:
2376 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2377 if (mode > 400 && mode < 500) break;
2378 fallthrough;
2379 case 419:
2380 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2381 if (mode > 400 && mode < 500) break;
2382 fallthrough;
2383 case 420:
2384 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2385 if (mode > 400 && mode < 500) break;
2386 fallthrough;
2387 case 421:
2388 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2389 if (mode > 400 && mode < 500) break;
2390 fallthrough;
2391 case 422:
2392 test_ahash_speed("sm3", sec, generic_hash_speed_template);
2393 if (mode > 400 && mode < 500) break;
2394 fallthrough;
2395 case 499:
2396 break;
2397
2398 case 500:
2399 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2400 speed_template_16_24_32);
2401 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2402 speed_template_16_24_32);
2403 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2404 speed_template_16_24_32);
2405 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2406 speed_template_16_24_32);
2407 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2408 speed_template_32_40_48);
2409 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2410 speed_template_32_40_48);
2411 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2412 speed_template_32_64);
2413 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2414 speed_template_32_64);
2415 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2416 speed_template_16_24_32);
2417 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2418 speed_template_16_24_32);
2419 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2420 speed_template_16_24_32);
2421 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2422 speed_template_16_24_32);
2423 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2424 speed_template_20_28_36);
2425 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2426 speed_template_20_28_36);
2427 break;
2428
2429 case 501:
2430 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2431 des3_speed_template, DES3_SPEED_VECTORS,
2432 speed_template_24);
2433 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2434 des3_speed_template, DES3_SPEED_VECTORS,
2435 speed_template_24);
2436 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2437 des3_speed_template, DES3_SPEED_VECTORS,
2438 speed_template_24);
2439 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2440 des3_speed_template, DES3_SPEED_VECTORS,
2441 speed_template_24);
2442 break;
2443
2444 case 502:
2445 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2446 speed_template_8);
2447 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2448 speed_template_8);
2449 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2450 speed_template_8);
2451 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2452 speed_template_8);
2453 break;
2454
2455 case 503:
2456 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2457 speed_template_16_32);
2458 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2459 speed_template_16_32);
2460 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2461 speed_template_16_32);
2462 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2463 speed_template_16_32);
2464 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2465 speed_template_16_32);
2466 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2467 speed_template_16_32);
2468 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2469 speed_template_32_48);
2470 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2471 speed_template_32_48);
2472 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2473 speed_template_32_64);
2474 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2475 speed_template_32_64);
2476 break;
2477
2478 case 504:
2479 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2480 speed_template_16_24_32);
2481 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2482 speed_template_16_24_32);
2483 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2484 speed_template_16_24_32);
2485 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2486 speed_template_16_24_32);
2487 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2488 speed_template_16_24_32);
2489 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2490 speed_template_16_24_32);
2491 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2492 speed_template_32_40_48);
2493 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2494 speed_template_32_40_48);
2495 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2496 speed_template_32_48_64);
2497 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2498 speed_template_32_48_64);
2499 break;
2500
2501 case 505:
2502 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2503 speed_template_8);
2504 break;
2505
2506 case 506:
2507 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2508 speed_template_8_16);
2509 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2510 speed_template_8_16);
2511 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2512 speed_template_8_16);
2513 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2514 speed_template_8_16);
2515 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2516 speed_template_8_16);
2517 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2518 speed_template_8_16);
2519 break;
2520
2521 case 507:
2522 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2523 speed_template_16_32);
2524 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2525 speed_template_16_32);
2526 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2527 speed_template_16_32);
2528 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2529 speed_template_16_32);
2530 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2531 speed_template_16_32);
2532 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2533 speed_template_16_32);
2534 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2535 speed_template_32_48);
2536 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2537 speed_template_32_48);
2538 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2539 speed_template_32_64);
2540 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2541 speed_template_32_64);
2542 break;
2543
2544 case 508:
2545 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2546 speed_template_16_32);
2547 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2548 speed_template_16_32);
2549 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2550 speed_template_16_32);
2551 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2552 speed_template_16_32);
2553 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2554 speed_template_16_32);
2555 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2556 speed_template_16_32);
2557 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2558 speed_template_32_48);
2559 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2560 speed_template_32_48);
2561 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2562 speed_template_32_64);
2563 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2564 speed_template_32_64);
2565 break;
2566
2567 case 509:
2568 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2569 speed_template_8_32);
2570 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2571 speed_template_8_32);
2572 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2573 speed_template_8_32);
2574 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2575 speed_template_8_32);
2576 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2577 speed_template_8_32);
2578 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2579 speed_template_8_32);
2580 break;
2581
2582 case 518:
2583 test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2584 speed_template_16);
2585 test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2586 speed_template_16);
2587 test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2588 speed_template_16);
2589 test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2590 speed_template_16);
2591 test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2592 speed_template_16);
2593 test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2594 speed_template_16);
2595 test_acipher_speed("xts(sm4)", ENCRYPT, sec, NULL, 0,
2596 speed_template_32);
2597 test_acipher_speed("xts(sm4)", DECRYPT, sec, NULL, 0,
2598 speed_template_32);
2599 break;
2600
2601 case 519:
2602 test_acipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2603 speed_template_16_24_32);
2604 test_acipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2605 speed_template_16_24_32);
2606 test_acipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2607 speed_template_16_24_32);
2608 test_acipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2609 speed_template_16_24_32);
2610 break;
2611
2612 case 600:
2613 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2614 speed_template_16_24_32, num_mb);
2615 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2616 speed_template_16_24_32, num_mb);
2617 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2618 speed_template_16_24_32, num_mb);
2619 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2620 speed_template_16_24_32, num_mb);
2621 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2622 speed_template_32_40_48, num_mb);
2623 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2624 speed_template_32_40_48, num_mb);
2625 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2626 speed_template_32_64, num_mb);
2627 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2628 speed_template_32_64, num_mb);
2629 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2630 speed_template_16_24_32, num_mb);
2631 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2632 speed_template_16_24_32, num_mb);
2633 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2634 speed_template_16_24_32, num_mb);
2635 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2636 speed_template_16_24_32, num_mb);
2637 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2638 0, speed_template_20_28_36, num_mb);
2639 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2640 0, speed_template_20_28_36, num_mb);
2641 break;
2642
2643 case 601:
2644 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2645 des3_speed_template, DES3_SPEED_VECTORS,
2646 speed_template_24, num_mb);
2647 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2648 des3_speed_template, DES3_SPEED_VECTORS,
2649 speed_template_24, num_mb);
2650 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2651 des3_speed_template, DES3_SPEED_VECTORS,
2652 speed_template_24, num_mb);
2653 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2654 des3_speed_template, DES3_SPEED_VECTORS,
2655 speed_template_24, num_mb);
2656 break;
2657
2658 case 602:
2659 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2660 speed_template_8, num_mb);
2661 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2662 speed_template_8, num_mb);
2663 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2664 speed_template_8, num_mb);
2665 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2666 speed_template_8, num_mb);
2667 break;
2668
2669 case 603:
2670 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2671 speed_template_16_32, num_mb);
2672 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2673 speed_template_16_32, num_mb);
2674 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2675 speed_template_16_32, num_mb);
2676 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2677 speed_template_16_32, num_mb);
2678 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2679 speed_template_16_32, num_mb);
2680 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2681 speed_template_16_32, num_mb);
2682 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2683 speed_template_32_48, num_mb);
2684 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2685 speed_template_32_48, num_mb);
2686 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2687 speed_template_32_64, num_mb);
2688 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2689 speed_template_32_64, num_mb);
2690 break;
2691
2692 case 604:
2693 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2694 speed_template_16_24_32, num_mb);
2695 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2696 speed_template_16_24_32, num_mb);
2697 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2698 speed_template_16_24_32, num_mb);
2699 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2700 speed_template_16_24_32, num_mb);
2701 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2702 speed_template_16_24_32, num_mb);
2703 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2704 speed_template_16_24_32, num_mb);
2705 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2706 speed_template_32_40_48, num_mb);
2707 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2708 speed_template_32_40_48, num_mb);
2709 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2710 speed_template_32_48_64, num_mb);
2711 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2712 speed_template_32_48_64, num_mb);
2713 break;
2714
2715 case 605:
2716 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2717 speed_template_8, num_mb);
2718 break;
2719
2720 case 606:
2721 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2722 speed_template_8_16, num_mb);
2723 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2724 speed_template_8_16, num_mb);
2725 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2726 speed_template_8_16, num_mb);
2727 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2728 speed_template_8_16, num_mb);
2729 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2730 speed_template_8_16, num_mb);
2731 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2732 speed_template_8_16, num_mb);
2733 break;
2734
2735 case 607:
2736 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2737 speed_template_16_32, num_mb);
2738 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2739 speed_template_16_32, num_mb);
2740 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2741 speed_template_16_32, num_mb);
2742 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2743 speed_template_16_32, num_mb);
2744 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2745 speed_template_16_32, num_mb);
2746 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2747 speed_template_16_32, num_mb);
2748 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2749 speed_template_32_48, num_mb);
2750 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2751 speed_template_32_48, num_mb);
2752 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2753 speed_template_32_64, num_mb);
2754 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2755 speed_template_32_64, num_mb);
2756 break;
2757
2758 case 608:
2759 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2760 speed_template_16_32, num_mb);
2761 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2762 speed_template_16_32, num_mb);
2763 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2764 speed_template_16_32, num_mb);
2765 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2766 speed_template_16_32, num_mb);
2767 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2768 speed_template_16_32, num_mb);
2769 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2770 speed_template_16_32, num_mb);
2771 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2772 speed_template_32_48, num_mb);
2773 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2774 speed_template_32_48, num_mb);
2775 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2776 speed_template_32_64, num_mb);
2777 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2778 speed_template_32_64, num_mb);
2779 break;
2780
2781 case 609:
2782 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2783 speed_template_8_32, num_mb);
2784 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2785 speed_template_8_32, num_mb);
2786 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2787 speed_template_8_32, num_mb);
2788 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2789 speed_template_8_32, num_mb);
2790 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2791 speed_template_8_32, num_mb);
2792 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2793 speed_template_8_32, num_mb);
2794 break;
2795
2796 case 610:
2797 test_mb_skcipher_speed("ecb(aria)", ENCRYPT, sec, NULL, 0,
2798 speed_template_16_32, num_mb);
2799 test_mb_skcipher_speed("ecb(aria)", DECRYPT, sec, NULL, 0,
2800 speed_template_16_32, num_mb);
2801 test_mb_skcipher_speed("ctr(aria)", ENCRYPT, sec, NULL, 0,
2802 speed_template_16_32, num_mb);
2803 test_mb_skcipher_speed("ctr(aria)", DECRYPT, sec, NULL, 0,
2804 speed_template_16_32, num_mb);
2805 break;
2806
2807 }
2808
2809 return ret;
2810}
2811
2812static int __init tcrypt_mod_init(void)
2813{
2814 int err = -ENOMEM;
2815 int i;
2816
2817 for (i = 0; i < TVMEMSIZE; i++) {
2818 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2819 if (!tvmem[i])
2820 goto err_free_tv;
2821 }
2822
2823 err = do_test(alg, type, mask, mode, num_mb);
2824
2825 if (err) {
2826 pr_err("one or more tests failed!\n");
2827 goto err_free_tv;
2828 } else {
2829 pr_debug("all tests passed\n");
2830 }
2831
2832 /* We intentionaly return -EAGAIN to prevent keeping the module,
2833 * unless we're running in fips mode. It does all its work from
2834 * init() and doesn't offer any runtime functionality, but in
2835 * the fips case, checking for a successful load is helpful.
2836 * => we don't need it in the memory, do we?
2837 * -- mludvig
2838 */
2839 if (!fips_enabled)
2840 err = -EAGAIN;
2841
2842err_free_tv:
2843 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2844 free_page((unsigned long)tvmem[i]);
2845
2846 return err;
2847}
2848
2849/*
2850 * If an init function is provided, an exit function must also be provided
2851 * to allow module unload.
2852 */
2853static void __exit tcrypt_mod_fini(void) { }
2854
2855late_initcall(tcrypt_mod_init);
2856module_exit(tcrypt_mod_fini);
2857
2858module_param(alg, charp, 0);
2859module_param(type, uint, 0);
2860module_param(mask, uint, 0);
2861module_param(mode, int, 0);
2862module_param(sec, uint, 0);
2863MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2864 "(defaults to zero which uses CPU cycles instead)");
2865module_param(num_mb, uint, 0000);
2866MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
2867module_param(klen, uint, 0);
2868MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
2869
2870MODULE_LICENSE("GPL");
2871MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2872MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
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/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"
38
39/*
40 * Need slab memory for testing (size in number of pages).
41 */
42#define TVMEMSIZE 4
43
44/*
45* Used by test_cipher_speed()
46*/
47#define ENCRYPT 1
48#define DECRYPT 0
49
50/*
51 * Used by test_cipher_speed()
52 */
53static unsigned int sec;
54
55static char *alg = NULL;
56static u32 type;
57static u32 mask;
58static int mode;
59static char *tvmem[TVMEMSIZE];
60
61static 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
68};
69
70static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
71 struct scatterlist *sg, int blen, int sec)
72{
73 unsigned long start, end;
74 int bcount;
75 int ret;
76
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);
83
84 if (ret)
85 return ret;
86 }
87
88 printk("%d operations in %d seconds (%ld bytes)\n",
89 bcount, sec, (long)bcount * blen);
90 return 0;
91}
92
93static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
94 struct scatterlist *sg, int blen)
95{
96 unsigned long cycles = 0;
97 int ret = 0;
98 int i;
99
100 local_bh_disable();
101 local_irq_disable();
102
103 /* Warm-up run. */
104 for (i = 0; i < 4; i++) {
105 if (enc)
106 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
107 else
108 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
109
110 if (ret)
111 goto out;
112 }
113
114 /* The real thing. */
115 for (i = 0; i < 8; i++) {
116 cycles_t start, end;
117
118 start = get_cycles();
119 if (enc)
120 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
121 else
122 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
123 end = get_cycles();
124
125 if (ret)
126 goto out;
127
128 cycles += end - start;
129 }
130
131out:
132 local_irq_enable();
133 local_bh_enable();
134
135 if (ret == 0)
136 printk("1 operation in %lu cycles (%d bytes)\n",
137 (cycles + 4) / 8, blen);
138
139 return ret;
140}
141
142static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
143
144static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
145 struct cipher_speed_template *template,
146 unsigned int tcount, u8 *keysize)
147{
148 unsigned int ret, i, j, iv_len;
149 const char *key;
150 char iv[128];
151 struct crypto_blkcipher *tfm;
152 struct blkcipher_desc desc;
153 const char *e;
154 u32 *b_size;
155
156 if (enc == ENCRYPT)
157 e = "encryption";
158 else
159 e = "decryption";
160
161 printk("\ntesting speed of %s %s\n", algo, e);
162
163 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
164
165 if (IS_ERR(tfm)) {
166 printk("failed to load transform for %s: %ld\n", algo,
167 PTR_ERR(tfm));
168 return;
169 }
170 desc.tfm = tfm;
171 desc.flags = 0;
172
173 i = 0;
174 do {
175
176 b_size = block_sizes;
177 do {
178 struct scatterlist sg[TVMEMSIZE];
179
180 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
181 printk("template (%u) too big for "
182 "tvmem (%lu)\n", *keysize + *b_size,
183 TVMEMSIZE * PAGE_SIZE);
184 goto out;
185 }
186
187 printk("test %u (%d bit key, %d byte blocks): ", i,
188 *keysize * 8, *b_size);
189
190 memset(tvmem[0], 0xff, PAGE_SIZE);
191
192 /* set key, plain text and IV */
193 key = tvmem[0];
194 for (j = 0; j < tcount; j++) {
195 if (template[j].klen == *keysize) {
196 key = template[j].key;
197 break;
198 }
199 }
200
201 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
202 if (ret) {
203 printk("setkey() failed flags=%x\n",
204 crypto_blkcipher_get_flags(tfm));
205 goto out;
206 }
207
208 sg_init_table(sg, TVMEMSIZE);
209 sg_set_buf(sg, tvmem[0] + *keysize,
210 PAGE_SIZE - *keysize);
211 for (j = 1; j < TVMEMSIZE; j++) {
212 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
213 memset (tvmem[j], 0xff, PAGE_SIZE);
214 }
215
216 iv_len = crypto_blkcipher_ivsize(tfm);
217 if (iv_len) {
218 memset(&iv, 0xff, iv_len);
219 crypto_blkcipher_set_iv(tfm, iv, iv_len);
220 }
221
222 if (sec)
223 ret = test_cipher_jiffies(&desc, enc, sg,
224 *b_size, sec);
225 else
226 ret = test_cipher_cycles(&desc, enc, sg,
227 *b_size);
228
229 if (ret) {
230 printk("%s() failed flags=%x\n", e, desc.flags);
231 break;
232 }
233 b_size++;
234 i++;
235 } while (*b_size);
236 keysize++;
237 } while (*keysize);
238
239out:
240 crypto_free_blkcipher(tfm);
241}
242
243static int test_hash_jiffies_digest(struct hash_desc *desc,
244 struct scatterlist *sg, int blen,
245 char *out, int sec)
246{
247 unsigned long start, end;
248 int bcount;
249 int ret;
250
251 for (start = jiffies, end = start + sec * HZ, bcount = 0;
252 time_before(jiffies, end); bcount++) {
253 ret = crypto_hash_digest(desc, sg, blen, out);
254 if (ret)
255 return ret;
256 }
257
258 printk("%6u opers/sec, %9lu bytes/sec\n",
259 bcount / sec, ((long)bcount * blen) / sec);
260
261 return 0;
262}
263
264static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
265 int blen, int plen, char *out, int sec)
266{
267 unsigned long start, end;
268 int bcount, pcount;
269 int ret;
270
271 if (plen == blen)
272 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
273
274 for (start = jiffies, end = start + sec * HZ, bcount = 0;
275 time_before(jiffies, end); bcount++) {
276 ret = crypto_hash_init(desc);
277 if (ret)
278 return ret;
279 for (pcount = 0; pcount < blen; pcount += plen) {
280 ret = crypto_hash_update(desc, sg, plen);
281 if (ret)
282 return ret;
283 }
284 /* we assume there is enough space in 'out' for the result */
285 ret = crypto_hash_final(desc, out);
286 if (ret)
287 return ret;
288 }
289
290 printk("%6u opers/sec, %9lu bytes/sec\n",
291 bcount / sec, ((long)bcount * blen) / sec);
292
293 return 0;
294}
295
296static int test_hash_cycles_digest(struct hash_desc *desc,
297 struct scatterlist *sg, int blen, char *out)
298{
299 unsigned long cycles = 0;
300 int i;
301 int ret;
302
303 local_bh_disable();
304 local_irq_disable();
305
306 /* Warm-up run. */
307 for (i = 0; i < 4; i++) {
308 ret = crypto_hash_digest(desc, sg, blen, out);
309 if (ret)
310 goto out;
311 }
312
313 /* The real thing. */
314 for (i = 0; i < 8; i++) {
315 cycles_t start, end;
316
317 start = get_cycles();
318
319 ret = crypto_hash_digest(desc, sg, blen, out);
320 if (ret)
321 goto out;
322
323 end = get_cycles();
324
325 cycles += end - start;
326 }
327
328out:
329 local_irq_enable();
330 local_bh_enable();
331
332 if (ret)
333 return ret;
334
335 printk("%6lu cycles/operation, %4lu cycles/byte\n",
336 cycles / 8, cycles / (8 * blen));
337
338 return 0;
339}
340
341static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
342 int blen, int plen, char *out)
343{
344 unsigned long cycles = 0;
345 int i, pcount;
346 int ret;
347
348 if (plen == blen)
349 return test_hash_cycles_digest(desc, sg, blen, out);
350
351 local_bh_disable();
352 local_irq_disable();
353
354 /* Warm-up run. */
355 for (i = 0; i < 4; i++) {
356 ret = crypto_hash_init(desc);
357 if (ret)
358 goto out;
359 for (pcount = 0; pcount < blen; pcount += plen) {
360 ret = crypto_hash_update(desc, sg, plen);
361 if (ret)
362 goto out;
363 }
364 ret = crypto_hash_final(desc, out);
365 if (ret)
366 goto out;
367 }
368
369 /* The real thing. */
370 for (i = 0; i < 8; i++) {
371 cycles_t start, end;
372
373 start = get_cycles();
374
375 ret = crypto_hash_init(desc);
376 if (ret)
377 goto out;
378 for (pcount = 0; pcount < blen; pcount += plen) {
379 ret = crypto_hash_update(desc, sg, plen);
380 if (ret)
381 goto out;
382 }
383 ret = crypto_hash_final(desc, out);
384 if (ret)
385 goto out;
386
387 end = get_cycles();
388
389 cycles += end - start;
390 }
391
392out:
393 local_irq_enable();
394 local_bh_enable();
395
396 if (ret)
397 return ret;
398
399 printk("%6lu cycles/operation, %4lu cycles/byte\n",
400 cycles / 8, cycles / (8 * blen));
401
402 return 0;
403}
404
405static void test_hash_sg_init(struct scatterlist *sg)
406{
407 int i;
408
409 sg_init_table(sg, TVMEMSIZE);
410 for (i = 0; i < TVMEMSIZE; i++) {
411 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
412 memset(tvmem[i], 0xff, PAGE_SIZE);
413 }
414}
415
416static void test_hash_speed(const char *algo, unsigned int sec,
417 struct hash_speed *speed)
418{
419 struct scatterlist sg[TVMEMSIZE];
420 struct crypto_hash *tfm;
421 struct hash_desc desc;
422 static char output[1024];
423 int i;
424 int ret;
425
426 printk(KERN_INFO "\ntesting speed of %s\n", algo);
427
428 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
429
430 if (IS_ERR(tfm)) {
431 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
432 PTR_ERR(tfm));
433 return;
434 }
435
436 desc.tfm = tfm;
437 desc.flags = 0;
438
439 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
440 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
441 crypto_hash_digestsize(tfm), sizeof(output));
442 goto out;
443 }
444
445 test_hash_sg_init(sg);
446 for (i = 0; speed[i].blen != 0; i++) {
447 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
448 printk(KERN_ERR
449 "template (%u) too big for tvmem (%lu)\n",
450 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
451 goto out;
452 }
453
454 if (speed[i].klen)
455 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
456
457 printk(KERN_INFO "test%3u "
458 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
459 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
460
461 if (sec)
462 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
463 speed[i].plen, output, sec);
464 else
465 ret = test_hash_cycles(&desc, sg, speed[i].blen,
466 speed[i].plen, output);
467
468 if (ret) {
469 printk(KERN_ERR "hashing failed ret=%d\n", ret);
470 break;
471 }
472 }
473
474out:
475 crypto_free_hash(tfm);
476}
477
478struct tcrypt_result {
479 struct completion completion;
480 int err;
481};
482
483static void tcrypt_complete(struct crypto_async_request *req, int err)
484{
485 struct tcrypt_result *res = req->data;
486
487 if (err == -EINPROGRESS)
488 return;
489
490 res->err = err;
491 complete(&res->completion);
492}
493
494static inline int do_one_ahash_op(struct ahash_request *req, int ret)
495{
496 if (ret == -EINPROGRESS || ret == -EBUSY) {
497 struct tcrypt_result *tr = req->base.data;
498
499 ret = wait_for_completion_interruptible(&tr->completion);
500 if (!ret)
501 ret = tr->err;
502 INIT_COMPLETION(tr->completion);
503 }
504 return ret;
505}
506
507static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
508 char *out, int sec)
509{
510 unsigned long start, end;
511 int bcount;
512 int ret;
513
514 for (start = jiffies, end = start + sec * HZ, bcount = 0;
515 time_before(jiffies, end); bcount++) {
516 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
517 if (ret)
518 return ret;
519 }
520
521 printk("%6u opers/sec, %9lu bytes/sec\n",
522 bcount / sec, ((long)bcount * blen) / sec);
523
524 return 0;
525}
526
527static int test_ahash_jiffies(struct ahash_request *req, int blen,
528 int plen, char *out, int sec)
529{
530 unsigned long start, end;
531 int bcount, pcount;
532 int ret;
533
534 if (plen == blen)
535 return test_ahash_jiffies_digest(req, blen, out, sec);
536
537 for (start = jiffies, end = start + sec * HZ, bcount = 0;
538 time_before(jiffies, end); bcount++) {
539 ret = crypto_ahash_init(req);
540 if (ret)
541 return ret;
542 for (pcount = 0; pcount < blen; pcount += plen) {
543 ret = do_one_ahash_op(req, crypto_ahash_update(req));
544 if (ret)
545 return ret;
546 }
547 /* we assume there is enough space in 'out' for the result */
548 ret = do_one_ahash_op(req, crypto_ahash_final(req));
549 if (ret)
550 return ret;
551 }
552
553 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
554 bcount / sec, ((long)bcount * blen) / sec);
555
556 return 0;
557}
558
559static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
560 char *out)
561{
562 unsigned long cycles = 0;
563 int ret, i;
564
565 /* Warm-up run. */
566 for (i = 0; i < 4; i++) {
567 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
568 if (ret)
569 goto out;
570 }
571
572 /* The real thing. */
573 for (i = 0; i < 8; i++) {
574 cycles_t start, end;
575
576 start = get_cycles();
577
578 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
579 if (ret)
580 goto out;
581
582 end = get_cycles();
583
584 cycles += end - start;
585 }
586
587out:
588 if (ret)
589 return ret;
590
591 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
592 cycles / 8, cycles / (8 * blen));
593
594 return 0;
595}
596
597static int test_ahash_cycles(struct ahash_request *req, int blen,
598 int plen, char *out)
599{
600 unsigned long cycles = 0;
601 int i, pcount, ret;
602
603 if (plen == blen)
604 return test_ahash_cycles_digest(req, blen, out);
605
606 /* Warm-up run. */
607 for (i = 0; i < 4; i++) {
608 ret = crypto_ahash_init(req);
609 if (ret)
610 goto out;
611 for (pcount = 0; pcount < blen; pcount += plen) {
612 ret = do_one_ahash_op(req, crypto_ahash_update(req));
613 if (ret)
614 goto out;
615 }
616 ret = do_one_ahash_op(req, crypto_ahash_final(req));
617 if (ret)
618 goto out;
619 }
620
621 /* The real thing. */
622 for (i = 0; i < 8; i++) {
623 cycles_t start, end;
624
625 start = get_cycles();
626
627 ret = crypto_ahash_init(req);
628 if (ret)
629 goto out;
630 for (pcount = 0; pcount < blen; pcount += plen) {
631 ret = do_one_ahash_op(req, crypto_ahash_update(req));
632 if (ret)
633 goto out;
634 }
635 ret = do_one_ahash_op(req, crypto_ahash_final(req));
636 if (ret)
637 goto out;
638
639 end = get_cycles();
640
641 cycles += end - start;
642 }
643
644out:
645 if (ret)
646 return ret;
647
648 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
649 cycles / 8, cycles / (8 * blen));
650
651 return 0;
652}
653
654static void test_ahash_speed(const char *algo, unsigned int sec,
655 struct hash_speed *speed)
656{
657 struct scatterlist sg[TVMEMSIZE];
658 struct tcrypt_result tresult;
659 struct ahash_request *req;
660 struct crypto_ahash *tfm;
661 static char output[1024];
662 int i, ret;
663
664 printk(KERN_INFO "\ntesting speed of async %s\n", algo);
665
666 tfm = crypto_alloc_ahash(algo, 0, 0);
667 if (IS_ERR(tfm)) {
668 pr_err("failed to load transform for %s: %ld\n",
669 algo, PTR_ERR(tfm));
670 return;
671 }
672
673 if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
674 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
675 crypto_ahash_digestsize(tfm), sizeof(output));
676 goto out;
677 }
678
679 test_hash_sg_init(sg);
680 req = ahash_request_alloc(tfm, GFP_KERNEL);
681 if (!req) {
682 pr_err("ahash request allocation failure\n");
683 goto out;
684 }
685
686 init_completion(&tresult.completion);
687 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
688 tcrypt_complete, &tresult);
689
690 for (i = 0; speed[i].blen != 0; i++) {
691 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
692 pr_err("template (%u) too big for tvmem (%lu)\n",
693 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
694 break;
695 }
696
697 pr_info("test%3u "
698 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
699 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
700
701 ahash_request_set_crypt(req, sg, output, speed[i].plen);
702
703 if (sec)
704 ret = test_ahash_jiffies(req, speed[i].blen,
705 speed[i].plen, output, sec);
706 else
707 ret = test_ahash_cycles(req, speed[i].blen,
708 speed[i].plen, output);
709
710 if (ret) {
711 pr_err("hashing failed ret=%d\n", ret);
712 break;
713 }
714 }
715
716 ahash_request_free(req);
717
718out:
719 crypto_free_ahash(tfm);
720}
721
722static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
723{
724 if (ret == -EINPROGRESS || ret == -EBUSY) {
725 struct tcrypt_result *tr = req->base.data;
726
727 ret = wait_for_completion_interruptible(&tr->completion);
728 if (!ret)
729 ret = tr->err;
730 INIT_COMPLETION(tr->completion);
731 }
732
733 return ret;
734}
735
736static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
737 int blen, int sec)
738{
739 unsigned long start, end;
740 int bcount;
741 int ret;
742
743 for (start = jiffies, end = start + sec * HZ, bcount = 0;
744 time_before(jiffies, end); bcount++) {
745 if (enc)
746 ret = do_one_acipher_op(req,
747 crypto_ablkcipher_encrypt(req));
748 else
749 ret = do_one_acipher_op(req,
750 crypto_ablkcipher_decrypt(req));
751
752 if (ret)
753 return ret;
754 }
755
756 pr_cont("%d operations in %d seconds (%ld bytes)\n",
757 bcount, sec, (long)bcount * blen);
758 return 0;
759}
760
761static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
762 int blen)
763{
764 unsigned long cycles = 0;
765 int ret = 0;
766 int i;
767
768 /* Warm-up run. */
769 for (i = 0; i < 4; i++) {
770 if (enc)
771 ret = do_one_acipher_op(req,
772 crypto_ablkcipher_encrypt(req));
773 else
774 ret = do_one_acipher_op(req,
775 crypto_ablkcipher_decrypt(req));
776
777 if (ret)
778 goto out;
779 }
780
781 /* The real thing. */
782 for (i = 0; i < 8; i++) {
783 cycles_t start, end;
784
785 start = get_cycles();
786 if (enc)
787 ret = do_one_acipher_op(req,
788 crypto_ablkcipher_encrypt(req));
789 else
790 ret = do_one_acipher_op(req,
791 crypto_ablkcipher_decrypt(req));
792 end = get_cycles();
793
794 if (ret)
795 goto out;
796
797 cycles += end - start;
798 }
799
800out:
801 if (ret == 0)
802 pr_cont("1 operation in %lu cycles (%d bytes)\n",
803 (cycles + 4) / 8, blen);
804
805 return ret;
806}
807
808static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
809 struct cipher_speed_template *template,
810 unsigned int tcount, u8 *keysize)
811{
812 unsigned int ret, i, j, iv_len;
813 struct tcrypt_result tresult;
814 const char *key;
815 char iv[128];
816 struct ablkcipher_request *req;
817 struct crypto_ablkcipher *tfm;
818 const char *e;
819 u32 *b_size;
820
821 if (enc == ENCRYPT)
822 e = "encryption";
823 else
824 e = "decryption";
825
826 pr_info("\ntesting speed of async %s %s\n", algo, e);
827
828 init_completion(&tresult.completion);
829
830 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
831
832 if (IS_ERR(tfm)) {
833 pr_err("failed to load transform for %s: %ld\n", algo,
834 PTR_ERR(tfm));
835 return;
836 }
837
838 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
839 if (!req) {
840 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
841 algo);
842 goto out;
843 }
844
845 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
846 tcrypt_complete, &tresult);
847
848 i = 0;
849 do {
850 b_size = block_sizes;
851
852 do {
853 struct scatterlist sg[TVMEMSIZE];
854
855 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
856 pr_err("template (%u) too big for "
857 "tvmem (%lu)\n", *keysize + *b_size,
858 TVMEMSIZE * PAGE_SIZE);
859 goto out_free_req;
860 }
861
862 pr_info("test %u (%d bit key, %d byte blocks): ", i,
863 *keysize * 8, *b_size);
864
865 memset(tvmem[0], 0xff, PAGE_SIZE);
866
867 /* set key, plain text and IV */
868 key = tvmem[0];
869 for (j = 0; j < tcount; j++) {
870 if (template[j].klen == *keysize) {
871 key = template[j].key;
872 break;
873 }
874 }
875
876 crypto_ablkcipher_clear_flags(tfm, ~0);
877
878 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
879 if (ret) {
880 pr_err("setkey() failed flags=%x\n",
881 crypto_ablkcipher_get_flags(tfm));
882 goto out_free_req;
883 }
884
885 sg_init_table(sg, TVMEMSIZE);
886 sg_set_buf(sg, tvmem[0] + *keysize,
887 PAGE_SIZE - *keysize);
888 for (j = 1; j < TVMEMSIZE; j++) {
889 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
890 memset(tvmem[j], 0xff, PAGE_SIZE);
891 }
892
893 iv_len = crypto_ablkcipher_ivsize(tfm);
894 if (iv_len)
895 memset(&iv, 0xff, iv_len);
896
897 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
898
899 if (sec)
900 ret = test_acipher_jiffies(req, enc,
901 *b_size, sec);
902 else
903 ret = test_acipher_cycles(req, enc,
904 *b_size);
905
906 if (ret) {
907 pr_err("%s() failed flags=%x\n", e,
908 crypto_ablkcipher_get_flags(tfm));
909 break;
910 }
911 b_size++;
912 i++;
913 } while (*b_size);
914 keysize++;
915 } while (*keysize);
916
917out_free_req:
918 ablkcipher_request_free(req);
919out:
920 crypto_free_ablkcipher(tfm);
921}
922
923static void test_available(void)
924{
925 char **name = check;
926
927 while (*name) {
928 printk("alg %s ", *name);
929 printk(crypto_has_alg(*name, 0, 0) ?
930 "found\n" : "not found\n");
931 name++;
932 }
933}
934
935static inline int tcrypt_test(const char *alg)
936{
937 int ret;
938
939 ret = alg_test(alg, alg, 0, 0);
940 /* non-fips algs return -EINVAL in fips mode */
941 if (fips_enabled && ret == -EINVAL)
942 ret = 0;
943 return ret;
944}
945
946static int do_test(int m)
947{
948 int i;
949 int ret = 0;
950
951 switch (m) {
952 case 0:
953 for (i = 1; i < 200; i++)
954 ret += do_test(i);
955 break;
956
957 case 1:
958 ret += tcrypt_test("md5");
959 break;
960
961 case 2:
962 ret += tcrypt_test("sha1");
963 break;
964
965 case 3:
966 ret += tcrypt_test("ecb(des)");
967 ret += tcrypt_test("cbc(des)");
968 break;
969
970 case 4:
971 ret += tcrypt_test("ecb(des3_ede)");
972 ret += tcrypt_test("cbc(des3_ede)");
973 break;
974
975 case 5:
976 ret += tcrypt_test("md4");
977 break;
978
979 case 6:
980 ret += tcrypt_test("sha256");
981 break;
982
983 case 7:
984 ret += tcrypt_test("ecb(blowfish)");
985 ret += tcrypt_test("cbc(blowfish)");
986 ret += tcrypt_test("ctr(blowfish)");
987 break;
988
989 case 8:
990 ret += tcrypt_test("ecb(twofish)");
991 ret += tcrypt_test("cbc(twofish)");
992 ret += tcrypt_test("ctr(twofish)");
993 ret += tcrypt_test("lrw(twofish)");
994 ret += tcrypt_test("xts(twofish)");
995 break;
996
997 case 9:
998 ret += tcrypt_test("ecb(serpent)");
999 ret += tcrypt_test("cbc(serpent)");
1000 ret += tcrypt_test("ctr(serpent)");
1001 ret += tcrypt_test("lrw(serpent)");
1002 ret += tcrypt_test("xts(serpent)");
1003 break;
1004
1005 case 10:
1006 ret += tcrypt_test("ecb(aes)");
1007 ret += tcrypt_test("cbc(aes)");
1008 ret += tcrypt_test("lrw(aes)");
1009 ret += tcrypt_test("xts(aes)");
1010 ret += tcrypt_test("ctr(aes)");
1011 ret += tcrypt_test("rfc3686(ctr(aes))");
1012 break;
1013
1014 case 11:
1015 ret += tcrypt_test("sha384");
1016 break;
1017
1018 case 12:
1019 ret += tcrypt_test("sha512");
1020 break;
1021
1022 case 13:
1023 ret += tcrypt_test("deflate");
1024 break;
1025
1026 case 14:
1027 ret += tcrypt_test("ecb(cast5)");
1028 break;
1029
1030 case 15:
1031 ret += tcrypt_test("ecb(cast6)");
1032 break;
1033
1034 case 16:
1035 ret += tcrypt_test("ecb(arc4)");
1036 break;
1037
1038 case 17:
1039 ret += tcrypt_test("michael_mic");
1040 break;
1041
1042 case 18:
1043 ret += tcrypt_test("crc32c");
1044 break;
1045
1046 case 19:
1047 ret += tcrypt_test("ecb(tea)");
1048 break;
1049
1050 case 20:
1051 ret += tcrypt_test("ecb(xtea)");
1052 break;
1053
1054 case 21:
1055 ret += tcrypt_test("ecb(khazad)");
1056 break;
1057
1058 case 22:
1059 ret += tcrypt_test("wp512");
1060 break;
1061
1062 case 23:
1063 ret += tcrypt_test("wp384");
1064 break;
1065
1066 case 24:
1067 ret += tcrypt_test("wp256");
1068 break;
1069
1070 case 25:
1071 ret += tcrypt_test("ecb(tnepres)");
1072 break;
1073
1074 case 26:
1075 ret += tcrypt_test("ecb(anubis)");
1076 ret += tcrypt_test("cbc(anubis)");
1077 break;
1078
1079 case 27:
1080 ret += tcrypt_test("tgr192");
1081 break;
1082
1083 case 28:
1084
1085 ret += tcrypt_test("tgr160");
1086 break;
1087
1088 case 29:
1089 ret += tcrypt_test("tgr128");
1090 break;
1091
1092 case 30:
1093 ret += tcrypt_test("ecb(xeta)");
1094 break;
1095
1096 case 31:
1097 ret += tcrypt_test("pcbc(fcrypt)");
1098 break;
1099
1100 case 32:
1101 ret += tcrypt_test("ecb(camellia)");
1102 ret += tcrypt_test("cbc(camellia)");
1103 break;
1104 case 33:
1105 ret += tcrypt_test("sha224");
1106 break;
1107
1108 case 34:
1109 ret += tcrypt_test("salsa20");
1110 break;
1111
1112 case 35:
1113 ret += tcrypt_test("gcm(aes)");
1114 break;
1115
1116 case 36:
1117 ret += tcrypt_test("lzo");
1118 break;
1119
1120 case 37:
1121 ret += tcrypt_test("ccm(aes)");
1122 break;
1123
1124 case 38:
1125 ret += tcrypt_test("cts(cbc(aes))");
1126 break;
1127
1128 case 39:
1129 ret += tcrypt_test("rmd128");
1130 break;
1131
1132 case 40:
1133 ret += tcrypt_test("rmd160");
1134 break;
1135
1136 case 41:
1137 ret += tcrypt_test("rmd256");
1138 break;
1139
1140 case 42:
1141 ret += tcrypt_test("rmd320");
1142 break;
1143
1144 case 43:
1145 ret += tcrypt_test("ecb(seed)");
1146 break;
1147
1148 case 44:
1149 ret += tcrypt_test("zlib");
1150 break;
1151
1152 case 45:
1153 ret += tcrypt_test("rfc4309(ccm(aes))");
1154 break;
1155
1156 case 100:
1157 ret += tcrypt_test("hmac(md5)");
1158 break;
1159
1160 case 101:
1161 ret += tcrypt_test("hmac(sha1)");
1162 break;
1163
1164 case 102:
1165 ret += tcrypt_test("hmac(sha256)");
1166 break;
1167
1168 case 103:
1169 ret += tcrypt_test("hmac(sha384)");
1170 break;
1171
1172 case 104:
1173 ret += tcrypt_test("hmac(sha512)");
1174 break;
1175
1176 case 105:
1177 ret += tcrypt_test("hmac(sha224)");
1178 break;
1179
1180 case 106:
1181 ret += tcrypt_test("xcbc(aes)");
1182 break;
1183
1184 case 107:
1185 ret += tcrypt_test("hmac(rmd128)");
1186 break;
1187
1188 case 108:
1189 ret += tcrypt_test("hmac(rmd160)");
1190 break;
1191
1192 case 109:
1193 ret += tcrypt_test("vmac(aes)");
1194 break;
1195
1196 case 150:
1197 ret += tcrypt_test("ansi_cprng");
1198 break;
1199
1200 case 151:
1201 ret += tcrypt_test("rfc4106(gcm(aes))");
1202 break;
1203
1204 case 200:
1205 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1206 speed_template_16_24_32);
1207 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1208 speed_template_16_24_32);
1209 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1210 speed_template_16_24_32);
1211 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1212 speed_template_16_24_32);
1213 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1214 speed_template_32_40_48);
1215 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1216 speed_template_32_40_48);
1217 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1218 speed_template_32_48_64);
1219 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1220 speed_template_32_48_64);
1221 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1222 speed_template_16_24_32);
1223 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1224 speed_template_16_24_32);
1225 break;
1226
1227 case 201:
1228 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1229 des3_speed_template, DES3_SPEED_VECTORS,
1230 speed_template_24);
1231 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1232 des3_speed_template, DES3_SPEED_VECTORS,
1233 speed_template_24);
1234 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1235 des3_speed_template, DES3_SPEED_VECTORS,
1236 speed_template_24);
1237 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1238 des3_speed_template, DES3_SPEED_VECTORS,
1239 speed_template_24);
1240 break;
1241
1242 case 202:
1243 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1244 speed_template_16_24_32);
1245 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1246 speed_template_16_24_32);
1247 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1248 speed_template_16_24_32);
1249 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1250 speed_template_16_24_32);
1251 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1252 speed_template_16_24_32);
1253 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1254 speed_template_16_24_32);
1255 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1256 speed_template_32_40_48);
1257 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1258 speed_template_32_40_48);
1259 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1260 speed_template_32_48_64);
1261 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1262 speed_template_32_48_64);
1263 break;
1264
1265 case 203:
1266 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1267 speed_template_8_32);
1268 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1269 speed_template_8_32);
1270 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1271 speed_template_8_32);
1272 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1273 speed_template_8_32);
1274 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1275 speed_template_8_32);
1276 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1277 speed_template_8_32);
1278 break;
1279
1280 case 204:
1281 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1282 speed_template_8);
1283 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1284 speed_template_8);
1285 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1286 speed_template_8);
1287 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1288 speed_template_8);
1289 break;
1290
1291 case 205:
1292 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1293 speed_template_16_24_32);
1294 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1295 speed_template_16_24_32);
1296 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1297 speed_template_16_24_32);
1298 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1299 speed_template_16_24_32);
1300 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1301 speed_template_16_24_32);
1302 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1303 speed_template_16_24_32);
1304 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1305 speed_template_32_40_48);
1306 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1307 speed_template_32_40_48);
1308 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1309 speed_template_32_48_64);
1310 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1311 speed_template_32_48_64);
1312 break;
1313
1314 case 206:
1315 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1316 speed_template_16_32);
1317 break;
1318
1319 case 207:
1320 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1321 speed_template_16_32);
1322 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1323 speed_template_16_32);
1324 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1325 speed_template_16_32);
1326 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1327 speed_template_16_32);
1328 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1329 speed_template_16_32);
1330 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1331 speed_template_16_32);
1332 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1333 speed_template_32_48);
1334 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1335 speed_template_32_48);
1336 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1337 speed_template_32_64);
1338 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1339 speed_template_32_64);
1340 break;
1341
1342 case 300:
1343 /* fall through */
1344
1345 case 301:
1346 test_hash_speed("md4", sec, generic_hash_speed_template);
1347 if (mode > 300 && mode < 400) break;
1348
1349 case 302:
1350 test_hash_speed("md5", sec, generic_hash_speed_template);
1351 if (mode > 300 && mode < 400) break;
1352
1353 case 303:
1354 test_hash_speed("sha1", sec, generic_hash_speed_template);
1355 if (mode > 300 && mode < 400) break;
1356
1357 case 304:
1358 test_hash_speed("sha256", sec, generic_hash_speed_template);
1359 if (mode > 300 && mode < 400) break;
1360
1361 case 305:
1362 test_hash_speed("sha384", sec, generic_hash_speed_template);
1363 if (mode > 300 && mode < 400) break;
1364
1365 case 306:
1366 test_hash_speed("sha512", sec, generic_hash_speed_template);
1367 if (mode > 300 && mode < 400) break;
1368
1369 case 307:
1370 test_hash_speed("wp256", sec, generic_hash_speed_template);
1371 if (mode > 300 && mode < 400) break;
1372
1373 case 308:
1374 test_hash_speed("wp384", sec, generic_hash_speed_template);
1375 if (mode > 300 && mode < 400) break;
1376
1377 case 309:
1378 test_hash_speed("wp512", sec, generic_hash_speed_template);
1379 if (mode > 300 && mode < 400) break;
1380
1381 case 310:
1382 test_hash_speed("tgr128", sec, generic_hash_speed_template);
1383 if (mode > 300 && mode < 400) break;
1384
1385 case 311:
1386 test_hash_speed("tgr160", sec, generic_hash_speed_template);
1387 if (mode > 300 && mode < 400) break;
1388
1389 case 312:
1390 test_hash_speed("tgr192", sec, generic_hash_speed_template);
1391 if (mode > 300 && mode < 400) break;
1392
1393 case 313:
1394 test_hash_speed("sha224", sec, generic_hash_speed_template);
1395 if (mode > 300 && mode < 400) break;
1396
1397 case 314:
1398 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1399 if (mode > 300 && mode < 400) break;
1400
1401 case 315:
1402 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1403 if (mode > 300 && mode < 400) break;
1404
1405 case 316:
1406 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1407 if (mode > 300 && mode < 400) break;
1408
1409 case 317:
1410 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1411 if (mode > 300 && mode < 400) break;
1412
1413 case 318:
1414 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1415 if (mode > 300 && mode < 400) break;
1416
1417 case 399:
1418 break;
1419
1420 case 400:
1421 /* fall through */
1422
1423 case 401:
1424 test_ahash_speed("md4", sec, generic_hash_speed_template);
1425 if (mode > 400 && mode < 500) break;
1426
1427 case 402:
1428 test_ahash_speed("md5", sec, generic_hash_speed_template);
1429 if (mode > 400 && mode < 500) break;
1430
1431 case 403:
1432 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1433 if (mode > 400 && mode < 500) break;
1434
1435 case 404:
1436 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1437 if (mode > 400 && mode < 500) break;
1438
1439 case 405:
1440 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1441 if (mode > 400 && mode < 500) break;
1442
1443 case 406:
1444 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1445 if (mode > 400 && mode < 500) break;
1446
1447 case 407:
1448 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1449 if (mode > 400 && mode < 500) break;
1450
1451 case 408:
1452 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1453 if (mode > 400 && mode < 500) break;
1454
1455 case 409:
1456 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1457 if (mode > 400 && mode < 500) break;
1458
1459 case 410:
1460 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1461 if (mode > 400 && mode < 500) break;
1462
1463 case 411:
1464 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1465 if (mode > 400 && mode < 500) break;
1466
1467 case 412:
1468 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1469 if (mode > 400 && mode < 500) break;
1470
1471 case 413:
1472 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1473 if (mode > 400 && mode < 500) break;
1474
1475 case 414:
1476 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1477 if (mode > 400 && mode < 500) break;
1478
1479 case 415:
1480 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1481 if (mode > 400 && mode < 500) break;
1482
1483 case 416:
1484 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1485 if (mode > 400 && mode < 500) break;
1486
1487 case 417:
1488 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1489 if (mode > 400 && mode < 500) break;
1490
1491 case 499:
1492 break;
1493
1494 case 500:
1495 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1496 speed_template_16_24_32);
1497 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1498 speed_template_16_24_32);
1499 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1500 speed_template_16_24_32);
1501 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1502 speed_template_16_24_32);
1503 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1504 speed_template_32_40_48);
1505 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1506 speed_template_32_40_48);
1507 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1508 speed_template_32_48_64);
1509 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1510 speed_template_32_48_64);
1511 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1512 speed_template_16_24_32);
1513 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1514 speed_template_16_24_32);
1515 break;
1516
1517 case 501:
1518 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1519 des3_speed_template, DES3_SPEED_VECTORS,
1520 speed_template_24);
1521 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1522 des3_speed_template, DES3_SPEED_VECTORS,
1523 speed_template_24);
1524 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1525 des3_speed_template, DES3_SPEED_VECTORS,
1526 speed_template_24);
1527 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1528 des3_speed_template, DES3_SPEED_VECTORS,
1529 speed_template_24);
1530 break;
1531
1532 case 502:
1533 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1534 speed_template_8);
1535 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1536 speed_template_8);
1537 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1538 speed_template_8);
1539 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1540 speed_template_8);
1541 break;
1542
1543 case 503:
1544 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1545 speed_template_16_32);
1546 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1547 speed_template_16_32);
1548 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1549 speed_template_16_32);
1550 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1551 speed_template_16_32);
1552 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1553 speed_template_16_32);
1554 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1555 speed_template_16_32);
1556 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1557 speed_template_32_48);
1558 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1559 speed_template_32_48);
1560 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1561 speed_template_32_64);
1562 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1563 speed_template_32_64);
1564 break;
1565
1566 case 1000:
1567 test_available();
1568 break;
1569 }
1570
1571 return ret;
1572}
1573
1574static int do_alg_test(const char *alg, u32 type, u32 mask)
1575{
1576 return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
1577 0 : -ENOENT;
1578}
1579
1580static int __init tcrypt_mod_init(void)
1581{
1582 int err = -ENOMEM;
1583 int i;
1584
1585 for (i = 0; i < TVMEMSIZE; i++) {
1586 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
1587 if (!tvmem[i])
1588 goto err_free_tv;
1589 }
1590
1591 if (alg)
1592 err = do_alg_test(alg, type, mask);
1593 else
1594 err = do_test(mode);
1595
1596 if (err) {
1597 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
1598 goto err_free_tv;
1599 }
1600
1601 /* We intentionaly return -EAGAIN to prevent keeping the module,
1602 * unless we're running in fips mode. It does all its work from
1603 * init() and doesn't offer any runtime functionality, but in
1604 * the fips case, checking for a successful load is helpful.
1605 * => we don't need it in the memory, do we?
1606 * -- mludvig
1607 */
1608 if (!fips_enabled)
1609 err = -EAGAIN;
1610
1611err_free_tv:
1612 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
1613 free_page((unsigned long)tvmem[i]);
1614
1615 return err;
1616}
1617
1618/*
1619 * If an init function is provided, an exit function must also be provided
1620 * to allow module unload.
1621 */
1622static void __exit tcrypt_mod_fini(void) { }
1623
1624module_init(tcrypt_mod_init);
1625module_exit(tcrypt_mod_fini);
1626
1627module_param(alg, charp, 0);
1628module_param(type, uint, 0);
1629module_param(mask, uint, 0);
1630module_param(mode, int, 0);
1631module_param(sec, uint, 0);
1632MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
1633 "(defaults to zero which uses CPU cycles instead)");
1634
1635MODULE_LICENSE("GPL");
1636MODULE_DESCRIPTION("Quick & dirty crypto testing module");
1637MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");