blob: c20c9f5c18f229c3c878528b343e29bd4883d703 [file] [log] [blame]
Herbert Xuef2736f2005-06-22 13:26:03 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Quick & dirty crypto testing module.
3 *
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
Mikko Herranene3a4ea42007-11-26 22:12:07 +08009 * Copyright (c) 2007 Nokia Siemens Networks
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
Adrian Hoban69435b92010-11-04 15:02:04 -040011 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
Herbert Xuef2736f2005-06-22 13:26:03 -070020 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * any later version.
22 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Rabin Vincent76512f22017-01-18 14:54:05 +010025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Herbert Xu1ce5a042015-04-22 15:06:30 +080027#include <crypto/aead.h>
Herbert Xu18e33e62008-07-10 16:01:22 +080028#include <crypto/hash.h>
Herbert Xu7166e582016-06-29 18:03:50 +080029#include <crypto/skcipher.h>
Herbert Xucba83562006-08-13 08:26:09 +100030#include <linux/err.h>
Herbert Xudaf09442015-04-22 13:25:57 +080031#include <linux/fips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/module.h>
David Hardeman378f0582005-09-17 17:55:31 +100035#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070038#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070039#include <linux/timex.h>
40#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "tcrypt.h"
42
43/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080044 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080046#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
Herbert Xuda7f0332008-07-31 17:08:25 +080049* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070050*/
51#define ENCRYPT 1
52#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Horia Geant?f074f7b2015-08-27 18:38:36 +030054#define MAX_DIGEST_SIZE 64
55
Harald Welteebfd9bc2005-06-22 13:27:23 -070056/*
Luca Clementi263a8df2014-06-25 22:57:42 -070057 * return a string with the driver name
58 */
59#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
60
61/*
Harald Welteebfd9bc2005-06-22 13:27:23 -070062 * Used by test_cipher_speed()
63 */
Herbert Xu6a179442005-06-22 13:29:03 -070064static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070065
Steffen Klasserta873a5f2009-06-19 19:46:53 +080066static char *alg = NULL;
67static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080068static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int mode;
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +000070static u32 num_mb = 8;
Herbert Xuf139cfa2008-07-31 12:23:53 +080071static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73static char *check[] = {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +030074 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080075 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110077 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080078 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
Horia Geantă4d407b02018-09-19 17:54:21 +030079 "lzo", "cts", "sha3-224", "sha3-256", "sha3-384", "sha3-512", NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +000082static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
83static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
84
85#define XBUFSIZE 8
86#define MAX_IVLEN 32
87
88static int testmgr_alloc_buf(char *buf[XBUFSIZE])
89{
90 int i;
91
92 for (i = 0; i < XBUFSIZE; i++) {
93 buf[i] = (void *)__get_free_page(GFP_KERNEL);
94 if (!buf[i])
95 goto err_free_buf;
96 }
97
98 return 0;
99
100err_free_buf:
101 while (i-- > 0)
102 free_page((unsigned long)buf[i]);
103
104 return -ENOMEM;
105}
106
107static void testmgr_free_buf(char *buf[XBUFSIZE])
108{
109 int i;
110
111 for (i = 0; i < XBUFSIZE; i++)
112 free_page((unsigned long)buf[i]);
113}
114
115static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
116 unsigned int buflen, const void *assoc,
117 unsigned int aad_size)
118{
119 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
120 int k, rem;
121
122 if (np > XBUFSIZE) {
123 rem = PAGE_SIZE;
124 np = XBUFSIZE;
125 } else {
126 rem = buflen % PAGE_SIZE;
127 }
128
129 sg_init_table(sg, np + 1);
130
131 sg_set_buf(&sg[0], assoc, aad_size);
132
133 if (rem)
134 np--;
135 for (k = 0; k < np; k++)
136 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
137
138 if (rem)
139 sg_set_buf(&sg[k + 1], xbuf[k], rem);
140}
141
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530142static inline int do_one_aead_op(struct aead_request *req, int ret)
143{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100144 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530145
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100146 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530147}
148
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000149struct test_mb_aead_data {
150 struct scatterlist sg[XBUFSIZE];
151 struct scatterlist sgout[XBUFSIZE];
152 struct aead_request *req;
153 struct crypto_wait wait;
154 char *xbuf[XBUFSIZE];
155 char *xoutbuf[XBUFSIZE];
156 char *axbuf[XBUFSIZE];
157};
158
159static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,
Kees Cook4e234ee2018-04-26 19:57:28 -0700160 u32 num_mb, int *rc)
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000161{
Kees Cook4e234ee2018-04-26 19:57:28 -0700162 int i, err = 0;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000163
164 /* Fire up a bunch of concurrent requests */
165 for (i = 0; i < num_mb; i++) {
166 if (enc == ENCRYPT)
167 rc[i] = crypto_aead_encrypt(data[i].req);
168 else
169 rc[i] = crypto_aead_decrypt(data[i].req);
170 }
171
172 /* Wait for all requests to finish */
173 for (i = 0; i < num_mb; i++) {
174 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
175
176 if (rc[i]) {
177 pr_info("concurrent request %d error %d\n", i, rc[i]);
178 err = rc[i];
179 }
180 }
181
182 return err;
183}
184
185static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc,
186 int blen, int secs, u32 num_mb)
187{
188 unsigned long start, end;
189 int bcount;
Kees Cook4e234ee2018-04-26 19:57:28 -0700190 int ret = 0;
191 int *rc;
192
193 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
194 if (!rc)
195 return -ENOMEM;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000196
197 for (start = jiffies, end = start + secs * HZ, bcount = 0;
198 time_before(jiffies, end); bcount++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700199 ret = do_mult_aead_op(data, enc, num_mb, rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000200 if (ret)
Kees Cook4e234ee2018-04-26 19:57:28 -0700201 goto out;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000202 }
203
204 pr_cont("%d operations in %d seconds (%ld bytes)\n",
205 bcount * num_mb, secs, (long)bcount * blen * num_mb);
Kees Cook4e234ee2018-04-26 19:57:28 -0700206
207out:
208 kfree(rc);
209 return ret;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000210}
211
212static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc,
213 int blen, u32 num_mb)
214{
215 unsigned long cycles = 0;
216 int ret = 0;
217 int i;
Kees Cook4e234ee2018-04-26 19:57:28 -0700218 int *rc;
219
220 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
221 if (!rc)
222 return -ENOMEM;
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000223
224 /* Warm-up run. */
225 for (i = 0; i < 4; i++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700226 ret = do_mult_aead_op(data, enc, num_mb, rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000227 if (ret)
228 goto out;
229 }
230
231 /* The real thing. */
232 for (i = 0; i < 8; i++) {
233 cycles_t start, end;
234
235 start = get_cycles();
Kees Cook4e234ee2018-04-26 19:57:28 -0700236 ret = do_mult_aead_op(data, enc, num_mb, rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000237 end = get_cycles();
238
239 if (ret)
240 goto out;
241
242 cycles += end - start;
243 }
244
Kees Cook4e234ee2018-04-26 19:57:28 -0700245 pr_cont("1 operation in %lu cycles (%d bytes)\n",
246 (cycles + 4) / (8 * num_mb), blen);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000247
Kees Cook4e234ee2018-04-26 19:57:28 -0700248out:
249 kfree(rc);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000250 return ret;
251}
252
253static void test_mb_aead_speed(const char *algo, int enc, int secs,
254 struct aead_speed_template *template,
255 unsigned int tcount, u8 authsize,
256 unsigned int aad_size, u8 *keysize, u32 num_mb)
257{
258 struct test_mb_aead_data *data;
259 struct crypto_aead *tfm;
260 unsigned int i, j, iv_len;
261 const char *key;
262 const char *e;
263 void *assoc;
264 u32 *b_size;
265 char *iv;
266 int ret;
267
268
269 if (aad_size >= PAGE_SIZE) {
270 pr_err("associate data length (%u) too big\n", aad_size);
271 return;
272 }
273
274 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
275 if (!iv)
276 return;
277
278 if (enc == ENCRYPT)
279 e = "encryption";
280 else
281 e = "decryption";
282
283 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
284 if (!data)
285 goto out_free_iv;
286
287 tfm = crypto_alloc_aead(algo, 0, 0);
288 if (IS_ERR(tfm)) {
289 pr_err("failed to load transform for %s: %ld\n",
290 algo, PTR_ERR(tfm));
291 goto out_free_data;
292 }
293
294 ret = crypto_aead_setauthsize(tfm, authsize);
295
296 for (i = 0; i < num_mb; ++i)
297 if (testmgr_alloc_buf(data[i].xbuf)) {
298 while (i--)
299 testmgr_free_buf(data[i].xbuf);
300 goto out_free_tfm;
301 }
302
303 for (i = 0; i < num_mb; ++i)
304 if (testmgr_alloc_buf(data[i].axbuf)) {
305 while (i--)
306 testmgr_free_buf(data[i].axbuf);
307 goto out_free_xbuf;
308 }
309
310 for (i = 0; i < num_mb; ++i)
311 if (testmgr_alloc_buf(data[i].xoutbuf)) {
312 while (i--)
Colin Ian Kingc6ba4f32018-01-02 15:43:04 +0000313 testmgr_free_buf(data[i].xoutbuf);
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000314 goto out_free_axbuf;
315 }
316
317 for (i = 0; i < num_mb; ++i) {
318 data[i].req = aead_request_alloc(tfm, GFP_KERNEL);
319 if (!data[i].req) {
320 pr_err("alg: skcipher: Failed to allocate request for %s\n",
321 algo);
322 while (i--)
323 aead_request_free(data[i].req);
324 goto out_free_xoutbuf;
325 }
326 }
327
328 for (i = 0; i < num_mb; ++i) {
329 crypto_init_wait(&data[i].wait);
330 aead_request_set_callback(data[i].req,
331 CRYPTO_TFM_REQ_MAY_BACKLOG,
332 crypto_req_done, &data[i].wait);
333 }
334
335 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
336 get_driver_name(crypto_aead, tfm), e);
337
338 i = 0;
339 do {
340 b_size = aead_sizes;
341 do {
342 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) {
Colin Ian King38dbe2d2018-01-02 09:21:06 +0000343 pr_err("template (%u) too big for buffer (%lu)\n",
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000344 authsize + *b_size,
345 XBUFSIZE * PAGE_SIZE);
346 goto out;
347 }
348
349 pr_info("test %u (%d bit key, %d byte blocks): ", i,
350 *keysize * 8, *b_size);
351
352 /* Set up tfm global state, i.e. the key */
353
354 memset(tvmem[0], 0xff, PAGE_SIZE);
355 key = tvmem[0];
356 for (j = 0; j < tcount; j++) {
357 if (template[j].klen == *keysize) {
358 key = template[j].key;
359 break;
360 }
361 }
362
363 crypto_aead_clear_flags(tfm, ~0);
364
365 ret = crypto_aead_setkey(tfm, key, *keysize);
366 if (ret) {
367 pr_err("setkey() failed flags=%x\n",
368 crypto_aead_get_flags(tfm));
369 goto out;
370 }
371
372 iv_len = crypto_aead_ivsize(tfm);
373 if (iv_len)
374 memset(iv, 0xff, iv_len);
375
376 /* Now setup per request stuff, i.e. buffers */
377
378 for (j = 0; j < num_mb; ++j) {
379 struct test_mb_aead_data *cur = &data[j];
380
381 assoc = cur->axbuf[0];
382 memset(assoc, 0xff, aad_size);
383
384 sg_init_aead(cur->sg, cur->xbuf,
385 *b_size + (enc ? 0 : authsize),
386 assoc, aad_size);
387
388 sg_init_aead(cur->sgout, cur->xoutbuf,
389 *b_size + (enc ? authsize : 0),
390 assoc, aad_size);
391
392 aead_request_set_ad(cur->req, aad_size);
393
394 if (!enc) {
395
396 aead_request_set_crypt(cur->req,
397 cur->sgout,
398 cur->sg,
399 *b_size, iv);
400 ret = crypto_aead_encrypt(cur->req);
401 ret = do_one_aead_op(cur->req, ret);
402
403 if (ret) {
404 pr_err("calculating auth failed failed (%d)\n",
405 ret);
406 break;
407 }
408 }
409
410 aead_request_set_crypt(cur->req, cur->sg,
411 cur->sgout, *b_size +
412 (enc ? 0 : authsize),
413 iv);
414
415 }
416
Horia Geantă2af63292018-07-23 17:18:48 +0300417 if (secs) {
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000418 ret = test_mb_aead_jiffies(data, enc, *b_size,
419 secs, num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300420 cond_resched();
421 } else {
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000422 ret = test_mb_aead_cycles(data, enc, *b_size,
423 num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300424 }
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +0000425
426 if (ret) {
427 pr_err("%s() failed return code=%d\n", e, ret);
428 break;
429 }
430 b_size++;
431 i++;
432 } while (*b_size);
433 keysize++;
434 } while (*keysize);
435
436out:
437 for (i = 0; i < num_mb; ++i)
438 aead_request_free(data[i].req);
439out_free_xoutbuf:
440 for (i = 0; i < num_mb; ++i)
441 testmgr_free_buf(data[i].xoutbuf);
442out_free_axbuf:
443 for (i = 0; i < num_mb; ++i)
444 testmgr_free_buf(data[i].axbuf);
445out_free_xbuf:
446 for (i = 0; i < num_mb; ++i)
447 testmgr_free_buf(data[i].xbuf);
448out_free_tfm:
449 crypto_free_aead(tfm);
450out_free_data:
451 kfree(data);
452out_free_iv:
453 kfree(iv);
454}
455
Tim Chen53f52d72013-12-11 14:28:47 -0800456static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700457 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -0800458{
459 unsigned long start, end;
460 int bcount;
461 int ret;
462
Mark Rustad3e3dc252014-07-25 02:53:38 -0700463 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -0800464 time_before(jiffies, end); bcount++) {
465 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530466 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800467 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530468 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800469
470 if (ret)
471 return ret;
472 }
473
474 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700475 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800476 return 0;
477}
478
479static int test_aead_cycles(struct aead_request *req, int enc, int blen)
480{
481 unsigned long cycles = 0;
482 int ret = 0;
483 int i;
484
Tim Chen53f52d72013-12-11 14:28:47 -0800485 /* Warm-up run. */
486 for (i = 0; i < 4; i++) {
487 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530488 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800489 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530490 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800491
492 if (ret)
493 goto out;
494 }
495
496 /* The real thing. */
497 for (i = 0; i < 8; i++) {
498 cycles_t start, end;
499
500 start = get_cycles();
501 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530502 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800503 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530504 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800505 end = get_cycles();
506
507 if (ret)
508 goto out;
509
510 cycles += end - start;
511 }
512
513out:
Tim Chen53f52d72013-12-11 14:28:47 -0800514 if (ret == 0)
515 printk("1 operation in %lu cycles (%d bytes)\n",
516 (cycles + 4) / 8, blen);
517
518 return ret;
519}
520
Mark Rustad3e3dc252014-07-25 02:53:38 -0700521static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800522 struct aead_speed_template *template,
523 unsigned int tcount, u8 authsize,
524 unsigned int aad_size, u8 *keysize)
525{
526 unsigned int i, j;
527 struct crypto_aead *tfm;
528 int ret = -ENOMEM;
529 const char *key;
530 struct aead_request *req;
531 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800532 struct scatterlist *sgout;
533 const char *e;
534 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200535 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800536 char *xbuf[XBUFSIZE];
537 char *xoutbuf[XBUFSIZE];
538 char *axbuf[XBUFSIZE];
539 unsigned int *b_size;
540 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100541 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800542
Cristian Stoica96692a732015-01-28 13:07:32 +0200543 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
544 if (!iv)
545 return;
546
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200547 if (aad_size >= PAGE_SIZE) {
548 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200549 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200550 }
551
Tim Chen53f52d72013-12-11 14:28:47 -0800552 if (enc == ENCRYPT)
553 e = "encryption";
554 else
555 e = "decryption";
556
557 if (testmgr_alloc_buf(xbuf))
558 goto out_noxbuf;
559 if (testmgr_alloc_buf(axbuf))
560 goto out_noaxbuf;
561 if (testmgr_alloc_buf(xoutbuf))
562 goto out_nooutbuf;
563
Herbert Xua3f21852015-05-27 16:03:51 +0800564 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800565 if (!sg)
566 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800567 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800568
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800569 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800570
571 if (IS_ERR(tfm)) {
572 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
573 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200574 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800575 }
576
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100577 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700578 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
579 get_driver_name(crypto_aead, tfm), e);
580
Tim Chen53f52d72013-12-11 14:28:47 -0800581 req = aead_request_alloc(tfm, GFP_KERNEL);
582 if (!req) {
583 pr_err("alg: aead: Failed to allocate request for %s\n",
584 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200585 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800586 }
587
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530588 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100589 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530590
Tim Chen53f52d72013-12-11 14:28:47 -0800591 i = 0;
592 do {
593 b_size = aead_sizes;
594 do {
595 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200596 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800597
598 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
599 pr_err("template (%u) too big for tvmem (%lu)\n",
600 *keysize + *b_size,
601 TVMEMSIZE * PAGE_SIZE);
602 goto out;
603 }
604
605 key = tvmem[0];
606 for (j = 0; j < tcount; j++) {
607 if (template[j].klen == *keysize) {
608 key = template[j].key;
609 break;
610 }
611 }
612 ret = crypto_aead_setkey(tfm, key, *keysize);
613 ret = crypto_aead_setauthsize(tfm, authsize);
614
615 iv_len = crypto_aead_ivsize(tfm);
616 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200617 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800618
619 crypto_aead_clear_flags(tfm, ~0);
620 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
621 i, *keysize * 8, *b_size);
622
623
624 memset(tvmem[0], 0xff, PAGE_SIZE);
625
626 if (ret) {
627 pr_err("setkey() failed flags=%x\n",
628 crypto_aead_get_flags(tfm));
629 goto out;
630 }
631
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200632 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
633 assoc, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800634
Herbert Xu31267272015-06-17 14:05:26 +0800635 sg_init_aead(sgout, xoutbuf,
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200636 *b_size + (enc ? authsize : 0), assoc,
637 aad_size);
Herbert Xu31267272015-06-17 14:05:26 +0800638
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +0000639 aead_request_set_ad(req, aad_size);
640
641 if (!enc) {
642
643 /*
644 * For decryption we need a proper auth so
645 * we do the encryption path once with buffers
646 * reversed (input <-> output) to calculate it
647 */
648 aead_request_set_crypt(req, sgout, sg,
649 *b_size, iv);
650 ret = do_one_aead_op(req,
651 crypto_aead_encrypt(req));
652
653 if (ret) {
654 pr_err("calculating auth failed failed (%d)\n",
655 ret);
656 break;
657 }
658 }
659
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300660 aead_request_set_crypt(req, sg, sgout,
661 *b_size + (enc ? 0 : authsize),
662 iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800663
Horia Geantă2af63292018-07-23 17:18:48 +0300664 if (secs) {
Mark Rustad3e3dc252014-07-25 02:53:38 -0700665 ret = test_aead_jiffies(req, enc, *b_size,
666 secs);
Horia Geantă2af63292018-07-23 17:18:48 +0300667 cond_resched();
668 } else {
Tim Chen53f52d72013-12-11 14:28:47 -0800669 ret = test_aead_cycles(req, enc, *b_size);
Horia Geantă2af63292018-07-23 17:18:48 +0300670 }
Tim Chen53f52d72013-12-11 14:28:47 -0800671
672 if (ret) {
673 pr_err("%s() failed return code=%d\n", e, ret);
674 break;
675 }
676 b_size++;
677 i++;
678 } while (*b_size);
679 keysize++;
680 } while (*keysize);
681
682out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200683 aead_request_free(req);
684out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800685 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200686out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800687 kfree(sg);
688out_nosg:
689 testmgr_free_buf(xoutbuf);
690out_nooutbuf:
691 testmgr_free_buf(axbuf);
692out_noaxbuf:
693 testmgr_free_buf(xbuf);
694out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200695 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800696}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800697
David S. Millerbeb63da2010-05-19 14:11:21 +1000698static void test_hash_sg_init(struct scatterlist *sg)
699{
700 int i;
701
702 sg_init_table(sg, TVMEMSIZE);
703 for (i = 0; i < TVMEMSIZE; i++) {
704 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
705 memset(tvmem[i], 0xff, PAGE_SIZE);
706 }
707}
708
David S. Millerbeb63da2010-05-19 14:11:21 +1000709static inline int do_one_ahash_op(struct ahash_request *req, int ret)
710{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100711 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000712
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100713 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000714}
715
Herbert Xu72259de2016-06-28 20:33:52 +0800716struct test_mb_ahash_data {
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000717 struct scatterlist sg[XBUFSIZE];
Herbert Xu72259de2016-06-28 20:33:52 +0800718 char result[64];
719 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100720 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800721 char *xbuf[XBUFSIZE];
722};
Megha Dey087bcd22016-06-23 18:40:47 -0700723
Kees Cook4e234ee2018-04-26 19:57:28 -0700724static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb,
725 int *rc)
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000726{
Kees Cook4e234ee2018-04-26 19:57:28 -0700727 int i, err = 0;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000728
729 /* Fire up a bunch of concurrent requests */
730 for (i = 0; i < num_mb; i++)
731 rc[i] = crypto_ahash_digest(data[i].req);
732
733 /* Wait for all requests to finish */
734 for (i = 0; i < num_mb; i++) {
735 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
736
737 if (rc[i]) {
738 pr_info("concurrent request %d error %d\n", i, rc[i]);
739 err = rc[i];
740 }
741 }
742
743 return err;
744}
745
746static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
747 int secs, u32 num_mb)
748{
749 unsigned long start, end;
750 int bcount;
Kees Cook4e234ee2018-04-26 19:57:28 -0700751 int ret = 0;
752 int *rc;
753
754 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
755 if (!rc)
756 return -ENOMEM;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000757
758 for (start = jiffies, end = start + secs * HZ, bcount = 0;
759 time_before(jiffies, end); bcount++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700760 ret = do_mult_ahash_op(data, num_mb, rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000761 if (ret)
Kees Cook4e234ee2018-04-26 19:57:28 -0700762 goto out;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000763 }
764
765 pr_cont("%d operations in %d seconds (%ld bytes)\n",
766 bcount * num_mb, secs, (long)bcount * blen * num_mb);
Kees Cook4e234ee2018-04-26 19:57:28 -0700767
768out:
769 kfree(rc);
770 return ret;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000771}
772
773static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
774 u32 num_mb)
775{
776 unsigned long cycles = 0;
777 int ret = 0;
778 int i;
Kees Cook4e234ee2018-04-26 19:57:28 -0700779 int *rc;
780
781 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
782 if (!rc)
783 return -ENOMEM;
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000784
785 /* Warm-up run. */
786 for (i = 0; i < 4; i++) {
Kees Cook4e234ee2018-04-26 19:57:28 -0700787 ret = do_mult_ahash_op(data, num_mb, rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000788 if (ret)
789 goto out;
790 }
791
792 /* The real thing. */
793 for (i = 0; i < 8; i++) {
794 cycles_t start, end;
795
796 start = get_cycles();
Kees Cook4e234ee2018-04-26 19:57:28 -0700797 ret = do_mult_ahash_op(data, num_mb, rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000798 end = get_cycles();
799
800 if (ret)
801 goto out;
802
803 cycles += end - start;
804 }
805
Kees Cook4e234ee2018-04-26 19:57:28 -0700806 pr_cont("1 operation in %lu cycles (%d bytes)\n",
807 (cycles + 4) / (8 * num_mb), blen);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000808
Kees Cook4e234ee2018-04-26 19:57:28 -0700809out:
810 kfree(rc);
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000811 return ret;
812}
813
814static void test_mb_ahash_speed(const char *algo, unsigned int secs,
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000815 struct hash_speed *speed, u32 num_mb)
Megha Dey087bcd22016-06-23 18:40:47 -0700816{
Herbert Xu72259de2016-06-28 20:33:52 +0800817 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700818 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800819 unsigned int i, j, k;
820 int ret;
821
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000822 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
Herbert Xu72259de2016-06-28 20:33:52 +0800823 if (!data)
824 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700825
826 tfm = crypto_alloc_ahash(algo, 0, 0);
827 if (IS_ERR(tfm)) {
828 pr_err("failed to load transform for %s: %ld\n",
829 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800830 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700831 }
Herbert Xu72259de2016-06-28 20:33:52 +0800832
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000833 for (i = 0; i < num_mb; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800834 if (testmgr_alloc_buf(data[i].xbuf))
835 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700836
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100837 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700838
Herbert Xu72259de2016-06-28 20:33:52 +0800839 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
840 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200841 pr_err("alg: hash: Failed to allocate request for %s\n",
842 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800843 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700844 }
Megha Dey087bcd22016-06-23 18:40:47 -0700845
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100846 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
847 &data[i].wait);
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000848
849 sg_init_table(data[i].sg, XBUFSIZE);
850 for (j = 0; j < XBUFSIZE; j++) {
851 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
852 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
853 }
Megha Dey087bcd22016-06-23 18:40:47 -0700854 }
855
Herbert Xu72259de2016-06-28 20:33:52 +0800856 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
857 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700858
859 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800860 /* For some reason this only tests digests. */
861 if (speed[i].blen != speed[i].plen)
862 continue;
863
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000864 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200865 pr_err("template (%u) too big for tvmem (%lu)\n",
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000866 speed[i].blen, XBUFSIZE * PAGE_SIZE);
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200867 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700868 }
869
870 if (speed[i].klen)
871 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
872
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000873 for (k = 0; k < num_mb; k++)
Herbert Xu72259de2016-06-28 20:33:52 +0800874 ahash_request_set_crypt(data[k].req, data[k].sg,
875 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700876
Herbert Xu72259de2016-06-28 20:33:52 +0800877 pr_info("test%3u "
878 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700879 i, speed[i].blen, speed[i].plen,
880 speed[i].blen / speed[i].plen);
881
Horia Geantă2af63292018-07-23 17:18:48 +0300882 if (secs) {
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000883 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
884 num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300885 cond_resched();
886 } else {
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000887 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +0300888 }
Herbert Xu72259de2016-06-28 20:33:52 +0800889
Herbert Xu72259de2016-06-28 20:33:52 +0800890
891 if (ret) {
892 pr_err("At least one hashing failed ret=%d\n", ret);
893 break;
894 }
Megha Dey087bcd22016-06-23 18:40:47 -0700895 }
Megha Dey087bcd22016-06-23 18:40:47 -0700896
897out:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000898 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800899 ahash_request_free(data[k].req);
900
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000901 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800902 testmgr_free_buf(data[k].xbuf);
903
904 crypto_free_ahash(tfm);
905
906free_data:
907 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700908}
909
David S. Millerbeb63da2010-05-19 14:11:21 +1000910static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700911 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000912{
913 unsigned long start, end;
914 int bcount;
915 int ret;
916
Mark Rustad3e3dc252014-07-25 02:53:38 -0700917 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000918 time_before(jiffies, end); bcount++) {
919 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
920 if (ret)
921 return ret;
922 }
923
924 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700925 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000926
927 return 0;
928}
929
930static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700931 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000932{
933 unsigned long start, end;
934 int bcount, pcount;
935 int ret;
936
937 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700938 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000939
Mark Rustad3e3dc252014-07-25 02:53:38 -0700940 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000941 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800942 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000943 if (ret)
944 return ret;
945 for (pcount = 0; pcount < blen; pcount += plen) {
946 ret = do_one_ahash_op(req, crypto_ahash_update(req));
947 if (ret)
948 return ret;
949 }
950 /* we assume there is enough space in 'out' for the result */
951 ret = do_one_ahash_op(req, crypto_ahash_final(req));
952 if (ret)
953 return ret;
954 }
955
956 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700957 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000958
959 return 0;
960}
961
962static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
963 char *out)
964{
965 unsigned long cycles = 0;
966 int ret, i;
967
968 /* Warm-up run. */
969 for (i = 0; i < 4; i++) {
970 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
971 if (ret)
972 goto out;
973 }
974
975 /* The real thing. */
976 for (i = 0; i < 8; i++) {
977 cycles_t start, end;
978
979 start = get_cycles();
980
981 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
982 if (ret)
983 goto out;
984
985 end = get_cycles();
986
987 cycles += end - start;
988 }
989
990out:
991 if (ret)
992 return ret;
993
994 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
995 cycles / 8, cycles / (8 * blen));
996
997 return 0;
998}
999
1000static int test_ahash_cycles(struct ahash_request *req, int blen,
1001 int plen, char *out)
1002{
1003 unsigned long cycles = 0;
1004 int i, pcount, ret;
1005
1006 if (plen == blen)
1007 return test_ahash_cycles_digest(req, blen, out);
1008
1009 /* Warm-up run. */
1010 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +08001011 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +10001012 if (ret)
1013 goto out;
1014 for (pcount = 0; pcount < blen; pcount += plen) {
1015 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1016 if (ret)
1017 goto out;
1018 }
1019 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1020 if (ret)
1021 goto out;
1022 }
1023
1024 /* The real thing. */
1025 for (i = 0; i < 8; i++) {
1026 cycles_t start, end;
1027
1028 start = get_cycles();
1029
Herbert Xu43a96072015-04-22 11:02:27 +08001030 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +10001031 if (ret)
1032 goto out;
1033 for (pcount = 0; pcount < blen; pcount += plen) {
1034 ret = do_one_ahash_op(req, crypto_ahash_update(req));
1035 if (ret)
1036 goto out;
1037 }
1038 ret = do_one_ahash_op(req, crypto_ahash_final(req));
1039 if (ret)
1040 goto out;
1041
1042 end = get_cycles();
1043
1044 cycles += end - start;
1045 }
1046
1047out:
1048 if (ret)
1049 return ret;
1050
1051 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
1052 cycles / 8, cycles / (8 * blen));
1053
1054 return 0;
1055}
1056
Herbert Xu06605112016-02-01 21:36:49 +08001057static void test_ahash_speed_common(const char *algo, unsigned int secs,
1058 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +10001059{
1060 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001061 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +10001062 struct ahash_request *req;
1063 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +03001064 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +10001065 int i, ret;
1066
Herbert Xu06605112016-02-01 21:36:49 +08001067 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +10001068 if (IS_ERR(tfm)) {
1069 pr_err("failed to load transform for %s: %ld\n",
1070 algo, PTR_ERR(tfm));
1071 return;
1072 }
1073
Luca Clementi263a8df2014-06-25 22:57:42 -07001074 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
1075 get_driver_name(crypto_ahash, tfm));
1076
Horia Geant?f074f7b2015-08-27 18:38:36 +03001077 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
1078 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
1079 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +10001080 goto out;
1081 }
1082
1083 test_hash_sg_init(sg);
1084 req = ahash_request_alloc(tfm, GFP_KERNEL);
1085 if (!req) {
1086 pr_err("ahash request allocation failure\n");
1087 goto out;
1088 }
1089
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001090 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +10001091 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001092 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +10001093
Horia Geant?f074f7b2015-08-27 18:38:36 +03001094 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
1095 if (!output)
1096 goto out_nomem;
1097
David S. Millerbeb63da2010-05-19 14:11:21 +10001098 for (i = 0; speed[i].blen != 0; i++) {
1099 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
1100 pr_err("template (%u) too big for tvmem (%lu)\n",
1101 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
1102 break;
1103 }
1104
Horia Geantă331351f2018-09-12 16:20:48 +03001105 if (speed[i].klen)
1106 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
1107
David S. Millerbeb63da2010-05-19 14:11:21 +10001108 pr_info("test%3u "
1109 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
1110 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
1111
1112 ahash_request_set_crypt(req, sg, output, speed[i].plen);
1113
Horia Geantă2af63292018-07-23 17:18:48 +03001114 if (secs) {
David S. Millerbeb63da2010-05-19 14:11:21 +10001115 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001116 speed[i].plen, output, secs);
Horia Geantă2af63292018-07-23 17:18:48 +03001117 cond_resched();
1118 } else {
David S. Millerbeb63da2010-05-19 14:11:21 +10001119 ret = test_ahash_cycles(req, speed[i].blen,
1120 speed[i].plen, output);
Horia Geantă2af63292018-07-23 17:18:48 +03001121 }
David S. Millerbeb63da2010-05-19 14:11:21 +10001122
1123 if (ret) {
1124 pr_err("hashing failed ret=%d\n", ret);
1125 break;
1126 }
1127 }
1128
Horia Geant?f074f7b2015-08-27 18:38:36 +03001129 kfree(output);
1130
1131out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +10001132 ahash_request_free(req);
1133
1134out:
1135 crypto_free_ahash(tfm);
1136}
1137
Herbert Xu06605112016-02-01 21:36:49 +08001138static void test_ahash_speed(const char *algo, unsigned int secs,
1139 struct hash_speed *speed)
1140{
1141 return test_ahash_speed_common(algo, secs, speed, 0);
1142}
1143
1144static void test_hash_speed(const char *algo, unsigned int secs,
1145 struct hash_speed *speed)
1146{
1147 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
1148}
1149
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001150struct test_mb_skcipher_data {
1151 struct scatterlist sg[XBUFSIZE];
1152 struct skcipher_request *req;
1153 struct crypto_wait wait;
1154 char *xbuf[XBUFSIZE];
1155};
1156
1157static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc,
Kees Cook4e234ee2018-04-26 19:57:28 -07001158 u32 num_mb, int *rc)
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001159{
Kees Cook4e234ee2018-04-26 19:57:28 -07001160 int i, err = 0;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001161
1162 /* Fire up a bunch of concurrent requests */
1163 for (i = 0; i < num_mb; i++) {
1164 if (enc == ENCRYPT)
1165 rc[i] = crypto_skcipher_encrypt(data[i].req);
1166 else
1167 rc[i] = crypto_skcipher_decrypt(data[i].req);
1168 }
1169
1170 /* Wait for all requests to finish */
1171 for (i = 0; i < num_mb; i++) {
1172 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
1173
1174 if (rc[i]) {
1175 pr_info("concurrent request %d error %d\n", i, rc[i]);
1176 err = rc[i];
1177 }
1178 }
1179
1180 return err;
1181}
1182
1183static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc,
1184 int blen, int secs, u32 num_mb)
1185{
1186 unsigned long start, end;
1187 int bcount;
Kees Cook4e234ee2018-04-26 19:57:28 -07001188 int ret = 0;
1189 int *rc;
1190
1191 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1192 if (!rc)
1193 return -ENOMEM;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001194
1195 for (start = jiffies, end = start + secs * HZ, bcount = 0;
1196 time_before(jiffies, end); bcount++) {
Kees Cook4e234ee2018-04-26 19:57:28 -07001197 ret = do_mult_acipher_op(data, enc, num_mb, rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001198 if (ret)
Kees Cook4e234ee2018-04-26 19:57:28 -07001199 goto out;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001200 }
1201
1202 pr_cont("%d operations in %d seconds (%ld bytes)\n",
1203 bcount * num_mb, secs, (long)bcount * blen * num_mb);
Kees Cook4e234ee2018-04-26 19:57:28 -07001204
1205out:
1206 kfree(rc);
1207 return ret;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001208}
1209
1210static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc,
1211 int blen, u32 num_mb)
1212{
1213 unsigned long cycles = 0;
1214 int ret = 0;
1215 int i;
Kees Cook4e234ee2018-04-26 19:57:28 -07001216 int *rc;
1217
1218 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL);
1219 if (!rc)
1220 return -ENOMEM;
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001221
1222 /* Warm-up run. */
1223 for (i = 0; i < 4; i++) {
Kees Cook4e234ee2018-04-26 19:57:28 -07001224 ret = do_mult_acipher_op(data, enc, num_mb, rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001225 if (ret)
1226 goto out;
1227 }
1228
1229 /* The real thing. */
1230 for (i = 0; i < 8; i++) {
1231 cycles_t start, end;
1232
1233 start = get_cycles();
Kees Cook4e234ee2018-04-26 19:57:28 -07001234 ret = do_mult_acipher_op(data, enc, num_mb, rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001235 end = get_cycles();
1236
1237 if (ret)
1238 goto out;
1239
1240 cycles += end - start;
1241 }
1242
Kees Cook4e234ee2018-04-26 19:57:28 -07001243 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1244 (cycles + 4) / (8 * num_mb), blen);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001245
Kees Cook4e234ee2018-04-26 19:57:28 -07001246out:
1247 kfree(rc);
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001248 return ret;
1249}
1250
1251static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
1252 struct cipher_speed_template *template,
1253 unsigned int tcount, u8 *keysize, u32 num_mb)
1254{
1255 struct test_mb_skcipher_data *data;
1256 struct crypto_skcipher *tfm;
1257 unsigned int i, j, iv_len;
1258 const char *key;
1259 const char *e;
1260 u32 *b_size;
1261 char iv[128];
1262 int ret;
1263
1264 if (enc == ENCRYPT)
1265 e = "encryption";
1266 else
1267 e = "decryption";
1268
1269 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
1270 if (!data)
1271 return;
1272
1273 tfm = crypto_alloc_skcipher(algo, 0, 0);
1274 if (IS_ERR(tfm)) {
1275 pr_err("failed to load transform for %s: %ld\n",
1276 algo, PTR_ERR(tfm));
1277 goto out_free_data;
1278 }
1279
1280 for (i = 0; i < num_mb; ++i)
1281 if (testmgr_alloc_buf(data[i].xbuf)) {
1282 while (i--)
1283 testmgr_free_buf(data[i].xbuf);
1284 goto out_free_tfm;
1285 }
1286
1287
1288 for (i = 0; i < num_mb; ++i)
1289 if (testmgr_alloc_buf(data[i].xbuf)) {
1290 while (i--)
1291 testmgr_free_buf(data[i].xbuf);
1292 goto out_free_tfm;
1293 }
1294
1295
1296 for (i = 0; i < num_mb; ++i) {
1297 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
1298 if (!data[i].req) {
1299 pr_err("alg: skcipher: Failed to allocate request for %s\n",
1300 algo);
1301 while (i--)
1302 skcipher_request_free(data[i].req);
1303 goto out_free_xbuf;
1304 }
1305 }
1306
1307 for (i = 0; i < num_mb; ++i) {
1308 skcipher_request_set_callback(data[i].req,
1309 CRYPTO_TFM_REQ_MAY_BACKLOG,
1310 crypto_req_done, &data[i].wait);
1311 crypto_init_wait(&data[i].wait);
1312 }
1313
1314 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo,
1315 get_driver_name(crypto_skcipher, tfm), e);
1316
1317 i = 0;
1318 do {
1319 b_size = block_sizes;
1320 do {
1321 if (*b_size > XBUFSIZE * PAGE_SIZE) {
Colin Ian King38dbe2d2018-01-02 09:21:06 +00001322 pr_err("template (%u) too big for buffer (%lu)\n",
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001323 *b_size, XBUFSIZE * PAGE_SIZE);
1324 goto out;
1325 }
1326
1327 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1328 *keysize * 8, *b_size);
1329
1330 /* Set up tfm global state, i.e. the key */
1331
1332 memset(tvmem[0], 0xff, PAGE_SIZE);
1333 key = tvmem[0];
1334 for (j = 0; j < tcount; j++) {
1335 if (template[j].klen == *keysize) {
1336 key = template[j].key;
1337 break;
1338 }
1339 }
1340
1341 crypto_skcipher_clear_flags(tfm, ~0);
1342
1343 ret = crypto_skcipher_setkey(tfm, key, *keysize);
1344 if (ret) {
1345 pr_err("setkey() failed flags=%x\n",
1346 crypto_skcipher_get_flags(tfm));
1347 goto out;
1348 }
1349
1350 iv_len = crypto_skcipher_ivsize(tfm);
1351 if (iv_len)
1352 memset(&iv, 0xff, iv_len);
1353
1354 /* Now setup per request stuff, i.e. buffers */
1355
1356 for (j = 0; j < num_mb; ++j) {
1357 struct test_mb_skcipher_data *cur = &data[j];
1358 unsigned int k = *b_size;
1359 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE);
1360 unsigned int p = 0;
1361
1362 sg_init_table(cur->sg, pages);
1363
1364 while (k > PAGE_SIZE) {
1365 sg_set_buf(cur->sg + p, cur->xbuf[p],
1366 PAGE_SIZE);
1367 memset(cur->xbuf[p], 0xff, PAGE_SIZE);
1368 p++;
1369 k -= PAGE_SIZE;
1370 }
1371
1372 sg_set_buf(cur->sg + p, cur->xbuf[p], k);
1373 memset(cur->xbuf[p], 0xff, k);
1374
1375 skcipher_request_set_crypt(cur->req, cur->sg,
1376 cur->sg, *b_size,
1377 iv);
1378 }
1379
Horia Geantă2af63292018-07-23 17:18:48 +03001380 if (secs) {
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001381 ret = test_mb_acipher_jiffies(data, enc,
1382 *b_size, secs,
1383 num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +03001384 cond_resched();
1385 } else {
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001386 ret = test_mb_acipher_cycles(data, enc,
1387 *b_size, num_mb);
Horia Geantă2af63292018-07-23 17:18:48 +03001388 }
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00001389
1390 if (ret) {
1391 pr_err("%s() failed flags=%x\n", e,
1392 crypto_skcipher_get_flags(tfm));
1393 break;
1394 }
1395 b_size++;
1396 i++;
1397 } while (*b_size);
1398 keysize++;
1399 } while (*keysize);
1400
1401out:
1402 for (i = 0; i < num_mb; ++i)
1403 skcipher_request_free(data[i].req);
1404out_free_xbuf:
1405 for (i = 0; i < num_mb; ++i)
1406 testmgr_free_buf(data[i].xbuf);
1407out_free_tfm:
1408 crypto_free_skcipher(tfm);
1409out_free_data:
1410 kfree(data);
1411}
1412
Herbert Xu7166e582016-06-29 18:03:50 +08001413static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001414{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001415 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001416
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001417 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001418}
1419
Herbert Xu7166e582016-06-29 18:03:50 +08001420static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001421 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001422{
1423 unsigned long start, end;
1424 int bcount;
1425 int ret;
1426
Mark Rustad3e3dc252014-07-25 02:53:38 -07001427 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001428 time_before(jiffies, end); bcount++) {
1429 if (enc)
1430 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001431 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001432 else
1433 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001434 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001435
1436 if (ret)
1437 return ret;
1438 }
1439
1440 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -07001441 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001442 return 0;
1443}
1444
Herbert Xu7166e582016-06-29 18:03:50 +08001445static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001446 int blen)
1447{
1448 unsigned long cycles = 0;
1449 int ret = 0;
1450 int i;
1451
1452 /* Warm-up run. */
1453 for (i = 0; i < 4; i++) {
1454 if (enc)
1455 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001456 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001457 else
1458 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001459 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001460
1461 if (ret)
1462 goto out;
1463 }
1464
1465 /* The real thing. */
1466 for (i = 0; i < 8; i++) {
1467 cycles_t start, end;
1468
1469 start = get_cycles();
1470 if (enc)
1471 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001472 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001473 else
1474 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +08001475 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001476 end = get_cycles();
1477
1478 if (ret)
1479 goto out;
1480
1481 cycles += end - start;
1482 }
1483
1484out:
1485 if (ret == 0)
1486 pr_cont("1 operation in %lu cycles (%d bytes)\n",
1487 (cycles + 4) / 8, blen);
1488
1489 return ret;
1490}
1491
Herbert Xu7166e582016-06-29 18:03:50 +08001492static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
1493 struct cipher_speed_template *template,
1494 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001495{
Nicolas Royerde1975332012-07-01 19:19:47 +02001496 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001497 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001498 const char *key;
1499 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +08001500 struct skcipher_request *req;
1501 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001502 const char *e;
1503 u32 *b_size;
1504
1505 if (enc == ENCRYPT)
1506 e = "encryption";
1507 else
1508 e = "decryption";
1509
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001510 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001511
Herbert Xu7166e582016-06-29 18:03:50 +08001512 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001513
1514 if (IS_ERR(tfm)) {
1515 pr_err("failed to load transform for %s: %ld\n", algo,
1516 PTR_ERR(tfm));
1517 return;
1518 }
1519
Luca Clementi263a8df2014-06-25 22:57:42 -07001520 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
Herbert Xu7166e582016-06-29 18:03:50 +08001521 get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -07001522
Herbert Xu7166e582016-06-29 18:03:50 +08001523 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001524 if (!req) {
1525 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
1526 algo);
1527 goto out;
1528 }
1529
Herbert Xu7166e582016-06-29 18:03:50 +08001530 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +01001531 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001532
1533 i = 0;
1534 do {
1535 b_size = block_sizes;
1536
1537 do {
1538 struct scatterlist sg[TVMEMSIZE];
1539
1540 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
1541 pr_err("template (%u) too big for "
1542 "tvmem (%lu)\n", *keysize + *b_size,
1543 TVMEMSIZE * PAGE_SIZE);
1544 goto out_free_req;
1545 }
1546
1547 pr_info("test %u (%d bit key, %d byte blocks): ", i,
1548 *keysize * 8, *b_size);
1549
1550 memset(tvmem[0], 0xff, PAGE_SIZE);
1551
1552 /* set key, plain text and IV */
1553 key = tvmem[0];
1554 for (j = 0; j < tcount; j++) {
1555 if (template[j].klen == *keysize) {
1556 key = template[j].key;
1557 break;
1558 }
1559 }
1560
Herbert Xu7166e582016-06-29 18:03:50 +08001561 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001562
Herbert Xu7166e582016-06-29 18:03:50 +08001563 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001564 if (ret) {
1565 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +08001566 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001567 goto out_free_req;
1568 }
1569
Nicolas Royerde1975332012-07-01 19:19:47 +02001570 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +02001571 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
1572
Nicolas Royerde1975332012-07-01 19:19:47 +02001573 if (k > PAGE_SIZE) {
1574 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001575 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +02001576 k -= PAGE_SIZE;
1577 j = 1;
1578 while (k > PAGE_SIZE) {
1579 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
1580 memset(tvmem[j], 0xff, PAGE_SIZE);
1581 j++;
1582 k -= PAGE_SIZE;
1583 }
1584 sg_set_buf(sg + j, tvmem[j], k);
1585 memset(tvmem[j], 0xff, k);
1586 } else {
1587 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001588 }
1589
Herbert Xu7166e582016-06-29 18:03:50 +08001590 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001591 if (iv_len)
1592 memset(&iv, 0xff, iv_len);
1593
Herbert Xu7166e582016-06-29 18:03:50 +08001594 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001595
Horia Geantă2af63292018-07-23 17:18:48 +03001596 if (secs) {
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001597 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001598 *b_size, secs);
Horia Geantă2af63292018-07-23 17:18:48 +03001599 cond_resched();
1600 } else {
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001601 ret = test_acipher_cycles(req, enc,
1602 *b_size);
Horia Geantă2af63292018-07-23 17:18:48 +03001603 }
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001604
1605 if (ret) {
1606 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +08001607 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001608 break;
1609 }
1610 b_size++;
1611 i++;
1612 } while (*b_size);
1613 keysize++;
1614 } while (*keysize);
1615
1616out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +08001617 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001618out:
Herbert Xu7166e582016-06-29 18:03:50 +08001619 crypto_free_skcipher(tfm);
1620}
1621
1622static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1623 struct cipher_speed_template *template,
1624 unsigned int tcount, u8 *keysize)
1625{
1626 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1627 true);
1628}
1629
1630static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1631 struct cipher_speed_template *template,
1632 unsigned int tcount, u8 *keysize)
1633{
1634 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1635 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001636}
1637
Herbert Xuef2736f2005-06-22 13:26:03 -07001638static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639{
1640 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 while (*name) {
1643 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001644 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001645 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648}
1649
Herbert Xu01b32322008-07-31 15:41:55 +08001650static inline int tcrypt_test(const char *alg)
1651{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001652 int ret;
1653
Rabin Vincent76512f22017-01-18 14:54:05 +01001654 pr_debug("testing %s\n", alg);
1655
Jarod Wilson4e033a62009-05-27 15:10:21 +10001656 ret = alg_test(alg, alg, 0, 0);
1657 /* non-fips algs return -EINVAL in fips mode */
1658 if (fips_enabled && ret == -EINVAL)
1659 ret = 0;
1660 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001661}
1662
Kees Cook4e234ee2018-04-26 19:57:28 -07001663static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
Herbert Xu01b32322008-07-31 15:41:55 +08001664{
1665 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001666 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001667
1668 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001670 if (alg) {
1671 if (!crypto_has_alg(alg, type,
1672 mask ?: CRYPTO_ALG_TYPE_MASK))
1673 ret = -ENOENT;
1674 break;
1675 }
1676
Herbert Xu01b32322008-07-31 15:41:55 +08001677 for (i = 1; i < 200; i++)
Kees Cook4e234ee2018-04-26 19:57:28 -07001678 ret += do_test(NULL, 0, 0, i, num_mb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 break;
1680
1681 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001682 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 break;
1684
1685 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001686 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 break;
1688
1689 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001690 ret += tcrypt_test("ecb(des)");
1691 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001692 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 break;
1694
1695 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001696 ret += tcrypt_test("ecb(des3_ede)");
1697 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001698 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 break;
1700
1701 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001702 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001704
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001706 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001708
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001710 ret += tcrypt_test("ecb(blowfish)");
1711 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001712 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 break;
1714
1715 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001716 ret += tcrypt_test("ecb(twofish)");
1717 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001718 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001719 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001720 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001724 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001725 ret += tcrypt_test("cbc(serpent)");
1726 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001727 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001728 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 break;
1730
1731 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001732 ret += tcrypt_test("ecb(aes)");
1733 ret += tcrypt_test("cbc(aes)");
1734 ret += tcrypt_test("lrw(aes)");
1735 ret += tcrypt_test("xts(aes)");
1736 ret += tcrypt_test("ctr(aes)");
1737 ret += tcrypt_test("rfc3686(ctr(aes))");
Gilad Ben-Yossefdfb89ab2018-09-20 14:18:40 +01001738 ret += tcrypt_test("ofb(aes)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 break;
1740
1741 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001742 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001746 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 break;
1748
1749 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001750 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 break;
1752
1753 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001754 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001755 ret += tcrypt_test("cbc(cast5)");
1756 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 break;
1758
1759 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001760 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001761 ret += tcrypt_test("cbc(cast6)");
1762 ret += tcrypt_test("ctr(cast6)");
1763 ret += tcrypt_test("lrw(cast6)");
1764 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 break;
1766
1767 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001768 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 break;
1770
1771 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001772 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 break;
1774
1775 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001776 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 break;
1778
1779 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001780 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 break;
1782
1783 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001784 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 break;
1786
1787 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001788 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 break;
1790
1791 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001792 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 break;
1794
1795 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001796 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 break;
1798
1799 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001800 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 break;
1802
1803 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001804 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 break;
1806
1807 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001808 ret += tcrypt_test("ecb(anubis)");
1809 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 break;
1811
1812 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001813 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 break;
1815
1816 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001817 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 break;
1819
1820 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001821 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001823
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001824 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001825 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001826 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
David Howells90831632006-12-16 12:13:14 +11001828 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001829 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001830 break;
1831
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001832 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001833 ret += tcrypt_test("ecb(camellia)");
1834 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001835 ret += tcrypt_test("ctr(camellia)");
1836 ret += tcrypt_test("lrw(camellia)");
1837 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001838 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001839
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001840 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001841 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001842 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001843
Tan Swee Heng2407d602007-11-23 19:45:00 +08001844 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001845 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001846 break;
1847
Herbert Xu8df213d2007-12-02 14:55:47 +11001848 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001849 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001850 break;
1851
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001852 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001853 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001854 break;
1855
Joy Latten93cc74e2007-12-12 20:24:22 +08001856 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001857 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001858 break;
1859
Kevin Coffman76cb9522008-03-24 21:26:16 +08001860 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001861 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001862 break;
1863
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001864 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001865 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001866 break;
1867
1868 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001869 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001870 break;
1871
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001872 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001873 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001874 break;
1875
1876 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001877 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001878 break;
1879
1880 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001881 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001882 break;
1883
Jarod Wilson5d667322009-05-04 19:23:40 +08001884 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001885 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001886 break;
1887
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001888 case 46:
1889 ret += tcrypt_test("ghash");
1890 break;
1891
Herbert Xu684115212013-09-07 12:56:26 +10001892 case 47:
1893 ret += tcrypt_test("crct10dif");
1894 break;
1895
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301896 case 48:
1897 ret += tcrypt_test("sha3-224");
1898 break;
1899
1900 case 49:
1901 ret += tcrypt_test("sha3-256");
1902 break;
1903
1904 case 50:
1905 ret += tcrypt_test("sha3-384");
1906 break;
1907
1908 case 51:
1909 ret += tcrypt_test("sha3-512");
1910 break;
1911
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001912 case 52:
1913 ret += tcrypt_test("sm3");
1914 break;
1915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001917 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001919
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001921 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001923
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001925 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 break;
1927
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001928 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001929 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001930 break;
1931
1932 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001933 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001934 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001935
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001936 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001937 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001938 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001940 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001941 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001942 break;
1943
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001944 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001945 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001946 break;
1947
1948 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001949 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001950 break;
1951
Shane Wangf1939f72009-09-02 20:05:22 +10001952 case 109:
Eric Biggers0917b872018-06-18 10:22:40 -07001953 ret += tcrypt_test("vmac64(aes)");
Shane Wangf1939f72009-09-02 20:05:22 +10001954 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001955
raveendra padasalagi98eca722016-07-01 11:16:54 +05301956 case 111:
1957 ret += tcrypt_test("hmac(sha3-224)");
1958 break;
1959
1960 case 112:
1961 ret += tcrypt_test("hmac(sha3-256)");
1962 break;
1963
1964 case 113:
1965 ret += tcrypt_test("hmac(sha3-384)");
1966 break;
1967
1968 case 114:
1969 ret += tcrypt_test("hmac(sha3-512)");
1970 break;
1971
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001972 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001973 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001974 break;
1975
Adrian Hoban69435b92010-11-04 15:02:04 -04001976 case 151:
1977 ret += tcrypt_test("rfc4106(gcm(aes))");
1978 break;
1979
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001980 case 152:
1981 ret += tcrypt_test("rfc4543(gcm(aes))");
1982 break;
1983
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001984 case 153:
1985 ret += tcrypt_test("cmac(aes)");
1986 break;
1987
1988 case 154:
1989 ret += tcrypt_test("cmac(des3_ede)");
1990 break;
1991
Horia Geantabbf9c892013-11-28 15:11:16 +02001992 case 155:
1993 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1994 break;
1995
Horia Geantabca4feb2014-03-14 17:46:51 +02001996 case 156:
1997 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1998 break;
1999
2000 case 157:
2001 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
2002 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05302003 case 181:
2004 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
2005 break;
2006 case 182:
2007 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
2008 break;
2009 case 183:
2010 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
2011 break;
2012 case 184:
2013 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
2014 break;
2015 case 185:
2016 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
2017 break;
2018 case 186:
2019 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
2020 break;
2021 case 187:
2022 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
2023 break;
2024 case 188:
2025 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
2026 break;
2027 case 189:
2028 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
2029 break;
2030 case 190:
2031 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
2032 break;
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00002033 case 191:
2034 ret += tcrypt_test("ecb(sm4)");
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002035 ret += tcrypt_test("cbc(sm4)");
2036 ret += tcrypt_test("ctr(sm4)");
Gilad Ben-Yossefcd83a8a2018-03-06 09:44:43 +00002037 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07002038 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10002039 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002040 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002041 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002042 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002043 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002044 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002045 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002046 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11002047 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002048 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11002049 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002050 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08002051 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002052 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08002053 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002054 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08002055 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2056 speed_template_16_24_32);
2057 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2058 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10002059 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2060 speed_template_16_24_32);
2061 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2062 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002063 break;
2064
2065 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10002066 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002067 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002068 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10002069 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002070 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002071 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10002072 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002073 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002074 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10002075 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08002076 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002077 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03002078 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
2079 des3_speed_template, DES3_SPEED_VECTORS,
2080 speed_template_24);
2081 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
2082 des3_speed_template, DES3_SPEED_VECTORS,
2083 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002084 break;
2085
2086 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10002087 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002088 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002089 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002090 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002091 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002092 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10002093 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002094 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03002095 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2096 speed_template_16_24_32);
2097 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2098 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03002099 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2100 speed_template_32_40_48);
2101 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2102 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03002103 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2104 speed_template_32_48_64);
2105 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2106 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002107 break;
2108
2109 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10002110 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002111 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10002112 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002113 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10002114 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002115 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10002116 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002117 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03002118 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2119 speed_template_8_32);
2120 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2121 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002122 break;
2123
2124 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10002125 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002126 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10002127 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002128 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10002129 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002130 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10002131 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002132 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002133 break;
2134
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002135 case 205:
2136 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002137 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002138 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002139 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002140 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002141 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002142 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002143 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02002144 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2145 speed_template_16_24_32);
2146 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2147 speed_template_16_24_32);
2148 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2149 speed_template_32_40_48);
2150 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2151 speed_template_32_40_48);
2152 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2153 speed_template_32_48_64);
2154 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2155 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11002156 break;
2157
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08002158 case 206:
2159 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08002160 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08002161 break;
2162
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002163 case 207:
2164 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2165 speed_template_16_32);
2166 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2167 speed_template_16_32);
2168 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2169 speed_template_16_32);
2170 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2171 speed_template_16_32);
2172 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2173 speed_template_16_32);
2174 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2175 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002176 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2177 speed_template_32_48);
2178 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2179 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002180 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2181 speed_template_32_64);
2182 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2183 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002184 break;
2185
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002186 case 208:
2187 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2188 speed_template_8);
2189 break;
2190
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002191 case 209:
2192 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2193 speed_template_8_16);
2194 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2195 speed_template_8_16);
2196 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2197 speed_template_8_16);
2198 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2199 speed_template_8_16);
2200 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2201 speed_template_8_16);
2202 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2203 speed_template_8_16);
2204 break;
2205
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002206 case 210:
2207 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2208 speed_template_16_32);
2209 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2210 speed_template_16_32);
2211 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2212 speed_template_16_32);
2213 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2214 speed_template_16_32);
2215 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2216 speed_template_16_32);
2217 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2218 speed_template_16_32);
2219 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2220 speed_template_32_48);
2221 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2222 speed_template_32_48);
2223 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2224 speed_template_32_64);
2225 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2226 speed_template_32_64);
2227 break;
2228
Tim Chen53f52d72013-12-11 14:28:47 -08002229 case 211:
2230 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08002231 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05302232 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01002233 NULL, 0, 16, 8, speed_template_16_24_32);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00002234 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
2235 NULL, 0, 16, 16, aead_speed_template_20);
2236 test_aead_speed("gcm(aes)", DECRYPT, sec,
2237 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08002238 break;
2239
Herbert Xu4e4aab62015-06-17 14:04:21 +08002240 case 212:
2241 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08002242 NULL, 0, 16, 16, aead_speed_template_19);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00002243 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
2244 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08002245 break;
2246
Martin Willi2dce0632015-07-16 19:13:59 +02002247 case 213:
2248 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
2249 NULL, 0, 16, 8, aead_speed_template_36);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00002250 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
2251 NULL, 0, 16, 8, aead_speed_template_36);
Martin Willi2dce0632015-07-16 19:13:59 +02002252 break;
2253
2254 case 214:
2255 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
2256 speed_template_32);
2257 break;
2258
Gilad Ben-Yossef427988d2017-12-17 08:29:05 +00002259 case 215:
2260 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL,
2261 0, 16, 16, aead_speed_template_20, num_mb);
2262 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8,
2263 speed_template_16_24_32, num_mb);
2264 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL,
2265 0, 16, 16, aead_speed_template_20, num_mb);
2266 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8,
2267 speed_template_16_24_32, num_mb);
2268 break;
2269
2270 case 216:
2271 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0,
2272 16, 16, aead_speed_template_19, num_mb);
2273 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0,
2274 16, 16, aead_speed_template_19, num_mb);
2275 break;
2276
2277 case 217:
2278 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT,
2279 sec, NULL, 0, 16, 8, aead_speed_template_36,
2280 num_mb);
2281 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT,
2282 sec, NULL, 0, 16, 8, aead_speed_template_36,
2283 num_mb);
2284 break;
2285
Gilad Ben-Yossef95ba5972018-09-20 14:18:38 +01002286 case 218:
2287 test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0,
2288 speed_template_16);
2289 test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0,
2290 speed_template_16);
2291 test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0,
2292 speed_template_16);
2293 test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0,
2294 speed_template_16);
2295 test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0,
2296 speed_template_16);
2297 test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0,
2298 speed_template_16);
2299 break;
Michal Ludvige8057922006-05-30 22:04:19 +10002300 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08002301 if (alg) {
2302 test_hash_speed(alg, sec, generic_hash_speed_template);
2303 break;
2304 }
Michal Ludvige8057922006-05-30 22:04:19 +10002305 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002306 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10002307 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002308 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002309 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002310 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10002311 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002312 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002313 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002314 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10002315 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002316 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002317 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002318 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10002319 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002320 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002321 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002322 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10002323 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002324 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002325 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002326 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10002327 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002328 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002329 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002330 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10002331 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002332 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002333 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002334 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10002335 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002336 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002337 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002338 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10002339 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002340 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002341 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002342 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10002343 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002344 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002345 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002346 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10002347 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002348 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002349 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002350 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10002351 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10002352 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002353 /* fall through */
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08002354 case 313:
2355 test_hash_speed("sha224", sec, generic_hash_speed_template);
2356 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002357 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08002358 case 314:
2359 test_hash_speed("rmd128", sec, generic_hash_speed_template);
2360 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002361 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08002362 case 315:
2363 test_hash_speed("rmd160", sec, generic_hash_speed_template);
2364 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002365 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08002366 case 316:
2367 test_hash_speed("rmd256", sec, generic_hash_speed_template);
2368 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002369 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08002370 case 317:
2371 test_hash_speed("rmd320", sec, generic_hash_speed_template);
2372 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002373 /* fall through */
Huang Ying18bcc912010-03-10 18:30:32 +08002374 case 318:
2375 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
2376 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002377 /* fall through */
Tim Chene3899e42012-09-27 15:44:24 -07002378 case 319:
2379 test_hash_speed("crc32c", sec, generic_hash_speed_template);
2380 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002381 /* fall through */
Herbert Xu684115212013-09-07 12:56:26 +10002382 case 320:
2383 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
2384 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002385 /* fall through */
Martin Willi2dce0632015-07-16 19:13:59 +02002386 case 321:
2387 test_hash_speed("poly1305", sec, poly1305_speed_template);
2388 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002389 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302390 case 322:
2391 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
2392 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002393 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302394 case 323:
2395 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
2396 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002397 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302398 case 324:
2399 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
2400 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002401 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302402 case 325:
2403 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
2404 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002405 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002406 case 326:
2407 test_hash_speed("sm3", sec, generic_hash_speed_template);
2408 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002409 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10002410 case 399:
2411 break;
2412
David S. Millerbeb63da2010-05-19 14:11:21 +10002413 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08002414 if (alg) {
2415 test_ahash_speed(alg, sec, generic_hash_speed_template);
2416 break;
2417 }
David S. Millerbeb63da2010-05-19 14:11:21 +10002418 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002419 case 401:
2420 test_ahash_speed("md4", sec, generic_hash_speed_template);
2421 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002422 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002423 case 402:
2424 test_ahash_speed("md5", sec, generic_hash_speed_template);
2425 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002426 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002427 case 403:
2428 test_ahash_speed("sha1", sec, generic_hash_speed_template);
2429 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002430 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002431 case 404:
2432 test_ahash_speed("sha256", sec, generic_hash_speed_template);
2433 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002434 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002435 case 405:
2436 test_ahash_speed("sha384", sec, generic_hash_speed_template);
2437 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002438 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002439 case 406:
2440 test_ahash_speed("sha512", sec, generic_hash_speed_template);
2441 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002442 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002443 case 407:
2444 test_ahash_speed("wp256", sec, generic_hash_speed_template);
2445 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002446 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002447 case 408:
2448 test_ahash_speed("wp384", sec, generic_hash_speed_template);
2449 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002450 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002451 case 409:
2452 test_ahash_speed("wp512", sec, generic_hash_speed_template);
2453 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002454 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002455 case 410:
2456 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
2457 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002458 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002459 case 411:
2460 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
2461 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002462 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002463 case 412:
2464 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
2465 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002466 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002467 case 413:
2468 test_ahash_speed("sha224", sec, generic_hash_speed_template);
2469 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002470 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002471 case 414:
2472 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
2473 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002474 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002475 case 415:
2476 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
2477 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002478 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002479 case 416:
2480 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
2481 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002482 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002483 case 417:
2484 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
2485 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002486 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302487 case 418:
2488 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
2489 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002490 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302491 case 419:
2492 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
2493 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002494 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302495 case 420:
2496 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
2497 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002498 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05302499 case 421:
2500 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
2501 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002502 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07002503 case 422:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002504 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
2505 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07002506 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002507 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07002508 case 423:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002509 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
2510 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07002511 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002512 /* fall through */
Megha Dey14009c42016-06-27 10:20:09 -07002513 case 424:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002514 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
2515 num_mb);
Megha Dey14009c42016-06-27 10:20:09 -07002516 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002517 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002518 case 425:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002519 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
2520 num_mb);
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03002521 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05002522 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10002523 case 499:
2524 break;
2525
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002526 case 500:
2527 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2528 speed_template_16_24_32);
2529 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2530 speed_template_16_24_32);
2531 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2532 speed_template_16_24_32);
2533 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2534 speed_template_16_24_32);
2535 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2536 speed_template_32_40_48);
2537 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2538 speed_template_32_40_48);
2539 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002540 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002541 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03002542 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08002543 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2544 speed_template_16_24_32);
2545 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2546 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002547 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2548 speed_template_16_24_32);
2549 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2550 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02002551 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2552 speed_template_16_24_32);
2553 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2554 speed_template_16_24_32);
2555 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2556 speed_template_16_24_32);
2557 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2558 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02002559 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
2560 speed_template_20_28_36);
2561 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
2562 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002563 break;
2564
2565 case 501:
2566 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2567 des3_speed_template, DES3_SPEED_VECTORS,
2568 speed_template_24);
2569 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
2570 des3_speed_template, DES3_SPEED_VECTORS,
2571 speed_template_24);
2572 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2573 des3_speed_template, DES3_SPEED_VECTORS,
2574 speed_template_24);
2575 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
2576 des3_speed_template, DES3_SPEED_VECTORS,
2577 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02002578 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2579 des3_speed_template, DES3_SPEED_VECTORS,
2580 speed_template_24);
2581 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
2582 des3_speed_template, DES3_SPEED_VECTORS,
2583 speed_template_24);
2584 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2585 des3_speed_template, DES3_SPEED_VECTORS,
2586 speed_template_24);
2587 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
2588 des3_speed_template, DES3_SPEED_VECTORS,
2589 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002590 break;
2591
2592 case 502:
2593 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2594 speed_template_8);
2595 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2596 speed_template_8);
2597 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2598 speed_template_8);
2599 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2600 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02002601 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2602 speed_template_8);
2603 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2604 speed_template_8);
2605 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2606 speed_template_8);
2607 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2608 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03002609 break;
2610
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002611 case 503:
2612 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2613 speed_template_16_32);
2614 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2615 speed_template_16_32);
2616 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2617 speed_template_16_32);
2618 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2619 speed_template_16_32);
2620 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2621 speed_template_16_32);
2622 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2623 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03002624 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2625 speed_template_32_48);
2626 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2627 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03002628 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2629 speed_template_32_64);
2630 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2631 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03002632 break;
2633
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002634 case 504:
2635 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2636 speed_template_16_24_32);
2637 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2638 speed_template_16_24_32);
2639 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2640 speed_template_16_24_32);
2641 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2642 speed_template_16_24_32);
2643 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2644 speed_template_16_24_32);
2645 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2646 speed_template_16_24_32);
2647 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2648 speed_template_32_40_48);
2649 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2650 speed_template_32_40_48);
2651 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2652 speed_template_32_48_64);
2653 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2654 speed_template_32_48_64);
2655 break;
2656
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002657 case 505:
2658 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2659 speed_template_8);
2660 break;
2661
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002662 case 506:
2663 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2664 speed_template_8_16);
2665 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2666 speed_template_8_16);
2667 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2668 speed_template_8_16);
2669 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2670 speed_template_8_16);
2671 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2672 speed_template_8_16);
2673 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2674 speed_template_8_16);
2675 break;
2676
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002677 case 507:
2678 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2679 speed_template_16_32);
2680 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2681 speed_template_16_32);
2682 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2683 speed_template_16_32);
2684 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2685 speed_template_16_32);
2686 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2687 speed_template_16_32);
2688 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2689 speed_template_16_32);
2690 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2691 speed_template_32_48);
2692 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2693 speed_template_32_48);
2694 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2695 speed_template_32_64);
2696 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2697 speed_template_32_64);
2698 break;
2699
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002700 case 508:
2701 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2702 speed_template_16_32);
2703 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2704 speed_template_16_32);
2705 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2706 speed_template_16_32);
2707 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2708 speed_template_16_32);
2709 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2710 speed_template_16_32);
2711 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2712 speed_template_16_32);
2713 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2714 speed_template_32_48);
2715 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2716 speed_template_32_48);
2717 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2718 speed_template_32_64);
2719 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2720 speed_template_32_64);
2721 break;
2722
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002723 case 509:
2724 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2725 speed_template_8_32);
2726 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2727 speed_template_8_32);
2728 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2729 speed_template_8_32);
2730 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2731 speed_template_8_32);
2732 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2733 speed_template_8_32);
2734 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2735 speed_template_8_32);
2736 break;
2737
Gilad Ben-Yossefe161c592017-12-17 08:29:04 +00002738 case 600:
2739 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
2740 speed_template_16_24_32, num_mb);
2741 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
2742 speed_template_16_24_32, num_mb);
2743 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
2744 speed_template_16_24_32, num_mb);
2745 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
2746 speed_template_16_24_32, num_mb);
2747 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
2748 speed_template_32_40_48, num_mb);
2749 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
2750 speed_template_32_40_48, num_mb);
2751 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
2752 speed_template_32_64, num_mb);
2753 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
2754 speed_template_32_64, num_mb);
2755 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
2756 speed_template_16_24_32, num_mb);
2757 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
2758 speed_template_16_24_32, num_mb);
2759 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
2760 speed_template_16_24_32, num_mb);
2761 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
2762 speed_template_16_24_32, num_mb);
2763 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
2764 speed_template_16_24_32, num_mb);
2765 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
2766 speed_template_16_24_32, num_mb);
2767 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
2768 speed_template_16_24_32, num_mb);
2769 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
2770 speed_template_16_24_32, num_mb);
2771 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL,
2772 0, speed_template_20_28_36, num_mb);
2773 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL,
2774 0, speed_template_20_28_36, num_mb);
2775 break;
2776
2777 case 601:
2778 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec,
2779 des3_speed_template, DES3_SPEED_VECTORS,
2780 speed_template_24, num_mb);
2781 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec,
2782 des3_speed_template, DES3_SPEED_VECTORS,
2783 speed_template_24, num_mb);
2784 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec,
2785 des3_speed_template, DES3_SPEED_VECTORS,
2786 speed_template_24, num_mb);
2787 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec,
2788 des3_speed_template, DES3_SPEED_VECTORS,
2789 speed_template_24, num_mb);
2790 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec,
2791 des3_speed_template, DES3_SPEED_VECTORS,
2792 speed_template_24, num_mb);
2793 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec,
2794 des3_speed_template, DES3_SPEED_VECTORS,
2795 speed_template_24, num_mb);
2796 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec,
2797 des3_speed_template, DES3_SPEED_VECTORS,
2798 speed_template_24, num_mb);
2799 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec,
2800 des3_speed_template, DES3_SPEED_VECTORS,
2801 speed_template_24, num_mb);
2802 break;
2803
2804 case 602:
2805 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
2806 speed_template_8, num_mb);
2807 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
2808 speed_template_8, num_mb);
2809 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
2810 speed_template_8, num_mb);
2811 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
2812 speed_template_8, num_mb);
2813 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
2814 speed_template_8, num_mb);
2815 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
2816 speed_template_8, num_mb);
2817 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
2818 speed_template_8, num_mb);
2819 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
2820 speed_template_8, num_mb);
2821 break;
2822
2823 case 603:
2824 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
2825 speed_template_16_32, num_mb);
2826 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
2827 speed_template_16_32, num_mb);
2828 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
2829 speed_template_16_32, num_mb);
2830 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
2831 speed_template_16_32, num_mb);
2832 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
2833 speed_template_16_32, num_mb);
2834 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
2835 speed_template_16_32, num_mb);
2836 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
2837 speed_template_32_48, num_mb);
2838 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
2839 speed_template_32_48, num_mb);
2840 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
2841 speed_template_32_64, num_mb);
2842 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
2843 speed_template_32_64, num_mb);
2844 break;
2845
2846 case 604:
2847 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2848 speed_template_16_24_32, num_mb);
2849 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2850 speed_template_16_24_32, num_mb);
2851 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2852 speed_template_16_24_32, num_mb);
2853 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2854 speed_template_16_24_32, num_mb);
2855 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2856 speed_template_16_24_32, num_mb);
2857 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2858 speed_template_16_24_32, num_mb);
2859 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2860 speed_template_32_40_48, num_mb);
2861 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2862 speed_template_32_40_48, num_mb);
2863 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2864 speed_template_32_48_64, num_mb);
2865 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2866 speed_template_32_48_64, num_mb);
2867 break;
2868
2869 case 605:
2870 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2871 speed_template_8, num_mb);
2872 break;
2873
2874 case 606:
2875 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2876 speed_template_8_16, num_mb);
2877 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2878 speed_template_8_16, num_mb);
2879 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2880 speed_template_8_16, num_mb);
2881 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2882 speed_template_8_16, num_mb);
2883 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2884 speed_template_8_16, num_mb);
2885 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2886 speed_template_8_16, num_mb);
2887 break;
2888
2889 case 607:
2890 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2891 speed_template_16_32, num_mb);
2892 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2893 speed_template_16_32, num_mb);
2894 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2895 speed_template_16_32, num_mb);
2896 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2897 speed_template_16_32, num_mb);
2898 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2899 speed_template_16_32, num_mb);
2900 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2901 speed_template_16_32, num_mb);
2902 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2903 speed_template_32_48, num_mb);
2904 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2905 speed_template_32_48, num_mb);
2906 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2907 speed_template_32_64, num_mb);
2908 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2909 speed_template_32_64, num_mb);
2910 break;
2911
2912 case 608:
2913 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2914 speed_template_16_32, num_mb);
2915 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2916 speed_template_16_32, num_mb);
2917 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2918 speed_template_16_32, num_mb);
2919 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2920 speed_template_16_32, num_mb);
2921 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2922 speed_template_16_32, num_mb);
2923 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2924 speed_template_16_32, num_mb);
2925 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2926 speed_template_32_48, num_mb);
2927 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2928 speed_template_32_48, num_mb);
2929 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2930 speed_template_32_64, num_mb);
2931 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2932 speed_template_32_64, num_mb);
2933 break;
2934
2935 case 609:
2936 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2937 speed_template_8_32, num_mb);
2938 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2939 speed_template_8_32, num_mb);
2940 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2941 speed_template_8_32, num_mb);
2942 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2943 speed_template_8_32, num_mb);
2944 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2945 speed_template_8_32, num_mb);
2946 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2947 speed_template_8_32, num_mb);
2948 break;
2949
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 case 1000:
2951 test_available();
2952 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002954
2955 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956}
2957
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002958static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002960 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002961 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002962
Herbert Xuf139cfa2008-07-31 12:23:53 +08002963 for (i = 0; i < TVMEMSIZE; i++) {
2964 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2965 if (!tvmem[i])
2966 goto err_free_tv;
2967 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Kees Cook4e234ee2018-04-26 19:57:28 -07002969 err = do_test(alg, type, mask, mode, num_mb);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002970
Jarod Wilson4e033a62009-05-27 15:10:21 +10002971 if (err) {
2972 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2973 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01002974 } else {
2975 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10002976 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977
Jarod Wilson4e033a62009-05-27 15:10:21 +10002978 /* We intentionaly return -EAGAIN to prevent keeping the module,
2979 * unless we're running in fips mode. It does all its work from
2980 * init() and doesn't offer any runtime functionality, but in
2981 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002982 * => we don't need it in the memory, do we?
2983 * -- mludvig
2984 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002985 if (!fips_enabled)
2986 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002987
Herbert Xuf139cfa2008-07-31 12:23:53 +08002988err_free_tv:
2989 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2990 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002991
2992 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993}
2994
2995/*
2996 * If an init function is provided, an exit function must also be provided
2997 * to allow module unload.
2998 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002999static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08003001module_init(tcrypt_mod_init);
3002module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003
Steffen Klasserta873a5f2009-06-19 19:46:53 +08003004module_param(alg, charp, 0);
3005module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08003006module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07003008module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07003009MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
3010 "(defaults to zero which uses CPU cycles instead)");
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00003011module_param(num_mb, uint, 0000);
3012MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013
3014MODULE_LICENSE("GPL");
3015MODULE_DESCRIPTION("Quick & dirty crypto testing module");
3016MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");