blob: 1856d7ff26883bebe3dda79214e08cad6d58290b [file] [log] [blame]
Herbert Xuef2736f2005-06-22 13:26:03 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Mikko Herranene3a4ea42007-11-26 22:12:07 +08009 * Copyright (c) 2007 Nokia Siemens Networks
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
Adrian Hoban69435b92010-11-04 15:02:04 -040011 * 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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * 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
Herbert Xuef2736f2005-06-22 13:26:03 -070020 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * any later version.
22 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Herbert Xu18e33e62008-07-10 16:01:22 +080025#include <crypto/hash.h>
Herbert Xucba83562006-08-13 08:26:09 +100026#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
David Hardeman378f0582005-09-17 17:55:31 +100030#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070033#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070034#include <linux/timex.h>
35#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "tcrypt.h"
Jarod Wilson4e033a62009-05-27 15:10:21 +100037#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080040 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080042#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/*
Herbert Xuda7f0332008-07-31 17:08:25 +080045* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070046*/
47#define ENCRYPT 1
48#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Harald Welteebfd9bc2005-06-22 13:27:23 -070050/*
51 * Used by test_cipher_speed()
52 */
Herbert Xu6a179442005-06-22 13:29:03 -070053static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070054
Steffen Klasserta873a5f2009-06-19 19:46:53 +080055static char *alg = NULL;
56static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080057static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080059static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static char *check[] = {
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080062 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
63 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
64 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110065 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080066 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +080067 "lzo", "cts", "zlib", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070068};
69
Herbert Xuf139cfa2008-07-31 12:23:53 +080070static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
71 struct scatterlist *sg, int blen, int sec)
Herbert Xu6a179442005-06-22 13:29:03 -070072{
Herbert Xu6a179442005-06-22 13:29:03 -070073 unsigned long start, end;
74 int bcount;
75 int ret;
76
Herbert Xu6a179442005-06-22 13:29:03 -070077 for (start = jiffies, end = start + sec * HZ, bcount = 0;
78 time_before(jiffies, end); bcount++) {
79 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100080 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070081 else
Herbert Xucba83562006-08-13 08:26:09 +100082 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070083
84 if (ret)
85 return ret;
86 }
87
88 printk("%d operations in %d seconds (%ld bytes)\n",
89 bcount, sec, (long)bcount * blen);
90 return 0;
91}
92
Herbert Xuf139cfa2008-07-31 12:23:53 +080093static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
94 struct scatterlist *sg, int blen)
Herbert Xu6a179442005-06-22 13:29:03 -070095{
Herbert Xu6a179442005-06-22 13:29:03 -070096 unsigned long cycles = 0;
97 int ret = 0;
98 int i;
99
Herbert Xu6a179442005-06-22 13:29:03 -0700100 local_irq_disable();
101
102 /* Warm-up run. */
103 for (i = 0; i < 4; i++) {
104 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000105 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700106 else
Herbert Xucba83562006-08-13 08:26:09 +1000107 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700108
109 if (ret)
110 goto out;
111 }
112
113 /* The real thing. */
114 for (i = 0; i < 8; i++) {
115 cycles_t start, end;
116
117 start = get_cycles();
118 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000119 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700120 else
Herbert Xucba83562006-08-13 08:26:09 +1000121 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700122 end = get_cycles();
123
124 if (ret)
125 goto out;
126
127 cycles += end - start;
128 }
129
130out:
131 local_irq_enable();
Herbert Xu6a179442005-06-22 13:29:03 -0700132
133 if (ret == 0)
134 printk("1 operation in %lu cycles (%d bytes)\n",
135 (cycles + 4) / 8, blen);
136
137 return ret;
138}
139
Tim Chen53f52d72013-12-11 14:28:47 -0800140static int test_aead_jiffies(struct aead_request *req, int enc,
141 int blen, int sec)
142{
143 unsigned long start, end;
144 int bcount;
145 int ret;
146
147 for (start = jiffies, end = start + sec * HZ, bcount = 0;
148 time_before(jiffies, end); bcount++) {
149 if (enc)
150 ret = crypto_aead_encrypt(req);
151 else
152 ret = crypto_aead_decrypt(req);
153
154 if (ret)
155 return ret;
156 }
157
158 printk("%d operations in %d seconds (%ld bytes)\n",
159 bcount, sec, (long)bcount * blen);
160 return 0;
161}
162
163static int test_aead_cycles(struct aead_request *req, int enc, int blen)
164{
165 unsigned long cycles = 0;
166 int ret = 0;
167 int i;
168
169 local_irq_disable();
170
171 /* Warm-up run. */
172 for (i = 0; i < 4; i++) {
173 if (enc)
174 ret = crypto_aead_encrypt(req);
175 else
176 ret = crypto_aead_decrypt(req);
177
178 if (ret)
179 goto out;
180 }
181
182 /* The real thing. */
183 for (i = 0; i < 8; i++) {
184 cycles_t start, end;
185
186 start = get_cycles();
187 if (enc)
188 ret = crypto_aead_encrypt(req);
189 else
190 ret = crypto_aead_decrypt(req);
191 end = get_cycles();
192
193 if (ret)
194 goto out;
195
196 cycles += end - start;
197 }
198
199out:
200 local_irq_enable();
201
202 if (ret == 0)
203 printk("1 operation in %lu cycles (%d bytes)\n",
204 (cycles + 4) / 8, blen);
205
206 return ret;
207}
208
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800209static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800210static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
211
212#define XBUFSIZE 8
213#define MAX_IVLEN 32
214
215static int testmgr_alloc_buf(char *buf[XBUFSIZE])
216{
217 int i;
218
219 for (i = 0; i < XBUFSIZE; i++) {
220 buf[i] = (void *)__get_free_page(GFP_KERNEL);
221 if (!buf[i])
222 goto err_free_buf;
223 }
224
225 return 0;
226
227err_free_buf:
228 while (i-- > 0)
229 free_page((unsigned long)buf[i]);
230
231 return -ENOMEM;
232}
233
234static void testmgr_free_buf(char *buf[XBUFSIZE])
235{
236 int i;
237
238 for (i = 0; i < XBUFSIZE; i++)
239 free_page((unsigned long)buf[i]);
240}
241
242static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
243 unsigned int buflen)
244{
245 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
246 int k, rem;
247
248 np = (np > XBUFSIZE) ? XBUFSIZE : np;
249 rem = buflen % PAGE_SIZE;
250 if (np > XBUFSIZE) {
251 rem = PAGE_SIZE;
252 np = XBUFSIZE;
253 }
254 sg_init_table(sg, np);
255 for (k = 0; k < np; ++k) {
256 if (k == (np-1))
257 sg_set_buf(&sg[k], xbuf[k], rem);
258 else
259 sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE);
260 }
261}
262
263static void test_aead_speed(const char *algo, int enc, unsigned int sec,
264 struct aead_speed_template *template,
265 unsigned int tcount, u8 authsize,
266 unsigned int aad_size, u8 *keysize)
267{
268 unsigned int i, j;
269 struct crypto_aead *tfm;
270 int ret = -ENOMEM;
271 const char *key;
272 struct aead_request *req;
273 struct scatterlist *sg;
274 struct scatterlist *asg;
275 struct scatterlist *sgout;
276 const char *e;
277 void *assoc;
278 char iv[MAX_IVLEN];
279 char *xbuf[XBUFSIZE];
280 char *xoutbuf[XBUFSIZE];
281 char *axbuf[XBUFSIZE];
282 unsigned int *b_size;
283 unsigned int iv_len;
284
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200285 if (aad_size >= PAGE_SIZE) {
286 pr_err("associate data length (%u) too big\n", aad_size);
287 return;
288 }
289
Tim Chen53f52d72013-12-11 14:28:47 -0800290 if (enc == ENCRYPT)
291 e = "encryption";
292 else
293 e = "decryption";
294
295 if (testmgr_alloc_buf(xbuf))
296 goto out_noxbuf;
297 if (testmgr_alloc_buf(axbuf))
298 goto out_noaxbuf;
299 if (testmgr_alloc_buf(xoutbuf))
300 goto out_nooutbuf;
301
302 sg = kmalloc(sizeof(*sg) * 8 * 3, GFP_KERNEL);
303 if (!sg)
304 goto out_nosg;
305 asg = &sg[8];
306 sgout = &asg[8];
307
308
309 printk(KERN_INFO "\ntesting speed of %s %s\n", algo, e);
310
311 tfm = crypto_alloc_aead(algo, 0, 0);
312
313 if (IS_ERR(tfm)) {
314 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
315 PTR_ERR(tfm));
316 return;
317 }
318
319 req = aead_request_alloc(tfm, GFP_KERNEL);
320 if (!req) {
321 pr_err("alg: aead: Failed to allocate request for %s\n",
322 algo);
323 goto out;
324 }
325
326 i = 0;
327 do {
328 b_size = aead_sizes;
329 do {
330 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200331 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800332 sg_init_one(&asg[0], assoc, aad_size);
333
334 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
335 pr_err("template (%u) too big for tvmem (%lu)\n",
336 *keysize + *b_size,
337 TVMEMSIZE * PAGE_SIZE);
338 goto out;
339 }
340
341 key = tvmem[0];
342 for (j = 0; j < tcount; j++) {
343 if (template[j].klen == *keysize) {
344 key = template[j].key;
345 break;
346 }
347 }
348 ret = crypto_aead_setkey(tfm, key, *keysize);
349 ret = crypto_aead_setauthsize(tfm, authsize);
350
351 iv_len = crypto_aead_ivsize(tfm);
352 if (iv_len)
353 memset(&iv, 0xff, iv_len);
354
355 crypto_aead_clear_flags(tfm, ~0);
356 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
357 i, *keysize * 8, *b_size);
358
359
360 memset(tvmem[0], 0xff, PAGE_SIZE);
361
362 if (ret) {
363 pr_err("setkey() failed flags=%x\n",
364 crypto_aead_get_flags(tfm));
365 goto out;
366 }
367
368 sg_init_aead(&sg[0], xbuf,
369 *b_size + (enc ? authsize : 0));
370
371 sg_init_aead(&sgout[0], xoutbuf,
372 *b_size + (enc ? authsize : 0));
373
374 aead_request_set_crypt(req, sg, sgout, *b_size, iv);
375 aead_request_set_assoc(req, asg, aad_size);
376
377 if (sec)
378 ret = test_aead_jiffies(req, enc, *b_size, sec);
379 else
380 ret = test_aead_cycles(req, enc, *b_size);
381
382 if (ret) {
383 pr_err("%s() failed return code=%d\n", e, ret);
384 break;
385 }
386 b_size++;
387 i++;
388 } while (*b_size);
389 keysize++;
390 } while (*keysize);
391
392out:
393 crypto_free_aead(tfm);
394 kfree(sg);
395out_nosg:
396 testmgr_free_buf(xoutbuf);
397out_nooutbuf:
398 testmgr_free_buf(axbuf);
399out_noaxbuf:
400 testmgr_free_buf(xbuf);
401out_noxbuf:
402 return;
403}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800404
Herbert Xu01b32322008-07-31 15:41:55 +0800405static void test_cipher_speed(const char *algo, int enc, unsigned int sec,
Herbert Xuda7f0332008-07-31 17:08:25 +0800406 struct cipher_speed_template *template,
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800407 unsigned int tcount, u8 *keysize)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700408{
Herbert Xudce907c2005-06-22 13:27:51 -0700409 unsigned int ret, i, j, iv_len;
David Sterbaf07ef1d2011-03-04 15:28:52 +0800410 const char *key;
411 char iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000412 struct crypto_blkcipher *tfm;
413 struct blkcipher_desc desc;
414 const char *e;
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800415 u32 *b_size;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700416
417 if (enc == ENCRYPT)
418 e = "encryption";
419 else
420 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700421
Herbert Xucba83562006-08-13 08:26:09 +1000422 printk("\ntesting speed of %s %s\n", algo, e);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700423
Herbert Xucba83562006-08-13 08:26:09 +1000424 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700425
Herbert Xucba83562006-08-13 08:26:09 +1000426 if (IS_ERR(tfm)) {
427 printk("failed to load transform for %s: %ld\n", algo,
428 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700429 return;
430 }
Herbert Xucba83562006-08-13 08:26:09 +1000431 desc.tfm = tfm;
432 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700433
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800434 i = 0;
435 do {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700436
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800437 b_size = block_sizes;
438 do {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800439 struct scatterlist sg[TVMEMSIZE];
Harald Welteebfd9bc2005-06-22 13:27:23 -0700440
Herbert Xuf139cfa2008-07-31 12:23:53 +0800441 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
442 printk("template (%u) too big for "
443 "tvmem (%lu)\n", *keysize + *b_size,
444 TVMEMSIZE * PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800445 goto out;
446 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700447
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800448 printk("test %u (%d bit key, %d byte blocks): ", i,
449 *keysize * 8, *b_size);
450
Herbert Xuf139cfa2008-07-31 12:23:53 +0800451 memset(tvmem[0], 0xff, PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800452
453 /* set key, plain text and IV */
Herbert Xuda7f0332008-07-31 17:08:25 +0800454 key = tvmem[0];
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800455 for (j = 0; j < tcount; j++) {
456 if (template[j].klen == *keysize) {
457 key = template[j].key;
458 break;
459 }
460 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800461
462 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
463 if (ret) {
464 printk("setkey() failed flags=%x\n",
465 crypto_blkcipher_get_flags(tfm));
466 goto out;
467 }
468
Herbert Xuf139cfa2008-07-31 12:23:53 +0800469 sg_init_table(sg, TVMEMSIZE);
470 sg_set_buf(sg, tvmem[0] + *keysize,
471 PAGE_SIZE - *keysize);
472 for (j = 1; j < TVMEMSIZE; j++) {
473 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
474 memset (tvmem[j], 0xff, PAGE_SIZE);
475 }
476
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800477 iv_len = crypto_blkcipher_ivsize(tfm);
478 if (iv_len) {
479 memset(&iv, 0xff, iv_len);
480 crypto_blkcipher_set_iv(tfm, iv, iv_len);
481 }
482
483 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800484 ret = test_cipher_jiffies(&desc, enc, sg,
485 *b_size, sec);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800486 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800487 ret = test_cipher_cycles(&desc, enc, sg,
488 *b_size);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800489
490 if (ret) {
491 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xudce907c2005-06-22 13:27:51 -0700492 break;
493 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800494 b_size++;
495 i++;
496 } while (*b_size);
497 keysize++;
498 } while (*keysize);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700499
500out:
Herbert Xucba83562006-08-13 08:26:09 +1000501 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700502}
503
Herbert Xuf139cfa2008-07-31 12:23:53 +0800504static int test_hash_jiffies_digest(struct hash_desc *desc,
505 struct scatterlist *sg, int blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000506 char *out, int sec)
Michal Ludvige8057922006-05-30 22:04:19 +1000507{
Michal Ludvige8057922006-05-30 22:04:19 +1000508 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000509 int bcount;
510 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000511
512 for (start = jiffies, end = start + sec * HZ, bcount = 0;
513 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000514 ret = crypto_hash_digest(desc, sg, blen, out);
515 if (ret)
516 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000517 }
518
519 printk("%6u opers/sec, %9lu bytes/sec\n",
520 bcount / sec, ((long)bcount * blen) / sec);
521
Herbert Xue9d41162006-08-19 21:38:49 +1000522 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000523}
524
Herbert Xuf139cfa2008-07-31 12:23:53 +0800525static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
526 int blen, int plen, char *out, int sec)
Herbert Xue9d41162006-08-19 21:38:49 +1000527{
Herbert Xue9d41162006-08-19 21:38:49 +1000528 unsigned long start, end;
529 int bcount, pcount;
530 int ret;
531
532 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800533 return test_hash_jiffies_digest(desc, sg, blen, out, sec);
Herbert Xua5a613a2007-10-27 00:51:21 -0700534
Herbert Xue9d41162006-08-19 21:38:49 +1000535 for (start = jiffies, end = start + sec * HZ, bcount = 0;
536 time_before(jiffies, end); bcount++) {
537 ret = crypto_hash_init(desc);
538 if (ret)
539 return ret;
540 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000541 ret = crypto_hash_update(desc, sg, plen);
542 if (ret)
543 return ret;
544 }
545 /* we assume there is enough space in 'out' for the result */
546 ret = crypto_hash_final(desc, out);
547 if (ret)
548 return ret;
549 }
550
551 printk("%6u opers/sec, %9lu bytes/sec\n",
552 bcount / sec, ((long)bcount * blen) / sec);
553
554 return 0;
555}
556
Herbert Xuf139cfa2008-07-31 12:23:53 +0800557static int test_hash_cycles_digest(struct hash_desc *desc,
558 struct scatterlist *sg, int blen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000559{
Michal Ludvige8057922006-05-30 22:04:19 +1000560 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000561 int i;
562 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000563
Michal Ludvige8057922006-05-30 22:04:19 +1000564 local_irq_disable();
565
566 /* Warm-up run. */
567 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000568 ret = crypto_hash_digest(desc, sg, blen, out);
569 if (ret)
570 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000571 }
572
573 /* The real thing. */
574 for (i = 0; i < 8; i++) {
575 cycles_t start, end;
576
Michal Ludvige8057922006-05-30 22:04:19 +1000577 start = get_cycles();
578
Herbert Xue9d41162006-08-19 21:38:49 +1000579 ret = crypto_hash_digest(desc, sg, blen, out);
580 if (ret)
581 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000582
583 end = get_cycles();
584
585 cycles += end - start;
586 }
587
Herbert Xue9d41162006-08-19 21:38:49 +1000588out:
Michal Ludvige8057922006-05-30 22:04:19 +1000589 local_irq_enable();
Michal Ludvige8057922006-05-30 22:04:19 +1000590
Herbert Xue9d41162006-08-19 21:38:49 +1000591 if (ret)
592 return ret;
593
Michal Ludvige8057922006-05-30 22:04:19 +1000594 printk("%6lu cycles/operation, %4lu cycles/byte\n",
595 cycles / 8, cycles / (8 * blen));
596
Herbert Xue9d41162006-08-19 21:38:49 +1000597 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000598}
599
Herbert Xuf139cfa2008-07-31 12:23:53 +0800600static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
601 int blen, int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000602{
Herbert Xue9d41162006-08-19 21:38:49 +1000603 unsigned long cycles = 0;
604 int i, pcount;
605 int ret;
606
607 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800608 return test_hash_cycles_digest(desc, sg, blen, out);
Herbert Xua5a613a2007-10-27 00:51:21 -0700609
Herbert Xue9d41162006-08-19 21:38:49 +1000610 local_irq_disable();
611
612 /* Warm-up run. */
613 for (i = 0; i < 4; i++) {
614 ret = crypto_hash_init(desc);
615 if (ret)
616 goto out;
617 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000618 ret = crypto_hash_update(desc, sg, plen);
619 if (ret)
620 goto out;
621 }
Herbert Xu29059d12007-05-18 16:25:19 +1000622 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000623 if (ret)
624 goto out;
625 }
626
627 /* The real thing. */
628 for (i = 0; i < 8; i++) {
629 cycles_t start, end;
630
631 start = get_cycles();
632
633 ret = crypto_hash_init(desc);
634 if (ret)
635 goto out;
636 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000637 ret = crypto_hash_update(desc, sg, plen);
638 if (ret)
639 goto out;
640 }
641 ret = crypto_hash_final(desc, out);
642 if (ret)
643 goto out;
644
645 end = get_cycles();
646
647 cycles += end - start;
648 }
649
650out:
651 local_irq_enable();
Herbert Xue9d41162006-08-19 21:38:49 +1000652
653 if (ret)
654 return ret;
655
656 printk("%6lu cycles/operation, %4lu cycles/byte\n",
657 cycles / 8, cycles / (8 * blen));
658
659 return 0;
660}
661
David S. Millerbeb63da72010-05-19 14:11:21 +1000662static void test_hash_sg_init(struct scatterlist *sg)
663{
664 int i;
665
666 sg_init_table(sg, TVMEMSIZE);
667 for (i = 0; i < TVMEMSIZE; i++) {
668 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
669 memset(tvmem[i], 0xff, PAGE_SIZE);
670 }
671}
672
Herbert Xu01b32322008-07-31 15:41:55 +0800673static void test_hash_speed(const char *algo, unsigned int sec,
674 struct hash_speed *speed)
Herbert Xue9d41162006-08-19 21:38:49 +1000675{
Herbert Xuf139cfa2008-07-31 12:23:53 +0800676 struct scatterlist sg[TVMEMSIZE];
Herbert Xue9d41162006-08-19 21:38:49 +1000677 struct crypto_hash *tfm;
678 struct hash_desc desc;
Frank Seidel376bacb2009-03-29 15:18:39 +0800679 static char output[1024];
Michal Ludvige8057922006-05-30 22:04:19 +1000680 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000681 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000682
Frank Seidel376bacb2009-03-29 15:18:39 +0800683 printk(KERN_INFO "\ntesting speed of %s\n", algo);
Michal Ludvige8057922006-05-30 22:04:19 +1000684
Herbert Xue9d41162006-08-19 21:38:49 +1000685 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000686
Herbert Xue9d41162006-08-19 21:38:49 +1000687 if (IS_ERR(tfm)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800688 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
Herbert Xue9d41162006-08-19 21:38:49 +1000689 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000690 return;
691 }
692
Herbert Xue9d41162006-08-19 21:38:49 +1000693 desc.tfm = tfm;
694 desc.flags = 0;
695
696 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800697 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000698 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000699 goto out;
700 }
701
David S. Millerbeb63da72010-05-19 14:11:21 +1000702 test_hash_sg_init(sg);
Michal Ludvige8057922006-05-30 22:04:19 +1000703 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800704 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800705 printk(KERN_ERR
706 "template (%u) too big for tvmem (%lu)\n",
Herbert Xuf139cfa2008-07-31 12:23:53 +0800707 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
Michal Ludvige8057922006-05-30 22:04:19 +1000708 goto out;
709 }
710
Huang Ying18bcc912010-03-10 18:30:32 +0800711 if (speed[i].klen)
712 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
713
Frank Seidel376bacb2009-03-29 15:18:39 +0800714 printk(KERN_INFO "test%3u "
715 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Michal Ludvige8057922006-05-30 22:04:19 +1000716 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
717
Michal Ludvige8057922006-05-30 22:04:19 +1000718 if (sec)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800719 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000720 speed[i].plen, output, sec);
Michal Ludvige8057922006-05-30 22:04:19 +1000721 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800722 ret = test_hash_cycles(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000723 speed[i].plen, output);
724
725 if (ret) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800726 printk(KERN_ERR "hashing failed ret=%d\n", ret);
Herbert Xue9d41162006-08-19 21:38:49 +1000727 break;
728 }
Michal Ludvige8057922006-05-30 22:04:19 +1000729 }
730
731out:
Herbert Xue9d41162006-08-19 21:38:49 +1000732 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000733}
734
David S. Millerbeb63da72010-05-19 14:11:21 +1000735struct tcrypt_result {
736 struct completion completion;
737 int err;
738};
739
740static void tcrypt_complete(struct crypto_async_request *req, int err)
741{
742 struct tcrypt_result *res = req->data;
743
744 if (err == -EINPROGRESS)
745 return;
746
747 res->err = err;
748 complete(&res->completion);
749}
750
751static inline int do_one_ahash_op(struct ahash_request *req, int ret)
752{
753 if (ret == -EINPROGRESS || ret == -EBUSY) {
754 struct tcrypt_result *tr = req->base.data;
755
756 ret = wait_for_completion_interruptible(&tr->completion);
757 if (!ret)
758 ret = tr->err;
Wolfram Sang16735d02013-11-14 14:32:02 -0800759 reinit_completion(&tr->completion);
David S. Millerbeb63da72010-05-19 14:11:21 +1000760 }
761 return ret;
762}
763
764static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
765 char *out, int sec)
766{
767 unsigned long start, end;
768 int bcount;
769 int ret;
770
771 for (start = jiffies, end = start + sec * HZ, bcount = 0;
772 time_before(jiffies, end); bcount++) {
773 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
774 if (ret)
775 return ret;
776 }
777
778 printk("%6u opers/sec, %9lu bytes/sec\n",
779 bcount / sec, ((long)bcount * blen) / sec);
780
781 return 0;
782}
783
784static int test_ahash_jiffies(struct ahash_request *req, int blen,
785 int plen, char *out, int sec)
786{
787 unsigned long start, end;
788 int bcount, pcount;
789 int ret;
790
791 if (plen == blen)
792 return test_ahash_jiffies_digest(req, blen, out, sec);
793
794 for (start = jiffies, end = start + sec * HZ, bcount = 0;
795 time_before(jiffies, end); bcount++) {
796 ret = crypto_ahash_init(req);
797 if (ret)
798 return ret;
799 for (pcount = 0; pcount < blen; pcount += plen) {
800 ret = do_one_ahash_op(req, crypto_ahash_update(req));
801 if (ret)
802 return ret;
803 }
804 /* we assume there is enough space in 'out' for the result */
805 ret = do_one_ahash_op(req, crypto_ahash_final(req));
806 if (ret)
807 return ret;
808 }
809
810 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
811 bcount / sec, ((long)bcount * blen) / sec);
812
813 return 0;
814}
815
816static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
817 char *out)
818{
819 unsigned long cycles = 0;
820 int ret, i;
821
822 /* Warm-up run. */
823 for (i = 0; i < 4; i++) {
824 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
825 if (ret)
826 goto out;
827 }
828
829 /* The real thing. */
830 for (i = 0; i < 8; i++) {
831 cycles_t start, end;
832
833 start = get_cycles();
834
835 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
836 if (ret)
837 goto out;
838
839 end = get_cycles();
840
841 cycles += end - start;
842 }
843
844out:
845 if (ret)
846 return ret;
847
848 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
849 cycles / 8, cycles / (8 * blen));
850
851 return 0;
852}
853
854static int test_ahash_cycles(struct ahash_request *req, int blen,
855 int plen, char *out)
856{
857 unsigned long cycles = 0;
858 int i, pcount, ret;
859
860 if (plen == blen)
861 return test_ahash_cycles_digest(req, blen, out);
862
863 /* Warm-up run. */
864 for (i = 0; i < 4; i++) {
865 ret = crypto_ahash_init(req);
866 if (ret)
867 goto out;
868 for (pcount = 0; pcount < blen; pcount += plen) {
869 ret = do_one_ahash_op(req, crypto_ahash_update(req));
870 if (ret)
871 goto out;
872 }
873 ret = do_one_ahash_op(req, crypto_ahash_final(req));
874 if (ret)
875 goto out;
876 }
877
878 /* The real thing. */
879 for (i = 0; i < 8; i++) {
880 cycles_t start, end;
881
882 start = get_cycles();
883
884 ret = crypto_ahash_init(req);
885 if (ret)
886 goto out;
887 for (pcount = 0; pcount < blen; pcount += plen) {
888 ret = do_one_ahash_op(req, crypto_ahash_update(req));
889 if (ret)
890 goto out;
891 }
892 ret = do_one_ahash_op(req, crypto_ahash_final(req));
893 if (ret)
894 goto out;
895
896 end = get_cycles();
897
898 cycles += end - start;
899 }
900
901out:
902 if (ret)
903 return ret;
904
905 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
906 cycles / 8, cycles / (8 * blen));
907
908 return 0;
909}
910
911static void test_ahash_speed(const char *algo, unsigned int sec,
912 struct hash_speed *speed)
913{
914 struct scatterlist sg[TVMEMSIZE];
915 struct tcrypt_result tresult;
916 struct ahash_request *req;
917 struct crypto_ahash *tfm;
918 static char output[1024];
919 int i, ret;
920
921 printk(KERN_INFO "\ntesting speed of async %s\n", algo);
922
923 tfm = crypto_alloc_ahash(algo, 0, 0);
924 if (IS_ERR(tfm)) {
925 pr_err("failed to load transform for %s: %ld\n",
926 algo, PTR_ERR(tfm));
927 return;
928 }
929
930 if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
931 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
932 crypto_ahash_digestsize(tfm), sizeof(output));
933 goto out;
934 }
935
936 test_hash_sg_init(sg);
937 req = ahash_request_alloc(tfm, GFP_KERNEL);
938 if (!req) {
939 pr_err("ahash request allocation failure\n");
940 goto out;
941 }
942
943 init_completion(&tresult.completion);
944 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
945 tcrypt_complete, &tresult);
946
947 for (i = 0; speed[i].blen != 0; i++) {
948 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
949 pr_err("template (%u) too big for tvmem (%lu)\n",
950 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
951 break;
952 }
953
954 pr_info("test%3u "
955 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
956 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
957
958 ahash_request_set_crypt(req, sg, output, speed[i].plen);
959
960 if (sec)
961 ret = test_ahash_jiffies(req, speed[i].blen,
962 speed[i].plen, output, sec);
963 else
964 ret = test_ahash_cycles(req, speed[i].blen,
965 speed[i].plen, output);
966
967 if (ret) {
968 pr_err("hashing failed ret=%d\n", ret);
969 break;
970 }
971 }
972
973 ahash_request_free(req);
974
975out:
976 crypto_free_ahash(tfm);
977}
978
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300979static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
980{
981 if (ret == -EINPROGRESS || ret == -EBUSY) {
982 struct tcrypt_result *tr = req->base.data;
983
984 ret = wait_for_completion_interruptible(&tr->completion);
985 if (!ret)
986 ret = tr->err;
Wolfram Sang16735d02013-11-14 14:32:02 -0800987 reinit_completion(&tr->completion);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300988 }
989
990 return ret;
991}
992
993static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
994 int blen, int sec)
995{
996 unsigned long start, end;
997 int bcount;
998 int ret;
999
1000 for (start = jiffies, end = start + sec * HZ, bcount = 0;
1001 time_before(jiffies, end); bcount++) {
1002 if (enc)
1003 ret = do_one_acipher_op(req,
1004 crypto_ablkcipher_encrypt(req));
1005 else
1006 ret = do_one_acipher_op(req,
1007 crypto_ablkcipher_decrypt(req));
1008
1009 if (ret)
1010 return ret;
1011 }
1012
1013 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1014 bcount, sec, (long)bcount * blen);
1015 return 0;
1016}
1017
1018static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
1019 int blen)
1020{
1021 unsigned long cycles = 0;
1022 int ret = 0;
1023 int i;
1024
1025 /* Warm-up run. */
1026 for (i = 0; i < 4; i++) {
1027 if (enc)
1028 ret = do_one_acipher_op(req,
1029 crypto_ablkcipher_encrypt(req));
1030 else
1031 ret = do_one_acipher_op(req,
1032 crypto_ablkcipher_decrypt(req));
1033
1034 if (ret)
1035 goto out;
1036 }
1037
1038 /* The real thing. */
1039 for (i = 0; i < 8; i++) {
1040 cycles_t start, end;
1041
1042 start = get_cycles();
1043 if (enc)
1044 ret = do_one_acipher_op(req,
1045 crypto_ablkcipher_encrypt(req));
1046 else
1047 ret = do_one_acipher_op(req,
1048 crypto_ablkcipher_decrypt(req));
1049 end = get_cycles();
1050
1051 if (ret)
1052 goto out;
1053
1054 cycles += end - start;
1055 }
1056
1057out:
1058 if (ret == 0)
1059 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1060 (cycles + 4) / 8, blen);
1061
1062 return ret;
1063}
1064
1065static void test_acipher_speed(const char *algo, int enc, unsigned int sec,
1066 struct cipher_speed_template *template,
1067 unsigned int tcount, u8 *keysize)
1068{
Nicolas Royerde1975332012-07-01 19:19:47 +02001069 unsigned int ret, i, j, k, iv_len;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001070 struct tcrypt_result tresult;
1071 const char *key;
1072 char iv[128];
1073 struct ablkcipher_request *req;
1074 struct crypto_ablkcipher *tfm;
1075 const char *e;
1076 u32 *b_size;
1077
1078 if (enc == ENCRYPT)
1079 e = "encryption";
1080 else
1081 e = "decryption";
1082
1083 pr_info("\ntesting speed of async %s %s\n", algo, e);
1084
1085 init_completion(&tresult.completion);
1086
1087 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1088
1089 if (IS_ERR(tfm)) {
1090 pr_err("failed to load transform for %s: %ld\n", algo,
1091 PTR_ERR(tfm));
1092 return;
1093 }
1094
1095 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
1096 if (!req) {
1097 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1098 algo);
1099 goto out;
1100 }
1101
1102 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1103 tcrypt_complete, &tresult);
1104
1105 i = 0;
1106 do {
1107 b_size = block_sizes;
1108
1109 do {
1110 struct scatterlist sg[TVMEMSIZE];
1111
1112 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1113 pr_err("template (%u) too big for "
1114 "tvmem (%lu)\n", *keysize + *b_size,
1115 TVMEMSIZE * PAGE_SIZE);
1116 goto out_free_req;
1117 }
1118
1119 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1120 *keysize * 8, *b_size);
1121
1122 memset(tvmem[0], 0xff, PAGE_SIZE);
1123
1124 /* set key, plain text and IV */
1125 key = tvmem[0];
1126 for (j = 0; j < tcount; j++) {
1127 if (template[j].klen == *keysize) {
1128 key = template[j].key;
1129 break;
1130 }
1131 }
1132
1133 crypto_ablkcipher_clear_flags(tfm, ~0);
1134
1135 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
1136 if (ret) {
1137 pr_err("setkey() failed flags=%x\n",
1138 crypto_ablkcipher_get_flags(tfm));
1139 goto out_free_req;
1140 }
1141
1142 sg_init_table(sg, TVMEMSIZE);
Nicolas Royerde1975332012-07-01 19:19:47 +02001143
1144 k = *keysize + *b_size;
1145 if (k > PAGE_SIZE) {
1146 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001147 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +02001148 k -= PAGE_SIZE;
1149 j = 1;
1150 while (k > PAGE_SIZE) {
1151 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1152 memset(tvmem[j], 0xff, PAGE_SIZE);
1153 j++;
1154 k -= PAGE_SIZE;
1155 }
1156 sg_set_buf(sg + j, tvmem[j], k);
1157 memset(tvmem[j], 0xff, k);
1158 } else {
1159 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001160 }
1161
1162 iv_len = crypto_ablkcipher_ivsize(tfm);
1163 if (iv_len)
1164 memset(&iv, 0xff, iv_len);
1165
1166 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1167
1168 if (sec)
1169 ret = test_acipher_jiffies(req, enc,
1170 *b_size, sec);
1171 else
1172 ret = test_acipher_cycles(req, enc,
1173 *b_size);
1174
1175 if (ret) {
1176 pr_err("%s() failed flags=%x\n", e,
1177 crypto_ablkcipher_get_flags(tfm));
1178 break;
1179 }
1180 b_size++;
1181 i++;
1182 } while (*b_size);
1183 keysize++;
1184 } while (*keysize);
1185
1186out_free_req:
1187 ablkcipher_request_free(req);
1188out:
1189 crypto_free_ablkcipher(tfm);
1190}
1191
Herbert Xuef2736f2005-06-22 13:26:03 -07001192static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193{
1194 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 while (*name) {
1197 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001198 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001199 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202}
1203
Herbert Xu01b32322008-07-31 15:41:55 +08001204static inline int tcrypt_test(const char *alg)
1205{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001206 int ret;
1207
1208 ret = alg_test(alg, alg, 0, 0);
1209 /* non-fips algs return -EINVAL in fips mode */
1210 if (fips_enabled && ret == -EINVAL)
1211 ret = 0;
1212 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001213}
1214
Jarod Wilson4e033a62009-05-27 15:10:21 +10001215static int do_test(int m)
Herbert Xu01b32322008-07-31 15:41:55 +08001216{
1217 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001218 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001219
1220 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 case 0:
Herbert Xu01b32322008-07-31 15:41:55 +08001222 for (i = 1; i < 200; i++)
Jarod Wilson4e033a62009-05-27 15:10:21 +10001223 ret += do_test(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 break;
1225
1226 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001227 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 break;
1229
1230 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001231 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 break;
1233
1234 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001235 ret += tcrypt_test("ecb(des)");
1236 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001237 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 break;
1239
1240 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001241 ret += tcrypt_test("ecb(des3_ede)");
1242 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001243 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 break;
1245
1246 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001247 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001251 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001255 ret += tcrypt_test("ecb(blowfish)");
1256 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001257 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 break;
1259
1260 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001261 ret += tcrypt_test("ecb(twofish)");
1262 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001263 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001264 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001265 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001267
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001269 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001270 ret += tcrypt_test("cbc(serpent)");
1271 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001272 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001273 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 break;
1275
1276 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001277 ret += tcrypt_test("ecb(aes)");
1278 ret += tcrypt_test("cbc(aes)");
1279 ret += tcrypt_test("lrw(aes)");
1280 ret += tcrypt_test("xts(aes)");
1281 ret += tcrypt_test("ctr(aes)");
1282 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 break;
1284
1285 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001286 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001290 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 break;
1292
1293 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001294 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 break;
1296
1297 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001298 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001299 ret += tcrypt_test("cbc(cast5)");
1300 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 break;
1302
1303 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001304 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001305 ret += tcrypt_test("cbc(cast6)");
1306 ret += tcrypt_test("ctr(cast6)");
1307 ret += tcrypt_test("lrw(cast6)");
1308 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 break;
1310
1311 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001312 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 break;
1314
1315 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001316 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 break;
1318
1319 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001320 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 break;
1322
1323 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001324 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 break;
1326
1327 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001328 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 break;
1330
1331 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001332 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 break;
1334
1335 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001336 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 break;
1338
1339 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001340 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 break;
1342
1343 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001344 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 break;
1346
1347 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001348 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 break;
1350
1351 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001352 ret += tcrypt_test("ecb(anubis)");
1353 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 break;
1355
1356 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001357 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 break;
1359
1360 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001361 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 break;
1363
1364 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001365 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001367
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001368 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001369 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001370 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
David Howells90831632006-12-16 12:13:14 +11001372 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001373 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001374 break;
1375
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001376 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001377 ret += tcrypt_test("ecb(camellia)");
1378 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001379 ret += tcrypt_test("ctr(camellia)");
1380 ret += tcrypt_test("lrw(camellia)");
1381 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001382 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001383
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001384 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001385 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001386 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001387
Tan Swee Heng2407d602007-11-23 19:45:00 +08001388 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001389 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001390 break;
1391
Herbert Xu8df213d2007-12-02 14:55:47 +11001392 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001393 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001394 break;
1395
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001396 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001397 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001398 break;
1399
Joy Latten93cc74e2007-12-12 20:24:22 +08001400 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001401 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001402 break;
1403
Kevin Coffman76cb9522008-03-24 21:26:16 +08001404 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001405 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001406 break;
1407
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001408 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001409 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001410 break;
1411
1412 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001413 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001414 break;
1415
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001416 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001417 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001418 break;
1419
1420 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001421 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001422 break;
1423
1424 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001425 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001426 break;
1427
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001428 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001429 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001430 break;
1431
Jarod Wilson5d667322009-05-04 19:23:40 +08001432 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001433 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001434 break;
1435
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001436 case 46:
1437 ret += tcrypt_test("ghash");
1438 break;
1439
Herbert Xu684115212013-09-07 12:56:26 +10001440 case 47:
1441 ret += tcrypt_test("crct10dif");
1442 break;
1443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001445 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001449 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001453 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 break;
1455
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001456 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001457 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001458 break;
1459
1460 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001461 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001462 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001463
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001464 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001465 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001466 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001468 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001469 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001470 break;
1471
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001472 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001473 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001474 break;
1475
1476 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001477 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001478 break;
1479
Shane Wangf1939f72009-09-02 20:05:22 +10001480 case 109:
1481 ret += tcrypt_test("vmac(aes)");
1482 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001483
Sonic Zhanga482b082012-05-25 17:54:13 +08001484 case 110:
1485 ret += tcrypt_test("hmac(crc32)");
1486 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001487
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001488 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001489 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001490 break;
1491
Adrian Hoban69435b92010-11-04 15:02:04 -04001492 case 151:
1493 ret += tcrypt_test("rfc4106(gcm(aes))");
1494 break;
1495
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001496 case 152:
1497 ret += tcrypt_test("rfc4543(gcm(aes))");
1498 break;
1499
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001500 case 153:
1501 ret += tcrypt_test("cmac(aes)");
1502 break;
1503
1504 case 154:
1505 ret += tcrypt_test("cmac(des3_ede)");
1506 break;
1507
Horia Geantabbf9c892013-11-28 15:11:16 +02001508 case 155:
1509 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1510 break;
1511
Horia Geantabca4feb2014-03-14 17:46:51 +02001512 case 156:
1513 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1514 break;
1515
1516 case 157:
1517 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1518 break;
1519
Harald Welteebfd9bc2005-06-22 13:27:23 -07001520 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001521 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001522 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001523 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001524 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001525 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001526 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001527 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001528 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001529 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001530 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001531 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001532 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001533 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001534 speed_template_32_48_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001535 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001536 speed_template_32_48_64);
Jan Glauber9996e342011-04-26 16:34:01 +10001537 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);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001541 break;
1542
1543 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001544 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001545 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001546 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001547 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001548 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001549 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001550 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001551 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001552 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001553 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001554 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001555 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001556 break;
1557
1558 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001559 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001560 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001561 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001562 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001563 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001564 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001565 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001566 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001567 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1568 speed_template_16_24_32);
1569 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1570 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001571 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1572 speed_template_32_40_48);
1573 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1574 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001575 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1576 speed_template_32_48_64);
1577 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1578 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001579 break;
1580
1581 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001582 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001583 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001584 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001585 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001586 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001587 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001588 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001589 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001590 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1591 speed_template_8_32);
1592 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1593 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001594 break;
1595
1596 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001597 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001598 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001599 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001600 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001601 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001602 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001603 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001604 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001605 break;
1606
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001607 case 205:
1608 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001609 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001610 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001611 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001612 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001613 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001614 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001615 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001616 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1617 speed_template_16_24_32);
1618 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1619 speed_template_16_24_32);
1620 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1621 speed_template_32_40_48);
1622 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1623 speed_template_32_40_48);
1624 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1625 speed_template_32_48_64);
1626 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1627 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001628 break;
1629
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001630 case 206:
1631 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001632 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001633 break;
1634
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001635 case 207:
1636 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1637 speed_template_16_32);
1638 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1639 speed_template_16_32);
1640 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1641 speed_template_16_32);
1642 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1643 speed_template_16_32);
1644 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1645 speed_template_16_32);
1646 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1647 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001648 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1649 speed_template_32_48);
1650 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1651 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001652 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1653 speed_template_32_64);
1654 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1655 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001656 break;
1657
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001658 case 208:
1659 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1660 speed_template_8);
1661 break;
1662
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001663 case 209:
1664 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1665 speed_template_8_16);
1666 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1667 speed_template_8_16);
1668 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1669 speed_template_8_16);
1670 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1671 speed_template_8_16);
1672 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1673 speed_template_8_16);
1674 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1675 speed_template_8_16);
1676 break;
1677
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001678 case 210:
1679 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1680 speed_template_16_32);
1681 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1682 speed_template_16_32);
1683 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1684 speed_template_16_32);
1685 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1686 speed_template_16_32);
1687 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1688 speed_template_16_32);
1689 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1690 speed_template_16_32);
1691 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1692 speed_template_32_48);
1693 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1694 speed_template_32_48);
1695 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1696 speed_template_32_64);
1697 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1698 speed_template_32_64);
1699 break;
1700
Tim Chen53f52d72013-12-11 14:28:47 -08001701 case 211:
1702 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1703 NULL, 0, 16, 8, aead_speed_template_20);
1704 break;
1705
Michal Ludvige8057922006-05-30 22:04:19 +10001706 case 300:
1707 /* fall through */
1708
1709 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001710 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001711 if (mode > 300 && mode < 400) break;
1712
1713 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001714 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001715 if (mode > 300 && mode < 400) break;
1716
1717 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001718 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001719 if (mode > 300 && mode < 400) break;
1720
1721 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001722 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001723 if (mode > 300 && mode < 400) break;
1724
1725 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001726 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001727 if (mode > 300 && mode < 400) break;
1728
1729 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001730 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001731 if (mode > 300 && mode < 400) break;
1732
1733 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001734 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001735 if (mode > 300 && mode < 400) break;
1736
1737 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001738 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001739 if (mode > 300 && mode < 400) break;
1740
1741 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001742 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001743 if (mode > 300 && mode < 400) break;
1744
1745 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001746 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001747 if (mode > 300 && mode < 400) break;
1748
1749 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001750 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001751 if (mode > 300 && mode < 400) break;
1752
1753 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001754 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001755 if (mode > 300 && mode < 400) break;
1756
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001757 case 313:
1758 test_hash_speed("sha224", sec, generic_hash_speed_template);
1759 if (mode > 300 && mode < 400) break;
1760
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001761 case 314:
1762 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1763 if (mode > 300 && mode < 400) break;
1764
1765 case 315:
1766 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1767 if (mode > 300 && mode < 400) break;
1768
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001769 case 316:
1770 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1771 if (mode > 300 && mode < 400) break;
1772
1773 case 317:
1774 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1775 if (mode > 300 && mode < 400) break;
1776
Huang Ying18bcc912010-03-10 18:30:32 +08001777 case 318:
1778 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1779 if (mode > 300 && mode < 400) break;
1780
Tim Chene3899e42012-09-27 15:44:24 -07001781 case 319:
1782 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1783 if (mode > 300 && mode < 400) break;
1784
Herbert Xu684115212013-09-07 12:56:26 +10001785 case 320:
1786 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1787 if (mode > 300 && mode < 400) break;
1788
Michal Ludvige8057922006-05-30 22:04:19 +10001789 case 399:
1790 break;
1791
David S. Millerbeb63da72010-05-19 14:11:21 +10001792 case 400:
1793 /* fall through */
1794
1795 case 401:
1796 test_ahash_speed("md4", sec, generic_hash_speed_template);
1797 if (mode > 400 && mode < 500) break;
1798
1799 case 402:
1800 test_ahash_speed("md5", sec, generic_hash_speed_template);
1801 if (mode > 400 && mode < 500) break;
1802
1803 case 403:
1804 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1805 if (mode > 400 && mode < 500) break;
1806
1807 case 404:
1808 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1809 if (mode > 400 && mode < 500) break;
1810
1811 case 405:
1812 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1813 if (mode > 400 && mode < 500) break;
1814
1815 case 406:
1816 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1817 if (mode > 400 && mode < 500) break;
1818
1819 case 407:
1820 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1821 if (mode > 400 && mode < 500) break;
1822
1823 case 408:
1824 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1825 if (mode > 400 && mode < 500) break;
1826
1827 case 409:
1828 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1829 if (mode > 400 && mode < 500) break;
1830
1831 case 410:
1832 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1833 if (mode > 400 && mode < 500) break;
1834
1835 case 411:
1836 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1837 if (mode > 400 && mode < 500) break;
1838
1839 case 412:
1840 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1841 if (mode > 400 && mode < 500) break;
1842
1843 case 413:
1844 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1845 if (mode > 400 && mode < 500) break;
1846
1847 case 414:
1848 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1849 if (mode > 400 && mode < 500) break;
1850
1851 case 415:
1852 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1853 if (mode > 400 && mode < 500) break;
1854
1855 case 416:
1856 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1857 if (mode > 400 && mode < 500) break;
1858
1859 case 417:
1860 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1861 if (mode > 400 && mode < 500) break;
1862
1863 case 499:
1864 break;
1865
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001866 case 500:
1867 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1868 speed_template_16_24_32);
1869 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1870 speed_template_16_24_32);
1871 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1872 speed_template_16_24_32);
1873 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1874 speed_template_16_24_32);
1875 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1876 speed_template_32_40_48);
1877 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1878 speed_template_32_40_48);
1879 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1880 speed_template_32_48_64);
1881 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1882 speed_template_32_48_64);
1883 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1884 speed_template_16_24_32);
1885 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1886 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02001887 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1888 speed_template_16_24_32);
1889 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1890 speed_template_16_24_32);
1891 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1892 speed_template_16_24_32);
1893 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1894 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02001895 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1896 speed_template_20_28_36);
1897 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1898 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001899 break;
1900
1901 case 501:
1902 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1903 des3_speed_template, DES3_SPEED_VECTORS,
1904 speed_template_24);
1905 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1906 des3_speed_template, DES3_SPEED_VECTORS,
1907 speed_template_24);
1908 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1909 des3_speed_template, DES3_SPEED_VECTORS,
1910 speed_template_24);
1911 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1912 des3_speed_template, DES3_SPEED_VECTORS,
1913 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02001914 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1915 des3_speed_template, DES3_SPEED_VECTORS,
1916 speed_template_24);
1917 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1918 des3_speed_template, DES3_SPEED_VECTORS,
1919 speed_template_24);
1920 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1921 des3_speed_template, DES3_SPEED_VECTORS,
1922 speed_template_24);
1923 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1924 des3_speed_template, DES3_SPEED_VECTORS,
1925 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001926 break;
1927
1928 case 502:
1929 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1930 speed_template_8);
1931 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1932 speed_template_8);
1933 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1934 speed_template_8);
1935 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1936 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02001937 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1938 speed_template_8);
1939 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1940 speed_template_8);
1941 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1942 speed_template_8);
1943 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1944 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001945 break;
1946
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001947 case 503:
1948 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1949 speed_template_16_32);
1950 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1951 speed_template_16_32);
1952 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1953 speed_template_16_32);
1954 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1955 speed_template_16_32);
1956 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1957 speed_template_16_32);
1958 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1959 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001960 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1961 speed_template_32_48);
1962 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1963 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001964 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1965 speed_template_32_64);
1966 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1967 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001968 break;
1969
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001970 case 504:
1971 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1972 speed_template_16_24_32);
1973 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1974 speed_template_16_24_32);
1975 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1976 speed_template_16_24_32);
1977 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1978 speed_template_16_24_32);
1979 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1980 speed_template_16_24_32);
1981 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1982 speed_template_16_24_32);
1983 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1984 speed_template_32_40_48);
1985 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1986 speed_template_32_40_48);
1987 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1988 speed_template_32_48_64);
1989 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1990 speed_template_32_48_64);
1991 break;
1992
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001993 case 505:
1994 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1995 speed_template_8);
1996 break;
1997
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001998 case 506:
1999 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2000 speed_template_8_16);
2001 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2002 speed_template_8_16);
2003 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2004 speed_template_8_16);
2005 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2006 speed_template_8_16);
2007 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2008 speed_template_8_16);
2009 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2010 speed_template_8_16);
2011 break;
2012
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002013 case 507:
2014 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2015 speed_template_16_32);
2016 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2017 speed_template_16_32);
2018 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2019 speed_template_16_32);
2020 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2021 speed_template_16_32);
2022 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2023 speed_template_16_32);
2024 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2025 speed_template_16_32);
2026 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2027 speed_template_32_48);
2028 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2029 speed_template_32_48);
2030 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2031 speed_template_32_64);
2032 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2033 speed_template_32_64);
2034 break;
2035
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002036 case 508:
2037 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2038 speed_template_16_32);
2039 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2040 speed_template_16_32);
2041 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2042 speed_template_16_32);
2043 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2044 speed_template_16_32);
2045 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2046 speed_template_16_32);
2047 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2048 speed_template_16_32);
2049 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2050 speed_template_32_48);
2051 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2052 speed_template_32_48);
2053 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2054 speed_template_32_64);
2055 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2056 speed_template_32_64);
2057 break;
2058
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002059 case 509:
2060 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2061 speed_template_8_32);
2062 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2063 speed_template_8_32);
2064 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2065 speed_template_8_32);
2066 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2067 speed_template_8_32);
2068 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2069 speed_template_8_32);
2070 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2071 speed_template_8_32);
2072 break;
2073
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 case 1000:
2075 test_available();
2076 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002078
2079 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
Herbert Xu7be380f2009-07-14 16:06:54 +08002082static int do_alg_test(const char *alg, u32 type, u32 mask)
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002083{
Herbert Xu7be380f2009-07-14 16:06:54 +08002084 return crypto_has_alg(alg, type, mask ?: CRYPTO_ALG_TYPE_MASK) ?
2085 0 : -ENOENT;
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002086}
2087
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002088static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002090 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002091 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002092
Herbert Xuf139cfa2008-07-31 12:23:53 +08002093 for (i = 0; i < TVMEMSIZE; i++) {
2094 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2095 if (!tvmem[i])
2096 goto err_free_tv;
2097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002099 if (alg)
Herbert Xu7be380f2009-07-14 16:06:54 +08002100 err = do_alg_test(alg, type, mask);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002101 else
2102 err = do_test(mode);
2103
Jarod Wilson4e033a62009-05-27 15:10:21 +10002104 if (err) {
2105 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2106 goto err_free_tv;
2107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
Jarod Wilson4e033a62009-05-27 15:10:21 +10002109 /* We intentionaly return -EAGAIN to prevent keeping the module,
2110 * unless we're running in fips mode. It does all its work from
2111 * init() and doesn't offer any runtime functionality, but in
2112 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002113 * => we don't need it in the memory, do we?
2114 * -- mludvig
2115 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002116 if (!fips_enabled)
2117 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002118
Herbert Xuf139cfa2008-07-31 12:23:53 +08002119err_free_tv:
2120 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2121 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002122
2123 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
2126/*
2127 * If an init function is provided, an exit function must also be provided
2128 * to allow module unload.
2129 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002130static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002132module_init(tcrypt_mod_init);
2133module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002135module_param(alg, charp, 0);
2136module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002137module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002139module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002140MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2141 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143MODULE_LICENSE("GPL");
2144MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2145MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");