tcrypt.c 50.3 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
#include <crypto/hash.h>
26
#include <linux/err.h>
L
Linus Torvalds 已提交
27
#include <linux/init.h>
28
#include <linux/gfp.h>
L
Linus Torvalds 已提交
29
#include <linux/module.h>
30
#include <linux/scatterlist.h>
L
Linus Torvalds 已提交
31 32
#include <linux/string.h>
#include <linux/moduleparam.h>
H
Harald Welte 已提交
33
#include <linux/jiffies.h>
34 35
#include <linux/timex.h>
#include <linux/interrupt.h>
L
Linus Torvalds 已提交
36
#include "tcrypt.h"
37
#include "internal.h"
L
Linus Torvalds 已提交
38 39

/*
40
 * Need slab memory for testing (size in number of pages).
L
Linus Torvalds 已提交
41
 */
42
#define TVMEMSIZE	4
L
Linus Torvalds 已提交
43 44

/*
45
* Used by test_cipher_speed()
L
Linus Torvalds 已提交
46 47 48 49
*/
#define ENCRYPT 1
#define DECRYPT 0

H
Harald Welte 已提交
50 51 52
/*
 * Used by test_cipher_speed()
 */
53
static unsigned int sec;
H
Harald Welte 已提交
54

55 56
static char *alg = NULL;
static u32 type;
H
Herbert Xu 已提交
57
static u32 mask;
L
Linus Torvalds 已提交
58
static int mode;
59
static char *tvmem[TVMEMSIZE];
L
Linus Torvalds 已提交
60 61

static char *check[] = {
62 63 64
	"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
	"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
	"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
65
	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
66
	"camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
67
	"lzo", "cts", "zlib", NULL
L
Linus Torvalds 已提交
68 69
};

70 71
static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
			       struct scatterlist *sg, int blen, int sec)
72 73 74 75 76 77 78 79
{
	unsigned long start, end;
	int bcount;
	int ret;

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		if (enc)
80
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
81
		else
82
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
83 84 85 86 87 88 89 90 91 92

		if (ret)
			return ret;
	}

	printk("%d operations in %d seconds (%ld bytes)\n",
	       bcount, sec, (long)bcount * blen);
	return 0;
}

93 94
static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
			      struct scatterlist *sg, int blen)
95 96 97 98 99 100 101 102 103 104
{
	unsigned long cycles = 0;
	int ret = 0;
	int i;

	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
105
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
106
		else
107
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
108 109 110 111 112 113 114 115 116 117 118

		if (ret)
			goto out;
	}

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

		start = get_cycles();
		if (enc)
119
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
120
		else
121
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
		end = get_cycles();

		if (ret)
			goto out;

		cycles += end - start;
	}

out:
	local_irq_enable();

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

	return ret;
}

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 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
static int test_aead_jiffies(struct aead_request *req, int enc,
				int blen, int sec)
{
	unsigned long start, end;
	int bcount;
	int ret;

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		if (enc)
			ret = crypto_aead_encrypt(req);
		else
			ret = crypto_aead_decrypt(req);

		if (ret)
			return ret;
	}

	printk("%d operations in %d seconds (%ld bytes)\n",
	       bcount, sec, (long)bcount * blen);
	return 0;
}

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

	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
			ret = crypto_aead_encrypt(req);
		else
			ret = crypto_aead_decrypt(req);

		if (ret)
			goto out;
	}

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

		start = get_cycles();
		if (enc)
			ret = crypto_aead_encrypt(req);
		else
			ret = crypto_aead_decrypt(req);
		end = get_cycles();

		if (ret)
			goto out;

		cycles += end - start;
	}

out:
	local_irq_enable();

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

	return ret;
}

209
static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
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;

	np = (np > XBUFSIZE) ? XBUFSIZE : np;
	rem = buflen % PAGE_SIZE;
	if (np > XBUFSIZE) {
		rem = PAGE_SIZE;
		np = XBUFSIZE;
	}
	sg_init_table(sg, np);
	for (k = 0; k < np; ++k) {
		if (k == (np-1))
			sg_set_buf(&sg[k], xbuf[k], rem);
		else
			sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE);
	}
}

static void test_aead_speed(const char *algo, int enc, unsigned int sec,
			    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 *asg;
	struct scatterlist *sgout;
	const char *e;
	void *assoc;
	char iv[MAX_IVLEN];
	char *xbuf[XBUFSIZE];
	char *xoutbuf[XBUFSIZE];
	char *axbuf[XBUFSIZE];
	unsigned int *b_size;
	unsigned int iv_len;

285 286 287 288 289
	if (aad_size >= PAGE_SIZE) {
		pr_err("associate data length (%u) too big\n", aad_size);
		return;
	}

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
	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;

	sg = kmalloc(sizeof(*sg) * 8 * 3, GFP_KERNEL);
	if (!sg)
		goto out_nosg;
	asg = &sg[8];
	sgout = &asg[8];


	printk(KERN_INFO "\ntesting speed of %s %s\n", algo, e);

	tfm = crypto_alloc_aead(algo, 0, 0);

	if (IS_ERR(tfm)) {
		pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
316
		goto out_notfm;
317 318 319 320 321 322 323 324 325 326 327 328 329 330
	}

	req = aead_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		pr_err("alg: aead: Failed to allocate request for %s\n",
		       algo);
		goto out;
	}

	i = 0;
	do {
		b_size = aead_sizes;
		do {
			assoc = axbuf[0];
331
			memset(assoc, 0xff, aad_size);
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
			sg_init_one(&asg[0], assoc, aad_size);

			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)
				memset(&iv, 0xff, iv_len);

			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;
			}

			sg_init_aead(&sg[0], xbuf,
				    *b_size + (enc ? authsize : 0));

			sg_init_aead(&sgout[0], xoutbuf,
				    *b_size + (enc ? authsize : 0));

			aead_request_set_crypt(req, sg, sgout, *b_size, iv);
			aead_request_set_assoc(req, asg, aad_size);

			if (sec)
				ret = test_aead_jiffies(req, enc, *b_size, sec);
			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:
	crypto_free_aead(tfm);
394
out_notfm:
395 396 397 398 399 400 401 402 403 404
	kfree(sg);
out_nosg:
	testmgr_free_buf(xoutbuf);
out_nooutbuf:
	testmgr_free_buf(axbuf);
out_noaxbuf:
	testmgr_free_buf(xbuf);
out_noxbuf:
	return;
}
405

406
static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
407
			      struct cipher_speed_template *template,
408
			      unsigned int tcount, u8 *keysize)
H
Harald Welte 已提交
409
{
410
	unsigned int ret, i, j, iv_len;
411 412
	const char *key;
	char iv[128];
413 414 415
	struct crypto_blkcipher *tfm;
	struct blkcipher_desc desc;
	const char *e;
416
	u32 *b_size;
H
Harald Welte 已提交
417 418 419 420 421 422

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

423
	printk("\ntesting speed of %s %s\n", algo, e);
H
Harald Welte 已提交
424

425
	tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
H
Harald Welte 已提交
426

427 428 429
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
H
Harald Welte 已提交
430 431
		return;
	}
432 433
	desc.tfm = tfm;
	desc.flags = 0;
H
Harald Welte 已提交
434

435 436
	i = 0;
	do {
H
Harald Welte 已提交
437

438 439
		b_size = block_sizes;
		do {
440
			struct scatterlist sg[TVMEMSIZE];
H
Harald Welte 已提交
441

442 443 444 445
			if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
				printk("template (%u) too big for "
				       "tvmem (%lu)\n", *keysize + *b_size,
				       TVMEMSIZE * PAGE_SIZE);
446 447
				goto out;
			}
H
Harald Welte 已提交
448

449 450 451
			printk("test %u (%d bit key, %d byte blocks): ", i,
					*keysize * 8, *b_size);

452
			memset(tvmem[0], 0xff, PAGE_SIZE);
453 454

			/* set key, plain text and IV */
455
			key = tvmem[0];
456 457 458 459 460
			for (j = 0; j < tcount; j++) {
				if (template[j].klen == *keysize) {
					key = template[j].key;
					break;
				}
461
			}
H
Harald Welte 已提交
462

463 464 465 466 467 468
			ret = crypto_blkcipher_setkey(tfm, key, *keysize);
			if (ret) {
				printk("setkey() failed flags=%x\n",
						crypto_blkcipher_get_flags(tfm));
				goto out;
			}
H
Harald Welte 已提交
469

470 471 472 473 474 475 476 477
			sg_init_table(sg, TVMEMSIZE);
			sg_set_buf(sg, tvmem[0] + *keysize,
				   PAGE_SIZE - *keysize);
			for (j = 1; j < TVMEMSIZE; j++) {
				sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
				memset (tvmem[j], 0xff, PAGE_SIZE);
			}

478 479 480 481 482
			iv_len = crypto_blkcipher_ivsize(tfm);
			if (iv_len) {
				memset(&iv, 0xff, iv_len);
				crypto_blkcipher_set_iv(tfm, iv, iv_len);
			}
H
Harald Welte 已提交
483

484
			if (sec)
485 486
				ret = test_cipher_jiffies(&desc, enc, sg,
							  *b_size, sec);
487
			else
488 489
				ret = test_cipher_cycles(&desc, enc, sg,
							 *b_size);
H
Harald Welte 已提交
490

491 492 493 494 495 496 497 498 499
			if (ret) {
				printk("%s() failed flags=%x\n", e, desc.flags);
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);
H
Harald Welte 已提交
500 501

out:
502
	crypto_free_blkcipher(tfm);
H
Harald Welte 已提交
503 504
}

505 506
static int test_hash_jiffies_digest(struct hash_desc *desc,
				    struct scatterlist *sg, int blen,
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
				    char *out, int sec)
{
	unsigned long start, end;
	int bcount;
	int ret;

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		ret = crypto_hash_digest(desc, sg, blen, out);
		if (ret)
			return ret;
	}

	printk("%6u opers/sec, %9lu bytes/sec\n",
	       bcount / sec, ((long)bcount * blen) / sec);

	return 0;
}

526 527
static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
			     int blen, int plen, char *out, int sec)
528 529 530
{
	unsigned long start, end;
	int bcount, pcount;
531 532 533
	int ret;

	if (plen == blen)
534
		return test_hash_jiffies_digest(desc, sg, blen, out, sec);
535

536 537
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
538 539 540
		ret = crypto_hash_init(desc);
		if (ret)
			return ret;
541
		for (pcount = 0; pcount < blen; pcount += plen) {
542 543 544
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				return ret;
545 546
		}
		/* we assume there is enough space in 'out' for the result */
547 548 549
		ret = crypto_hash_final(desc, out);
		if (ret)
			return ret;
550 551 552 553 554
	}

	printk("%6u opers/sec, %9lu bytes/sec\n",
	       bcount / sec, ((long)bcount * blen) / sec);

555 556 557
	return 0;
}

558 559
static int test_hash_cycles_digest(struct hash_desc *desc,
				   struct scatterlist *sg, int blen, char *out)
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
{
	unsigned long cycles = 0;
	int i;
	int ret;

	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		ret = crypto_hash_digest(desc, sg, blen, out);
		if (ret)
			goto out;
	}

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

		start = get_cycles();

		ret = crypto_hash_digest(desc, sg, blen, out);
		if (ret)
			goto out;

		end = get_cycles();

		cycles += end - start;
	}

out:
	local_irq_enable();

	if (ret)
		return ret;

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

	return 0;
599 600
}

601 602
static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
			    int blen, int plen, char *out)
603 604 605
{
	unsigned long cycles = 0;
	int i, pcount;
606 607 608
	int ret;

	if (plen == blen)
609
		return test_hash_cycles_digest(desc, sg, blen, out);
610

611 612 613 614
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
615 616 617
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
618
		for (pcount = 0; pcount < blen; pcount += plen) {
619 620 621
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
622
		}
623
		ret = crypto_hash_final(desc, out);
624 625
		if (ret)
			goto out;
626 627 628 629 630 631 632 633
	}

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

		start = get_cycles();

634 635 636
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
637
		for (pcount = 0; pcount < blen; pcount += plen) {
638 639 640
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
641
		}
642 643 644
		ret = crypto_hash_final(desc, out);
		if (ret)
			goto out;
645 646 647 648 649 650

		end = get_cycles();

		cycles += end - start;
	}

651
out:
652 653
	local_irq_enable();

654 655 656
	if (ret)
		return ret;

657 658 659
	printk("%6lu cycles/operation, %4lu cycles/byte\n",
	       cycles / 8, cycles / (8 * blen));

660
	return 0;
661 662
}

663 664 665 666 667 668 669 670 671 672 673
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);
	}
}

674 675
static void test_hash_speed(const char *algo, unsigned int sec,
			    struct hash_speed *speed)
676
{
677
	struct scatterlist sg[TVMEMSIZE];
678 679
	struct crypto_hash *tfm;
	struct hash_desc desc;
680
	static char output[1024];
681
	int i;
682
	int ret;
683

684
	printk(KERN_INFO "\ntesting speed of %s\n", algo);
685

686
	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
687

688
	if (IS_ERR(tfm)) {
689
		printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
690
		       PTR_ERR(tfm));
691 692 693
		return;
	}

694 695 696 697
	desc.tfm = tfm;
	desc.flags = 0;

	if (crypto_hash_digestsize(tfm) > sizeof(output)) {
698
		printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
699
		       crypto_hash_digestsize(tfm), sizeof(output));
700 701 702
		goto out;
	}

703
	test_hash_sg_init(sg);
704
	for (i = 0; speed[i].blen != 0; i++) {
705
		if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
706 707
			printk(KERN_ERR
			       "template (%u) too big for tvmem (%lu)\n",
708
			       speed[i].blen, TVMEMSIZE * PAGE_SIZE);
709 710 711
			goto out;
		}

712 713 714
		if (speed[i].klen)
			crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);

715 716
		printk(KERN_INFO "test%3u "
		       "(%5u byte blocks,%5u bytes per update,%4u updates): ",
717 718 719
		       i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);

		if (sec)
720
			ret = test_hash_jiffies(&desc, sg, speed[i].blen,
721
						speed[i].plen, output, sec);
722
		else
723
			ret = test_hash_cycles(&desc, sg, speed[i].blen,
724 725 726
					       speed[i].plen, output);

		if (ret) {
727
			printk(KERN_ERR "hashing failed ret=%d\n", ret);
728 729
			break;
		}
730 731 732
	}

out:
733
	crypto_free_hash(tfm);
734 735
}

736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
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_ahash_op(struct ahash_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;
760
		reinit_completion(&tr->completion);
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 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 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
	}
	return ret;
}

static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
				     char *out, int sec)
{
	unsigned long start, end;
	int bcount;
	int ret;

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     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",
	       bcount / sec, ((long)bcount * blen) / sec);

	return 0;
}

static int test_ahash_jiffies(struct ahash_request *req, int blen,
			      int plen, char *out, int sec)
{
	unsigned long start, end;
	int bcount, pcount;
	int ret;

	if (plen == blen)
		return test_ahash_jiffies_digest(req, blen, out, sec);

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		ret = crypto_ahash_init(req);
		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",
		bcount / sec, ((long)bcount * blen) / sec);

	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++) {
		ret = crypto_ahash_init(req);
		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();

		ret = crypto_ahash_init(req);
		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;
}

static void test_ahash_speed(const char *algo, unsigned int sec,
			     struct hash_speed *speed)
{
	struct scatterlist sg[TVMEMSIZE];
	struct tcrypt_result tresult;
	struct ahash_request *req;
	struct crypto_ahash *tfm;
	static char output[1024];
	int i, ret;

	printk(KERN_INFO "\ntesting speed of async %s\n", algo);

	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));
		return;
	}

	if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
		pr_err("digestsize(%u) > outputbuffer(%zu)\n",
		       crypto_ahash_digestsize(tfm), sizeof(output));
		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);

	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);

		if (sec)
			ret = test_ahash_jiffies(req, speed[i].blen,
						 speed[i].plen, output, sec);
		else
			ret = test_ahash_cycles(req, speed[i].blen,
						speed[i].plen, output);

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

	ahash_request_free(req);

out:
	crypto_free_ahash(tfm);
}

980 981 982 983 984 985 986 987
static inline int do_one_acipher_op(struct ablkcipher_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;
988
		reinit_completion(&tr->completion);
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
	}

	return ret;
}

static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
				int blen, int sec)
{
	unsigned long start, end;
	int bcount;
	int ret;

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		if (enc)
			ret = do_one_acipher_op(req,
						crypto_ablkcipher_encrypt(req));
		else
			ret = do_one_acipher_op(req,
						crypto_ablkcipher_decrypt(req));

		if (ret)
			return ret;
	}

	pr_cont("%d operations in %d seconds (%ld bytes)\n",
		bcount, sec, (long)bcount * blen);
	return 0;
}

static int test_acipher_cycles(struct ablkcipher_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)
			ret = do_one_acipher_op(req,
						crypto_ablkcipher_encrypt(req));
		else
			ret = do_one_acipher_op(req,
						crypto_ablkcipher_decrypt(req));

		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,
						crypto_ablkcipher_encrypt(req));
		else
			ret = do_one_acipher_op(req,
						crypto_ablkcipher_decrypt(req));
		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;
}

static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
			       struct cipher_speed_template *template,
			       unsigned int tcount, u8 *keysize)
{
1070
	unsigned int ret, i, j, k, iv_len;
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
	struct tcrypt_result tresult;
	const char *key;
	char iv[128];
	struct ablkcipher_request *req;
	struct crypto_ablkcipher *tfm;
	const char *e;
	u32 *b_size;

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

	pr_info("\ntesting speed of async %s %s\n", algo, e);

	init_completion(&tresult.completion);

	tfm = crypto_alloc_ablkcipher(algo, 0, 0);

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

	req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
		       algo);
		goto out;
	}

	ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
					tcrypt_complete, &tresult);

	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;
				}
			}

			crypto_ablkcipher_clear_flags(tfm, ~0);

			ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
			if (ret) {
				pr_err("setkey() failed flags=%x\n",
					crypto_ablkcipher_get_flags(tfm));
				goto out_free_req;
			}

			sg_init_table(sg, TVMEMSIZE);
1144 1145 1146 1147

			k = *keysize + *b_size;
			if (k > PAGE_SIZE) {
				sg_set_buf(sg, tvmem[0] + *keysize,
1148
				   PAGE_SIZE - *keysize);
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
				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);
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
			}

			iv_len = crypto_ablkcipher_ivsize(tfm);
			if (iv_len)
				memset(&iv, 0xff, iv_len);

			ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);

			if (sec)
				ret = test_acipher_jiffies(req, enc,
							   *b_size, sec);
			else
				ret = test_acipher_cycles(req, enc,
							  *b_size);

			if (ret) {
				pr_err("%s() failed flags=%x\n", e,
					crypto_ablkcipher_get_flags(tfm));
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);

out_free_req:
	ablkcipher_request_free(req);
out:
	crypto_free_ablkcipher(tfm);
}

1193
static void test_available(void)
L
Linus Torvalds 已提交
1194 1195
{
	char **name = check;
1196

L
Linus Torvalds 已提交
1197 1198
	while (*name) {
		printk("alg %s ", *name);
1199
		printk(crypto_has_alg(*name, 0, 0) ?
1200
		       "found\n" : "not found\n");
L
Linus Torvalds 已提交
1201
		name++;
1202
	}
L
Linus Torvalds 已提交
1203 1204
}

1205 1206
static inline int tcrypt_test(const char *alg)
{
1207 1208 1209 1210 1211 1212 1213
	int ret;

	ret = alg_test(alg, alg, 0, 0);
	/* non-fips algs return -EINVAL in fips mode */
	if (fips_enabled && ret == -EINVAL)
		ret = 0;
	return ret;
1214 1215
}

1216
static int do_test(int m)
1217 1218
{
	int i;
1219
	int ret = 0;
1220 1221

	switch (m) {
L
Linus Torvalds 已提交
1222
	case 0:
1223
		for (i = 1; i < 200; i++)
1224
			ret += do_test(i);
L
Linus Torvalds 已提交
1225 1226 1227
		break;

	case 1:
1228
		ret += tcrypt_test("md5");
L
Linus Torvalds 已提交
1229 1230 1231
		break;

	case 2:
1232
		ret += tcrypt_test("sha1");
L
Linus Torvalds 已提交
1233 1234 1235
		break;

	case 3:
1236 1237
		ret += tcrypt_test("ecb(des)");
		ret += tcrypt_test("cbc(des)");
1238
		ret += tcrypt_test("ctr(des)");
L
Linus Torvalds 已提交
1239 1240 1241
		break;

	case 4:
1242 1243
		ret += tcrypt_test("ecb(des3_ede)");
		ret += tcrypt_test("cbc(des3_ede)");
1244
		ret += tcrypt_test("ctr(des3_ede)");
L
Linus Torvalds 已提交
1245 1246 1247
		break;

	case 5:
1248
		ret += tcrypt_test("md4");
L
Linus Torvalds 已提交
1249
		break;
1250

L
Linus Torvalds 已提交
1251
	case 6:
1252
		ret += tcrypt_test("sha256");
L
Linus Torvalds 已提交
1253
		break;
1254

L
Linus Torvalds 已提交
1255
	case 7:
1256 1257
		ret += tcrypt_test("ecb(blowfish)");
		ret += tcrypt_test("cbc(blowfish)");
1258
		ret += tcrypt_test("ctr(blowfish)");
L
Linus Torvalds 已提交
1259 1260 1261
		break;

	case 8:
1262 1263
		ret += tcrypt_test("ecb(twofish)");
		ret += tcrypt_test("cbc(twofish)");
1264
		ret += tcrypt_test("ctr(twofish)");
1265
		ret += tcrypt_test("lrw(twofish)");
1266
		ret += tcrypt_test("xts(twofish)");
L
Linus Torvalds 已提交
1267
		break;
1268

L
Linus Torvalds 已提交
1269
	case 9:
1270
		ret += tcrypt_test("ecb(serpent)");
1271 1272
		ret += tcrypt_test("cbc(serpent)");
		ret += tcrypt_test("ctr(serpent)");
1273
		ret += tcrypt_test("lrw(serpent)");
1274
		ret += tcrypt_test("xts(serpent)");
L
Linus Torvalds 已提交
1275 1276 1277
		break;

	case 10:
1278 1279 1280 1281 1282 1283
		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 已提交
1284 1285 1286
		break;

	case 11:
1287
		ret += tcrypt_test("sha384");
L
Linus Torvalds 已提交
1288
		break;
1289

L
Linus Torvalds 已提交
1290
	case 12:
1291
		ret += tcrypt_test("sha512");
L
Linus Torvalds 已提交
1292 1293 1294
		break;

	case 13:
1295
		ret += tcrypt_test("deflate");
L
Linus Torvalds 已提交
1296 1297 1298
		break;

	case 14:
1299
		ret += tcrypt_test("ecb(cast5)");
1300 1301
		ret += tcrypt_test("cbc(cast5)");
		ret += tcrypt_test("ctr(cast5)");
L
Linus Torvalds 已提交
1302 1303 1304
		break;

	case 15:
1305
		ret += tcrypt_test("ecb(cast6)");
1306 1307 1308 1309
		ret += tcrypt_test("cbc(cast6)");
		ret += tcrypt_test("ctr(cast6)");
		ret += tcrypt_test("lrw(cast6)");
		ret += tcrypt_test("xts(cast6)");
L
Linus Torvalds 已提交
1310 1311 1312
		break;

	case 16:
1313
		ret += tcrypt_test("ecb(arc4)");
L
Linus Torvalds 已提交
1314 1315 1316
		break;

	case 17:
1317
		ret += tcrypt_test("michael_mic");
L
Linus Torvalds 已提交
1318 1319 1320
		break;

	case 18:
1321
		ret += tcrypt_test("crc32c");
L
Linus Torvalds 已提交
1322 1323 1324
		break;

	case 19:
1325
		ret += tcrypt_test("ecb(tea)");
L
Linus Torvalds 已提交
1326 1327 1328
		break;

	case 20:
1329
		ret += tcrypt_test("ecb(xtea)");
L
Linus Torvalds 已提交
1330 1331 1332
		break;

	case 21:
1333
		ret += tcrypt_test("ecb(khazad)");
L
Linus Torvalds 已提交
1334 1335 1336
		break;

	case 22:
1337
		ret += tcrypt_test("wp512");
L
Linus Torvalds 已提交
1338 1339 1340
		break;

	case 23:
1341
		ret += tcrypt_test("wp384");
L
Linus Torvalds 已提交
1342 1343 1344
		break;

	case 24:
1345
		ret += tcrypt_test("wp256");
L
Linus Torvalds 已提交
1346 1347 1348
		break;

	case 25:
1349
		ret += tcrypt_test("ecb(tnepres)");
L
Linus Torvalds 已提交
1350 1351 1352
		break;

	case 26:
1353 1354
		ret += tcrypt_test("ecb(anubis)");
		ret += tcrypt_test("cbc(anubis)");
L
Linus Torvalds 已提交
1355 1356 1357
		break;

	case 27:
1358
		ret += tcrypt_test("tgr192");
L
Linus Torvalds 已提交
1359 1360 1361
		break;

	case 28:
1362
		ret += tcrypt_test("tgr160");
L
Linus Torvalds 已提交
1363 1364 1365
		break;

	case 29:
1366
		ret += tcrypt_test("tgr128");
L
Linus Torvalds 已提交
1367
		break;
1368

A
Aaron Grothe 已提交
1369
	case 30:
1370
		ret += tcrypt_test("ecb(xeta)");
A
Aaron Grothe 已提交
1371
		break;
L
Linus Torvalds 已提交
1372

1373
	case 31:
1374
		ret += tcrypt_test("pcbc(fcrypt)");
1375 1376
		break;

1377
	case 32:
1378 1379
		ret += tcrypt_test("ecb(camellia)");
		ret += tcrypt_test("cbc(camellia)");
1380 1381 1382
		ret += tcrypt_test("ctr(camellia)");
		ret += tcrypt_test("lrw(camellia)");
		ret += tcrypt_test("xts(camellia)");
1383
		break;
1384

1385
	case 33:
1386
		ret += tcrypt_test("sha224");
1387
		break;
1388

1389
	case 34:
1390
		ret += tcrypt_test("salsa20");
1391 1392
		break;

1393
	case 35:
1394
		ret += tcrypt_test("gcm(aes)");
1395 1396
		break;

1397
	case 36:
1398
		ret += tcrypt_test("lzo");
1399 1400
		break;

J
Joy Latten 已提交
1401
	case 37:
1402
		ret += tcrypt_test("ccm(aes)");
J
Joy Latten 已提交
1403 1404
		break;

1405
	case 38:
1406
		ret += tcrypt_test("cts(cbc(aes))");
1407 1408
		break;

1409
        case 39:
1410
		ret += tcrypt_test("rmd128");
1411 1412 1413
		break;

        case 40:
1414
		ret += tcrypt_test("rmd160");
1415 1416
		break;

1417
	case 41:
1418
		ret += tcrypt_test("rmd256");
1419 1420 1421
		break;

	case 42:
1422
		ret += tcrypt_test("rmd320");
1423 1424 1425
		break;

	case 43:
1426
		ret += tcrypt_test("ecb(seed)");
1427 1428
		break;

1429
	case 44:
1430
		ret += tcrypt_test("zlib");
1431 1432
		break;

1433
	case 45:
1434
		ret += tcrypt_test("rfc4309(ccm(aes))");
1435 1436
		break;

1437 1438 1439 1440
	case 46:
		ret += tcrypt_test("ghash");
		break;

1441 1442 1443 1444
	case 47:
		ret += tcrypt_test("crct10dif");
		break;

L
Linus Torvalds 已提交
1445
	case 100:
1446
		ret += tcrypt_test("hmac(md5)");
L
Linus Torvalds 已提交
1447
		break;
1448

L
Linus Torvalds 已提交
1449
	case 101:
1450
		ret += tcrypt_test("hmac(sha1)");
L
Linus Torvalds 已提交
1451
		break;
1452

L
Linus Torvalds 已提交
1453
	case 102:
1454
		ret += tcrypt_test("hmac(sha256)");
L
Linus Torvalds 已提交
1455 1456
		break;

1457
	case 103:
1458
		ret += tcrypt_test("hmac(sha384)");
1459 1460 1461
		break;

	case 104:
1462
		ret += tcrypt_test("hmac(sha512)");
1463
		break;
1464

1465
	case 105:
1466
		ret += tcrypt_test("hmac(sha224)");
1467
		break;
L
Linus Torvalds 已提交
1468

1469
	case 106:
1470
		ret += tcrypt_test("xcbc(aes)");
1471 1472
		break;

1473
	case 107:
1474
		ret += tcrypt_test("hmac(rmd128)");
1475 1476 1477
		break;

	case 108:
1478
		ret += tcrypt_test("hmac(rmd160)");
1479 1480
		break;

1481 1482 1483
	case 109:
		ret += tcrypt_test("vmac(aes)");
		break;
1484

1485 1486 1487
	case 110:
		ret += tcrypt_test("hmac(crc32)");
		break;
1488

1489
	case 150:
1490
		ret += tcrypt_test("ansi_cprng");
1491 1492
		break;

1493 1494 1495 1496
	case 151:
		ret += tcrypt_test("rfc4106(gcm(aes))");
		break;

1497 1498 1499 1500
	case 152:
		ret += tcrypt_test("rfc4543(gcm(aes))");
		break;

1501 1502 1503 1504 1505 1506 1507 1508
	case 153:
		ret += tcrypt_test("cmac(aes)");
		break;

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

1509 1510 1511 1512
	case 155:
		ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
		break;

1513 1514 1515 1516 1517 1518 1519 1520
	case 156:
		ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
		break;

	case 157:
		ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
		break;

H
Harald Welte 已提交
1521
	case 200:
1522
		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1523
				speed_template_16_24_32);
1524
		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1525
				speed_template_16_24_32);
1526
		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1527
				speed_template_16_24_32);
1528
		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1529
				speed_template_16_24_32);
R
Rik Snel 已提交
1530
		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1531
				speed_template_32_40_48);
R
Rik Snel 已提交
1532
		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1533
				speed_template_32_40_48);
1534
		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1535
				speed_template_32_48_64);
1536
		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1537
				speed_template_32_48_64);
1538 1539 1540 1541
		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 已提交
1542 1543 1544
		break;

	case 201:
1545
		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1546
				des3_speed_template, DES3_SPEED_VECTORS,
1547
				speed_template_24);
1548
		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1549
				des3_speed_template, DES3_SPEED_VECTORS,
1550
				speed_template_24);
1551
		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1552
				des3_speed_template, DES3_SPEED_VECTORS,
1553
				speed_template_24);
1554
		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1555
				des3_speed_template, DES3_SPEED_VECTORS,
1556
				speed_template_24);
H
Harald Welte 已提交
1557 1558 1559
		break;

	case 202:
1560
		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1561
				speed_template_16_24_32);
1562
		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1563
				speed_template_16_24_32);
1564
		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1565
				speed_template_16_24_32);
1566
		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1567
				speed_template_16_24_32);
1568 1569 1570 1571
		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);
1572 1573 1574 1575
		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);
1576 1577 1578 1579
		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 已提交
1580 1581 1582
		break;

	case 203:
1583
		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1584
				  speed_template_8_32);
1585
		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1586
				  speed_template_8_32);
1587
		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1588
				  speed_template_8_32);
1589
		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1590
				  speed_template_8_32);
1591 1592 1593 1594
		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 已提交
1595 1596 1597
		break;

	case 204:
1598
		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1599
				  speed_template_8);
1600
		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1601
				  speed_template_8);
1602
		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1603
				  speed_template_8);
1604
		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1605
				  speed_template_8);
H
Harald Welte 已提交
1606 1607
		break;

1608 1609
	case 205:
		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1610
				speed_template_16_24_32);
1611
		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1612
				speed_template_16_24_32);
1613
		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1614
				speed_template_16_24_32);
1615
		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1616
				speed_template_16_24_32);
1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628
		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);
1629 1630
		break;

1631 1632
	case 206:
		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1633
				  speed_template_16_32);
1634 1635
		break;

1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
	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);
1649 1650 1651 1652
		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);
1653 1654 1655 1656
		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);
1657 1658
		break;

1659 1660 1661 1662 1663
	case 208:
		test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
				  speed_template_8);
		break;

1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
	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;

1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
	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;

1702 1703 1704 1705 1706
	case 211:
		test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
				NULL, 0, 16, 8, aead_speed_template_20);
		break;

1707 1708 1709 1710
	case 300:
		/* fall through */

	case 301:
1711
		test_hash_speed("md4", sec, generic_hash_speed_template);
1712 1713 1714
		if (mode > 300 && mode < 400) break;

	case 302:
1715
		test_hash_speed("md5", sec, generic_hash_speed_template);
1716 1717 1718
		if (mode > 300 && mode < 400) break;

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

	case 304:
1723
		test_hash_speed("sha256", sec, generic_hash_speed_template);
1724 1725 1726
		if (mode > 300 && mode < 400) break;

	case 305:
1727
		test_hash_speed("sha384", sec, generic_hash_speed_template);
1728 1729 1730
		if (mode > 300 && mode < 400) break;

	case 306:
1731
		test_hash_speed("sha512", sec, generic_hash_speed_template);
1732 1733 1734
		if (mode > 300 && mode < 400) break;

	case 307:
1735
		test_hash_speed("wp256", sec, generic_hash_speed_template);
1736 1737 1738
		if (mode > 300 && mode < 400) break;

	case 308:
1739
		test_hash_speed("wp384", sec, generic_hash_speed_template);
1740 1741 1742
		if (mode > 300 && mode < 400) break;

	case 309:
1743
		test_hash_speed("wp512", sec, generic_hash_speed_template);
1744 1745 1746
		if (mode > 300 && mode < 400) break;

	case 310:
1747
		test_hash_speed("tgr128", sec, generic_hash_speed_template);
1748 1749 1750
		if (mode > 300 && mode < 400) break;

	case 311:
1751
		test_hash_speed("tgr160", sec, generic_hash_speed_template);
1752 1753 1754
		if (mode > 300 && mode < 400) break;

	case 312:
1755
		test_hash_speed("tgr192", sec, generic_hash_speed_template);
1756 1757
		if (mode > 300 && mode < 400) break;

1758 1759 1760 1761
	case 313:
		test_hash_speed("sha224", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1762 1763 1764 1765 1766 1767 1768 1769
	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;

1770 1771 1772 1773 1774 1775 1776 1777
	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;

1778 1779 1780 1781
	case 318:
		test_hash_speed("ghash-generic", sec, hash_speed_template_16);
		if (mode > 300 && mode < 400) break;

1782 1783 1784 1785
	case 319:
		test_hash_speed("crc32c", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1786 1787 1788 1789
	case 320:
		test_hash_speed("crct10dif", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1790 1791 1792
	case 399:
		break;

1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
	case 400:
		/* 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;

	case 499:
		break;

1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
	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,
				   speed_template_32_48_64);
		test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
				   speed_template_32_48_64);
		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);
1888 1889 1890 1891 1892 1893 1894 1895
		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);
1896 1897 1898 1899
		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);
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914
		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);
1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
		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);
1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
		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);
1938 1939 1940 1941 1942 1943 1944 1945
		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);
1946 1947
		break;

1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
	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);
1961 1962 1963 1964
		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);
1965 1966 1967 1968
		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);
1969 1970
		break;

1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
	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;

1994 1995 1996 1997 1998
	case 505:
		test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		break;

1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013
	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;

2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
	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;

2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
	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;

2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074
	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 已提交
2075 2076 2077 2078
	case 1000:
		test_available();
		break;
	}
2079 2080

	return ret;
L
Linus Torvalds 已提交
2081 2082
}

H
Herbert Xu 已提交
2083
static int do_alg_test(const char *alg, u32 type, u32 mask)
2084
{
H
Herbert Xu 已提交
2085 2086
	return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
	       0 : -ENOENT;
2087 2088
}

2089
static int __init tcrypt_mod_init(void)
L
Linus Torvalds 已提交
2090
{
2091
	int err = -ENOMEM;
2092
	int i;
2093

2094 2095 2096 2097 2098
	for (i = 0; i < TVMEMSIZE; i++) {
		tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
		if (!tvmem[i])
			goto err_free_tv;
	}
L
Linus Torvalds 已提交
2099

2100
	if (alg)
H
Herbert Xu 已提交
2101
		err = do_alg_test(alg, type, mask);
2102 2103 2104
	else
		err = do_test(mode);

2105 2106 2107 2108
	if (err) {
		printk(KERN_ERR "tcrypt: one or more tests failed!\n");
		goto err_free_tv;
	}
2109

2110 2111 2112 2113
	/* 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.
2114 2115 2116
	 * => we don't need it in the memory, do we?
	 *                                        -- mludvig
	 */
2117 2118
	if (!fips_enabled)
		err = -EAGAIN;
2119

2120 2121 2122
err_free_tv:
	for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
		free_page((unsigned long)tvmem[i]);
2123 2124

	return err;
L
Linus Torvalds 已提交
2125 2126 2127 2128 2129 2130
}

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

2133 2134
module_init(tcrypt_mod_init);
module_exit(tcrypt_mod_fini);
L
Linus Torvalds 已提交
2135

2136 2137
module_param(alg, charp, 0);
module_param(type, uint, 0);
H
Herbert Xu 已提交
2138
module_param(mask, uint, 0);
L
Linus Torvalds 已提交
2139
module_param(mode, int, 0);
H
Harald Welte 已提交
2140
module_param(sec, uint, 0);
2141 2142
MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
		      "(defaults to zero which uses CPU cycles instead)");
L
Linus Torvalds 已提交
2143 2144 2145 2146

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