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