blob: 9267cbdb14d2458a66e36468755d9d7b0a27b7a4 [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;
Herbert Xuf139cfa2008-07-31 12:23:53 +080070static char *tvmem[TVMEMSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72static char *check[] = {
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +030073 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3",
Jonathan Lynchcd12fb902007-11-10 20:08:25 +080074 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes",
75 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
David Howells90831632006-12-16 12:13:14 +110076 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +080077 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +053078 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
79 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053082static inline int do_one_aead_op(struct aead_request *req, int ret)
83{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010084 struct crypto_wait *wait = req->base.data;
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053085
Gilad Ben-Yossef64671042017-10-18 08:00:48 +010086 return crypto_wait_req(ret, wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053087}
88
Tim Chen53f52d72013-12-11 14:28:47 -080089static int test_aead_jiffies(struct aead_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -070090 int blen, int secs)
Tim Chen53f52d72013-12-11 14:28:47 -080091{
92 unsigned long start, end;
93 int bcount;
94 int ret;
95
Mark Rustad3e3dc252014-07-25 02:53:38 -070096 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Tim Chen53f52d72013-12-11 14:28:47 -080097 time_before(jiffies, end); bcount++) {
98 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +053099 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800100 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530101 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800102
103 if (ret)
104 return ret;
105 }
106
107 printk("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700108 bcount, secs, (long)bcount * blen);
Tim Chen53f52d72013-12-11 14:28:47 -0800109 return 0;
110}
111
112static int test_aead_cycles(struct aead_request *req, int enc, int blen)
113{
114 unsigned long cycles = 0;
115 int ret = 0;
116 int i;
117
Tim Chen53f52d72013-12-11 14:28:47 -0800118 /* Warm-up run. */
119 for (i = 0; i < 4; i++) {
120 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530121 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800122 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530123 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800124
125 if (ret)
126 goto out;
127 }
128
129 /* The real thing. */
130 for (i = 0; i < 8; i++) {
131 cycles_t start, end;
132
133 start = get_cycles();
134 if (enc)
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530135 ret = do_one_aead_op(req, crypto_aead_encrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800136 else
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530137 ret = do_one_aead_op(req, crypto_aead_decrypt(req));
Tim Chen53f52d72013-12-11 14:28:47 -0800138 end = get_cycles();
139
140 if (ret)
141 goto out;
142
143 cycles += end - start;
144 }
145
146out:
Tim Chen53f52d72013-12-11 14:28:47 -0800147 if (ret == 0)
148 printk("1 operation in %lu cycles (%d bytes)\n",
149 (cycles + 4) / 8, blen);
150
151 return ret;
152}
153
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800154static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 };
Tim Chen53f52d72013-12-11 14:28:47 -0800155static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 };
156
157#define XBUFSIZE 8
158#define MAX_IVLEN 32
159
160static int testmgr_alloc_buf(char *buf[XBUFSIZE])
161{
162 int i;
163
164 for (i = 0; i < XBUFSIZE; i++) {
165 buf[i] = (void *)__get_free_page(GFP_KERNEL);
166 if (!buf[i])
167 goto err_free_buf;
168 }
169
170 return 0;
171
172err_free_buf:
173 while (i-- > 0)
174 free_page((unsigned long)buf[i]);
175
176 return -ENOMEM;
177}
178
179static void testmgr_free_buf(char *buf[XBUFSIZE])
180{
181 int i;
182
183 for (i = 0; i < XBUFSIZE; i++)
184 free_page((unsigned long)buf[i]);
185}
186
187static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],
188 unsigned int buflen)
189{
190 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE;
191 int k, rem;
192
Tim Chen53f52d72013-12-11 14:28:47 -0800193 if (np > XBUFSIZE) {
194 rem = PAGE_SIZE;
195 np = XBUFSIZE;
Cristian Stoicac4768992015-01-27 11:54:27 +0200196 } else {
197 rem = buflen % PAGE_SIZE;
Tim Chen53f52d72013-12-11 14:28:47 -0800198 }
Cristian Stoicac4768992015-01-27 11:54:27 +0200199
Herbert Xu31267272015-06-17 14:05:26 +0800200 sg_init_table(sg, np + 1);
Cristian Stoicac4768992015-01-27 11:54:27 +0200201 np--;
202 for (k = 0; k < np; k++)
Herbert Xu31267272015-06-17 14:05:26 +0800203 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE);
Cristian Stoicac4768992015-01-27 11:54:27 +0200204
Herbert Xu31267272015-06-17 14:05:26 +0800205 sg_set_buf(&sg[k + 1], xbuf[k], rem);
Tim Chen53f52d72013-12-11 14:28:47 -0800206}
207
Mark Rustad3e3dc252014-07-25 02:53:38 -0700208static void test_aead_speed(const char *algo, int enc, unsigned int secs,
Tim Chen53f52d72013-12-11 14:28:47 -0800209 struct aead_speed_template *template,
210 unsigned int tcount, u8 authsize,
211 unsigned int aad_size, u8 *keysize)
212{
213 unsigned int i, j;
214 struct crypto_aead *tfm;
215 int ret = -ENOMEM;
216 const char *key;
217 struct aead_request *req;
218 struct scatterlist *sg;
Tim Chen53f52d72013-12-11 14:28:47 -0800219 struct scatterlist *sgout;
220 const char *e;
221 void *assoc;
Cristian Stoica96692a732015-01-28 13:07:32 +0200222 char *iv;
Tim Chen53f52d72013-12-11 14:28:47 -0800223 char *xbuf[XBUFSIZE];
224 char *xoutbuf[XBUFSIZE];
225 char *axbuf[XBUFSIZE];
226 unsigned int *b_size;
227 unsigned int iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100228 struct crypto_wait wait;
Tim Chen53f52d72013-12-11 14:28:47 -0800229
Cristian Stoica96692a732015-01-28 13:07:32 +0200230 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
231 if (!iv)
232 return;
233
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200234 if (aad_size >= PAGE_SIZE) {
235 pr_err("associate data length (%u) too big\n", aad_size);
Cristian Stoica96692a732015-01-28 13:07:32 +0200236 goto out_noxbuf;
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200237 }
238
Tim Chen53f52d72013-12-11 14:28:47 -0800239 if (enc == ENCRYPT)
240 e = "encryption";
241 else
242 e = "decryption";
243
244 if (testmgr_alloc_buf(xbuf))
245 goto out_noxbuf;
246 if (testmgr_alloc_buf(axbuf))
247 goto out_noaxbuf;
248 if (testmgr_alloc_buf(xoutbuf))
249 goto out_nooutbuf;
250
Herbert Xua3f21852015-05-27 16:03:51 +0800251 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL);
Tim Chen53f52d72013-12-11 14:28:47 -0800252 if (!sg)
253 goto out_nosg;
Herbert Xua3f21852015-05-27 16:03:51 +0800254 sgout = &sg[9];
Tim Chen53f52d72013-12-11 14:28:47 -0800255
Herbert Xu5e4b8c12015-08-13 17:29:06 +0800256 tfm = crypto_alloc_aead(algo, 0, 0);
Tim Chen53f52d72013-12-11 14:28:47 -0800257
258 if (IS_ERR(tfm)) {
259 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo,
260 PTR_ERR(tfm));
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200261 goto out_notfm;
Tim Chen53f52d72013-12-11 14:28:47 -0800262 }
263
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100264 crypto_init_wait(&wait);
Luca Clementi263a8df2014-06-25 22:57:42 -0700265 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
266 get_driver_name(crypto_aead, tfm), e);
267
Tim Chen53f52d72013-12-11 14:28:47 -0800268 req = aead_request_alloc(tfm, GFP_KERNEL);
269 if (!req) {
270 pr_err("alg: aead: Failed to allocate request for %s\n",
271 algo);
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200272 goto out_noreq;
Tim Chen53f52d72013-12-11 14:28:47 -0800273 }
274
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530275 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100276 crypto_req_done, &wait);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +0530277
Tim Chen53f52d72013-12-11 14:28:47 -0800278 i = 0;
279 do {
280 b_size = aead_sizes;
281 do {
282 assoc = axbuf[0];
Christian Engelmayerac5f8632014-04-21 20:45:59 +0200283 memset(assoc, 0xff, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800284
285 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
286 pr_err("template (%u) too big for tvmem (%lu)\n",
287 *keysize + *b_size,
288 TVMEMSIZE * PAGE_SIZE);
289 goto out;
290 }
291
292 key = tvmem[0];
293 for (j = 0; j < tcount; j++) {
294 if (template[j].klen == *keysize) {
295 key = template[j].key;
296 break;
297 }
298 }
299 ret = crypto_aead_setkey(tfm, key, *keysize);
300 ret = crypto_aead_setauthsize(tfm, authsize);
301
302 iv_len = crypto_aead_ivsize(tfm);
303 if (iv_len)
Cristian Stoica96692a732015-01-28 13:07:32 +0200304 memset(iv, 0xff, iv_len);
Tim Chen53f52d72013-12-11 14:28:47 -0800305
306 crypto_aead_clear_flags(tfm, ~0);
307 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ",
308 i, *keysize * 8, *b_size);
309
310
311 memset(tvmem[0], 0xff, PAGE_SIZE);
312
313 if (ret) {
314 pr_err("setkey() failed flags=%x\n",
315 crypto_aead_get_flags(tfm));
316 goto out;
317 }
318
Herbert Xu31267272015-06-17 14:05:26 +0800319 sg_init_aead(sg, xbuf,
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300320 *b_size + (enc ? 0 : authsize));
Tim Chen53f52d72013-12-11 14:28:47 -0800321
Herbert Xu31267272015-06-17 14:05:26 +0800322 sg_init_aead(sgout, xoutbuf,
Tim Chen53f52d72013-12-11 14:28:47 -0800323 *b_size + (enc ? authsize : 0));
324
Herbert Xu31267272015-06-17 14:05:26 +0800325 sg_set_buf(&sg[0], assoc, aad_size);
326 sg_set_buf(&sgout[0], assoc, aad_size);
327
Robert Baronescu7aacbfc2017-10-10 13:22:00 +0300328 aead_request_set_crypt(req, sg, sgout,
329 *b_size + (enc ? 0 : authsize),
330 iv);
Herbert Xua3f21852015-05-27 16:03:51 +0800331 aead_request_set_ad(req, aad_size);
Tim Chen53f52d72013-12-11 14:28:47 -0800332
Mark Rustad3e3dc252014-07-25 02:53:38 -0700333 if (secs)
334 ret = test_aead_jiffies(req, enc, *b_size,
335 secs);
Tim Chen53f52d72013-12-11 14:28:47 -0800336 else
337 ret = test_aead_cycles(req, enc, *b_size);
338
339 if (ret) {
340 pr_err("%s() failed return code=%d\n", e, ret);
341 break;
342 }
343 b_size++;
344 i++;
345 } while (*b_size);
346 keysize++;
347 } while (*keysize);
348
349out:
Christian Engelmayer6af1f932014-04-21 20:47:05 +0200350 aead_request_free(req);
351out_noreq:
Tim Chen53f52d72013-12-11 14:28:47 -0800352 crypto_free_aead(tfm);
Christian Engelmayera2ea6ed2014-04-21 20:46:40 +0200353out_notfm:
Tim Chen53f52d72013-12-11 14:28:47 -0800354 kfree(sg);
355out_nosg:
356 testmgr_free_buf(xoutbuf);
357out_nooutbuf:
358 testmgr_free_buf(axbuf);
359out_noaxbuf:
360 testmgr_free_buf(xbuf);
361out_noxbuf:
Cristian Stoica96692a732015-01-28 13:07:32 +0200362 kfree(iv);
Tim Chen53f52d72013-12-11 14:28:47 -0800363}
Sebastian Siewiord5dc3922008-03-11 21:27:11 +0800364
David S. Millerbeb63da2010-05-19 14:11:21 +1000365static void test_hash_sg_init(struct scatterlist *sg)
366{
367 int i;
368
369 sg_init_table(sg, TVMEMSIZE);
370 for (i = 0; i < TVMEMSIZE; i++) {
371 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE);
372 memset(tvmem[i], 0xff, PAGE_SIZE);
373 }
374}
375
David S. Millerbeb63da2010-05-19 14:11:21 +1000376static inline int do_one_ahash_op(struct ahash_request *req, int ret)
377{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100378 struct crypto_wait *wait = req->base.data;
David S. Millerbeb63da2010-05-19 14:11:21 +1000379
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100380 return crypto_wait_req(ret, wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000381}
382
Herbert Xu72259de2016-06-28 20:33:52 +0800383struct test_mb_ahash_data {
384 struct scatterlist sg[TVMEMSIZE];
385 char result[64];
386 struct ahash_request *req;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100387 struct crypto_wait wait;
Herbert Xu72259de2016-06-28 20:33:52 +0800388 char *xbuf[XBUFSIZE];
389};
Megha Dey087bcd22016-06-23 18:40:47 -0700390
391static void test_mb_ahash_speed(const char *algo, unsigned int sec,
Herbert Xu72259de2016-06-28 20:33:52 +0800392 struct hash_speed *speed)
Megha Dey087bcd22016-06-23 18:40:47 -0700393{
Herbert Xu72259de2016-06-28 20:33:52 +0800394 struct test_mb_ahash_data *data;
Megha Dey087bcd22016-06-23 18:40:47 -0700395 struct crypto_ahash *tfm;
Herbert Xu72259de2016-06-28 20:33:52 +0800396 unsigned long start, end;
Herbert Xuf8de55b2016-06-28 16:41:38 +0800397 unsigned long cycles;
Herbert Xu72259de2016-06-28 20:33:52 +0800398 unsigned int i, j, k;
399 int ret;
400
401 data = kzalloc(sizeof(*data) * 8, GFP_KERNEL);
402 if (!data)
403 return;
Megha Dey087bcd22016-06-23 18:40:47 -0700404
405 tfm = crypto_alloc_ahash(algo, 0, 0);
406 if (IS_ERR(tfm)) {
407 pr_err("failed to load transform for %s: %ld\n",
408 algo, PTR_ERR(tfm));
Herbert Xu72259de2016-06-28 20:33:52 +0800409 goto free_data;
Megha Dey087bcd22016-06-23 18:40:47 -0700410 }
Herbert Xu72259de2016-06-28 20:33:52 +0800411
Megha Dey087bcd22016-06-23 18:40:47 -0700412 for (i = 0; i < 8; ++i) {
Herbert Xu72259de2016-06-28 20:33:52 +0800413 if (testmgr_alloc_buf(data[i].xbuf))
414 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700415
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100416 crypto_init_wait(&data[i].wait);
Megha Dey087bcd22016-06-23 18:40:47 -0700417
Herbert Xu72259de2016-06-28 20:33:52 +0800418 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
419 if (!data[i].req) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200420 pr_err("alg: hash: Failed to allocate request for %s\n",
421 algo);
Herbert Xu72259de2016-06-28 20:33:52 +0800422 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700423 }
Megha Dey087bcd22016-06-23 18:40:47 -0700424
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100425 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
426 &data[i].wait);
Herbert Xu72259de2016-06-28 20:33:52 +0800427 test_hash_sg_init(data[i].sg);
Megha Dey087bcd22016-06-23 18:40:47 -0700428 }
429
Herbert Xu72259de2016-06-28 20:33:52 +0800430 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo,
431 get_driver_name(crypto_ahash, tfm));
Megha Dey087bcd22016-06-23 18:40:47 -0700432
433 for (i = 0; speed[i].blen != 0; i++) {
Herbert Xu72259de2016-06-28 20:33:52 +0800434 /* For some reason this only tests digests. */
435 if (speed[i].blen != speed[i].plen)
436 continue;
437
Megha Dey087bcd22016-06-23 18:40:47 -0700438 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
Krzysztof Kozlowskif83f5b12016-06-28 09:23:06 +0200439 pr_err("template (%u) too big for tvmem (%lu)\n",
440 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
441 goto out;
Megha Dey087bcd22016-06-23 18:40:47 -0700442 }
443
444 if (speed[i].klen)
445 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen);
446
Herbert Xu72259de2016-06-28 20:33:52 +0800447 for (k = 0; k < 8; k++)
448 ahash_request_set_crypt(data[k].req, data[k].sg,
449 data[k].result, speed[i].blen);
Megha Dey087bcd22016-06-23 18:40:47 -0700450
Herbert Xu72259de2016-06-28 20:33:52 +0800451 pr_info("test%3u "
452 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
Megha Dey087bcd22016-06-23 18:40:47 -0700453 i, speed[i].blen, speed[i].plen,
454 speed[i].blen / speed[i].plen);
455
Herbert Xu72259de2016-06-28 20:33:52 +0800456 start = get_cycles();
457
458 for (k = 0; k < 8; k++) {
459 ret = crypto_ahash_digest(data[k].req);
Herbert Xud13cd112016-06-30 11:00:13 +0800460 if (ret == -EINPROGRESS) {
461 ret = 0;
Megha Dey087bcd22016-06-23 18:40:47 -0700462 continue;
Herbert Xud13cd112016-06-30 11:00:13 +0800463 }
Megha Dey087bcd22016-06-23 18:40:47 -0700464
Megha Dey087bcd22016-06-23 18:40:47 -0700465 if (ret)
Herbert Xu72259de2016-06-28 20:33:52 +0800466 break;
467
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100468 crypto_req_done(&data[k].req->base, 0);
Megha Dey087bcd22016-06-23 18:40:47 -0700469 }
470
Herbert Xu72259de2016-06-28 20:33:52 +0800471 for (j = 0; j < k; j++) {
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100472 struct crypto_wait *wait = &data[j].wait;
473 int wait_ret;
Herbert Xu72259de2016-06-28 20:33:52 +0800474
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100475 wait_ret = crypto_wait_req(-EINPROGRESS, wait);
476 if (wait_ret)
477 ret = wait_ret;
Herbert Xu72259de2016-06-28 20:33:52 +0800478 }
479
480 end = get_cycles();
481 cycles = end - start;
482 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
483 cycles, cycles / (8 * speed[i].blen));
484
485 if (ret) {
486 pr_err("At least one hashing failed ret=%d\n", ret);
487 break;
488 }
Megha Dey087bcd22016-06-23 18:40:47 -0700489 }
Megha Dey087bcd22016-06-23 18:40:47 -0700490
491out:
492 for (k = 0; k < 8; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800493 ahash_request_free(data[k].req);
494
Megha Dey087bcd22016-06-23 18:40:47 -0700495 for (k = 0; k < 8; ++k)
Herbert Xu72259de2016-06-28 20:33:52 +0800496 testmgr_free_buf(data[k].xbuf);
497
498 crypto_free_ahash(tfm);
499
500free_data:
501 kfree(data);
Megha Dey087bcd22016-06-23 18:40:47 -0700502}
503
David S. Millerbeb63da2010-05-19 14:11:21 +1000504static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700505 char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000506{
507 unsigned long start, end;
508 int bcount;
509 int ret;
510
Mark Rustad3e3dc252014-07-25 02:53:38 -0700511 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000512 time_before(jiffies, end); bcount++) {
513 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
514 if (ret)
515 return ret;
516 }
517
518 printk("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700519 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000520
521 return 0;
522}
523
524static int test_ahash_jiffies(struct ahash_request *req, int blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700525 int plen, char *out, int secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000526{
527 unsigned long start, end;
528 int bcount, pcount;
529 int ret;
530
531 if (plen == blen)
Mark Rustad3e3dc252014-07-25 02:53:38 -0700532 return test_ahash_jiffies_digest(req, blen, out, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000533
Mark Rustad3e3dc252014-07-25 02:53:38 -0700534 for (start = jiffies, end = start + secs * HZ, bcount = 0;
David S. Millerbeb63da2010-05-19 14:11:21 +1000535 time_before(jiffies, end); bcount++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800536 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000537 if (ret)
538 return ret;
539 for (pcount = 0; pcount < blen; pcount += plen) {
540 ret = do_one_ahash_op(req, crypto_ahash_update(req));
541 if (ret)
542 return ret;
543 }
544 /* we assume there is enough space in 'out' for the result */
545 ret = do_one_ahash_op(req, crypto_ahash_final(req));
546 if (ret)
547 return ret;
548 }
549
550 pr_cont("%6u opers/sec, %9lu bytes/sec\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700551 bcount / secs, ((long)bcount * blen) / secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000552
553 return 0;
554}
555
556static int test_ahash_cycles_digest(struct ahash_request *req, int blen,
557 char *out)
558{
559 unsigned long cycles = 0;
560 int ret, i;
561
562 /* Warm-up run. */
563 for (i = 0; i < 4; i++) {
564 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
565 if (ret)
566 goto out;
567 }
568
569 /* The real thing. */
570 for (i = 0; i < 8; i++) {
571 cycles_t start, end;
572
573 start = get_cycles();
574
575 ret = do_one_ahash_op(req, crypto_ahash_digest(req));
576 if (ret)
577 goto out;
578
579 end = get_cycles();
580
581 cycles += end - start;
582 }
583
584out:
585 if (ret)
586 return ret;
587
588 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
589 cycles / 8, cycles / (8 * blen));
590
591 return 0;
592}
593
594static int test_ahash_cycles(struct ahash_request *req, int blen,
595 int plen, char *out)
596{
597 unsigned long cycles = 0;
598 int i, pcount, ret;
599
600 if (plen == blen)
601 return test_ahash_cycles_digest(req, blen, out);
602
603 /* Warm-up run. */
604 for (i = 0; i < 4; i++) {
Herbert Xu43a96072015-04-22 11:02:27 +0800605 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000606 if (ret)
607 goto out;
608 for (pcount = 0; pcount < blen; pcount += plen) {
609 ret = do_one_ahash_op(req, crypto_ahash_update(req));
610 if (ret)
611 goto out;
612 }
613 ret = do_one_ahash_op(req, crypto_ahash_final(req));
614 if (ret)
615 goto out;
616 }
617
618 /* The real thing. */
619 for (i = 0; i < 8; i++) {
620 cycles_t start, end;
621
622 start = get_cycles();
623
Herbert Xu43a96072015-04-22 11:02:27 +0800624 ret = do_one_ahash_op(req, crypto_ahash_init(req));
David S. Millerbeb63da2010-05-19 14:11:21 +1000625 if (ret)
626 goto out;
627 for (pcount = 0; pcount < blen; pcount += plen) {
628 ret = do_one_ahash_op(req, crypto_ahash_update(req));
629 if (ret)
630 goto out;
631 }
632 ret = do_one_ahash_op(req, crypto_ahash_final(req));
633 if (ret)
634 goto out;
635
636 end = get_cycles();
637
638 cycles += end - start;
639 }
640
641out:
642 if (ret)
643 return ret;
644
645 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n",
646 cycles / 8, cycles / (8 * blen));
647
648 return 0;
649}
650
Herbert Xu06605112016-02-01 21:36:49 +0800651static void test_ahash_speed_common(const char *algo, unsigned int secs,
652 struct hash_speed *speed, unsigned mask)
David S. Millerbeb63da2010-05-19 14:11:21 +1000653{
654 struct scatterlist sg[TVMEMSIZE];
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100655 struct crypto_wait wait;
David S. Millerbeb63da2010-05-19 14:11:21 +1000656 struct ahash_request *req;
657 struct crypto_ahash *tfm;
Horia Geant?f074f7b2015-08-27 18:38:36 +0300658 char *output;
David S. Millerbeb63da2010-05-19 14:11:21 +1000659 int i, ret;
660
Herbert Xu06605112016-02-01 21:36:49 +0800661 tfm = crypto_alloc_ahash(algo, 0, mask);
David S. Millerbeb63da2010-05-19 14:11:21 +1000662 if (IS_ERR(tfm)) {
663 pr_err("failed to load transform for %s: %ld\n",
664 algo, PTR_ERR(tfm));
665 return;
666 }
667
Luca Clementi263a8df2014-06-25 22:57:42 -0700668 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo,
669 get_driver_name(crypto_ahash, tfm));
670
Horia Geant?f074f7b2015-08-27 18:38:36 +0300671 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) {
672 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm),
673 MAX_DIGEST_SIZE);
David S. Millerbeb63da2010-05-19 14:11:21 +1000674 goto out;
675 }
676
677 test_hash_sg_init(sg);
678 req = ahash_request_alloc(tfm, GFP_KERNEL);
679 if (!req) {
680 pr_err("ahash request allocation failure\n");
681 goto out;
682 }
683
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100684 crypto_init_wait(&wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000685 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100686 crypto_req_done, &wait);
David S. Millerbeb63da2010-05-19 14:11:21 +1000687
Horia Geant?f074f7b2015-08-27 18:38:36 +0300688 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
689 if (!output)
690 goto out_nomem;
691
David S. Millerbeb63da2010-05-19 14:11:21 +1000692 for (i = 0; speed[i].blen != 0; i++) {
693 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) {
694 pr_err("template (%u) too big for tvmem (%lu)\n",
695 speed[i].blen, TVMEMSIZE * PAGE_SIZE);
696 break;
697 }
698
699 pr_info("test%3u "
700 "(%5u byte blocks,%5u bytes per update,%4u updates): ",
701 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen);
702
703 ahash_request_set_crypt(req, sg, output, speed[i].plen);
704
Mark Rustad3e3dc252014-07-25 02:53:38 -0700705 if (secs)
David S. Millerbeb63da2010-05-19 14:11:21 +1000706 ret = test_ahash_jiffies(req, speed[i].blen,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700707 speed[i].plen, output, secs);
David S. Millerbeb63da2010-05-19 14:11:21 +1000708 else
709 ret = test_ahash_cycles(req, speed[i].blen,
710 speed[i].plen, output);
711
712 if (ret) {
713 pr_err("hashing failed ret=%d\n", ret);
714 break;
715 }
716 }
717
Horia Geant?f074f7b2015-08-27 18:38:36 +0300718 kfree(output);
719
720out_nomem:
David S. Millerbeb63da2010-05-19 14:11:21 +1000721 ahash_request_free(req);
722
723out:
724 crypto_free_ahash(tfm);
725}
726
Herbert Xu06605112016-02-01 21:36:49 +0800727static void test_ahash_speed(const char *algo, unsigned int secs,
728 struct hash_speed *speed)
729{
730 return test_ahash_speed_common(algo, secs, speed, 0);
731}
732
733static void test_hash_speed(const char *algo, unsigned int secs,
734 struct hash_speed *speed)
735{
736 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC);
737}
738
Herbert Xu7166e582016-06-29 18:03:50 +0800739static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300740{
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100741 struct crypto_wait *wait = req->base.data;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300742
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100743 return crypto_wait_req(ret, wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300744}
745
Herbert Xu7166e582016-06-29 18:03:50 +0800746static int test_acipher_jiffies(struct skcipher_request *req, int enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700747 int blen, int secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300748{
749 unsigned long start, end;
750 int bcount;
751 int ret;
752
Mark Rustad3e3dc252014-07-25 02:53:38 -0700753 for (start = jiffies, end = start + secs * HZ, bcount = 0;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300754 time_before(jiffies, end); bcount++) {
755 if (enc)
756 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800757 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300758 else
759 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800760 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300761
762 if (ret)
763 return ret;
764 }
765
766 pr_cont("%d operations in %d seconds (%ld bytes)\n",
Mark Rustad3e3dc252014-07-25 02:53:38 -0700767 bcount, secs, (long)bcount * blen);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300768 return 0;
769}
770
Herbert Xu7166e582016-06-29 18:03:50 +0800771static int test_acipher_cycles(struct skcipher_request *req, int enc,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300772 int blen)
773{
774 unsigned long cycles = 0;
775 int ret = 0;
776 int i;
777
778 /* Warm-up run. */
779 for (i = 0; i < 4; i++) {
780 if (enc)
781 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800782 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300783 else
784 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800785 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300786
787 if (ret)
788 goto out;
789 }
790
791 /* The real thing. */
792 for (i = 0; i < 8; i++) {
793 cycles_t start, end;
794
795 start = get_cycles();
796 if (enc)
797 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800798 crypto_skcipher_encrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300799 else
800 ret = do_one_acipher_op(req,
Herbert Xu7166e582016-06-29 18:03:50 +0800801 crypto_skcipher_decrypt(req));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300802 end = get_cycles();
803
804 if (ret)
805 goto out;
806
807 cycles += end - start;
808 }
809
810out:
811 if (ret == 0)
812 pr_cont("1 operation in %lu cycles (%d bytes)\n",
813 (cycles + 4) / 8, blen);
814
815 return ret;
816}
817
Herbert Xu7166e582016-06-29 18:03:50 +0800818static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
819 struct cipher_speed_template *template,
820 unsigned int tcount, u8 *keysize, bool async)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300821{
Nicolas Royerde1975332012-07-01 19:19:47 +0200822 unsigned int ret, i, j, k, iv_len;
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100823 struct crypto_wait wait;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300824 const char *key;
825 char iv[128];
Herbert Xu7166e582016-06-29 18:03:50 +0800826 struct skcipher_request *req;
827 struct crypto_skcipher *tfm;
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300828 const char *e;
829 u32 *b_size;
830
831 if (enc == ENCRYPT)
832 e = "encryption";
833 else
834 e = "decryption";
835
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100836 crypto_init_wait(&wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300837
Herbert Xu7166e582016-06-29 18:03:50 +0800838 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300839
840 if (IS_ERR(tfm)) {
841 pr_err("failed to load transform for %s: %ld\n", algo,
842 PTR_ERR(tfm));
843 return;
844 }
845
Luca Clementi263a8df2014-06-25 22:57:42 -0700846 pr_info("\ntesting speed of async %s (%s) %s\n", algo,
Herbert Xu7166e582016-06-29 18:03:50 +0800847 get_driver_name(crypto_skcipher, tfm), e);
Luca Clementi263a8df2014-06-25 22:57:42 -0700848
Herbert Xu7166e582016-06-29 18:03:50 +0800849 req = skcipher_request_alloc(tfm, GFP_KERNEL);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300850 if (!req) {
851 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n",
852 algo);
853 goto out;
854 }
855
Herbert Xu7166e582016-06-29 18:03:50 +0800856 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
Gilad Ben-Yossef64671042017-10-18 08:00:48 +0100857 crypto_req_done, &wait);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300858
859 i = 0;
860 do {
861 b_size = block_sizes;
862
863 do {
864 struct scatterlist sg[TVMEMSIZE];
865
866 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) {
867 pr_err("template (%u) too big for "
868 "tvmem (%lu)\n", *keysize + *b_size,
869 TVMEMSIZE * PAGE_SIZE);
870 goto out_free_req;
871 }
872
873 pr_info("test %u (%d bit key, %d byte blocks): ", i,
874 *keysize * 8, *b_size);
875
876 memset(tvmem[0], 0xff, PAGE_SIZE);
877
878 /* set key, plain text and IV */
879 key = tvmem[0];
880 for (j = 0; j < tcount; j++) {
881 if (template[j].klen == *keysize) {
882 key = template[j].key;
883 break;
884 }
885 }
886
Herbert Xu7166e582016-06-29 18:03:50 +0800887 crypto_skcipher_clear_flags(tfm, ~0);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300888
Herbert Xu7166e582016-06-29 18:03:50 +0800889 ret = crypto_skcipher_setkey(tfm, key, *keysize);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300890 if (ret) {
891 pr_err("setkey() failed flags=%x\n",
Herbert Xu7166e582016-06-29 18:03:50 +0800892 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300893 goto out_free_req;
894 }
895
Nicolas Royerde1975332012-07-01 19:19:47 +0200896 k = *keysize + *b_size;
Horia Geant?007ee8d2015-03-09 16:14:58 +0200897 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE));
898
Nicolas Royerde1975332012-07-01 19:19:47 +0200899 if (k > PAGE_SIZE) {
900 sg_set_buf(sg, tvmem[0] + *keysize,
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300901 PAGE_SIZE - *keysize);
Nicolas Royerde1975332012-07-01 19:19:47 +0200902 k -= PAGE_SIZE;
903 j = 1;
904 while (k > PAGE_SIZE) {
905 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE);
906 memset(tvmem[j], 0xff, PAGE_SIZE);
907 j++;
908 k -= PAGE_SIZE;
909 }
910 sg_set_buf(sg + j, tvmem[j], k);
911 memset(tvmem[j], 0xff, k);
912 } else {
913 sg_set_buf(sg, tvmem[0] + *keysize, *b_size);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300914 }
915
Herbert Xu7166e582016-06-29 18:03:50 +0800916 iv_len = crypto_skcipher_ivsize(tfm);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300917 if (iv_len)
918 memset(&iv, 0xff, iv_len);
919
Herbert Xu7166e582016-06-29 18:03:50 +0800920 skcipher_request_set_crypt(req, sg, sg, *b_size, iv);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300921
Mark Rustad3e3dc252014-07-25 02:53:38 -0700922 if (secs)
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300923 ret = test_acipher_jiffies(req, enc,
Mark Rustad3e3dc252014-07-25 02:53:38 -0700924 *b_size, secs);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300925 else
926 ret = test_acipher_cycles(req, enc,
927 *b_size);
928
929 if (ret) {
930 pr_err("%s() failed flags=%x\n", e,
Herbert Xu7166e582016-06-29 18:03:50 +0800931 crypto_skcipher_get_flags(tfm));
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300932 break;
933 }
934 b_size++;
935 i++;
936 } while (*b_size);
937 keysize++;
938 } while (*keysize);
939
940out_free_req:
Herbert Xu7166e582016-06-29 18:03:50 +0800941 skcipher_request_free(req);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300942out:
Herbert Xu7166e582016-06-29 18:03:50 +0800943 crypto_free_skcipher(tfm);
944}
945
946static void test_acipher_speed(const char *algo, int enc, unsigned int secs,
947 struct cipher_speed_template *template,
948 unsigned int tcount, u8 *keysize)
949{
950 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
951 true);
952}
953
954static void test_cipher_speed(const char *algo, int enc, unsigned int secs,
955 struct cipher_speed_template *template,
956 unsigned int tcount, u8 *keysize)
957{
958 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize,
959 false);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +0300960}
961
Herbert Xuef2736f2005-06-22 13:26:03 -0700962static void test_available(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
964 char **name = check;
Herbert Xuef2736f2005-06-22 13:26:03 -0700965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 while (*name) {
967 printk("alg %s ", *name);
Herbert Xu6158efc2007-04-04 17:41:07 +1000968 printk(crypto_has_alg(*name, 0, 0) ?
Herbert Xue4d5b792006-08-26 18:12:40 +1000969 "found\n" : "not found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 name++;
Herbert Xuef2736f2005-06-22 13:26:03 -0700971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972}
973
Herbert Xu01b32322008-07-31 15:41:55 +0800974static inline int tcrypt_test(const char *alg)
975{
Jarod Wilson4e033a62009-05-27 15:10:21 +1000976 int ret;
977
Rabin Vincent76512f22017-01-18 14:54:05 +0100978 pr_debug("testing %s\n", alg);
979
Jarod Wilson4e033a62009-05-27 15:10:21 +1000980 ret = alg_test(alg, alg, 0, 0);
981 /* non-fips algs return -EINVAL in fips mode */
982 if (fips_enabled && ret == -EINVAL)
983 ret = 0;
984 return ret;
Herbert Xu01b32322008-07-31 15:41:55 +0800985}
986
Herbert Xu86068132014-12-04 16:43:29 +0800987static int do_test(const char *alg, u32 type, u32 mask, int m)
Herbert Xu01b32322008-07-31 15:41:55 +0800988{
989 int i;
Jarod Wilson4e033a62009-05-27 15:10:21 +1000990 int ret = 0;
Herbert Xu01b32322008-07-31 15:41:55 +0800991
992 switch (m) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 case 0:
Herbert Xu86068132014-12-04 16:43:29 +0800994 if (alg) {
995 if (!crypto_has_alg(alg, type,
996 mask ?: CRYPTO_ALG_TYPE_MASK))
997 ret = -ENOENT;
998 break;
999 }
1000
Herbert Xu01b32322008-07-31 15:41:55 +08001001 for (i = 1; i < 200; i++)
Herbert Xu86068132014-12-04 16:43:29 +08001002 ret += do_test(NULL, 0, 0, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 break;
1004
1005 case 1:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001006 ret += tcrypt_test("md5");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 break;
1008
1009 case 2:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001010 ret += tcrypt_test("sha1");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 break;
1012
1013 case 3:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001014 ret += tcrypt_test("ecb(des)");
1015 ret += tcrypt_test("cbc(des)");
Jussi Kivilinna8163fc32012-10-20 14:53:07 +03001016 ret += tcrypt_test("ctr(des)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 break;
1018
1019 case 4:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001020 ret += tcrypt_test("ecb(des3_ede)");
1021 ret += tcrypt_test("cbc(des3_ede)");
Jussi Kivilinnae080b172012-10-20 14:53:12 +03001022 ret += tcrypt_test("ctr(des3_ede)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 break;
1024
1025 case 5:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001026 ret += tcrypt_test("md4");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 case 6:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001030 ret += tcrypt_test("sha256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 case 7:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001034 ret += tcrypt_test("ecb(blowfish)");
1035 ret += tcrypt_test("cbc(blowfish)");
Jussi Kivilinna85b63e32011-10-10 23:03:03 +03001036 ret += tcrypt_test("ctr(blowfish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 break;
1038
1039 case 8:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001040 ret += tcrypt_test("ecb(twofish)");
1041 ret += tcrypt_test("cbc(twofish)");
Jussi Kivilinna573da622011-10-10 23:03:12 +03001042 ret += tcrypt_test("ctr(twofish)");
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001043 ret += tcrypt_test("lrw(twofish)");
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001044 ret += tcrypt_test("xts(twofish)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 case 9:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001048 ret += tcrypt_test("ecb(serpent)");
Jussi Kivilinna9d259172011-10-18 00:02:53 +03001049 ret += tcrypt_test("cbc(serpent)");
1050 ret += tcrypt_test("ctr(serpent)");
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001051 ret += tcrypt_test("lrw(serpent)");
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001052 ret += tcrypt_test("xts(serpent)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 break;
1054
1055 case 10:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001056 ret += tcrypt_test("ecb(aes)");
1057 ret += tcrypt_test("cbc(aes)");
1058 ret += tcrypt_test("lrw(aes)");
1059 ret += tcrypt_test("xts(aes)");
1060 ret += tcrypt_test("ctr(aes)");
1061 ret += tcrypt_test("rfc3686(ctr(aes))");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 break;
1063
1064 case 11:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001065 ret += tcrypt_test("sha384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 case 12:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001069 ret += tcrypt_test("sha512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 break;
1071
1072 case 13:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001073 ret += tcrypt_test("deflate");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 break;
1075
1076 case 14:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001077 ret += tcrypt_test("ecb(cast5)");
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001078 ret += tcrypt_test("cbc(cast5)");
1079 ret += tcrypt_test("ctr(cast5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 break;
1081
1082 case 15:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001083 ret += tcrypt_test("ecb(cast6)");
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001084 ret += tcrypt_test("cbc(cast6)");
1085 ret += tcrypt_test("ctr(cast6)");
1086 ret += tcrypt_test("lrw(cast6)");
1087 ret += tcrypt_test("xts(cast6)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 break;
1089
1090 case 16:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001091 ret += tcrypt_test("ecb(arc4)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 break;
1093
1094 case 17:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001095 ret += tcrypt_test("michael_mic");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 break;
1097
1098 case 18:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001099 ret += tcrypt_test("crc32c");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 break;
1101
1102 case 19:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001103 ret += tcrypt_test("ecb(tea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 break;
1105
1106 case 20:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001107 ret += tcrypt_test("ecb(xtea)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 break;
1109
1110 case 21:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001111 ret += tcrypt_test("ecb(khazad)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 break;
1113
1114 case 22:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001115 ret += tcrypt_test("wp512");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 break;
1117
1118 case 23:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001119 ret += tcrypt_test("wp384");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 break;
1121
1122 case 24:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001123 ret += tcrypt_test("wp256");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 break;
1125
1126 case 25:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001127 ret += tcrypt_test("ecb(tnepres)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 break;
1129
1130 case 26:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001131 ret += tcrypt_test("ecb(anubis)");
1132 ret += tcrypt_test("cbc(anubis)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 break;
1134
1135 case 27:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001136 ret += tcrypt_test("tgr192");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 break;
1138
1139 case 28:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001140 ret += tcrypt_test("tgr160");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 break;
1142
1143 case 29:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001144 ret += tcrypt_test("tgr128");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 break;
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001146
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001147 case 30:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001148 ret += tcrypt_test("ecb(xeta)");
Aaron Grothefb4f10e2005-09-01 17:42:46 -07001149 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
David Howells90831632006-12-16 12:13:14 +11001151 case 31:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001152 ret += tcrypt_test("pcbc(fcrypt)");
David Howells90831632006-12-16 12:13:14 +11001153 break;
1154
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001155 case 32:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001156 ret += tcrypt_test("ecb(camellia)");
1157 ret += tcrypt_test("cbc(camellia)");
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001158 ret += tcrypt_test("ctr(camellia)");
1159 ret += tcrypt_test("lrw(camellia)");
1160 ret += tcrypt_test("xts(camellia)");
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001161 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001162
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001163 case 33:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001164 ret += tcrypt_test("sha224");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001165 break;
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001166
Tan Swee Heng2407d602007-11-23 19:45:00 +08001167 case 34:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001168 ret += tcrypt_test("salsa20");
Tan Swee Heng2407d602007-11-23 19:45:00 +08001169 break;
1170
Herbert Xu8df213d2007-12-02 14:55:47 +11001171 case 35:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001172 ret += tcrypt_test("gcm(aes)");
Herbert Xu8df213d2007-12-02 14:55:47 +11001173 break;
1174
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001175 case 36:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001176 ret += tcrypt_test("lzo");
Zoltan Sogor0b77abb2007-12-07 16:53:23 +08001177 break;
1178
Joy Latten93cc74e2007-12-12 20:24:22 +08001179 case 37:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001180 ret += tcrypt_test("ccm(aes)");
Joy Latten93cc74e2007-12-12 20:24:22 +08001181 break;
1182
Kevin Coffman76cb9522008-03-24 21:26:16 +08001183 case 38:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001184 ret += tcrypt_test("cts(cbc(aes))");
Kevin Coffman76cb9522008-03-24 21:26:16 +08001185 break;
1186
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001187 case 39:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001188 ret += tcrypt_test("rmd128");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001189 break;
1190
1191 case 40:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001192 ret += tcrypt_test("rmd160");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001193 break;
1194
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001195 case 41:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001196 ret += tcrypt_test("rmd256");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001197 break;
1198
1199 case 42:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001200 ret += tcrypt_test("rmd320");
Herbert Xu01b32322008-07-31 15:41:55 +08001201 break;
1202
1203 case 43:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001204 ret += tcrypt_test("ecb(seed)");
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001205 break;
1206
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001207 case 44:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001208 ret += tcrypt_test("zlib");
Geert Uytterhoeven0c01aed2009-03-04 15:42:15 +08001209 break;
1210
Jarod Wilson5d667322009-05-04 19:23:40 +08001211 case 45:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001212 ret += tcrypt_test("rfc4309(ccm(aes))");
Jarod Wilson5d667322009-05-04 19:23:40 +08001213 break;
1214
Jussi Kivilinna54216bb2012-09-21 10:27:10 +03001215 case 46:
1216 ret += tcrypt_test("ghash");
1217 break;
1218
Herbert Xu684115212013-09-07 12:56:26 +10001219 case 47:
1220 ret += tcrypt_test("crct10dif");
1221 break;
1222
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301223 case 48:
1224 ret += tcrypt_test("sha3-224");
1225 break;
1226
1227 case 49:
1228 ret += tcrypt_test("sha3-256");
1229 break;
1230
1231 case 50:
1232 ret += tcrypt_test("sha3-384");
1233 break;
1234
1235 case 51:
1236 ret += tcrypt_test("sha3-512");
1237 break;
1238
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001239 case 52:
1240 ret += tcrypt_test("sm3");
1241 break;
1242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 case 100:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001244 ret += tcrypt_test("hmac(md5)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 case 101:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001248 ret += tcrypt_test("hmac(sha1)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 break;
Herbert Xuef2736f2005-06-22 13:26:03 -07001250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 case 102:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001252 ret += tcrypt_test("hmac(sha256)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 break;
1254
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001255 case 103:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001256 ret += tcrypt_test("hmac(sha384)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001257 break;
1258
1259 case 104:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001260 ret += tcrypt_test("hmac(sha512)");
Andrew Donofrioa28091a2006-12-10 12:10:20 +11001261 break;
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001262
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001263 case 105:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001264 ret += tcrypt_test("hmac(sha224)");
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001267 case 106:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001268 ret += tcrypt_test("xcbc(aes)");
Herbert Xu38ed9ab2008-01-01 15:59:28 +11001269 break;
1270
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001271 case 107:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001272 ret += tcrypt_test("hmac(rmd128)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001273 break;
1274
1275 case 108:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001276 ret += tcrypt_test("hmac(rmd160)");
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001277 break;
1278
Shane Wangf1939f72009-09-02 20:05:22 +10001279 case 109:
1280 ret += tcrypt_test("vmac(aes)");
1281 break;
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001282
Sonic Zhanga482b082012-05-25 17:54:13 +08001283 case 110:
1284 ret += tcrypt_test("hmac(crc32)");
1285 break;
Shane Wangf1939f72009-09-02 20:05:22 +10001286
raveendra padasalagi98eca722016-07-01 11:16:54 +05301287 case 111:
1288 ret += tcrypt_test("hmac(sha3-224)");
1289 break;
1290
1291 case 112:
1292 ret += tcrypt_test("hmac(sha3-256)");
1293 break;
1294
1295 case 113:
1296 ret += tcrypt_test("hmac(sha3-384)");
1297 break;
1298
1299 case 114:
1300 ret += tcrypt_test("hmac(sha3-512)");
1301 break;
1302
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001303 case 150:
Jarod Wilson4e033a62009-05-27 15:10:21 +10001304 ret += tcrypt_test("ansi_cprng");
Jarod Wilsone08ca2d2009-05-04 19:46:29 +08001305 break;
1306
Adrian Hoban69435b92010-11-04 15:02:04 -04001307 case 151:
1308 ret += tcrypt_test("rfc4106(gcm(aes))");
1309 break;
1310
Jussi Kivilinnae9b74412013-04-07 16:43:51 +03001311 case 152:
1312 ret += tcrypt_test("rfc4543(gcm(aes))");
1313 break;
1314
Jussi Kivilinna93b5e862013-04-08 10:48:44 +03001315 case 153:
1316 ret += tcrypt_test("cmac(aes)");
1317 break;
1318
1319 case 154:
1320 ret += tcrypt_test("cmac(des3_ede)");
1321 break;
1322
Horia Geantabbf9c892013-11-28 15:11:16 +02001323 case 155:
1324 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
1325 break;
1326
Horia Geantabca4feb2014-03-14 17:46:51 +02001327 case 156:
1328 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
1329 break;
1330
1331 case 157:
1332 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
1333 break;
Nitesh Lal5208ed22014-05-21 17:09:08 +05301334 case 181:
1335 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
1336 break;
1337 case 182:
1338 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
1339 break;
1340 case 183:
1341 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
1342 break;
1343 case 184:
1344 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
1345 break;
1346 case 185:
1347 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
1348 break;
1349 case 186:
1350 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
1351 break;
1352 case 187:
1353 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
1354 break;
1355 case 188:
1356 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
1357 break;
1358 case 189:
1359 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
1360 break;
1361 case 190:
1362 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
1363 break;
Harald Welteebfd9bc2005-06-22 13:27:23 -07001364 case 200:
Herbert Xucba83562006-08-13 08:26:09 +10001365 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001366 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001367 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001368 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001369 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001370 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001371 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001372 speed_template_16_24_32);
Rik Snelf3d10442006-11-29 19:01:41 +11001373 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001374 speed_template_32_40_48);
Rik Snelf3d10442006-11-29 19:01:41 +11001375 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001376 speed_template_32_40_48);
Rik Snelf19f5112007-09-19 20:23:13 +08001377 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001378 speed_template_32_64);
Rik Snelf19f5112007-09-19 20:23:13 +08001379 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001380 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001381 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1382 speed_template_16_24_32);
1383 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1384 speed_template_16_24_32);
Jan Glauber9996e342011-04-26 16:34:01 +10001385 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1386 speed_template_16_24_32);
1387 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1388 speed_template_16_24_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001389 break;
1390
1391 case 201:
Herbert Xucba83562006-08-13 08:26:09 +10001392 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001393 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001394 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001395 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001396 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001397 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001398 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001399 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001400 speed_template_24);
Herbert Xucba83562006-08-13 08:26:09 +10001401 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec,
Herbert Xuda7f0332008-07-31 17:08:25 +08001402 des3_speed_template, DES3_SPEED_VECTORS,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001403 speed_template_24);
Jussi Kivilinna87131502014-06-09 20:59:49 +03001404 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec,
1405 des3_speed_template, DES3_SPEED_VECTORS,
1406 speed_template_24);
1407 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec,
1408 des3_speed_template, DES3_SPEED_VECTORS,
1409 speed_template_24);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001410 break;
1411
1412 case 202:
Herbert Xucba83562006-08-13 08:26:09 +10001413 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001414 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001415 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001416 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001417 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001418 speed_template_16_24_32);
Herbert Xucba83562006-08-13 08:26:09 +10001419 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001420 speed_template_16_24_32);
Jussi Kivilinnaee5002a2011-09-26 16:47:15 +03001421 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1422 speed_template_16_24_32);
1423 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1424 speed_template_16_24_32);
Jussi Kivilinnabee3a902011-10-18 13:32:56 +03001425 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1426 speed_template_32_40_48);
1427 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1428 speed_template_32_40_48);
Jussi Kivilinna131f7542011-10-18 13:33:38 +03001429 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1430 speed_template_32_48_64);
1431 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1432 speed_template_32_48_64);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001433 break;
1434
1435 case 203:
Herbert Xucba83562006-08-13 08:26:09 +10001436 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001437 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001438 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001439 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001440 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001441 speed_template_8_32);
Herbert Xucba83562006-08-13 08:26:09 +10001442 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001443 speed_template_8_32);
Jussi Kivilinna7d47b862011-09-02 01:45:17 +03001444 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
1445 speed_template_8_32);
1446 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
1447 speed_template_8_32);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001448 break;
1449
1450 case 204:
Herbert Xucba83562006-08-13 08:26:09 +10001451 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001452 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001453 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001454 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001455 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001456 speed_template_8);
Herbert Xucba83562006-08-13 08:26:09 +10001457 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001458 speed_template_8);
Harald Welteebfd9bc2005-06-22 13:27:23 -07001459 break;
1460
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001461 case 205:
1462 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001463 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001464 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001465 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001466 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001467 speed_template_16_24_32);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001468 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001469 speed_template_16_24_32);
Jussi Kivilinna4de59332012-03-05 20:26:26 +02001470 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1471 speed_template_16_24_32);
1472 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1473 speed_template_16_24_32);
1474 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1475 speed_template_32_40_48);
1476 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1477 speed_template_32_40_48);
1478 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1479 speed_template_32_48_64);
1480 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1481 speed_template_32_48_64);
Noriaki TAKAMIYA02ab5a72007-01-24 21:48:19 +11001482 break;
1483
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001484 case 206:
1485 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0,
Sebastian Siewior477035c2008-03-11 21:24:26 +08001486 speed_template_16_32);
Tan Swee Heng5de8f1b2007-12-07 17:17:43 +08001487 break;
1488
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001489 case 207:
1490 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1491 speed_template_16_32);
1492 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1493 speed_template_16_32);
1494 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1495 speed_template_16_32);
1496 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1497 speed_template_16_32);
1498 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1499 speed_template_16_32);
1500 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1501 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001502 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1503 speed_template_32_48);
1504 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1505 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001506 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1507 speed_template_32_64);
1508 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1509 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001510 break;
1511
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001512 case 208:
1513 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1514 speed_template_8);
1515 break;
1516
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001517 case 209:
1518 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1519 speed_template_8_16);
1520 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1521 speed_template_8_16);
1522 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1523 speed_template_8_16);
1524 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1525 speed_template_8_16);
1526 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1527 speed_template_8_16);
1528 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1529 speed_template_8_16);
1530 break;
1531
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001532 case 210:
1533 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1534 speed_template_16_32);
1535 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1536 speed_template_16_32);
1537 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1538 speed_template_16_32);
1539 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1540 speed_template_16_32);
1541 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1542 speed_template_16_32);
1543 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1544 speed_template_16_32);
1545 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1546 speed_template_32_48);
1547 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1548 speed_template_32_48);
1549 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1550 speed_template_32_64);
1551 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1552 speed_template_32_64);
1553 break;
1554
Tim Chen53f52d72013-12-11 14:28:47 -08001555 case 211:
1556 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001557 NULL, 0, 16, 16, aead_speed_template_20);
Vutla, Lokesh1425d2d2015-07-07 21:01:49 +05301558 test_aead_speed("gcm(aes)", ENCRYPT, sec,
Cyrille Pitchenf18611d2015-11-17 13:37:10 +01001559 NULL, 0, 16, 8, speed_template_16_24_32);
Tim Chen53f52d72013-12-11 14:28:47 -08001560 break;
1561
Herbert Xu4e4aab62015-06-17 14:04:21 +08001562 case 212:
1563 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec,
Herbert Xu34a1c742015-07-09 07:17:26 +08001564 NULL, 0, 16, 16, aead_speed_template_19);
Herbert Xu4e4aab62015-06-17 14:04:21 +08001565 break;
1566
Martin Willi2dce0632015-07-16 19:13:59 +02001567 case 213:
1568 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec,
1569 NULL, 0, 16, 8, aead_speed_template_36);
1570 break;
1571
1572 case 214:
1573 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0,
1574 speed_template_32);
1575 break;
1576
Michal Ludvige8057922006-05-30 22:04:19 +10001577 case 300:
Herbert Xu86068132014-12-04 16:43:29 +08001578 if (alg) {
1579 test_hash_speed(alg, sec, generic_hash_speed_template);
1580 break;
1581 }
Michal Ludvige8057922006-05-30 22:04:19 +10001582 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001583 case 301:
Herbert Xue9d41162006-08-19 21:38:49 +10001584 test_hash_speed("md4", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001585 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001586 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001587 case 302:
Herbert Xue9d41162006-08-19 21:38:49 +10001588 test_hash_speed("md5", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001589 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001590 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001591 case 303:
Herbert Xue9d41162006-08-19 21:38:49 +10001592 test_hash_speed("sha1", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001593 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001594 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001595 case 304:
Herbert Xue9d41162006-08-19 21:38:49 +10001596 test_hash_speed("sha256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001597 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001598 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001599 case 305:
Herbert Xue9d41162006-08-19 21:38:49 +10001600 test_hash_speed("sha384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001601 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001602 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001603 case 306:
Herbert Xue9d41162006-08-19 21:38:49 +10001604 test_hash_speed("sha512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001605 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001606 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001607 case 307:
Herbert Xue9d41162006-08-19 21:38:49 +10001608 test_hash_speed("wp256", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001609 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001610 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001611 case 308:
Herbert Xue9d41162006-08-19 21:38:49 +10001612 test_hash_speed("wp384", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001613 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001614 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001615 case 309:
Herbert Xue9d41162006-08-19 21:38:49 +10001616 test_hash_speed("wp512", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001617 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001618 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001619 case 310:
Herbert Xue9d41162006-08-19 21:38:49 +10001620 test_hash_speed("tgr128", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001621 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001622 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001623 case 311:
Herbert Xue9d41162006-08-19 21:38:49 +10001624 test_hash_speed("tgr160", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001625 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001626 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001627 case 312:
Herbert Xue9d41162006-08-19 21:38:49 +10001628 test_hash_speed("tgr192", sec, generic_hash_speed_template);
Michal Ludvige8057922006-05-30 22:04:19 +10001629 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001630 /* fall through */
Jonathan Lynchcd12fb902007-11-10 20:08:25 +08001631 case 313:
1632 test_hash_speed("sha224", sec, generic_hash_speed_template);
1633 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001634 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001635 case 314:
1636 test_hash_speed("rmd128", sec, generic_hash_speed_template);
1637 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001638 /* fall through */
Adrian-Ken Rueegseggerfd4adf12008-05-07 22:16:36 +08001639 case 315:
1640 test_hash_speed("rmd160", sec, generic_hash_speed_template);
1641 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001642 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001643 case 316:
1644 test_hash_speed("rmd256", sec, generic_hash_speed_template);
1645 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001646 /* fall through */
Adrian-Ken Rueegsegger2998db32008-05-09 21:29:35 +08001647 case 317:
1648 test_hash_speed("rmd320", sec, generic_hash_speed_template);
1649 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001650 /* fall through */
Huang Ying18bcc912010-03-10 18:30:32 +08001651 case 318:
1652 test_hash_speed("ghash-generic", sec, hash_speed_template_16);
1653 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001654 /* fall through */
Tim Chene3899e42012-09-27 15:44:24 -07001655 case 319:
1656 test_hash_speed("crc32c", sec, generic_hash_speed_template);
1657 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001658 /* fall through */
Herbert Xu684115212013-09-07 12:56:26 +10001659 case 320:
1660 test_hash_speed("crct10dif", sec, generic_hash_speed_template);
1661 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001662 /* fall through */
Martin Willi2dce0632015-07-16 19:13:59 +02001663 case 321:
1664 test_hash_speed("poly1305", sec, poly1305_speed_template);
1665 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001666 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301667 case 322:
1668 test_hash_speed("sha3-224", sec, generic_hash_speed_template);
1669 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001670 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301671 case 323:
1672 test_hash_speed("sha3-256", sec, generic_hash_speed_template);
1673 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001674 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301675 case 324:
1676 test_hash_speed("sha3-384", sec, generic_hash_speed_template);
1677 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001678 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301679 case 325:
1680 test_hash_speed("sha3-512", sec, generic_hash_speed_template);
1681 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001682 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001683 case 326:
1684 test_hash_speed("sm3", sec, generic_hash_speed_template);
1685 if (mode > 300 && mode < 400) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001686 /* fall through */
Michal Ludvige8057922006-05-30 22:04:19 +10001687 case 399:
1688 break;
1689
David S. Millerbeb63da2010-05-19 14:11:21 +10001690 case 400:
Herbert Xu86068132014-12-04 16:43:29 +08001691 if (alg) {
1692 test_ahash_speed(alg, sec, generic_hash_speed_template);
1693 break;
1694 }
David S. Millerbeb63da2010-05-19 14:11:21 +10001695 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001696 case 401:
1697 test_ahash_speed("md4", sec, generic_hash_speed_template);
1698 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001699 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001700 case 402:
1701 test_ahash_speed("md5", sec, generic_hash_speed_template);
1702 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001703 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001704 case 403:
1705 test_ahash_speed("sha1", sec, generic_hash_speed_template);
1706 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001707 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001708 case 404:
1709 test_ahash_speed("sha256", sec, generic_hash_speed_template);
1710 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001711 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001712 case 405:
1713 test_ahash_speed("sha384", sec, generic_hash_speed_template);
1714 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001715 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001716 case 406:
1717 test_ahash_speed("sha512", sec, generic_hash_speed_template);
1718 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001719 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001720 case 407:
1721 test_ahash_speed("wp256", sec, generic_hash_speed_template);
1722 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001723 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001724 case 408:
1725 test_ahash_speed("wp384", sec, generic_hash_speed_template);
1726 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001727 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001728 case 409:
1729 test_ahash_speed("wp512", sec, generic_hash_speed_template);
1730 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001731 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001732 case 410:
1733 test_ahash_speed("tgr128", sec, generic_hash_speed_template);
1734 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001735 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001736 case 411:
1737 test_ahash_speed("tgr160", sec, generic_hash_speed_template);
1738 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001739 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001740 case 412:
1741 test_ahash_speed("tgr192", sec, generic_hash_speed_template);
1742 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001743 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001744 case 413:
1745 test_ahash_speed("sha224", sec, generic_hash_speed_template);
1746 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001747 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001748 case 414:
1749 test_ahash_speed("rmd128", sec, generic_hash_speed_template);
1750 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001751 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001752 case 415:
1753 test_ahash_speed("rmd160", sec, generic_hash_speed_template);
1754 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001755 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001756 case 416:
1757 test_ahash_speed("rmd256", sec, generic_hash_speed_template);
1758 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001759 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001760 case 417:
1761 test_ahash_speed("rmd320", sec, generic_hash_speed_template);
1762 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001763 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301764 case 418:
1765 test_ahash_speed("sha3-224", sec, generic_hash_speed_template);
1766 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001767 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301768 case 419:
1769 test_ahash_speed("sha3-256", sec, generic_hash_speed_template);
1770 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001771 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301772 case 420:
1773 test_ahash_speed("sha3-384", sec, generic_hash_speed_template);
1774 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001775 /* fall through */
raveendra padasalagi79cc6ab2016-06-17 10:30:36 +05301776 case 421:
1777 test_ahash_speed("sha3-512", sec, generic_hash_speed_template);
1778 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001779 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001780 case 422:
1781 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template);
1782 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001783 /* fall through */
Megha Dey087bcd22016-06-23 18:40:47 -07001784 case 423:
1785 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template);
1786 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001787 /* fall through */
Megha Dey14009c42016-06-27 10:20:09 -07001788 case 424:
1789 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template);
1790 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001791 /* fall through */
Gilad Ben-Yossefb7e27532017-08-21 13:51:29 +03001792 case 425:
1793 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template);
1794 if (mode > 400 && mode < 500) break;
Gustavo A. R. Silva59517222017-10-09 14:43:21 -05001795 /* fall through */
David S. Millerbeb63da2010-05-19 14:11:21 +10001796 case 499:
1797 break;
1798
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001799 case 500:
1800 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
1801 speed_template_16_24_32);
1802 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0,
1803 speed_template_16_24_32);
1804 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0,
1805 speed_template_16_24_32);
1806 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0,
1807 speed_template_16_24_32);
1808 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0,
1809 speed_template_32_40_48);
1810 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0,
1811 speed_template_32_40_48);
1812 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001813 speed_template_32_64);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001814 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0,
Horia Geantăb66ad0b2017-07-19 19:40:32 +03001815 speed_template_32_64);
Herbert Xu1503a242016-06-29 18:04:14 +08001816 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0,
1817 speed_template_16_24_32);
1818 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0,
1819 speed_template_16_24_32);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001820 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0,
1821 speed_template_16_24_32);
1822 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0,
1823 speed_template_16_24_32);
Nicolas Royerde1975332012-07-01 19:19:47 +02001824 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0,
1825 speed_template_16_24_32);
1826 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0,
1827 speed_template_16_24_32);
1828 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0,
1829 speed_template_16_24_32);
1830 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0,
1831 speed_template_16_24_32);
Jussi Kivilinna69d31502012-12-28 12:04:58 +02001832 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0,
1833 speed_template_20_28_36);
1834 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0,
1835 speed_template_20_28_36);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001836 break;
1837
1838 case 501:
1839 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec,
1840 des3_speed_template, DES3_SPEED_VECTORS,
1841 speed_template_24);
1842 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec,
1843 des3_speed_template, DES3_SPEED_VECTORS,
1844 speed_template_24);
1845 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec,
1846 des3_speed_template, DES3_SPEED_VECTORS,
1847 speed_template_24);
1848 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec,
1849 des3_speed_template, DES3_SPEED_VECTORS,
1850 speed_template_24);
Nicolas Royerde1975332012-07-01 19:19:47 +02001851 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec,
1852 des3_speed_template, DES3_SPEED_VECTORS,
1853 speed_template_24);
1854 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec,
1855 des3_speed_template, DES3_SPEED_VECTORS,
1856 speed_template_24);
1857 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec,
1858 des3_speed_template, DES3_SPEED_VECTORS,
1859 speed_template_24);
1860 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec,
1861 des3_speed_template, DES3_SPEED_VECTORS,
1862 speed_template_24);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001863 break;
1864
1865 case 502:
1866 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0,
1867 speed_template_8);
1868 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0,
1869 speed_template_8);
1870 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0,
1871 speed_template_8);
1872 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0,
1873 speed_template_8);
Nicolas Royerde1975332012-07-01 19:19:47 +02001874 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0,
1875 speed_template_8);
1876 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0,
1877 speed_template_8);
1878 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0,
1879 speed_template_8);
1880 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0,
1881 speed_template_8);
Jussi Kivilinna3f3baf32011-10-18 00:02:58 +03001882 break;
1883
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001884 case 503:
1885 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0,
1886 speed_template_16_32);
1887 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0,
1888 speed_template_16_32);
1889 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0,
1890 speed_template_16_32);
1891 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0,
1892 speed_template_16_32);
1893 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0,
1894 speed_template_16_32);
1895 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0,
1896 speed_template_16_32);
Jussi Kivilinna87aae4b2011-10-18 13:32:39 +03001897 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0,
1898 speed_template_32_48);
1899 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0,
1900 speed_template_32_48);
Jussi Kivilinna5209c072011-10-18 13:33:22 +03001901 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0,
1902 speed_template_32_64);
1903 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0,
1904 speed_template_32_64);
Jussi Kivilinna7fb7fe42011-10-18 00:03:03 +03001905 break;
1906
Johannes Goetzfried107778b2012-05-28 15:54:24 +02001907 case 504:
1908 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0,
1909 speed_template_16_24_32);
1910 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0,
1911 speed_template_16_24_32);
1912 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0,
1913 speed_template_16_24_32);
1914 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0,
1915 speed_template_16_24_32);
1916 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0,
1917 speed_template_16_24_32);
1918 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0,
1919 speed_template_16_24_32);
1920 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0,
1921 speed_template_32_40_48);
1922 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0,
1923 speed_template_32_40_48);
1924 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0,
1925 speed_template_32_48_64);
1926 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0,
1927 speed_template_32_48_64);
1928 break;
1929
Jussi Kivilinna31b4cd292012-06-12 16:52:04 +08001930 case 505:
1931 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0,
1932 speed_template_8);
1933 break;
1934
Johannes Goetzfrieda2c58262012-07-11 19:37:21 +02001935 case 506:
1936 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0,
1937 speed_template_8_16);
1938 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0,
1939 speed_template_8_16);
1940 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0,
1941 speed_template_8_16);
1942 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0,
1943 speed_template_8_16);
1944 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0,
1945 speed_template_8_16);
1946 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0,
1947 speed_template_8_16);
1948 break;
1949
Johannes Goetzfried9b8b0402012-07-11 19:38:29 +02001950 case 507:
1951 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0,
1952 speed_template_16_32);
1953 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0,
1954 speed_template_16_32);
1955 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0,
1956 speed_template_16_32);
1957 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0,
1958 speed_template_16_32);
1959 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0,
1960 speed_template_16_32);
1961 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0,
1962 speed_template_16_32);
1963 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0,
1964 speed_template_32_48);
1965 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0,
1966 speed_template_32_48);
1967 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0,
1968 speed_template_32_64);
1969 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0,
1970 speed_template_32_64);
1971 break;
1972
Jussi Kivilinnabf9c5182012-10-26 14:48:51 +03001973 case 508:
1974 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0,
1975 speed_template_16_32);
1976 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0,
1977 speed_template_16_32);
1978 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0,
1979 speed_template_16_32);
1980 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
1981 speed_template_16_32);
1982 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
1983 speed_template_16_32);
1984 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
1985 speed_template_16_32);
1986 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
1987 speed_template_32_48);
1988 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
1989 speed_template_32_48);
1990 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
1991 speed_template_32_64);
1992 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
1993 speed_template_32_64);
1994 break;
1995
Jussi Kivilinnaad8b7c32013-04-13 13:46:40 +03001996 case 509:
1997 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0,
1998 speed_template_8_32);
1999 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0,
2000 speed_template_8_32);
2001 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0,
2002 speed_template_8_32);
2003 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0,
2004 speed_template_8_32);
2005 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0,
2006 speed_template_8_32);
2007 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0,
2008 speed_template_8_32);
2009 break;
2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 case 1000:
2012 test_available();
2013 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 }
Jarod Wilson4e033a62009-05-27 15:10:21 +10002015
2016 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017}
2018
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002019static int __init tcrypt_mod_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002021 int err = -ENOMEM;
Herbert Xuf139cfa2008-07-31 12:23:53 +08002022 int i;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002023
Herbert Xuf139cfa2008-07-31 12:23:53 +08002024 for (i = 0; i < TVMEMSIZE; i++) {
2025 tvmem[i] = (void *)__get_free_page(GFP_KERNEL);
2026 if (!tvmem[i])
2027 goto err_free_tv;
2028 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
Herbert Xu86068132014-12-04 16:43:29 +08002030 err = do_test(alg, type, mask, mode);
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002031
Jarod Wilson4e033a62009-05-27 15:10:21 +10002032 if (err) {
2033 printk(KERN_ERR "tcrypt: one or more tests failed!\n");
2034 goto err_free_tv;
Rabin Vincent76512f22017-01-18 14:54:05 +01002035 } else {
2036 pr_debug("all tests passed\n");
Jarod Wilson4e033a62009-05-27 15:10:21 +10002037 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
Jarod Wilson4e033a62009-05-27 15:10:21 +10002039 /* We intentionaly return -EAGAIN to prevent keeping the module,
2040 * unless we're running in fips mode. It does all its work from
2041 * init() and doesn't offer any runtime functionality, but in
2042 * the fips case, checking for a successful load is helpful.
Michal Ludvig14fdf472006-05-30 14:49:38 +10002043 * => we don't need it in the memory, do we?
2044 * -- mludvig
2045 */
Jarod Wilson4e033a62009-05-27 15:10:21 +10002046 if (!fips_enabled)
2047 err = -EAGAIN;
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002048
Herbert Xuf139cfa2008-07-31 12:23:53 +08002049err_free_tv:
2050 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++)
2051 free_page((unsigned long)tvmem[i]);
Mikko Herranene3a4ea42007-11-26 22:12:07 +08002052
2053 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054}
2055
2056/*
2057 * If an init function is provided, an exit function must also be provided
2058 * to allow module unload.
2059 */
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002060static void __exit tcrypt_mod_fini(void) { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Kamalesh Babulal3af5b902008-04-05 21:00:57 +08002062module_init(tcrypt_mod_init);
2063module_exit(tcrypt_mod_fini);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Steffen Klasserta873a5f2009-06-19 19:46:53 +08002065module_param(alg, charp, 0);
2066module_param(type, uint, 0);
Herbert Xu7be380f2009-07-14 16:06:54 +08002067module_param(mask, uint, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068module_param(mode, int, 0);
Harald Welteebfd9bc2005-06-22 13:27:23 -07002069module_param(sec, uint, 0);
Herbert Xu6a179442005-06-22 13:29:03 -07002070MODULE_PARM_DESC(sec, "Length in seconds of speed tests "
2071 "(defaults to zero which uses CPU cycles instead)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
2073MODULE_LICENSE("GPL");
2074MODULE_DESCRIPTION("Quick & dirty crypto testing module");
2075MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");