]>
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 | 10 | * |
69435b94 AH |
11 | * Updated RFC4106 AES-GCM testing. |
12 | * Authors: Aidan O'Mahony ([email protected]) | |
13 | * Adrian Hoban <[email protected]> | |
14 | * Gabriele Paoloni <[email protected]> | |
15 | * Tadeusz Struk ([email protected]) | |
16 | * Copyright (c) 2010, Intel Corporation. | |
17 | * | |
1da177e4 LT |
18 | * This program is free software; you can redistribute it and/or modify it |
19 | * under the terms of the GNU General Public License as published by the Free | |
ef2736fc | 20 | * Software Foundation; either version 2 of the License, or (at your option) |
1da177e4 LT |
21 | * any later version. |
22 | * | |
1da177e4 LT |
23 | */ |
24 | ||
18e33e6d | 25 | #include <crypto/hash.h> |
cba83564 | 26 | #include <linux/err.h> |
1da177e4 | 27 | #include <linux/init.h> |
5a0e3ad6 | 28 | #include <linux/gfp.h> |
1da177e4 | 29 | #include <linux/module.h> |
378f058c | 30 | #include <linux/scatterlist.h> |
1da177e4 | 31 | #include <linux/string.h> |
1da177e4 | 32 | #include <linux/moduleparam.h> |
ebfd9bcf | 33 | #include <linux/jiffies.h> |
6a17944c HX |
34 | #include <linux/timex.h> |
35 | #include <linux/interrupt.h> | |
1da177e4 | 36 | #include "tcrypt.h" |
4e033a6b | 37 | #include "internal.h" |
1da177e4 LT |
38 | |
39 | /* | |
f139cfa7 | 40 | * Need slab memory for testing (size in number of pages). |
1da177e4 | 41 | */ |
f139cfa7 | 42 | #define TVMEMSIZE 4 |
1da177e4 LT |
43 | |
44 | /* | |
da7f033d | 45 | * Used by test_cipher_speed() |
1da177e4 LT |
46 | */ |
47 | #define ENCRYPT 1 | |
48 | #define DECRYPT 0 | |
1da177e4 | 49 | |
ebfd9bcf HW |
50 | /* |
51 | * Used by test_cipher_speed() | |
52 | */ | |
6a17944c | 53 | static unsigned int sec; |
ebfd9bcf | 54 | |
a873a5f1 SK |
55 | static char *alg = NULL; |
56 | static u32 type; | |
7be380f7 | 57 | static u32 mask; |
1da177e4 | 58 | static int mode; |
f139cfa7 | 59 | static char *tvmem[TVMEMSIZE]; |
1da177e4 LT |
60 | |
61 | static char *check[] = { | |
cd12fb90 JL |
62 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
63 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", | |
64 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | |
90831639 | 65 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
2998db37 | 66 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
0c01aed5 | 67 | "lzo", "cts", "zlib", NULL |
1da177e4 LT |
68 | }; |
69 | ||
f139cfa7 HX |
70 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, |
71 | struct scatterlist *sg, int blen, int sec) | |
6a17944c | 72 | { |
6a17944c HX |
73 | unsigned long start, end; |
74 | int bcount; | |
75 | int ret; | |
76 | ||
6a17944c HX |
77 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
78 | time_before(jiffies, end); bcount++) { | |
79 | if (enc) | |
cba83564 | 80 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 81 | else |
cba83564 | 82 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
83 | |
84 | if (ret) | |
85 | return ret; | |
86 | } | |
87 | ||
88 | printk("%d operations in %d seconds (%ld bytes)\n", | |
89 | bcount, sec, (long)bcount * blen); | |
90 | return 0; | |
91 | } | |
92 | ||
f139cfa7 HX |
93 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, |
94 | struct scatterlist *sg, int blen) | |
6a17944c | 95 | { |
6a17944c HX |
96 | unsigned long cycles = 0; |
97 | int ret = 0; | |
98 | int i; | |
99 | ||
6a17944c HX |
100 | local_irq_disable(); |
101 | ||
102 | /* Warm-up run. */ | |
103 | for (i = 0; i < 4; i++) { | |
104 | if (enc) | |
cba83564 | 105 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 106 | else |
cba83564 | 107 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
108 | |
109 | if (ret) | |
110 | goto out; | |
111 | } | |
112 | ||
113 | /* The real thing. */ | |
114 | for (i = 0; i < 8; i++) { | |
115 | cycles_t start, end; | |
116 | ||
117 | start = get_cycles(); | |
118 | if (enc) | |
cba83564 | 119 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 120 | else |
cba83564 | 121 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
122 | end = get_cycles(); |
123 | ||
124 | if (ret) | |
125 | goto out; | |
126 | ||
127 | cycles += end - start; | |
128 | } | |
129 | ||
130 | out: | |
131 | local_irq_enable(); | |
6a17944c HX |
132 | |
133 | if (ret == 0) | |
134 | printk("1 operation in %lu cycles (%d bytes)\n", | |
135 | (cycles + 4) / 8, blen); | |
136 | ||
137 | return ret; | |
138 | } | |
139 | ||
d5dc3927 SS |
140 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
141 | ||
01b32324 | 142 | static void test_cipher_speed(const char *algo, int enc, unsigned int sec, |
da7f033d | 143 | struct cipher_speed_template *template, |
d5dc3927 | 144 | unsigned int tcount, u8 *keysize) |
ebfd9bcf | 145 | { |
dce907c0 | 146 | unsigned int ret, i, j, iv_len; |
f07ef1de DS |
147 | const char *key; |
148 | char iv[128]; | |
cba83564 HX |
149 | struct crypto_blkcipher *tfm; |
150 | struct blkcipher_desc desc; | |
151 | const char *e; | |
d5dc3927 | 152 | u32 *b_size; |
ebfd9bcf HW |
153 | |
154 | if (enc == ENCRYPT) | |
155 | e = "encryption"; | |
156 | else | |
157 | e = "decryption"; | |
ebfd9bcf | 158 | |
cba83564 | 159 | printk("\ntesting speed of %s %s\n", algo, e); |
ebfd9bcf | 160 | |
cba83564 | 161 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
ebfd9bcf | 162 | |
cba83564 HX |
163 | if (IS_ERR(tfm)) { |
164 | printk("failed to load transform for %s: %ld\n", algo, | |
165 | PTR_ERR(tfm)); | |
ebfd9bcf HW |
166 | return; |
167 | } | |
cba83564 HX |
168 | desc.tfm = tfm; |
169 | desc.flags = 0; | |
ebfd9bcf | 170 | |
d5dc3927 SS |
171 | i = 0; |
172 | do { | |
ebfd9bcf | 173 | |
d5dc3927 SS |
174 | b_size = block_sizes; |
175 | do { | |
f139cfa7 | 176 | struct scatterlist sg[TVMEMSIZE]; |
ebfd9bcf | 177 | |
f139cfa7 HX |
178 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
179 | printk("template (%u) too big for " | |
180 | "tvmem (%lu)\n", *keysize + *b_size, | |
181 | TVMEMSIZE * PAGE_SIZE); | |
d5dc3927 SS |
182 | goto out; |
183 | } | |
ebfd9bcf | 184 | |
d5dc3927 SS |
185 | printk("test %u (%d bit key, %d byte blocks): ", i, |
186 | *keysize * 8, *b_size); | |
187 | ||
f139cfa7 | 188 | memset(tvmem[0], 0xff, PAGE_SIZE); |
d5dc3927 SS |
189 | |
190 | /* set key, plain text and IV */ | |
da7f033d | 191 | key = tvmem[0]; |
d5dc3927 SS |
192 | for (j = 0; j < tcount; j++) { |
193 | if (template[j].klen == *keysize) { | |
194 | key = template[j].key; | |
195 | break; | |
196 | } | |
dce907c0 | 197 | } |
ebfd9bcf | 198 | |
d5dc3927 SS |
199 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
200 | if (ret) { | |
201 | printk("setkey() failed flags=%x\n", | |
202 | crypto_blkcipher_get_flags(tfm)); | |
203 | goto out; | |
204 | } | |
ebfd9bcf | 205 | |
f139cfa7 HX |
206 | sg_init_table(sg, TVMEMSIZE); |
207 | sg_set_buf(sg, tvmem[0] + *keysize, | |
208 | PAGE_SIZE - *keysize); | |
209 | for (j = 1; j < TVMEMSIZE; j++) { | |
210 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); | |
211 | memset (tvmem[j], 0xff, PAGE_SIZE); | |
212 | } | |
213 | ||
d5dc3927 SS |
214 | iv_len = crypto_blkcipher_ivsize(tfm); |
215 | if (iv_len) { | |
216 | memset(&iv, 0xff, iv_len); | |
217 | crypto_blkcipher_set_iv(tfm, iv, iv_len); | |
218 | } | |
ebfd9bcf | 219 | |
d5dc3927 | 220 | if (sec) |
f139cfa7 HX |
221 | ret = test_cipher_jiffies(&desc, enc, sg, |
222 | *b_size, sec); | |
d5dc3927 | 223 | else |
f139cfa7 HX |
224 | ret = test_cipher_cycles(&desc, enc, sg, |
225 | *b_size); | |
ebfd9bcf | 226 | |
d5dc3927 SS |
227 | if (ret) { |
228 | printk("%s() failed flags=%x\n", e, desc.flags); | |
229 | break; | |
230 | } | |
231 | b_size++; | |
232 | i++; | |
233 | } while (*b_size); | |
234 | keysize++; | |
235 | } while (*keysize); | |
ebfd9bcf HW |
236 | |
237 | out: | |
cba83564 | 238 | crypto_free_blkcipher(tfm); |
ebfd9bcf HW |
239 | } |
240 | ||
f139cfa7 HX |
241 | static int test_hash_jiffies_digest(struct hash_desc *desc, |
242 | struct scatterlist *sg, int blen, | |
e9d41164 HX |
243 | char *out, int sec) |
244 | { | |
e9d41164 HX |
245 | unsigned long start, end; |
246 | int bcount; | |
247 | int ret; | |
248 | ||
249 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
250 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
251 | ret = crypto_hash_digest(desc, sg, blen, out); |
252 | if (ret) | |
253 | return ret; | |
254 | } | |
255 | ||
256 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
257 | bcount / sec, ((long)bcount * blen) / sec); | |
258 | ||
259 | return 0; | |
260 | } | |
261 | ||
f139cfa7 HX |
262 | static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg, |
263 | int blen, int plen, char *out, int sec) | |
e8057928 | 264 | { |
e8057928 ML |
265 | unsigned long start, end; |
266 | int bcount, pcount; | |
e9d41164 HX |
267 | int ret; |
268 | ||
269 | if (plen == blen) | |
f139cfa7 | 270 | return test_hash_jiffies_digest(desc, sg, blen, out, sec); |
a5a613a4 | 271 | |
e8057928 ML |
272 | for (start = jiffies, end = start + sec * HZ, bcount = 0; |
273 | time_before(jiffies, end); bcount++) { | |
e9d41164 HX |
274 | ret = crypto_hash_init(desc); |
275 | if (ret) | |
276 | return ret; | |
e8057928 | 277 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
278 | ret = crypto_hash_update(desc, sg, plen); |
279 | if (ret) | |
280 | return ret; | |
e8057928 ML |
281 | } |
282 | /* we assume there is enough space in 'out' for the result */ | |
e9d41164 HX |
283 | ret = crypto_hash_final(desc, out); |
284 | if (ret) | |
285 | return ret; | |
e8057928 ML |
286 | } |
287 | ||
288 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
289 | bcount / sec, ((long)bcount * blen) / sec); | |
290 | ||
e9d41164 HX |
291 | return 0; |
292 | } | |
293 | ||
f139cfa7 HX |
294 | static int test_hash_cycles_digest(struct hash_desc *desc, |
295 | struct scatterlist *sg, int blen, char *out) | |
e9d41164 | 296 | { |
e9d41164 HX |
297 | unsigned long cycles = 0; |
298 | int i; | |
299 | int ret; | |
300 | ||
e9d41164 HX |
301 | local_irq_disable(); |
302 | ||
303 | /* Warm-up run. */ | |
304 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
305 | ret = crypto_hash_digest(desc, sg, blen, out); |
306 | if (ret) | |
307 | goto out; | |
308 | } | |
309 | ||
310 | /* The real thing. */ | |
311 | for (i = 0; i < 8; i++) { | |
312 | cycles_t start, end; | |
313 | ||
314 | start = get_cycles(); | |
315 | ||
e9d41164 HX |
316 | ret = crypto_hash_digest(desc, sg, blen, out); |
317 | if (ret) | |
318 | goto out; | |
319 | ||
320 | end = get_cycles(); | |
321 | ||
322 | cycles += end - start; | |
323 | } | |
324 | ||
325 | out: | |
326 | local_irq_enable(); | |
e9d41164 HX |
327 | |
328 | if (ret) | |
329 | return ret; | |
330 | ||
331 | printk("%6lu cycles/operation, %4lu cycles/byte\n", | |
332 | cycles / 8, cycles / (8 * blen)); | |
333 | ||
334 | return 0; | |
e8057928 ML |
335 | } |
336 | ||
f139cfa7 HX |
337 | static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg, |
338 | int blen, int plen, char *out) | |
e8057928 | 339 | { |
e8057928 ML |
340 | unsigned long cycles = 0; |
341 | int i, pcount; | |
e9d41164 HX |
342 | int ret; |
343 | ||
344 | if (plen == blen) | |
f139cfa7 | 345 | return test_hash_cycles_digest(desc, sg, blen, out); |
a5a613a4 | 346 | |
e8057928 ML |
347 | local_irq_disable(); |
348 | ||
349 | /* Warm-up run. */ | |
350 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
351 | ret = crypto_hash_init(desc); |
352 | if (ret) | |
353 | goto out; | |
e8057928 | 354 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
355 | ret = crypto_hash_update(desc, sg, plen); |
356 | if (ret) | |
357 | goto out; | |
e8057928 | 358 | } |
29059d12 | 359 | ret = crypto_hash_final(desc, out); |
e9d41164 HX |
360 | if (ret) |
361 | goto out; | |
e8057928 ML |
362 | } |
363 | ||
364 | /* The real thing. */ | |
365 | for (i = 0; i < 8; i++) { | |
366 | cycles_t start, end; | |
367 | ||
e8057928 ML |
368 | start = get_cycles(); |
369 | ||
e9d41164 HX |
370 | ret = crypto_hash_init(desc); |
371 | if (ret) | |
372 | goto out; | |
e8057928 | 373 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
374 | ret = crypto_hash_update(desc, sg, plen); |
375 | if (ret) | |
376 | goto out; | |
e8057928 | 377 | } |
e9d41164 HX |
378 | ret = crypto_hash_final(desc, out); |
379 | if (ret) | |
380 | goto out; | |
e8057928 ML |
381 | |
382 | end = get_cycles(); | |
383 | ||
384 | cycles += end - start; | |
385 | } | |
386 | ||
e9d41164 | 387 | out: |
e8057928 | 388 | local_irq_enable(); |
e8057928 | 389 | |
e9d41164 HX |
390 | if (ret) |
391 | return ret; | |
392 | ||
e8057928 ML |
393 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
394 | cycles / 8, cycles / (8 * blen)); | |
395 | ||
e9d41164 | 396 | return 0; |
e8057928 ML |
397 | } |
398 | ||
beb63da7 DM |
399 | static void test_hash_sg_init(struct scatterlist *sg) |
400 | { | |
401 | int i; | |
402 | ||
403 | sg_init_table(sg, TVMEMSIZE); | |
404 | for (i = 0; i < TVMEMSIZE; i++) { | |
405 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); | |
406 | memset(tvmem[i], 0xff, PAGE_SIZE); | |
407 | } | |
408 | } | |
409 | ||
01b32324 HX |
410 | static void test_hash_speed(const char *algo, unsigned int sec, |
411 | struct hash_speed *speed) | |
e8057928 | 412 | { |
f139cfa7 | 413 | struct scatterlist sg[TVMEMSIZE]; |
e9d41164 HX |
414 | struct crypto_hash *tfm; |
415 | struct hash_desc desc; | |
376bacb0 | 416 | static char output[1024]; |
e8057928 | 417 | int i; |
e9d41164 | 418 | int ret; |
e8057928 | 419 | |
376bacb0 | 420 | printk(KERN_INFO "\ntesting speed of %s\n", algo); |
e8057928 | 421 | |
e9d41164 | 422 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
e8057928 | 423 | |
e9d41164 | 424 | if (IS_ERR(tfm)) { |
376bacb0 | 425 | printk(KERN_ERR "failed to load transform for %s: %ld\n", algo, |
e9d41164 | 426 | PTR_ERR(tfm)); |
e8057928 ML |
427 | return; |
428 | } | |
429 | ||
e9d41164 HX |
430 | desc.tfm = tfm; |
431 | desc.flags = 0; | |
432 | ||
433 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { | |
376bacb0 | 434 | printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n", |
e9d41164 | 435 | crypto_hash_digestsize(tfm), sizeof(output)); |
e8057928 ML |
436 | goto out; |
437 | } | |
438 | ||
beb63da7 | 439 | test_hash_sg_init(sg); |
e8057928 | 440 | for (i = 0; speed[i].blen != 0; i++) { |
f139cfa7 | 441 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
376bacb0 FS |
442 | printk(KERN_ERR |
443 | "template (%u) too big for tvmem (%lu)\n", | |
f139cfa7 | 444 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
e8057928 ML |
445 | goto out; |
446 | } | |
447 | ||
18bcc919 YH |
448 | if (speed[i].klen) |
449 | crypto_hash_setkey(tfm, tvmem[0], speed[i].klen); | |
450 | ||
376bacb0 FS |
451 | printk(KERN_INFO "test%3u " |
452 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", | |
e8057928 ML |
453 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
454 | ||
e8057928 | 455 | if (sec) |
f139cfa7 | 456 | ret = test_hash_jiffies(&desc, sg, speed[i].blen, |
e9d41164 | 457 | speed[i].plen, output, sec); |
e8057928 | 458 | else |
f139cfa7 | 459 | ret = test_hash_cycles(&desc, sg, speed[i].blen, |
e9d41164 HX |
460 | speed[i].plen, output); |
461 | ||
462 | if (ret) { | |
376bacb0 | 463 | printk(KERN_ERR "hashing failed ret=%d\n", ret); |
e9d41164 HX |
464 | break; |
465 | } | |
e8057928 ML |
466 | } |
467 | ||
468 | out: | |
e9d41164 | 469 | crypto_free_hash(tfm); |
e8057928 ML |
470 | } |
471 | ||
beb63da7 DM |
472 | struct tcrypt_result { |
473 | struct completion completion; | |
474 | int err; | |
475 | }; | |
476 | ||
477 | static void tcrypt_complete(struct crypto_async_request *req, int err) | |
478 | { | |
479 | struct tcrypt_result *res = req->data; | |
480 | ||
481 | if (err == -EINPROGRESS) | |
482 | return; | |
483 | ||
484 | res->err = err; | |
485 | complete(&res->completion); | |
486 | } | |
487 | ||
488 | static inline int do_one_ahash_op(struct ahash_request *req, int ret) | |
489 | { | |
490 | if (ret == -EINPROGRESS || ret == -EBUSY) { | |
491 | struct tcrypt_result *tr = req->base.data; | |
492 | ||
493 | ret = wait_for_completion_interruptible(&tr->completion); | |
494 | if (!ret) | |
495 | ret = tr->err; | |
496 | INIT_COMPLETION(tr->completion); | |
497 | } | |
498 | return ret; | |
499 | } | |
500 | ||
501 | static int test_ahash_jiffies_digest(struct ahash_request *req, int blen, | |
502 | char *out, int sec) | |
503 | { | |
504 | unsigned long start, end; | |
505 | int bcount; | |
506 | int ret; | |
507 | ||
508 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
509 | time_before(jiffies, end); bcount++) { | |
510 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
511 | if (ret) | |
512 | return ret; | |
513 | } | |
514 | ||
515 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
516 | bcount / sec, ((long)bcount * blen) / sec); | |
517 | ||
518 | return 0; | |
519 | } | |
520 | ||
521 | static int test_ahash_jiffies(struct ahash_request *req, int blen, | |
522 | int plen, char *out, int sec) | |
523 | { | |
524 | unsigned long start, end; | |
525 | int bcount, pcount; | |
526 | int ret; | |
527 | ||
528 | if (plen == blen) | |
529 | return test_ahash_jiffies_digest(req, blen, out, sec); | |
530 | ||
531 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
532 | time_before(jiffies, end); bcount++) { | |
533 | ret = crypto_ahash_init(req); | |
534 | if (ret) | |
535 | return ret; | |
536 | for (pcount = 0; pcount < blen; pcount += plen) { | |
537 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
538 | if (ret) | |
539 | return ret; | |
540 | } | |
541 | /* we assume there is enough space in 'out' for the result */ | |
542 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
543 | if (ret) | |
544 | return ret; | |
545 | } | |
546 | ||
547 | pr_cont("%6u opers/sec, %9lu bytes/sec\n", | |
548 | bcount / sec, ((long)bcount * blen) / sec); | |
549 | ||
550 | return 0; | |
551 | } | |
552 | ||
553 | static int test_ahash_cycles_digest(struct ahash_request *req, int blen, | |
554 | char *out) | |
555 | { | |
556 | unsigned long cycles = 0; | |
557 | int ret, i; | |
558 | ||
559 | /* Warm-up run. */ | |
560 | for (i = 0; i < 4; i++) { | |
561 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
562 | if (ret) | |
563 | goto out; | |
564 | } | |
565 | ||
566 | /* The real thing. */ | |
567 | for (i = 0; i < 8; i++) { | |
568 | cycles_t start, end; | |
569 | ||
570 | start = get_cycles(); | |
571 | ||
572 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
573 | if (ret) | |
574 | goto out; | |
575 | ||
576 | end = get_cycles(); | |
577 | ||
578 | cycles += end - start; | |
579 | } | |
580 | ||
581 | out: | |
582 | if (ret) | |
583 | return ret; | |
584 | ||
585 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", | |
586 | cycles / 8, cycles / (8 * blen)); | |
587 | ||
588 | return 0; | |
589 | } | |
590 | ||
591 | static int test_ahash_cycles(struct ahash_request *req, int blen, | |
592 | int plen, char *out) | |
593 | { | |
594 | unsigned long cycles = 0; | |
595 | int i, pcount, ret; | |
596 | ||
597 | if (plen == blen) | |
598 | return test_ahash_cycles_digest(req, blen, out); | |
599 | ||
600 | /* Warm-up run. */ | |
601 | for (i = 0; i < 4; i++) { | |
602 | ret = crypto_ahash_init(req); | |
603 | if (ret) | |
604 | goto out; | |
605 | for (pcount = 0; pcount < blen; pcount += plen) { | |
606 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
607 | if (ret) | |
608 | goto out; | |
609 | } | |
610 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
611 | if (ret) | |
612 | goto out; | |
613 | } | |
614 | ||
615 | /* The real thing. */ | |
616 | for (i = 0; i < 8; i++) { | |
617 | cycles_t start, end; | |
618 | ||
619 | start = get_cycles(); | |
620 | ||
621 | ret = crypto_ahash_init(req); | |
622 | if (ret) | |
623 | goto out; | |
624 | for (pcount = 0; pcount < blen; pcount += plen) { | |
625 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
626 | if (ret) | |
627 | goto out; | |
628 | } | |
629 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
630 | if (ret) | |
631 | goto out; | |
632 | ||
633 | end = get_cycles(); | |
634 | ||
635 | cycles += end - start; | |
636 | } | |
637 | ||
638 | out: | |
639 | if (ret) | |
640 | return ret; | |
641 | ||
642 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", | |
643 | cycles / 8, cycles / (8 * blen)); | |
644 | ||
645 | return 0; | |
646 | } | |
647 | ||
648 | static void test_ahash_speed(const char *algo, unsigned int sec, | |
649 | struct hash_speed *speed) | |
650 | { | |
651 | struct scatterlist sg[TVMEMSIZE]; | |
652 | struct tcrypt_result tresult; | |
653 | struct ahash_request *req; | |
654 | struct crypto_ahash *tfm; | |
655 | static char output[1024]; | |
656 | int i, ret; | |
657 | ||
658 | printk(KERN_INFO "\ntesting speed of async %s\n", algo); | |
659 | ||
660 | tfm = crypto_alloc_ahash(algo, 0, 0); | |
661 | if (IS_ERR(tfm)) { | |
662 | pr_err("failed to load transform for %s: %ld\n", | |
663 | algo, PTR_ERR(tfm)); | |
664 | return; | |
665 | } | |
666 | ||
667 | if (crypto_ahash_digestsize(tfm) > sizeof(output)) { | |
668 | pr_err("digestsize(%u) > outputbuffer(%zu)\n", | |
669 | crypto_ahash_digestsize(tfm), sizeof(output)); | |
670 | goto out; | |
671 | } | |
672 | ||
673 | test_hash_sg_init(sg); | |
674 | req = ahash_request_alloc(tfm, GFP_KERNEL); | |
675 | if (!req) { | |
676 | pr_err("ahash request allocation failure\n"); | |
677 | goto out; | |
678 | } | |
679 | ||
680 | init_completion(&tresult.completion); | |
681 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
682 | tcrypt_complete, &tresult); | |
683 | ||
684 | for (i = 0; speed[i].blen != 0; i++) { | |
685 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { | |
686 | pr_err("template (%u) too big for tvmem (%lu)\n", | |
687 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); | |
688 | break; | |
689 | } | |
690 | ||
691 | pr_info("test%3u " | |
692 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", | |
693 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); | |
694 | ||
695 | ahash_request_set_crypt(req, sg, output, speed[i].plen); | |
696 | ||
697 | if (sec) | |
698 | ret = test_ahash_jiffies(req, speed[i].blen, | |
699 | speed[i].plen, output, sec); | |
700 | else | |
701 | ret = test_ahash_cycles(req, speed[i].blen, | |
702 | speed[i].plen, output); | |
703 | ||
704 | if (ret) { | |
705 | pr_err("hashing failed ret=%d\n", ret); | |
706 | break; | |
707 | } | |
708 | } | |
709 | ||
710 | ahash_request_free(req); | |
711 | ||
712 | out: | |
713 | crypto_free_ahash(tfm); | |
714 | } | |
715 | ||
3f3baf35 JK |
716 | static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret) |
717 | { | |
718 | if (ret == -EINPROGRESS || ret == -EBUSY) { | |
719 | struct tcrypt_result *tr = req->base.data; | |
720 | ||
721 | ret = wait_for_completion_interruptible(&tr->completion); | |
722 | if (!ret) | |
723 | ret = tr->err; | |
724 | INIT_COMPLETION(tr->completion); | |
725 | } | |
726 | ||
727 | return ret; | |
728 | } | |
729 | ||
730 | static int test_acipher_jiffies(struct ablkcipher_request *req, int enc, | |
731 | int blen, int sec) | |
732 | { | |
733 | unsigned long start, end; | |
734 | int bcount; | |
735 | int ret; | |
736 | ||
737 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | |
738 | time_before(jiffies, end); bcount++) { | |
739 | if (enc) | |
740 | ret = do_one_acipher_op(req, | |
741 | crypto_ablkcipher_encrypt(req)); | |
742 | else | |
743 | ret = do_one_acipher_op(req, | |
744 | crypto_ablkcipher_decrypt(req)); | |
745 | ||
746 | if (ret) | |
747 | return ret; | |
748 | } | |
749 | ||
750 | pr_cont("%d operations in %d seconds (%ld bytes)\n", | |
751 | bcount, sec, (long)bcount * blen); | |
752 | return 0; | |
753 | } | |
754 | ||
755 | static int test_acipher_cycles(struct ablkcipher_request *req, int enc, | |
756 | int blen) | |
757 | { | |
758 | unsigned long cycles = 0; | |
759 | int ret = 0; | |
760 | int i; | |
761 | ||
762 | /* Warm-up run. */ | |
763 | for (i = 0; i < 4; i++) { | |
764 | if (enc) | |
765 | ret = do_one_acipher_op(req, | |
766 | crypto_ablkcipher_encrypt(req)); | |
767 | else | |
768 | ret = do_one_acipher_op(req, | |
769 | crypto_ablkcipher_decrypt(req)); | |
770 | ||
771 | if (ret) | |
772 | goto out; | |
773 | } | |
774 | ||
775 | /* The real thing. */ | |
776 | for (i = 0; i < 8; i++) { | |
777 | cycles_t start, end; | |
778 | ||
779 | start = get_cycles(); | |
780 | if (enc) | |
781 | ret = do_one_acipher_op(req, | |
782 | crypto_ablkcipher_encrypt(req)); | |
783 | else | |
784 | ret = do_one_acipher_op(req, | |
785 | crypto_ablkcipher_decrypt(req)); | |
786 | end = get_cycles(); | |
787 | ||
788 | if (ret) | |
789 | goto out; | |
790 | ||
791 | cycles += end - start; | |
792 | } | |
793 | ||
794 | out: | |
795 | if (ret == 0) | |
796 | pr_cont("1 operation in %lu cycles (%d bytes)\n", | |
797 | (cycles + 4) / 8, blen); | |
798 | ||
799 | return ret; | |
800 | } | |
801 | ||
802 | static void test_acipher_speed(const char *algo, int enc, unsigned int sec, | |
803 | struct cipher_speed_template *template, | |
804 | unsigned int tcount, u8 *keysize) | |
805 | { | |
de197533 | 806 | unsigned int ret, i, j, k, iv_len; |
3f3baf35 JK |
807 | struct tcrypt_result tresult; |
808 | const char *key; | |
809 | char iv[128]; | |
810 | struct ablkcipher_request *req; | |
811 | struct crypto_ablkcipher *tfm; | |
812 | const char *e; | |
813 | u32 *b_size; | |
814 | ||
815 | if (enc == ENCRYPT) | |
816 | e = "encryption"; | |
817 | else | |
818 | e = "decryption"; | |
819 | ||
820 | pr_info("\ntesting speed of async %s %s\n", algo, e); | |
821 | ||
822 | init_completion(&tresult.completion); | |
823 | ||
824 | tfm = crypto_alloc_ablkcipher(algo, 0, 0); | |
825 | ||
826 | if (IS_ERR(tfm)) { | |
827 | pr_err("failed to load transform for %s: %ld\n", algo, | |
828 | PTR_ERR(tfm)); | |
829 | return; | |
830 | } | |
831 | ||
832 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); | |
833 | if (!req) { | |
834 | pr_err("tcrypt: skcipher: Failed to allocate request for %s\n", | |
835 | algo); | |
836 | goto out; | |
837 | } | |
838 | ||
839 | ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
840 | tcrypt_complete, &tresult); | |
841 | ||
842 | i = 0; | |
843 | do { | |
844 | b_size = block_sizes; | |
845 | ||
846 | do { | |
847 | struct scatterlist sg[TVMEMSIZE]; | |
848 | ||
849 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { | |
850 | pr_err("template (%u) too big for " | |
851 | "tvmem (%lu)\n", *keysize + *b_size, | |
852 | TVMEMSIZE * PAGE_SIZE); | |
853 | goto out_free_req; | |
854 | } | |
855 | ||
856 | pr_info("test %u (%d bit key, %d byte blocks): ", i, | |
857 | *keysize * 8, *b_size); | |
858 | ||
859 | memset(tvmem[0], 0xff, PAGE_SIZE); | |
860 | ||
861 | /* set key, plain text and IV */ | |
862 | key = tvmem[0]; | |
863 | for (j = 0; j < tcount; j++) { | |
864 | if (template[j].klen == *keysize) { | |
865 | key = template[j].key; | |
866 | break; | |
867 | } | |
868 | } | |
869 | ||
870 | crypto_ablkcipher_clear_flags(tfm, ~0); | |
871 | ||
872 | ret = crypto_ablkcipher_setkey(tfm, key, *keysize); | |
873 | if (ret) { | |
874 | pr_err("setkey() failed flags=%x\n", | |
875 | crypto_ablkcipher_get_flags(tfm)); | |
876 | goto out_free_req; | |
877 | } | |
878 | ||
879 | sg_init_table(sg, TVMEMSIZE); | |
de197533 NR |
880 | |
881 | k = *keysize + *b_size; | |
882 | if (k > PAGE_SIZE) { | |
883 | sg_set_buf(sg, tvmem[0] + *keysize, | |
3f3baf35 | 884 | PAGE_SIZE - *keysize); |
de197533 NR |
885 | k -= PAGE_SIZE; |
886 | j = 1; | |
887 | while (k > PAGE_SIZE) { | |
888 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); | |
889 | memset(tvmem[j], 0xff, PAGE_SIZE); | |
890 | j++; | |
891 | k -= PAGE_SIZE; | |
892 | } | |
893 | sg_set_buf(sg + j, tvmem[j], k); | |
894 | memset(tvmem[j], 0xff, k); | |
895 | } else { | |
896 | sg_set_buf(sg, tvmem[0] + *keysize, *b_size); | |
3f3baf35 JK |
897 | } |
898 | ||
899 | iv_len = crypto_ablkcipher_ivsize(tfm); | |
900 | if (iv_len) | |
901 | memset(&iv, 0xff, iv_len); | |
902 | ||
903 | ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv); | |
904 | ||
905 | if (sec) | |
906 | ret = test_acipher_jiffies(req, enc, | |
907 | *b_size, sec); | |
908 | else | |
909 | ret = test_acipher_cycles(req, enc, | |
910 | *b_size); | |
911 | ||
912 | if (ret) { | |
913 | pr_err("%s() failed flags=%x\n", e, | |
914 | crypto_ablkcipher_get_flags(tfm)); | |
915 | break; | |
916 | } | |
917 | b_size++; | |
918 | i++; | |
919 | } while (*b_size); | |
920 | keysize++; | |
921 | } while (*keysize); | |
922 | ||
923 | out_free_req: | |
924 | ablkcipher_request_free(req); | |
925 | out: | |
926 | crypto_free_ablkcipher(tfm); | |
927 | } | |
928 | ||
ef2736fc | 929 | static void test_available(void) |
1da177e4 LT |
930 | { |
931 | char **name = check; | |
ef2736fc | 932 | |
1da177e4 LT |
933 | while (*name) { |
934 | printk("alg %s ", *name); | |
6158efc0 | 935 | printk(crypto_has_alg(*name, 0, 0) ? |
e4d5b79c | 936 | "found\n" : "not found\n"); |
1da177e4 | 937 | name++; |
ef2736fc | 938 | } |
1da177e4 LT |
939 | } |
940 | ||
01b32324 HX |
941 | static inline int tcrypt_test(const char *alg) |
942 | { | |
4e033a6b JW |
943 | int ret; |
944 | ||
945 | ret = alg_test(alg, alg, 0, 0); | |
946 | /* non-fips algs return -EINVAL in fips mode */ | |
947 | if (fips_enabled && ret == -EINVAL) | |
948 | ret = 0; | |
949 | return ret; | |
01b32324 HX |
950 | } |
951 | ||
4e033a6b | 952 | static int do_test(int m) |
01b32324 HX |
953 | { |
954 | int i; | |
4e033a6b | 955 | int ret = 0; |
01b32324 HX |
956 | |
957 | switch (m) { | |
1da177e4 | 958 | case 0: |
01b32324 | 959 | for (i = 1; i < 200; i++) |
4e033a6b | 960 | ret += do_test(i); |
1da177e4 LT |
961 | break; |
962 | ||
963 | case 1: | |
4e033a6b | 964 | ret += tcrypt_test("md5"); |
1da177e4 LT |
965 | break; |
966 | ||
967 | case 2: | |
4e033a6b | 968 | ret += tcrypt_test("sha1"); |
1da177e4 LT |
969 | break; |
970 | ||
971 | case 3: | |
4e033a6b JW |
972 | ret += tcrypt_test("ecb(des)"); |
973 | ret += tcrypt_test("cbc(des)"); | |
1da177e4 LT |
974 | break; |
975 | ||
976 | case 4: | |
4e033a6b JW |
977 | ret += tcrypt_test("ecb(des3_ede)"); |
978 | ret += tcrypt_test("cbc(des3_ede)"); | |
1da177e4 LT |
979 | break; |
980 | ||
981 | case 5: | |
4e033a6b | 982 | ret += tcrypt_test("md4"); |
1da177e4 | 983 | break; |
ef2736fc | 984 | |
1da177e4 | 985 | case 6: |
4e033a6b | 986 | ret += tcrypt_test("sha256"); |
1da177e4 | 987 | break; |
ef2736fc | 988 | |
1da177e4 | 989 | case 7: |
4e033a6b JW |
990 | ret += tcrypt_test("ecb(blowfish)"); |
991 | ret += tcrypt_test("cbc(blowfish)"); | |
85b63e34 | 992 | ret += tcrypt_test("ctr(blowfish)"); |
1da177e4 LT |
993 | break; |
994 | ||
995 | case 8: | |
4e033a6b JW |
996 | ret += tcrypt_test("ecb(twofish)"); |
997 | ret += tcrypt_test("cbc(twofish)"); | |
573da620 | 998 | ret += tcrypt_test("ctr(twofish)"); |
bee3a90e | 999 | ret += tcrypt_test("lrw(twofish)"); |
131f7541 | 1000 | ret += tcrypt_test("xts(twofish)"); |
1da177e4 | 1001 | break; |
ef2736fc | 1002 | |
1da177e4 | 1003 | case 9: |
4e033a6b | 1004 | ret += tcrypt_test("ecb(serpent)"); |
9d25917d JK |
1005 | ret += tcrypt_test("cbc(serpent)"); |
1006 | ret += tcrypt_test("ctr(serpent)"); | |
87aae4bf | 1007 | ret += tcrypt_test("lrw(serpent)"); |
5209c07a | 1008 | ret += tcrypt_test("xts(serpent)"); |
1da177e4 LT |
1009 | break; |
1010 | ||
1011 | case 10: | |
4e033a6b JW |
1012 | ret += tcrypt_test("ecb(aes)"); |
1013 | ret += tcrypt_test("cbc(aes)"); | |
1014 | ret += tcrypt_test("lrw(aes)"); | |
1015 | ret += tcrypt_test("xts(aes)"); | |
1016 | ret += tcrypt_test("ctr(aes)"); | |
1017 | ret += tcrypt_test("rfc3686(ctr(aes))"); | |
1da177e4 LT |
1018 | break; |
1019 | ||
1020 | case 11: | |
4e033a6b | 1021 | ret += tcrypt_test("sha384"); |
1da177e4 | 1022 | break; |
ef2736fc | 1023 | |
1da177e4 | 1024 | case 12: |
4e033a6b | 1025 | ret += tcrypt_test("sha512"); |
1da177e4 LT |
1026 | break; |
1027 | ||
1028 | case 13: | |
4e033a6b | 1029 | ret += tcrypt_test("deflate"); |
1da177e4 LT |
1030 | break; |
1031 | ||
1032 | case 14: | |
4e033a6b | 1033 | ret += tcrypt_test("ecb(cast5)"); |
a2c58260 JG |
1034 | ret += tcrypt_test("cbc(cast5)"); |
1035 | ret += tcrypt_test("ctr(cast5)"); | |
1da177e4 LT |
1036 | break; |
1037 | ||
1038 | case 15: | |
4e033a6b | 1039 | ret += tcrypt_test("ecb(cast6)"); |
9b8b0405 JG |
1040 | ret += tcrypt_test("cbc(cast6)"); |
1041 | ret += tcrypt_test("ctr(cast6)"); | |
1042 | ret += tcrypt_test("lrw(cast6)"); | |
1043 | ret += tcrypt_test("xts(cast6)"); | |
1da177e4 LT |
1044 | break; |
1045 | ||
1046 | case 16: | |
4e033a6b | 1047 | ret += tcrypt_test("ecb(arc4)"); |
1da177e4 LT |
1048 | break; |
1049 | ||
1050 | case 17: | |
4e033a6b | 1051 | ret += tcrypt_test("michael_mic"); |
1da177e4 LT |
1052 | break; |
1053 | ||
1054 | case 18: | |
4e033a6b | 1055 | ret += tcrypt_test("crc32c"); |
1da177e4 LT |
1056 | break; |
1057 | ||
1058 | case 19: | |
4e033a6b | 1059 | ret += tcrypt_test("ecb(tea)"); |
1da177e4 LT |
1060 | break; |
1061 | ||
1062 | case 20: | |
4e033a6b | 1063 | ret += tcrypt_test("ecb(xtea)"); |
1da177e4 LT |
1064 | break; |
1065 | ||
1066 | case 21: | |
4e033a6b | 1067 | ret += tcrypt_test("ecb(khazad)"); |
1da177e4 LT |
1068 | break; |
1069 | ||
1070 | case 22: | |
4e033a6b | 1071 | ret += tcrypt_test("wp512"); |
1da177e4 LT |
1072 | break; |
1073 | ||
1074 | case 23: | |
4e033a6b | 1075 | ret += tcrypt_test("wp384"); |
1da177e4 LT |
1076 | break; |
1077 | ||
1078 | case 24: | |
4e033a6b | 1079 | ret += tcrypt_test("wp256"); |
1da177e4 LT |
1080 | break; |
1081 | ||
1082 | case 25: | |
4e033a6b | 1083 | ret += tcrypt_test("ecb(tnepres)"); |
1da177e4 LT |
1084 | break; |
1085 | ||
1086 | case 26: | |
4e033a6b JW |
1087 | ret += tcrypt_test("ecb(anubis)"); |
1088 | ret += tcrypt_test("cbc(anubis)"); | |
1da177e4 LT |
1089 | break; |
1090 | ||
1091 | case 27: | |
4e033a6b | 1092 | ret += tcrypt_test("tgr192"); |
1da177e4 LT |
1093 | break; |
1094 | ||
1095 | case 28: | |
1096 | ||
4e033a6b | 1097 | ret += tcrypt_test("tgr160"); |
1da177e4 LT |
1098 | break; |
1099 | ||
1100 | case 29: | |
4e033a6b | 1101 | ret += tcrypt_test("tgr128"); |
1da177e4 | 1102 | break; |
2998db37 | 1103 | |
fb4f10ed | 1104 | case 30: |
4e033a6b | 1105 | ret += tcrypt_test("ecb(xeta)"); |
fb4f10ed | 1106 | break; |
1da177e4 | 1107 | |
90831639 | 1108 | case 31: |
4e033a6b | 1109 | ret += tcrypt_test("pcbc(fcrypt)"); |
90831639 DH |
1110 | break; |
1111 | ||
02ab5a70 | 1112 | case 32: |
4e033a6b JW |
1113 | ret += tcrypt_test("ecb(camellia)"); |
1114 | ret += tcrypt_test("cbc(camellia)"); | |
54216bbd JK |
1115 | ret += tcrypt_test("ctr(camellia)"); |
1116 | ret += tcrypt_test("lrw(camellia)"); | |
1117 | ret += tcrypt_test("xts(camellia)"); | |
02ab5a70 | 1118 | break; |
cd12fb90 | 1119 | case 33: |
4e033a6b | 1120 | ret += tcrypt_test("sha224"); |
cd12fb90 | 1121 | break; |
02ab5a70 | 1122 | |
2407d608 | 1123 | case 34: |
4e033a6b | 1124 | ret += tcrypt_test("salsa20"); |
2407d608 TSH |
1125 | break; |
1126 | ||
8df213d9 | 1127 | case 35: |
4e033a6b | 1128 | ret += tcrypt_test("gcm(aes)"); |
8df213d9 HX |
1129 | break; |
1130 | ||
0b77abb3 | 1131 | case 36: |
4e033a6b | 1132 | ret += tcrypt_test("lzo"); |
0b77abb3 ZS |
1133 | break; |
1134 | ||
93cc74e0 | 1135 | case 37: |
4e033a6b | 1136 | ret += tcrypt_test("ccm(aes)"); |
93cc74e0 JL |
1137 | break; |
1138 | ||
76cb9521 | 1139 | case 38: |
4e033a6b | 1140 | ret += tcrypt_test("cts(cbc(aes))"); |
76cb9521 KC |
1141 | break; |
1142 | ||
fd4adf1a | 1143 | case 39: |
4e033a6b | 1144 | ret += tcrypt_test("rmd128"); |
fd4adf1a AKR |
1145 | break; |
1146 | ||
1147 | case 40: | |
4e033a6b | 1148 | ret += tcrypt_test("rmd160"); |
fd4adf1a AKR |
1149 | break; |
1150 | ||
2998db37 | 1151 | case 41: |
4e033a6b | 1152 | ret += tcrypt_test("rmd256"); |
2998db37 AKR |
1153 | break; |
1154 | ||
1155 | case 42: | |
4e033a6b | 1156 | ret += tcrypt_test("rmd320"); |
01b32324 HX |
1157 | break; |
1158 | ||
1159 | case 43: | |
4e033a6b | 1160 | ret += tcrypt_test("ecb(seed)"); |
2998db37 AKR |
1161 | break; |
1162 | ||
0c01aed5 | 1163 | case 44: |
4e033a6b | 1164 | ret += tcrypt_test("zlib"); |
0c01aed5 GU |
1165 | break; |
1166 | ||
5d667322 | 1167 | case 45: |
4e033a6b | 1168 | ret += tcrypt_test("rfc4309(ccm(aes))"); |
5d667322 JW |
1169 | break; |
1170 | ||
54216bbd JK |
1171 | case 46: |
1172 | ret += tcrypt_test("ghash"); | |
1173 | break; | |
1174 | ||
1da177e4 | 1175 | case 100: |
4e033a6b | 1176 | ret += tcrypt_test("hmac(md5)"); |
1da177e4 | 1177 | break; |
ef2736fc | 1178 | |
1da177e4 | 1179 | case 101: |
4e033a6b | 1180 | ret += tcrypt_test("hmac(sha1)"); |
1da177e4 | 1181 | break; |
ef2736fc | 1182 | |
1da177e4 | 1183 | case 102: |
4e033a6b | 1184 | ret += tcrypt_test("hmac(sha256)"); |
1da177e4 LT |
1185 | break; |
1186 | ||
a28091ae | 1187 | case 103: |
4e033a6b | 1188 | ret += tcrypt_test("hmac(sha384)"); |
a28091ae AD |
1189 | break; |
1190 | ||
1191 | case 104: | |
4e033a6b | 1192 | ret += tcrypt_test("hmac(sha512)"); |
a28091ae | 1193 | break; |
38ed9ab2 | 1194 | |
cd12fb90 | 1195 | case 105: |
4e033a6b | 1196 | ret += tcrypt_test("hmac(sha224)"); |
cd12fb90 | 1197 | break; |
1da177e4 | 1198 | |
38ed9ab2 | 1199 | case 106: |
4e033a6b | 1200 | ret += tcrypt_test("xcbc(aes)"); |
38ed9ab2 HX |
1201 | break; |
1202 | ||
fd4adf1a | 1203 | case 107: |
4e033a6b | 1204 | ret += tcrypt_test("hmac(rmd128)"); |
fd4adf1a AKR |
1205 | break; |
1206 | ||
1207 | case 108: | |
4e033a6b | 1208 | ret += tcrypt_test("hmac(rmd160)"); |
fd4adf1a AKR |
1209 | break; |
1210 | ||
f1939f7c SW |
1211 | case 109: |
1212 | ret += tcrypt_test("vmac(aes)"); | |
1213 | break; | |
a482b081 SZ |
1214 | case 110: |
1215 | ret += tcrypt_test("hmac(crc32)"); | |
1216 | break; | |
f1939f7c | 1217 | |
e08ca2da | 1218 | case 150: |
4e033a6b | 1219 | ret += tcrypt_test("ansi_cprng"); |
e08ca2da JW |
1220 | break; |
1221 | ||
69435b94 AH |
1222 | case 151: |
1223 | ret += tcrypt_test("rfc4106(gcm(aes))"); | |
1224 | break; | |
1225 | ||
ebfd9bcf | 1226 | case 200: |
cba83564 | 1227 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1228 | speed_template_16_24_32); |
cba83564 | 1229 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1230 | speed_template_16_24_32); |
cba83564 | 1231 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1232 | speed_template_16_24_32); |
cba83564 | 1233 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1234 | speed_template_16_24_32); |
f3d1044c | 1235 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1236 | speed_template_32_40_48); |
f3d1044c | 1237 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1238 | speed_template_32_40_48); |
f19f5111 | 1239 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1240 | speed_template_32_48_64); |
f19f5111 | 1241 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1242 | speed_template_32_48_64); |
9996e342 JG |
1243 | test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
1244 | speed_template_16_24_32); | |
1245 | test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, | |
1246 | speed_template_16_24_32); | |
ebfd9bcf HW |
1247 | break; |
1248 | ||
1249 | case 201: | |
cba83564 | 1250 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
da7f033d | 1251 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1252 | speed_template_24); |
cba83564 | 1253 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
da7f033d | 1254 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1255 | speed_template_24); |
cba83564 | 1256 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
da7f033d | 1257 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1258 | speed_template_24); |
cba83564 | 1259 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
da7f033d | 1260 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1261 | speed_template_24); |
ebfd9bcf HW |
1262 | break; |
1263 | ||
1264 | case 202: | |
cba83564 | 1265 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1266 | speed_template_16_24_32); |
cba83564 | 1267 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1268 | speed_template_16_24_32); |
cba83564 | 1269 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1270 | speed_template_16_24_32); |
cba83564 | 1271 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1272 | speed_template_16_24_32); |
ee5002a5 JK |
1273 | test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
1274 | speed_template_16_24_32); | |
1275 | test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, | |
1276 | speed_template_16_24_32); | |
bee3a90e JK |
1277 | test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
1278 | speed_template_32_40_48); | |
1279 | test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, | |
1280 | speed_template_32_40_48); | |
131f7541 JK |
1281 | test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
1282 | speed_template_32_48_64); | |
1283 | test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, | |
1284 | speed_template_32_48_64); | |
ebfd9bcf HW |
1285 | break; |
1286 | ||
1287 | case 203: | |
cba83564 | 1288 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1289 | speed_template_8_32); |
cba83564 | 1290 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1291 | speed_template_8_32); |
cba83564 | 1292 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1293 | speed_template_8_32); |
cba83564 | 1294 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1295 | speed_template_8_32); |
7d47b86c JK |
1296 | test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
1297 | speed_template_8_32); | |
1298 | test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, | |
1299 | speed_template_8_32); | |
ebfd9bcf HW |
1300 | break; |
1301 | ||
1302 | case 204: | |
cba83564 | 1303 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1304 | speed_template_8); |
cba83564 | 1305 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1306 | speed_template_8); |
cba83564 | 1307 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1308 | speed_template_8); |
cba83564 | 1309 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1310 | speed_template_8); |
ebfd9bcf HW |
1311 | break; |
1312 | ||
02ab5a70 NT |
1313 | case 205: |
1314 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1315 | speed_template_16_24_32); |
02ab5a70 | 1316 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1317 | speed_template_16_24_32); |
02ab5a70 | 1318 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1319 | speed_template_16_24_32); |
02ab5a70 | 1320 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1321 | speed_template_16_24_32); |
4de59337 JK |
1322 | test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
1323 | speed_template_16_24_32); | |
1324 | test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, | |
1325 | speed_template_16_24_32); | |
1326 | test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, | |
1327 | speed_template_32_40_48); | |
1328 | test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, | |
1329 | speed_template_32_40_48); | |
1330 | test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, | |
1331 | speed_template_32_48_64); | |
1332 | test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, | |
1333 | speed_template_32_48_64); | |
02ab5a70 NT |
1334 | break; |
1335 | ||
5de8f1b5 TSH |
1336 | case 206: |
1337 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1338 | speed_template_16_32); |
5de8f1b5 TSH |
1339 | break; |
1340 | ||
7fb7fe44 JK |
1341 | case 207: |
1342 | test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, | |
1343 | speed_template_16_32); | |
1344 | test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, | |
1345 | speed_template_16_32); | |
1346 | test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, | |
1347 | speed_template_16_32); | |
1348 | test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, | |
1349 | speed_template_16_32); | |
1350 | test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, | |
1351 | speed_template_16_32); | |
1352 | test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, | |
1353 | speed_template_16_32); | |
87aae4bf JK |
1354 | test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
1355 | speed_template_32_48); | |
1356 | test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, | |
1357 | speed_template_32_48); | |
5209c07a JK |
1358 | test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
1359 | speed_template_32_64); | |
1360 | test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, | |
1361 | speed_template_32_64); | |
7fb7fe44 JK |
1362 | break; |
1363 | ||
31b4cd29 JK |
1364 | case 208: |
1365 | test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, | |
1366 | speed_template_8); | |
1367 | break; | |
1368 | ||
a2c58260 JG |
1369 | case 209: |
1370 | test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, | |
1371 | speed_template_8_16); | |
1372 | test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, | |
1373 | speed_template_8_16); | |
1374 | test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, | |
1375 | speed_template_8_16); | |
1376 | test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, | |
1377 | speed_template_8_16); | |
1378 | test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, | |
1379 | speed_template_8_16); | |
1380 | test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, | |
1381 | speed_template_8_16); | |
1382 | break; | |
1383 | ||
9b8b0405 JG |
1384 | case 210: |
1385 | test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, | |
1386 | speed_template_16_32); | |
1387 | test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, | |
1388 | speed_template_16_32); | |
1389 | test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, | |
1390 | speed_template_16_32); | |
1391 | test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, | |
1392 | speed_template_16_32); | |
1393 | test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, | |
1394 | speed_template_16_32); | |
1395 | test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, | |
1396 | speed_template_16_32); | |
1397 | test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, | |
1398 | speed_template_32_48); | |
1399 | test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, | |
1400 | speed_template_32_48); | |
1401 | test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, | |
1402 | speed_template_32_64); | |
1403 | test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, | |
1404 | speed_template_32_64); | |
1405 | break; | |
1406 | ||
e8057928 ML |
1407 | case 300: |
1408 | /* fall through */ | |
1409 | ||
1410 | case 301: | |
e9d41164 | 1411 | test_hash_speed("md4", sec, generic_hash_speed_template); |
e8057928 ML |
1412 | if (mode > 300 && mode < 400) break; |
1413 | ||
1414 | case 302: | |
e9d41164 | 1415 | test_hash_speed("md5", sec, generic_hash_speed_template); |
e8057928 ML |
1416 | if (mode > 300 && mode < 400) break; |
1417 | ||
1418 | case 303: | |
e9d41164 | 1419 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
e8057928 ML |
1420 | if (mode > 300 && mode < 400) break; |
1421 | ||
1422 | case 304: | |
e9d41164 | 1423 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
e8057928 ML |
1424 | if (mode > 300 && mode < 400) break; |
1425 | ||
1426 | case 305: | |
e9d41164 | 1427 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
e8057928 ML |
1428 | if (mode > 300 && mode < 400) break; |
1429 | ||
1430 | case 306: | |
e9d41164 | 1431 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
e8057928 ML |
1432 | if (mode > 300 && mode < 400) break; |
1433 | ||
1434 | case 307: | |
e9d41164 | 1435 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
e8057928 ML |
1436 | if (mode > 300 && mode < 400) break; |
1437 | ||
1438 | case 308: | |
e9d41164 | 1439 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
e8057928 ML |
1440 | if (mode > 300 && mode < 400) break; |
1441 | ||
1442 | case 309: | |
e9d41164 | 1443 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
e8057928 ML |
1444 | if (mode > 300 && mode < 400) break; |
1445 | ||
1446 | case 310: | |
e9d41164 | 1447 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
e8057928 ML |
1448 | if (mode > 300 && mode < 400) break; |
1449 | ||
1450 | case 311: | |
e9d41164 | 1451 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
e8057928 ML |
1452 | if (mode > 300 && mode < 400) break; |
1453 | ||
1454 | case 312: | |
e9d41164 | 1455 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
e8057928 ML |
1456 | if (mode > 300 && mode < 400) break; |
1457 | ||
cd12fb90 JL |
1458 | case 313: |
1459 | test_hash_speed("sha224", sec, generic_hash_speed_template); | |
1460 | if (mode > 300 && mode < 400) break; | |
1461 | ||
fd4adf1a AKR |
1462 | case 314: |
1463 | test_hash_speed("rmd128", sec, generic_hash_speed_template); | |
1464 | if (mode > 300 && mode < 400) break; | |
1465 | ||
1466 | case 315: | |
1467 | test_hash_speed("rmd160", sec, generic_hash_speed_template); | |
1468 | if (mode > 300 && mode < 400) break; | |
1469 | ||
2998db37 AKR |
1470 | case 316: |
1471 | test_hash_speed("rmd256", sec, generic_hash_speed_template); | |
1472 | if (mode > 300 && mode < 400) break; | |
1473 | ||
1474 | case 317: | |
1475 | test_hash_speed("rmd320", sec, generic_hash_speed_template); | |
1476 | if (mode > 300 && mode < 400) break; | |
1477 | ||
18bcc919 YH |
1478 | case 318: |
1479 | test_hash_speed("ghash-generic", sec, hash_speed_template_16); | |
1480 | if (mode > 300 && mode < 400) break; | |
1481 | ||
e8057928 ML |
1482 | case 399: |
1483 | break; | |
1484 | ||
beb63da7 DM |
1485 | case 400: |
1486 | /* fall through */ | |
1487 | ||
1488 | case 401: | |
1489 | test_ahash_speed("md4", sec, generic_hash_speed_template); | |
1490 | if (mode > 400 && mode < 500) break; | |
1491 | ||
1492 | case 402: | |
1493 | test_ahash_speed("md5", sec, generic_hash_speed_template); | |
1494 | if (mode > 400 && mode < 500) break; | |
1495 | ||
1496 | case 403: | |
1497 | test_ahash_speed("sha1", sec, generic_hash_speed_template); | |
1498 | if (mode > 400 && mode < 500) break; | |
1499 | ||
1500 | case 404: | |
1501 | test_ahash_speed("sha256", sec, generic_hash_speed_template); | |
1502 | if (mode > 400 && mode < 500) break; | |
1503 | ||
1504 | case 405: | |
1505 | test_ahash_speed("sha384", sec, generic_hash_speed_template); | |
1506 | if (mode > 400 && mode < 500) break; | |
1507 | ||
1508 | case 406: | |
1509 | test_ahash_speed("sha512", sec, generic_hash_speed_template); | |
1510 | if (mode > 400 && mode < 500) break; | |
1511 | ||
1512 | case 407: | |
1513 | test_ahash_speed("wp256", sec, generic_hash_speed_template); | |
1514 | if (mode > 400 && mode < 500) break; | |
1515 | ||
1516 | case 408: | |
1517 | test_ahash_speed("wp384", sec, generic_hash_speed_template); | |
1518 | if (mode > 400 && mode < 500) break; | |
1519 | ||
1520 | case 409: | |
1521 | test_ahash_speed("wp512", sec, generic_hash_speed_template); | |
1522 | if (mode > 400 && mode < 500) break; | |
1523 | ||
1524 | case 410: | |
1525 | test_ahash_speed("tgr128", sec, generic_hash_speed_template); | |
1526 | if (mode > 400 && mode < 500) break; | |
1527 | ||
1528 | case 411: | |
1529 | test_ahash_speed("tgr160", sec, generic_hash_speed_template); | |
1530 | if (mode > 400 && mode < 500) break; | |
1531 | ||
1532 | case 412: | |
1533 | test_ahash_speed("tgr192", sec, generic_hash_speed_template); | |
1534 | if (mode > 400 && mode < 500) break; | |
1535 | ||
1536 | case 413: | |
1537 | test_ahash_speed("sha224", sec, generic_hash_speed_template); | |
1538 | if (mode > 400 && mode < 500) break; | |
1539 | ||
1540 | case 414: | |
1541 | test_ahash_speed("rmd128", sec, generic_hash_speed_template); | |
1542 | if (mode > 400 && mode < 500) break; | |
1543 | ||
1544 | case 415: | |
1545 | test_ahash_speed("rmd160", sec, generic_hash_speed_template); | |
1546 | if (mode > 400 && mode < 500) break; | |
1547 | ||
1548 | case 416: | |
1549 | test_ahash_speed("rmd256", sec, generic_hash_speed_template); | |
1550 | if (mode > 400 && mode < 500) break; | |
1551 | ||
1552 | case 417: | |
1553 | test_ahash_speed("rmd320", sec, generic_hash_speed_template); | |
1554 | if (mode > 400 && mode < 500) break; | |
1555 | ||
1556 | case 499: | |
1557 | break; | |
1558 | ||
3f3baf35 JK |
1559 | case 500: |
1560 | test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, | |
1561 | speed_template_16_24_32); | |
1562 | test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, | |
1563 | speed_template_16_24_32); | |
1564 | test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, | |
1565 | speed_template_16_24_32); | |
1566 | test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, | |
1567 | speed_template_16_24_32); | |
1568 | test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, | |
1569 | speed_template_32_40_48); | |
1570 | test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, | |
1571 | speed_template_32_40_48); | |
1572 | test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, | |
1573 | speed_template_32_48_64); | |
1574 | test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, | |
1575 | speed_template_32_48_64); | |
1576 | test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, | |
1577 | speed_template_16_24_32); | |
1578 | test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, | |
1579 | speed_template_16_24_32); | |
de197533 NR |
1580 | test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, |
1581 | speed_template_16_24_32); | |
1582 | test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, | |
1583 | speed_template_16_24_32); | |
1584 | test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, | |
1585 | speed_template_16_24_32); | |
1586 | test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, | |
1587 | speed_template_16_24_32); | |
3f3baf35 JK |
1588 | break; |
1589 | ||
1590 | case 501: | |
1591 | test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec, | |
1592 | des3_speed_template, DES3_SPEED_VECTORS, | |
1593 | speed_template_24); | |
1594 | test_acipher_speed("ecb(des3_ede)", DECRYPT, sec, | |
1595 | des3_speed_template, DES3_SPEED_VECTORS, | |
1596 | speed_template_24); | |
1597 | test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec, | |
1598 | des3_speed_template, DES3_SPEED_VECTORS, | |
1599 | speed_template_24); | |
1600 | test_acipher_speed("cbc(des3_ede)", DECRYPT, sec, | |
1601 | des3_speed_template, DES3_SPEED_VECTORS, | |
1602 | speed_template_24); | |
de197533 NR |
1603 | test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec, |
1604 | des3_speed_template, DES3_SPEED_VECTORS, | |
1605 | speed_template_24); | |
1606 | test_acipher_speed("cfb(des3_ede)", DECRYPT, sec, | |
1607 | des3_speed_template, DES3_SPEED_VECTORS, | |
1608 | speed_template_24); | |
1609 | test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec, | |
1610 | des3_speed_template, DES3_SPEED_VECTORS, | |
1611 | speed_template_24); | |
1612 | test_acipher_speed("ofb(des3_ede)", DECRYPT, sec, | |
1613 | des3_speed_template, DES3_SPEED_VECTORS, | |
1614 | speed_template_24); | |
3f3baf35 JK |
1615 | break; |
1616 | ||
1617 | case 502: | |
1618 | test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, | |
1619 | speed_template_8); | |
1620 | test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, | |
1621 | speed_template_8); | |
1622 | test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, | |
1623 | speed_template_8); | |
1624 | test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, | |
1625 | speed_template_8); | |
de197533 NR |
1626 | test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, |
1627 | speed_template_8); | |
1628 | test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, | |
1629 | speed_template_8); | |
1630 | test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, | |
1631 | speed_template_8); | |
1632 | test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, | |
1633 | speed_template_8); | |
3f3baf35 JK |
1634 | break; |
1635 | ||
7fb7fe44 JK |
1636 | case 503: |
1637 | test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, | |
1638 | speed_template_16_32); | |
1639 | test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, | |
1640 | speed_template_16_32); | |
1641 | test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, | |
1642 | speed_template_16_32); | |
1643 | test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, | |
1644 | speed_template_16_32); | |
1645 | test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, | |
1646 | speed_template_16_32); | |
1647 | test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, | |
1648 | speed_template_16_32); | |
87aae4bf JK |
1649 | test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
1650 | speed_template_32_48); | |
1651 | test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, | |
1652 | speed_template_32_48); | |
5209c07a JK |
1653 | test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
1654 | speed_template_32_64); | |
1655 | test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, | |
1656 | speed_template_32_64); | |
7fb7fe44 JK |
1657 | break; |
1658 | ||
107778b5 JG |
1659 | case 504: |
1660 | test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, | |
1661 | speed_template_16_24_32); | |
1662 | test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, | |
1663 | speed_template_16_24_32); | |
1664 | test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, | |
1665 | speed_template_16_24_32); | |
1666 | test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, | |
1667 | speed_template_16_24_32); | |
1668 | test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, | |
1669 | speed_template_16_24_32); | |
1670 | test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, | |
1671 | speed_template_16_24_32); | |
1672 | test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, | |
1673 | speed_template_32_40_48); | |
1674 | test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, | |
1675 | speed_template_32_40_48); | |
1676 | test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, | |
1677 | speed_template_32_48_64); | |
1678 | test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, | |
1679 | speed_template_32_48_64); | |
1680 | break; | |
1681 | ||
31b4cd29 JK |
1682 | case 505: |
1683 | test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, | |
1684 | speed_template_8); | |
1685 | break; | |
1686 | ||
a2c58260 JG |
1687 | case 506: |
1688 | test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, | |
1689 | speed_template_8_16); | |
1690 | test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, | |
1691 | speed_template_8_16); | |
1692 | test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, | |
1693 | speed_template_8_16); | |
1694 | test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, | |
1695 | speed_template_8_16); | |
1696 | test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, | |
1697 | speed_template_8_16); | |
1698 | test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, | |
1699 | speed_template_8_16); | |
1700 | break; | |
1701 | ||
9b8b0405 JG |
1702 | case 507: |
1703 | test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, | |
1704 | speed_template_16_32); | |
1705 | test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, | |
1706 | speed_template_16_32); | |
1707 | test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, | |
1708 | speed_template_16_32); | |
1709 | test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, | |
1710 | speed_template_16_32); | |
1711 | test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, | |
1712 | speed_template_16_32); | |
1713 | test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, | |
1714 | speed_template_16_32); | |
1715 | test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, | |
1716 | speed_template_32_48); | |
1717 | test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, | |
1718 | speed_template_32_48); | |
1719 | test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, | |
1720 | speed_template_32_64); | |
1721 | test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, | |
1722 | speed_template_32_64); | |
1723 | break; | |
1724 | ||
1da177e4 LT |
1725 | case 1000: |
1726 | test_available(); | |
1727 | break; | |
1da177e4 | 1728 | } |
4e033a6b JW |
1729 | |
1730 | return ret; | |
1da177e4 LT |
1731 | } |
1732 | ||
7be380f7 | 1733 | static int do_alg_test(const char *alg, u32 type, u32 mask) |
a873a5f1 | 1734 | { |
7be380f7 HX |
1735 | return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ? |
1736 | 0 : -ENOENT; | |
a873a5f1 SK |
1737 | } |
1738 | ||
3af5b90b | 1739 | static int __init tcrypt_mod_init(void) |
1da177e4 | 1740 | { |
e3a4ea4f | 1741 | int err = -ENOMEM; |
f139cfa7 | 1742 | int i; |
e3a4ea4f | 1743 | |
f139cfa7 HX |
1744 | for (i = 0; i < TVMEMSIZE; i++) { |
1745 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); | |
1746 | if (!tvmem[i]) | |
1747 | goto err_free_tv; | |
1748 | } | |
1da177e4 | 1749 | |
a873a5f1 | 1750 | if (alg) |
7be380f7 | 1751 | err = do_alg_test(alg, type, mask); |
a873a5f1 SK |
1752 | else |
1753 | err = do_test(mode); | |
1754 | ||
4e033a6b JW |
1755 | if (err) { |
1756 | printk(KERN_ERR "tcrypt: one or more tests failed!\n"); | |
1757 | goto err_free_tv; | |
1758 | } | |
14fdf477 | 1759 | |
4e033a6b JW |
1760 | /* We intentionaly return -EAGAIN to prevent keeping the module, |
1761 | * unless we're running in fips mode. It does all its work from | |
1762 | * init() and doesn't offer any runtime functionality, but in | |
1763 | * the fips case, checking for a successful load is helpful. | |
14fdf477 ML |
1764 | * => we don't need it in the memory, do we? |
1765 | * -- mludvig | |
1766 | */ | |
4e033a6b JW |
1767 | if (!fips_enabled) |
1768 | err = -EAGAIN; | |
e3a4ea4f | 1769 | |
f139cfa7 HX |
1770 | err_free_tv: |
1771 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) | |
1772 | free_page((unsigned long)tvmem[i]); | |
e3a4ea4f MH |
1773 | |
1774 | return err; | |
1da177e4 LT |
1775 | } |
1776 | ||
1777 | /* | |
1778 | * If an init function is provided, an exit function must also be provided | |
1779 | * to allow module unload. | |
1780 | */ | |
3af5b90b | 1781 | static void __exit tcrypt_mod_fini(void) { } |
1da177e4 | 1782 | |
3af5b90b KB |
1783 | module_init(tcrypt_mod_init); |
1784 | module_exit(tcrypt_mod_fini); | |
1da177e4 | 1785 | |
a873a5f1 SK |
1786 | module_param(alg, charp, 0); |
1787 | module_param(type, uint, 0); | |
7be380f7 | 1788 | module_param(mask, uint, 0); |
1da177e4 | 1789 | module_param(mode, int, 0); |
ebfd9bcf | 1790 | module_param(sec, uint, 0); |
6a17944c HX |
1791 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
1792 | "(defaults to zero which uses CPU cycles instead)"); | |
1da177e4 LT |
1793 | |
1794 | MODULE_LICENSE("GPL"); | |
1795 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | |
1796 | MODULE_AUTHOR("James Morris <[email protected]>"); |