blob: 270bc4b82bd9aaf2625bbeddf426f0cfbfea0f7e [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 Xu1ce5a042015-04-22 15:06:30 +080025#include <crypto/aead.h>
Herbert Xu18e33e62008-07-10 16:01:22 +080026#include <crypto/hash.h>
Herbert Xucba83562006-08-13 08:26:09 +100027#include <linux/err.h>
Herbert Xudaf09442015-04-22 13:25:57 +080028#include <linux/fips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/module.h>
David Hardeman378f0582005-09-17 17:55:31 +100032#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070035#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070036#include <linux/timex.h>
37#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include "tcrypt.h"
39
40/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080041 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080043#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/*
Herbert Xuda7f0332008-07-31 17:08:25 +080046* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070047*/
48#define ENCRYPT 1
49#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Horia Geant?f074f7b2015-08-27 18:38:36 +030051#define MAX_DIGEST_SIZE 64
52
Harald Welteebfd9bc2005-06-22 13:27:23 -070053/*
Luca Clementi263a8df2014-06-25 22:57:42 -070054 * return a string with the driver name
55 */
56#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
57
58/*
Harald Welteebfd9bc2005-06-22 13:27:23 -070059 * Used by test_cipher_speed()
60 */
Herbert Xu6a179442005-06-22 13:29:03 -070061static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070062
Steffen Klasserta873a5f2009-06-19 19:46:53 +080063static char *alg = NULL;
64static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080065static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080067static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69static char *check[] = {
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080070 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256",
71 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110073 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080074 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +080075 "lzo", "cts", "zlib", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053078struct tcrypt_result {
79 struct completion completion;
80 int err;
81};
82
83static void tcrypt_complete(struct crypto_async_request *req, int err)
84{
85 struct tcrypt_result *res = req->data;
86
87 if (err == -EINPROGRESS)
88 return;
89
90 res->err = err;
91 complete(&res->completion);
92}
93
Herbert Xuf139cfa2008-07-31 12:23:53 +080094static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070095 struct scatterlist *sg, int blen, int secs)
Herbert Xu6a179442005-06-22 13:29:03 -070096{
Herbert Xu6a179442005-06-22 13:29:03 -070097 unsigned long start, end;
98 int bcount;
99 int ret;
100
Mark Rustad3e3dc252014-07-25 02:53:38 -0700101 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Herbert Xu6a179442005-06-22 13:29:03 -0700102 time_before(jiffies, end); bcount++) {
103 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000104 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700105 else
Herbert Xucba83562006-08-13 08:26:09 +1000106 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700107
108 if (ret)
109 return ret;
110 }
111
112 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700113 bcount, secs, (long)bcount * blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700114 return 0;
115}
116
Herbert Xuf139cfa2008-07-31 12:23:53 +0800117static int test_cipher_cycles(struct blkcipher_desc *desc, int enc,
118 struct scatterlist *sg, int blen)
Herbert Xu6a179442005-06-22 13:29:03 -0700119{
Herbert Xu6a179442005-06-22 13:29:03 -0700120 unsigned long cycles = 0;
121 int ret = 0;
122 int i;
123
Herbert Xu6a179442005-06-22 13:29:03 -0700124 local_irq_disable();
125
126 /* Warm-up run. */
127 for (i = 0; i < 4; i++) {
128 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000129 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700130 else
Herbert Xucba83562006-08-13 08:26:09 +1000131 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700132
133 if (ret)
134 goto out;
135 }
136
137 /* The real thing. */
138 for (i = 0; i < 8; i++) {
139 cycles_t start, end;
140
141 start = get_cycles();
142 if (enc)
Herbert Xucba83562006-08-13 08:26:09 +1000143 ret = crypto_blkcipher_encrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700144 else
Herbert Xucba83562006-08-13 08:26:09 +1000145 ret = crypto_blkcipher_decrypt(desc, sg, sg, blen);
Herbert Xu6a179442005-06-22 13:29:03 -0700146 end = get_cycles();
147
148 if (ret)
149 goto out;
150
151 cycles += end - start;
152 }
153
154out:
155 local_irq_enable();
Herbert Xu6a179442005-06-22 13:29:03 -0700156
157 if (ret == 0)
158 printk("1 operation in %lu cycles (%d bytes)\n",
159 (cycles + 4) / 8, blen);
160
161 return ret;
162}
163
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530164static inline int do_one_aead_op(struct aead_request *req, int ret)
165{
166 if (ret == -EINPROGRESS || ret == -EBUSY) {
167 struct tcrypt_result *tr = req->base.data;
168
169 ret = wait_for_completion_interruptible(&tr->completion);
170 if (!ret)
171 ret = tr->err;
172 reinit_completion(&tr->completion);
173 }
174
175 return ret;
176}
177
Tim Chen53f52d72013-12-11 14:28:47 -0800178static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700179 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -0800180{
181 unsigned long start, end;
182 int bcount;
183 int ret;
184
Mark Rustad3e3dc252014-07-25 02:53:38 -0700185 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -0800186 time_before(jiffies, end); bcount++) {
187 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530188 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800189 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530190 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800191
192 if (ret)
193 return ret;
194 }
195
196 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700197 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800198 return 0;
199}
200
201static int test_aead_cycles(struct aead_request *req, int enc, int blen)
202{
203 unsigned long cycles = 0;
204 int ret = 0;
205 int i;
206
207 local_irq_disable();
208
209 /* Warm-up run. */
210 for (i = 0; i < 4; i++) {
211 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530212 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800213 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530214 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800215
216 if (ret)
217 goto out;
218 }
219
220 /* The real thing. */
221 for (i = 0; i < 8; i++) {
222 cycles_t start, end;
223
224 start = get_cycles();
225 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530226 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800227 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530228 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800229 end = get_cycles();
230
231 if (ret)
232 goto out;
233
234 cycles += end - start;
235 }
236
237out:
238 local_irq_enable();
239
240 if (ret == 0)
241 printk("1 operation in %lu cycles (%d bytes)\n",
242 (cycles + 4) / 8, blen);
243
244 return ret;
245}
246
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800247static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800248static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
249
250#define XBUFSIZE 8
251#define MAX_IVLEN 32
252
253static int testmgr_alloc_buf(char *buf[XBUFSIZE])
254{
255 int i;
256
257 for (i = 0; i < XBUFSIZE; i++) {
258 buf[i] = (void *)__get_free_page(GFP_KERNEL);
259 if (!buf[i])
260 goto err_free_buf;
261 }
262
263 return 0;
264
265err_free_buf:
266 while (i-- > 0)
267 free_page((unsigned long)buf[i]);
268
269 return -ENOMEM;
270}
271
272static void testmgr_free_buf(char *buf[XBUFSIZE])
273{
274 int i;
275
276 for (i = 0; i < XBUFSIZE; i++)
277 free_page((unsigned long)buf[i]);
278}
279
280static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
281 unsigned int buflen)
282{
283 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
284 int k, rem;
285
Tim Chen53f52d72013-12-11 14:28:47 -0800286 if (np > XBUFSIZE) {
287 rem = PAGE_SIZE;
288 np = XBUFSIZE;
Cristian Stoicac4768992015-01-27 11:54:27 +0200289 } else {
290 rem = buflen % PAGE_SIZE;
Tim Chen53f52d72013-12-11 14:28:47 -0800291 }
Cristian Stoicac4768992015-01-27 11:54:27 +0200292
Herbert Xu31267272015-06-17 14:05:26 +0800293 sg_init_table(sg, np + 1);
Cristian Stoicac4768992015-01-27 11:54:27 +0200294 np--;
295 for (k = 0; k < np; k++)
Herbert Xu31267272015-06-17 14:05:26 +0800296 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
Cristian Stoicac4768992015-01-27 11:54:27 +0200297
Herbert Xu31267272015-06-17 14:05:26 +0800298 sg_set_buf(&sg[k + 1], xbuf[k], rem);
Tim Chen53f52d72013-12-11 14:28:47 -0800299}
300
Mark Rustad3e3dc252014-07-25 02:53:38 -0700301static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800302 struct aead_speed_template *template,
303 unsigned int tcount, u8 authsize,
304 unsigned int aad_size, u8 *keysize)
305{
306 unsigned int i, j;
307 struct crypto_aead *tfm;
308 int ret = -ENOMEM;
309 const char *key;
310 struct aead_request *req;
311 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800312 struct scatterlist *sgout;
313 const char *e;
314 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200315 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800316 char *xbuf[XBUFSIZE];
317 char *xoutbuf[XBUFSIZE];
318 char *axbuf[XBUFSIZE];
319 unsigned int *b_size;
320 unsigned int iv_len;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530321 struct tcrypt_result result;
Tim Chen53f52d72013-12-11 14:28:47 -0800322
Cristian Stoica96692a732015-01-28 13:07:32 +0200323 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
324 if (!iv)
325 return;
326
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200327 if (aad_size >= PAGE_SIZE) {
328 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200329 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200330 }
331
Tim Chen53f52d72013-12-11 14:28:47 -0800332 if (enc == ENCRYPT)
333 e = "encryption";
334 else
335 e = "decryption";
336
337 if (testmgr_alloc_buf(xbuf))
338 goto out_noxbuf;
339 if (testmgr_alloc_buf(axbuf))
340 goto out_noaxbuf;
341 if (testmgr_alloc_buf(xoutbuf))
342 goto out_nooutbuf;
343
Herbert Xua3f21852015-05-27 16:03:51 +0800344 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800345 if (!sg)
346 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800347 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800348
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800349 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800350
351 if (IS_ERR(tfm)) {
352 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
353 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200354 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800355 }
356
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530357 init_completion(&result.completion);
Luca Clementi263a8df2014-06-25 22:57:42 -0700358 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
359 get_driver_name(crypto_aead, tfm), e);
360
Tim Chen53f52d72013-12-11 14:28:47 -0800361 req = aead_request_alloc(tfm, GFP_KERNEL);
362 if (!req) {
363 pr_err("alg: aead: Failed to allocate request for %s\n",
364 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200365 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800366 }
367
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530368 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
369 tcrypt_complete, &result);
370
Tim Chen53f52d72013-12-11 14:28:47 -0800371 i = 0;
372 do {
373 b_size = aead_sizes;
374 do {
375 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200376 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800377
378 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
379 pr_err("template (%u) too big for tvmem (%lu)\n",
380 *keysize + *b_size,
381 TVMEMSIZE * PAGE_SIZE);
382 goto out;
383 }
384
385 key = tvmem[0];
386 for (j = 0; j < tcount; j++) {
387 if (template[j].klen == *keysize) {
388 key = template[j].key;
389 break;
390 }
391 }
392 ret = crypto_aead_setkey(tfm, key, *keysize);
393 ret = crypto_aead_setauthsize(tfm, authsize);
394
395 iv_len = crypto_aead_ivsize(tfm);
396 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200397 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800398
399 crypto_aead_clear_flags(tfm, ~0);
400 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
401 i, *keysize * 8, *b_size);
402
403
404 memset(tvmem[0], 0xff, PAGE_SIZE);
405
406 if (ret) {
407 pr_err("setkey() failed flags=%x\n",
408 crypto_aead_get_flags(tfm));
409 goto out;
410 }
411
Herbert Xu31267272015-06-17 14:05:26 +0800412 sg_init_aead(sg, xbuf,
Tim Chen53f52d72013-12-11 14:28:47 -0800413 *b_size + (enc ? authsize : 0));
414
Herbert Xu31267272015-06-17 14:05:26 +0800415 sg_init_aead(sgout, xoutbuf,
Tim Chen53f52d72013-12-11 14:28:47 -0800416 *b_size + (enc ? authsize : 0));
417
Herbert Xu31267272015-06-17 14:05:26 +0800418 sg_set_buf(&sg[0], assoc, aad_size);
419 sg_set_buf(&sgout[0], assoc, aad_size);
420
Tim Chen53f52d72013-12-11 14:28:47 -0800421 aead_request_set_crypt(req, sg, sgout, *b_size, iv);
Herbert Xua3f21852015-05-27 16:03:51 +0800422 aead_request_set_ad(req, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800423
Mark Rustad3e3dc252014-07-25 02:53:38 -0700424 if (secs)
425 ret = test_aead_jiffies(req, enc, *b_size,
426 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800427 else
428 ret = test_aead_cycles(req, enc, *b_size);
429
430 if (ret) {
431 pr_err("%s() failed return code=%d\n", e, ret);
432 break;
433 }
434 b_size++;
435 i++;
436 } while (*b_size);
437 keysize++;
438 } while (*keysize);
439
440out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200441 aead_request_free(req);
442out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800443 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200444out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800445 kfree(sg);
446out_nosg:
447 testmgr_free_buf(xoutbuf);
448out_nooutbuf:
449 testmgr_free_buf(axbuf);
450out_noaxbuf:
451 testmgr_free_buf(xbuf);
452out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200453 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800454 return;
455}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800456
Mark Rustad3e3dc252014-07-25 02:53:38 -0700457static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
Herbert Xuda7f0332008-07-31 17:08:25 +0800458 struct cipher_speed_template *template,
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800459 unsigned int tcount, u8 *keysize)
Harald Welteebfd9bc2005-06-22 13:27:23 -0700460{
Herbert Xudce907c2005-06-22 13:27:51 -0700461 unsigned int ret, i, j, iv_len;
David Sterbaf07ef1d2011-03-04 15:28:52 +0800462 const char *key;
463 char iv[128];
Herbert Xucba83562006-08-13 08:26:09 +1000464 struct crypto_blkcipher *tfm;
465 struct blkcipher_desc desc;
466 const char *e;
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800467 u32 *b_size;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700468
469 if (enc == ENCRYPT)
470 e = "encryption";
471 else
472 e = "decryption";
Harald Welteebfd9bc2005-06-22 13:27:23 -0700473
Herbert Xucba83562006-08-13 08:26:09 +1000474 tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700475
Herbert Xucba83562006-08-13 08:26:09 +1000476 if (IS_ERR(tfm)) {
477 printk("failed to load transform for %s: %ld\n", algo,
478 PTR_ERR(tfm));
Harald Welteebfd9bc2005-06-22 13:27:23 -0700479 return;
480 }
Herbert Xucba83562006-08-13 08:26:09 +1000481 desc.tfm = tfm;
482 desc.flags = 0;
Harald Welteebfd9bc2005-06-22 13:27:23 -0700483
Luca Clementi263a8df2014-06-25 22:57:42 -0700484 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
485 get_driver_name(crypto_blkcipher, tfm), e);
486
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800487 i = 0;
488 do {
Harald Welteebfd9bc2005-06-22 13:27:23 -0700489
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800490 b_size = block_sizes;
491 do {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800492 struct scatterlist sg[TVMEMSIZE];
Harald Welteebfd9bc2005-06-22 13:27:23 -0700493
Herbert Xuf139cfa2008-07-31 12:23:53 +0800494 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
495 printk("template (%u) too big for "
496 "tvmem (%lu)\n", *keysize + *b_size,
497 TVMEMSIZE * PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800498 goto out;
499 }
Harald Welteebfd9bc2005-06-22 13:27:23 -0700500
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800501 printk("test %u (%d bit key, %d byte blocks): ", i,
502 *keysize * 8, *b_size);
503
Herbert Xuf139cfa2008-07-31 12:23:53 +0800504 memset(tvmem[0], 0xff, PAGE_SIZE);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800505
506 /* set key, plain text and IV */
Herbert Xuda7f0332008-07-31 17:08:25 +0800507 key = tvmem[0];
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800508 for (j = 0; j < tcount; j++) {
509 if (template[j].klen == *keysize) {
510 key = template[j].key;
511 break;
512 }
513 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800514
515 ret = crypto_blkcipher_setkey(tfm, key, *keysize);
516 if (ret) {
517 printk("setkey() failed flags=%x\n",
518 crypto_blkcipher_get_flags(tfm));
519 goto out;
520 }
521
Herbert Xuf139cfa2008-07-31 12:23:53 +0800522 sg_init_table(sg, TVMEMSIZE);
523 sg_set_buf(sg, tvmem[0] + *keysize,
524 PAGE_SIZE - *keysize);
525 for (j = 1; j < TVMEMSIZE; j++) {
526 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
527 memset (tvmem[j], 0xff, PAGE_SIZE);
528 }
529
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800530 iv_len = crypto_blkcipher_ivsize(tfm);
531 if (iv_len) {
532 memset(&iv, 0xff, iv_len);
533 crypto_blkcipher_set_iv(tfm, iv, iv_len);
534 }
535
Mark Rustad3e3dc252014-07-25 02:53:38 -0700536 if (secs)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800537 ret = test_cipher_jiffies(&desc, enc, sg,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700538 *b_size, secs);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800539 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800540 ret = test_cipher_cycles(&desc, enc, sg,
541 *b_size);
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800542
543 if (ret) {
544 printk("%s() failed flags=%x\n", e, desc.flags);
Herbert Xudce907c2005-06-22 13:27:51 -0700545 break;
546 }
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800547 b_size++;
548 i++;
549 } while (*b_size);
550 keysize++;
551 } while (*keysize);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700552
553out:
Herbert Xucba83562006-08-13 08:26:09 +1000554 crypto_free_blkcipher(tfm);
Harald Welteebfd9bc2005-06-22 13:27:23 -0700555}
556
Herbert Xuf139cfa2008-07-31 12:23:53 +0800557static int test_hash_jiffies_digest(struct hash_desc *desc,
558 struct scatterlist *sg, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700559 char *out, int secs)
Michal Ludvige8057922006-05-30 22:04:19 +1000560{
Michal Ludvige8057922006-05-30 22:04:19 +1000561 unsigned long start, end;
Herbert Xue9d41162006-08-19 21:38:49 +1000562 int bcount;
563 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000564
Mark Rustad3e3dc252014-07-25 02:53:38 -0700565 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000566 time_before(jiffies, end); bcount++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000567 ret = crypto_hash_digest(desc, sg, blen, out);
568 if (ret)
569 return ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000570 }
571
572 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700573 bcount / secs, ((long)bcount * blen) / secs);
Michal Ludvige8057922006-05-30 22:04:19 +1000574
Herbert Xue9d41162006-08-19 21:38:49 +1000575 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000576}
577
Herbert Xuf139cfa2008-07-31 12:23:53 +0800578static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700579 int blen, int plen, char *out, int secs)
Herbert Xue9d41162006-08-19 21:38:49 +1000580{
Herbert Xue9d41162006-08-19 21:38:49 +1000581 unsigned long start, end;
582 int bcount, pcount;
583 int ret;
584
585 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700586 return test_hash_jiffies_digest(desc, sg, blen, out, secs);
Herbert Xua5a613a2007-10-27 00:51:21 -0700587
Mark Rustad3e3dc252014-07-25 02:53:38 -0700588 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000589 time_before(jiffies, end); bcount++) {
590 ret = crypto_hash_init(desc);
591 if (ret)
592 return ret;
593 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000594 ret = crypto_hash_update(desc, sg, plen);
595 if (ret)
596 return ret;
597 }
598 /* we assume there is enough space in 'out' for the result */
599 ret = crypto_hash_final(desc, out);
600 if (ret)
601 return ret;
602 }
603
604 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700605 bcount / secs, ((long)bcount * blen) / secs);
Herbert Xue9d41162006-08-19 21:38:49 +1000606
607 return 0;
608}
609
Herbert Xuf139cfa2008-07-31 12:23:53 +0800610static int test_hash_cycles_digest(struct hash_desc *desc,
611 struct scatterlist *sg, int blen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000612{
Michal Ludvige8057922006-05-30 22:04:19 +1000613 unsigned long cycles = 0;
Herbert Xue9d41162006-08-19 21:38:49 +1000614 int i;
615 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000616
Michal Ludvige8057922006-05-30 22:04:19 +1000617 local_irq_disable();
618
619 /* Warm-up run. */
620 for (i = 0; i < 4; i++) {
Herbert Xue9d41162006-08-19 21:38:49 +1000621 ret = crypto_hash_digest(desc, sg, blen, out);
622 if (ret)
623 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000624 }
625
626 /* The real thing. */
627 for (i = 0; i < 8; i++) {
628 cycles_t start, end;
629
Michal Ludvige8057922006-05-30 22:04:19 +1000630 start = get_cycles();
631
Herbert Xue9d41162006-08-19 21:38:49 +1000632 ret = crypto_hash_digest(desc, sg, blen, out);
633 if (ret)
634 goto out;
Michal Ludvige8057922006-05-30 22:04:19 +1000635
636 end = get_cycles();
637
638 cycles += end - start;
639 }
640
Herbert Xue9d41162006-08-19 21:38:49 +1000641out:
Michal Ludvige8057922006-05-30 22:04:19 +1000642 local_irq_enable();
Michal Ludvige8057922006-05-30 22:04:19 +1000643
Herbert Xue9d41162006-08-19 21:38:49 +1000644 if (ret)
645 return ret;
646
Michal Ludvige8057922006-05-30 22:04:19 +1000647 printk("%6lu cycles/operation, %4lu cycles/byte\n",
648 cycles / 8, cycles / (8 * blen));
649
Herbert Xue9d41162006-08-19 21:38:49 +1000650 return 0;
Michal Ludvige8057922006-05-30 22:04:19 +1000651}
652
Herbert Xuf139cfa2008-07-31 12:23:53 +0800653static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg,
654 int blen, int plen, char *out)
Michal Ludvige8057922006-05-30 22:04:19 +1000655{
Herbert Xue9d41162006-08-19 21:38:49 +1000656 unsigned long cycles = 0;
657 int i, pcount;
658 int ret;
659
660 if (plen == blen)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800661 return test_hash_cycles_digest(desc, sg, blen, out);
Herbert Xua5a613a2007-10-27 00:51:21 -0700662
Herbert Xue9d41162006-08-19 21:38:49 +1000663 local_irq_disable();
664
665 /* Warm-up run. */
666 for (i = 0; i < 4; i++) {
667 ret = crypto_hash_init(desc);
668 if (ret)
669 goto out;
670 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000671 ret = crypto_hash_update(desc, sg, plen);
672 if (ret)
673 goto out;
674 }
Herbert Xu29059d12007-05-18 16:25:19 +1000675 ret = crypto_hash_final(desc, out);
Herbert Xue9d41162006-08-19 21:38:49 +1000676 if (ret)
677 goto out;
678 }
679
680 /* The real thing. */
681 for (i = 0; i < 8; i++) {
682 cycles_t start, end;
683
684 start = get_cycles();
685
686 ret = crypto_hash_init(desc);
687 if (ret)
688 goto out;
689 for (pcount = 0; pcount < blen; pcount += plen) {
Herbert Xue9d41162006-08-19 21:38:49 +1000690 ret = crypto_hash_update(desc, sg, plen);
691 if (ret)
692 goto out;
693 }
694 ret = crypto_hash_final(desc, out);
695 if (ret)
696 goto out;
697
698 end = get_cycles();
699
700 cycles += end - start;
701 }
702
703out:
704 local_irq_enable();
Herbert Xue9d41162006-08-19 21:38:49 +1000705
706 if (ret)
707 return ret;
708
709 printk("%6lu cycles/operation, %4lu cycles/byte\n",
710 cycles / 8, cycles / (8 * blen));
711
712 return 0;
713}
714
David S. Millerbeb63da2010-05-19 14:11:21 +1000715static void test_hash_sg_init(struct scatterlist *sg)
716{
717 int i;
718
719 sg_init_table(sg, TVMEMSIZE);
720 for (i = 0; i < TVMEMSIZE; i++) {
721 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
722 memset(tvmem[i], 0xff, PAGE_SIZE);
723 }
724}
725
Mark Rustad3e3dc252014-07-25 02:53:38 -0700726static void test_hash_speed(const char *algo, unsigned int secs,
Herbert Xu01b32322008-07-31 15:41:55 +0800727 struct hash_speed *speed)
Herbert Xue9d41162006-08-19 21:38:49 +1000728{
Herbert Xuf139cfa2008-07-31 12:23:53 +0800729 struct scatterlist sg[TVMEMSIZE];
Herbert Xue9d41162006-08-19 21:38:49 +1000730 struct crypto_hash *tfm;
731 struct hash_desc desc;
Frank Seidel376bacb2009-03-29 15:18:39 +0800732 static char output[1024];
Michal Ludvige8057922006-05-30 22:04:19 +1000733 int i;
Herbert Xue9d41162006-08-19 21:38:49 +1000734 int ret;
Michal Ludvige8057922006-05-30 22:04:19 +1000735
Herbert Xue9d41162006-08-19 21:38:49 +1000736 tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC);
Michal Ludvige8057922006-05-30 22:04:19 +1000737
Herbert Xue9d41162006-08-19 21:38:49 +1000738 if (IS_ERR(tfm)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800739 printk(KERN_ERR "failed to load transform for %s: %ld\n", algo,
Herbert Xue9d41162006-08-19 21:38:49 +1000740 PTR_ERR(tfm));
Michal Ludvige8057922006-05-30 22:04:19 +1000741 return;
742 }
743
Luca Clementi263a8df2014-06-25 22:57:42 -0700744 printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo,
745 get_driver_name(crypto_hash, tfm));
746
Herbert Xue9d41162006-08-19 21:38:49 +1000747 desc.tfm = tfm;
748 desc.flags = 0;
749
750 if (crypto_hash_digestsize(tfm) > sizeof(output)) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800751 printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n",
Herbert Xue9d41162006-08-19 21:38:49 +1000752 crypto_hash_digestsize(tfm), sizeof(output));
Michal Ludvige8057922006-05-30 22:04:19 +1000753 goto out;
754 }
755
David S. Millerbeb63da2010-05-19 14:11:21 +1000756 test_hash_sg_init(sg);
Michal Ludvige8057922006-05-30 22:04:19 +1000757 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xuf139cfa2008-07-31 12:23:53 +0800758 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800759 printk(KERN_ERR
760 "template (%u) too big for tvmem (%lu)\n",
Herbert Xuf139cfa2008-07-31 12:23:53 +0800761 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
Michal Ludvige8057922006-05-30 22:04:19 +1000762 goto out;
763 }
764
Huang Ying18bcc912010-03-10 18:30:32 +0800765 if (speed[i].klen)
766 crypto_hash_setkey(tfm, tvmem[0], speed[i].klen);
767
Frank Seidel376bacb2009-03-29 15:18:39 +0800768 printk(KERN_INFO "test%3u "
769 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Michal Ludvige8057922006-05-30 22:04:19 +1000770 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
771
Mark Rustad3e3dc252014-07-25 02:53:38 -0700772 if (secs)
Herbert Xuf139cfa2008-07-31 12:23:53 +0800773 ret = test_hash_jiffies(&desc, sg, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700774 speed[i].plen, output, secs);
Michal Ludvige8057922006-05-30 22:04:19 +1000775 else
Herbert Xuf139cfa2008-07-31 12:23:53 +0800776 ret = test_hash_cycles(&desc, sg, speed[i].blen,
Herbert Xue9d41162006-08-19 21:38:49 +1000777 speed[i].plen, output);
778
779 if (ret) {
Frank Seidel376bacb2009-03-29 15:18:39 +0800780 printk(KERN_ERR "hashing failed ret=%d\n", ret);
Herbert Xue9d41162006-08-19 21:38:49 +1000781 break;
782 }
Michal Ludvige8057922006-05-30 22:04:19 +1000783 }
784
785out:
Herbert Xue9d41162006-08-19 21:38:49 +1000786 crypto_free_hash(tfm);
Michal Ludvige8057922006-05-30 22:04:19 +1000787}
788
David S. Millerbeb63da2010-05-19 14:11:21 +1000789static inline int do_one_ahash_op(struct ahash_request *req, int ret)
790{
791 if (ret == -EINPROGRESS || ret == -EBUSY) {
792 struct tcrypt_result *tr = req->base.data;
793
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100794 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -0800795 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +0100796 ret = tr->err;
David S. Millerbeb63da2010-05-19 14:11:21 +1000797 }
798 return ret;
799}
800
801static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700802 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000803{
804 unsigned long start, end;
805 int bcount;
806 int ret;
807
Mark Rustad3e3dc252014-07-25 02:53:38 -0700808 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000809 time_before(jiffies, end); bcount++) {
810 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
811 if (ret)
812 return ret;
813 }
814
815 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700816 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000817
818 return 0;
819}
820
821static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700822 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000823{
824 unsigned long start, end;
825 int bcount, pcount;
826 int ret;
827
828 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700829 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000830
Mark Rustad3e3dc252014-07-25 02:53:38 -0700831 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000832 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800833 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000834 if (ret)
835 return ret;
836 for (pcount = 0; pcount < blen; pcount += plen) {
837 ret = do_one_ahash_op(req, crypto_ahash_update(req));
838 if (ret)
839 return ret;
840 }
841 /* we assume there is enough space in 'out' for the result */
842 ret = do_one_ahash_op(req, crypto_ahash_final(req));
843 if (ret)
844 return ret;
845 }
846
847 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700848 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000849
850 return 0;
851}
852
853static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
854 char *out)
855{
856 unsigned long cycles = 0;
857 int ret, i;
858
859 /* Warm-up run. */
860 for (i = 0; i < 4; i++) {
861 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
862 if (ret)
863 goto out;
864 }
865
866 /* The real thing. */
867 for (i = 0; i < 8; i++) {
868 cycles_t start, end;
869
870 start = get_cycles();
871
872 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
873 if (ret)
874 goto out;
875
876 end = get_cycles();
877
878 cycles += end - start;
879 }
880
881out:
882 if (ret)
883 return ret;
884
885 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
886 cycles / 8, cycles / (8 * blen));
887
888 return 0;
889}
890
891static int test_ahash_cycles(struct ahash_request *req, int blen,
892 int plen, char *out)
893{
894 unsigned long cycles = 0;
895 int i, pcount, ret;
896
897 if (plen == blen)
898 return test_ahash_cycles_digest(req, blen, out);
899
900 /* Warm-up run. */
901 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800902 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000903 if (ret)
904 goto out;
905 for (pcount = 0; pcount < blen; pcount += plen) {
906 ret = do_one_ahash_op(req, crypto_ahash_update(req));
907 if (ret)
908 goto out;
909 }
910 ret = do_one_ahash_op(req, crypto_ahash_final(req));
911 if (ret)
912 goto out;
913 }
914
915 /* The real thing. */
916 for (i = 0; i < 8; i++) {
917 cycles_t start, end;
918
919 start = get_cycles();
920
Herbert Xu43a96072015-04-22 11:02:27 +0800921 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000922 if (ret)
923 goto out;
924 for (pcount = 0; pcount < blen; pcount += plen) {
925 ret = do_one_ahash_op(req, crypto_ahash_update(req));
926 if (ret)
927 goto out;
928 }
929 ret = do_one_ahash_op(req, crypto_ahash_final(req));
930 if (ret)
931 goto out;
932
933 end = get_cycles();
934
935 cycles += end - start;
936 }
937
938out:
939 if (ret)
940 return ret;
941
942 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
943 cycles / 8, cycles / (8 * blen));
944
945 return 0;
946}
947
Mark Rustad3e3dc252014-07-25 02:53:38 -0700948static void test_ahash_speed(const char *algo, unsigned int secs,
David S. Millerbeb63da2010-05-19 14:11:21 +1000949 struct hash_speed *speed)
950{
951 struct scatterlist sg[TVMEMSIZE];
952 struct tcrypt_result tresult;
953 struct ahash_request *req;
954 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +0300955 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +1000956 int i, ret;
957
David S. Millerbeb63da2010-05-19 14:11:21 +1000958 tfm = crypto_alloc_ahash(algo, 0, 0);
959 if (IS_ERR(tfm)) {
960 pr_err("failed to load transform for %s: %ld\n",
961 algo, PTR_ERR(tfm));
962 return;
963 }
964
Luca Clementi263a8df2014-06-25 22:57:42 -0700965 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
966 get_driver_name(crypto_ahash, tfm));
967
Horia Geant?f074f7b2015-08-27 18:38:36 +0300968 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
969 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
970 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +1000971 goto out;
972 }
973
974 test_hash_sg_init(sg);
975 req = ahash_request_alloc(tfm, GFP_KERNEL);
976 if (!req) {
977 pr_err("ahash request allocation failure\n");
978 goto out;
979 }
980
981 init_completion(&tresult.completion);
982 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
983 tcrypt_complete, &tresult);
984
Horia Geant?f074f7b2015-08-27 18:38:36 +0300985 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
986 if (!output)
987 goto out_nomem;
988
David S. Millerbeb63da2010-05-19 14:11:21 +1000989 for (i = 0; speed[i].blen != 0; i++) {
990 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
991 pr_err("template (%u) too big for tvmem (%lu)\n",
992 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
993 break;
994 }
995
996 pr_info("test%3u "
997 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
998 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
999
1000 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1001
Mark Rustad3e3dc252014-07-25 02:53:38 -07001002 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +10001003 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001004 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +10001005 else
1006 ret = test_ahash_cycles(req, speed[i].blen,
1007 speed[i].plen, output);
1008
1009 if (ret) {
1010 pr_err("hashing failed ret=%d\n", ret);
1011 break;
1012 }
1013 }
1014
Horia Geant?f074f7b2015-08-27 18:38:36 +03001015 kfree(output);
1016
1017out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +10001018 ahash_request_free(req);
1019
1020out:
1021 crypto_free_ahash(tfm);
1022}
1023
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001024static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret)
1025{
1026 if (ret == -EINPROGRESS || ret == -EBUSY) {
1027 struct tcrypt_result *tr = req->base.data;
1028
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001029 wait_for_completion(&tr->completion);
Wolfram Sang16735d02013-11-14 14:32:02 -08001030 reinit_completion(&tr->completion);
Rabin Vincent8a45ac12015-01-09 16:25:28 +01001031 ret = tr->err;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001032 }
1033
1034 return ret;
1035}
1036
1037static int test_acipher_jiffies(struct ablkcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001038 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001039{
1040 unsigned long start, end;
1041 int bcount;
1042 int ret;
1043
Mark Rustad3e3dc252014-07-25 02:53:38 -07001044 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001045 time_before(jiffies, end); bcount++) {
1046 if (enc)
1047 ret = do_one_acipher_op(req,
1048 crypto_ablkcipher_encrypt(req));
1049 else
1050 ret = do_one_acipher_op(req,
1051 crypto_ablkcipher_decrypt(req));
1052
1053 if (ret)
1054 return ret;
1055 }
1056
1057 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -07001058 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001059 return 0;
1060}
1061
1062static int test_acipher_cycles(struct ablkcipher_request *req, int enc,
1063 int blen)
1064{
1065 unsigned long cycles = 0;
1066 int ret = 0;
1067 int i;
1068
1069 /* Warm-up run. */
1070 for (i = 0; i < 4; i++) {
1071 if (enc)
1072 ret = do_one_acipher_op(req,
1073 crypto_ablkcipher_encrypt(req));
1074 else
1075 ret = do_one_acipher_op(req,
1076 crypto_ablkcipher_decrypt(req));
1077
1078 if (ret)
1079 goto out;
1080 }
1081
1082 /* The real thing. */
1083 for (i = 0; i < 8; i++) {
1084 cycles_t start, end;
1085
1086 start = get_cycles();
1087 if (enc)
1088 ret = do_one_acipher_op(req,
1089 crypto_ablkcipher_encrypt(req));
1090 else
1091 ret = do_one_acipher_op(req,
1092 crypto_ablkcipher_decrypt(req));
1093 end = get_cycles();
1094
1095 if (ret)
1096 goto out;
1097
1098 cycles += end - start;
1099 }
1100
1101out:
1102 if (ret == 0)
1103 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1104 (cycles + 4) / 8, blen);
1105
1106 return ret;
1107}
1108
Mark Rustad3e3dc252014-07-25 02:53:38 -07001109static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001110 struct cipher_speed_template *template,
1111 unsigned int tcount, u8 *keysize)
1112{
Nicolas Royerde1975332012-07-01 19:19:47 +02001113 unsigned int ret, i, j, k, iv_len;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001114 struct tcrypt_result tresult;
1115 const char *key;
1116 char iv[128];
1117 struct ablkcipher_request *req;
1118 struct crypto_ablkcipher *tfm;
1119 const char *e;
1120 u32 *b_size;
1121
1122 if (enc == ENCRYPT)
1123 e = "encryption";
1124 else
1125 e = "decryption";
1126
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001127 init_completion(&tresult.completion);
1128
1129 tfm = crypto_alloc_ablkcipher(algo, 0, 0);
1130
1131 if (IS_ERR(tfm)) {
1132 pr_err("failed to load transform for %s: %ld\n", algo,
1133 PTR_ERR(tfm));
1134 return;
1135 }
1136
Luca Clementi263a8df2014-06-25 22:57:42 -07001137 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
1138 get_driver_name(crypto_ablkcipher, tfm), e);
1139
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001140 req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
1141 if (!req) {
1142 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1143 algo);
1144 goto out;
1145 }
1146
1147 ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
1148 tcrypt_complete, &tresult);
1149
1150 i = 0;
1151 do {
1152 b_size = block_sizes;
1153
1154 do {
1155 struct scatterlist sg[TVMEMSIZE];
1156
1157 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1158 pr_err("template (%u) too big for "
1159 "tvmem (%lu)\n", *keysize + *b_size,
1160 TVMEMSIZE * PAGE_SIZE);
1161 goto out_free_req;
1162 }
1163
1164 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1165 *keysize * 8, *b_size);
1166
1167 memset(tvmem[0], 0xff, PAGE_SIZE);
1168
1169 /* set key, plain text and IV */
1170 key = tvmem[0];
1171 for (j = 0; j < tcount; j++) {
1172 if (template[j].klen == *keysize) {
1173 key = template[j].key;
1174 break;
1175 }
1176 }
1177
1178 crypto_ablkcipher_clear_flags(tfm, ~0);
1179
1180 ret = crypto_ablkcipher_setkey(tfm, key, *keysize);
1181 if (ret) {
1182 pr_err("setkey() failed flags=%x\n",
1183 crypto_ablkcipher_get_flags(tfm));
1184 goto out_free_req;
1185 }
1186
Nicolas Royerde1975332012-07-01 19:19:47 +02001187 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +02001188 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1189
Nicolas Royerde1975332012-07-01 19:19:47 +02001190 if (k > PAGE_SIZE) {
1191 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001192 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +02001193 k -= PAGE_SIZE;
1194 j = 1;
1195 while (k > PAGE_SIZE) {
1196 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1197 memset(tvmem[j], 0xff, PAGE_SIZE);
1198 j++;
1199 k -= PAGE_SIZE;
1200 }
1201 sg_set_buf(sg + j, tvmem[j], k);
1202 memset(tvmem[j], 0xff, k);
1203 } else {
1204 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001205 }
1206
1207 iv_len = crypto_ablkcipher_ivsize(tfm);
1208 if (iv_len)
1209 memset(&iv, 0xff, iv_len);
1210
1211 ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv);
1212
Mark Rustad3e3dc252014-07-25 02:53:38 -07001213 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001214 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001215 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001216 else
1217 ret = test_acipher_cycles(req, enc,
1218 *b_size);
1219
1220 if (ret) {
1221 pr_err("%s() failed flags=%x\n", e,
1222 crypto_ablkcipher_get_flags(tfm));
1223 break;
1224 }
1225 b_size++;
1226 i++;
1227 } while (*b_size);
1228 keysize++;
1229 } while (*keysize);
1230
1231out_free_req:
1232 ablkcipher_request_free(req);
1233out:
1234 crypto_free_ablkcipher(tfm);
1235}
1236
Herbert Xuef2736f2005-06-22 13:26:03 -07001237static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238{
1239 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 while (*name) {
1242 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001243 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001244 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247}
1248
Herbert Xu01b32322008-07-31 15:41:55 +08001249static inline int tcrypt_test(const char *alg)
1250{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001251 int ret;
1252
1253 ret = alg_test(alg, alg, 0, 0);
1254 /* non-fips algs return -EINVAL in fips mode */
1255 if (fips_enabled && ret == -EINVAL)
1256 ret = 0;
1257 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001258}
1259
Herbert Xu86068132014-12-04 16:43:29 +08001260static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +08001261{
1262 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001263 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001264
1265 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001267 if (alg) {
1268 if (!crypto_has_alg(alg, type,
1269 mask ?: CRYPTO_ALG_TYPE_MASK))
1270 ret = -ENOENT;
1271 break;
1272 }
1273
Herbert Xu01b32322008-07-31 15:41:55 +08001274 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001275 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 break;
1277
1278 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001279 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 break;
1281
1282 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001283 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 break;
1285
1286 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001287 ret += tcrypt_test("ecb(des)");
1288 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001289 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 break;
1291
1292 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001293 ret += tcrypt_test("ecb(des3_ede)");
1294 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001295 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 break;
1297
1298 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001299 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001301
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001303 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001307 ret += tcrypt_test("ecb(blowfish)");
1308 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001309 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 break;
1311
1312 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001313 ret += tcrypt_test("ecb(twofish)");
1314 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001315 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001316 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001317 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001321 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001322 ret += tcrypt_test("cbc(serpent)");
1323 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001324 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001325 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 break;
1327
1328 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001329 ret += tcrypt_test("ecb(aes)");
1330 ret += tcrypt_test("cbc(aes)");
1331 ret += tcrypt_test("lrw(aes)");
1332 ret += tcrypt_test("xts(aes)");
1333 ret += tcrypt_test("ctr(aes)");
1334 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 break;
1336
1337 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001338 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001342 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 break;
1344
1345 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001346 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 break;
1348
1349 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001350 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001351 ret += tcrypt_test("cbc(cast5)");
1352 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 break;
1354
1355 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001356 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001357 ret += tcrypt_test("cbc(cast6)");
1358 ret += tcrypt_test("ctr(cast6)");
1359 ret += tcrypt_test("lrw(cast6)");
1360 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 break;
1362
1363 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001364 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 break;
1366
1367 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001368 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 break;
1370
1371 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001372 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 break;
1374
1375 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001376 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 break;
1378
1379 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001380 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 break;
1382
1383 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001384 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 break;
1386
1387 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001388 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 break;
1390
1391 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001392 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 break;
1394
1395 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001396 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 break;
1398
1399 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001400 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 break;
1402
1403 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001404 ret += tcrypt_test("ecb(anubis)");
1405 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 break;
1407
1408 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001409 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 break;
1411
1412 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001413 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 break;
1415
1416 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001417 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001419
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001420 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001421 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001422 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
David Howells90831632006-12-16 12:13:14 +11001424 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001425 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001426 break;
1427
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001428 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001429 ret += tcrypt_test("ecb(camellia)");
1430 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001431 ret += tcrypt_test("ctr(camellia)");
1432 ret += tcrypt_test("lrw(camellia)");
1433 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001434 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001435
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001436 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001437 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001438 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001439
Tan Swee Heng2407d602007-11-23 19:45:00 +08001440 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001441 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001442 break;
1443
Herbert Xu8df213d2007-12-02 14:55:47 +11001444 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001445 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001446 break;
1447
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001448 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001449 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001450 break;
1451
Joy Latten93cc74e2007-12-12 20:24:22 +08001452 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001453 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001454 break;
1455
Kevin Coffman76cb9522008-03-24 21:26:16 +08001456 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001457 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001458 break;
1459
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001460 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001461 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001462 break;
1463
1464 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001465 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001466 break;
1467
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001468 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001469 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001470 break;
1471
1472 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001473 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001474 break;
1475
1476 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001477 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001478 break;
1479
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001480 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001481 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001482 break;
1483
Jarod Wilson5d667322009-05-04 19:23:40 +08001484 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001485 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001486 break;
1487
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001488 case 46:
1489 ret += tcrypt_test("ghash");
1490 break;
1491
Herbert Xu684115212013-09-07 12:56:26 +10001492 case 47:
1493 ret += tcrypt_test("crct10dif");
1494 break;
1495
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001497 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001501 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001505 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 break;
1507
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001508 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001509 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001510 break;
1511
1512 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001513 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001514 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001515
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001516 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001517 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001518 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001520 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001521 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001522 break;
1523
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001524 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001525 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001526 break;
1527
1528 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001529 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001530 break;
1531
Shane Wangf1939f72009-09-02 20:05:22 +10001532 case 109:
1533 ret += tcrypt_test("vmac(aes)");
1534 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001535
Sonic Zhanga482b082012-05-25 17:54:13 +08001536 case 110:
1537 ret += tcrypt_test("hmac(crc32)");
1538 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001539
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001540 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001541 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001542 break;
1543
Adrian Hoban69435b92010-11-04 15:02:04 -04001544 case 151:
1545 ret += tcrypt_test("rfc4106(gcm(aes))");
1546 break;
1547
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001548 case 152:
1549 ret += tcrypt_test("rfc4543(gcm(aes))");
1550 break;
1551
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001552 case 153:
1553 ret += tcrypt_test("cmac(aes)");
1554 break;
1555
1556 case 154:
1557 ret += tcrypt_test("cmac(des3_ede)");
1558 break;
1559
Horia Geantabbf9c892013-11-28 15:11:16 +02001560 case 155:
1561 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1562 break;
1563
Horia Geantabca4feb2014-03-14 17:46:51 +02001564 case 156:
1565 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1566 break;
1567
1568 case 157:
1569 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1570 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301571 case 181:
1572 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1573 break;
1574 case 182:
1575 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1576 break;
1577 case 183:
1578 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1579 break;
1580 case 184:
1581 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1582 break;
1583 case 185:
1584 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1585 break;
1586 case 186:
1587 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1588 break;
1589 case 187:
1590 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1591 break;
1592 case 188:
1593 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1594 break;
1595 case 189:
1596 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1597 break;
1598 case 190:
1599 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1600 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001601 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001602 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001603 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001604 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001605 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001606 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001607 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001608 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001609 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001610 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001611 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001612 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001613 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001614 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001615 speed_template_32_48_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001616 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001617 speed_template_32_48_64);
Jan Glauber9996e342011-04-26 16:34:01 +10001618 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1619 speed_template_16_24_32);
1620 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1621 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001622 break;
1623
1624 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001625 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001626 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001627 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001628 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001629 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001630 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001631 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001632 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001633 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001634 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001635 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001636 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001637 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1638 des3_speed_template, DES3_SPEED_VECTORS,
1639 speed_template_24);
1640 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1641 des3_speed_template, DES3_SPEED_VECTORS,
1642 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001643 break;
1644
1645 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001646 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001647 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001648 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001649 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001650 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001651 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001652 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001653 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001654 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1655 speed_template_16_24_32);
1656 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1657 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001658 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1659 speed_template_32_40_48);
1660 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1661 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001662 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1663 speed_template_32_48_64);
1664 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1665 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001666 break;
1667
1668 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001669 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001670 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001671 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001672 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001673 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001674 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001675 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001676 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001677 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1678 speed_template_8_32);
1679 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1680 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001681 break;
1682
1683 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001684 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001685 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001686 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001687 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001688 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001689 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001690 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001691 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001692 break;
1693
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001694 case 205:
1695 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001696 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001697 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001698 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001699 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001700 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001701 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001702 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001703 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1704 speed_template_16_24_32);
1705 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1706 speed_template_16_24_32);
1707 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1708 speed_template_32_40_48);
1709 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1710 speed_template_32_40_48);
1711 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1712 speed_template_32_48_64);
1713 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1714 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001715 break;
1716
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001717 case 206:
1718 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001719 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001720 break;
1721
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001722 case 207:
1723 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1724 speed_template_16_32);
1725 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1726 speed_template_16_32);
1727 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1728 speed_template_16_32);
1729 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1730 speed_template_16_32);
1731 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1732 speed_template_16_32);
1733 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1734 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001735 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1736 speed_template_32_48);
1737 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1738 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001739 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1740 speed_template_32_64);
1741 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1742 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001743 break;
1744
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001745 case 208:
1746 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1747 speed_template_8);
1748 break;
1749
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001750 case 209:
1751 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1752 speed_template_8_16);
1753 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1754 speed_template_8_16);
1755 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1756 speed_template_8_16);
1757 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1758 speed_template_8_16);
1759 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1760 speed_template_8_16);
1761 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1762 speed_template_8_16);
1763 break;
1764
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001765 case 210:
1766 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1767 speed_template_16_32);
1768 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1769 speed_template_16_32);
1770 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1771 speed_template_16_32);
1772 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1773 speed_template_16_32);
1774 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1775 speed_template_16_32);
1776 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1777 speed_template_16_32);
1778 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1779 speed_template_32_48);
1780 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1781 speed_template_32_48);
1782 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1783 speed_template_32_64);
1784 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1785 speed_template_32_64);
1786 break;
1787
Tim Chen53f52d72013-12-11 14:28:47 -08001788 case 211:
1789 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001790 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05301791 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01001792 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08001793 break;
1794
Herbert Xu4e4aab62015-06-17 14:04:21 +08001795 case 212:
1796 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001797 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08001798 break;
1799
Martin Willi2dce0632015-07-16 19:13:59 +02001800 case 213:
1801 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1802 NULL, 0, 16, 8, aead_speed_template_36);
1803 break;
1804
1805 case 214:
1806 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1807 speed_template_32);
1808 break;
1809
1810
Michal Ludvige8057922006-05-30 22:04:19 +10001811 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001812 if (alg) {
1813 test_hash_speed(alg, sec, generic_hash_speed_template);
1814 break;
1815 }
1816
Michal Ludvige8057922006-05-30 22:04:19 +10001817 /* fall through */
1818
1819 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001820 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001821 if (mode > 300 && mode < 400) break;
1822
1823 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001824 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001825 if (mode > 300 && mode < 400) break;
1826
1827 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001828 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001829 if (mode > 300 && mode < 400) break;
1830
1831 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001832 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001833 if (mode > 300 && mode < 400) break;
1834
1835 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001836 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001837 if (mode > 300 && mode < 400) break;
1838
1839 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001840 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001841 if (mode > 300 && mode < 400) break;
1842
1843 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001844 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001845 if (mode > 300 && mode < 400) break;
1846
1847 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001848 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001849 if (mode > 300 && mode < 400) break;
1850
1851 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001852 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001853 if (mode > 300 && mode < 400) break;
1854
1855 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001856 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001857 if (mode > 300 && mode < 400) break;
1858
1859 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001860 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001861 if (mode > 300 && mode < 400) break;
1862
1863 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001864 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001865 if (mode > 300 && mode < 400) break;
1866
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001867 case 313:
1868 test_hash_speed("sha224", sec, generic_hash_speed_template);
1869 if (mode > 300 && mode < 400) break;
1870
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001871 case 314:
1872 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1873 if (mode > 300 && mode < 400) break;
1874
1875 case 315:
1876 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1877 if (mode > 300 && mode < 400) break;
1878
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001879 case 316:
1880 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1881 if (mode > 300 && mode < 400) break;
1882
1883 case 317:
1884 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1885 if (mode > 300 && mode < 400) break;
1886
Huang Ying18bcc912010-03-10 18:30:32 +08001887 case 318:
1888 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1889 if (mode > 300 && mode < 400) break;
1890
Tim Chene3899e42012-09-27 15:44:24 -07001891 case 319:
1892 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1893 if (mode > 300 && mode < 400) break;
1894
Herbert Xu684115212013-09-07 12:56:26 +10001895 case 320:
1896 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1897 if (mode > 300 && mode < 400) break;
1898
Martin Willi2dce0632015-07-16 19:13:59 +02001899 case 321:
1900 test_hash_speed("poly1305", sec, poly1305_speed_template);
1901 if (mode > 300 && mode < 400) break;
1902
Michal Ludvige8057922006-05-30 22:04:19 +10001903 case 399:
1904 break;
1905
David S. Millerbeb63da2010-05-19 14:11:21 +10001906 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08001907 if (alg) {
1908 test_ahash_speed(alg, sec, generic_hash_speed_template);
1909 break;
1910 }
1911
David S. Millerbeb63da2010-05-19 14:11:21 +10001912 /* fall through */
1913
1914 case 401:
1915 test_ahash_speed("md4", sec, generic_hash_speed_template);
1916 if (mode > 400 && mode < 500) break;
1917
1918 case 402:
1919 test_ahash_speed("md5", sec, generic_hash_speed_template);
1920 if (mode > 400 && mode < 500) break;
1921
1922 case 403:
1923 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1924 if (mode > 400 && mode < 500) break;
1925
1926 case 404:
1927 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1928 if (mode > 400 && mode < 500) break;
1929
1930 case 405:
1931 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1932 if (mode > 400 && mode < 500) break;
1933
1934 case 406:
1935 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1936 if (mode > 400 && mode < 500) break;
1937
1938 case 407:
1939 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1940 if (mode > 400 && mode < 500) break;
1941
1942 case 408:
1943 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1944 if (mode > 400 && mode < 500) break;
1945
1946 case 409:
1947 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1948 if (mode > 400 && mode < 500) break;
1949
1950 case 410:
1951 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1952 if (mode > 400 && mode < 500) break;
1953
1954 case 411:
1955 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1956 if (mode > 400 && mode < 500) break;
1957
1958 case 412:
1959 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1960 if (mode > 400 && mode < 500) break;
1961
1962 case 413:
1963 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1964 if (mode > 400 && mode < 500) break;
1965
1966 case 414:
1967 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1968 if (mode > 400 && mode < 500) break;
1969
1970 case 415:
1971 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1972 if (mode > 400 && mode < 500) break;
1973
1974 case 416:
1975 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1976 if (mode > 400 && mode < 500) break;
1977
1978 case 417:
1979 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1980 if (mode > 400 && mode < 500) break;
1981
1982 case 499:
1983 break;
1984
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001985 case 500:
1986 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1987 speed_template_16_24_32);
1988 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1989 speed_template_16_24_32);
1990 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1991 speed_template_16_24_32);
1992 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1993 speed_template_16_24_32);
1994 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1995 speed_template_32_40_48);
1996 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1997 speed_template_32_40_48);
1998 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
1999 speed_template_32_48_64);
2000 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2001 speed_template_32_48_64);
2002 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2003 speed_template_16_24_32);
2004 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2005 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02002006 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2007 speed_template_16_24_32);
2008 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2009 speed_template_16_24_32);
2010 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2011 speed_template_16_24_32);
2012 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2013 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02002014 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2015 speed_template_20_28_36);
2016 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2017 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002018 break;
2019
2020 case 501:
2021 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2022 des3_speed_template, DES3_SPEED_VECTORS,
2023 speed_template_24);
2024 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2025 des3_speed_template, DES3_SPEED_VECTORS,
2026 speed_template_24);
2027 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2028 des3_speed_template, DES3_SPEED_VECTORS,
2029 speed_template_24);
2030 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2031 des3_speed_template, DES3_SPEED_VECTORS,
2032 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02002033 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2034 des3_speed_template, DES3_SPEED_VECTORS,
2035 speed_template_24);
2036 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2037 des3_speed_template, DES3_SPEED_VECTORS,
2038 speed_template_24);
2039 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2040 des3_speed_template, DES3_SPEED_VECTORS,
2041 speed_template_24);
2042 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2043 des3_speed_template, DES3_SPEED_VECTORS,
2044 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002045 break;
2046
2047 case 502:
2048 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2049 speed_template_8);
2050 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2051 speed_template_8);
2052 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2053 speed_template_8);
2054 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2055 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02002056 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2057 speed_template_8);
2058 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2059 speed_template_8);
2060 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2061 speed_template_8);
2062 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2063 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002064 break;
2065
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002066 case 503:
2067 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2068 speed_template_16_32);
2069 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2070 speed_template_16_32);
2071 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2072 speed_template_16_32);
2073 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2074 speed_template_16_32);
2075 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2076 speed_template_16_32);
2077 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2078 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002079 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2080 speed_template_32_48);
2081 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2082 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002083 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2084 speed_template_32_64);
2085 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2086 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002087 break;
2088
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002089 case 504:
2090 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2091 speed_template_16_24_32);
2092 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2093 speed_template_16_24_32);
2094 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2095 speed_template_16_24_32);
2096 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2097 speed_template_16_24_32);
2098 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2099 speed_template_16_24_32);
2100 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2101 speed_template_16_24_32);
2102 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2103 speed_template_32_40_48);
2104 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2105 speed_template_32_40_48);
2106 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2107 speed_template_32_48_64);
2108 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2109 speed_template_32_48_64);
2110 break;
2111
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002112 case 505:
2113 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2114 speed_template_8);
2115 break;
2116
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002117 case 506:
2118 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2119 speed_template_8_16);
2120 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2121 speed_template_8_16);
2122 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2123 speed_template_8_16);
2124 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2125 speed_template_8_16);
2126 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2127 speed_template_8_16);
2128 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2129 speed_template_8_16);
2130 break;
2131
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002132 case 507:
2133 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2134 speed_template_16_32);
2135 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2136 speed_template_16_32);
2137 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2138 speed_template_16_32);
2139 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2140 speed_template_16_32);
2141 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2142 speed_template_16_32);
2143 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2144 speed_template_16_32);
2145 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2146 speed_template_32_48);
2147 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2148 speed_template_32_48);
2149 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2150 speed_template_32_64);
2151 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2152 speed_template_32_64);
2153 break;
2154
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002155 case 508:
2156 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2157 speed_template_16_32);
2158 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2159 speed_template_16_32);
2160 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2161 speed_template_16_32);
2162 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2163 speed_template_16_32);
2164 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2165 speed_template_16_32);
2166 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2167 speed_template_16_32);
2168 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2169 speed_template_32_48);
2170 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2171 speed_template_32_48);
2172 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2173 speed_template_32_64);
2174 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2175 speed_template_32_64);
2176 break;
2177
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002178 case 509:
2179 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2180 speed_template_8_32);
2181 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2182 speed_template_8_32);
2183 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2184 speed_template_8_32);
2185 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2186 speed_template_8_32);
2187 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2188 speed_template_8_32);
2189 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2190 speed_template_8_32);
2191 break;
2192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 case 1000:
2194 test_available();
2195 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002197
2198 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199}
2200
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002201static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002203 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002204 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002205
Herbert Xuf139cfa2008-07-31 12:23:53 +08002206 for (i = 0; i < TVMEMSIZE; i++) {
2207 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2208 if (!tvmem[i])
2209 goto err_free_tv;
2210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Herbert Xu86068132014-12-04 16:43:29 +08002212 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002213
Jarod Wilson4e033a62009-05-27 15:10:21 +10002214 if (err) {
2215 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2216 goto err_free_tv;
2217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
Jarod Wilson4e033a62009-05-27 15:10:21 +10002219 /* We intentionaly return -EAGAIN to prevent keeping the module,
2220 * unless we're running in fips mode. It does all its work from
2221 * init() and doesn't offer any runtime functionality, but in
2222 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002223 * => we don't need it in the memory, do we?
2224 * -- mludvig
2225 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002226 if (!fips_enabled)
2227 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002228
Herbert Xuf139cfa2008-07-31 12:23:53 +08002229err_free_tv:
2230 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2231 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002232
2233 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234}
2235
2236/*
2237 * If an init function is provided, an exit function must also be provided
2238 * to allow module unload.
2239 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002240static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002242module_init(tcrypt_mod_init);
2243module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002245module_param(alg, charp, 0);
2246module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002247module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002249module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002250MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2251 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253MODULE_LICENSE("GPL");
2254MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2255MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");