tcrypt.c 51.1 KB
Newer Older
1
/*
L
Linus Torvalds 已提交
2 3 4 5 6 7 8
 * Quick & dirty crypto testing module.
 *
 * This will only exist until we have a better testing mechanism
 * (e.g. a char device).
 *
 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
9
 * Copyright (c) 2007 Nokia Siemens Networks
L
Linus Torvalds 已提交
10
 *
11 12 13 14 15 16 17
 * Updated RFC4106 AES-GCM testing.
 *    Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
 *             Adrian Hoban <adrian.hoban@intel.com>
 *             Gabriele Paoloni <gabriele.paoloni@intel.com>
 *             Tadeusz Struk (tadeusz.struk@intel.com)
 *             Copyright (c) 2010, Intel Corporation.
 *
L
Linus Torvalds 已提交
18 19
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
20
 * Software Foundation; either version 2 of the License, or (at your option)
L
Linus Torvalds 已提交
21 22 23 24
 * any later version.
 *
 */

25 26
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

27
#include <crypto/aead.h>
28
#include <crypto/hash.h>
H
Herbert Xu 已提交
29
#include <crypto/skcipher.h>
30
#include <linux/err.h>
31
#include <linux/fips.h>
L
Linus Torvalds 已提交
32
#include <linux/init.h>
33
#include <linux/gfp.h>
L
Linus Torvalds 已提交
34
#include <linux/module.h>
35
#include <linux/scatterlist.h>
L
Linus Torvalds 已提交
36 37
#include <linux/string.h>
#include <linux/moduleparam.h>
H
Harald Welte 已提交
38
#include <linux/jiffies.h>
39 40
#include <linux/timex.h>
#include <linux/interrupt.h>
L
Linus Torvalds 已提交
41 42 43
#include "tcrypt.h"

/*
44
 * Need slab memory for testing (size in number of pages).
L
Linus Torvalds 已提交
45
 */
46
#define TVMEMSIZE	4
L
Linus Torvalds 已提交
47 48

/*
49
* Used by test_cipher_speed()
L
Linus Torvalds 已提交
50 51 52 53
*/
#define ENCRYPT 1
#define DECRYPT 0

54 55
#define MAX_DIGEST_SIZE		64

56 57 58 59 60
/*
 * return a string with the driver name
 */
#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))

H
Harald Welte 已提交
61 62 63
/*
 * Used by test_cipher_speed()
 */
64
static unsigned int sec;
H
Harald Welte 已提交
65

66 67
static char *alg = NULL;
static u32 type;
H
Herbert Xu 已提交
68
static u32 mask;
L
Linus Torvalds 已提交
69
static int mode;
70
static char *tvmem[TVMEMSIZE];
L
Linus Torvalds 已提交
71 72

static char *check[] = {
73
	"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
74 75
	"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
	"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
76
	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
77
	"camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
78 79
	"lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
	NULL
L
Linus Torvalds 已提交
80 81
};

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
struct tcrypt_result {
	struct completion completion;
	int err;
};

static void tcrypt_complete(struct crypto_async_request *req, int err)
{
	struct tcrypt_result *res = req->data;

	if (err == -EINPROGRESS)
		return;

	res->err = err;
	complete(&res->completion);
}

static inline int do_one_aead_op(struct aead_request *req, int ret)
{
	if (ret == -EINPROGRESS || ret == -EBUSY) {
		struct tcrypt_result *tr = req->base.data;

		ret = wait_for_completion_interruptible(&tr->completion);
		if (!ret)
			ret = tr->err;
		reinit_completion(&tr->completion);
	}

	return ret;
}

112
static int test_aead_jiffies(struct aead_request *req, int enc,
M
Mark Rustad 已提交
113
				int blen, int secs)
114 115 116 117 118
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
119
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
120 121
	     time_before(jiffies, end); bcount++) {
		if (enc)
122
			ret = do_one_aead_op(req, crypto_aead_encrypt(req));
123
		else
124
			ret = do_one_aead_op(req, crypto_aead_decrypt(req));
125 126 127 128 129 130

		if (ret)
			return ret;
	}

	printk("%d operations in %d seconds (%ld bytes)\n",
M
Mark Rustad 已提交
131
	       bcount, secs, (long)bcount * blen);
132 133 134 135 136 137 138 139 140 141 142 143
	return 0;
}

static int test_aead_cycles(struct aead_request *req, int enc, int blen)
{
	unsigned long cycles = 0;
	int ret = 0;
	int i;

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
144
			ret = do_one_aead_op(req, crypto_aead_encrypt(req));
145
		else
146
			ret = do_one_aead_op(req, crypto_aead_decrypt(req));
147 148 149 150 151 152 153 154 155 156 157

		if (ret)
			goto out;
	}

	/* The real thing. */
	for (i = 0; i < 8; i++) {
		cycles_t start, end;

		start = get_cycles();
		if (enc)
158
			ret = do_one_aead_op(req, crypto_aead_encrypt(req));
159
		else
160
			ret = do_one_aead_op(req, crypto_aead_decrypt(req));
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
		end = get_cycles();

		if (ret)
			goto out;

		cycles += end - start;
	}

out:
	if (ret == 0)
		printk("1 operation in %lu cycles (%d bytes)\n",
		       (cycles + 4) / 8, blen);

	return ret;
}

177
static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };

#define XBUFSIZE 8
#define MAX_IVLEN 32

static int testmgr_alloc_buf(char *buf[XBUFSIZE])
{
	int i;

	for (i = 0; i < XBUFSIZE; i++) {
		buf[i] = (void *)__get_free_page(GFP_KERNEL);
		if (!buf[i])
			goto err_free_buf;
	}

	return 0;

err_free_buf:
	while (i-- > 0)
		free_page((unsigned long)buf[i]);

	return -ENOMEM;
}

static void testmgr_free_buf(char *buf[XBUFSIZE])
{
	int i;

	for (i = 0; i < XBUFSIZE; i++)
		free_page((unsigned long)buf[i]);
}

static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
			unsigned int buflen)
{
	int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
	int k, rem;

	if (np > XBUFSIZE) {
		rem = PAGE_SIZE;
		np = XBUFSIZE;
219 220
	} else {
		rem = buflen % PAGE_SIZE;
221
	}
222

223
	sg_init_table(sg, np + 1);
224 225
	np--;
	for (k = 0; k < np; k++)
226
		sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
227

228
	sg_set_buf(&sg[k + 1], xbuf[k], rem);
229 230
}

M
Mark Rustad 已提交
231
static void test_aead_speed(const char *algo, int enc, unsigned int secs,
232 233 234 235 236 237 238 239 240 241 242 243 244
			    struct aead_speed_template *template,
			    unsigned int tcount, u8 authsize,
			    unsigned int aad_size, u8 *keysize)
{
	unsigned int i, j;
	struct crypto_aead *tfm;
	int ret = -ENOMEM;
	const char *key;
	struct aead_request *req;
	struct scatterlist *sg;
	struct scatterlist *sgout;
	const char *e;
	void *assoc;
245
	char *iv;
246 247 248 249 250
	char *xbuf[XBUFSIZE];
	char *xoutbuf[XBUFSIZE];
	char *axbuf[XBUFSIZE];
	unsigned int *b_size;
	unsigned int iv_len;
251
	struct tcrypt_result result;
252

253 254 255 256
	iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
	if (!iv)
		return;

257 258
	if (aad_size >= PAGE_SIZE) {
		pr_err("associate data length (%u) too big\n", aad_size);
259
		goto out_noxbuf;
260 261
	}

262 263 264 265 266 267 268 269 270 271 272 273
	if (enc == ENCRYPT)
		e = "encryption";
	else
		e = "decryption";

	if (testmgr_alloc_buf(xbuf))
		goto out_noxbuf;
	if (testmgr_alloc_buf(axbuf))
		goto out_noaxbuf;
	if (testmgr_alloc_buf(xoutbuf))
		goto out_nooutbuf;

274
	sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
275 276
	if (!sg)
		goto out_nosg;
277
	sgout = &sg[9];
278

279
	tfm = crypto_alloc_aead(algo, 0, 0);
280 281 282 283

	if (IS_ERR(tfm)) {
		pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
284
		goto out_notfm;
285 286
	}

287
	init_completion(&result.completion);
288 289 290
	printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
			get_driver_name(crypto_aead, tfm), e);

291 292 293 294
	req = aead_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		pr_err("alg: aead: Failed to allocate request for %s\n",
		       algo);
295
		goto out_noreq;
296 297
	}

298 299 300
	aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
				  tcrypt_complete, &result);

301 302 303 304 305
	i = 0;
	do {
		b_size = aead_sizes;
		do {
			assoc = axbuf[0];
306
			memset(assoc, 0xff, aad_size);
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

			if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
				pr_err("template (%u) too big for tvmem (%lu)\n",
				       *keysize + *b_size,
					TVMEMSIZE * PAGE_SIZE);
				goto out;
			}

			key = tvmem[0];
			for (j = 0; j < tcount; j++) {
				if (template[j].klen == *keysize) {
					key = template[j].key;
					break;
				}
			}
			ret = crypto_aead_setkey(tfm, key, *keysize);
			ret = crypto_aead_setauthsize(tfm, authsize);

			iv_len = crypto_aead_ivsize(tfm);
			if (iv_len)
327
				memset(iv, 0xff, iv_len);
328 329 330 331 332 333 334 335 336 337 338 339 340 341

			crypto_aead_clear_flags(tfm, ~0);
			printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
					i, *keysize * 8, *b_size);


			memset(tvmem[0], 0xff, PAGE_SIZE);

			if (ret) {
				pr_err("setkey() failed flags=%x\n",
						crypto_aead_get_flags(tfm));
				goto out;
			}

342
			sg_init_aead(sg, xbuf,
343 344
				    *b_size + (enc ? authsize : 0));

345
			sg_init_aead(sgout, xoutbuf,
346 347
				    *b_size + (enc ? authsize : 0));

348 349 350
			sg_set_buf(&sg[0], assoc, aad_size);
			sg_set_buf(&sgout[0], assoc, aad_size);

351
			aead_request_set_crypt(req, sg, sgout, *b_size, iv);
352
			aead_request_set_ad(req, aad_size);
353

M
Mark Rustad 已提交
354 355 356
			if (secs)
				ret = test_aead_jiffies(req, enc, *b_size,
							secs);
357 358 359 360 361 362 363 364 365 366 367 368 369 370
			else
				ret = test_aead_cycles(req, enc, *b_size);

			if (ret) {
				pr_err("%s() failed return code=%d\n", e, ret);
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);

out:
371 372
	aead_request_free(req);
out_noreq:
373
	crypto_free_aead(tfm);
374
out_notfm:
375 376 377 378 379 380 381 382
	kfree(sg);
out_nosg:
	testmgr_free_buf(xoutbuf);
out_nooutbuf:
	testmgr_free_buf(axbuf);
out_noaxbuf:
	testmgr_free_buf(xbuf);
out_noxbuf:
383
	kfree(iv);
384 385
	return;
}
386

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
static void test_hash_sg_init(struct scatterlist *sg)
{
	int i;

	sg_init_table(sg, TVMEMSIZE);
	for (i = 0; i < TVMEMSIZE; i++) {
		sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
		memset(tvmem[i], 0xff, PAGE_SIZE);
	}
}

static inline int do_one_ahash_op(struct ahash_request *req, int ret)
{
	if (ret == -EINPROGRESS || ret == -EBUSY) {
		struct tcrypt_result *tr = req->base.data;

403
		wait_for_completion(&tr->completion);
404
		reinit_completion(&tr->completion);
405
		ret = tr->err;
406 407 408 409
	}
	return ret;
}

410 411 412 413 414 415 416
struct test_mb_ahash_data {
	struct scatterlist sg[TVMEMSIZE];
	char result[64];
	struct ahash_request *req;
	struct tcrypt_result tresult;
	char *xbuf[XBUFSIZE];
};
417 418

static void test_mb_ahash_speed(const char *algo, unsigned int sec,
419
				struct hash_speed *speed)
420
{
421
	struct test_mb_ahash_data *data;
422
	struct crypto_ahash *tfm;
423
	unsigned long start, end;
424
	unsigned long cycles;
425 426 427 428 429 430
	unsigned int i, j, k;
	int ret;

	data = kzalloc(sizeof(*data) * 8, GFP_KERNEL);
	if (!data)
		return;
431 432 433 434 435

	tfm = crypto_alloc_ahash(algo, 0, 0);
	if (IS_ERR(tfm)) {
		pr_err("failed to load transform for %s: %ld\n",
			algo, PTR_ERR(tfm));
436
		goto free_data;
437
	}
438

439
	for (i = 0; i < 8; ++i) {
440 441
		if (testmgr_alloc_buf(data[i].xbuf))
			goto out;
442

443
		init_completion(&data[i].tresult.completion);
444

445 446
		data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
		if (!data[i].req) {
447 448
			pr_err("alg: hash: Failed to allocate request for %s\n",
			       algo);
449
			goto out;
450 451
		}

452 453 454
		ahash_request_set_callback(data[i].req, 0,
					   tcrypt_complete, &data[i].tresult);
		test_hash_sg_init(data[i].sg);
455 456
	}

457 458
	pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
		get_driver_name(crypto_ahash, tfm));
459 460

	for (i = 0; speed[i].blen != 0; i++) {
461 462 463 464
		/* For some reason this only tests digests. */
		if (speed[i].blen != speed[i].plen)
			continue;

465
		if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
466 467 468
			pr_err("template (%u) too big for tvmem (%lu)\n",
			       speed[i].blen, TVMEMSIZE * PAGE_SIZE);
			goto out;
469 470 471 472 473
		}

		if (speed[i].klen)
			crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);

474 475 476
		for (k = 0; k < 8; k++)
			ahash_request_set_crypt(data[k].req, data[k].sg,
						data[k].result, speed[i].blen);
477

478 479
		pr_info("test%3u "
			"(%5u byte blocks,%5u bytes per update,%4u updates): ",
480 481 482
			i, speed[i].blen, speed[i].plen,
			speed[i].blen / speed[i].plen);

483 484 485 486
		start = get_cycles();

		for (k = 0; k < 8; k++) {
			ret = crypto_ahash_digest(data[k].req);
487 488
			if (ret == -EINPROGRESS) {
				ret = 0;
489
				continue;
490
			}
491 492 493 494 495 496

			if (ret)
				break;

			complete(&data[k].tresult.completion);
			data[k].tresult.err = 0;
497 498
		}

499 500
		for (j = 0; j < k; j++) {
			struct tcrypt_result *tr = &data[j].tresult;
501

502 503 504
			wait_for_completion(&tr->completion);
			if (tr->err)
				ret = tr->err;
505 506
		}

507 508 509 510 511 512 513 514 515
		end = get_cycles();
		cycles = end - start;
		pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
			cycles, cycles / (8 * speed[i].blen));

		if (ret) {
			pr_err("At least one hashing failed ret=%d\n", ret);
			break;
		}
516 517 518 519
	}

out:
	for (k = 0; k < 8; ++k)
520 521
		ahash_request_free(data[k].req);

522
	for (k = 0; k < 8; ++k)
523 524 525 526 527 528
		testmgr_free_buf(data[k].xbuf);

	crypto_free_ahash(tfm);

free_data:
	kfree(data);
529 530
}

531
static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
M
Mark Rustad 已提交
532
				     char *out, int secs)
533 534 535 536 537
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
538
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
539 540 541 542 543 544 545
	     time_before(jiffies, end); bcount++) {
		ret = do_one_ahash_op(req, crypto_ahash_digest(req));
		if (ret)
			return ret;
	}

	printk("%6u opers/sec, %9lu bytes/sec\n",
M
Mark Rustad 已提交
546
	       bcount / secs, ((long)bcount * blen) / secs);
547 548 549 550 551

	return 0;
}

static int test_ahash_jiffies(struct ahash_request *req, int blen,
M
Mark Rustad 已提交
552
			      int plen, char *out, int secs)
553 554 555 556 557 558
{
	unsigned long start, end;
	int bcount, pcount;
	int ret;

	if (plen == blen)
M
Mark Rustad 已提交
559
		return test_ahash_jiffies_digest(req, blen, out, secs);
560

M
Mark Rustad 已提交
561
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
562
	     time_before(jiffies, end); bcount++) {
563
		ret = do_one_ahash_op(req, crypto_ahash_init(req));
564 565 566 567 568 569 570 571 572 573 574 575 576 577
		if (ret)
			return ret;
		for (pcount = 0; pcount < blen; pcount += plen) {
			ret = do_one_ahash_op(req, crypto_ahash_update(req));
			if (ret)
				return ret;
		}
		/* we assume there is enough space in 'out' for the result */
		ret = do_one_ahash_op(req, crypto_ahash_final(req));
		if (ret)
			return ret;
	}

	pr_cont("%6u opers/sec, %9lu bytes/sec\n",
M
Mark Rustad 已提交
578
		bcount / secs, ((long)bcount * blen) / secs);
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631

	return 0;
}

static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
				    char *out)
{
	unsigned long cycles = 0;
	int ret, i;

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		ret = do_one_ahash_op(req, crypto_ahash_digest(req));
		if (ret)
			goto out;
	}

	/* The real thing. */
	for (i = 0; i < 8; i++) {
		cycles_t start, end;

		start = get_cycles();

		ret = do_one_ahash_op(req, crypto_ahash_digest(req));
		if (ret)
			goto out;

		end = get_cycles();

		cycles += end - start;
	}

out:
	if (ret)
		return ret;

	pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
		cycles / 8, cycles / (8 * blen));

	return 0;
}

static int test_ahash_cycles(struct ahash_request *req, int blen,
			     int plen, char *out)
{
	unsigned long cycles = 0;
	int i, pcount, ret;

	if (plen == blen)
		return test_ahash_cycles_digest(req, blen, out);

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
632
		ret = do_one_ahash_op(req, crypto_ahash_init(req));
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
		if (ret)
			goto out;
		for (pcount = 0; pcount < blen; pcount += plen) {
			ret = do_one_ahash_op(req, crypto_ahash_update(req));
			if (ret)
				goto out;
		}
		ret = do_one_ahash_op(req, crypto_ahash_final(req));
		if (ret)
			goto out;
	}

	/* The real thing. */
	for (i = 0; i < 8; i++) {
		cycles_t start, end;

		start = get_cycles();

651
		ret = do_one_ahash_op(req, crypto_ahash_init(req));
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
		if (ret)
			goto out;
		for (pcount = 0; pcount < blen; pcount += plen) {
			ret = do_one_ahash_op(req, crypto_ahash_update(req));
			if (ret)
				goto out;
		}
		ret = do_one_ahash_op(req, crypto_ahash_final(req));
		if (ret)
			goto out;

		end = get_cycles();

		cycles += end - start;
	}

out:
	if (ret)
		return ret;

	pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
		cycles / 8, cycles / (8 * blen));

	return 0;
}

H
Herbert Xu 已提交
678 679
static void test_ahash_speed_common(const char *algo, unsigned int secs,
				    struct hash_speed *speed, unsigned mask)
680 681 682 683 684
{
	struct scatterlist sg[TVMEMSIZE];
	struct tcrypt_result tresult;
	struct ahash_request *req;
	struct crypto_ahash *tfm;
685
	char *output;
686 687
	int i, ret;

H
Herbert Xu 已提交
688
	tfm = crypto_alloc_ahash(algo, 0, mask);
689 690 691 692 693 694
	if (IS_ERR(tfm)) {
		pr_err("failed to load transform for %s: %ld\n",
		       algo, PTR_ERR(tfm));
		return;
	}

695 696 697
	printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
			get_driver_name(crypto_ahash, tfm));

698 699 700
	if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
		pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
		       MAX_DIGEST_SIZE);
701 702 703 704 705 706 707 708 709 710 711 712 713 714
		goto out;
	}

	test_hash_sg_init(sg);
	req = ahash_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		pr_err("ahash request allocation failure\n");
		goto out;
	}

	init_completion(&tresult.completion);
	ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
				   tcrypt_complete, &tresult);

715 716 717 718
	output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
	if (!output)
		goto out_nomem;

719 720 721 722 723 724 725 726 727 728 729 730 731
	for (i = 0; speed[i].blen != 0; i++) {
		if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
			pr_err("template (%u) too big for tvmem (%lu)\n",
			       speed[i].blen, TVMEMSIZE * PAGE_SIZE);
			break;
		}

		pr_info("test%3u "
			"(%5u byte blocks,%5u bytes per update,%4u updates): ",
			i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);

		ahash_request_set_crypt(req, sg, output, speed[i].plen);

M
Mark Rustad 已提交
732
		if (secs)
733
			ret = test_ahash_jiffies(req, speed[i].blen,
M
Mark Rustad 已提交
734
						 speed[i].plen, output, secs);
735 736 737 738 739 740 741 742 743 744
		else
			ret = test_ahash_cycles(req, speed[i].blen,
						speed[i].plen, output);

		if (ret) {
			pr_err("hashing failed ret=%d\n", ret);
			break;
		}
	}

745 746 747
	kfree(output);

out_nomem:
748 749 750 751 752 753
	ahash_request_free(req);

out:
	crypto_free_ahash(tfm);
}

H
Herbert Xu 已提交
754 755 756 757 758 759 760 761 762 763 764 765
static void test_ahash_speed(const char *algo, unsigned int secs,
			     struct hash_speed *speed)
{
	return test_ahash_speed_common(algo, secs, speed, 0);
}

static void test_hash_speed(const char *algo, unsigned int secs,
			    struct hash_speed *speed)
{
	return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
}

H
Herbert Xu 已提交
766
static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
767 768 769 770
{
	if (ret == -EINPROGRESS || ret == -EBUSY) {
		struct tcrypt_result *tr = req->base.data;

771
		wait_for_completion(&tr->completion);
772
		reinit_completion(&tr->completion);
773
		ret = tr->err;
774 775 776 777 778
	}

	return ret;
}

H
Herbert Xu 已提交
779
static int test_acipher_jiffies(struct skcipher_request *req, int enc,
M
Mark Rustad 已提交
780
				int blen, int secs)
781 782 783 784 785
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
786
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
787 788 789
	     time_before(jiffies, end); bcount++) {
		if (enc)
			ret = do_one_acipher_op(req,
H
Herbert Xu 已提交
790
						crypto_skcipher_encrypt(req));
791 792
		else
			ret = do_one_acipher_op(req,
H
Herbert Xu 已提交
793
						crypto_skcipher_decrypt(req));
794 795 796 797 798 799

		if (ret)
			return ret;
	}

	pr_cont("%d operations in %d seconds (%ld bytes)\n",
M
Mark Rustad 已提交
800
		bcount, secs, (long)bcount * blen);
801 802 803
	return 0;
}

H
Herbert Xu 已提交
804
static int test_acipher_cycles(struct skcipher_request *req, int enc,
805 806 807 808 809 810 811 812 813 814
			       int blen)
{
	unsigned long cycles = 0;
	int ret = 0;
	int i;

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
			ret = do_one_acipher_op(req,
H
Herbert Xu 已提交
815
						crypto_skcipher_encrypt(req));
816 817
		else
			ret = do_one_acipher_op(req,
H
Herbert Xu 已提交
818
						crypto_skcipher_decrypt(req));
819 820 821 822 823 824 825 826 827 828 829 830

		if (ret)
			goto out;
	}

	/* The real thing. */
	for (i = 0; i < 8; i++) {
		cycles_t start, end;

		start = get_cycles();
		if (enc)
			ret = do_one_acipher_op(req,
H
Herbert Xu 已提交
831
						crypto_skcipher_encrypt(req));
832 833
		else
			ret = do_one_acipher_op(req,
H
Herbert Xu 已提交
834
						crypto_skcipher_decrypt(req));
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
		end = get_cycles();

		if (ret)
			goto out;

		cycles += end - start;
	}

out:
	if (ret == 0)
		pr_cont("1 operation in %lu cycles (%d bytes)\n",
			(cycles + 4) / 8, blen);

	return ret;
}

H
Herbert Xu 已提交
851 852 853
static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
				struct cipher_speed_template *template,
				unsigned int tcount, u8 *keysize, bool async)
854
{
855
	unsigned int ret, i, j, k, iv_len;
856 857 858
	struct tcrypt_result tresult;
	const char *key;
	char iv[128];
H
Herbert Xu 已提交
859 860
	struct skcipher_request *req;
	struct crypto_skcipher *tfm;
861 862 863 864 865 866 867 868 869 870
	const char *e;
	u32 *b_size;

	if (enc == ENCRYPT)
		e = "encryption";
	else
		e = "decryption";

	init_completion(&tresult.completion);

H
Herbert Xu 已提交
871
	tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
872 873 874 875 876 877 878

	if (IS_ERR(tfm)) {
		pr_err("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
		return;
	}

879
	pr_info("\ntesting speed of async %s (%s) %s\n", algo,
H
Herbert Xu 已提交
880
			get_driver_name(crypto_skcipher, tfm), e);
881

H
Herbert Xu 已提交
882
	req = skcipher_request_alloc(tfm, GFP_KERNEL);
883 884 885 886 887 888
	if (!req) {
		pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
		       algo);
		goto out;
	}

H
Herbert Xu 已提交
889 890
	skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
				      tcrypt_complete, &tresult);
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919

	i = 0;
	do {
		b_size = block_sizes;

		do {
			struct scatterlist sg[TVMEMSIZE];

			if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
				pr_err("template (%u) too big for "
				       "tvmem (%lu)\n", *keysize + *b_size,
				       TVMEMSIZE * PAGE_SIZE);
				goto out_free_req;
			}

			pr_info("test %u (%d bit key, %d byte blocks): ", i,
				*keysize * 8, *b_size);

			memset(tvmem[0], 0xff, PAGE_SIZE);

			/* set key, plain text and IV */
			key = tvmem[0];
			for (j = 0; j < tcount; j++) {
				if (template[j].klen == *keysize) {
					key = template[j].key;
					break;
				}
			}

H
Herbert Xu 已提交
920
			crypto_skcipher_clear_flags(tfm, ~0);
921

H
Herbert Xu 已提交
922
			ret = crypto_skcipher_setkey(tfm, key, *keysize);
923 924
			if (ret) {
				pr_err("setkey() failed flags=%x\n",
H
Herbert Xu 已提交
925
					crypto_skcipher_get_flags(tfm));
926 927 928
				goto out_free_req;
			}

929
			k = *keysize + *b_size;
930 931
			sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));

932 933
			if (k > PAGE_SIZE) {
				sg_set_buf(sg, tvmem[0] + *keysize,
934
				   PAGE_SIZE - *keysize);
935 936 937 938 939 940 941 942 943 944 945 946
				k -= PAGE_SIZE;
				j = 1;
				while (k > PAGE_SIZE) {
					sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
					memset(tvmem[j], 0xff, PAGE_SIZE);
					j++;
					k -= PAGE_SIZE;
				}
				sg_set_buf(sg + j, tvmem[j], k);
				memset(tvmem[j], 0xff, k);
			} else {
				sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
947 948
			}

H
Herbert Xu 已提交
949
			iv_len = crypto_skcipher_ivsize(tfm);
950 951 952
			if (iv_len)
				memset(&iv, 0xff, iv_len);

H
Herbert Xu 已提交
953
			skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
954

M
Mark Rustad 已提交
955
			if (secs)
956
				ret = test_acipher_jiffies(req, enc,
M
Mark Rustad 已提交
957
							   *b_size, secs);
958 959 960 961 962 963
			else
				ret = test_acipher_cycles(req, enc,
							  *b_size);

			if (ret) {
				pr_err("%s() failed flags=%x\n", e,
H
Herbert Xu 已提交
964
				       crypto_skcipher_get_flags(tfm));
965 966 967 968 969 970 971 972 973
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);

out_free_req:
H
Herbert Xu 已提交
974
	skcipher_request_free(req);
975
out:
H
Herbert Xu 已提交
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
	crypto_free_skcipher(tfm);
}

static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
			       struct cipher_speed_template *template,
			       unsigned int tcount, u8 *keysize)
{
	return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
				   true);
}

static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
			      struct cipher_speed_template *template,
			      unsigned int tcount, u8 *keysize)
{
	return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
				   false);
993 994
}

995
static void test_available(void)
L
Linus Torvalds 已提交
996 997
{
	char **name = check;
998

L
Linus Torvalds 已提交
999 1000
	while (*name) {
		printk("alg %s ", *name);
1001
		printk(crypto_has_alg(*name, 0, 0) ?
1002
		       "found\n" : "not found\n");
L
Linus Torvalds 已提交
1003
		name++;
1004
	}
L
Linus Torvalds 已提交
1005 1006
}

1007 1008
static inline int tcrypt_test(const char *alg)
{
1009 1010
	int ret;

1011 1012
	pr_debug("testing %s\n", alg);

1013 1014 1015 1016 1017
	ret = alg_test(alg, alg, 0, 0);
	/* non-fips algs return -EINVAL in fips mode */
	if (fips_enabled && ret == -EINVAL)
		ret = 0;
	return ret;
1018 1019
}

1020
static int do_test(const char *alg, u32 type, u32 mask, int m)
1021 1022
{
	int i;
1023
	int ret = 0;
1024 1025

	switch (m) {
L
Linus Torvalds 已提交
1026
	case 0:
1027 1028 1029 1030 1031 1032 1033
		if (alg) {
			if (!crypto_has_alg(alg, type,
					    mask ?: CRYPTO_ALG_TYPE_MASK))
				ret = -ENOENT;
			break;
		}

1034
		for (i = 1; i < 200; i++)
1035
			ret += do_test(NULL, 0, 0, i);
L
Linus Torvalds 已提交
1036 1037 1038
		break;

	case 1:
1039
		ret += tcrypt_test("md5");
L
Linus Torvalds 已提交
1040 1041 1042
		break;

	case 2:
1043
		ret += tcrypt_test("sha1");
L
Linus Torvalds 已提交
1044 1045 1046
		break;

	case 3:
1047 1048
		ret += tcrypt_test("ecb(des)");
		ret += tcrypt_test("cbc(des)");
1049
		ret += tcrypt_test("ctr(des)");
L
Linus Torvalds 已提交
1050 1051 1052
		break;

	case 4:
1053 1054
		ret += tcrypt_test("ecb(des3_ede)");
		ret += tcrypt_test("cbc(des3_ede)");
1055
		ret += tcrypt_test("ctr(des3_ede)");
L
Linus Torvalds 已提交
1056 1057 1058
		break;

	case 5:
1059
		ret += tcrypt_test("md4");
L
Linus Torvalds 已提交
1060
		break;
1061

L
Linus Torvalds 已提交
1062
	case 6:
1063
		ret += tcrypt_test("sha256");
L
Linus Torvalds 已提交
1064
		break;
1065

L
Linus Torvalds 已提交
1066
	case 7:
1067 1068
		ret += tcrypt_test("ecb(blowfish)");
		ret += tcrypt_test("cbc(blowfish)");
1069
		ret += tcrypt_test("ctr(blowfish)");
L
Linus Torvalds 已提交
1070 1071 1072
		break;

	case 8:
1073 1074
		ret += tcrypt_test("ecb(twofish)");
		ret += tcrypt_test("cbc(twofish)");
1075
		ret += tcrypt_test("ctr(twofish)");
1076
		ret += tcrypt_test("lrw(twofish)");
1077
		ret += tcrypt_test("xts(twofish)");
L
Linus Torvalds 已提交
1078
		break;
1079

L
Linus Torvalds 已提交
1080
	case 9:
1081
		ret += tcrypt_test("ecb(serpent)");
1082 1083
		ret += tcrypt_test("cbc(serpent)");
		ret += tcrypt_test("ctr(serpent)");
1084
		ret += tcrypt_test("lrw(serpent)");
1085
		ret += tcrypt_test("xts(serpent)");
L
Linus Torvalds 已提交
1086 1087 1088
		break;

	case 10:
1089 1090 1091 1092 1093 1094
		ret += tcrypt_test("ecb(aes)");
		ret += tcrypt_test("cbc(aes)");
		ret += tcrypt_test("lrw(aes)");
		ret += tcrypt_test("xts(aes)");
		ret += tcrypt_test("ctr(aes)");
		ret += tcrypt_test("rfc3686(ctr(aes))");
L
Linus Torvalds 已提交
1095 1096 1097
		break;

	case 11:
1098
		ret += tcrypt_test("sha384");
L
Linus Torvalds 已提交
1099
		break;
1100

L
Linus Torvalds 已提交
1101
	case 12:
1102
		ret += tcrypt_test("sha512");
L
Linus Torvalds 已提交
1103 1104 1105
		break;

	case 13:
1106
		ret += tcrypt_test("deflate");
L
Linus Torvalds 已提交
1107 1108 1109
		break;

	case 14:
1110
		ret += tcrypt_test("ecb(cast5)");
1111 1112
		ret += tcrypt_test("cbc(cast5)");
		ret += tcrypt_test("ctr(cast5)");
L
Linus Torvalds 已提交
1113 1114 1115
		break;

	case 15:
1116
		ret += tcrypt_test("ecb(cast6)");
1117 1118 1119 1120
		ret += tcrypt_test("cbc(cast6)");
		ret += tcrypt_test("ctr(cast6)");
		ret += tcrypt_test("lrw(cast6)");
		ret += tcrypt_test("xts(cast6)");
L
Linus Torvalds 已提交
1121 1122 1123
		break;

	case 16:
1124
		ret += tcrypt_test("ecb(arc4)");
L
Linus Torvalds 已提交
1125 1126 1127
		break;

	case 17:
1128
		ret += tcrypt_test("michael_mic");
L
Linus Torvalds 已提交
1129 1130 1131
		break;

	case 18:
1132
		ret += tcrypt_test("crc32c");
L
Linus Torvalds 已提交
1133 1134 1135
		break;

	case 19:
1136
		ret += tcrypt_test("ecb(tea)");
L
Linus Torvalds 已提交
1137 1138 1139
		break;

	case 20:
1140
		ret += tcrypt_test("ecb(xtea)");
L
Linus Torvalds 已提交
1141 1142 1143
		break;

	case 21:
1144
		ret += tcrypt_test("ecb(khazad)");
L
Linus Torvalds 已提交
1145 1146 1147
		break;

	case 22:
1148
		ret += tcrypt_test("wp512");
L
Linus Torvalds 已提交
1149 1150 1151
		break;

	case 23:
1152
		ret += tcrypt_test("wp384");
L
Linus Torvalds 已提交
1153 1154 1155
		break;

	case 24:
1156
		ret += tcrypt_test("wp256");
L
Linus Torvalds 已提交
1157 1158 1159
		break;

	case 25:
1160
		ret += tcrypt_test("ecb(tnepres)");
L
Linus Torvalds 已提交
1161 1162 1163
		break;

	case 26:
1164 1165
		ret += tcrypt_test("ecb(anubis)");
		ret += tcrypt_test("cbc(anubis)");
L
Linus Torvalds 已提交
1166 1167 1168
		break;

	case 27:
1169
		ret += tcrypt_test("tgr192");
L
Linus Torvalds 已提交
1170 1171 1172
		break;

	case 28:
1173
		ret += tcrypt_test("tgr160");
L
Linus Torvalds 已提交
1174 1175 1176
		break;

	case 29:
1177
		ret += tcrypt_test("tgr128");
L
Linus Torvalds 已提交
1178
		break;
1179

A
Aaron Grothe 已提交
1180
	case 30:
1181
		ret += tcrypt_test("ecb(xeta)");
A
Aaron Grothe 已提交
1182
		break;
L
Linus Torvalds 已提交
1183

1184
	case 31:
1185
		ret += tcrypt_test("pcbc(fcrypt)");
1186 1187
		break;

1188
	case 32:
1189 1190
		ret += tcrypt_test("ecb(camellia)");
		ret += tcrypt_test("cbc(camellia)");
1191 1192 1193
		ret += tcrypt_test("ctr(camellia)");
		ret += tcrypt_test("lrw(camellia)");
		ret += tcrypt_test("xts(camellia)");
1194
		break;
1195

1196
	case 33:
1197
		ret += tcrypt_test("sha224");
1198
		break;
1199

1200
	case 34:
1201
		ret += tcrypt_test("salsa20");
1202 1203
		break;

1204
	case 35:
1205
		ret += tcrypt_test("gcm(aes)");
1206 1207
		break;

1208
	case 36:
1209
		ret += tcrypt_test("lzo");
1210 1211
		break;

J
Joy Latten 已提交
1212
	case 37:
1213
		ret += tcrypt_test("ccm(aes)");
J
Joy Latten 已提交
1214 1215
		break;

1216
	case 38:
1217
		ret += tcrypt_test("cts(cbc(aes))");
1218 1219
		break;

1220
        case 39:
1221
		ret += tcrypt_test("rmd128");
1222 1223 1224
		break;

        case 40:
1225
		ret += tcrypt_test("rmd160");
1226 1227
		break;

1228
	case 41:
1229
		ret += tcrypt_test("rmd256");
1230 1231 1232
		break;

	case 42:
1233
		ret += tcrypt_test("rmd320");
1234 1235 1236
		break;

	case 43:
1237
		ret += tcrypt_test("ecb(seed)");
1238 1239
		break;

1240
	case 44:
1241
		ret += tcrypt_test("zlib");
1242 1243
		break;

1244
	case 45:
1245
		ret += tcrypt_test("rfc4309(ccm(aes))");
1246 1247
		break;

1248 1249 1250 1251
	case 46:
		ret += tcrypt_test("ghash");
		break;

1252 1253 1254 1255
	case 47:
		ret += tcrypt_test("crct10dif");
		break;

1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
	case 48:
		ret += tcrypt_test("sha3-224");
		break;

	case 49:
		ret += tcrypt_test("sha3-256");
		break;

	case 50:
		ret += tcrypt_test("sha3-384");
		break;

	case 51:
		ret += tcrypt_test("sha3-512");
		break;

1272 1273 1274 1275
	case 52:
		ret += tcrypt_test("sm3");
		break;

L
Linus Torvalds 已提交
1276
	case 100:
1277
		ret += tcrypt_test("hmac(md5)");
L
Linus Torvalds 已提交
1278
		break;
1279

L
Linus Torvalds 已提交
1280
	case 101:
1281
		ret += tcrypt_test("hmac(sha1)");
L
Linus Torvalds 已提交
1282
		break;
1283

L
Linus Torvalds 已提交
1284
	case 102:
1285
		ret += tcrypt_test("hmac(sha256)");
L
Linus Torvalds 已提交
1286 1287
		break;

1288
	case 103:
1289
		ret += tcrypt_test("hmac(sha384)");
1290 1291 1292
		break;

	case 104:
1293
		ret += tcrypt_test("hmac(sha512)");
1294
		break;
1295

1296
	case 105:
1297
		ret += tcrypt_test("hmac(sha224)");
1298
		break;
L
Linus Torvalds 已提交
1299

1300
	case 106:
1301
		ret += tcrypt_test("xcbc(aes)");
1302 1303
		break;

1304
	case 107:
1305
		ret += tcrypt_test("hmac(rmd128)");
1306 1307 1308
		break;

	case 108:
1309
		ret += tcrypt_test("hmac(rmd160)");
1310 1311
		break;

1312 1313 1314
	case 109:
		ret += tcrypt_test("vmac(aes)");
		break;
1315

1316 1317 1318
	case 110:
		ret += tcrypt_test("hmac(crc32)");
		break;
1319

1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
	case 111:
		ret += tcrypt_test("hmac(sha3-224)");
		break;

	case 112:
		ret += tcrypt_test("hmac(sha3-256)");
		break;

	case 113:
		ret += tcrypt_test("hmac(sha3-384)");
		break;

	case 114:
		ret += tcrypt_test("hmac(sha3-512)");
		break;

1336
	case 150:
1337
		ret += tcrypt_test("ansi_cprng");
1338 1339
		break;

1340 1341 1342 1343
	case 151:
		ret += tcrypt_test("rfc4106(gcm(aes))");
		break;

1344 1345 1346 1347
	case 152:
		ret += tcrypt_test("rfc4543(gcm(aes))");
		break;

1348 1349 1350 1351 1352 1353 1354 1355
	case 153:
		ret += tcrypt_test("cmac(aes)");
		break;

	case 154:
		ret += tcrypt_test("cmac(des3_ede)");
		break;

1356 1357 1358 1359
	case 155:
		ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
		break;

1360 1361 1362 1363 1364 1365 1366
	case 156:
		ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
		break;

	case 157:
		ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
		break;
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
	case 181:
		ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
		break;
	case 182:
		ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
		break;
	case 183:
		ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
		break;
	case 184:
		ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
		break;
	case 185:
		ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
		break;
	case 186:
		ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
		break;
	case 187:
		ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
		break;
	case 188:
		ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
		break;
	case 189:
		ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
		break;
	case 190:
		ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
		break;
H
Harald Welte 已提交
1397
	case 200:
1398
		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1399
				speed_template_16_24_32);
1400
		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1401
				speed_template_16_24_32);
1402
		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1403
				speed_template_16_24_32);
1404
		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1405
				speed_template_16_24_32);
R
Rik Snel 已提交
1406
		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1407
				speed_template_32_40_48);
R
Rik Snel 已提交
1408
		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1409
				speed_template_32_40_48);
1410
		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1411
				speed_template_32_64);
1412
		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1413
				speed_template_32_64);
1414 1415 1416 1417
		test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
				speed_template_16_24_32);
		test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
				speed_template_16_24_32);
1418 1419 1420 1421
		test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
				speed_template_16_24_32);
		test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
				speed_template_16_24_32);
H
Harald Welte 已提交
1422 1423 1424
		break;

	case 201:
1425
		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1426
				des3_speed_template, DES3_SPEED_VECTORS,
1427
				speed_template_24);
1428
		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1429
				des3_speed_template, DES3_SPEED_VECTORS,
1430
				speed_template_24);
1431
		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1432
				des3_speed_template, DES3_SPEED_VECTORS,
1433
				speed_template_24);
1434
		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1435
				des3_speed_template, DES3_SPEED_VECTORS,
1436
				speed_template_24);
1437 1438 1439 1440 1441 1442
		test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
				des3_speed_template, DES3_SPEED_VECTORS,
				speed_template_24);
		test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
				des3_speed_template, DES3_SPEED_VECTORS,
				speed_template_24);
H
Harald Welte 已提交
1443 1444 1445
		break;

	case 202:
1446
		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1447
				speed_template_16_24_32);
1448
		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1449
				speed_template_16_24_32);
1450
		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1451
				speed_template_16_24_32);
1452
		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1453
				speed_template_16_24_32);
1454 1455 1456 1457
		test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
				speed_template_16_24_32);
		test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
				speed_template_16_24_32);
1458 1459 1460 1461
		test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
				speed_template_32_40_48);
		test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
				speed_template_32_40_48);
1462 1463 1464 1465
		test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
				speed_template_32_48_64);
		test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
				speed_template_32_48_64);
H
Harald Welte 已提交
1466 1467 1468
		break;

	case 203:
1469
		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1470
				  speed_template_8_32);
1471
		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1472
				  speed_template_8_32);
1473
		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1474
				  speed_template_8_32);
1475
		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1476
				  speed_template_8_32);
1477 1478 1479 1480
		test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
				  speed_template_8_32);
		test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
				  speed_template_8_32);
H
Harald Welte 已提交
1481 1482 1483
		break;

	case 204:
1484
		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1485
				  speed_template_8);
1486
		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1487
				  speed_template_8);
1488
		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1489
				  speed_template_8);
1490
		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1491
				  speed_template_8);
H
Harald Welte 已提交
1492 1493
		break;

1494 1495
	case 205:
		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1496
				speed_template_16_24_32);
1497
		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1498
				speed_template_16_24_32);
1499
		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1500
				speed_template_16_24_32);
1501
		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1502
				speed_template_16_24_32);
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
		test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
				speed_template_16_24_32);
		test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
				speed_template_16_24_32);
		test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
				speed_template_32_40_48);
		test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
				speed_template_32_40_48);
		test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
				speed_template_32_48_64);
		test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
				speed_template_32_48_64);
1515 1516
		break;

1517 1518
	case 206:
		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1519
				  speed_template_16_32);
1520 1521
		break;

1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
	case 207:
		test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
				  speed_template_16_32);
1535 1536 1537 1538
		test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
				  speed_template_32_48);
		test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
				  speed_template_32_48);
1539 1540 1541 1542
		test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
				  speed_template_32_64);
		test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
				  speed_template_32_64);
1543 1544
		break;

1545 1546 1547 1548 1549
	case 208:
		test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
				  speed_template_8);
		break;

1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
	case 209:
		test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
				  speed_template_8_16);
		test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
				  speed_template_8_16);
		test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
				  speed_template_8_16);
		test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
				  speed_template_8_16);
		test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
				  speed_template_8_16);
		test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
				  speed_template_8_16);
		break;

1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
	case 210:
		test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
				  speed_template_16_32);
		test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
				  speed_template_32_48);
		test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
				  speed_template_32_48);
		test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
				  speed_template_32_64);
		test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
				  speed_template_32_64);
		break;

1588 1589
	case 211:
		test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1590
				NULL, 0, 16, 16, aead_speed_template_20);
1591
		test_aead_speed("gcm(aes)", ENCRYPT, sec,
1592
				NULL, 0, 16, 8, speed_template_16_24_32);
1593 1594
		break;

1595 1596
	case 212:
		test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
1597
				NULL, 0, 16, 16, aead_speed_template_19);
1598 1599
		break;

1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610
	case 213:
		test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
				NULL, 0, 16, 8, aead_speed_template_36);
		break;

	case 214:
		test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
				  speed_template_32);
		break;


1611
	case 300:
1612 1613 1614 1615 1616
		if (alg) {
			test_hash_speed(alg, sec, generic_hash_speed_template);
			break;
		}

1617 1618 1619
		/* fall through */

	case 301:
1620
		test_hash_speed("md4", sec, generic_hash_speed_template);
1621 1622 1623
		if (mode > 300 && mode < 400) break;

	case 302:
1624
		test_hash_speed("md5", sec, generic_hash_speed_template);
1625 1626 1627
		if (mode > 300 && mode < 400) break;

	case 303:
1628
		test_hash_speed("sha1", sec, generic_hash_speed_template);
1629 1630 1631
		if (mode > 300 && mode < 400) break;

	case 304:
1632
		test_hash_speed("sha256", sec, generic_hash_speed_template);
1633 1634 1635
		if (mode > 300 && mode < 400) break;

	case 305:
1636
		test_hash_speed("sha384", sec, generic_hash_speed_template);
1637 1638 1639
		if (mode > 300 && mode < 400) break;

	case 306:
1640
		test_hash_speed("sha512", sec, generic_hash_speed_template);
1641 1642 1643
		if (mode > 300 && mode < 400) break;

	case 307:
1644
		test_hash_speed("wp256", sec, generic_hash_speed_template);
1645 1646 1647
		if (mode > 300 && mode < 400) break;

	case 308:
1648
		test_hash_speed("wp384", sec, generic_hash_speed_template);
1649 1650 1651
		if (mode > 300 && mode < 400) break;

	case 309:
1652
		test_hash_speed("wp512", sec, generic_hash_speed_template);
1653 1654 1655
		if (mode > 300 && mode < 400) break;

	case 310:
1656
		test_hash_speed("tgr128", sec, generic_hash_speed_template);
1657 1658 1659
		if (mode > 300 && mode < 400) break;

	case 311:
1660
		test_hash_speed("tgr160", sec, generic_hash_speed_template);
1661 1662 1663
		if (mode > 300 && mode < 400) break;

	case 312:
1664
		test_hash_speed("tgr192", sec, generic_hash_speed_template);
1665 1666
		if (mode > 300 && mode < 400) break;

1667 1668 1669 1670
	case 313:
		test_hash_speed("sha224", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1671 1672 1673 1674 1675 1676 1677 1678
	case 314:
		test_hash_speed("rmd128", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

	case 315:
		test_hash_speed("rmd160", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1679 1680 1681 1682 1683 1684 1685 1686
	case 316:
		test_hash_speed("rmd256", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

	case 317:
		test_hash_speed("rmd320", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1687 1688 1689 1690
	case 318:
		test_hash_speed("ghash-generic", sec, hash_speed_template_16);
		if (mode > 300 && mode < 400) break;

1691 1692 1693 1694
	case 319:
		test_hash_speed("crc32c", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1695 1696 1697 1698
	case 320:
		test_hash_speed("crct10dif", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1699 1700 1701 1702
	case 321:
		test_hash_speed("poly1305", sec, poly1305_speed_template);
		if (mode > 300 && mode < 400) break;

1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
	case 322:
		test_hash_speed("sha3-224", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

	case 323:
		test_hash_speed("sha3-256", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

	case 324:
		test_hash_speed("sha3-384", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

	case 325:
		test_hash_speed("sha3-512", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1719 1720 1721 1722
	case 326:
		test_hash_speed("sm3", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1723 1724 1725
	case 399:
		break;

1726
	case 400:
1727 1728 1729 1730 1731
		if (alg) {
			test_ahash_speed(alg, sec, generic_hash_speed_template);
			break;
		}

1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
		/* fall through */

	case 401:
		test_ahash_speed("md4", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 402:
		test_ahash_speed("md5", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 403:
		test_ahash_speed("sha1", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 404:
		test_ahash_speed("sha256", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 405:
		test_ahash_speed("sha384", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 406:
		test_ahash_speed("sha512", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 407:
		test_ahash_speed("wp256", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 408:
		test_ahash_speed("wp384", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 409:
		test_ahash_speed("wp512", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 410:
		test_ahash_speed("tgr128", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 411:
		test_ahash_speed("tgr160", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 412:
		test_ahash_speed("tgr192", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 413:
		test_ahash_speed("sha224", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 414:
		test_ahash_speed("rmd128", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 415:
		test_ahash_speed("rmd160", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 416:
		test_ahash_speed("rmd256", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 417:
		test_ahash_speed("rmd320", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818
	case 418:
		test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 419:
		test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 420:
		test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;


	case 421:
		test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

1819 1820 1821 1822 1823 1824 1825
	case 422:
		test_mb_ahash_speed("sha1", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

	case 423:
		test_mb_ahash_speed("sha256", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;
1826

1827 1828 1829 1830
	case 424:
		test_mb_ahash_speed("sha512", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

1831 1832 1833 1834
	case 425:
		test_mb_ahash_speed("sm3", sec, generic_hash_speed_template);
		if (mode > 400 && mode < 500) break;

1835 1836 1837
	case 499:
		break;

1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
	case 500:
		test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_40_48);
		test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_32_40_48);
		test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1852
				   speed_template_32_64);
1853
		test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1854
				   speed_template_32_64);
1855 1856 1857 1858
		test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
1859 1860 1861 1862
		test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
1863 1864 1865 1866 1867 1868 1869 1870
		test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
1871 1872 1873 1874
		test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
				   speed_template_20_28_36);
		test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
				   speed_template_20_28_36);
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
		break;

	case 501:
		test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
		test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
		test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
		test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901
		test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
		test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
		test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
		test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
				   des3_speed_template, DES3_SPEED_VECTORS,
				   speed_template_24);
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912
		break;

	case 502:
		test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
				   speed_template_8);
		test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
				   speed_template_8);
1913 1914 1915 1916 1917 1918 1919 1920
		test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
				   speed_template_8);
		test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
				   speed_template_8);
1921 1922
		break;

1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935
	case 503:
		test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
1936 1937 1938 1939
		test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_48);
		test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
				   speed_template_32_48);
1940 1941 1942 1943
		test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_64);
		test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
				   speed_template_32_64);
1944 1945
		break;

1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968
	case 504:
		test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
				   speed_template_16_24_32);
		test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_40_48);
		test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
				   speed_template_32_40_48);
		test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_48_64);
		test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
				   speed_template_32_48_64);
		break;

1969 1970 1971 1972 1973
	case 505:
		test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		break;

1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988
	case 506:
		test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
				   speed_template_8_16);
		test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
				   speed_template_8_16);
		test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
				   speed_template_8_16);
		test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
				   speed_template_8_16);
		test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
				   speed_template_8_16);
		test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
				   speed_template_8_16);
		break;

1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
	case 507:
		test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_48);
		test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
				   speed_template_32_48);
		test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_64);
		test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
				   speed_template_32_64);
		break;

2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
	case 508:
		test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
				   speed_template_16_32);
		test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_48);
		test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
				   speed_template_32_48);
		test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
				   speed_template_32_64);
		test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
				   speed_template_32_64);
		break;

2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049
	case 509:
		test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
				   speed_template_8_32);
		test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
				   speed_template_8_32);
		test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
				   speed_template_8_32);
		test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
				   speed_template_8_32);
		test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
				   speed_template_8_32);
		test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
				   speed_template_8_32);
		break;

L
Linus Torvalds 已提交
2050 2051 2052 2053
	case 1000:
		test_available();
		break;
	}
2054 2055

	return ret;
L
Linus Torvalds 已提交
2056 2057
}

2058
static int __init tcrypt_mod_init(void)
L
Linus Torvalds 已提交
2059
{
2060
	int err = -ENOMEM;
2061
	int i;
2062

2063 2064 2065 2066 2067
	for (i = 0; i < TVMEMSIZE; i++) {
		tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
		if (!tvmem[i])
			goto err_free_tv;
	}
L
Linus Torvalds 已提交
2068

2069
	err = do_test(alg, type, mask, mode);
2070

2071 2072 2073
	if (err) {
		printk(KERN_ERR "tcrypt: one or more tests failed!\n");
		goto err_free_tv;
2074 2075
	} else {
		pr_debug("all tests passed\n");
2076
	}
2077

2078 2079 2080 2081
	/* We intentionaly return -EAGAIN to prevent keeping the module,
	 * unless we're running in fips mode. It does all its work from
	 * init() and doesn't offer any runtime functionality, but in
	 * the fips case, checking for a successful load is helpful.
2082 2083 2084
	 * => we don't need it in the memory, do we?
	 *                                        -- mludvig
	 */
2085 2086
	if (!fips_enabled)
		err = -EAGAIN;
2087

2088 2089 2090
err_free_tv:
	for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
		free_page((unsigned long)tvmem[i]);
2091 2092

	return err;
L
Linus Torvalds 已提交
2093 2094 2095 2096 2097 2098
}

/*
 * If an init function is provided, an exit function must also be provided
 * to allow module unload.
 */
2099
static void __exit tcrypt_mod_fini(void) { }
L
Linus Torvalds 已提交
2100

2101 2102
module_init(tcrypt_mod_init);
module_exit(tcrypt_mod_fini);
L
Linus Torvalds 已提交
2103

2104 2105
module_param(alg, charp, 0);
module_param(type, uint, 0);
H
Herbert Xu 已提交
2106
module_param(mask, uint, 0);
L
Linus Torvalds 已提交
2107
module_param(mode, int, 0);
H
Harald Welte 已提交
2108
module_param(sec, uint, 0);
2109 2110
MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
		      "(defaults to zero which uses CPU cycles instead)");
L
Linus Torvalds 已提交
2111 2112 2113 2114

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Quick & dirty crypto testing module");
MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");