blob: fc1f3e516694f69d682d4bca0bf1e84f122dd0c5 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Herbert Xuef2736f2005-06-22 13:26:03 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Quick & dirty crypto testing module.
4 *
5 * This will only exist until we have a better testing mechanism
6 * (e.g. a char device).
7 *
8 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
9 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
Mikko Herranene3a4ea42007-11-26 22:12:07 +080010 * Copyright (c) 2007 Nokia Siemens Networks
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
Adrian Hoban69435b92010-11-04 15:02:04 -040012 * Updated RFC4106 AES-GCM testing.
13 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
14 * Adrian Hoban <adrian.hoban@intel.com>
15 * Gabriele Paoloni <gabriele.paoloni@intel.com>
16 * Tadeusz Struk (tadeusz.struk@intel.com)
17 * Copyright (c) 2010, Intel Corporation.
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 */
19
Rabin Vincent76512f22017-01-18 14:54:05 +010020#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Herbert Xu1ce5a042015-04-22 15:06:30 +080022#include <crypto/aead.h>
Herbert Xu18e33e62008-07-10 16:01:22 +080023#include <crypto/hash.h>
Herbert Xu7166e582016-06-29 18:03:50 +080024#include <crypto/skcipher.h>
Herbert Xucba83562006-08-13 08:26:09 +100025#include <linux/err.h>
Herbert Xudaf09442015-04-22 13:25:57 +080026#include <linux/fips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/module.h>
David Hardeman378f0582005-09-17 17:55:31 +100030#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070033#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070034#include <linux/timex.h>
35#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "tcrypt.h"
37
38/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080039 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080041#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/*
Herbert Xuda7f0332008-07-31 17:08:25 +080044* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070045*/
46#define ENCRYPT 1
47#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Horia Geant?f074f7b2015-08-27 18:38:36 +030049#define MAX_DIGEST_SIZE 64
50
Harald Welteebfd9bc2005-06-22 13:27:23 -070051/*
Luca Clementi263a8df2014-06-25 22:57:42 -070052 * return a string with the driver name
53 */
54#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
55
56/*
Harald Welteebfd9bc2005-06-22 13:27:23 -070057 * Used by test_cipher_speed()
58 */
Herbert Xu6a179442005-06-22 13:29:03 -070059static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070060
Steffen Klasserta873a5f2009-06-19 19:46:53 +080061static char *alg = NULL;
62static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080063static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064static int mode;
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +000065static u32 num_mb = 8;
Herbert Xuba974ad2020-08-05 15:57:08 +100066static unsigned int klen;
Herbert Xuf139cfa2008-07-31 12:23:53 +080067static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Corentin Labbe07d8f182019-11-08 15:42:13 +000069static const char *check[] = {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +030070 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080071 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
72 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110073 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080074 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Dave Rodgman45ec9752019-03-07 16:30:44 -080075 "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384",
76 "sha3-512", "streebog256", "streebog512",
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +030077 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
Ard Biesheuvelee5bbc92018-12-04 14:13:31 +010080static u32 block_sizes[] = { 16, 64, 256, 1024, 1472, 8192, 0 };
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +000081static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
82
83#define XBUFSIZE 8
84#define MAX_IVLEN 32
85
86static int testmgr_alloc_buf(char *buf[XBUFSIZE])
87{
88 int i;
89
90 for (i = 0; i < XBUFSIZE; i++) {
91 buf[i] = (void *)__get_free_page(GFP_KERNEL);
92 if (!buf[i])
93 goto err_free_buf;
94 }
95
96 return 0;
97
98err_free_buf:
99 while (i-- > 0)
100 free_page((unsigned long)buf[i]);
101
102 return -ENOMEM;
103}
104
105static void testmgr_free_buf(char *buf[XBUFSIZE])
106{
107 int i;
108
109 for (i = 0; i < XBUFSIZE; i++)
110 free_page((unsigned long)buf[i]);
111}
112
113static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
114 unsigned int buflen, const void *assoc,
115 unsigned int aad_size)
116{
117 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
118 int k, rem;
119
120 if (np > XBUFSIZE) {
121 rem = PAGE_SIZE;
122 np = XBUFSIZE;
123 } else {
124 rem = buflen % PAGE_SIZE;
125 }
126
127 sg_init_table(sg, np + 1);
128
129 sg_set_buf(&sg[0], assoc, aad_size);
130
131 if (rem)
132 np--;
133 for (k = 0; k < np; k++)
134 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
135
136 if (rem)
137 sg_set_buf(&sg[k + 1], xbuf[k], rem);
138}
139
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530140static inline int do_one_aead_op(struct aead_request *req, int ret)
141{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100142 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530143
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100144 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530145}
146
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000147struct test_mb_aead_data {
148 struct scatterlist sg[XBUFSIZE];
149 struct scatterlist sgout[XBUFSIZE];
150 struct aead_request *req;
151 struct crypto_wait wait;
152 char *xbuf[XBUFSIZE];
153 char *xoutbuf[XBUFSIZE];
154 char *axbuf[XBUFSIZE];
155};
156
157static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
Kees Cook4e234ee2018-04-26 19:57:28 -0700158 u32 num_mb, int *rc)
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000159{
Kees Cook4e234ee2018-04-26 19:57:28 -0700160 int i, err = 0;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000161
162 /* Fire up a bunch of concurrent requests */
163 for (i = 0; i < num_mb; i++) {
164 if (enc == ENCRYPT)
165 rc[i] = crypto_aead_encrypt(data[i].req);
166 else
167 rc[i] = crypto_aead_decrypt(data[i].req);
168 }
169
170 /* Wait for all requests to finish */
171 for (i = 0; i < num_mb; i++) {
172 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
173
174 if (rc[i]) {
175 pr_info("concurrent request %d error %d\n", i, rc[i]);
176 err = rc[i];
177 }
178 }
179
180 return err;
181}
182
183static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
184 int blen, int secs, u32 num_mb)
185{
186 unsigned long start, end;
187 int bcount;
Kees Cook4e234ee2018-04-26 19:57:28 -0700188 int ret = 0;
189 int *rc;
190
191 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
192 if (!rc)
193 return -ENOMEM;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000194
195 for (start = jiffies, end = start + secs * HZ, bcount = 0;
196 time_before(jiffies, end); bcount++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700197 ret = do_mult_aead_op(data, enc, num_mb, rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000198 if (ret)
Kees Cook4e234ee2018-04-26 19:57:28 -0700199 goto out;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000200 }
201
202 pr_cont("%d operations in %d seconds (%ld bytes)\n",
203 bcount * num_mb, secs, (long)bcount * blen * num_mb);
Kees Cook4e234ee2018-04-26 19:57:28 -0700204
205out:
206 kfree(rc);
207 return ret;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000208}
209
210static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
211 int blen, u32 num_mb)
212{
213 unsigned long cycles = 0;
214 int ret = 0;
215 int i;
Kees Cook4e234ee2018-04-26 19:57:28 -0700216 int *rc;
217
218 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
219 if (!rc)
220 return -ENOMEM;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000221
222 /* Warm-up run. */
223 for (i = 0; i < 4; i++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700224 ret = do_mult_aead_op(data, enc, num_mb, rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000225 if (ret)
226 goto out;
227 }
228
229 /* The real thing. */
230 for (i = 0; i < 8; i++) {
231 cycles_t start, end;
232
233 start = get_cycles();
Kees Cook4e234ee2018-04-26 19:57:28 -0700234 ret = do_mult_aead_op(data, enc, num_mb, rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000235 end = get_cycles();
236
237 if (ret)
238 goto out;
239
240 cycles += end - start;
241 }
242
Kees Cook4e234ee2018-04-26 19:57:28 -0700243 pr_cont("1 operation in %lu cycles (%d bytes)\n",
244 (cycles + 4) / (8 * num_mb), blen);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000245
Kees Cook4e234ee2018-04-26 19:57:28 -0700246out:
247 kfree(rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000248 return ret;
249}
250
251static void test_mb_aead_speed(const char *algo, int enc, int secs,
252 struct aead_speed_template *template,
253 unsigned int tcount, u8 authsize,
254 unsigned int aad_size, u8 *keysize, u32 num_mb)
255{
256 struct test_mb_aead_data *data;
257 struct crypto_aead *tfm;
258 unsigned int i, j, iv_len;
259 const char *key;
260 const char *e;
261 void *assoc;
262 u32 *b_size;
263 char *iv;
264 int ret;
265
266
267 if (aad_size >= PAGE_SIZE) {
268 pr_err("associate data length (%u) too big\n", aad_size);
269 return;
270 }
271
272 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
273 if (!iv)
274 return;
275
276 if (enc == ENCRYPT)
277 e = "encryption";
278 else
279 e = "decryption";
280
281 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
282 if (!data)
283 goto out_free_iv;
284
285 tfm = crypto_alloc_aead(algo, 0, 0);
286 if (IS_ERR(tfm)) {
287 pr_err("failed to load transform for %s: %ld\n",
288 algo, PTR_ERR(tfm));
289 goto out_free_data;
290 }
291
292 ret = crypto_aead_setauthsize(tfm, authsize);
293
294 for (i = 0; i < num_mb; ++i)
295 if (testmgr_alloc_buf(data[i].xbuf)) {
296 while (i--)
297 testmgr_free_buf(data[i].xbuf);
298 goto out_free_tfm;
299 }
300
301 for (i = 0; i < num_mb; ++i)
302 if (testmgr_alloc_buf(data[i].axbuf)) {
303 while (i--)
304 testmgr_free_buf(data[i].axbuf);
305 goto out_free_xbuf;
306 }
307
308 for (i = 0; i < num_mb; ++i)
309 if (testmgr_alloc_buf(data[i].xoutbuf)) {
310 while (i--)
Colin Ian Kingc6ba4f32018-01-02 15:43:04 +0000311 testmgr_free_buf(data[i].xoutbuf);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000312 goto out_free_axbuf;
313 }
314
315 for (i = 0; i < num_mb; ++i) {
316 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
317 if (!data[i].req) {
318 pr_err("alg: skcipher: Failed to allocate request for %s\n",
319 algo);
320 while (i--)
321 aead_request_free(data[i].req);
322 goto out_free_xoutbuf;
323 }
324 }
325
326 for (i = 0; i < num_mb; ++i) {
327 crypto_init_wait(&data[i].wait);
328 aead_request_set_callback(data[i].req,
329 CRYPTO_TFM_REQ_MAY_BACKLOG,
330 crypto_req_done, &data[i].wait);
331 }
332
333 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
334 get_driver_name(crypto_aead, tfm), e);
335
336 i = 0;
337 do {
338 b_size = aead_sizes;
339 do {
340 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
Colin Ian King38dbe2d2018-01-02 09:21:06 +0000341 pr_err("template (%u) too big for buffer (%lu)\n",
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000342 authsize + *b_size,
343 XBUFSIZE * PAGE_SIZE);
344 goto out;
345 }
346
347 pr_info("test %u (%d bit key, %d byte blocks): ", i,
348 *keysize * 8, *b_size);
349
350 /* Set up tfm global state, i.e. the key */
351
352 memset(tvmem[0], 0xff, PAGE_SIZE);
353 key = tvmem[0];
354 for (j = 0; j < tcount; j++) {
355 if (template[j].klen == *keysize) {
356 key = template[j].key;
357 break;
358 }
359 }
360
361 crypto_aead_clear_flags(tfm, ~0);
362
363 ret = crypto_aead_setkey(tfm, key, *keysize);
364 if (ret) {
365 pr_err("setkey() failed flags=%x\n",
366 crypto_aead_get_flags(tfm));
367 goto out;
368 }
369
370 iv_len = crypto_aead_ivsize(tfm);
371 if (iv_len)
372 memset(iv, 0xff, iv_len);
373
374 /* Now setup per request stuff, i.e. buffers */
375
376 for (j = 0; j < num_mb; ++j) {
377 struct test_mb_aead_data *cur = &data[j];
378
379 assoc = cur->axbuf[0];
380 memset(assoc, 0xff, aad_size);
381
382 sg_init_aead(cur->sg, cur->xbuf,
383 *b_size + (enc ? 0 : authsize),
384 assoc, aad_size);
385
386 sg_init_aead(cur->sgout, cur->xoutbuf,
387 *b_size + (enc ? authsize : 0),
388 assoc, aad_size);
389
390 aead_request_set_ad(cur->req, aad_size);
391
392 if (!enc) {
393
394 aead_request_set_crypt(cur->req,
395 cur->sgout,
396 cur->sg,
397 *b_size, iv);
398 ret = crypto_aead_encrypt(cur->req);
399 ret = do_one_aead_op(cur->req, ret);
400
401 if (ret) {
Randy Dunlap129a4db2020-07-30 19:39:24 -0700402 pr_err("calculating auth failed (%d)\n",
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000403 ret);
404 break;
405 }
406 }
407
408 aead_request_set_crypt(cur->req, cur->sg,
409 cur->sgout, *b_size +
410 (enc ? 0 : authsize),
411 iv);
412
413 }
414
Horia Geantă2af63292018-07-23 17:18:48 +0300415 if (secs) {
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000416 ret = test_mb_aead_jiffies(data, enc, *b_size,
417 secs, num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300418 cond_resched();
419 } else {
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000420 ret = test_mb_aead_cycles(data, enc, *b_size,
421 num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300422 }
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000423
424 if (ret) {
425 pr_err("%s() failed return code=%d\n", e, ret);
426 break;
427 }
428 b_size++;
429 i++;
430 } while (*b_size);
431 keysize++;
432 } while (*keysize);
433
434out:
435 for (i = 0; i < num_mb; ++i)
436 aead_request_free(data[i].req);
437out_free_xoutbuf:
438 for (i = 0; i < num_mb; ++i)
439 testmgr_free_buf(data[i].xoutbuf);
440out_free_axbuf:
441 for (i = 0; i < num_mb; ++i)
442 testmgr_free_buf(data[i].axbuf);
443out_free_xbuf:
444 for (i = 0; i < num_mb; ++i)
445 testmgr_free_buf(data[i].xbuf);
446out_free_tfm:
447 crypto_free_aead(tfm);
448out_free_data:
449 kfree(data);
450out_free_iv:
451 kfree(iv);
452}
453
Tim Chen53f52d72013-12-11 14:28:47 -0800454static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700455 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -0800456{
457 unsigned long start, end;
458 int bcount;
459 int ret;
460
Mark Rustad3e3dc252014-07-25 02:53:38 -0700461 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -0800462 time_before(jiffies, end); bcount++) {
463 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530464 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800465 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530466 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800467
468 if (ret)
469 return ret;
470 }
471
472 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700473 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800474 return 0;
475}
476
477static int test_aead_cycles(struct aead_request *req, int enc, int blen)
478{
479 unsigned long cycles = 0;
480 int ret = 0;
481 int i;
482
Tim Chen53f52d72013-12-11 14:28:47 -0800483 /* Warm-up run. */
484 for (i = 0; i < 4; i++) {
485 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530486 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800487 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530488 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800489
490 if (ret)
491 goto out;
492 }
493
494 /* The real thing. */
495 for (i = 0; i < 8; i++) {
496 cycles_t start, end;
497
498 start = get_cycles();
499 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530500 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800501 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530502 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800503 end = get_cycles();
504
505 if (ret)
506 goto out;
507
508 cycles += end - start;
509 }
510
511out:
Tim Chen53f52d72013-12-11 14:28:47 -0800512 if (ret == 0)
513 printk("1 operation in %lu cycles (%d bytes)\n",
514 (cycles + 4) / 8, blen);
515
516 return ret;
517}
518
Mark Rustad3e3dc252014-07-25 02:53:38 -0700519static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800520 struct aead_speed_template *template,
521 unsigned int tcount, u8 authsize,
522 unsigned int aad_size, u8 *keysize)
523{
524 unsigned int i, j;
525 struct crypto_aead *tfm;
526 int ret = -ENOMEM;
527 const char *key;
528 struct aead_request *req;
529 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800530 struct scatterlist *sgout;
531 const char *e;
532 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200533 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800534 char *xbuf[XBUFSIZE];
535 char *xoutbuf[XBUFSIZE];
536 char *axbuf[XBUFSIZE];
537 unsigned int *b_size;
538 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100539 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800540
Cristian Stoica96692a732015-01-28 13:07:32 +0200541 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
542 if (!iv)
543 return;
544
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200545 if (aad_size >= PAGE_SIZE) {
546 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200547 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200548 }
549
Tim Chen53f52d72013-12-11 14:28:47 -0800550 if (enc == ENCRYPT)
551 e = "encryption";
552 else
553 e = "decryption";
554
555 if (testmgr_alloc_buf(xbuf))
556 goto out_noxbuf;
557 if (testmgr_alloc_buf(axbuf))
558 goto out_noaxbuf;
559 if (testmgr_alloc_buf(xoutbuf))
560 goto out_nooutbuf;
561
Herbert Xua3f21852015-05-27 16:03:51 +0800562 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800563 if (!sg)
564 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800565 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800566
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800567 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800568
569 if (IS_ERR(tfm)) {
570 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
571 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200572 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800573 }
574
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100575 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700576 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
577 get_driver_name(crypto_aead, tfm), e);
578
Tim Chen53f52d72013-12-11 14:28:47 -0800579 req = aead_request_alloc(tfm, GFP_KERNEL);
580 if (!req) {
581 pr_err("alg: aead: Failed to allocate request for %s\n",
582 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200583 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800584 }
585
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530586 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100587 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530588
Tim Chen53f52d72013-12-11 14:28:47 -0800589 i = 0;
590 do {
591 b_size = aead_sizes;
592 do {
593 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200594 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800595
596 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
597 pr_err("template (%u) too big for tvmem (%lu)\n",
598 *keysize + *b_size,
599 TVMEMSIZE * PAGE_SIZE);
600 goto out;
601 }
602
603 key = tvmem[0];
604 for (j = 0; j < tcount; j++) {
605 if (template[j].klen == *keysize) {
606 key = template[j].key;
607 break;
608 }
609 }
610 ret = crypto_aead_setkey(tfm, key, *keysize);
611 ret = crypto_aead_setauthsize(tfm, authsize);
612
613 iv_len = crypto_aead_ivsize(tfm);
614 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200615 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800616
617 crypto_aead_clear_flags(tfm, ~0);
618 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
619 i, *keysize * 8, *b_size);
620
621
622 memset(tvmem[0], 0xff, PAGE_SIZE);
623
624 if (ret) {
625 pr_err("setkey() failed flags=%x\n",
626 crypto_aead_get_flags(tfm));
627 goto out;
628 }
629
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200630 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
631 assoc, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800632
Herbert Xu31267272015-06-17 14:05:26 +0800633 sg_init_aead(sgout, xoutbuf,
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200634 *b_size + (enc ? authsize : 0), assoc,
635 aad_size);
Herbert Xu31267272015-06-17 14:05:26 +0800636
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +0000637 aead_request_set_ad(req, aad_size);
638
639 if (!enc) {
640
641 /*
642 * For decryption we need a proper auth so
643 * we do the encryption path once with buffers
644 * reversed (input <-> output) to calculate it
645 */
646 aead_request_set_crypt(req, sgout, sg,
647 *b_size, iv);
648 ret = do_one_aead_op(req,
649 crypto_aead_encrypt(req));
650
651 if (ret) {
Randy Dunlap129a4db2020-07-30 19:39:24 -0700652 pr_err("calculating auth failed (%d)\n",
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +0000653 ret);
654 break;
655 }
656 }
657
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300658 aead_request_set_crypt(req, sg, sgout,
659 *b_size + (enc ? 0 : authsize),
660 iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800661
Horia Geantă2af63292018-07-23 17:18:48 +0300662 if (secs) {
Mark Rustad3e3dc252014-07-25 02:53:38 -0700663 ret = test_aead_jiffies(req, enc, *b_size,
664 secs);
Horia Geantă2af63292018-07-23 17:18:48 +0300665 cond_resched();
666 } else {
Tim Chen53f52d72013-12-11 14:28:47 -0800667 ret = test_aead_cycles(req, enc, *b_size);
Horia Geantă2af63292018-07-23 17:18:48 +0300668 }
Tim Chen53f52d72013-12-11 14:28:47 -0800669
670 if (ret) {
671 pr_err("%s() failed return code=%d\n", e, ret);
672 break;
673 }
674 b_size++;
675 i++;
676 } while (*b_size);
677 keysize++;
678 } while (*keysize);
679
680out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200681 aead_request_free(req);
682out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800683 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200684out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800685 kfree(sg);
686out_nosg:
687 testmgr_free_buf(xoutbuf);
688out_nooutbuf:
689 testmgr_free_buf(axbuf);
690out_noaxbuf:
691 testmgr_free_buf(xbuf);
692out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200693 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800694}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800695
David S. Millerbeb63da2010-05-19 14:11:21 +1000696static void test_hash_sg_init(struct scatterlist *sg)
697{
698 int i;
699
700 sg_init_table(sg, TVMEMSIZE);
701 for (i = 0; i < TVMEMSIZE; i++) {
702 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
703 memset(tvmem[i], 0xff, PAGE_SIZE);
704 }
705}
706
David S. Millerbeb63da2010-05-19 14:11:21 +1000707static inline int do_one_ahash_op(struct ahash_request *req, int ret)
708{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100709 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000710
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100711 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000712}
713
Herbert Xu72259de2016-06-28 20:33:52 +0800714struct test_mb_ahash_data {
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000715 struct scatterlist sg[XBUFSIZE];
Herbert Xu72259de2016-06-28 20:33:52 +0800716 char result[64];
717 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100718 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800719 char *xbuf[XBUFSIZE];
720};
Megha Dey087bcd22016-06-23 18:40:47 -0700721
Kees Cook4e234ee2018-04-26 19:57:28 -0700722static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
723 int *rc)
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000724{
Kees Cook4e234ee2018-04-26 19:57:28 -0700725 int i, err = 0;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000726
727 /* Fire up a bunch of concurrent requests */
728 for (i = 0; i < num_mb; i++)
729 rc[i] = crypto_ahash_digest(data[i].req);
730
731 /* Wait for all requests to finish */
732 for (i = 0; i < num_mb; i++) {
733 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
734
735 if (rc[i]) {
736 pr_info("concurrent request %d error %d\n", i, rc[i]);
737 err = rc[i];
738 }
739 }
740
741 return err;
742}
743
744static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
745 int secs, u32 num_mb)
746{
747 unsigned long start, end;
748 int bcount;
Kees Cook4e234ee2018-04-26 19:57:28 -0700749 int ret = 0;
750 int *rc;
751
752 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
753 if (!rc)
754 return -ENOMEM;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000755
756 for (start = jiffies, end = start + secs * HZ, bcount = 0;
757 time_before(jiffies, end); bcount++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700758 ret = do_mult_ahash_op(data, num_mb, rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000759 if (ret)
Kees Cook4e234ee2018-04-26 19:57:28 -0700760 goto out;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000761 }
762
763 pr_cont("%d operations in %d seconds (%ld bytes)\n",
764 bcount * num_mb, secs, (long)bcount * blen * num_mb);
Kees Cook4e234ee2018-04-26 19:57:28 -0700765
766out:
767 kfree(rc);
768 return ret;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000769}
770
771static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
772 u32 num_mb)
773{
774 unsigned long cycles = 0;
775 int ret = 0;
776 int i;
Kees Cook4e234ee2018-04-26 19:57:28 -0700777 int *rc;
778
779 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
780 if (!rc)
781 return -ENOMEM;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000782
783 /* Warm-up run. */
784 for (i = 0; i < 4; i++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700785 ret = do_mult_ahash_op(data, num_mb, rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000786 if (ret)
787 goto out;
788 }
789
790 /* The real thing. */
791 for (i = 0; i < 8; i++) {
792 cycles_t start, end;
793
794 start = get_cycles();
Kees Cook4e234ee2018-04-26 19:57:28 -0700795 ret = do_mult_ahash_op(data, num_mb, rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000796 end = get_cycles();
797
798 if (ret)
799 goto out;
800
801 cycles += end - start;
802 }
803
Kees Cook4e234ee2018-04-26 19:57:28 -0700804 pr_cont("1 operation in %lu cycles (%d bytes)\n",
805 (cycles + 4) / (8 * num_mb), blen);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000806
Kees Cook4e234ee2018-04-26 19:57:28 -0700807out:
808 kfree(rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000809 return ret;
810}
811
812static void test_mb_ahash_speed(const char *algo, unsigned int secs,
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000813 struct hash_speed *speed, u32 num_mb)
Megha Dey087bcd22016-06-23 18:40:47 -0700814{
Herbert Xu72259de2016-06-28 20:33:52 +0800815 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700816 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800817 unsigned int i, j, k;
818 int ret;
819
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000820 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
Herbert Xu72259de2016-06-28 20:33:52 +0800821 if (!data)
822 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700823
824 tfm = crypto_alloc_ahash(algo, 0, 0);
825 if (IS_ERR(tfm)) {
826 pr_err("failed to load transform for %s: %ld\n",
827 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800828 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700829 }
Herbert Xu72259de2016-06-28 20:33:52 +0800830
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000831 for (i = 0; i < num_mb; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800832 if (testmgr_alloc_buf(data[i].xbuf))
833 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700834
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100835 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700836
Herbert Xu72259de2016-06-28 20:33:52 +0800837 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
838 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200839 pr_err("alg: hash: Failed to allocate request for %s\n",
840 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800841 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700842 }
Megha Dey087bcd22016-06-23 18:40:47 -0700843
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100844 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
845 &data[i].wait);
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000846
847 sg_init_table(data[i].sg, XBUFSIZE);
848 for (j = 0; j < XBUFSIZE; j++) {
849 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
850 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
851 }
Megha Dey087bcd22016-06-23 18:40:47 -0700852 }
853
Herbert Xu72259de2016-06-28 20:33:52 +0800854 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
855 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700856
857 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800858 /* For some reason this only tests digests. */
859 if (speed[i].blen != speed[i].plen)
860 continue;
861
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000862 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200863 pr_err("template (%u) too big for tvmem (%lu)\n",
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000864 speed[i].blen, XBUFSIZE * PAGE_SIZE);
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200865 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700866 }
867
Herbert Xuba974ad2020-08-05 15:57:08 +1000868 if (klen)
869 crypto_ahash_setkey(tfm, tvmem[0], klen);
Megha Dey087bcd22016-06-23 18:40:47 -0700870
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000871 for (k = 0; k < num_mb; k++)
Herbert Xu72259de2016-06-28 20:33:52 +0800872 ahash_request_set_crypt(data[k].req, data[k].sg,
873 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700874
Herbert Xu72259de2016-06-28 20:33:52 +0800875 pr_info("test%3u "
876 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700877 i, speed[i].blen, speed[i].plen,
878 speed[i].blen / speed[i].plen);
879
Horia Geantă2af63292018-07-23 17:18:48 +0300880 if (secs) {
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000881 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
882 num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300883 cond_resched();
884 } else {
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000885 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300886 }
Herbert Xu72259de2016-06-28 20:33:52 +0800887
Herbert Xu72259de2016-06-28 20:33:52 +0800888
889 if (ret) {
890 pr_err("At least one hashing failed ret=%d\n", ret);
891 break;
892 }
Megha Dey087bcd22016-06-23 18:40:47 -0700893 }
Megha Dey087bcd22016-06-23 18:40:47 -0700894
895out:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000896 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800897 ahash_request_free(data[k].req);
898
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000899 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800900 testmgr_free_buf(data[k].xbuf);
901
902 crypto_free_ahash(tfm);
903
904free_data:
905 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700906}
907
David S. Millerbeb63da2010-05-19 14:11:21 +1000908static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700909 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000910{
911 unsigned long start, end;
912 int bcount;
913 int ret;
914
Mark Rustad3e3dc252014-07-25 02:53:38 -0700915 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000916 time_before(jiffies, end); bcount++) {
917 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
918 if (ret)
919 return ret;
920 }
921
922 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700923 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000924
925 return 0;
926}
927
928static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700929 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000930{
931 unsigned long start, end;
932 int bcount, pcount;
933 int ret;
934
935 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700936 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000937
Mark Rustad3e3dc252014-07-25 02:53:38 -0700938 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000939 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800940 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000941 if (ret)
942 return ret;
943 for (pcount = 0; pcount < blen; pcount += plen) {
944 ret = do_one_ahash_op(req, crypto_ahash_update(req));
945 if (ret)
946 return ret;
947 }
948 /* we assume there is enough space in 'out' for the result */
949 ret = do_one_ahash_op(req, crypto_ahash_final(req));
950 if (ret)
951 return ret;
952 }
953
954 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700955 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000956
957 return 0;
958}
959
960static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
961 char *out)
962{
963 unsigned long cycles = 0;
964 int ret, i;
965
966 /* Warm-up run. */
967 for (i = 0; i < 4; i++) {
968 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
969 if (ret)
970 goto out;
971 }
972
973 /* The real thing. */
974 for (i = 0; i < 8; i++) {
975 cycles_t start, end;
976
977 start = get_cycles();
978
979 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
980 if (ret)
981 goto out;
982
983 end = get_cycles();
984
985 cycles += end - start;
986 }
987
988out:
989 if (ret)
990 return ret;
991
992 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
993 cycles / 8, cycles / (8 * blen));
994
995 return 0;
996}
997
998static int test_ahash_cycles(struct ahash_request *req, int blen,
999 int plen, char *out)
1000{
1001 unsigned long cycles = 0;
1002 int i, pcount, ret;
1003
1004 if (plen == blen)
1005 return test_ahash_cycles_digest(req, blen, out);
1006
1007 /* Warm-up run. */
1008 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +08001009 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +10001010 if (ret)
1011 goto out;
1012 for (pcount = 0; pcount < blen; pcount += plen) {
1013 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1014 if (ret)
1015 goto out;
1016 }
1017 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1018 if (ret)
1019 goto out;
1020 }
1021
1022 /* The real thing. */
1023 for (i = 0; i < 8; i++) {
1024 cycles_t start, end;
1025
1026 start = get_cycles();
1027
Herbert Xu43a96072015-04-22 11:02:27 +08001028 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +10001029 if (ret)
1030 goto out;
1031 for (pcount = 0; pcount < blen; pcount += plen) {
1032 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1033 if (ret)
1034 goto out;
1035 }
1036 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1037 if (ret)
1038 goto out;
1039
1040 end = get_cycles();
1041
1042 cycles += end - start;
1043 }
1044
1045out:
1046 if (ret)
1047 return ret;
1048
1049 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1050 cycles / 8, cycles / (8 * blen));
1051
1052 return 0;
1053}
1054
Herbert Xu06605112016-02-01 21:36:49 +08001055static void test_ahash_speed_common(const char *algo, unsigned int secs,
1056 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +10001057{
1058 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001059 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +10001060 struct ahash_request *req;
1061 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +03001062 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +10001063 int i, ret;
1064
Herbert Xu06605112016-02-01 21:36:49 +08001065 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +10001066 if (IS_ERR(tfm)) {
1067 pr_err("failed to load transform for %s: %ld\n",
1068 algo, PTR_ERR(tfm));
1069 return;
1070 }
1071
Luca Clementi263a8df2014-06-25 22:57:42 -07001072 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1073 get_driver_name(crypto_ahash, tfm));
1074
Horia Geant?f074f7b2015-08-27 18:38:36 +03001075 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1076 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1077 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +10001078 goto out;
1079 }
1080
1081 test_hash_sg_init(sg);
1082 req = ahash_request_alloc(tfm, GFP_KERNEL);
1083 if (!req) {
1084 pr_err("ahash request allocation failure\n");
1085 goto out;
1086 }
1087
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001088 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +10001089 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001090 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +10001091
Horia Geant?f074f7b2015-08-27 18:38:36 +03001092 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1093 if (!output)
1094 goto out_nomem;
1095
David S. Millerbeb63da2010-05-19 14:11:21 +10001096 for (i = 0; speed[i].blen != 0; i++) {
1097 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1098 pr_err("template (%u) too big for tvmem (%lu)\n",
1099 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1100 break;
1101 }
1102
Herbert Xuba974ad2020-08-05 15:57:08 +10001103 if (klen)
1104 crypto_ahash_setkey(tfm, tvmem[0], klen);
Horia Geantă331351f2018-09-12 16:20:48 +03001105
David S. Millerbeb63da2010-05-19 14:11:21 +10001106 pr_info("test%3u "
1107 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1108 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1109
1110 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1111
Horia Geantă2af63292018-07-23 17:18:48 +03001112 if (secs) {
David S. Millerbeb63da2010-05-19 14:11:21 +10001113 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001114 speed[i].plen, output, secs);
Horia Geantă2af63292018-07-23 17:18:48 +03001115 cond_resched();
1116 } else {
David S. Millerbeb63da2010-05-19 14:11:21 +10001117 ret = test_ahash_cycles(req, speed[i].blen,
1118 speed[i].plen, output);
Horia Geantă2af63292018-07-23 17:18:48 +03001119 }
David S. Millerbeb63da2010-05-19 14:11:21 +10001120
1121 if (ret) {
1122 pr_err("hashing failed ret=%d\n", ret);
1123 break;
1124 }
1125 }
1126
Horia Geant?f074f7b2015-08-27 18:38:36 +03001127 kfree(output);
1128
1129out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +10001130 ahash_request_free(req);
1131
1132out:
1133 crypto_free_ahash(tfm);
1134}
1135
Herbert Xu06605112016-02-01 21:36:49 +08001136static void test_ahash_speed(const char *algo, unsigned int secs,
1137 struct hash_speed *speed)
1138{
1139 return test_ahash_speed_common(algo, secs, speed, 0);
1140}
1141
1142static void test_hash_speed(const char *algo, unsigned int secs,
1143 struct hash_speed *speed)
1144{
1145 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1146}
1147
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001148struct test_mb_skcipher_data {
1149 struct scatterlist sg[XBUFSIZE];
1150 struct skcipher_request *req;
1151 struct crypto_wait wait;
1152 char *xbuf[XBUFSIZE];
1153};
1154
1155static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
Kees Cook4e234ee2018-04-26 19:57:28 -07001156 u32 num_mb, int *rc)
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001157{
Kees Cook4e234ee2018-04-26 19:57:28 -07001158 int i, err = 0;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001159
1160 /* Fire up a bunch of concurrent requests */
1161 for (i = 0; i < num_mb; i++) {
1162 if (enc == ENCRYPT)
1163 rc[i] = crypto_skcipher_encrypt(data[i].req);
1164 else
1165 rc[i] = crypto_skcipher_decrypt(data[i].req);
1166 }
1167
1168 /* Wait for all requests to finish */
1169 for (i = 0; i < num_mb; i++) {
1170 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1171
1172 if (rc[i]) {
1173 pr_info("concurrent request %d error %d\n", i, rc[i]);
1174 err = rc[i];
1175 }
1176 }
1177
1178 return err;
1179}
1180
1181static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1182 int blen, int secs, u32 num_mb)
1183{
1184 unsigned long start, end;
1185 int bcount;
Kees Cook4e234ee2018-04-26 19:57:28 -07001186 int ret = 0;
1187 int *rc;
1188
1189 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1190 if (!rc)
1191 return -ENOMEM;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001192
1193 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1194 time_before(jiffies, end); bcount++) {
Kees Cook4e234ee2018-04-26 19:57:28 -07001195 ret = do_mult_acipher_op(data, enc, num_mb, rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001196 if (ret)
Kees Cook4e234ee2018-04-26 19:57:28 -07001197 goto out;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001198 }
1199
1200 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1201 bcount * num_mb, secs, (long)bcount * blen * num_mb);
Kees Cook4e234ee2018-04-26 19:57:28 -07001202
1203out:
1204 kfree(rc);
1205 return ret;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001206}
1207
1208static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1209 int blen, u32 num_mb)
1210{
1211 unsigned long cycles = 0;
1212 int ret = 0;
1213 int i;
Kees Cook4e234ee2018-04-26 19:57:28 -07001214 int *rc;
1215
1216 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1217 if (!rc)
1218 return -ENOMEM;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001219
1220 /* Warm-up run. */
1221 for (i = 0; i < 4; i++) {
Kees Cook4e234ee2018-04-26 19:57:28 -07001222 ret = do_mult_acipher_op(data, enc, num_mb, rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001223 if (ret)
1224 goto out;
1225 }
1226
1227 /* The real thing. */
1228 for (i = 0; i < 8; i++) {
1229 cycles_t start, end;
1230
1231 start = get_cycles();
Kees Cook4e234ee2018-04-26 19:57:28 -07001232 ret = do_mult_acipher_op(data, enc, num_mb, rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001233 end = get_cycles();
1234
1235 if (ret)
1236 goto out;
1237
1238 cycles += end - start;
1239 }
1240
Kees Cook4e234ee2018-04-26 19:57:28 -07001241 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1242 (cycles + 4) / (8 * num_mb), blen);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001243
Kees Cook4e234ee2018-04-26 19:57:28 -07001244out:
1245 kfree(rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001246 return ret;
1247}
1248
1249static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1250 struct cipher_speed_template *template,
1251 unsigned int tcount, u8 *keysize, u32 num_mb)
1252{
1253 struct test_mb_skcipher_data *data;
1254 struct crypto_skcipher *tfm;
1255 unsigned int i, j, iv_len;
1256 const char *key;
1257 const char *e;
1258 u32 *b_size;
1259 char iv[128];
1260 int ret;
1261
1262 if (enc == ENCRYPT)
1263 e = "encryption";
1264 else
1265 e = "decryption";
1266
1267 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1268 if (!data)
1269 return;
1270
1271 tfm = crypto_alloc_skcipher(algo, 0, 0);
1272 if (IS_ERR(tfm)) {
1273 pr_err("failed to load transform for %s: %ld\n",
1274 algo, PTR_ERR(tfm));
1275 goto out_free_data;
1276 }
1277
1278 for (i = 0; i < num_mb; ++i)
1279 if (testmgr_alloc_buf(data[i].xbuf)) {
1280 while (i--)
1281 testmgr_free_buf(data[i].xbuf);
1282 goto out_free_tfm;
1283 }
1284
1285
1286 for (i = 0; i < num_mb; ++i)
1287 if (testmgr_alloc_buf(data[i].xbuf)) {
1288 while (i--)
1289 testmgr_free_buf(data[i].xbuf);
1290 goto out_free_tfm;
1291 }
1292
1293
1294 for (i = 0; i < num_mb; ++i) {
1295 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1296 if (!data[i].req) {
1297 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1298 algo);
1299 while (i--)
1300 skcipher_request_free(data[i].req);
1301 goto out_free_xbuf;
1302 }
1303 }
1304
1305 for (i = 0; i < num_mb; ++i) {
1306 skcipher_request_set_callback(data[i].req,
1307 CRYPTO_TFM_REQ_MAY_BACKLOG,
1308 crypto_req_done, &data[i].wait);
1309 crypto_init_wait(&data[i].wait);
1310 }
1311
1312 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1313 get_driver_name(crypto_skcipher, tfm), e);
1314
1315 i = 0;
1316 do {
1317 b_size = block_sizes;
1318 do {
1319 if (*b_size > XBUFSIZE * PAGE_SIZE) {
Colin Ian King38dbe2d2018-01-02 09:21:06 +00001320 pr_err("template (%u) too big for buffer (%lu)\n",
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001321 *b_size, XBUFSIZE * PAGE_SIZE);
1322 goto out;
1323 }
1324
1325 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1326 *keysize * 8, *b_size);
1327
1328 /* Set up tfm global state, i.e. the key */
1329
1330 memset(tvmem[0], 0xff, PAGE_SIZE);
1331 key = tvmem[0];
1332 for (j = 0; j < tcount; j++) {
1333 if (template[j].klen == *keysize) {
1334 key = template[j].key;
1335 break;
1336 }
1337 }
1338
1339 crypto_skcipher_clear_flags(tfm, ~0);
1340
1341 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1342 if (ret) {
1343 pr_err("setkey() failed flags=%x\n",
1344 crypto_skcipher_get_flags(tfm));
1345 goto out;
1346 }
1347
1348 iv_len = crypto_skcipher_ivsize(tfm);
1349 if (iv_len)
1350 memset(&iv, 0xff, iv_len);
1351
1352 /* Now setup per request stuff, i.e. buffers */
1353
1354 for (j = 0; j < num_mb; ++j) {
1355 struct test_mb_skcipher_data *cur = &data[j];
1356 unsigned int k = *b_size;
1357 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1358 unsigned int p = 0;
1359
1360 sg_init_table(cur->sg, pages);
1361
1362 while (k > PAGE_SIZE) {
1363 sg_set_buf(cur->sg + p, cur->xbuf[p],
1364 PAGE_SIZE);
1365 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1366 p++;
1367 k -= PAGE_SIZE;
1368 }
1369
1370 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1371 memset(cur->xbuf[p], 0xff, k);
1372
1373 skcipher_request_set_crypt(cur->req, cur->sg,
1374 cur->sg, *b_size,
1375 iv);
1376 }
1377
Horia Geantă2af63292018-07-23 17:18:48 +03001378 if (secs) {
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001379 ret = test_mb_acipher_jiffies(data, enc,
1380 *b_size, secs,
1381 num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +03001382 cond_resched();
1383 } else {
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001384 ret = test_mb_acipher_cycles(data, enc,
1385 *b_size, num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +03001386 }
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001387
1388 if (ret) {
1389 pr_err("%s() failed flags=%x\n", e,
1390 crypto_skcipher_get_flags(tfm));
1391 break;
1392 }
1393 b_size++;
1394 i++;
1395 } while (*b_size);
1396 keysize++;
1397 } while (*keysize);
1398
1399out:
1400 for (i = 0; i < num_mb; ++i)
1401 skcipher_request_free(data[i].req);
1402out_free_xbuf:
1403 for (i = 0; i < num_mb; ++i)
1404 testmgr_free_buf(data[i].xbuf);
1405out_free_tfm:
1406 crypto_free_skcipher(tfm);
1407out_free_data:
1408 kfree(data);
1409}
1410
Herbert Xu7166e582016-06-29 18:03:50 +08001411static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001412{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001413 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001414
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001415 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001416}
1417
Herbert Xu7166e582016-06-29 18:03:50 +08001418static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001419 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001420{
1421 unsigned long start, end;
1422 int bcount;
1423 int ret;
1424
Mark Rustad3e3dc252014-07-25 02:53:38 -07001425 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001426 time_before(jiffies, end); bcount++) {
1427 if (enc)
1428 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001429 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001430 else
1431 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001432 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001433
1434 if (ret)
1435 return ret;
1436 }
1437
1438 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -07001439 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001440 return 0;
1441}
1442
Herbert Xu7166e582016-06-29 18:03:50 +08001443static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001444 int blen)
1445{
1446 unsigned long cycles = 0;
1447 int ret = 0;
1448 int i;
1449
1450 /* Warm-up run. */
1451 for (i = 0; i < 4; i++) {
1452 if (enc)
1453 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001454 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001455 else
1456 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001457 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001458
1459 if (ret)
1460 goto out;
1461 }
1462
1463 /* The real thing. */
1464 for (i = 0; i < 8; i++) {
1465 cycles_t start, end;
1466
1467 start = get_cycles();
1468 if (enc)
1469 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001470 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001471 else
1472 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001473 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001474 end = get_cycles();
1475
1476 if (ret)
1477 goto out;
1478
1479 cycles += end - start;
1480 }
1481
1482out:
1483 if (ret == 0)
1484 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1485 (cycles + 4) / 8, blen);
1486
1487 return ret;
1488}
1489
Herbert Xu7166e582016-06-29 18:03:50 +08001490static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1491 struct cipher_speed_template *template,
1492 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001493{
Nicolas Royerde1975332012-07-01 19:19:47 +02001494 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001495 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001496 const char *key;
1497 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +08001498 struct skcipher_request *req;
1499 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001500 const char *e;
1501 u32 *b_size;
1502
1503 if (enc == ENCRYPT)
1504 e = "encryption";
1505 else
1506 e = "decryption";
1507
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001508 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001509
Herbert Xu7166e582016-06-29 18:03:50 +08001510 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001511
1512 if (IS_ERR(tfm)) {
1513 pr_err("failed to load transform for %s: %ld\n", algo,
1514 PTR_ERR(tfm));
1515 return;
1516 }
1517
Horia Geantă8e3b7fd2020-02-05 12:19:58 +02001518 pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync",
1519 algo, get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -07001520
Herbert Xu7166e582016-06-29 18:03:50 +08001521 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001522 if (!req) {
1523 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1524 algo);
1525 goto out;
1526 }
1527
Herbert Xu7166e582016-06-29 18:03:50 +08001528 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001529 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001530
1531 i = 0;
1532 do {
1533 b_size = block_sizes;
1534
1535 do {
1536 struct scatterlist sg[TVMEMSIZE];
1537
1538 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1539 pr_err("template (%u) too big for "
1540 "tvmem (%lu)\n", *keysize + *b_size,
1541 TVMEMSIZE * PAGE_SIZE);
1542 goto out_free_req;
1543 }
1544
1545 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1546 *keysize * 8, *b_size);
1547
1548 memset(tvmem[0], 0xff, PAGE_SIZE);
1549
1550 /* set key, plain text and IV */
1551 key = tvmem[0];
1552 for (j = 0; j < tcount; j++) {
1553 if (template[j].klen == *keysize) {
1554 key = template[j].key;
1555 break;
1556 }
1557 }
1558
Herbert Xu7166e582016-06-29 18:03:50 +08001559 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001560
Herbert Xu7166e582016-06-29 18:03:50 +08001561 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001562 if (ret) {
1563 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +08001564 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001565 goto out_free_req;
1566 }
1567
Nicolas Royerde1975332012-07-01 19:19:47 +02001568 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +02001569 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1570
Nicolas Royerde1975332012-07-01 19:19:47 +02001571 if (k > PAGE_SIZE) {
1572 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001573 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +02001574 k -= PAGE_SIZE;
1575 j = 1;
1576 while (k > PAGE_SIZE) {
1577 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1578 memset(tvmem[j], 0xff, PAGE_SIZE);
1579 j++;
1580 k -= PAGE_SIZE;
1581 }
1582 sg_set_buf(sg + j, tvmem[j], k);
1583 memset(tvmem[j], 0xff, k);
1584 } else {
1585 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001586 }
1587
Herbert Xu7166e582016-06-29 18:03:50 +08001588 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001589 if (iv_len)
1590 memset(&iv, 0xff, iv_len);
1591
Herbert Xu7166e582016-06-29 18:03:50 +08001592 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001593
Horia Geantă2af63292018-07-23 17:18:48 +03001594 if (secs) {
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001595 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001596 *b_size, secs);
Horia Geantă2af63292018-07-23 17:18:48 +03001597 cond_resched();
1598 } else {
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001599 ret = test_acipher_cycles(req, enc,
1600 *b_size);
Horia Geantă2af63292018-07-23 17:18:48 +03001601 }
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001602
1603 if (ret) {
1604 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +08001605 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001606 break;
1607 }
1608 b_size++;
1609 i++;
1610 } while (*b_size);
1611 keysize++;
1612 } while (*keysize);
1613
1614out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +08001615 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001616out:
Herbert Xu7166e582016-06-29 18:03:50 +08001617 crypto_free_skcipher(tfm);
1618}
1619
1620static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1621 struct cipher_speed_template *template,
1622 unsigned int tcount, u8 *keysize)
1623{
1624 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1625 true);
1626}
1627
1628static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1629 struct cipher_speed_template *template,
1630 unsigned int tcount, u8 *keysize)
1631{
1632 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1633 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001634}
1635
Herbert Xuef2736f2005-06-22 13:26:03 -07001636static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
Corentin Labbe07d8f182019-11-08 15:42:13 +00001638 const char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 while (*name) {
1641 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001642 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001643 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646}
1647
Herbert Xu01b32322008-07-31 15:41:55 +08001648static inline int tcrypt_test(const char *alg)
1649{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001650 int ret;
1651
Rabin Vincent76512f22017-01-18 14:54:05 +01001652 pr_debug("testing %s\n", alg);
1653
Jarod Wilson4e033a62009-05-27 15:10:21 +10001654 ret = alg_test(alg, alg, 0, 0);
1655 /* non-fips algs return -EINVAL in fips mode */
1656 if (fips_enabled && ret == -EINVAL)
1657 ret = 0;
1658 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001659}
1660
Kees Cook4e234ee2018-04-26 19:57:28 -07001661static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
Herbert Xu01b32322008-07-31 15:41:55 +08001662{
1663 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001664 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001665
1666 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001668 if (alg) {
1669 if (!crypto_has_alg(alg, type,
1670 mask ?: CRYPTO_ALG_TYPE_MASK))
1671 ret = -ENOENT;
1672 break;
1673 }
1674
Herbert Xu01b32322008-07-31 15:41:55 +08001675 for (i = 1; i < 200; i++)
Kees Cook4e234ee2018-04-26 19:57:28 -07001676 ret += do_test(NULL, 0, 0, i, num_mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 break;
1678
1679 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001680 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 break;
1682
1683 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001684 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 break;
1686
1687 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001688 ret += tcrypt_test("ecb(des)");
1689 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001690 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 break;
1692
1693 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001694 ret += tcrypt_test("ecb(des3_ede)");
1695 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001696 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 break;
1698
1699 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001700 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001704 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001708 ret += tcrypt_test("ecb(blowfish)");
1709 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001710 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 break;
1712
1713 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001714 ret += tcrypt_test("ecb(twofish)");
1715 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001716 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001717 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001718 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001722 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001723 ret += tcrypt_test("cbc(serpent)");
1724 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001725 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001726 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 break;
1728
1729 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001730 ret += tcrypt_test("ecb(aes)");
1731 ret += tcrypt_test("cbc(aes)");
1732 ret += tcrypt_test("lrw(aes)");
1733 ret += tcrypt_test("xts(aes)");
1734 ret += tcrypt_test("ctr(aes)");
1735 ret += tcrypt_test("rfc3686(ctr(aes))");
Gilad Ben-Yossefdfb89ab2018-09-20 14:18:40 +01001736 ret += tcrypt_test("ofb(aes)");
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03001737 ret += tcrypt_test("cfb(aes)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 break;
1739
1740 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001741 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001743
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001745 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 break;
1747
1748 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001749 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 break;
1751
1752 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001753 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001754 ret += tcrypt_test("cbc(cast5)");
1755 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 break;
1757
1758 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001759 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001760 ret += tcrypt_test("cbc(cast6)");
1761 ret += tcrypt_test("ctr(cast6)");
1762 ret += tcrypt_test("lrw(cast6)");
1763 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 break;
1765
1766 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001767 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 break;
1769
1770 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001771 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 break;
1773
1774 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001775 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 break;
1777
1778 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001779 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 break;
1781
1782 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001783 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 break;
1785
1786 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001787 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 break;
1789
1790 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001791 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 break;
1793
1794 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001795 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 break;
1797
1798 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001799 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 break;
1801
1802 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001803 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 break;
1805
1806 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001807 ret += tcrypt_test("ecb(anubis)");
1808 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 break;
1810
1811 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001812 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 break;
1814
1815 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001816 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 break;
1818
1819 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001820 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001822
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001823 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001824 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001825 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
David Howells90831632006-12-16 12:13:14 +11001827 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001828 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001829 break;
1830
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001831 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001832 ret += tcrypt_test("ecb(camellia)");
1833 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001834 ret += tcrypt_test("ctr(camellia)");
1835 ret += tcrypt_test("lrw(camellia)");
1836 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001837 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001838
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001839 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001840 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001841 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001842
Tan Swee Heng2407d602007-11-23 19:45:00 +08001843 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001844 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001845 break;
1846
Herbert Xu8df213d2007-12-02 14:55:47 +11001847 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001848 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001849 break;
1850
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001851 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001852 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001853 break;
1854
Joy Latten93cc74e2007-12-12 20:24:22 +08001855 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001856 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001857 break;
1858
Kevin Coffman76cb9522008-03-24 21:26:16 +08001859 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001860 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001861 break;
1862
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001863 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001864 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001865 break;
1866
1867 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001868 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001869 break;
1870
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001871 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001872 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001873 break;
1874
1875 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001876 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001877 break;
1878
1879 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001880 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001881 break;
1882
Jarod Wilson5d667322009-05-04 19:23:40 +08001883 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001884 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001885 break;
1886
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001887 case 46:
1888 ret += tcrypt_test("ghash");
1889 break;
1890
Herbert Xu684115212013-09-07 12:56:26 +10001891 case 47:
1892 ret += tcrypt_test("crct10dif");
1893 break;
1894
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301895 case 48:
1896 ret += tcrypt_test("sha3-224");
1897 break;
1898
1899 case 49:
1900 ret += tcrypt_test("sha3-256");
1901 break;
1902
1903 case 50:
1904 ret += tcrypt_test("sha3-384");
1905 break;
1906
1907 case 51:
1908 ret += tcrypt_test("sha3-512");
1909 break;
1910
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001911 case 52:
1912 ret += tcrypt_test("sm3");
1913 break;
1914
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03001915 case 53:
1916 ret += tcrypt_test("streebog256");
1917 break;
1918
1919 case 54:
1920 ret += tcrypt_test("streebog512");
1921 break;
1922
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001924 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001928 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001930
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001932 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 break;
1934
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001935 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001936 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001937 break;
1938
1939 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001940 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001941 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001942
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001943 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001944 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001945 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001947 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001948 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001949 break;
1950
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001951 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001952 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001953 break;
1954
1955 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001956 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001957 break;
1958
Shane Wangf1939f72009-09-02 20:05:22 +10001959 case 109:
Eric Biggers0917b872018-06-18 10:22:40 -07001960 ret += tcrypt_test("vmac64(aes)");
Shane Wangf1939f72009-09-02 20:05:22 +10001961 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001962
raveendra padasalagi98eca722016-07-01 11:16:54 +05301963 case 111:
1964 ret += tcrypt_test("hmac(sha3-224)");
1965 break;
1966
1967 case 112:
1968 ret += tcrypt_test("hmac(sha3-256)");
1969 break;
1970
1971 case 113:
1972 ret += tcrypt_test("hmac(sha3-384)");
1973 break;
1974
1975 case 114:
1976 ret += tcrypt_test("hmac(sha3-512)");
1977 break;
1978
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03001979 case 115:
1980 ret += tcrypt_test("hmac(streebog256)");
1981 break;
1982
1983 case 116:
1984 ret += tcrypt_test("hmac(streebog512)");
1985 break;
1986
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001987 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001988 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001989 break;
1990
Adrian Hoban69435b92010-11-04 15:02:04 -04001991 case 151:
1992 ret += tcrypt_test("rfc4106(gcm(aes))");
1993 break;
1994
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001995 case 152:
1996 ret += tcrypt_test("rfc4543(gcm(aes))");
1997 break;
1998
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001999 case 153:
2000 ret += tcrypt_test("cmac(aes)");
2001 break;
2002
2003 case 154:
2004 ret += tcrypt_test("cmac(des3_ede)");
2005 break;
2006
Horia Geantabbf9c892013-11-28 15:11:16 +02002007 case 155:
2008 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
2009 break;
2010
Horia Geantabca4feb2014-03-14 17:46:51 +02002011 case 156:
2012 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
2013 break;
2014
2015 case 157:
2016 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2017 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05302018 case 181:
2019 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2020 break;
2021 case 182:
2022 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2023 break;
2024 case 183:
2025 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2026 break;
2027 case 184:
2028 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2029 break;
2030 case 185:
2031 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2032 break;
2033 case 186:
2034 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2035 break;
2036 case 187:
2037 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2038 break;
2039 case 188:
2040 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2041 break;
2042 case 189:
2043 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2044 break;
2045 case 190:
2046 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2047 break;
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00002048 case 191:
2049 ret += tcrypt_test("ecb(sm4)");
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002050 ret += tcrypt_test("cbc(sm4)");
2051 ret += tcrypt_test("ctr(sm4)");
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00002052 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07002053 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10002054 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002055 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002056 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002057 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002058 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002059 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002060 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002061 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11002062 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002063 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11002064 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002065 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08002066 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002067 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08002068 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002069 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08002070 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2071 speed_template_16_24_32);
2072 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2073 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10002074 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2075 speed_template_16_24_32);
2076 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2077 speed_template_16_24_32);
Dmitry Eremin-Solenikov7da66672018-10-20 02:01:53 +03002078 test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2079 speed_template_16_24_32);
2080 test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2081 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002082 break;
2083
2084 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10002085 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002086 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002087 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10002088 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002089 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002090 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10002091 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002092 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002093 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10002094 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002095 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002096 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03002097 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2098 des3_speed_template, DES3_SPEED_VECTORS,
2099 speed_template_24);
2100 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2101 des3_speed_template, DES3_SPEED_VECTORS,
2102 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002103 break;
2104
2105 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10002106 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002107 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002108 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002109 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002110 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002111 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002112 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002113 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03002114 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2115 speed_template_16_24_32);
2116 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2117 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03002118 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2119 speed_template_32_40_48);
2120 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2121 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03002122 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2123 speed_template_32_48_64);
2124 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2125 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002126 break;
2127
2128 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10002129 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002130 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10002131 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002132 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10002133 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002134 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10002135 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002136 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03002137 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2138 speed_template_8_32);
2139 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2140 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002141 break;
2142
2143 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10002144 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002145 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10002146 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002147 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10002148 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002149 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10002150 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002151 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002152 break;
2153
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002154 case 205:
2155 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002156 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002157 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002158 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002159 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002160 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002161 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002162 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02002163 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2164 speed_template_16_24_32);
2165 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2166 speed_template_16_24_32);
2167 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2168 speed_template_32_40_48);
2169 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2170 speed_template_32_40_48);
2171 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2172 speed_template_32_48_64);
2173 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2174 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002175 break;
2176
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08002177 case 206:
2178 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002179 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08002180 break;
2181
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002182 case 207:
2183 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2184 speed_template_16_32);
2185 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2186 speed_template_16_32);
2187 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2188 speed_template_16_32);
2189 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2190 speed_template_16_32);
2191 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2192 speed_template_16_32);
2193 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2194 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002195 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2196 speed_template_32_48);
2197 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2198 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002199 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2200 speed_template_32_64);
2201 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2202 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002203 break;
2204
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002205 case 208:
2206 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2207 speed_template_8);
2208 break;
2209
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002210 case 209:
2211 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2212 speed_template_8_16);
2213 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2214 speed_template_8_16);
2215 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2216 speed_template_8_16);
2217 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2218 speed_template_8_16);
2219 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2220 speed_template_8_16);
2221 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2222 speed_template_8_16);
2223 break;
2224
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002225 case 210:
2226 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2227 speed_template_16_32);
2228 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2229 speed_template_16_32);
2230 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2231 speed_template_16_32);
2232 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2233 speed_template_16_32);
2234 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2235 speed_template_16_32);
2236 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2237 speed_template_16_32);
2238 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2239 speed_template_32_48);
2240 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2241 speed_template_32_48);
2242 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2243 speed_template_32_64);
2244 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2245 speed_template_32_64);
2246 break;
2247
Tim Chen53f52d72013-12-11 14:28:47 -08002248 case 211:
2249 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08002250 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05302251 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01002252 NULL, 0, 16, 8, speed_template_16_24_32);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00002253 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2254 NULL, 0, 16, 16, aead_speed_template_20);
2255 test_aead_speed("gcm(aes)", DECRYPT, sec,
2256 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08002257 break;
2258
Herbert Xu4e4aab62015-06-17 14:04:21 +08002259 case 212:
2260 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08002261 NULL, 0, 16, 16, aead_speed_template_19);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00002262 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2263 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08002264 break;
2265
Martin Willi2dce0632015-07-16 19:13:59 +02002266 case 213:
2267 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2268 NULL, 0, 16, 8, aead_speed_template_36);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00002269 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2270 NULL, 0, 16, 8, aead_speed_template_36);
Martin Willi2dce0632015-07-16 19:13:59 +02002271 break;
2272
2273 case 214:
2274 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2275 speed_template_32);
2276 break;
2277
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +00002278 case 215:
2279 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2280 0, 16, 16, aead_speed_template_20, num_mb);
2281 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2282 speed_template_16_24_32, num_mb);
2283 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2284 0, 16, 16, aead_speed_template_20, num_mb);
2285 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2286 speed_template_16_24_32, num_mb);
2287 break;
2288
2289 case 216:
2290 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2291 16, 16, aead_speed_template_19, num_mb);
2292 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2293 16, 16, aead_speed_template_19, num_mb);
2294 break;
2295
2296 case 217:
2297 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2298 sec, NULL, 0, 16, 8, aead_speed_template_36,
2299 num_mb);
2300 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2301 sec, NULL, 0, 16, 8, aead_speed_template_36,
2302 num_mb);
2303 break;
2304
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002305 case 218:
2306 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2307 speed_template_16);
2308 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2309 speed_template_16);
2310 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2311 speed_template_16);
2312 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2313 speed_template_16);
2314 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2315 speed_template_16);
2316 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2317 speed_template_16);
2318 break;
Eric Biggers059c2a42018-11-16 17:26:31 -08002319
2320 case 219:
2321 test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL,
2322 0, speed_template_32);
2323 test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL,
2324 0, speed_template_32);
2325 test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL,
2326 0, speed_template_32);
2327 test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL,
2328 0, speed_template_32);
2329 break;
2330
Ard Biesheuvelf975abb2019-08-19 17:17:34 +03002331 case 220:
2332 test_acipher_speed("essiv(cbc(aes),sha256)",
2333 ENCRYPT, sec, NULL, 0,
2334 speed_template_16_24_32);
2335 test_acipher_speed("essiv(cbc(aes),sha256)",
2336 DECRYPT, sec, NULL, 0,
2337 speed_template_16_24_32);
2338 break;
2339
Ard Biesheuvel97bcb162019-07-03 10:55:12 +02002340 case 221:
2341 test_aead_speed("aegis128", ENCRYPT, sec,
2342 NULL, 0, 16, 8, speed_template_16);
2343 test_aead_speed("aegis128", DECRYPT, sec,
2344 NULL, 0, 16, 8, speed_template_16);
2345 break;
2346
Michal Ludvige8057922006-05-30 22:04:19 +10002347 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08002348 if (alg) {
2349 test_hash_speed(alg, sec, generic_hash_speed_template);
2350 break;
2351 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002352 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002353 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10002354 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002355 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002356 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002357 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10002358 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002359 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002360 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002361 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10002362 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002363 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002364 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002365 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10002366 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002367 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002368 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002369 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10002370 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002371 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002372 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002373 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10002374 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002375 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002376 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002377 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10002378 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002379 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002380 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002381 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10002382 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002383 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002384 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002385 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10002386 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002387 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002388 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002389 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10002390 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002391 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002392 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002393 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10002394 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002395 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002396 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002397 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10002398 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002399 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002400 fallthrough;
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08002401 case 313:
2402 test_hash_speed("sha224", sec, generic_hash_speed_template);
2403 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002404 fallthrough;
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08002405 case 314:
2406 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2407 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002408 fallthrough;
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08002409 case 315:
2410 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2411 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002412 fallthrough;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08002413 case 316:
2414 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2415 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002416 fallthrough;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08002417 case 317:
2418 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2419 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002420 fallthrough;
Huang Ying18bcc912010-03-10 18:30:32 +08002421 case 318:
Herbert Xuba974ad2020-08-05 15:57:08 +10002422 klen = 16;
2423 test_hash_speed("ghash", sec, generic_hash_speed_template);
Huang Ying18bcc912010-03-10 18:30:32 +08002424 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002425 fallthrough;
Tim Chene3899e42012-09-27 15:44:24 -07002426 case 319:
2427 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2428 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002429 fallthrough;
Herbert Xu684115212013-09-07 12:56:26 +10002430 case 320:
2431 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2432 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002433 fallthrough;
Martin Willi2dce0632015-07-16 19:13:59 +02002434 case 321:
2435 test_hash_speed("poly1305", sec, poly1305_speed_template);
2436 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002437 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302438 case 322:
2439 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2440 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002441 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302442 case 323:
2443 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2444 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002445 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302446 case 324:
2447 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2448 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002449 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302450 case 325:
2451 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2452 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002453 fallthrough;
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002454 case 326:
2455 test_hash_speed("sm3", sec, generic_hash_speed_template);
2456 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002457 fallthrough;
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03002458 case 327:
2459 test_hash_speed("streebog256", sec,
2460 generic_hash_speed_template);
2461 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002462 fallthrough;
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03002463 case 328:
2464 test_hash_speed("streebog512", sec,
2465 generic_hash_speed_template);
2466 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002467 fallthrough;
Michal Ludvige8057922006-05-30 22:04:19 +10002468 case 399:
2469 break;
2470
David S. Millerbeb63da2010-05-19 14:11:21 +10002471 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08002472 if (alg) {
2473 test_ahash_speed(alg, sec, generic_hash_speed_template);
2474 break;
2475 }
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002476 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002477 case 401:
2478 test_ahash_speed("md4", sec, generic_hash_speed_template);
2479 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002480 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002481 case 402:
2482 test_ahash_speed("md5", sec, generic_hash_speed_template);
2483 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002484 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002485 case 403:
2486 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2487 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002488 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002489 case 404:
2490 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2491 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002492 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002493 case 405:
2494 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2495 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002496 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002497 case 406:
2498 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2499 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002500 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002501 case 407:
2502 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2503 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002504 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002505 case 408:
2506 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2507 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002508 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002509 case 409:
2510 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2511 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002512 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002513 case 410:
2514 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2515 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002516 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002517 case 411:
2518 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2519 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002520 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002521 case 412:
2522 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2523 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002524 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002525 case 413:
2526 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2527 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002528 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002529 case 414:
2530 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2531 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002532 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002533 case 415:
2534 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2535 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002536 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002537 case 416:
2538 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2539 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002540 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002541 case 417:
2542 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2543 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002544 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302545 case 418:
2546 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2547 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002548 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302549 case 419:
2550 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2551 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002552 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302553 case 420:
2554 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2555 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002556 fallthrough;
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302557 case 421:
2558 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2559 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002560 fallthrough;
Megha Dey087bcd22016-06-23 18:40:47 -07002561 case 422:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002562 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2563 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07002564 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002565 fallthrough;
Megha Dey087bcd22016-06-23 18:40:47 -07002566 case 423:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002567 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2568 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07002569 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002570 fallthrough;
Megha Dey14009c42016-06-27 10:20:09 -07002571 case 424:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002572 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2573 num_mb);
Megha Dey14009c42016-06-27 10:20:09 -07002574 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002575 fallthrough;
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002576 case 425:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002577 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2578 num_mb);
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002579 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002580 fallthrough;
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03002581 case 426:
2582 test_mb_ahash_speed("streebog256", sec,
2583 generic_hash_speed_template, num_mb);
2584 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002585 fallthrough;
Vitaly Chikunov25a0b9d2018-11-07 00:00:03 +03002586 case 427:
2587 test_mb_ahash_speed("streebog512", sec,
2588 generic_hash_speed_template, num_mb);
2589 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002590 fallthrough;
David S. Millerbeb63da2010-05-19 14:11:21 +10002591 case 499:
2592 break;
2593
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002594 case 500:
2595 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2596 speed_template_16_24_32);
2597 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2598 speed_template_16_24_32);
2599 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2600 speed_template_16_24_32);
2601 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2602 speed_template_16_24_32);
2603 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2604 speed_template_32_40_48);
2605 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2606 speed_template_32_40_48);
2607 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002608 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002609 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002610 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08002611 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2612 speed_template_16_24_32);
2613 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2614 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002615 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2616 speed_template_16_24_32);
2617 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2618 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02002619 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2620 speed_template_16_24_32);
2621 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2622 speed_template_16_24_32);
2623 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2624 speed_template_16_24_32);
2625 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2626 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02002627 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2628 speed_template_20_28_36);
2629 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2630 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002631 break;
2632
2633 case 501:
2634 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2635 des3_speed_template, DES3_SPEED_VECTORS,
2636 speed_template_24);
2637 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2638 des3_speed_template, DES3_SPEED_VECTORS,
2639 speed_template_24);
2640 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2641 des3_speed_template, DES3_SPEED_VECTORS,
2642 speed_template_24);
2643 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2644 des3_speed_template, DES3_SPEED_VECTORS,
2645 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02002646 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2647 des3_speed_template, DES3_SPEED_VECTORS,
2648 speed_template_24);
2649 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2650 des3_speed_template, DES3_SPEED_VECTORS,
2651 speed_template_24);
2652 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2653 des3_speed_template, DES3_SPEED_VECTORS,
2654 speed_template_24);
2655 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2656 des3_speed_template, DES3_SPEED_VECTORS,
2657 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002658 break;
2659
2660 case 502:
2661 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2662 speed_template_8);
2663 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2664 speed_template_8);
2665 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2666 speed_template_8);
2667 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2668 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02002669 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2670 speed_template_8);
2671 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2672 speed_template_8);
2673 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2674 speed_template_8);
2675 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2676 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002677 break;
2678
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002679 case 503:
2680 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2681 speed_template_16_32);
2682 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2683 speed_template_16_32);
2684 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2685 speed_template_16_32);
2686 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2687 speed_template_16_32);
2688 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2689 speed_template_16_32);
2690 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2691 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002692 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2693 speed_template_32_48);
2694 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2695 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002696 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2697 speed_template_32_64);
2698 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2699 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002700 break;
2701
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002702 case 504:
2703 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2704 speed_template_16_24_32);
2705 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2706 speed_template_16_24_32);
2707 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2708 speed_template_16_24_32);
2709 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2710 speed_template_16_24_32);
2711 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2712 speed_template_16_24_32);
2713 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2714 speed_template_16_24_32);
2715 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2716 speed_template_32_40_48);
2717 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2718 speed_template_32_40_48);
2719 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2720 speed_template_32_48_64);
2721 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2722 speed_template_32_48_64);
2723 break;
2724
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002725 case 505:
2726 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2727 speed_template_8);
2728 break;
2729
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002730 case 506:
2731 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2732 speed_template_8_16);
2733 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2734 speed_template_8_16);
2735 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2736 speed_template_8_16);
2737 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2738 speed_template_8_16);
2739 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2740 speed_template_8_16);
2741 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2742 speed_template_8_16);
2743 break;
2744
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002745 case 507:
2746 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2747 speed_template_16_32);
2748 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2749 speed_template_16_32);
2750 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2751 speed_template_16_32);
2752 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2753 speed_template_16_32);
2754 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2755 speed_template_16_32);
2756 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2757 speed_template_16_32);
2758 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2759 speed_template_32_48);
2760 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2761 speed_template_32_48);
2762 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2763 speed_template_32_64);
2764 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2765 speed_template_32_64);
2766 break;
2767
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002768 case 508:
2769 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2770 speed_template_16_32);
2771 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2772 speed_template_16_32);
2773 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2774 speed_template_16_32);
2775 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2776 speed_template_16_32);
2777 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2778 speed_template_16_32);
2779 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2780 speed_template_16_32);
2781 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2782 speed_template_32_48);
2783 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2784 speed_template_32_48);
2785 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2786 speed_template_32_64);
2787 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2788 speed_template_32_64);
2789 break;
2790
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002791 case 509:
2792 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2793 speed_template_8_32);
2794 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2795 speed_template_8_32);
2796 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2797 speed_template_8_32);
2798 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2799 speed_template_8_32);
2800 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2801 speed_template_8_32);
2802 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2803 speed_template_8_32);
2804 break;
2805
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00002806 case 600:
2807 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2808 speed_template_16_24_32, num_mb);
2809 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2810 speed_template_16_24_32, num_mb);
2811 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2812 speed_template_16_24_32, num_mb);
2813 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2814 speed_template_16_24_32, num_mb);
2815 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2816 speed_template_32_40_48, num_mb);
2817 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2818 speed_template_32_40_48, num_mb);
2819 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2820 speed_template_32_64, num_mb);
2821 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2822 speed_template_32_64, num_mb);
2823 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2824 speed_template_16_24_32, num_mb);
2825 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2826 speed_template_16_24_32, num_mb);
2827 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2828 speed_template_16_24_32, num_mb);
2829 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2830 speed_template_16_24_32, num_mb);
2831 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2832 speed_template_16_24_32, num_mb);
2833 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2834 speed_template_16_24_32, num_mb);
2835 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2836 speed_template_16_24_32, num_mb);
2837 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2838 speed_template_16_24_32, num_mb);
2839 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2840 0, speed_template_20_28_36, num_mb);
2841 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2842 0, speed_template_20_28_36, num_mb);
2843 break;
2844
2845 case 601:
2846 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2847 des3_speed_template, DES3_SPEED_VECTORS,
2848 speed_template_24, num_mb);
2849 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2850 des3_speed_template, DES3_SPEED_VECTORS,
2851 speed_template_24, num_mb);
2852 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2853 des3_speed_template, DES3_SPEED_VECTORS,
2854 speed_template_24, num_mb);
2855 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2856 des3_speed_template, DES3_SPEED_VECTORS,
2857 speed_template_24, num_mb);
2858 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2859 des3_speed_template, DES3_SPEED_VECTORS,
2860 speed_template_24, num_mb);
2861 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2862 des3_speed_template, DES3_SPEED_VECTORS,
2863 speed_template_24, num_mb);
2864 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2865 des3_speed_template, DES3_SPEED_VECTORS,
2866 speed_template_24, num_mb);
2867 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2868 des3_speed_template, DES3_SPEED_VECTORS,
2869 speed_template_24, num_mb);
2870 break;
2871
2872 case 602:
2873 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2874 speed_template_8, num_mb);
2875 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2876 speed_template_8, num_mb);
2877 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2878 speed_template_8, num_mb);
2879 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2880 speed_template_8, num_mb);
2881 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2882 speed_template_8, num_mb);
2883 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2884 speed_template_8, num_mb);
2885 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2886 speed_template_8, num_mb);
2887 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2888 speed_template_8, num_mb);
2889 break;
2890
2891 case 603:
2892 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2893 speed_template_16_32, num_mb);
2894 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2895 speed_template_16_32, num_mb);
2896 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2897 speed_template_16_32, num_mb);
2898 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2899 speed_template_16_32, num_mb);
2900 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2901 speed_template_16_32, num_mb);
2902 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2903 speed_template_16_32, num_mb);
2904 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2905 speed_template_32_48, num_mb);
2906 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2907 speed_template_32_48, num_mb);
2908 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2909 speed_template_32_64, num_mb);
2910 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2911 speed_template_32_64, num_mb);
2912 break;
2913
2914 case 604:
2915 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2916 speed_template_16_24_32, num_mb);
2917 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2918 speed_template_16_24_32, num_mb);
2919 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2920 speed_template_16_24_32, num_mb);
2921 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2922 speed_template_16_24_32, num_mb);
2923 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2924 speed_template_16_24_32, num_mb);
2925 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2926 speed_template_16_24_32, num_mb);
2927 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2928 speed_template_32_40_48, num_mb);
2929 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2930 speed_template_32_40_48, num_mb);
2931 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2932 speed_template_32_48_64, num_mb);
2933 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2934 speed_template_32_48_64, num_mb);
2935 break;
2936
2937 case 605:
2938 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2939 speed_template_8, num_mb);
2940 break;
2941
2942 case 606:
2943 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2944 speed_template_8_16, num_mb);
2945 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2946 speed_template_8_16, num_mb);
2947 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2948 speed_template_8_16, num_mb);
2949 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2950 speed_template_8_16, num_mb);
2951 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2952 speed_template_8_16, num_mb);
2953 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2954 speed_template_8_16, num_mb);
2955 break;
2956
2957 case 607:
2958 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2959 speed_template_16_32, num_mb);
2960 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2961 speed_template_16_32, num_mb);
2962 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2963 speed_template_16_32, num_mb);
2964 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2965 speed_template_16_32, num_mb);
2966 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2967 speed_template_16_32, num_mb);
2968 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2969 speed_template_16_32, num_mb);
2970 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2971 speed_template_32_48, num_mb);
2972 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2973 speed_template_32_48, num_mb);
2974 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2975 speed_template_32_64, num_mb);
2976 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2977 speed_template_32_64, num_mb);
2978 break;
2979
2980 case 608:
2981 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2982 speed_template_16_32, num_mb);
2983 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2984 speed_template_16_32, num_mb);
2985 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2986 speed_template_16_32, num_mb);
2987 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2988 speed_template_16_32, num_mb);
2989 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2990 speed_template_16_32, num_mb);
2991 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2992 speed_template_16_32, num_mb);
2993 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2994 speed_template_32_48, num_mb);
2995 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2996 speed_template_32_48, num_mb);
2997 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2998 speed_template_32_64, num_mb);
2999 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
3000 speed_template_32_64, num_mb);
3001 break;
3002
3003 case 609:
3004 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
3005 speed_template_8_32, num_mb);
3006 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
3007 speed_template_8_32, num_mb);
3008 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
3009 speed_template_8_32, num_mb);
3010 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
3011 speed_template_8_32, num_mb);
3012 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
3013 speed_template_8_32, num_mb);
3014 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
3015 speed_template_8_32, num_mb);
3016 break;
3017
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 case 1000:
3019 test_available();
3020 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10003022
3023 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024}
3025
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08003026static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08003028 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08003029 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08003030
Herbert Xuf139cfa2008-07-31 12:23:53 +08003031 for (i = 0; i < TVMEMSIZE; i++) {
3032 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
3033 if (!tvmem[i])
3034 goto err_free_tv;
3035 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036
Kees Cook4e234ee2018-04-26 19:57:28 -07003037 err = do_test(alg, type, mask, mode, num_mb);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08003038
Jarod Wilson4e033a62009-05-27 15:10:21 +10003039 if (err) {
3040 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
3041 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01003042 } else {
3043 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10003044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
Jarod Wilson4e033a62009-05-27 15:10:21 +10003046 /* We intentionaly return -EAGAIN to prevent keeping the module,
3047 * unless we're running in fips mode. It does all its work from
3048 * init() and doesn't offer any runtime functionality, but in
3049 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10003050 * => we don't need it in the memory, do we?
3051 * -- mludvig
3052 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10003053 if (!fips_enabled)
3054 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08003055
Herbert Xuf139cfa2008-07-31 12:23:53 +08003056err_free_tv:
3057 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
3058 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08003059
3060 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061}
3062
3063/*
3064 * If an init function is provided, an exit function must also be provided
3065 * to allow module unload.
3066 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08003067static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
Ard Biesheuvel08a7e332020-11-20 12:04:31 +01003069late_initcall(tcrypt_mod_init);
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08003070module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
Steffen Klasserta873a5f2009-06-19 19:46:53 +08003072module_param(alg, charp, 0);
3073module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08003074module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07003076module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07003077MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3078 "(defaults to zero which uses CPU cycles instead)");
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00003079module_param(num_mb, uint, 0000);
3080MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
Herbert Xuba974ad2020-08-05 15:57:08 +10003081module_param(klen, uint, 0);
3082MODULE_PARM_DESC(klen, "Key length (defaults to 0)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
3084MODULE_LICENSE("GPL");
3085MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3086MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");