Blame view

crypto/tcrypt.c 28.3 KB
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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>
e3a4ea4fd   Mikko Herranen   [CRYPTO] tcrypt: ...
9
   * Copyright (c) 2007 Nokia Siemens Networks
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
   *
69435b94d   Adrian Hoban   crypto: rfc4106 -...
11
12
13
14
15
16
17
   * Updated RFC4106 AES-GCM testing.
   *    Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
   *             Adrian Hoban <adrian.hoban@intel.com>
   *             Gabriele Paoloni <gabriele.paoloni@intel.com>
   *             Tadeusz Struk (tadeusz.struk@intel.com)
   *             Copyright (c) 2010, Intel Corporation.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the Free
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
20
   * Software Foundation; either version 2 of the License, or (at your option)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
   * any later version.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
   */
18e33e6d5   Herbert Xu   crypto: hash - Mo...
24
  #include <crypto/hash.h>
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
25
  #include <linux/err.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include <linux/init.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
27
  #include <linux/gfp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
  #include <linux/module.h>
378f058cc   David Hardeman   [PATCH] Use sg_se...
29
  #include <linux/scatterlist.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include <linux/string.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  #include <linux/moduleparam.h>
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
32
  #include <linux/jiffies.h>
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
33
34
  #include <linux/timex.h>
  #include <linux/interrupt.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
  #include "tcrypt.h"
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
36
  #include "internal.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
  
  /*
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
39
   * Need slab memory for testing (size in number of pages).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
   */
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
41
  #define TVMEMSIZE	4
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
  
  /*
da7f033dd   Herbert Xu   crypto: cryptomgr...
44
  * Used by test_cipher_speed()
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
  */
  #define ENCRYPT 1
  #define DECRYPT 0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48

ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
49
50
51
  /*
   * Used by test_cipher_speed()
   */
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
52
  static unsigned int sec;
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
53

a873a5f1c   Steffen Klassert   crypto: tcrypt - ...
54
55
  static char *alg = NULL;
  static u32 type;
7be380f72   Herbert Xu   crypto: tcrypt - ...
56
  static u32 mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  static int mode;
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
58
  static char *tvmem[TVMEMSIZE];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
  
  static char *check[] = {
cd12fb906   Jonathan Lynch   [CRYPTO] sha256-g...
61
62
63
  	"des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
  	"blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
  	"cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
90831639a   David Howells   [CRYPTO] fcrypt: ...
64
  	"khazad", "wp512", "wp384", "wp256", "tnepres", "xeta",  "fcrypt",
2998db37b   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
65
  	"camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
0c01aed50   Geert Uytterhoeven   crypto: testmgr -...
66
  	"lzo", "cts", "zlib", NULL
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
  };
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
68
69
  static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
  			       struct scatterlist *sg, int blen, int sec)
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
70
  {
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
71
72
73
  	unsigned long start, end;
  	int bcount;
  	int ret;
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
74
75
76
  	for (start = jiffies, end = start + sec * HZ, bcount = 0;
  	     time_before(jiffies, end); bcount++) {
  		if (enc)
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
77
  			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
78
  		else
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
79
  			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
80
81
82
83
84
85
86
87
88
89
  
  		if (ret)
  			return ret;
  	}
  
  	printk("%d operations in %d seconds (%ld bytes)
  ",
  	       bcount, sec, (long)bcount * blen);
  	return 0;
  }
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
90
91
  static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
  			      struct scatterlist *sg, int blen)
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
92
  {
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
93
94
95
  	unsigned long cycles = 0;
  	int ret = 0;
  	int i;
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
96
97
98
99
100
101
  	local_bh_disable();
  	local_irq_disable();
  
  	/* Warm-up run. */
  	for (i = 0; i < 4; i++) {
  		if (enc)
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
102
  			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
103
  		else
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
104
  			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
105
106
107
108
109
110
111
112
113
114
115
  
  		if (ret)
  			goto out;
  	}
  
  	/* The real thing. */
  	for (i = 0; i < 8; i++) {
  		cycles_t start, end;
  
  		start = get_cycles();
  		if (enc)
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
116
  			ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
117
  		else
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
118
  			ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
  		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)
  ",
  		       (cycles + 4) / 8, blen);
  
  	return ret;
  }
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
138
  static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
01b323245   Herbert Xu   crypto: tcrypt - ...
139
  static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
da7f033dd   Herbert Xu   crypto: cryptomgr...
140
  			      struct cipher_speed_template *template,
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
141
  			      unsigned int tcount, u8 *keysize)
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
142
  {
dce907c00   Herbert Xu   [CRYPTO]: Use tem...
143
  	unsigned int ret, i, j, iv_len;
f07ef1de9   David Sterba   crypto: tcrypt - ...
144
145
  	const char *key;
  	char iv[128];
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
146
147
148
  	struct crypto_blkcipher *tfm;
  	struct blkcipher_desc desc;
  	const char *e;
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
149
  	u32 *b_size;
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
150
151
152
153
154
  
  	if (enc == ENCRYPT)
  	        e = "encryption";
  	else
  		e = "decryption";
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
155

cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
156
157
158
  	printk("
  testing speed of %s %s
  ", algo, e);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
159

cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
160
  	tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
161

cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
162
163
164
165
  	if (IS_ERR(tfm)) {
  		printk("failed to load transform for %s: %ld
  ", algo,
  		       PTR_ERR(tfm));
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
166
167
  		return;
  	}
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
168
169
  	desc.tfm = tfm;
  	desc.flags = 0;
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
170

d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
171
172
  	i = 0;
  	do {
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
173

d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
174
175
  		b_size = block_sizes;
  		do {
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
176
  			struct scatterlist sg[TVMEMSIZE];
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
177

f139cfa7c   Herbert Xu   crypto: tcrypt - ...
178
179
180
181
182
  			if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
  				printk("template (%u) too big for "
  				       "tvmem (%lu)
  ", *keysize + *b_size,
  				       TVMEMSIZE * PAGE_SIZE);
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
183
184
  				goto out;
  			}
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
185

d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
186
187
  			printk("test %u (%d bit key, %d byte blocks): ", i,
  					*keysize * 8, *b_size);
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
188
  			memset(tvmem[0], 0xff, PAGE_SIZE);
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
189
190
  
  			/* set key, plain text and IV */
da7f033dd   Herbert Xu   crypto: cryptomgr...
191
  			key = tvmem[0];
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
192
193
194
195
196
  			for (j = 0; j < tcount; j++) {
  				if (template[j].klen == *keysize) {
  					key = template[j].key;
  					break;
  				}
dce907c00   Herbert Xu   [CRYPTO]: Use tem...
197
  			}
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
198

d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
199
200
201
202
203
204
205
  			ret = crypto_blkcipher_setkey(tfm, key, *keysize);
  			if (ret) {
  				printk("setkey() failed flags=%x
  ",
  						crypto_blkcipher_get_flags(tfm));
  				goto out;
  			}
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
206

f139cfa7c   Herbert Xu   crypto: tcrypt - ...
207
208
209
210
211
212
213
  			sg_init_table(sg, TVMEMSIZE);
  			sg_set_buf(sg, tvmem[0] + *keysize,
  				   PAGE_SIZE - *keysize);
  			for (j = 1; j < TVMEMSIZE; j++) {
  				sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
  				memset (tvmem[j], 0xff, PAGE_SIZE);
  			}
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
214
215
216
217
218
  			iv_len = crypto_blkcipher_ivsize(tfm);
  			if (iv_len) {
  				memset(&iv, 0xff, iv_len);
  				crypto_blkcipher_set_iv(tfm, iv, iv_len);
  			}
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
219

d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
220
  			if (sec)
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
221
222
  				ret = test_cipher_jiffies(&desc, enc, sg,
  							  *b_size, sec);
d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
223
  			else
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
224
225
  				ret = test_cipher_cycles(&desc, enc, sg,
  							 *b_size);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
226

d5dc39274   Sebastian Siewior   [CRYPTO] tcrypt: ...
227
228
229
230
231
232
233
234
235
236
  			if (ret) {
  				printk("%s() failed flags=%x
  ", e, desc.flags);
  				break;
  			}
  			b_size++;
  			i++;
  		} while (*b_size);
  		keysize++;
  	} while (*keysize);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
237
238
  
  out:
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
239
  	crypto_free_blkcipher(tfm);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
240
  }
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
241
242
  static int test_hash_jiffies_digest(struct hash_desc *desc,
  				    struct scatterlist *sg, int blen,
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
243
244
  				    char *out, int sec)
  {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
245
246
247
248
249
250
  	unsigned long start, end;
  	int bcount;
  	int ret;
  
  	for (start = jiffies, end = start + sec * HZ, bcount = 0;
  	     time_before(jiffies, end); bcount++) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
251
252
253
254
255
256
257
258
259
260
261
  		ret = crypto_hash_digest(desc, sg, blen, out);
  		if (ret)
  			return ret;
  	}
  
  	printk("%6u opers/sec, %9lu bytes/sec
  ",
  	       bcount / sec, ((long)bcount * blen) / sec);
  
  	return 0;
  }
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
262
263
  static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
  			     int blen, int plen, char *out, int sec)
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
264
  {
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
265
266
  	unsigned long start, end;
  	int bcount, pcount;
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
267
268
269
  	int ret;
  
  	if (plen == blen)
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
270
  		return test_hash_jiffies_digest(desc, sg, blen, out, sec);
a5a613a42   Herbert Xu   [CRYPTO] tcrypt: ...
271

e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
272
273
  	for (start = jiffies, end = start + sec * HZ, bcount = 0;
  	     time_before(jiffies, end); bcount++) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
274
275
276
  		ret = crypto_hash_init(desc);
  		if (ret)
  			return ret;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
277
  		for (pcount = 0; pcount < blen; pcount += plen) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
278
279
280
  			ret = crypto_hash_update(desc, sg, plen);
  			if (ret)
  				return ret;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
281
282
  		}
  		/* we assume there is enough space in 'out' for the result */
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
283
284
285
  		ret = crypto_hash_final(desc, out);
  		if (ret)
  			return ret;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
286
287
288
289
290
  	}
  
  	printk("%6u opers/sec, %9lu bytes/sec
  ",
  	       bcount / sec, ((long)bcount * blen) / sec);
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
291
292
  	return 0;
  }
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
293
294
  static int test_hash_cycles_digest(struct hash_desc *desc,
  				   struct scatterlist *sg, int blen, char *out)
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
295
  {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
296
297
298
299
300
301
302
303
304
  	unsigned long cycles = 0;
  	int i;
  	int ret;
  
  	local_bh_disable();
  	local_irq_disable();
  
  	/* Warm-up run. */
  	for (i = 0; i < 4; i++) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
305
306
307
308
309
310
311
312
313
314
  		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();
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
  		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
  ",
  	       cycles / 8, cycles / (8 * blen));
  
  	return 0;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
336
  }
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
337
338
  static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
  			    int blen, int plen, char *out)
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
339
  {
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
340
341
  	unsigned long cycles = 0;
  	int i, pcount;
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
342
343
344
  	int ret;
  
  	if (plen == blen)
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
345
  		return test_hash_cycles_digest(desc, sg, blen, out);
a5a613a42   Herbert Xu   [CRYPTO] tcrypt: ...
346

e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
347
348
349
350
351
  	local_bh_disable();
  	local_irq_disable();
  
  	/* Warm-up run. */
  	for (i = 0; i < 4; i++) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
352
353
354
  		ret = crypto_hash_init(desc);
  		if (ret)
  			goto out;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
355
  		for (pcount = 0; pcount < blen; pcount += plen) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
356
357
358
  			ret = crypto_hash_update(desc, sg, plen);
  			if (ret)
  				goto out;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
359
  		}
29059d12e   Herbert Xu   [CRYPTO] tcrypt: ...
360
  		ret = crypto_hash_final(desc, out);
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
361
362
  		if (ret)
  			goto out;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
363
364
365
366
367
  	}
  
  	/* The real thing. */
  	for (i = 0; i < 8; i++) {
  		cycles_t start, end;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
368
  		start = get_cycles();
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
369
370
371
  		ret = crypto_hash_init(desc);
  		if (ret)
  			goto out;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
372
  		for (pcount = 0; pcount < blen; pcount += plen) {
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
373
374
375
  			ret = crypto_hash_update(desc, sg, plen);
  			if (ret)
  				goto out;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
376
  		}
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
377
378
379
  		ret = crypto_hash_final(desc, out);
  		if (ret)
  			goto out;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
380
381
382
383
384
  
  		end = get_cycles();
  
  		cycles += end - start;
  	}
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
385
  out:
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
386
387
  	local_irq_enable();
  	local_bh_enable();
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
388
389
  	if (ret)
  		return ret;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
390
391
392
  	printk("%6lu cycles/operation, %4lu cycles/byte
  ",
  	       cycles / 8, cycles / (8 * blen));
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
393
  	return 0;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
394
  }
beb63da73   David S. Miller   crypto: tcrypt - ...
395
396
397
398
399
400
401
402
403
404
  static void test_hash_sg_init(struct scatterlist *sg)
  {
  	int i;
  
  	sg_init_table(sg, TVMEMSIZE);
  	for (i = 0; i < TVMEMSIZE; i++) {
  		sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
  		memset(tvmem[i], 0xff, PAGE_SIZE);
  	}
  }
01b323245   Herbert Xu   crypto: tcrypt - ...
405
406
  static void test_hash_speed(const char *algo, unsigned int sec,
  			    struct hash_speed *speed)
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
407
  {
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
408
  	struct scatterlist sg[TVMEMSIZE];
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
409
410
  	struct crypto_hash *tfm;
  	struct hash_desc desc;
376bacb0a   Frank Seidel   crypto: tcrypt - ...
411
  	static char output[1024];
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
412
  	int i;
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
413
  	int ret;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
414

376bacb0a   Frank Seidel   crypto: tcrypt - ...
415
416
417
  	printk(KERN_INFO "
  testing speed of %s
  ", algo);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
418

e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
419
  	tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
420

e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
421
  	if (IS_ERR(tfm)) {
376bacb0a   Frank Seidel   crypto: tcrypt - ...
422
423
  		printk(KERN_ERR "failed to load transform for %s: %ld
  ", algo,
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
424
  		       PTR_ERR(tfm));
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
425
426
  		return;
  	}
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
427
428
429
430
  	desc.tfm = tfm;
  	desc.flags = 0;
  
  	if (crypto_hash_digestsize(tfm) > sizeof(output)) {
376bacb0a   Frank Seidel   crypto: tcrypt - ...
431
432
  		printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)
  ",
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
433
  		       crypto_hash_digestsize(tfm), sizeof(output));
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
434
435
  		goto out;
  	}
beb63da73   David S. Miller   crypto: tcrypt - ...
436
  	test_hash_sg_init(sg);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
437
  	for (i = 0; speed[i].blen != 0; i++) {
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
438
  		if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
376bacb0a   Frank Seidel   crypto: tcrypt - ...
439
440
441
  			printk(KERN_ERR
  			       "template (%u) too big for tvmem (%lu)
  ",
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
442
  			       speed[i].blen, TVMEMSIZE * PAGE_SIZE);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
443
444
  			goto out;
  		}
18bcc9194   Huang Ying   crypto: tcrypt - ...
445
446
  		if (speed[i].klen)
  			crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
376bacb0a   Frank Seidel   crypto: tcrypt - ...
447
448
  		printk(KERN_INFO "test%3u "
  		       "(%5u byte blocks,%5u bytes per update,%4u updates): ",
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
449
  		       i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
450
  		if (sec)
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
451
  			ret = test_hash_jiffies(&desc, sg, speed[i].blen,
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
452
  						speed[i].plen, output, sec);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
453
  		else
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
454
  			ret = test_hash_cycles(&desc, sg, speed[i].blen,
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
455
456
457
  					       speed[i].plen, output);
  
  		if (ret) {
376bacb0a   Frank Seidel   crypto: tcrypt - ...
458
459
  			printk(KERN_ERR "hashing failed ret=%d
  ", ret);
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
460
461
  			break;
  		}
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
462
463
464
  	}
  
  out:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
465
  	crypto_free_hash(tfm);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
466
  }
beb63da73   David S. Miller   crypto: tcrypt - ...
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
  struct tcrypt_result {
  	struct completion completion;
  	int err;
  };
  
  static void tcrypt_complete(struct crypto_async_request *req, int err)
  {
  	struct tcrypt_result *res = req->data;
  
  	if (err == -EINPROGRESS)
  		return;
  
  	res->err = err;
  	complete(&res->completion);
  }
  
  static inline int do_one_ahash_op(struct ahash_request *req, int ret)
  {
  	if (ret == -EINPROGRESS || ret == -EBUSY) {
  		struct tcrypt_result *tr = req->base.data;
  
  		ret = wait_for_completion_interruptible(&tr->completion);
  		if (!ret)
  			ret = tr->err;
  		INIT_COMPLETION(tr->completion);
  	}
  	return ret;
  }
  
  static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
  				     char *out, int sec)
  {
  	unsigned long start, end;
  	int bcount;
  	int ret;
  
  	for (start = jiffies, end = start + sec * HZ, bcount = 0;
  	     time_before(jiffies, end); bcount++) {
  		ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  		if (ret)
  			return ret;
  	}
  
  	printk("%6u opers/sec, %9lu bytes/sec
  ",
  	       bcount / sec, ((long)bcount * blen) / sec);
  
  	return 0;
  }
  
  static int test_ahash_jiffies(struct ahash_request *req, int blen,
  			      int plen, char *out, int sec)
  {
  	unsigned long start, end;
  	int bcount, pcount;
  	int ret;
  
  	if (plen == blen)
  		return test_ahash_jiffies_digest(req, blen, out, sec);
  
  	for (start = jiffies, end = start + sec * HZ, bcount = 0;
  	     time_before(jiffies, end); bcount++) {
  		ret = crypto_ahash_init(req);
  		if (ret)
  			return ret;
  		for (pcount = 0; pcount < blen; pcount += plen) {
  			ret = do_one_ahash_op(req, crypto_ahash_update(req));
  			if (ret)
  				return ret;
  		}
  		/* we assume there is enough space in 'out' for the result */
  		ret = do_one_ahash_op(req, crypto_ahash_final(req));
  		if (ret)
  			return ret;
  	}
  
  	pr_cont("%6u opers/sec, %9lu bytes/sec
  ",
  		bcount / sec, ((long)bcount * blen) / sec);
  
  	return 0;
  }
  
  static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
  				    char *out)
  {
  	unsigned long cycles = 0;
  	int ret, i;
  
  	/* Warm-up run. */
  	for (i = 0; i < 4; i++) {
  		ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  		if (ret)
  			goto out;
  	}
  
  	/* The real thing. */
  	for (i = 0; i < 8; i++) {
  		cycles_t start, end;
  
  		start = get_cycles();
  
  		ret = do_one_ahash_op(req, crypto_ahash_digest(req));
  		if (ret)
  			goto out;
  
  		end = get_cycles();
  
  		cycles += end - start;
  	}
  
  out:
  	if (ret)
  		return ret;
  
  	pr_cont("%6lu cycles/operation, %4lu cycles/byte
  ",
  		cycles / 8, cycles / (8 * blen));
  
  	return 0;
  }
  
  static int test_ahash_cycles(struct ahash_request *req, int blen,
  			     int plen, char *out)
  {
  	unsigned long cycles = 0;
  	int i, pcount, ret;
  
  	if (plen == blen)
  		return test_ahash_cycles_digest(req, blen, out);
  
  	/* Warm-up run. */
  	for (i = 0; i < 4; i++) {
  		ret = crypto_ahash_init(req);
  		if (ret)
  			goto out;
  		for (pcount = 0; pcount < blen; pcount += plen) {
  			ret = do_one_ahash_op(req, crypto_ahash_update(req));
  			if (ret)
  				goto out;
  		}
  		ret = do_one_ahash_op(req, crypto_ahash_final(req));
  		if (ret)
  			goto out;
  	}
  
  	/* The real thing. */
  	for (i = 0; i < 8; i++) {
  		cycles_t start, end;
  
  		start = get_cycles();
  
  		ret = crypto_ahash_init(req);
  		if (ret)
  			goto out;
  		for (pcount = 0; pcount < blen; pcount += plen) {
  			ret = do_one_ahash_op(req, crypto_ahash_update(req));
  			if (ret)
  				goto out;
  		}
  		ret = do_one_ahash_op(req, crypto_ahash_final(req));
  		if (ret)
  			goto out;
  
  		end = get_cycles();
  
  		cycles += end - start;
  	}
  
  out:
  	if (ret)
  		return ret;
  
  	pr_cont("%6lu cycles/operation, %4lu cycles/byte
  ",
  		cycles / 8, cycles / (8 * blen));
  
  	return 0;
  }
  
  static void test_ahash_speed(const char *algo, unsigned int sec,
  			     struct hash_speed *speed)
  {
  	struct scatterlist sg[TVMEMSIZE];
  	struct tcrypt_result tresult;
  	struct ahash_request *req;
  	struct crypto_ahash *tfm;
  	static char output[1024];
  	int i, ret;
  
  	printk(KERN_INFO "
  testing speed of async %s
  ", algo);
  
  	tfm = crypto_alloc_ahash(algo, 0, 0);
  	if (IS_ERR(tfm)) {
  		pr_err("failed to load transform for %s: %ld
  ",
  		       algo, PTR_ERR(tfm));
  		return;
  	}
  
  	if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
  		pr_err("digestsize(%u) > outputbuffer(%zu)
  ",
  		       crypto_ahash_digestsize(tfm), sizeof(output));
  		goto out;
  	}
  
  	test_hash_sg_init(sg);
  	req = ahash_request_alloc(tfm, GFP_KERNEL);
  	if (!req) {
  		pr_err("ahash request allocation failure
  ");
  		goto out;
  	}
  
  	init_completion(&tresult.completion);
  	ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
  				   tcrypt_complete, &tresult);
  
  	for (i = 0; speed[i].blen != 0; i++) {
  		if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
  			pr_err("template (%u) too big for tvmem (%lu)
  ",
  			       speed[i].blen, TVMEMSIZE * PAGE_SIZE);
  			break;
  		}
  
  		pr_info("test%3u "
  			"(%5u byte blocks,%5u bytes per update,%4u updates): ",
  			i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
  
  		ahash_request_set_crypt(req, sg, output, speed[i].plen);
  
  		if (sec)
  			ret = test_ahash_jiffies(req, speed[i].blen,
  						 speed[i].plen, output, sec);
  		else
  			ret = test_ahash_cycles(req, speed[i].blen,
  						speed[i].plen, output);
  
  		if (ret) {
  			pr_err("hashing failed ret=%d
  ", ret);
  			break;
  		}
  	}
  
  	ahash_request_free(req);
  
  out:
  	crypto_free_ahash(tfm);
  }
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
721
  static void test_available(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
722
723
  {
  	char **name = check;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
724

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
726
  	while (*name) {
  		printk("alg %s ", *name);
6158efc09   Herbert Xu   [CRYPTO] tcrypt: ...
727
  		printk(crypto_has_alg(*name, 0, 0) ?
e4d5b79c6   Herbert Xu   [CRYPTO] users: U...
728
729
730
  		       "found
  " : "not found
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
731
  		name++;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
732
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
733
  }
01b323245   Herbert Xu   crypto: tcrypt - ...
734
735
  static inline int tcrypt_test(const char *alg)
  {
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
736
737
738
739
740
741
742
  	int ret;
  
  	ret = alg_test(alg, alg, 0, 0);
  	/* non-fips algs return -EINVAL in fips mode */
  	if (fips_enabled && ret == -EINVAL)
  		ret = 0;
  	return ret;
01b323245   Herbert Xu   crypto: tcrypt - ...
743
  }
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
744
  static int do_test(int m)
01b323245   Herbert Xu   crypto: tcrypt - ...
745
746
  {
  	int i;
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
747
  	int ret = 0;
01b323245   Herbert Xu   crypto: tcrypt - ...
748
749
  
  	switch (m) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
750
  	case 0:
01b323245   Herbert Xu   crypto: tcrypt - ...
751
  		for (i = 1; i < 200; i++)
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
752
  			ret += do_test(i);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
753
754
755
  		break;
  
  	case 1:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
756
  		ret += tcrypt_test("md5");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
757
758
759
  		break;
  
  	case 2:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
760
  		ret += tcrypt_test("sha1");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
761
762
763
  		break;
  
  	case 3:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
764
765
  		ret += tcrypt_test("ecb(des)");
  		ret += tcrypt_test("cbc(des)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
766
767
768
  		break;
  
  	case 4:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
769
770
  		ret += tcrypt_test("ecb(des3_ede)");
  		ret += tcrypt_test("cbc(des3_ede)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
771
772
773
  		break;
  
  	case 5:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
774
  		ret += tcrypt_test("md4");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
775
  		break;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
776

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
777
  	case 6:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
778
  		ret += tcrypt_test("sha256");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
779
  		break;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
780

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
781
  	case 7:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
782
783
  		ret += tcrypt_test("ecb(blowfish)");
  		ret += tcrypt_test("cbc(blowfish)");
85b63e342   Jussi Kivilinna   crypto: testmgr -...
784
  		ret += tcrypt_test("ctr(blowfish)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
785
786
787
  		break;
  
  	case 8:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
788
789
  		ret += tcrypt_test("ecb(twofish)");
  		ret += tcrypt_test("cbc(twofish)");
573da6208   Jussi Kivilinna   crypto: testmgr -...
790
  		ret += tcrypt_test("ctr(twofish)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
791
  		break;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
792

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
793
  	case 9:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
794
  		ret += tcrypt_test("ecb(serpent)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
795
796
797
  		break;
  
  	case 10:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
798
799
800
801
802
803
  		ret += tcrypt_test("ecb(aes)");
  		ret += tcrypt_test("cbc(aes)");
  		ret += tcrypt_test("lrw(aes)");
  		ret += tcrypt_test("xts(aes)");
  		ret += tcrypt_test("ctr(aes)");
  		ret += tcrypt_test("rfc3686(ctr(aes))");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
804
805
806
  		break;
  
  	case 11:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
807
  		ret += tcrypt_test("sha384");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
808
  		break;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
809

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
810
  	case 12:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
811
  		ret += tcrypt_test("sha512");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
812
813
814
  		break;
  
  	case 13:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
815
  		ret += tcrypt_test("deflate");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
816
817
818
  		break;
  
  	case 14:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
819
  		ret += tcrypt_test("ecb(cast5)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
820
821
822
  		break;
  
  	case 15:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
823
  		ret += tcrypt_test("ecb(cast6)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
824
825
826
  		break;
  
  	case 16:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
827
  		ret += tcrypt_test("ecb(arc4)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
828
829
830
  		break;
  
  	case 17:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
831
  		ret += tcrypt_test("michael_mic");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
832
833
834
  		break;
  
  	case 18:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
835
  		ret += tcrypt_test("crc32c");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
836
837
838
  		break;
  
  	case 19:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
839
  		ret += tcrypt_test("ecb(tea)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
840
841
842
  		break;
  
  	case 20:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
843
  		ret += tcrypt_test("ecb(xtea)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
844
845
846
  		break;
  
  	case 21:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
847
  		ret += tcrypt_test("ecb(khazad)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
848
849
850
  		break;
  
  	case 22:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
851
  		ret += tcrypt_test("wp512");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
852
853
854
  		break;
  
  	case 23:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
855
  		ret += tcrypt_test("wp384");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
856
857
858
  		break;
  
  	case 24:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
859
  		ret += tcrypt_test("wp256");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
860
861
862
  		break;
  
  	case 25:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
863
  		ret += tcrypt_test("ecb(tnepres)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
864
865
866
  		break;
  
  	case 26:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
867
868
  		ret += tcrypt_test("ecb(anubis)");
  		ret += tcrypt_test("cbc(anubis)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
869
870
871
  		break;
  
  	case 27:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
872
  		ret += tcrypt_test("tgr192");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
873
874
875
  		break;
  
  	case 28:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
876
  		ret += tcrypt_test("tgr160");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
877
878
879
  		break;
  
  	case 29:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
880
  		ret += tcrypt_test("tgr128");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
881
  		break;
2998db37b   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
882

fb4f10ed5   Aaron Grothe   [CRYPTO]: Fix XTE...
883
  	case 30:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
884
  		ret += tcrypt_test("ecb(xeta)");
fb4f10ed5   Aaron Grothe   [CRYPTO]: Fix XTE...
885
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
886

90831639a   David Howells   [CRYPTO] fcrypt: ...
887
  	case 31:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
888
  		ret += tcrypt_test("pcbc(fcrypt)");
90831639a   David Howells   [CRYPTO] fcrypt: ...
889
  		break;
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
890
  	case 32:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
891
892
  		ret += tcrypt_test("ecb(camellia)");
  		ret += tcrypt_test("cbc(camellia)");
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
893
  		break;
cd12fb906   Jonathan Lynch   [CRYPTO] sha256-g...
894
  	case 33:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
895
  		ret += tcrypt_test("sha224");
cd12fb906   Jonathan Lynch   [CRYPTO] sha256-g...
896
  		break;
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
897

2407d6087   Tan Swee Heng   [CRYPTO] salsa20:...
898
  	case 34:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
899
  		ret += tcrypt_test("salsa20");
2407d6087   Tan Swee Heng   [CRYPTO] salsa20:...
900
  		break;
8df213d9b   Herbert Xu   [CRYPTO] tcrypt: ...
901
  	case 35:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
902
  		ret += tcrypt_test("gcm(aes)");
8df213d9b   Herbert Xu   [CRYPTO] tcrypt: ...
903
  		break;
0b77abb3b   Zoltan Sogor   [CRYPTO] lzo: Add...
904
  	case 36:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
905
  		ret += tcrypt_test("lzo");
0b77abb3b   Zoltan Sogor   [CRYPTO] lzo: Add...
906
  		break;
93cc74e07   Joy Latten   [CRYPTO] tcrypt: ...
907
  	case 37:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
908
  		ret += tcrypt_test("ccm(aes)");
93cc74e07   Joy Latten   [CRYPTO] tcrypt: ...
909
  		break;
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
910
  	case 38:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
911
  		ret += tcrypt_test("cts(cbc(aes))");
76cb95217   Kevin Coffman   [CRYPTO] cts: Add...
912
  		break;
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
913
          case 39:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
914
  		ret += tcrypt_test("rmd128");
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
915
916
917
  		break;
  
          case 40:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
918
  		ret += tcrypt_test("rmd160");
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
919
  		break;
2998db37b   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
920
  	case 41:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
921
  		ret += tcrypt_test("rmd256");
2998db37b   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
922
923
924
  		break;
  
  	case 42:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
925
  		ret += tcrypt_test("rmd320");
01b323245   Herbert Xu   crypto: tcrypt - ...
926
927
928
  		break;
  
  	case 43:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
929
  		ret += tcrypt_test("ecb(seed)");
2998db37b   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
930
  		break;
0c01aed50   Geert Uytterhoeven   crypto: testmgr -...
931
  	case 44:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
932
  		ret += tcrypt_test("zlib");
0c01aed50   Geert Uytterhoeven   crypto: testmgr -...
933
  		break;
5d667322a   Jarod Wilson   crypto: testmgr -...
934
  	case 45:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
935
  		ret += tcrypt_test("rfc4309(ccm(aes))");
5d667322a   Jarod Wilson   crypto: testmgr -...
936
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
937
  	case 100:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
938
  		ret += tcrypt_test("hmac(md5)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
939
  		break;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
940

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
941
  	case 101:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
942
  		ret += tcrypt_test("hmac(sha1)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
943
  		break;
ef2736fc7   Herbert Xu   [CRYPTO]: White s...
944

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
945
  	case 102:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
946
  		ret += tcrypt_test("hmac(sha256)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
947
  		break;
a28091ae1   Andrew Donofrio   [CRYPTO] tcrypt: ...
948
  	case 103:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
949
  		ret += tcrypt_test("hmac(sha384)");
a28091ae1   Andrew Donofrio   [CRYPTO] tcrypt: ...
950
951
952
  		break;
  
  	case 104:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
953
  		ret += tcrypt_test("hmac(sha512)");
a28091ae1   Andrew Donofrio   [CRYPTO] tcrypt: ...
954
  		break;
38ed9ab23   Herbert Xu   [CRYPTO] tcrypt: ...
955

cd12fb906   Jonathan Lynch   [CRYPTO] sha256-g...
956
  	case 105:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
957
  		ret += tcrypt_test("hmac(sha224)");
cd12fb906   Jonathan Lynch   [CRYPTO] sha256-g...
958
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
959

38ed9ab23   Herbert Xu   [CRYPTO] tcrypt: ...
960
  	case 106:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
961
  		ret += tcrypt_test("xcbc(aes)");
38ed9ab23   Herbert Xu   [CRYPTO] tcrypt: ...
962
  		break;
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
963
  	case 107:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
964
  		ret += tcrypt_test("hmac(rmd128)");
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
965
966
967
  		break;
  
  	case 108:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
968
  		ret += tcrypt_test("hmac(rmd160)");
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
969
  		break;
f1939f7c5   Shane Wang   crypto: vmac - Ne...
970
971
972
  	case 109:
  		ret += tcrypt_test("vmac(aes)");
  		break;
e08ca2da3   Jarod Wilson   crypto: testmgr -...
973
  	case 150:
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
974
  		ret += tcrypt_test("ansi_cprng");
e08ca2da3   Jarod Wilson   crypto: testmgr -...
975
  		break;
69435b94d   Adrian Hoban   crypto: rfc4106 -...
976
977
978
  	case 151:
  		ret += tcrypt_test("rfc4106(gcm(aes))");
  		break;
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
979
  	case 200:
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
980
  		test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
981
  				speed_template_16_24_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
982
  		test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
983
  				speed_template_16_24_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
984
  		test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
985
  				speed_template_16_24_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
986
  		test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
987
  				speed_template_16_24_32);
f3d1044cd   Rik Snel   [CRYPTO] tcrypt: ...
988
  		test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
989
  				speed_template_32_40_48);
f3d1044cd   Rik Snel   [CRYPTO] tcrypt: ...
990
  		test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
991
  				speed_template_32_40_48);
f19f5111c   Rik Snel   [CRYPTO] xts: XTS...
992
  		test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
993
  				speed_template_32_48_64);
f19f5111c   Rik Snel   [CRYPTO] xts: XTS...
994
  		test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
995
  				speed_template_32_48_64);
9996e3421   Jan Glauber   crypto: tcrypt - ...
996
997
998
999
  		test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
  				speed_template_16_24_32);
  		test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
  				speed_template_16_24_32);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
1000
1001
1002
  		break;
  
  	case 201:
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1003
  		test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
da7f033dd   Herbert Xu   crypto: cryptomgr...
1004
  				des3_speed_template, DES3_SPEED_VECTORS,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1005
  				speed_template_24);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1006
  		test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
da7f033dd   Herbert Xu   crypto: cryptomgr...
1007
  				des3_speed_template, DES3_SPEED_VECTORS,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1008
  				speed_template_24);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1009
  		test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
da7f033dd   Herbert Xu   crypto: cryptomgr...
1010
  				des3_speed_template, DES3_SPEED_VECTORS,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1011
  				speed_template_24);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1012
  		test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
da7f033dd   Herbert Xu   crypto: cryptomgr...
1013
  				des3_speed_template, DES3_SPEED_VECTORS,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1014
  				speed_template_24);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
1015
1016
1017
  		break;
  
  	case 202:
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1018
  		test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1019
  				speed_template_16_24_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1020
  		test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1021
  				speed_template_16_24_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1022
  		test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1023
  				speed_template_16_24_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1024
  		test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1025
  				speed_template_16_24_32);
ee5002a54   Jussi Kivilinna   crypto: tcrypt - ...
1026
1027
1028
1029
  		test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
  				speed_template_16_24_32);
  		test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
  				speed_template_16_24_32);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
1030
1031
1032
  		break;
  
  	case 203:
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1033
  		test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1034
  				  speed_template_8_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1035
  		test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1036
  				  speed_template_8_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1037
  		test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1038
  				  speed_template_8_32);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1039
  		test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1040
  				  speed_template_8_32);
7d47b86cf   Jussi Kivilinna   crypto: tcrypt - ...
1041
1042
1043
1044
  		test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
  				  speed_template_8_32);
  		test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
  				  speed_template_8_32);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
1045
1046
1047
  		break;
  
  	case 204:
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1048
  		test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1049
  				  speed_template_8);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1050
  		test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1051
  				  speed_template_8);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1052
  		test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1053
  				  speed_template_8);
cba83564d   Herbert Xu   [CRYPTO] tcrypt: ...
1054
  		test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1055
  				  speed_template_8);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
1056
  		break;
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
1057
1058
  	case 205:
  		test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1059
  				speed_template_16_24_32);
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
1060
  		test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1061
  				speed_template_16_24_32);
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
1062
  		test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1063
  				speed_template_16_24_32);
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
1064
  		test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1065
  				speed_template_16_24_32);
02ab5a705   Noriaki TAKAMIYA   [CRYPTO] camellia...
1066
  		break;
5de8f1b56   Tan Swee Heng   [CRYPTO] tcrypt: ...
1067
1068
  	case 206:
  		test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
477035c2a   Sebastian Siewior   [CRYPTO] tcrypt: ...
1069
  				  speed_template_16_32);
5de8f1b56   Tan Swee Heng   [CRYPTO] tcrypt: ...
1070
  		break;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1071
1072
1073
1074
  	case 300:
  		/* fall through */
  
  	case 301:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1075
  		test_hash_speed("md4", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1076
1077
1078
  		if (mode > 300 && mode < 400) break;
  
  	case 302:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1079
  		test_hash_speed("md5", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1080
1081
1082
  		if (mode > 300 && mode < 400) break;
  
  	case 303:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1083
  		test_hash_speed("sha1", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1084
1085
1086
  		if (mode > 300 && mode < 400) break;
  
  	case 304:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1087
  		test_hash_speed("sha256", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1088
1089
1090
  		if (mode > 300 && mode < 400) break;
  
  	case 305:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1091
  		test_hash_speed("sha384", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1092
1093
1094
  		if (mode > 300 && mode < 400) break;
  
  	case 306:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1095
  		test_hash_speed("sha512", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1096
1097
1098
  		if (mode > 300 && mode < 400) break;
  
  	case 307:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1099
  		test_hash_speed("wp256", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1100
1101
1102
  		if (mode > 300 && mode < 400) break;
  
  	case 308:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1103
  		test_hash_speed("wp384", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1104
1105
1106
  		if (mode > 300 && mode < 400) break;
  
  	case 309:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1107
  		test_hash_speed("wp512", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1108
1109
1110
  		if (mode > 300 && mode < 400) break;
  
  	case 310:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1111
  		test_hash_speed("tgr128", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1112
1113
1114
  		if (mode > 300 && mode < 400) break;
  
  	case 311:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1115
  		test_hash_speed("tgr160", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1116
1117
1118
  		if (mode > 300 && mode < 400) break;
  
  	case 312:
e9d41164e   Herbert Xu   [CRYPTO] tcrypt: ...
1119
  		test_hash_speed("tgr192", sec, generic_hash_speed_template);
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1120
  		if (mode > 300 && mode < 400) break;
cd12fb906   Jonathan Lynch   [CRYPTO] sha256-g...
1121
1122
1123
  	case 313:
  		test_hash_speed("sha224", sec, generic_hash_speed_template);
  		if (mode > 300 && mode < 400) break;
fd4adf1a0   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
1124
1125
1126
1127
1128
1129
1130
  	case 314:
  		test_hash_speed("rmd128", sec, generic_hash_speed_template);
  		if (mode > 300 && mode < 400) break;
  
  	case 315:
  		test_hash_speed("rmd160", sec, generic_hash_speed_template);
  		if (mode > 300 && mode < 400) break;
2998db37b   Adrian-Ken Rueegsegger   [CRYPTO] tcrypt: ...
1131
1132
1133
1134
1135
1136
1137
  	case 316:
  		test_hash_speed("rmd256", sec, generic_hash_speed_template);
  		if (mode > 300 && mode < 400) break;
  
  	case 317:
  		test_hash_speed("rmd320", sec, generic_hash_speed_template);
  		if (mode > 300 && mode < 400) break;
18bcc9194   Huang Ying   crypto: tcrypt - ...
1138
1139
1140
  	case 318:
  		test_hash_speed("ghash-generic", sec, hash_speed_template_16);
  		if (mode > 300 && mode < 400) break;
e80579285   Michal Ludvig   [CRYPTO] tcrypt: ...
1141
1142
  	case 399:
  		break;
beb63da73   David S. Miller   crypto: tcrypt - ...
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
  	case 400:
  		/* fall through */
  
  	case 401:
  		test_ahash_speed("md4", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 402:
  		test_ahash_speed("md5", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 403:
  		test_ahash_speed("sha1", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 404:
  		test_ahash_speed("sha256", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 405:
  		test_ahash_speed("sha384", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 406:
  		test_ahash_speed("sha512", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 407:
  		test_ahash_speed("wp256", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 408:
  		test_ahash_speed("wp384", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 409:
  		test_ahash_speed("wp512", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 410:
  		test_ahash_speed("tgr128", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 411:
  		test_ahash_speed("tgr160", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 412:
  		test_ahash_speed("tgr192", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 413:
  		test_ahash_speed("sha224", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 414:
  		test_ahash_speed("rmd128", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 415:
  		test_ahash_speed("rmd160", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 416:
  		test_ahash_speed("rmd256", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 417:
  		test_ahash_speed("rmd320", sec, generic_hash_speed_template);
  		if (mode > 400 && mode < 500) break;
  
  	case 499:
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1216
1217
1218
  	case 1000:
  		test_available();
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1219
  	}
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
1220
1221
  
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1222
  }
7be380f72   Herbert Xu   crypto: tcrypt - ...
1223
  static int do_alg_test(const char *alg, u32 type, u32 mask)
a873a5f1c   Steffen Klassert   crypto: tcrypt - ...
1224
  {
7be380f72   Herbert Xu   crypto: tcrypt - ...
1225
1226
  	return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
  	       0 : -ENOENT;
a873a5f1c   Steffen Klassert   crypto: tcrypt - ...
1227
  }
3af5b90bd   Kamalesh Babulal   [CRYPTO] all: Cle...
1228
  static int __init tcrypt_mod_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1229
  {
e3a4ea4fd   Mikko Herranen   [CRYPTO] tcrypt: ...
1230
  	int err = -ENOMEM;
f139cfa7c   Herbert Xu   crypto: tcrypt - ...
1231
  	int i;
e3a4ea4fd   Mikko Herranen   [CRYPTO] tcrypt: ...
1232

f139cfa7c   Herbert Xu   crypto: tcrypt - ...
1233
1234
1235
1236
1237
  	for (i = 0; i < TVMEMSIZE; i++) {
  		tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
  		if (!tvmem[i])
  			goto err_free_tv;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1238

a873a5f1c   Steffen Klassert   crypto: tcrypt - ...
1239
  	if (alg)
7be380f72   Herbert Xu   crypto: tcrypt - ...
1240
  		err = do_alg_test(alg, type, mask);
a873a5f1c   Steffen Klassert   crypto: tcrypt - ...
1241
1242
  	else
  		err = do_test(mode);
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
1243
1244
1245
1246
1247
  	if (err) {
  		printk(KERN_ERR "tcrypt: one or more tests failed!
  ");
  		goto err_free_tv;
  	}
14fdf477a   Michal Ludvig   [CRYPTO] tcrypt: ...
1248

4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
1249
1250
1251
1252
  	/* We intentionaly return -EAGAIN to prevent keeping the module,
  	 * unless we're running in fips mode. It does all its work from
  	 * init() and doesn't offer any runtime functionality, but in
  	 * the fips case, checking for a successful load is helpful.
14fdf477a   Michal Ludvig   [CRYPTO] tcrypt: ...
1253
1254
1255
  	 * => we don't need it in the memory, do we?
  	 *                                        -- mludvig
  	 */
4e033a6bc   Jarod Wilson   crypto: tcrypt - ...
1256
1257
  	if (!fips_enabled)
  		err = -EAGAIN;
e3a4ea4fd   Mikko Herranen   [CRYPTO] tcrypt: ...
1258

f139cfa7c   Herbert Xu   crypto: tcrypt - ...
1259
1260
1261
  err_free_tv:
  	for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
  		free_page((unsigned long)tvmem[i]);
e3a4ea4fd   Mikko Herranen   [CRYPTO] tcrypt: ...
1262
1263
  
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1264
1265
1266
1267
1268
1269
  }
  
  /*
   * If an init function is provided, an exit function must also be provided
   * to allow module unload.
   */
3af5b90bd   Kamalesh Babulal   [CRYPTO] all: Cle...
1270
  static void __exit tcrypt_mod_fini(void) { }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1271

3af5b90bd   Kamalesh Babulal   [CRYPTO] all: Cle...
1272
1273
  module_init(tcrypt_mod_init);
  module_exit(tcrypt_mod_fini);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1274

a873a5f1c   Steffen Klassert   crypto: tcrypt - ...
1275
1276
  module_param(alg, charp, 0);
  module_param(type, uint, 0);
7be380f72   Herbert Xu   crypto: tcrypt - ...
1277
  module_param(mask, uint, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1278
  module_param(mode, int, 0);
ebfd9bcf1   Harald Welte   [CRYPTO]: Add cip...
1279
  module_param(sec, uint, 0);
6a17944ca   Herbert Xu   [CRYPTO]: Use CPU...
1280
1281
  MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
  		      "(defaults to zero which uses CPU cycles instead)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1282
1283
1284
1285
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("Quick & dirty crypto testing module");
  MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");