tcrypt.c 48.5 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
 *
 * 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
13
 * Software Foundation; either version 2 of the License, or (at your option)
L
Linus Torvalds 已提交
14 15 16 17
 * any later version.
 *
 */

18
#include <crypto/hash.h>
19
#include <linux/err.h>
L
Linus Torvalds 已提交
20 21 22 23
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
24
#include <linux/scatterlist.h>
L
Linus Torvalds 已提交
25 26 27
#include <linux/string.h>
#include <linux/crypto.h>
#include <linux/moduleparam.h>
H
Harald Welte 已提交
28
#include <linux/jiffies.h>
29 30
#include <linux/timex.h>
#include <linux/interrupt.h>
L
Linus Torvalds 已提交
31 32 33
#include "tcrypt.h"

/*
34
 * Need to kmalloc() memory for testing.
L
Linus Torvalds 已提交
35
 */
H
Harald Welte 已提交
36
#define TVMEMSIZE	16384
L
Linus Torvalds 已提交
37 38 39 40 41
#define XBUFSIZE	32768

/*
 * Indexes into the xbuf to simulate cross-page access.
 */
42
#define IDX1		32
L
Linus Torvalds 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56
#define IDX2		32400
#define IDX3		1
#define IDX4		8193
#define IDX5		22222
#define IDX6		17101
#define IDX7		27333
#define IDX8		3000

/*
* Used by test_cipher()
*/
#define ENCRYPT 1
#define DECRYPT 0

57 58 59 60 61
struct tcrypt_result {
	struct completion completion;
	int err;
};

L
Linus Torvalds 已提交
62 63
static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 };

H
Harald Welte 已提交
64 65 66
/*
 * Used by test_cipher_speed()
 */
67
static unsigned int sec;
H
Harald Welte 已提交
68

L
Linus Torvalds 已提交
69 70
static int mode;
static char *xbuf;
71
static char *axbuf;
L
Linus Torvalds 已提交
72 73 74
static char *tvmem;

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

83
static void hexdump(unsigned char *buf, unsigned int len)
L
Linus Torvalds 已提交
84
{
85 86 87
	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
			16, 1,
			buf, len, false);
L
Linus Torvalds 已提交
88 89
}

90 91 92 93 94 95 96 97 98 99 100
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);
}

101 102
static void test_hash(char *algo, struct hash_testvec *template,
		      unsigned int tcount)
L
Linus Torvalds 已提交
103
{
104 105 106
	unsigned int i, j, k, temp;
	struct scatterlist sg[8];
	char result[64];
107 108 109
	struct crypto_ahash *tfm;
	struct ahash_request *req;
	struct tcrypt_result tresult;
110
	int ret;
111
	void *hash_buff;
112 113 114

	printk("\ntesting %s\n", algo);

115 116 117
	init_completion(&tresult.completion);

	tfm = crypto_alloc_ahash(algo, 0, 0);
118 119 120
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
L
Linus Torvalds 已提交
121 122 123
		return;
	}

124 125 126 127 128 129 130
	req = ahash_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		printk(KERN_ERR "failed to allocate request for %s\n", algo);
		goto out_noreq;
	}
	ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
				   tcrypt_complete, &tresult);
131

L
Linus Torvalds 已提交
132
	for (i = 0; i < tcount; i++) {
133 134
		printk("test %u:\n", i + 1);
		memset(result, 0, 64);
L
Linus Torvalds 已提交
135

136 137 138
		hash_buff = kzalloc(template[i].psize, GFP_KERNEL);
		if (!hash_buff)
			continue;
L
Linus Torvalds 已提交
139

140 141 142 143
		memcpy(hash_buff, template[i].plaintext, template[i].psize);
		sg_init_one(&sg[0], hash_buff, template[i].psize);

		if (template[i].ksize) {
144 145 146
			crypto_ahash_clear_flags(tfm, ~0);
			ret = crypto_ahash_setkey(tfm, template[i].key,
						  template[i].ksize);
147 148
			if (ret) {
				printk("setkey() failed ret=%d\n", ret);
149
				kfree(hash_buff);
150 151 152 153
				goto out;
			}
		}

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
		ahash_request_set_crypt(req, sg, result, template[i].psize);
		ret = crypto_ahash_digest(req);
		switch (ret) {
		case 0:
			break;
		case -EINPROGRESS:
		case -EBUSY:
			ret = wait_for_completion_interruptible(
				&tresult.completion);
			if (!ret && !(ret = tresult.err)) {
				INIT_COMPLETION(tresult.completion);
				break;
			}
			/* fall through */
		default:
169
			printk("digest () failed ret=%d\n", ret);
170
			kfree(hash_buff);
171 172
			goto out;
		}
L
Linus Torvalds 已提交
173

174
		hexdump(result, crypto_ahash_digestsize(tfm));
L
Linus Torvalds 已提交
175
		printk("%s\n",
176
		       memcmp(result, template[i].digest,
177
			      crypto_ahash_digestsize(tfm)) ?
178
		       "fail" : "pass");
179
		kfree(hash_buff);
L
Linus Torvalds 已提交
180 181
	}

182
	printk("testing %s across pages\n", algo);
L
Linus Torvalds 已提交
183 184

	/* setup the dummy buffer first */
185
	memset(xbuf, 0, XBUFSIZE);
L
Linus Torvalds 已提交
186 187 188

	j = 0;
	for (i = 0; i < tcount; i++) {
189
		if (template[i].np) {
L
Linus Torvalds 已提交
190
			j++;
191 192
			printk("test %u:\n", j);
			memset(result, 0, 64);
L
Linus Torvalds 已提交
193 194

			temp = 0;
195 196
			sg_init_table(sg, template[i].np);
			for (k = 0; k < template[i].np; k++) {
197
				memcpy(&xbuf[IDX[k]],
198 199 200
				       template[i].plaintext + temp,
				       template[i].tap[k]);
				temp += template[i].tap[k];
201
				sg_set_buf(&sg[k], &xbuf[IDX[k]],
202
					    template[i].tap[k]);
L
Linus Torvalds 已提交
203 204
			}

205
			if (template[i].ksize) {
206 207 208
				crypto_ahash_clear_flags(tfm, ~0);
				ret = crypto_ahash_setkey(tfm, template[i].key,
							  template[i].ksize);
209

210 211 212 213
				if (ret) {
					printk("setkey() failed ret=%d\n", ret);
					goto out;
				}
L
Linus Torvalds 已提交
214 215
			}

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
			ahash_request_set_crypt(req, sg, result,
						template[i].psize);
			ret = crypto_ahash_digest(req);
			switch (ret) {
			case 0:
				break;
			case -EINPROGRESS:
			case -EBUSY:
				ret = wait_for_completion_interruptible(
					&tresult.completion);
				if (!ret && !(ret = tresult.err)) {
					INIT_COMPLETION(tresult.completion);
					break;
				}
				/* fall through */
			default:
232 233 234
				printk("digest () failed ret=%d\n", ret);
				goto out;
			}
235

236
			hexdump(result, crypto_ahash_digestsize(tfm));
L
Linus Torvalds 已提交
237
			printk("%s\n",
238
			       memcmp(result, template[i].digest,
239
				      crypto_ahash_digestsize(tfm)) ?
240
			       "fail" : "pass");
L
Linus Torvalds 已提交
241 242
		}
	}
243

L
Linus Torvalds 已提交
244
out:
245 246 247
	ahash_request_free(req);
out_noreq:
	crypto_free_ahash(tfm);
L
Linus Torvalds 已提交
248 249
}

250 251 252
static void test_aead(char *algo, int enc, struct aead_testvec *template,
		      unsigned int tcount)
{
253
	unsigned int ret, i, j, k, n, temp;
254 255 256 257 258 259 260 261
	char *q;
	struct crypto_aead *tfm;
	char *key;
	struct aead_request *req;
	struct scatterlist sg[8];
	struct scatterlist asg[8];
	const char *e;
	struct tcrypt_result result;
H
Herbert Xu 已提交
262
	unsigned int authsize;
263 264 265
	void *input;
	void *assoc;
	char iv[MAX_IVLEN];
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293

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

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

	init_completion(&result.completion);

	tfm = crypto_alloc_aead(algo, 0, 0);

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

	req = aead_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		printk(KERN_INFO "failed to allocate request for %s\n", algo);
		goto out;
	}

	aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
				  tcrypt_complete, &result);

	for (i = 0, j = 0; i < tcount; i++) {
294
		if (!template[i].np) {
295
			printk(KERN_INFO "test %u (%d bit key):\n",
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
			       ++j, template[i].klen * 8);

			/* some tepmplates have no input data but they will
			 * touch input
			 */
			input = kzalloc(template[i].ilen + template[i].rlen, GFP_KERNEL);
			if (!input)
				continue;

			assoc = kzalloc(template[i].alen, GFP_KERNEL);
			if (!assoc) {
				kfree(input);
				continue;
			}

			memcpy(input, template[i].input, template[i].ilen);
			memcpy(assoc, template[i].assoc, template[i].alen);
			if (template[i].iv)
				memcpy(iv, template[i].iv, MAX_IVLEN);
			else
				memset(iv, 0, MAX_IVLEN);
317 318

			crypto_aead_clear_flags(tfm, ~0);
319
			if (template[i].wk)
320 321
				crypto_aead_set_flags(
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
322 323 324 325 326

			if (template[i].key)
				key = template[i].key;
			else
				key = kzalloc(template[i].klen, GFP_KERNEL);
327 328

			ret = crypto_aead_setkey(tfm, key,
329
						 template[i].klen);
330 331 332 333
			if (ret) {
				printk(KERN_INFO "setkey() failed flags=%x\n",
				       crypto_aead_get_flags(tfm));

334 335
				if (!template[i].fail)
					goto next_one;
336 337
			}

338
			authsize = abs(template[i].rlen - template[i].ilen);
J
Joy Latten 已提交
339 340 341 342 343
			ret = crypto_aead_setauthsize(tfm, authsize);
			if (ret) {
				printk(KERN_INFO
				       "failed to set authsize = %u\n",
				       authsize);
344
				goto next_one;
J
Joy Latten 已提交
345 346
			}

347 348
			sg_init_one(&sg[0], input,
				    template[i].ilen + (enc ? authsize : 0));
349

350
			sg_init_one(&asg[0], assoc, template[i].alen);
351 352

			aead_request_set_crypt(req, sg, sg,
353
					       template[i].ilen, iv);
354

355
			aead_request_set_assoc(req, asg, template[i].alen);
356

H
Herbert Xu 已提交
357 358 359
			ret = enc ?
				crypto_aead_encrypt(req) :
				crypto_aead_decrypt(req);
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375

			switch (ret) {
			case 0:
				break;
			case -EINPROGRESS:
			case -EBUSY:
				ret = wait_for_completion_interruptible(
					&result.completion);
				if (!ret && !(ret = result.err)) {
					INIT_COMPLETION(result.completion);
					break;
				}
				/* fall through */
			default:
				printk(KERN_INFO "%s () failed err=%d\n",
				       e, -ret);
376
				goto next_one;
377 378
			}

379
			q = input;
380
			hexdump(q, template[i].rlen);
381 382

			printk(KERN_INFO "enc/dec: %s\n",
383 384 385 386 387 388 389
			       memcmp(q, template[i].result,
				      template[i].rlen) ? "fail" : "pass");
next_one:
			if (!template[i].key)
				kfree(key);
			kfree(assoc);
			kfree(input);
390 391 392 393
		}
	}

	printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
394
	memset(axbuf, 0, XBUFSIZE);
395 396

	for (i = 0, j = 0; i < tcount; i++) {
397
		if (template[i].np) {
398
			printk(KERN_INFO "test %u (%d bit key):\n",
399 400 401 402 403 404
			       ++j, template[i].klen * 8);

			if (template[i].iv)
				memcpy(iv, template[i].iv, MAX_IVLEN);
			else
				memset(iv, 0, MAX_IVLEN);
405 406

			crypto_aead_clear_flags(tfm, ~0);
407
			if (template[i].wk)
408 409
				crypto_aead_set_flags(
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
410
			key = template[i].key;
411

412
			ret = crypto_aead_setkey(tfm, key, template[i].klen);
413 414 415 416
			if (ret) {
				printk(KERN_INFO "setkey() failed flags=%x\n",
				       crypto_aead_get_flags(tfm));

417
				if (!template[i].fail)
418 419 420
					goto out;
			}

421
			memset(xbuf, 0, XBUFSIZE);
422 423
			sg_init_table(sg, template[i].np);
			for (k = 0, temp = 0; k < template[i].np; k++) {
424
				memcpy(&xbuf[IDX[k]],
425 426 427
				       template[i].input + temp,
				       template[i].tap[k]);
				temp += template[i].tap[k];
428
				sg_set_buf(&sg[k], &xbuf[IDX[k]],
429
					   template[i].tap[k]);
430 431
			}

432
			authsize = abs(template[i].rlen - template[i].ilen);
J
Joy Latten 已提交
433 434 435 436 437 438 439 440
			ret = crypto_aead_setauthsize(tfm, authsize);
			if (ret) {
				printk(KERN_INFO
				       "failed to set authsize = %u\n",
				       authsize);
				goto out;
			}

H
Herbert Xu 已提交
441 442 443
			if (enc)
				sg[k - 1].length += authsize;

444 445
			sg_init_table(asg, template[i].anp);
			for (k = 0, temp = 0; k < template[i].anp; k++) {
446
				memcpy(&axbuf[IDX[k]],
447 448 449
				       template[i].assoc + temp,
				       template[i].atap[k]);
				temp += template[i].atap[k];
450
				sg_set_buf(&asg[k], &axbuf[IDX[k]],
451
					   template[i].atap[k]);
452 453 454
			}

			aead_request_set_crypt(req, sg, sg,
455 456
					       template[i].ilen,
					       iv);
457

458
			aead_request_set_assoc(req, asg, template[i].alen);
459

H
Herbert Xu 已提交
460 461 462
			ret = enc ?
				crypto_aead_encrypt(req) :
				crypto_aead_decrypt(req);
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481

			switch (ret) {
			case 0:
				break;
			case -EINPROGRESS:
			case -EBUSY:
				ret = wait_for_completion_interruptible(
					&result.completion);
				if (!ret && !(ret = result.err)) {
					INIT_COMPLETION(result.completion);
					break;
				}
				/* fall through */
			default:
				printk(KERN_INFO "%s () failed err=%d\n",
				       e, -ret);
				goto out;
			}

482
			for (k = 0, temp = 0; k < template[i].np; k++) {
483
				printk(KERN_INFO "page %u\n", k);
484
				q = &axbuf[IDX[k]];
485
				hexdump(q, template[i].tap[k]);
486
				printk(KERN_INFO "%s\n",
487 488 489
				       memcmp(q, template[i].result + temp,
					      template[i].tap[k] -
					      (k < template[i].np - 1 || enc ?
H
Herbert Xu 已提交
490
					       0 : authsize)) ?
491 492
				       "fail" : "pass");

493 494 495 496 497 498 499 500
				for (n = 0; q[template[i].tap[k] + n]; n++)
					;
				if (n) {
					printk("Result buffer corruption %u "
					       "bytes:\n", n);
					hexdump(&q[template[i].tap[k]], n);
				}

501
				temp += template[i].tap[k];
502 503 504 505 506 507 508 509 510
			}
		}
	}

out:
	crypto_free_aead(tfm);
	aead_request_free(req);
}

511
static void test_cipher(char *algo, int enc,
512
			struct cipher_testvec *template, unsigned int tcount)
L
Linus Torvalds 已提交
513
{
514
	unsigned int ret, i, j, k, n, temp;
515
	char *q;
516 517
	struct crypto_ablkcipher *tfm;
	struct ablkcipher_request *req;
L
Linus Torvalds 已提交
518
	struct scatterlist sg[8];
519
	const char *e;
520
	struct tcrypt_result result;
521 522
	void *data;
	char iv[MAX_IVLEN];
L
Linus Torvalds 已提交
523 524

	if (enc == ENCRYPT)
525
	        e = "encryption";
L
Linus Torvalds 已提交
526
	else
527
		e = "decryption";
L
Linus Torvalds 已提交
528

529
	printk("\ntesting %s %s\n", algo, e);
L
Linus Torvalds 已提交
530

531 532
	init_completion(&result.completion);
	tfm = crypto_alloc_ablkcipher(algo, 0, 0);
L
Linus Torvalds 已提交
533

534 535 536
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
L
Linus Torvalds 已提交
537 538
		return;
	}
539 540 541 542 543 544 545 546 547

	req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
	if (!req) {
		printk("failed to allocate request for %s\n", algo);
		goto out;
	}

	ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
					tcrypt_complete, &result);
548

L
Linus Torvalds 已提交
549 550
	j = 0;
	for (i = 0; i < tcount; i++) {
551 552 553 554 555 556 557 558 559 560 561 562

		data = kzalloc(template[i].ilen, GFP_KERNEL);
		if (!data)
			continue;

		memcpy(data, template[i].input, template[i].ilen);
		if (template[i].iv)
			memcpy(iv, template[i].iv, MAX_IVLEN);
		else
			memset(iv, 0, MAX_IVLEN);

		if (!(template[i].np)) {
563
			j++;
L
Linus Torvalds 已提交
564
			printk("test %u (%d bit key):\n",
565
			j, template[i].klen * 8);
L
Linus Torvalds 已提交
566

567
			crypto_ablkcipher_clear_flags(tfm, ~0);
568
			if (template[i].wk)
569
				crypto_ablkcipher_set_flags(
570
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
571

572 573
			ret = crypto_ablkcipher_setkey(tfm, template[i].key,
						       template[i].klen);
L
Linus Torvalds 已提交
574
			if (ret) {
575
				printk("setkey() failed flags=%x\n",
576
				       crypto_ablkcipher_get_flags(tfm));
577

578 579
				if (!template[i].fail) {
					kfree(data);
L
Linus Torvalds 已提交
580
					goto out;
581
				}
582
			}
L
Linus Torvalds 已提交
583

584
			sg_init_one(&sg[0], data, template[i].ilen);
585

586
			ablkcipher_request_set_crypt(req, sg, sg,
587
						     template[i].ilen, iv);
588
			ret = enc ?
589 590
				crypto_ablkcipher_encrypt(req) :
				crypto_ablkcipher_decrypt(req);
591

592 593 594 595 596 597 598 599 600 601 602 603 604 605
			switch (ret) {
			case 0:
				break;
			case -EINPROGRESS:
			case -EBUSY:
				ret = wait_for_completion_interruptible(
					&result.completion);
				if (!ret && !((ret = result.err))) {
					INIT_COMPLETION(result.completion);
					break;
				}
				/* fall through */
			default:
				printk("%s () failed err=%d\n", e, -ret);
606
				kfree(data);
L
Linus Torvalds 已提交
607
				goto out;
608 609
			}

610
			q = data;
611
			hexdump(q, template[i].rlen);
612 613

			printk("%s\n",
614 615
			       memcmp(q, template[i].result,
				      template[i].rlen) ? "fail" : "pass");
L
Linus Torvalds 已提交
616
		}
617
		kfree(data);
L
Linus Torvalds 已提交
618
	}
619

620
	printk("\ntesting %s %s across pages (chunking)\n", algo, e);
621

L
Linus Torvalds 已提交
622 623
	j = 0;
	for (i = 0; i < tcount; i++) {
624 625 626 627 628 629 630

		if (template[i].iv)
			memcpy(iv, template[i].iv, MAX_IVLEN);
		else
			memset(iv, 0, MAX_IVLEN);

		if (template[i].np) {
631
			j++;
L
Linus Torvalds 已提交
632
			printk("test %u (%d bit key):\n",
633
			j, template[i].klen * 8);
L
Linus Torvalds 已提交
634

635
			memset(xbuf, 0, XBUFSIZE);
636
			crypto_ablkcipher_clear_flags(tfm, ~0);
637
			if (template[i].wk)
638
				crypto_ablkcipher_set_flags(
639
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
640

641 642
			ret = crypto_ablkcipher_setkey(tfm, template[i].key,
						       template[i].klen);
L
Linus Torvalds 已提交
643
			if (ret) {
644
				printk("setkey() failed flags=%x\n",
645
						crypto_ablkcipher_get_flags(tfm));
646

647
				if (!template[i].fail)
L
Linus Torvalds 已提交
648 649 650 651
					goto out;
			}

			temp = 0;
652 653
			sg_init_table(sg, template[i].np);
			for (k = 0; k < template[i].np; k++) {
654
				memcpy(&xbuf[IDX[k]],
655 656 657
						template[i].input + temp,
						template[i].tap[k]);
				temp += template[i].tap[k];
658
				sg_set_buf(&sg[k], &xbuf[IDX[k]],
659
						template[i].tap[k]);
L
Linus Torvalds 已提交
660
			}
661

662
			ablkcipher_request_set_crypt(req, sg, sg,
663
					template[i].ilen, iv);
664

665
			ret = enc ?
666 667
				crypto_ablkcipher_encrypt(req) :
				crypto_ablkcipher_decrypt(req);
668

669 670 671 672 673 674 675 676 677 678 679 680 681 682
			switch (ret) {
			case 0:
				break;
			case -EINPROGRESS:
			case -EBUSY:
				ret = wait_for_completion_interruptible(
					&result.completion);
				if (!ret && !((ret = result.err))) {
					INIT_COMPLETION(result.completion);
					break;
				}
				/* fall through */
			default:
				printk("%s () failed err=%d\n", e, -ret);
L
Linus Torvalds 已提交
683 684 685 686
				goto out;
			}

			temp = 0;
687
			for (k = 0; k < template[i].np; k++) {
L
Linus Torvalds 已提交
688
				printk("page %u\n", k);
689
				q = &xbuf[IDX[k]];
690
				hexdump(q, template[i].tap[k]);
691
				printk("%s\n",
692 693
					memcmp(q, template[i].result + temp,
						template[i].tap[k]) ? "fail" :
L
Linus Torvalds 已提交
694
					"pass");
695 696 697 698 699 700 701 702

				for (n = 0; q[template[i].tap[k] + n]; n++)
					;
				if (n) {
					printk("Result buffer corruption %u "
					       "bytes:\n", n);
					hexdump(&q[template[i].tap[k]], n);
				}
703
				temp += template[i].tap[k];
L
Linus Torvalds 已提交
704 705 706 707
			}
		}
	}
out:
708 709
	crypto_free_ablkcipher(tfm);
	ablkcipher_request_free(req);
L
Linus Torvalds 已提交
710 711
}

712
static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
713 714
			       int blen, int sec)
{
715
	struct scatterlist sg[1];
716 717 718 719
	unsigned long start, end;
	int bcount;
	int ret;

720
	sg_init_one(sg, p, blen);
721 722 723 724

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		if (enc)
725
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
726
		else
727
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
728 729 730 731 732 733 734 735 736 737

		if (ret)
			return ret;
	}

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

738
static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
739 740
			      int blen)
{
741
	struct scatterlist sg[1];
742 743 744 745
	unsigned long cycles = 0;
	int ret = 0;
	int i;

746
	sg_init_one(sg, p, blen);
747 748 749 750 751 752 753

	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
754
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
755
		else
756
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
757 758 759 760 761 762 763 764 765 766 767

		if (ret)
			goto out;
	}

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

		start = get_cycles();
		if (enc)
768
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
769
		else
770
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
		end = get_cycles();

		if (ret)
			goto out;

		cycles += end - start;
	}

out:
	local_irq_enable();
	local_bh_enable();

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

	return ret;
}

790 791
static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };

792
static void test_cipher_speed(char *algo, int enc, unsigned int sec,
793
			      struct cipher_testvec *template,
794
			      unsigned int tcount, u8 *keysize)
H
Harald Welte 已提交
795
{
796
	unsigned int ret, i, j, iv_len;
H
Harald Welte 已提交
797
	unsigned char *key, *p, iv[128];
798 799 800
	struct crypto_blkcipher *tfm;
	struct blkcipher_desc desc;
	const char *e;
801
	u32 *b_size;
H
Harald Welte 已提交
802 803 804 805 806 807

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

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

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

812 813 814
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
H
Harald Welte 已提交
815 816
		return;
	}
817 818
	desc.tfm = tfm;
	desc.flags = 0;
H
Harald Welte 已提交
819

820 821
	i = 0;
	do {
H
Harald Welte 已提交
822

823 824
		b_size = block_sizes;
		do {
H
Harald Welte 已提交
825

826 827 828 829 830
			if ((*keysize + *b_size) > TVMEMSIZE) {
				printk("template (%u) too big for tvmem (%u)\n",
						*keysize + *b_size, TVMEMSIZE);
				goto out;
			}
H
Harald Welte 已提交
831

832 833 834 835 836 837 838 839 840 841 842 843
			printk("test %u (%d bit key, %d byte blocks): ", i,
					*keysize * 8, *b_size);

			memset(tvmem, 0xff, *keysize + *b_size);

			/* set key, plain text and IV */
			key = (unsigned char *)tvmem;
			for (j = 0; j < tcount; j++) {
				if (template[j].klen == *keysize) {
					key = template[j].key;
					break;
				}
844
			}
845
			p = (unsigned char *)tvmem + *keysize;
H
Harald Welte 已提交
846

847 848 849 850 851 852
			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 已提交
853

854 855 856 857 858
			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 已提交
859

860 861 862 863
			if (sec)
				ret = test_cipher_jiffies(&desc, enc, p, *b_size, sec);
			else
				ret = test_cipher_cycles(&desc, enc, p, *b_size);
H
Harald Welte 已提交
864

865 866 867 868 869 870 871 872 873
			if (ret) {
				printk("%s() failed flags=%x\n", e, desc.flags);
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);
H
Harald Welte 已提交
874 875

out:
876
	crypto_free_blkcipher(tfm);
H
Harald Welte 已提交
877 878
}

879 880 881 882 883 884 885 886
static int test_hash_jiffies_digest(struct hash_desc *desc, char *p, int blen,
				    char *out, int sec)
{
	struct scatterlist sg[1];
	unsigned long start, end;
	int bcount;
	int ret;

887 888
	sg_init_table(sg, 1);

889 890
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
891
		sg_set_buf(sg, p, blen);
892 893 894 895 896 897 898 899 900 901 902 903 904
		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;
}

static int test_hash_jiffies(struct hash_desc *desc, char *p, int blen,
			     int plen, char *out, int sec)
905 906 907 908
{
	struct scatterlist sg[1];
	unsigned long start, end;
	int bcount, pcount;
909 910 911 912
	int ret;

	if (plen == blen)
		return test_hash_jiffies_digest(desc, p, blen, out, sec);
913

914 915
	sg_init_table(sg, 1);

916 917
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
918 919 920
		ret = crypto_hash_init(desc);
		if (ret)
			return ret;
921
		for (pcount = 0; pcount < blen; pcount += plen) {
922
			sg_set_buf(sg, p + pcount, plen);
923 924 925
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				return ret;
926 927
		}
		/* we assume there is enough space in 'out' for the result */
928 929 930
		ret = crypto_hash_final(desc, out);
		if (ret)
			return ret;
931 932 933 934 935
	}

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

936 937 938 939 940 941 942 943 944 945 946
	return 0;
}

static int test_hash_cycles_digest(struct hash_desc *desc, char *p, int blen,
				   char *out)
{
	struct scatterlist sg[1];
	unsigned long cycles = 0;
	int i;
	int ret;

947 948
	sg_init_table(sg, 1);

949 950 951 952 953
	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
954
		sg_set_buf(sg, p, blen);
955 956 957 958 959 960 961 962 963 964 965
		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();

966
		sg_set_buf(sg, p, blen);
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
		ret = crypto_hash_digest(desc, sg, blen, out);
		if (ret)
			goto out;

		end = get_cycles();

		cycles += end - start;
	}

out:
	local_irq_enable();
	local_bh_enable();

	if (ret)
		return ret;

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

	return 0;
987 988
}

989 990
static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
			    int plen, char *out)
991 992 993 994
{
	struct scatterlist sg[1];
	unsigned long cycles = 0;
	int i, pcount;
995 996 997 998
	int ret;

	if (plen == blen)
		return test_hash_cycles_digest(desc, p, blen, out);
999

1000 1001
	sg_init_table(sg, 1);

1002 1003 1004 1005 1006
	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
1007 1008 1009
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
1010
		for (pcount = 0; pcount < blen; pcount += plen) {
1011
			sg_set_buf(sg, p + pcount, plen);
1012 1013 1014
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
1015
		}
1016
		ret = crypto_hash_final(desc, out);
1017 1018
		if (ret)
			goto out;
1019 1020 1021 1022 1023 1024 1025 1026
	}

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

		start = get_cycles();

1027 1028 1029
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
1030
		for (pcount = 0; pcount < blen; pcount += plen) {
1031
			sg_set_buf(sg, p + pcount, plen);
1032 1033 1034
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
1035
		}
1036 1037 1038
		ret = crypto_hash_final(desc, out);
		if (ret)
			goto out;
1039 1040 1041 1042 1043 1044

		end = get_cycles();

		cycles += end - start;
	}

1045
out:
1046 1047 1048
	local_irq_enable();
	local_bh_enable();

1049 1050 1051
	if (ret)
		return ret;

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

1055
	return 0;
1056 1057
}

1058 1059
static void test_hash_speed(char *algo, unsigned int sec,
			      struct hash_speed *speed)
1060
{
1061 1062
	struct crypto_hash *tfm;
	struct hash_desc desc;
1063 1064
	char output[1024];
	int i;
1065
	int ret;
1066 1067 1068

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

1069
	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
1070

1071 1072 1073
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
1074 1075 1076
		return;
	}

1077 1078 1079 1080
	desc.tfm = tfm;
	desc.flags = 0;

	if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1081
		printk("digestsize(%u) > outputbuffer(%zu)\n",
1082
		       crypto_hash_digestsize(tfm), sizeof(output));
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
		goto out;
	}

	for (i = 0; speed[i].blen != 0; i++) {
		if (speed[i].blen > TVMEMSIZE) {
			printk("template (%u) too big for tvmem (%u)\n",
			       speed[i].blen, TVMEMSIZE);
			goto out;
		}

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

		memset(tvmem, 0xff, speed[i].blen);

		if (sec)
1099 1100
			ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
						speed[i].plen, output, sec);
1101
		else
1102 1103 1104 1105 1106 1107 1108
			ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
					       speed[i].plen, output);

		if (ret) {
			printk("hashing failed ret=%d\n", ret);
			break;
		}
1109 1110 1111
	}

out:
1112
	crypto_free_hash(tfm);
1113 1114
}

1115 1116
static void test_comp(char *algo, struct comp_testvec *ctemplate,
		       struct comp_testvec *dtemplate, int ctcount, int dtcount)
L
Linus Torvalds 已提交
1117 1118 1119
{
	unsigned int i;
	char result[COMP_BUF_SIZE];
1120
	struct crypto_comp *tfm;
L
Linus Torvalds 已提交
1121 1122
	unsigned int tsize;

1123
	printk("\ntesting %s compression\n", algo);
L
Linus Torvalds 已提交
1124

1125
	tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1126
	if (IS_ERR(tfm)) {
1127
		printk("failed to load transform for %s\n", algo);
L
Linus Torvalds 已提交
1128 1129 1130
		return;
	}

1131
	for (i = 0; i < ctcount; i++) {
L
Linus Torvalds 已提交
1132
		int ilen, ret, dlen = COMP_BUF_SIZE;
1133

L
Linus Torvalds 已提交
1134 1135 1136
		printk("test %u:\n", i + 1);
		memset(result, 0, sizeof (result));

1137 1138
		ilen = ctemplate[i].inlen;
		ret = crypto_comp_compress(tfm, ctemplate[i].input,
L
Linus Torvalds 已提交
1139 1140 1141 1142 1143 1144 1145
		                           ilen, result, &dlen);
		if (ret) {
			printk("fail: ret=%d\n", ret);
			continue;
		}
		hexdump(result, dlen);
		printk("%s (ratio %d:%d)\n",
1146
		       memcmp(result, ctemplate[i].output, dlen) ? "fail" : "pass",
L
Linus Torvalds 已提交
1147 1148 1149
		       ilen, dlen);
	}

1150
	printk("\ntesting %s decompression\n", algo);
L
Linus Torvalds 已提交
1151

1152 1153
	tsize = sizeof(struct comp_testvec);
	tsize *= dtcount;
L
Linus Torvalds 已提交
1154 1155 1156 1157 1158 1159
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize,
		       TVMEMSIZE);
		goto out;
	}

1160
	for (i = 0; i < dtcount; i++) {
L
Linus Torvalds 已提交
1161
		int ilen, ret, dlen = COMP_BUF_SIZE;
1162

L
Linus Torvalds 已提交
1163 1164 1165
		printk("test %u:\n", i + 1);
		memset(result, 0, sizeof (result));

1166 1167
		ilen = dtemplate[i].inlen;
		ret = crypto_comp_decompress(tfm, dtemplate[i].input,
L
Linus Torvalds 已提交
1168 1169 1170 1171 1172 1173 1174
		                             ilen, result, &dlen);
		if (ret) {
			printk("fail: ret=%d\n", ret);
			continue;
		}
		hexdump(result, dlen);
		printk("%s (ratio %d:%d)\n",
1175
		       memcmp(result, dtemplate[i].output, dlen) ? "fail" : "pass",
L
Linus Torvalds 已提交
1176 1177 1178
		       ilen, dlen);
	}
out:
1179
	crypto_free_comp(tfm);
L
Linus Torvalds 已提交
1180 1181
}

1182
static void test_available(void)
L
Linus Torvalds 已提交
1183 1184
{
	char **name = check;
1185

L
Linus Torvalds 已提交
1186 1187
	while (*name) {
		printk("alg %s ", *name);
1188
		printk(crypto_has_alg(*name, 0, 0) ?
1189
		       "found\n" : "not found\n");
L
Linus Torvalds 已提交
1190
		name++;
1191
	}
L
Linus Torvalds 已提交
1192 1193
}

1194
static void do_test(void)
L
Linus Torvalds 已提交
1195 1196 1197 1198 1199
{
	switch (mode) {

	case 0:
		test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
1200

L
Linus Torvalds 已提交
1201
		test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1202

L
Linus Torvalds 已提交
1203
		//DES
1204 1205 1206 1207 1208 1209 1210 1211
		test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
			    DES_ENC_TEST_VECTORS);
		test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
			    DES_DEC_TEST_VECTORS);
		test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
			    DES_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
			    DES_CBC_DEC_TEST_VECTORS);
1212

L
Linus Torvalds 已提交
1213
		//DES3_EDE
1214 1215 1216 1217
		test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
			    DES3_EDE_ENC_TEST_VECTORS);
		test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
			    DES3_EDE_DEC_TEST_VECTORS);
1218

1219 1220 1221 1222 1223 1224 1225 1226
		test_cipher("cbc(des3_ede)", ENCRYPT,
			    des3_ede_cbc_enc_tv_template,
			    DES3_EDE_CBC_ENC_TEST_VECTORS);

		test_cipher("cbc(des3_ede)", DECRYPT,
			    des3_ede_cbc_dec_tv_template,
			    DES3_EDE_CBC_DEC_TEST_VECTORS);

L
Linus Torvalds 已提交
1227
		test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1228

1229 1230
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);

L
Linus Torvalds 已提交
1231
		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1232

L
Linus Torvalds 已提交
1233
		//BLOWFISH
1234 1235 1236 1237 1238 1239 1240 1241
		test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
			    BF_ENC_TEST_VECTORS);
		test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
			    BF_DEC_TEST_VECTORS);
		test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
			    BF_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
			    BF_CBC_DEC_TEST_VECTORS);
1242

L
Linus Torvalds 已提交
1243
		//TWOFISH
1244 1245 1246 1247 1248 1249 1250 1251
		test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
			    TF_ENC_TEST_VECTORS);
		test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
			    TF_DEC_TEST_VECTORS);
		test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
			    TF_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
			    TF_CBC_DEC_TEST_VECTORS);
1252

L
Linus Torvalds 已提交
1253
		//SERPENT
1254 1255 1256 1257
		test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
			    SERPENT_ENC_TEST_VECTORS);
		test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
			    SERPENT_DEC_TEST_VECTORS);
1258

L
Linus Torvalds 已提交
1259
		//TNEPRES
1260 1261 1262 1263
		test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
			    TNEPRES_ENC_TEST_VECTORS);
		test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
			    TNEPRES_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1264 1265

		//AES
1266 1267 1268 1269 1270 1271 1272 1273
		test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
			    AES_ENC_TEST_VECTORS);
		test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
			    AES_DEC_TEST_VECTORS);
		test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
			    AES_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
			    AES_CBC_DEC_TEST_VECTORS);
R
Rik Snel 已提交
1274 1275 1276 1277
		test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
			    AES_LRW_ENC_TEST_VECTORS);
		test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
			    AES_LRW_DEC_TEST_VECTORS);
1278 1279 1280 1281
		test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
			    AES_XTS_ENC_TEST_VECTORS);
		test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
			    AES_XTS_DEC_TEST_VECTORS);
1282
		test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1283
			    AES_CTR_ENC_TEST_VECTORS);
1284
		test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1285
			    AES_CTR_DEC_TEST_VECTORS);
M
Mikko Herranen 已提交
1286 1287 1288 1289
		test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
			  AES_GCM_ENC_TEST_VECTORS);
		test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
			  AES_GCM_DEC_TEST_VECTORS);
J
Joy Latten 已提交
1290 1291 1292 1293
		test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
			  AES_CCM_ENC_TEST_VECTORS);
		test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
			  AES_CCM_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1294 1295

		//CAST5
1296 1297 1298 1299
		test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
			    CAST5_ENC_TEST_VECTORS);
		test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
			    CAST5_DEC_TEST_VECTORS);
1300

L
Linus Torvalds 已提交
1301
		//CAST6
1302 1303 1304 1305
		test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
			    CAST6_ENC_TEST_VECTORS);
		test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
			    CAST6_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1306 1307

		//ARC4
1308 1309 1310 1311
		test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
			    ARC4_ENC_TEST_VECTORS);
		test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
			    ARC4_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1312 1313

		//TEA
1314 1315 1316 1317
		test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
			    TEA_ENC_TEST_VECTORS);
		test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
			    TEA_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1318 1319 1320


		//XTEA
1321 1322 1323 1324
		test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
			    XTEA_ENC_TEST_VECTORS);
		test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
			    XTEA_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1325 1326

		//KHAZAD
1327 1328 1329 1330
		test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
			    KHAZAD_ENC_TEST_VECTORS);
		test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
			    KHAZAD_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1331 1332

		//ANUBIS
1333 1334 1335 1336 1337 1338 1339 1340
		test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
			    ANUBIS_ENC_TEST_VECTORS);
		test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
			    ANUBIS_DEC_TEST_VECTORS);
		test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
			    ANUBIS_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
			    ANUBIS_CBC_ENC_TEST_VECTORS);
L
Linus Torvalds 已提交
1341

A
Aaron Grothe 已提交
1342
		//XETA
1343 1344 1345 1346
		test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
			    XETA_ENC_TEST_VECTORS);
		test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
			    XETA_DEC_TEST_VECTORS);
A
Aaron Grothe 已提交
1347

1348 1349 1350 1351 1352 1353
		//FCrypt
		test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
			    FCRYPT_ENC_TEST_VECTORS);
		test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
			    FCRYPT_DEC_TEST_VECTORS);

1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367
		//CAMELLIA
		test_cipher("ecb(camellia)", ENCRYPT,
			    camellia_enc_tv_template,
			    CAMELLIA_ENC_TEST_VECTORS);
		test_cipher("ecb(camellia)", DECRYPT,
			    camellia_dec_tv_template,
			    CAMELLIA_DEC_TEST_VECTORS);
		test_cipher("cbc(camellia)", ENCRYPT,
			    camellia_cbc_enc_tv_template,
			    CAMELLIA_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(camellia)", DECRYPT,
			    camellia_cbc_dec_tv_template,
			    CAMELLIA_CBC_DEC_TEST_VECTORS);

1368 1369 1370 1371 1372 1373
		//SEED
		test_cipher("ecb(seed)", ENCRYPT, seed_enc_tv_template,
			    SEED_ENC_TEST_VECTORS);
		test_cipher("ecb(seed)", DECRYPT, seed_dec_tv_template,
			    SEED_DEC_TEST_VECTORS);

1374 1375 1376 1377 1378 1379
		//CTS
		test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
			    CTS_MODE_ENC_TEST_VECTORS);
		test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
			    CTS_MODE_DEC_TEST_VECTORS);

L
Linus Torvalds 已提交
1380 1381 1382 1383 1384 1385 1386 1387
		test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
		test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
		test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
		test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
		test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
		test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
		test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
1388 1389 1390
		test_comp("deflate", deflate_comp_tv_template,
			  deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
			  DEFLATE_DECOMP_TEST_VECTORS);
1391 1392
		test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
			  LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1393
		test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1394 1395 1396 1397
		test_hash("hmac(md5)", hmac_md5_tv_template,
			  HMAC_MD5_TEST_VECTORS);
		test_hash("hmac(sha1)", hmac_sha1_tv_template,
			  HMAC_SHA1_TEST_VECTORS);
1398 1399
		test_hash("hmac(sha224)", hmac_sha224_tv_template,
			  HMAC_SHA224_TEST_VECTORS);
1400 1401
		test_hash("hmac(sha256)", hmac_sha256_tv_template,
			  HMAC_SHA256_TEST_VECTORS);
1402 1403 1404 1405
		test_hash("hmac(sha384)", hmac_sha384_tv_template,
			  HMAC_SHA384_TEST_VECTORS);
		test_hash("hmac(sha512)", hmac_sha512_tv_template,
			  HMAC_SHA512_TEST_VECTORS);
L
Linus Torvalds 已提交
1406

1407 1408 1409
		test_hash("xcbc(aes)", aes_xcbc128_tv_template,
			  XCBC_AES_TEST_VECTORS);

L
Linus Torvalds 已提交
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
		test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
		break;

	case 1:
		test_hash("md5", md5_tv_template, MD5_TEST_VECTORS);
		break;

	case 2:
		test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
		break;

	case 3:
1422 1423 1424 1425 1426 1427 1428 1429
		test_cipher("ecb(des)", ENCRYPT, des_enc_tv_template,
			    DES_ENC_TEST_VECTORS);
		test_cipher("ecb(des)", DECRYPT, des_dec_tv_template,
			    DES_DEC_TEST_VECTORS);
		test_cipher("cbc(des)", ENCRYPT, des_cbc_enc_tv_template,
			    DES_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(des)", DECRYPT, des_cbc_dec_tv_template,
			    DES_CBC_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1430 1431 1432
		break;

	case 4:
1433 1434 1435 1436
		test_cipher("ecb(des3_ede)", ENCRYPT, des3_ede_enc_tv_template,
			    DES3_EDE_ENC_TEST_VECTORS);
		test_cipher("ecb(des3_ede)", DECRYPT, des3_ede_dec_tv_template,
			    DES3_EDE_DEC_TEST_VECTORS);
1437 1438 1439 1440 1441 1442 1443 1444

		test_cipher("cbc(des3_ede)", ENCRYPT,
			    des3_ede_cbc_enc_tv_template,
			    DES3_EDE_CBC_ENC_TEST_VECTORS);

		test_cipher("cbc(des3_ede)", DECRYPT,
			    des3_ede_cbc_dec_tv_template,
			    DES3_EDE_CBC_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1445 1446 1447 1448 1449
		break;

	case 5:
		test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
		break;
1450

L
Linus Torvalds 已提交
1451 1452 1453
	case 6:
		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
		break;
1454

L
Linus Torvalds 已提交
1455
	case 7:
1456 1457 1458 1459 1460 1461 1462 1463
		test_cipher("ecb(blowfish)", ENCRYPT, bf_enc_tv_template,
			    BF_ENC_TEST_VECTORS);
		test_cipher("ecb(blowfish)", DECRYPT, bf_dec_tv_template,
			    BF_DEC_TEST_VECTORS);
		test_cipher("cbc(blowfish)", ENCRYPT, bf_cbc_enc_tv_template,
			    BF_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(blowfish)", DECRYPT, bf_cbc_dec_tv_template,
			    BF_CBC_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1464 1465 1466
		break;

	case 8:
1467 1468 1469 1470 1471 1472 1473 1474
		test_cipher("ecb(twofish)", ENCRYPT, tf_enc_tv_template,
			    TF_ENC_TEST_VECTORS);
		test_cipher("ecb(twofish)", DECRYPT, tf_dec_tv_template,
			    TF_DEC_TEST_VECTORS);
		test_cipher("cbc(twofish)", ENCRYPT, tf_cbc_enc_tv_template,
			    TF_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(twofish)", DECRYPT, tf_cbc_dec_tv_template,
			    TF_CBC_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1475
		break;
1476

L
Linus Torvalds 已提交
1477
	case 9:
1478 1479 1480 1481
		test_cipher("ecb(serpent)", ENCRYPT, serpent_enc_tv_template,
			    SERPENT_ENC_TEST_VECTORS);
		test_cipher("ecb(serpent)", DECRYPT, serpent_dec_tv_template,
			    SERPENT_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1482 1483 1484
		break;

	case 10:
1485 1486 1487 1488 1489 1490 1491 1492
		test_cipher("ecb(aes)", ENCRYPT, aes_enc_tv_template,
			    AES_ENC_TEST_VECTORS);
		test_cipher("ecb(aes)", DECRYPT, aes_dec_tv_template,
			    AES_DEC_TEST_VECTORS);
		test_cipher("cbc(aes)", ENCRYPT, aes_cbc_enc_tv_template,
			    AES_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(aes)", DECRYPT, aes_cbc_dec_tv_template,
			    AES_CBC_DEC_TEST_VECTORS);
R
Rik Snel 已提交
1493 1494 1495 1496
		test_cipher("lrw(aes)", ENCRYPT, aes_lrw_enc_tv_template,
			    AES_LRW_ENC_TEST_VECTORS);
		test_cipher("lrw(aes)", DECRYPT, aes_lrw_dec_tv_template,
			    AES_LRW_DEC_TEST_VECTORS);
1497 1498 1499 1500
		test_cipher("xts(aes)", ENCRYPT, aes_xts_enc_tv_template,
			    AES_XTS_ENC_TEST_VECTORS);
		test_cipher("xts(aes)", DECRYPT, aes_xts_dec_tv_template,
			    AES_XTS_DEC_TEST_VECTORS);
1501
		test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1502
			    AES_CTR_ENC_TEST_VECTORS);
1503
		test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1504
			    AES_CTR_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1505 1506 1507 1508 1509
		break;

	case 11:
		test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS);
		break;
1510

L
Linus Torvalds 已提交
1511 1512 1513 1514 1515
	case 12:
		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
		break;

	case 13:
1516 1517 1518
		test_comp("deflate", deflate_comp_tv_template,
			  deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
			  DEFLATE_DECOMP_TEST_VECTORS);
L
Linus Torvalds 已提交
1519 1520 1521
		break;

	case 14:
1522 1523 1524 1525
		test_cipher("ecb(cast5)", ENCRYPT, cast5_enc_tv_template,
			    CAST5_ENC_TEST_VECTORS);
		test_cipher("ecb(cast5)", DECRYPT, cast5_dec_tv_template,
			    CAST5_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1526 1527 1528
		break;

	case 15:
1529 1530 1531 1532
		test_cipher("ecb(cast6)", ENCRYPT, cast6_enc_tv_template,
			    CAST6_ENC_TEST_VECTORS);
		test_cipher("ecb(cast6)", DECRYPT, cast6_dec_tv_template,
			    CAST6_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1533 1534 1535
		break;

	case 16:
1536 1537 1538 1539
		test_cipher("ecb(arc4)", ENCRYPT, arc4_enc_tv_template,
			    ARC4_ENC_TEST_VECTORS);
		test_cipher("ecb(arc4)", DECRYPT, arc4_dec_tv_template,
			    ARC4_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1540 1541 1542 1543 1544 1545 1546
		break;

	case 17:
		test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS);
		break;

	case 18:
1547
		test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
L
Linus Torvalds 已提交
1548 1549 1550
		break;

	case 19:
1551 1552 1553 1554
		test_cipher("ecb(tea)", ENCRYPT, tea_enc_tv_template,
			    TEA_ENC_TEST_VECTORS);
		test_cipher("ecb(tea)", DECRYPT, tea_dec_tv_template,
			    TEA_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1555 1556 1557
		break;

	case 20:
1558 1559 1560 1561
		test_cipher("ecb(xtea)", ENCRYPT, xtea_enc_tv_template,
			    XTEA_ENC_TEST_VECTORS);
		test_cipher("ecb(xtea)", DECRYPT, xtea_dec_tv_template,
			    XTEA_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1562 1563 1564
		break;

	case 21:
1565 1566 1567 1568
		test_cipher("ecb(khazad)", ENCRYPT, khazad_enc_tv_template,
			    KHAZAD_ENC_TEST_VECTORS);
		test_cipher("ecb(khazad)", DECRYPT, khazad_dec_tv_template,
			    KHAZAD_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
		break;

	case 22:
		test_hash("wp512", wp512_tv_template, WP512_TEST_VECTORS);
		break;

	case 23:
		test_hash("wp384", wp384_tv_template, WP384_TEST_VECTORS);
		break;

	case 24:
		test_hash("wp256", wp256_tv_template, WP256_TEST_VECTORS);
		break;

	case 25:
1584 1585 1586 1587
		test_cipher("ecb(tnepres)", ENCRYPT, tnepres_enc_tv_template,
			    TNEPRES_ENC_TEST_VECTORS);
		test_cipher("ecb(tnepres)", DECRYPT, tnepres_dec_tv_template,
			    TNEPRES_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1588 1589 1590
		break;

	case 26:
1591 1592 1593 1594 1595 1596 1597 1598
		test_cipher("ecb(anubis)", ENCRYPT, anubis_enc_tv_template,
			    ANUBIS_ENC_TEST_VECTORS);
		test_cipher("ecb(anubis)", DECRYPT, anubis_dec_tv_template,
			    ANUBIS_DEC_TEST_VECTORS);
		test_cipher("cbc(anubis)", ENCRYPT, anubis_cbc_enc_tv_template,
			    ANUBIS_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(anubis)", DECRYPT, anubis_cbc_dec_tv_template,
			    ANUBIS_CBC_ENC_TEST_VECTORS);
L
Linus Torvalds 已提交
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612
		break;

	case 27:
		test_hash("tgr192", tgr192_tv_template, TGR192_TEST_VECTORS);
		break;

	case 28:

		test_hash("tgr160", tgr160_tv_template, TGR160_TEST_VECTORS);
		break;

	case 29:
		test_hash("tgr128", tgr128_tv_template, TGR128_TEST_VECTORS);
		break;
1613

A
Aaron Grothe 已提交
1614
	case 30:
1615 1616 1617 1618
		test_cipher("ecb(xeta)", ENCRYPT, xeta_enc_tv_template,
			    XETA_ENC_TEST_VECTORS);
		test_cipher("ecb(xeta)", DECRYPT, xeta_dec_tv_template,
			    XETA_DEC_TEST_VECTORS);
A
Aaron Grothe 已提交
1619
		break;
L
Linus Torvalds 已提交
1620

1621 1622 1623 1624 1625 1626 1627
	case 31:
		test_cipher("pcbc(fcrypt)", ENCRYPT, fcrypt_pcbc_enc_tv_template,
			    FCRYPT_ENC_TEST_VECTORS);
		test_cipher("pcbc(fcrypt)", DECRYPT, fcrypt_pcbc_dec_tv_template,
			    FCRYPT_DEC_TEST_VECTORS);
		break;

1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
	case 32:
		test_cipher("ecb(camellia)", ENCRYPT,
			    camellia_enc_tv_template,
			    CAMELLIA_ENC_TEST_VECTORS);
		test_cipher("ecb(camellia)", DECRYPT,
			    camellia_dec_tv_template,
			    CAMELLIA_DEC_TEST_VECTORS);
		test_cipher("cbc(camellia)", ENCRYPT,
			    camellia_cbc_enc_tv_template,
			    CAMELLIA_CBC_ENC_TEST_VECTORS);
		test_cipher("cbc(camellia)", DECRYPT,
			    camellia_cbc_dec_tv_template,
			    CAMELLIA_CBC_DEC_TEST_VECTORS);
		break;
1642 1643 1644
	case 33:
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
		break;
1645

1646 1647 1648 1649 1650 1651
	case 34:
		test_cipher("salsa20", ENCRYPT,
			    salsa20_stream_enc_tv_template,
			    SALSA20_STREAM_ENC_TEST_VECTORS);
		break;

1652 1653 1654 1655 1656 1657 1658
	case 35:
		test_aead("gcm(aes)", ENCRYPT, aes_gcm_enc_tv_template,
			  AES_GCM_ENC_TEST_VECTORS);
		test_aead("gcm(aes)", DECRYPT, aes_gcm_dec_tv_template,
			  AES_GCM_DEC_TEST_VECTORS);
		break;

1659 1660 1661 1662 1663
	case 36:
		test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
			  LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
		break;

J
Joy Latten 已提交
1664 1665 1666 1667 1668 1669 1670
	case 37:
		test_aead("ccm(aes)", ENCRYPT, aes_ccm_enc_tv_template,
			  AES_CCM_ENC_TEST_VECTORS);
		test_aead("ccm(aes)", DECRYPT, aes_ccm_dec_tv_template,
			  AES_CCM_DEC_TEST_VECTORS);
		break;

1671 1672 1673 1674 1675 1676 1677
	case 38:
		test_cipher("cts(cbc(aes))", ENCRYPT, cts_mode_enc_tv_template,
			    CTS_MODE_ENC_TEST_VECTORS);
		test_cipher("cts(cbc(aes))", DECRYPT, cts_mode_dec_tv_template,
			    CTS_MODE_DEC_TEST_VECTORS);
		break;

1678 1679 1680 1681 1682 1683 1684 1685
        case 39:
		test_hash("rmd128", rmd128_tv_template, RMD128_TEST_VECTORS);
		break;

        case 40:
		test_hash("rmd160", rmd160_tv_template, RMD160_TEST_VECTORS);
		break;

1686 1687 1688 1689 1690 1691 1692 1693
	case 41:
		test_hash("rmd256", rmd256_tv_template, RMD256_TEST_VECTORS);
		break;

	case 42:
		test_hash("rmd320", rmd320_tv_template, RMD320_TEST_VECTORS);
		break;

L
Linus Torvalds 已提交
1694
	case 100:
1695 1696
		test_hash("hmac(md5)", hmac_md5_tv_template,
			  HMAC_MD5_TEST_VECTORS);
L
Linus Torvalds 已提交
1697
		break;
1698

L
Linus Torvalds 已提交
1699
	case 101:
1700 1701
		test_hash("hmac(sha1)", hmac_sha1_tv_template,
			  HMAC_SHA1_TEST_VECTORS);
L
Linus Torvalds 已提交
1702
		break;
1703

L
Linus Torvalds 已提交
1704
	case 102:
1705 1706
		test_hash("hmac(sha256)", hmac_sha256_tv_template,
			  HMAC_SHA256_TEST_VECTORS);
L
Linus Torvalds 已提交
1707 1708
		break;

1709 1710 1711 1712 1713 1714 1715 1716 1717
	case 103:
		test_hash("hmac(sha384)", hmac_sha384_tv_template,
			  HMAC_SHA384_TEST_VECTORS);
		break;

	case 104:
		test_hash("hmac(sha512)", hmac_sha512_tv_template,
			  HMAC_SHA512_TEST_VECTORS);
		break;
1718

1719 1720 1721 1722
	case 105:
		test_hash("hmac(sha224)", hmac_sha224_tv_template,
			  HMAC_SHA224_TEST_VECTORS);
		break;
L
Linus Torvalds 已提交
1723

1724 1725 1726 1727 1728
	case 106:
		test_hash("xcbc(aes)", aes_xcbc128_tv_template,
			  XCBC_AES_TEST_VECTORS);
		break;

1729 1730 1731 1732 1733 1734 1735 1736 1737 1738
	case 107:
		test_hash("hmac(rmd128)", hmac_rmd128_tv_template,
			  HMAC_RMD128_TEST_VECTORS);
		break;

	case 108:
		test_hash("hmac(rmd160)", hmac_rmd160_tv_template,
			  HMAC_RMD160_TEST_VECTORS);
		break;

H
Harald Welte 已提交
1739
	case 200:
1740
		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1741
				speed_template_16_24_32);
1742
		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1743
				speed_template_16_24_32);
1744
		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1745
				speed_template_16_24_32);
1746
		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1747
				speed_template_16_24_32);
R
Rik Snel 已提交
1748
		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1749
				speed_template_32_40_48);
R
Rik Snel 已提交
1750
		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1751
				speed_template_32_40_48);
1752
		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1753
				speed_template_32_48_64);
1754
		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1755
				speed_template_32_48_64);
H
Harald Welte 已提交
1756 1757 1758
		break;

	case 201:
1759
		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1760 1761
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
1762
		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1763 1764
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
1765
		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1766 1767
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
1768
		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1769 1770
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
H
Harald Welte 已提交
1771 1772 1773
		break;

	case 202:
1774
		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1775
				speed_template_16_24_32);
1776
		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1777
				speed_template_16_24_32);
1778
		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1779
				speed_template_16_24_32);
1780
		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1781
				speed_template_16_24_32);
H
Harald Welte 已提交
1782 1783 1784
		break;

	case 203:
1785
		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1786
				  speed_template_8_32);
1787
		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1788
				  speed_template_8_32);
1789
		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1790
				  speed_template_8_32);
1791
		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1792
				  speed_template_8_32);
H
Harald Welte 已提交
1793 1794 1795
		break;

	case 204:
1796
		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1797
				  speed_template_8);
1798
		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1799
				  speed_template_8);
1800
		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1801
				  speed_template_8);
1802
		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1803
				  speed_template_8);
H
Harald Welte 已提交
1804 1805
		break;

1806 1807
	case 205:
		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1808
				speed_template_16_24_32);
1809
		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1810
				speed_template_16_24_32);
1811
		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1812
				speed_template_16_24_32);
1813
		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1814
				speed_template_16_24_32);
1815 1816
		break;

1817 1818
	case 206:
		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1819
				  speed_template_16_32);
1820 1821
		break;

1822 1823 1824 1825
	case 300:
		/* fall through */

	case 301:
1826
		test_hash_speed("md4", sec, generic_hash_speed_template);
1827 1828 1829
		if (mode > 300 && mode < 400) break;

	case 302:
1830
		test_hash_speed("md5", sec, generic_hash_speed_template);
1831 1832 1833
		if (mode > 300 && mode < 400) break;

	case 303:
1834
		test_hash_speed("sha1", sec, generic_hash_speed_template);
1835 1836 1837
		if (mode > 300 && mode < 400) break;

	case 304:
1838
		test_hash_speed("sha256", sec, generic_hash_speed_template);
1839 1840 1841
		if (mode > 300 && mode < 400) break;

	case 305:
1842
		test_hash_speed("sha384", sec, generic_hash_speed_template);
1843 1844 1845
		if (mode > 300 && mode < 400) break;

	case 306:
1846
		test_hash_speed("sha512", sec, generic_hash_speed_template);
1847 1848 1849
		if (mode > 300 && mode < 400) break;

	case 307:
1850
		test_hash_speed("wp256", sec, generic_hash_speed_template);
1851 1852 1853
		if (mode > 300 && mode < 400) break;

	case 308:
1854
		test_hash_speed("wp384", sec, generic_hash_speed_template);
1855 1856 1857
		if (mode > 300 && mode < 400) break;

	case 309:
1858
		test_hash_speed("wp512", sec, generic_hash_speed_template);
1859 1860 1861
		if (mode > 300 && mode < 400) break;

	case 310:
1862
		test_hash_speed("tgr128", sec, generic_hash_speed_template);
1863 1864 1865
		if (mode > 300 && mode < 400) break;

	case 311:
1866
		test_hash_speed("tgr160", sec, generic_hash_speed_template);
1867 1868 1869
		if (mode > 300 && mode < 400) break;

	case 312:
1870
		test_hash_speed("tgr192", sec, generic_hash_speed_template);
1871 1872
		if (mode > 300 && mode < 400) break;

1873 1874 1875 1876
	case 313:
		test_hash_speed("sha224", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1877 1878 1879 1880 1881 1882 1883 1884
	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;

1885 1886 1887 1888 1889 1890 1891 1892
	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;

1893 1894 1895
	case 399:
		break;

L
Linus Torvalds 已提交
1896 1897 1898
	case 1000:
		test_available();
		break;
1899

L
Linus Torvalds 已提交
1900 1901 1902 1903 1904 1905 1906
	default:
		/* useful for debugging */
		printk("not testing anything\n");
		break;
	}
}

1907
static int __init tcrypt_mod_init(void)
L
Linus Torvalds 已提交
1908
{
1909 1910
	int err = -ENOMEM;

L
Linus Torvalds 已提交
1911 1912
	tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
	if (tvmem == NULL)
1913
		return err;
L
Linus Torvalds 已提交
1914 1915

	xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1916 1917
	if (xbuf == NULL)
		goto err_free_tv;
L
Linus Torvalds 已提交
1918

1919 1920 1921
	axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
	if (axbuf == NULL)
		goto err_free_xbuf;
L
Linus Torvalds 已提交
1922

1923
	do_test();
1924 1925 1926 1927 1928 1929 1930

	/* We intentionaly return -EAGAIN to prevent keeping
	 * the module. It does all its work from init()
	 * and doesn't offer any runtime functionality 
	 * => we don't need it in the memory, do we?
	 *                                        -- mludvig
	 */
1931 1932 1933 1934 1935 1936 1937 1938 1939
	err = -EAGAIN;

	kfree(axbuf);
 err_free_xbuf:
	kfree(xbuf);
 err_free_tv:
	kfree(tvmem);

	return err;
L
Linus Torvalds 已提交
1940 1941 1942 1943 1944 1945
}

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

1948 1949
module_init(tcrypt_mod_init);
module_exit(tcrypt_mod_fini);
L
Linus Torvalds 已提交
1950 1951

module_param(mode, int, 0);
H
Harald Welte 已提交
1952
module_param(sec, uint, 0);
1953 1954
MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
		      "(defaults to zero which uses CPU cycles instead)");
L
Linus Torvalds 已提交
1955 1956 1957 1958

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