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

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

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

51 52 53 54 55
/*
 * 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 已提交
56 57 58
/*
 * Used by test_cipher_speed()
 */
59
static unsigned int sec;
H
Harald Welte 已提交
60

61 62
static char *alg = NULL;
static u32 type;
H
Herbert Xu 已提交
63
static u32 mask;
L
Linus Torvalds 已提交
64
static int mode;
65
static char *tvmem[TVMEMSIZE];
L
Linus Torvalds 已提交
66 67

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

76
static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
M
Mark Rustad 已提交
77
			       struct scatterlist *sg, int blen, int secs)
78 79 80 81 82
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
83
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
84 85
	     time_before(jiffies, end); bcount++) {
		if (enc)
86
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
87
		else
88
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
89 90 91 92 93 94

		if (ret)
			return ret;
	}

	printk("%d operations in %d seconds (%ld bytes)\n",
M
Mark Rustad 已提交
95
	       bcount, secs, (long)bcount * blen);
96 97 98
	return 0;
}

99 100
static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
			      struct scatterlist *sg, int blen)
101 102 103 104 105 106 107 108 109 110
{
	unsigned long cycles = 0;
	int ret = 0;
	int i;

	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
111
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
112
		else
113
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
114 115 116 117 118 119 120 121 122 123 124

		if (ret)
			goto out;
	}

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

		start = get_cycles();
		if (enc)
125
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
126
		else
127
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
		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;
}

146
static int test_aead_jiffies(struct aead_request *req, int enc,
M
Mark Rustad 已提交
147
				int blen, int secs)
148 149 150 151 152
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
153
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
154 155 156 157 158 159 160 161 162 163 164
	     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",
M
Mark Rustad 已提交
165
	       bcount, secs, (long)bcount * blen);
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 209 210 211 212 213 214
	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;
}

215
static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
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
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;
257 258
	} else {
		rem = buflen % PAGE_SIZE;
259
	}
260

261
	sg_init_table(sg, np);
262 263 264 265 266
	np--;
	for (k = 0; k < np; k++)
		sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE);

	sg_set_buf(&sg[k], xbuf[k], rem);
267 268
}

M
Mark Rustad 已提交
269
static void test_aead_speed(const char *algo, int enc, unsigned int secs,
270 271 272 273 274 275 276 277 278 279 280 281 282
			    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;
283
	char *iv;
284 285 286 287 288 289
	char *xbuf[XBUFSIZE];
	char *xoutbuf[XBUFSIZE];
	char *axbuf[XBUFSIZE];
	unsigned int *b_size;
	unsigned int iv_len;

290 291 292 293
	iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
	if (!iv)
		return;

294 295
	if (aad_size >= PAGE_SIZE) {
		pr_err("associate data length (%u) too big\n", aad_size);
296
		goto out_noxbuf;
297 298
	}

299 300 301 302 303 304 305 306 307 308 309 310
	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;

311
	sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
312 313
	if (!sg)
		goto out_nosg;
314
	sgout = &sg[9];
315 316 317 318 319 320

	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));
321
		goto out_notfm;
322 323
	}

324 325 326
	printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
			get_driver_name(crypto_aead, tfm), e);

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);
331
		goto out_noreq;
332 333 334 335 336 337 338
	}

	i = 0;
	do {
		b_size = aead_sizes;
		do {
			assoc = axbuf[0];
339
			memset(assoc, 0xff, aad_size);
340 341
			sg_set_buf(&sg[0], assoc, aad_size);
			sg_set_buf(&sgout[0], assoc, aad_size);
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361

			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)
362
				memset(iv, 0xff, iv_len);
363 364 365 366 367 368 369 370 371 372 373 374 375 376

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

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

380
			sg_init_aead(&sgout[1], xoutbuf,
381 382 383
				    *b_size + (enc ? authsize : 0));

			aead_request_set_crypt(req, sg, sgout, *b_size, iv);
384
			aead_request_set_ad(req, aad_size);
385

M
Mark Rustad 已提交
386 387 388
			if (secs)
				ret = test_aead_jiffies(req, enc, *b_size,
							secs);
389 390 391 392 393 394 395 396 397 398 399 400 401 402
			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:
403 404
	aead_request_free(req);
out_noreq:
405
	crypto_free_aead(tfm);
406
out_notfm:
407 408 409 410 411 412 413 414
	kfree(sg);
out_nosg:
	testmgr_free_buf(xoutbuf);
out_nooutbuf:
	testmgr_free_buf(axbuf);
out_noaxbuf:
	testmgr_free_buf(xbuf);
out_noxbuf:
415
	kfree(iv);
416 417
	return;
}
418

M
Mark Rustad 已提交
419
static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
420
			      struct cipher_speed_template *template,
421
			      unsigned int tcount, u8 *keysize)
H
Harald Welte 已提交
422
{
423
	unsigned int ret, i, j, iv_len;
424 425
	const char *key;
	char iv[128];
426 427 428
	struct crypto_blkcipher *tfm;
	struct blkcipher_desc desc;
	const char *e;
429
	u32 *b_size;
H
Harald Welte 已提交
430 431 432 433 434 435

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

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

438 439 440
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
H
Harald Welte 已提交
441 442
		return;
	}
443 444
	desc.tfm = tfm;
	desc.flags = 0;
H
Harald Welte 已提交
445

446 447 448
	printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
			get_driver_name(crypto_blkcipher, tfm), e);

449 450
	i = 0;
	do {
H
Harald Welte 已提交
451

452 453
		b_size = block_sizes;
		do {
454
			struct scatterlist sg[TVMEMSIZE];
H
Harald Welte 已提交
455

456 457 458 459
			if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
				printk("template (%u) too big for "
				       "tvmem (%lu)\n", *keysize + *b_size,
				       TVMEMSIZE * PAGE_SIZE);
460 461
				goto out;
			}
H
Harald Welte 已提交
462

463 464 465
			printk("test %u (%d bit key, %d byte blocks): ", i,
					*keysize * 8, *b_size);

466
			memset(tvmem[0], 0xff, PAGE_SIZE);
467 468

			/* set key, plain text and IV */
469
			key = tvmem[0];
470 471 472 473 474
			for (j = 0; j < tcount; j++) {
				if (template[j].klen == *keysize) {
					key = template[j].key;
					break;
				}
475
			}
H
Harald Welte 已提交
476

477 478 479 480 481 482
			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 已提交
483

484 485 486 487 488 489 490 491
			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);
			}

492 493 494 495 496
			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 已提交
497

M
Mark Rustad 已提交
498
			if (secs)
499
				ret = test_cipher_jiffies(&desc, enc, sg,
M
Mark Rustad 已提交
500
							  *b_size, secs);
501
			else
502 503
				ret = test_cipher_cycles(&desc, enc, sg,
							 *b_size);
H
Harald Welte 已提交
504

505 506 507 508 509 510 511 512 513
			if (ret) {
				printk("%s() failed flags=%x\n", e, desc.flags);
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);
H
Harald Welte 已提交
514 515

out:
516
	crypto_free_blkcipher(tfm);
H
Harald Welte 已提交
517 518
}

519 520
static int test_hash_jiffies_digest(struct hash_desc *desc,
				    struct scatterlist *sg, int blen,
M
Mark Rustad 已提交
521
				    char *out, int secs)
522 523 524 525 526
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
527
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
528 529 530 531 532 533 534
	     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",
M
Mark Rustad 已提交
535
	       bcount / secs, ((long)bcount * blen) / secs);
536 537 538 539

	return 0;
}

540
static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
M
Mark Rustad 已提交
541
			     int blen, int plen, char *out, int secs)
542 543 544
{
	unsigned long start, end;
	int bcount, pcount;
545 546 547
	int ret;

	if (plen == blen)
M
Mark Rustad 已提交
548
		return test_hash_jiffies_digest(desc, sg, blen, out, secs);
549

M
Mark Rustad 已提交
550
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
551
	     time_before(jiffies, end); bcount++) {
552 553 554
		ret = crypto_hash_init(desc);
		if (ret)
			return ret;
555
		for (pcount = 0; pcount < blen; pcount += plen) {
556 557 558
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				return ret;
559 560
		}
		/* we assume there is enough space in 'out' for the result */
561 562 563
		ret = crypto_hash_final(desc, out);
		if (ret)
			return ret;
564 565 566
	}

	printk("%6u opers/sec, %9lu bytes/sec\n",
M
Mark Rustad 已提交
567
	       bcount / secs, ((long)bcount * blen) / secs);
568

569 570 571
	return 0;
}

572 573
static int test_hash_cycles_digest(struct hash_desc *desc,
				   struct scatterlist *sg, int blen, char *out)
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 599 600 601 602 603 604 605 606 607 608 609 610 611 612
{
	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;
613 614
}

615 616
static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
			    int blen, int plen, char *out)
617 618 619
{
	unsigned long cycles = 0;
	int i, pcount;
620 621 622
	int ret;

	if (plen == blen)
623
		return test_hash_cycles_digest(desc, sg, blen, out);
624

625 626 627 628
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
629 630 631
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
632
		for (pcount = 0; pcount < blen; pcount += plen) {
633 634 635
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
636
		}
637
		ret = crypto_hash_final(desc, out);
638 639
		if (ret)
			goto out;
640 641 642 643 644 645 646 647
	}

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

		start = get_cycles();

648 649 650
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
651
		for (pcount = 0; pcount < blen; pcount += plen) {
652 653 654
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
655
		}
656 657 658
		ret = crypto_hash_final(desc, out);
		if (ret)
			goto out;
659 660 661 662 663 664

		end = get_cycles();

		cycles += end - start;
	}

665
out:
666 667
	local_irq_enable();

668 669 670
	if (ret)
		return ret;

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

674
	return 0;
675 676
}

677 678 679 680 681 682 683 684 685 686 687
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);
	}
}

M
Mark Rustad 已提交
688
static void test_hash_speed(const char *algo, unsigned int secs,
689
			    struct hash_speed *speed)
690
{
691
	struct scatterlist sg[TVMEMSIZE];
692 693
	struct crypto_hash *tfm;
	struct hash_desc desc;
694
	static char output[1024];
695
	int i;
696
	int ret;
697

698
	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
699

700
	if (IS_ERR(tfm)) {
701
		printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
702
		       PTR_ERR(tfm));
703 704 705
		return;
	}

706 707 708
	printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
			get_driver_name(crypto_hash, tfm));

709 710 711 712
	desc.tfm = tfm;
	desc.flags = 0;

	if (crypto_hash_digestsize(tfm) > sizeof(output)) {
713
		printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
714
		       crypto_hash_digestsize(tfm), sizeof(output));
715 716 717
		goto out;
	}

718
	test_hash_sg_init(sg);
719
	for (i = 0; speed[i].blen != 0; i++) {
720
		if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
721 722
			printk(KERN_ERR
			       "template (%u) too big for tvmem (%lu)\n",
723
			       speed[i].blen, TVMEMSIZE * PAGE_SIZE);
724 725 726
			goto out;
		}

727 728 729
		if (speed[i].klen)
			crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);

730 731
		printk(KERN_INFO "test%3u "
		       "(%5u byte blocks,%5u bytes per update,%4u updates): ",
732 733
		       i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);

M
Mark Rustad 已提交
734
		if (secs)
735
			ret = test_hash_jiffies(&desc, sg, speed[i].blen,
M
Mark Rustad 已提交
736
						speed[i].plen, output, secs);
737
		else
738
			ret = test_hash_cycles(&desc, sg, speed[i].blen,
739 740 741
					       speed[i].plen, output);

		if (ret) {
742
			printk(KERN_ERR "hashing failed ret=%d\n", ret);
743 744
			break;
		}
745 746 747
	}

out:
748
	crypto_free_hash(tfm);
749 750
}

751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
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;

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

static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
M
Mark Rustad 已提交
780
				     char *out, 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 790 791 792 793
	     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 已提交
794
	       bcount / secs, ((long)bcount * blen) / secs);
795 796 797 798 799

	return 0;
}

static int test_ahash_jiffies(struct ahash_request *req, int blen,
M
Mark Rustad 已提交
800
			      int plen, char *out, int secs)
801 802 803 804 805 806
{
	unsigned long start, end;
	int bcount, pcount;
	int ret;

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

M
Mark Rustad 已提交
809
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
810
	     time_before(jiffies, end); bcount++) {
811
		ret = do_one_ahash_op(req, crypto_ahash_init(req));
812 813 814 815 816 817 818 819 820 821 822 823 824 825
		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 已提交
826
		bcount / secs, ((long)bcount * blen) / secs);
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

	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++) {
880
		ret = do_one_ahash_op(req, crypto_ahash_init(req));
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
		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();

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

M
Mark Rustad 已提交
926
static void test_ahash_speed(const char *algo, unsigned int secs,
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
			     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;

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

943 944 945
	printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
			get_driver_name(crypto_ahash, tfm));

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

M
Mark Rustad 已提交
976
		if (secs)
977
			ret = test_ahash_jiffies(req, speed[i].blen,
M
Mark Rustad 已提交
978
						 speed[i].plen, output, secs);
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
		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);
}

995 996 997 998 999
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;

1000
		wait_for_completion(&tr->completion);
1001
		reinit_completion(&tr->completion);
1002
		ret = tr->err;
1003 1004 1005 1006 1007 1008
	}

	return ret;
}

static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
M
Mark Rustad 已提交
1009
				int blen, int secs)
1010 1011 1012 1013 1014
{
	unsigned long start, end;
	int bcount;
	int ret;

M
Mark Rustad 已提交
1015
	for (start = jiffies, end = start + secs * HZ, bcount = 0;
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028
	     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",
M
Mark Rustad 已提交
1029
		bcount, secs, (long)bcount * blen);
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 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079
	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;
}

M
Mark Rustad 已提交
1080
static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1081 1082 1083
			       struct cipher_speed_template *template,
			       unsigned int tcount, u8 *keysize)
{
1084
	unsigned int ret, i, j, k, iv_len;
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
	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";

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

1108 1109 1110
	pr_info("\ntesting speed of async %s (%s) %s\n", algo,
			get_driver_name(crypto_ablkcipher, tfm), e);

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 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
	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;
			}

1158
			k = *keysize + *b_size;
1159 1160
			sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));

1161 1162
			if (k > PAGE_SIZE) {
				sg_set_buf(sg, tvmem[0] + *keysize,
1163
				   PAGE_SIZE - *keysize);
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
				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);
1176 1177 1178 1179 1180 1181 1182 1183
			}

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

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

M
Mark Rustad 已提交
1184
			if (secs)
1185
				ret = test_acipher_jiffies(req, enc,
M
Mark Rustad 已提交
1186
							   *b_size, secs);
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
			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);
}

1208
static void test_available(void)
L
Linus Torvalds 已提交
1209 1210
{
	char **name = check;
1211

L
Linus Torvalds 已提交
1212 1213
	while (*name) {
		printk("alg %s ", *name);
1214
		printk(crypto_has_alg(*name, 0, 0) ?
1215
		       "found\n" : "not found\n");
L
Linus Torvalds 已提交
1216
		name++;
1217
	}
L
Linus Torvalds 已提交
1218 1219
}

1220 1221
static inline int tcrypt_test(const char *alg)
{
1222 1223 1224 1225 1226 1227 1228
	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;
1229 1230
}

1231
static int do_test(const char *alg, u32 type, u32 mask, int m)
1232 1233
{
	int i;
1234
	int ret = 0;
1235 1236

	switch (m) {
L
Linus Torvalds 已提交
1237
	case 0:
1238 1239 1240 1241 1242 1243 1244
		if (alg) {
			if (!crypto_has_alg(alg, type,
					    mask ?: CRYPTO_ALG_TYPE_MASK))
				ret = -ENOENT;
			break;
		}

1245
		for (i = 1; i < 200; i++)
1246
			ret += do_test(NULL, 0, 0, i);
L
Linus Torvalds 已提交
1247 1248 1249
		break;

	case 1:
1250
		ret += tcrypt_test("md5");
L
Linus Torvalds 已提交
1251 1252 1253
		break;

	case 2:
1254
		ret += tcrypt_test("sha1");
L
Linus Torvalds 已提交
1255 1256 1257
		break;

	case 3:
1258 1259
		ret += tcrypt_test("ecb(des)");
		ret += tcrypt_test("cbc(des)");
1260
		ret += tcrypt_test("ctr(des)");
L
Linus Torvalds 已提交
1261 1262 1263
		break;

	case 4:
1264 1265
		ret += tcrypt_test("ecb(des3_ede)");
		ret += tcrypt_test("cbc(des3_ede)");
1266
		ret += tcrypt_test("ctr(des3_ede)");
L
Linus Torvalds 已提交
1267 1268 1269
		break;

	case 5:
1270
		ret += tcrypt_test("md4");
L
Linus Torvalds 已提交
1271
		break;
1272

L
Linus Torvalds 已提交
1273
	case 6:
1274
		ret += tcrypt_test("sha256");
L
Linus Torvalds 已提交
1275
		break;
1276

L
Linus Torvalds 已提交
1277
	case 7:
1278 1279
		ret += tcrypt_test("ecb(blowfish)");
		ret += tcrypt_test("cbc(blowfish)");
1280
		ret += tcrypt_test("ctr(blowfish)");
L
Linus Torvalds 已提交
1281 1282 1283
		break;

	case 8:
1284 1285
		ret += tcrypt_test("ecb(twofish)");
		ret += tcrypt_test("cbc(twofish)");
1286
		ret += tcrypt_test("ctr(twofish)");
1287
		ret += tcrypt_test("lrw(twofish)");
1288
		ret += tcrypt_test("xts(twofish)");
L
Linus Torvalds 已提交
1289
		break;
1290

L
Linus Torvalds 已提交
1291
	case 9:
1292
		ret += tcrypt_test("ecb(serpent)");
1293 1294
		ret += tcrypt_test("cbc(serpent)");
		ret += tcrypt_test("ctr(serpent)");
1295
		ret += tcrypt_test("lrw(serpent)");
1296
		ret += tcrypt_test("xts(serpent)");
L
Linus Torvalds 已提交
1297 1298 1299
		break;

	case 10:
1300 1301 1302 1303 1304 1305
		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 已提交
1306 1307 1308
		break;

	case 11:
1309
		ret += tcrypt_test("sha384");
L
Linus Torvalds 已提交
1310
		break;
1311

L
Linus Torvalds 已提交
1312
	case 12:
1313
		ret += tcrypt_test("sha512");
L
Linus Torvalds 已提交
1314 1315 1316
		break;

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

	case 14:
1321
		ret += tcrypt_test("ecb(cast5)");
1322 1323
		ret += tcrypt_test("cbc(cast5)");
		ret += tcrypt_test("ctr(cast5)");
L
Linus Torvalds 已提交
1324 1325 1326
		break;

	case 15:
1327
		ret += tcrypt_test("ecb(cast6)");
1328 1329 1330 1331
		ret += tcrypt_test("cbc(cast6)");
		ret += tcrypt_test("ctr(cast6)");
		ret += tcrypt_test("lrw(cast6)");
		ret += tcrypt_test("xts(cast6)");
L
Linus Torvalds 已提交
1332 1333 1334
		break;

	case 16:
1335
		ret += tcrypt_test("ecb(arc4)");
L
Linus Torvalds 已提交
1336 1337 1338
		break;

	case 17:
1339
		ret += tcrypt_test("michael_mic");
L
Linus Torvalds 已提交
1340 1341 1342
		break;

	case 18:
1343
		ret += tcrypt_test("crc32c");
L
Linus Torvalds 已提交
1344 1345 1346
		break;

	case 19:
1347
		ret += tcrypt_test("ecb(tea)");
L
Linus Torvalds 已提交
1348 1349 1350
		break;

	case 20:
1351
		ret += tcrypt_test("ecb(xtea)");
L
Linus Torvalds 已提交
1352 1353 1354
		break;

	case 21:
1355
		ret += tcrypt_test("ecb(khazad)");
L
Linus Torvalds 已提交
1356 1357 1358
		break;

	case 22:
1359
		ret += tcrypt_test("wp512");
L
Linus Torvalds 已提交
1360 1361 1362
		break;

	case 23:
1363
		ret += tcrypt_test("wp384");
L
Linus Torvalds 已提交
1364 1365 1366
		break;

	case 24:
1367
		ret += tcrypt_test("wp256");
L
Linus Torvalds 已提交
1368 1369 1370
		break;

	case 25:
1371
		ret += tcrypt_test("ecb(tnepres)");
L
Linus Torvalds 已提交
1372 1373 1374
		break;

	case 26:
1375 1376
		ret += tcrypt_test("ecb(anubis)");
		ret += tcrypt_test("cbc(anubis)");
L
Linus Torvalds 已提交
1377 1378 1379
		break;

	case 27:
1380
		ret += tcrypt_test("tgr192");
L
Linus Torvalds 已提交
1381 1382 1383
		break;

	case 28:
1384
		ret += tcrypt_test("tgr160");
L
Linus Torvalds 已提交
1385 1386 1387
		break;

	case 29:
1388
		ret += tcrypt_test("tgr128");
L
Linus Torvalds 已提交
1389
		break;
1390

A
Aaron Grothe 已提交
1391
	case 30:
1392
		ret += tcrypt_test("ecb(xeta)");
A
Aaron Grothe 已提交
1393
		break;
L
Linus Torvalds 已提交
1394

1395
	case 31:
1396
		ret += tcrypt_test("pcbc(fcrypt)");
1397 1398
		break;

1399
	case 32:
1400 1401
		ret += tcrypt_test("ecb(camellia)");
		ret += tcrypt_test("cbc(camellia)");
1402 1403 1404
		ret += tcrypt_test("ctr(camellia)");
		ret += tcrypt_test("lrw(camellia)");
		ret += tcrypt_test("xts(camellia)");
1405
		break;
1406

1407
	case 33:
1408
		ret += tcrypt_test("sha224");
1409
		break;
1410

1411
	case 34:
1412
		ret += tcrypt_test("salsa20");
1413 1414
		break;

1415
	case 35:
1416
		ret += tcrypt_test("gcm(aes)");
1417 1418
		break;

1419
	case 36:
1420
		ret += tcrypt_test("lzo");
1421 1422
		break;

J
Joy Latten 已提交
1423
	case 37:
1424
		ret += tcrypt_test("ccm(aes)");
J
Joy Latten 已提交
1425 1426
		break;

1427
	case 38:
1428
		ret += tcrypt_test("cts(cbc(aes))");
1429 1430
		break;

1431
        case 39:
1432
		ret += tcrypt_test("rmd128");
1433 1434 1435
		break;

        case 40:
1436
		ret += tcrypt_test("rmd160");
1437 1438
		break;

1439
	case 41:
1440
		ret += tcrypt_test("rmd256");
1441 1442 1443
		break;

	case 42:
1444
		ret += tcrypt_test("rmd320");
1445 1446 1447
		break;

	case 43:
1448
		ret += tcrypt_test("ecb(seed)");
1449 1450
		break;

1451
	case 44:
1452
		ret += tcrypt_test("zlib");
1453 1454
		break;

1455
	case 45:
1456
		ret += tcrypt_test("rfc4309(ccm(aes))");
1457 1458
		break;

1459 1460 1461 1462
	case 46:
		ret += tcrypt_test("ghash");
		break;

1463 1464 1465 1466
	case 47:
		ret += tcrypt_test("crct10dif");
		break;

L
Linus Torvalds 已提交
1467
	case 100:
1468
		ret += tcrypt_test("hmac(md5)");
L
Linus Torvalds 已提交
1469
		break;
1470

L
Linus Torvalds 已提交
1471
	case 101:
1472
		ret += tcrypt_test("hmac(sha1)");
L
Linus Torvalds 已提交
1473
		break;
1474

L
Linus Torvalds 已提交
1475
	case 102:
1476
		ret += tcrypt_test("hmac(sha256)");
L
Linus Torvalds 已提交
1477 1478
		break;

1479
	case 103:
1480
		ret += tcrypt_test("hmac(sha384)");
1481 1482 1483
		break;

	case 104:
1484
		ret += tcrypt_test("hmac(sha512)");
1485
		break;
1486

1487
	case 105:
1488
		ret += tcrypt_test("hmac(sha224)");
1489
		break;
L
Linus Torvalds 已提交
1490

1491
	case 106:
1492
		ret += tcrypt_test("xcbc(aes)");
1493 1494
		break;

1495
	case 107:
1496
		ret += tcrypt_test("hmac(rmd128)");
1497 1498 1499
		break;

	case 108:
1500
		ret += tcrypt_test("hmac(rmd160)");
1501 1502
		break;

1503 1504 1505
	case 109:
		ret += tcrypt_test("vmac(aes)");
		break;
1506

1507 1508 1509
	case 110:
		ret += tcrypt_test("hmac(crc32)");
		break;
1510

1511
	case 150:
1512
		ret += tcrypt_test("ansi_cprng");
1513 1514
		break;

1515 1516 1517 1518
	case 151:
		ret += tcrypt_test("rfc4106(gcm(aes))");
		break;

1519 1520 1521 1522
	case 152:
		ret += tcrypt_test("rfc4543(gcm(aes))");
		break;

1523 1524 1525 1526 1527 1528 1529 1530
	case 153:
		ret += tcrypt_test("cmac(aes)");
		break;

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

1531 1532 1533 1534
	case 155:
		ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
		break;

1535 1536 1537 1538 1539 1540 1541
	case 156:
		ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
		break;

	case 157:
		ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
		break;
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
	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 已提交
1572
	case 200:
1573
		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1574
				speed_template_16_24_32);
1575
		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1576
				speed_template_16_24_32);
1577
		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1578
				speed_template_16_24_32);
1579
		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1580
				speed_template_16_24_32);
R
Rik Snel 已提交
1581
		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1582
				speed_template_32_40_48);
R
Rik Snel 已提交
1583
		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1584
				speed_template_32_40_48);
1585
		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1586
				speed_template_32_48_64);
1587
		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1588
				speed_template_32_48_64);
1589 1590 1591 1592
		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 已提交
1593 1594 1595
		break;

	case 201:
1596
		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1597
				des3_speed_template, DES3_SPEED_VECTORS,
1598
				speed_template_24);
1599
		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1600
				des3_speed_template, DES3_SPEED_VECTORS,
1601
				speed_template_24);
1602
		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1603
				des3_speed_template, DES3_SPEED_VECTORS,
1604
				speed_template_24);
1605
		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1606
				des3_speed_template, DES3_SPEED_VECTORS,
1607
				speed_template_24);
1608 1609 1610 1611 1612 1613
		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 已提交
1614 1615 1616
		break;

	case 202:
1617
		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1618
				speed_template_16_24_32);
1619
		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1620
				speed_template_16_24_32);
1621
		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1622
				speed_template_16_24_32);
1623
		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1624
				speed_template_16_24_32);
1625 1626 1627 1628
		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);
1629 1630 1631 1632
		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);
1633 1634 1635 1636
		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 已提交
1637 1638 1639
		break;

	case 203:
1640
		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1641
				  speed_template_8_32);
1642
		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1643
				  speed_template_8_32);
1644
		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1645
				  speed_template_8_32);
1646
		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1647
				  speed_template_8_32);
1648 1649 1650 1651
		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 已提交
1652 1653 1654
		break;

	case 204:
1655
		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1656
				  speed_template_8);
1657
		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1658
				  speed_template_8);
1659
		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1660
				  speed_template_8);
1661
		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1662
				  speed_template_8);
H
Harald Welte 已提交
1663 1664
		break;

1665 1666
	case 205:
		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1667
				speed_template_16_24_32);
1668
		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1669
				speed_template_16_24_32);
1670
		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1671
				speed_template_16_24_32);
1672
		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1673
				speed_template_16_24_32);
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
		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);
1686 1687
		break;

1688 1689
	case 206:
		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1690
				  speed_template_16_32);
1691 1692
		break;

1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
	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);
1706 1707 1708 1709
		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);
1710 1711 1712 1713
		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);
1714 1715
		break;

1716 1717 1718 1719 1720
	case 208:
		test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
				  speed_template_8);
		break;

1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
	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;

1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
	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;

1759 1760 1761 1762 1763
	case 211:
		test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
				NULL, 0, 16, 8, aead_speed_template_20);
		break;

1764
	case 300:
1765 1766 1767 1768 1769
		if (alg) {
			test_hash_speed(alg, sec, generic_hash_speed_template);
			break;
		}

1770 1771 1772
		/* fall through */

	case 301:
1773
		test_hash_speed("md4", sec, generic_hash_speed_template);
1774 1775 1776
		if (mode > 300 && mode < 400) break;

	case 302:
1777
		test_hash_speed("md5", sec, generic_hash_speed_template);
1778 1779 1780
		if (mode > 300 && mode < 400) break;

	case 303:
1781
		test_hash_speed("sha1", sec, generic_hash_speed_template);
1782 1783 1784
		if (mode > 300 && mode < 400) break;

	case 304:
1785
		test_hash_speed("sha256", sec, generic_hash_speed_template);
1786 1787 1788
		if (mode > 300 && mode < 400) break;

	case 305:
1789
		test_hash_speed("sha384", sec, generic_hash_speed_template);
1790 1791 1792
		if (mode > 300 && mode < 400) break;

	case 306:
1793
		test_hash_speed("sha512", sec, generic_hash_speed_template);
1794 1795 1796
		if (mode > 300 && mode < 400) break;

	case 307:
1797
		test_hash_speed("wp256", sec, generic_hash_speed_template);
1798 1799 1800
		if (mode > 300 && mode < 400) break;

	case 308:
1801
		test_hash_speed("wp384", sec, generic_hash_speed_template);
1802 1803 1804
		if (mode > 300 && mode < 400) break;

	case 309:
1805
		test_hash_speed("wp512", sec, generic_hash_speed_template);
1806 1807 1808
		if (mode > 300 && mode < 400) break;

	case 310:
1809
		test_hash_speed("tgr128", sec, generic_hash_speed_template);
1810 1811 1812
		if (mode > 300 && mode < 400) break;

	case 311:
1813
		test_hash_speed("tgr160", sec, generic_hash_speed_template);
1814 1815 1816
		if (mode > 300 && mode < 400) break;

	case 312:
1817
		test_hash_speed("tgr192", sec, generic_hash_speed_template);
1818 1819
		if (mode > 300 && mode < 400) break;

1820 1821 1822 1823
	case 313:
		test_hash_speed("sha224", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1824 1825 1826 1827 1828 1829 1830 1831
	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;

1832 1833 1834 1835 1836 1837 1838 1839
	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;

1840 1841 1842 1843
	case 318:
		test_hash_speed("ghash-generic", sec, hash_speed_template_16);
		if (mode > 300 && mode < 400) break;

1844 1845 1846 1847
	case 319:
		test_hash_speed("crc32c", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1848 1849 1850 1851
	case 320:
		test_hash_speed("crct10dif", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1852 1853 1854
	case 399:
		break;

1855
	case 400:
1856 1857 1858 1859 1860
		if (alg) {
			test_ahash_speed(alg, sec, generic_hash_speed_template);
			break;
		}

1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933
		/* 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;

1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954
	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);
1955 1956 1957 1958 1959 1960 1961 1962
		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);
1963 1964 1965 1966
		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);
1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981
		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);
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
		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);
1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004
		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);
2005 2006 2007 2008 2009 2010 2011 2012
		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);
2013 2014
		break;

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

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

2061 2062 2063 2064 2065
	case 505:
		test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
				   speed_template_8);
		break;

2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
	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;

2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
	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;

2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126
	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;

2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141
	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 已提交
2142 2143 2144 2145
	case 1000:
		test_available();
		break;
	}
2146 2147

	return ret;
L
Linus Torvalds 已提交
2148 2149
}

2150
static int __init tcrypt_mod_init(void)
L
Linus Torvalds 已提交
2151
{
2152
	int err = -ENOMEM;
2153
	int i;
2154

2155 2156 2157 2158 2159
	for (i = 0; i < TVMEMSIZE; i++) {
		tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
		if (!tvmem[i])
			goto err_free_tv;
	}
L
Linus Torvalds 已提交
2160

2161
	err = do_test(alg, type, mask, mode);
2162

2163 2164 2165 2166
	if (err) {
		printk(KERN_ERR "tcrypt: one or more tests failed!\n");
		goto err_free_tv;
	}
2167

2168 2169 2170 2171
	/* 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.
2172 2173 2174
	 * => we don't need it in the memory, do we?
	 *                                        -- mludvig
	 */
2175 2176
	if (!fips_enabled)
		err = -EAGAIN;
2177

2178 2179 2180
err_free_tv:
	for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
		free_page((unsigned long)tvmem[i]);
2181 2182

	return err;
L
Linus Torvalds 已提交
2183 2184 2185 2186 2187 2188
}

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

2191 2192
module_init(tcrypt_mod_init);
module_exit(tcrypt_mod_fini);
L
Linus Torvalds 已提交
2193

2194 2195
module_param(alg, charp, 0);
module_param(type, uint, 0);
H
Herbert Xu 已提交
2196
module_param(mask, uint, 0);
L
Linus Torvalds 已提交
2197
module_param(mode, int, 0);
H
Harald Welte 已提交
2198
module_param(sec, uint, 0);
2199 2200
MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
		      "(defaults to zero which uses CPU cycles instead)");
L
Linus Torvalds 已提交
2201 2202 2203 2204

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