]>
Commit | Line | Data |
---|---|---|
ef2736fc | 1 | /* |
1da177e4 LT |
2 | * Quick & dirty crypto testing module. |
3 | * | |
4 | * This will only exist until we have a better testing mechanism | |
5 | * (e.g. a char device). | |
6 | * | |
7 | * Copyright (c) 2002 James Morris <[email protected]> | |
8 | * Copyright (c) 2002 Jean-Francois Dive <[email protected]> | |
e3a4ea4f | 9 | * Copyright (c) 2007 Nokia Siemens Networks |
1da177e4 LT |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the Free | |
ef2736fc | 13 | * Software Foundation; either version 2 of the License, or (at your option) |
1da177e4 LT |
14 | * any later version. |
15 | * | |
1da177e4 LT |
16 | */ |
17 | ||
18e33e6d | 18 | #include <crypto/hash.h> |
cba83564 | 19 | #include <linux/err.h> |
1da177e4 LT |
20 | #include <linux/init.h> |
21 | #include <linux/module.h> | |
1da177e4 | 22 | #include <linux/slab.h> |
378f058c | 23 | #include <linux/scatterlist.h> |
1da177e4 | 24 | #include <linux/string.h> |
1da177e4 | 25 | #include <linux/moduleparam.h> |
ebfd9bcf | 26 | #include <linux/jiffies.h> |
6a17944c HX |
27 | #include <linux/timex.h> |
28 | #include <linux/interrupt.h> | |
1da177e4 LT |
29 | #include "tcrypt.h" |
30 | ||
31 | /* | |
f139cfa7 | 32 | * Need slab memory for testing (size in number of pages). |
1da177e4 | 33 | */ |
f139cfa7 | 34 | #define TVMEMSIZE 4 |
1da177e4 LT |
35 | |
36 | /* | |
da7f033d | 37 | * Used by test_cipher_speed() |
1da177e4 LT |
38 | */ |
39 | #define ENCRYPT 1 | |
40 | #define DECRYPT 0 | |
1da177e4 | 41 | |
ebfd9bcf HW |
42 | /* |
43 | * Used by test_cipher_speed() | |
44 | */ | |
6a17944c | 45 | static unsigned int sec; |
ebfd9bcf | 46 | |
1da177e4 | 47 | static int mode; |
f139cfa7 | 48 | static char *tvmem[TVMEMSIZE]; |
1da177e4 LT |
49 | |
50 | static char *check[] = { | |
cd12fb90 JL |
51 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
52 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", | |
53 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | |
90831639 | 54 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
2998db37 | 55 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
0c01aed5 | 56 | "lzo", "cts", "zlib", NULL |
1da177e4 LT |
57 | }; |
58 | ||
f139cfa7 HX |
59 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, |
60 | struct scatterlist *sg, int blen, int sec) | |
6a17944c | 61 | { |
6a17944c HX |
62 | unsigned long start, end; |
63 | int bcount; | |
64 | int ret; | |
65 | ||
6a17944c HX |
66 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
67 | time_before(jiffies, end); bcount++) { | |
68 | if (enc) | |
cba83564 | 69 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 70 | else |
cba83564 | 71 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
72 | |
73 | if (ret) | |
74 | return ret; | |
75 | } | |
76 | ||
77 | printk("%d operations in %d seconds (%ld bytes)\n", | |
78 | bcount, sec, (long)bcount * blen); | |
79 | return 0; | |
80 | } | |
81 | ||
f139cfa7 HX |
82 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, |
83 | struct scatterlist *sg, int blen) | |
6a17944c | 84 | { |
6a17944c HX |
85 | unsigned long cycles = 0; |
86 | int ret = 0; | |
87 | int i; | |
88 | ||
6a17944c HX |
89 | local_bh_disable(); |
90 | local_irq_disable(); | |
91 | ||
92 | /* Warm-up run. */ | |
93 | for (i = 0; i < 4; i++) { | |
94 | if (enc) | |
cba83564 | 95 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 96 | else |
cba83564 | 97 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
98 | |
99 | if (ret) | |
100 | goto out; | |
101 | } | |
102 | ||
103 | /* The real thing. */ | |
104 | for (i = 0; i < 8; i++) { | |
105 | cycles_t start, end; | |
106 | ||
107 | start = get_cycles(); | |
108 | if (enc) | |
cba83564 | 109 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 110 | else |
cba83564 | 111 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
112 | end = get_cycles(); |
113 | ||
114 | if (ret) | |
115 | goto out; | |
116 | ||
117 | cycles += end - start; | |
118 | } | |
119 | ||
120 | out: | |
121 | local_irq_enable(); | |
122 | local_bh_enable(); | |
123 | ||
124 | if (ret == 0) | |
125 | printk("1 operation in %lu cycles (%d bytes)\n", | |
126 | (cycles + 4) / 8, blen); | |
127 | ||
128 | return ret; | |
129 | } | |
130 | ||
d5dc3927 SS |
131 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
132 | ||
01b32324 | 133 | static void test_cipher_speed(const char *algo, int enc, unsigned int sec, |
da7f033d | 134 | struct cipher_speed_template *template, |
d5dc3927 | 135 | unsigned int tcount, u8 *keysize) |
ebfd9bcf | 136 | { |
dce907c0 | 137 | unsigned int ret, i, j, iv_len; |
da7f033d | 138 | const char *key, iv[128]; |
cba83564 HX |
139 | struct crypto_blkcipher *tfm; |
140 | struct blkcipher_desc desc; | |
141 | const char *e; | |
d5dc3927 | 142 | u32 *b_size; |
ebfd9bcf HW |
143 | |
144 | if (enc == ENCRYPT) | |
145 | e = "encryption"; | |
146 | else | |
147 | e = "decryption"; | |
ebfd9bcf | 148 | |
cba83564 | 149 | printk("\ntesting speed of %s %s\n", algo, e); |
ebfd9bcf | 150 | |
cba83564 | 151 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
ebfd9bcf | 152 | |
cba83564 HX |
153 | if (IS_ERR(tfm)) { |
154 | printk("failed to load transform for %s: %ld\n", algo, | |
155 | PTR_ERR(tfm)); | |
ebfd9bcf HW |
156 | return; |
157 | } | |
cba83564 HX |
158 | desc.tfm = tfm; |
159 | desc.flags = 0; | |
ebfd9bcf | 160 | |
d5dc3927 SS |
161 | i = 0; |
162 | do { | |
ebfd9bcf | 163 | |
d5dc3927 SS |
164 | b_size = block_sizes; |
165 | do { | |
f139cfa7 | 166 | struct scatterlist sg[TVMEMSIZE]; |
ebfd9bcf | 167 | |
f139cfa7 HX |
168 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
169 | printk("template (%u) too big for " | |
170 | "tvmem (%lu)\n", *keysize + *b_size, | |
171 | TVMEMSIZE * PAGE_SIZE); | |
d5dc3927 SS |
172 | goto out; |
173 | } | |
ebfd9bcf | 174 | |
d5dc3927 SS |
175 | printk("test %u (%d bit key, %d byte blocks): ", i, |
176 | *keysize * 8, *b_size); | |
177 | ||
f139cfa7 | 178 | memset(tvmem[0], 0xff, PAGE_SIZE); |
d5dc3927 SS |
179 | |
180 | /* set key, plain text and IV */ | |
da7f033d | 181 | key = tvmem[0]; |
d5dc3927 SS |
182 | for (j = 0; j < tcount; j++) { |
183 | if (template[j].klen == *keysize) { | |
184 | key = template[j].key; | |
185 | break; | |
186 | } | |
dce907c0 | 187 | } |
ebfd9bcf | 188 | |
d5dc3927 SS |
189 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
190 | if (ret) { | |
191 | printk("setkey() failed flags=%x\n", | |
192 | crypto_blkcipher_get_flags(tfm)); | |
193 | goto out; | |
194 | } | |
ebfd9bcf | 195 | |
f139cfa7 HX |
196 | sg_init_table(sg, TVMEMSIZE); |
197 | sg_set_buf(sg, tvmem[0] + *keysize, | |
198 | PAGE_SIZE - *keysize); | |
199 | for (j = 1; j < TVMEMSIZE; j++) { | |
200 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); | |
201 | memset (tvmem[j], 0xff, PAGE_SIZE); | |
202 | } | |
203 | ||
d5dc3927 SS |
204 | iv_len = crypto_blkcipher_ivsize(tfm); |
205 | if (iv_len) { | |
206 | memset(&iv, 0xff, iv_len); | |
207 | crypto_blkcipher_set_iv(tfm, iv, iv_len); | |
208 | } | |
ebfd9bcf | 209 | |
d5dc3927 | 210 | if (sec) |
f139cfa7 HX |
211 | ret = test_cipher_jiffies(&desc, enc, sg, |
212 | *b_size, sec); | |
d5dc3927 | 213 | else |
f139cfa7 HX |
214 | ret = test_cipher_cycles(&desc, enc, sg, |
215 | *b_size); | |
ebfd9bcf | 216 | |
d5dc3927 SS |
217 | if (ret) { |
218 | printk("%s() failed flags=%x\n", e, desc.flags); | |
219 | break; | |
220 | } | |
221 | b_size++; | |
222 | i++; | |
223 | } while (*b_size); | |
224 | keysize++; | |
225 | } while (*keysize); | |
ebfd9bcf HW |
226 | |
227 | out: | |
cba83564 | 228 | crypto_free_blkcipher(tfm); |
ebfd9bcf HW |
229 | } |
230 | ||
f139cfa7 HX |
231 | static int test_hash_jiffies_digest(struct hash_desc *desc, |
232 | struct scatterlist *sg, int blen, | |
e9d41164 HX |
233 | char *out, int sec) |
234 | { | |
e9d41164 HX |
235 | unsigned long start, end; |
236 | int bcount; | |
237 | int ret; | |
238 | ||
239 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
240 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
241 | ret = crypto_hash_digest(desc, sg, blen, out); |
242 | if (ret) | |
243 | return ret; | |
244 | } | |
245 | ||
246 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
247 | bcount / sec, ((long)bcount * blen) / sec); | |
248 | ||
249 | return 0; | |
250 | } | |
251 | ||
f139cfa7 HX |
252 | static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg, |
253 | int blen, int plen, char *out, int sec) | |
e8057928 | 254 | { |
e8057928 ML |
255 | unsigned long start, end; |
256 | int bcount, pcount; | |
e9d41164 HX |
257 | int ret; |
258 | ||
259 | if (plen == blen) | |
f139cfa7 | 260 | return test_hash_jiffies_digest(desc, sg, blen, out, sec); |
a5a613a4 | 261 | |
e8057928 ML |
262 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
263 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
264 | ret = crypto_hash_init(desc); |
265 | if (ret) | |
266 | return ret; | |
e8057928 | 267 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
268 | ret = crypto_hash_update(desc, sg, plen); |
269 | if (ret) | |
270 | return ret; | |
e8057928 ML |
271 | } |
272 | /* we assume there is enough space in 'out' for the result */ | |
e9d41164 HX |
273 | ret = crypto_hash_final(desc, out); |
274 | if (ret) | |
275 | return ret; | |
e8057928 ML |
276 | } |
277 | ||
278 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
279 | bcount / sec, ((long)bcount * blen) / sec); | |
280 | ||
e9d41164 HX |
281 | return 0; |
282 | } | |
283 | ||
f139cfa7 HX |
284 | static int test_hash_cycles_digest(struct hash_desc *desc, |
285 | struct scatterlist *sg, int blen, char *out) | |
e9d41164 | 286 | { |
e9d41164 HX |
287 | unsigned long cycles = 0; |
288 | int i; | |
289 | int ret; | |
290 | ||
291 | local_bh_disable(); | |
292 | local_irq_disable(); | |
293 | ||
294 | /* Warm-up run. */ | |
295 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
296 | ret = crypto_hash_digest(desc, sg, blen, out); |
297 | if (ret) | |
298 | goto out; | |
299 | } | |
300 | ||
301 | /* The real thing. */ | |
302 | for (i = 0; i < 8; i++) { | |
303 | cycles_t start, end; | |
304 | ||
305 | start = get_cycles(); | |
306 | ||
e9d41164 HX |
307 | ret = crypto_hash_digest(desc, sg, blen, out); |
308 | if (ret) | |
309 | goto out; | |
310 | ||
311 | end = get_cycles(); | |
312 | ||
313 | cycles += end - start; | |
314 | } | |
315 | ||
316 | out: | |
317 | local_irq_enable(); | |
318 | local_bh_enable(); | |
319 | ||
320 | if (ret) | |
321 | return ret; | |
322 | ||
323 | printk("%6lu cycles/operation, %4lu cycles/byte\n", | |
324 | cycles / 8, cycles / (8 * blen)); | |
325 | ||
326 | return 0; | |
e8057928 ML |
327 | } |
328 | ||
f139cfa7 HX |
329 | static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg, |
330 | int blen, int plen, char *out) | |
e8057928 | 331 | { |
e8057928 ML |
332 | unsigned long cycles = 0; |
333 | int i, pcount; | |
e9d41164 HX |
334 | int ret; |
335 | ||
336 | if (plen == blen) | |
f139cfa7 | 337 | return test_hash_cycles_digest(desc, sg, blen, out); |
a5a613a4 | 338 | |
e8057928 ML |
339 | local_bh_disable(); |
340 | local_irq_disable(); | |
341 | ||
342 | /* Warm-up run. */ | |
343 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
344 | ret = crypto_hash_init(desc); |
345 | if (ret) | |
346 | goto out; | |
e8057928 | 347 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
348 | ret = crypto_hash_update(desc, sg, plen); |
349 | if (ret) | |
350 | goto out; | |
e8057928 | 351 | } |
29059d12 | 352 | ret = crypto_hash_final(desc, out); |
e9d41164 HX |
353 | if (ret) |
354 | goto out; | |
e8057928 ML |
355 | } |
356 | ||
357 | /* The real thing. */ | |
358 | for (i = 0; i < 8; i++) { | |
359 | cycles_t start, end; | |
360 | ||
e8057928 ML |
361 | start = get_cycles(); |
362 | ||
e9d41164 HX |
363 | ret = crypto_hash_init(desc); |
364 | if (ret) | |
365 | goto out; | |
e8057928 | 366 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
367 | ret = crypto_hash_update(desc, sg, plen); |
368 | if (ret) | |
369 | goto out; | |
e8057928 | 370 | } |
e9d41164 HX |
371 | ret = crypto_hash_final(desc, out); |
372 | if (ret) | |
373 | goto out; | |
e8057928 ML |
374 | |
375 | end = get_cycles(); | |
376 | ||
377 | cycles += end - start; | |
378 | } | |
379 | ||
e9d41164 | 380 | out: |
e8057928 ML |
381 | local_irq_enable(); |
382 | local_bh_enable(); | |
383 | ||
e9d41164 HX |
384 | if (ret) |
385 | return ret; | |
386 | ||
e8057928 ML |
387 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
388 | cycles / 8, cycles / (8 * blen)); | |
389 | ||
e9d41164 | 390 | return 0; |
e8057928 ML |
391 | } |
392 | ||
01b32324 HX |
393 | static void test_hash_speed(const char *algo, unsigned int sec, |
394 | struct hash_speed *speed) | |
e8057928 | 395 | { |
f139cfa7 | 396 | struct scatterlist sg[TVMEMSIZE]; |
e9d41164 HX |
397 | struct crypto_hash *tfm; |
398 | struct hash_desc desc; | |
e8057928 ML |
399 | char output[1024]; |
400 | int i; | |
e9d41164 | 401 | int ret; |
e8057928 ML |
402 | |
403 | printk("\ntesting speed of %s\n", algo); | |
404 | ||
e9d41164 | 405 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
e8057928 | 406 | |
e9d41164 HX |
407 | if (IS_ERR(tfm)) { |
408 | printk("failed to load transform for %s: %ld\n", algo, | |
409 | PTR_ERR(tfm)); | |
e8057928 ML |
410 | return; |
411 | } | |
412 | ||
e9d41164 HX |
413 | desc.tfm = tfm; |
414 | desc.flags = 0; | |
415 | ||
416 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { | |
e8057928 | 417 | printk("digestsize(%u) > outputbuffer(%zu)\n", |
e9d41164 | 418 | crypto_hash_digestsize(tfm), sizeof(output)); |
e8057928 ML |
419 | goto out; |
420 | } | |
421 | ||
f139cfa7 HX |
422 | sg_init_table(sg, TVMEMSIZE); |
423 | for (i = 0; i < TVMEMSIZE; i++) { | |
424 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); | |
425 | memset(tvmem[i], 0xff, PAGE_SIZE); | |
426 | } | |
427 | ||
e8057928 | 428 | for (i = 0; speed[i].blen != 0; i++) { |
f139cfa7 HX |
429 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
430 | printk("template (%u) too big for tvmem (%lu)\n", | |
431 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); | |
e8057928 ML |
432 | goto out; |
433 | } | |
434 | ||
435 | printk("test%3u (%5u byte blocks,%5u bytes per update,%4u updates): ", | |
436 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); | |
437 | ||
e8057928 | 438 | if (sec) |
f139cfa7 | 439 | ret = test_hash_jiffies(&desc, sg, speed[i].blen, |
e9d41164 | 440 | speed[i].plen, output, sec); |
e8057928 | 441 | else |
f139cfa7 | 442 | ret = test_hash_cycles(&desc, sg, speed[i].blen, |
e9d41164 HX |
443 | speed[i].plen, output); |
444 | ||
445 | if (ret) { | |
446 | printk("hashing failed ret=%d\n", ret); | |
447 | break; | |
448 | } | |
e8057928 ML |
449 | } |
450 | ||
451 | out: | |
e9d41164 | 452 | crypto_free_hash(tfm); |
e8057928 ML |
453 | } |
454 | ||
ef2736fc | 455 | static void test_available(void) |
1da177e4 LT |
456 | { |
457 | char **name = check; | |
ef2736fc | 458 | |
1da177e4 LT |
459 | while (*name) { |
460 | printk("alg %s ", *name); | |
6158efc0 | 461 | printk(crypto_has_alg(*name, 0, 0) ? |
e4d5b79c | 462 | "found\n" : "not found\n"); |
1da177e4 | 463 | name++; |
ef2736fc | 464 | } |
1da177e4 LT |
465 | } |
466 | ||
01b32324 HX |
467 | static inline int tcrypt_test(const char *alg) |
468 | { | |
469 | return alg_test(alg, alg, 0, 0); | |
470 | } | |
471 | ||
472 | static void do_test(int m) | |
473 | { | |
474 | int i; | |
475 | ||
476 | switch (m) { | |
1da177e4 | 477 | case 0: |
01b32324 HX |
478 | for (i = 1; i < 200; i++) |
479 | do_test(i); | |
1da177e4 LT |
480 | break; |
481 | ||
482 | case 1: | |
01b32324 | 483 | tcrypt_test("md5"); |
1da177e4 LT |
484 | break; |
485 | ||
486 | case 2: | |
01b32324 | 487 | tcrypt_test("sha1"); |
1da177e4 LT |
488 | break; |
489 | ||
490 | case 3: | |
01b32324 HX |
491 | tcrypt_test("ecb(des)"); |
492 | tcrypt_test("cbc(des)"); | |
1da177e4 LT |
493 | break; |
494 | ||
495 | case 4: | |
01b32324 HX |
496 | tcrypt_test("ecb(des3_ede)"); |
497 | tcrypt_test("cbc(des3_ede)"); | |
1da177e4 LT |
498 | break; |
499 | ||
500 | case 5: | |
01b32324 | 501 | tcrypt_test("md4"); |
1da177e4 | 502 | break; |
ef2736fc | 503 | |
1da177e4 | 504 | case 6: |
01b32324 | 505 | tcrypt_test("sha256"); |
1da177e4 | 506 | break; |
ef2736fc | 507 | |
1da177e4 | 508 | case 7: |
01b32324 HX |
509 | tcrypt_test("ecb(blowfish)"); |
510 | tcrypt_test("cbc(blowfish)"); | |
1da177e4 LT |
511 | break; |
512 | ||
513 | case 8: | |
01b32324 HX |
514 | tcrypt_test("ecb(twofish)"); |
515 | tcrypt_test("cbc(twofish)"); | |
1da177e4 | 516 | break; |
ef2736fc | 517 | |
1da177e4 | 518 | case 9: |
01b32324 | 519 | tcrypt_test("ecb(serpent)"); |
1da177e4 LT |
520 | break; |
521 | ||
522 | case 10: | |
01b32324 HX |
523 | tcrypt_test("ecb(aes)"); |
524 | tcrypt_test("cbc(aes)"); | |
525 | tcrypt_test("lrw(aes)"); | |
526 | tcrypt_test("xts(aes)"); | |
527 | tcrypt_test("rfc3686(ctr(aes))"); | |
1da177e4 LT |
528 | break; |
529 | ||
530 | case 11: | |
01b32324 | 531 | tcrypt_test("sha384"); |
1da177e4 | 532 | break; |
ef2736fc | 533 | |
1da177e4 | 534 | case 12: |
01b32324 | 535 | tcrypt_test("sha512"); |
1da177e4 LT |
536 | break; |
537 | ||
538 | case 13: | |
01b32324 | 539 | tcrypt_test("deflate"); |
1da177e4 LT |
540 | break; |
541 | ||
542 | case 14: | |
01b32324 | 543 | tcrypt_test("ecb(cast5)"); |
1da177e4 LT |
544 | break; |
545 | ||
546 | case 15: | |
01b32324 | 547 | tcrypt_test("ecb(cast6)"); |
1da177e4 LT |
548 | break; |
549 | ||
550 | case 16: | |
01b32324 | 551 | tcrypt_test("ecb(arc4)"); |
1da177e4 LT |
552 | break; |
553 | ||
554 | case 17: | |
01b32324 | 555 | tcrypt_test("michael_mic"); |
1da177e4 LT |
556 | break; |
557 | ||
558 | case 18: | |
01b32324 | 559 | tcrypt_test("crc32c"); |
1da177e4 LT |
560 | break; |
561 | ||
562 | case 19: | |
01b32324 | 563 | tcrypt_test("ecb(tea)"); |
1da177e4 LT |
564 | break; |
565 | ||
566 | case 20: | |
01b32324 | 567 | tcrypt_test("ecb(xtea)"); |
1da177e4 LT |
568 | break; |
569 | ||
570 | case 21: | |
01b32324 | 571 | tcrypt_test("ecb(khazad)"); |
1da177e4 LT |
572 | break; |
573 | ||
574 | case 22: | |
01b32324 | 575 | tcrypt_test("wp512"); |
1da177e4 LT |
576 | break; |
577 | ||
578 | case 23: | |
01b32324 | 579 | tcrypt_test("wp384"); |
1da177e4 LT |
580 | break; |
581 | ||
582 | case 24: | |
01b32324 | 583 | tcrypt_test("wp256"); |
1da177e4 LT |
584 | break; |
585 | ||
586 | case 25: | |
01b32324 | 587 | tcrypt_test("ecb(tnepres)"); |
1da177e4 LT |
588 | break; |
589 | ||
590 | case 26: | |
01b32324 HX |
591 | tcrypt_test("ecb(anubis)"); |
592 | tcrypt_test("cbc(anubis)"); | |
1da177e4 LT |
593 | break; |
594 | ||
595 | case 27: | |
01b32324 | 596 | tcrypt_test("tgr192"); |
1da177e4 LT |
597 | break; |
598 | ||
599 | case 28: | |
600 | ||
01b32324 | 601 | tcrypt_test("tgr160"); |
1da177e4 LT |
602 | break; |
603 | ||
604 | case 29: | |
01b32324 | 605 | tcrypt_test("tgr128"); |
1da177e4 | 606 | break; |
2998db37 | 607 | |
fb4f10ed | 608 | case 30: |
01b32324 | 609 | tcrypt_test("ecb(xeta)"); |
fb4f10ed | 610 | break; |
1da177e4 | 611 | |
90831639 | 612 | case 31: |
01b32324 | 613 | tcrypt_test("pcbc(fcrypt)"); |
90831639 DH |
614 | break; |
615 | ||
02ab5a70 | 616 | case 32: |
01b32324 HX |
617 | tcrypt_test("ecb(camellia)"); |
618 | tcrypt_test("cbc(camellia)"); | |
02ab5a70 | 619 | break; |
cd12fb90 | 620 | case 33: |
01b32324 | 621 | tcrypt_test("sha224"); |
cd12fb90 | 622 | break; |
02ab5a70 | 623 | |
2407d608 | 624 | case 34: |
01b32324 | 625 | tcrypt_test("salsa20"); |
2407d608 TSH |
626 | break; |
627 | ||
8df213d9 | 628 | case 35: |
01b32324 | 629 | tcrypt_test("gcm(aes)"); |
8df213d9 HX |
630 | break; |
631 | ||
0b77abb3 | 632 | case 36: |
01b32324 | 633 | tcrypt_test("lzo"); |
0b77abb3 ZS |
634 | break; |
635 | ||
93cc74e0 | 636 | case 37: |
01b32324 | 637 | tcrypt_test("ccm(aes)"); |
93cc74e0 JL |
638 | break; |
639 | ||
76cb9521 | 640 | case 38: |
01b32324 | 641 | tcrypt_test("cts(cbc(aes))"); |
76cb9521 KC |
642 | break; |
643 | ||
fd4adf1a | 644 | case 39: |
01b32324 | 645 | tcrypt_test("rmd128"); |
fd4adf1a AKR |
646 | break; |
647 | ||
648 | case 40: | |
01b32324 | 649 | tcrypt_test("rmd160"); |
fd4adf1a AKR |
650 | break; |
651 | ||
2998db37 | 652 | case 41: |
01b32324 | 653 | tcrypt_test("rmd256"); |
2998db37 AKR |
654 | break; |
655 | ||
656 | case 42: | |
01b32324 HX |
657 | tcrypt_test("rmd320"); |
658 | break; | |
659 | ||
660 | case 43: | |
661 | tcrypt_test("ecb(seed)"); | |
2998db37 AKR |
662 | break; |
663 | ||
0c01aed5 GU |
664 | case 44: |
665 | tcrypt_test("zlib"); | |
666 | break; | |
667 | ||
1da177e4 | 668 | case 100: |
01b32324 | 669 | tcrypt_test("hmac(md5)"); |
1da177e4 | 670 | break; |
ef2736fc | 671 | |
1da177e4 | 672 | case 101: |
01b32324 | 673 | tcrypt_test("hmac(sha1)"); |
1da177e4 | 674 | break; |
ef2736fc | 675 | |
1da177e4 | 676 | case 102: |
01b32324 | 677 | tcrypt_test("hmac(sha256)"); |
1da177e4 LT |
678 | break; |
679 | ||
a28091ae | 680 | case 103: |
01b32324 | 681 | tcrypt_test("hmac(sha384)"); |
a28091ae AD |
682 | break; |
683 | ||
684 | case 104: | |
01b32324 | 685 | tcrypt_test("hmac(sha512)"); |
a28091ae | 686 | break; |
38ed9ab2 | 687 | |
cd12fb90 | 688 | case 105: |
01b32324 | 689 | tcrypt_test("hmac(sha224)"); |
cd12fb90 | 690 | break; |
1da177e4 | 691 | |
38ed9ab2 | 692 | case 106: |
01b32324 | 693 | tcrypt_test("xcbc(aes)"); |
38ed9ab2 HX |
694 | break; |
695 | ||
fd4adf1a | 696 | case 107: |
01b32324 | 697 | tcrypt_test("hmac(rmd128)"); |
fd4adf1a AKR |
698 | break; |
699 | ||
700 | case 108: | |
01b32324 | 701 | tcrypt_test("hmac(rmd160)"); |
fd4adf1a AKR |
702 | break; |
703 | ||
ebfd9bcf | 704 | case 200: |
cba83564 | 705 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 706 | speed_template_16_24_32); |
cba83564 | 707 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 708 | speed_template_16_24_32); |
cba83564 | 709 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 710 | speed_template_16_24_32); |
cba83564 | 711 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 712 | speed_template_16_24_32); |
f3d1044c | 713 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 714 | speed_template_32_40_48); |
f3d1044c | 715 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 716 | speed_template_32_40_48); |
f19f5111 | 717 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 718 | speed_template_32_48_64); |
f19f5111 | 719 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 720 | speed_template_32_48_64); |
ebfd9bcf HW |
721 | break; |
722 | ||
723 | case 201: | |
cba83564 | 724 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
da7f033d | 725 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 726 | speed_template_24); |
cba83564 | 727 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
da7f033d | 728 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 729 | speed_template_24); |
cba83564 | 730 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
da7f033d | 731 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 732 | speed_template_24); |
cba83564 | 733 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
da7f033d | 734 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 735 | speed_template_24); |
ebfd9bcf HW |
736 | break; |
737 | ||
738 | case 202: | |
cba83564 | 739 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 740 | speed_template_16_24_32); |
cba83564 | 741 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 742 | speed_template_16_24_32); |
cba83564 | 743 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 744 | speed_template_16_24_32); |
cba83564 | 745 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 746 | speed_template_16_24_32); |
ebfd9bcf HW |
747 | break; |
748 | ||
749 | case 203: | |
cba83564 | 750 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 751 | speed_template_8_32); |
cba83564 | 752 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 753 | speed_template_8_32); |
cba83564 | 754 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 755 | speed_template_8_32); |
cba83564 | 756 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 757 | speed_template_8_32); |
ebfd9bcf HW |
758 | break; |
759 | ||
760 | case 204: | |
cba83564 | 761 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 762 | speed_template_8); |
cba83564 | 763 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 764 | speed_template_8); |
cba83564 | 765 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 766 | speed_template_8); |
cba83564 | 767 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 768 | speed_template_8); |
ebfd9bcf HW |
769 | break; |
770 | ||
02ab5a70 NT |
771 | case 205: |
772 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, | |
477035c2 | 773 | speed_template_16_24_32); |
02ab5a70 | 774 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 775 | speed_template_16_24_32); |
02ab5a70 | 776 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
477035c2 | 777 | speed_template_16_24_32); |
02ab5a70 | 778 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 779 | speed_template_16_24_32); |
02ab5a70 NT |
780 | break; |
781 | ||
5de8f1b5 TSH |
782 | case 206: |
783 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, | |
477035c2 | 784 | speed_template_16_32); |
5de8f1b5 TSH |
785 | break; |
786 | ||
e8057928 ML |
787 | case 300: |
788 | /* fall through */ | |
789 | ||
790 | case 301: | |
e9d41164 | 791 | test_hash_speed("md4", sec, generic_hash_speed_template); |
e8057928 ML |
792 | if (mode > 300 && mode < 400) break; |
793 | ||
794 | case 302: | |
e9d41164 | 795 | test_hash_speed("md5", sec, generic_hash_speed_template); |
e8057928 ML |
796 | if (mode > 300 && mode < 400) break; |
797 | ||
798 | case 303: | |
e9d41164 | 799 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
e8057928 ML |
800 | if (mode > 300 && mode < 400) break; |
801 | ||
802 | case 304: | |
e9d41164 | 803 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
e8057928 ML |
804 | if (mode > 300 && mode < 400) break; |
805 | ||
806 | case 305: | |
e9d41164 | 807 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
e8057928 ML |
808 | if (mode > 300 && mode < 400) break; |
809 | ||
810 | case 306: | |
e9d41164 | 811 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
e8057928 ML |
812 | if (mode > 300 && mode < 400) break; |
813 | ||
814 | case 307: | |
e9d41164 | 815 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
e8057928 ML |
816 | if (mode > 300 && mode < 400) break; |
817 | ||
818 | case 308: | |
e9d41164 | 819 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
e8057928 ML |
820 | if (mode > 300 && mode < 400) break; |
821 | ||
822 | case 309: | |
e9d41164 | 823 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
e8057928 ML |
824 | if (mode > 300 && mode < 400) break; |
825 | ||
826 | case 310: | |
e9d41164 | 827 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
e8057928 ML |
828 | if (mode > 300 && mode < 400) break; |
829 | ||
830 | case 311: | |
e9d41164 | 831 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
e8057928 ML |
832 | if (mode > 300 && mode < 400) break; |
833 | ||
834 | case 312: | |
e9d41164 | 835 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
e8057928 ML |
836 | if (mode > 300 && mode < 400) break; |
837 | ||
cd12fb90 JL |
838 | case 313: |
839 | test_hash_speed("sha224", sec, generic_hash_speed_template); | |
840 | if (mode > 300 && mode < 400) break; | |
841 | ||
fd4adf1a AKR |
842 | case 314: |
843 | test_hash_speed("rmd128", sec, generic_hash_speed_template); | |
844 | if (mode > 300 && mode < 400) break; | |
845 | ||
846 | case 315: | |
847 | test_hash_speed("rmd160", sec, generic_hash_speed_template); | |
848 | if (mode > 300 && mode < 400) break; | |
849 | ||
2998db37 AKR |
850 | case 316: |
851 | test_hash_speed("rmd256", sec, generic_hash_speed_template); | |
852 | if (mode > 300 && mode < 400) break; | |
853 | ||
854 | case 317: | |
855 | test_hash_speed("rmd320", sec, generic_hash_speed_template); | |
856 | if (mode > 300 && mode < 400) break; | |
857 | ||
e8057928 ML |
858 | case 399: |
859 | break; | |
860 | ||
1da177e4 LT |
861 | case 1000: |
862 | test_available(); | |
863 | break; | |
1da177e4 LT |
864 | } |
865 | } | |
866 | ||
3af5b90b | 867 | static int __init tcrypt_mod_init(void) |
1da177e4 | 868 | { |
e3a4ea4f | 869 | int err = -ENOMEM; |
f139cfa7 | 870 | int i; |
e3a4ea4f | 871 | |
f139cfa7 HX |
872 | for (i = 0; i < TVMEMSIZE; i++) { |
873 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); | |
874 | if (!tvmem[i]) | |
875 | goto err_free_tv; | |
876 | } | |
1da177e4 | 877 | |
01b32324 | 878 | do_test(mode); |
14fdf477 ML |
879 | |
880 | /* We intentionaly return -EAGAIN to prevent keeping | |
881 | * the module. It does all its work from init() | |
882 | * and doesn't offer any runtime functionality | |
883 | * => we don't need it in the memory, do we? | |
884 | * -- mludvig | |
885 | */ | |
e3a4ea4f MH |
886 | err = -EAGAIN; |
887 | ||
f139cfa7 HX |
888 | err_free_tv: |
889 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) | |
890 | free_page((unsigned long)tvmem[i]); | |
e3a4ea4f MH |
891 | |
892 | return err; | |
1da177e4 LT |
893 | } |
894 | ||
895 | /* | |
896 | * If an init function is provided, an exit function must also be provided | |
897 | * to allow module unload. | |
898 | */ | |
3af5b90b | 899 | static void __exit tcrypt_mod_fini(void) { } |
1da177e4 | 900 | |
3af5b90b KB |
901 | module_init(tcrypt_mod_init); |
902 | module_exit(tcrypt_mod_fini); | |
1da177e4 LT |
903 | |
904 | module_param(mode, int, 0); | |
ebfd9bcf | 905 | module_param(sec, uint, 0); |
6a17944c HX |
906 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
907 | "(defaults to zero which uses CPU cycles instead)"); | |
1da177e4 LT |
908 | |
909 | MODULE_LICENSE("GPL"); | |
910 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | |
911 | MODULE_AUTHOR("James Morris <[email protected]>"); |