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 725
static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };

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

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

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

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

746 747 748
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
H
Harald Welte 已提交
749 750
		return;
	}
751 752
	desc.tfm = tfm;
	desc.flags = 0;
H
Harald Welte 已提交
753

754 755
	i = 0;
	do {
H
Harald Welte 已提交
756

757 758
		b_size = block_sizes;
		do {
H
Harald Welte 已提交
759

760 761 762 763 764
			if ((*keysize + *b_size) > TVMEMSIZE) {
				printk("template (%u) too big for tvmem (%u)\n",
						*keysize + *b_size, TVMEMSIZE);
				goto out;
			}
H
Harald Welte 已提交
765

766 767 768 769 770 771 772 773 774 775 776 777
			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;
				}
778
			}
779
			p = (unsigned char *)tvmem + *keysize;
H
Harald Welte 已提交
780

781 782 783 784 785 786
			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 已提交
787

788 789 790 791 792
			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 已提交
793

794 795 796 797
			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 已提交
798

799 800 801 802 803 804 805 806 807
			if (ret) {
				printk("%s() failed flags=%x\n", e, desc.flags);
				break;
			}
			b_size++;
			i++;
		} while (*b_size);
		keysize++;
	} while (*keysize);
H
Harald Welte 已提交
808 809

out:
810
	crypto_free_blkcipher(tfm);
H
Harald Welte 已提交
811 812
}

813 814 815 816 817 818 819 820
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;

821 822
	sg_init_table(sg, 1);

823 824
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
825
		sg_set_buf(sg, p, blen);
826 827 828 829 830 831 832 833 834 835 836 837 838
		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)
839 840 841 842
{
	struct scatterlist sg[1];
	unsigned long start, end;
	int bcount, pcount;
843 844 845 846
	int ret;

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

848 849
	sg_init_table(sg, 1);

850 851
	for (start = jiffies, end = start + sec * HZ, bcount = 0;
	     time_before(jiffies, end); bcount++) {
852 853 854
		ret = crypto_hash_init(desc);
		if (ret)
			return ret;
855
		for (pcount = 0; pcount < blen; pcount += plen) {
856
			sg_set_buf(sg, p + pcount, plen);
857 858 859
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				return ret;
860 861
		}
		/* we assume there is enough space in 'out' for the result */
862 863 864
		ret = crypto_hash_final(desc, out);
		if (ret)
			return ret;
865 866 867 868 869
	}

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

870 871 872 873 874 875 876 877 878 879 880
	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;

881 882
	sg_init_table(sg, 1);

883 884 885 886 887
	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
888
		sg_set_buf(sg, p, blen);
889 890 891 892 893 894 895 896 897 898 899
		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();

900
		sg_set_buf(sg, p, blen);
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
		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;
921 922
}

923 924
static int test_hash_cycles(struct hash_desc *desc, char *p, int blen,
			    int plen, char *out)
925 926 927 928
{
	struct scatterlist sg[1];
	unsigned long cycles = 0;
	int i, pcount;
929 930 931 932
	int ret;

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

934 935
	sg_init_table(sg, 1);

936 937 938 939 940
	local_bh_disable();
	local_irq_disable();

	/* Warm-up run. */
	for (i = 0; i < 4; i++) {
941 942 943
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
944
		for (pcount = 0; pcount < blen; pcount += plen) {
945
			sg_set_buf(sg, p + pcount, plen);
946 947 948
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
949
		}
950
		ret = crypto_hash_final(desc, out);
951 952
		if (ret)
			goto out;
953 954 955 956 957 958 959 960
	}

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

		start = get_cycles();

961 962 963
		ret = crypto_hash_init(desc);
		if (ret)
			goto out;
964
		for (pcount = 0; pcount < blen; pcount += plen) {
965
			sg_set_buf(sg, p + pcount, plen);
966 967 968
			ret = crypto_hash_update(desc, sg, plen);
			if (ret)
				goto out;
969
		}
970 971 972
		ret = crypto_hash_final(desc, out);
		if (ret)
			goto out;
973 974 975 976 977 978

		end = get_cycles();

		cycles += end - start;
	}

979
out:
980 981 982
	local_irq_enable();
	local_bh_enable();

983 984 985
	if (ret)
		return ret;

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

989
	return 0;
990 991
}

992 993
static void test_hash_speed(char *algo, unsigned int sec,
			      struct hash_speed *speed)
994
{
995 996
	struct crypto_hash *tfm;
	struct hash_desc desc;
997 998
	char output[1024];
	int i;
999
	int ret;
1000 1001 1002

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

1003
	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
1004

1005 1006 1007
	if (IS_ERR(tfm)) {
		printk("failed to load transform for %s: %ld\n", algo,
		       PTR_ERR(tfm));
1008 1009 1010
		return;
	}

1011 1012 1013 1014
	desc.tfm = tfm;
	desc.flags = 0;

	if (crypto_hash_digestsize(tfm) > sizeof(output)) {
1015
		printk("digestsize(%u) > outputbuffer(%zu)\n",
1016
		       crypto_hash_digestsize(tfm), sizeof(output));
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
		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)
1033 1034
			ret = test_hash_jiffies(&desc, tvmem, speed[i].blen,
						speed[i].plen, output, sec);
1035
		else
1036 1037 1038 1039 1040 1041 1042
			ret = test_hash_cycles(&desc, tvmem, speed[i].blen,
					       speed[i].plen, output);

		if (ret) {
			printk("hashing failed ret=%d\n", ret);
			break;
		}
1043 1044 1045
	}

out:
1046
	crypto_free_hash(tfm);
1047 1048
}

1049 1050
static void test_comp(char *algo, struct comp_testvec *ctemplate,
		       struct comp_testvec *dtemplate, int ctcount, int dtcount)
L
Linus Torvalds 已提交
1051 1052 1053
{
	unsigned int i;
	char result[COMP_BUF_SIZE];
1054
	struct crypto_comp *tfm;
L
Linus Torvalds 已提交
1055 1056 1057
	struct comp_testvec *tv;
	unsigned int tsize;

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

1060 1061
	tsize = sizeof(struct comp_testvec);
	tsize *= ctcount;
L
Linus Torvalds 已提交
1062 1063 1064 1065 1066 1067
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize,
		       TVMEMSIZE);
		return;
	}

1068
	memcpy(tvmem, ctemplate, tsize);
1069
	tv = (void *)tvmem;
L
Linus Torvalds 已提交
1070

1071
	tfm = crypto_alloc_comp(algo, 0, CRYPTO_ALG_ASYNC);
1072
	if (IS_ERR(tfm)) {
1073
		printk("failed to load transform for %s\n", algo);
L
Linus Torvalds 已提交
1074 1075 1076
		return;
	}

1077
	for (i = 0; i < ctcount; i++) {
L
Linus Torvalds 已提交
1078
		int ilen, ret, dlen = COMP_BUF_SIZE;
1079

L
Linus Torvalds 已提交
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
		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);
	}

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

1098 1099
	tsize = sizeof(struct comp_testvec);
	tsize *= dtcount;
L
Linus Torvalds 已提交
1100 1101 1102 1103 1104 1105
	if (tsize > TVMEMSIZE) {
		printk("template (%u) too big for tvmem (%u)\n", tsize,
		       TVMEMSIZE);
		goto out;
	}

1106
	memcpy(tvmem, dtemplate, tsize);
1107
	tv = (void *)tvmem;
L
Linus Torvalds 已提交
1108

1109
	for (i = 0; i < dtcount; i++) {
L
Linus Torvalds 已提交
1110
		int ilen, ret, dlen = COMP_BUF_SIZE;
1111

L
Linus Torvalds 已提交
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
		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:
1128
	crypto_free_comp(tfm);
L
Linus Torvalds 已提交
1129 1130
}

1131
static void test_available(void)
L
Linus Torvalds 已提交
1132 1133
{
	char **name = check;
1134

L
Linus Torvalds 已提交
1135 1136
	while (*name) {
		printk("alg %s ", *name);
1137
		printk(crypto_has_alg(*name, 0, 0) ?
1138
		       "found\n" : "not found\n");
L
Linus Torvalds 已提交
1139
		name++;
1140
	}
L
Linus Torvalds 已提交
1141 1142
}

1143
static void do_test(void)
L
Linus Torvalds 已提交
1144 1145 1146 1147 1148
{
	switch (mode) {

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

L
Linus Torvalds 已提交
1150
		test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS);
1151

L
Linus Torvalds 已提交
1152
		//DES
1153 1154 1155 1156 1157 1158 1159 1160
		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);
1161

L
Linus Torvalds 已提交
1162
		//DES3_EDE
1163 1164 1165 1166
		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);
1167

L
Linus Torvalds 已提交
1168
		test_hash("md4", md4_tv_template, MD4_TEST_VECTORS);
1169

1170 1171
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);

L
Linus Torvalds 已提交
1172
		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
1173

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

L
Linus Torvalds 已提交
1184
		//TWOFISH
1185 1186 1187 1188 1189 1190 1191 1192
		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);
1193

L
Linus Torvalds 已提交
1194
		//SERPENT
1195 1196 1197 1198
		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);
1199

L
Linus Torvalds 已提交
1200
		//TNEPRES
1201 1202 1203 1204
		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 已提交
1205 1206

		//AES
1207 1208 1209 1210 1211 1212 1213 1214
		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 已提交
1215 1216 1217 1218
		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);
1219 1220 1221 1222
		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);
1223
		test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1224
			    AES_CTR_ENC_TEST_VECTORS);
1225
		test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1226
			    AES_CTR_DEC_TEST_VECTORS);
M
Mikko Herranen 已提交
1227 1228 1229 1230
		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 已提交
1231 1232 1233 1234
		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 已提交
1235 1236

		//CAST5
1237 1238 1239 1240
		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);
1241

L
Linus Torvalds 已提交
1242
		//CAST6
1243 1244 1245 1246
		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 已提交
1247 1248

		//ARC4
1249 1250 1251 1252
		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 已提交
1253 1254

		//TEA
1255 1256 1257 1258
		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 已提交
1259 1260 1261


		//XTEA
1262 1263 1264 1265
		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 已提交
1266 1267

		//KHAZAD
1268 1269 1270 1271
		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 已提交
1272 1273

		//ANUBIS
1274 1275 1276 1277 1278 1279 1280 1281
		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 已提交
1282

A
Aaron Grothe 已提交
1283
		//XETA
1284 1285 1286 1287
		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 已提交
1288

1289 1290 1291 1292 1293 1294
		//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);

1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
		//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);

1309 1310 1311 1312 1313 1314
		//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 已提交
1315 1316 1317 1318 1319 1320 1321 1322
		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);
1323 1324 1325
		test_comp("deflate", deflate_comp_tv_template,
			  deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
			  DEFLATE_DECOMP_TEST_VECTORS);
1326 1327
		test_comp("lzo", lzo_comp_tv_template, lzo_decomp_tv_template,
			  LZO_COMP_TEST_VECTORS, LZO_DECOMP_TEST_VECTORS);
1328
		test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
1329 1330 1331 1332
		test_hash("hmac(md5)", hmac_md5_tv_template,
			  HMAC_MD5_TEST_VECTORS);
		test_hash("hmac(sha1)", hmac_sha1_tv_template,
			  HMAC_SHA1_TEST_VECTORS);
1333 1334
		test_hash("hmac(sha224)", hmac_sha224_tv_template,
			  HMAC_SHA224_TEST_VECTORS);
1335 1336
		test_hash("hmac(sha256)", hmac_sha256_tv_template,
			  HMAC_SHA256_TEST_VECTORS);
1337 1338 1339 1340
		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 已提交
1341

1342 1343 1344
		test_hash("xcbc(aes)", aes_xcbc128_tv_template,
			  XCBC_AES_TEST_VECTORS);

L
Linus Torvalds 已提交
1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
		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:
1357 1358 1359 1360 1361 1362 1363 1364
		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 已提交
1365 1366 1367
		break;

	case 4:
1368 1369 1370 1371
		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 已提交
1372 1373 1374 1375 1376
		break;

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

L
Linus Torvalds 已提交
1378 1379 1380
	case 6:
		test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS);
		break;
1381

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

	case 8:
1394 1395 1396 1397 1398 1399 1400 1401
		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 已提交
1402
		break;
1403

L
Linus Torvalds 已提交
1404
	case 9:
1405 1406 1407 1408
		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 已提交
1409 1410 1411
		break;

	case 10:
1412 1413 1414 1415 1416 1417 1418 1419
		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 已提交
1420 1421 1422 1423
		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);
1424 1425 1426 1427
		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);
1428
		test_cipher("rfc3686(ctr(aes))", ENCRYPT, aes_ctr_enc_tv_template,
1429
			    AES_CTR_ENC_TEST_VECTORS);
1430
		test_cipher("rfc3686(ctr(aes))", DECRYPT, aes_ctr_dec_tv_template,
1431
			    AES_CTR_DEC_TEST_VECTORS);
L
Linus Torvalds 已提交
1432 1433 1434 1435 1436
		break;

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

L
Linus Torvalds 已提交
1438 1439 1440 1441 1442
	case 12:
		test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS);
		break;

	case 13:
1443 1444 1445
		test_comp("deflate", deflate_comp_tv_template,
			  deflate_decomp_tv_template, DEFLATE_COMP_TEST_VECTORS,
			  DEFLATE_DECOMP_TEST_VECTORS);
L
Linus Torvalds 已提交
1446 1447 1448
		break;

	case 14:
1449 1450 1451 1452
		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 已提交
1453 1454 1455
		break;

	case 15:
1456 1457 1458 1459
		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 已提交
1460 1461 1462
		break;

	case 16:
1463 1464 1465 1466
		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 已提交
1467 1468 1469 1470 1471 1472 1473
		break;

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

	case 18:
1474
		test_hash("crc32c", crc32c_tv_template, CRC32C_TEST_VECTORS);
L
Linus Torvalds 已提交
1475 1476 1477
		break;

	case 19:
1478 1479 1480 1481
		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 已提交
1482 1483 1484
		break;

	case 20:
1485 1486 1487 1488
		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 已提交
1489 1490 1491
		break;

	case 21:
1492 1493 1494 1495
		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 已提交
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
		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:
1511 1512 1513 1514
		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 已提交
1515 1516 1517
		break;

	case 26:
1518 1519 1520 1521 1522 1523 1524 1525
		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 已提交
1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
		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 已提交
1540 1541
		
	case 30:
1542 1543 1544 1545
		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 已提交
1546
		break;
L
Linus Torvalds 已提交
1547

1548 1549 1550 1551 1552 1553 1554
	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;

1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
	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;
1569 1570 1571
	case 33:
		test_hash("sha224", sha224_tv_template, SHA224_TEST_VECTORS);
		break;
1572

1573 1574 1575 1576 1577 1578
	case 34:
		test_cipher("salsa20", ENCRYPT,
			    salsa20_stream_enc_tv_template,
			    SALSA20_STREAM_ENC_TEST_VECTORS);
		break;

1579 1580 1581 1582 1583 1584 1585
	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;

1586 1587 1588 1589 1590
	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 已提交
1591 1592 1593 1594 1595 1596 1597
	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 已提交
1598
	case 100:
1599 1600
		test_hash("hmac(md5)", hmac_md5_tv_template,
			  HMAC_MD5_TEST_VECTORS);
L
Linus Torvalds 已提交
1601
		break;
1602

L
Linus Torvalds 已提交
1603
	case 101:
1604 1605
		test_hash("hmac(sha1)", hmac_sha1_tv_template,
			  HMAC_SHA1_TEST_VECTORS);
L
Linus Torvalds 已提交
1606
		break;
1607

L
Linus Torvalds 已提交
1608
	case 102:
1609 1610
		test_hash("hmac(sha256)", hmac_sha256_tv_template,
			  HMAC_SHA256_TEST_VECTORS);
L
Linus Torvalds 已提交
1611 1612
		break;

1613 1614 1615 1616 1617 1618 1619 1620 1621
	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;
1622

1623 1624 1625 1626
	case 105:
		test_hash("hmac(sha224)", hmac_sha224_tv_template,
			  HMAC_SHA224_TEST_VECTORS);
		break;
L
Linus Torvalds 已提交
1627

1628 1629 1630 1631 1632
	case 106:
		test_hash("xcbc(aes)", aes_xcbc128_tv_template,
			  XCBC_AES_TEST_VECTORS);
		break;

H
Harald Welte 已提交
1633
	case 200:
1634
		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1635
				speed_template_16_24_32);
1636
		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1637
				speed_template_16_24_32);
1638
		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1639
				speed_template_16_24_32);
1640
		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1641
				speed_template_16_24_32);
R
Rik Snel 已提交
1642
		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1643
				speed_template_32_40_48);
R
Rik Snel 已提交
1644
		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1645
				speed_template_32_40_48);
1646
		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1647
				speed_template_32_48_64);
1648
		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1649
				speed_template_32_48_64);
H
Harald Welte 已提交
1650 1651 1652
		break;

	case 201:
1653
		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1654 1655
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
1656
		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
1657 1658
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
1659
		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1660 1661
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
1662
		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
1663 1664
				des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS,
				speed_template_24);
H
Harald Welte 已提交
1665 1666 1667
		break;

	case 202:
1668
		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1669
				speed_template_16_24_32);
1670
		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1671
				speed_template_16_24_32);
1672
		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1673
				speed_template_16_24_32);
1674
		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1675
				speed_template_16_24_32);
H
Harald Welte 已提交
1676 1677 1678
		break;

	case 203:
1679
		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1680
				  speed_template_8_32);
1681
		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
1682
				  speed_template_8_32);
1683
		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
1684
				  speed_template_8_32);
1685
		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
1686
				  speed_template_8_32);
H
Harald Welte 已提交
1687 1688 1689
		break;

	case 204:
1690
		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1691
				  speed_template_8);
1692
		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1693
				  speed_template_8);
1694
		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1695
				  speed_template_8);
1696
		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1697
				  speed_template_8);
H
Harald Welte 已提交
1698 1699
		break;

1700 1701
	case 205:
		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1702
				speed_template_16_24_32);
1703
		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1704
				speed_template_16_24_32);
1705
		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1706
				speed_template_16_24_32);
1707
		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1708
				speed_template_16_24_32);
1709 1710
		break;

1711 1712
	case 206:
		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
1713
				  speed_template_16_32);
1714 1715
		break;

1716 1717 1718 1719
	case 300:
		/* fall through */

	case 301:
1720
		test_hash_speed("md4", sec, generic_hash_speed_template);
1721 1722 1723
		if (mode > 300 && mode < 400) break;

	case 302:
1724
		test_hash_speed("md5", sec, generic_hash_speed_template);
1725 1726 1727
		if (mode > 300 && mode < 400) break;

	case 303:
1728
		test_hash_speed("sha1", sec, generic_hash_speed_template);
1729 1730 1731
		if (mode > 300 && mode < 400) break;

	case 304:
1732
		test_hash_speed("sha256", sec, generic_hash_speed_template);
1733 1734 1735
		if (mode > 300 && mode < 400) break;

	case 305:
1736
		test_hash_speed("sha384", sec, generic_hash_speed_template);
1737 1738 1739
		if (mode > 300 && mode < 400) break;

	case 306:
1740
		test_hash_speed("sha512", sec, generic_hash_speed_template);
1741 1742 1743
		if (mode > 300 && mode < 400) break;

	case 307:
1744
		test_hash_speed("wp256", sec, generic_hash_speed_template);
1745 1746 1747
		if (mode > 300 && mode < 400) break;

	case 308:
1748
		test_hash_speed("wp384", sec, generic_hash_speed_template);
1749 1750 1751
		if (mode > 300 && mode < 400) break;

	case 309:
1752
		test_hash_speed("wp512", sec, generic_hash_speed_template);
1753 1754 1755
		if (mode > 300 && mode < 400) break;

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

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

	case 312:
1764
		test_hash_speed("tgr192", sec, generic_hash_speed_template);
1765 1766
		if (mode > 300 && mode < 400) break;

1767 1768 1769 1770
	case 313:
		test_hash_speed("sha224", sec, generic_hash_speed_template);
		if (mode > 300 && mode < 400) break;

1771 1772 1773
	case 399:
		break;

L
Linus Torvalds 已提交
1774 1775 1776
	case 1000:
		test_available();
		break;
1777

L
Linus Torvalds 已提交
1778 1779 1780 1781 1782 1783 1784
	default:
		/* useful for debugging */
		printk("not testing anything\n");
		break;
	}
}

1785
static int __init init(void)
L
Linus Torvalds 已提交
1786
{
1787 1788
	int err = -ENOMEM;

L
Linus Torvalds 已提交
1789 1790
	tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL);
	if (tvmem == NULL)
1791
		return err;
L
Linus Torvalds 已提交
1792 1793

	xbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
1794 1795
	if (xbuf == NULL)
		goto err_free_tv;
L
Linus Torvalds 已提交
1796

1797 1798 1799
	axbuf = kmalloc(XBUFSIZE, GFP_KERNEL);
	if (axbuf == NULL)
		goto err_free_xbuf;
L
Linus Torvalds 已提交
1800

1801
	do_test();
1802 1803 1804 1805 1806 1807 1808

	/* 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
	 */
1809 1810 1811 1812 1813 1814 1815 1816 1817
	err = -EAGAIN;

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

	return err;
L
Linus Torvalds 已提交
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829
}

/*
 * 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 已提交
1830
module_param(sec, uint, 0);
1831 1832
MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
		      "(defaults to zero which uses CPU cycles instead)");
L
Linus Torvalds 已提交
1833 1834 1835 1836

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