blob: 260436004a76b67200de0a5b9dd98e562204552c [file] [log] [blame]
Herbert Xuef2736f2005-06-22 13:26:03 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Quick & dirty crypto testing module.
3 *
4 * This will only exist until we have a better testing mechanism
5 * (e.g. a char device).
6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
8 * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org>
Mikko Herranene3a4ea42007-11-26 22:12:07 +08009 * Copyright (c) 2007 Nokia Siemens Networks
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
Adrian Hoban69435b92010-11-04 15:02:04 -040011 * Updated RFC4106 AES-GCM testing.
12 * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com)
13 * Adrian Hoban <adrian.hoban@intel.com>
14 * Gabriele Paoloni <gabriele.paoloni@intel.com>
15 * Tadeusz Struk (tadeusz.struk@intel.com)
16 * Copyright (c) 2010, Intel Corporation.
17 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * This program is free software; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the Free
Herbert Xuef2736f2005-06-22 13:26:03 -070020 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * any later version.
22 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24
Rabin Vincent76512f22017-01-18 14:54:05 +010025#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26
Herbert Xu1ce5a042015-04-22 15:06:30 +080027#include <crypto/aead.h>
Herbert Xu18e33e62008-07-10 16:01:22 +080028#include <crypto/hash.h>
Herbert Xu7166e582016-06-29 18:03:50 +080029#include <crypto/skcipher.h>
Herbert Xucba83562006-08-13 08:26:09 +100030#include <linux/err.h>
Herbert Xudaf09442015-04-22 13:25:57 +080031#include <linux/fips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/module.h>
David Hardeman378f0582005-09-17 17:55:31 +100035#include <linux/scatterlist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/moduleparam.h>
Harald Welteebfd9bc2005-06-22 13:27:23 -070038#include <linux/jiffies.h>
Herbert Xu6a179442005-06-22 13:29:03 -070039#include <linux/timex.h>
40#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "tcrypt.h"
42
43/*
Herbert Xuf139cfa2008-07-31 12:23:53 +080044 * Need slab memory for testing (size in number of pages).
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 */
Herbert Xuf139cfa2008-07-31 12:23:53 +080046#define TVMEMSIZE 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/*
Herbert Xuda7f0332008-07-31 17:08:25 +080049* Used by test_cipher_speed()
Linus Torvalds1da177e2005-04-16 15:20:36 -070050*/
51#define ENCRYPT 1
52#define DECRYPT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Horia Geant?f074f7b2015-08-27 18:38:36 +030054#define MAX_DIGEST_SIZE 64
55
Harald Welteebfd9bc2005-06-22 13:27:23 -070056/*
Luca Clementi263a8df2014-06-25 22:57:42 -070057 * return a string with the driver name
58 */
59#define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm))
60
61/*
Harald Welteebfd9bc2005-06-22 13:27:23 -070062 * Used by test_cipher_speed()
63 */
Herbert Xu6a179442005-06-22 13:29:03 -070064static unsigned int sec;
Harald Welteebfd9bc2005-06-22 13:27:23 -070065
Steffen Klasserta873a5f2009-06-19 19:46:53 +080066static char *alg = NULL;
67static u32 type;
Herbert Xu7be380f2009-07-14 16:06:54 +080068static u32 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int mode;
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +000070static u32 num_mb = 8;
Herbert Xuf139cfa2008-07-31 12:23:53 +080071static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73static char *check[] = {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +030074 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
Jonathan Lynchcd12fb92007-11-10 20:08:25 +080075 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110077 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080078 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +053079 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
80 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053083static inline int do_one_aead_op(struct aead_request *req, int ret)
84{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010085 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053086
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010087 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053088}
89
Tim Chen53f52d72013-12-11 14:28:47 -080090static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070091 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -080092{
93 unsigned long start, end;
94 int bcount;
95 int ret;
96
Mark Rustad3e3dc252014-07-25 02:53:38 -070097 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -080098 time_before(jiffies, end); bcount++) {
99 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530100 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800101 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530102 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800103
104 if (ret)
105 return ret;
106 }
107
108 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700109 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800110 return 0;
111}
112
113static int test_aead_cycles(struct aead_request *req, int enc, int blen)
114{
115 unsigned long cycles = 0;
116 int ret = 0;
117 int i;
118
Tim Chen53f52d72013-12-11 14:28:47 -0800119 /* Warm-up run. */
120 for (i = 0; i < 4; i++) {
121 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530122 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800123 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530124 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800125
126 if (ret)
127 goto out;
128 }
129
130 /* The real thing. */
131 for (i = 0; i < 8; i++) {
132 cycles_t start, end;
133
134 start = get_cycles();
135 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530136 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800137 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530138 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800139 end = get_cycles();
140
141 if (ret)
142 goto out;
143
144 cycles += end - start;
145 }
146
147out:
Tim Chen53f52d72013-12-11 14:28:47 -0800148 if (ret == 0)
149 printk("1 operation in %lu cycles (%d bytes)\n",
150 (cycles + 4) / 8, blen);
151
152 return ret;
153}
154
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800155static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800156static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
157
158#define XBUFSIZE 8
159#define MAX_IVLEN 32
160
161static int testmgr_alloc_buf(char *buf[XBUFSIZE])
162{
163 int i;
164
165 for (i = 0; i < XBUFSIZE; i++) {
166 buf[i] = (void *)__get_free_page(GFP_KERNEL);
167 if (!buf[i])
168 goto err_free_buf;
169 }
170
171 return 0;
172
173err_free_buf:
174 while (i-- > 0)
175 free_page((unsigned long)buf[i]);
176
177 return -ENOMEM;
178}
179
180static void testmgr_free_buf(char *buf[XBUFSIZE])
181{
182 int i;
183
184 for (i = 0; i < XBUFSIZE; i++)
185 free_page((unsigned long)buf[i]);
186}
187
188static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200189 unsigned int buflen, const void *assoc,
190 unsigned int aad_size)
Tim Chen53f52d72013-12-11 14:28:47 -0800191{
192 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
193 int k, rem;
194
Tim Chen53f52d72013-12-11 14:28:47 -0800195 if (np > XBUFSIZE) {
196 rem = PAGE_SIZE;
197 np = XBUFSIZE;
Cristian Stoicac4768992015-01-27 11:54:27 +0200198 } else {
199 rem = buflen % PAGE_SIZE;
Tim Chen53f52d72013-12-11 14:28:47 -0800200 }
Cristian Stoicac4768992015-01-27 11:54:27 +0200201
Herbert Xu31267272015-06-17 14:05:26 +0800202 sg_init_table(sg, np + 1);
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200203
204 sg_set_buf(&sg[0], assoc, aad_size);
205
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300206 if (rem)
207 np--;
Cristian Stoicac4768992015-01-27 11:54:27 +0200208 for (k = 0; k < np; k++)
Herbert Xu31267272015-06-17 14:05:26 +0800209 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
Cristian Stoicac4768992015-01-27 11:54:27 +0200210
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300211 if (rem)
212 sg_set_buf(&sg[k + 1], xbuf[k], rem);
Tim Chen53f52d72013-12-11 14:28:47 -0800213}
214
Mark Rustad3e3dc252014-07-25 02:53:38 -0700215static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800216 struct aead_speed_template *template,
217 unsigned int tcount, u8 authsize,
218 unsigned int aad_size, u8 *keysize)
219{
220 unsigned int i, j;
221 struct crypto_aead *tfm;
222 int ret = -ENOMEM;
223 const char *key;
224 struct aead_request *req;
225 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800226 struct scatterlist *sgout;
227 const char *e;
228 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200229 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800230 char *xbuf[XBUFSIZE];
231 char *xoutbuf[XBUFSIZE];
232 char *axbuf[XBUFSIZE];
233 unsigned int *b_size;
234 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100235 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800236
Cristian Stoica96692a732015-01-28 13:07:32 +0200237 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
238 if (!iv)
239 return;
240
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200241 if (aad_size >= PAGE_SIZE) {
242 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200243 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200244 }
245
Tim Chen53f52d72013-12-11 14:28:47 -0800246 if (enc == ENCRYPT)
247 e = "encryption";
248 else
249 e = "decryption";
250
251 if (testmgr_alloc_buf(xbuf))
252 goto out_noxbuf;
253 if (testmgr_alloc_buf(axbuf))
254 goto out_noaxbuf;
255 if (testmgr_alloc_buf(xoutbuf))
256 goto out_nooutbuf;
257
Herbert Xua3f21852015-05-27 16:03:51 +0800258 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800259 if (!sg)
260 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800261 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800262
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800263 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800264
265 if (IS_ERR(tfm)) {
266 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
267 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200268 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800269 }
270
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100271 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700272 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
273 get_driver_name(crypto_aead, tfm), e);
274
Tim Chen53f52d72013-12-11 14:28:47 -0800275 req = aead_request_alloc(tfm, GFP_KERNEL);
276 if (!req) {
277 pr_err("alg: aead: Failed to allocate request for %s\n",
278 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200279 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800280 }
281
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530282 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100283 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530284
Tim Chen53f52d72013-12-11 14:28:47 -0800285 i = 0;
286 do {
287 b_size = aead_sizes;
288 do {
289 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200290 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800291
292 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
293 pr_err("template (%u) too big for tvmem (%lu)\n",
294 *keysize + *b_size,
295 TVMEMSIZE * PAGE_SIZE);
296 goto out;
297 }
298
299 key = tvmem[0];
300 for (j = 0; j < tcount; j++) {
301 if (template[j].klen == *keysize) {
302 key = template[j].key;
303 break;
304 }
305 }
306 ret = crypto_aead_setkey(tfm, key, *keysize);
307 ret = crypto_aead_setauthsize(tfm, authsize);
308
309 iv_len = crypto_aead_ivsize(tfm);
310 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200311 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800312
313 crypto_aead_clear_flags(tfm, ~0);
314 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
315 i, *keysize * 8, *b_size);
316
317
318 memset(tvmem[0], 0xff, PAGE_SIZE);
319
320 if (ret) {
321 pr_err("setkey() failed flags=%x\n",
322 crypto_aead_get_flags(tfm));
323 goto out;
324 }
325
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200326 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
327 assoc, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800328
Herbert Xu31267272015-06-17 14:05:26 +0800329 sg_init_aead(sgout, xoutbuf,
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200330 *b_size + (enc ? authsize : 0), assoc,
331 aad_size);
Herbert Xu31267272015-06-17 14:05:26 +0800332
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +0000333 aead_request_set_ad(req, aad_size);
334
335 if (!enc) {
336
337 /*
338 * For decryption we need a proper auth so
339 * we do the encryption path once with buffers
340 * reversed (input <-> output) to calculate it
341 */
342 aead_request_set_crypt(req, sgout, sg,
343 *b_size, iv);
344 ret = do_one_aead_op(req,
345 crypto_aead_encrypt(req));
346
347 if (ret) {
348 pr_err("calculating auth failed failed (%d)\n",
349 ret);
350 break;
351 }
352 }
353
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300354 aead_request_set_crypt(req, sg, sgout,
355 *b_size + (enc ? 0 : authsize),
356 iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800357
Mark Rustad3e3dc252014-07-25 02:53:38 -0700358 if (secs)
359 ret = test_aead_jiffies(req, enc, *b_size,
360 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800361 else
362 ret = test_aead_cycles(req, enc, *b_size);
363
364 if (ret) {
365 pr_err("%s() failed return code=%d\n", e, ret);
366 break;
367 }
368 b_size++;
369 i++;
370 } while (*b_size);
371 keysize++;
372 } while (*keysize);
373
374out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200375 aead_request_free(req);
376out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800377 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200378out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800379 kfree(sg);
380out_nosg:
381 testmgr_free_buf(xoutbuf);
382out_nooutbuf:
383 testmgr_free_buf(axbuf);
384out_noaxbuf:
385 testmgr_free_buf(xbuf);
386out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200387 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800388}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800389
David S. Millerbeb63da2010-05-19 14:11:21 +1000390static void test_hash_sg_init(struct scatterlist *sg)
391{
392 int i;
393
394 sg_init_table(sg, TVMEMSIZE);
395 for (i = 0; i < TVMEMSIZE; i++) {
396 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
397 memset(tvmem[i], 0xff, PAGE_SIZE);
398 }
399}
400
David S. Millerbeb63da2010-05-19 14:11:21 +1000401static inline int do_one_ahash_op(struct ahash_request *req, int ret)
402{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100403 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000404
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100405 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000406}
407
Herbert Xu72259de2016-06-28 20:33:52 +0800408struct test_mb_ahash_data {
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000409 struct scatterlist sg[XBUFSIZE];
Herbert Xu72259de2016-06-28 20:33:52 +0800410 char result[64];
411 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100412 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800413 char *xbuf[XBUFSIZE];
414};
Megha Dey087bcd22016-06-23 18:40:47 -0700415
416static void test_mb_ahash_speed(const char *algo, unsigned int sec,
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000417 struct hash_speed *speed, u32 num_mb)
Megha Dey087bcd22016-06-23 18:40:47 -0700418{
Herbert Xu72259de2016-06-28 20:33:52 +0800419 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700420 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800421 unsigned long start, end;
Herbert Xuf8de55b2016-06-28 16:41:38 +0800422 unsigned long cycles;
Herbert Xu72259de2016-06-28 20:33:52 +0800423 unsigned int i, j, k;
424 int ret;
425
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000426 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
Herbert Xu72259de2016-06-28 20:33:52 +0800427 if (!data)
428 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700429
430 tfm = crypto_alloc_ahash(algo, 0, 0);
431 if (IS_ERR(tfm)) {
432 pr_err("failed to load transform for %s: %ld\n",
433 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800434 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700435 }
Herbert Xu72259de2016-06-28 20:33:52 +0800436
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000437 for (i = 0; i < num_mb; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800438 if (testmgr_alloc_buf(data[i].xbuf))
439 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700440
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100441 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700442
Herbert Xu72259de2016-06-28 20:33:52 +0800443 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
444 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200445 pr_err("alg: hash: Failed to allocate request for %s\n",
446 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800447 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700448 }
Megha Dey087bcd22016-06-23 18:40:47 -0700449
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100450 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
451 &data[i].wait);
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000452
453 sg_init_table(data[i].sg, XBUFSIZE);
454 for (j = 0; j < XBUFSIZE; j++) {
455 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
456 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
457 }
Megha Dey087bcd22016-06-23 18:40:47 -0700458 }
459
Herbert Xu72259de2016-06-28 20:33:52 +0800460 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
461 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700462
463 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800464 /* For some reason this only tests digests. */
465 if (speed[i].blen != speed[i].plen)
466 continue;
467
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000468 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200469 pr_err("template (%u) too big for tvmem (%lu)\n",
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000470 speed[i].blen, XBUFSIZE * PAGE_SIZE);
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200471 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700472 }
473
474 if (speed[i].klen)
475 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
476
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000477 for (k = 0; k < num_mb; k++)
Herbert Xu72259de2016-06-28 20:33:52 +0800478 ahash_request_set_crypt(data[k].req, data[k].sg,
479 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700480
Herbert Xu72259de2016-06-28 20:33:52 +0800481 pr_info("test%3u "
482 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700483 i, speed[i].blen, speed[i].plen,
484 speed[i].blen / speed[i].plen);
485
Herbert Xu72259de2016-06-28 20:33:52 +0800486 start = get_cycles();
487
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000488 for (k = 0; k < num_mb; k++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800489 ret = crypto_ahash_digest(data[k].req);
Herbert Xud13cd112016-06-30 11:00:13 +0800490 if (ret == -EINPROGRESS) {
491 ret = 0;
Megha Dey087bcd22016-06-23 18:40:47 -0700492 continue;
Herbert Xud13cd112016-06-30 11:00:13 +0800493 }
Megha Dey087bcd22016-06-23 18:40:47 -0700494
Megha Dey087bcd22016-06-23 18:40:47 -0700495 if (ret)
Herbert Xu72259de2016-06-28 20:33:52 +0800496 break;
497
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100498 crypto_req_done(&data[k].req->base, 0);
Megha Dey087bcd22016-06-23 18:40:47 -0700499 }
500
Herbert Xu72259de2016-06-28 20:33:52 +0800501 for (j = 0; j < k; j++) {
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100502 struct crypto_wait *wait = &data[j].wait;
503 int wait_ret;
Herbert Xu72259de2016-06-28 20:33:52 +0800504
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100505 wait_ret = crypto_wait_req(-EINPROGRESS, wait);
506 if (wait_ret)
507 ret = wait_ret;
Herbert Xu72259de2016-06-28 20:33:52 +0800508 }
509
510 end = get_cycles();
511 cycles = end - start;
512 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000513 cycles, cycles / (num_mb * speed[i].blen));
Herbert Xu72259de2016-06-28 20:33:52 +0800514
515 if (ret) {
516 pr_err("At least one hashing failed ret=%d\n", ret);
517 break;
518 }
Megha Dey087bcd22016-06-23 18:40:47 -0700519 }
Megha Dey087bcd22016-06-23 18:40:47 -0700520
521out:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000522 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800523 ahash_request_free(data[k].req);
524
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000525 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800526 testmgr_free_buf(data[k].xbuf);
527
528 crypto_free_ahash(tfm);
529
530free_data:
531 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700532}
533
David S. Millerbeb63da2010-05-19 14:11:21 +1000534static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700535 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000536{
537 unsigned long start, end;
538 int bcount;
539 int ret;
540
Mark Rustad3e3dc252014-07-25 02:53:38 -0700541 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000542 time_before(jiffies, end); bcount++) {
543 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
544 if (ret)
545 return ret;
546 }
547
548 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700549 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000550
551 return 0;
552}
553
554static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700555 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000556{
557 unsigned long start, end;
558 int bcount, pcount;
559 int ret;
560
561 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700562 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000563
Mark Rustad3e3dc252014-07-25 02:53:38 -0700564 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000565 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800566 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000567 if (ret)
568 return ret;
569 for (pcount = 0; pcount < blen; pcount += plen) {
570 ret = do_one_ahash_op(req, crypto_ahash_update(req));
571 if (ret)
572 return ret;
573 }
574 /* we assume there is enough space in 'out' for the result */
575 ret = do_one_ahash_op(req, crypto_ahash_final(req));
576 if (ret)
577 return ret;
578 }
579
580 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700581 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000582
583 return 0;
584}
585
586static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
587 char *out)
588{
589 unsigned long cycles = 0;
590 int ret, i;
591
592 /* Warm-up run. */
593 for (i = 0; i < 4; i++) {
594 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
595 if (ret)
596 goto out;
597 }
598
599 /* The real thing. */
600 for (i = 0; i < 8; i++) {
601 cycles_t start, end;
602
603 start = get_cycles();
604
605 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
606 if (ret)
607 goto out;
608
609 end = get_cycles();
610
611 cycles += end - start;
612 }
613
614out:
615 if (ret)
616 return ret;
617
618 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
619 cycles / 8, cycles / (8 * blen));
620
621 return 0;
622}
623
624static int test_ahash_cycles(struct ahash_request *req, int blen,
625 int plen, char *out)
626{
627 unsigned long cycles = 0;
628 int i, pcount, ret;
629
630 if (plen == blen)
631 return test_ahash_cycles_digest(req, blen, out);
632
633 /* Warm-up run. */
634 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800635 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000636 if (ret)
637 goto out;
638 for (pcount = 0; pcount < blen; pcount += plen) {
639 ret = do_one_ahash_op(req, crypto_ahash_update(req));
640 if (ret)
641 goto out;
642 }
643 ret = do_one_ahash_op(req, crypto_ahash_final(req));
644 if (ret)
645 goto out;
646 }
647
648 /* The real thing. */
649 for (i = 0; i < 8; i++) {
650 cycles_t start, end;
651
652 start = get_cycles();
653
Herbert Xu43a96072015-04-22 11:02:27 +0800654 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000655 if (ret)
656 goto out;
657 for (pcount = 0; pcount < blen; pcount += plen) {
658 ret = do_one_ahash_op(req, crypto_ahash_update(req));
659 if (ret)
660 goto out;
661 }
662 ret = do_one_ahash_op(req, crypto_ahash_final(req));
663 if (ret)
664 goto out;
665
666 end = get_cycles();
667
668 cycles += end - start;
669 }
670
671out:
672 if (ret)
673 return ret;
674
675 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
676 cycles / 8, cycles / (8 * blen));
677
678 return 0;
679}
680
Herbert Xu06605112016-02-01 21:36:49 +0800681static void test_ahash_speed_common(const char *algo, unsigned int secs,
682 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +1000683{
684 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100685 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +1000686 struct ahash_request *req;
687 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +0300688 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +1000689 int i, ret;
690
Herbert Xu06605112016-02-01 21:36:49 +0800691 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +1000692 if (IS_ERR(tfm)) {
693 pr_err("failed to load transform for %s: %ld\n",
694 algo, PTR_ERR(tfm));
695 return;
696 }
697
Luca Clementi263a8df2014-06-25 22:57:42 -0700698 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
699 get_driver_name(crypto_ahash, tfm));
700
Horia Geant?f074f7b2015-08-27 18:38:36 +0300701 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
702 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
703 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +1000704 goto out;
705 }
706
707 test_hash_sg_init(sg);
708 req = ahash_request_alloc(tfm, GFP_KERNEL);
709 if (!req) {
710 pr_err("ahash request allocation failure\n");
711 goto out;
712 }
713
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100714 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000715 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100716 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000717
Horia Geant?f074f7b2015-08-27 18:38:36 +0300718 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
719 if (!output)
720 goto out_nomem;
721
David S. Millerbeb63da2010-05-19 14:11:21 +1000722 for (i = 0; speed[i].blen != 0; i++) {
723 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
724 pr_err("template (%u) too big for tvmem (%lu)\n",
725 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
726 break;
727 }
728
729 pr_info("test%3u "
730 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
731 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
732
733 ahash_request_set_crypt(req, sg, output, speed[i].plen);
734
Mark Rustad3e3dc252014-07-25 02:53:38 -0700735 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000736 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700737 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000738 else
739 ret = test_ahash_cycles(req, speed[i].blen,
740 speed[i].plen, output);
741
742 if (ret) {
743 pr_err("hashing failed ret=%d\n", ret);
744 break;
745 }
746 }
747
Horia Geant?f074f7b2015-08-27 18:38:36 +0300748 kfree(output);
749
750out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +1000751 ahash_request_free(req);
752
753out:
754 crypto_free_ahash(tfm);
755}
756
Herbert Xu06605112016-02-01 21:36:49 +0800757static void test_ahash_speed(const char *algo, unsigned int secs,
758 struct hash_speed *speed)
759{
760 return test_ahash_speed_common(algo, secs, speed, 0);
761}
762
763static void test_hash_speed(const char *algo, unsigned int secs,
764 struct hash_speed *speed)
765{
766 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
767}
768
Herbert Xu7166e582016-06-29 18:03:50 +0800769static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300770{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100771 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300772
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100773 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300774}
775
Herbert Xu7166e582016-06-29 18:03:50 +0800776static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700777 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300778{
779 unsigned long start, end;
780 int bcount;
781 int ret;
782
Mark Rustad3e3dc252014-07-25 02:53:38 -0700783 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300784 time_before(jiffies, end); bcount++) {
785 if (enc)
786 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800787 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300788 else
789 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800790 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300791
792 if (ret)
793 return ret;
794 }
795
796 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700797 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300798 return 0;
799}
800
Herbert Xu7166e582016-06-29 18:03:50 +0800801static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300802 int blen)
803{
804 unsigned long cycles = 0;
805 int ret = 0;
806 int i;
807
808 /* Warm-up run. */
809 for (i = 0; i < 4; i++) {
810 if (enc)
811 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800812 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300813 else
814 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800815 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300816
817 if (ret)
818 goto out;
819 }
820
821 /* The real thing. */
822 for (i = 0; i < 8; i++) {
823 cycles_t start, end;
824
825 start = get_cycles();
826 if (enc)
827 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800828 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300829 else
830 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800831 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300832 end = get_cycles();
833
834 if (ret)
835 goto out;
836
837 cycles += end - start;
838 }
839
840out:
841 if (ret == 0)
842 pr_cont("1 operation in %lu cycles (%d bytes)\n",
843 (cycles + 4) / 8, blen);
844
845 return ret;
846}
847
Herbert Xu7166e582016-06-29 18:03:50 +0800848static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
849 struct cipher_speed_template *template,
850 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300851{
Nicolas Royerde1975332012-07-01 19:19:47 +0200852 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100853 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300854 const char *key;
855 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +0800856 struct skcipher_request *req;
857 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300858 const char *e;
859 u32 *b_size;
860
861 if (enc == ENCRYPT)
862 e = "encryption";
863 else
864 e = "decryption";
865
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100866 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300867
Herbert Xu7166e582016-06-29 18:03:50 +0800868 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300869
870 if (IS_ERR(tfm)) {
871 pr_err("failed to load transform for %s: %ld\n", algo,
872 PTR_ERR(tfm));
873 return;
874 }
875
Luca Clementi263a8df2014-06-25 22:57:42 -0700876 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
Herbert Xu7166e582016-06-29 18:03:50 +0800877 get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -0700878
Herbert Xu7166e582016-06-29 18:03:50 +0800879 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300880 if (!req) {
881 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
882 algo);
883 goto out;
884 }
885
Herbert Xu7166e582016-06-29 18:03:50 +0800886 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100887 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300888
889 i = 0;
890 do {
891 b_size = block_sizes;
892
893 do {
894 struct scatterlist sg[TVMEMSIZE];
895
896 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
897 pr_err("template (%u) too big for "
898 "tvmem (%lu)\n", *keysize + *b_size,
899 TVMEMSIZE * PAGE_SIZE);
900 goto out_free_req;
901 }
902
903 pr_info("test %u (%d bit key, %d byte blocks): ", i,
904 *keysize * 8, *b_size);
905
906 memset(tvmem[0], 0xff, PAGE_SIZE);
907
908 /* set key, plain text and IV */
909 key = tvmem[0];
910 for (j = 0; j < tcount; j++) {
911 if (template[j].klen == *keysize) {
912 key = template[j].key;
913 break;
914 }
915 }
916
Herbert Xu7166e582016-06-29 18:03:50 +0800917 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300918
Herbert Xu7166e582016-06-29 18:03:50 +0800919 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300920 if (ret) {
921 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +0800922 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300923 goto out_free_req;
924 }
925
Nicolas Royerde1975332012-07-01 19:19:47 +0200926 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +0200927 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
928
Nicolas Royerde1975332012-07-01 19:19:47 +0200929 if (k > PAGE_SIZE) {
930 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300931 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +0200932 k -= PAGE_SIZE;
933 j = 1;
934 while (k > PAGE_SIZE) {
935 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
936 memset(tvmem[j], 0xff, PAGE_SIZE);
937 j++;
938 k -= PAGE_SIZE;
939 }
940 sg_set_buf(sg + j, tvmem[j], k);
941 memset(tvmem[j], 0xff, k);
942 } else {
943 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300944 }
945
Herbert Xu7166e582016-06-29 18:03:50 +0800946 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300947 if (iv_len)
948 memset(&iv, 0xff, iv_len);
949
Herbert Xu7166e582016-06-29 18:03:50 +0800950 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300951
Mark Rustad3e3dc252014-07-25 02:53:38 -0700952 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300953 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700954 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300955 else
956 ret = test_acipher_cycles(req, enc,
957 *b_size);
958
959 if (ret) {
960 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +0800961 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300962 break;
963 }
964 b_size++;
965 i++;
966 } while (*b_size);
967 keysize++;
968 } while (*keysize);
969
970out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +0800971 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300972out:
Herbert Xu7166e582016-06-29 18:03:50 +0800973 crypto_free_skcipher(tfm);
974}
975
976static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
977 struct cipher_speed_template *template,
978 unsigned int tcount, u8 *keysize)
979{
980 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
981 true);
982}
983
984static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
985 struct cipher_speed_template *template,
986 unsigned int tcount, u8 *keysize)
987{
988 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
989 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300990}
991
Herbert Xuef2736f2005-06-22 13:26:03 -0700992static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
994 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 while (*name) {
997 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000998 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000999 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001001 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002}
1003
Herbert Xu01b32322008-07-31 15:41:55 +08001004static inline int tcrypt_test(const char *alg)
1005{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001006 int ret;
1007
Rabin Vincent76512f22017-01-18 14:54:05 +01001008 pr_debug("testing %s\n", alg);
1009
Jarod Wilson4e033a62009-05-27 15:10:21 +10001010 ret = alg_test(alg, alg, 0, 0);
1011 /* non-fips algs return -EINVAL in fips mode */
1012 if (fips_enabled && ret == -EINVAL)
1013 ret = 0;
1014 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001015}
1016
Herbert Xu86068132014-12-04 16:43:29 +08001017static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +08001018{
1019 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001020 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001021
1022 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001024 if (alg) {
1025 if (!crypto_has_alg(alg, type,
1026 mask ?: CRYPTO_ALG_TYPE_MASK))
1027 ret = -ENOENT;
1028 break;
1029 }
1030
Herbert Xu01b32322008-07-31 15:41:55 +08001031 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001032 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 break;
1034
1035 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001036 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 break;
1038
1039 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001040 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 break;
1042
1043 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001044 ret += tcrypt_test("ecb(des)");
1045 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001046 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 break;
1048
1049 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001050 ret += tcrypt_test("ecb(des3_ede)");
1051 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001052 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 break;
1054
1055 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001056 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001060 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001064 ret += tcrypt_test("ecb(blowfish)");
1065 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001066 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 break;
1068
1069 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001070 ret += tcrypt_test("ecb(twofish)");
1071 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001072 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001073 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001074 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001078 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001079 ret += tcrypt_test("cbc(serpent)");
1080 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001081 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001082 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 break;
1084
1085 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001086 ret += tcrypt_test("ecb(aes)");
1087 ret += tcrypt_test("cbc(aes)");
1088 ret += tcrypt_test("lrw(aes)");
1089 ret += tcrypt_test("xts(aes)");
1090 ret += tcrypt_test("ctr(aes)");
1091 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 break;
1093
1094 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001095 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001099 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 break;
1101
1102 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001103 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 break;
1105
1106 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001107 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001108 ret += tcrypt_test("cbc(cast5)");
1109 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 break;
1111
1112 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001113 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001114 ret += tcrypt_test("cbc(cast6)");
1115 ret += tcrypt_test("ctr(cast6)");
1116 ret += tcrypt_test("lrw(cast6)");
1117 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 break;
1119
1120 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001121 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 break;
1123
1124 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001125 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 break;
1127
1128 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001129 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 break;
1131
1132 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001133 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 break;
1135
1136 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001137 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 break;
1139
1140 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001141 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 break;
1143
1144 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001145 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 break;
1147
1148 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001149 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 break;
1151
1152 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001153 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 break;
1155
1156 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001157 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 break;
1159
1160 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001161 ret += tcrypt_test("ecb(anubis)");
1162 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 break;
1164
1165 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001166 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 break;
1168
1169 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001170 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 break;
1172
1173 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001174 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001176
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001177 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001178 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001179 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
David Howells90831632006-12-16 12:13:14 +11001181 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001182 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001183 break;
1184
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001185 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001186 ret += tcrypt_test("ecb(camellia)");
1187 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001188 ret += tcrypt_test("ctr(camellia)");
1189 ret += tcrypt_test("lrw(camellia)");
1190 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001191 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001192
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001193 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001194 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001195 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001196
Tan Swee Heng2407d602007-11-23 19:45:00 +08001197 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001198 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001199 break;
1200
Herbert Xu8df213d2007-12-02 14:55:47 +11001201 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001202 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001203 break;
1204
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001205 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001206 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001207 break;
1208
Joy Latten93cc74e2007-12-12 20:24:22 +08001209 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001210 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001211 break;
1212
Kevin Coffman76cb9522008-03-24 21:26:16 +08001213 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001214 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001215 break;
1216
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001217 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001218 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001219 break;
1220
1221 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001222 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001223 break;
1224
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001225 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001226 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001227 break;
1228
1229 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001230 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001231 break;
1232
1233 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001234 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001235 break;
1236
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001237 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001238 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001239 break;
1240
Jarod Wilson5d667322009-05-04 19:23:40 +08001241 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001242 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001243 break;
1244
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001245 case 46:
1246 ret += tcrypt_test("ghash");
1247 break;
1248
Herbert Xu684115212013-09-07 12:56:26 +10001249 case 47:
1250 ret += tcrypt_test("crct10dif");
1251 break;
1252
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301253 case 48:
1254 ret += tcrypt_test("sha3-224");
1255 break;
1256
1257 case 49:
1258 ret += tcrypt_test("sha3-256");
1259 break;
1260
1261 case 50:
1262 ret += tcrypt_test("sha3-384");
1263 break;
1264
1265 case 51:
1266 ret += tcrypt_test("sha3-512");
1267 break;
1268
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001269 case 52:
1270 ret += tcrypt_test("sm3");
1271 break;
1272
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001274 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001276
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001278 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001282 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 break;
1284
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001285 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001286 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001287 break;
1288
1289 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001290 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001291 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001292
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001293 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001294 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001297 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001298 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001299 break;
1300
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001301 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001302 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001303 break;
1304
1305 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001306 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001307 break;
1308
Shane Wangf1939f72009-09-02 20:05:22 +10001309 case 109:
1310 ret += tcrypt_test("vmac(aes)");
1311 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001312
Sonic Zhanga482b082012-05-25 17:54:13 +08001313 case 110:
1314 ret += tcrypt_test("hmac(crc32)");
1315 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001316
raveendra padasalagi98eca722016-07-01 11:16:54 +05301317 case 111:
1318 ret += tcrypt_test("hmac(sha3-224)");
1319 break;
1320
1321 case 112:
1322 ret += tcrypt_test("hmac(sha3-256)");
1323 break;
1324
1325 case 113:
1326 ret += tcrypt_test("hmac(sha3-384)");
1327 break;
1328
1329 case 114:
1330 ret += tcrypt_test("hmac(sha3-512)");
1331 break;
1332
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001333 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001334 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001335 break;
1336
Adrian Hoban69435b92010-11-04 15:02:04 -04001337 case 151:
1338 ret += tcrypt_test("rfc4106(gcm(aes))");
1339 break;
1340
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001341 case 152:
1342 ret += tcrypt_test("rfc4543(gcm(aes))");
1343 break;
1344
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001345 case 153:
1346 ret += tcrypt_test("cmac(aes)");
1347 break;
1348
1349 case 154:
1350 ret += tcrypt_test("cmac(des3_ede)");
1351 break;
1352
Horia Geantabbf9c892013-11-28 15:11:16 +02001353 case 155:
1354 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1355 break;
1356
Horia Geantabca4feb2014-03-14 17:46:51 +02001357 case 156:
1358 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1359 break;
1360
1361 case 157:
1362 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1363 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301364 case 181:
1365 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1366 break;
1367 case 182:
1368 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1369 break;
1370 case 183:
1371 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1372 break;
1373 case 184:
1374 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1375 break;
1376 case 185:
1377 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1378 break;
1379 case 186:
1380 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1381 break;
1382 case 187:
1383 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1384 break;
1385 case 188:
1386 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1387 break;
1388 case 189:
1389 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1390 break;
1391 case 190:
1392 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1393 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001394 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001395 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001396 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001397 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001398 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001399 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001400 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001401 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001402 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001403 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001404 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001405 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001406 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001407 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001408 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001409 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001410 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001411 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1412 speed_template_16_24_32);
1413 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1414 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10001415 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1416 speed_template_16_24_32);
1417 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1418 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001419 break;
1420
1421 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001422 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001423 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001424 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001425 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001426 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001427 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001428 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001429 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001430 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001431 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001432 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001433 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001434 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1435 des3_speed_template, DES3_SPEED_VECTORS,
1436 speed_template_24);
1437 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1438 des3_speed_template, DES3_SPEED_VECTORS,
1439 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001440 break;
1441
1442 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001443 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001444 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001445 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001446 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001447 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001448 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001449 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001450 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001451 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1452 speed_template_16_24_32);
1453 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1454 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001455 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1456 speed_template_32_40_48);
1457 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1458 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001459 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1460 speed_template_32_48_64);
1461 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1462 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001463 break;
1464
1465 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001466 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001467 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001468 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001469 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001470 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001471 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001472 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001473 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001474 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1475 speed_template_8_32);
1476 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1477 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001478 break;
1479
1480 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001481 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001482 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001483 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001484 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001485 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001486 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001487 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001488 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001489 break;
1490
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001491 case 205:
1492 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001493 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001494 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001495 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001496 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001497 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001498 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001499 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001500 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1501 speed_template_16_24_32);
1502 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1503 speed_template_16_24_32);
1504 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1505 speed_template_32_40_48);
1506 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1507 speed_template_32_40_48);
1508 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1509 speed_template_32_48_64);
1510 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1511 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001512 break;
1513
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001514 case 206:
1515 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001516 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001517 break;
1518
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001519 case 207:
1520 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1521 speed_template_16_32);
1522 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1523 speed_template_16_32);
1524 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1525 speed_template_16_32);
1526 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1527 speed_template_16_32);
1528 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1529 speed_template_16_32);
1530 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1531 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001532 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1533 speed_template_32_48);
1534 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1535 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001536 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1537 speed_template_32_64);
1538 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1539 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001540 break;
1541
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001542 case 208:
1543 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1544 speed_template_8);
1545 break;
1546
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001547 case 209:
1548 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1549 speed_template_8_16);
1550 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1551 speed_template_8_16);
1552 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1553 speed_template_8_16);
1554 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1555 speed_template_8_16);
1556 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1557 speed_template_8_16);
1558 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1559 speed_template_8_16);
1560 break;
1561
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001562 case 210:
1563 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1564 speed_template_16_32);
1565 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1566 speed_template_16_32);
1567 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1568 speed_template_16_32);
1569 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1570 speed_template_16_32);
1571 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1572 speed_template_16_32);
1573 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1574 speed_template_16_32);
1575 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1576 speed_template_32_48);
1577 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1578 speed_template_32_48);
1579 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1580 speed_template_32_64);
1581 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1582 speed_template_32_64);
1583 break;
1584
Tim Chen53f52d72013-12-11 14:28:47 -08001585 case 211:
1586 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001587 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05301588 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01001589 NULL, 0, 16, 8, speed_template_16_24_32);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001590 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
1591 NULL, 0, 16, 16, aead_speed_template_20);
1592 test_aead_speed("gcm(aes)", DECRYPT, sec,
1593 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08001594 break;
1595
Herbert Xu4e4aab62015-06-17 14:04:21 +08001596 case 212:
1597 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001598 NULL, 0, 16, 16, aead_speed_template_19);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001599 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
1600 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08001601 break;
1602
Martin Willi2dce0632015-07-16 19:13:59 +02001603 case 213:
1604 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1605 NULL, 0, 16, 8, aead_speed_template_36);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001606 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
1607 NULL, 0, 16, 8, aead_speed_template_36);
Martin Willi2dce0632015-07-16 19:13:59 +02001608 break;
1609
1610 case 214:
1611 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1612 speed_template_32);
1613 break;
1614
Michal Ludvige8057922006-05-30 22:04:19 +10001615 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001616 if (alg) {
1617 test_hash_speed(alg, sec, generic_hash_speed_template);
1618 break;
1619 }
Michal Ludvige8057922006-05-30 22:04:19 +10001620 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001621 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001622 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001623 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001624 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001625 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001626 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001627 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001628 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001629 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001630 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001631 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001632 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001633 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001634 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001635 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001636 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001637 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001638 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001639 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001640 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001641 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001642 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001643 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001644 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001645 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001646 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001647 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001648 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001649 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001650 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001651 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001652 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001653 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001654 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001655 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001656 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001657 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001658 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001659 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001660 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001661 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001662 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001663 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001664 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001665 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001666 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001667 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001668 /* fall through */
Jonathan Lynchcd12fb92007-11-10 20:08:25 +08001669 case 313:
1670 test_hash_speed("sha224", sec, generic_hash_speed_template);
1671 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001672 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001673 case 314:
1674 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1675 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001676 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001677 case 315:
1678 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1679 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001680 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001681 case 316:
1682 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1683 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001684 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001685 case 317:
1686 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1687 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001688 /* fall through */
Huang Ying18bcc912010-03-10 18:30:32 +08001689 case 318:
1690 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1691 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001692 /* fall through */
Tim Chene3899e42012-09-27 15:44:24 -07001693 case 319:
1694 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1695 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001696 /* fall through */
Herbert Xu684115212013-09-07 12:56:26 +10001697 case 320:
1698 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1699 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001700 /* fall through */
Martin Willi2dce0632015-07-16 19:13:59 +02001701 case 321:
1702 test_hash_speed("poly1305", sec, poly1305_speed_template);
1703 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001704 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301705 case 322:
1706 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
1707 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001708 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301709 case 323:
1710 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
1711 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001712 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301713 case 324:
1714 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
1715 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001716 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301717 case 325:
1718 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
1719 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001720 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001721 case 326:
1722 test_hash_speed("sm3", sec, generic_hash_speed_template);
1723 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001724 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001725 case 399:
1726 break;
1727
David S. Millerbeb63da2010-05-19 14:11:21 +10001728 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08001729 if (alg) {
1730 test_ahash_speed(alg, sec, generic_hash_speed_template);
1731 break;
1732 }
David S. Millerbeb63da2010-05-19 14:11:21 +10001733 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001734 case 401:
1735 test_ahash_speed("md4", sec, generic_hash_speed_template);
1736 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001737 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001738 case 402:
1739 test_ahash_speed("md5", sec, generic_hash_speed_template);
1740 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001741 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001742 case 403:
1743 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1744 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001745 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001746 case 404:
1747 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1748 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001749 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001750 case 405:
1751 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1752 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001753 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001754 case 406:
1755 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1756 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001757 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001758 case 407:
1759 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1760 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001761 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001762 case 408:
1763 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1764 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001765 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001766 case 409:
1767 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1768 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001769 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001770 case 410:
1771 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1772 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001773 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001774 case 411:
1775 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1776 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001777 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001778 case 412:
1779 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1780 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001781 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001782 case 413:
1783 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1784 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001785 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001786 case 414:
1787 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1788 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001789 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001790 case 415:
1791 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1792 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001793 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001794 case 416:
1795 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1796 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001797 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001798 case 417:
1799 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1800 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001801 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301802 case 418:
1803 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
1804 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001805 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301806 case 419:
1807 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
1808 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001809 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301810 case 420:
1811 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
1812 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001813 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301814 case 421:
1815 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
1816 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001817 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001818 case 422:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001819 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
1820 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07001821 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001822 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001823 case 423:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001824 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
1825 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07001826 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001827 /* fall through */
Megha Dey14009c42016-06-27 10:20:09 -07001828 case 424:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001829 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
1830 num_mb);
Megha Dey14009c42016-06-27 10:20:09 -07001831 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001832 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001833 case 425:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001834 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
1835 num_mb);
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001836 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001837 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001838 case 499:
1839 break;
1840
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001841 case 500:
1842 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1843 speed_template_16_24_32);
1844 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1845 speed_template_16_24_32);
1846 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1847 speed_template_16_24_32);
1848 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1849 speed_template_16_24_32);
1850 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1851 speed_template_32_40_48);
1852 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1853 speed_template_32_40_48);
1854 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001855 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001856 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001857 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001858 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1859 speed_template_16_24_32);
1860 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1861 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001862 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1863 speed_template_16_24_32);
1864 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1865 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02001866 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1867 speed_template_16_24_32);
1868 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1869 speed_template_16_24_32);
1870 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1871 speed_template_16_24_32);
1872 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1873 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02001874 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1875 speed_template_20_28_36);
1876 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1877 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001878 break;
1879
1880 case 501:
1881 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1882 des3_speed_template, DES3_SPEED_VECTORS,
1883 speed_template_24);
1884 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1885 des3_speed_template, DES3_SPEED_VECTORS,
1886 speed_template_24);
1887 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1888 des3_speed_template, DES3_SPEED_VECTORS,
1889 speed_template_24);
1890 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1891 des3_speed_template, DES3_SPEED_VECTORS,
1892 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02001893 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1894 des3_speed_template, DES3_SPEED_VECTORS,
1895 speed_template_24);
1896 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1897 des3_speed_template, DES3_SPEED_VECTORS,
1898 speed_template_24);
1899 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1900 des3_speed_template, DES3_SPEED_VECTORS,
1901 speed_template_24);
1902 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1903 des3_speed_template, DES3_SPEED_VECTORS,
1904 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001905 break;
1906
1907 case 502:
1908 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1909 speed_template_8);
1910 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1911 speed_template_8);
1912 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1913 speed_template_8);
1914 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1915 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02001916 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1917 speed_template_8);
1918 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1919 speed_template_8);
1920 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1921 speed_template_8);
1922 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1923 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001924 break;
1925
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001926 case 503:
1927 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1928 speed_template_16_32);
1929 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1930 speed_template_16_32);
1931 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1932 speed_template_16_32);
1933 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1934 speed_template_16_32);
1935 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1936 speed_template_16_32);
1937 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1938 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001939 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1940 speed_template_32_48);
1941 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1942 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001943 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1944 speed_template_32_64);
1945 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1946 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001947 break;
1948
Johannes Goetzfried107778b52012-05-28 15:54:24 +02001949 case 504:
1950 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1951 speed_template_16_24_32);
1952 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1953 speed_template_16_24_32);
1954 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1955 speed_template_16_24_32);
1956 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1957 speed_template_16_24_32);
1958 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1959 speed_template_16_24_32);
1960 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1961 speed_template_16_24_32);
1962 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1963 speed_template_32_40_48);
1964 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1965 speed_template_32_40_48);
1966 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1967 speed_template_32_48_64);
1968 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1969 speed_template_32_48_64);
1970 break;
1971
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001972 case 505:
1973 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1974 speed_template_8);
1975 break;
1976
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001977 case 506:
1978 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1979 speed_template_8_16);
1980 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1981 speed_template_8_16);
1982 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1983 speed_template_8_16);
1984 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1985 speed_template_8_16);
1986 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1987 speed_template_8_16);
1988 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1989 speed_template_8_16);
1990 break;
1991
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001992 case 507:
1993 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1994 speed_template_16_32);
1995 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1996 speed_template_16_32);
1997 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1998 speed_template_16_32);
1999 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2000 speed_template_16_32);
2001 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2002 speed_template_16_32);
2003 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2004 speed_template_16_32);
2005 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2006 speed_template_32_48);
2007 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2008 speed_template_32_48);
2009 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2010 speed_template_32_64);
2011 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2012 speed_template_32_64);
2013 break;
2014
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002015 case 508:
2016 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2017 speed_template_16_32);
2018 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2019 speed_template_16_32);
2020 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2021 speed_template_16_32);
2022 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2023 speed_template_16_32);
2024 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2025 speed_template_16_32);
2026 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2027 speed_template_16_32);
2028 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2029 speed_template_32_48);
2030 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2031 speed_template_32_48);
2032 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2033 speed_template_32_64);
2034 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2035 speed_template_32_64);
2036 break;
2037
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002038 case 509:
2039 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2040 speed_template_8_32);
2041 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2042 speed_template_8_32);
2043 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2044 speed_template_8_32);
2045 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2046 speed_template_8_32);
2047 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2048 speed_template_8_32);
2049 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2050 speed_template_8_32);
2051 break;
2052
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 case 1000:
2054 test_available();
2055 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002057
2058 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002061static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002063 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002064 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002065
Herbert Xuf139cfa2008-07-31 12:23:53 +08002066 for (i = 0; i < TVMEMSIZE; i++) {
2067 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2068 if (!tvmem[i])
2069 goto err_free_tv;
2070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Herbert Xu86068132014-12-04 16:43:29 +08002072 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002073
Jarod Wilson4e033a62009-05-27 15:10:21 +10002074 if (err) {
2075 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2076 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01002077 } else {
2078 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10002079 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Jarod Wilson4e033a62009-05-27 15:10:21 +10002081 /* We intentionaly return -EAGAIN to prevent keeping the module,
2082 * unless we're running in fips mode. It does all its work from
2083 * init() and doesn't offer any runtime functionality, but in
2084 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002085 * => we don't need it in the memory, do we?
2086 * -- mludvig
2087 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002088 if (!fips_enabled)
2089 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002090
Herbert Xuf139cfa2008-07-31 12:23:53 +08002091err_free_tv:
2092 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2093 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002094
2095 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096}
2097
2098/*
2099 * If an init function is provided, an exit function must also be provided
2100 * to allow module unload.
2101 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002102static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002104module_init(tcrypt_mod_init);
2105module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002107module_param(alg, charp, 0);
2108module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002109module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002111module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002112MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2113 "(defaults to zero which uses CPU cycles instead)");
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002114module_param(num_mb, uint, 0000);
2115MODULE_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 -07002116
2117MODULE_LICENSE("GPL");
2118MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2119MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");