tcrypt.c 45.4 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
 * any later version.
 *
M
Mikko Herranen 已提交
16
 * 2007-11-13 Added GCM tests
17
 * 2007-11-13 Added AEAD support
18
 * 2007-11-06 Added SHA-224 and SHA-224-HMAC tests
19
 * 2006-12-07 Added SHA384 HMAC and SHA512 HMAC tests
H
Harald Welte 已提交
20 21 22
 * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>)
 * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt
 *
L
Linus Torvalds 已提交
23 24
 */

25
#include <linux/err.h>
L
Linus Torvalds 已提交
26 27 28 29
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mm.h>
#include <linux/slab.h>
30
#include <linux/scatterlist.h>
L
Linus Torvalds 已提交
31 32 33 34
#include <linux/string.h>
#include <linux/crypto.h>
#include <linux/highmem.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 41 42
#include "tcrypt.h"

/*
 * Need to kmalloc() memory for testing kmap().
 */
H
Harald Welte 已提交
43
#define TVMEMSIZE	16384
L
Linus Torvalds 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#define XBUFSIZE	32768

/*
 * Indexes into the xbuf to simulate cross-page access.
 */
#define IDX1		37
#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

64 65 66 67 68
struct tcrypt_result {
	struct completion completion;
	int err;
};

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

H
Harald Welte 已提交
71 72 73
/*
 * Used by test_cipher_speed()
 */
74
static unsigned int sec;
H
Harald Welte 已提交
75

L
Linus Torvalds 已提交
76 77
static int mode;
static char *xbuf;
78
static char *axbuf;
L
Linus Torvalds 已提交
79 80 81
static char *tvmem;

static char *check[] = {
82 83 84
	"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
	"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
	"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
85
	"arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
86
	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
87
	"camellia", "seed", "salsa20", "lzo", NULL
L
Linus Torvalds 已提交
88 89
};

90
static void hexdump(unsigned char *buf, unsigned int len)
L
Linus Torvalds 已提交
91
{
92 93 94
	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
			16, 1,
			buf, len, false);
L
Linus Torvalds 已提交
95 96
}

97 98 99 100 101 102 103 104 105 106 107
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);
}

108 109
static void test_hash(char *algo, struct hash_testvec *template,
		      unsigned int tcount)
L
Linus Torvalds 已提交
110
{
111 112 113
	unsigned int i, j, k, temp;
	struct scatterlist sg[8];
	char result[64];
114 115
	struct crypto_hash *tfm;
	struct hash_desc desc;
116 117
	struct hash_testvec *hash_tv;
	unsigned int tsize;
118
	int ret;
119 120 121 122

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

	tsize = sizeof(struct hash_testvec);
L
Linus Torvalds 已提交
123
	tsize *= tcount;
124

L
Linus Torvalds 已提交
125 126 127 128 129 130
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE);
		return;
	}

	memcpy(tvmem, template, tsize);
131
	hash_tv = (void *)tvmem;
132 133 134 135 136

	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
L
Linus Torvalds 已提交
137 138 139
		return;
	}

140 141 142
	desc.tfm = tfm;
	desc.flags = 0;

L
Linus Torvalds 已提交
143
	for (i = 0; i < tcount; i++) {
144 145
		printk("test %u:\n", i + 1);
		memset(result, 0, 64);
L
Linus Torvalds 已提交
146

147
		sg_init_one(&sg[0], hash_tv[i].plaintext, hash_tv[i].psize);
L
Linus Torvalds 已提交
148

149 150 151 152 153 154 155 156 157 158 159 160 161 162
		if (hash_tv[i].ksize) {
			ret = crypto_hash_setkey(tfm, hash_tv[i].key,
						 hash_tv[i].ksize);
			if (ret) {
				printk("setkey() failed ret=%d\n", ret);
				goto out;
			}
		}

		ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize, result);
		if (ret) {
			printk("digest () failed ret=%d\n", ret);
			goto out;
		}
L
Linus Torvalds 已提交
163

164
		hexdump(result, crypto_hash_digestsize(tfm));
L
Linus Torvalds 已提交
165
		printk("%s\n",
166
		       memcmp(result, hash_tv[i].digest,
167
			      crypto_hash_digestsize(tfm)) ?
168
		       "fail" : "pass");
L
Linus Torvalds 已提交
169 170
	}

171
	printk("testing %s across pages\n", algo);
L
Linus Torvalds 已提交
172 173

	/* setup the dummy buffer first */
174
	memset(xbuf, 0, XBUFSIZE);
L
Linus Torvalds 已提交
175 176 177 178 179

	j = 0;
	for (i = 0; i < tcount; i++) {
		if (hash_tv[i].np) {
			j++;
180 181
			printk("test %u:\n", j);
			memset(result, 0, 64);
L
Linus Torvalds 已提交
182 183

			temp = 0;
184
			sg_init_table(sg, hash_tv[i].np);
L
Linus Torvalds 已提交
185
			for (k = 0; k < hash_tv[i].np; k++) {
186 187 188
				memcpy(&xbuf[IDX[k]],
				       hash_tv[i].plaintext + temp,
				       hash_tv[i].tap[k]);
L
Linus Torvalds 已提交
189
				temp += hash_tv[i].tap[k];
190 191
				sg_set_buf(&sg[k], &xbuf[IDX[k]],
					    hash_tv[i].tap[k]);
L
Linus Torvalds 已提交
192 193
			}

194 195 196
			if (hash_tv[i].ksize) {
				ret = crypto_hash_setkey(tfm, hash_tv[i].key,
							 hash_tv[i].ksize);
197

198 199 200 201
				if (ret) {
					printk("setkey() failed ret=%d\n", ret);
					goto out;
				}
L
Linus Torvalds 已提交
202 203
			}

204 205 206 207 208 209
			ret = crypto_hash_digest(&desc, sg, hash_tv[i].psize,
						 result);
			if (ret) {
				printk("digest () failed ret=%d\n", ret);
				goto out;
			}
210

211
			hexdump(result, crypto_hash_digestsize(tfm));
L
Linus Torvalds 已提交
212
			printk("%s\n",
213 214
			       memcmp(result, hash_tv[i].digest,
				      crypto_hash_digestsize(tfm)) ?
215
			       "fail" : "pass");
L
Linus Torvalds 已提交
216 217
		}
	}
218

L
Linus Torvalds 已提交
219
out:
220
	crypto_free_hash(tfm);
L
Linus Torvalds 已提交
221 222
}

223 224 225 226 227 228 229 230 231 232 233 234 235 236
static void test_aead(char *algo, int enc, struct aead_testvec *template,
		      unsigned int tcount)
{
	unsigned int ret, i, j, k, temp;
	unsigned int tsize;
	char *q;
	struct crypto_aead *tfm;
	char *key;
	struct aead_testvec *aead_tv;
	struct aead_request *req;
	struct scatterlist sg[8];
	struct scatterlist asg[8];
	const char *e;
	struct tcrypt_result result;
H
Herbert Xu 已提交
237
	unsigned int authsize;
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297

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

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

	tsize = sizeof(struct aead_testvec);
	tsize *= tcount;

	if (tsize > TVMEMSIZE) {
		printk(KERN_INFO "template (%u) too big for tvmem (%u)\n",
		       tsize, TVMEMSIZE);
		return;
	}

	memcpy(tvmem, template, tsize);
	aead_tv = (void *)tvmem;

	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++) {
		if (!aead_tv[i].np) {
			printk(KERN_INFO "test %u (%d bit key):\n",
			       ++j, aead_tv[i].klen * 8);

			crypto_aead_clear_flags(tfm, ~0);
			if (aead_tv[i].wk)
				crypto_aead_set_flags(
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
			key = aead_tv[i].key;

			ret = crypto_aead_setkey(tfm, key,
						 aead_tv[i].klen);
			if (ret) {
				printk(KERN_INFO "setkey() failed flags=%x\n",
				       crypto_aead_get_flags(tfm));

				if (!aead_tv[i].fail)
					goto out;
			}

J
Joy Latten 已提交
298 299 300 301 302 303 304 305 306
			authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
			ret = crypto_aead_setauthsize(tfm, authsize);
			if (ret) {
				printk(KERN_INFO
				       "failed to set authsize = %u\n",
				       authsize);
				goto out;
			}

307
			sg_init_one(&sg[0], aead_tv[i].input,
H
Herbert Xu 已提交
308
				    aead_tv[i].ilen + (enc ? authsize : 0));
309 310 311 312 313 314 315 316 317 318

			sg_init_one(&asg[0], aead_tv[i].assoc,
				    aead_tv[i].alen);

			aead_request_set_crypt(req, sg, sg,
					       aead_tv[i].ilen,
					       aead_tv[i].iv);

			aead_request_set_assoc(req, asg, aead_tv[i].alen);

H
Herbert Xu 已提交
319 320 321
			ret = enc ?
				crypto_aead_encrypt(req) :
				crypto_aead_decrypt(req);
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351

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

			q = kmap(sg_page(&sg[0])) + sg[0].offset;
			hexdump(q, aead_tv[i].rlen);

			printk(KERN_INFO "enc/dec: %s\n",
			       memcmp(q, aead_tv[i].result,
				      aead_tv[i].rlen) ? "fail" : "pass");
		}
	}

	printk(KERN_INFO "\ntesting %s %s across pages (chunking)\n", algo, e);
	memset(xbuf, 0, XBUFSIZE);
352
	memset(axbuf, 0, XBUFSIZE);
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

	for (i = 0, j = 0; i < tcount; i++) {
		if (aead_tv[i].np) {
			printk(KERN_INFO "test %u (%d bit key):\n",
			       ++j, aead_tv[i].klen * 8);

			crypto_aead_clear_flags(tfm, ~0);
			if (aead_tv[i].wk)
				crypto_aead_set_flags(
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
			key = aead_tv[i].key;

			ret = crypto_aead_setkey(tfm, key, aead_tv[i].klen);
			if (ret) {
				printk(KERN_INFO "setkey() failed flags=%x\n",
				       crypto_aead_get_flags(tfm));

				if (!aead_tv[i].fail)
					goto out;
			}

			sg_init_table(sg, aead_tv[i].np);
			for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
				memcpy(&xbuf[IDX[k]],
				       aead_tv[i].input + temp,
				       aead_tv[i].tap[k]);
				temp += aead_tv[i].tap[k];
				sg_set_buf(&sg[k], &xbuf[IDX[k]],
					   aead_tv[i].tap[k]);
			}

J
Joy Latten 已提交
384 385 386 387 388 389 390 391 392
			authsize = abs(aead_tv[i].rlen - aead_tv[i].ilen);
			ret = crypto_aead_setauthsize(tfm, authsize);
			if (ret) {
				printk(KERN_INFO
				       "failed to set authsize = %u\n",
				       authsize);
				goto out;
			}

H
Herbert Xu 已提交
393 394 395
			if (enc)
				sg[k - 1].length += authsize;

396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
			sg_init_table(asg, aead_tv[i].anp);
			for (k = 0, temp = 0; k < aead_tv[i].anp; k++) {
				memcpy(&axbuf[IDX[k]],
				       aead_tv[i].assoc + temp,
				       aead_tv[i].atap[k]);
				temp += aead_tv[i].atap[k];
				sg_set_buf(&asg[k], &axbuf[IDX[k]],
					   aead_tv[i].atap[k]);
			}

			aead_request_set_crypt(req, sg, sg,
					       aead_tv[i].ilen,
					       aead_tv[i].iv);

			aead_request_set_assoc(req, asg, aead_tv[i].alen);

H
Herbert Xu 已提交
412 413 414
			ret = enc ?
				crypto_aead_encrypt(req) :
				crypto_aead_decrypt(req);
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

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

			for (k = 0, temp = 0; k < aead_tv[i].np; k++) {
				printk(KERN_INFO "page %u\n", k);
				q = kmap(sg_page(&sg[k])) + sg[k].offset;
				hexdump(q, aead_tv[i].tap[k]);
				printk(KERN_INFO "%s\n",
				       memcmp(q, aead_tv[i].result + temp,
H
Herbert Xu 已提交
440 441 442
					      aead_tv[i].tap[k] -
					      (k < aead_tv[i].np - 1 || enc ?
					       0 : authsize)) ?
443 444 445 446 447 448 449 450 451 452 453 454
				       "fail" : "pass");

				temp += aead_tv[i].tap[k];
			}
		}
	}

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

455
static void test_cipher(char *algo, int enc,
456
			struct cipher_testvec *template, unsigned int tcount)
L
Linus Torvalds 已提交
457 458 459
{
	unsigned int ret, i, j, k, temp;
	unsigned int tsize;
460
	char *q;
461
	struct crypto_ablkcipher *tfm;
L
Linus Torvalds 已提交
462 463
	char *key;
	struct cipher_testvec *cipher_tv;
464
	struct ablkcipher_request *req;
L
Linus Torvalds 已提交
465
	struct scatterlist sg[8];
466
	const char *e;
467
	struct tcrypt_result result;
L
Linus Torvalds 已提交
468 469

	if (enc == ENCRYPT)
470
	        e = "encryption";
L
Linus Torvalds 已提交
471
	else
472
		e = "decryption";
L
Linus Torvalds 已提交
473

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

476
	tsize = sizeof (struct cipher_testvec);
L
Linus Torvalds 已提交
477 478 479 480 481
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize,
		       TVMEMSIZE);
		return;
	}
482 483
	cipher_tv = (void *)tvmem;

484 485 486
	init_completion(&result.completion);

	tfm = crypto_alloc_ablkcipher(algo, 0, 0);
L
Linus Torvalds 已提交
487

488 489 490
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
L
Linus Torvalds 已提交
491 492
		return;
	}
493 494 495 496 497 498 499 500 501

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

L
Linus Torvalds 已提交
503 504
	j = 0;
	for (i = 0; i < tcount; i++) {
505 506
		memcpy(cipher_tv, &template[i], tsize);
		if (!(cipher_tv->np)) {
507
			j++;
L
Linus Torvalds 已提交
508
			printk("test %u (%d bit key):\n",
509
			j, cipher_tv->klen * 8);
L
Linus Torvalds 已提交
510

511
			crypto_ablkcipher_clear_flags(tfm, ~0);
512
			if (cipher_tv->wk)
513
				crypto_ablkcipher_set_flags(
514
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
515
			key = cipher_tv->key;
516

517
			ret = crypto_ablkcipher_setkey(tfm, key,
518
						       cipher_tv->klen);
L
Linus Torvalds 已提交
519
			if (ret) {
520
				printk("setkey() failed flags=%x\n",
521
				       crypto_ablkcipher_get_flags(tfm));
522

523
				if (!cipher_tv->fail)
L
Linus Torvalds 已提交
524
					goto out;
525
			}
L
Linus Torvalds 已提交
526

527 528
			sg_init_one(&sg[0], cipher_tv->input,
				    cipher_tv->ilen);
529

530
			ablkcipher_request_set_crypt(req, sg, sg,
531 532
						     cipher_tv->ilen,
						     cipher_tv->iv);
533

534
			ret = enc ?
535 536
				crypto_ablkcipher_encrypt(req) :
				crypto_ablkcipher_decrypt(req);
537

538 539 540 541 542 543 544 545 546 547 548 549 550 551
			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 已提交
552
				goto out;
553 554
			}

J
Jens Axboe 已提交
555
			q = kmap(sg_page(&sg[0])) + sg[0].offset;
556
			hexdump(q, cipher_tv->rlen);
557 558

			printk("%s\n",
559 560
			       memcmp(q, cipher_tv->result,
				      cipher_tv->rlen) ? "fail" : "pass");
L
Linus Torvalds 已提交
561 562
		}
	}
563

564
	printk("\ntesting %s %s across pages (chunking)\n", algo, e);
L
Linus Torvalds 已提交
565
	memset(xbuf, 0, XBUFSIZE);
566

L
Linus Torvalds 已提交
567 568
	j = 0;
	for (i = 0; i < tcount; i++) {
569 570
		memcpy(cipher_tv, &template[i], tsize);
		if (cipher_tv->np) {
571
			j++;
L
Linus Torvalds 已提交
572
			printk("test %u (%d bit key):\n",
573
			j, cipher_tv->klen * 8);
L
Linus Torvalds 已提交
574

575
			crypto_ablkcipher_clear_flags(tfm, ~0);
576
			if (cipher_tv->wk)
577
				crypto_ablkcipher_set_flags(
578
					tfm, CRYPTO_TFM_REQ_WEAK_KEY);
579
			key = cipher_tv->key;
580

581
			ret = crypto_ablkcipher_setkey(tfm, key,
582
						       cipher_tv->klen);
L
Linus Torvalds 已提交
583
			if (ret) {
584
				printk("setkey() failed flags=%x\n",
585
				       crypto_ablkcipher_get_flags(tfm));
586

587
				if (!cipher_tv->fail)
L
Linus Torvalds 已提交
588 589 590 591
					goto out;
			}

			temp = 0;
592 593
			sg_init_table(sg, cipher_tv->np);
			for (k = 0; k < cipher_tv->np; k++) {
594
				memcpy(&xbuf[IDX[k]],
595 596 597
				       cipher_tv->input + temp,
				       cipher_tv->tap[k]);
				temp += cipher_tv->tap[k];
598
				sg_set_buf(&sg[k], &xbuf[IDX[k]],
599
					   cipher_tv->tap[k]);
L
Linus Torvalds 已提交
600
			}
601

602
			ablkcipher_request_set_crypt(req, sg, sg,
603 604
						     cipher_tv->ilen,
						     cipher_tv->iv);
605

606
			ret = enc ?
607 608
				crypto_ablkcipher_encrypt(req) :
				crypto_ablkcipher_decrypt(req);
609

610 611 612 613 614 615 616 617 618 619 620 621 622 623
			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 已提交
624 625 626 627
				goto out;
			}

			temp = 0;
628
			for (k = 0; k < cipher_tv->np; k++) {
L
Linus Torvalds 已提交
629
				printk("page %u\n", k);
J
Jens Axboe 已提交
630
				q = kmap(sg_page(&sg[k])) + sg[k].offset;
631
				hexdump(q, cipher_tv->tap[k]);
632
				printk("%s\n",
633 634
					memcmp(q, cipher_tv->result + temp,
						cipher_tv->tap[k]) ? "fail" :
L
Linus Torvalds 已提交
635
					"pass");
636
				temp += cipher_tv->tap[k];
L
Linus Torvalds 已提交
637 638 639 640 641
			}
		}
	}

out:
642 643
	crypto_free_ablkcipher(tfm);
	ablkcipher_request_free(req);
L
Linus Torvalds 已提交
644 645
}

646
static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, char *p,
647 648
			       int blen, int sec)
{
649
	struct scatterlist sg[1];
650 651 652 653
	unsigned long start, end;
	int bcount;
	int ret;

654
	sg_init_one(sg, p, blen);
655 656 657 658

	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
		if (enc)
659
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
660
		else
661
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
662 663 664 665 666 667 668 669 670 671

		if (ret)
			return ret;
	}

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

672
static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, char *p,
673 674
			      int blen)
{
675
	struct scatterlist sg[1];
676 677 678 679
	unsigned long cycles = 0;
	int ret = 0;
	int i;

680
	sg_init_one(sg, p, blen);
681 682 683 684 685 686 687

	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
		if (enc)
688
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
689
		else
690
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
691 692 693 694 695 696 697 698 699 700 701

		if (ret)
			goto out;
	}

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

		start = get_cycles();
		if (enc)
702
			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
703
		else
704
			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723
		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;
}

724
static void test_cipher_speed(char *algo, int enc, unsigned int sec,
725 726
			      struct cipher_testvec *template,
			      unsigned int tcount, struct cipher_speed *speed)
H
Harald Welte 已提交
727
{
728
	unsigned int ret, i, j, iv_len;
H
Harald Welte 已提交
729
	unsigned char *key, *p, iv[128];
730 731 732
	struct crypto_blkcipher *tfm;
	struct blkcipher_desc desc;
	const char *e;
H
Harald Welte 已提交
733 734 735 736 737 738

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

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

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

743 744 745
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
H
Harald Welte 已提交
746 747
		return;
	}
748 749
	desc.tfm = tfm;
	desc.flags = 0;
H
Harald Welte 已提交
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764

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

		printk("test %u (%d bit key, %d byte blocks): ", i,
		       speed[i].klen * 8, speed[i].blen);

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

		/* set key, plain text and IV */
		key = (unsigned char *)tvmem;
765 766 767 768 769 770
		for (j = 0; j < tcount; j++) {
			if (template[j].klen == speed[i].klen) {
				key = template[j].key;
				break;
			}
		}
H
Harald Welte 已提交
771 772
		p = (unsigned char *)tvmem + speed[i].klen;

773
		ret = crypto_blkcipher_setkey(tfm, key, speed[i].klen);
H
Harald Welte 已提交
774
		if (ret) {
775 776
			printk("setkey() failed flags=%x\n",
			       crypto_blkcipher_get_flags(tfm));
H
Harald Welte 已提交
777 778 779
			goto out;
		}

780 781
		iv_len = crypto_blkcipher_ivsize(tfm);
		if (iv_len) {
H
Harald Welte 已提交
782
			memset(&iv, 0xff, iv_len);
783
			crypto_blkcipher_set_iv(tfm, iv, iv_len);
H
Harald Welte 已提交
784 785
		}

786
		if (sec)
787
			ret = test_cipher_jiffies(&desc, enc, p, speed[i].blen,
788 789
						  sec);
		else
790
			ret = test_cipher_cycles(&desc, enc, p, speed[i].blen);
H
Harald Welte 已提交
791

792
		if (ret) {
793
			printk("%s() failed flags=%x\n", e, desc.flags);
794
			break;
H
Harald Welte 已提交
795 796 797 798
		}
	}

out:
799
	crypto_free_blkcipher(tfm);
H
Harald Welte 已提交
800 801
}

802 803 804 805 806 807 808 809
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;

810 811
	sg_init_table(sg, 1);

812 813
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
814
		sg_set_buf(sg, p, blen);
815 816 817 818 819 820 821 822 823 824 825 826 827
		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)
828 829 830 831
{
	struct scatterlist sg[1];
	unsigned long start, end;
	int bcount, pcount;
832 833 834 835
	int ret;

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

837 838
	sg_init_table(sg, 1);

839 840
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
841 842 843
		ret = crypto_hash_init(desc);
		if (ret)
			return ret;
844
		for (pcount = 0; pcount < blen; pcount += plen) {
845
			sg_set_buf(sg, p + pcount, plen);
846 847 848
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				return ret;
849 850
		}
		/* we assume there is enough space in 'out' for the result */
851 852 853
		ret = crypto_hash_final(desc, out);
		if (ret)
			return ret;
854 855 856 857 858
	}

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

859 860 861 862 863 864 865 866 867 868 869
	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;

870 871
	sg_init_table(sg, 1);

872 873 874 875 876
	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
877
		sg_set_buf(sg, p, blen);
878 879 880 881 882 883 884 885 886 887 888
		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();

889
		sg_set_buf(sg, p, blen);
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
		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;
910 911
}

912 913
static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
			    int plen, char *out)
914 915 916 917
{
	struct scatterlist sg[1];
	unsigned long cycles = 0;
	int i, pcount;
918 919 920 921
	int ret;

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

923 924
	sg_init_table(sg, 1);

925 926 927 928 929
	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
930 931 932
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
933
		for (pcount = 0; pcount < blen; pcount += plen) {
934
			sg_set_buf(sg, p + pcount, plen);
935 936 937
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
938
		}
939
		ret = crypto_hash_final(desc, out);
940 941
		if (ret)
			goto out;
942 943 944 945 946 947 948 949
	}

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

		start = get_cycles();

950 951 952
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
953
		for (pcount = 0; pcount < blen; pcount += plen) {
954
			sg_set_buf(sg, p + pcount, plen);
955 956 957
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
958
		}
959 960 961
		ret = crypto_hash_final(desc, out);
		if (ret)
			goto out;
962 963 964 965 966 967

		end = get_cycles();

		cycles += end - start;
	}

968
out:
969 970 971
	local_irq_enable();
	local_bh_enable();

972 973 974
	if (ret)
		return ret;

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

978
	return 0;
979 980
}

981 982
static void test_hash_speed(char *algo, unsigned int sec,
			      struct hash_speed *speed)
983
{
984 985
	struct crypto_hash *tfm;
	struct hash_desc desc;
986 987
	char output[1024];
	int i;
988
	int ret;
989 990 991

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

992
	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
993

994 995 996
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
997 998 999
		return;
	}

1000 1001 1002 1003
	desc.tfm = tfm;
	desc.flags = 0;

	if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1004
		printk("digestsize(%u) > outputbuffer(%zu)\n",
1005
		       crypto_hash_digestsize(tfm), sizeof(output));
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
		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)
1022 1023
			ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
						speed[i].plen, output, sec);
1024
		else
1025 1026 1027 1028 1029 1030 1031
			ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
					       speed[i].plen, output);

		if (ret) {
			printk("hashing failed ret=%d\n", ret);
			break;
		}
1032 1033 1034
	}

out:
1035
	crypto_free_hash(tfm);
1036 1037
}

1038 1039
static void test_comp(char *algo, struct comp_testvec *ctemplate,
		       struct comp_testvec *dtemplate, int ctcount, int dtcount)
L
Linus Torvalds 已提交
1040 1041 1042
{
	unsigned int i;
	char result[COMP_BUF_SIZE];
1043
	struct crypto_comp *tfm;
L
Linus Torvalds 已提交
1044 1045 1046
	struct comp_testvec *tv;
	unsigned int tsize;

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

1049 1050
	tsize = sizeof(struct comp_testvec);
	tsize *= ctcount;
L
Linus Torvalds 已提交
1051 1052 1053 1054 1055 1056
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize,
		       TVMEMSIZE);
		return;
	}

1057
	memcpy(tvmem, ctemplate, tsize);
1058
	tv = (void *)tvmem;
L
Linus Torvalds 已提交
1059

1060
	tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1061
	if (IS_ERR(tfm)) {
1062
		printk("failed to load transform for %s\n", algo);
L
Linus Torvalds 已提交
1063 1064 1065
		return;
	}

1066
	for (i = 0; i < ctcount; i++) {
L
Linus Torvalds 已提交
1067
		int ilen, ret, dlen = COMP_BUF_SIZE;
1068

L
Linus Torvalds 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
		printk("test %u:\n", i + 1);
		memset(result, 0, sizeof (result));

		ilen = tv[i].inlen;
		ret = crypto_comp_compress(tfm, tv[i].input,
		                           ilen, result, &dlen);
		if (ret) {
			printk("fail: ret=%d\n", ret);
			continue;
		}
		hexdump(result, dlen);
		printk("%s (ratio %d:%d)\n",
		       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
		       ilen, dlen);
	}

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

1087 1088
	tsize = sizeof(struct comp_testvec);
	tsize *= dtcount;
L
Linus Torvalds 已提交
1089 1090 1091 1092 1093 1094
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize,
		       TVMEMSIZE);
		goto out;
	}

1095
	memcpy(tvmem, dtemplate, tsize);
1096
	tv = (void *)tvmem;
L
Linus Torvalds 已提交
1097

1098
	for (i = 0; i < dtcount; i++) {
L
Linus Torvalds 已提交
1099
		int ilen, ret, dlen = COMP_BUF_SIZE;
1100

L
Linus Torvalds 已提交
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
		printk("test %u:\n", i + 1);
		memset(result, 0, sizeof (result));

		ilen = tv[i].inlen;
		ret = crypto_comp_decompress(tfm, tv[i].input,
		                             ilen, result, &dlen);
		if (ret) {
			printk("fail: ret=%d\n", ret);
			continue;
		}
		hexdump(result, dlen);
		printk("%s (ratio %d:%d)\n",
		       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
		       ilen, dlen);
	}
out:
1117
	crypto_free_comp(tfm);
L
Linus Torvalds 已提交
1118 1119
}

1120
static void test_available(void)
L
Linus Torvalds 已提交
1121 1122
{
	char **name = check;
1123

L
Linus Torvalds 已提交
1124 1125
	while (*name) {
		printk("alg %s ", *name);
1126
		printk(crypto_has_alg(*name, 0, 0) ?
1127
		       "found\n" : "not found\n");
L
Linus Torvalds 已提交
1128
		name++;
1129
	}
L
Linus Torvalds 已提交
1130 1131
}

1132
static void do_test(void)
L
Linus Torvalds 已提交
1133 1134 1135 1136 1137
{
	switch (mode) {

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

L
Linus Torvalds 已提交
1139
		test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1140

L
Linus Torvalds 已提交
1141
		//DES
1142 1143 1144 1145 1146 1147 1148 1149
		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);
1150

L
Linus Torvalds 已提交
1151
		//DES3_EDE
1152 1153 1154 1155
		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);
1156

L
Linus Torvalds 已提交
1157
		test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1158

1159 1160
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);

L
Linus Torvalds 已提交
1161
		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1162

L
Linus Torvalds 已提交
1163
		//BLOWFISH
1164 1165 1166 1167 1168 1169 1170 1171
		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);
1172

L
Linus Torvalds 已提交
1173
		//TWOFISH
1174 1175 1176 1177 1178 1179 1180 1181
		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);
1182

L
Linus Torvalds 已提交
1183
		//SERPENT
1184 1185 1186 1187
		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);
1188

L
Linus Torvalds 已提交
1189
		//TNEPRES
1190 1191 1192 1193
		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 已提交
1194 1195

		//AES
1196 1197 1198 1199 1200 1201 1202 1203
		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 已提交
1204 1205 1206 1207
		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);
1208 1209 1210 1211
		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);
1212
		test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1213
			    AES_CTR_ENC_TEST_VECTORS);
1214
		test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1215
			    AES_CTR_DEC_TEST_VECTORS);
M
Mikko Herranen 已提交
1216 1217 1218 1219
		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 已提交
1220 1221 1222 1223
		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 已提交
1224 1225

		//CAST5
1226 1227 1228 1229
		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);
1230

L
Linus Torvalds 已提交
1231
		//CAST6
1232 1233 1234 1235
		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 已提交
1236 1237

		//ARC4
1238 1239 1240 1241
		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 已提交
1242 1243

		//TEA
1244 1245 1246 1247
		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 已提交
1248 1249 1250


		//XTEA
1251 1252 1253 1254
		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 已提交
1255 1256

		//KHAZAD
1257 1258 1259 1260
		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 已提交
1261 1262

		//ANUBIS
1263 1264 1265 1266 1267 1268 1269 1270
		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 已提交
1271

A
Aaron Grothe 已提交
1272
		//XETA
1273 1274 1275 1276
		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 已提交
1277

1278 1279 1280 1281 1282 1283
		//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);

1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
		//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);

1298 1299 1300 1301 1302 1303
		//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);

L
Linus Torvalds 已提交
1304 1305 1306 1307 1308 1309 1310 1311
		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);
1312 1313 1314
		test_comp("deflate", deflate_comp_tv_template,
			  deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
			  DEFLATE_DECOMP_TEST_VECTORS);
1315 1316
		test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
			  LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1317
		test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1318 1319 1320 1321
		test_hash("hmac(md5)", hmac_md5_tv_template,
			  HMAC_MD5_TEST_VECTORS);
		test_hash("hmac(sha1)", hmac_sha1_tv_template,
			  HMAC_SHA1_TEST_VECTORS);
1322 1323
		test_hash("hmac(sha224)", hmac_sha224_tv_template,
			  HMAC_SHA224_TEST_VECTORS);
1324 1325
		test_hash("hmac(sha256)", hmac_sha256_tv_template,
			  HMAC_SHA256_TEST_VECTORS);
1326 1327 1328 1329
		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 已提交
1330

1331 1332 1333
		test_hash("xcbc(aes)", aes_xcbc128_tv_template,
			  XCBC_AES_TEST_VECTORS);

L
Linus Torvalds 已提交
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345
		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:
1346 1347 1348 1349 1350 1351 1352 1353
		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 已提交
1354 1355 1356
		break;

	case 4:
1357 1358 1359 1360
		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);
L
Linus Torvalds 已提交
1361 1362 1363 1364 1365
		break;

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

L
Linus Torvalds 已提交
1367 1368 1369
	case 6:
		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
		break;
1370

L
Linus Torvalds 已提交
1371
	case 7:
1372 1373 1374 1375 1376 1377 1378 1379
		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 已提交
1380 1381 1382
		break;

	case 8:
1383 1384 1385 1386 1387 1388 1389 1390
		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 已提交
1391
		break;
1392

L
Linus Torvalds 已提交
1393
	case 9:
1394 1395 1396 1397
		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 已提交
1398 1399 1400
		break;

	case 10:
1401 1402 1403 1404 1405 1406 1407 1408
		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 已提交
1409 1410 1411 1412
		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);
1413 1414 1415 1416
		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);
1417
		test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1418
			    AES_CTR_ENC_TEST_VECTORS);
1419
		test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1420
			    AES_CTR_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1421 1422 1423 1424 1425
		break;

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

L
Linus Torvalds 已提交
1427 1428 1429 1430 1431
	case 12:
		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
		break;

	case 13:
1432 1433 1434
		test_comp("deflate", deflate_comp_tv_template,
			  deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
			  DEFLATE_DECOMP_TEST_VECTORS);
L
Linus Torvalds 已提交
1435 1436 1437
		break;

	case 14:
1438 1439 1440 1441
		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 已提交
1442 1443 1444
		break;

	case 15:
1445 1446 1447 1448
		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 已提交
1449 1450 1451
		break;

	case 16:
1452 1453 1454 1455
		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 已提交
1456 1457 1458 1459 1460 1461 1462
		break;

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

	case 18:
1463
		test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
L
Linus Torvalds 已提交
1464 1465 1466
		break;

	case 19:
1467 1468 1469 1470
		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 已提交
1471 1472 1473
		break;

	case 20:
1474 1475 1476 1477
		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 已提交
1478 1479 1480
		break;

	case 21:
1481 1482 1483 1484
		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 已提交
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
		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:
1500 1501 1502 1503
		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 已提交
1504 1505 1506
		break;

	case 26:
1507 1508 1509 1510 1511 1512 1513 1514
		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 已提交
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
		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;
A
Aaron Grothe 已提交
1529 1530
		
	case 30:
1531 1532 1533 1534
		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 已提交
1535
		break;
L
Linus Torvalds 已提交
1536

1537 1538 1539 1540 1541 1542 1543
	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;

1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557
	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;
1558 1559 1560
	case 33:
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
		break;
1561

1562 1563 1564 1565 1566 1567
	case 34:
		test_cipher("salsa20", ENCRYPT,
			    salsa20_stream_enc_tv_template,
			    SALSA20_STREAM_ENC_TEST_VECTORS);
		break;

1568 1569 1570 1571 1572 1573 1574
	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;

1575 1576 1577 1578 1579
	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 已提交
1580 1581 1582 1583 1584 1585 1586
	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;

L
Linus Torvalds 已提交
1587
	case 100:
1588 1589
		test_hash("hmac(md5)", hmac_md5_tv_template,
			  HMAC_MD5_TEST_VECTORS);
L
Linus Torvalds 已提交
1590
		break;
1591

L
Linus Torvalds 已提交
1592
	case 101:
1593 1594
		test_hash("hmac(sha1)", hmac_sha1_tv_template,
			  HMAC_SHA1_TEST_VECTORS);
L
Linus Torvalds 已提交
1595
		break;
1596

L
Linus Torvalds 已提交
1597
	case 102:
1598 1599
		test_hash("hmac(sha256)", hmac_sha256_tv_template,
			  HMAC_SHA256_TEST_VECTORS);
L
Linus Torvalds 已提交
1600 1601
		break;

1602 1603 1604 1605 1606 1607 1608 1609 1610
	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;
1611

1612 1613 1614 1615
	case 105:
		test_hash("hmac(sha224)", hmac_sha224_tv_template,
			  HMAC_SHA224_TEST_VECTORS);
		break;
L
Linus Torvalds 已提交
1616

1617 1618 1619 1620 1621
	case 106:
		test_hash("xcbc(aes)", aes_xcbc128_tv_template,
			  XCBC_AES_TEST_VECTORS);
		break;

H
Harald Welte 已提交
1622
	case 200:
1623
		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1624
				  aes_speed_template);
1625
		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1626
				  aes_speed_template);
1627
		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1628
				  aes_speed_template);
1629
		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1630
				  aes_speed_template);
R
Rik Snel 已提交
1631 1632 1633 1634
		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
				  aes_lrw_speed_template);
		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
				  aes_lrw_speed_template);
1635 1636 1637 1638
		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
				  aes_xts_speed_template);
		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
				  aes_xts_speed_template);
H
Harald Welte 已提交
1639 1640 1641
		break;

	case 201:
1642
		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1643 1644 1645
				  des3_ede_enc_tv_template,
				  DES3_EDE_ENC_TEST_VECTORS,
				  des3_ede_speed_template);
1646
		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1647 1648 1649
				  des3_ede_dec_tv_template,
				  DES3_EDE_DEC_TEST_VECTORS,
				  des3_ede_speed_template);
1650
		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1651 1652 1653
				  des3_ede_enc_tv_template,
				  DES3_EDE_ENC_TEST_VECTORS,
				  des3_ede_speed_template);
1654
		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1655 1656 1657
				  des3_ede_dec_tv_template,
				  DES3_EDE_DEC_TEST_VECTORS,
				  des3_ede_speed_template);
H
Harald Welte 已提交
1658 1659 1660
		break;

	case 202:
1661
		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1662
				  twofish_speed_template);
1663
		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1664
				  twofish_speed_template);
1665
		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1666
				  twofish_speed_template);
1667
		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1668
				  twofish_speed_template);
H
Harald Welte 已提交
1669 1670 1671
		break;

	case 203:
1672
		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1673
				  blowfish_speed_template);
1674
		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1675
				  blowfish_speed_template);
1676
		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1677
				  blowfish_speed_template);
1678
		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1679
				  blowfish_speed_template);
H
Harald Welte 已提交
1680 1681 1682
		break;

	case 204:
1683
		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1684
				  des_speed_template);
1685
		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1686
				  des_speed_template);
1687
		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1688
				  des_speed_template);
1689
		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1690
				  des_speed_template);
H
Harald Welte 已提交
1691 1692
		break;

1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
	case 205:
		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
				camellia_speed_template);
		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
				camellia_speed_template);
		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
				camellia_speed_template);
		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
				camellia_speed_template);
		break;

1704 1705 1706 1707 1708
	case 206:
		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
				  salsa20_speed_template);
		break;

1709 1710 1711 1712
	case 300:
		/* fall through */

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

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

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

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

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

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

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

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

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

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

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

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

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

1764 1765 1766
	case 399:
		break;

L
Linus Torvalds 已提交
1767 1768 1769
	case 1000:
		test_available();
		break;
1770

L
Linus Torvalds 已提交
1771 1772 1773 1774 1775 1776 1777
	default:
		/* useful for debugging */
		printk("not testing anything\n");
		break;
	}
}

1778
static int __init init(void)
L
Linus Torvalds 已提交
1779
{
1780 1781
	int err = -ENOMEM;

L
Linus Torvalds 已提交
1782 1783
	tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
	if (tvmem == NULL)
1784
		return err;
L
Linus Torvalds 已提交
1785 1786

	xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1787 1788
	if (xbuf == NULL)
		goto err_free_tv;
L
Linus Torvalds 已提交
1789

1790 1791 1792
	axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
	if (axbuf == NULL)
		goto err_free_xbuf;
L
Linus Torvalds 已提交
1793

1794
	do_test();
1795 1796 1797 1798 1799 1800 1801

	/* 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
	 */
1802 1803 1804 1805 1806 1807 1808 1809 1810
	err = -EAGAIN;

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

	return err;
L
Linus Torvalds 已提交
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822
}

/*
 * If an init function is provided, an exit function must also be provided
 * to allow module unload.
 */
static void __exit fini(void) { }

module_init(init);
module_exit(fini);

module_param(mode, int, 0);
H
Harald Welte 已提交
1823
module_param(sec, uint, 0);
1824 1825
MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
		      "(defaults to zero which uses CPU cycles instead)");
L
Linus Torvalds 已提交
1826 1827 1828 1829

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