blob: 3ced1ba1fd11824f76752de67e883d2cabbdbcbe [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
Rabin Vincent76512f22017-01-18 14:54:05 +010025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Herbert Xu1ce5a042015-04-22 15:06:30 +080027#include <crypto/aead.h>
Herbert Xu18e33e62008-07-10 16:01:22 +080028#include <crypto/hash.h>
Herbert Xu7166e582016-06-29 18:03:50 +080029#include <crypto/skcipher.h>
Herbert Xucba83562006-08-13 08:26:09 +100030#include <linux/err.h>
Herbert Xudaf09442015-04-22 13:25:57 +080031#include <linux/fips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/module.h>
David Hardeman378f0582005-09-17 17:55:31 +100035#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070038#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070039#include <linux/timex.h>
40#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "tcrypt.h"
42
43/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080044 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080046#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
Herbert Xuda7f0332008-07-31 17:08:25 +080049* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070050*/
51#define ENCRYPT 1
52#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Horia Geant?f074f7b2015-08-27 18:38:36 +030054#define MAX_DIGEST_SIZE 64
55
Harald Welteebfd9bc2005-06-22 13:27:23 -070056/*
Luca Clementi263a8df2014-06-25 22:57:42 -070057 * return a string with the driver name
58 */
59#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
60
61/*
Harald Welteebfd9bc2005-06-22 13:27:23 -070062 * Used by test_cipher_speed()
63 */
Herbert Xu6a179442005-06-22 13:29:03 -070064static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070065
Steffen Klasserta873a5f2009-06-19 19:46:53 +080066static char *alg = NULL;
67static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080068static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int mode;
Herbert Xuf139cfa2008-07-31 12:23:53 +080070static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72static char *check[] = {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +030073 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080074 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
75 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110076 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080077 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +053078 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
79 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053082static inline int do_one_aead_op(struct aead_request *req, int ret)
83{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010084 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053085
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010086 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053087}
88
Tim Chen53f52d72013-12-11 14:28:47 -080089static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070090 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -080091{
92 unsigned long start, end;
93 int bcount;
94 int ret;
95
Mark Rustad3e3dc252014-07-25 02:53:38 -070096 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -080097 time_before(jiffies, end); bcount++) {
98 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053099 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800100 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530101 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800102
103 if (ret)
104 return ret;
105 }
106
107 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700108 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800109 return 0;
110}
111
112static int test_aead_cycles(struct aead_request *req, int enc, int blen)
113{
114 unsigned long cycles = 0;
115 int ret = 0;
116 int i;
117
Tim Chen53f52d72013-12-11 14:28:47 -0800118 /* Warm-up run. */
119 for (i = 0; i < 4; i++) {
120 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530121 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800122 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530123 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800124
125 if (ret)
126 goto out;
127 }
128
129 /* The real thing. */
130 for (i = 0; i < 8; i++) {
131 cycles_t start, end;
132
133 start = get_cycles();
134 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530135 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800136 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530137 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800138 end = get_cycles();
139
140 if (ret)
141 goto out;
142
143 cycles += end - start;
144 }
145
146out:
Tim Chen53f52d72013-12-11 14:28:47 -0800147 if (ret == 0)
148 printk("1 operation in %lu cycles (%d bytes)\n",
149 (cycles + 4) / 8, blen);
150
151 return ret;
152}
153
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800154static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800155static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
156
157#define XBUFSIZE 8
158#define MAX_IVLEN 32
159
160static int testmgr_alloc_buf(char *buf[XBUFSIZE])
161{
162 int i;
163
164 for (i = 0; i < XBUFSIZE; i++) {
165 buf[i] = (void *)__get_free_page(GFP_KERNEL);
166 if (!buf[i])
167 goto err_free_buf;
168 }
169
170 return 0;
171
172err_free_buf:
173 while (i-- > 0)
174 free_page((unsigned long)buf[i]);
175
176 return -ENOMEM;
177}
178
179static void testmgr_free_buf(char *buf[XBUFSIZE])
180{
181 int i;
182
183 for (i = 0; i < XBUFSIZE; i++)
184 free_page((unsigned long)buf[i]);
185}
186
187static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
188 unsigned int buflen)
189{
190 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
191 int k, rem;
192
Tim Chen53f52d72013-12-11 14:28:47 -0800193 if (np > XBUFSIZE) {
194 rem = PAGE_SIZE;
195 np = XBUFSIZE;
Cristian Stoicac4768992015-01-27 11:54:27 +0200196 } else {
197 rem = buflen % PAGE_SIZE;
Tim Chen53f52d72013-12-11 14:28:47 -0800198 }
Cristian Stoicac4768992015-01-27 11:54:27 +0200199
Herbert Xu31267272015-06-17 14:05:26 +0800200 sg_init_table(sg, np + 1);
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300201 if (rem)
202 np--;
Cristian Stoicac4768992015-01-27 11:54:27 +0200203 for (k = 0; k < np; k++)
Herbert Xu31267272015-06-17 14:05:26 +0800204 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
Cristian Stoicac4768992015-01-27 11:54:27 +0200205
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300206 if (rem)
207 sg_set_buf(&sg[k + 1], xbuf[k], rem);
Tim Chen53f52d72013-12-11 14:28:47 -0800208}
209
Mark Rustad3e3dc252014-07-25 02:53:38 -0700210static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800211 struct aead_speed_template *template,
212 unsigned int tcount, u8 authsize,
213 unsigned int aad_size, u8 *keysize)
214{
215 unsigned int i, j;
216 struct crypto_aead *tfm;
217 int ret = -ENOMEM;
218 const char *key;
219 struct aead_request *req;
220 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800221 struct scatterlist *sgout;
222 const char *e;
223 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200224 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800225 char *xbuf[XBUFSIZE];
226 char *xoutbuf[XBUFSIZE];
227 char *axbuf[XBUFSIZE];
228 unsigned int *b_size;
229 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100230 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800231
Cristian Stoica96692a732015-01-28 13:07:32 +0200232 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
233 if (!iv)
234 return;
235
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200236 if (aad_size >= PAGE_SIZE) {
237 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200238 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200239 }
240
Tim Chen53f52d72013-12-11 14:28:47 -0800241 if (enc == ENCRYPT)
242 e = "encryption";
243 else
244 e = "decryption";
245
246 if (testmgr_alloc_buf(xbuf))
247 goto out_noxbuf;
248 if (testmgr_alloc_buf(axbuf))
249 goto out_noaxbuf;
250 if (testmgr_alloc_buf(xoutbuf))
251 goto out_nooutbuf;
252
Herbert Xua3f21852015-05-27 16:03:51 +0800253 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800254 if (!sg)
255 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800256 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800257
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800258 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800259
260 if (IS_ERR(tfm)) {
261 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
262 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200263 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800264 }
265
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100266 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700267 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
268 get_driver_name(crypto_aead, tfm), e);
269
Tim Chen53f52d72013-12-11 14:28:47 -0800270 req = aead_request_alloc(tfm, GFP_KERNEL);
271 if (!req) {
272 pr_err("alg: aead: Failed to allocate request for %s\n",
273 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200274 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800275 }
276
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530277 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100278 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530279
Tim Chen53f52d72013-12-11 14:28:47 -0800280 i = 0;
281 do {
282 b_size = aead_sizes;
283 do {
284 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200285 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800286
287 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
288 pr_err("template (%u) too big for tvmem (%lu)\n",
289 *keysize + *b_size,
290 TVMEMSIZE * PAGE_SIZE);
291 goto out;
292 }
293
294 key = tvmem[0];
295 for (j = 0; j < tcount; j++) {
296 if (template[j].klen == *keysize) {
297 key = template[j].key;
298 break;
299 }
300 }
301 ret = crypto_aead_setkey(tfm, key, *keysize);
302 ret = crypto_aead_setauthsize(tfm, authsize);
303
304 iv_len = crypto_aead_ivsize(tfm);
305 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200306 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800307
308 crypto_aead_clear_flags(tfm, ~0);
309 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
310 i, *keysize * 8, *b_size);
311
312
313 memset(tvmem[0], 0xff, PAGE_SIZE);
314
315 if (ret) {
316 pr_err("setkey() failed flags=%x\n",
317 crypto_aead_get_flags(tfm));
318 goto out;
319 }
320
Herbert Xu31267272015-06-17 14:05:26 +0800321 sg_init_aead(sg, xbuf,
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300322 *b_size + (enc ? 0 : authsize));
Tim Chen53f52d72013-12-11 14:28:47 -0800323
Herbert Xu31267272015-06-17 14:05:26 +0800324 sg_init_aead(sgout, xoutbuf,
Tim Chen53f52d72013-12-11 14:28:47 -0800325 *b_size + (enc ? authsize : 0));
326
Herbert Xu31267272015-06-17 14:05:26 +0800327 sg_set_buf(&sg[0], assoc, aad_size);
328 sg_set_buf(&sgout[0], assoc, aad_size);
329
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300330 aead_request_set_crypt(req, sg, sgout,
331 *b_size + (enc ? 0 : authsize),
332 iv);
Herbert Xua3f21852015-05-27 16:03:51 +0800333 aead_request_set_ad(req, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800334
Mark Rustad3e3dc252014-07-25 02:53:38 -0700335 if (secs)
336 ret = test_aead_jiffies(req, enc, *b_size,
337 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800338 else
339 ret = test_aead_cycles(req, enc, *b_size);
340
341 if (ret) {
342 pr_err("%s() failed return code=%d\n", e, ret);
343 break;
344 }
345 b_size++;
346 i++;
347 } while (*b_size);
348 keysize++;
349 } while (*keysize);
350
351out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200352 aead_request_free(req);
353out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800354 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200355out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800356 kfree(sg);
357out_nosg:
358 testmgr_free_buf(xoutbuf);
359out_nooutbuf:
360 testmgr_free_buf(axbuf);
361out_noaxbuf:
362 testmgr_free_buf(xbuf);
363out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200364 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800365}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800366
David S. Millerbeb63da2010-05-19 14:11:21 +1000367static void test_hash_sg_init(struct scatterlist *sg)
368{
369 int i;
370
371 sg_init_table(sg, TVMEMSIZE);
372 for (i = 0; i < TVMEMSIZE; i++) {
373 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
374 memset(tvmem[i], 0xff, PAGE_SIZE);
375 }
376}
377
David S. Millerbeb63da2010-05-19 14:11:21 +1000378static inline int do_one_ahash_op(struct ahash_request *req, int ret)
379{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100380 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000381
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100382 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000383}
384
Herbert Xu72259de2016-06-28 20:33:52 +0800385struct test_mb_ahash_data {
386 struct scatterlist sg[TVMEMSIZE];
387 char result[64];
388 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100389 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800390 char *xbuf[XBUFSIZE];
391};
Megha Dey087bcd22016-06-23 18:40:47 -0700392
393static void test_mb_ahash_speed(const char *algo, unsigned int sec,
Herbert Xu72259de2016-06-28 20:33:52 +0800394 struct hash_speed *speed)
Megha Dey087bcd22016-06-23 18:40:47 -0700395{
Herbert Xu72259de2016-06-28 20:33:52 +0800396 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700397 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800398 unsigned long start, end;
Herbert Xuf8de55b2016-06-28 16:41:38 +0800399 unsigned long cycles;
Herbert Xu72259de2016-06-28 20:33:52 +0800400 unsigned int i, j, k;
401 int ret;
402
403 data = kzalloc(sizeof(*data) * 8, GFP_KERNEL);
404 if (!data)
405 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700406
407 tfm = crypto_alloc_ahash(algo, 0, 0);
408 if (IS_ERR(tfm)) {
409 pr_err("failed to load transform for %s: %ld\n",
410 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800411 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700412 }
Herbert Xu72259de2016-06-28 20:33:52 +0800413
Megha Dey087bcd22016-06-23 18:40:47 -0700414 for (i = 0; i < 8; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800415 if (testmgr_alloc_buf(data[i].xbuf))
416 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700417
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100418 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700419
Herbert Xu72259de2016-06-28 20:33:52 +0800420 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
421 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200422 pr_err("alg: hash: Failed to allocate request for %s\n",
423 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800424 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700425 }
Megha Dey087bcd22016-06-23 18:40:47 -0700426
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100427 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
428 &data[i].wait);
Herbert Xu72259de2016-06-28 20:33:52 +0800429 test_hash_sg_init(data[i].sg);
Megha Dey087bcd22016-06-23 18:40:47 -0700430 }
431
Herbert Xu72259de2016-06-28 20:33:52 +0800432 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
433 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700434
435 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800436 /* For some reason this only tests digests. */
437 if (speed[i].blen != speed[i].plen)
438 continue;
439
Megha Dey087bcd22016-06-23 18:40:47 -0700440 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200441 pr_err("template (%u) too big for tvmem (%lu)\n",
442 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
443 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700444 }
445
446 if (speed[i].klen)
447 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
448
Herbert Xu72259de2016-06-28 20:33:52 +0800449 for (k = 0; k < 8; k++)
450 ahash_request_set_crypt(data[k].req, data[k].sg,
451 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700452
Herbert Xu72259de2016-06-28 20:33:52 +0800453 pr_info("test%3u "
454 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700455 i, speed[i].blen, speed[i].plen,
456 speed[i].blen / speed[i].plen);
457
Herbert Xu72259de2016-06-28 20:33:52 +0800458 start = get_cycles();
459
460 for (k = 0; k < 8; k++) {
461 ret = crypto_ahash_digest(data[k].req);
Herbert Xud13cd112016-06-30 11:00:13 +0800462 if (ret == -EINPROGRESS) {
463 ret = 0;
Megha Dey087bcd22016-06-23 18:40:47 -0700464 continue;
Herbert Xud13cd112016-06-30 11:00:13 +0800465 }
Megha Dey087bcd22016-06-23 18:40:47 -0700466
Megha Dey087bcd22016-06-23 18:40:47 -0700467 if (ret)
Herbert Xu72259de2016-06-28 20:33:52 +0800468 break;
469
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100470 crypto_req_done(&data[k].req->base, 0);
Megha Dey087bcd22016-06-23 18:40:47 -0700471 }
472
Herbert Xu72259de2016-06-28 20:33:52 +0800473 for (j = 0; j < k; j++) {
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100474 struct crypto_wait *wait = &data[j].wait;
475 int wait_ret;
Herbert Xu72259de2016-06-28 20:33:52 +0800476
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100477 wait_ret = crypto_wait_req(-EINPROGRESS, wait);
478 if (wait_ret)
479 ret = wait_ret;
Herbert Xu72259de2016-06-28 20:33:52 +0800480 }
481
482 end = get_cycles();
483 cycles = end - start;
484 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
485 cycles, cycles / (8 * speed[i].blen));
486
487 if (ret) {
488 pr_err("At least one hashing failed ret=%d\n", ret);
489 break;
490 }
Megha Dey087bcd22016-06-23 18:40:47 -0700491 }
Megha Dey087bcd22016-06-23 18:40:47 -0700492
493out:
494 for (k = 0; k < 8; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800495 ahash_request_free(data[k].req);
496
Megha Dey087bcd22016-06-23 18:40:47 -0700497 for (k = 0; k < 8; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800498 testmgr_free_buf(data[k].xbuf);
499
500 crypto_free_ahash(tfm);
501
502free_data:
503 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700504}
505
David S. Millerbeb63da2010-05-19 14:11:21 +1000506static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700507 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000508{
509 unsigned long start, end;
510 int bcount;
511 int ret;
512
Mark Rustad3e3dc252014-07-25 02:53:38 -0700513 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000514 time_before(jiffies, end); bcount++) {
515 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
516 if (ret)
517 return ret;
518 }
519
520 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700521 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000522
523 return 0;
524}
525
526static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700527 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000528{
529 unsigned long start, end;
530 int bcount, pcount;
531 int ret;
532
533 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700534 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000535
Mark Rustad3e3dc252014-07-25 02:53:38 -0700536 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000537 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800538 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000539 if (ret)
540 return ret;
541 for (pcount = 0; pcount < blen; pcount += plen) {
542 ret = do_one_ahash_op(req, crypto_ahash_update(req));
543 if (ret)
544 return ret;
545 }
546 /* we assume there is enough space in 'out' for the result */
547 ret = do_one_ahash_op(req, crypto_ahash_final(req));
548 if (ret)
549 return ret;
550 }
551
552 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700553 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000554
555 return 0;
556}
557
558static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
559 char *out)
560{
561 unsigned long cycles = 0;
562 int ret, i;
563
564 /* Warm-up run. */
565 for (i = 0; i < 4; i++) {
566 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
567 if (ret)
568 goto out;
569 }
570
571 /* The real thing. */
572 for (i = 0; i < 8; i++) {
573 cycles_t start, end;
574
575 start = get_cycles();
576
577 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
578 if (ret)
579 goto out;
580
581 end = get_cycles();
582
583 cycles += end - start;
584 }
585
586out:
587 if (ret)
588 return ret;
589
590 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
591 cycles / 8, cycles / (8 * blen));
592
593 return 0;
594}
595
596static int test_ahash_cycles(struct ahash_request *req, int blen,
597 int plen, char *out)
598{
599 unsigned long cycles = 0;
600 int i, pcount, ret;
601
602 if (plen == blen)
603 return test_ahash_cycles_digest(req, blen, out);
604
605 /* Warm-up run. */
606 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800607 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000608 if (ret)
609 goto out;
610 for (pcount = 0; pcount < blen; pcount += plen) {
611 ret = do_one_ahash_op(req, crypto_ahash_update(req));
612 if (ret)
613 goto out;
614 }
615 ret = do_one_ahash_op(req, crypto_ahash_final(req));
616 if (ret)
617 goto out;
618 }
619
620 /* The real thing. */
621 for (i = 0; i < 8; i++) {
622 cycles_t start, end;
623
624 start = get_cycles();
625
Herbert Xu43a96072015-04-22 11:02:27 +0800626 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000627 if (ret)
628 goto out;
629 for (pcount = 0; pcount < blen; pcount += plen) {
630 ret = do_one_ahash_op(req, crypto_ahash_update(req));
631 if (ret)
632 goto out;
633 }
634 ret = do_one_ahash_op(req, crypto_ahash_final(req));
635 if (ret)
636 goto out;
637
638 end = get_cycles();
639
640 cycles += end - start;
641 }
642
643out:
644 if (ret)
645 return ret;
646
647 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
648 cycles / 8, cycles / (8 * blen));
649
650 return 0;
651}
652
Herbert Xu06605112016-02-01 21:36:49 +0800653static void test_ahash_speed_common(const char *algo, unsigned int secs,
654 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +1000655{
656 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100657 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +1000658 struct ahash_request *req;
659 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +0300660 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +1000661 int i, ret;
662
Herbert Xu06605112016-02-01 21:36:49 +0800663 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +1000664 if (IS_ERR(tfm)) {
665 pr_err("failed to load transform for %s: %ld\n",
666 algo, PTR_ERR(tfm));
667 return;
668 }
669
Luca Clementi263a8df2014-06-25 22:57:42 -0700670 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
671 get_driver_name(crypto_ahash, tfm));
672
Horia Geant?f074f7b2015-08-27 18:38:36 +0300673 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
674 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
675 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +1000676 goto out;
677 }
678
679 test_hash_sg_init(sg);
680 req = ahash_request_alloc(tfm, GFP_KERNEL);
681 if (!req) {
682 pr_err("ahash request allocation failure\n");
683 goto out;
684 }
685
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100686 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000687 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100688 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000689
Horia Geant?f074f7b2015-08-27 18:38:36 +0300690 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
691 if (!output)
692 goto out_nomem;
693
David S. Millerbeb63da2010-05-19 14:11:21 +1000694 for (i = 0; speed[i].blen != 0; i++) {
695 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
696 pr_err("template (%u) too big for tvmem (%lu)\n",
697 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
698 break;
699 }
700
701 pr_info("test%3u "
702 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
703 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
704
705 ahash_request_set_crypt(req, sg, output, speed[i].plen);
706
Mark Rustad3e3dc252014-07-25 02:53:38 -0700707 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000708 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700709 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000710 else
711 ret = test_ahash_cycles(req, speed[i].blen,
712 speed[i].plen, output);
713
714 if (ret) {
715 pr_err("hashing failed ret=%d\n", ret);
716 break;
717 }
718 }
719
Horia Geant?f074f7b2015-08-27 18:38:36 +0300720 kfree(output);
721
722out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +1000723 ahash_request_free(req);
724
725out:
726 crypto_free_ahash(tfm);
727}
728
Herbert Xu06605112016-02-01 21:36:49 +0800729static void test_ahash_speed(const char *algo, unsigned int secs,
730 struct hash_speed *speed)
731{
732 return test_ahash_speed_common(algo, secs, speed, 0);
733}
734
735static void test_hash_speed(const char *algo, unsigned int secs,
736 struct hash_speed *speed)
737{
738 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
739}
740
Herbert Xu7166e582016-06-29 18:03:50 +0800741static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300742{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100743 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300744
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100745 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300746}
747
Herbert Xu7166e582016-06-29 18:03:50 +0800748static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700749 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300750{
751 unsigned long start, end;
752 int bcount;
753 int ret;
754
Mark Rustad3e3dc252014-07-25 02:53:38 -0700755 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300756 time_before(jiffies, end); bcount++) {
757 if (enc)
758 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800759 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300760 else
761 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800762 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300763
764 if (ret)
765 return ret;
766 }
767
768 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700769 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300770 return 0;
771}
772
Herbert Xu7166e582016-06-29 18:03:50 +0800773static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300774 int blen)
775{
776 unsigned long cycles = 0;
777 int ret = 0;
778 int i;
779
780 /* Warm-up run. */
781 for (i = 0; i < 4; i++) {
782 if (enc)
783 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800784 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300785 else
786 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800787 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300788
789 if (ret)
790 goto out;
791 }
792
793 /* The real thing. */
794 for (i = 0; i < 8; i++) {
795 cycles_t start, end;
796
797 start = get_cycles();
798 if (enc)
799 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800800 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300801 else
802 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800803 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300804 end = get_cycles();
805
806 if (ret)
807 goto out;
808
809 cycles += end - start;
810 }
811
812out:
813 if (ret == 0)
814 pr_cont("1 operation in %lu cycles (%d bytes)\n",
815 (cycles + 4) / 8, blen);
816
817 return ret;
818}
819
Herbert Xu7166e582016-06-29 18:03:50 +0800820static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
821 struct cipher_speed_template *template,
822 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300823{
Nicolas Royerde1975332012-07-01 19:19:47 +0200824 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100825 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300826 const char *key;
827 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +0800828 struct skcipher_request *req;
829 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300830 const char *e;
831 u32 *b_size;
832
833 if (enc == ENCRYPT)
834 e = "encryption";
835 else
836 e = "decryption";
837
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100838 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300839
Herbert Xu7166e582016-06-29 18:03:50 +0800840 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300841
842 if (IS_ERR(tfm)) {
843 pr_err("failed to load transform for %s: %ld\n", algo,
844 PTR_ERR(tfm));
845 return;
846 }
847
Luca Clementi263a8df2014-06-25 22:57:42 -0700848 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
Herbert Xu7166e582016-06-29 18:03:50 +0800849 get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -0700850
Herbert Xu7166e582016-06-29 18:03:50 +0800851 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300852 if (!req) {
853 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
854 algo);
855 goto out;
856 }
857
Herbert Xu7166e582016-06-29 18:03:50 +0800858 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100859 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300860
861 i = 0;
862 do {
863 b_size = block_sizes;
864
865 do {
866 struct scatterlist sg[TVMEMSIZE];
867
868 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
869 pr_err("template (%u) too big for "
870 "tvmem (%lu)\n", *keysize + *b_size,
871 TVMEMSIZE * PAGE_SIZE);
872 goto out_free_req;
873 }
874
875 pr_info("test %u (%d bit key, %d byte blocks): ", i,
876 *keysize * 8, *b_size);
877
878 memset(tvmem[0], 0xff, PAGE_SIZE);
879
880 /* set key, plain text and IV */
881 key = tvmem[0];
882 for (j = 0; j < tcount; j++) {
883 if (template[j].klen == *keysize) {
884 key = template[j].key;
885 break;
886 }
887 }
888
Herbert Xu7166e582016-06-29 18:03:50 +0800889 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300890
Herbert Xu7166e582016-06-29 18:03:50 +0800891 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300892 if (ret) {
893 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +0800894 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300895 goto out_free_req;
896 }
897
Nicolas Royerde1975332012-07-01 19:19:47 +0200898 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +0200899 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
900
Nicolas Royerde1975332012-07-01 19:19:47 +0200901 if (k > PAGE_SIZE) {
902 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300903 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +0200904 k -= PAGE_SIZE;
905 j = 1;
906 while (k > PAGE_SIZE) {
907 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
908 memset(tvmem[j], 0xff, PAGE_SIZE);
909 j++;
910 k -= PAGE_SIZE;
911 }
912 sg_set_buf(sg + j, tvmem[j], k);
913 memset(tvmem[j], 0xff, k);
914 } else {
915 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300916 }
917
Herbert Xu7166e582016-06-29 18:03:50 +0800918 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300919 if (iv_len)
920 memset(&iv, 0xff, iv_len);
921
Herbert Xu7166e582016-06-29 18:03:50 +0800922 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300923
Mark Rustad3e3dc252014-07-25 02:53:38 -0700924 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300925 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700926 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300927 else
928 ret = test_acipher_cycles(req, enc,
929 *b_size);
930
931 if (ret) {
932 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +0800933 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300934 break;
935 }
936 b_size++;
937 i++;
938 } while (*b_size);
939 keysize++;
940 } while (*keysize);
941
942out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +0800943 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300944out:
Herbert Xu7166e582016-06-29 18:03:50 +0800945 crypto_free_skcipher(tfm);
946}
947
948static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
949 struct cipher_speed_template *template,
950 unsigned int tcount, u8 *keysize)
951{
952 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
953 true);
954}
955
956static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
957 struct cipher_speed_template *template,
958 unsigned int tcount, u8 *keysize)
959{
960 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
961 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300962}
963
Herbert Xuef2736f2005-06-22 13:26:03 -0700964static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
966 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700967
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 while (*name) {
969 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000970 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000971 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974}
975
Herbert Xu01b32322008-07-31 15:41:55 +0800976static inline int tcrypt_test(const char *alg)
977{
Jarod Wilson4e033a62009-05-27 15:10:21 +1000978 int ret;
979
Rabin Vincent76512f22017-01-18 14:54:05 +0100980 pr_debug("testing %s\n", alg);
981
Jarod Wilson4e033a62009-05-27 15:10:21 +1000982 ret = alg_test(alg, alg, 0, 0);
983 /* non-fips algs return -EINVAL in fips mode */
984 if (fips_enabled && ret == -EINVAL)
985 ret = 0;
986 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +0800987}
988
Herbert Xu86068132014-12-04 16:43:29 +0800989static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +0800990{
991 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +1000992 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +0800993
994 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 case 0:
Herbert Xu86068132014-12-04 16:43:29 +0800996 if (alg) {
997 if (!crypto_has_alg(alg, type,
998 mask ?: CRYPTO_ALG_TYPE_MASK))
999 ret = -ENOENT;
1000 break;
1001 }
1002
Herbert Xu01b32322008-07-31 15:41:55 +08001003 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001004 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 break;
1006
1007 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001008 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 break;
1010
1011 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001012 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 break;
1014
1015 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001016 ret += tcrypt_test("ecb(des)");
1017 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001018 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 break;
1020
1021 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001022 ret += tcrypt_test("ecb(des3_ede)");
1023 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001024 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 break;
1026
1027 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001028 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001032 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001036 ret += tcrypt_test("ecb(blowfish)");
1037 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001038 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 break;
1040
1041 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001042 ret += tcrypt_test("ecb(twofish)");
1043 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001044 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001045 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001046 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001050 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001051 ret += tcrypt_test("cbc(serpent)");
1052 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001053 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001054 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 break;
1056
1057 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001058 ret += tcrypt_test("ecb(aes)");
1059 ret += tcrypt_test("cbc(aes)");
1060 ret += tcrypt_test("lrw(aes)");
1061 ret += tcrypt_test("xts(aes)");
1062 ret += tcrypt_test("ctr(aes)");
1063 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 break;
1065
1066 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001067 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001071 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 break;
1073
1074 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001075 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 break;
1077
1078 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001079 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001080 ret += tcrypt_test("cbc(cast5)");
1081 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 break;
1083
1084 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001085 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001086 ret += tcrypt_test("cbc(cast6)");
1087 ret += tcrypt_test("ctr(cast6)");
1088 ret += tcrypt_test("lrw(cast6)");
1089 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 break;
1091
1092 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001093 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 break;
1095
1096 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001097 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 break;
1099
1100 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001101 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 break;
1103
1104 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001105 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 break;
1107
1108 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001109 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 break;
1111
1112 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001113 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 break;
1115
1116 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001117 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 break;
1119
1120 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001121 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 break;
1123
1124 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001125 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 break;
1127
1128 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001129 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 break;
1131
1132 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001133 ret += tcrypt_test("ecb(anubis)");
1134 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 break;
1136
1137 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001138 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 break;
1140
1141 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001142 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 break;
1144
1145 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001146 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001148
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001149 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001150 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001151 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
David Howells90831632006-12-16 12:13:14 +11001153 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001154 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001155 break;
1156
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001157 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001158 ret += tcrypt_test("ecb(camellia)");
1159 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001160 ret += tcrypt_test("ctr(camellia)");
1161 ret += tcrypt_test("lrw(camellia)");
1162 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001163 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001164
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001165 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001166 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001167 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001168
Tan Swee Heng2407d602007-11-23 19:45:00 +08001169 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001170 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001171 break;
1172
Herbert Xu8df213d2007-12-02 14:55:47 +11001173 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001174 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001175 break;
1176
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001177 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001178 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001179 break;
1180
Joy Latten93cc74e2007-12-12 20:24:22 +08001181 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001182 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001183 break;
1184
Kevin Coffman76cb9522008-03-24 21:26:16 +08001185 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001186 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001187 break;
1188
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001189 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001190 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001191 break;
1192
1193 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001194 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001195 break;
1196
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001197 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001198 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001199 break;
1200
1201 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001202 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001203 break;
1204
1205 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001206 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001207 break;
1208
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001209 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001210 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001211 break;
1212
Jarod Wilson5d667322009-05-04 19:23:40 +08001213 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001214 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001215 break;
1216
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001217 case 46:
1218 ret += tcrypt_test("ghash");
1219 break;
1220
Herbert Xu684115212013-09-07 12:56:26 +10001221 case 47:
1222 ret += tcrypt_test("crct10dif");
1223 break;
1224
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301225 case 48:
1226 ret += tcrypt_test("sha3-224");
1227 break;
1228
1229 case 49:
1230 ret += tcrypt_test("sha3-256");
1231 break;
1232
1233 case 50:
1234 ret += tcrypt_test("sha3-384");
1235 break;
1236
1237 case 51:
1238 ret += tcrypt_test("sha3-512");
1239 break;
1240
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001241 case 52:
1242 ret += tcrypt_test("sm3");
1243 break;
1244
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001246 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001250 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001254 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 break;
1256
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001257 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001258 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001259 break;
1260
1261 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001262 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001263 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001264
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001265 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001266 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001269 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001270 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001271 break;
1272
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001273 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001274 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001275 break;
1276
1277 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001278 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001279 break;
1280
Shane Wangf1939f72009-09-02 20:05:22 +10001281 case 109:
1282 ret += tcrypt_test("vmac(aes)");
1283 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001284
Sonic Zhanga482b082012-05-25 17:54:13 +08001285 case 110:
1286 ret += tcrypt_test("hmac(crc32)");
1287 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001288
raveendra padasalagi98eca722016-07-01 11:16:54 +05301289 case 111:
1290 ret += tcrypt_test("hmac(sha3-224)");
1291 break;
1292
1293 case 112:
1294 ret += tcrypt_test("hmac(sha3-256)");
1295 break;
1296
1297 case 113:
1298 ret += tcrypt_test("hmac(sha3-384)");
1299 break;
1300
1301 case 114:
1302 ret += tcrypt_test("hmac(sha3-512)");
1303 break;
1304
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001305 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001306 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001307 break;
1308
Adrian Hoban69435b92010-11-04 15:02:04 -04001309 case 151:
1310 ret += tcrypt_test("rfc4106(gcm(aes))");
1311 break;
1312
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001313 case 152:
1314 ret += tcrypt_test("rfc4543(gcm(aes))");
1315 break;
1316
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001317 case 153:
1318 ret += tcrypt_test("cmac(aes)");
1319 break;
1320
1321 case 154:
1322 ret += tcrypt_test("cmac(des3_ede)");
1323 break;
1324
Horia Geantabbf9c892013-11-28 15:11:16 +02001325 case 155:
1326 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1327 break;
1328
Horia Geantabca4feb2014-03-14 17:46:51 +02001329 case 156:
1330 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1331 break;
1332
1333 case 157:
1334 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1335 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301336 case 181:
1337 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1338 break;
1339 case 182:
1340 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1341 break;
1342 case 183:
1343 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1344 break;
1345 case 184:
1346 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1347 break;
1348 case 185:
1349 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1350 break;
1351 case 186:
1352 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1353 break;
1354 case 187:
1355 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1356 break;
1357 case 188:
1358 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1359 break;
1360 case 189:
1361 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1362 break;
1363 case 190:
1364 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1365 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001366 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001367 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001368 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001369 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001370 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001371 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001372 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001373 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001374 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001375 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001376 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001377 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001378 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001379 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001380 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001381 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001382 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001383 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1384 speed_template_16_24_32);
1385 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1386 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10001387 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1388 speed_template_16_24_32);
1389 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1390 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001391 break;
1392
1393 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001394 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001395 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001396 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001397 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001398 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001399 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001400 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001401 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001402 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001403 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001404 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001405 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001406 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1407 des3_speed_template, DES3_SPEED_VECTORS,
1408 speed_template_24);
1409 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1410 des3_speed_template, DES3_SPEED_VECTORS,
1411 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001412 break;
1413
1414 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001415 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001416 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001417 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001418 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001419 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001420 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001421 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001422 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001423 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1424 speed_template_16_24_32);
1425 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1426 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001427 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1428 speed_template_32_40_48);
1429 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1430 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001431 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1432 speed_template_32_48_64);
1433 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1434 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001435 break;
1436
1437 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001438 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001439 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001440 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001441 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001442 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001443 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001444 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001445 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001446 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1447 speed_template_8_32);
1448 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1449 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001450 break;
1451
1452 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001453 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001454 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001455 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001456 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001457 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001458 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001459 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001460 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001461 break;
1462
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001463 case 205:
1464 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001465 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001466 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001467 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001468 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001469 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001470 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001471 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001472 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1473 speed_template_16_24_32);
1474 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1475 speed_template_16_24_32);
1476 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1477 speed_template_32_40_48);
1478 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1479 speed_template_32_40_48);
1480 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1481 speed_template_32_48_64);
1482 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1483 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001484 break;
1485
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001486 case 206:
1487 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001488 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001489 break;
1490
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001491 case 207:
1492 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1493 speed_template_16_32);
1494 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1495 speed_template_16_32);
1496 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1497 speed_template_16_32);
1498 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1499 speed_template_16_32);
1500 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1501 speed_template_16_32);
1502 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1503 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001504 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1505 speed_template_32_48);
1506 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1507 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001508 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1509 speed_template_32_64);
1510 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1511 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001512 break;
1513
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001514 case 208:
1515 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1516 speed_template_8);
1517 break;
1518
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001519 case 209:
1520 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1521 speed_template_8_16);
1522 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1523 speed_template_8_16);
1524 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1525 speed_template_8_16);
1526 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1527 speed_template_8_16);
1528 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1529 speed_template_8_16);
1530 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1531 speed_template_8_16);
1532 break;
1533
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001534 case 210:
1535 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1536 speed_template_16_32);
1537 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1538 speed_template_16_32);
1539 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1540 speed_template_16_32);
1541 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1542 speed_template_16_32);
1543 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1544 speed_template_16_32);
1545 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1546 speed_template_16_32);
1547 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1548 speed_template_32_48);
1549 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1550 speed_template_32_48);
1551 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1552 speed_template_32_64);
1553 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1554 speed_template_32_64);
1555 break;
1556
Tim Chen53f52d72013-12-11 14:28:47 -08001557 case 211:
1558 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001559 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05301560 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01001561 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08001562 break;
1563
Herbert Xu4e4aab62015-06-17 14:04:21 +08001564 case 212:
1565 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001566 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08001567 break;
1568
Martin Willi2dce0632015-07-16 19:13:59 +02001569 case 213:
1570 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1571 NULL, 0, 16, 8, aead_speed_template_36);
1572 break;
1573
1574 case 214:
1575 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1576 speed_template_32);
1577 break;
1578
Michal Ludvige8057922006-05-30 22:04:19 +10001579 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001580 if (alg) {
1581 test_hash_speed(alg, sec, generic_hash_speed_template);
1582 break;
1583 }
Michal Ludvige8057922006-05-30 22:04:19 +10001584 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001585 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001586 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001587 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001588 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001589 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001590 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001591 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001592 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001593 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001594 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001595 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001596 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001597 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001598 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001599 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001600 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001601 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001602 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001603 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001604 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001605 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001606 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001607 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001608 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001609 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001610 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001611 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001612 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001613 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001614 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001615 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001616 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001617 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001618 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001619 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001620 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001621 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001622 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001623 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001624 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001625 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001626 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001627 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001628 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001629 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001630 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001631 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001632 /* fall through */
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001633 case 313:
1634 test_hash_speed("sha224", sec, generic_hash_speed_template);
1635 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001636 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001637 case 314:
1638 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1639 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001640 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001641 case 315:
1642 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1643 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001644 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001645 case 316:
1646 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1647 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001648 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001649 case 317:
1650 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1651 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001652 /* fall through */
Huang Ying18bcc912010-03-10 18:30:32 +08001653 case 318:
1654 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1655 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001656 /* fall through */
Tim Chene3899e42012-09-27 15:44:24 -07001657 case 319:
1658 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1659 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001660 /* fall through */
Herbert Xu684115212013-09-07 12:56:26 +10001661 case 320:
1662 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1663 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001664 /* fall through */
Martin Willi2dce0632015-07-16 19:13:59 +02001665 case 321:
1666 test_hash_speed("poly1305", sec, poly1305_speed_template);
1667 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001668 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301669 case 322:
1670 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
1671 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001672 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301673 case 323:
1674 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
1675 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001676 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301677 case 324:
1678 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
1679 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001680 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301681 case 325:
1682 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
1683 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001684 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001685 case 326:
1686 test_hash_speed("sm3", sec, generic_hash_speed_template);
1687 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001688 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001689 case 399:
1690 break;
1691
David S. Millerbeb63da2010-05-19 14:11:21 +10001692 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08001693 if (alg) {
1694 test_ahash_speed(alg, sec, generic_hash_speed_template);
1695 break;
1696 }
David S. Millerbeb63da2010-05-19 14:11:21 +10001697 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001698 case 401:
1699 test_ahash_speed("md4", sec, generic_hash_speed_template);
1700 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001701 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001702 case 402:
1703 test_ahash_speed("md5", sec, generic_hash_speed_template);
1704 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001705 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001706 case 403:
1707 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1708 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001709 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001710 case 404:
1711 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1712 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001713 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001714 case 405:
1715 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1716 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001717 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001718 case 406:
1719 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1720 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001721 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001722 case 407:
1723 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1724 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001725 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001726 case 408:
1727 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1728 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001729 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001730 case 409:
1731 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1732 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001733 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001734 case 410:
1735 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1736 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001737 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001738 case 411:
1739 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1740 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001741 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001742 case 412:
1743 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1744 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001745 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001746 case 413:
1747 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1748 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001749 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001750 case 414:
1751 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1752 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001753 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001754 case 415:
1755 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1756 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001757 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001758 case 416:
1759 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1760 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001761 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001762 case 417:
1763 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1764 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001765 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301766 case 418:
1767 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
1768 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001769 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301770 case 419:
1771 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
1772 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001773 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301774 case 420:
1775 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
1776 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001777 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301778 case 421:
1779 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
1780 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001781 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001782 case 422:
1783 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template);
1784 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001785 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001786 case 423:
1787 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template);
1788 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001789 /* fall through */
Megha Dey14009c42016-06-27 10:20:09 -07001790 case 424:
1791 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template);
1792 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001793 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001794 case 425:
1795 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template);
1796 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001797 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001798 case 499:
1799 break;
1800
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001801 case 500:
1802 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1803 speed_template_16_24_32);
1804 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1805 speed_template_16_24_32);
1806 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1807 speed_template_16_24_32);
1808 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1809 speed_template_16_24_32);
1810 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1811 speed_template_32_40_48);
1812 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1813 speed_template_32_40_48);
1814 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001815 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001816 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001817 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001818 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1819 speed_template_16_24_32);
1820 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1821 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001822 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1823 speed_template_16_24_32);
1824 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1825 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02001826 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1827 speed_template_16_24_32);
1828 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1829 speed_template_16_24_32);
1830 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1831 speed_template_16_24_32);
1832 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1833 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02001834 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1835 speed_template_20_28_36);
1836 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1837 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001838 break;
1839
1840 case 501:
1841 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1842 des3_speed_template, DES3_SPEED_VECTORS,
1843 speed_template_24);
1844 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1845 des3_speed_template, DES3_SPEED_VECTORS,
1846 speed_template_24);
1847 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1848 des3_speed_template, DES3_SPEED_VECTORS,
1849 speed_template_24);
1850 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1851 des3_speed_template, DES3_SPEED_VECTORS,
1852 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02001853 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1854 des3_speed_template, DES3_SPEED_VECTORS,
1855 speed_template_24);
1856 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1857 des3_speed_template, DES3_SPEED_VECTORS,
1858 speed_template_24);
1859 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1860 des3_speed_template, DES3_SPEED_VECTORS,
1861 speed_template_24);
1862 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1863 des3_speed_template, DES3_SPEED_VECTORS,
1864 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001865 break;
1866
1867 case 502:
1868 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1869 speed_template_8);
1870 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1871 speed_template_8);
1872 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1873 speed_template_8);
1874 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1875 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02001876 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1877 speed_template_8);
1878 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1879 speed_template_8);
1880 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1881 speed_template_8);
1882 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1883 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001884 break;
1885
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001886 case 503:
1887 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1888 speed_template_16_32);
1889 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1890 speed_template_16_32);
1891 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1892 speed_template_16_32);
1893 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1894 speed_template_16_32);
1895 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1896 speed_template_16_32);
1897 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1898 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001899 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1900 speed_template_32_48);
1901 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1902 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001903 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1904 speed_template_32_64);
1905 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1906 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001907 break;
1908
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001909 case 504:
1910 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1911 speed_template_16_24_32);
1912 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1913 speed_template_16_24_32);
1914 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1915 speed_template_16_24_32);
1916 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1917 speed_template_16_24_32);
1918 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1919 speed_template_16_24_32);
1920 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1921 speed_template_16_24_32);
1922 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1923 speed_template_32_40_48);
1924 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1925 speed_template_32_40_48);
1926 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1927 speed_template_32_48_64);
1928 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1929 speed_template_32_48_64);
1930 break;
1931
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001932 case 505:
1933 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1934 speed_template_8);
1935 break;
1936
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001937 case 506:
1938 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1939 speed_template_8_16);
1940 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1941 speed_template_8_16);
1942 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1943 speed_template_8_16);
1944 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1945 speed_template_8_16);
1946 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1947 speed_template_8_16);
1948 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1949 speed_template_8_16);
1950 break;
1951
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001952 case 507:
1953 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1954 speed_template_16_32);
1955 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1956 speed_template_16_32);
1957 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1958 speed_template_16_32);
1959 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1960 speed_template_16_32);
1961 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1962 speed_template_16_32);
1963 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1964 speed_template_16_32);
1965 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1966 speed_template_32_48);
1967 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1968 speed_template_32_48);
1969 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1970 speed_template_32_64);
1971 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1972 speed_template_32_64);
1973 break;
1974
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03001975 case 508:
1976 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1977 speed_template_16_32);
1978 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1979 speed_template_16_32);
1980 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1981 speed_template_16_32);
1982 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1983 speed_template_16_32);
1984 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1985 speed_template_16_32);
1986 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1987 speed_template_16_32);
1988 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1989 speed_template_32_48);
1990 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1991 speed_template_32_48);
1992 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1993 speed_template_32_64);
1994 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1995 speed_template_32_64);
1996 break;
1997
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03001998 case 509:
1999 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2000 speed_template_8_32);
2001 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2002 speed_template_8_32);
2003 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2004 speed_template_8_32);
2005 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2006 speed_template_8_32);
2007 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2008 speed_template_8_32);
2009 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2010 speed_template_8_32);
2011 break;
2012
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 case 1000:
2014 test_available();
2015 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002017
2018 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019}
2020
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002021static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002023 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002024 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002025
Herbert Xuf139cfa2008-07-31 12:23:53 +08002026 for (i = 0; i < TVMEMSIZE; i++) {
2027 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2028 if (!tvmem[i])
2029 goto err_free_tv;
2030 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Herbert Xu86068132014-12-04 16:43:29 +08002032 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002033
Jarod Wilson4e033a62009-05-27 15:10:21 +10002034 if (err) {
2035 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2036 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01002037 } else {
2038 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10002039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Jarod Wilson4e033a62009-05-27 15:10:21 +10002041 /* We intentionaly return -EAGAIN to prevent keeping the module,
2042 * unless we're running in fips mode. It does all its work from
2043 * init() and doesn't offer any runtime functionality, but in
2044 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002045 * => we don't need it in the memory, do we?
2046 * -- mludvig
2047 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002048 if (!fips_enabled)
2049 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002050
Herbert Xuf139cfa2008-07-31 12:23:53 +08002051err_free_tv:
2052 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2053 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002054
2055 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056}
2057
2058/*
2059 * If an init function is provided, an exit function must also be provided
2060 * to allow module unload.
2061 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002062static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002064module_init(tcrypt_mod_init);
2065module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002067module_param(alg, charp, 0);
2068module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002069module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002071module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002072MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2073 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075MODULE_LICENSE("GPL");
2076MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2077MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");