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