Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Quick & dirty crypto testing module. |
| 4 | * |
| 5 | * This will only exist until we have a better testing mechanism |
| 6 | * (e.g. a char device). |
| 7 | * |
| 8 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 9 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 10 | * Copyright (c) 2007 Nokia Siemens Networks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 12 | * Updated RFC4106 AES-GCM testing. |
| 13 | * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) |
| 14 | * Adrian Hoban <adrian.hoban@intel.com> |
| 15 | * Gabriele Paoloni <gabriele.paoloni@intel.com> |
| 16 | * Tadeusz Struk (tadeusz.struk@intel.com) |
| 17 | * Copyright (c) 2010, Intel Corporation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Rabin Vincent | 76512f2 | 2017-01-18 14:54:05 +0100 | [diff] [blame] | 20 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 21 | |
Herbert Xu | 1ce5a04 | 2015-04-22 15:06:30 +0800 | [diff] [blame] | 22 | #include <crypto/aead.h> |
Herbert Xu | 18e33e6 | 2008-07-10 16:01:22 +0800 | [diff] [blame] | 23 | #include <crypto/hash.h> |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 24 | #include <crypto/skcipher.h> |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 25 | #include <linux/err.h> |
Herbert Xu | daf0944 | 2015-04-22 13:25:57 +0800 | [diff] [blame] | 26 | #include <linux/fips.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/module.h> |
David Hardeman | 378f058 | 2005-09-17 17:55:31 +1000 | [diff] [blame] | 30 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/moduleparam.h> |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 33 | #include <linux/jiffies.h> |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 34 | #include <linux/timex.h> |
| 35 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "tcrypt.h" |
| 37 | |
| 38 | /* |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 39 | * Need slab memory for testing (size in number of pages). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | */ |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 41 | #define TVMEMSIZE 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 44 | * Used by test_cipher_speed() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | */ |
| 46 | #define ENCRYPT 1 |
| 47 | #define DECRYPT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Horia Geant? | f074f7b | 2015-08-27 18:38:36 +0300 | [diff] [blame] | 49 | #define MAX_DIGEST_SIZE 64 |
| 50 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 51 | /* |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 52 | * return a string with the driver name |
| 53 | */ |
| 54 | #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm)) |
| 55 | |
| 56 | /* |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 57 | * Used by test_cipher_speed() |
| 58 | */ |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 59 | static unsigned int sec; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 60 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 61 | static char *alg = NULL; |
| 62 | static u32 type; |
Herbert Xu | 7be380f | 2009-07-14 16:06:54 +0800 | [diff] [blame] | 63 | static u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static int mode; |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 65 | static u32 num_mb = 8; |
Herbert Xu | ba974ad | 2020-08-05 15:57:08 +1000 | [diff] [blame] | 66 | static unsigned int klen; |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 67 | static char *tvmem[TVMEMSIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Corentin Labbe | 07d8f18 | 2019-11-08 15:42:13 +0000 | [diff] [blame] | 69 | static const char *check[] = { |
Gilad Ben-Yossef | b7e2753 | 2017-08-21 13:51:29 +0300 | [diff] [blame] | 70 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3", |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 71 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", |
| 72 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
Ard Biesheuvel | 784506a | 2021-02-01 19:02:30 +0100 | [diff] [blame] | 73 | "khazad", "wp512", "wp384", "wp256", "xeta", "fcrypt", |
Ard Biesheuvel | 663f63e | 2021-01-21 14:07:33 +0100 | [diff] [blame] | 74 | "camellia", "seed", "rmd160", |
Dave Rodgman | 45ec975 | 2019-03-07 16:30:44 -0800 | [diff] [blame] | 75 | "lzo", "lzo-rle", "cts", "sha3-224", "sha3-256", "sha3-384", |
| 76 | "sha3-512", "streebog256", "streebog512", |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 77 | NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Tianjia Zhang | a7fc80b | 2021-07-20 11:46:42 +0800 | [diff] [blame] | 80 | static const int block_sizes[] = { 16, 64, 128, 256, 1024, 1420, 4096, 0 }; |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 81 | static const int aead_sizes[] = { 16, 64, 256, 512, 1024, 1420, 4096, 8192, 0 }; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 82 | |
| 83 | #define XBUFSIZE 8 |
| 84 | #define MAX_IVLEN 32 |
| 85 | |
| 86 | static int testmgr_alloc_buf(char *buf[XBUFSIZE]) |
| 87 | { |
| 88 | int i; |
| 89 | |
| 90 | for (i = 0; i < XBUFSIZE; i++) { |
| 91 | buf[i] = (void *)__get_free_page(GFP_KERNEL); |
| 92 | if (!buf[i]) |
| 93 | goto err_free_buf; |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | |
| 98 | err_free_buf: |
| 99 | while (i-- > 0) |
| 100 | free_page((unsigned long)buf[i]); |
| 101 | |
| 102 | return -ENOMEM; |
| 103 | } |
| 104 | |
| 105 | static void testmgr_free_buf(char *buf[XBUFSIZE]) |
| 106 | { |
| 107 | int i; |
| 108 | |
| 109 | for (i = 0; i < XBUFSIZE; i++) |
| 110 | free_page((unsigned long)buf[i]); |
| 111 | } |
| 112 | |
| 113 | static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE], |
| 114 | unsigned int buflen, const void *assoc, |
| 115 | unsigned int aad_size) |
| 116 | { |
| 117 | int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE; |
| 118 | int k, rem; |
| 119 | |
| 120 | if (np > XBUFSIZE) { |
| 121 | rem = PAGE_SIZE; |
| 122 | np = XBUFSIZE; |
| 123 | } else { |
| 124 | rem = buflen % PAGE_SIZE; |
| 125 | } |
| 126 | |
| 127 | sg_init_table(sg, np + 1); |
| 128 | |
| 129 | sg_set_buf(&sg[0], assoc, aad_size); |
| 130 | |
| 131 | if (rem) |
| 132 | np--; |
| 133 | for (k = 0; k < np; k++) |
| 134 | sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE); |
| 135 | |
| 136 | if (rem) |
| 137 | sg_set_buf(&sg[k + 1], xbuf[k], rem); |
| 138 | } |
| 139 | |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 140 | static inline int do_one_aead_op(struct aead_request *req, int ret) |
| 141 | { |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 142 | struct crypto_wait *wait = req->base.data; |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 143 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 144 | return crypto_wait_req(ret, wait); |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 145 | } |
| 146 | |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 147 | struct test_mb_aead_data { |
| 148 | struct scatterlist sg[XBUFSIZE]; |
| 149 | struct scatterlist sgout[XBUFSIZE]; |
| 150 | struct aead_request *req; |
| 151 | struct crypto_wait wait; |
| 152 | char *xbuf[XBUFSIZE]; |
| 153 | char *xoutbuf[XBUFSIZE]; |
| 154 | char *axbuf[XBUFSIZE]; |
| 155 | }; |
| 156 | |
| 157 | static int do_mult_aead_op(struct test_mb_aead_data *data, int enc, |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 158 | u32 num_mb, int *rc) |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 159 | { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 160 | int i, err = 0; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 161 | |
| 162 | /* Fire up a bunch of concurrent requests */ |
| 163 | for (i = 0; i < num_mb; i++) { |
| 164 | if (enc == ENCRYPT) |
| 165 | rc[i] = crypto_aead_encrypt(data[i].req); |
| 166 | else |
| 167 | rc[i] = crypto_aead_decrypt(data[i].req); |
| 168 | } |
| 169 | |
| 170 | /* Wait for all requests to finish */ |
| 171 | for (i = 0; i < num_mb; i++) { |
| 172 | rc[i] = crypto_wait_req(rc[i], &data[i].wait); |
| 173 | |
| 174 | if (rc[i]) { |
| 175 | pr_info("concurrent request %d error %d\n", i, rc[i]); |
| 176 | err = rc[i]; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | return err; |
| 181 | } |
| 182 | |
| 183 | static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc, |
| 184 | int blen, int secs, u32 num_mb) |
| 185 | { |
| 186 | unsigned long start, end; |
| 187 | int bcount; |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 188 | int ret = 0; |
| 189 | int *rc; |
| 190 | |
| 191 | rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); |
| 192 | if (!rc) |
| 193 | return -ENOMEM; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 194 | |
| 195 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
| 196 | time_before(jiffies, end); bcount++) { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 197 | ret = do_mult_aead_op(data, enc, num_mb, rc); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 198 | if (ret) |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 199 | goto out; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Ard Biesheuvel | 303fd3e | 2020-12-08 15:34:41 +0100 | [diff] [blame] | 202 | pr_cont("%d operations in %d seconds (%llu bytes)\n", |
| 203 | bcount * num_mb, secs, (u64)bcount * blen * num_mb); |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 204 | |
| 205 | out: |
| 206 | kfree(rc); |
| 207 | return ret; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc, |
| 211 | int blen, u32 num_mb) |
| 212 | { |
| 213 | unsigned long cycles = 0; |
| 214 | int ret = 0; |
| 215 | int i; |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 216 | int *rc; |
| 217 | |
| 218 | rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); |
| 219 | if (!rc) |
| 220 | return -ENOMEM; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 221 | |
| 222 | /* Warm-up run. */ |
| 223 | for (i = 0; i < 4; i++) { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 224 | ret = do_mult_aead_op(data, enc, num_mb, rc); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 225 | if (ret) |
| 226 | goto out; |
| 227 | } |
| 228 | |
| 229 | /* The real thing. */ |
| 230 | for (i = 0; i < 8; i++) { |
| 231 | cycles_t start, end; |
| 232 | |
| 233 | start = get_cycles(); |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 234 | ret = do_mult_aead_op(data, enc, num_mb, rc); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 235 | end = get_cycles(); |
| 236 | |
| 237 | if (ret) |
| 238 | goto out; |
| 239 | |
| 240 | cycles += end - start; |
| 241 | } |
| 242 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 243 | pr_cont("1 operation in %lu cycles (%d bytes)\n", |
| 244 | (cycles + 4) / (8 * num_mb), blen); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 245 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 246 | out: |
| 247 | kfree(rc); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static void test_mb_aead_speed(const char *algo, int enc, int secs, |
| 252 | struct aead_speed_template *template, |
| 253 | unsigned int tcount, u8 authsize, |
| 254 | unsigned int aad_size, u8 *keysize, u32 num_mb) |
| 255 | { |
| 256 | struct test_mb_aead_data *data; |
| 257 | struct crypto_aead *tfm; |
| 258 | unsigned int i, j, iv_len; |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 259 | const int *b_size; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 260 | const char *key; |
| 261 | const char *e; |
| 262 | void *assoc; |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 263 | char *iv; |
| 264 | int ret; |
| 265 | |
| 266 | |
| 267 | if (aad_size >= PAGE_SIZE) { |
| 268 | pr_err("associate data length (%u) too big\n", aad_size); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
| 273 | if (!iv) |
| 274 | return; |
| 275 | |
| 276 | if (enc == ENCRYPT) |
| 277 | e = "encryption"; |
| 278 | else |
| 279 | e = "decryption"; |
| 280 | |
| 281 | data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL); |
| 282 | if (!data) |
| 283 | goto out_free_iv; |
| 284 | |
| 285 | tfm = crypto_alloc_aead(algo, 0, 0); |
| 286 | if (IS_ERR(tfm)) { |
| 287 | pr_err("failed to load transform for %s: %ld\n", |
| 288 | algo, PTR_ERR(tfm)); |
| 289 | goto out_free_data; |
| 290 | } |
| 291 | |
| 292 | ret = crypto_aead_setauthsize(tfm, authsize); |
Tianjia Zhang | 7b3d526 | 2021-08-13 15:55:06 +0800 | [diff] [blame] | 293 | if (ret) { |
| 294 | pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo, |
| 295 | ret); |
| 296 | goto out_free_tfm; |
| 297 | } |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 298 | |
| 299 | for (i = 0; i < num_mb; ++i) |
| 300 | if (testmgr_alloc_buf(data[i].xbuf)) { |
| 301 | while (i--) |
| 302 | testmgr_free_buf(data[i].xbuf); |
| 303 | goto out_free_tfm; |
| 304 | } |
| 305 | |
| 306 | for (i = 0; i < num_mb; ++i) |
| 307 | if (testmgr_alloc_buf(data[i].axbuf)) { |
| 308 | while (i--) |
| 309 | testmgr_free_buf(data[i].axbuf); |
| 310 | goto out_free_xbuf; |
| 311 | } |
| 312 | |
| 313 | for (i = 0; i < num_mb; ++i) |
| 314 | if (testmgr_alloc_buf(data[i].xoutbuf)) { |
| 315 | while (i--) |
Colin Ian King | c6ba4f3 | 2018-01-02 15:43:04 +0000 | [diff] [blame] | 316 | testmgr_free_buf(data[i].xoutbuf); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 317 | goto out_free_axbuf; |
| 318 | } |
| 319 | |
| 320 | for (i = 0; i < num_mb; ++i) { |
| 321 | data[i].req = aead_request_alloc(tfm, GFP_KERNEL); |
| 322 | if (!data[i].req) { |
Tianjia Zhang | 7b3d526 | 2021-08-13 15:55:06 +0800 | [diff] [blame] | 323 | pr_err("alg: aead: Failed to allocate request for %s\n", |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 324 | algo); |
| 325 | while (i--) |
| 326 | aead_request_free(data[i].req); |
| 327 | goto out_free_xoutbuf; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | for (i = 0; i < num_mb; ++i) { |
| 332 | crypto_init_wait(&data[i].wait); |
| 333 | aead_request_set_callback(data[i].req, |
| 334 | CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 335 | crypto_req_done, &data[i].wait); |
| 336 | } |
| 337 | |
| 338 | pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo, |
| 339 | get_driver_name(crypto_aead, tfm), e); |
| 340 | |
| 341 | i = 0; |
| 342 | do { |
| 343 | b_size = aead_sizes; |
| 344 | do { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 345 | int bs = round_up(*b_size, crypto_aead_blocksize(tfm)); |
| 346 | |
| 347 | if (bs + authsize > XBUFSIZE * PAGE_SIZE) { |
Colin Ian King | 38dbe2d | 2018-01-02 09:21:06 +0000 | [diff] [blame] | 348 | pr_err("template (%u) too big for buffer (%lu)\n", |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 349 | authsize + bs, |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 350 | XBUFSIZE * PAGE_SIZE); |
| 351 | goto out; |
| 352 | } |
| 353 | |
| 354 | pr_info("test %u (%d bit key, %d byte blocks): ", i, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 355 | *keysize * 8, bs); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 356 | |
| 357 | /* Set up tfm global state, i.e. the key */ |
| 358 | |
| 359 | memset(tvmem[0], 0xff, PAGE_SIZE); |
| 360 | key = tvmem[0]; |
| 361 | for (j = 0; j < tcount; j++) { |
| 362 | if (template[j].klen == *keysize) { |
| 363 | key = template[j].key; |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | crypto_aead_clear_flags(tfm, ~0); |
| 369 | |
| 370 | ret = crypto_aead_setkey(tfm, key, *keysize); |
| 371 | if (ret) { |
| 372 | pr_err("setkey() failed flags=%x\n", |
| 373 | crypto_aead_get_flags(tfm)); |
| 374 | goto out; |
| 375 | } |
| 376 | |
| 377 | iv_len = crypto_aead_ivsize(tfm); |
| 378 | if (iv_len) |
| 379 | memset(iv, 0xff, iv_len); |
| 380 | |
| 381 | /* Now setup per request stuff, i.e. buffers */ |
| 382 | |
| 383 | for (j = 0; j < num_mb; ++j) { |
| 384 | struct test_mb_aead_data *cur = &data[j]; |
| 385 | |
| 386 | assoc = cur->axbuf[0]; |
| 387 | memset(assoc, 0xff, aad_size); |
| 388 | |
| 389 | sg_init_aead(cur->sg, cur->xbuf, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 390 | bs + (enc ? 0 : authsize), |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 391 | assoc, aad_size); |
| 392 | |
| 393 | sg_init_aead(cur->sgout, cur->xoutbuf, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 394 | bs + (enc ? authsize : 0), |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 395 | assoc, aad_size); |
| 396 | |
| 397 | aead_request_set_ad(cur->req, aad_size); |
| 398 | |
| 399 | if (!enc) { |
| 400 | |
| 401 | aead_request_set_crypt(cur->req, |
| 402 | cur->sgout, |
| 403 | cur->sg, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 404 | bs, iv); |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 405 | ret = crypto_aead_encrypt(cur->req); |
| 406 | ret = do_one_aead_op(cur->req, ret); |
| 407 | |
| 408 | if (ret) { |
Randy Dunlap | 129a4db | 2020-07-30 19:39:24 -0700 | [diff] [blame] | 409 | pr_err("calculating auth failed (%d)\n", |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 410 | ret); |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | aead_request_set_crypt(cur->req, cur->sg, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 416 | cur->sgout, bs + |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 417 | (enc ? 0 : authsize), |
| 418 | iv); |
| 419 | |
| 420 | } |
| 421 | |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 422 | if (secs) { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 423 | ret = test_mb_aead_jiffies(data, enc, bs, |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 424 | secs, num_mb); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 425 | cond_resched(); |
| 426 | } else { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 427 | ret = test_mb_aead_cycles(data, enc, bs, |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 428 | num_mb); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 429 | } |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 430 | |
| 431 | if (ret) { |
| 432 | pr_err("%s() failed return code=%d\n", e, ret); |
| 433 | break; |
| 434 | } |
| 435 | b_size++; |
| 436 | i++; |
| 437 | } while (*b_size); |
| 438 | keysize++; |
| 439 | } while (*keysize); |
| 440 | |
| 441 | out: |
| 442 | for (i = 0; i < num_mb; ++i) |
| 443 | aead_request_free(data[i].req); |
| 444 | out_free_xoutbuf: |
| 445 | for (i = 0; i < num_mb; ++i) |
| 446 | testmgr_free_buf(data[i].xoutbuf); |
| 447 | out_free_axbuf: |
| 448 | for (i = 0; i < num_mb; ++i) |
| 449 | testmgr_free_buf(data[i].axbuf); |
| 450 | out_free_xbuf: |
| 451 | for (i = 0; i < num_mb; ++i) |
| 452 | testmgr_free_buf(data[i].xbuf); |
| 453 | out_free_tfm: |
| 454 | crypto_free_aead(tfm); |
| 455 | out_free_data: |
| 456 | kfree(data); |
| 457 | out_free_iv: |
| 458 | kfree(iv); |
| 459 | } |
| 460 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 461 | static int test_aead_jiffies(struct aead_request *req, int enc, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 462 | int blen, int secs) |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 463 | { |
| 464 | unsigned long start, end; |
| 465 | int bcount; |
| 466 | int ret; |
| 467 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 468 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 469 | time_before(jiffies, end); bcount++) { |
| 470 | if (enc) |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 471 | ret = do_one_aead_op(req, crypto_aead_encrypt(req)); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 472 | else |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 473 | ret = do_one_aead_op(req, crypto_aead_decrypt(req)); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 474 | |
| 475 | if (ret) |
| 476 | return ret; |
| 477 | } |
| 478 | |
Ard Biesheuvel | 303fd3e | 2020-12-08 15:34:41 +0100 | [diff] [blame] | 479 | pr_cont("%d operations in %d seconds (%llu bytes)\n", |
| 480 | bcount, secs, (u64)bcount * blen); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | static int test_aead_cycles(struct aead_request *req, int enc, int blen) |
| 485 | { |
| 486 | unsigned long cycles = 0; |
| 487 | int ret = 0; |
| 488 | int i; |
| 489 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 490 | /* Warm-up run. */ |
| 491 | for (i = 0; i < 4; i++) { |
| 492 | if (enc) |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 493 | ret = do_one_aead_op(req, crypto_aead_encrypt(req)); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 494 | else |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 495 | ret = do_one_aead_op(req, crypto_aead_decrypt(req)); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 496 | |
| 497 | if (ret) |
| 498 | goto out; |
| 499 | } |
| 500 | |
| 501 | /* The real thing. */ |
| 502 | for (i = 0; i < 8; i++) { |
| 503 | cycles_t start, end; |
| 504 | |
| 505 | start = get_cycles(); |
| 506 | if (enc) |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 507 | ret = do_one_aead_op(req, crypto_aead_encrypt(req)); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 508 | else |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 509 | ret = do_one_aead_op(req, crypto_aead_decrypt(req)); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 510 | end = get_cycles(); |
| 511 | |
| 512 | if (ret) |
| 513 | goto out; |
| 514 | |
| 515 | cycles += end - start; |
| 516 | } |
| 517 | |
| 518 | out: |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 519 | if (ret == 0) |
| 520 | printk("1 operation in %lu cycles (%d bytes)\n", |
| 521 | (cycles + 4) / 8, blen); |
| 522 | |
| 523 | return ret; |
| 524 | } |
| 525 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 526 | static void test_aead_speed(const char *algo, int enc, unsigned int secs, |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 527 | struct aead_speed_template *template, |
| 528 | unsigned int tcount, u8 authsize, |
| 529 | unsigned int aad_size, u8 *keysize) |
| 530 | { |
| 531 | unsigned int i, j; |
| 532 | struct crypto_aead *tfm; |
| 533 | int ret = -ENOMEM; |
| 534 | const char *key; |
| 535 | struct aead_request *req; |
| 536 | struct scatterlist *sg; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 537 | struct scatterlist *sgout; |
| 538 | const char *e; |
| 539 | void *assoc; |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 540 | char *iv; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 541 | char *xbuf[XBUFSIZE]; |
| 542 | char *xoutbuf[XBUFSIZE]; |
| 543 | char *axbuf[XBUFSIZE]; |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 544 | const int *b_size; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 545 | unsigned int iv_len; |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 546 | struct crypto_wait wait; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 547 | |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 548 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
| 549 | if (!iv) |
| 550 | return; |
| 551 | |
Christian Engelmayer | ac5f863 | 2014-04-21 20:45:59 +0200 | [diff] [blame] | 552 | if (aad_size >= PAGE_SIZE) { |
| 553 | pr_err("associate data length (%u) too big\n", aad_size); |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 554 | goto out_noxbuf; |
Christian Engelmayer | ac5f863 | 2014-04-21 20:45:59 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 557 | if (enc == ENCRYPT) |
| 558 | e = "encryption"; |
| 559 | else |
| 560 | e = "decryption"; |
| 561 | |
| 562 | if (testmgr_alloc_buf(xbuf)) |
| 563 | goto out_noxbuf; |
| 564 | if (testmgr_alloc_buf(axbuf)) |
| 565 | goto out_noaxbuf; |
| 566 | if (testmgr_alloc_buf(xoutbuf)) |
| 567 | goto out_nooutbuf; |
| 568 | |
Herbert Xu | a3f2185 | 2015-05-27 16:03:51 +0800 | [diff] [blame] | 569 | sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 570 | if (!sg) |
| 571 | goto out_nosg; |
Herbert Xu | a3f2185 | 2015-05-27 16:03:51 +0800 | [diff] [blame] | 572 | sgout = &sg[9]; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 573 | |
Herbert Xu | 5e4b8c1 | 2015-08-13 17:29:06 +0800 | [diff] [blame] | 574 | tfm = crypto_alloc_aead(algo, 0, 0); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 575 | if (IS_ERR(tfm)) { |
| 576 | pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo, |
| 577 | PTR_ERR(tfm)); |
Christian Engelmayer | a2ea6ed | 2014-04-21 20:46:40 +0200 | [diff] [blame] | 578 | goto out_notfm; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 579 | } |
| 580 | |
Tianjia Zhang | 7b3d526 | 2021-08-13 15:55:06 +0800 | [diff] [blame] | 581 | ret = crypto_aead_setauthsize(tfm, authsize); |
| 582 | if (ret) { |
| 583 | pr_err("alg: aead: Failed to setauthsize for %s: %d\n", algo, |
| 584 | ret); |
| 585 | goto out_noreq; |
| 586 | } |
| 587 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 588 | crypto_init_wait(&wait); |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 589 | printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, |
| 590 | get_driver_name(crypto_aead, tfm), e); |
| 591 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 592 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 593 | if (!req) { |
| 594 | pr_err("alg: aead: Failed to allocate request for %s\n", |
| 595 | algo); |
Christian Engelmayer | 6af1f93 | 2014-04-21 20:47:05 +0200 | [diff] [blame] | 596 | goto out_noreq; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 599 | aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 600 | crypto_req_done, &wait); |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 601 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 602 | i = 0; |
| 603 | do { |
| 604 | b_size = aead_sizes; |
| 605 | do { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 606 | u32 bs = round_up(*b_size, crypto_aead_blocksize(tfm)); |
| 607 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 608 | assoc = axbuf[0]; |
Christian Engelmayer | ac5f863 | 2014-04-21 20:45:59 +0200 | [diff] [blame] | 609 | memset(assoc, 0xff, aad_size); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 610 | |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 611 | if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) { |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 612 | pr_err("template (%u) too big for tvmem (%lu)\n", |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 613 | *keysize + bs, |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 614 | TVMEMSIZE * PAGE_SIZE); |
| 615 | goto out; |
| 616 | } |
| 617 | |
| 618 | key = tvmem[0]; |
| 619 | for (j = 0; j < tcount; j++) { |
| 620 | if (template[j].klen == *keysize) { |
| 621 | key = template[j].key; |
| 622 | break; |
| 623 | } |
| 624 | } |
Tianjia Zhang | 7b3d526 | 2021-08-13 15:55:06 +0800 | [diff] [blame] | 625 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 626 | ret = crypto_aead_setkey(tfm, key, *keysize); |
Tianjia Zhang | 7b3d526 | 2021-08-13 15:55:06 +0800 | [diff] [blame] | 627 | if (ret) { |
| 628 | pr_err("setkey() failed flags=%x: %d\n", |
| 629 | crypto_aead_get_flags(tfm), ret); |
| 630 | goto out; |
| 631 | } |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 632 | |
| 633 | iv_len = crypto_aead_ivsize(tfm); |
| 634 | if (iv_len) |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 635 | memset(iv, 0xff, iv_len); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 636 | |
| 637 | crypto_aead_clear_flags(tfm, ~0); |
| 638 | printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ", |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 639 | i, *keysize * 8, bs); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 640 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 641 | memset(tvmem[0], 0xff, PAGE_SIZE); |
| 642 | |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 643 | sg_init_aead(sg, xbuf, bs + (enc ? 0 : authsize), |
Tudor-Dan Ambarus | 5601e01 | 2017-11-14 16:59:15 +0200 | [diff] [blame] | 644 | assoc, aad_size); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 645 | |
Herbert Xu | 3126727 | 2015-06-17 14:05:26 +0800 | [diff] [blame] | 646 | sg_init_aead(sgout, xoutbuf, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 647 | bs + (enc ? authsize : 0), assoc, |
Tudor-Dan Ambarus | 5601e01 | 2017-11-14 16:59:15 +0200 | [diff] [blame] | 648 | aad_size); |
Herbert Xu | 3126727 | 2015-06-17 14:05:26 +0800 | [diff] [blame] | 649 | |
Gilad Ben-Yossef | 4431bd4 | 2017-12-17 08:29:01 +0000 | [diff] [blame] | 650 | aead_request_set_ad(req, aad_size); |
| 651 | |
| 652 | if (!enc) { |
| 653 | |
| 654 | /* |
| 655 | * For decryption we need a proper auth so |
| 656 | * we do the encryption path once with buffers |
| 657 | * reversed (input <-> output) to calculate it |
| 658 | */ |
| 659 | aead_request_set_crypt(req, sgout, sg, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 660 | bs, iv); |
Gilad Ben-Yossef | 4431bd4 | 2017-12-17 08:29:01 +0000 | [diff] [blame] | 661 | ret = do_one_aead_op(req, |
| 662 | crypto_aead_encrypt(req)); |
| 663 | |
| 664 | if (ret) { |
Randy Dunlap | 129a4db | 2020-07-30 19:39:24 -0700 | [diff] [blame] | 665 | pr_err("calculating auth failed (%d)\n", |
Gilad Ben-Yossef | 4431bd4 | 2017-12-17 08:29:01 +0000 | [diff] [blame] | 666 | ret); |
| 667 | break; |
| 668 | } |
| 669 | } |
| 670 | |
Robert Baronescu | 7aacbfc | 2017-10-10 13:22:00 +0300 | [diff] [blame] | 671 | aead_request_set_crypt(req, sg, sgout, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 672 | bs + (enc ? 0 : authsize), |
Robert Baronescu | 7aacbfc | 2017-10-10 13:22:00 +0300 | [diff] [blame] | 673 | iv); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 674 | |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 675 | if (secs) { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 676 | ret = test_aead_jiffies(req, enc, bs, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 677 | secs); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 678 | cond_resched(); |
| 679 | } else { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 680 | ret = test_aead_cycles(req, enc, bs); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 681 | } |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 682 | |
| 683 | if (ret) { |
| 684 | pr_err("%s() failed return code=%d\n", e, ret); |
| 685 | break; |
| 686 | } |
| 687 | b_size++; |
| 688 | i++; |
| 689 | } while (*b_size); |
| 690 | keysize++; |
| 691 | } while (*keysize); |
| 692 | |
| 693 | out: |
Christian Engelmayer | 6af1f93 | 2014-04-21 20:47:05 +0200 | [diff] [blame] | 694 | aead_request_free(req); |
| 695 | out_noreq: |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 696 | crypto_free_aead(tfm); |
Christian Engelmayer | a2ea6ed | 2014-04-21 20:46:40 +0200 | [diff] [blame] | 697 | out_notfm: |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 698 | kfree(sg); |
| 699 | out_nosg: |
| 700 | testmgr_free_buf(xoutbuf); |
| 701 | out_nooutbuf: |
| 702 | testmgr_free_buf(axbuf); |
| 703 | out_noaxbuf: |
| 704 | testmgr_free_buf(xbuf); |
| 705 | out_noxbuf: |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 706 | kfree(iv); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 707 | } |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 708 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 709 | static void test_hash_sg_init(struct scatterlist *sg) |
| 710 | { |
| 711 | int i; |
| 712 | |
| 713 | sg_init_table(sg, TVMEMSIZE); |
| 714 | for (i = 0; i < TVMEMSIZE; i++) { |
| 715 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); |
| 716 | memset(tvmem[i], 0xff, PAGE_SIZE); |
| 717 | } |
| 718 | } |
| 719 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 720 | static inline int do_one_ahash_op(struct ahash_request *req, int ret) |
| 721 | { |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 722 | struct crypto_wait *wait = req->base.data; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 723 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 724 | return crypto_wait_req(ret, wait); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 725 | } |
| 726 | |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 727 | struct test_mb_ahash_data { |
Gilad Ben-Yossef | 7c3f132 | 2017-12-17 08:29:00 +0000 | [diff] [blame] | 728 | struct scatterlist sg[XBUFSIZE]; |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 729 | char result[64]; |
| 730 | struct ahash_request *req; |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 731 | struct crypto_wait wait; |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 732 | char *xbuf[XBUFSIZE]; |
| 733 | }; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 734 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 735 | static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb, |
| 736 | int *rc) |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 737 | { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 738 | int i, err = 0; |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 739 | |
| 740 | /* Fire up a bunch of concurrent requests */ |
| 741 | for (i = 0; i < num_mb; i++) |
| 742 | rc[i] = crypto_ahash_digest(data[i].req); |
| 743 | |
| 744 | /* Wait for all requests to finish */ |
| 745 | for (i = 0; i < num_mb; i++) { |
| 746 | rc[i] = crypto_wait_req(rc[i], &data[i].wait); |
| 747 | |
| 748 | if (rc[i]) { |
| 749 | pr_info("concurrent request %d error %d\n", i, rc[i]); |
| 750 | err = rc[i]; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | return err; |
| 755 | } |
| 756 | |
| 757 | static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen, |
| 758 | int secs, u32 num_mb) |
| 759 | { |
| 760 | unsigned long start, end; |
| 761 | int bcount; |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 762 | int ret = 0; |
| 763 | int *rc; |
| 764 | |
| 765 | rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); |
| 766 | if (!rc) |
| 767 | return -ENOMEM; |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 768 | |
| 769 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
| 770 | time_before(jiffies, end); bcount++) { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 771 | ret = do_mult_ahash_op(data, num_mb, rc); |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 772 | if (ret) |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 773 | goto out; |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Ard Biesheuvel | 303fd3e | 2020-12-08 15:34:41 +0100 | [diff] [blame] | 776 | pr_cont("%d operations in %d seconds (%llu bytes)\n", |
| 777 | bcount * num_mb, secs, (u64)bcount * blen * num_mb); |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 778 | |
| 779 | out: |
| 780 | kfree(rc); |
| 781 | return ret; |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen, |
| 785 | u32 num_mb) |
| 786 | { |
| 787 | unsigned long cycles = 0; |
| 788 | int ret = 0; |
| 789 | int i; |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 790 | int *rc; |
| 791 | |
| 792 | rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); |
| 793 | if (!rc) |
| 794 | return -ENOMEM; |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 795 | |
| 796 | /* Warm-up run. */ |
| 797 | for (i = 0; i < 4; i++) { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 798 | ret = do_mult_ahash_op(data, num_mb, rc); |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 799 | if (ret) |
| 800 | goto out; |
| 801 | } |
| 802 | |
| 803 | /* The real thing. */ |
| 804 | for (i = 0; i < 8; i++) { |
| 805 | cycles_t start, end; |
| 806 | |
| 807 | start = get_cycles(); |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 808 | ret = do_mult_ahash_op(data, num_mb, rc); |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 809 | end = get_cycles(); |
| 810 | |
| 811 | if (ret) |
| 812 | goto out; |
| 813 | |
| 814 | cycles += end - start; |
| 815 | } |
| 816 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 817 | pr_cont("1 operation in %lu cycles (%d bytes)\n", |
| 818 | (cycles + 4) / (8 * num_mb), blen); |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 819 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 820 | out: |
| 821 | kfree(rc); |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | static void test_mb_ahash_speed(const char *algo, unsigned int secs, |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 826 | struct hash_speed *speed, u32 num_mb) |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 827 | { |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 828 | struct test_mb_ahash_data *data; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 829 | struct crypto_ahash *tfm; |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 830 | unsigned int i, j, k; |
| 831 | int ret; |
| 832 | |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 833 | data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL); |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 834 | if (!data) |
| 835 | return; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 836 | |
| 837 | tfm = crypto_alloc_ahash(algo, 0, 0); |
| 838 | if (IS_ERR(tfm)) { |
| 839 | pr_err("failed to load transform for %s: %ld\n", |
| 840 | algo, PTR_ERR(tfm)); |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 841 | goto free_data; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 842 | } |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 843 | |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 844 | for (i = 0; i < num_mb; ++i) { |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 845 | if (testmgr_alloc_buf(data[i].xbuf)) |
| 846 | goto out; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 847 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 848 | crypto_init_wait(&data[i].wait); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 849 | |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 850 | data[i].req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 851 | if (!data[i].req) { |
Krzysztof Kozlowski | f83f5b1 | 2016-06-28 09:23:06 +0200 | [diff] [blame] | 852 | pr_err("alg: hash: Failed to allocate request for %s\n", |
| 853 | algo); |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 854 | goto out; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 855 | } |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 856 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 857 | ahash_request_set_callback(data[i].req, 0, crypto_req_done, |
| 858 | &data[i].wait); |
Gilad Ben-Yossef | 7c3f132 | 2017-12-17 08:29:00 +0000 | [diff] [blame] | 859 | |
| 860 | sg_init_table(data[i].sg, XBUFSIZE); |
| 861 | for (j = 0; j < XBUFSIZE; j++) { |
| 862 | sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE); |
| 863 | memset(data[i].xbuf[j], 0xff, PAGE_SIZE); |
| 864 | } |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 867 | pr_info("\ntesting speed of multibuffer %s (%s)\n", algo, |
| 868 | get_driver_name(crypto_ahash, tfm)); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 869 | |
| 870 | for (i = 0; speed[i].blen != 0; i++) { |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 871 | /* For some reason this only tests digests. */ |
| 872 | if (speed[i].blen != speed[i].plen) |
| 873 | continue; |
| 874 | |
Gilad Ben-Yossef | 7c3f132 | 2017-12-17 08:29:00 +0000 | [diff] [blame] | 875 | if (speed[i].blen > XBUFSIZE * PAGE_SIZE) { |
Krzysztof Kozlowski | f83f5b1 | 2016-06-28 09:23:06 +0200 | [diff] [blame] | 876 | pr_err("template (%u) too big for tvmem (%lu)\n", |
Gilad Ben-Yossef | 7c3f132 | 2017-12-17 08:29:00 +0000 | [diff] [blame] | 877 | speed[i].blen, XBUFSIZE * PAGE_SIZE); |
Krzysztof Kozlowski | f83f5b1 | 2016-06-28 09:23:06 +0200 | [diff] [blame] | 878 | goto out; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Herbert Xu | ba974ad | 2020-08-05 15:57:08 +1000 | [diff] [blame] | 881 | if (klen) |
| 882 | crypto_ahash_setkey(tfm, tvmem[0], klen); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 883 | |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 884 | for (k = 0; k < num_mb; k++) |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 885 | ahash_request_set_crypt(data[k].req, data[k].sg, |
| 886 | data[k].result, speed[i].blen); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 887 | |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 888 | pr_info("test%3u " |
| 889 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 890 | i, speed[i].blen, speed[i].plen, |
| 891 | speed[i].blen / speed[i].plen); |
| 892 | |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 893 | if (secs) { |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 894 | ret = test_mb_ahash_jiffies(data, speed[i].blen, secs, |
| 895 | num_mb); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 896 | cond_resched(); |
| 897 | } else { |
Gilad Ben-Yossef | b34a0f67 | 2017-12-17 08:29:03 +0000 | [diff] [blame] | 898 | ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 899 | } |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 900 | |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 901 | |
| 902 | if (ret) { |
| 903 | pr_err("At least one hashing failed ret=%d\n", ret); |
| 904 | break; |
| 905 | } |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 906 | } |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 907 | |
| 908 | out: |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 909 | for (k = 0; k < num_mb; ++k) |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 910 | ahash_request_free(data[k].req); |
| 911 | |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 912 | for (k = 0; k < num_mb; ++k) |
Herbert Xu | 72259de | 2016-06-28 20:33:52 +0800 | [diff] [blame] | 913 | testmgr_free_buf(data[k].xbuf); |
| 914 | |
| 915 | crypto_free_ahash(tfm); |
| 916 | |
| 917 | free_data: |
| 918 | kfree(data); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 919 | } |
| 920 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 921 | static int test_ahash_jiffies_digest(struct ahash_request *req, int blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 922 | char *out, int secs) |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 923 | { |
| 924 | unsigned long start, end; |
| 925 | int bcount; |
| 926 | int ret; |
| 927 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 928 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 929 | time_before(jiffies, end); bcount++) { |
| 930 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); |
| 931 | if (ret) |
| 932 | return ret; |
| 933 | } |
| 934 | |
| 935 | printk("%6u opers/sec, %9lu bytes/sec\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 936 | bcount / secs, ((long)bcount * blen) / secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | static int test_ahash_jiffies(struct ahash_request *req, int blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 942 | int plen, char *out, int secs) |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 943 | { |
| 944 | unsigned long start, end; |
| 945 | int bcount, pcount; |
| 946 | int ret; |
| 947 | |
| 948 | if (plen == blen) |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 949 | return test_ahash_jiffies_digest(req, blen, out, secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 950 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 951 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 952 | time_before(jiffies, end); bcount++) { |
Herbert Xu | 43a9607 | 2015-04-22 11:02:27 +0800 | [diff] [blame] | 953 | ret = do_one_ahash_op(req, crypto_ahash_init(req)); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 954 | if (ret) |
| 955 | return ret; |
| 956 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 957 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); |
| 958 | if (ret) |
| 959 | return ret; |
| 960 | } |
| 961 | /* we assume there is enough space in 'out' for the result */ |
| 962 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); |
| 963 | if (ret) |
| 964 | return ret; |
| 965 | } |
| 966 | |
| 967 | pr_cont("%6u opers/sec, %9lu bytes/sec\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 968 | bcount / secs, ((long)bcount * blen) / secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | static int test_ahash_cycles_digest(struct ahash_request *req, int blen, |
| 974 | char *out) |
| 975 | { |
| 976 | unsigned long cycles = 0; |
| 977 | int ret, i; |
| 978 | |
| 979 | /* Warm-up run. */ |
| 980 | for (i = 0; i < 4; i++) { |
| 981 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); |
| 982 | if (ret) |
| 983 | goto out; |
| 984 | } |
| 985 | |
| 986 | /* The real thing. */ |
| 987 | for (i = 0; i < 8; i++) { |
| 988 | cycles_t start, end; |
| 989 | |
| 990 | start = get_cycles(); |
| 991 | |
| 992 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); |
| 993 | if (ret) |
| 994 | goto out; |
| 995 | |
| 996 | end = get_cycles(); |
| 997 | |
| 998 | cycles += end - start; |
| 999 | } |
| 1000 | |
| 1001 | out: |
| 1002 | if (ret) |
| 1003 | return ret; |
| 1004 | |
| 1005 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", |
| 1006 | cycles / 8, cycles / (8 * blen)); |
| 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | static int test_ahash_cycles(struct ahash_request *req, int blen, |
| 1012 | int plen, char *out) |
| 1013 | { |
| 1014 | unsigned long cycles = 0; |
| 1015 | int i, pcount, ret; |
| 1016 | |
| 1017 | if (plen == blen) |
| 1018 | return test_ahash_cycles_digest(req, blen, out); |
| 1019 | |
| 1020 | /* Warm-up run. */ |
| 1021 | for (i = 0; i < 4; i++) { |
Herbert Xu | 43a9607 | 2015-04-22 11:02:27 +0800 | [diff] [blame] | 1022 | ret = do_one_ahash_op(req, crypto_ahash_init(req)); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1023 | if (ret) |
| 1024 | goto out; |
| 1025 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 1026 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); |
| 1027 | if (ret) |
| 1028 | goto out; |
| 1029 | } |
| 1030 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); |
| 1031 | if (ret) |
| 1032 | goto out; |
| 1033 | } |
| 1034 | |
| 1035 | /* The real thing. */ |
| 1036 | for (i = 0; i < 8; i++) { |
| 1037 | cycles_t start, end; |
| 1038 | |
| 1039 | start = get_cycles(); |
| 1040 | |
Herbert Xu | 43a9607 | 2015-04-22 11:02:27 +0800 | [diff] [blame] | 1041 | ret = do_one_ahash_op(req, crypto_ahash_init(req)); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1042 | if (ret) |
| 1043 | goto out; |
| 1044 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 1045 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); |
| 1046 | if (ret) |
| 1047 | goto out; |
| 1048 | } |
| 1049 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); |
| 1050 | if (ret) |
| 1051 | goto out; |
| 1052 | |
| 1053 | end = get_cycles(); |
| 1054 | |
| 1055 | cycles += end - start; |
| 1056 | } |
| 1057 | |
| 1058 | out: |
| 1059 | if (ret) |
| 1060 | return ret; |
| 1061 | |
| 1062 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", |
| 1063 | cycles / 8, cycles / (8 * blen)); |
| 1064 | |
| 1065 | return 0; |
| 1066 | } |
| 1067 | |
Herbert Xu | 0660511 | 2016-02-01 21:36:49 +0800 | [diff] [blame] | 1068 | static void test_ahash_speed_common(const char *algo, unsigned int secs, |
| 1069 | struct hash_speed *speed, unsigned mask) |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1070 | { |
| 1071 | struct scatterlist sg[TVMEMSIZE]; |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1072 | struct crypto_wait wait; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1073 | struct ahash_request *req; |
| 1074 | struct crypto_ahash *tfm; |
Horia Geant? | f074f7b | 2015-08-27 18:38:36 +0300 | [diff] [blame] | 1075 | char *output; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1076 | int i, ret; |
| 1077 | |
Herbert Xu | 0660511 | 2016-02-01 21:36:49 +0800 | [diff] [blame] | 1078 | tfm = crypto_alloc_ahash(algo, 0, mask); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1079 | if (IS_ERR(tfm)) { |
| 1080 | pr_err("failed to load transform for %s: %ld\n", |
| 1081 | algo, PTR_ERR(tfm)); |
| 1082 | return; |
| 1083 | } |
| 1084 | |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 1085 | printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo, |
| 1086 | get_driver_name(crypto_ahash, tfm)); |
| 1087 | |
Horia Geant? | f074f7b | 2015-08-27 18:38:36 +0300 | [diff] [blame] | 1088 | if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) { |
| 1089 | pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm), |
| 1090 | MAX_DIGEST_SIZE); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1091 | goto out; |
| 1092 | } |
| 1093 | |
| 1094 | test_hash_sg_init(sg); |
| 1095 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 1096 | if (!req) { |
| 1097 | pr_err("ahash request allocation failure\n"); |
| 1098 | goto out; |
| 1099 | } |
| 1100 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1101 | crypto_init_wait(&wait); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1102 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1103 | crypto_req_done, &wait); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1104 | |
Horia Geant? | f074f7b | 2015-08-27 18:38:36 +0300 | [diff] [blame] | 1105 | output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); |
| 1106 | if (!output) |
| 1107 | goto out_nomem; |
| 1108 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1109 | for (i = 0; speed[i].blen != 0; i++) { |
| 1110 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
| 1111 | pr_err("template (%u) too big for tvmem (%lu)\n", |
| 1112 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
| 1113 | break; |
| 1114 | } |
| 1115 | |
Herbert Xu | ba974ad | 2020-08-05 15:57:08 +1000 | [diff] [blame] | 1116 | if (klen) |
| 1117 | crypto_ahash_setkey(tfm, tvmem[0], klen); |
Horia Geantă | 331351f | 2018-09-12 16:20:48 +0300 | [diff] [blame] | 1118 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1119 | pr_info("test%3u " |
| 1120 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", |
| 1121 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
| 1122 | |
| 1123 | ahash_request_set_crypt(req, sg, output, speed[i].plen); |
| 1124 | |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1125 | if (secs) { |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1126 | ret = test_ahash_jiffies(req, speed[i].blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1127 | speed[i].plen, output, secs); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1128 | cond_resched(); |
| 1129 | } else { |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1130 | ret = test_ahash_cycles(req, speed[i].blen, |
| 1131 | speed[i].plen, output); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1132 | } |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1133 | |
| 1134 | if (ret) { |
| 1135 | pr_err("hashing failed ret=%d\n", ret); |
| 1136 | break; |
| 1137 | } |
| 1138 | } |
| 1139 | |
Horia Geant? | f074f7b | 2015-08-27 18:38:36 +0300 | [diff] [blame] | 1140 | kfree(output); |
| 1141 | |
| 1142 | out_nomem: |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1143 | ahash_request_free(req); |
| 1144 | |
| 1145 | out: |
| 1146 | crypto_free_ahash(tfm); |
| 1147 | } |
| 1148 | |
Herbert Xu | 0660511 | 2016-02-01 21:36:49 +0800 | [diff] [blame] | 1149 | static void test_ahash_speed(const char *algo, unsigned int secs, |
| 1150 | struct hash_speed *speed) |
| 1151 | { |
| 1152 | return test_ahash_speed_common(algo, secs, speed, 0); |
| 1153 | } |
| 1154 | |
| 1155 | static void test_hash_speed(const char *algo, unsigned int secs, |
| 1156 | struct hash_speed *speed) |
| 1157 | { |
| 1158 | return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC); |
| 1159 | } |
| 1160 | |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1161 | struct test_mb_skcipher_data { |
| 1162 | struct scatterlist sg[XBUFSIZE]; |
| 1163 | struct skcipher_request *req; |
| 1164 | struct crypto_wait wait; |
| 1165 | char *xbuf[XBUFSIZE]; |
| 1166 | }; |
| 1167 | |
| 1168 | static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc, |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1169 | u32 num_mb, int *rc) |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1170 | { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1171 | int i, err = 0; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1172 | |
| 1173 | /* Fire up a bunch of concurrent requests */ |
| 1174 | for (i = 0; i < num_mb; i++) { |
| 1175 | if (enc == ENCRYPT) |
| 1176 | rc[i] = crypto_skcipher_encrypt(data[i].req); |
| 1177 | else |
| 1178 | rc[i] = crypto_skcipher_decrypt(data[i].req); |
| 1179 | } |
| 1180 | |
| 1181 | /* Wait for all requests to finish */ |
| 1182 | for (i = 0; i < num_mb; i++) { |
| 1183 | rc[i] = crypto_wait_req(rc[i], &data[i].wait); |
| 1184 | |
| 1185 | if (rc[i]) { |
| 1186 | pr_info("concurrent request %d error %d\n", i, rc[i]); |
| 1187 | err = rc[i]; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | return err; |
| 1192 | } |
| 1193 | |
| 1194 | static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc, |
| 1195 | int blen, int secs, u32 num_mb) |
| 1196 | { |
| 1197 | unsigned long start, end; |
| 1198 | int bcount; |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1199 | int ret = 0; |
| 1200 | int *rc; |
| 1201 | |
| 1202 | rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); |
| 1203 | if (!rc) |
| 1204 | return -ENOMEM; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1205 | |
| 1206 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
| 1207 | time_before(jiffies, end); bcount++) { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1208 | ret = do_mult_acipher_op(data, enc, num_mb, rc); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1209 | if (ret) |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1210 | goto out; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Ard Biesheuvel | 303fd3e | 2020-12-08 15:34:41 +0100 | [diff] [blame] | 1213 | pr_cont("%d operations in %d seconds (%llu bytes)\n", |
| 1214 | bcount * num_mb, secs, (u64)bcount * blen * num_mb); |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1215 | |
| 1216 | out: |
| 1217 | kfree(rc); |
| 1218 | return ret; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc, |
| 1222 | int blen, u32 num_mb) |
| 1223 | { |
| 1224 | unsigned long cycles = 0; |
| 1225 | int ret = 0; |
| 1226 | int i; |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1227 | int *rc; |
| 1228 | |
| 1229 | rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); |
| 1230 | if (!rc) |
| 1231 | return -ENOMEM; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1232 | |
| 1233 | /* Warm-up run. */ |
| 1234 | for (i = 0; i < 4; i++) { |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1235 | ret = do_mult_acipher_op(data, enc, num_mb, rc); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1236 | if (ret) |
| 1237 | goto out; |
| 1238 | } |
| 1239 | |
| 1240 | /* The real thing. */ |
| 1241 | for (i = 0; i < 8; i++) { |
| 1242 | cycles_t start, end; |
| 1243 | |
| 1244 | start = get_cycles(); |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1245 | ret = do_mult_acipher_op(data, enc, num_mb, rc); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1246 | end = get_cycles(); |
| 1247 | |
| 1248 | if (ret) |
| 1249 | goto out; |
| 1250 | |
| 1251 | cycles += end - start; |
| 1252 | } |
| 1253 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1254 | pr_cont("1 operation in %lu cycles (%d bytes)\n", |
| 1255 | (cycles + 4) / (8 * num_mb), blen); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1256 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1257 | out: |
| 1258 | kfree(rc); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1259 | return ret; |
| 1260 | } |
| 1261 | |
| 1262 | static void test_mb_skcipher_speed(const char *algo, int enc, int secs, |
| 1263 | struct cipher_speed_template *template, |
| 1264 | unsigned int tcount, u8 *keysize, u32 num_mb) |
| 1265 | { |
| 1266 | struct test_mb_skcipher_data *data; |
| 1267 | struct crypto_skcipher *tfm; |
| 1268 | unsigned int i, j, iv_len; |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1269 | const int *b_size; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1270 | const char *key; |
| 1271 | const char *e; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1272 | char iv[128]; |
| 1273 | int ret; |
| 1274 | |
| 1275 | if (enc == ENCRYPT) |
| 1276 | e = "encryption"; |
| 1277 | else |
| 1278 | e = "decryption"; |
| 1279 | |
| 1280 | data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL); |
| 1281 | if (!data) |
| 1282 | return; |
| 1283 | |
| 1284 | tfm = crypto_alloc_skcipher(algo, 0, 0); |
| 1285 | if (IS_ERR(tfm)) { |
| 1286 | pr_err("failed to load transform for %s: %ld\n", |
| 1287 | algo, PTR_ERR(tfm)); |
| 1288 | goto out_free_data; |
| 1289 | } |
| 1290 | |
| 1291 | for (i = 0; i < num_mb; ++i) |
| 1292 | if (testmgr_alloc_buf(data[i].xbuf)) { |
| 1293 | while (i--) |
| 1294 | testmgr_free_buf(data[i].xbuf); |
| 1295 | goto out_free_tfm; |
| 1296 | } |
| 1297 | |
| 1298 | |
| 1299 | for (i = 0; i < num_mb; ++i) |
| 1300 | if (testmgr_alloc_buf(data[i].xbuf)) { |
| 1301 | while (i--) |
| 1302 | testmgr_free_buf(data[i].xbuf); |
| 1303 | goto out_free_tfm; |
| 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | for (i = 0; i < num_mb; ++i) { |
| 1308 | data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL); |
| 1309 | if (!data[i].req) { |
| 1310 | pr_err("alg: skcipher: Failed to allocate request for %s\n", |
| 1311 | algo); |
| 1312 | while (i--) |
| 1313 | skcipher_request_free(data[i].req); |
| 1314 | goto out_free_xbuf; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | for (i = 0; i < num_mb; ++i) { |
| 1319 | skcipher_request_set_callback(data[i].req, |
| 1320 | CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 1321 | crypto_req_done, &data[i].wait); |
| 1322 | crypto_init_wait(&data[i].wait); |
| 1323 | } |
| 1324 | |
| 1325 | pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo, |
| 1326 | get_driver_name(crypto_skcipher, tfm), e); |
| 1327 | |
| 1328 | i = 0; |
| 1329 | do { |
| 1330 | b_size = block_sizes; |
| 1331 | do { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1332 | u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm)); |
| 1333 | |
| 1334 | if (bs > XBUFSIZE * PAGE_SIZE) { |
Colin Ian King | 38dbe2d | 2018-01-02 09:21:06 +0000 | [diff] [blame] | 1335 | pr_err("template (%u) too big for buffer (%lu)\n", |
Horia Geantă | 3ae88f6 | 2021-10-15 10:39:18 +0300 | [diff] [blame] | 1336 | bs, XBUFSIZE * PAGE_SIZE); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1337 | goto out; |
| 1338 | } |
| 1339 | |
| 1340 | pr_info("test %u (%d bit key, %d byte blocks): ", i, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1341 | *keysize * 8, bs); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1342 | |
| 1343 | /* Set up tfm global state, i.e. the key */ |
| 1344 | |
| 1345 | memset(tvmem[0], 0xff, PAGE_SIZE); |
| 1346 | key = tvmem[0]; |
| 1347 | for (j = 0; j < tcount; j++) { |
| 1348 | if (template[j].klen == *keysize) { |
| 1349 | key = template[j].key; |
| 1350 | break; |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | crypto_skcipher_clear_flags(tfm, ~0); |
| 1355 | |
| 1356 | ret = crypto_skcipher_setkey(tfm, key, *keysize); |
| 1357 | if (ret) { |
| 1358 | pr_err("setkey() failed flags=%x\n", |
| 1359 | crypto_skcipher_get_flags(tfm)); |
| 1360 | goto out; |
| 1361 | } |
| 1362 | |
| 1363 | iv_len = crypto_skcipher_ivsize(tfm); |
| 1364 | if (iv_len) |
| 1365 | memset(&iv, 0xff, iv_len); |
| 1366 | |
| 1367 | /* Now setup per request stuff, i.e. buffers */ |
| 1368 | |
| 1369 | for (j = 0; j < num_mb; ++j) { |
| 1370 | struct test_mb_skcipher_data *cur = &data[j]; |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1371 | unsigned int k = bs; |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1372 | unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE); |
| 1373 | unsigned int p = 0; |
| 1374 | |
| 1375 | sg_init_table(cur->sg, pages); |
| 1376 | |
| 1377 | while (k > PAGE_SIZE) { |
| 1378 | sg_set_buf(cur->sg + p, cur->xbuf[p], |
| 1379 | PAGE_SIZE); |
| 1380 | memset(cur->xbuf[p], 0xff, PAGE_SIZE); |
| 1381 | p++; |
| 1382 | k -= PAGE_SIZE; |
| 1383 | } |
| 1384 | |
| 1385 | sg_set_buf(cur->sg + p, cur->xbuf[p], k); |
| 1386 | memset(cur->xbuf[p], 0xff, k); |
| 1387 | |
| 1388 | skcipher_request_set_crypt(cur->req, cur->sg, |
Horia Geantă | 3ae88f6 | 2021-10-15 10:39:18 +0300 | [diff] [blame] | 1389 | cur->sg, bs, iv); |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1392 | if (secs) { |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1393 | ret = test_mb_acipher_jiffies(data, enc, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1394 | bs, secs, |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1395 | num_mb); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1396 | cond_resched(); |
| 1397 | } else { |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1398 | ret = test_mb_acipher_cycles(data, enc, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1399 | bs, num_mb); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1400 | } |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 1401 | |
| 1402 | if (ret) { |
| 1403 | pr_err("%s() failed flags=%x\n", e, |
| 1404 | crypto_skcipher_get_flags(tfm)); |
| 1405 | break; |
| 1406 | } |
| 1407 | b_size++; |
| 1408 | i++; |
| 1409 | } while (*b_size); |
| 1410 | keysize++; |
| 1411 | } while (*keysize); |
| 1412 | |
| 1413 | out: |
| 1414 | for (i = 0; i < num_mb; ++i) |
| 1415 | skcipher_request_free(data[i].req); |
| 1416 | out_free_xbuf: |
| 1417 | for (i = 0; i < num_mb; ++i) |
| 1418 | testmgr_free_buf(data[i].xbuf); |
| 1419 | out_free_tfm: |
| 1420 | crypto_free_skcipher(tfm); |
| 1421 | out_free_data: |
| 1422 | kfree(data); |
| 1423 | } |
| 1424 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1425 | static inline int do_one_acipher_op(struct skcipher_request *req, int ret) |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1426 | { |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1427 | struct crypto_wait *wait = req->base.data; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1428 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1429 | return crypto_wait_req(ret, wait); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1430 | } |
| 1431 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1432 | static int test_acipher_jiffies(struct skcipher_request *req, int enc, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1433 | int blen, int secs) |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1434 | { |
| 1435 | unsigned long start, end; |
| 1436 | int bcount; |
| 1437 | int ret; |
| 1438 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1439 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1440 | time_before(jiffies, end); bcount++) { |
| 1441 | if (enc) |
| 1442 | ret = do_one_acipher_op(req, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1443 | crypto_skcipher_encrypt(req)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1444 | else |
| 1445 | ret = do_one_acipher_op(req, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1446 | crypto_skcipher_decrypt(req)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1447 | |
| 1448 | if (ret) |
| 1449 | return ret; |
| 1450 | } |
| 1451 | |
Ard Biesheuvel | 303fd3e | 2020-12-08 15:34:41 +0100 | [diff] [blame] | 1452 | pr_cont("%d operations in %d seconds (%llu bytes)\n", |
| 1453 | bcount, secs, (u64)bcount * blen); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1454 | return 0; |
| 1455 | } |
| 1456 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1457 | static int test_acipher_cycles(struct skcipher_request *req, int enc, |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1458 | int blen) |
| 1459 | { |
| 1460 | unsigned long cycles = 0; |
| 1461 | int ret = 0; |
| 1462 | int i; |
| 1463 | |
| 1464 | /* Warm-up run. */ |
| 1465 | for (i = 0; i < 4; i++) { |
| 1466 | if (enc) |
| 1467 | ret = do_one_acipher_op(req, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1468 | crypto_skcipher_encrypt(req)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1469 | else |
| 1470 | ret = do_one_acipher_op(req, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1471 | crypto_skcipher_decrypt(req)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1472 | |
| 1473 | if (ret) |
| 1474 | goto out; |
| 1475 | } |
| 1476 | |
| 1477 | /* The real thing. */ |
| 1478 | for (i = 0; i < 8; i++) { |
| 1479 | cycles_t start, end; |
| 1480 | |
| 1481 | start = get_cycles(); |
| 1482 | if (enc) |
| 1483 | ret = do_one_acipher_op(req, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1484 | crypto_skcipher_encrypt(req)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1485 | else |
| 1486 | ret = do_one_acipher_op(req, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1487 | crypto_skcipher_decrypt(req)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1488 | end = get_cycles(); |
| 1489 | |
| 1490 | if (ret) |
| 1491 | goto out; |
| 1492 | |
| 1493 | cycles += end - start; |
| 1494 | } |
| 1495 | |
| 1496 | out: |
| 1497 | if (ret == 0) |
| 1498 | pr_cont("1 operation in %lu cycles (%d bytes)\n", |
| 1499 | (cycles + 4) / 8, blen); |
| 1500 | |
| 1501 | return ret; |
| 1502 | } |
| 1503 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1504 | static void test_skcipher_speed(const char *algo, int enc, unsigned int secs, |
| 1505 | struct cipher_speed_template *template, |
| 1506 | unsigned int tcount, u8 *keysize, bool async) |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1507 | { |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1508 | unsigned int ret, i, j, k, iv_len; |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1509 | struct crypto_wait wait; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1510 | const char *key; |
| 1511 | char iv[128]; |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1512 | struct skcipher_request *req; |
| 1513 | struct crypto_skcipher *tfm; |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1514 | const int *b_size; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1515 | const char *e; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1516 | |
| 1517 | if (enc == ENCRYPT) |
| 1518 | e = "encryption"; |
| 1519 | else |
| 1520 | e = "decryption"; |
| 1521 | |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1522 | crypto_init_wait(&wait); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1523 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1524 | tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1525 | |
| 1526 | if (IS_ERR(tfm)) { |
| 1527 | pr_err("failed to load transform for %s: %ld\n", algo, |
| 1528 | PTR_ERR(tfm)); |
| 1529 | return; |
| 1530 | } |
| 1531 | |
Horia Geantă | 8e3b7fd | 2020-02-05 12:19:58 +0200 | [diff] [blame] | 1532 | pr_info("\ntesting speed of %s %s (%s) %s\n", async ? "async" : "sync", |
| 1533 | algo, get_driver_name(crypto_skcipher, tfm), e); |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 1534 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1535 | req = skcipher_request_alloc(tfm, GFP_KERNEL); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1536 | if (!req) { |
| 1537 | pr_err("tcrypt: skcipher: Failed to allocate request for %s\n", |
| 1538 | algo); |
| 1539 | goto out; |
| 1540 | } |
| 1541 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1542 | skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
Gilad Ben-Yossef | 6467104 | 2017-10-18 08:00:48 +0100 | [diff] [blame] | 1543 | crypto_req_done, &wait); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1544 | |
| 1545 | i = 0; |
| 1546 | do { |
| 1547 | b_size = block_sizes; |
| 1548 | |
| 1549 | do { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1550 | u32 bs = round_up(*b_size, crypto_skcipher_blocksize(tfm)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1551 | struct scatterlist sg[TVMEMSIZE]; |
| 1552 | |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1553 | if ((*keysize + bs) > TVMEMSIZE * PAGE_SIZE) { |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1554 | pr_err("template (%u) too big for " |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1555 | "tvmem (%lu)\n", *keysize + bs, |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1556 | TVMEMSIZE * PAGE_SIZE); |
| 1557 | goto out_free_req; |
| 1558 | } |
| 1559 | |
| 1560 | pr_info("test %u (%d bit key, %d byte blocks): ", i, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1561 | *keysize * 8, bs); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1562 | |
| 1563 | memset(tvmem[0], 0xff, PAGE_SIZE); |
| 1564 | |
| 1565 | /* set key, plain text and IV */ |
| 1566 | key = tvmem[0]; |
| 1567 | for (j = 0; j < tcount; j++) { |
| 1568 | if (template[j].klen == *keysize) { |
| 1569 | key = template[j].key; |
| 1570 | break; |
| 1571 | } |
| 1572 | } |
| 1573 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1574 | crypto_skcipher_clear_flags(tfm, ~0); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1575 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1576 | ret = crypto_skcipher_setkey(tfm, key, *keysize); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1577 | if (ret) { |
| 1578 | pr_err("setkey() failed flags=%x\n", |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1579 | crypto_skcipher_get_flags(tfm)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1580 | goto out_free_req; |
| 1581 | } |
| 1582 | |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1583 | k = *keysize + bs; |
Horia Geant? | 007ee8d | 2015-03-09 16:14:58 +0200 | [diff] [blame] | 1584 | sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE)); |
| 1585 | |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1586 | if (k > PAGE_SIZE) { |
| 1587 | sg_set_buf(sg, tvmem[0] + *keysize, |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1588 | PAGE_SIZE - *keysize); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1589 | k -= PAGE_SIZE; |
| 1590 | j = 1; |
| 1591 | while (k > PAGE_SIZE) { |
| 1592 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); |
| 1593 | memset(tvmem[j], 0xff, PAGE_SIZE); |
| 1594 | j++; |
| 1595 | k -= PAGE_SIZE; |
| 1596 | } |
| 1597 | sg_set_buf(sg + j, tvmem[j], k); |
| 1598 | memset(tvmem[j], 0xff, k); |
| 1599 | } else { |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1600 | sg_set_buf(sg, tvmem[0] + *keysize, bs); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1601 | } |
| 1602 | |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1603 | iv_len = crypto_skcipher_ivsize(tfm); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1604 | if (iv_len) |
| 1605 | memset(&iv, 0xff, iv_len); |
| 1606 | |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1607 | skcipher_request_set_crypt(req, sg, sg, bs, iv); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1608 | |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1609 | if (secs) { |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1610 | ret = test_acipher_jiffies(req, enc, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1611 | bs, secs); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1612 | cond_resched(); |
| 1613 | } else { |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1614 | ret = test_acipher_cycles(req, enc, |
Ard Biesheuvel | ad6d66b | 2020-11-20 12:04:33 +0100 | [diff] [blame] | 1615 | bs); |
Horia Geantă | 2af6329 | 2018-07-23 17:18:48 +0300 | [diff] [blame] | 1616 | } |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1617 | |
| 1618 | if (ret) { |
| 1619 | pr_err("%s() failed flags=%x\n", e, |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1620 | crypto_skcipher_get_flags(tfm)); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1621 | break; |
| 1622 | } |
| 1623 | b_size++; |
| 1624 | i++; |
| 1625 | } while (*b_size); |
| 1626 | keysize++; |
| 1627 | } while (*keysize); |
| 1628 | |
| 1629 | out_free_req: |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1630 | skcipher_request_free(req); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1631 | out: |
Herbert Xu | 7166e58 | 2016-06-29 18:03:50 +0800 | [diff] [blame] | 1632 | crypto_free_skcipher(tfm); |
| 1633 | } |
| 1634 | |
| 1635 | static void test_acipher_speed(const char *algo, int enc, unsigned int secs, |
| 1636 | struct cipher_speed_template *template, |
| 1637 | unsigned int tcount, u8 *keysize) |
| 1638 | { |
| 1639 | return test_skcipher_speed(algo, enc, secs, template, tcount, keysize, |
| 1640 | true); |
| 1641 | } |
| 1642 | |
| 1643 | static void test_cipher_speed(const char *algo, int enc, unsigned int secs, |
| 1644 | struct cipher_speed_template *template, |
| 1645 | unsigned int tcount, u8 *keysize) |
| 1646 | { |
| 1647 | return test_skcipher_speed(algo, enc, secs, template, tcount, keysize, |
| 1648 | false); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1649 | } |
| 1650 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1651 | static void test_available(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | { |
Corentin Labbe | 07d8f18 | 2019-11-08 15:42:13 +0000 | [diff] [blame] | 1653 | const char **name = check; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | while (*name) { |
| 1656 | printk("alg %s ", *name); |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 1657 | printk(crypto_has_alg(*name, 0, 0) ? |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 1658 | "found\n" : "not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | name++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1663 | static inline int tcrypt_test(const char *alg) |
| 1664 | { |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1665 | int ret; |
| 1666 | |
Rabin Vincent | 76512f2 | 2017-01-18 14:54:05 +0100 | [diff] [blame] | 1667 | pr_debug("testing %s\n", alg); |
| 1668 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1669 | ret = alg_test(alg, alg, 0, 0); |
| 1670 | /* non-fips algs return -EINVAL in fips mode */ |
| 1671 | if (fips_enabled && ret == -EINVAL) |
| 1672 | ret = 0; |
| 1673 | return ret; |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1674 | } |
| 1675 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1676 | static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1677 | { |
| 1678 | int i; |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1679 | int ret = 0; |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1680 | |
| 1681 | switch (m) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | case 0: |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 1683 | if (alg) { |
| 1684 | if (!crypto_has_alg(alg, type, |
| 1685 | mask ?: CRYPTO_ALG_TYPE_MASK)) |
| 1686 | ret = -ENOENT; |
| 1687 | break; |
| 1688 | } |
| 1689 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1690 | for (i = 1; i < 200; i++) |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 1691 | ret += do_test(NULL, 0, 0, i, num_mb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | break; |
| 1693 | |
| 1694 | case 1: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1695 | ret += tcrypt_test("md5"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | break; |
| 1697 | |
| 1698 | case 2: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1699 | ret += tcrypt_test("sha1"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | break; |
| 1701 | |
| 1702 | case 3: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1703 | ret += tcrypt_test("ecb(des)"); |
| 1704 | ret += tcrypt_test("cbc(des)"); |
Jussi Kivilinna | 8163fc3 | 2012-10-20 14:53:07 +0300 | [diff] [blame] | 1705 | ret += tcrypt_test("ctr(des)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | break; |
| 1707 | |
| 1708 | case 4: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1709 | ret += tcrypt_test("ecb(des3_ede)"); |
| 1710 | ret += tcrypt_test("cbc(des3_ede)"); |
Jussi Kivilinna | e080b17 | 2012-10-20 14:53:12 +0300 | [diff] [blame] | 1711 | ret += tcrypt_test("ctr(des3_ede)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | break; |
| 1713 | |
| 1714 | case 5: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1715 | ret += tcrypt_test("md4"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | case 6: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1719 | ret += tcrypt_test("sha256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | case 7: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1723 | ret += tcrypt_test("ecb(blowfish)"); |
| 1724 | ret += tcrypt_test("cbc(blowfish)"); |
Jussi Kivilinna | 85b63e3 | 2011-10-10 23:03:03 +0300 | [diff] [blame] | 1725 | ret += tcrypt_test("ctr(blowfish)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | break; |
| 1727 | |
| 1728 | case 8: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1729 | ret += tcrypt_test("ecb(twofish)"); |
| 1730 | ret += tcrypt_test("cbc(twofish)"); |
Jussi Kivilinna | 573da62 | 2011-10-10 23:03:12 +0300 | [diff] [blame] | 1731 | ret += tcrypt_test("ctr(twofish)"); |
Jussi Kivilinna | bee3a90 | 2011-10-18 13:32:56 +0300 | [diff] [blame] | 1732 | ret += tcrypt_test("lrw(twofish)"); |
Jussi Kivilinna | 131f754 | 2011-10-18 13:33:38 +0300 | [diff] [blame] | 1733 | ret += tcrypt_test("xts(twofish)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | case 9: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1737 | ret += tcrypt_test("ecb(serpent)"); |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 1738 | ret += tcrypt_test("cbc(serpent)"); |
| 1739 | ret += tcrypt_test("ctr(serpent)"); |
Jussi Kivilinna | 87aae4b | 2011-10-18 13:32:39 +0300 | [diff] [blame] | 1740 | ret += tcrypt_test("lrw(serpent)"); |
Jussi Kivilinna | 5209c07 | 2011-10-18 13:33:22 +0300 | [diff] [blame] | 1741 | ret += tcrypt_test("xts(serpent)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | break; |
| 1743 | |
| 1744 | case 10: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1745 | ret += tcrypt_test("ecb(aes)"); |
| 1746 | ret += tcrypt_test("cbc(aes)"); |
| 1747 | ret += tcrypt_test("lrw(aes)"); |
| 1748 | ret += tcrypt_test("xts(aes)"); |
| 1749 | ret += tcrypt_test("ctr(aes)"); |
| 1750 | ret += tcrypt_test("rfc3686(ctr(aes))"); |
Gilad Ben-Yossef | dfb89ab | 2018-09-20 14:18:40 +0100 | [diff] [blame] | 1751 | ret += tcrypt_test("ofb(aes)"); |
Dmitry Eremin-Solenikov | 7da6667 | 2018-10-20 02:01:53 +0300 | [diff] [blame] | 1752 | ret += tcrypt_test("cfb(aes)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | break; |
| 1754 | |
| 1755 | case 11: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1756 | ret += tcrypt_test("sha384"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1758 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | case 12: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1760 | ret += tcrypt_test("sha512"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | break; |
| 1762 | |
| 1763 | case 13: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1764 | ret += tcrypt_test("deflate"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | break; |
| 1766 | |
| 1767 | case 14: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1768 | ret += tcrypt_test("ecb(cast5)"); |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 1769 | ret += tcrypt_test("cbc(cast5)"); |
| 1770 | ret += tcrypt_test("ctr(cast5)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | break; |
| 1772 | |
| 1773 | case 15: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1774 | ret += tcrypt_test("ecb(cast6)"); |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 1775 | ret += tcrypt_test("cbc(cast6)"); |
| 1776 | ret += tcrypt_test("ctr(cast6)"); |
| 1777 | ret += tcrypt_test("lrw(cast6)"); |
| 1778 | ret += tcrypt_test("xts(cast6)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | break; |
| 1780 | |
| 1781 | case 16: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1782 | ret += tcrypt_test("ecb(arc4)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | break; |
| 1784 | |
| 1785 | case 17: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1786 | ret += tcrypt_test("michael_mic"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | break; |
| 1788 | |
| 1789 | case 18: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1790 | ret += tcrypt_test("crc32c"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | break; |
| 1792 | |
| 1793 | case 19: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1794 | ret += tcrypt_test("ecb(tea)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | break; |
| 1796 | |
| 1797 | case 20: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1798 | ret += tcrypt_test("ecb(xtea)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | break; |
| 1800 | |
| 1801 | case 21: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1802 | ret += tcrypt_test("ecb(khazad)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | break; |
| 1804 | |
| 1805 | case 22: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1806 | ret += tcrypt_test("wp512"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | break; |
| 1808 | |
| 1809 | case 23: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1810 | ret += tcrypt_test("wp384"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | break; |
| 1812 | |
| 1813 | case 24: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1814 | ret += tcrypt_test("wp256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | break; |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | case 26: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1818 | ret += tcrypt_test("ecb(anubis)"); |
| 1819 | ret += tcrypt_test("cbc(anubis)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | break; |
| 1821 | |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1822 | case 30: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1823 | ret += tcrypt_test("ecb(xeta)"); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1824 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1826 | case 31: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1827 | ret += tcrypt_test("pcbc(fcrypt)"); |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1828 | break; |
| 1829 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1830 | case 32: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1831 | ret += tcrypt_test("ecb(camellia)"); |
| 1832 | ret += tcrypt_test("cbc(camellia)"); |
Jussi Kivilinna | 54216bb | 2012-09-21 10:27:10 +0300 | [diff] [blame] | 1833 | ret += tcrypt_test("ctr(camellia)"); |
| 1834 | ret += tcrypt_test("lrw(camellia)"); |
| 1835 | ret += tcrypt_test("xts(camellia)"); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1836 | break; |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 1837 | |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1838 | case 33: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1839 | ret += tcrypt_test("sha224"); |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1840 | break; |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1841 | |
Herbert Xu | 8df213d | 2007-12-02 14:55:47 +1100 | [diff] [blame] | 1842 | case 35: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1843 | ret += tcrypt_test("gcm(aes)"); |
Herbert Xu | 8df213d | 2007-12-02 14:55:47 +1100 | [diff] [blame] | 1844 | break; |
| 1845 | |
Zoltan Sogor | 0b77abb | 2007-12-07 16:53:23 +0800 | [diff] [blame] | 1846 | case 36: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1847 | ret += tcrypt_test("lzo"); |
Zoltan Sogor | 0b77abb | 2007-12-07 16:53:23 +0800 | [diff] [blame] | 1848 | break; |
| 1849 | |
Joy Latten | 93cc74e | 2007-12-12 20:24:22 +0800 | [diff] [blame] | 1850 | case 37: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1851 | ret += tcrypt_test("ccm(aes)"); |
Joy Latten | 93cc74e | 2007-12-12 20:24:22 +0800 | [diff] [blame] | 1852 | break; |
| 1853 | |
Kevin Coffman | 76cb952 | 2008-03-24 21:26:16 +0800 | [diff] [blame] | 1854 | case 38: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1855 | ret += tcrypt_test("cts(cbc(aes))"); |
Kevin Coffman | 76cb952 | 2008-03-24 21:26:16 +0800 | [diff] [blame] | 1856 | break; |
| 1857 | |
Ard Biesheuvel | aa22cd7 | 2021-05-20 12:40:00 +0200 | [diff] [blame] | 1858 | case 39: |
| 1859 | ret += tcrypt_test("xxhash64"); |
| 1860 | break; |
| 1861 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1862 | case 40: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1863 | ret += tcrypt_test("rmd160"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1864 | break; |
| 1865 | |
Ard Biesheuvel | aa22cd7 | 2021-05-20 12:40:00 +0200 | [diff] [blame] | 1866 | case 41: |
| 1867 | ret += tcrypt_test("blake2s-256"); |
| 1868 | break; |
| 1869 | |
| 1870 | case 42: |
| 1871 | ret += tcrypt_test("blake2b-512"); |
| 1872 | break; |
| 1873 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1874 | case 43: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1875 | ret += tcrypt_test("ecb(seed)"); |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 1876 | break; |
| 1877 | |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 1878 | case 45: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1879 | ret += tcrypt_test("rfc4309(ccm(aes))"); |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 1880 | break; |
| 1881 | |
Jussi Kivilinna | 54216bb | 2012-09-21 10:27:10 +0300 | [diff] [blame] | 1882 | case 46: |
| 1883 | ret += tcrypt_test("ghash"); |
| 1884 | break; |
| 1885 | |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 1886 | case 47: |
| 1887 | ret += tcrypt_test("crct10dif"); |
| 1888 | break; |
| 1889 | |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 1890 | case 48: |
| 1891 | ret += tcrypt_test("sha3-224"); |
| 1892 | break; |
| 1893 | |
| 1894 | case 49: |
| 1895 | ret += tcrypt_test("sha3-256"); |
| 1896 | break; |
| 1897 | |
| 1898 | case 50: |
| 1899 | ret += tcrypt_test("sha3-384"); |
| 1900 | break; |
| 1901 | |
| 1902 | case 51: |
| 1903 | ret += tcrypt_test("sha3-512"); |
| 1904 | break; |
| 1905 | |
Gilad Ben-Yossef | b7e2753 | 2017-08-21 13:51:29 +0300 | [diff] [blame] | 1906 | case 52: |
| 1907 | ret += tcrypt_test("sm3"); |
| 1908 | break; |
| 1909 | |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 1910 | case 53: |
| 1911 | ret += tcrypt_test("streebog256"); |
| 1912 | break; |
| 1913 | |
| 1914 | case 54: |
| 1915 | ret += tcrypt_test("streebog512"); |
| 1916 | break; |
| 1917 | |
Tianjia Zhang | 357a753 | 2021-08-13 15:55:08 +0800 | [diff] [blame] | 1918 | case 55: |
| 1919 | ret += tcrypt_test("gcm(sm4)"); |
| 1920 | break; |
| 1921 | |
| 1922 | case 56: |
| 1923 | ret += tcrypt_test("ccm(sm4)"); |
| 1924 | break; |
| 1925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | case 100: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1927 | ret += tcrypt_test("hmac(md5)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | case 101: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1931 | ret += tcrypt_test("hmac(sha1)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | case 102: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1935 | ret += tcrypt_test("hmac(sha256)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | break; |
| 1937 | |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1938 | case 103: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1939 | ret += tcrypt_test("hmac(sha384)"); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1940 | break; |
| 1941 | |
| 1942 | case 104: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1943 | ret += tcrypt_test("hmac(sha512)"); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1944 | break; |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 1945 | |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1946 | case 105: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1947 | ret += tcrypt_test("hmac(sha224)"); |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1948 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 1950 | case 106: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1951 | ret += tcrypt_test("xcbc(aes)"); |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 1952 | break; |
| 1953 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1954 | case 108: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1955 | ret += tcrypt_test("hmac(rmd160)"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1956 | break; |
| 1957 | |
Shane Wang | f1939f7 | 2009-09-02 20:05:22 +1000 | [diff] [blame] | 1958 | case 109: |
Eric Biggers | 0917b87 | 2018-06-18 10:22:40 -0700 | [diff] [blame] | 1959 | ret += tcrypt_test("vmac64(aes)"); |
Shane Wang | f1939f7 | 2009-09-02 20:05:22 +1000 | [diff] [blame] | 1960 | break; |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 1961 | |
raveendra padasalagi | 98eca72 | 2016-07-01 11:16:54 +0530 | [diff] [blame] | 1962 | case 111: |
| 1963 | ret += tcrypt_test("hmac(sha3-224)"); |
| 1964 | break; |
| 1965 | |
| 1966 | case 112: |
| 1967 | ret += tcrypt_test("hmac(sha3-256)"); |
| 1968 | break; |
| 1969 | |
| 1970 | case 113: |
| 1971 | ret += tcrypt_test("hmac(sha3-384)"); |
| 1972 | break; |
| 1973 | |
| 1974 | case 114: |
| 1975 | ret += tcrypt_test("hmac(sha3-512)"); |
| 1976 | break; |
| 1977 | |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 1978 | case 115: |
| 1979 | ret += tcrypt_test("hmac(streebog256)"); |
| 1980 | break; |
| 1981 | |
| 1982 | case 116: |
| 1983 | ret += tcrypt_test("hmac(streebog512)"); |
| 1984 | break; |
| 1985 | |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 1986 | case 150: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1987 | ret += tcrypt_test("ansi_cprng"); |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 1988 | break; |
| 1989 | |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 1990 | case 151: |
| 1991 | ret += tcrypt_test("rfc4106(gcm(aes))"); |
| 1992 | break; |
| 1993 | |
Jussi Kivilinna | e9b7441 | 2013-04-07 16:43:51 +0300 | [diff] [blame] | 1994 | case 152: |
| 1995 | ret += tcrypt_test("rfc4543(gcm(aes))"); |
| 1996 | break; |
| 1997 | |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 1998 | case 153: |
| 1999 | ret += tcrypt_test("cmac(aes)"); |
| 2000 | break; |
| 2001 | |
| 2002 | case 154: |
| 2003 | ret += tcrypt_test("cmac(des3_ede)"); |
| 2004 | break; |
| 2005 | |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 2006 | case 155: |
| 2007 | ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))"); |
| 2008 | break; |
| 2009 | |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 2010 | case 156: |
| 2011 | ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"); |
| 2012 | break; |
| 2013 | |
| 2014 | case 157: |
| 2015 | ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"); |
| 2016 | break; |
Tianjia Zhang | 357a753 | 2021-08-13 15:55:08 +0800 | [diff] [blame] | 2017 | |
| 2018 | case 158: |
| 2019 | ret += tcrypt_test("cbcmac(sm4)"); |
| 2020 | break; |
| 2021 | |
| 2022 | case 159: |
| 2023 | ret += tcrypt_test("cmac(sm4)"); |
| 2024 | break; |
| 2025 | |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 2026 | case 181: |
| 2027 | ret += tcrypt_test("authenc(hmac(sha1),cbc(des))"); |
| 2028 | break; |
| 2029 | case 182: |
| 2030 | ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"); |
| 2031 | break; |
| 2032 | case 183: |
| 2033 | ret += tcrypt_test("authenc(hmac(sha224),cbc(des))"); |
| 2034 | break; |
| 2035 | case 184: |
| 2036 | ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"); |
| 2037 | break; |
| 2038 | case 185: |
| 2039 | ret += tcrypt_test("authenc(hmac(sha256),cbc(des))"); |
| 2040 | break; |
| 2041 | case 186: |
| 2042 | ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"); |
| 2043 | break; |
| 2044 | case 187: |
| 2045 | ret += tcrypt_test("authenc(hmac(sha384),cbc(des))"); |
| 2046 | break; |
| 2047 | case 188: |
| 2048 | ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"); |
| 2049 | break; |
| 2050 | case 189: |
| 2051 | ret += tcrypt_test("authenc(hmac(sha512),cbc(des))"); |
| 2052 | break; |
| 2053 | case 190: |
| 2054 | ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"); |
| 2055 | break; |
Gilad Ben-Yossef | cd83a8a | 2018-03-06 09:44:43 +0000 | [diff] [blame] | 2056 | case 191: |
| 2057 | ret += tcrypt_test("ecb(sm4)"); |
Gilad Ben-Yossef | 95ba597 | 2018-09-20 14:18:38 +0100 | [diff] [blame] | 2058 | ret += tcrypt_test("cbc(sm4)"); |
Tianjia Zhang | a7fc80b | 2021-07-20 11:46:42 +0800 | [diff] [blame] | 2059 | ret += tcrypt_test("cfb(sm4)"); |
Gilad Ben-Yossef | 95ba597 | 2018-09-20 14:18:38 +0100 | [diff] [blame] | 2060 | ret += tcrypt_test("ctr(sm4)"); |
Gilad Ben-Yossef | cd83a8a | 2018-03-06 09:44:43 +0000 | [diff] [blame] | 2061 | break; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2062 | case 200: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2063 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2064 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2065 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2066 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2067 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2068 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2069 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2070 | speed_template_16_24_32); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 2071 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2072 | speed_template_32_40_48); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 2073 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2074 | speed_template_32_40_48); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 2075 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
Horia Geantă | b66ad0b | 2017-07-19 19:40:32 +0300 | [diff] [blame] | 2076 | speed_template_32_64); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 2077 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
Horia Geantă | b66ad0b | 2017-07-19 19:40:32 +0300 | [diff] [blame] | 2078 | speed_template_32_64); |
Herbert Xu | 1503a24 | 2016-06-29 18:04:14 +0800 | [diff] [blame] | 2079 | test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0, |
| 2080 | speed_template_16_24_32); |
| 2081 | test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0, |
| 2082 | speed_template_16_24_32); |
Jan Glauber | 9996e34 | 2011-04-26 16:34:01 +1000 | [diff] [blame] | 2083 | test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
| 2084 | speed_template_16_24_32); |
| 2085 | test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, |
| 2086 | speed_template_16_24_32); |
Dmitry Eremin-Solenikov | 7da6667 | 2018-10-20 02:01:53 +0300 | [diff] [blame] | 2087 | test_cipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, |
| 2088 | speed_template_16_24_32); |
| 2089 | test_cipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, |
| 2090 | speed_template_16_24_32); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2091 | break; |
| 2092 | |
| 2093 | case 201: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2094 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2095 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2096 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2097 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2098 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2099 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2100 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2101 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2102 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2103 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 2104 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2105 | speed_template_24); |
Jussi Kivilinna | 8713150 | 2014-06-09 20:59:49 +0300 | [diff] [blame] | 2106 | test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec, |
| 2107 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2108 | speed_template_24); |
| 2109 | test_cipher_speed("ctr(des3_ede)", DECRYPT, sec, |
| 2110 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2111 | speed_template_24); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2112 | break; |
| 2113 | |
| 2114 | case 202: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2115 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2116 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2117 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2118 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2119 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2120 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2121 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2122 | speed_template_16_24_32); |
Jussi Kivilinna | ee5002a | 2011-09-26 16:47:15 +0300 | [diff] [blame] | 2123 | test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
| 2124 | speed_template_16_24_32); |
| 2125 | test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, |
| 2126 | speed_template_16_24_32); |
Jussi Kivilinna | bee3a90 | 2011-10-18 13:32:56 +0300 | [diff] [blame] | 2127 | test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
| 2128 | speed_template_32_40_48); |
| 2129 | test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, |
| 2130 | speed_template_32_40_48); |
Jussi Kivilinna | 131f754 | 2011-10-18 13:33:38 +0300 | [diff] [blame] | 2131 | test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
| 2132 | speed_template_32_48_64); |
| 2133 | test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, |
| 2134 | speed_template_32_48_64); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2135 | break; |
| 2136 | |
| 2137 | case 203: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2138 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2139 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2140 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2141 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2142 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2143 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2144 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2145 | speed_template_8_32); |
Jussi Kivilinna | 7d47b86 | 2011-09-02 01:45:17 +0300 | [diff] [blame] | 2146 | test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2147 | speed_template_8_32); |
| 2148 | test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, |
| 2149 | speed_template_8_32); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2150 | break; |
| 2151 | |
| 2152 | case 204: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2153 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2154 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2155 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2156 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2157 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2158 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 2159 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2160 | speed_template_8); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2161 | break; |
| 2162 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 2163 | case 205: |
| 2164 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2165 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 2166 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2167 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 2168 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2169 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 2170 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 2171 | speed_template_16_24_32); |
Jussi Kivilinna | 4de5933 | 2012-03-05 20:26:26 +0200 | [diff] [blame] | 2172 | test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
| 2173 | speed_template_16_24_32); |
| 2174 | test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, |
| 2175 | speed_template_16_24_32); |
| 2176 | test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, |
| 2177 | speed_template_32_40_48); |
| 2178 | test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, |
| 2179 | speed_template_32_40_48); |
| 2180 | test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, |
| 2181 | speed_template_32_48_64); |
| 2182 | test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, |
| 2183 | speed_template_32_48_64); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 2184 | break; |
| 2185 | |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 2186 | case 207: |
| 2187 | test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, |
| 2188 | speed_template_16_32); |
| 2189 | test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, |
| 2190 | speed_template_16_32); |
| 2191 | test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, |
| 2192 | speed_template_16_32); |
| 2193 | test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, |
| 2194 | speed_template_16_32); |
| 2195 | test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, |
| 2196 | speed_template_16_32); |
| 2197 | test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, |
| 2198 | speed_template_16_32); |
Jussi Kivilinna | 87aae4b | 2011-10-18 13:32:39 +0300 | [diff] [blame] | 2199 | test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
| 2200 | speed_template_32_48); |
| 2201 | test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, |
| 2202 | speed_template_32_48); |
Jussi Kivilinna | 5209c07 | 2011-10-18 13:33:22 +0300 | [diff] [blame] | 2203 | test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
| 2204 | speed_template_32_64); |
| 2205 | test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, |
| 2206 | speed_template_32_64); |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 2207 | break; |
| 2208 | |
Jussi Kivilinna | 31b4cd29 | 2012-06-12 16:52:04 +0800 | [diff] [blame] | 2209 | case 208: |
| 2210 | test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, |
| 2211 | speed_template_8); |
| 2212 | break; |
| 2213 | |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 2214 | case 209: |
| 2215 | test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, |
| 2216 | speed_template_8_16); |
| 2217 | test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, |
| 2218 | speed_template_8_16); |
| 2219 | test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, |
| 2220 | speed_template_8_16); |
| 2221 | test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, |
| 2222 | speed_template_8_16); |
| 2223 | test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, |
| 2224 | speed_template_8_16); |
| 2225 | test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, |
| 2226 | speed_template_8_16); |
| 2227 | break; |
| 2228 | |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 2229 | case 210: |
| 2230 | test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, |
| 2231 | speed_template_16_32); |
| 2232 | test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, |
| 2233 | speed_template_16_32); |
| 2234 | test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, |
| 2235 | speed_template_16_32); |
| 2236 | test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, |
| 2237 | speed_template_16_32); |
| 2238 | test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, |
| 2239 | speed_template_16_32); |
| 2240 | test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, |
| 2241 | speed_template_16_32); |
| 2242 | test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, |
| 2243 | speed_template_32_48); |
| 2244 | test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, |
| 2245 | speed_template_32_48); |
| 2246 | test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, |
| 2247 | speed_template_32_64); |
| 2248 | test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, |
| 2249 | speed_template_32_64); |
| 2250 | break; |
| 2251 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 2252 | case 211: |
| 2253 | test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, |
Herbert Xu | 34a1c74 | 2015-07-09 07:17:26 +0800 | [diff] [blame] | 2254 | NULL, 0, 16, 16, aead_speed_template_20); |
Vutla, Lokesh | 1425d2d | 2015-07-07 21:01:49 +0530 | [diff] [blame] | 2255 | test_aead_speed("gcm(aes)", ENCRYPT, sec, |
Cyrille Pitchen | f18611d | 2015-11-17 13:37:10 +0100 | [diff] [blame] | 2256 | NULL, 0, 16, 8, speed_template_16_24_32); |
Gilad Ben-Yossef | 4431bd4 | 2017-12-17 08:29:01 +0000 | [diff] [blame] | 2257 | test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, |
| 2258 | NULL, 0, 16, 16, aead_speed_template_20); |
| 2259 | test_aead_speed("gcm(aes)", DECRYPT, sec, |
| 2260 | NULL, 0, 16, 8, speed_template_16_24_32); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 2261 | break; |
| 2262 | |
Herbert Xu | 4e4aab6 | 2015-06-17 14:04:21 +0800 | [diff] [blame] | 2263 | case 212: |
| 2264 | test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, |
Herbert Xu | 34a1c74 | 2015-07-09 07:17:26 +0800 | [diff] [blame] | 2265 | NULL, 0, 16, 16, aead_speed_template_19); |
Gilad Ben-Yossef | 4431bd4 | 2017-12-17 08:29:01 +0000 | [diff] [blame] | 2266 | test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, |
| 2267 | NULL, 0, 16, 16, aead_speed_template_19); |
Herbert Xu | 4e4aab6 | 2015-06-17 14:04:21 +0800 | [diff] [blame] | 2268 | break; |
| 2269 | |
Martin Willi | 2dce063 | 2015-07-16 19:13:59 +0200 | [diff] [blame] | 2270 | case 213: |
| 2271 | test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec, |
| 2272 | NULL, 0, 16, 8, aead_speed_template_36); |
Gilad Ben-Yossef | 4431bd4 | 2017-12-17 08:29:01 +0000 | [diff] [blame] | 2273 | test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec, |
| 2274 | NULL, 0, 16, 8, aead_speed_template_36); |
Martin Willi | 2dce063 | 2015-07-16 19:13:59 +0200 | [diff] [blame] | 2275 | break; |
| 2276 | |
| 2277 | case 214: |
| 2278 | test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0, |
| 2279 | speed_template_32); |
| 2280 | break; |
| 2281 | |
Gilad Ben-Yossef | 427988d | 2017-12-17 08:29:05 +0000 | [diff] [blame] | 2282 | case 215: |
| 2283 | test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL, |
| 2284 | 0, 16, 16, aead_speed_template_20, num_mb); |
| 2285 | test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8, |
| 2286 | speed_template_16_24_32, num_mb); |
| 2287 | test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL, |
| 2288 | 0, 16, 16, aead_speed_template_20, num_mb); |
| 2289 | test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8, |
| 2290 | speed_template_16_24_32, num_mb); |
| 2291 | break; |
| 2292 | |
| 2293 | case 216: |
| 2294 | test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0, |
| 2295 | 16, 16, aead_speed_template_19, num_mb); |
| 2296 | test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0, |
| 2297 | 16, 16, aead_speed_template_19, num_mb); |
| 2298 | break; |
| 2299 | |
| 2300 | case 217: |
| 2301 | test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, |
| 2302 | sec, NULL, 0, 16, 8, aead_speed_template_36, |
| 2303 | num_mb); |
| 2304 | test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, |
| 2305 | sec, NULL, 0, 16, 8, aead_speed_template_36, |
| 2306 | num_mb); |
| 2307 | break; |
| 2308 | |
Gilad Ben-Yossef | 95ba597 | 2018-09-20 14:18:38 +0100 | [diff] [blame] | 2309 | case 218: |
| 2310 | test_cipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0, |
| 2311 | speed_template_16); |
| 2312 | test_cipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0, |
| 2313 | speed_template_16); |
| 2314 | test_cipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0, |
| 2315 | speed_template_16); |
| 2316 | test_cipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0, |
| 2317 | speed_template_16); |
Tianjia Zhang | a7fc80b | 2021-07-20 11:46:42 +0800 | [diff] [blame] | 2318 | test_cipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0, |
| 2319 | speed_template_16); |
| 2320 | test_cipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0, |
| 2321 | speed_template_16); |
Gilad Ben-Yossef | 95ba597 | 2018-09-20 14:18:38 +0100 | [diff] [blame] | 2322 | test_cipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0, |
| 2323 | speed_template_16); |
| 2324 | test_cipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0, |
| 2325 | speed_template_16); |
| 2326 | break; |
Eric Biggers | 059c2a4 | 2018-11-16 17:26:31 -0800 | [diff] [blame] | 2327 | |
| 2328 | case 219: |
| 2329 | test_cipher_speed("adiantum(xchacha12,aes)", ENCRYPT, sec, NULL, |
| 2330 | 0, speed_template_32); |
| 2331 | test_cipher_speed("adiantum(xchacha12,aes)", DECRYPT, sec, NULL, |
| 2332 | 0, speed_template_32); |
| 2333 | test_cipher_speed("adiantum(xchacha20,aes)", ENCRYPT, sec, NULL, |
| 2334 | 0, speed_template_32); |
| 2335 | test_cipher_speed("adiantum(xchacha20,aes)", DECRYPT, sec, NULL, |
| 2336 | 0, speed_template_32); |
| 2337 | break; |
| 2338 | |
Ard Biesheuvel | f975abb | 2019-08-19 17:17:34 +0300 | [diff] [blame] | 2339 | case 220: |
| 2340 | test_acipher_speed("essiv(cbc(aes),sha256)", |
| 2341 | ENCRYPT, sec, NULL, 0, |
| 2342 | speed_template_16_24_32); |
| 2343 | test_acipher_speed("essiv(cbc(aes),sha256)", |
| 2344 | DECRYPT, sec, NULL, 0, |
| 2345 | speed_template_16_24_32); |
| 2346 | break; |
| 2347 | |
Ard Biesheuvel | 97bcb16 | 2019-07-03 10:55:12 +0200 | [diff] [blame] | 2348 | case 221: |
| 2349 | test_aead_speed("aegis128", ENCRYPT, sec, |
| 2350 | NULL, 0, 16, 8, speed_template_16); |
| 2351 | test_aead_speed("aegis128", DECRYPT, sec, |
| 2352 | NULL, 0, 16, 8, speed_template_16); |
| 2353 | break; |
| 2354 | |
Tianjia Zhang | 357a753 | 2021-08-13 15:55:08 +0800 | [diff] [blame] | 2355 | case 222: |
| 2356 | test_aead_speed("gcm(sm4)", ENCRYPT, sec, |
| 2357 | NULL, 0, 16, 8, speed_template_16); |
| 2358 | test_aead_speed("gcm(sm4)", DECRYPT, sec, |
| 2359 | NULL, 0, 16, 8, speed_template_16); |
| 2360 | break; |
| 2361 | |
| 2362 | case 223: |
| 2363 | test_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, |
| 2364 | NULL, 0, 16, 16, aead_speed_template_19); |
| 2365 | test_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, |
| 2366 | NULL, 0, 16, 16, aead_speed_template_19); |
| 2367 | break; |
| 2368 | |
| 2369 | case 224: |
| 2370 | test_mb_aead_speed("gcm(sm4)", ENCRYPT, sec, NULL, 0, 16, 8, |
| 2371 | speed_template_16, num_mb); |
| 2372 | test_mb_aead_speed("gcm(sm4)", DECRYPT, sec, NULL, 0, 16, 8, |
| 2373 | speed_template_16, num_mb); |
| 2374 | break; |
| 2375 | |
| 2376 | case 225: |
| 2377 | test_mb_aead_speed("rfc4309(ccm(sm4))", ENCRYPT, sec, NULL, 0, |
| 2378 | 16, 16, aead_speed_template_19, num_mb); |
| 2379 | test_mb_aead_speed("rfc4309(ccm(sm4))", DECRYPT, sec, NULL, 0, |
| 2380 | 16, 16, aead_speed_template_19, num_mb); |
| 2381 | break; |
| 2382 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2383 | case 300: |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 2384 | if (alg) { |
| 2385 | test_hash_speed(alg, sec, generic_hash_speed_template); |
| 2386 | break; |
| 2387 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2388 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2389 | case 301: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2390 | test_hash_speed("md4", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2391 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2392 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2393 | case 302: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2394 | test_hash_speed("md5", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2395 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2396 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2397 | case 303: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2398 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2399 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2400 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2401 | case 304: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2402 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2403 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2404 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2405 | case 305: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2406 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2407 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2408 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2409 | case 306: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2410 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2411 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2412 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2413 | case 307: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2414 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2415 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2416 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2417 | case 308: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2418 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2419 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2420 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2421 | case 309: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 2422 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2423 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2424 | fallthrough; |
Jonathan Lynch | cd12fb9 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 2425 | case 313: |
| 2426 | test_hash_speed("sha224", sec, generic_hash_speed_template); |
| 2427 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2428 | fallthrough; |
Ard Biesheuvel | aa22cd7 | 2021-05-20 12:40:00 +0200 | [diff] [blame] | 2429 | case 314: |
| 2430 | test_hash_speed("xxhash64", sec, generic_hash_speed_template); |
| 2431 | if (mode > 300 && mode < 400) break; |
| 2432 | fallthrough; |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 2433 | case 315: |
| 2434 | test_hash_speed("rmd160", sec, generic_hash_speed_template); |
| 2435 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2436 | fallthrough; |
Ard Biesheuvel | aa22cd7 | 2021-05-20 12:40:00 +0200 | [diff] [blame] | 2437 | case 316: |
| 2438 | test_hash_speed("blake2s-256", sec, generic_hash_speed_template); |
| 2439 | if (mode > 300 && mode < 400) break; |
| 2440 | fallthrough; |
| 2441 | case 317: |
| 2442 | test_hash_speed("blake2b-512", sec, generic_hash_speed_template); |
| 2443 | if (mode > 300 && mode < 400) break; |
| 2444 | fallthrough; |
Huang Ying | 18bcc91 | 2010-03-10 18:30:32 +0800 | [diff] [blame] | 2445 | case 318: |
Herbert Xu | ba974ad | 2020-08-05 15:57:08 +1000 | [diff] [blame] | 2446 | klen = 16; |
| 2447 | test_hash_speed("ghash", sec, generic_hash_speed_template); |
Huang Ying | 18bcc91 | 2010-03-10 18:30:32 +0800 | [diff] [blame] | 2448 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2449 | fallthrough; |
Tim Chen | e3899e4 | 2012-09-27 15:44:24 -0700 | [diff] [blame] | 2450 | case 319: |
| 2451 | test_hash_speed("crc32c", sec, generic_hash_speed_template); |
| 2452 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2453 | fallthrough; |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 2454 | case 320: |
| 2455 | test_hash_speed("crct10dif", sec, generic_hash_speed_template); |
| 2456 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2457 | fallthrough; |
Martin Willi | 2dce063 | 2015-07-16 19:13:59 +0200 | [diff] [blame] | 2458 | case 321: |
| 2459 | test_hash_speed("poly1305", sec, poly1305_speed_template); |
| 2460 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2461 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2462 | case 322: |
| 2463 | test_hash_speed("sha3-224", sec, generic_hash_speed_template); |
| 2464 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2465 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2466 | case 323: |
| 2467 | test_hash_speed("sha3-256", sec, generic_hash_speed_template); |
| 2468 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2469 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2470 | case 324: |
| 2471 | test_hash_speed("sha3-384", sec, generic_hash_speed_template); |
| 2472 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2473 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2474 | case 325: |
| 2475 | test_hash_speed("sha3-512", sec, generic_hash_speed_template); |
| 2476 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2477 | fallthrough; |
Gilad Ben-Yossef | b7e2753 | 2017-08-21 13:51:29 +0300 | [diff] [blame] | 2478 | case 326: |
| 2479 | test_hash_speed("sm3", sec, generic_hash_speed_template); |
| 2480 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2481 | fallthrough; |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 2482 | case 327: |
| 2483 | test_hash_speed("streebog256", sec, |
| 2484 | generic_hash_speed_template); |
| 2485 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2486 | fallthrough; |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 2487 | case 328: |
| 2488 | test_hash_speed("streebog512", sec, |
| 2489 | generic_hash_speed_template); |
| 2490 | if (mode > 300 && mode < 400) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2491 | fallthrough; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 2492 | case 399: |
| 2493 | break; |
| 2494 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2495 | case 400: |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 2496 | if (alg) { |
| 2497 | test_ahash_speed(alg, sec, generic_hash_speed_template); |
| 2498 | break; |
| 2499 | } |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2500 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2501 | case 401: |
| 2502 | test_ahash_speed("md4", sec, generic_hash_speed_template); |
| 2503 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2504 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2505 | case 402: |
| 2506 | test_ahash_speed("md5", sec, generic_hash_speed_template); |
| 2507 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2508 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2509 | case 403: |
| 2510 | test_ahash_speed("sha1", sec, generic_hash_speed_template); |
| 2511 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2512 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2513 | case 404: |
| 2514 | test_ahash_speed("sha256", sec, generic_hash_speed_template); |
| 2515 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2516 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2517 | case 405: |
| 2518 | test_ahash_speed("sha384", sec, generic_hash_speed_template); |
| 2519 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2520 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2521 | case 406: |
| 2522 | test_ahash_speed("sha512", sec, generic_hash_speed_template); |
| 2523 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2524 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2525 | case 407: |
| 2526 | test_ahash_speed("wp256", sec, generic_hash_speed_template); |
| 2527 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2528 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2529 | case 408: |
| 2530 | test_ahash_speed("wp384", sec, generic_hash_speed_template); |
| 2531 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2532 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2533 | case 409: |
| 2534 | test_ahash_speed("wp512", sec, generic_hash_speed_template); |
| 2535 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2536 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2537 | case 413: |
| 2538 | test_ahash_speed("sha224", sec, generic_hash_speed_template); |
| 2539 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2540 | fallthrough; |
Ard Biesheuvel | aa22cd7 | 2021-05-20 12:40:00 +0200 | [diff] [blame] | 2541 | case 414: |
| 2542 | test_ahash_speed("xxhash64", sec, generic_hash_speed_template); |
| 2543 | if (mode > 400 && mode < 500) break; |
| 2544 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2545 | case 415: |
| 2546 | test_ahash_speed("rmd160", sec, generic_hash_speed_template); |
| 2547 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2548 | fallthrough; |
Ard Biesheuvel | aa22cd7 | 2021-05-20 12:40:00 +0200 | [diff] [blame] | 2549 | case 416: |
| 2550 | test_ahash_speed("blake2s-256", sec, generic_hash_speed_template); |
| 2551 | if (mode > 400 && mode < 500) break; |
| 2552 | fallthrough; |
| 2553 | case 417: |
| 2554 | test_ahash_speed("blake2b-512", sec, generic_hash_speed_template); |
| 2555 | if (mode > 400 && mode < 500) break; |
| 2556 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2557 | case 418: |
| 2558 | test_ahash_speed("sha3-224", sec, generic_hash_speed_template); |
| 2559 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2560 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2561 | case 419: |
| 2562 | test_ahash_speed("sha3-256", sec, generic_hash_speed_template); |
| 2563 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2564 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2565 | case 420: |
| 2566 | test_ahash_speed("sha3-384", sec, generic_hash_speed_template); |
| 2567 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2568 | fallthrough; |
raveendra padasalagi | 79cc6ab | 2016-06-17 10:30:36 +0530 | [diff] [blame] | 2569 | case 421: |
| 2570 | test_ahash_speed("sha3-512", sec, generic_hash_speed_template); |
| 2571 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2572 | fallthrough; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 2573 | case 422: |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 2574 | test_mb_ahash_speed("sha1", sec, generic_hash_speed_template, |
| 2575 | num_mb); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 2576 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2577 | fallthrough; |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 2578 | case 423: |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 2579 | test_mb_ahash_speed("sha256", sec, generic_hash_speed_template, |
| 2580 | num_mb); |
Megha Dey | 087bcd2 | 2016-06-23 18:40:47 -0700 | [diff] [blame] | 2581 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2582 | fallthrough; |
Megha Dey | 14009c4 | 2016-06-27 10:20:09 -0700 | [diff] [blame] | 2583 | case 424: |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 2584 | test_mb_ahash_speed("sha512", sec, generic_hash_speed_template, |
| 2585 | num_mb); |
Megha Dey | 14009c4 | 2016-06-27 10:20:09 -0700 | [diff] [blame] | 2586 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2587 | fallthrough; |
Gilad Ben-Yossef | b7e2753 | 2017-08-21 13:51:29 +0300 | [diff] [blame] | 2588 | case 425: |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 2589 | test_mb_ahash_speed("sm3", sec, generic_hash_speed_template, |
| 2590 | num_mb); |
Gilad Ben-Yossef | b7e2753 | 2017-08-21 13:51:29 +0300 | [diff] [blame] | 2591 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2592 | fallthrough; |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 2593 | case 426: |
| 2594 | test_mb_ahash_speed("streebog256", sec, |
| 2595 | generic_hash_speed_template, num_mb); |
| 2596 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2597 | fallthrough; |
Vitaly Chikunov | 25a0b9d | 2018-11-07 00:00:03 +0300 | [diff] [blame] | 2598 | case 427: |
| 2599 | test_mb_ahash_speed("streebog512", sec, |
| 2600 | generic_hash_speed_template, num_mb); |
| 2601 | if (mode > 400 && mode < 500) break; |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 2602 | fallthrough; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 2603 | case 499: |
| 2604 | break; |
| 2605 | |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2606 | case 500: |
| 2607 | test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
| 2608 | speed_template_16_24_32); |
| 2609 | test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
| 2610 | speed_template_16_24_32); |
| 2611 | test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
| 2612 | speed_template_16_24_32); |
| 2613 | test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
| 2614 | speed_template_16_24_32); |
| 2615 | test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
| 2616 | speed_template_32_40_48); |
| 2617 | test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
| 2618 | speed_template_32_40_48); |
| 2619 | test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
Horia Geantă | b66ad0b | 2017-07-19 19:40:32 +0300 | [diff] [blame] | 2620 | speed_template_32_64); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2621 | test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
Horia Geantă | b66ad0b | 2017-07-19 19:40:32 +0300 | [diff] [blame] | 2622 | speed_template_32_64); |
Herbert Xu | 1503a24 | 2016-06-29 18:04:14 +0800 | [diff] [blame] | 2623 | test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0, |
| 2624 | speed_template_16_24_32); |
| 2625 | test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0, |
| 2626 | speed_template_16_24_32); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2627 | test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
| 2628 | speed_template_16_24_32); |
| 2629 | test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, |
| 2630 | speed_template_16_24_32); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 2631 | test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, |
| 2632 | speed_template_16_24_32); |
| 2633 | test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, |
| 2634 | speed_template_16_24_32); |
| 2635 | test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, |
| 2636 | speed_template_16_24_32); |
| 2637 | test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, |
| 2638 | speed_template_16_24_32); |
Jussi Kivilinna | 69d3150 | 2012-12-28 12:04:58 +0200 | [diff] [blame] | 2639 | test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0, |
| 2640 | speed_template_20_28_36); |
| 2641 | test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0, |
| 2642 | speed_template_20_28_36); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2643 | break; |
| 2644 | |
| 2645 | case 501: |
| 2646 | test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
| 2647 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2648 | speed_template_24); |
| 2649 | test_acipher_speed("ecb(des3_ede)", DECRYPT, sec, |
| 2650 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2651 | speed_template_24); |
| 2652 | test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
| 2653 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2654 | speed_template_24); |
| 2655 | test_acipher_speed("cbc(des3_ede)", DECRYPT, sec, |
| 2656 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2657 | speed_template_24); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 2658 | test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec, |
| 2659 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2660 | speed_template_24); |
| 2661 | test_acipher_speed("cfb(des3_ede)", DECRYPT, sec, |
| 2662 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2663 | speed_template_24); |
| 2664 | test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec, |
| 2665 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2666 | speed_template_24); |
| 2667 | test_acipher_speed("ofb(des3_ede)", DECRYPT, sec, |
| 2668 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2669 | speed_template_24); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2670 | break; |
| 2671 | |
| 2672 | case 502: |
| 2673 | test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
| 2674 | speed_template_8); |
| 2675 | test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
| 2676 | speed_template_8); |
| 2677 | test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
| 2678 | speed_template_8); |
| 2679 | test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
| 2680 | speed_template_8); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 2681 | test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, |
| 2682 | speed_template_8); |
| 2683 | test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, |
| 2684 | speed_template_8); |
| 2685 | test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, |
| 2686 | speed_template_8); |
| 2687 | test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, |
| 2688 | speed_template_8); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2689 | break; |
| 2690 | |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 2691 | case 503: |
| 2692 | test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, |
| 2693 | speed_template_16_32); |
| 2694 | test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, |
| 2695 | speed_template_16_32); |
| 2696 | test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, |
| 2697 | speed_template_16_32); |
| 2698 | test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, |
| 2699 | speed_template_16_32); |
| 2700 | test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, |
| 2701 | speed_template_16_32); |
| 2702 | test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, |
| 2703 | speed_template_16_32); |
Jussi Kivilinna | 87aae4b | 2011-10-18 13:32:39 +0300 | [diff] [blame] | 2704 | test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
| 2705 | speed_template_32_48); |
| 2706 | test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, |
| 2707 | speed_template_32_48); |
Jussi Kivilinna | 5209c07 | 2011-10-18 13:33:22 +0300 | [diff] [blame] | 2708 | test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
| 2709 | speed_template_32_64); |
| 2710 | test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, |
| 2711 | speed_template_32_64); |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 2712 | break; |
| 2713 | |
Johannes Goetzfried | 107778b5 | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2714 | case 504: |
| 2715 | test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
| 2716 | speed_template_16_24_32); |
| 2717 | test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
| 2718 | speed_template_16_24_32); |
| 2719 | test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
| 2720 | speed_template_16_24_32); |
| 2721 | test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
| 2722 | speed_template_16_24_32); |
| 2723 | test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
| 2724 | speed_template_16_24_32); |
| 2725 | test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, |
| 2726 | speed_template_16_24_32); |
| 2727 | test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
| 2728 | speed_template_32_40_48); |
| 2729 | test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, |
| 2730 | speed_template_32_40_48); |
| 2731 | test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
| 2732 | speed_template_32_48_64); |
| 2733 | test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, |
| 2734 | speed_template_32_48_64); |
| 2735 | break; |
| 2736 | |
Jussi Kivilinna | 31b4cd29 | 2012-06-12 16:52:04 +0800 | [diff] [blame] | 2737 | case 505: |
| 2738 | test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, |
| 2739 | speed_template_8); |
| 2740 | break; |
| 2741 | |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 2742 | case 506: |
| 2743 | test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, |
| 2744 | speed_template_8_16); |
| 2745 | test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, |
| 2746 | speed_template_8_16); |
| 2747 | test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, |
| 2748 | speed_template_8_16); |
| 2749 | test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, |
| 2750 | speed_template_8_16); |
| 2751 | test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, |
| 2752 | speed_template_8_16); |
| 2753 | test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, |
| 2754 | speed_template_8_16); |
| 2755 | break; |
| 2756 | |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 2757 | case 507: |
| 2758 | test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, |
| 2759 | speed_template_16_32); |
| 2760 | test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, |
| 2761 | speed_template_16_32); |
| 2762 | test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, |
| 2763 | speed_template_16_32); |
| 2764 | test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, |
| 2765 | speed_template_16_32); |
| 2766 | test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, |
| 2767 | speed_template_16_32); |
| 2768 | test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, |
| 2769 | speed_template_16_32); |
| 2770 | test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, |
| 2771 | speed_template_32_48); |
| 2772 | test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, |
| 2773 | speed_template_32_48); |
| 2774 | test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, |
| 2775 | speed_template_32_64); |
| 2776 | test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, |
| 2777 | speed_template_32_64); |
| 2778 | break; |
| 2779 | |
Jussi Kivilinna | bf9c518 | 2012-10-26 14:48:51 +0300 | [diff] [blame] | 2780 | case 508: |
| 2781 | test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
| 2782 | speed_template_16_32); |
| 2783 | test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
| 2784 | speed_template_16_32); |
| 2785 | test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
| 2786 | speed_template_16_32); |
| 2787 | test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
| 2788 | speed_template_16_32); |
| 2789 | test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
| 2790 | speed_template_16_32); |
| 2791 | test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, |
| 2792 | speed_template_16_32); |
| 2793 | test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, |
| 2794 | speed_template_32_48); |
| 2795 | test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, |
| 2796 | speed_template_32_48); |
| 2797 | test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, |
| 2798 | speed_template_32_64); |
| 2799 | test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, |
| 2800 | speed_template_32_64); |
| 2801 | break; |
| 2802 | |
Jussi Kivilinna | ad8b7c3 | 2013-04-13 13:46:40 +0300 | [diff] [blame] | 2803 | case 509: |
| 2804 | test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2805 | speed_template_8_32); |
| 2806 | test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
| 2807 | speed_template_8_32); |
| 2808 | test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2809 | speed_template_8_32); |
| 2810 | test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
| 2811 | speed_template_8_32); |
| 2812 | test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2813 | speed_template_8_32); |
| 2814 | test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, |
| 2815 | speed_template_8_32); |
| 2816 | break; |
| 2817 | |
Tianjia Zhang | a7fc80b | 2021-07-20 11:46:42 +0800 | [diff] [blame] | 2818 | case 518: |
| 2819 | test_acipher_speed("ecb(sm4)", ENCRYPT, sec, NULL, 0, |
| 2820 | speed_template_16); |
| 2821 | test_acipher_speed("ecb(sm4)", DECRYPT, sec, NULL, 0, |
| 2822 | speed_template_16); |
| 2823 | test_acipher_speed("cbc(sm4)", ENCRYPT, sec, NULL, 0, |
| 2824 | speed_template_16); |
| 2825 | test_acipher_speed("cbc(sm4)", DECRYPT, sec, NULL, 0, |
| 2826 | speed_template_16); |
| 2827 | test_acipher_speed("cfb(sm4)", ENCRYPT, sec, NULL, 0, |
| 2828 | speed_template_16); |
| 2829 | test_acipher_speed("cfb(sm4)", DECRYPT, sec, NULL, 0, |
| 2830 | speed_template_16); |
| 2831 | test_acipher_speed("ctr(sm4)", ENCRYPT, sec, NULL, 0, |
| 2832 | speed_template_16); |
| 2833 | test_acipher_speed("ctr(sm4)", DECRYPT, sec, NULL, 0, |
| 2834 | speed_template_16); |
| 2835 | break; |
| 2836 | |
Gilad Ben-Yossef | e161c59 | 2017-12-17 08:29:04 +0000 | [diff] [blame] | 2837 | case 600: |
| 2838 | test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
| 2839 | speed_template_16_24_32, num_mb); |
| 2840 | test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
| 2841 | speed_template_16_24_32, num_mb); |
| 2842 | test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
| 2843 | speed_template_16_24_32, num_mb); |
| 2844 | test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
| 2845 | speed_template_16_24_32, num_mb); |
| 2846 | test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
| 2847 | speed_template_32_40_48, num_mb); |
| 2848 | test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
| 2849 | speed_template_32_40_48, num_mb); |
| 2850 | test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
| 2851 | speed_template_32_64, num_mb); |
| 2852 | test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
| 2853 | speed_template_32_64, num_mb); |
| 2854 | test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0, |
| 2855 | speed_template_16_24_32, num_mb); |
| 2856 | test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0, |
| 2857 | speed_template_16_24_32, num_mb); |
| 2858 | test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
| 2859 | speed_template_16_24_32, num_mb); |
| 2860 | test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, |
| 2861 | speed_template_16_24_32, num_mb); |
| 2862 | test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, |
| 2863 | speed_template_16_24_32, num_mb); |
| 2864 | test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, |
| 2865 | speed_template_16_24_32, num_mb); |
| 2866 | test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, |
| 2867 | speed_template_16_24_32, num_mb); |
| 2868 | test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, |
| 2869 | speed_template_16_24_32, num_mb); |
| 2870 | test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, |
| 2871 | 0, speed_template_20_28_36, num_mb); |
| 2872 | test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, |
| 2873 | 0, speed_template_20_28_36, num_mb); |
| 2874 | break; |
| 2875 | |
| 2876 | case 601: |
| 2877 | test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
| 2878 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2879 | speed_template_24, num_mb); |
| 2880 | test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec, |
| 2881 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2882 | speed_template_24, num_mb); |
| 2883 | test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
| 2884 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2885 | speed_template_24, num_mb); |
| 2886 | test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec, |
| 2887 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2888 | speed_template_24, num_mb); |
| 2889 | test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec, |
| 2890 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2891 | speed_template_24, num_mb); |
| 2892 | test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec, |
| 2893 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2894 | speed_template_24, num_mb); |
| 2895 | test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec, |
| 2896 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2897 | speed_template_24, num_mb); |
| 2898 | test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec, |
| 2899 | des3_speed_template, DES3_SPEED_VECTORS, |
| 2900 | speed_template_24, num_mb); |
| 2901 | break; |
| 2902 | |
| 2903 | case 602: |
| 2904 | test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
| 2905 | speed_template_8, num_mb); |
| 2906 | test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
| 2907 | speed_template_8, num_mb); |
| 2908 | test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
| 2909 | speed_template_8, num_mb); |
| 2910 | test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
| 2911 | speed_template_8, num_mb); |
| 2912 | test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, |
| 2913 | speed_template_8, num_mb); |
| 2914 | test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, |
| 2915 | speed_template_8, num_mb); |
| 2916 | test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, |
| 2917 | speed_template_8, num_mb); |
| 2918 | test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, |
| 2919 | speed_template_8, num_mb); |
| 2920 | break; |
| 2921 | |
| 2922 | case 603: |
| 2923 | test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, |
| 2924 | speed_template_16_32, num_mb); |
| 2925 | test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, |
| 2926 | speed_template_16_32, num_mb); |
| 2927 | test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, |
| 2928 | speed_template_16_32, num_mb); |
| 2929 | test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, |
| 2930 | speed_template_16_32, num_mb); |
| 2931 | test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, |
| 2932 | speed_template_16_32, num_mb); |
| 2933 | test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, |
| 2934 | speed_template_16_32, num_mb); |
| 2935 | test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
| 2936 | speed_template_32_48, num_mb); |
| 2937 | test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, |
| 2938 | speed_template_32_48, num_mb); |
| 2939 | test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
| 2940 | speed_template_32_64, num_mb); |
| 2941 | test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, |
| 2942 | speed_template_32_64, num_mb); |
| 2943 | break; |
| 2944 | |
| 2945 | case 604: |
| 2946 | test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
| 2947 | speed_template_16_24_32, num_mb); |
| 2948 | test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
| 2949 | speed_template_16_24_32, num_mb); |
| 2950 | test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
| 2951 | speed_template_16_24_32, num_mb); |
| 2952 | test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
| 2953 | speed_template_16_24_32, num_mb); |
| 2954 | test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
| 2955 | speed_template_16_24_32, num_mb); |
| 2956 | test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, |
| 2957 | speed_template_16_24_32, num_mb); |
| 2958 | test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
| 2959 | speed_template_32_40_48, num_mb); |
| 2960 | test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, |
| 2961 | speed_template_32_40_48, num_mb); |
| 2962 | test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
| 2963 | speed_template_32_48_64, num_mb); |
| 2964 | test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, |
| 2965 | speed_template_32_48_64, num_mb); |
| 2966 | break; |
| 2967 | |
| 2968 | case 605: |
| 2969 | test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, |
| 2970 | speed_template_8, num_mb); |
| 2971 | break; |
| 2972 | |
| 2973 | case 606: |
| 2974 | test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, |
| 2975 | speed_template_8_16, num_mb); |
| 2976 | test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, |
| 2977 | speed_template_8_16, num_mb); |
| 2978 | test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, |
| 2979 | speed_template_8_16, num_mb); |
| 2980 | test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, |
| 2981 | speed_template_8_16, num_mb); |
| 2982 | test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, |
| 2983 | speed_template_8_16, num_mb); |
| 2984 | test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, |
| 2985 | speed_template_8_16, num_mb); |
| 2986 | break; |
| 2987 | |
| 2988 | case 607: |
| 2989 | test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, |
| 2990 | speed_template_16_32, num_mb); |
| 2991 | test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, |
| 2992 | speed_template_16_32, num_mb); |
| 2993 | test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, |
| 2994 | speed_template_16_32, num_mb); |
| 2995 | test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, |
| 2996 | speed_template_16_32, num_mb); |
| 2997 | test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, |
| 2998 | speed_template_16_32, num_mb); |
| 2999 | test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, |
| 3000 | speed_template_16_32, num_mb); |
| 3001 | test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, |
| 3002 | speed_template_32_48, num_mb); |
| 3003 | test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, |
| 3004 | speed_template_32_48, num_mb); |
| 3005 | test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, |
| 3006 | speed_template_32_64, num_mb); |
| 3007 | test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, |
| 3008 | speed_template_32_64, num_mb); |
| 3009 | break; |
| 3010 | |
| 3011 | case 608: |
| 3012 | test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
| 3013 | speed_template_16_32, num_mb); |
| 3014 | test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
| 3015 | speed_template_16_32, num_mb); |
| 3016 | test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
| 3017 | speed_template_16_32, num_mb); |
| 3018 | test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
| 3019 | speed_template_16_32, num_mb); |
| 3020 | test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
| 3021 | speed_template_16_32, num_mb); |
| 3022 | test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, |
| 3023 | speed_template_16_32, num_mb); |
| 3024 | test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, |
| 3025 | speed_template_32_48, num_mb); |
| 3026 | test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, |
| 3027 | speed_template_32_48, num_mb); |
| 3028 | test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, |
| 3029 | speed_template_32_64, num_mb); |
| 3030 | test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, |
| 3031 | speed_template_32_64, num_mb); |
| 3032 | break; |
| 3033 | |
| 3034 | case 609: |
| 3035 | test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
| 3036 | speed_template_8_32, num_mb); |
| 3037 | test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
| 3038 | speed_template_8_32, num_mb); |
| 3039 | test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
| 3040 | speed_template_8_32, num_mb); |
| 3041 | test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
| 3042 | speed_template_8_32, num_mb); |
| 3043 | test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
| 3044 | speed_template_8_32, num_mb); |
| 3045 | test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, |
| 3046 | speed_template_8_32, num_mb); |
| 3047 | break; |
| 3048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | case 1000: |
| 3050 | test_available(); |
| 3051 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | } |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 3053 | |
| 3054 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 3057 | static int __init tcrypt_mod_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | { |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 3059 | int err = -ENOMEM; |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 3060 | int i; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 3061 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 3062 | for (i = 0; i < TVMEMSIZE; i++) { |
| 3063 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); |
| 3064 | if (!tvmem[i]) |
| 3065 | goto err_free_tv; |
| 3066 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | |
Kees Cook | 4e234ee | 2018-04-26 19:57:28 -0700 | [diff] [blame] | 3068 | err = do_test(alg, type, mask, mode, num_mb); |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 3069 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 3070 | if (err) { |
| 3071 | printk(KERN_ERR "tcrypt: one or more tests failed!\n"); |
| 3072 | goto err_free_tv; |
Rabin Vincent | 76512f2 | 2017-01-18 14:54:05 +0100 | [diff] [blame] | 3073 | } else { |
| 3074 | pr_debug("all tests passed\n"); |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 3075 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 3077 | /* We intentionaly return -EAGAIN to prevent keeping the module, |
| 3078 | * unless we're running in fips mode. It does all its work from |
| 3079 | * init() and doesn't offer any runtime functionality, but in |
| 3080 | * the fips case, checking for a successful load is helpful. |
Michal Ludvig | 14fdf47 | 2006-05-30 14:49:38 +1000 | [diff] [blame] | 3081 | * => we don't need it in the memory, do we? |
| 3082 | * -- mludvig |
| 3083 | */ |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 3084 | if (!fips_enabled) |
| 3085 | err = -EAGAIN; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 3086 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 3087 | err_free_tv: |
| 3088 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) |
| 3089 | free_page((unsigned long)tvmem[i]); |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 3090 | |
| 3091 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | /* |
| 3095 | * If an init function is provided, an exit function must also be provided |
| 3096 | * to allow module unload. |
| 3097 | */ |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 3098 | static void __exit tcrypt_mod_fini(void) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | |
Ard Biesheuvel | 08a7e33 | 2020-11-20 12:04:31 +0100 | [diff] [blame] | 3100 | late_initcall(tcrypt_mod_init); |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 3101 | module_exit(tcrypt_mod_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 3103 | module_param(alg, charp, 0); |
| 3104 | module_param(type, uint, 0); |
Herbert Xu | 7be380f | 2009-07-14 16:06:54 +0800 | [diff] [blame] | 3105 | module_param(mask, uint, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | module_param(mode, int, 0); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 3107 | module_param(sec, uint, 0); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 3108 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
| 3109 | "(defaults to zero which uses CPU cycles instead)"); |
Gilad Ben-Yossef | 8fcdc86 | 2017-12-17 08:29:02 +0000 | [diff] [blame] | 3110 | module_param(num_mb, uint, 0000); |
| 3111 | MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)"); |
Herbert Xu | ba974ad | 2020-08-05 15:57:08 +1000 | [diff] [blame] | 3112 | module_param(klen, uint, 0); |
| 3113 | MODULE_PARM_DESC(klen, "Key length (defaults to 0)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | |
| 3115 | MODULE_LICENSE("GPL"); |
| 3116 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
| 3117 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |