]>
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 | 20 | #include <linux/init.h> |
5a0e3ad6 | 21 | #include <linux/gfp.h> |
1da177e4 | 22 | #include <linux/module.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 | 29 | #include "tcrypt.h" |
4e033a6b | 30 | #include "internal.h" |
1da177e4 LT |
31 | |
32 | /* | |
f139cfa7 | 33 | * Need slab memory for testing (size in number of pages). |
1da177e4 | 34 | */ |
f139cfa7 | 35 | #define TVMEMSIZE 4 |
1da177e4 LT |
36 | |
37 | /* | |
da7f033d | 38 | * Used by test_cipher_speed() |
1da177e4 LT |
39 | */ |
40 | #define ENCRYPT 1 | |
41 | #define DECRYPT 0 | |
1da177e4 | 42 | |
ebfd9bcf HW |
43 | /* |
44 | * Used by test_cipher_speed() | |
45 | */ | |
6a17944c | 46 | static unsigned int sec; |
ebfd9bcf | 47 | |
a873a5f1 SK |
48 | static char *alg = NULL; |
49 | static u32 type; | |
7be380f7 | 50 | static u32 mask; |
1da177e4 | 51 | static int mode; |
f139cfa7 | 52 | static char *tvmem[TVMEMSIZE]; |
1da177e4 LT |
53 | |
54 | static char *check[] = { | |
cd12fb90 JL |
55 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
56 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", | |
57 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | |
90831639 | 58 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
2998db37 | 59 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
0c01aed5 | 60 | "lzo", "cts", "zlib", NULL |
1da177e4 LT |
61 | }; |
62 | ||
f139cfa7 HX |
63 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, |
64 | struct scatterlist *sg, int blen, int sec) | |
6a17944c | 65 | { |
6a17944c HX |
66 | unsigned long start, end; |
67 | int bcount; | |
68 | int ret; | |
69 | ||
6a17944c HX |
70 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
71 | time_before(jiffies, end); bcount++) { | |
72 | if (enc) | |
cba83564 | 73 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 74 | else |
cba83564 | 75 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
76 | |
77 | if (ret) | |
78 | return ret; | |
79 | } | |
80 | ||
81 | printk("%d operations in %d seconds (%ld bytes)\n", | |
82 | bcount, sec, (long)bcount * blen); | |
83 | return 0; | |
84 | } | |
85 | ||
f139cfa7 HX |
86 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, |
87 | struct scatterlist *sg, int blen) | |
6a17944c | 88 | { |
6a17944c HX |
89 | unsigned long cycles = 0; |
90 | int ret = 0; | |
91 | int i; | |
92 | ||
6a17944c HX |
93 | local_bh_disable(); |
94 | local_irq_disable(); | |
95 | ||
96 | /* Warm-up run. */ | |
97 | for (i = 0; i < 4; i++) { | |
98 | if (enc) | |
cba83564 | 99 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 100 | else |
cba83564 | 101 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
102 | |
103 | if (ret) | |
104 | goto out; | |
105 | } | |
106 | ||
107 | /* The real thing. */ | |
108 | for (i = 0; i < 8; i++) { | |
109 | cycles_t start, end; | |
110 | ||
111 | start = get_cycles(); | |
112 | if (enc) | |
cba83564 | 113 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 114 | else |
cba83564 | 115 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
116 | end = get_cycles(); |
117 | ||
118 | if (ret) | |
119 | goto out; | |
120 | ||
121 | cycles += end - start; | |
122 | } | |
123 | ||
124 | out: | |
125 | local_irq_enable(); | |
126 | local_bh_enable(); | |
127 | ||
128 | if (ret == 0) | |
129 | printk("1 operation in %lu cycles (%d bytes)\n", | |
130 | (cycles + 4) / 8, blen); | |
131 | ||
132 | return ret; | |
133 | } | |
134 | ||
d5dc3927 SS |
135 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
136 | ||
01b32324 | 137 | static void test_cipher_speed(const char *algo, int enc, unsigned int sec, |
da7f033d | 138 | struct cipher_speed_template *template, |
d5dc3927 | 139 | unsigned int tcount, u8 *keysize) |
ebfd9bcf | 140 | { |
dce907c0 | 141 | unsigned int ret, i, j, iv_len; |
da7f033d | 142 | const char *key, iv[128]; |
cba83564 HX |
143 | struct crypto_blkcipher *tfm; |
144 | struct blkcipher_desc desc; | |
145 | const char *e; | |
d5dc3927 | 146 | u32 *b_size; |
ebfd9bcf HW |
147 | |
148 | if (enc == ENCRYPT) | |
149 | e = "encryption"; | |
150 | else | |
151 | e = "decryption"; | |
ebfd9bcf | 152 | |
cba83564 | 153 | printk("\ntesting speed of %s %s\n", algo, e); |
ebfd9bcf | 154 | |
cba83564 | 155 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
ebfd9bcf | 156 | |
cba83564 HX |
157 | if (IS_ERR(tfm)) { |
158 | printk("failed to load transform for %s: %ld\n", algo, | |
159 | PTR_ERR(tfm)); | |
ebfd9bcf HW |
160 | return; |
161 | } | |
cba83564 HX |
162 | desc.tfm = tfm; |
163 | desc.flags = 0; | |
ebfd9bcf | 164 | |
d5dc3927 SS |
165 | i = 0; |
166 | do { | |
ebfd9bcf | 167 | |
d5dc3927 SS |
168 | b_size = block_sizes; |
169 | do { | |
f139cfa7 | 170 | struct scatterlist sg[TVMEMSIZE]; |
ebfd9bcf | 171 | |
f139cfa7 HX |
172 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
173 | printk("template (%u) too big for " | |
174 | "tvmem (%lu)\n", *keysize + *b_size, | |
175 | TVMEMSIZE * PAGE_SIZE); | |
d5dc3927 SS |
176 | goto out; |
177 | } | |
ebfd9bcf | 178 | |
d5dc3927 SS |
179 | printk("test %u (%d bit key, %d byte blocks): ", i, |
180 | *keysize * 8, *b_size); | |
181 | ||
f139cfa7 | 182 | memset(tvmem[0], 0xff, PAGE_SIZE); |
d5dc3927 SS |
183 | |
184 | /* set key, plain text and IV */ | |
da7f033d | 185 | key = tvmem[0]; |
d5dc3927 SS |
186 | for (j = 0; j < tcount; j++) { |
187 | if (template[j].klen == *keysize) { | |
188 | key = template[j].key; | |
189 | break; | |
190 | } | |
dce907c0 | 191 | } |
ebfd9bcf | 192 | |
d5dc3927 SS |
193 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
194 | if (ret) { | |
195 | printk("setkey() failed flags=%x\n", | |
196 | crypto_blkcipher_get_flags(tfm)); | |
197 | goto out; | |
198 | } | |
ebfd9bcf | 199 | |
f139cfa7 HX |
200 | sg_init_table(sg, TVMEMSIZE); |
201 | sg_set_buf(sg, tvmem[0] + *keysize, | |
202 | PAGE_SIZE - *keysize); | |
203 | for (j = 1; j < TVMEMSIZE; j++) { | |
204 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); | |
205 | memset (tvmem[j], 0xff, PAGE_SIZE); | |
206 | } | |
207 | ||
d5dc3927 SS |
208 | iv_len = crypto_blkcipher_ivsize(tfm); |
209 | if (iv_len) { | |
210 | memset(&iv, 0xff, iv_len); | |
211 | crypto_blkcipher_set_iv(tfm, iv, iv_len); | |
212 | } | |
ebfd9bcf | 213 | |
d5dc3927 | 214 | if (sec) |
f139cfa7 HX |
215 | ret = test_cipher_jiffies(&desc, enc, sg, |
216 | *b_size, sec); | |
d5dc3927 | 217 | else |
f139cfa7 HX |
218 | ret = test_cipher_cycles(&desc, enc, sg, |
219 | *b_size); | |
ebfd9bcf | 220 | |
d5dc3927 SS |
221 | if (ret) { |
222 | printk("%s() failed flags=%x\n", e, desc.flags); | |
223 | break; | |
224 | } | |
225 | b_size++; | |
226 | i++; | |
227 | } while (*b_size); | |
228 | keysize++; | |
229 | } while (*keysize); | |
ebfd9bcf HW |
230 | |
231 | out: | |
cba83564 | 232 | crypto_free_blkcipher(tfm); |
ebfd9bcf HW |
233 | } |
234 | ||
f139cfa7 HX |
235 | static int test_hash_jiffies_digest(struct hash_desc *desc, |
236 | struct scatterlist *sg, int blen, | |
e9d41164 HX |
237 | char *out, int sec) |
238 | { | |
e9d41164 HX |
239 | unsigned long start, end; |
240 | int bcount; | |
241 | int ret; | |
242 | ||
243 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
244 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
245 | ret = crypto_hash_digest(desc, sg, blen, out); |
246 | if (ret) | |
247 | return ret; | |
248 | } | |
249 | ||
250 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
251 | bcount / sec, ((long)bcount * blen) / sec); | |
252 | ||
253 | return 0; | |
254 | } | |
255 | ||
f139cfa7 HX |
256 | static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg, |
257 | int blen, int plen, char *out, int sec) | |
e8057928 | 258 | { |
e8057928 ML |
259 | unsigned long start, end; |
260 | int bcount, pcount; | |
e9d41164 HX |
261 | int ret; |
262 | ||
263 | if (plen == blen) | |
f139cfa7 | 264 | return test_hash_jiffies_digest(desc, sg, blen, out, sec); |
a5a613a4 | 265 | |
e8057928 ML |
266 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
267 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
268 | ret = crypto_hash_init(desc); |
269 | if (ret) | |
270 | return ret; | |
e8057928 | 271 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
272 | ret = crypto_hash_update(desc, sg, plen); |
273 | if (ret) | |
274 | return ret; | |
e8057928 ML |
275 | } |
276 | /* we assume there is enough space in 'out' for the result */ | |
e9d41164 HX |
277 | ret = crypto_hash_final(desc, out); |
278 | if (ret) | |
279 | return ret; | |
e8057928 ML |
280 | } |
281 | ||
282 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
283 | bcount / sec, ((long)bcount * blen) / sec); | |
284 | ||
e9d41164 HX |
285 | return 0; |
286 | } | |
287 | ||
f139cfa7 HX |
288 | static int test_hash_cycles_digest(struct hash_desc *desc, |
289 | struct scatterlist *sg, int blen, char *out) | |
e9d41164 | 290 | { |
e9d41164 HX |
291 | unsigned long cycles = 0; |
292 | int i; | |
293 | int ret; | |
294 | ||
295 | local_bh_disable(); | |
296 | local_irq_disable(); | |
297 | ||
298 | /* Warm-up run. */ | |
299 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
300 | ret = crypto_hash_digest(desc, sg, blen, out); |
301 | if (ret) | |
302 | goto out; | |
303 | } | |
304 | ||
305 | /* The real thing. */ | |
306 | for (i = 0; i < 8; i++) { | |
307 | cycles_t start, end; | |
308 | ||
309 | start = get_cycles(); | |
310 | ||
e9d41164 HX |
311 | ret = crypto_hash_digest(desc, sg, blen, out); |
312 | if (ret) | |
313 | goto out; | |
314 | ||
315 | end = get_cycles(); | |
316 | ||
317 | cycles += end - start; | |
318 | } | |
319 | ||
320 | out: | |
321 | local_irq_enable(); | |
322 | local_bh_enable(); | |
323 | ||
324 | if (ret) | |
325 | return ret; | |
326 | ||
327 | printk("%6lu cycles/operation, %4lu cycles/byte\n", | |
328 | cycles / 8, cycles / (8 * blen)); | |
329 | ||
330 | return 0; | |
e8057928 ML |
331 | } |
332 | ||
f139cfa7 HX |
333 | static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg, |
334 | int blen, int plen, char *out) | |
e8057928 | 335 | { |
e8057928 ML |
336 | unsigned long cycles = 0; |
337 | int i, pcount; | |
e9d41164 HX |
338 | int ret; |
339 | ||
340 | if (plen == blen) | |
f139cfa7 | 341 | return test_hash_cycles_digest(desc, sg, blen, out); |
a5a613a4 | 342 | |
e8057928 ML |
343 | local_bh_disable(); |
344 | local_irq_disable(); | |
345 | ||
346 | /* Warm-up run. */ | |
347 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
348 | ret = crypto_hash_init(desc); |
349 | if (ret) | |
350 | goto out; | |
e8057928 | 351 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
352 | ret = crypto_hash_update(desc, sg, plen); |
353 | if (ret) | |
354 | goto out; | |
e8057928 | 355 | } |
29059d12 | 356 | ret = crypto_hash_final(desc, out); |
e9d41164 HX |
357 | if (ret) |
358 | goto out; | |
e8057928 ML |
359 | } |
360 | ||
361 | /* The real thing. */ | |
362 | for (i = 0; i < 8; i++) { | |
363 | cycles_t start, end; | |
364 | ||
e8057928 ML |
365 | start = get_cycles(); |
366 | ||
e9d41164 HX |
367 | ret = crypto_hash_init(desc); |
368 | if (ret) | |
369 | goto out; | |
e8057928 | 370 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
371 | ret = crypto_hash_update(desc, sg, plen); |
372 | if (ret) | |
373 | goto out; | |
e8057928 | 374 | } |
e9d41164 HX |
375 | ret = crypto_hash_final(desc, out); |
376 | if (ret) | |
377 | goto out; | |
e8057928 ML |
378 | |
379 | end = get_cycles(); | |
380 | ||
381 | cycles += end - start; | |
382 | } | |
383 | ||
e9d41164 | 384 | out: |
e8057928 ML |
385 | local_irq_enable(); |
386 | local_bh_enable(); | |
387 | ||
e9d41164 HX |
388 | if (ret) |
389 | return ret; | |
390 | ||
e8057928 ML |
391 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
392 | cycles / 8, cycles / (8 * blen)); | |
393 | ||
e9d41164 | 394 | return 0; |
e8057928 ML |
395 | } |
396 | ||
beb63da7 DM |
397 | static void test_hash_sg_init(struct scatterlist *sg) |
398 | { | |
399 | int i; | |
400 | ||
401 | sg_init_table(sg, TVMEMSIZE); | |
402 | for (i = 0; i < TVMEMSIZE; i++) { | |
403 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); | |
404 | memset(tvmem[i], 0xff, PAGE_SIZE); | |
405 | } | |
406 | } | |
407 | ||
01b32324 HX |
408 | static void test_hash_speed(const char *algo, unsigned int sec, |
409 | struct hash_speed *speed) | |
e8057928 | 410 | { |
f139cfa7 | 411 | struct scatterlist sg[TVMEMSIZE]; |
e9d41164 HX |
412 | struct crypto_hash *tfm; |
413 | struct hash_desc desc; | |
376bacb0 | 414 | static char output[1024]; |
e8057928 | 415 | int i; |
e9d41164 | 416 | int ret; |
e8057928 | 417 | |
376bacb0 | 418 | printk(KERN_INFO "\ntesting speed of %s\n", algo); |
e8057928 | 419 | |
e9d41164 | 420 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
e8057928 | 421 | |
e9d41164 | 422 | if (IS_ERR(tfm)) { |
376bacb0 | 423 | printk(KERN_ERR "failed to load transform for %s: %ld\n", algo, |
e9d41164 | 424 | PTR_ERR(tfm)); |
e8057928 ML |
425 | return; |
426 | } | |
427 | ||
e9d41164 HX |
428 | desc.tfm = tfm; |
429 | desc.flags = 0; | |
430 | ||
431 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { | |
376bacb0 | 432 | printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n", |
e9d41164 | 433 | crypto_hash_digestsize(tfm), sizeof(output)); |
e8057928 ML |
434 | goto out; |
435 | } | |
436 | ||
beb63da7 | 437 | test_hash_sg_init(sg); |
e8057928 | 438 | for (i = 0; speed[i].blen != 0; i++) { |
f139cfa7 | 439 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
376bacb0 FS |
440 | printk(KERN_ERR |
441 | "template (%u) too big for tvmem (%lu)\n", | |
f139cfa7 | 442 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
e8057928 ML |
443 | goto out; |
444 | } | |
445 | ||
18bcc919 YH |
446 | if (speed[i].klen) |
447 | crypto_hash_setkey(tfm, tvmem[0], speed[i].klen); | |
448 | ||
376bacb0 FS |
449 | printk(KERN_INFO "test%3u " |
450 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", | |
e8057928 ML |
451 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
452 | ||
e8057928 | 453 | if (sec) |
f139cfa7 | 454 | ret = test_hash_jiffies(&desc, sg, speed[i].blen, |
e9d41164 | 455 | speed[i].plen, output, sec); |
e8057928 | 456 | else |
f139cfa7 | 457 | ret = test_hash_cycles(&desc, sg, speed[i].blen, |
e9d41164 HX |
458 | speed[i].plen, output); |
459 | ||
460 | if (ret) { | |
376bacb0 | 461 | printk(KERN_ERR "hashing failed ret=%d\n", ret); |
e9d41164 HX |
462 | break; |
463 | } | |
e8057928 ML |
464 | } |
465 | ||
466 | out: | |
e9d41164 | 467 | crypto_free_hash(tfm); |
e8057928 ML |
468 | } |
469 | ||
beb63da7 DM |
470 | struct tcrypt_result { |
471 | struct completion completion; | |
472 | int err; | |
473 | }; | |
474 | ||
475 | static void tcrypt_complete(struct crypto_async_request *req, int err) | |
476 | { | |
477 | struct tcrypt_result *res = req->data; | |
478 | ||
479 | if (err == -EINPROGRESS) | |
480 | return; | |
481 | ||
482 | res->err = err; | |
483 | complete(&res->completion); | |
484 | } | |
485 | ||
486 | static inline int do_one_ahash_op(struct ahash_request *req, int ret) | |
487 | { | |
488 | if (ret == -EINPROGRESS || ret == -EBUSY) { | |
489 | struct tcrypt_result *tr = req->base.data; | |
490 | ||
491 | ret = wait_for_completion_interruptible(&tr->completion); | |
492 | if (!ret) | |
493 | ret = tr->err; | |
494 | INIT_COMPLETION(tr->completion); | |
495 | } | |
496 | return ret; | |
497 | } | |
498 | ||
499 | static int test_ahash_jiffies_digest(struct ahash_request *req, int blen, | |
500 | char *out, int sec) | |
501 | { | |
502 | unsigned long start, end; | |
503 | int bcount; | |
504 | int ret; | |
505 | ||
506 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
507 | time_before(jiffies, end); bcount++) { | |
508 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
509 | if (ret) | |
510 | return ret; | |
511 | } | |
512 | ||
513 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
514 | bcount / sec, ((long)bcount * blen) / sec); | |
515 | ||
516 | return 0; | |
517 | } | |
518 | ||
519 | static int test_ahash_jiffies(struct ahash_request *req, int blen, | |
520 | int plen, char *out, int sec) | |
521 | { | |
522 | unsigned long start, end; | |
523 | int bcount, pcount; | |
524 | int ret; | |
525 | ||
526 | if (plen == blen) | |
527 | return test_ahash_jiffies_digest(req, blen, out, sec); | |
528 | ||
529 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
530 | time_before(jiffies, end); bcount++) { | |
531 | ret = crypto_ahash_init(req); | |
532 | if (ret) | |
533 | return ret; | |
534 | for (pcount = 0; pcount < blen; pcount += plen) { | |
535 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
536 | if (ret) | |
537 | return ret; | |
538 | } | |
539 | /* we assume there is enough space in 'out' for the result */ | |
540 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
541 | if (ret) | |
542 | return ret; | |
543 | } | |
544 | ||
545 | pr_cont("%6u opers/sec, %9lu bytes/sec\n", | |
546 | bcount / sec, ((long)bcount * blen) / sec); | |
547 | ||
548 | return 0; | |
549 | } | |
550 | ||
551 | static int test_ahash_cycles_digest(struct ahash_request *req, int blen, | |
552 | char *out) | |
553 | { | |
554 | unsigned long cycles = 0; | |
555 | int ret, i; | |
556 | ||
557 | /* Warm-up run. */ | |
558 | for (i = 0; i < 4; i++) { | |
559 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
560 | if (ret) | |
561 | goto out; | |
562 | } | |
563 | ||
564 | /* The real thing. */ | |
565 | for (i = 0; i < 8; i++) { | |
566 | cycles_t start, end; | |
567 | ||
568 | start = get_cycles(); | |
569 | ||
570 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
571 | if (ret) | |
572 | goto out; | |
573 | ||
574 | end = get_cycles(); | |
575 | ||
576 | cycles += end - start; | |
577 | } | |
578 | ||
579 | out: | |
580 | if (ret) | |
581 | return ret; | |
582 | ||
583 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", | |
584 | cycles / 8, cycles / (8 * blen)); | |
585 | ||
586 | return 0; | |
587 | } | |
588 | ||
589 | static int test_ahash_cycles(struct ahash_request *req, int blen, | |
590 | int plen, char *out) | |
591 | { | |
592 | unsigned long cycles = 0; | |
593 | int i, pcount, ret; | |
594 | ||
595 | if (plen == blen) | |
596 | return test_ahash_cycles_digest(req, blen, out); | |
597 | ||
598 | /* Warm-up run. */ | |
599 | for (i = 0; i < 4; i++) { | |
600 | ret = crypto_ahash_init(req); | |
601 | if (ret) | |
602 | goto out; | |
603 | for (pcount = 0; pcount < blen; pcount += plen) { | |
604 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
605 | if (ret) | |
606 | goto out; | |
607 | } | |
608 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
609 | if (ret) | |
610 | goto out; | |
611 | } | |
612 | ||
613 | /* The real thing. */ | |
614 | for (i = 0; i < 8; i++) { | |
615 | cycles_t start, end; | |
616 | ||
617 | start = get_cycles(); | |
618 | ||
619 | ret = crypto_ahash_init(req); | |
620 | if (ret) | |
621 | goto out; | |
622 | for (pcount = 0; pcount < blen; pcount += plen) { | |
623 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
624 | if (ret) | |
625 | goto out; | |
626 | } | |
627 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
628 | if (ret) | |
629 | goto out; | |
630 | ||
631 | end = get_cycles(); | |
632 | ||
633 | cycles += end - start; | |
634 | } | |
635 | ||
636 | out: | |
637 | if (ret) | |
638 | return ret; | |
639 | ||
640 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", | |
641 | cycles / 8, cycles / (8 * blen)); | |
642 | ||
643 | return 0; | |
644 | } | |
645 | ||
646 | static void test_ahash_speed(const char *algo, unsigned int sec, | |
647 | struct hash_speed *speed) | |
648 | { | |
649 | struct scatterlist sg[TVMEMSIZE]; | |
650 | struct tcrypt_result tresult; | |
651 | struct ahash_request *req; | |
652 | struct crypto_ahash *tfm; | |
653 | static char output[1024]; | |
654 | int i, ret; | |
655 | ||
656 | printk(KERN_INFO "\ntesting speed of async %s\n", algo); | |
657 | ||
658 | tfm = crypto_alloc_ahash(algo, 0, 0); | |
659 | if (IS_ERR(tfm)) { | |
660 | pr_err("failed to load transform for %s: %ld\n", | |
661 | algo, PTR_ERR(tfm)); | |
662 | return; | |
663 | } | |
664 | ||
665 | if (crypto_ahash_digestsize(tfm) > sizeof(output)) { | |
666 | pr_err("digestsize(%u) > outputbuffer(%zu)\n", | |
667 | crypto_ahash_digestsize(tfm), sizeof(output)); | |
668 | goto out; | |
669 | } | |
670 | ||
671 | test_hash_sg_init(sg); | |
672 | req = ahash_request_alloc(tfm, GFP_KERNEL); | |
673 | if (!req) { | |
674 | pr_err("ahash request allocation failure\n"); | |
675 | goto out; | |
676 | } | |
677 | ||
678 | init_completion(&tresult.completion); | |
679 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
680 | tcrypt_complete, &tresult); | |
681 | ||
682 | for (i = 0; speed[i].blen != 0; i++) { | |
683 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { | |
684 | pr_err("template (%u) too big for tvmem (%lu)\n", | |
685 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); | |
686 | break; | |
687 | } | |
688 | ||
689 | pr_info("test%3u " | |
690 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", | |
691 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); | |
692 | ||
693 | ahash_request_set_crypt(req, sg, output, speed[i].plen); | |
694 | ||
695 | if (sec) | |
696 | ret = test_ahash_jiffies(req, speed[i].blen, | |
697 | speed[i].plen, output, sec); | |
698 | else | |
699 | ret = test_ahash_cycles(req, speed[i].blen, | |
700 | speed[i].plen, output); | |
701 | ||
702 | if (ret) { | |
703 | pr_err("hashing failed ret=%d\n", ret); | |
704 | break; | |
705 | } | |
706 | } | |
707 | ||
708 | ahash_request_free(req); | |
709 | ||
710 | out: | |
711 | crypto_free_ahash(tfm); | |
712 | } | |
713 | ||
ef2736fc | 714 | static void test_available(void) |
1da177e4 LT |
715 | { |
716 | char **name = check; | |
ef2736fc | 717 | |
1da177e4 LT |
718 | while (*name) { |
719 | printk("alg %s ", *name); | |
6158efc0 | 720 | printk(crypto_has_alg(*name, 0, 0) ? |
e4d5b79c | 721 | "found\n" : "not found\n"); |
1da177e4 | 722 | name++; |
ef2736fc | 723 | } |
1da177e4 LT |
724 | } |
725 | ||
01b32324 HX |
726 | static inline int tcrypt_test(const char *alg) |
727 | { | |
4e033a6b JW |
728 | int ret; |
729 | ||
730 | ret = alg_test(alg, alg, 0, 0); | |
731 | /* non-fips algs return -EINVAL in fips mode */ | |
732 | if (fips_enabled && ret == -EINVAL) | |
733 | ret = 0; | |
734 | return ret; | |
01b32324 HX |
735 | } |
736 | ||
4e033a6b | 737 | static int do_test(int m) |
01b32324 HX |
738 | { |
739 | int i; | |
4e033a6b | 740 | int ret = 0; |
01b32324 HX |
741 | |
742 | switch (m) { | |
1da177e4 | 743 | case 0: |
01b32324 | 744 | for (i = 1; i < 200; i++) |
4e033a6b | 745 | ret += do_test(i); |
1da177e4 LT |
746 | break; |
747 | ||
748 | case 1: | |
4e033a6b | 749 | ret += tcrypt_test("md5"); |
1da177e4 LT |
750 | break; |
751 | ||
752 | case 2: | |
4e033a6b | 753 | ret += tcrypt_test("sha1"); |
1da177e4 LT |
754 | break; |
755 | ||
756 | case 3: | |
4e033a6b JW |
757 | ret += tcrypt_test("ecb(des)"); |
758 | ret += tcrypt_test("cbc(des)"); | |
1da177e4 LT |
759 | break; |
760 | ||
761 | case 4: | |
4e033a6b JW |
762 | ret += tcrypt_test("ecb(des3_ede)"); |
763 | ret += tcrypt_test("cbc(des3_ede)"); | |
1da177e4 LT |
764 | break; |
765 | ||
766 | case 5: | |
4e033a6b | 767 | ret += tcrypt_test("md4"); |
1da177e4 | 768 | break; |
ef2736fc | 769 | |
1da177e4 | 770 | case 6: |
4e033a6b | 771 | ret += tcrypt_test("sha256"); |
1da177e4 | 772 | break; |
ef2736fc | 773 | |
1da177e4 | 774 | case 7: |
4e033a6b JW |
775 | ret += tcrypt_test("ecb(blowfish)"); |
776 | ret += tcrypt_test("cbc(blowfish)"); | |
1da177e4 LT |
777 | break; |
778 | ||
779 | case 8: | |
4e033a6b JW |
780 | ret += tcrypt_test("ecb(twofish)"); |
781 | ret += tcrypt_test("cbc(twofish)"); | |
1da177e4 | 782 | break; |
ef2736fc | 783 | |
1da177e4 | 784 | case 9: |
4e033a6b | 785 | ret += tcrypt_test("ecb(serpent)"); |
1da177e4 LT |
786 | break; |
787 | ||
788 | case 10: | |
4e033a6b JW |
789 | ret += tcrypt_test("ecb(aes)"); |
790 | ret += tcrypt_test("cbc(aes)"); | |
791 | ret += tcrypt_test("lrw(aes)"); | |
792 | ret += tcrypt_test("xts(aes)"); | |
793 | ret += tcrypt_test("ctr(aes)"); | |
794 | ret += tcrypt_test("rfc3686(ctr(aes))"); | |
1da177e4 LT |
795 | break; |
796 | ||
797 | case 11: | |
4e033a6b | 798 | ret += tcrypt_test("sha384"); |
1da177e4 | 799 | break; |
ef2736fc | 800 | |
1da177e4 | 801 | case 12: |
4e033a6b | 802 | ret += tcrypt_test("sha512"); |
1da177e4 LT |
803 | break; |
804 | ||
805 | case 13: | |
4e033a6b | 806 | ret += tcrypt_test("deflate"); |
1da177e4 LT |
807 | break; |
808 | ||
809 | case 14: | |
4e033a6b | 810 | ret += tcrypt_test("ecb(cast5)"); |
1da177e4 LT |
811 | break; |
812 | ||
813 | case 15: | |
4e033a6b | 814 | ret += tcrypt_test("ecb(cast6)"); |
1da177e4 LT |
815 | break; |
816 | ||
817 | case 16: | |
4e033a6b | 818 | ret += tcrypt_test("ecb(arc4)"); |
1da177e4 LT |
819 | break; |
820 | ||
821 | case 17: | |
4e033a6b | 822 | ret += tcrypt_test("michael_mic"); |
1da177e4 LT |
823 | break; |
824 | ||
825 | case 18: | |
4e033a6b | 826 | ret += tcrypt_test("crc32c"); |
1da177e4 LT |
827 | break; |
828 | ||
829 | case 19: | |
4e033a6b | 830 | ret += tcrypt_test("ecb(tea)"); |
1da177e4 LT |
831 | break; |
832 | ||
833 | case 20: | |
4e033a6b | 834 | ret += tcrypt_test("ecb(xtea)"); |
1da177e4 LT |
835 | break; |
836 | ||
837 | case 21: | |
4e033a6b | 838 | ret += tcrypt_test("ecb(khazad)"); |
1da177e4 LT |
839 | break; |
840 | ||
841 | case 22: | |
4e033a6b | 842 | ret += tcrypt_test("wp512"); |
1da177e4 LT |
843 | break; |
844 | ||
845 | case 23: | |
4e033a6b | 846 | ret += tcrypt_test("wp384"); |
1da177e4 LT |
847 | break; |
848 | ||
849 | case 24: | |
4e033a6b | 850 | ret += tcrypt_test("wp256"); |
1da177e4 LT |
851 | break; |
852 | ||
853 | case 25: | |
4e033a6b | 854 | ret += tcrypt_test("ecb(tnepres)"); |
1da177e4 LT |
855 | break; |
856 | ||
857 | case 26: | |
4e033a6b JW |
858 | ret += tcrypt_test("ecb(anubis)"); |
859 | ret += tcrypt_test("cbc(anubis)"); | |
1da177e4 LT |
860 | break; |
861 | ||
862 | case 27: | |
4e033a6b | 863 | ret += tcrypt_test("tgr192"); |
1da177e4 LT |
864 | break; |
865 | ||
866 | case 28: | |
867 | ||
4e033a6b | 868 | ret += tcrypt_test("tgr160"); |
1da177e4 LT |
869 | break; |
870 | ||
871 | case 29: | |
4e033a6b | 872 | ret += tcrypt_test("tgr128"); |
1da177e4 | 873 | break; |
2998db37 | 874 | |
fb4f10ed | 875 | case 30: |
4e033a6b | 876 | ret += tcrypt_test("ecb(xeta)"); |
fb4f10ed | 877 | break; |
1da177e4 | 878 | |
90831639 | 879 | case 31: |
4e033a6b | 880 | ret += tcrypt_test("pcbc(fcrypt)"); |
90831639 DH |
881 | break; |
882 | ||
02ab5a70 | 883 | case 32: |
4e033a6b JW |
884 | ret += tcrypt_test("ecb(camellia)"); |
885 | ret += tcrypt_test("cbc(camellia)"); | |
02ab5a70 | 886 | break; |
cd12fb90 | 887 | case 33: |
4e033a6b | 888 | ret += tcrypt_test("sha224"); |
cd12fb90 | 889 | break; |
02ab5a70 | 890 | |
2407d608 | 891 | case 34: |
4e033a6b | 892 | ret += tcrypt_test("salsa20"); |
2407d608 TSH |
893 | break; |
894 | ||
8df213d9 | 895 | case 35: |
4e033a6b | 896 | ret += tcrypt_test("gcm(aes)"); |
8df213d9 HX |
897 | break; |
898 | ||
0b77abb3 | 899 | case 36: |
4e033a6b | 900 | ret += tcrypt_test("lzo"); |
0b77abb3 ZS |
901 | break; |
902 | ||
93cc74e0 | 903 | case 37: |
4e033a6b | 904 | ret += tcrypt_test("ccm(aes)"); |
93cc74e0 JL |
905 | break; |
906 | ||
76cb9521 | 907 | case 38: |
4e033a6b | 908 | ret += tcrypt_test("cts(cbc(aes))"); |
76cb9521 KC |
909 | break; |
910 | ||
fd4adf1a | 911 | case 39: |
4e033a6b | 912 | ret += tcrypt_test("rmd128"); |
fd4adf1a AKR |
913 | break; |
914 | ||
915 | case 40: | |
4e033a6b | 916 | ret += tcrypt_test("rmd160"); |
fd4adf1a AKR |
917 | break; |
918 | ||
2998db37 | 919 | case 41: |
4e033a6b | 920 | ret += tcrypt_test("rmd256"); |
2998db37 AKR |
921 | break; |
922 | ||
923 | case 42: | |
4e033a6b | 924 | ret += tcrypt_test("rmd320"); |
01b32324 HX |
925 | break; |
926 | ||
927 | case 43: | |
4e033a6b | 928 | ret += tcrypt_test("ecb(seed)"); |
2998db37 AKR |
929 | break; |
930 | ||
0c01aed5 | 931 | case 44: |
4e033a6b | 932 | ret += tcrypt_test("zlib"); |
0c01aed5 GU |
933 | break; |
934 | ||
5d667322 | 935 | case 45: |
4e033a6b | 936 | ret += tcrypt_test("rfc4309(ccm(aes))"); |
5d667322 JW |
937 | break; |
938 | ||
1da177e4 | 939 | case 100: |
4e033a6b | 940 | ret += tcrypt_test("hmac(md5)"); |
1da177e4 | 941 | break; |
ef2736fc | 942 | |
1da177e4 | 943 | case 101: |
4e033a6b | 944 | ret += tcrypt_test("hmac(sha1)"); |
1da177e4 | 945 | break; |
ef2736fc | 946 | |
1da177e4 | 947 | case 102: |
4e033a6b | 948 | ret += tcrypt_test("hmac(sha256)"); |
1da177e4 LT |
949 | break; |
950 | ||
a28091ae | 951 | case 103: |
4e033a6b | 952 | ret += tcrypt_test("hmac(sha384)"); |
a28091ae AD |
953 | break; |
954 | ||
955 | case 104: | |
4e033a6b | 956 | ret += tcrypt_test("hmac(sha512)"); |
a28091ae | 957 | break; |
38ed9ab2 | 958 | |
cd12fb90 | 959 | case 105: |
4e033a6b | 960 | ret += tcrypt_test("hmac(sha224)"); |
cd12fb90 | 961 | break; |
1da177e4 | 962 | |
38ed9ab2 | 963 | case 106: |
4e033a6b | 964 | ret += tcrypt_test("xcbc(aes)"); |
38ed9ab2 HX |
965 | break; |
966 | ||
fd4adf1a | 967 | case 107: |
4e033a6b | 968 | ret += tcrypt_test("hmac(rmd128)"); |
fd4adf1a AKR |
969 | break; |
970 | ||
971 | case 108: | |
4e033a6b | 972 | ret += tcrypt_test("hmac(rmd160)"); |
fd4adf1a AKR |
973 | break; |
974 | ||
f1939f7c SW |
975 | case 109: |
976 | ret += tcrypt_test("vmac(aes)"); | |
977 | break; | |
978 | ||
e08ca2da | 979 | case 150: |
4e033a6b | 980 | ret += tcrypt_test("ansi_cprng"); |
e08ca2da JW |
981 | break; |
982 | ||
ebfd9bcf | 983 | case 200: |
cba83564 | 984 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 985 | speed_template_16_24_32); |
cba83564 | 986 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 987 | speed_template_16_24_32); |
cba83564 | 988 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 989 | speed_template_16_24_32); |
cba83564 | 990 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 991 | speed_template_16_24_32); |
f3d1044c | 992 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 993 | speed_template_32_40_48); |
f3d1044c | 994 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 995 | speed_template_32_40_48); |
f19f5111 | 996 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 997 | speed_template_32_48_64); |
f19f5111 | 998 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 999 | speed_template_32_48_64); |
ebfd9bcf HW |
1000 | break; |
1001 | ||
1002 | case 201: | |
cba83564 | 1003 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
da7f033d | 1004 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1005 | speed_template_24); |
cba83564 | 1006 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
da7f033d | 1007 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1008 | speed_template_24); |
cba83564 | 1009 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
da7f033d | 1010 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1011 | speed_template_24); |
cba83564 | 1012 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
da7f033d | 1013 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1014 | speed_template_24); |
ebfd9bcf HW |
1015 | break; |
1016 | ||
1017 | case 202: | |
cba83564 | 1018 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1019 | speed_template_16_24_32); |
cba83564 | 1020 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1021 | speed_template_16_24_32); |
cba83564 | 1022 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1023 | speed_template_16_24_32); |
cba83564 | 1024 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1025 | speed_template_16_24_32); |
ebfd9bcf HW |
1026 | break; |
1027 | ||
1028 | case 203: | |
cba83564 | 1029 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1030 | speed_template_8_32); |
cba83564 | 1031 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1032 | speed_template_8_32); |
cba83564 | 1033 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1034 | speed_template_8_32); |
cba83564 | 1035 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1036 | speed_template_8_32); |
ebfd9bcf HW |
1037 | break; |
1038 | ||
1039 | case 204: | |
cba83564 | 1040 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1041 | speed_template_8); |
cba83564 | 1042 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1043 | speed_template_8); |
cba83564 | 1044 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1045 | speed_template_8); |
cba83564 | 1046 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1047 | speed_template_8); |
ebfd9bcf HW |
1048 | break; |
1049 | ||
02ab5a70 NT |
1050 | case 205: |
1051 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1052 | speed_template_16_24_32); |
02ab5a70 | 1053 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1054 | speed_template_16_24_32); |
02ab5a70 | 1055 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1056 | speed_template_16_24_32); |
02ab5a70 | 1057 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1058 | speed_template_16_24_32); |
02ab5a70 NT |
1059 | break; |
1060 | ||
5de8f1b5 TSH |
1061 | case 206: |
1062 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1063 | speed_template_16_32); |
5de8f1b5 TSH |
1064 | break; |
1065 | ||
e8057928 ML |
1066 | case 300: |
1067 | /* fall through */ | |
1068 | ||
1069 | case 301: | |
e9d41164 | 1070 | test_hash_speed("md4", sec, generic_hash_speed_template); |
e8057928 ML |
1071 | if (mode > 300 && mode < 400) break; |
1072 | ||
1073 | case 302: | |
e9d41164 | 1074 | test_hash_speed("md5", sec, generic_hash_speed_template); |
e8057928 ML |
1075 | if (mode > 300 && mode < 400) break; |
1076 | ||
1077 | case 303: | |
e9d41164 | 1078 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
e8057928 ML |
1079 | if (mode > 300 && mode < 400) break; |
1080 | ||
1081 | case 304: | |
e9d41164 | 1082 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
e8057928 ML |
1083 | if (mode > 300 && mode < 400) break; |
1084 | ||
1085 | case 305: | |
e9d41164 | 1086 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
e8057928 ML |
1087 | if (mode > 300 && mode < 400) break; |
1088 | ||
1089 | case 306: | |
e9d41164 | 1090 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
e8057928 ML |
1091 | if (mode > 300 && mode < 400) break; |
1092 | ||
1093 | case 307: | |
e9d41164 | 1094 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
e8057928 ML |
1095 | if (mode > 300 && mode < 400) break; |
1096 | ||
1097 | case 308: | |
e9d41164 | 1098 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
e8057928 ML |
1099 | if (mode > 300 && mode < 400) break; |
1100 | ||
1101 | case 309: | |
e9d41164 | 1102 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
e8057928 ML |
1103 | if (mode > 300 && mode < 400) break; |
1104 | ||
1105 | case 310: | |
e9d41164 | 1106 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
e8057928 ML |
1107 | if (mode > 300 && mode < 400) break; |
1108 | ||
1109 | case 311: | |
e9d41164 | 1110 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
e8057928 ML |
1111 | if (mode > 300 && mode < 400) break; |
1112 | ||
1113 | case 312: | |
e9d41164 | 1114 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
e8057928 ML |
1115 | if (mode > 300 && mode < 400) break; |
1116 | ||
cd12fb90 JL |
1117 | case 313: |
1118 | test_hash_speed("sha224", sec, generic_hash_speed_template); | |
1119 | if (mode > 300 && mode < 400) break; | |
1120 | ||
fd4adf1a AKR |
1121 | case 314: |
1122 | test_hash_speed("rmd128", sec, generic_hash_speed_template); | |
1123 | if (mode > 300 && mode < 400) break; | |
1124 | ||
1125 | case 315: | |
1126 | test_hash_speed("rmd160", sec, generic_hash_speed_template); | |
1127 | if (mode > 300 && mode < 400) break; | |
1128 | ||
2998db37 AKR |
1129 | case 316: |
1130 | test_hash_speed("rmd256", sec, generic_hash_speed_template); | |
1131 | if (mode > 300 && mode < 400) break; | |
1132 | ||
1133 | case 317: | |
1134 | test_hash_speed("rmd320", sec, generic_hash_speed_template); | |
1135 | if (mode > 300 && mode < 400) break; | |
1136 | ||
18bcc919 YH |
1137 | case 318: |
1138 | test_hash_speed("ghash-generic", sec, hash_speed_template_16); | |
1139 | if (mode > 300 && mode < 400) break; | |
1140 | ||
e8057928 ML |
1141 | case 399: |
1142 | break; | |
1143 | ||
beb63da7 DM |
1144 | case 400: |
1145 | /* fall through */ | |
1146 | ||
1147 | case 401: | |
1148 | test_ahash_speed("md4", sec, generic_hash_speed_template); | |
1149 | if (mode > 400 && mode < 500) break; | |
1150 | ||
1151 | case 402: | |
1152 | test_ahash_speed("md5", sec, generic_hash_speed_template); | |
1153 | if (mode > 400 && mode < 500) break; | |
1154 | ||
1155 | case 403: | |
1156 | test_ahash_speed("sha1", sec, generic_hash_speed_template); | |
1157 | if (mode > 400 && mode < 500) break; | |
1158 | ||
1159 | case 404: | |
1160 | test_ahash_speed("sha256", sec, generic_hash_speed_template); | |
1161 | if (mode > 400 && mode < 500) break; | |
1162 | ||
1163 | case 405: | |
1164 | test_ahash_speed("sha384", sec, generic_hash_speed_template); | |
1165 | if (mode > 400 && mode < 500) break; | |
1166 | ||
1167 | case 406: | |
1168 | test_ahash_speed("sha512", sec, generic_hash_speed_template); | |
1169 | if (mode > 400 && mode < 500) break; | |
1170 | ||
1171 | case 407: | |
1172 | test_ahash_speed("wp256", sec, generic_hash_speed_template); | |
1173 | if (mode > 400 && mode < 500) break; | |
1174 | ||
1175 | case 408: | |
1176 | test_ahash_speed("wp384", sec, generic_hash_speed_template); | |
1177 | if (mode > 400 && mode < 500) break; | |
1178 | ||
1179 | case 409: | |
1180 | test_ahash_speed("wp512", sec, generic_hash_speed_template); | |
1181 | if (mode > 400 && mode < 500) break; | |
1182 | ||
1183 | case 410: | |
1184 | test_ahash_speed("tgr128", sec, generic_hash_speed_template); | |
1185 | if (mode > 400 && mode < 500) break; | |
1186 | ||
1187 | case 411: | |
1188 | test_ahash_speed("tgr160", sec, generic_hash_speed_template); | |
1189 | if (mode > 400 && mode < 500) break; | |
1190 | ||
1191 | case 412: | |
1192 | test_ahash_speed("tgr192", sec, generic_hash_speed_template); | |
1193 | if (mode > 400 && mode < 500) break; | |
1194 | ||
1195 | case 413: | |
1196 | test_ahash_speed("sha224", sec, generic_hash_speed_template); | |
1197 | if (mode > 400 && mode < 500) break; | |
1198 | ||
1199 | case 414: | |
1200 | test_ahash_speed("rmd128", sec, generic_hash_speed_template); | |
1201 | if (mode > 400 && mode < 500) break; | |
1202 | ||
1203 | case 415: | |
1204 | test_ahash_speed("rmd160", sec, generic_hash_speed_template); | |
1205 | if (mode > 400 && mode < 500) break; | |
1206 | ||
1207 | case 416: | |
1208 | test_ahash_speed("rmd256", sec, generic_hash_speed_template); | |
1209 | if (mode > 400 && mode < 500) break; | |
1210 | ||
1211 | case 417: | |
1212 | test_ahash_speed("rmd320", sec, generic_hash_speed_template); | |
1213 | if (mode > 400 && mode < 500) break; | |
1214 | ||
1215 | case 499: | |
1216 | break; | |
1217 | ||
1da177e4 LT |
1218 | case 1000: |
1219 | test_available(); | |
1220 | break; | |
1da177e4 | 1221 | } |
4e033a6b JW |
1222 | |
1223 | return ret; | |
1da177e4 LT |
1224 | } |
1225 | ||
7be380f7 | 1226 | static int do_alg_test(const char *alg, u32 type, u32 mask) |
a873a5f1 | 1227 | { |
7be380f7 HX |
1228 | return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ? |
1229 | 0 : -ENOENT; | |
a873a5f1 SK |
1230 | } |
1231 | ||
3af5b90b | 1232 | static int __init tcrypt_mod_init(void) |
1da177e4 | 1233 | { |
e3a4ea4f | 1234 | int err = -ENOMEM; |
f139cfa7 | 1235 | int i; |
e3a4ea4f | 1236 | |
f139cfa7 HX |
1237 | for (i = 0; i < TVMEMSIZE; i++) { |
1238 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); | |
1239 | if (!tvmem[i]) | |
1240 | goto err_free_tv; | |
1241 | } | |
1da177e4 | 1242 | |
a873a5f1 | 1243 | if (alg) |
7be380f7 | 1244 | err = do_alg_test(alg, type, mask); |
a873a5f1 SK |
1245 | else |
1246 | err = do_test(mode); | |
1247 | ||
4e033a6b JW |
1248 | if (err) { |
1249 | printk(KERN_ERR "tcrypt: one or more tests failed!\n"); | |
1250 | goto err_free_tv; | |
1251 | } | |
14fdf477 | 1252 | |
4e033a6b JW |
1253 | /* We intentionaly return -EAGAIN to prevent keeping the module, |
1254 | * unless we're running in fips mode. It does all its work from | |
1255 | * init() and doesn't offer any runtime functionality, but in | |
1256 | * the fips case, checking for a successful load is helpful. | |
14fdf477 ML |
1257 | * => we don't need it in the memory, do we? |
1258 | * -- mludvig | |
1259 | */ | |
4e033a6b JW |
1260 | if (!fips_enabled) |
1261 | err = -EAGAIN; | |
e3a4ea4f | 1262 | |
f139cfa7 HX |
1263 | err_free_tv: |
1264 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) | |
1265 | free_page((unsigned long)tvmem[i]); | |
e3a4ea4f MH |
1266 | |
1267 | return err; | |
1da177e4 LT |
1268 | } |
1269 | ||
1270 | /* | |
1271 | * If an init function is provided, an exit function must also be provided | |
1272 | * to allow module unload. | |
1273 | */ | |
3af5b90b | 1274 | static void __exit tcrypt_mod_fini(void) { } |
1da177e4 | 1275 | |
3af5b90b KB |
1276 | module_init(tcrypt_mod_init); |
1277 | module_exit(tcrypt_mod_fini); | |
1da177e4 | 1278 | |
a873a5f1 SK |
1279 | module_param(alg, charp, 0); |
1280 | module_param(type, uint, 0); | |
7be380f7 | 1281 | module_param(mask, uint, 0); |
1da177e4 | 1282 | module_param(mode, int, 0); |
ebfd9bcf | 1283 | module_param(sec, uint, 0); |
6a17944c HX |
1284 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
1285 | "(defaults to zero which uses CPU cycles instead)"); | |
1da177e4 LT |
1286 | |
1287 | MODULE_LICENSE("GPL"); | |
1288 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | |
1289 | MODULE_AUTHOR("James Morris <[email protected]>"); |