blob: 1d864e988ea9f44b76db78c7f2395fecb1623089 [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/*
Luca Clementi263a8df2014-06-25 22:57:42 -070051 * return a string with the driver name
52 */
53#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
54
55/*
Harald Welteebfd9bc2005-06-22 13:27:23 -070056 * Used by test_cipher_speed()
57 */
Herbert Xu6a179442005-06-22 13:29:03 -070058static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070059
Steffen Klasserta873a5f2009-06-19 19:46:53 +080060static char *alg = NULL;
61static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080062static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080064static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66static char *check[] = {
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080067 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
68 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
69 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110070 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080071 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +080072 "lzo", "cts", "zlib", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
Herbert Xuf139cfa2008-07-31 12:23:53 +080075static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070076 struct scatterlist *sg, int blen, int secs)
Herbert Xu6a179442005-06-22 13:29:03 -070077{
Herbert Xu6a179442005-06-22 13:29:03 -070078 unsigned long start, end;
79 int bcount;
80 int ret;
81
Mark Rustad3e3dc252014-07-25 02:53:38 -070082 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Herbert Xu6a179442005-06-22 13:29:03 -070083 time_before(jiffies, end); bcount++) {
84 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +100085 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070086 else
Herbert Xucba83562006-08-13 08:26:09 +100087 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -070088
89 if (ret)
90 return ret;
91 }
92
93 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -070094 bcount, secs, (long)bcount * blen);
Herbert Xu6a179442005-06-22 13:29:03 -070095 return 0;
96}
97
Herbert Xuf139cfa2008-07-31 12:23:53 +080098static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
99 struct scatterlist *sg, int blen)
Herbert Xu6a179442005-06-22 13:29:03 -0700100{
Herbert Xu6a179442005-06-22 13:29:03 -0700101 unsigned long cycles = 0;
102 int ret = 0;
103 int i;
104
Herbert Xu6a179442005-06-22 13:29:03 -0700105 local_irq_disable();
106
107 /* Warm-up run. */
108 for (i = 0; i < 4; i++) {
109 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000110 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700111 else
Herbert Xucba83562006-08-13 08:26:09 +1000112 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700113
114 if (ret)
115 goto out;
116 }
117
118 /* The real thing. */
119 for (i = 0; i < 8; i++) {
120 cycles_t start, end;
121
122 start = get_cycles();
123 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000124 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700125 else
Herbert Xucba83562006-08-13 08:26:09 +1000126 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700127 end = get_cycles();
128
129 if (ret)
130 goto out;
131
132 cycles += end - start;
133 }
134
135out:
136 local_irq_enable();
Herbert Xu6a179442005-06-22 13:29:03 -0700137
138 if (ret == 0)
139 printk("1 operation in %lu cycles (%d bytes)\n",
140 (cycles + 4) / 8, blen);
141
142 return ret;
143}
144
Tim Chen53f52d72013-12-11 14:28:47 -0800145static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700146 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -0800147{
148 unsigned long start, end;
149 int bcount;
150 int ret;
151
Mark Rustad3e3dc252014-07-25 02:53:38 -0700152 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -0800153 time_before(jiffies, end); bcount++) {
154 if (enc)
155 ret = crypto_aead_encrypt(req);
156 else
157 ret = crypto_aead_decrypt(req);
158
159 if (ret)
160 return ret;
161 }
162
163 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700164 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800165 return 0;
166}
167
168static int test_aead_cycles(struct aead_request *req, int enc, int blen)
169{
170 unsigned long cycles = 0;
171 int ret = 0;
172 int i;
173
174 local_irq_disable();
175
176 /* Warm-up run. */
177 for (i = 0; i < 4; i++) {
178 if (enc)
179 ret = crypto_aead_encrypt(req);
180 else
181 ret = crypto_aead_decrypt(req);
182
183 if (ret)
184 goto out;
185 }
186
187 /* The real thing. */
188 for (i = 0; i < 8; i++) {
189 cycles_t start, end;
190
191 start = get_cycles();
192 if (enc)
193 ret = crypto_aead_encrypt(req);
194 else
195 ret = crypto_aead_decrypt(req);
196 end = get_cycles();
197
198 if (ret)
199 goto out;
200
201 cycles += end - start;
202 }
203
204out:
205 local_irq_enable();
206
207 if (ret == 0)
208 printk("1 operation in %lu cycles (%d bytes)\n",
209 (cycles + 4) / 8, blen);
210
211 return ret;
212}
213
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800214static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800215static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
216
217#define XBUFSIZE 8
218#define MAX_IVLEN 32
219
220static int testmgr_alloc_buf(char *buf[XBUFSIZE])
221{
222 int i;
223
224 for (i = 0; i < XBUFSIZE; i++) {
225 buf[i] = (void *)__get_free_page(GFP_KERNEL);
226 if (!buf[i])
227 goto err_free_buf;
228 }
229
230 return 0;
231
232err_free_buf:
233 while (i-- > 0)
234 free_page((unsigned long)buf[i]);
235
236 return -ENOMEM;
237}
238
239static void testmgr_free_buf(char *buf[XBUFSIZE])
240{
241 int i;
242
243 for (i = 0; i < XBUFSIZE; i++)
244 free_page((unsigned long)buf[i]);
245}
246
247static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
248 unsigned int buflen)
249{
250 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
251 int k, rem;
252
253 np = (np > XBUFSIZE) ? XBUFSIZE : np;
254 rem = buflen % PAGE_SIZE;
255 if (np > XBUFSIZE) {
256 rem = PAGE_SIZE;
257 np = XBUFSIZE;
258 }
259 sg_init_table(sg, np);
260 for (k = 0; k < np; ++k) {
261 if (k == (np-1))
262 sg_set_buf(&sg[k], xbuf[k], rem);
263 else
264 sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE);
265 }
266}
267
Mark Rustad3e3dc252014-07-25 02:53:38 -0700268static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800269 struct aead_speed_template *template,
270 unsigned int tcount, u8 authsize,
271 unsigned int aad_size, u8 *keysize)
272{
273 unsigned int i, j;
274 struct crypto_aead *tfm;
275 int ret = -ENOMEM;
276 const char *key;
277 struct aead_request *req;
278 struct scatterlist *sg;
279 struct scatterlist *asg;
280 struct scatterlist *sgout;
281 const char *e;
282 void *assoc;
283 char iv[MAX_IVLEN];
284 char *xbuf[XBUFSIZE];
285 char *xoutbuf[XBUFSIZE];
286 char *axbuf[XBUFSIZE];
287 unsigned int *b_size;
288 unsigned int iv_len;
289
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200290 if (aad_size >= PAGE_SIZE) {
291 pr_err("associate data length (%u) too big\n", aad_size);
292 return;
293 }
294
Tim Chen53f52d72013-12-11 14:28:47 -0800295 if (enc == ENCRYPT)
296 e = "encryption";
297 else
298 e = "decryption";
299
300 if (testmgr_alloc_buf(xbuf))
301 goto out_noxbuf;
302 if (testmgr_alloc_buf(axbuf))
303 goto out_noaxbuf;
304 if (testmgr_alloc_buf(xoutbuf))
305 goto out_nooutbuf;
306
307 sg = kmalloc(sizeof(*sg) * 8 * 3, GFP_KERNEL);
308 if (!sg)
309 goto out_nosg;
310 asg = &sg[8];
311 sgout = &asg[8];
312
Tim Chen53f52d72013-12-11 14:28:47 -0800313 tfm = crypto_alloc_aead(algo, 0, 0);
314
315 if (IS_ERR(tfm)) {
316 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
317 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200318 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800319 }
320
Luca Clementi263a8df2014-06-25 22:57:42 -0700321 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
322 get_driver_name(crypto_aead, tfm), e);
323
Tim Chen53f52d72013-12-11 14:28:47 -0800324 req = aead_request_alloc(tfm, GFP_KERNEL);
325 if (!req) {
326 pr_err("alg: aead: Failed to allocate request for %s\n",
327 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200328 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800329 }
330
331 i = 0;
332 do {
333 b_size = aead_sizes;
334 do {
335 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200336 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800337 sg_init_one(&asg[0], assoc, aad_size);
338
339 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
340 pr_err("template (%u) too big for tvmem (%lu)\n",
341 *keysize + *b_size,
342 TVMEMSIZE * PAGE_SIZE);
343 goto out;
344 }
345
346 key = tvmem[0];
347 for (j = 0; j < tcount; j++) {
348 if (template[j].klen == *keysize) {
349 key = template[j].key;
350 break;
351 }
352 }
353 ret = crypto_aead_setkey(tfm, key, *keysize);
354 ret = crypto_aead_setauthsize(tfm, authsize);
355
356 iv_len = crypto_aead_ivsize(tfm);
357 if (iv_len)
358 memset(&iv, 0xff, iv_len);
359
360 crypto_aead_clear_flags(tfm, ~0);
361 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
362 i, *keysize * 8, *b_size);
363
364
365 memset(tvmem[0], 0xff, PAGE_SIZE);
366
367 if (ret) {
368 pr_err("setkey() failed flags=%x\n",
369 crypto_aead_get_flags(tfm));
370 goto out;
371 }
372
373 sg_init_aead(&sg[0], xbuf,
374 *b_size + (enc ? authsize : 0));
375
376 sg_init_aead(&sgout[0], xoutbuf,
377 *b_size + (enc ? authsize : 0));
378
379 aead_request_set_crypt(req, sg, sgout, *b_size, iv);
380 aead_request_set_assoc(req, asg, aad_size);
381
Mark Rustad3e3dc252014-07-25 02:53:38 -0700382 if (secs)
383 ret = test_aead_jiffies(req, enc, *b_size,
384 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800385 else
386 ret = test_aead_cycles(req, enc, *b_size);
387
388 if (ret) {
389 pr_err("%s() failed return code=%d\n", e, ret);
390 break;
391 }
392 b_size++;
393 i++;
394 } while (*b_size);
395 keysize++;
396 } while (*keysize);
397
398out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200399 aead_request_free(req);
400out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800401 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200402out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800403 kfree(sg);
404out_nosg:
405 testmgr_free_buf(xoutbuf);
406out_nooutbuf:
407 testmgr_free_buf(axbuf);
408out_noaxbuf:
409 testmgr_free_buf(xbuf);
410out_noxbuf:
411 return;
412}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800413
Mark Rustad3e3dc252014-07-25 02:53:38 -0700414static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
Herbert Xuda7f0332008-07-31 17:08:25 +0800415 struct cipher_speed_template *template,
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800416 unsigned int tcount, u8 *keysize)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700417{
Herbert Xudce907c2005-06-22 13:27:51 -0700418 unsigned int ret, i, j, iv_len;
David Sterbaf07ef1d2011-03-04 15:28:52 +0800419 const char *key;
420 char iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000421 struct crypto_blkcipher *tfm;
422 struct blkcipher_desc desc;
423 const char *e;
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800424 u32 *b_size;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700425
426 if (enc == ENCRYPT)
427 e = "encryption";
428 else
429 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700430
Herbert Xucba83562006-08-13 08:26:09 +1000431 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700432
Herbert Xucba83562006-08-13 08:26:09 +1000433 if (IS_ERR(tfm)) {
434 printk("failed to load transform for %s: %ld\n", algo,
435 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700436 return;
437 }
Herbert Xucba83562006-08-13 08:26:09 +1000438 desc.tfm = tfm;
439 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700440
Luca Clementi263a8df2014-06-25 22:57:42 -0700441 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
442 get_driver_name(crypto_blkcipher, tfm), e);
443
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800444 i = 0;
445 do {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700446
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800447 b_size = block_sizes;
448 do {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800449 struct scatterlist sg[TVMEMSIZE];
Harald Welteebfd9bc2005-06-22 13:27:23 -0700450
Herbert Xuf139cfa2008-07-31 12:23:53 +0800451 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
452 printk("template (%u) too big for "
453 "tvmem (%lu)\n", *keysize + *b_size,
454 TVMEMSIZE * PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800455 goto out;
456 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700457
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800458 printk("test %u (%d bit key, %d byte blocks): ", i,
459 *keysize * 8, *b_size);
460
Herbert Xuf139cfa2008-07-31 12:23:53 +0800461 memset(tvmem[0], 0xff, PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800462
463 /* set key, plain text and IV */
Herbert Xuda7f0332008-07-31 17:08:25 +0800464 key = tvmem[0];
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800465 for (j = 0; j < tcount; j++) {
466 if (template[j].klen == *keysize) {
467 key = template[j].key;
468 break;
469 }
470 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800471
472 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
473 if (ret) {
474 printk("setkey() failed flags=%x\n",
475 crypto_blkcipher_get_flags(tfm));
476 goto out;
477 }
478
Herbert Xuf139cfa2008-07-31 12:23:53 +0800479 sg_init_table(sg, TVMEMSIZE);
480 sg_set_buf(sg, tvmem[0] + *keysize,
481 PAGE_SIZE - *keysize);
482 for (j = 1; j < TVMEMSIZE; j++) {
483 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
484 memset (tvmem[j], 0xff, PAGE_SIZE);
485 }
486
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800487 iv_len = crypto_blkcipher_ivsize(tfm);
488 if (iv_len) {
489 memset(&iv, 0xff, iv_len);
490 crypto_blkcipher_set_iv(tfm, iv, iv_len);
491 }
492
Mark Rustad3e3dc252014-07-25 02:53:38 -0700493 if (secs)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800494 ret = test_cipher_jiffies(&desc, enc, sg,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700495 *b_size, secs);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800496 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800497 ret = test_cipher_cycles(&desc, enc, sg,
498 *b_size);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800499
500 if (ret) {
501 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xudce907c2005-06-22 13:27:51 -0700502 break;
503 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800504 b_size++;
505 i++;
506 } while (*b_size);
507 keysize++;
508 } while (*keysize);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700509
510out:
Herbert Xucba83562006-08-13 08:26:09 +1000511 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700512}
513
Herbert Xuf139cfa2008-07-31 12:23:53 +0800514static int test_hash_jiffies_digest(struct hash_desc *desc,
515 struct scatterlist *sg, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700516 char *out, int secs)
Michal Ludvige8057922006-05-30 22:04:19 +1000517{
Michal Ludvige8057922006-05-30 22:04:19 +1000518 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000519 int bcount;
520 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000521
Mark Rustad3e3dc252014-07-25 02:53:38 -0700522 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000523 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000524 ret = crypto_hash_digest(desc, sg, blen, out);
525 if (ret)
526 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000527 }
528
529 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700530 bcount / secs, ((long)bcount * blen) / secs);
Michal Ludvige8057922006-05-30 22:04:19 +1000531
Herbert Xue9d41162006-08-19 21:38:49 +1000532 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000533}
534
Herbert Xuf139cfa2008-07-31 12:23:53 +0800535static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700536 int blen, int plen, char *out, int secs)
Herbert Xue9d41162006-08-19 21:38:49 +1000537{
Herbert Xue9d41162006-08-19 21:38:49 +1000538 unsigned long start, end;
539 int bcount, pcount;
540 int ret;
541
542 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700543 return test_hash_jiffies_digest(desc, sg, blen, out, secs);
Herbert Xua5a613a2007-10-27 00:51:21 -0700544
Mark Rustad3e3dc252014-07-25 02:53:38 -0700545 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000546 time_before(jiffies, end); bcount++) {
547 ret = crypto_hash_init(desc);
548 if (ret)
549 return ret;
550 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000551 ret = crypto_hash_update(desc, sg, plen);
552 if (ret)
553 return ret;
554 }
555 /* we assume there is enough space in 'out' for the result */
556 ret = crypto_hash_final(desc, out);
557 if (ret)
558 return ret;
559 }
560
561 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700562 bcount / secs, ((long)bcount * blen) / secs);
Herbert Xue9d41162006-08-19 21:38:49 +1000563
564 return 0;
565}
566
Herbert Xuf139cfa2008-07-31 12:23:53 +0800567static int test_hash_cycles_digest(struct hash_desc *desc,
568 struct scatterlist *sg, int blen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000569{
Michal Ludvige8057922006-05-30 22:04:19 +1000570 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000571 int i;
572 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000573
Michal Ludvige8057922006-05-30 22:04:19 +1000574 local_irq_disable();
575
576 /* Warm-up run. */
577 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000578 ret = crypto_hash_digest(desc, sg, blen, out);
579 if (ret)
580 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000581 }
582
583 /* The real thing. */
584 for (i = 0; i < 8; i++) {
585 cycles_t start, end;
586
Michal Ludvige8057922006-05-30 22:04:19 +1000587 start = get_cycles();
588
Herbert Xue9d41162006-08-19 21:38:49 +1000589 ret = crypto_hash_digest(desc, sg, blen, out);
590 if (ret)
591 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000592
593 end = get_cycles();
594
595 cycles += end - start;
596 }
597
Herbert Xue9d41162006-08-19 21:38:49 +1000598out:
Michal Ludvige8057922006-05-30 22:04:19 +1000599 local_irq_enable();
Michal Ludvige8057922006-05-30 22:04:19 +1000600
Herbert Xue9d41162006-08-19 21:38:49 +1000601 if (ret)
602 return ret;
603
Michal Ludvige8057922006-05-30 22:04:19 +1000604 printk("%6lu cycles/operation, %4lu cycles/byte\n",
605 cycles / 8, cycles / (8 * blen));
606
Herbert Xue9d41162006-08-19 21:38:49 +1000607 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000608}
609
Herbert Xuf139cfa2008-07-31 12:23:53 +0800610static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
611 int blen, int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000612{
Herbert Xue9d41162006-08-19 21:38:49 +1000613 unsigned long cycles = 0;
614 int i, pcount;
615 int ret;
616
617 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800618 return test_hash_cycles_digest(desc, sg, blen, out);
Herbert Xua5a613a2007-10-27 00:51:21 -0700619
Herbert Xue9d41162006-08-19 21:38:49 +1000620 local_irq_disable();
621
622 /* Warm-up run. */
623 for (i = 0; i < 4; i++) {
624 ret = crypto_hash_init(desc);
625 if (ret)
626 goto out;
627 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000628 ret = crypto_hash_update(desc, sg, plen);
629 if (ret)
630 goto out;
631 }
Herbert Xu29059d12007-05-18 16:25:19 +1000632 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000633 if (ret)
634 goto out;
635 }
636
637 /* The real thing. */
638 for (i = 0; i < 8; i++) {
639 cycles_t start, end;
640
641 start = get_cycles();
642
643 ret = crypto_hash_init(desc);
644 if (ret)
645 goto out;
646 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000647 ret = crypto_hash_update(desc, sg, plen);
648 if (ret)
649 goto out;
650 }
651 ret = crypto_hash_final(desc, out);
652 if (ret)
653 goto out;
654
655 end = get_cycles();
656
657 cycles += end - start;
658 }
659
660out:
661 local_irq_enable();
Herbert Xue9d41162006-08-19 21:38:49 +1000662
663 if (ret)
664 return ret;
665
666 printk("%6lu cycles/operation, %4lu cycles/byte\n",
667 cycles / 8, cycles / (8 * blen));
668
669 return 0;
670}
671
David S. Millerbeb63da2010-05-19 14:11:21 +1000672static void test_hash_sg_init(struct scatterlist *sg)
673{
674 int i;
675
676 sg_init_table(sg, TVMEMSIZE);
677 for (i = 0; i < TVMEMSIZE; i++) {
678 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
679 memset(tvmem[i], 0xff, PAGE_SIZE);
680 }
681}
682
Mark Rustad3e3dc252014-07-25 02:53:38 -0700683static void test_hash_speed(const char *algo, unsigned int secs,
Herbert Xu01b32322008-07-31 15:41:55 +0800684 struct hash_speed *speed)
Herbert Xue9d41162006-08-19 21:38:49 +1000685{
Herbert Xuf139cfa2008-07-31 12:23:53 +0800686 struct scatterlist sg[TVMEMSIZE];
Herbert Xue9d41162006-08-19 21:38:49 +1000687 struct crypto_hash *tfm;
688 struct hash_desc desc;
Frank Seidel376bacb2009-03-29 15:18:39 +0800689 static char output[1024];
Michal Ludvige8057922006-05-30 22:04:19 +1000690 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000691 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000692
Herbert Xue9d41162006-08-19 21:38:49 +1000693 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000694
Herbert Xue9d41162006-08-19 21:38:49 +1000695 if (IS_ERR(tfm)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800696 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
Herbert Xue9d41162006-08-19 21:38:49 +1000697 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000698 return;
699 }
700
Luca Clementi263a8df2014-06-25 22:57:42 -0700701 printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
702 get_driver_name(crypto_hash, tfm));
703
Herbert Xue9d41162006-08-19 21:38:49 +1000704 desc.tfm = tfm;
705 desc.flags = 0;
706
707 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800708 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000709 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000710 goto out;
711 }
712
David S. Millerbeb63da2010-05-19 14:11:21 +1000713 test_hash_sg_init(sg);
Michal Ludvige8057922006-05-30 22:04:19 +1000714 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800715 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800716 printk(KERN_ERR
717 "template (%u) too big for tvmem (%lu)\n",
Herbert Xuf139cfa2008-07-31 12:23:53 +0800718 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
Michal Ludvige8057922006-05-30 22:04:19 +1000719 goto out;
720 }
721
Huang Ying18bcc912010-03-10 18:30:32 +0800722 if (speed[i].klen)
723 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
724
Frank Seidel376bacb2009-03-29 15:18:39 +0800725 printk(KERN_INFO "test%3u "
726 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Michal Ludvige8057922006-05-30 22:04:19 +1000727 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
728
Mark Rustad3e3dc252014-07-25 02:53:38 -0700729 if (secs)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800730 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700731 speed[i].plen, output, secs);
Michal Ludvige8057922006-05-30 22:04:19 +1000732 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800733 ret = test_hash_cycles(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000734 speed[i].plen, output);
735
736 if (ret) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800737 printk(KERN_ERR "hashing failed ret=%d\n", ret);
Herbert Xue9d41162006-08-19 21:38:49 +1000738 break;
739 }
Michal Ludvige8057922006-05-30 22:04:19 +1000740 }
741
742out:
Herbert Xue9d41162006-08-19 21:38:49 +1000743 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000744}
745
David S. Millerbeb63da2010-05-19 14:11:21 +1000746struct tcrypt_result {
747 struct completion completion;
748 int err;
749};
750
751static void tcrypt_complete(struct crypto_async_request *req, int err)
752{
753 struct tcrypt_result *res = req->data;
754
755 if (err == -EINPROGRESS)
756 return;
757
758 res->err = err;
759 complete(&res->completion);
760}
761
762static inline int do_one_ahash_op(struct ahash_request *req, int ret)
763{
764 if (ret == -EINPROGRESS || ret == -EBUSY) {
765 struct tcrypt_result *tr = req->base.data;
766
767 ret = wait_for_completion_interruptible(&tr->completion);
768 if (!ret)
769 ret = tr->err;
Wolfram Sang16735d02013-11-14 14:32:02 -0800770 reinit_completion(&tr->completion);
David S. Millerbeb63da2010-05-19 14:11:21 +1000771 }
772 return ret;
773}
774
775static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700776 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000777{
778 unsigned long start, end;
779 int bcount;
780 int ret;
781
Mark Rustad3e3dc252014-07-25 02:53:38 -0700782 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000783 time_before(jiffies, end); bcount++) {
784 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
785 if (ret)
786 return ret;
787 }
788
789 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700790 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000791
792 return 0;
793}
794
795static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700796 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000797{
798 unsigned long start, end;
799 int bcount, pcount;
800 int ret;
801
802 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700803 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000804
Mark Rustad3e3dc252014-07-25 02:53:38 -0700805 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000806 time_before(jiffies, end); bcount++) {
807 ret = crypto_ahash_init(req);
808 if (ret)
809 return ret;
810 for (pcount = 0; pcount < blen; pcount += plen) {
811 ret = do_one_ahash_op(req, crypto_ahash_update(req));
812 if (ret)
813 return ret;
814 }
815 /* we assume there is enough space in 'out' for the result */
816 ret = do_one_ahash_op(req, crypto_ahash_final(req));
817 if (ret)
818 return ret;
819 }
820
821 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700822 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000823
824 return 0;
825}
826
827static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
828 char *out)
829{
830 unsigned long cycles = 0;
831 int ret, i;
832
833 /* Warm-up run. */
834 for (i = 0; i < 4; i++) {
835 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
836 if (ret)
837 goto out;
838 }
839
840 /* The real thing. */
841 for (i = 0; i < 8; i++) {
842 cycles_t start, end;
843
844 start = get_cycles();
845
846 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
847 if (ret)
848 goto out;
849
850 end = get_cycles();
851
852 cycles += end - start;
853 }
854
855out:
856 if (ret)
857 return ret;
858
859 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
860 cycles / 8, cycles / (8 * blen));
861
862 return 0;
863}
864
865static int test_ahash_cycles(struct ahash_request *req, int blen,
866 int plen, char *out)
867{
868 unsigned long cycles = 0;
869 int i, pcount, ret;
870
871 if (plen == blen)
872 return test_ahash_cycles_digest(req, blen, out);
873
874 /* Warm-up run. */
875 for (i = 0; i < 4; i++) {
876 ret = crypto_ahash_init(req);
877 if (ret)
878 goto out;
879 for (pcount = 0; pcount < blen; pcount += plen) {
880 ret = do_one_ahash_op(req, crypto_ahash_update(req));
881 if (ret)
882 goto out;
883 }
884 ret = do_one_ahash_op(req, crypto_ahash_final(req));
885 if (ret)
886 goto out;
887 }
888
889 /* The real thing. */
890 for (i = 0; i < 8; i++) {
891 cycles_t start, end;
892
893 start = get_cycles();
894
895 ret = crypto_ahash_init(req);
896 if (ret)
897 goto out;
898 for (pcount = 0; pcount < blen; pcount += plen) {
899 ret = do_one_ahash_op(req, crypto_ahash_update(req));
900 if (ret)
901 goto out;
902 }
903 ret = do_one_ahash_op(req, crypto_ahash_final(req));
904 if (ret)
905 goto out;
906
907 end = get_cycles();
908
909 cycles += end - start;
910 }
911
912out:
913 if (ret)
914 return ret;
915
916 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
917 cycles / 8, cycles / (8 * blen));
918
919 return 0;
920}
921
Mark Rustad3e3dc252014-07-25 02:53:38 -0700922static void test_ahash_speed(const char *algo, unsigned int secs,
David S. Millerbeb63da2010-05-19 14:11:21 +1000923 struct hash_speed *speed)
924{
925 struct scatterlist sg[TVMEMSIZE];
926 struct tcrypt_result tresult;
927 struct ahash_request *req;
928 struct crypto_ahash *tfm;
929 static char output[1024];
930 int i, ret;
931
David S. Millerbeb63da2010-05-19 14:11:21 +1000932 tfm = crypto_alloc_ahash(algo, 0, 0);
933 if (IS_ERR(tfm)) {
934 pr_err("failed to load transform for %s: %ld\n",
935 algo, PTR_ERR(tfm));
936 return;
937 }
938
Luca Clementi263a8df2014-06-25 22:57:42 -0700939 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
940 get_driver_name(crypto_ahash, tfm));
941
David S. Millerbeb63da2010-05-19 14:11:21 +1000942 if (crypto_ahash_digestsize(tfm) > sizeof(output)) {
943 pr_err("digestsize(%u) > outputbuffer(%zu)\n",
944 crypto_ahash_digestsize(tfm), sizeof(output));
945 goto out;
946 }
947
948 test_hash_sg_init(sg);
949 req = ahash_request_alloc(tfm, GFP_KERNEL);
950 if (!req) {
951 pr_err("ahash request allocation failure\n");
952 goto out;
953 }
954
955 init_completion(&tresult.completion);
956 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
957 tcrypt_complete, &tresult);
958
959 for (i = 0; speed[i].blen != 0; i++) {
960 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
961 pr_err("template (%u) too big for tvmem (%lu)\n",
962 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
963 break;
964 }
965
966 pr_info("test%3u "
967 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
968 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
969
970 ahash_request_set_crypt(req, sg, output, speed[i].plen);
971
Mark Rustad3e3dc252014-07-25 02:53:38 -0700972 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000973 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700974 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000975 else
976 ret = test_ahash_cycles(req, speed[i].blen,
977 speed[i].plen, output);
978
979 if (ret) {
980 pr_err("hashing failed ret=%d\n", ret);
981 break;
982 }
983 }
984
985 ahash_request_free(req);
986
987out:
988 crypto_free_ahash(tfm);
989}
990
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300991static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
992{
993 if (ret == -EINPROGRESS || ret == -EBUSY) {
994 struct tcrypt_result *tr = req->base.data;
995
996 ret = wait_for_completion_interruptible(&tr->completion);
997 if (!ret)
998 ret = tr->err;
Wolfram Sang16735d02013-11-14 14:32:02 -0800999 reinit_completion(&tr->completion);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001000 }
1001
1002 return ret;
1003}
1004
1005static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001006 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001007{
1008 unsigned long start, end;
1009 int bcount;
1010 int ret;
1011
Mark Rustad3e3dc252014-07-25 02:53:38 -07001012 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001013 time_before(jiffies, end); bcount++) {
1014 if (enc)
1015 ret = do_one_acipher_op(req,
1016 crypto_ablkcipher_encrypt(req));
1017 else
1018 ret = do_one_acipher_op(req,
1019 crypto_ablkcipher_decrypt(req));
1020
1021 if (ret)
1022 return ret;
1023 }
1024
1025 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -07001026 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001027 return 0;
1028}
1029
1030static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
1031 int blen)
1032{
1033 unsigned long cycles = 0;
1034 int ret = 0;
1035 int i;
1036
1037 /* Warm-up run. */
1038 for (i = 0; i < 4; i++) {
1039 if (enc)
1040 ret = do_one_acipher_op(req,
1041 crypto_ablkcipher_encrypt(req));
1042 else
1043 ret = do_one_acipher_op(req,
1044 crypto_ablkcipher_decrypt(req));
1045
1046 if (ret)
1047 goto out;
1048 }
1049
1050 /* The real thing. */
1051 for (i = 0; i < 8; i++) {
1052 cycles_t start, end;
1053
1054 start = get_cycles();
1055 if (enc)
1056 ret = do_one_acipher_op(req,
1057 crypto_ablkcipher_encrypt(req));
1058 else
1059 ret = do_one_acipher_op(req,
1060 crypto_ablkcipher_decrypt(req));
1061 end = get_cycles();
1062
1063 if (ret)
1064 goto out;
1065
1066 cycles += end - start;
1067 }
1068
1069out:
1070 if (ret == 0)
1071 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1072 (cycles + 4) / 8, blen);
1073
1074 return ret;
1075}
1076
Mark Rustad3e3dc252014-07-25 02:53:38 -07001077static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001078 struct cipher_speed_template *template,
1079 unsigned int tcount, u8 *keysize)
1080{
Nicolas Royerde1975332012-07-01 19:19:47 +02001081 unsigned int ret, i, j, k, iv_len;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001082 struct tcrypt_result tresult;
1083 const char *key;
1084 char iv[128];
1085 struct ablkcipher_request *req;
1086 struct crypto_ablkcipher *tfm;
1087 const char *e;
1088 u32 *b_size;
1089
1090 if (enc == ENCRYPT)
1091 e = "encryption";
1092 else
1093 e = "decryption";
1094
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001095 init_completion(&tresult.completion);
1096
1097 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1098
1099 if (IS_ERR(tfm)) {
1100 pr_err("failed to load transform for %s: %ld\n", algo,
1101 PTR_ERR(tfm));
1102 return;
1103 }
1104
Luca Clementi263a8df2014-06-25 22:57:42 -07001105 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1106 get_driver_name(crypto_ablkcipher, tfm), e);
1107
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001108 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
1109 if (!req) {
1110 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1111 algo);
1112 goto out;
1113 }
1114
1115 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1116 tcrypt_complete, &tresult);
1117
1118 i = 0;
1119 do {
1120 b_size = block_sizes;
1121
1122 do {
1123 struct scatterlist sg[TVMEMSIZE];
1124
1125 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1126 pr_err("template (%u) too big for "
1127 "tvmem (%lu)\n", *keysize + *b_size,
1128 TVMEMSIZE * PAGE_SIZE);
1129 goto out_free_req;
1130 }
1131
1132 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1133 *keysize * 8, *b_size);
1134
1135 memset(tvmem[0], 0xff, PAGE_SIZE);
1136
1137 /* set key, plain text and IV */
1138 key = tvmem[0];
1139 for (j = 0; j < tcount; j++) {
1140 if (template[j].klen == *keysize) {
1141 key = template[j].key;
1142 break;
1143 }
1144 }
1145
1146 crypto_ablkcipher_clear_flags(tfm, ~0);
1147
1148 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
1149 if (ret) {
1150 pr_err("setkey() failed flags=%x\n",
1151 crypto_ablkcipher_get_flags(tfm));
1152 goto out_free_req;
1153 }
1154
1155 sg_init_table(sg, TVMEMSIZE);
Nicolas Royerde1975332012-07-01 19:19:47 +02001156
1157 k = *keysize + *b_size;
1158 if (k > PAGE_SIZE) {
1159 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001160 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +02001161 k -= PAGE_SIZE;
1162 j = 1;
1163 while (k > PAGE_SIZE) {
1164 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1165 memset(tvmem[j], 0xff, PAGE_SIZE);
1166 j++;
1167 k -= PAGE_SIZE;
1168 }
1169 sg_set_buf(sg + j, tvmem[j], k);
1170 memset(tvmem[j], 0xff, k);
1171 } else {
1172 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001173 }
1174
1175 iv_len = crypto_ablkcipher_ivsize(tfm);
1176 if (iv_len)
1177 memset(&iv, 0xff, iv_len);
1178
1179 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1180
Mark Rustad3e3dc252014-07-25 02:53:38 -07001181 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001182 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001183 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001184 else
1185 ret = test_acipher_cycles(req, enc,
1186 *b_size);
1187
1188 if (ret) {
1189 pr_err("%s() failed flags=%x\n", e,
1190 crypto_ablkcipher_get_flags(tfm));
1191 break;
1192 }
1193 b_size++;
1194 i++;
1195 } while (*b_size);
1196 keysize++;
1197 } while (*keysize);
1198
1199out_free_req:
1200 ablkcipher_request_free(req);
1201out:
1202 crypto_free_ablkcipher(tfm);
1203}
1204
Herbert Xuef2736f2005-06-22 13:26:03 -07001205static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
1207 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001208
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 while (*name) {
1210 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001211 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001212 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Herbert Xu01b32322008-07-31 15:41:55 +08001217static inline int tcrypt_test(const char *alg)
1218{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001219 int ret;
1220
1221 ret = alg_test(alg, alg, 0, 0);
1222 /* non-fips algs return -EINVAL in fips mode */
1223 if (fips_enabled && ret == -EINVAL)
1224 ret = 0;
1225 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001226}
1227
Herbert Xu86068132014-12-04 16:43:29 +08001228static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +08001229{
1230 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001231 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001232
1233 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001235 if (alg) {
1236 if (!crypto_has_alg(alg, type,
1237 mask ?: CRYPTO_ALG_TYPE_MASK))
1238 ret = -ENOENT;
1239 break;
1240 }
1241
Herbert Xu01b32322008-07-31 15:41:55 +08001242 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001243 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 break;
1245
1246 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001247 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 break;
1249
1250 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001251 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 break;
1253
1254 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001255 ret += tcrypt_test("ecb(des)");
1256 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001257 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 break;
1259
1260 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001261 ret += tcrypt_test("ecb(des3_ede)");
1262 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001263 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 break;
1265
1266 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001267 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001269
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001271 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001275 ret += tcrypt_test("ecb(blowfish)");
1276 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001277 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 break;
1279
1280 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001281 ret += tcrypt_test("ecb(twofish)");
1282 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001283 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001284 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001285 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001287
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001289 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001290 ret += tcrypt_test("cbc(serpent)");
1291 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001292 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001293 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 break;
1295
1296 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001297 ret += tcrypt_test("ecb(aes)");
1298 ret += tcrypt_test("cbc(aes)");
1299 ret += tcrypt_test("lrw(aes)");
1300 ret += tcrypt_test("xts(aes)");
1301 ret += tcrypt_test("ctr(aes)");
1302 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 break;
1304
1305 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001306 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001310 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 break;
1312
1313 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001314 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 break;
1316
1317 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001318 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001319 ret += tcrypt_test("cbc(cast5)");
1320 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 break;
1322
1323 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001324 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001325 ret += tcrypt_test("cbc(cast6)");
1326 ret += tcrypt_test("ctr(cast6)");
1327 ret += tcrypt_test("lrw(cast6)");
1328 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 break;
1330
1331 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001332 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 break;
1334
1335 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001336 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 break;
1338
1339 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001340 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 break;
1342
1343 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001344 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 break;
1346
1347 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001348 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 break;
1350
1351 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001352 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 break;
1354
1355 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001356 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 break;
1358
1359 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001360 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 break;
1362
1363 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001364 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 break;
1366
1367 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001368 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 break;
1370
1371 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001372 ret += tcrypt_test("ecb(anubis)");
1373 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 break;
1375
1376 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001377 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 break;
1379
1380 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001381 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 break;
1383
1384 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001385 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001387
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001388 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001389 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001390 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
David Howells90831632006-12-16 12:13:14 +11001392 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001393 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001394 break;
1395
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001396 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001397 ret += tcrypt_test("ecb(camellia)");
1398 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001399 ret += tcrypt_test("ctr(camellia)");
1400 ret += tcrypt_test("lrw(camellia)");
1401 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001402 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001403
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001404 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001405 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001406 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001407
Tan Swee Heng2407d602007-11-23 19:45:00 +08001408 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001409 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001410 break;
1411
Herbert Xu8df213d2007-12-02 14:55:47 +11001412 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001413 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001414 break;
1415
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001416 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001417 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001418 break;
1419
Joy Latten93cc74e2007-12-12 20:24:22 +08001420 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001421 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001422 break;
1423
Kevin Coffman76cb9522008-03-24 21:26:16 +08001424 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001425 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001426 break;
1427
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001428 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001429 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001430 break;
1431
1432 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001433 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001434 break;
1435
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001436 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001437 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001438 break;
1439
1440 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001441 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001442 break;
1443
1444 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001445 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001446 break;
1447
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001448 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001449 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001450 break;
1451
Jarod Wilson5d667322009-05-04 19:23:40 +08001452 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001453 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001454 break;
1455
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001456 case 46:
1457 ret += tcrypt_test("ghash");
1458 break;
1459
Herbert Xu684115212013-09-07 12:56:26 +10001460 case 47:
1461 ret += tcrypt_test("crct10dif");
1462 break;
1463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001465 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001469 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001471
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001473 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 break;
1475
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001476 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001477 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001478 break;
1479
1480 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001481 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001482 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001483
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001484 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001485 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001488 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001489 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001490 break;
1491
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001492 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001493 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001494 break;
1495
1496 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001497 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001498 break;
1499
Shane Wangf1939f72009-09-02 20:05:22 +10001500 case 109:
1501 ret += tcrypt_test("vmac(aes)");
1502 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001503
Sonic Zhanga482b082012-05-25 17:54:13 +08001504 case 110:
1505 ret += tcrypt_test("hmac(crc32)");
1506 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001507
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001508 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001509 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001510 break;
1511
Adrian Hoban69435b92010-11-04 15:02:04 -04001512 case 151:
1513 ret += tcrypt_test("rfc4106(gcm(aes))");
1514 break;
1515
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001516 case 152:
1517 ret += tcrypt_test("rfc4543(gcm(aes))");
1518 break;
1519
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001520 case 153:
1521 ret += tcrypt_test("cmac(aes)");
1522 break;
1523
1524 case 154:
1525 ret += tcrypt_test("cmac(des3_ede)");
1526 break;
1527
Horia Geantabbf9c892013-11-28 15:11:16 +02001528 case 155:
1529 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1530 break;
1531
Horia Geantabca4feb2014-03-14 17:46:51 +02001532 case 156:
1533 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1534 break;
1535
1536 case 157:
1537 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1538 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301539 case 181:
1540 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1541 break;
1542 case 182:
1543 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1544 break;
1545 case 183:
1546 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1547 break;
1548 case 184:
1549 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1550 break;
1551 case 185:
1552 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1553 break;
1554 case 186:
1555 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1556 break;
1557 case 187:
1558 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1559 break;
1560 case 188:
1561 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1562 break;
1563 case 189:
1564 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1565 break;
1566 case 190:
1567 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1568 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001569 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001570 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001571 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001572 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001573 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001574 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001575 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001576 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001577 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001578 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001579 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001580 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001581 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001582 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001583 speed_template_32_48_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001584 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001585 speed_template_32_48_64);
Jan Glauber9996e342011-04-26 16:34:01 +10001586 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1587 speed_template_16_24_32);
1588 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1589 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001590 break;
1591
1592 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001593 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001594 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001595 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001596 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001597 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001598 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001599 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001600 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001601 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001602 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001603 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001604 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001605 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1606 des3_speed_template, DES3_SPEED_VECTORS,
1607 speed_template_24);
1608 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1609 des3_speed_template, DES3_SPEED_VECTORS,
1610 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001611 break;
1612
1613 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001614 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001615 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001616 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001617 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001618 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001619 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001620 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001621 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001622 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1623 speed_template_16_24_32);
1624 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1625 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001626 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1627 speed_template_32_40_48);
1628 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1629 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001630 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1631 speed_template_32_48_64);
1632 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1633 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001634 break;
1635
1636 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001637 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001638 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001639 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001640 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001641 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001642 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001643 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001644 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001645 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1646 speed_template_8_32);
1647 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1648 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001649 break;
1650
1651 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001652 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001653 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001654 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001655 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001656 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001657 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001658 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001659 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001660 break;
1661
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001662 case 205:
1663 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001664 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001665 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001666 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001667 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001668 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001669 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001670 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001671 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1672 speed_template_16_24_32);
1673 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1674 speed_template_16_24_32);
1675 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1676 speed_template_32_40_48);
1677 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1678 speed_template_32_40_48);
1679 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1680 speed_template_32_48_64);
1681 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1682 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001683 break;
1684
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001685 case 206:
1686 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001687 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001688 break;
1689
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001690 case 207:
1691 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1692 speed_template_16_32);
1693 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1694 speed_template_16_32);
1695 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1696 speed_template_16_32);
1697 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1698 speed_template_16_32);
1699 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1700 speed_template_16_32);
1701 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1702 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001703 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1704 speed_template_32_48);
1705 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1706 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001707 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1708 speed_template_32_64);
1709 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1710 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001711 break;
1712
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001713 case 208:
1714 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1715 speed_template_8);
1716 break;
1717
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001718 case 209:
1719 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1720 speed_template_8_16);
1721 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1722 speed_template_8_16);
1723 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1724 speed_template_8_16);
1725 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1726 speed_template_8_16);
1727 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1728 speed_template_8_16);
1729 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1730 speed_template_8_16);
1731 break;
1732
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001733 case 210:
1734 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1735 speed_template_16_32);
1736 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1737 speed_template_16_32);
1738 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1739 speed_template_16_32);
1740 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1741 speed_template_16_32);
1742 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1743 speed_template_16_32);
1744 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1745 speed_template_16_32);
1746 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1747 speed_template_32_48);
1748 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1749 speed_template_32_48);
1750 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1751 speed_template_32_64);
1752 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1753 speed_template_32_64);
1754 break;
1755
Tim Chen53f52d72013-12-11 14:28:47 -08001756 case 211:
1757 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
1758 NULL, 0, 16, 8, aead_speed_template_20);
1759 break;
1760
Michal Ludvige8057922006-05-30 22:04:19 +10001761 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001762 if (alg) {
1763 test_hash_speed(alg, sec, generic_hash_speed_template);
1764 break;
1765 }
1766
Michal Ludvige8057922006-05-30 22:04:19 +10001767 /* fall through */
1768
1769 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001770 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001771 if (mode > 300 && mode < 400) break;
1772
1773 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001774 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001775 if (mode > 300 && mode < 400) break;
1776
1777 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001778 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001779 if (mode > 300 && mode < 400) break;
1780
1781 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001782 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001783 if (mode > 300 && mode < 400) break;
1784
1785 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001786 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001787 if (mode > 300 && mode < 400) break;
1788
1789 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001790 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001791 if (mode > 300 && mode < 400) break;
1792
1793 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001794 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001795 if (mode > 300 && mode < 400) break;
1796
1797 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001798 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001799 if (mode > 300 && mode < 400) break;
1800
1801 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001802 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001803 if (mode > 300 && mode < 400) break;
1804
1805 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001806 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001807 if (mode > 300 && mode < 400) break;
1808
1809 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001810 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001811 if (mode > 300 && mode < 400) break;
1812
1813 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001814 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001815 if (mode > 300 && mode < 400) break;
1816
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001817 case 313:
1818 test_hash_speed("sha224", sec, generic_hash_speed_template);
1819 if (mode > 300 && mode < 400) break;
1820
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001821 case 314:
1822 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1823 if (mode > 300 && mode < 400) break;
1824
1825 case 315:
1826 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1827 if (mode > 300 && mode < 400) break;
1828
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001829 case 316:
1830 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1831 if (mode > 300 && mode < 400) break;
1832
1833 case 317:
1834 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1835 if (mode > 300 && mode < 400) break;
1836
Huang Ying18bcc912010-03-10 18:30:32 +08001837 case 318:
1838 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1839 if (mode > 300 && mode < 400) break;
1840
Tim Chene3899e42012-09-27 15:44:24 -07001841 case 319:
1842 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1843 if (mode > 300 && mode < 400) break;
1844
Herbert Xu684115212013-09-07 12:56:26 +10001845 case 320:
1846 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1847 if (mode > 300 && mode < 400) break;
1848
Michal Ludvige8057922006-05-30 22:04:19 +10001849 case 399:
1850 break;
1851
David S. Millerbeb63da2010-05-19 14:11:21 +10001852 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08001853 if (alg) {
1854 test_ahash_speed(alg, sec, generic_hash_speed_template);
1855 break;
1856 }
1857
David S. Millerbeb63da2010-05-19 14:11:21 +10001858 /* fall through */
1859
1860 case 401:
1861 test_ahash_speed("md4", sec, generic_hash_speed_template);
1862 if (mode > 400 && mode < 500) break;
1863
1864 case 402:
1865 test_ahash_speed("md5", sec, generic_hash_speed_template);
1866 if (mode > 400 && mode < 500) break;
1867
1868 case 403:
1869 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1870 if (mode > 400 && mode < 500) break;
1871
1872 case 404:
1873 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1874 if (mode > 400 && mode < 500) break;
1875
1876 case 405:
1877 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1878 if (mode > 400 && mode < 500) break;
1879
1880 case 406:
1881 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1882 if (mode > 400 && mode < 500) break;
1883
1884 case 407:
1885 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1886 if (mode > 400 && mode < 500) break;
1887
1888 case 408:
1889 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1890 if (mode > 400 && mode < 500) break;
1891
1892 case 409:
1893 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1894 if (mode > 400 && mode < 500) break;
1895
1896 case 410:
1897 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1898 if (mode > 400 && mode < 500) break;
1899
1900 case 411:
1901 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1902 if (mode > 400 && mode < 500) break;
1903
1904 case 412:
1905 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1906 if (mode > 400 && mode < 500) break;
1907
1908 case 413:
1909 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1910 if (mode > 400 && mode < 500) break;
1911
1912 case 414:
1913 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1914 if (mode > 400 && mode < 500) break;
1915
1916 case 415:
1917 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1918 if (mode > 400 && mode < 500) break;
1919
1920 case 416:
1921 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1922 if (mode > 400 && mode < 500) break;
1923
1924 case 417:
1925 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1926 if (mode > 400 && mode < 500) break;
1927
1928 case 499:
1929 break;
1930
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001931 case 500:
1932 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1933 speed_template_16_24_32);
1934 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1935 speed_template_16_24_32);
1936 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1937 speed_template_16_24_32);
1938 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1939 speed_template_16_24_32);
1940 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1941 speed_template_32_40_48);
1942 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1943 speed_template_32_40_48);
1944 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1945 speed_template_32_48_64);
1946 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
1947 speed_template_32_48_64);
1948 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1949 speed_template_16_24_32);
1950 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1951 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02001952 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1953 speed_template_16_24_32);
1954 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1955 speed_template_16_24_32);
1956 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1957 speed_template_16_24_32);
1958 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1959 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02001960 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1961 speed_template_20_28_36);
1962 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1963 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001964 break;
1965
1966 case 501:
1967 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1968 des3_speed_template, DES3_SPEED_VECTORS,
1969 speed_template_24);
1970 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1971 des3_speed_template, DES3_SPEED_VECTORS,
1972 speed_template_24);
1973 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1974 des3_speed_template, DES3_SPEED_VECTORS,
1975 speed_template_24);
1976 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1977 des3_speed_template, DES3_SPEED_VECTORS,
1978 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02001979 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1980 des3_speed_template, DES3_SPEED_VECTORS,
1981 speed_template_24);
1982 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1983 des3_speed_template, DES3_SPEED_VECTORS,
1984 speed_template_24);
1985 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1986 des3_speed_template, DES3_SPEED_VECTORS,
1987 speed_template_24);
1988 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1989 des3_speed_template, DES3_SPEED_VECTORS,
1990 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001991 break;
1992
1993 case 502:
1994 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1995 speed_template_8);
1996 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1997 speed_template_8);
1998 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1999 speed_template_8);
2000 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2001 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02002002 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2003 speed_template_8);
2004 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2005 speed_template_8);
2006 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2007 speed_template_8);
2008 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2009 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002010 break;
2011
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002012 case 503:
2013 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2014 speed_template_16_32);
2015 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2016 speed_template_16_32);
2017 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2018 speed_template_16_32);
2019 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2020 speed_template_16_32);
2021 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2022 speed_template_16_32);
2023 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2024 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002025 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2026 speed_template_32_48);
2027 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2028 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002029 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2030 speed_template_32_64);
2031 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2032 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002033 break;
2034
Johannes Goetzfried107778b2012-05-28 15:54:24 +02002035 case 504:
2036 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2037 speed_template_16_24_32);
2038 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2039 speed_template_16_24_32);
2040 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2041 speed_template_16_24_32);
2042 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2043 speed_template_16_24_32);
2044 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2045 speed_template_16_24_32);
2046 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2047 speed_template_16_24_32);
2048 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2049 speed_template_32_40_48);
2050 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2051 speed_template_32_40_48);
2052 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2053 speed_template_32_48_64);
2054 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2055 speed_template_32_48_64);
2056 break;
2057
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002058 case 505:
2059 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2060 speed_template_8);
2061 break;
2062
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002063 case 506:
2064 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2065 speed_template_8_16);
2066 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2067 speed_template_8_16);
2068 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2069 speed_template_8_16);
2070 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2071 speed_template_8_16);
2072 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2073 speed_template_8_16);
2074 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2075 speed_template_8_16);
2076 break;
2077
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002078 case 507:
2079 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2080 speed_template_16_32);
2081 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2082 speed_template_16_32);
2083 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2084 speed_template_16_32);
2085 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2086 speed_template_16_32);
2087 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2088 speed_template_16_32);
2089 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2090 speed_template_16_32);
2091 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2092 speed_template_32_48);
2093 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2094 speed_template_32_48);
2095 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2096 speed_template_32_64);
2097 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2098 speed_template_32_64);
2099 break;
2100
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002101 case 508:
2102 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2103 speed_template_16_32);
2104 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2105 speed_template_16_32);
2106 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2107 speed_template_16_32);
2108 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2109 speed_template_16_32);
2110 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2111 speed_template_16_32);
2112 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2113 speed_template_16_32);
2114 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2115 speed_template_32_48);
2116 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2117 speed_template_32_48);
2118 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2119 speed_template_32_64);
2120 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2121 speed_template_32_64);
2122 break;
2123
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002124 case 509:
2125 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2126 speed_template_8_32);
2127 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2128 speed_template_8_32);
2129 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2130 speed_template_8_32);
2131 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2132 speed_template_8_32);
2133 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2134 speed_template_8_32);
2135 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2136 speed_template_8_32);
2137 break;
2138
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 case 1000:
2140 test_available();
2141 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002143
2144 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145}
2146
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002147static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002149 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002150 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002151
Herbert Xuf139cfa2008-07-31 12:23:53 +08002152 for (i = 0; i < TVMEMSIZE; i++) {
2153 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2154 if (!tvmem[i])
2155 goto err_free_tv;
2156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
Herbert Xu86068132014-12-04 16:43:29 +08002158 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002159
Jarod Wilson4e033a62009-05-27 15:10:21 +10002160 if (err) {
2161 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2162 goto err_free_tv;
2163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Jarod Wilson4e033a62009-05-27 15:10:21 +10002165 /* We intentionaly return -EAGAIN to prevent keeping the module,
2166 * unless we're running in fips mode. It does all its work from
2167 * init() and doesn't offer any runtime functionality, but in
2168 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002169 * => we don't need it in the memory, do we?
2170 * -- mludvig
2171 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002172 if (!fips_enabled)
2173 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002174
Herbert Xuf139cfa2008-07-31 12:23:53 +08002175err_free_tv:
2176 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2177 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002178
2179 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180}
2181
2182/*
2183 * If an init function is provided, an exit function must also be provided
2184 * to allow module unload.
2185 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002186static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002188module_init(tcrypt_mod_init);
2189module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002191module_param(alg, charp, 0);
2192module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002193module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002195module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002196MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2197 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
2199MODULE_LICENSE("GPL");
2200MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2201MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");