blob: e406b00db89cd4f1a32c1967841b652edc15f523 [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 Lynchcd12fb902007-11-10 20:08:25 +080075 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110077 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080078 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +053079 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
80 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053083static inline int do_one_aead_op(struct aead_request *req, int ret)
84{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010085 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053086
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010087 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053088}
89
Tim Chen53f52d72013-12-11 14:28:47 -080090static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070091 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -080092{
93 unsigned long start, end;
94 int bcount;
95 int ret;
96
Mark Rustad3e3dc252014-07-25 02:53:38 -070097 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -080098 time_before(jiffies, end); bcount++) {
99 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530100 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800101 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530102 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800103
104 if (ret)
105 return ret;
106 }
107
108 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700109 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800110 return 0;
111}
112
113static int test_aead_cycles(struct aead_request *req, int enc, int blen)
114{
115 unsigned long cycles = 0;
116 int ret = 0;
117 int i;
118
Tim Chen53f52d72013-12-11 14:28:47 -0800119 /* Warm-up run. */
120 for (i = 0; i < 4; i++) {
121 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530122 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800123 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530124 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800125
126 if (ret)
127 goto out;
128 }
129
130 /* The real thing. */
131 for (i = 0; i < 8; i++) {
132 cycles_t start, end;
133
134 start = get_cycles();
135 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530136 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800137 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530138 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800139 end = get_cycles();
140
141 if (ret)
142 goto out;
143
144 cycles += end - start;
145 }
146
147out:
Tim Chen53f52d72013-12-11 14:28:47 -0800148 if (ret == 0)
149 printk("1 operation in %lu cycles (%d bytes)\n",
150 (cycles + 4) / 8, blen);
151
152 return ret;
153}
154
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800155static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800156static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
157
158#define XBUFSIZE 8
159#define MAX_IVLEN 32
160
161static int testmgr_alloc_buf(char *buf[XBUFSIZE])
162{
163 int i;
164
165 for (i = 0; i < XBUFSIZE; i++) {
166 buf[i] = (void *)__get_free_page(GFP_KERNEL);
167 if (!buf[i])
168 goto err_free_buf;
169 }
170
171 return 0;
172
173err_free_buf:
174 while (i-- > 0)
175 free_page((unsigned long)buf[i]);
176
177 return -ENOMEM;
178}
179
180static void testmgr_free_buf(char *buf[XBUFSIZE])
181{
182 int i;
183
184 for (i = 0; i < XBUFSIZE; i++)
185 free_page((unsigned long)buf[i]);
186}
187
188static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200189 unsigned int buflen, const void *assoc,
190 unsigned int aad_size)
Tim Chen53f52d72013-12-11 14:28:47 -0800191{
192 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
193 int k, rem;
194
Tim Chen53f52d72013-12-11 14:28:47 -0800195 if (np > XBUFSIZE) {
196 rem = PAGE_SIZE;
197 np = XBUFSIZE;
Cristian Stoicac4768992015-01-27 11:54:27 +0200198 } else {
199 rem = buflen % PAGE_SIZE;
Tim Chen53f52d72013-12-11 14:28:47 -0800200 }
Cristian Stoicac4768992015-01-27 11:54:27 +0200201
Herbert Xu31267272015-06-17 14:05:26 +0800202 sg_init_table(sg, np + 1);
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200203
204 sg_set_buf(&sg[0], assoc, aad_size);
205
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300206 if (rem)
207 np--;
Cristian Stoicac4768992015-01-27 11:54:27 +0200208 for (k = 0; k < np; k++)
Herbert Xu31267272015-06-17 14:05:26 +0800209 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
Cristian Stoicac4768992015-01-27 11:54:27 +0200210
Robert Baronescu5c6ac1d2017-10-10 13:21:59 +0300211 if (rem)
212 sg_set_buf(&sg[k + 1], xbuf[k], rem);
Tim Chen53f52d72013-12-11 14:28:47 -0800213}
214
Mark Rustad3e3dc252014-07-25 02:53:38 -0700215static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800216 struct aead_speed_template *template,
217 unsigned int tcount, u8 authsize,
218 unsigned int aad_size, u8 *keysize)
219{
220 unsigned int i, j;
221 struct crypto_aead *tfm;
222 int ret = -ENOMEM;
223 const char *key;
224 struct aead_request *req;
225 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800226 struct scatterlist *sgout;
227 const char *e;
228 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200229 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800230 char *xbuf[XBUFSIZE];
231 char *xoutbuf[XBUFSIZE];
232 char *axbuf[XBUFSIZE];
233 unsigned int *b_size;
234 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100235 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800236
Cristian Stoica96692a732015-01-28 13:07:32 +0200237 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
238 if (!iv)
239 return;
240
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200241 if (aad_size >= PAGE_SIZE) {
242 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200243 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200244 }
245
Tim Chen53f52d72013-12-11 14:28:47 -0800246 if (enc == ENCRYPT)
247 e = "encryption";
248 else
249 e = "decryption";
250
251 if (testmgr_alloc_buf(xbuf))
252 goto out_noxbuf;
253 if (testmgr_alloc_buf(axbuf))
254 goto out_noaxbuf;
255 if (testmgr_alloc_buf(xoutbuf))
256 goto out_nooutbuf;
257
Herbert Xua3f21852015-05-27 16:03:51 +0800258 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800259 if (!sg)
260 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800261 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800262
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800263 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800264
265 if (IS_ERR(tfm)) {
266 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
267 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200268 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800269 }
270
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100271 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700272 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
273 get_driver_name(crypto_aead, tfm), e);
274
Tim Chen53f52d72013-12-11 14:28:47 -0800275 req = aead_request_alloc(tfm, GFP_KERNEL);
276 if (!req) {
277 pr_err("alg: aead: Failed to allocate request for %s\n",
278 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200279 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800280 }
281
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530282 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100283 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530284
Tim Chen53f52d72013-12-11 14:28:47 -0800285 i = 0;
286 do {
287 b_size = aead_sizes;
288 do {
289 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200290 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800291
292 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
293 pr_err("template (%u) too big for tvmem (%lu)\n",
294 *keysize + *b_size,
295 TVMEMSIZE * PAGE_SIZE);
296 goto out;
297 }
298
299 key = tvmem[0];
300 for (j = 0; j < tcount; j++) {
301 if (template[j].klen == *keysize) {
302 key = template[j].key;
303 break;
304 }
305 }
306 ret = crypto_aead_setkey(tfm, key, *keysize);
307 ret = crypto_aead_setauthsize(tfm, authsize);
308
309 iv_len = crypto_aead_ivsize(tfm);
310 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200311 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800312
313 crypto_aead_clear_flags(tfm, ~0);
314 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
315 i, *keysize * 8, *b_size);
316
317
318 memset(tvmem[0], 0xff, PAGE_SIZE);
319
320 if (ret) {
321 pr_err("setkey() failed flags=%x\n",
322 crypto_aead_get_flags(tfm));
323 goto out;
324 }
325
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200326 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize),
327 assoc, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800328
Herbert Xu31267272015-06-17 14:05:26 +0800329 sg_init_aead(sgout, xoutbuf,
Tudor-Dan Ambarus5601e012017-11-14 16:59:15 +0200330 *b_size + (enc ? authsize : 0), assoc,
331 aad_size);
Herbert Xu31267272015-06-17 14:05:26 +0800332
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +0000333 aead_request_set_ad(req, aad_size);
334
335 if (!enc) {
336
337 /*
338 * For decryption we need a proper auth so
339 * we do the encryption path once with buffers
340 * reversed (input <-> output) to calculate it
341 */
342 aead_request_set_crypt(req, sgout, sg,
343 *b_size, iv);
344 ret = do_one_aead_op(req,
345 crypto_aead_encrypt(req));
346
347 if (ret) {
348 pr_err("calculating auth failed failed (%d)\n",
349 ret);
350 break;
351 }
352 }
353
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300354 aead_request_set_crypt(req, sg, sgout,
355 *b_size + (enc ? 0 : authsize),
356 iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800357
Mark Rustad3e3dc252014-07-25 02:53:38 -0700358 if (secs)
359 ret = test_aead_jiffies(req, enc, *b_size,
360 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800361 else
362 ret = test_aead_cycles(req, enc, *b_size);
363
364 if (ret) {
365 pr_err("%s() failed return code=%d\n", e, ret);
366 break;
367 }
368 b_size++;
369 i++;
370 } while (*b_size);
371 keysize++;
372 } while (*keysize);
373
374out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200375 aead_request_free(req);
376out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800377 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200378out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800379 kfree(sg);
380out_nosg:
381 testmgr_free_buf(xoutbuf);
382out_nooutbuf:
383 testmgr_free_buf(axbuf);
384out_noaxbuf:
385 testmgr_free_buf(xbuf);
386out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200387 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800388}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800389
David S. Millerbeb63da2010-05-19 14:11:21 +1000390static void test_hash_sg_init(struct scatterlist *sg)
391{
392 int i;
393
394 sg_init_table(sg, TVMEMSIZE);
395 for (i = 0; i < TVMEMSIZE; i++) {
396 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
397 memset(tvmem[i], 0xff, PAGE_SIZE);
398 }
399}
400
David S. Millerbeb63da2010-05-19 14:11:21 +1000401static inline int do_one_ahash_op(struct ahash_request *req, int ret)
402{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100403 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000404
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100405 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000406}
407
Herbert Xu72259de2016-06-28 20:33:52 +0800408struct test_mb_ahash_data {
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000409 struct scatterlist sg[XBUFSIZE];
Herbert Xu72259de2016-06-28 20:33:52 +0800410 char result[64];
411 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100412 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800413 char *xbuf[XBUFSIZE];
414};
Megha Dey087bcd22016-06-23 18:40:47 -0700415
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000416static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb)
417{
418 int i, rc[num_mb], err = 0;
419
420 /* Fire up a bunch of concurrent requests */
421 for (i = 0; i < num_mb; i++)
422 rc[i] = crypto_ahash_digest(data[i].req);
423
424 /* Wait for all requests to finish */
425 for (i = 0; i < num_mb; i++) {
426 rc[i] = crypto_wait_req(rc[i], &data[i].wait);
427
428 if (rc[i]) {
429 pr_info("concurrent request %d error %d\n", i, rc[i]);
430 err = rc[i];
431 }
432 }
433
434 return err;
435}
436
437static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen,
438 int secs, u32 num_mb)
439{
440 unsigned long start, end;
441 int bcount;
442 int ret;
443
444 for (start = jiffies, end = start + secs * HZ, bcount = 0;
445 time_before(jiffies, end); bcount++) {
446 ret = do_mult_ahash_op(data, num_mb);
447 if (ret)
448 return ret;
449 }
450
451 pr_cont("%d operations in %d seconds (%ld bytes)\n",
452 bcount * num_mb, secs, (long)bcount * blen * num_mb);
453 return 0;
454}
455
456static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen,
457 u32 num_mb)
458{
459 unsigned long cycles = 0;
460 int ret = 0;
461 int i;
462
463 /* Warm-up run. */
464 for (i = 0; i < 4; i++) {
465 ret = do_mult_ahash_op(data, num_mb);
466 if (ret)
467 goto out;
468 }
469
470 /* The real thing. */
471 for (i = 0; i < 8; i++) {
472 cycles_t start, end;
473
474 start = get_cycles();
475 ret = do_mult_ahash_op(data, num_mb);
476 end = get_cycles();
477
478 if (ret)
479 goto out;
480
481 cycles += end - start;
482 }
483
484out:
485 if (ret == 0)
486 pr_cont("1 operation in %lu cycles (%d bytes)\n",
487 (cycles + 4) / (8 * num_mb), blen);
488
489 return ret;
490}
491
492static void test_mb_ahash_speed(const char *algo, unsigned int secs,
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000493 struct hash_speed *speed, u32 num_mb)
Megha Dey087bcd22016-06-23 18:40:47 -0700494{
Herbert Xu72259de2016-06-28 20:33:52 +0800495 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700496 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800497 unsigned int i, j, k;
498 int ret;
499
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000500 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL);
Herbert Xu72259de2016-06-28 20:33:52 +0800501 if (!data)
502 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700503
504 tfm = crypto_alloc_ahash(algo, 0, 0);
505 if (IS_ERR(tfm)) {
506 pr_err("failed to load transform for %s: %ld\n",
507 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800508 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700509 }
Herbert Xu72259de2016-06-28 20:33:52 +0800510
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000511 for (i = 0; i < num_mb; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800512 if (testmgr_alloc_buf(data[i].xbuf))
513 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700514
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100515 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700516
Herbert Xu72259de2016-06-28 20:33:52 +0800517 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
518 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200519 pr_err("alg: hash: Failed to allocate request for %s\n",
520 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800521 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700522 }
Megha Dey087bcd22016-06-23 18:40:47 -0700523
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100524 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
525 &data[i].wait);
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000526
527 sg_init_table(data[i].sg, XBUFSIZE);
528 for (j = 0; j < XBUFSIZE; j++) {
529 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE);
530 memset(data[i].xbuf[j], 0xff, PAGE_SIZE);
531 }
Megha Dey087bcd22016-06-23 18:40:47 -0700532 }
533
Herbert Xu72259de2016-06-28 20:33:52 +0800534 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
535 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700536
537 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800538 /* For some reason this only tests digests. */
539 if (speed[i].blen != speed[i].plen)
540 continue;
541
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000542 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200543 pr_err("template (%u) too big for tvmem (%lu)\n",
Gilad Ben-Yossef7c3f1322017-12-17 08:29:00 +0000544 speed[i].blen, XBUFSIZE * PAGE_SIZE);
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200545 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700546 }
547
548 if (speed[i].klen)
549 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
550
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000551 for (k = 0; k < num_mb; k++)
Herbert Xu72259de2016-06-28 20:33:52 +0800552 ahash_request_set_crypt(data[k].req, data[k].sg,
553 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700554
Herbert Xu72259de2016-06-28 20:33:52 +0800555 pr_info("test%3u "
556 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700557 i, speed[i].blen, speed[i].plen,
558 speed[i].blen / speed[i].plen);
559
Gilad Ben-Yossefb34a0f672017-12-17 08:29:03 +0000560 if (secs)
561 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs,
562 num_mb);
563 else
564 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb);
Herbert Xu72259de2016-06-28 20:33:52 +0800565
Herbert Xu72259de2016-06-28 20:33:52 +0800566
567 if (ret) {
568 pr_err("At least one hashing failed ret=%d\n", ret);
569 break;
570 }
Megha Dey087bcd22016-06-23 18:40:47 -0700571 }
Megha Dey087bcd22016-06-23 18:40:47 -0700572
573out:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000574 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800575 ahash_request_free(data[k].req);
576
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +0000577 for (k = 0; k < num_mb; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800578 testmgr_free_buf(data[k].xbuf);
579
580 crypto_free_ahash(tfm);
581
582free_data:
583 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700584}
585
David S. Millerbeb63da2010-05-19 14:11:21 +1000586static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700587 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000588{
589 unsigned long start, end;
590 int bcount;
591 int ret;
592
Mark Rustad3e3dc252014-07-25 02:53:38 -0700593 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000594 time_before(jiffies, end); bcount++) {
595 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
596 if (ret)
597 return ret;
598 }
599
600 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700601 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000602
603 return 0;
604}
605
606static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700607 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000608{
609 unsigned long start, end;
610 int bcount, pcount;
611 int ret;
612
613 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700614 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000615
Mark Rustad3e3dc252014-07-25 02:53:38 -0700616 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000617 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800618 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000619 if (ret)
620 return ret;
621 for (pcount = 0; pcount < blen; pcount += plen) {
622 ret = do_one_ahash_op(req, crypto_ahash_update(req));
623 if (ret)
624 return ret;
625 }
626 /* we assume there is enough space in 'out' for the result */
627 ret = do_one_ahash_op(req, crypto_ahash_final(req));
628 if (ret)
629 return ret;
630 }
631
632 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700633 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000634
635 return 0;
636}
637
638static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
639 char *out)
640{
641 unsigned long cycles = 0;
642 int ret, i;
643
644 /* Warm-up run. */
645 for (i = 0; i < 4; i++) {
646 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
647 if (ret)
648 goto out;
649 }
650
651 /* The real thing. */
652 for (i = 0; i < 8; i++) {
653 cycles_t start, end;
654
655 start = get_cycles();
656
657 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
658 if (ret)
659 goto out;
660
661 end = get_cycles();
662
663 cycles += end - start;
664 }
665
666out:
667 if (ret)
668 return ret;
669
670 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
671 cycles / 8, cycles / (8 * blen));
672
673 return 0;
674}
675
676static int test_ahash_cycles(struct ahash_request *req, int blen,
677 int plen, char *out)
678{
679 unsigned long cycles = 0;
680 int i, pcount, ret;
681
682 if (plen == blen)
683 return test_ahash_cycles_digest(req, blen, out);
684
685 /* Warm-up run. */
686 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800687 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000688 if (ret)
689 goto out;
690 for (pcount = 0; pcount < blen; pcount += plen) {
691 ret = do_one_ahash_op(req, crypto_ahash_update(req));
692 if (ret)
693 goto out;
694 }
695 ret = do_one_ahash_op(req, crypto_ahash_final(req));
696 if (ret)
697 goto out;
698 }
699
700 /* The real thing. */
701 for (i = 0; i < 8; i++) {
702 cycles_t start, end;
703
704 start = get_cycles();
705
Herbert Xu43a96072015-04-22 11:02:27 +0800706 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000707 if (ret)
708 goto out;
709 for (pcount = 0; pcount < blen; pcount += plen) {
710 ret = do_one_ahash_op(req, crypto_ahash_update(req));
711 if (ret)
712 goto out;
713 }
714 ret = do_one_ahash_op(req, crypto_ahash_final(req));
715 if (ret)
716 goto out;
717
718 end = get_cycles();
719
720 cycles += end - start;
721 }
722
723out:
724 if (ret)
725 return ret;
726
727 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
728 cycles / 8, cycles / (8 * blen));
729
730 return 0;
731}
732
Herbert Xu06605112016-02-01 21:36:49 +0800733static void test_ahash_speed_common(const char *algo, unsigned int secs,
734 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +1000735{
736 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100737 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +1000738 struct ahash_request *req;
739 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +0300740 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +1000741 int i, ret;
742
Herbert Xu06605112016-02-01 21:36:49 +0800743 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +1000744 if (IS_ERR(tfm)) {
745 pr_err("failed to load transform for %s: %ld\n",
746 algo, PTR_ERR(tfm));
747 return;
748 }
749
Luca Clementi263a8df2014-06-25 22:57:42 -0700750 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
751 get_driver_name(crypto_ahash, tfm));
752
Horia Geant?f074f7b2015-08-27 18:38:36 +0300753 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
754 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
755 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +1000756 goto out;
757 }
758
759 test_hash_sg_init(sg);
760 req = ahash_request_alloc(tfm, GFP_KERNEL);
761 if (!req) {
762 pr_err("ahash request allocation failure\n");
763 goto out;
764 }
765
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100766 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000767 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100768 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000769
Horia Geant?f074f7b2015-08-27 18:38:36 +0300770 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
771 if (!output)
772 goto out_nomem;
773
David S. Millerbeb63da2010-05-19 14:11:21 +1000774 for (i = 0; speed[i].blen != 0; i++) {
775 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
776 pr_err("template (%u) too big for tvmem (%lu)\n",
777 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
778 break;
779 }
780
781 pr_info("test%3u "
782 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
783 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
784
785 ahash_request_set_crypt(req, sg, output, speed[i].plen);
786
Mark Rustad3e3dc252014-07-25 02:53:38 -0700787 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000788 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700789 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000790 else
791 ret = test_ahash_cycles(req, speed[i].blen,
792 speed[i].plen, output);
793
794 if (ret) {
795 pr_err("hashing failed ret=%d\n", ret);
796 break;
797 }
798 }
799
Horia Geant?f074f7b2015-08-27 18:38:36 +0300800 kfree(output);
801
802out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +1000803 ahash_request_free(req);
804
805out:
806 crypto_free_ahash(tfm);
807}
808
Herbert Xu06605112016-02-01 21:36:49 +0800809static void test_ahash_speed(const char *algo, unsigned int secs,
810 struct hash_speed *speed)
811{
812 return test_ahash_speed_common(algo, secs, speed, 0);
813}
814
815static void test_hash_speed(const char *algo, unsigned int secs,
816 struct hash_speed *speed)
817{
818 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
819}
820
Herbert Xu7166e582016-06-29 18:03:50 +0800821static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300822{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100823 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300824
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100825 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300826}
827
Herbert Xu7166e582016-06-29 18:03:50 +0800828static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700829 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300830{
831 unsigned long start, end;
832 int bcount;
833 int ret;
834
Mark Rustad3e3dc252014-07-25 02:53:38 -0700835 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300836 time_before(jiffies, end); bcount++) {
837 if (enc)
838 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800839 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300840 else
841 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800842 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300843
844 if (ret)
845 return ret;
846 }
847
848 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700849 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300850 return 0;
851}
852
Herbert Xu7166e582016-06-29 18:03:50 +0800853static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300854 int blen)
855{
856 unsigned long cycles = 0;
857 int ret = 0;
858 int i;
859
860 /* Warm-up run. */
861 for (i = 0; i < 4; i++) {
862 if (enc)
863 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800864 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300865 else
866 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800867 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300868
869 if (ret)
870 goto out;
871 }
872
873 /* The real thing. */
874 for (i = 0; i < 8; i++) {
875 cycles_t start, end;
876
877 start = get_cycles();
878 if (enc)
879 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800880 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300881 else
882 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800883 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300884 end = get_cycles();
885
886 if (ret)
887 goto out;
888
889 cycles += end - start;
890 }
891
892out:
893 if (ret == 0)
894 pr_cont("1 operation in %lu cycles (%d bytes)\n",
895 (cycles + 4) / 8, blen);
896
897 return ret;
898}
899
Herbert Xu7166e582016-06-29 18:03:50 +0800900static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
901 struct cipher_speed_template *template,
902 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300903{
Nicolas Royerde1975332012-07-01 19:19:47 +0200904 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100905 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300906 const char *key;
907 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +0800908 struct skcipher_request *req;
909 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300910 const char *e;
911 u32 *b_size;
912
913 if (enc == ENCRYPT)
914 e = "encryption";
915 else
916 e = "decryption";
917
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100918 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300919
Herbert Xu7166e582016-06-29 18:03:50 +0800920 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300921
922 if (IS_ERR(tfm)) {
923 pr_err("failed to load transform for %s: %ld\n", algo,
924 PTR_ERR(tfm));
925 return;
926 }
927
Luca Clementi263a8df2014-06-25 22:57:42 -0700928 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
Herbert Xu7166e582016-06-29 18:03:50 +0800929 get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -0700930
Herbert Xu7166e582016-06-29 18:03:50 +0800931 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300932 if (!req) {
933 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
934 algo);
935 goto out;
936 }
937
Herbert Xu7166e582016-06-29 18:03:50 +0800938 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100939 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300940
941 i = 0;
942 do {
943 b_size = block_sizes;
944
945 do {
946 struct scatterlist sg[TVMEMSIZE];
947
948 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
949 pr_err("template (%u) too big for "
950 "tvmem (%lu)\n", *keysize + *b_size,
951 TVMEMSIZE * PAGE_SIZE);
952 goto out_free_req;
953 }
954
955 pr_info("test %u (%d bit key, %d byte blocks): ", i,
956 *keysize * 8, *b_size);
957
958 memset(tvmem[0], 0xff, PAGE_SIZE);
959
960 /* set key, plain text and IV */
961 key = tvmem[0];
962 for (j = 0; j < tcount; j++) {
963 if (template[j].klen == *keysize) {
964 key = template[j].key;
965 break;
966 }
967 }
968
Herbert Xu7166e582016-06-29 18:03:50 +0800969 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300970
Herbert Xu7166e582016-06-29 18:03:50 +0800971 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300972 if (ret) {
973 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +0800974 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300975 goto out_free_req;
976 }
977
Nicolas Royerde1975332012-07-01 19:19:47 +0200978 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +0200979 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
980
Nicolas Royerde1975332012-07-01 19:19:47 +0200981 if (k > PAGE_SIZE) {
982 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300983 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +0200984 k -= PAGE_SIZE;
985 j = 1;
986 while (k > PAGE_SIZE) {
987 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
988 memset(tvmem[j], 0xff, PAGE_SIZE);
989 j++;
990 k -= PAGE_SIZE;
991 }
992 sg_set_buf(sg + j, tvmem[j], k);
993 memset(tvmem[j], 0xff, k);
994 } else {
995 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300996 }
997
Herbert Xu7166e582016-06-29 18:03:50 +0800998 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300999 if (iv_len)
1000 memset(&iv, 0xff, iv_len);
1001
Herbert Xu7166e582016-06-29 18:03:50 +08001002 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001003
Mark Rustad3e3dc252014-07-25 02:53:38 -07001004 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001005 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -07001006 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001007 else
1008 ret = test_acipher_cycles(req, enc,
1009 *b_size);
1010
1011 if (ret) {
1012 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +08001013 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001014 break;
1015 }
1016 b_size++;
1017 i++;
1018 } while (*b_size);
1019 keysize++;
1020 } while (*keysize);
1021
1022out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +08001023 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001024out:
Herbert Xu7166e582016-06-29 18:03:50 +08001025 crypto_free_skcipher(tfm);
1026}
1027
1028static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
1029 struct cipher_speed_template *template,
1030 unsigned int tcount, u8 *keysize)
1031{
1032 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1033 true);
1034}
1035
1036static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
1037 struct cipher_speed_template *template,
1038 unsigned int tcount, u8 *keysize)
1039{
1040 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
1041 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001042}
1043
Herbert Xuef2736f2005-06-22 13:26:03 -07001044static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045{
1046 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -07001047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 while (*name) {
1049 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +10001050 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +10001051 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -07001053 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054}
1055
Herbert Xu01b32322008-07-31 15:41:55 +08001056static inline int tcrypt_test(const char *alg)
1057{
Jarod Wilson4e033a62009-05-27 15:10:21 +10001058 int ret;
1059
Rabin Vincent76512f22017-01-18 14:54:05 +01001060 pr_debug("testing %s\n", alg);
1061
Jarod Wilson4e033a62009-05-27 15:10:21 +10001062 ret = alg_test(alg, alg, 0, 0);
1063 /* non-fips algs return -EINVAL in fips mode */
1064 if (fips_enabled && ret == -EINVAL)
1065 ret = 0;
1066 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +08001067}
1068
Herbert Xu86068132014-12-04 16:43:29 +08001069static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +08001070{
1071 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +10001072 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +08001073
1074 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 case 0:
Herbert Xu86068132014-12-04 16:43:29 +08001076 if (alg) {
1077 if (!crypto_has_alg(alg, type,
1078 mask ?: CRYPTO_ALG_TYPE_MASK))
1079 ret = -ENOENT;
1080 break;
1081 }
1082
Herbert Xu01b32322008-07-31 15:41:55 +08001083 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001084 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 break;
1086
1087 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001088 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 break;
1090
1091 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001092 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 break;
1094
1095 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001096 ret += tcrypt_test("ecb(des)");
1097 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001098 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 break;
1100
1101 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001102 ret += tcrypt_test("ecb(des3_ede)");
1103 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001104 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 break;
1106
1107 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001108 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001110
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001112 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001116 ret += tcrypt_test("ecb(blowfish)");
1117 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001118 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 break;
1120
1121 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001122 ret += tcrypt_test("ecb(twofish)");
1123 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001124 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001125 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001126 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001130 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001131 ret += tcrypt_test("cbc(serpent)");
1132 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001133 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001134 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 break;
1136
1137 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001138 ret += tcrypt_test("ecb(aes)");
1139 ret += tcrypt_test("cbc(aes)");
1140 ret += tcrypt_test("lrw(aes)");
1141 ret += tcrypt_test("xts(aes)");
1142 ret += tcrypt_test("ctr(aes)");
1143 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 break;
1145
1146 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001147 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001151 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 break;
1153
1154 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001155 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 break;
1157
1158 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001159 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001160 ret += tcrypt_test("cbc(cast5)");
1161 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 break;
1163
1164 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001165 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001166 ret += tcrypt_test("cbc(cast6)");
1167 ret += tcrypt_test("ctr(cast6)");
1168 ret += tcrypt_test("lrw(cast6)");
1169 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 break;
1171
1172 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001173 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 break;
1175
1176 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001177 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
1180 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001181 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183
1184 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001185 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 break;
1187
1188 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001189 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 break;
1191
1192 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001193 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 break;
1195
1196 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001197 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 break;
1199
1200 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001201 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 break;
1203
1204 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001205 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 break;
1207
1208 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001209 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 break;
1211
1212 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001213 ret += tcrypt_test("ecb(anubis)");
1214 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 break;
1216
1217 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001218 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 break;
1220
1221 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001222 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 break;
1224
1225 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001226 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001228
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001229 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001230 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001231 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
David Howells90831632006-12-16 12:13:14 +11001233 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001234 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001235 break;
1236
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001237 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001238 ret += tcrypt_test("ecb(camellia)");
1239 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001240 ret += tcrypt_test("ctr(camellia)");
1241 ret += tcrypt_test("lrw(camellia)");
1242 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001243 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001244
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001245 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001246 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001247 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001248
Tan Swee Heng2407d602007-11-23 19:45:00 +08001249 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001250 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001251 break;
1252
Herbert Xu8df213d2007-12-02 14:55:47 +11001253 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001254 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001255 break;
1256
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001257 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001258 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001259 break;
1260
Joy Latten93cc74e2007-12-12 20:24:22 +08001261 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001262 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001263 break;
1264
Kevin Coffman76cb9522008-03-24 21:26:16 +08001265 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001266 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001267 break;
1268
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001269 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001270 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001271 break;
1272
1273 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001274 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001275 break;
1276
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001277 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001278 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001279 break;
1280
1281 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001282 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001283 break;
1284
1285 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001286 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001287 break;
1288
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001289 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001290 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001291 break;
1292
Jarod Wilson5d667322009-05-04 19:23:40 +08001293 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001294 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001295 break;
1296
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001297 case 46:
1298 ret += tcrypt_test("ghash");
1299 break;
1300
Herbert Xu684115212013-09-07 12:56:26 +10001301 case 47:
1302 ret += tcrypt_test("crct10dif");
1303 break;
1304
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301305 case 48:
1306 ret += tcrypt_test("sha3-224");
1307 break;
1308
1309 case 49:
1310 ret += tcrypt_test("sha3-256");
1311 break;
1312
1313 case 50:
1314 ret += tcrypt_test("sha3-384");
1315 break;
1316
1317 case 51:
1318 ret += tcrypt_test("sha3-512");
1319 break;
1320
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001321 case 52:
1322 ret += tcrypt_test("sm3");
1323 break;
1324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001326 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001330 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001332
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001334 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 break;
1336
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001337 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001338 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001339 break;
1340
1341 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001342 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001343 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001344
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001345 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001346 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001347 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001349 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001350 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001351 break;
1352
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001353 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001354 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001355 break;
1356
1357 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001358 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001359 break;
1360
Shane Wangf1939f72009-09-02 20:05:22 +10001361 case 109:
1362 ret += tcrypt_test("vmac(aes)");
1363 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001364
Sonic Zhanga482b082012-05-25 17:54:13 +08001365 case 110:
1366 ret += tcrypt_test("hmac(crc32)");
1367 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001368
raveendra padasalagi98eca722016-07-01 11:16:54 +05301369 case 111:
1370 ret += tcrypt_test("hmac(sha3-224)");
1371 break;
1372
1373 case 112:
1374 ret += tcrypt_test("hmac(sha3-256)");
1375 break;
1376
1377 case 113:
1378 ret += tcrypt_test("hmac(sha3-384)");
1379 break;
1380
1381 case 114:
1382 ret += tcrypt_test("hmac(sha3-512)");
1383 break;
1384
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001385 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001386 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001387 break;
1388
Adrian Hoban69435b92010-11-04 15:02:04 -04001389 case 151:
1390 ret += tcrypt_test("rfc4106(gcm(aes))");
1391 break;
1392
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001393 case 152:
1394 ret += tcrypt_test("rfc4543(gcm(aes))");
1395 break;
1396
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001397 case 153:
1398 ret += tcrypt_test("cmac(aes)");
1399 break;
1400
1401 case 154:
1402 ret += tcrypt_test("cmac(des3_ede)");
1403 break;
1404
Horia Geantabbf9c892013-11-28 15:11:16 +02001405 case 155:
1406 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1407 break;
1408
Horia Geantabca4feb2014-03-14 17:46:51 +02001409 case 156:
1410 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1411 break;
1412
1413 case 157:
1414 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1415 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301416 case 181:
1417 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1418 break;
1419 case 182:
1420 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1421 break;
1422 case 183:
1423 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1424 break;
1425 case 184:
1426 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1427 break;
1428 case 185:
1429 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1430 break;
1431 case 186:
1432 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1433 break;
1434 case 187:
1435 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1436 break;
1437 case 188:
1438 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1439 break;
1440 case 189:
1441 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1442 break;
1443 case 190:
1444 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1445 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001446 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001447 test_cipher_speed("ecb(aes)", 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("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001450 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001451 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001452 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001453 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001454 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001455 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001456 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001457 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001458 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001459 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001460 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001461 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001462 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001463 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1464 speed_template_16_24_32);
1465 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1466 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10001467 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1468 speed_template_16_24_32);
1469 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1470 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001471 break;
1472
1473 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001474 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001475 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001476 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001477 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001478 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001479 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001480 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001481 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001482 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001483 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001484 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001485 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001486 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1487 des3_speed_template, DES3_SPEED_VECTORS,
1488 speed_template_24);
1489 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1490 des3_speed_template, DES3_SPEED_VECTORS,
1491 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001492 break;
1493
1494 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001495 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001496 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001497 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001498 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001499 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001500 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001501 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001502 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001503 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1504 speed_template_16_24_32);
1505 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1506 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001507 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1508 speed_template_32_40_48);
1509 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1510 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001511 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1512 speed_template_32_48_64);
1513 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1514 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001515 break;
1516
1517 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001518 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001519 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001520 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001521 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001522 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001523 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001524 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001525 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001526 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1527 speed_template_8_32);
1528 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1529 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001530 break;
1531
1532 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001533 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001534 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001535 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001536 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001537 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001538 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001539 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001540 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001541 break;
1542
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001543 case 205:
1544 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001545 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001546 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001547 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001548 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001549 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001550 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001551 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001552 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1553 speed_template_16_24_32);
1554 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1555 speed_template_16_24_32);
1556 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1557 speed_template_32_40_48);
1558 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1559 speed_template_32_40_48);
1560 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1561 speed_template_32_48_64);
1562 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1563 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001564 break;
1565
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001566 case 206:
1567 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001568 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001569 break;
1570
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001571 case 207:
1572 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1573 speed_template_16_32);
1574 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1575 speed_template_16_32);
1576 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1577 speed_template_16_32);
1578 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1579 speed_template_16_32);
1580 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1581 speed_template_16_32);
1582 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1583 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001584 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1585 speed_template_32_48);
1586 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1587 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001588 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1589 speed_template_32_64);
1590 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1591 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001592 break;
1593
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001594 case 208:
1595 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1596 speed_template_8);
1597 break;
1598
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001599 case 209:
1600 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1601 speed_template_8_16);
1602 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1603 speed_template_8_16);
1604 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1605 speed_template_8_16);
1606 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1607 speed_template_8_16);
1608 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1609 speed_template_8_16);
1610 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1611 speed_template_8_16);
1612 break;
1613
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001614 case 210:
1615 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1616 speed_template_16_32);
1617 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1618 speed_template_16_32);
1619 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1620 speed_template_16_32);
1621 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1622 speed_template_16_32);
1623 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1624 speed_template_16_32);
1625 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1626 speed_template_16_32);
1627 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1628 speed_template_32_48);
1629 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1630 speed_template_32_48);
1631 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1632 speed_template_32_64);
1633 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1634 speed_template_32_64);
1635 break;
1636
Tim Chen53f52d72013-12-11 14:28:47 -08001637 case 211:
1638 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001639 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05301640 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01001641 NULL, 0, 16, 8, speed_template_16_24_32);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001642 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec,
1643 NULL, 0, 16, 16, aead_speed_template_20);
1644 test_aead_speed("gcm(aes)", DECRYPT, sec,
1645 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08001646 break;
1647
Herbert Xu4e4aab62015-06-17 14:04:21 +08001648 case 212:
1649 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001650 NULL, 0, 16, 16, aead_speed_template_19);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001651 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec,
1652 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08001653 break;
1654
Martin Willi2dce0632015-07-16 19:13:59 +02001655 case 213:
1656 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1657 NULL, 0, 16, 8, aead_speed_template_36);
Gilad Ben-Yossef4431bd42017-12-17 08:29:01 +00001658 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec,
1659 NULL, 0, 16, 8, aead_speed_template_36);
Martin Willi2dce0632015-07-16 19:13:59 +02001660 break;
1661
1662 case 214:
1663 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1664 speed_template_32);
1665 break;
1666
Michal Ludvige8057922006-05-30 22:04:19 +10001667 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001668 if (alg) {
1669 test_hash_speed(alg, sec, generic_hash_speed_template);
1670 break;
1671 }
Michal Ludvige8057922006-05-30 22:04:19 +10001672 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001673 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001674 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001675 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001676 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001677 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001678 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001679 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001680 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001681 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001682 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001683 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001684 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001685 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001686 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001687 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001688 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001689 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001690 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001691 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001692 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001693 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001694 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001695 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001696 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001697 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001698 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001699 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001700 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001701 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001702 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001703 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001704 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001705 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001706 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001707 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001708 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001709 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001710 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001711 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001712 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001713 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001714 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001715 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001716 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001717 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001718 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001719 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001720 /* fall through */
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001721 case 313:
1722 test_hash_speed("sha224", sec, generic_hash_speed_template);
1723 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001724 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001725 case 314:
1726 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1727 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001728 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001729 case 315:
1730 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1731 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001732 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001733 case 316:
1734 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1735 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001736 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001737 case 317:
1738 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1739 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001740 /* fall through */
Huang Ying18bcc912010-03-10 18:30:32 +08001741 case 318:
1742 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1743 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001744 /* fall through */
Tim Chene3899e42012-09-27 15:44:24 -07001745 case 319:
1746 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1747 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001748 /* fall through */
Herbert Xu684115212013-09-07 12:56:26 +10001749 case 320:
1750 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1751 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001752 /* fall through */
Martin Willi2dce0632015-07-16 19:13:59 +02001753 case 321:
1754 test_hash_speed("poly1305", sec, poly1305_speed_template);
1755 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001756 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301757 case 322:
1758 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
1759 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001760 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301761 case 323:
1762 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
1763 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001764 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301765 case 324:
1766 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
1767 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001768 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301769 case 325:
1770 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
1771 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001772 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001773 case 326:
1774 test_hash_speed("sm3", sec, generic_hash_speed_template);
1775 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001776 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001777 case 399:
1778 break;
1779
David S. Millerbeb63da2010-05-19 14:11:21 +10001780 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08001781 if (alg) {
1782 test_ahash_speed(alg, sec, generic_hash_speed_template);
1783 break;
1784 }
David S. Millerbeb63da2010-05-19 14:11:21 +10001785 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001786 case 401:
1787 test_ahash_speed("md4", 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 402:
1791 test_ahash_speed("md5", 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 403:
1795 test_ahash_speed("sha1", 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 404:
1799 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1800 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001801 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001802 case 405:
1803 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1804 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001805 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001806 case 406:
1807 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1808 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001809 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001810 case 407:
1811 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1812 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001813 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001814 case 408:
1815 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1816 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001817 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001818 case 409:
1819 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1820 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001821 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001822 case 410:
1823 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1824 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001825 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001826 case 411:
1827 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1828 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001829 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001830 case 412:
1831 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1832 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001833 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001834 case 413:
1835 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1836 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 414:
1839 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1840 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001841 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001842 case 415:
1843 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1844 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001845 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001846 case 416:
1847 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1848 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001849 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001850 case 417:
1851 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1852 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001853 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301854 case 418:
1855 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
1856 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001857 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301858 case 419:
1859 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
1860 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001861 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301862 case 420:
1863 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
1864 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001865 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301866 case 421:
1867 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
1868 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001869 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001870 case 422:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001871 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template,
1872 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07001873 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001874 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001875 case 423:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001876 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template,
1877 num_mb);
Megha Dey087bcd22016-06-23 18:40:47 -07001878 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001879 /* fall through */
Megha Dey14009c42016-06-27 10:20:09 -07001880 case 424:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001881 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template,
1882 num_mb);
Megha Dey14009c42016-06-27 10:20:09 -07001883 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001884 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001885 case 425:
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00001886 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template,
1887 num_mb);
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001888 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001889 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001890 case 499:
1891 break;
1892
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001893 case 500:
1894 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1895 speed_template_16_24_32);
1896 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1897 speed_template_16_24_32);
1898 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1899 speed_template_16_24_32);
1900 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1901 speed_template_16_24_32);
1902 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1903 speed_template_32_40_48);
1904 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1905 speed_template_32_40_48);
1906 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001907 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001908 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001909 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001910 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1911 speed_template_16_24_32);
1912 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1913 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001914 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1915 speed_template_16_24_32);
1916 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1917 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02001918 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1919 speed_template_16_24_32);
1920 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1921 speed_template_16_24_32);
1922 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1923 speed_template_16_24_32);
1924 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1925 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02001926 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1927 speed_template_20_28_36);
1928 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1929 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001930 break;
1931
1932 case 501:
1933 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1934 des3_speed_template, DES3_SPEED_VECTORS,
1935 speed_template_24);
1936 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1937 des3_speed_template, DES3_SPEED_VECTORS,
1938 speed_template_24);
1939 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1940 des3_speed_template, DES3_SPEED_VECTORS,
1941 speed_template_24);
1942 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1943 des3_speed_template, DES3_SPEED_VECTORS,
1944 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02001945 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1946 des3_speed_template, DES3_SPEED_VECTORS,
1947 speed_template_24);
1948 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1949 des3_speed_template, DES3_SPEED_VECTORS,
1950 speed_template_24);
1951 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1952 des3_speed_template, DES3_SPEED_VECTORS,
1953 speed_template_24);
1954 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1955 des3_speed_template, DES3_SPEED_VECTORS,
1956 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001957 break;
1958
1959 case 502:
1960 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1961 speed_template_8);
1962 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1963 speed_template_8);
1964 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1965 speed_template_8);
1966 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1967 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02001968 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1969 speed_template_8);
1970 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1971 speed_template_8);
1972 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1973 speed_template_8);
1974 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1975 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001976 break;
1977
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001978 case 503:
1979 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1980 speed_template_16_32);
1981 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1982 speed_template_16_32);
1983 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1984 speed_template_16_32);
1985 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1986 speed_template_16_32);
1987 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1988 speed_template_16_32);
1989 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1990 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001991 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1992 speed_template_32_48);
1993 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1994 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001995 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1996 speed_template_32_64);
1997 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1998 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001999 break;
2000
Johannes Goetzfried107778b52012-05-28 15:54:24 +02002001 case 504:
2002 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
2003 speed_template_16_24_32);
2004 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
2005 speed_template_16_24_32);
2006 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
2007 speed_template_16_24_32);
2008 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
2009 speed_template_16_24_32);
2010 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
2011 speed_template_16_24_32);
2012 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
2013 speed_template_16_24_32);
2014 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
2015 speed_template_32_40_48);
2016 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
2017 speed_template_32_40_48);
2018 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
2019 speed_template_32_48_64);
2020 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
2021 speed_template_32_48_64);
2022 break;
2023
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08002024 case 505:
2025 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
2026 speed_template_8);
2027 break;
2028
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02002029 case 506:
2030 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
2031 speed_template_8_16);
2032 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
2033 speed_template_8_16);
2034 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
2035 speed_template_8_16);
2036 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
2037 speed_template_8_16);
2038 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
2039 speed_template_8_16);
2040 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
2041 speed_template_8_16);
2042 break;
2043
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02002044 case 507:
2045 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
2046 speed_template_16_32);
2047 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
2048 speed_template_16_32);
2049 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
2050 speed_template_16_32);
2051 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
2052 speed_template_16_32);
2053 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
2054 speed_template_16_32);
2055 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
2056 speed_template_16_32);
2057 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
2058 speed_template_32_48);
2059 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
2060 speed_template_32_48);
2061 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
2062 speed_template_32_64);
2063 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
2064 speed_template_32_64);
2065 break;
2066
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03002067 case 508:
2068 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
2069 speed_template_16_32);
2070 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
2071 speed_template_16_32);
2072 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
2073 speed_template_16_32);
2074 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
2075 speed_template_16_32);
2076 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
2077 speed_template_16_32);
2078 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
2079 speed_template_16_32);
2080 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
2081 speed_template_32_48);
2082 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
2083 speed_template_32_48);
2084 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
2085 speed_template_32_64);
2086 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
2087 speed_template_32_64);
2088 break;
2089
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03002090 case 509:
2091 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
2092 speed_template_8_32);
2093 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2094 speed_template_8_32);
2095 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2096 speed_template_8_32);
2097 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2098 speed_template_8_32);
2099 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2100 speed_template_8_32);
2101 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2102 speed_template_8_32);
2103 break;
2104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 case 1000:
2106 test_available();
2107 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002109
2110 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002113static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002115 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002116 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002117
Herbert Xuf139cfa2008-07-31 12:23:53 +08002118 for (i = 0; i < TVMEMSIZE; i++) {
2119 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2120 if (!tvmem[i])
2121 goto err_free_tv;
2122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Herbert Xu86068132014-12-04 16:43:29 +08002124 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002125
Jarod Wilson4e033a62009-05-27 15:10:21 +10002126 if (err) {
2127 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2128 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01002129 } else {
2130 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10002131 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
Jarod Wilson4e033a62009-05-27 15:10:21 +10002133 /* We intentionaly return -EAGAIN to prevent keeping the module,
2134 * unless we're running in fips mode. It does all its work from
2135 * init() and doesn't offer any runtime functionality, but in
2136 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002137 * => we don't need it in the memory, do we?
2138 * -- mludvig
2139 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002140 if (!fips_enabled)
2141 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002142
Herbert Xuf139cfa2008-07-31 12:23:53 +08002143err_free_tv:
2144 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2145 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002146
2147 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148}
2149
2150/*
2151 * If an init function is provided, an exit function must also be provided
2152 * to allow module unload.
2153 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002154static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002156module_init(tcrypt_mod_init);
2157module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002159module_param(alg, charp, 0);
2160module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002161module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002163module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002164MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2165 "(defaults to zero which uses CPU cycles instead)");
Gilad Ben-Yossef8fcdc862017-12-17 08:29:02 +00002166module_param(num_mb, uint, 0000);
2167MODULE_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 -07002168
2169MODULE_LICENSE("GPL");
2170MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2171MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");