blob: d617c1956533c353f07d103bbe9893f63c7dec25 [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;
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +000070static u32 num_mb = 8;
Herbert Xuf139cfa2008-07-31 12:23:53 +080071static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73static char *check[] = {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +030074 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080075 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110077 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080078 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +053079 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
80 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053083static inline int do_one_aead_op(struct aead_request *req, int ret)
84{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010085 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053086
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010087 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053088}
89
Tim Chen53f52d72013-12-11 14:28:47 -080090static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070091 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -080092{
93 unsigned long start, end;
94 int bcount;
95 int ret;
96
Mark Rustad3e3dc252014-07-25 02:53:38 -070097 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -080098 time_before(jiffies, end); bcount++) {
99 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530100 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800101 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530102 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800103
104 if (ret)
105 return ret;
106 }
107
108 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700109 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800110 return 0;
111}
112
113static int test_aead_cycles(struct aead_request *req, int enc, int blen)
114{
115 unsigned long cycles = 0;
116 int ret = 0;
117 int i;
118
Tim Chen53f52d72013-12-11 14:28:47 -0800119 /* Warm-up run. */
120 for (i = 0; i < 4; i++) {
121 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530122 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800123 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530124 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800125
126 if (ret)
127 goto out;
128 }
129
130 /* The real thing. */
131 for (i = 0; i < 8; i++) {
132 cycles_t start, end;
133
134 start = get_cycles();
135 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530136 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800137 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530138 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800139 end = get_cycles();
140
141 if (ret)
142 goto out;
143
144 cycles += end - start;
145 }
146
147out:
Tim Chen53f52d72013-12-11 14:28:47 -0800148 if (ret == 0)
149 printk("1 operation in %lu cycles (%d bytes)\n",
150 (cycles + 4) / 8, blen);
151
152 return ret;
153}
154
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800155static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800156static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
157
158#define XBUFSIZE 8
159#define MAX_IVLEN 32
160
161static int testmgr_alloc_buf(char *buf[XBUFSIZE])
162{
163 int i;
164
165 for (i = 0; i < XBUFSIZE; i++) {
166 buf[i] = (void *)__get_free_page(GFP_KERNEL);
167 if (!buf[i])
168 goto err_free_buf;
169 }
170
171 return 0;
172
173err_free_buf:
174 while (i-- > 0)
175 free_page((unsigned long)buf[i]);
176
177 return -ENOMEM;
178}
179
180static void testmgr_free_buf(char *buf[XBUFSIZE])
181{
182 int i;
183
184 for (i = 0; i < XBUFSIZE; i++)
185 free_page((unsigned long)buf[i]);
186}
187
188static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200189 unsigned int buflen, const void *assoc,
190 unsigned int aad_size)
Tim Chen53f52d72013-12-11 14:28:47 -0800191{
192 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
193 int k, rem;
194
Tim Chen53f52d72013-12-11 14:28:47 -0800195 if (np > XBUFSIZE) {
196 rem = PAGE_SIZE;
197 np = XBUFSIZE;
Cristian Stoicac4768992015-01-27 11:54:27 +0200198 } else {
199 rem = buflen % PAGE_SIZE;
Tim Chen53f52d72013-12-11 14:28:47 -0800200 }
Cristian Stoicac4768992015-01-27 11:54:27 +0200201
Herbert Xu31267272015-06-17 14:05:26 +0800202 sg_init_table(sg, np + 1);
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200203
204 sg_set_buf(&sg[0], assoc, aad_size);
205
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300206 if (rem)
207 np--;
Cristian Stoicac4768992015-01-27 11:54:27 +0200208 for (k = 0; k < np; k++)
Herbert Xu31267272015-06-17 14:05:26 +0800209 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
Cristian Stoicac4768992015-01-27 11:54:27 +0200210
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300211 if (rem)
212 sg_set_buf(&sg[k + 1], xbuf[k], rem);
Tim Chen53f52d72013-12-11 14:28:47 -0800213}
214
Mark Rustad3e3dc252014-07-25 02:53:38 -0700215static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800216 struct aead_speed_template *template,
217 unsigned int tcount, u8 authsize,
218 unsigned int aad_size, u8 *keysize)
219{
220 unsigned int i, j;
221 struct crypto_aead *tfm;
222 int ret = -ENOMEM;
223 const char *key;
224 struct aead_request *req;
225 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800226 struct scatterlist *sgout;
227 const char *e;
228 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200229 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800230 char *xbuf[XBUFSIZE];
231 char *xoutbuf[XBUFSIZE];
232 char *axbuf[XBUFSIZE];
233 unsigned int *b_size;
234 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100235 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800236
Cristian Stoica96692a732015-01-28 13:07:32 +0200237 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
238 if (!iv)
239 return;
240
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200241 if (aad_size >= PAGE_SIZE) {
242 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200243 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200244 }
245
Tim Chen53f52d72013-12-11 14:28:47 -0800246 if (enc == ENCRYPT)
247 e = "encryption";
248 else
249 e = "decryption";
250
251 if (testmgr_alloc_buf(xbuf))
252 goto out_noxbuf;
253 if (testmgr_alloc_buf(axbuf))
254 goto out_noaxbuf;
255 if (testmgr_alloc_buf(xoutbuf))
256 goto out_nooutbuf;
257
Herbert Xua3f21852015-05-27 16:03:51 +0800258 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800259 if (!sg)
260 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800261 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800262
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800263 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800264
265 if (IS_ERR(tfm)) {
266 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
267 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200268 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800269 }
270
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100271 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700272 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
273 get_driver_name(crypto_aead, tfm), e);
274
Tim Chen53f52d72013-12-11 14:28:47 -0800275 req = aead_request_alloc(tfm, GFP_KERNEL);
276 if (!req) {
277 pr_err("alg: aead: Failed to allocate request for %s\n",
278 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200279 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800280 }
281
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530282 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100283 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530284
Tim Chen53f52d72013-12-11 14:28:47 -0800285 i = 0;
286 do {
287 b_size = aead_sizes;
288 do {
289 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200290 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800291
292 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
293 pr_err("template (%u) too big for tvmem (%lu)\n",
294 *keysize + *b_size,
295 TVMEMSIZE * PAGE_SIZE);
296 goto out;
297 }
298
299 key = tvmem[0];
300 for (j = 0; j < tcount; j++) {
301 if (template[j].klen == *keysize) {
302 key = template[j].key;
303 break;
304 }
305 }
306 ret = crypto_aead_setkey(tfm, key, *keysize);
307 ret = crypto_aead_setauthsize(tfm, authsize);
308
309 iv_len = crypto_aead_ivsize(tfm);
310 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200311 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800312
313 crypto_aead_clear_flags(tfm, ~0);
314 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
315 i, *keysize * 8, *b_size);
316
317
318 memset(tvmem[0], 0xff, PAGE_SIZE);
319
320 if (ret) {
321 pr_err("setkey() failed flags=%x\n",
322 crypto_aead_get_flags(tfm));
323 goto out;
324 }
325
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200326 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
327 assoc, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800328
Herbert Xu31267272015-06-17 14:05:26 +0800329 sg_init_aead(sgout, xoutbuf,
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200330 *b_size + (enc ? authsize : 0), assoc,
331 aad_size);
Herbert Xu31267272015-06-17 14:05:26 +0800332
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +0000333 aead_request_set_ad(req, aad_size);
334
335 if (!enc) {
336
337 /*
338 * For decryption we need a proper auth so
339 * we do the encryption path once with buffers
340 * reversed (input <-> output) to calculate it
341 */
342 aead_request_set_crypt(req, sgout, sg,
343 *b_size, iv);
344 ret = do_one_aead_op(req,
345 crypto_aead_encrypt(req));
346
347 if (ret) {
348 pr_err("calculating auth failed failed (%d)\n",
349 ret);
350 break;
351 }
352 }
353
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300354 aead_request_set_crypt(req, sg, sgout,
355 *b_size + (enc ? 0 : authsize),
356 iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800357
Mark Rustad3e3dc252014-07-25 02:53:38 -0700358 if (secs)
359 ret = test_aead_jiffies(req, enc, *b_size,
360 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800361 else
362 ret = test_aead_cycles(req, enc, *b_size);
363
364 if (ret) {
365 pr_err("%s() failed return code=%d\n", e, ret);
366 break;
367 }
368 b_size++;
369 i++;
370 } while (*b_size);
371 keysize++;
372 } while (*keysize);
373
374out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200375 aead_request_free(req);
376out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800377 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200378out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800379 kfree(sg);
380out_nosg:
381 testmgr_free_buf(xoutbuf);
382out_nooutbuf:
383 testmgr_free_buf(axbuf);
384out_noaxbuf:
385 testmgr_free_buf(xbuf);
386out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200387 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800388}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800389
David S. Millerbeb63da2010-05-19 14:11:21 +1000390static void test_hash_sg_init(struct scatterlist *sg)
391{
392 int i;
393
394 sg_init_table(sg, TVMEMSIZE);
395 for (i = 0; i < TVMEMSIZE; i++) {
396 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
397 memset(tvmem[i], 0xff, PAGE_SIZE);
398 }
399}
400
David S. Millerbeb63da2010-05-19 14:11:21 +1000401static inline int do_one_ahash_op(struct ahash_request *req, int ret)
402{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100403 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000404
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100405 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000406}
407
Herbert Xu72259de2016-06-28 20:33:52 +0800408struct test_mb_ahash_data {
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000409 struct scatterlist sg[XBUFSIZE];
Herbert Xu72259de2016-06-28 20:33:52 +0800410 char result[64];
411 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100412 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800413 char *xbuf[XBUFSIZE];
414};
Megha Dey087bcd22016-06-23 18:40:47 -0700415
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000416static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb)
417{
418 int i, rc[num_mb], err = 0;
419
420 /* Fire up a bunch of concurrent requests */
421 for (i = 0; i < num_mb; i++)
422 rc[i] = crypto_ahash_digest(data[i].req);
423
424 /* Wait for all requests to finish */
425 for (i = 0; i < num_mb; i++) {
426 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
427
428 if (rc[i]) {
429 pr_info("concurrent request %d error %d\n", i, rc[i]);
430 err = rc[i];
431 }
432 }
433
434 return err;
435}
436
437static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
438 int secs, u32 num_mb)
439{
440 unsigned long start, end;
441 int bcount;
442 int ret;
443
444 for (start = jiffies, end = start + secs * HZ, bcount = 0;
445 time_before(jiffies, end); bcount++) {
446 ret = do_mult_ahash_op(data, num_mb);
447 if (ret)
448 return ret;
449 }
450
451 pr_cont("%d operations in %d seconds (%ld bytes)\n",
452 bcount * num_mb, secs, (long)bcount * blen * num_mb);
453 return 0;
454}
455
456static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
457 u32 num_mb)
458{
459 unsigned long cycles = 0;
460 int ret = 0;
461 int i;
462
463 /* Warm-up run. */
464 for (i = 0; i < 4; i++) {
465 ret = do_mult_ahash_op(data, num_mb);
466 if (ret)
467 goto out;
468 }
469
470 /* The real thing. */
471 for (i = 0; i < 8; i++) {
472 cycles_t start, end;
473
474 start = get_cycles();
475 ret = do_mult_ahash_op(data, num_mb);
476 end = get_cycles();
477
478 if (ret)
479 goto out;
480
481 cycles += end - start;
482 }
483
484out:
485 if (ret == 0)
486 pr_cont("1 operation in %lu cycles (%d bytes)\n",
487 (cycles + 4) / (8 * num_mb), blen);
488
489 return ret;
490}
491
492static void test_mb_ahash_speed(const char *algo, unsigned int secs,
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000493 struct hash_speed *speed, u32 num_mb)
Megha Dey087bcd22016-06-23 18:40:47 -0700494{
Herbert Xu72259de2016-06-28 20:33:52 +0800495 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700496 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800497 unsigned int i, j, k;
498 int ret;
499
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000500 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
Herbert Xu72259de2016-06-28 20:33:52 +0800501 if (!data)
502 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700503
504 tfm = crypto_alloc_ahash(algo, 0, 0);
505 if (IS_ERR(tfm)) {
506 pr_err("failed to load transform for %s: %ld\n",
507 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800508 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700509 }
Herbert Xu72259de2016-06-28 20:33:52 +0800510
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000511 for (i = 0; i < num_mb; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800512 if (testmgr_alloc_buf(data[i].xbuf))
513 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700514
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100515 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700516
Herbert Xu72259de2016-06-28 20:33:52 +0800517 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
518 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200519 pr_err("alg: hash: Failed to allocate request for %s\n",
520 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800521 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700522 }
Megha Dey087bcd22016-06-23 18:40:47 -0700523
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100524 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
525 &data[i].wait);
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000526
527 sg_init_table(data[i].sg, XBUFSIZE);
528 for (j = 0; j < XBUFSIZE; j++) {
529 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
530 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
531 }
Megha Dey087bcd22016-06-23 18:40:47 -0700532 }
533
Herbert Xu72259de2016-06-28 20:33:52 +0800534 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
535 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700536
537 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800538 /* For some reason this only tests digests. */
539 if (speed[i].blen != speed[i].plen)
540 continue;
541
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000542 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200543 pr_err("template (%u) too big for tvmem (%lu)\n",
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000544 speed[i].blen, XBUFSIZE * PAGE_SIZE);
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200545 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700546 }
547
548 if (speed[i].klen)
549 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
550
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000551 for (k = 0; k < num_mb; k++)
Herbert Xu72259de2016-06-28 20:33:52 +0800552 ahash_request_set_crypt(data[k].req, data[k].sg,
553 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700554
Herbert Xu72259de2016-06-28 20:33:52 +0800555 pr_info("test%3u "
556 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700557 i, speed[i].blen, speed[i].plen,
558 speed[i].blen / speed[i].plen);
559
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000560 if (secs)
561 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
562 num_mb);
563 else
564 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
Herbert Xu72259de2016-06-28 20:33:52 +0800565
Herbert Xu72259de2016-06-28 20:33:52 +0800566
567 if (ret) {
568 pr_err("At least one hashing failed ret=%d\n", ret);
569 break;
570 }
Megha Dey087bcd22016-06-23 18:40:47 -0700571 }
Megha Dey087bcd22016-06-23 18:40:47 -0700572
573out:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000574 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800575 ahash_request_free(data[k].req);
576
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000577 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800578 testmgr_free_buf(data[k].xbuf);
579
580 crypto_free_ahash(tfm);
581
582free_data:
583 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700584}
585
David S. Millerbeb63da2010-05-19 14:11:21 +1000586static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700587 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000588{
589 unsigned long start, end;
590 int bcount;
591 int ret;
592
Mark Rustad3e3dc252014-07-25 02:53:38 -0700593 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000594 time_before(jiffies, end); bcount++) {
595 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
596 if (ret)
597 return ret;
598 }
599
600 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700601 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000602
603 return 0;
604}
605
606static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700607 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000608{
609 unsigned long start, end;
610 int bcount, pcount;
611 int ret;
612
613 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700614 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000615
Mark Rustad3e3dc252014-07-25 02:53:38 -0700616 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000617 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800618 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000619 if (ret)
620 return ret;
621 for (pcount = 0; pcount < blen; pcount += plen) {
622 ret = do_one_ahash_op(req, crypto_ahash_update(req));
623 if (ret)
624 return ret;
625 }
626 /* we assume there is enough space in 'out' for the result */
627 ret = do_one_ahash_op(req, crypto_ahash_final(req));
628 if (ret)
629 return ret;
630 }
631
632 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700633 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000634
635 return 0;
636}
637
638static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
639 char *out)
640{
641 unsigned long cycles = 0;
642 int ret, i;
643
644 /* Warm-up run. */
645 for (i = 0; i < 4; i++) {
646 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
647 if (ret)
648 goto out;
649 }
650
651 /* The real thing. */
652 for (i = 0; i < 8; i++) {
653 cycles_t start, end;
654
655 start = get_cycles();
656
657 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
658 if (ret)
659 goto out;
660
661 end = get_cycles();
662
663 cycles += end - start;
664 }
665
666out:
667 if (ret)
668 return ret;
669
670 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
671 cycles / 8, cycles / (8 * blen));
672
673 return 0;
674}
675
676static int test_ahash_cycles(struct ahash_request *req, int blen,
677 int plen, char *out)
678{
679 unsigned long cycles = 0;
680 int i, pcount, ret;
681
682 if (plen == blen)
683 return test_ahash_cycles_digest(req, blen, out);
684
685 /* Warm-up run. */
686 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800687 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000688 if (ret)
689 goto out;
690 for (pcount = 0; pcount < blen; pcount += plen) {
691 ret = do_one_ahash_op(req, crypto_ahash_update(req));
692 if (ret)
693 goto out;
694 }
695 ret = do_one_ahash_op(req, crypto_ahash_final(req));
696 if (ret)
697 goto out;
698 }
699
700 /* The real thing. */
701 for (i = 0; i < 8; i++) {
702 cycles_t start, end;
703
704 start = get_cycles();
705
Herbert Xu43a96072015-04-22 11:02:27 +0800706 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000707 if (ret)
708 goto out;
709 for (pcount = 0; pcount < blen; pcount += plen) {
710 ret = do_one_ahash_op(req, crypto_ahash_update(req));
711 if (ret)
712 goto out;
713 }
714 ret = do_one_ahash_op(req, crypto_ahash_final(req));
715 if (ret)
716 goto out;
717
718 end = get_cycles();
719
720 cycles += end - start;
721 }
722
723out:
724 if (ret)
725 return ret;
726
727 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
728 cycles / 8, cycles / (8 * blen));
729
730 return 0;
731}
732
Herbert Xu06605112016-02-01 21:36:49 +0800733static void test_ahash_speed_common(const char *algo, unsigned int secs,
734 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +1000735{
736 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100737 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +1000738 struct ahash_request *req;
739 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +0300740 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +1000741 int i, ret;
742
Herbert Xu06605112016-02-01 21:36:49 +0800743 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +1000744 if (IS_ERR(tfm)) {
745 pr_err("failed to load transform for %s: %ld\n",
746 algo, PTR_ERR(tfm));
747 return;
748 }
749
Luca Clementi263a8df2014-06-25 22:57:42 -0700750 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
751 get_driver_name(crypto_ahash, tfm));
752
Horia Geant?f074f7b2015-08-27 18:38:36 +0300753 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
754 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
755 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +1000756 goto out;
757 }
758
759 test_hash_sg_init(sg);
760 req = ahash_request_alloc(tfm, GFP_KERNEL);
761 if (!req) {
762 pr_err("ahash request allocation failure\n");
763 goto out;
764 }
765
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100766 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000767 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100768 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000769
Horia Geant?f074f7b2015-08-27 18:38:36 +0300770 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
771 if (!output)
772 goto out_nomem;
773
David S. Millerbeb63da2010-05-19 14:11:21 +1000774 for (i = 0; speed[i].blen != 0; i++) {
775 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
776 pr_err("template (%u) too big for tvmem (%lu)\n",
777 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
778 break;
779 }
780
781 pr_info("test%3u "
782 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
783 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
784
785 ahash_request_set_crypt(req, sg, output, speed[i].plen);
786
Mark Rustad3e3dc252014-07-25 02:53:38 -0700787 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000788 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700789 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000790 else
791 ret = test_ahash_cycles(req, speed[i].blen,
792 speed[i].plen, output);
793
794 if (ret) {
795 pr_err("hashing failed ret=%d\n", ret);
796 break;
797 }
798 }
799
Horia Geant?f074f7b2015-08-27 18:38:36 +0300800 kfree(output);
801
802out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +1000803 ahash_request_free(req);
804
805out:
806 crypto_free_ahash(tfm);
807}
808
Herbert Xu06605112016-02-01 21:36:49 +0800809static void test_ahash_speed(const char *algo, unsigned int secs,
810 struct hash_speed *speed)
811{
812 return test_ahash_speed_common(algo, secs, speed, 0);
813}
814
815static void test_hash_speed(const char *algo, unsigned int secs,
816 struct hash_speed *speed)
817{
818 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
819}
820
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +0000821struct test_mb_skcipher_data {
822 struct scatterlist sg[XBUFSIZE];
823 struct skcipher_request *req;
824 struct crypto_wait wait;
825 char *xbuf[XBUFSIZE];
826};
827
828static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
829 u32 num_mb)
830{
831 int i, rc[num_mb], err = 0;
832
833 /* Fire up a bunch of concurrent requests */
834 for (i = 0; i < num_mb; i++) {
835 if (enc == ENCRYPT)
836 rc[i] = crypto_skcipher_encrypt(data[i].req);
837 else
838 rc[i] = crypto_skcipher_decrypt(data[i].req);
839 }
840
841 /* Wait for all requests to finish */
842 for (i = 0; i < num_mb; i++) {
843 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
844
845 if (rc[i]) {
846 pr_info("concurrent request %d error %d\n", i, rc[i]);
847 err = rc[i];
848 }
849 }
850
851 return err;
852}
853
854static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
855 int blen, int secs, u32 num_mb)
856{
857 unsigned long start, end;
858 int bcount;
859 int ret;
860
861 for (start = jiffies, end = start + secs * HZ, bcount = 0;
862 time_before(jiffies, end); bcount++) {
863 ret = do_mult_acipher_op(data, enc, num_mb);
864 if (ret)
865 return ret;
866 }
867
868 pr_cont("%d operations in %d seconds (%ld bytes)\n",
869 bcount * num_mb, secs, (long)bcount * blen * num_mb);
870 return 0;
871}
872
873static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
874 int blen, u32 num_mb)
875{
876 unsigned long cycles = 0;
877 int ret = 0;
878 int i;
879
880 /* Warm-up run. */
881 for (i = 0; i < 4; i++) {
882 ret = do_mult_acipher_op(data, enc, num_mb);
883 if (ret)
884 goto out;
885 }
886
887 /* The real thing. */
888 for (i = 0; i < 8; i++) {
889 cycles_t start, end;
890
891 start = get_cycles();
892 ret = do_mult_acipher_op(data, enc, num_mb);
893 end = get_cycles();
894
895 if (ret)
896 goto out;
897
898 cycles += end - start;
899 }
900
901out:
902 if (ret == 0)
903 pr_cont("1 operation in %lu cycles (%d bytes)\n",
904 (cycles + 4) / (8 * num_mb), blen);
905
906 return ret;
907}
908
909static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
910 struct cipher_speed_template *template,
911 unsigned int tcount, u8 *keysize, u32 num_mb)
912{
913 struct test_mb_skcipher_data *data;
914 struct crypto_skcipher *tfm;
915 unsigned int i, j, iv_len;
916 const char *key;
917 const char *e;
918 u32 *b_size;
919 char iv[128];
920 int ret;
921
922 if (enc == ENCRYPT)
923 e = "encryption";
924 else
925 e = "decryption";
926
927 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
928 if (!data)
929 return;
930
931 tfm = crypto_alloc_skcipher(algo, 0, 0);
932 if (IS_ERR(tfm)) {
933 pr_err("failed to load transform for %s: %ld\n",
934 algo, PTR_ERR(tfm));
935 goto out_free_data;
936 }
937
938 for (i = 0; i < num_mb; ++i)
939 if (testmgr_alloc_buf(data[i].xbuf)) {
940 while (i--)
941 testmgr_free_buf(data[i].xbuf);
942 goto out_free_tfm;
943 }
944
945
946 for (i = 0; i < num_mb; ++i)
947 if (testmgr_alloc_buf(data[i].xbuf)) {
948 while (i--)
949 testmgr_free_buf(data[i].xbuf);
950 goto out_free_tfm;
951 }
952
953
954 for (i = 0; i < num_mb; ++i) {
955 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
956 if (!data[i].req) {
957 pr_err("alg: skcipher: Failed to allocate request for %s\n",
958 algo);
959 while (i--)
960 skcipher_request_free(data[i].req);
961 goto out_free_xbuf;
962 }
963 }
964
965 for (i = 0; i < num_mb; ++i) {
966 skcipher_request_set_callback(data[i].req,
967 CRYPTO_TFM_REQ_MAY_BACKLOG,
968 crypto_req_done, &data[i].wait);
969 crypto_init_wait(&data[i].wait);
970 }
971
972 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
973 get_driver_name(crypto_skcipher, tfm), e);
974
975 i = 0;
976 do {
977 b_size = block_sizes;
978 do {
979 if (*b_size > XBUFSIZE * PAGE_SIZE) {
980 pr_err("template (%u) too big for bufufer (%lu)\n",
981 *b_size, XBUFSIZE * PAGE_SIZE);
982 goto out;
983 }
984
985 pr_info("test %u (%d bit key, %d byte blocks): ", i,
986 *keysize * 8, *b_size);
987
988 /* Set up tfm global state, i.e. the key */
989
990 memset(tvmem[0], 0xff, PAGE_SIZE);
991 key = tvmem[0];
992 for (j = 0; j < tcount; j++) {
993 if (template[j].klen == *keysize) {
994 key = template[j].key;
995 break;
996 }
997 }
998
999 crypto_skcipher_clear_flags(tfm, ~0);
1000
1001 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1002 if (ret) {
1003 pr_err("setkey() failed flags=%x\n",
1004 crypto_skcipher_get_flags(tfm));
1005 goto out;
1006 }
1007
1008 iv_len = crypto_skcipher_ivsize(tfm);
1009 if (iv_len)
1010 memset(&iv, 0xff, iv_len);
1011
1012 /* Now setup per request stuff, i.e. buffers */
1013
1014 for (j = 0; j < num_mb; ++j) {
1015 struct test_mb_skcipher_data *cur = &data[j];
1016 unsigned int k = *b_size;
1017 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1018 unsigned int p = 0;
1019
1020 sg_init_table(cur->sg, pages);
1021
1022 while (k > PAGE_SIZE) {
1023 sg_set_buf(cur->sg + p, cur->xbuf[p],
1024 PAGE_SIZE);
1025 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1026 p++;
1027 k -= PAGE_SIZE;
1028 }
1029
1030 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1031 memset(cur->xbuf[p], 0xff, k);
1032
1033 skcipher_request_set_crypt(cur->req, cur->sg,
1034 cur->sg, *b_size,
1035 iv);
1036 }
1037
1038 if (secs)
1039 ret = test_mb_acipher_jiffies(data, enc,
1040 *b_size, secs,
1041 num_mb);
1042 else
1043 ret = test_mb_acipher_cycles(data, enc,
1044 *b_size, num_mb);
1045
1046 if (ret) {
1047 pr_err("%s() failed flags=%x\n", e,
1048 crypto_skcipher_get_flags(tfm));
1049 break;
1050 }
1051 b_size++;
1052 i++;
1053 } while (*b_size);
1054 keysize++;
1055 } while (*keysize);
1056
1057out:
1058 for (i = 0; i < num_mb; ++i)
1059 skcipher_request_free(data[i].req);
1060out_free_xbuf:
1061 for (i = 0; i < num_mb; ++i)
1062 testmgr_free_buf(data[i].xbuf);
1063out_free_tfm:
1064 crypto_free_skcipher(tfm);
1065out_free_data:
1066 kfree(data);
1067}
1068
Herbert Xu7166e582016-06-29 18:03:50 +08001069static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001070{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001071 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001072
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001073 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001074}
1075
Herbert Xu7166e582016-06-29 18:03:50 +08001076static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001077 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001078{
1079 unsigned long start, end;
1080 int bcount;
1081 int ret;
1082
Mark Rustad3e3dc252014-07-25 02:53:38 -07001083 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001084 time_before(jiffies, end); bcount++) {
1085 if (enc)
1086 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001087 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001088 else
1089 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001090 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001091
1092 if (ret)
1093 return ret;
1094 }
1095
1096 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -07001097 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001098 return 0;
1099}
1100
Herbert Xu7166e582016-06-29 18:03:50 +08001101static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001102 int blen)
1103{
1104 unsigned long cycles = 0;
1105 int ret = 0;
1106 int i;
1107
1108 /* Warm-up run. */
1109 for (i = 0; i < 4; i++) {
1110 if (enc)
1111 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001112 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001113 else
1114 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001115 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001116
1117 if (ret)
1118 goto out;
1119 }
1120
1121 /* The real thing. */
1122 for (i = 0; i < 8; i++) {
1123 cycles_t start, end;
1124
1125 start = get_cycles();
1126 if (enc)
1127 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001128 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001129 else
1130 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001131 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001132 end = get_cycles();
1133
1134 if (ret)
1135 goto out;
1136
1137 cycles += end - start;
1138 }
1139
1140out:
1141 if (ret == 0)
1142 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1143 (cycles + 4) / 8, blen);
1144
1145 return ret;
1146}
1147
Herbert Xu7166e582016-06-29 18:03:50 +08001148static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1149 struct cipher_speed_template *template,
1150 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001151{
Nicolas Royerde1975332012-07-01 19:19:47 +02001152 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001153 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001154 const char *key;
1155 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +08001156 struct skcipher_request *req;
1157 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001158 const char *e;
1159 u32 *b_size;
1160
1161 if (enc == ENCRYPT)
1162 e = "encryption";
1163 else
1164 e = "decryption";
1165
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001166 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001167
Herbert Xu7166e582016-06-29 18:03:50 +08001168 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001169
1170 if (IS_ERR(tfm)) {
1171 pr_err("failed to load transform for %s: %ld\n", algo,
1172 PTR_ERR(tfm));
1173 return;
1174 }
1175
Luca Clementi263a8df2014-06-25 22:57:42 -07001176 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
Herbert Xu7166e582016-06-29 18:03:50 +08001177 get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -07001178
Herbert Xu7166e582016-06-29 18:03:50 +08001179 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001180 if (!req) {
1181 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1182 algo);
1183 goto out;
1184 }
1185
Herbert Xu7166e582016-06-29 18:03:50 +08001186 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001187 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001188
1189 i = 0;
1190 do {
1191 b_size = block_sizes;
1192
1193 do {
1194 struct scatterlist sg[TVMEMSIZE];
1195
1196 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1197 pr_err("template (%u) too big for "
1198 "tvmem (%lu)\n", *keysize + *b_size,
1199 TVMEMSIZE * PAGE_SIZE);
1200 goto out_free_req;
1201 }
1202
1203 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1204 *keysize * 8, *b_size);
1205
1206 memset(tvmem[0], 0xff, PAGE_SIZE);
1207
1208 /* set key, plain text and IV */
1209 key = tvmem[0];
1210 for (j = 0; j < tcount; j++) {
1211 if (template[j].klen == *keysize) {
1212 key = template[j].key;
1213 break;
1214 }
1215 }
1216
Herbert Xu7166e582016-06-29 18:03:50 +08001217 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001218
Herbert Xu7166e582016-06-29 18:03:50 +08001219 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001220 if (ret) {
1221 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +08001222 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001223 goto out_free_req;
1224 }
1225
Nicolas Royerde1975332012-07-01 19:19:47 +02001226 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +02001227 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1228
Nicolas Royerde1975332012-07-01 19:19:47 +02001229 if (k > PAGE_SIZE) {
1230 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001231 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +02001232 k -= PAGE_SIZE;
1233 j = 1;
1234 while (k > PAGE_SIZE) {
1235 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1236 memset(tvmem[j], 0xff, PAGE_SIZE);
1237 j++;
1238 k -= PAGE_SIZE;
1239 }
1240 sg_set_buf(sg + j, tvmem[j], k);
1241 memset(tvmem[j], 0xff, k);
1242 } else {
1243 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001244 }
1245
Herbert Xu7166e582016-06-29 18:03:50 +08001246 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001247 if (iv_len)
1248 memset(&iv, 0xff, iv_len);
1249
Herbert Xu7166e582016-06-29 18:03:50 +08001250 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001251
Mark Rustad3e3dc252014-07-25 02:53:38 -07001252 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001253 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001254 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001255 else
1256 ret = test_acipher_cycles(req, enc,
1257 *b_size);
1258
1259 if (ret) {
1260 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +08001261 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001262 break;
1263 }
1264 b_size++;
1265 i++;
1266 } while (*b_size);
1267 keysize++;
1268 } while (*keysize);
1269
1270out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +08001271 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001272out:
Herbert Xu7166e582016-06-29 18:03:50 +08001273 crypto_free_skcipher(tfm);
1274}
1275
1276static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1277 struct cipher_speed_template *template,
1278 unsigned int tcount, u8 *keysize)
1279{
1280 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1281 true);
1282}
1283
1284static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1285 struct cipher_speed_template *template,
1286 unsigned int tcount, u8 *keysize)
1287{
1288 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1289 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001290}
1291
Herbert Xuef2736f2005-06-22 13:26:03 -07001292static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293{
1294 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 while (*name) {
1297 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001298 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001299 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302}
1303
Herbert Xu01b32322008-07-31 15:41:55 +08001304static inline int tcrypt_test(const char *alg)
1305{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001306 int ret;
1307
Rabin Vincent76512f22017-01-18 14:54:05 +01001308 pr_debug("testing %s\n", alg);
1309
Jarod Wilson4e033a62009-05-27 15:10:21 +10001310 ret = alg_test(alg, alg, 0, 0);
1311 /* non-fips algs return -EINVAL in fips mode */
1312 if (fips_enabled && ret == -EINVAL)
1313 ret = 0;
1314 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001315}
1316
Herbert Xu86068132014-12-04 16:43:29 +08001317static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +08001318{
1319 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001320 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001321
1322 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001324 if (alg) {
1325 if (!crypto_has_alg(alg, type,
1326 mask ?: CRYPTO_ALG_TYPE_MASK))
1327 ret = -ENOENT;
1328 break;
1329 }
1330
Herbert Xu01b32322008-07-31 15:41:55 +08001331 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001332 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 break;
1334
1335 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001336 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 break;
1338
1339 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001340 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 break;
1342
1343 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001344 ret += tcrypt_test("ecb(des)");
1345 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001346 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 break;
1348
1349 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001350 ret += tcrypt_test("ecb(des3_ede)");
1351 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001352 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 break;
1354
1355 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001356 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001358
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001360 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001364 ret += tcrypt_test("ecb(blowfish)");
1365 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001366 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 break;
1368
1369 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001370 ret += tcrypt_test("ecb(twofish)");
1371 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001372 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001373 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001374 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001376
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001378 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001379 ret += tcrypt_test("cbc(serpent)");
1380 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001381 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001382 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 break;
1384
1385 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001386 ret += tcrypt_test("ecb(aes)");
1387 ret += tcrypt_test("cbc(aes)");
1388 ret += tcrypt_test("lrw(aes)");
1389 ret += tcrypt_test("xts(aes)");
1390 ret += tcrypt_test("ctr(aes)");
1391 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 break;
1393
1394 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001395 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001399 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 break;
1401
1402 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001403 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 break;
1405
1406 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001407 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001408 ret += tcrypt_test("cbc(cast5)");
1409 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 break;
1411
1412 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001413 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001414 ret += tcrypt_test("cbc(cast6)");
1415 ret += tcrypt_test("ctr(cast6)");
1416 ret += tcrypt_test("lrw(cast6)");
1417 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 break;
1419
1420 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001421 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 break;
1423
1424 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001425 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 break;
1427
1428 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001429 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 break;
1431
1432 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001433 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 break;
1435
1436 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001437 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 break;
1439
1440 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001441 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 break;
1443
1444 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001445 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 break;
1447
1448 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001449 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 break;
1451
1452 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001453 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 break;
1455
1456 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001457 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 break;
1459
1460 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001461 ret += tcrypt_test("ecb(anubis)");
1462 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 break;
1464
1465 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001466 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 break;
1468
1469 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001470 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 break;
1472
1473 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001474 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001476
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001477 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001478 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001479 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
David Howells90831632006-12-16 12:13:14 +11001481 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001482 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001483 break;
1484
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001485 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001486 ret += tcrypt_test("ecb(camellia)");
1487 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001488 ret += tcrypt_test("ctr(camellia)");
1489 ret += tcrypt_test("lrw(camellia)");
1490 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001491 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001492
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001493 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001494 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001495 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001496
Tan Swee Heng2407d602007-11-23 19:45:00 +08001497 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001498 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001499 break;
1500
Herbert Xu8df213d2007-12-02 14:55:47 +11001501 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001502 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001503 break;
1504
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001505 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001506 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001507 break;
1508
Joy Latten93cc74e2007-12-12 20:24:22 +08001509 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001510 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001511 break;
1512
Kevin Coffman76cb9522008-03-24 21:26:16 +08001513 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001514 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001515 break;
1516
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001517 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001518 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001519 break;
1520
1521 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001522 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001523 break;
1524
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001525 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001526 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001527 break;
1528
1529 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001530 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001531 break;
1532
1533 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001534 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001535 break;
1536
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001537 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001538 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001539 break;
1540
Jarod Wilson5d667322009-05-04 19:23:40 +08001541 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001542 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001543 break;
1544
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001545 case 46:
1546 ret += tcrypt_test("ghash");
1547 break;
1548
Herbert Xu684115212013-09-07 12:56:26 +10001549 case 47:
1550 ret += tcrypt_test("crct10dif");
1551 break;
1552
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301553 case 48:
1554 ret += tcrypt_test("sha3-224");
1555 break;
1556
1557 case 49:
1558 ret += tcrypt_test("sha3-256");
1559 break;
1560
1561 case 50:
1562 ret += tcrypt_test("sha3-384");
1563 break;
1564
1565 case 51:
1566 ret += tcrypt_test("sha3-512");
1567 break;
1568
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001569 case 52:
1570 ret += tcrypt_test("sm3");
1571 break;
1572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001574 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001578 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001580
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001582 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 break;
1584
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001585 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001586 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001587 break;
1588
1589 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001590 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001591 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001592
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001593 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001594 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001595 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001597 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001598 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001599 break;
1600
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001601 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001602 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001603 break;
1604
1605 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001606 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001607 break;
1608
Shane Wangf1939f72009-09-02 20:05:22 +10001609 case 109:
1610 ret += tcrypt_test("vmac(aes)");
1611 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001612
Sonic Zhanga482b082012-05-25 17:54:13 +08001613 case 110:
1614 ret += tcrypt_test("hmac(crc32)");
1615 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001616
raveendra padasalagi98eca722016-07-01 11:16:54 +05301617 case 111:
1618 ret += tcrypt_test("hmac(sha3-224)");
1619 break;
1620
1621 case 112:
1622 ret += tcrypt_test("hmac(sha3-256)");
1623 break;
1624
1625 case 113:
1626 ret += tcrypt_test("hmac(sha3-384)");
1627 break;
1628
1629 case 114:
1630 ret += tcrypt_test("hmac(sha3-512)");
1631 break;
1632
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001633 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001634 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001635 break;
1636
Adrian Hoban69435b92010-11-04 15:02:04 -04001637 case 151:
1638 ret += tcrypt_test("rfc4106(gcm(aes))");
1639 break;
1640
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001641 case 152:
1642 ret += tcrypt_test("rfc4543(gcm(aes))");
1643 break;
1644
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001645 case 153:
1646 ret += tcrypt_test("cmac(aes)");
1647 break;
1648
1649 case 154:
1650 ret += tcrypt_test("cmac(des3_ede)");
1651 break;
1652
Horia Geantabbf9c892013-11-28 15:11:16 +02001653 case 155:
1654 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1655 break;
1656
Horia Geantabca4feb2014-03-14 17:46:51 +02001657 case 156:
1658 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1659 break;
1660
1661 case 157:
1662 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1663 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301664 case 181:
1665 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1666 break;
1667 case 182:
1668 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1669 break;
1670 case 183:
1671 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1672 break;
1673 case 184:
1674 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1675 break;
1676 case 185:
1677 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1678 break;
1679 case 186:
1680 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1681 break;
1682 case 187:
1683 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1684 break;
1685 case 188:
1686 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1687 break;
1688 case 189:
1689 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1690 break;
1691 case 190:
1692 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1693 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001694 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001695 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001696 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001697 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001698 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001699 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001700 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001701 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001702 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001703 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001704 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001705 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001706 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001707 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001708 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001709 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001710 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001711 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1712 speed_template_16_24_32);
1713 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1714 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10001715 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1716 speed_template_16_24_32);
1717 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1718 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001719 break;
1720
1721 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001722 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001723 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001724 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001725 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001726 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001727 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001728 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001729 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001730 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001731 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001732 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001733 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001734 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1735 des3_speed_template, DES3_SPEED_VECTORS,
1736 speed_template_24);
1737 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1738 des3_speed_template, DES3_SPEED_VECTORS,
1739 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001740 break;
1741
1742 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001743 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001744 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001745 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001746 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001747 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001748 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001749 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001750 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001751 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1752 speed_template_16_24_32);
1753 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1754 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001755 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1756 speed_template_32_40_48);
1757 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1758 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001759 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1760 speed_template_32_48_64);
1761 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1762 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001763 break;
1764
1765 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001766 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001767 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001768 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001769 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001770 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001771 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001772 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001773 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001774 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1775 speed_template_8_32);
1776 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1777 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001778 break;
1779
1780 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001781 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001782 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001783 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001784 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001785 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001786 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001787 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001788 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001789 break;
1790
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001791 case 205:
1792 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001793 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001794 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001795 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001796 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001797 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001798 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001799 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001800 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1801 speed_template_16_24_32);
1802 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1803 speed_template_16_24_32);
1804 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1805 speed_template_32_40_48);
1806 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1807 speed_template_32_40_48);
1808 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1809 speed_template_32_48_64);
1810 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1811 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001812 break;
1813
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001814 case 206:
1815 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001816 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001817 break;
1818
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001819 case 207:
1820 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1821 speed_template_16_32);
1822 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1823 speed_template_16_32);
1824 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1825 speed_template_16_32);
1826 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1827 speed_template_16_32);
1828 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1829 speed_template_16_32);
1830 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1831 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001832 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1833 speed_template_32_48);
1834 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1835 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001836 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1837 speed_template_32_64);
1838 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1839 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001840 break;
1841
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001842 case 208:
1843 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1844 speed_template_8);
1845 break;
1846
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001847 case 209:
1848 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1849 speed_template_8_16);
1850 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1851 speed_template_8_16);
1852 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1853 speed_template_8_16);
1854 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1855 speed_template_8_16);
1856 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1857 speed_template_8_16);
1858 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1859 speed_template_8_16);
1860 break;
1861
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001862 case 210:
1863 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1864 speed_template_16_32);
1865 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1866 speed_template_16_32);
1867 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1868 speed_template_16_32);
1869 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1870 speed_template_16_32);
1871 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1872 speed_template_16_32);
1873 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1874 speed_template_16_32);
1875 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1876 speed_template_32_48);
1877 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1878 speed_template_32_48);
1879 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1880 speed_template_32_64);
1881 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1882 speed_template_32_64);
1883 break;
1884
Tim Chen53f52d72013-12-11 14:28:47 -08001885 case 211:
1886 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001887 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05301888 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01001889 NULL, 0, 16, 8, speed_template_16_24_32);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001890 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
1891 NULL, 0, 16, 16, aead_speed_template_20);
1892 test_aead_speed("gcm(aes)", DECRYPT, sec,
1893 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08001894 break;
1895
Herbert Xu4e4aab62015-06-17 14:04:21 +08001896 case 212:
1897 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001898 NULL, 0, 16, 16, aead_speed_template_19);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001899 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
1900 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08001901 break;
1902
Martin Willi2dce0632015-07-16 19:13:59 +02001903 case 213:
1904 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1905 NULL, 0, 16, 8, aead_speed_template_36);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001906 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
1907 NULL, 0, 16, 8, aead_speed_template_36);
Martin Willi2dce0632015-07-16 19:13:59 +02001908 break;
1909
1910 case 214:
1911 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1912 speed_template_32);
1913 break;
1914
Michal Ludvige8057922006-05-30 22:04:19 +10001915 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001916 if (alg) {
1917 test_hash_speed(alg, sec, generic_hash_speed_template);
1918 break;
1919 }
Michal Ludvige8057922006-05-30 22:04:19 +10001920 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001921 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001922 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001923 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001924 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001925 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001926 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001927 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001928 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001929 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001930 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001931 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001932 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001933 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001934 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001935 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001936 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001937 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001938 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001939 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001940 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001941 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001942 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001943 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001944 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001945 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001946 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001947 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001948 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001949 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001950 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001951 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001952 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001953 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001954 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001955 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001956 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001957 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001958 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001959 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001960 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001961 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001962 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001963 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001964 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001965 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001966 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001967 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001968 /* fall through */
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001969 case 313:
1970 test_hash_speed("sha224", sec, generic_hash_speed_template);
1971 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001972 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001973 case 314:
1974 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1975 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001976 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001977 case 315:
1978 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1979 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001980 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001981 case 316:
1982 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1983 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001984 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001985 case 317:
1986 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1987 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001988 /* fall through */
Huang Ying18bcc912010-03-10 18:30:32 +08001989 case 318:
1990 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1991 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001992 /* fall through */
Tim Chene3899e42012-09-27 15:44:24 -07001993 case 319:
1994 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1995 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001996 /* fall through */
Herbert Xu684115212013-09-07 12:56:26 +10001997 case 320:
1998 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1999 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002000 /* fall through */
Martin Willi2dce0632015-07-16 19:13:59 +02002001 case 321:
2002 test_hash_speed("poly1305", sec, poly1305_speed_template);
2003 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002004 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302005 case 322:
2006 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2007 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002008 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302009 case 323:
2010 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2011 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002012 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302013 case 324:
2014 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2015 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002016 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302017 case 325:
2018 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2019 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002020 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002021 case 326:
2022 test_hash_speed("sm3", sec, generic_hash_speed_template);
2023 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002024 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002025 case 399:
2026 break;
2027
David S. Millerbeb63da2010-05-19 14:11:21 +10002028 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08002029 if (alg) {
2030 test_ahash_speed(alg, sec, generic_hash_speed_template);
2031 break;
2032 }
David S. Millerbeb63da2010-05-19 14:11:21 +10002033 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002034 case 401:
2035 test_ahash_speed("md4", sec, generic_hash_speed_template);
2036 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002037 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002038 case 402:
2039 test_ahash_speed("md5", sec, generic_hash_speed_template);
2040 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002041 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002042 case 403:
2043 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2044 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002045 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002046 case 404:
2047 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2048 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002049 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002050 case 405:
2051 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2052 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002053 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002054 case 406:
2055 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2056 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002057 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002058 case 407:
2059 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2060 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002061 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002062 case 408:
2063 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2064 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002065 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002066 case 409:
2067 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2068 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002069 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002070 case 410:
2071 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2072 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002073 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002074 case 411:
2075 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2076 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002077 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002078 case 412:
2079 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2080 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002081 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002082 case 413:
2083 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2084 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002085 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002086 case 414:
2087 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2088 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002089 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002090 case 415:
2091 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2092 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002093 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002094 case 416:
2095 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2096 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002097 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002098 case 417:
2099 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2100 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002101 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302102 case 418:
2103 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2104 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002105 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302106 case 419:
2107 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2108 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002109 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302110 case 420:
2111 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2112 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002113 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302114 case 421:
2115 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2116 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002117 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07002118 case 422:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002119 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2120 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07002121 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002122 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07002123 case 423:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002124 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2125 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07002126 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002127 /* fall through */
Megha Dey14009c42016-06-27 10:20:09 -07002128 case 424:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002129 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2130 num_mb);
Megha Dey14009c42016-06-27 10:20:09 -07002131 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002132 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002133 case 425:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002134 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2135 num_mb);
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002136 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002137 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002138 case 499:
2139 break;
2140
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002141 case 500:
2142 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2143 speed_template_16_24_32);
2144 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2145 speed_template_16_24_32);
2146 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2147 speed_template_16_24_32);
2148 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2149 speed_template_16_24_32);
2150 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2151 speed_template_32_40_48);
2152 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2153 speed_template_32_40_48);
2154 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002155 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002156 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002157 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08002158 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2159 speed_template_16_24_32);
2160 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2161 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002162 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2163 speed_template_16_24_32);
2164 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2165 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02002166 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2167 speed_template_16_24_32);
2168 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2169 speed_template_16_24_32);
2170 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2171 speed_template_16_24_32);
2172 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2173 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02002174 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2175 speed_template_20_28_36);
2176 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2177 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002178 break;
2179
2180 case 501:
2181 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2182 des3_speed_template, DES3_SPEED_VECTORS,
2183 speed_template_24);
2184 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2185 des3_speed_template, DES3_SPEED_VECTORS,
2186 speed_template_24);
2187 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2188 des3_speed_template, DES3_SPEED_VECTORS,
2189 speed_template_24);
2190 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2191 des3_speed_template, DES3_SPEED_VECTORS,
2192 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02002193 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2194 des3_speed_template, DES3_SPEED_VECTORS,
2195 speed_template_24);
2196 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2197 des3_speed_template, DES3_SPEED_VECTORS,
2198 speed_template_24);
2199 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2200 des3_speed_template, DES3_SPEED_VECTORS,
2201 speed_template_24);
2202 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2203 des3_speed_template, DES3_SPEED_VECTORS,
2204 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002205 break;
2206
2207 case 502:
2208 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2209 speed_template_8);
2210 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2211 speed_template_8);
2212 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2213 speed_template_8);
2214 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2215 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02002216 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2217 speed_template_8);
2218 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2219 speed_template_8);
2220 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2221 speed_template_8);
2222 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2223 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002224 break;
2225
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002226 case 503:
2227 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2228 speed_template_16_32);
2229 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2230 speed_template_16_32);
2231 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2232 speed_template_16_32);
2233 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2234 speed_template_16_32);
2235 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2236 speed_template_16_32);
2237 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2238 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002239 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2240 speed_template_32_48);
2241 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2242 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002243 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2244 speed_template_32_64);
2245 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2246 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002247 break;
2248
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002249 case 504:
2250 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2251 speed_template_16_24_32);
2252 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2253 speed_template_16_24_32);
2254 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2255 speed_template_16_24_32);
2256 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2257 speed_template_16_24_32);
2258 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2259 speed_template_16_24_32);
2260 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2261 speed_template_16_24_32);
2262 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2263 speed_template_32_40_48);
2264 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2265 speed_template_32_40_48);
2266 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2267 speed_template_32_48_64);
2268 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2269 speed_template_32_48_64);
2270 break;
2271
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002272 case 505:
2273 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2274 speed_template_8);
2275 break;
2276
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002277 case 506:
2278 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2279 speed_template_8_16);
2280 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2281 speed_template_8_16);
2282 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2283 speed_template_8_16);
2284 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2285 speed_template_8_16);
2286 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2287 speed_template_8_16);
2288 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2289 speed_template_8_16);
2290 break;
2291
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002292 case 507:
2293 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2294 speed_template_16_32);
2295 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2296 speed_template_16_32);
2297 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2298 speed_template_16_32);
2299 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2300 speed_template_16_32);
2301 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2302 speed_template_16_32);
2303 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2304 speed_template_16_32);
2305 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2306 speed_template_32_48);
2307 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2308 speed_template_32_48);
2309 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2310 speed_template_32_64);
2311 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2312 speed_template_32_64);
2313 break;
2314
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002315 case 508:
2316 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2317 speed_template_16_32);
2318 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2319 speed_template_16_32);
2320 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2321 speed_template_16_32);
2322 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2323 speed_template_16_32);
2324 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2325 speed_template_16_32);
2326 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2327 speed_template_16_32);
2328 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2329 speed_template_32_48);
2330 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2331 speed_template_32_48);
2332 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2333 speed_template_32_64);
2334 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2335 speed_template_32_64);
2336 break;
2337
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002338 case 509:
2339 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2340 speed_template_8_32);
2341 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2342 speed_template_8_32);
2343 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2344 speed_template_8_32);
2345 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2346 speed_template_8_32);
2347 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2348 speed_template_8_32);
2349 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2350 speed_template_8_32);
2351 break;
2352
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00002353 case 600:
2354 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2355 speed_template_16_24_32, num_mb);
2356 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2357 speed_template_16_24_32, num_mb);
2358 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2359 speed_template_16_24_32, num_mb);
2360 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2361 speed_template_16_24_32, num_mb);
2362 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2363 speed_template_32_40_48, num_mb);
2364 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2365 speed_template_32_40_48, num_mb);
2366 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2367 speed_template_32_64, num_mb);
2368 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2369 speed_template_32_64, num_mb);
2370 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2371 speed_template_16_24_32, num_mb);
2372 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2373 speed_template_16_24_32, num_mb);
2374 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2375 speed_template_16_24_32, num_mb);
2376 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2377 speed_template_16_24_32, num_mb);
2378 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2379 speed_template_16_24_32, num_mb);
2380 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2381 speed_template_16_24_32, num_mb);
2382 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2383 speed_template_16_24_32, num_mb);
2384 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2385 speed_template_16_24_32, num_mb);
2386 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2387 0, speed_template_20_28_36, num_mb);
2388 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2389 0, speed_template_20_28_36, num_mb);
2390 break;
2391
2392 case 601:
2393 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2394 des3_speed_template, DES3_SPEED_VECTORS,
2395 speed_template_24, num_mb);
2396 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2397 des3_speed_template, DES3_SPEED_VECTORS,
2398 speed_template_24, num_mb);
2399 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2400 des3_speed_template, DES3_SPEED_VECTORS,
2401 speed_template_24, num_mb);
2402 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2403 des3_speed_template, DES3_SPEED_VECTORS,
2404 speed_template_24, num_mb);
2405 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2406 des3_speed_template, DES3_SPEED_VECTORS,
2407 speed_template_24, num_mb);
2408 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2409 des3_speed_template, DES3_SPEED_VECTORS,
2410 speed_template_24, num_mb);
2411 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2412 des3_speed_template, DES3_SPEED_VECTORS,
2413 speed_template_24, num_mb);
2414 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2415 des3_speed_template, DES3_SPEED_VECTORS,
2416 speed_template_24, num_mb);
2417 break;
2418
2419 case 602:
2420 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2421 speed_template_8, num_mb);
2422 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2423 speed_template_8, num_mb);
2424 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2425 speed_template_8, num_mb);
2426 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2427 speed_template_8, num_mb);
2428 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2429 speed_template_8, num_mb);
2430 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2431 speed_template_8, num_mb);
2432 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2433 speed_template_8, num_mb);
2434 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2435 speed_template_8, num_mb);
2436 break;
2437
2438 case 603:
2439 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2440 speed_template_16_32, num_mb);
2441 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2442 speed_template_16_32, num_mb);
2443 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2444 speed_template_16_32, num_mb);
2445 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2446 speed_template_16_32, num_mb);
2447 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2448 speed_template_16_32, num_mb);
2449 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2450 speed_template_16_32, num_mb);
2451 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2452 speed_template_32_48, num_mb);
2453 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2454 speed_template_32_48, num_mb);
2455 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2456 speed_template_32_64, num_mb);
2457 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2458 speed_template_32_64, num_mb);
2459 break;
2460
2461 case 604:
2462 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2463 speed_template_16_24_32, num_mb);
2464 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2465 speed_template_16_24_32, num_mb);
2466 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2467 speed_template_16_24_32, num_mb);
2468 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2469 speed_template_16_24_32, num_mb);
2470 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2471 speed_template_16_24_32, num_mb);
2472 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2473 speed_template_16_24_32, num_mb);
2474 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2475 speed_template_32_40_48, num_mb);
2476 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2477 speed_template_32_40_48, num_mb);
2478 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2479 speed_template_32_48_64, num_mb);
2480 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2481 speed_template_32_48_64, num_mb);
2482 break;
2483
2484 case 605:
2485 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2486 speed_template_8, num_mb);
2487 break;
2488
2489 case 606:
2490 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2491 speed_template_8_16, num_mb);
2492 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2493 speed_template_8_16, num_mb);
2494 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2495 speed_template_8_16, num_mb);
2496 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2497 speed_template_8_16, num_mb);
2498 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2499 speed_template_8_16, num_mb);
2500 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2501 speed_template_8_16, num_mb);
2502 break;
2503
2504 case 607:
2505 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2506 speed_template_16_32, num_mb);
2507 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2508 speed_template_16_32, num_mb);
2509 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2510 speed_template_16_32, num_mb);
2511 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2512 speed_template_16_32, num_mb);
2513 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2514 speed_template_16_32, num_mb);
2515 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2516 speed_template_16_32, num_mb);
2517 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2518 speed_template_32_48, num_mb);
2519 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2520 speed_template_32_48, num_mb);
2521 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2522 speed_template_32_64, num_mb);
2523 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2524 speed_template_32_64, num_mb);
2525 break;
2526
2527 case 608:
2528 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2529 speed_template_16_32, num_mb);
2530 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2531 speed_template_16_32, num_mb);
2532 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2533 speed_template_16_32, num_mb);
2534 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2535 speed_template_16_32, num_mb);
2536 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2537 speed_template_16_32, num_mb);
2538 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2539 speed_template_16_32, num_mb);
2540 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2541 speed_template_32_48, num_mb);
2542 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2543 speed_template_32_48, num_mb);
2544 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2545 speed_template_32_64, num_mb);
2546 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2547 speed_template_32_64, num_mb);
2548 break;
2549
2550 case 609:
2551 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2552 speed_template_8_32, num_mb);
2553 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2554 speed_template_8_32, num_mb);
2555 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2556 speed_template_8_32, num_mb);
2557 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2558 speed_template_8_32, num_mb);
2559 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2560 speed_template_8_32, num_mb);
2561 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2562 speed_template_8_32, num_mb);
2563 break;
2564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 case 1000:
2566 test_available();
2567 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002569
2570 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571}
2572
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002573static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002575 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002576 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002577
Herbert Xuf139cfa2008-07-31 12:23:53 +08002578 for (i = 0; i < TVMEMSIZE; i++) {
2579 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2580 if (!tvmem[i])
2581 goto err_free_tv;
2582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Herbert Xu86068132014-12-04 16:43:29 +08002584 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002585
Jarod Wilson4e033a62009-05-27 15:10:21 +10002586 if (err) {
2587 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2588 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01002589 } else {
2590 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10002591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
Jarod Wilson4e033a62009-05-27 15:10:21 +10002593 /* We intentionaly return -EAGAIN to prevent keeping the module,
2594 * unless we're running in fips mode. It does all its work from
2595 * init() and doesn't offer any runtime functionality, but in
2596 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002597 * => we don't need it in the memory, do we?
2598 * -- mludvig
2599 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002600 if (!fips_enabled)
2601 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002602
Herbert Xuf139cfa2008-07-31 12:23:53 +08002603err_free_tv:
2604 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2605 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002606
2607 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608}
2609
2610/*
2611 * If an init function is provided, an exit function must also be provided
2612 * to allow module unload.
2613 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002614static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002616module_init(tcrypt_mod_init);
2617module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002619module_param(alg, charp, 0);
2620module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002621module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002623module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002624MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2625 "(defaults to zero which uses CPU cycles instead)");
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002626module_param(num_mb, uint, 0000);
2627MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
2629MODULE_LICENSE("GPL");
2630MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2631MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");