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