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