]>
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 <jmorris@intercode.com.au> | |
8 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> | |
e3a4ea4f | 9 | * Copyright (c) 2007 Nokia Siemens Networks |
1da177e4 | 10 | * |
69435b94 AH |
11 | * Updated RFC4106 AES-GCM testing. |
12 | * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) | |
13 | * Adrian Hoban <adrian.hoban@intel.com> | |
14 | * Gabriele Paoloni <gabriele.paoloni@intel.com> | |
15 | * Tadeusz Struk (tadeusz.struk@intel.com) | |
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 | |
263a8df0 LC |
50 | /* |
51 | * return a string with the driver name | |
52 | */ | |
53 | #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm)) | |
54 | ||
ebfd9bcf HW |
55 | /* |
56 | * Used by test_cipher_speed() | |
57 | */ | |
6a17944c | 58 | static unsigned int sec; |
ebfd9bcf | 59 | |
a873a5f1 SK |
60 | static char *alg = NULL; |
61 | static u32 type; | |
7be380f7 | 62 | static u32 mask; |
1da177e4 | 63 | static int mode; |
f139cfa7 | 64 | static char *tvmem[TVMEMSIZE]; |
1da177e4 LT |
65 | |
66 | static char *check[] = { | |
cd12fb90 JL |
67 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
68 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", | |
69 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | |
90831639 | 70 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
2998db37 | 71 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
0c01aed5 | 72 | "lzo", "cts", "zlib", NULL |
1da177e4 LT |
73 | }; |
74 | ||
f139cfa7 | 75 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, |
3e3dc25f | 76 | struct scatterlist *sg, int blen, int secs) |
6a17944c | 77 | { |
6a17944c HX |
78 | unsigned long start, end; |
79 | int bcount; | |
80 | int ret; | |
81 | ||
3e3dc25f | 82 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
6a17944c HX |
83 | time_before(jiffies, end); bcount++) { |
84 | if (enc) | |
cba83564 | 85 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 86 | else |
cba83564 | 87 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
88 | |
89 | if (ret) | |
90 | return ret; | |
91 | } | |
92 | ||
93 | printk("%d operations in %d seconds (%ld bytes)\n", | |
3e3dc25f | 94 | bcount, secs, (long)bcount * blen); |
6a17944c HX |
95 | return 0; |
96 | } | |
97 | ||
f139cfa7 HX |
98 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, |
99 | struct scatterlist *sg, int blen) | |
6a17944c | 100 | { |
6a17944c HX |
101 | unsigned long cycles = 0; |
102 | int ret = 0; | |
103 | int i; | |
104 | ||
6a17944c HX |
105 | local_irq_disable(); |
106 | ||
107 | /* Warm-up run. */ | |
108 | for (i = 0; i < 4; i++) { | |
109 | if (enc) | |
cba83564 | 110 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 111 | else |
cba83564 | 112 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
113 | |
114 | if (ret) | |
115 | goto out; | |
116 | } | |
117 | ||
118 | /* The real thing. */ | |
119 | for (i = 0; i < 8; i++) { | |
120 | cycles_t start, end; | |
121 | ||
122 | start = get_cycles(); | |
123 | if (enc) | |
cba83564 | 124 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
6a17944c | 125 | else |
cba83564 | 126 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
6a17944c HX |
127 | end = get_cycles(); |
128 | ||
129 | if (ret) | |
130 | goto out; | |
131 | ||
132 | cycles += end - start; | |
133 | } | |
134 | ||
135 | out: | |
136 | local_irq_enable(); | |
6a17944c HX |
137 | |
138 | if (ret == 0) | |
139 | printk("1 operation in %lu cycles (%d bytes)\n", | |
140 | (cycles + 4) / 8, blen); | |
141 | ||
142 | return ret; | |
143 | } | |
144 | ||
53f52d7a | 145 | static int test_aead_jiffies(struct aead_request *req, int enc, |
3e3dc25f | 146 | int blen, int secs) |
53f52d7a TC |
147 | { |
148 | unsigned long start, end; | |
149 | int bcount; | |
150 | int ret; | |
151 | ||
3e3dc25f | 152 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
53f52d7a TC |
153 | time_before(jiffies, end); bcount++) { |
154 | if (enc) | |
155 | ret = crypto_aead_encrypt(req); | |
156 | else | |
157 | ret = crypto_aead_decrypt(req); | |
158 | ||
159 | if (ret) | |
160 | return ret; | |
161 | } | |
162 | ||
163 | printk("%d operations in %d seconds (%ld bytes)\n", | |
3e3dc25f | 164 | bcount, secs, (long)bcount * blen); |
53f52d7a TC |
165 | return 0; |
166 | } | |
167 | ||
168 | static int test_aead_cycles(struct aead_request *req, int enc, int blen) | |
169 | { | |
170 | unsigned long cycles = 0; | |
171 | int ret = 0; | |
172 | int i; | |
173 | ||
174 | local_irq_disable(); | |
175 | ||
176 | /* Warm-up run. */ | |
177 | for (i = 0; i < 4; i++) { | |
178 | if (enc) | |
179 | ret = crypto_aead_encrypt(req); | |
180 | else | |
181 | ret = crypto_aead_decrypt(req); | |
182 | ||
183 | if (ret) | |
184 | goto out; | |
185 | } | |
186 | ||
187 | /* The real thing. */ | |
188 | for (i = 0; i < 8; i++) { | |
189 | cycles_t start, end; | |
190 | ||
191 | start = get_cycles(); | |
192 | if (enc) | |
193 | ret = crypto_aead_encrypt(req); | |
194 | else | |
195 | ret = crypto_aead_decrypt(req); | |
196 | end = get_cycles(); | |
197 | ||
198 | if (ret) | |
199 | goto out; | |
200 | ||
201 | cycles += end - start; | |
202 | } | |
203 | ||
204 | out: | |
205 | local_irq_enable(); | |
206 | ||
207 | if (ret == 0) | |
208 | printk("1 operation in %lu cycles (%d bytes)\n", | |
209 | (cycles + 4) / 8, blen); | |
210 | ||
211 | return ret; | |
212 | } | |
213 | ||
d5dc3927 | 214 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
53f52d7a TC |
215 | static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 }; |
216 | ||
217 | #define XBUFSIZE 8 | |
218 | #define MAX_IVLEN 32 | |
219 | ||
220 | static int testmgr_alloc_buf(char *buf[XBUFSIZE]) | |
221 | { | |
222 | int i; | |
223 | ||
224 | for (i = 0; i < XBUFSIZE; i++) { | |
225 | buf[i] = (void *)__get_free_page(GFP_KERNEL); | |
226 | if (!buf[i]) | |
227 | goto err_free_buf; | |
228 | } | |
229 | ||
230 | return 0; | |
231 | ||
232 | err_free_buf: | |
233 | while (i-- > 0) | |
234 | free_page((unsigned long)buf[i]); | |
235 | ||
236 | return -ENOMEM; | |
237 | } | |
238 | ||
239 | static void testmgr_free_buf(char *buf[XBUFSIZE]) | |
240 | { | |
241 | int i; | |
242 | ||
243 | for (i = 0; i < XBUFSIZE; i++) | |
244 | free_page((unsigned long)buf[i]); | |
245 | } | |
246 | ||
247 | static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE], | |
248 | unsigned int buflen) | |
249 | { | |
250 | int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE; | |
251 | int k, rem; | |
252 | ||
53f52d7a TC |
253 | if (np > XBUFSIZE) { |
254 | rem = PAGE_SIZE; | |
255 | np = XBUFSIZE; | |
c4768993 CS |
256 | } else { |
257 | rem = buflen % PAGE_SIZE; | |
53f52d7a | 258 | } |
c4768993 | 259 | |
53f52d7a | 260 | sg_init_table(sg, np); |
c4768993 CS |
261 | np--; |
262 | for (k = 0; k < np; k++) | |
263 | sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE); | |
264 | ||
265 | sg_set_buf(&sg[k], xbuf[k], rem); | |
53f52d7a TC |
266 | } |
267 | ||
3e3dc25f | 268 | static void test_aead_speed(const char *algo, int enc, unsigned int secs, |
53f52d7a TC |
269 | struct aead_speed_template *template, |
270 | unsigned int tcount, u8 authsize, | |
271 | unsigned int aad_size, u8 *keysize) | |
272 | { | |
273 | unsigned int i, j; | |
274 | struct crypto_aead *tfm; | |
275 | int ret = -ENOMEM; | |
276 | const char *key; | |
277 | struct aead_request *req; | |
278 | struct scatterlist *sg; | |
279 | struct scatterlist *asg; | |
280 | struct scatterlist *sgout; | |
281 | const char *e; | |
282 | void *assoc; | |
96692a73 | 283 | char *iv; |
53f52d7a TC |
284 | char *xbuf[XBUFSIZE]; |
285 | char *xoutbuf[XBUFSIZE]; | |
286 | char *axbuf[XBUFSIZE]; | |
287 | unsigned int *b_size; | |
288 | unsigned int iv_len; | |
289 | ||
96692a73 CS |
290 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
291 | if (!iv) | |
292 | return; | |
293 | ||
ac5f863f CE |
294 | if (aad_size >= PAGE_SIZE) { |
295 | pr_err("associate data length (%u) too big\n", aad_size); | |
96692a73 | 296 | goto out_noxbuf; |
ac5f863f CE |
297 | } |
298 | ||
53f52d7a TC |
299 | if (enc == ENCRYPT) |
300 | e = "encryption"; | |
301 | else | |
302 | e = "decryption"; | |
303 | ||
304 | if (testmgr_alloc_buf(xbuf)) | |
305 | goto out_noxbuf; | |
306 | if (testmgr_alloc_buf(axbuf)) | |
307 | goto out_noaxbuf; | |
308 | if (testmgr_alloc_buf(xoutbuf)) | |
309 | goto out_nooutbuf; | |
310 | ||
311 | sg = kmalloc(sizeof(*sg) * 8 * 3, GFP_KERNEL); | |
312 | if (!sg) | |
313 | goto out_nosg; | |
314 | asg = &sg[8]; | |
315 | sgout = &asg[8]; | |
316 | ||
53f52d7a TC |
317 | tfm = crypto_alloc_aead(algo, 0, 0); |
318 | ||
319 | if (IS_ERR(tfm)) { | |
320 | pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo, | |
321 | PTR_ERR(tfm)); | |
a2ea6ed6 | 322 | goto out_notfm; |
53f52d7a TC |
323 | } |
324 | ||
263a8df0 LC |
325 | printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, |
326 | get_driver_name(crypto_aead, tfm), e); | |
327 | ||
53f52d7a TC |
328 | req = aead_request_alloc(tfm, GFP_KERNEL); |
329 | if (!req) { | |
330 | pr_err("alg: aead: Failed to allocate request for %s\n", | |
331 | algo); | |
6af1f93e | 332 | goto out_noreq; |
53f52d7a TC |
333 | } |
334 | ||
335 | i = 0; | |
336 | do { | |
337 | b_size = aead_sizes; | |
338 | do { | |
339 | assoc = axbuf[0]; | |
ac5f863f | 340 | memset(assoc, 0xff, aad_size); |
53f52d7a TC |
341 | sg_init_one(&asg[0], assoc, aad_size); |
342 | ||
343 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { | |
344 | pr_err("template (%u) too big for tvmem (%lu)\n", | |
345 | *keysize + *b_size, | |
346 | TVMEMSIZE * PAGE_SIZE); | |
347 | goto out; | |
348 | } | |
349 | ||
350 | key = tvmem[0]; | |
351 | for (j = 0; j < tcount; j++) { | |
352 | if (template[j].klen == *keysize) { | |
353 | key = template[j].key; | |
354 | break; | |
355 | } | |
356 | } | |
357 | ret = crypto_aead_setkey(tfm, key, *keysize); | |
358 | ret = crypto_aead_setauthsize(tfm, authsize); | |
359 | ||
360 | iv_len = crypto_aead_ivsize(tfm); | |
361 | if (iv_len) | |
96692a73 | 362 | memset(iv, 0xff, iv_len); |
53f52d7a TC |
363 | |
364 | crypto_aead_clear_flags(tfm, ~0); | |
365 | printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ", | |
366 | i, *keysize * 8, *b_size); | |
367 | ||
368 | ||
369 | memset(tvmem[0], 0xff, PAGE_SIZE); | |
370 | ||
371 | if (ret) { | |
372 | pr_err("setkey() failed flags=%x\n", | |
373 | crypto_aead_get_flags(tfm)); | |
374 | goto out; | |
375 | } | |
376 | ||
377 | sg_init_aead(&sg[0], xbuf, | |
378 | *b_size + (enc ? authsize : 0)); | |
379 | ||
380 | sg_init_aead(&sgout[0], xoutbuf, | |
381 | *b_size + (enc ? authsize : 0)); | |
382 | ||
383 | aead_request_set_crypt(req, sg, sgout, *b_size, iv); | |
384 | aead_request_set_assoc(req, asg, aad_size); | |
385 | ||
3e3dc25f MR |
386 | if (secs) |
387 | ret = test_aead_jiffies(req, enc, *b_size, | |
388 | secs); | |
53f52d7a TC |
389 | else |
390 | ret = test_aead_cycles(req, enc, *b_size); | |
391 | ||
392 | if (ret) { | |
393 | pr_err("%s() failed return code=%d\n", e, ret); | |
394 | break; | |
395 | } | |
396 | b_size++; | |
397 | i++; | |
398 | } while (*b_size); | |
399 | keysize++; | |
400 | } while (*keysize); | |
401 | ||
402 | out: | |
6af1f93e CE |
403 | aead_request_free(req); |
404 | out_noreq: | |
53f52d7a | 405 | crypto_free_aead(tfm); |
a2ea6ed6 | 406 | out_notfm: |
53f52d7a TC |
407 | kfree(sg); |
408 | out_nosg: | |
409 | testmgr_free_buf(xoutbuf); | |
410 | out_nooutbuf: | |
411 | testmgr_free_buf(axbuf); | |
412 | out_noaxbuf: | |
413 | testmgr_free_buf(xbuf); | |
414 | out_noxbuf: | |
96692a73 | 415 | kfree(iv); |
53f52d7a TC |
416 | return; |
417 | } | |
d5dc3927 | 418 | |
3e3dc25f | 419 | static void test_cipher_speed(const char *algo, int enc, unsigned int secs, |
da7f033d | 420 | struct cipher_speed_template *template, |
d5dc3927 | 421 | unsigned int tcount, u8 *keysize) |
ebfd9bcf | 422 | { |
dce907c0 | 423 | unsigned int ret, i, j, iv_len; |
f07ef1de DS |
424 | const char *key; |
425 | char iv[128]; | |
cba83564 HX |
426 | struct crypto_blkcipher *tfm; |
427 | struct blkcipher_desc desc; | |
428 | const char *e; | |
d5dc3927 | 429 | u32 *b_size; |
ebfd9bcf HW |
430 | |
431 | if (enc == ENCRYPT) | |
432 | e = "encryption"; | |
433 | else | |
434 | e = "decryption"; | |
ebfd9bcf | 435 | |
cba83564 | 436 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
ebfd9bcf | 437 | |
cba83564 HX |
438 | if (IS_ERR(tfm)) { |
439 | printk("failed to load transform for %s: %ld\n", algo, | |
440 | PTR_ERR(tfm)); | |
ebfd9bcf HW |
441 | return; |
442 | } | |
cba83564 HX |
443 | desc.tfm = tfm; |
444 | desc.flags = 0; | |
ebfd9bcf | 445 | |
263a8df0 LC |
446 | printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, |
447 | get_driver_name(crypto_blkcipher, tfm), e); | |
448 | ||
d5dc3927 SS |
449 | i = 0; |
450 | do { | |
ebfd9bcf | 451 | |
d5dc3927 SS |
452 | b_size = block_sizes; |
453 | do { | |
f139cfa7 | 454 | struct scatterlist sg[TVMEMSIZE]; |
ebfd9bcf | 455 | |
f139cfa7 HX |
456 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
457 | printk("template (%u) too big for " | |
458 | "tvmem (%lu)\n", *keysize + *b_size, | |
459 | TVMEMSIZE * PAGE_SIZE); | |
d5dc3927 SS |
460 | goto out; |
461 | } | |
ebfd9bcf | 462 | |
d5dc3927 SS |
463 | printk("test %u (%d bit key, %d byte blocks): ", i, |
464 | *keysize * 8, *b_size); | |
465 | ||
f139cfa7 | 466 | memset(tvmem[0], 0xff, PAGE_SIZE); |
d5dc3927 SS |
467 | |
468 | /* set key, plain text and IV */ | |
da7f033d | 469 | key = tvmem[0]; |
d5dc3927 SS |
470 | for (j = 0; j < tcount; j++) { |
471 | if (template[j].klen == *keysize) { | |
472 | key = template[j].key; | |
473 | break; | |
474 | } | |
dce907c0 | 475 | } |
ebfd9bcf | 476 | |
d5dc3927 SS |
477 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
478 | if (ret) { | |
479 | printk("setkey() failed flags=%x\n", | |
480 | crypto_blkcipher_get_flags(tfm)); | |
481 | goto out; | |
482 | } | |
ebfd9bcf | 483 | |
f139cfa7 HX |
484 | sg_init_table(sg, TVMEMSIZE); |
485 | sg_set_buf(sg, tvmem[0] + *keysize, | |
486 | PAGE_SIZE - *keysize); | |
487 | for (j = 1; j < TVMEMSIZE; j++) { | |
488 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); | |
489 | memset (tvmem[j], 0xff, PAGE_SIZE); | |
490 | } | |
491 | ||
d5dc3927 SS |
492 | iv_len = crypto_blkcipher_ivsize(tfm); |
493 | if (iv_len) { | |
494 | memset(&iv, 0xff, iv_len); | |
495 | crypto_blkcipher_set_iv(tfm, iv, iv_len); | |
496 | } | |
ebfd9bcf | 497 | |
3e3dc25f | 498 | if (secs) |
f139cfa7 | 499 | ret = test_cipher_jiffies(&desc, enc, sg, |
3e3dc25f | 500 | *b_size, secs); |
d5dc3927 | 501 | else |
f139cfa7 HX |
502 | ret = test_cipher_cycles(&desc, enc, sg, |
503 | *b_size); | |
ebfd9bcf | 504 | |
d5dc3927 SS |
505 | if (ret) { |
506 | printk("%s() failed flags=%x\n", e, desc.flags); | |
507 | break; | |
508 | } | |
509 | b_size++; | |
510 | i++; | |
511 | } while (*b_size); | |
512 | keysize++; | |
513 | } while (*keysize); | |
ebfd9bcf HW |
514 | |
515 | out: | |
cba83564 | 516 | crypto_free_blkcipher(tfm); |
ebfd9bcf HW |
517 | } |
518 | ||
f139cfa7 HX |
519 | static int test_hash_jiffies_digest(struct hash_desc *desc, |
520 | struct scatterlist *sg, int blen, | |
3e3dc25f | 521 | char *out, int secs) |
e9d41164 | 522 | { |
e9d41164 HX |
523 | unsigned long start, end; |
524 | int bcount; | |
525 | int ret; | |
526 | ||
3e3dc25f | 527 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
e9d41164 | 528 | time_before(jiffies, end); bcount++) { |
e9d41164 HX |
529 | ret = crypto_hash_digest(desc, sg, blen, out); |
530 | if (ret) | |
531 | return ret; | |
532 | } | |
533 | ||
534 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
3e3dc25f | 535 | bcount / secs, ((long)bcount * blen) / secs); |
e9d41164 HX |
536 | |
537 | return 0; | |
538 | } | |
539 | ||
f139cfa7 | 540 | static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg, |
3e3dc25f | 541 | int blen, int plen, char *out, int secs) |
e8057928 | 542 | { |
e8057928 ML |
543 | unsigned long start, end; |
544 | int bcount, pcount; | |
e9d41164 HX |
545 | int ret; |
546 | ||
547 | if (plen == blen) | |
3e3dc25f | 548 | return test_hash_jiffies_digest(desc, sg, blen, out, secs); |
a5a613a4 | 549 | |
3e3dc25f | 550 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
e8057928 | 551 | time_before(jiffies, end); bcount++) { |
e9d41164 HX |
552 | ret = crypto_hash_init(desc); |
553 | if (ret) | |
554 | return ret; | |
e8057928 | 555 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
556 | ret = crypto_hash_update(desc, sg, plen); |
557 | if (ret) | |
558 | return ret; | |
e8057928 ML |
559 | } |
560 | /* we assume there is enough space in 'out' for the result */ | |
e9d41164 HX |
561 | ret = crypto_hash_final(desc, out); |
562 | if (ret) | |
563 | return ret; | |
e8057928 ML |
564 | } |
565 | ||
566 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
3e3dc25f | 567 | bcount / secs, ((long)bcount * blen) / secs); |
e8057928 | 568 | |
e9d41164 HX |
569 | return 0; |
570 | } | |
571 | ||
f139cfa7 HX |
572 | static int test_hash_cycles_digest(struct hash_desc *desc, |
573 | struct scatterlist *sg, int blen, char *out) | |
e9d41164 | 574 | { |
e9d41164 HX |
575 | unsigned long cycles = 0; |
576 | int i; | |
577 | int ret; | |
578 | ||
e9d41164 HX |
579 | local_irq_disable(); |
580 | ||
581 | /* Warm-up run. */ | |
582 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
583 | ret = crypto_hash_digest(desc, sg, blen, out); |
584 | if (ret) | |
585 | goto out; | |
586 | } | |
587 | ||
588 | /* The real thing. */ | |
589 | for (i = 0; i < 8; i++) { | |
590 | cycles_t start, end; | |
591 | ||
592 | start = get_cycles(); | |
593 | ||
e9d41164 HX |
594 | ret = crypto_hash_digest(desc, sg, blen, out); |
595 | if (ret) | |
596 | goto out; | |
597 | ||
598 | end = get_cycles(); | |
599 | ||
600 | cycles += end - start; | |
601 | } | |
602 | ||
603 | out: | |
604 | local_irq_enable(); | |
e9d41164 HX |
605 | |
606 | if (ret) | |
607 | return ret; | |
608 | ||
609 | printk("%6lu cycles/operation, %4lu cycles/byte\n", | |
610 | cycles / 8, cycles / (8 * blen)); | |
611 | ||
612 | return 0; | |
e8057928 ML |
613 | } |
614 | ||
f139cfa7 HX |
615 | static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg, |
616 | int blen, int plen, char *out) | |
e8057928 | 617 | { |
e8057928 ML |
618 | unsigned long cycles = 0; |
619 | int i, pcount; | |
e9d41164 HX |
620 | int ret; |
621 | ||
622 | if (plen == blen) | |
f139cfa7 | 623 | return test_hash_cycles_digest(desc, sg, blen, out); |
a5a613a4 | 624 | |
e8057928 ML |
625 | local_irq_disable(); |
626 | ||
627 | /* Warm-up run. */ | |
628 | for (i = 0; i < 4; i++) { | |
e9d41164 HX |
629 | ret = crypto_hash_init(desc); |
630 | if (ret) | |
631 | goto out; | |
e8057928 | 632 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
633 | ret = crypto_hash_update(desc, sg, plen); |
634 | if (ret) | |
635 | goto out; | |
e8057928 | 636 | } |
29059d12 | 637 | ret = crypto_hash_final(desc, out); |
e9d41164 HX |
638 | if (ret) |
639 | goto out; | |
e8057928 ML |
640 | } |
641 | ||
642 | /* The real thing. */ | |
643 | for (i = 0; i < 8; i++) { | |
644 | cycles_t start, end; | |
645 | ||
e8057928 ML |
646 | start = get_cycles(); |
647 | ||
e9d41164 HX |
648 | ret = crypto_hash_init(desc); |
649 | if (ret) | |
650 | goto out; | |
e8057928 | 651 | for (pcount = 0; pcount < blen; pcount += plen) { |
e9d41164 HX |
652 | ret = crypto_hash_update(desc, sg, plen); |
653 | if (ret) | |
654 | goto out; | |
e8057928 | 655 | } |
e9d41164 HX |
656 | ret = crypto_hash_final(desc, out); |
657 | if (ret) | |
658 | goto out; | |
e8057928 ML |
659 | |
660 | end = get_cycles(); | |
661 | ||
662 | cycles += end - start; | |
663 | } | |
664 | ||
e9d41164 | 665 | out: |
e8057928 | 666 | local_irq_enable(); |
e8057928 | 667 | |
e9d41164 HX |
668 | if (ret) |
669 | return ret; | |
670 | ||
e8057928 ML |
671 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
672 | cycles / 8, cycles / (8 * blen)); | |
673 | ||
e9d41164 | 674 | return 0; |
e8057928 ML |
675 | } |
676 | ||
beb63da7 DM |
677 | static void test_hash_sg_init(struct scatterlist *sg) |
678 | { | |
679 | int i; | |
680 | ||
681 | sg_init_table(sg, TVMEMSIZE); | |
682 | for (i = 0; i < TVMEMSIZE; i++) { | |
683 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); | |
684 | memset(tvmem[i], 0xff, PAGE_SIZE); | |
685 | } | |
686 | } | |
687 | ||
3e3dc25f | 688 | static void test_hash_speed(const char *algo, unsigned int secs, |
01b32324 | 689 | struct hash_speed *speed) |
e8057928 | 690 | { |
f139cfa7 | 691 | struct scatterlist sg[TVMEMSIZE]; |
e9d41164 HX |
692 | struct crypto_hash *tfm; |
693 | struct hash_desc desc; | |
376bacb0 | 694 | static char output[1024]; |
e8057928 | 695 | int i; |
e9d41164 | 696 | int ret; |
e8057928 | 697 | |
e9d41164 | 698 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
e8057928 | 699 | |
e9d41164 | 700 | if (IS_ERR(tfm)) { |
376bacb0 | 701 | printk(KERN_ERR "failed to load transform for %s: %ld\n", algo, |
e9d41164 | 702 | PTR_ERR(tfm)); |
e8057928 ML |
703 | return; |
704 | } | |
705 | ||
263a8df0 LC |
706 | printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo, |
707 | get_driver_name(crypto_hash, tfm)); | |
708 | ||
e9d41164 HX |
709 | desc.tfm = tfm; |
710 | desc.flags = 0; | |
711 | ||
712 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { | |
376bacb0 | 713 | printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n", |
e9d41164 | 714 | crypto_hash_digestsize(tfm), sizeof(output)); |
e8057928 ML |
715 | goto out; |
716 | } | |
717 | ||
beb63da7 | 718 | test_hash_sg_init(sg); |
e8057928 | 719 | for (i = 0; speed[i].blen != 0; i++) { |
f139cfa7 | 720 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
376bacb0 FS |
721 | printk(KERN_ERR |
722 | "template (%u) too big for tvmem (%lu)\n", | |
f139cfa7 | 723 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
e8057928 ML |
724 | goto out; |
725 | } | |
726 | ||
18bcc919 HY |
727 | if (speed[i].klen) |
728 | crypto_hash_setkey(tfm, tvmem[0], speed[i].klen); | |
729 | ||
376bacb0 FS |
730 | printk(KERN_INFO "test%3u " |
731 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", | |
e8057928 ML |
732 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
733 | ||
3e3dc25f | 734 | if (secs) |
f139cfa7 | 735 | ret = test_hash_jiffies(&desc, sg, speed[i].blen, |
3e3dc25f | 736 | speed[i].plen, output, secs); |
e8057928 | 737 | else |
f139cfa7 | 738 | ret = test_hash_cycles(&desc, sg, speed[i].blen, |
e9d41164 HX |
739 | speed[i].plen, output); |
740 | ||
741 | if (ret) { | |
376bacb0 | 742 | printk(KERN_ERR "hashing failed ret=%d\n", ret); |
e9d41164 HX |
743 | break; |
744 | } | |
e8057928 ML |
745 | } |
746 | ||
747 | out: | |
e9d41164 | 748 | crypto_free_hash(tfm); |
e8057928 ML |
749 | } |
750 | ||
beb63da7 DM |
751 | struct tcrypt_result { |
752 | struct completion completion; | |
753 | int err; | |
754 | }; | |
755 | ||
756 | static void tcrypt_complete(struct crypto_async_request *req, int err) | |
757 | { | |
758 | struct tcrypt_result *res = req->data; | |
759 | ||
760 | if (err == -EINPROGRESS) | |
761 | return; | |
762 | ||
763 | res->err = err; | |
764 | complete(&res->completion); | |
765 | } | |
766 | ||
767 | static inline int do_one_ahash_op(struct ahash_request *req, int ret) | |
768 | { | |
769 | if (ret == -EINPROGRESS || ret == -EBUSY) { | |
770 | struct tcrypt_result *tr = req->base.data; | |
771 | ||
8a45ac12 | 772 | wait_for_completion(&tr->completion); |
16735d02 | 773 | reinit_completion(&tr->completion); |
8a45ac12 | 774 | ret = tr->err; |
beb63da7 DM |
775 | } |
776 | return ret; | |
777 | } | |
778 | ||
779 | static int test_ahash_jiffies_digest(struct ahash_request *req, int blen, | |
3e3dc25f | 780 | char *out, int secs) |
beb63da7 DM |
781 | { |
782 | unsigned long start, end; | |
783 | int bcount; | |
784 | int ret; | |
785 | ||
3e3dc25f | 786 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
beb63da7 DM |
787 | time_before(jiffies, end); bcount++) { |
788 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
789 | if (ret) | |
790 | return ret; | |
791 | } | |
792 | ||
793 | printk("%6u opers/sec, %9lu bytes/sec\n", | |
3e3dc25f | 794 | bcount / secs, ((long)bcount * blen) / secs); |
beb63da7 DM |
795 | |
796 | return 0; | |
797 | } | |
798 | ||
799 | static int test_ahash_jiffies(struct ahash_request *req, int blen, | |
3e3dc25f | 800 | int plen, char *out, int secs) |
beb63da7 DM |
801 | { |
802 | unsigned long start, end; | |
803 | int bcount, pcount; | |
804 | int ret; | |
805 | ||
806 | if (plen == blen) | |
3e3dc25f | 807 | return test_ahash_jiffies_digest(req, blen, out, secs); |
beb63da7 | 808 | |
3e3dc25f | 809 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
beb63da7 | 810 | time_before(jiffies, end); bcount++) { |
43a9607d | 811 | ret = do_one_ahash_op(req, crypto_ahash_init(req)); |
beb63da7 DM |
812 | if (ret) |
813 | return ret; | |
814 | for (pcount = 0; pcount < blen; pcount += plen) { | |
815 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
816 | if (ret) | |
817 | return ret; | |
818 | } | |
819 | /* we assume there is enough space in 'out' for the result */ | |
820 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
821 | if (ret) | |
822 | return ret; | |
823 | } | |
824 | ||
825 | pr_cont("%6u opers/sec, %9lu bytes/sec\n", | |
3e3dc25f | 826 | bcount / secs, ((long)bcount * blen) / secs); |
beb63da7 DM |
827 | |
828 | return 0; | |
829 | } | |
830 | ||
831 | static int test_ahash_cycles_digest(struct ahash_request *req, int blen, | |
832 | char *out) | |
833 | { | |
834 | unsigned long cycles = 0; | |
835 | int ret, i; | |
836 | ||
837 | /* Warm-up run. */ | |
838 | for (i = 0; i < 4; i++) { | |
839 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
840 | if (ret) | |
841 | goto out; | |
842 | } | |
843 | ||
844 | /* The real thing. */ | |
845 | for (i = 0; i < 8; i++) { | |
846 | cycles_t start, end; | |
847 | ||
848 | start = get_cycles(); | |
849 | ||
850 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); | |
851 | if (ret) | |
852 | goto out; | |
853 | ||
854 | end = get_cycles(); | |
855 | ||
856 | cycles += end - start; | |
857 | } | |
858 | ||
859 | out: | |
860 | if (ret) | |
861 | return ret; | |
862 | ||
863 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", | |
864 | cycles / 8, cycles / (8 * blen)); | |
865 | ||
866 | return 0; | |
867 | } | |
868 | ||
869 | static int test_ahash_cycles(struct ahash_request *req, int blen, | |
870 | int plen, char *out) | |
871 | { | |
872 | unsigned long cycles = 0; | |
873 | int i, pcount, ret; | |
874 | ||
875 | if (plen == blen) | |
876 | return test_ahash_cycles_digest(req, blen, out); | |
877 | ||
878 | /* Warm-up run. */ | |
879 | for (i = 0; i < 4; i++) { | |
43a9607d | 880 | ret = do_one_ahash_op(req, crypto_ahash_init(req)); |
beb63da7 DM |
881 | if (ret) |
882 | goto out; | |
883 | for (pcount = 0; pcount < blen; pcount += plen) { | |
884 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
885 | if (ret) | |
886 | goto out; | |
887 | } | |
888 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
889 | if (ret) | |
890 | goto out; | |
891 | } | |
892 | ||
893 | /* The real thing. */ | |
894 | for (i = 0; i < 8; i++) { | |
895 | cycles_t start, end; | |
896 | ||
897 | start = get_cycles(); | |
898 | ||
43a9607d | 899 | ret = do_one_ahash_op(req, crypto_ahash_init(req)); |
beb63da7 DM |
900 | if (ret) |
901 | goto out; | |
902 | for (pcount = 0; pcount < blen; pcount += plen) { | |
903 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); | |
904 | if (ret) | |
905 | goto out; | |
906 | } | |
907 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); | |
908 | if (ret) | |
909 | goto out; | |
910 | ||
911 | end = get_cycles(); | |
912 | ||
913 | cycles += end - start; | |
914 | } | |
915 | ||
916 | out: | |
917 | if (ret) | |
918 | return ret; | |
919 | ||
920 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", | |
921 | cycles / 8, cycles / (8 * blen)); | |
922 | ||
923 | return 0; | |
924 | } | |
925 | ||
3e3dc25f | 926 | static void test_ahash_speed(const char *algo, unsigned int secs, |
beb63da7 DM |
927 | struct hash_speed *speed) |
928 | { | |
929 | struct scatterlist sg[TVMEMSIZE]; | |
930 | struct tcrypt_result tresult; | |
931 | struct ahash_request *req; | |
932 | struct crypto_ahash *tfm; | |
933 | static char output[1024]; | |
934 | int i, ret; | |
935 | ||
beb63da7 DM |
936 | tfm = crypto_alloc_ahash(algo, 0, 0); |
937 | if (IS_ERR(tfm)) { | |
938 | pr_err("failed to load transform for %s: %ld\n", | |
939 | algo, PTR_ERR(tfm)); | |
940 | return; | |
941 | } | |
942 | ||
263a8df0 LC |
943 | printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo, |
944 | get_driver_name(crypto_ahash, tfm)); | |
945 | ||
beb63da7 DM |
946 | if (crypto_ahash_digestsize(tfm) > sizeof(output)) { |
947 | pr_err("digestsize(%u) > outputbuffer(%zu)\n", | |
948 | crypto_ahash_digestsize(tfm), sizeof(output)); | |
949 | goto out; | |
950 | } | |
951 | ||
952 | test_hash_sg_init(sg); | |
953 | req = ahash_request_alloc(tfm, GFP_KERNEL); | |
954 | if (!req) { | |
955 | pr_err("ahash request allocation failure\n"); | |
956 | goto out; | |
957 | } | |
958 | ||
959 | init_completion(&tresult.completion); | |
960 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
961 | tcrypt_complete, &tresult); | |
962 | ||
963 | for (i = 0; speed[i].blen != 0; i++) { | |
964 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { | |
965 | pr_err("template (%u) too big for tvmem (%lu)\n", | |
966 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); | |
967 | break; | |
968 | } | |
969 | ||
970 | pr_info("test%3u " | |
971 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", | |
972 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); | |
973 | ||
974 | ahash_request_set_crypt(req, sg, output, speed[i].plen); | |
975 | ||
3e3dc25f | 976 | if (secs) |
beb63da7 | 977 | ret = test_ahash_jiffies(req, speed[i].blen, |
3e3dc25f | 978 | speed[i].plen, output, secs); |
beb63da7 DM |
979 | else |
980 | ret = test_ahash_cycles(req, speed[i].blen, | |
981 | speed[i].plen, output); | |
982 | ||
983 | if (ret) { | |
984 | pr_err("hashing failed ret=%d\n", ret); | |
985 | break; | |
986 | } | |
987 | } | |
988 | ||
989 | ahash_request_free(req); | |
990 | ||
991 | out: | |
992 | crypto_free_ahash(tfm); | |
993 | } | |
994 | ||
3f3baf35 JK |
995 | static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret) |
996 | { | |
997 | if (ret == -EINPROGRESS || ret == -EBUSY) { | |
998 | struct tcrypt_result *tr = req->base.data; | |
999 | ||
8a45ac12 | 1000 | wait_for_completion(&tr->completion); |
16735d02 | 1001 | reinit_completion(&tr->completion); |
8a45ac12 | 1002 | ret = tr->err; |
3f3baf35 JK |
1003 | } |
1004 | ||
1005 | return ret; | |
1006 | } | |
1007 | ||
1008 | static int test_acipher_jiffies(struct ablkcipher_request *req, int enc, | |
3e3dc25f | 1009 | int blen, int secs) |
3f3baf35 JK |
1010 | { |
1011 | unsigned long start, end; | |
1012 | int bcount; | |
1013 | int ret; | |
1014 | ||
3e3dc25f | 1015 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
3f3baf35 JK |
1016 | time_before(jiffies, end); bcount++) { |
1017 | if (enc) | |
1018 | ret = do_one_acipher_op(req, | |
1019 | crypto_ablkcipher_encrypt(req)); | |
1020 | else | |
1021 | ret = do_one_acipher_op(req, | |
1022 | crypto_ablkcipher_decrypt(req)); | |
1023 | ||
1024 | if (ret) | |
1025 | return ret; | |
1026 | } | |
1027 | ||
1028 | pr_cont("%d operations in %d seconds (%ld bytes)\n", | |
3e3dc25f | 1029 | bcount, secs, (long)bcount * blen); |
3f3baf35 JK |
1030 | return 0; |
1031 | } | |
1032 | ||
1033 | static int test_acipher_cycles(struct ablkcipher_request *req, int enc, | |
1034 | int blen) | |
1035 | { | |
1036 | unsigned long cycles = 0; | |
1037 | int ret = 0; | |
1038 | int i; | |
1039 | ||
1040 | /* Warm-up run. */ | |
1041 | for (i = 0; i < 4; i++) { | |
1042 | if (enc) | |
1043 | ret = do_one_acipher_op(req, | |
1044 | crypto_ablkcipher_encrypt(req)); | |
1045 | else | |
1046 | ret = do_one_acipher_op(req, | |
1047 | crypto_ablkcipher_decrypt(req)); | |
1048 | ||
1049 | if (ret) | |
1050 | goto out; | |
1051 | } | |
1052 | ||
1053 | /* The real thing. */ | |
1054 | for (i = 0; i < 8; i++) { | |
1055 | cycles_t start, end; | |
1056 | ||
1057 | start = get_cycles(); | |
1058 | if (enc) | |
1059 | ret = do_one_acipher_op(req, | |
1060 | crypto_ablkcipher_encrypt(req)); | |
1061 | else | |
1062 | ret = do_one_acipher_op(req, | |
1063 | crypto_ablkcipher_decrypt(req)); | |
1064 | end = get_cycles(); | |
1065 | ||
1066 | if (ret) | |
1067 | goto out; | |
1068 | ||
1069 | cycles += end - start; | |
1070 | } | |
1071 | ||
1072 | out: | |
1073 | if (ret == 0) | |
1074 | pr_cont("1 operation in %lu cycles (%d bytes)\n", | |
1075 | (cycles + 4) / 8, blen); | |
1076 | ||
1077 | return ret; | |
1078 | } | |
1079 | ||
3e3dc25f | 1080 | static void test_acipher_speed(const char *algo, int enc, unsigned int secs, |
3f3baf35 JK |
1081 | struct cipher_speed_template *template, |
1082 | unsigned int tcount, u8 *keysize) | |
1083 | { | |
de197533 | 1084 | unsigned int ret, i, j, k, iv_len; |
3f3baf35 JK |
1085 | struct tcrypt_result tresult; |
1086 | const char *key; | |
1087 | char iv[128]; | |
1088 | struct ablkcipher_request *req; | |
1089 | struct crypto_ablkcipher *tfm; | |
1090 | const char *e; | |
1091 | u32 *b_size; | |
1092 | ||
1093 | if (enc == ENCRYPT) | |
1094 | e = "encryption"; | |
1095 | else | |
1096 | e = "decryption"; | |
1097 | ||
3f3baf35 JK |
1098 | init_completion(&tresult.completion); |
1099 | ||
1100 | tfm = crypto_alloc_ablkcipher(algo, 0, 0); | |
1101 | ||
1102 | if (IS_ERR(tfm)) { | |
1103 | pr_err("failed to load transform for %s: %ld\n", algo, | |
1104 | PTR_ERR(tfm)); | |
1105 | return; | |
1106 | } | |
1107 | ||
263a8df0 LC |
1108 | pr_info("\ntesting speed of async %s (%s) %s\n", algo, |
1109 | get_driver_name(crypto_ablkcipher, tfm), e); | |
1110 | ||
3f3baf35 JK |
1111 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); |
1112 | if (!req) { | |
1113 | pr_err("tcrypt: skcipher: Failed to allocate request for %s\n", | |
1114 | algo); | |
1115 | goto out; | |
1116 | } | |
1117 | ||
1118 | ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, | |
1119 | tcrypt_complete, &tresult); | |
1120 | ||
1121 | i = 0; | |
1122 | do { | |
1123 | b_size = block_sizes; | |
1124 | ||
1125 | do { | |
1126 | struct scatterlist sg[TVMEMSIZE]; | |
1127 | ||
1128 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { | |
1129 | pr_err("template (%u) too big for " | |
1130 | "tvmem (%lu)\n", *keysize + *b_size, | |
1131 | TVMEMSIZE * PAGE_SIZE); | |
1132 | goto out_free_req; | |
1133 | } | |
1134 | ||
1135 | pr_info("test %u (%d bit key, %d byte blocks): ", i, | |
1136 | *keysize * 8, *b_size); | |
1137 | ||
1138 | memset(tvmem[0], 0xff, PAGE_SIZE); | |
1139 | ||
1140 | /* set key, plain text and IV */ | |
1141 | key = tvmem[0]; | |
1142 | for (j = 0; j < tcount; j++) { | |
1143 | if (template[j].klen == *keysize) { | |
1144 | key = template[j].key; | |
1145 | break; | |
1146 | } | |
1147 | } | |
1148 | ||
1149 | crypto_ablkcipher_clear_flags(tfm, ~0); | |
1150 | ||
1151 | ret = crypto_ablkcipher_setkey(tfm, key, *keysize); | |
1152 | if (ret) { | |
1153 | pr_err("setkey() failed flags=%x\n", | |
1154 | crypto_ablkcipher_get_flags(tfm)); | |
1155 | goto out_free_req; | |
1156 | } | |
1157 | ||
de197533 | 1158 | k = *keysize + *b_size; |
007ee8de HG |
1159 | sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE)); |
1160 | ||
de197533 NR |
1161 | if (k > PAGE_SIZE) { |
1162 | sg_set_buf(sg, tvmem[0] + *keysize, | |
3f3baf35 | 1163 | PAGE_SIZE - *keysize); |
de197533 NR |
1164 | k -= PAGE_SIZE; |
1165 | j = 1; | |
1166 | while (k > PAGE_SIZE) { | |
1167 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); | |
1168 | memset(tvmem[j], 0xff, PAGE_SIZE); | |
1169 | j++; | |
1170 | k -= PAGE_SIZE; | |
1171 | } | |
1172 | sg_set_buf(sg + j, tvmem[j], k); | |
1173 | memset(tvmem[j], 0xff, k); | |
1174 | } else { | |
1175 | sg_set_buf(sg, tvmem[0] + *keysize, *b_size); | |
3f3baf35 JK |
1176 | } |
1177 | ||
1178 | iv_len = crypto_ablkcipher_ivsize(tfm); | |
1179 | if (iv_len) | |
1180 | memset(&iv, 0xff, iv_len); | |
1181 | ||
1182 | ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv); | |
1183 | ||
3e3dc25f | 1184 | if (secs) |
3f3baf35 | 1185 | ret = test_acipher_jiffies(req, enc, |
3e3dc25f | 1186 | *b_size, secs); |
3f3baf35 JK |
1187 | else |
1188 | ret = test_acipher_cycles(req, enc, | |
1189 | *b_size); | |
1190 | ||
1191 | if (ret) { | |
1192 | pr_err("%s() failed flags=%x\n", e, | |
1193 | crypto_ablkcipher_get_flags(tfm)); | |
1194 | break; | |
1195 | } | |
1196 | b_size++; | |
1197 | i++; | |
1198 | } while (*b_size); | |
1199 | keysize++; | |
1200 | } while (*keysize); | |
1201 | ||
1202 | out_free_req: | |
1203 | ablkcipher_request_free(req); | |
1204 | out: | |
1205 | crypto_free_ablkcipher(tfm); | |
1206 | } | |
1207 | ||
ef2736fc | 1208 | static void test_available(void) |
1da177e4 LT |
1209 | { |
1210 | char **name = check; | |
ef2736fc | 1211 | |
1da177e4 LT |
1212 | while (*name) { |
1213 | printk("alg %s ", *name); | |
6158efc0 | 1214 | printk(crypto_has_alg(*name, 0, 0) ? |
e4d5b79c | 1215 | "found\n" : "not found\n"); |
1da177e4 | 1216 | name++; |
ef2736fc | 1217 | } |
1da177e4 LT |
1218 | } |
1219 | ||
01b32324 HX |
1220 | static inline int tcrypt_test(const char *alg) |
1221 | { | |
4e033a6b JW |
1222 | int ret; |
1223 | ||
1224 | ret = alg_test(alg, alg, 0, 0); | |
1225 | /* non-fips algs return -EINVAL in fips mode */ | |
1226 | if (fips_enabled && ret == -EINVAL) | |
1227 | ret = 0; | |
1228 | return ret; | |
01b32324 HX |
1229 | } |
1230 | ||
8606813a | 1231 | static int do_test(const char *alg, u32 type, u32 mask, int m) |
01b32324 HX |
1232 | { |
1233 | int i; | |
4e033a6b | 1234 | int ret = 0; |
01b32324 HX |
1235 | |
1236 | switch (m) { | |
1da177e4 | 1237 | case 0: |
8606813a HX |
1238 | if (alg) { |
1239 | if (!crypto_has_alg(alg, type, | |
1240 | mask ?: CRYPTO_ALG_TYPE_MASK)) | |
1241 | ret = -ENOENT; | |
1242 | break; | |
1243 | } | |
1244 | ||
01b32324 | 1245 | for (i = 1; i < 200; i++) |
8606813a | 1246 | ret += do_test(NULL, 0, 0, i); |
1da177e4 LT |
1247 | break; |
1248 | ||
1249 | case 1: | |
4e033a6b | 1250 | ret += tcrypt_test("md5"); |
1da177e4 LT |
1251 | break; |
1252 | ||
1253 | case 2: | |
4e033a6b | 1254 | ret += tcrypt_test("sha1"); |
1da177e4 LT |
1255 | break; |
1256 | ||
1257 | case 3: | |
4e033a6b JW |
1258 | ret += tcrypt_test("ecb(des)"); |
1259 | ret += tcrypt_test("cbc(des)"); | |
8163fc30 | 1260 | ret += tcrypt_test("ctr(des)"); |
1da177e4 LT |
1261 | break; |
1262 | ||
1263 | case 4: | |
4e033a6b JW |
1264 | ret += tcrypt_test("ecb(des3_ede)"); |
1265 | ret += tcrypt_test("cbc(des3_ede)"); | |
e080b17a | 1266 | ret += tcrypt_test("ctr(des3_ede)"); |
1da177e4 LT |
1267 | break; |
1268 | ||
1269 | case 5: | |
4e033a6b | 1270 | ret += tcrypt_test("md4"); |
1da177e4 | 1271 | break; |
ef2736fc | 1272 | |
1da177e4 | 1273 | case 6: |
4e033a6b | 1274 | ret += tcrypt_test("sha256"); |
1da177e4 | 1275 | break; |
ef2736fc | 1276 | |
1da177e4 | 1277 | case 7: |
4e033a6b JW |
1278 | ret += tcrypt_test("ecb(blowfish)"); |
1279 | ret += tcrypt_test("cbc(blowfish)"); | |
85b63e34 | 1280 | ret += tcrypt_test("ctr(blowfish)"); |
1da177e4 LT |
1281 | break; |
1282 | ||
1283 | case 8: | |
4e033a6b JW |
1284 | ret += tcrypt_test("ecb(twofish)"); |
1285 | ret += tcrypt_test("cbc(twofish)"); | |
573da620 | 1286 | ret += tcrypt_test("ctr(twofish)"); |
bee3a90e | 1287 | ret += tcrypt_test("lrw(twofish)"); |
131f7541 | 1288 | ret += tcrypt_test("xts(twofish)"); |
1da177e4 | 1289 | break; |
ef2736fc | 1290 | |
1da177e4 | 1291 | case 9: |
4e033a6b | 1292 | ret += tcrypt_test("ecb(serpent)"); |
9d25917d JK |
1293 | ret += tcrypt_test("cbc(serpent)"); |
1294 | ret += tcrypt_test("ctr(serpent)"); | |
87aae4bf | 1295 | ret += tcrypt_test("lrw(serpent)"); |
5209c07a | 1296 | ret += tcrypt_test("xts(serpent)"); |
1da177e4 LT |
1297 | break; |
1298 | ||
1299 | case 10: | |
4e033a6b JW |
1300 | ret += tcrypt_test("ecb(aes)"); |
1301 | ret += tcrypt_test("cbc(aes)"); | |
1302 | ret += tcrypt_test("lrw(aes)"); | |
1303 | ret += tcrypt_test("xts(aes)"); | |
1304 | ret += tcrypt_test("ctr(aes)"); | |
1305 | ret += tcrypt_test("rfc3686(ctr(aes))"); | |
1da177e4 LT |
1306 | break; |
1307 | ||
1308 | case 11: | |
4e033a6b | 1309 | ret += tcrypt_test("sha384"); |
1da177e4 | 1310 | break; |
ef2736fc | 1311 | |
1da177e4 | 1312 | case 12: |
4e033a6b | 1313 | ret += tcrypt_test("sha512"); |
1da177e4 LT |
1314 | break; |
1315 | ||
1316 | case 13: | |
4e033a6b | 1317 | ret += tcrypt_test("deflate"); |
1da177e4 LT |
1318 | break; |
1319 | ||
1320 | case 14: | |
4e033a6b | 1321 | ret += tcrypt_test("ecb(cast5)"); |
a2c58260 JG |
1322 | ret += tcrypt_test("cbc(cast5)"); |
1323 | ret += tcrypt_test("ctr(cast5)"); | |
1da177e4 LT |
1324 | break; |
1325 | ||
1326 | case 15: | |
4e033a6b | 1327 | ret += tcrypt_test("ecb(cast6)"); |
9b8b0405 JG |
1328 | ret += tcrypt_test("cbc(cast6)"); |
1329 | ret += tcrypt_test("ctr(cast6)"); | |
1330 | ret += tcrypt_test("lrw(cast6)"); | |
1331 | ret += tcrypt_test("xts(cast6)"); | |
1da177e4 LT |
1332 | break; |
1333 | ||
1334 | case 16: | |
4e033a6b | 1335 | ret += tcrypt_test("ecb(arc4)"); |
1da177e4 LT |
1336 | break; |
1337 | ||
1338 | case 17: | |
4e033a6b | 1339 | ret += tcrypt_test("michael_mic"); |
1da177e4 LT |
1340 | break; |
1341 | ||
1342 | case 18: | |
4e033a6b | 1343 | ret += tcrypt_test("crc32c"); |
1da177e4 LT |
1344 | break; |
1345 | ||
1346 | case 19: | |
4e033a6b | 1347 | ret += tcrypt_test("ecb(tea)"); |
1da177e4 LT |
1348 | break; |
1349 | ||
1350 | case 20: | |
4e033a6b | 1351 | ret += tcrypt_test("ecb(xtea)"); |
1da177e4 LT |
1352 | break; |
1353 | ||
1354 | case 21: | |
4e033a6b | 1355 | ret += tcrypt_test("ecb(khazad)"); |
1da177e4 LT |
1356 | break; |
1357 | ||
1358 | case 22: | |
4e033a6b | 1359 | ret += tcrypt_test("wp512"); |
1da177e4 LT |
1360 | break; |
1361 | ||
1362 | case 23: | |
4e033a6b | 1363 | ret += tcrypt_test("wp384"); |
1da177e4 LT |
1364 | break; |
1365 | ||
1366 | case 24: | |
4e033a6b | 1367 | ret += tcrypt_test("wp256"); |
1da177e4 LT |
1368 | break; |
1369 | ||
1370 | case 25: | |
4e033a6b | 1371 | ret += tcrypt_test("ecb(tnepres)"); |
1da177e4 LT |
1372 | break; |
1373 | ||
1374 | case 26: | |
4e033a6b JW |
1375 | ret += tcrypt_test("ecb(anubis)"); |
1376 | ret += tcrypt_test("cbc(anubis)"); | |
1da177e4 LT |
1377 | break; |
1378 | ||
1379 | case 27: | |
4e033a6b | 1380 | ret += tcrypt_test("tgr192"); |
1da177e4 LT |
1381 | break; |
1382 | ||
1383 | case 28: | |
4e033a6b | 1384 | ret += tcrypt_test("tgr160"); |
1da177e4 LT |
1385 | break; |
1386 | ||
1387 | case 29: | |
4e033a6b | 1388 | ret += tcrypt_test("tgr128"); |
1da177e4 | 1389 | break; |
2998db37 | 1390 | |
fb4f10ed | 1391 | case 30: |
4e033a6b | 1392 | ret += tcrypt_test("ecb(xeta)"); |
fb4f10ed | 1393 | break; |
1da177e4 | 1394 | |
90831639 | 1395 | case 31: |
4e033a6b | 1396 | ret += tcrypt_test("pcbc(fcrypt)"); |
90831639 DH |
1397 | break; |
1398 | ||
02ab5a70 | 1399 | case 32: |
4e033a6b JW |
1400 | ret += tcrypt_test("ecb(camellia)"); |
1401 | ret += tcrypt_test("cbc(camellia)"); | |
54216bbd JK |
1402 | ret += tcrypt_test("ctr(camellia)"); |
1403 | ret += tcrypt_test("lrw(camellia)"); | |
1404 | ret += tcrypt_test("xts(camellia)"); | |
02ab5a70 | 1405 | break; |
93b5e86a | 1406 | |
cd12fb90 | 1407 | case 33: |
4e033a6b | 1408 | ret += tcrypt_test("sha224"); |
cd12fb90 | 1409 | break; |
02ab5a70 | 1410 | |
2407d608 | 1411 | case 34: |
4e033a6b | 1412 | ret += tcrypt_test("salsa20"); |
2407d608 TSH |
1413 | break; |
1414 | ||
8df213d9 | 1415 | case 35: |
4e033a6b | 1416 | ret += tcrypt_test("gcm(aes)"); |
8df213d9 HX |
1417 | break; |
1418 | ||
0b77abb3 | 1419 | case 36: |
4e033a6b | 1420 | ret += tcrypt_test("lzo"); |
0b77abb3 ZS |
1421 | break; |
1422 | ||
93cc74e0 | 1423 | case 37: |
4e033a6b | 1424 | ret += tcrypt_test("ccm(aes)"); |
93cc74e0 JL |
1425 | break; |
1426 | ||
76cb9521 | 1427 | case 38: |
4e033a6b | 1428 | ret += tcrypt_test("cts(cbc(aes))"); |
76cb9521 KC |
1429 | break; |
1430 | ||
fd4adf1a | 1431 | case 39: |
4e033a6b | 1432 | ret += tcrypt_test("rmd128"); |
fd4adf1a AKR |
1433 | break; |
1434 | ||
1435 | case 40: | |
4e033a6b | 1436 | ret += tcrypt_test("rmd160"); |
fd4adf1a AKR |
1437 | break; |
1438 | ||
2998db37 | 1439 | case 41: |
4e033a6b | 1440 | ret += tcrypt_test("rmd256"); |
2998db37 AKR |
1441 | break; |
1442 | ||
1443 | case 42: | |
4e033a6b | 1444 | ret += tcrypt_test("rmd320"); |
01b32324 HX |
1445 | break; |
1446 | ||
1447 | case 43: | |
4e033a6b | 1448 | ret += tcrypt_test("ecb(seed)"); |
2998db37 AKR |
1449 | break; |
1450 | ||
0c01aed5 | 1451 | case 44: |
4e033a6b | 1452 | ret += tcrypt_test("zlib"); |
0c01aed5 GU |
1453 | break; |
1454 | ||
5d667322 | 1455 | case 45: |
4e033a6b | 1456 | ret += tcrypt_test("rfc4309(ccm(aes))"); |
5d667322 JW |
1457 | break; |
1458 | ||
54216bbd JK |
1459 | case 46: |
1460 | ret += tcrypt_test("ghash"); | |
1461 | break; | |
1462 | ||
68411521 HX |
1463 | case 47: |
1464 | ret += tcrypt_test("crct10dif"); | |
1465 | break; | |
1466 | ||
1da177e4 | 1467 | case 100: |
4e033a6b | 1468 | ret += tcrypt_test("hmac(md5)"); |
1da177e4 | 1469 | break; |
ef2736fc | 1470 | |
1da177e4 | 1471 | case 101: |
4e033a6b | 1472 | ret += tcrypt_test("hmac(sha1)"); |
1da177e4 | 1473 | break; |
ef2736fc | 1474 | |
1da177e4 | 1475 | case 102: |
4e033a6b | 1476 | ret += tcrypt_test("hmac(sha256)"); |
1da177e4 LT |
1477 | break; |
1478 | ||
a28091ae | 1479 | case 103: |
4e033a6b | 1480 | ret += tcrypt_test("hmac(sha384)"); |
a28091ae AD |
1481 | break; |
1482 | ||
1483 | case 104: | |
4e033a6b | 1484 | ret += tcrypt_test("hmac(sha512)"); |
a28091ae | 1485 | break; |
38ed9ab2 | 1486 | |
cd12fb90 | 1487 | case 105: |
4e033a6b | 1488 | ret += tcrypt_test("hmac(sha224)"); |
cd12fb90 | 1489 | break; |
1da177e4 | 1490 | |
38ed9ab2 | 1491 | case 106: |
4e033a6b | 1492 | ret += tcrypt_test("xcbc(aes)"); |
38ed9ab2 HX |
1493 | break; |
1494 | ||
fd4adf1a | 1495 | case 107: |
4e033a6b | 1496 | ret += tcrypt_test("hmac(rmd128)"); |
fd4adf1a AKR |
1497 | break; |
1498 | ||
1499 | case 108: | |
4e033a6b | 1500 | ret += tcrypt_test("hmac(rmd160)"); |
fd4adf1a AKR |
1501 | break; |
1502 | ||
f1939f7c SW |
1503 | case 109: |
1504 | ret += tcrypt_test("vmac(aes)"); | |
1505 | break; | |
93b5e86a | 1506 | |
a482b081 SZ |
1507 | case 110: |
1508 | ret += tcrypt_test("hmac(crc32)"); | |
1509 | break; | |
f1939f7c | 1510 | |
e08ca2da | 1511 | case 150: |
4e033a6b | 1512 | ret += tcrypt_test("ansi_cprng"); |
e08ca2da JW |
1513 | break; |
1514 | ||
69435b94 AH |
1515 | case 151: |
1516 | ret += tcrypt_test("rfc4106(gcm(aes))"); | |
1517 | break; | |
1518 | ||
e9b7441a JK |
1519 | case 152: |
1520 | ret += tcrypt_test("rfc4543(gcm(aes))"); | |
1521 | break; | |
1522 | ||
93b5e86a JK |
1523 | case 153: |
1524 | ret += tcrypt_test("cmac(aes)"); | |
1525 | break; | |
1526 | ||
1527 | case 154: | |
1528 | ret += tcrypt_test("cmac(des3_ede)"); | |
1529 | break; | |
1530 | ||
bbf9c893 HG |
1531 | case 155: |
1532 | ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))"); | |
1533 | break; | |
1534 | ||
bca4feb0 HG |
1535 | case 156: |
1536 | ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"); | |
1537 | break; | |
1538 | ||
1539 | case 157: | |
1540 | ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"); | |
1541 | break; | |
5208ed2c NL |
1542 | case 181: |
1543 | ret += tcrypt_test("authenc(hmac(sha1),cbc(des))"); | |
1544 | break; | |
1545 | case 182: | |
1546 | ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"); | |
1547 | break; | |
1548 | case 183: | |
1549 | ret += tcrypt_test("authenc(hmac(sha224),cbc(des))"); | |
1550 | break; | |
1551 | case 184: | |
1552 | ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"); | |
1553 | break; | |
1554 | case 185: | |
1555 | ret += tcrypt_test("authenc(hmac(sha256),cbc(des))"); | |
1556 | break; | |
1557 | case 186: | |
1558 | ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"); | |
1559 | break; | |
1560 | case 187: | |
1561 | ret += tcrypt_test("authenc(hmac(sha384),cbc(des))"); | |
1562 | break; | |
1563 | case 188: | |
1564 | ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"); | |
1565 | break; | |
1566 | case 189: | |
1567 | ret += tcrypt_test("authenc(hmac(sha512),cbc(des))"); | |
1568 | break; | |
1569 | case 190: | |
1570 | ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"); | |
1571 | break; | |
ebfd9bcf | 1572 | case 200: |
cba83564 | 1573 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1574 | speed_template_16_24_32); |
cba83564 | 1575 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1576 | speed_template_16_24_32); |
cba83564 | 1577 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1578 | speed_template_16_24_32); |
cba83564 | 1579 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1580 | speed_template_16_24_32); |
f3d1044c | 1581 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1582 | speed_template_32_40_48); |
f3d1044c | 1583 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1584 | speed_template_32_40_48); |
f19f5111 | 1585 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1586 | speed_template_32_48_64); |
f19f5111 | 1587 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
477035c2 | 1588 | speed_template_32_48_64); |
9996e342 JG |
1589 | test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
1590 | speed_template_16_24_32); | |
1591 | test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, | |
1592 | speed_template_16_24_32); | |
ebfd9bcf HW |
1593 | break; |
1594 | ||
1595 | case 201: | |
cba83564 | 1596 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
da7f033d | 1597 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1598 | speed_template_24); |
cba83564 | 1599 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
da7f033d | 1600 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1601 | speed_template_24); |
cba83564 | 1602 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
da7f033d | 1603 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1604 | speed_template_24); |
cba83564 | 1605 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
da7f033d | 1606 | des3_speed_template, DES3_SPEED_VECTORS, |
477035c2 | 1607 | speed_template_24); |
87131507 JK |
1608 | test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec, |
1609 | des3_speed_template, DES3_SPEED_VECTORS, | |
1610 | speed_template_24); | |
1611 | test_cipher_speed("ctr(des3_ede)", DECRYPT, sec, | |
1612 | des3_speed_template, DES3_SPEED_VECTORS, | |
1613 | speed_template_24); | |
ebfd9bcf HW |
1614 | break; |
1615 | ||
1616 | case 202: | |
cba83564 | 1617 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1618 | speed_template_16_24_32); |
cba83564 | 1619 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1620 | speed_template_16_24_32); |
cba83564 | 1621 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1622 | speed_template_16_24_32); |
cba83564 | 1623 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1624 | speed_template_16_24_32); |
ee5002a5 JK |
1625 | test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
1626 | speed_template_16_24_32); | |
1627 | test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, | |
1628 | speed_template_16_24_32); | |
bee3a90e JK |
1629 | test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
1630 | speed_template_32_40_48); | |
1631 | test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, | |
1632 | speed_template_32_40_48); | |
131f7541 JK |
1633 | test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
1634 | speed_template_32_48_64); | |
1635 | test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, | |
1636 | speed_template_32_48_64); | |
ebfd9bcf HW |
1637 | break; |
1638 | ||
1639 | case 203: | |
cba83564 | 1640 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1641 | speed_template_8_32); |
cba83564 | 1642 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1643 | speed_template_8_32); |
cba83564 | 1644 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1645 | speed_template_8_32); |
cba83564 | 1646 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
477035c2 | 1647 | speed_template_8_32); |
7d47b86c JK |
1648 | test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
1649 | speed_template_8_32); | |
1650 | test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, | |
1651 | speed_template_8_32); | |
ebfd9bcf HW |
1652 | break; |
1653 | ||
1654 | case 204: | |
cba83564 | 1655 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1656 | speed_template_8); |
cba83564 | 1657 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1658 | speed_template_8); |
cba83564 | 1659 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1660 | speed_template_8); |
cba83564 | 1661 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
477035c2 | 1662 | speed_template_8); |
ebfd9bcf HW |
1663 | break; |
1664 | ||
02ab5a70 NT |
1665 | case 205: |
1666 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1667 | speed_template_16_24_32); |
02ab5a70 | 1668 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1669 | speed_template_16_24_32); |
02ab5a70 | 1670 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
477035c2 | 1671 | speed_template_16_24_32); |
02ab5a70 | 1672 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
477035c2 | 1673 | speed_template_16_24_32); |
4de59337 JK |
1674 | test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
1675 | speed_template_16_24_32); | |
1676 | test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, | |
1677 | speed_template_16_24_32); | |
1678 | test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, | |
1679 | speed_template_32_40_48); | |
1680 | test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, | |
1681 | speed_template_32_40_48); | |
1682 | test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, | |
1683 | speed_template_32_48_64); | |
1684 | test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, | |
1685 | speed_template_32_48_64); | |
02ab5a70 NT |
1686 | break; |
1687 | ||
5de8f1b5 TSH |
1688 | case 206: |
1689 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, | |
477035c2 | 1690 | speed_template_16_32); |
5de8f1b5 TSH |
1691 | break; |
1692 | ||
7fb7fe44 JK |
1693 | case 207: |
1694 | test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, | |
1695 | speed_template_16_32); | |
1696 | test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, | |
1697 | speed_template_16_32); | |
1698 | test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, | |
1699 | speed_template_16_32); | |
1700 | test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, | |
1701 | speed_template_16_32); | |
1702 | test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, | |
1703 | speed_template_16_32); | |
1704 | test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, | |
1705 | speed_template_16_32); | |
87aae4bf JK |
1706 | test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
1707 | speed_template_32_48); | |
1708 | test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, | |
1709 | speed_template_32_48); | |
5209c07a JK |
1710 | test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
1711 | speed_template_32_64); | |
1712 | test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, | |
1713 | speed_template_32_64); | |
7fb7fe44 JK |
1714 | break; |
1715 | ||
31b4cd29 JK |
1716 | case 208: |
1717 | test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, | |
1718 | speed_template_8); | |
1719 | break; | |
1720 | ||
a2c58260 JG |
1721 | case 209: |
1722 | test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, | |
1723 | speed_template_8_16); | |
1724 | test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, | |
1725 | speed_template_8_16); | |
1726 | test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, | |
1727 | speed_template_8_16); | |
1728 | test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, | |
1729 | speed_template_8_16); | |
1730 | test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, | |
1731 | speed_template_8_16); | |
1732 | test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, | |
1733 | speed_template_8_16); | |
1734 | break; | |
1735 | ||
9b8b0405 JG |
1736 | case 210: |
1737 | test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, | |
1738 | speed_template_16_32); | |
1739 | test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, | |
1740 | speed_template_16_32); | |
1741 | test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, | |
1742 | speed_template_16_32); | |
1743 | test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, | |
1744 | speed_template_16_32); | |
1745 | test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, | |
1746 | speed_template_16_32); | |
1747 | test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, | |
1748 | speed_template_16_32); | |
1749 | test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, | |
1750 | speed_template_32_48); | |
1751 | test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, | |
1752 | speed_template_32_48); | |
1753 | test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, | |
1754 | speed_template_32_64); | |
1755 | test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, | |
1756 | speed_template_32_64); | |
1757 | break; | |
1758 | ||
53f52d7a TC |
1759 | case 211: |
1760 | test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, | |
1761 | NULL, 0, 16, 8, aead_speed_template_20); | |
1762 | break; | |
1763 | ||
e8057928 | 1764 | case 300: |
8606813a HX |
1765 | if (alg) { |
1766 | test_hash_speed(alg, sec, generic_hash_speed_template); | |
1767 | break; | |
1768 | } | |
1769 | ||
e8057928 ML |
1770 | /* fall through */ |
1771 | ||
1772 | case 301: | |
e9d41164 | 1773 | test_hash_speed("md4", sec, generic_hash_speed_template); |
e8057928 ML |
1774 | if (mode > 300 && mode < 400) break; |
1775 | ||
1776 | case 302: | |
e9d41164 | 1777 | test_hash_speed("md5", sec, generic_hash_speed_template); |
e8057928 ML |
1778 | if (mode > 300 && mode < 400) break; |
1779 | ||
1780 | case 303: | |
e9d41164 | 1781 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
e8057928 ML |
1782 | if (mode > 300 && mode < 400) break; |
1783 | ||
1784 | case 304: | |
e9d41164 | 1785 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
e8057928 ML |
1786 | if (mode > 300 && mode < 400) break; |
1787 | ||
1788 | case 305: | |
e9d41164 | 1789 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
e8057928 ML |
1790 | if (mode > 300 && mode < 400) break; |
1791 | ||
1792 | case 306: | |
e9d41164 | 1793 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
e8057928 ML |
1794 | if (mode > 300 && mode < 400) break; |
1795 | ||
1796 | case 307: | |
e9d41164 | 1797 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
e8057928 ML |
1798 | if (mode > 300 && mode < 400) break; |
1799 | ||
1800 | case 308: | |
e9d41164 | 1801 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
e8057928 ML |
1802 | if (mode > 300 && mode < 400) break; |
1803 | ||
1804 | case 309: | |
e9d41164 | 1805 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
e8057928 ML |
1806 | if (mode > 300 && mode < 400) break; |
1807 | ||
1808 | case 310: | |
e9d41164 | 1809 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
e8057928 ML |
1810 | if (mode > 300 && mode < 400) break; |
1811 | ||
1812 | case 311: | |
e9d41164 | 1813 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
e8057928 ML |
1814 | if (mode > 300 && mode < 400) break; |
1815 | ||
1816 | case 312: | |
e9d41164 | 1817 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
e8057928 ML |
1818 | if (mode > 300 && mode < 400) break; |
1819 | ||
cd12fb90 JL |
1820 | case 313: |
1821 | test_hash_speed("sha224", sec, generic_hash_speed_template); | |
1822 | if (mode > 300 && mode < 400) break; | |
1823 | ||
fd4adf1a AKR |
1824 | case 314: |
1825 | test_hash_speed("rmd128", sec, generic_hash_speed_template); | |
1826 | if (mode > 300 && mode < 400) break; | |
1827 | ||
1828 | case 315: | |
1829 | test_hash_speed("rmd160", sec, generic_hash_speed_template); | |
1830 | if (mode > 300 && mode < 400) break; | |
1831 | ||
2998db37 AKR |
1832 | case 316: |
1833 | test_hash_speed("rmd256", sec, generic_hash_speed_template); | |
1834 | if (mode > 300 && mode < 400) break; | |
1835 | ||
1836 | case 317: | |
1837 | test_hash_speed("rmd320", sec, generic_hash_speed_template); | |
1838 | if (mode > 300 && mode < 400) break; | |
1839 | ||
18bcc919 HY |
1840 | case 318: |
1841 | test_hash_speed("ghash-generic", sec, hash_speed_template_16); | |
1842 | if (mode > 300 && mode < 400) break; | |
1843 | ||
e3899e4d TC |
1844 | case 319: |
1845 | test_hash_speed("crc32c", sec, generic_hash_speed_template); | |
1846 | if (mode > 300 && mode < 400) break; | |
1847 | ||
68411521 HX |
1848 | case 320: |
1849 | test_hash_speed("crct10dif", sec, generic_hash_speed_template); | |
1850 | if (mode > 300 && mode < 400) break; | |
1851 | ||
e8057928 ML |
1852 | case 399: |
1853 | break; | |
1854 | ||
beb63da7 | 1855 | case 400: |
8606813a HX |
1856 | if (alg) { |
1857 | test_ahash_speed(alg, sec, generic_hash_speed_template); | |
1858 | break; | |
1859 | } | |
1860 | ||
beb63da7 DM |
1861 | /* fall through */ |
1862 | ||
1863 | case 401: | |
1864 | test_ahash_speed("md4", sec, generic_hash_speed_template); | |
1865 | if (mode > 400 && mode < 500) break; | |
1866 | ||
1867 | case 402: | |
1868 | test_ahash_speed("md5", sec, generic_hash_speed_template); | |
1869 | if (mode > 400 && mode < 500) break; | |
1870 | ||
1871 | case 403: | |
1872 | test_ahash_speed("sha1", sec, generic_hash_speed_template); | |
1873 | if (mode > 400 && mode < 500) break; | |
1874 | ||
1875 | case 404: | |
1876 | test_ahash_speed("sha256", sec, generic_hash_speed_template); | |
1877 | if (mode > 400 && mode < 500) break; | |
1878 | ||
1879 | case 405: | |
1880 | test_ahash_speed("sha384", sec, generic_hash_speed_template); | |
1881 | if (mode > 400 && mode < 500) break; | |
1882 | ||
1883 | case 406: | |
1884 | test_ahash_speed("sha512", sec, generic_hash_speed_template); | |
1885 | if (mode > 400 && mode < 500) break; | |
1886 | ||
1887 | case 407: | |
1888 | test_ahash_speed("wp256", sec, generic_hash_speed_template); | |
1889 | if (mode > 400 && mode < 500) break; | |
1890 | ||
1891 | case 408: | |
1892 | test_ahash_speed("wp384", sec, generic_hash_speed_template); | |
1893 | if (mode > 400 && mode < 500) break; | |
1894 | ||
1895 | case 409: | |
1896 | test_ahash_speed("wp512", sec, generic_hash_speed_template); | |
1897 | if (mode > 400 && mode < 500) break; | |
1898 | ||
1899 | case 410: | |
1900 | test_ahash_speed("tgr128", sec, generic_hash_speed_template); | |
1901 | if (mode > 400 && mode < 500) break; | |
1902 | ||
1903 | case 411: | |
1904 | test_ahash_speed("tgr160", sec, generic_hash_speed_template); | |
1905 | if (mode > 400 && mode < 500) break; | |
1906 | ||
1907 | case 412: | |
1908 | test_ahash_speed("tgr192", sec, generic_hash_speed_template); | |
1909 | if (mode > 400 && mode < 500) break; | |
1910 | ||
1911 | case 413: | |
1912 | test_ahash_speed("sha224", sec, generic_hash_speed_template); | |
1913 | if (mode > 400 && mode < 500) break; | |
1914 | ||
1915 | case 414: | |
1916 | test_ahash_speed("rmd128", sec, generic_hash_speed_template); | |
1917 | if (mode > 400 && mode < 500) break; | |
1918 | ||
1919 | case 415: | |
1920 | test_ahash_speed("rmd160", sec, generic_hash_speed_template); | |
1921 | if (mode > 400 && mode < 500) break; | |
1922 | ||
1923 | case 416: | |
1924 | test_ahash_speed("rmd256", sec, generic_hash_speed_template); | |
1925 | if (mode > 400 && mode < 500) break; | |
1926 | ||
1927 | case 417: | |
1928 | test_ahash_speed("rmd320", sec, generic_hash_speed_template); | |
1929 | if (mode > 400 && mode < 500) break; | |
1930 | ||
1931 | case 499: | |
1932 | break; | |
1933 | ||
3f3baf35 JK |
1934 | case 500: |
1935 | test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, | |
1936 | speed_template_16_24_32); | |
1937 | test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, | |
1938 | speed_template_16_24_32); | |
1939 | test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, | |
1940 | speed_template_16_24_32); | |
1941 | test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, | |
1942 | speed_template_16_24_32); | |
1943 | test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, | |
1944 | speed_template_32_40_48); | |
1945 | test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, | |
1946 | speed_template_32_40_48); | |
1947 | test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, | |
1948 | speed_template_32_48_64); | |
1949 | test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, | |
1950 | speed_template_32_48_64); | |
1951 | test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, | |
1952 | speed_template_16_24_32); | |
1953 | test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, | |
1954 | speed_template_16_24_32); | |
de197533 NR |
1955 | test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, |
1956 | speed_template_16_24_32); | |
1957 | test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, | |
1958 | speed_template_16_24_32); | |
1959 | test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, | |
1960 | speed_template_16_24_32); | |
1961 | test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, | |
1962 | speed_template_16_24_32); | |
69d3150c JK |
1963 | test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0, |
1964 | speed_template_20_28_36); | |
1965 | test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0, | |
1966 | speed_template_20_28_36); | |
3f3baf35 JK |
1967 | break; |
1968 | ||
1969 | case 501: | |
1970 | test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec, | |
1971 | des3_speed_template, DES3_SPEED_VECTORS, | |
1972 | speed_template_24); | |
1973 | test_acipher_speed("ecb(des3_ede)", DECRYPT, sec, | |
1974 | des3_speed_template, DES3_SPEED_VECTORS, | |
1975 | speed_template_24); | |
1976 | test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec, | |
1977 | des3_speed_template, DES3_SPEED_VECTORS, | |
1978 | speed_template_24); | |
1979 | test_acipher_speed("cbc(des3_ede)", DECRYPT, sec, | |
1980 | des3_speed_template, DES3_SPEED_VECTORS, | |
1981 | speed_template_24); | |
de197533 NR |
1982 | test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec, |
1983 | des3_speed_template, DES3_SPEED_VECTORS, | |
1984 | speed_template_24); | |
1985 | test_acipher_speed("cfb(des3_ede)", DECRYPT, sec, | |
1986 | des3_speed_template, DES3_SPEED_VECTORS, | |
1987 | speed_template_24); | |
1988 | test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec, | |
1989 | des3_speed_template, DES3_SPEED_VECTORS, | |
1990 | speed_template_24); | |
1991 | test_acipher_speed("ofb(des3_ede)", DECRYPT, sec, | |
1992 | des3_speed_template, DES3_SPEED_VECTORS, | |
1993 | speed_template_24); | |
3f3baf35 JK |
1994 | break; |
1995 | ||
1996 | case 502: | |
1997 | test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, | |
1998 | speed_template_8); | |
1999 | test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, | |
2000 | speed_template_8); | |
2001 | test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, | |
2002 | speed_template_8); | |
2003 | test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, | |
2004 | speed_template_8); | |
de197533 NR |
2005 | test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, |
2006 | speed_template_8); | |
2007 | test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, | |
2008 | speed_template_8); | |
2009 | test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, | |
2010 | speed_template_8); | |
2011 | test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, | |
2012 | speed_template_8); | |
3f3baf35 JK |
2013 | break; |
2014 | ||
7fb7fe44 JK |
2015 | case 503: |
2016 | test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, | |
2017 | speed_template_16_32); | |
2018 | test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, | |
2019 | speed_template_16_32); | |
2020 | test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, | |
2021 | speed_template_16_32); | |
2022 | test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, | |
2023 | speed_template_16_32); | |
2024 | test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, | |
2025 | speed_template_16_32); | |
2026 | test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, | |
2027 | speed_template_16_32); | |
87aae4bf JK |
2028 | test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
2029 | speed_template_32_48); | |
2030 | test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, | |
2031 | speed_template_32_48); | |
5209c07a JK |
2032 | test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
2033 | speed_template_32_64); | |
2034 | test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, | |
2035 | speed_template_32_64); | |
7fb7fe44 JK |
2036 | break; |
2037 | ||
107778b5 JG |
2038 | case 504: |
2039 | test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, | |
2040 | speed_template_16_24_32); | |
2041 | test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, | |
2042 | speed_template_16_24_32); | |
2043 | test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, | |
2044 | speed_template_16_24_32); | |
2045 | test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, | |
2046 | speed_template_16_24_32); | |
2047 | test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, | |
2048 | speed_template_16_24_32); | |
2049 | test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, | |
2050 | speed_template_16_24_32); | |
2051 | test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, | |
2052 | speed_template_32_40_48); | |
2053 | test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, | |
2054 | speed_template_32_40_48); | |
2055 | test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, | |
2056 | speed_template_32_48_64); | |
2057 | test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, | |
2058 | speed_template_32_48_64); | |
2059 | break; | |
2060 | ||
31b4cd29 JK |
2061 | case 505: |
2062 | test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, | |
2063 | speed_template_8); | |
2064 | break; | |
2065 | ||
a2c58260 JG |
2066 | case 506: |
2067 | test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, | |
2068 | speed_template_8_16); | |
2069 | test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, | |
2070 | speed_template_8_16); | |
2071 | test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, | |
2072 | speed_template_8_16); | |
2073 | test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, | |
2074 | speed_template_8_16); | |
2075 | test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, | |
2076 | speed_template_8_16); | |
2077 | test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, | |
2078 | speed_template_8_16); | |
2079 | break; | |
2080 | ||
9b8b0405 JG |
2081 | case 507: |
2082 | test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, | |
2083 | speed_template_16_32); | |
2084 | test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, | |
2085 | speed_template_16_32); | |
2086 | test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, | |
2087 | speed_template_16_32); | |
2088 | test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, | |
2089 | speed_template_16_32); | |
2090 | test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, | |
2091 | speed_template_16_32); | |
2092 | test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, | |
2093 | speed_template_16_32); | |
2094 | test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, | |
2095 | speed_template_32_48); | |
2096 | test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, | |
2097 | speed_template_32_48); | |
2098 | test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, | |
2099 | speed_template_32_64); | |
2100 | test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, | |
2101 | speed_template_32_64); | |
2102 | break; | |
2103 | ||
bf9c5181 JK |
2104 | case 508: |
2105 | test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, | |
2106 | speed_template_16_32); | |
2107 | test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, | |
2108 | speed_template_16_32); | |
2109 | test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, | |
2110 | speed_template_16_32); | |
2111 | test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, | |
2112 | speed_template_16_32); | |
2113 | test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, | |
2114 | speed_template_16_32); | |
2115 | test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, | |
2116 | speed_template_16_32); | |
2117 | test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, | |
2118 | speed_template_32_48); | |
2119 | test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, | |
2120 | speed_template_32_48); | |
2121 | test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, | |
2122 | speed_template_32_64); | |
2123 | test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, | |
2124 | speed_template_32_64); | |
2125 | break; | |
2126 | ||
ad8b7c3e JK |
2127 | case 509: |
2128 | test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, | |
2129 | speed_template_8_32); | |
2130 | test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, | |
2131 | speed_template_8_32); | |
2132 | test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, | |
2133 | speed_template_8_32); | |
2134 | test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, | |
2135 | speed_template_8_32); | |
2136 | test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, | |
2137 | speed_template_8_32); | |
2138 | test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, | |
2139 | speed_template_8_32); | |
2140 | break; | |
2141 | ||
1da177e4 LT |
2142 | case 1000: |
2143 | test_available(); | |
2144 | break; | |
1da177e4 | 2145 | } |
4e033a6b JW |
2146 | |
2147 | return ret; | |
1da177e4 LT |
2148 | } |
2149 | ||
3af5b90b | 2150 | static int __init tcrypt_mod_init(void) |
1da177e4 | 2151 | { |
e3a4ea4f | 2152 | int err = -ENOMEM; |
f139cfa7 | 2153 | int i; |
e3a4ea4f | 2154 | |
f139cfa7 HX |
2155 | for (i = 0; i < TVMEMSIZE; i++) { |
2156 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); | |
2157 | if (!tvmem[i]) | |
2158 | goto err_free_tv; | |
2159 | } | |
1da177e4 | 2160 | |
8606813a | 2161 | err = do_test(alg, type, mask, mode); |
a873a5f1 | 2162 | |
4e033a6b JW |
2163 | if (err) { |
2164 | printk(KERN_ERR "tcrypt: one or more tests failed!\n"); | |
2165 | goto err_free_tv; | |
2166 | } | |
14fdf477 | 2167 | |
4e033a6b JW |
2168 | /* We intentionaly return -EAGAIN to prevent keeping the module, |
2169 | * unless we're running in fips mode. It does all its work from | |
2170 | * init() and doesn't offer any runtime functionality, but in | |
2171 | * the fips case, checking for a successful load is helpful. | |
14fdf477 ML |
2172 | * => we don't need it in the memory, do we? |
2173 | * -- mludvig | |
2174 | */ | |
4e033a6b JW |
2175 | if (!fips_enabled) |
2176 | err = -EAGAIN; | |
e3a4ea4f | 2177 | |
f139cfa7 HX |
2178 | err_free_tv: |
2179 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) | |
2180 | free_page((unsigned long)tvmem[i]); | |
e3a4ea4f MH |
2181 | |
2182 | return err; | |
1da177e4 LT |
2183 | } |
2184 | ||
2185 | /* | |
2186 | * If an init function is provided, an exit function must also be provided | |
2187 | * to allow module unload. | |
2188 | */ | |
3af5b90b | 2189 | static void __exit tcrypt_mod_fini(void) { } |
1da177e4 | 2190 | |
3af5b90b KB |
2191 | module_init(tcrypt_mod_init); |
2192 | module_exit(tcrypt_mod_fini); | |
1da177e4 | 2193 | |
a873a5f1 SK |
2194 | module_param(alg, charp, 0); |
2195 | module_param(type, uint, 0); | |
7be380f7 | 2196 | module_param(mask, uint, 0); |
1da177e4 | 2197 | module_param(mode, int, 0); |
ebfd9bcf | 2198 | module_param(sec, uint, 0); |
6a17944c HX |
2199 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
2200 | "(defaults to zero which uses CPU cycles instead)"); | |
1da177e4 LT |
2201 | |
2202 | MODULE_LICENSE("GPL"); | |
2203 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | |
2204 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |