Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Quick & dirty crypto testing module. |
| 3 | * |
| 4 | * This will only exist until we have a better testing mechanism |
| 5 | * (e.g. a char device). |
| 6 | * |
| 7 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
| 8 | * Copyright (c) 2002 Jean-Francois Dive <jef@linuxbe.org> |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 9 | * Copyright (c) 2007 Nokia Siemens Networks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 11 | * Updated RFC4106 AES-GCM testing. |
| 12 | * Authors: Aidan O'Mahony (aidan.o.mahony@intel.com) |
| 13 | * Adrian Hoban <adrian.hoban@intel.com> |
| 14 | * Gabriele Paoloni <gabriele.paoloni@intel.com> |
| 15 | * Tadeusz Struk (tadeusz.struk@intel.com) |
| 16 | * Copyright (c) 2010, Intel Corporation. |
| 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * This program is free software; you can redistribute it and/or modify it |
| 19 | * under the terms of the GNU General Public License as published by the Free |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 20 | * Software Foundation; either version 2 of the License, or (at your option) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * any later version. |
| 22 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | */ |
| 24 | |
Herbert Xu | 18e33e6 | 2008-07-10 16:01:22 +0800 | [diff] [blame] | 25 | #include <crypto/hash.h> |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 26 | #include <linux/err.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" |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 37 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | /* |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 40 | * Need slab memory for testing (size in number of pages). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | */ |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 42 | #define TVMEMSIZE 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | /* |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 45 | * Used by test_cipher_speed() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | */ |
| 47 | #define ENCRYPT 1 |
| 48 | #define DECRYPT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 50 | /* |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 51 | * return a string with the driver name |
| 52 | */ |
| 53 | #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm)) |
| 54 | |
| 55 | /* |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 56 | * Used by test_cipher_speed() |
| 57 | */ |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 58 | static unsigned int sec; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 59 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 60 | static char *alg = NULL; |
| 61 | static u32 type; |
Herbert Xu | 7be380f | 2009-07-14 16:06:54 +0800 | [diff] [blame] | 62 | static u32 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static int mode; |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 64 | static char *tvmem[TVMEMSIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | static char *check[] = { |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 67 | "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", |
| 68 | "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", |
| 69 | "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 70 | "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 71 | "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 72 | "lzo", "cts", "zlib", NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 75 | static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 76 | struct scatterlist *sg, int blen, int secs) |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 77 | { |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 78 | unsigned long start, end; |
| 79 | int bcount; |
| 80 | int ret; |
| 81 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 82 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 83 | time_before(jiffies, end); bcount++) { |
| 84 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 85 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 86 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 87 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 88 | |
| 89 | if (ret) |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | printk("%d operations in %d seconds (%ld bytes)\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 94 | bcount, secs, (long)bcount * blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 98 | static int test_cipher_cycles(struct blkcipher_desc *desc, int enc, |
| 99 | struct scatterlist *sg, int blen) |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 100 | { |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 101 | unsigned long cycles = 0; |
| 102 | int ret = 0; |
| 103 | int i; |
| 104 | |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 105 | local_irq_disable(); |
| 106 | |
| 107 | /* Warm-up run. */ |
| 108 | for (i = 0; i < 4; i++) { |
| 109 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 110 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 111 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 112 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 113 | |
| 114 | if (ret) |
| 115 | goto out; |
| 116 | } |
| 117 | |
| 118 | /* The real thing. */ |
| 119 | for (i = 0; i < 8; i++) { |
| 120 | cycles_t start, end; |
| 121 | |
| 122 | start = get_cycles(); |
| 123 | if (enc) |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 124 | ret = crypto_blkcipher_encrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 125 | else |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 126 | ret = crypto_blkcipher_decrypt(desc, sg, sg, blen); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 127 | end = get_cycles(); |
| 128 | |
| 129 | if (ret) |
| 130 | goto out; |
| 131 | |
| 132 | cycles += end - start; |
| 133 | } |
| 134 | |
| 135 | out: |
| 136 | local_irq_enable(); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 137 | |
| 138 | if (ret == 0) |
| 139 | printk("1 operation in %lu cycles (%d bytes)\n", |
| 140 | (cycles + 4) / 8, blen); |
| 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 145 | static int test_aead_jiffies(struct aead_request *req, int enc, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 146 | int blen, int secs) |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 147 | { |
| 148 | unsigned long start, end; |
| 149 | int bcount; |
| 150 | int ret; |
| 151 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 152 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 153 | time_before(jiffies, end); bcount++) { |
| 154 | if (enc) |
| 155 | ret = crypto_aead_encrypt(req); |
| 156 | else |
| 157 | ret = crypto_aead_decrypt(req); |
| 158 | |
| 159 | if (ret) |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | printk("%d operations in %d seconds (%ld bytes)\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 164 | bcount, secs, (long)bcount * blen); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | static int test_aead_cycles(struct aead_request *req, int enc, int blen) |
| 169 | { |
| 170 | unsigned long cycles = 0; |
| 171 | int ret = 0; |
| 172 | int i; |
| 173 | |
| 174 | local_irq_disable(); |
| 175 | |
| 176 | /* Warm-up run. */ |
| 177 | for (i = 0; i < 4; i++) { |
| 178 | if (enc) |
| 179 | ret = crypto_aead_encrypt(req); |
| 180 | else |
| 181 | ret = crypto_aead_decrypt(req); |
| 182 | |
| 183 | if (ret) |
| 184 | goto out; |
| 185 | } |
| 186 | |
| 187 | /* The real thing. */ |
| 188 | for (i = 0; i < 8; i++) { |
| 189 | cycles_t start, end; |
| 190 | |
| 191 | start = get_cycles(); |
| 192 | if (enc) |
| 193 | ret = crypto_aead_encrypt(req); |
| 194 | else |
| 195 | ret = crypto_aead_decrypt(req); |
| 196 | end = get_cycles(); |
| 197 | |
| 198 | if (ret) |
| 199 | goto out; |
| 200 | |
| 201 | cycles += end - start; |
| 202 | } |
| 203 | |
| 204 | out: |
| 205 | local_irq_enable(); |
| 206 | |
| 207 | if (ret == 0) |
| 208 | printk("1 operation in %lu cycles (%d bytes)\n", |
| 209 | (cycles + 4) / 8, blen); |
| 210 | |
| 211 | return ret; |
| 212 | } |
| 213 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 214 | static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 215 | static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 }; |
| 216 | |
| 217 | #define XBUFSIZE 8 |
| 218 | #define MAX_IVLEN 32 |
| 219 | |
| 220 | static int testmgr_alloc_buf(char *buf[XBUFSIZE]) |
| 221 | { |
| 222 | int i; |
| 223 | |
| 224 | for (i = 0; i < XBUFSIZE; i++) { |
| 225 | buf[i] = (void *)__get_free_page(GFP_KERNEL); |
| 226 | if (!buf[i]) |
| 227 | goto err_free_buf; |
| 228 | } |
| 229 | |
| 230 | return 0; |
| 231 | |
| 232 | err_free_buf: |
| 233 | while (i-- > 0) |
| 234 | free_page((unsigned long)buf[i]); |
| 235 | |
| 236 | return -ENOMEM; |
| 237 | } |
| 238 | |
| 239 | static void testmgr_free_buf(char *buf[XBUFSIZE]) |
| 240 | { |
| 241 | int i; |
| 242 | |
| 243 | for (i = 0; i < XBUFSIZE; i++) |
| 244 | free_page((unsigned long)buf[i]); |
| 245 | } |
| 246 | |
| 247 | static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE], |
| 248 | unsigned int buflen) |
| 249 | { |
| 250 | int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE; |
| 251 | int k, rem; |
| 252 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 253 | if (np > XBUFSIZE) { |
| 254 | rem = PAGE_SIZE; |
| 255 | np = XBUFSIZE; |
Cristian Stoica | c476899 | 2015-01-27 11:54:27 +0200 | [diff] [blame] | 256 | } else { |
| 257 | rem = buflen % PAGE_SIZE; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 258 | } |
Cristian Stoica | c476899 | 2015-01-27 11:54:27 +0200 | [diff] [blame] | 259 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 260 | sg_init_table(sg, np); |
Cristian Stoica | c476899 | 2015-01-27 11:54:27 +0200 | [diff] [blame] | 261 | np--; |
| 262 | for (k = 0; k < np; k++) |
| 263 | sg_set_buf(&sg[k], xbuf[k], PAGE_SIZE); |
| 264 | |
| 265 | sg_set_buf(&sg[k], xbuf[k], rem); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 268 | 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] | 269 | struct aead_speed_template *template, |
| 270 | unsigned int tcount, u8 authsize, |
| 271 | unsigned int aad_size, u8 *keysize) |
| 272 | { |
| 273 | unsigned int i, j; |
| 274 | struct crypto_aead *tfm; |
| 275 | int ret = -ENOMEM; |
| 276 | const char *key; |
| 277 | struct aead_request *req; |
| 278 | struct scatterlist *sg; |
| 279 | struct scatterlist *asg; |
| 280 | struct scatterlist *sgout; |
| 281 | const char *e; |
| 282 | void *assoc; |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 283 | char *iv; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 284 | char *xbuf[XBUFSIZE]; |
| 285 | char *xoutbuf[XBUFSIZE]; |
| 286 | char *axbuf[XBUFSIZE]; |
| 287 | unsigned int *b_size; |
| 288 | unsigned int iv_len; |
| 289 | |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 290 | iv = kzalloc(MAX_IVLEN, GFP_KERNEL); |
| 291 | if (!iv) |
| 292 | return; |
| 293 | |
Christian Engelmayer | ac5f863 | 2014-04-21 20:45:59 +0200 | [diff] [blame] | 294 | if (aad_size >= PAGE_SIZE) { |
| 295 | pr_err("associate data length (%u) too big\n", aad_size); |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 296 | goto out_noxbuf; |
Christian Engelmayer | ac5f863 | 2014-04-21 20:45:59 +0200 | [diff] [blame] | 297 | } |
| 298 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 299 | if (enc == ENCRYPT) |
| 300 | e = "encryption"; |
| 301 | else |
| 302 | e = "decryption"; |
| 303 | |
| 304 | if (testmgr_alloc_buf(xbuf)) |
| 305 | goto out_noxbuf; |
| 306 | if (testmgr_alloc_buf(axbuf)) |
| 307 | goto out_noaxbuf; |
| 308 | if (testmgr_alloc_buf(xoutbuf)) |
| 309 | goto out_nooutbuf; |
| 310 | |
| 311 | sg = kmalloc(sizeof(*sg) * 8 * 3, GFP_KERNEL); |
| 312 | if (!sg) |
| 313 | goto out_nosg; |
| 314 | asg = &sg[8]; |
| 315 | sgout = &asg[8]; |
| 316 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 317 | tfm = crypto_alloc_aead(algo, 0, 0); |
| 318 | |
| 319 | if (IS_ERR(tfm)) { |
| 320 | pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo, |
| 321 | PTR_ERR(tfm)); |
Christian Engelmayer | a2ea6ed | 2014-04-21 20:46:40 +0200 | [diff] [blame] | 322 | goto out_notfm; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 325 | printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, |
| 326 | get_driver_name(crypto_aead, tfm), e); |
| 327 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 328 | req = aead_request_alloc(tfm, GFP_KERNEL); |
| 329 | if (!req) { |
| 330 | pr_err("alg: aead: Failed to allocate request for %s\n", |
| 331 | algo); |
Christian Engelmayer | 6af1f93 | 2014-04-21 20:47:05 +0200 | [diff] [blame] | 332 | goto out_noreq; |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | i = 0; |
| 336 | do { |
| 337 | b_size = aead_sizes; |
| 338 | do { |
| 339 | assoc = axbuf[0]; |
Christian Engelmayer | ac5f863 | 2014-04-21 20:45:59 +0200 | [diff] [blame] | 340 | memset(assoc, 0xff, aad_size); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 341 | sg_init_one(&asg[0], assoc, aad_size); |
| 342 | |
| 343 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
| 344 | pr_err("template (%u) too big for tvmem (%lu)\n", |
| 345 | *keysize + *b_size, |
| 346 | TVMEMSIZE * PAGE_SIZE); |
| 347 | goto out; |
| 348 | } |
| 349 | |
| 350 | key = tvmem[0]; |
| 351 | for (j = 0; j < tcount; j++) { |
| 352 | if (template[j].klen == *keysize) { |
| 353 | key = template[j].key; |
| 354 | break; |
| 355 | } |
| 356 | } |
| 357 | ret = crypto_aead_setkey(tfm, key, *keysize); |
| 358 | ret = crypto_aead_setauthsize(tfm, authsize); |
| 359 | |
| 360 | iv_len = crypto_aead_ivsize(tfm); |
| 361 | if (iv_len) |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 362 | memset(iv, 0xff, iv_len); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 363 | |
| 364 | crypto_aead_clear_flags(tfm, ~0); |
| 365 | printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ", |
| 366 | i, *keysize * 8, *b_size); |
| 367 | |
| 368 | |
| 369 | memset(tvmem[0], 0xff, PAGE_SIZE); |
| 370 | |
| 371 | if (ret) { |
| 372 | pr_err("setkey() failed flags=%x\n", |
| 373 | crypto_aead_get_flags(tfm)); |
| 374 | goto out; |
| 375 | } |
| 376 | |
| 377 | sg_init_aead(&sg[0], xbuf, |
| 378 | *b_size + (enc ? authsize : 0)); |
| 379 | |
| 380 | sg_init_aead(&sgout[0], xoutbuf, |
| 381 | *b_size + (enc ? authsize : 0)); |
| 382 | |
| 383 | aead_request_set_crypt(req, sg, sgout, *b_size, iv); |
| 384 | aead_request_set_assoc(req, asg, aad_size); |
| 385 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 386 | if (secs) |
| 387 | ret = test_aead_jiffies(req, enc, *b_size, |
| 388 | secs); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 389 | else |
| 390 | ret = test_aead_cycles(req, enc, *b_size); |
| 391 | |
| 392 | if (ret) { |
| 393 | pr_err("%s() failed return code=%d\n", e, ret); |
| 394 | break; |
| 395 | } |
| 396 | b_size++; |
| 397 | i++; |
| 398 | } while (*b_size); |
| 399 | keysize++; |
| 400 | } while (*keysize); |
| 401 | |
| 402 | out: |
Christian Engelmayer | 6af1f93 | 2014-04-21 20:47:05 +0200 | [diff] [blame] | 403 | aead_request_free(req); |
| 404 | out_noreq: |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 405 | crypto_free_aead(tfm); |
Christian Engelmayer | a2ea6ed | 2014-04-21 20:46:40 +0200 | [diff] [blame] | 406 | out_notfm: |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 407 | kfree(sg); |
| 408 | out_nosg: |
| 409 | testmgr_free_buf(xoutbuf); |
| 410 | out_nooutbuf: |
| 411 | testmgr_free_buf(axbuf); |
| 412 | out_noaxbuf: |
| 413 | testmgr_free_buf(xbuf); |
| 414 | out_noxbuf: |
Cristian Stoica | 96692a73 | 2015-01-28 13:07:32 +0200 | [diff] [blame] | 415 | kfree(iv); |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 416 | return; |
| 417 | } |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 418 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 419 | static void test_cipher_speed(const char *algo, int enc, unsigned int secs, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 420 | struct cipher_speed_template *template, |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 421 | unsigned int tcount, u8 *keysize) |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 422 | { |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 423 | unsigned int ret, i, j, iv_len; |
David Sterba | f07ef1d | 2011-03-04 15:28:52 +0800 | [diff] [blame] | 424 | const char *key; |
| 425 | char iv[128]; |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 426 | struct crypto_blkcipher *tfm; |
| 427 | struct blkcipher_desc desc; |
| 428 | const char *e; |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 429 | u32 *b_size; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 430 | |
| 431 | if (enc == ENCRYPT) |
| 432 | e = "encryption"; |
| 433 | else |
| 434 | e = "decryption"; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 435 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 436 | tfm = crypto_alloc_blkcipher(algo, 0, CRYPTO_ALG_ASYNC); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 437 | |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 438 | if (IS_ERR(tfm)) { |
| 439 | printk("failed to load transform for %s: %ld\n", algo, |
| 440 | PTR_ERR(tfm)); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 441 | return; |
| 442 | } |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 443 | desc.tfm = tfm; |
| 444 | desc.flags = 0; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 445 | |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 446 | printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, |
| 447 | get_driver_name(crypto_blkcipher, tfm), e); |
| 448 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 449 | i = 0; |
| 450 | do { |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 451 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 452 | b_size = block_sizes; |
| 453 | do { |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 454 | struct scatterlist sg[TVMEMSIZE]; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 455 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 456 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
| 457 | printk("template (%u) too big for " |
| 458 | "tvmem (%lu)\n", *keysize + *b_size, |
| 459 | TVMEMSIZE * PAGE_SIZE); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 460 | goto out; |
| 461 | } |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 462 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 463 | printk("test %u (%d bit key, %d byte blocks): ", i, |
| 464 | *keysize * 8, *b_size); |
| 465 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 466 | memset(tvmem[0], 0xff, PAGE_SIZE); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 467 | |
| 468 | /* set key, plain text and IV */ |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 469 | key = tvmem[0]; |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 470 | for (j = 0; j < tcount; j++) { |
| 471 | if (template[j].klen == *keysize) { |
| 472 | key = template[j].key; |
| 473 | break; |
| 474 | } |
| 475 | } |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 476 | |
| 477 | ret = crypto_blkcipher_setkey(tfm, key, *keysize); |
| 478 | if (ret) { |
| 479 | printk("setkey() failed flags=%x\n", |
| 480 | crypto_blkcipher_get_flags(tfm)); |
| 481 | goto out; |
| 482 | } |
| 483 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 484 | sg_init_table(sg, TVMEMSIZE); |
| 485 | sg_set_buf(sg, tvmem[0] + *keysize, |
| 486 | PAGE_SIZE - *keysize); |
| 487 | for (j = 1; j < TVMEMSIZE; j++) { |
| 488 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); |
| 489 | memset (tvmem[j], 0xff, PAGE_SIZE); |
| 490 | } |
| 491 | |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 492 | iv_len = crypto_blkcipher_ivsize(tfm); |
| 493 | if (iv_len) { |
| 494 | memset(&iv, 0xff, iv_len); |
| 495 | crypto_blkcipher_set_iv(tfm, iv, iv_len); |
| 496 | } |
| 497 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 498 | if (secs) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 499 | ret = test_cipher_jiffies(&desc, enc, sg, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 500 | *b_size, secs); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 501 | else |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 502 | ret = test_cipher_cycles(&desc, enc, sg, |
| 503 | *b_size); |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 504 | |
| 505 | if (ret) { |
| 506 | printk("%s() failed flags=%x\n", e, desc.flags); |
Herbert Xu | dce907c | 2005-06-22 13:27:51 -0700 | [diff] [blame] | 507 | break; |
| 508 | } |
Sebastian Siewior | d5dc392 | 2008-03-11 21:27:11 +0800 | [diff] [blame] | 509 | b_size++; |
| 510 | i++; |
| 511 | } while (*b_size); |
| 512 | keysize++; |
| 513 | } while (*keysize); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 514 | |
| 515 | out: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 516 | crypto_free_blkcipher(tfm); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 519 | static int test_hash_jiffies_digest(struct hash_desc *desc, |
| 520 | struct scatterlist *sg, int blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 521 | char *out, int secs) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 522 | { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 523 | unsigned long start, end; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 524 | int bcount; |
| 525 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 526 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 527 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 528 | time_before(jiffies, end); bcount++) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 529 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 530 | if (ret) |
| 531 | return ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | printk("%6u opers/sec, %9lu bytes/sec\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 535 | bcount / secs, ((long)bcount * blen) / secs); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 536 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 537 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 538 | } |
| 539 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 540 | static int test_hash_jiffies(struct hash_desc *desc, struct scatterlist *sg, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 541 | int blen, int plen, char *out, int secs) |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 542 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 543 | unsigned long start, end; |
| 544 | int bcount, pcount; |
| 545 | int ret; |
| 546 | |
| 547 | if (plen == blen) |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 548 | return test_hash_jiffies_digest(desc, sg, blen, out, secs); |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 549 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 550 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 551 | time_before(jiffies, end); bcount++) { |
| 552 | ret = crypto_hash_init(desc); |
| 553 | if (ret) |
| 554 | return ret; |
| 555 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 556 | ret = crypto_hash_update(desc, sg, plen); |
| 557 | if (ret) |
| 558 | return ret; |
| 559 | } |
| 560 | /* we assume there is enough space in 'out' for the result */ |
| 561 | ret = crypto_hash_final(desc, out); |
| 562 | if (ret) |
| 563 | return ret; |
| 564 | } |
| 565 | |
| 566 | printk("%6u opers/sec, %9lu bytes/sec\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 567 | bcount / secs, ((long)bcount * blen) / secs); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 572 | static int test_hash_cycles_digest(struct hash_desc *desc, |
| 573 | struct scatterlist *sg, int blen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 574 | { |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 575 | unsigned long cycles = 0; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 576 | int i; |
| 577 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 578 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 579 | local_irq_disable(); |
| 580 | |
| 581 | /* Warm-up run. */ |
| 582 | for (i = 0; i < 4; i++) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 583 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 584 | if (ret) |
| 585 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* The real thing. */ |
| 589 | for (i = 0; i < 8; i++) { |
| 590 | cycles_t start, end; |
| 591 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 592 | start = get_cycles(); |
| 593 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 594 | ret = crypto_hash_digest(desc, sg, blen, out); |
| 595 | if (ret) |
| 596 | goto out; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 597 | |
| 598 | end = get_cycles(); |
| 599 | |
| 600 | cycles += end - start; |
| 601 | } |
| 602 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 603 | out: |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 604 | local_irq_enable(); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 605 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 606 | if (ret) |
| 607 | return ret; |
| 608 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 609 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 610 | cycles / 8, cycles / (8 * blen)); |
| 611 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 612 | return 0; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 613 | } |
| 614 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 615 | static int test_hash_cycles(struct hash_desc *desc, struct scatterlist *sg, |
| 616 | int blen, int plen, char *out) |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 617 | { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 618 | unsigned long cycles = 0; |
| 619 | int i, pcount; |
| 620 | int ret; |
| 621 | |
| 622 | if (plen == blen) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 623 | return test_hash_cycles_digest(desc, sg, blen, out); |
Herbert Xu | a5a613a | 2007-10-27 00:51:21 -0700 | [diff] [blame] | 624 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 625 | local_irq_disable(); |
| 626 | |
| 627 | /* Warm-up run. */ |
| 628 | for (i = 0; i < 4; i++) { |
| 629 | ret = crypto_hash_init(desc); |
| 630 | if (ret) |
| 631 | goto out; |
| 632 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 633 | ret = crypto_hash_update(desc, sg, plen); |
| 634 | if (ret) |
| 635 | goto out; |
| 636 | } |
Herbert Xu | 29059d1 | 2007-05-18 16:25:19 +1000 | [diff] [blame] | 637 | ret = crypto_hash_final(desc, out); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 638 | if (ret) |
| 639 | goto out; |
| 640 | } |
| 641 | |
| 642 | /* The real thing. */ |
| 643 | for (i = 0; i < 8; i++) { |
| 644 | cycles_t start, end; |
| 645 | |
| 646 | start = get_cycles(); |
| 647 | |
| 648 | ret = crypto_hash_init(desc); |
| 649 | if (ret) |
| 650 | goto out; |
| 651 | for (pcount = 0; pcount < blen; pcount += plen) { |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 652 | ret = crypto_hash_update(desc, sg, plen); |
| 653 | if (ret) |
| 654 | goto out; |
| 655 | } |
| 656 | ret = crypto_hash_final(desc, out); |
| 657 | if (ret) |
| 658 | goto out; |
| 659 | |
| 660 | end = get_cycles(); |
| 661 | |
| 662 | cycles += end - start; |
| 663 | } |
| 664 | |
| 665 | out: |
| 666 | local_irq_enable(); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 667 | |
| 668 | if (ret) |
| 669 | return ret; |
| 670 | |
| 671 | printk("%6lu cycles/operation, %4lu cycles/byte\n", |
| 672 | cycles / 8, cycles / (8 * blen)); |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 677 | static void test_hash_sg_init(struct scatterlist *sg) |
| 678 | { |
| 679 | int i; |
| 680 | |
| 681 | sg_init_table(sg, TVMEMSIZE); |
| 682 | for (i = 0; i < TVMEMSIZE; i++) { |
| 683 | sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); |
| 684 | memset(tvmem[i], 0xff, PAGE_SIZE); |
| 685 | } |
| 686 | } |
| 687 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 688 | static void test_hash_speed(const char *algo, unsigned int secs, |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 689 | struct hash_speed *speed) |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 690 | { |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 691 | struct scatterlist sg[TVMEMSIZE]; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 692 | struct crypto_hash *tfm; |
| 693 | struct hash_desc desc; |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 694 | static char output[1024]; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 695 | int i; |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 696 | int ret; |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 697 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 698 | tfm = crypto_alloc_hash(algo, 0, CRYPTO_ALG_ASYNC); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 699 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 700 | if (IS_ERR(tfm)) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 701 | printk(KERN_ERR "failed to load transform for %s: %ld\n", algo, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 702 | PTR_ERR(tfm)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 703 | return; |
| 704 | } |
| 705 | |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 706 | printk(KERN_INFO "\ntesting speed of %s (%s)\n", algo, |
| 707 | get_driver_name(crypto_hash, tfm)); |
| 708 | |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 709 | desc.tfm = tfm; |
| 710 | desc.flags = 0; |
| 711 | |
| 712 | if (crypto_hash_digestsize(tfm) > sizeof(output)) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 713 | printk(KERN_ERR "digestsize(%u) > outputbuffer(%zu)\n", |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 714 | crypto_hash_digestsize(tfm), sizeof(output)); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 715 | goto out; |
| 716 | } |
| 717 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 718 | test_hash_sg_init(sg); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 719 | for (i = 0; speed[i].blen != 0; i++) { |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 720 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 721 | printk(KERN_ERR |
| 722 | "template (%u) too big for tvmem (%lu)\n", |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 723 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 724 | goto out; |
| 725 | } |
| 726 | |
Huang Ying | 18bcc91 | 2010-03-10 18:30:32 +0800 | [diff] [blame] | 727 | if (speed[i].klen) |
| 728 | crypto_hash_setkey(tfm, tvmem[0], speed[i].klen); |
| 729 | |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 730 | printk(KERN_INFO "test%3u " |
| 731 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 732 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
| 733 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 734 | if (secs) |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 735 | ret = test_hash_jiffies(&desc, sg, speed[i].blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 736 | speed[i].plen, output, secs); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 737 | else |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 738 | ret = test_hash_cycles(&desc, sg, speed[i].blen, |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 739 | speed[i].plen, output); |
| 740 | |
| 741 | if (ret) { |
Frank Seidel | 376bacb | 2009-03-29 15:18:39 +0800 | [diff] [blame] | 742 | printk(KERN_ERR "hashing failed ret=%d\n", ret); |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 743 | break; |
| 744 | } |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | out: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 748 | crypto_free_hash(tfm); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 749 | } |
| 750 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 751 | struct tcrypt_result { |
| 752 | struct completion completion; |
| 753 | int err; |
| 754 | }; |
| 755 | |
| 756 | static void tcrypt_complete(struct crypto_async_request *req, int err) |
| 757 | { |
| 758 | struct tcrypt_result *res = req->data; |
| 759 | |
| 760 | if (err == -EINPROGRESS) |
| 761 | return; |
| 762 | |
| 763 | res->err = err; |
| 764 | complete(&res->completion); |
| 765 | } |
| 766 | |
| 767 | static inline int do_one_ahash_op(struct ahash_request *req, int ret) |
| 768 | { |
| 769 | if (ret == -EINPROGRESS || ret == -EBUSY) { |
| 770 | struct tcrypt_result *tr = req->base.data; |
| 771 | |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 772 | wait_for_completion(&tr->completion); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 773 | reinit_completion(&tr->completion); |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 774 | ret = tr->err; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 775 | } |
| 776 | return ret; |
| 777 | } |
| 778 | |
| 779 | static int test_ahash_jiffies_digest(struct ahash_request *req, int blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 780 | char *out, int secs) |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 781 | { |
| 782 | unsigned long start, end; |
| 783 | int bcount; |
| 784 | int ret; |
| 785 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 786 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 787 | time_before(jiffies, end); bcount++) { |
| 788 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); |
| 789 | if (ret) |
| 790 | return ret; |
| 791 | } |
| 792 | |
| 793 | printk("%6u opers/sec, %9lu bytes/sec\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 794 | bcount / secs, ((long)bcount * blen) / secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 795 | |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | static int test_ahash_jiffies(struct ahash_request *req, int blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 800 | int plen, char *out, int secs) |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 801 | { |
| 802 | unsigned long start, end; |
| 803 | int bcount, pcount; |
| 804 | int ret; |
| 805 | |
| 806 | if (plen == blen) |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 807 | return test_ahash_jiffies_digest(req, blen, out, secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 808 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 809 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 810 | time_before(jiffies, end); bcount++) { |
| 811 | ret = crypto_ahash_init(req); |
| 812 | if (ret) |
| 813 | return ret; |
| 814 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 815 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); |
| 816 | if (ret) |
| 817 | return ret; |
| 818 | } |
| 819 | /* we assume there is enough space in 'out' for the result */ |
| 820 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); |
| 821 | if (ret) |
| 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | pr_cont("%6u opers/sec, %9lu bytes/sec\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 826 | bcount / secs, ((long)bcount * blen) / secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int test_ahash_cycles_digest(struct ahash_request *req, int blen, |
| 832 | char *out) |
| 833 | { |
| 834 | unsigned long cycles = 0; |
| 835 | int ret, i; |
| 836 | |
| 837 | /* Warm-up run. */ |
| 838 | for (i = 0; i < 4; i++) { |
| 839 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); |
| 840 | if (ret) |
| 841 | goto out; |
| 842 | } |
| 843 | |
| 844 | /* The real thing. */ |
| 845 | for (i = 0; i < 8; i++) { |
| 846 | cycles_t start, end; |
| 847 | |
| 848 | start = get_cycles(); |
| 849 | |
| 850 | ret = do_one_ahash_op(req, crypto_ahash_digest(req)); |
| 851 | if (ret) |
| 852 | goto out; |
| 853 | |
| 854 | end = get_cycles(); |
| 855 | |
| 856 | cycles += end - start; |
| 857 | } |
| 858 | |
| 859 | out: |
| 860 | if (ret) |
| 861 | return ret; |
| 862 | |
| 863 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", |
| 864 | cycles / 8, cycles / (8 * blen)); |
| 865 | |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | static int test_ahash_cycles(struct ahash_request *req, int blen, |
| 870 | int plen, char *out) |
| 871 | { |
| 872 | unsigned long cycles = 0; |
| 873 | int i, pcount, ret; |
| 874 | |
| 875 | if (plen == blen) |
| 876 | return test_ahash_cycles_digest(req, blen, out); |
| 877 | |
| 878 | /* Warm-up run. */ |
| 879 | for (i = 0; i < 4; i++) { |
| 880 | ret = crypto_ahash_init(req); |
| 881 | if (ret) |
| 882 | goto out; |
| 883 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 884 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); |
| 885 | if (ret) |
| 886 | goto out; |
| 887 | } |
| 888 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); |
| 889 | if (ret) |
| 890 | goto out; |
| 891 | } |
| 892 | |
| 893 | /* The real thing. */ |
| 894 | for (i = 0; i < 8; i++) { |
| 895 | cycles_t start, end; |
| 896 | |
| 897 | start = get_cycles(); |
| 898 | |
| 899 | ret = crypto_ahash_init(req); |
| 900 | if (ret) |
| 901 | goto out; |
| 902 | for (pcount = 0; pcount < blen; pcount += plen) { |
| 903 | ret = do_one_ahash_op(req, crypto_ahash_update(req)); |
| 904 | if (ret) |
| 905 | goto out; |
| 906 | } |
| 907 | ret = do_one_ahash_op(req, crypto_ahash_final(req)); |
| 908 | if (ret) |
| 909 | goto out; |
| 910 | |
| 911 | end = get_cycles(); |
| 912 | |
| 913 | cycles += end - start; |
| 914 | } |
| 915 | |
| 916 | out: |
| 917 | if (ret) |
| 918 | return ret; |
| 919 | |
| 920 | pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", |
| 921 | cycles / 8, cycles / (8 * blen)); |
| 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 926 | static void test_ahash_speed(const char *algo, unsigned int secs, |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 927 | struct hash_speed *speed) |
| 928 | { |
| 929 | struct scatterlist sg[TVMEMSIZE]; |
| 930 | struct tcrypt_result tresult; |
| 931 | struct ahash_request *req; |
| 932 | struct crypto_ahash *tfm; |
| 933 | static char output[1024]; |
| 934 | int i, ret; |
| 935 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 936 | tfm = crypto_alloc_ahash(algo, 0, 0); |
| 937 | if (IS_ERR(tfm)) { |
| 938 | pr_err("failed to load transform for %s: %ld\n", |
| 939 | algo, PTR_ERR(tfm)); |
| 940 | return; |
| 941 | } |
| 942 | |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 943 | printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo, |
| 944 | get_driver_name(crypto_ahash, tfm)); |
| 945 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 946 | if (crypto_ahash_digestsize(tfm) > sizeof(output)) { |
| 947 | pr_err("digestsize(%u) > outputbuffer(%zu)\n", |
| 948 | crypto_ahash_digestsize(tfm), sizeof(output)); |
| 949 | goto out; |
| 950 | } |
| 951 | |
| 952 | test_hash_sg_init(sg); |
| 953 | req = ahash_request_alloc(tfm, GFP_KERNEL); |
| 954 | if (!req) { |
| 955 | pr_err("ahash request allocation failure\n"); |
| 956 | goto out; |
| 957 | } |
| 958 | |
| 959 | init_completion(&tresult.completion); |
| 960 | ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 961 | tcrypt_complete, &tresult); |
| 962 | |
| 963 | for (i = 0; speed[i].blen != 0; i++) { |
| 964 | if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { |
| 965 | pr_err("template (%u) too big for tvmem (%lu)\n", |
| 966 | speed[i].blen, TVMEMSIZE * PAGE_SIZE); |
| 967 | break; |
| 968 | } |
| 969 | |
| 970 | pr_info("test%3u " |
| 971 | "(%5u byte blocks,%5u bytes per update,%4u updates): ", |
| 972 | i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); |
| 973 | |
| 974 | ahash_request_set_crypt(req, sg, output, speed[i].plen); |
| 975 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 976 | if (secs) |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 977 | ret = test_ahash_jiffies(req, speed[i].blen, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 978 | speed[i].plen, output, secs); |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 979 | else |
| 980 | ret = test_ahash_cycles(req, speed[i].blen, |
| 981 | speed[i].plen, output); |
| 982 | |
| 983 | if (ret) { |
| 984 | pr_err("hashing failed ret=%d\n", ret); |
| 985 | break; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | ahash_request_free(req); |
| 990 | |
| 991 | out: |
| 992 | crypto_free_ahash(tfm); |
| 993 | } |
| 994 | |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 995 | static inline int do_one_acipher_op(struct ablkcipher_request *req, int ret) |
| 996 | { |
| 997 | if (ret == -EINPROGRESS || ret == -EBUSY) { |
| 998 | struct tcrypt_result *tr = req->base.data; |
| 999 | |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 1000 | wait_for_completion(&tr->completion); |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 1001 | reinit_completion(&tr->completion); |
Rabin Vincent | 8a45ac1 | 2015-01-09 16:25:28 +0100 | [diff] [blame] | 1002 | ret = tr->err; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | return ret; |
| 1006 | } |
| 1007 | |
| 1008 | static int test_acipher_jiffies(struct ablkcipher_request *req, int enc, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1009 | int blen, int secs) |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1010 | { |
| 1011 | unsigned long start, end; |
| 1012 | int bcount; |
| 1013 | int ret; |
| 1014 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1015 | for (start = jiffies, end = start + secs * HZ, bcount = 0; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1016 | time_before(jiffies, end); bcount++) { |
| 1017 | if (enc) |
| 1018 | ret = do_one_acipher_op(req, |
| 1019 | crypto_ablkcipher_encrypt(req)); |
| 1020 | else |
| 1021 | ret = do_one_acipher_op(req, |
| 1022 | crypto_ablkcipher_decrypt(req)); |
| 1023 | |
| 1024 | if (ret) |
| 1025 | return ret; |
| 1026 | } |
| 1027 | |
| 1028 | pr_cont("%d operations in %d seconds (%ld bytes)\n", |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1029 | bcount, secs, (long)bcount * blen); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static int test_acipher_cycles(struct ablkcipher_request *req, int enc, |
| 1034 | int blen) |
| 1035 | { |
| 1036 | unsigned long cycles = 0; |
| 1037 | int ret = 0; |
| 1038 | int i; |
| 1039 | |
| 1040 | /* Warm-up run. */ |
| 1041 | for (i = 0; i < 4; i++) { |
| 1042 | if (enc) |
| 1043 | ret = do_one_acipher_op(req, |
| 1044 | crypto_ablkcipher_encrypt(req)); |
| 1045 | else |
| 1046 | ret = do_one_acipher_op(req, |
| 1047 | crypto_ablkcipher_decrypt(req)); |
| 1048 | |
| 1049 | if (ret) |
| 1050 | goto out; |
| 1051 | } |
| 1052 | |
| 1053 | /* The real thing. */ |
| 1054 | for (i = 0; i < 8; i++) { |
| 1055 | cycles_t start, end; |
| 1056 | |
| 1057 | start = get_cycles(); |
| 1058 | if (enc) |
| 1059 | ret = do_one_acipher_op(req, |
| 1060 | crypto_ablkcipher_encrypt(req)); |
| 1061 | else |
| 1062 | ret = do_one_acipher_op(req, |
| 1063 | crypto_ablkcipher_decrypt(req)); |
| 1064 | end = get_cycles(); |
| 1065 | |
| 1066 | if (ret) |
| 1067 | goto out; |
| 1068 | |
| 1069 | cycles += end - start; |
| 1070 | } |
| 1071 | |
| 1072 | out: |
| 1073 | if (ret == 0) |
| 1074 | pr_cont("1 operation in %lu cycles (%d bytes)\n", |
| 1075 | (cycles + 4) / 8, blen); |
| 1076 | |
| 1077 | return ret; |
| 1078 | } |
| 1079 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1080 | static void test_acipher_speed(const char *algo, int enc, unsigned int secs, |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1081 | struct cipher_speed_template *template, |
| 1082 | unsigned int tcount, u8 *keysize) |
| 1083 | { |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1084 | unsigned int ret, i, j, k, iv_len; |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1085 | struct tcrypt_result tresult; |
| 1086 | const char *key; |
| 1087 | char iv[128]; |
| 1088 | struct ablkcipher_request *req; |
| 1089 | struct crypto_ablkcipher *tfm; |
| 1090 | const char *e; |
| 1091 | u32 *b_size; |
| 1092 | |
| 1093 | if (enc == ENCRYPT) |
| 1094 | e = "encryption"; |
| 1095 | else |
| 1096 | e = "decryption"; |
| 1097 | |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1098 | init_completion(&tresult.completion); |
| 1099 | |
| 1100 | tfm = crypto_alloc_ablkcipher(algo, 0, 0); |
| 1101 | |
| 1102 | if (IS_ERR(tfm)) { |
| 1103 | pr_err("failed to load transform for %s: %ld\n", algo, |
| 1104 | PTR_ERR(tfm)); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
Luca Clementi | 263a8df | 2014-06-25 22:57:42 -0700 | [diff] [blame] | 1108 | pr_info("\ntesting speed of async %s (%s) %s\n", algo, |
| 1109 | get_driver_name(crypto_ablkcipher, tfm), e); |
| 1110 | |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1111 | req = ablkcipher_request_alloc(tfm, GFP_KERNEL); |
| 1112 | if (!req) { |
| 1113 | pr_err("tcrypt: skcipher: Failed to allocate request for %s\n", |
| 1114 | algo); |
| 1115 | goto out; |
| 1116 | } |
| 1117 | |
| 1118 | ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
| 1119 | tcrypt_complete, &tresult); |
| 1120 | |
| 1121 | i = 0; |
| 1122 | do { |
| 1123 | b_size = block_sizes; |
| 1124 | |
| 1125 | do { |
| 1126 | struct scatterlist sg[TVMEMSIZE]; |
| 1127 | |
| 1128 | if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { |
| 1129 | pr_err("template (%u) too big for " |
| 1130 | "tvmem (%lu)\n", *keysize + *b_size, |
| 1131 | TVMEMSIZE * PAGE_SIZE); |
| 1132 | goto out_free_req; |
| 1133 | } |
| 1134 | |
| 1135 | pr_info("test %u (%d bit key, %d byte blocks): ", i, |
| 1136 | *keysize * 8, *b_size); |
| 1137 | |
| 1138 | memset(tvmem[0], 0xff, PAGE_SIZE); |
| 1139 | |
| 1140 | /* set key, plain text and IV */ |
| 1141 | key = tvmem[0]; |
| 1142 | for (j = 0; j < tcount; j++) { |
| 1143 | if (template[j].klen == *keysize) { |
| 1144 | key = template[j].key; |
| 1145 | break; |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | crypto_ablkcipher_clear_flags(tfm, ~0); |
| 1150 | |
| 1151 | ret = crypto_ablkcipher_setkey(tfm, key, *keysize); |
| 1152 | if (ret) { |
| 1153 | pr_err("setkey() failed flags=%x\n", |
| 1154 | crypto_ablkcipher_get_flags(tfm)); |
| 1155 | goto out_free_req; |
| 1156 | } |
| 1157 | |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1158 | k = *keysize + *b_size; |
Horia Geant? | 007ee8d | 2015-03-09 16:14:58 +0200 | [diff] [blame] | 1159 | sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE)); |
| 1160 | |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1161 | if (k > PAGE_SIZE) { |
| 1162 | sg_set_buf(sg, tvmem[0] + *keysize, |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1163 | PAGE_SIZE - *keysize); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1164 | k -= PAGE_SIZE; |
| 1165 | j = 1; |
| 1166 | while (k > PAGE_SIZE) { |
| 1167 | sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); |
| 1168 | memset(tvmem[j], 0xff, PAGE_SIZE); |
| 1169 | j++; |
| 1170 | k -= PAGE_SIZE; |
| 1171 | } |
| 1172 | sg_set_buf(sg + j, tvmem[j], k); |
| 1173 | memset(tvmem[j], 0xff, k); |
| 1174 | } else { |
| 1175 | sg_set_buf(sg, tvmem[0] + *keysize, *b_size); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | iv_len = crypto_ablkcipher_ivsize(tfm); |
| 1179 | if (iv_len) |
| 1180 | memset(&iv, 0xff, iv_len); |
| 1181 | |
| 1182 | ablkcipher_request_set_crypt(req, sg, sg, *b_size, iv); |
| 1183 | |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1184 | if (secs) |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1185 | ret = test_acipher_jiffies(req, enc, |
Mark Rustad | 3e3dc25 | 2014-07-25 02:53:38 -0700 | [diff] [blame] | 1186 | *b_size, secs); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1187 | else |
| 1188 | ret = test_acipher_cycles(req, enc, |
| 1189 | *b_size); |
| 1190 | |
| 1191 | if (ret) { |
| 1192 | pr_err("%s() failed flags=%x\n", e, |
| 1193 | crypto_ablkcipher_get_flags(tfm)); |
| 1194 | break; |
| 1195 | } |
| 1196 | b_size++; |
| 1197 | i++; |
| 1198 | } while (*b_size); |
| 1199 | keysize++; |
| 1200 | } while (*keysize); |
| 1201 | |
| 1202 | out_free_req: |
| 1203 | ablkcipher_request_free(req); |
| 1204 | out: |
| 1205 | crypto_free_ablkcipher(tfm); |
| 1206 | } |
| 1207 | |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1208 | static void test_available(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | { |
| 1210 | char **name = check; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | while (*name) { |
| 1213 | printk("alg %s ", *name); |
Herbert Xu | 6158efc | 2007-04-04 17:41:07 +1000 | [diff] [blame] | 1214 | printk(crypto_has_alg(*name, 0, 0) ? |
Herbert Xu | e4d5b79 | 2006-08-26 18:12:40 +1000 | [diff] [blame] | 1215 | "found\n" : "not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | name++; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1220 | static inline int tcrypt_test(const char *alg) |
| 1221 | { |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1222 | int ret; |
| 1223 | |
| 1224 | ret = alg_test(alg, alg, 0, 0); |
| 1225 | /* non-fips algs return -EINVAL in fips mode */ |
| 1226 | if (fips_enabled && ret == -EINVAL) |
| 1227 | ret = 0; |
| 1228 | return ret; |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1229 | } |
| 1230 | |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 1231 | static int do_test(const char *alg, u32 type, u32 mask, int m) |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1232 | { |
| 1233 | int i; |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1234 | int ret = 0; |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1235 | |
| 1236 | switch (m) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | case 0: |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 1238 | if (alg) { |
| 1239 | if (!crypto_has_alg(alg, type, |
| 1240 | mask ?: CRYPTO_ALG_TYPE_MASK)) |
| 1241 | ret = -ENOENT; |
| 1242 | break; |
| 1243 | } |
| 1244 | |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1245 | for (i = 1; i < 200; i++) |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 1246 | ret += do_test(NULL, 0, 0, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | break; |
| 1248 | |
| 1249 | case 1: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1250 | ret += tcrypt_test("md5"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | break; |
| 1252 | |
| 1253 | case 2: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1254 | ret += tcrypt_test("sha1"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | break; |
| 1256 | |
| 1257 | case 3: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1258 | ret += tcrypt_test("ecb(des)"); |
| 1259 | ret += tcrypt_test("cbc(des)"); |
Jussi Kivilinna | 8163fc3 | 2012-10-20 14:53:07 +0300 | [diff] [blame] | 1260 | ret += tcrypt_test("ctr(des)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | break; |
| 1262 | |
| 1263 | case 4: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1264 | ret += tcrypt_test("ecb(des3_ede)"); |
| 1265 | ret += tcrypt_test("cbc(des3_ede)"); |
Jussi Kivilinna | e080b17 | 2012-10-20 14:53:12 +0300 | [diff] [blame] | 1266 | ret += tcrypt_test("ctr(des3_ede)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | break; |
| 1268 | |
| 1269 | case 5: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1270 | ret += tcrypt_test("md4"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | case 6: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1274 | ret += tcrypt_test("sha256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | case 7: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1278 | ret += tcrypt_test("ecb(blowfish)"); |
| 1279 | ret += tcrypt_test("cbc(blowfish)"); |
Jussi Kivilinna | 85b63e3 | 2011-10-10 23:03:03 +0300 | [diff] [blame] | 1280 | ret += tcrypt_test("ctr(blowfish)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | break; |
| 1282 | |
| 1283 | case 8: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1284 | ret += tcrypt_test("ecb(twofish)"); |
| 1285 | ret += tcrypt_test("cbc(twofish)"); |
Jussi Kivilinna | 573da62 | 2011-10-10 23:03:12 +0300 | [diff] [blame] | 1286 | ret += tcrypt_test("ctr(twofish)"); |
Jussi Kivilinna | bee3a90 | 2011-10-18 13:32:56 +0300 | [diff] [blame] | 1287 | ret += tcrypt_test("lrw(twofish)"); |
Jussi Kivilinna | 131f754 | 2011-10-18 13:33:38 +0300 | [diff] [blame] | 1288 | ret += tcrypt_test("xts(twofish)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | case 9: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1292 | ret += tcrypt_test("ecb(serpent)"); |
Jussi Kivilinna | 9d25917 | 2011-10-18 00:02:53 +0300 | [diff] [blame] | 1293 | ret += tcrypt_test("cbc(serpent)"); |
| 1294 | ret += tcrypt_test("ctr(serpent)"); |
Jussi Kivilinna | 87aae4b | 2011-10-18 13:32:39 +0300 | [diff] [blame] | 1295 | ret += tcrypt_test("lrw(serpent)"); |
Jussi Kivilinna | 5209c07 | 2011-10-18 13:33:22 +0300 | [diff] [blame] | 1296 | ret += tcrypt_test("xts(serpent)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | break; |
| 1298 | |
| 1299 | case 10: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1300 | ret += tcrypt_test("ecb(aes)"); |
| 1301 | ret += tcrypt_test("cbc(aes)"); |
| 1302 | ret += tcrypt_test("lrw(aes)"); |
| 1303 | ret += tcrypt_test("xts(aes)"); |
| 1304 | ret += tcrypt_test("ctr(aes)"); |
| 1305 | ret += tcrypt_test("rfc3686(ctr(aes))"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case 11: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1309 | ret += tcrypt_test("sha384"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | case 12: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1313 | ret += tcrypt_test("sha512"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | |
| 1316 | case 13: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1317 | ret += tcrypt_test("deflate"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | break; |
| 1319 | |
| 1320 | case 14: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1321 | ret += tcrypt_test("ecb(cast5)"); |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 1322 | ret += tcrypt_test("cbc(cast5)"); |
| 1323 | ret += tcrypt_test("ctr(cast5)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | break; |
| 1325 | |
| 1326 | case 15: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1327 | ret += tcrypt_test("ecb(cast6)"); |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 1328 | ret += tcrypt_test("cbc(cast6)"); |
| 1329 | ret += tcrypt_test("ctr(cast6)"); |
| 1330 | ret += tcrypt_test("lrw(cast6)"); |
| 1331 | ret += tcrypt_test("xts(cast6)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | break; |
| 1333 | |
| 1334 | case 16: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1335 | ret += tcrypt_test("ecb(arc4)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | break; |
| 1337 | |
| 1338 | case 17: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1339 | ret += tcrypt_test("michael_mic"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | break; |
| 1341 | |
| 1342 | case 18: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1343 | ret += tcrypt_test("crc32c"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | break; |
| 1345 | |
| 1346 | case 19: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1347 | ret += tcrypt_test("ecb(tea)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | break; |
| 1349 | |
| 1350 | case 20: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1351 | ret += tcrypt_test("ecb(xtea)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | break; |
| 1353 | |
| 1354 | case 21: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1355 | ret += tcrypt_test("ecb(khazad)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | break; |
| 1357 | |
| 1358 | case 22: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1359 | ret += tcrypt_test("wp512"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | break; |
| 1361 | |
| 1362 | case 23: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1363 | ret += tcrypt_test("wp384"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | break; |
| 1365 | |
| 1366 | case 24: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1367 | ret += tcrypt_test("wp256"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | break; |
| 1369 | |
| 1370 | case 25: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1371 | ret += tcrypt_test("ecb(tnepres)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | break; |
| 1373 | |
| 1374 | case 26: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1375 | ret += tcrypt_test("ecb(anubis)"); |
| 1376 | ret += tcrypt_test("cbc(anubis)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | break; |
| 1378 | |
| 1379 | case 27: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1380 | ret += tcrypt_test("tgr192"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | break; |
| 1382 | |
| 1383 | case 28: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1384 | ret += tcrypt_test("tgr160"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | break; |
| 1386 | |
| 1387 | case 29: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1388 | ret += tcrypt_test("tgr128"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | break; |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 1390 | |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1391 | case 30: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1392 | ret += tcrypt_test("ecb(xeta)"); |
Aaron Grothe | fb4f10e | 2005-09-01 17:42:46 -0700 | [diff] [blame] | 1393 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1395 | case 31: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1396 | ret += tcrypt_test("pcbc(fcrypt)"); |
David Howells | 9083163 | 2006-12-16 12:13:14 +1100 | [diff] [blame] | 1397 | break; |
| 1398 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1399 | case 32: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1400 | ret += tcrypt_test("ecb(camellia)"); |
| 1401 | ret += tcrypt_test("cbc(camellia)"); |
Jussi Kivilinna | 54216bb | 2012-09-21 10:27:10 +0300 | [diff] [blame] | 1402 | ret += tcrypt_test("ctr(camellia)"); |
| 1403 | ret += tcrypt_test("lrw(camellia)"); |
| 1404 | ret += tcrypt_test("xts(camellia)"); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1405 | break; |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 1406 | |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1407 | case 33: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1408 | ret += tcrypt_test("sha224"); |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1409 | break; |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1410 | |
Tan Swee Heng | 2407d60 | 2007-11-23 19:45:00 +0800 | [diff] [blame] | 1411 | case 34: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1412 | ret += tcrypt_test("salsa20"); |
Tan Swee Heng | 2407d60 | 2007-11-23 19:45:00 +0800 | [diff] [blame] | 1413 | break; |
| 1414 | |
Herbert Xu | 8df213d | 2007-12-02 14:55:47 +1100 | [diff] [blame] | 1415 | case 35: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1416 | ret += tcrypt_test("gcm(aes)"); |
Herbert Xu | 8df213d | 2007-12-02 14:55:47 +1100 | [diff] [blame] | 1417 | break; |
| 1418 | |
Zoltan Sogor | 0b77abb | 2007-12-07 16:53:23 +0800 | [diff] [blame] | 1419 | case 36: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1420 | ret += tcrypt_test("lzo"); |
Zoltan Sogor | 0b77abb | 2007-12-07 16:53:23 +0800 | [diff] [blame] | 1421 | break; |
| 1422 | |
Joy Latten | 93cc74e | 2007-12-12 20:24:22 +0800 | [diff] [blame] | 1423 | case 37: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1424 | ret += tcrypt_test("ccm(aes)"); |
Joy Latten | 93cc74e | 2007-12-12 20:24:22 +0800 | [diff] [blame] | 1425 | break; |
| 1426 | |
Kevin Coffman | 76cb952 | 2008-03-24 21:26:16 +0800 | [diff] [blame] | 1427 | case 38: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1428 | ret += tcrypt_test("cts(cbc(aes))"); |
Kevin Coffman | 76cb952 | 2008-03-24 21:26:16 +0800 | [diff] [blame] | 1429 | break; |
| 1430 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1431 | case 39: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1432 | ret += tcrypt_test("rmd128"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1433 | break; |
| 1434 | |
| 1435 | case 40: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1436 | ret += tcrypt_test("rmd160"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1437 | break; |
| 1438 | |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 1439 | case 41: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1440 | ret += tcrypt_test("rmd256"); |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | case 42: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1444 | ret += tcrypt_test("rmd320"); |
Herbert Xu | 01b3232 | 2008-07-31 15:41:55 +0800 | [diff] [blame] | 1445 | break; |
| 1446 | |
| 1447 | case 43: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1448 | ret += tcrypt_test("ecb(seed)"); |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 1449 | break; |
| 1450 | |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 1451 | case 44: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1452 | ret += tcrypt_test("zlib"); |
Geert Uytterhoeven | 0c01aed | 2009-03-04 15:42:15 +0800 | [diff] [blame] | 1453 | break; |
| 1454 | |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 1455 | case 45: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1456 | ret += tcrypt_test("rfc4309(ccm(aes))"); |
Jarod Wilson | 5d66732 | 2009-05-04 19:23:40 +0800 | [diff] [blame] | 1457 | break; |
| 1458 | |
Jussi Kivilinna | 54216bb | 2012-09-21 10:27:10 +0300 | [diff] [blame] | 1459 | case 46: |
| 1460 | ret += tcrypt_test("ghash"); |
| 1461 | break; |
| 1462 | |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 1463 | case 47: |
| 1464 | ret += tcrypt_test("crct10dif"); |
| 1465 | break; |
| 1466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | case 100: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1468 | ret += tcrypt_test("hmac(md5)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | case 101: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1472 | ret += tcrypt_test("hmac(sha1)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | break; |
Herbert Xu | ef2736f | 2005-06-22 13:26:03 -0700 | [diff] [blame] | 1474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | case 102: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1476 | ret += tcrypt_test("hmac(sha256)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | break; |
| 1478 | |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1479 | case 103: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1480 | ret += tcrypt_test("hmac(sha384)"); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1481 | break; |
| 1482 | |
| 1483 | case 104: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1484 | ret += tcrypt_test("hmac(sha512)"); |
Andrew Donofrio | a28091a | 2006-12-10 12:10:20 +1100 | [diff] [blame] | 1485 | break; |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 1486 | |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1487 | case 105: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1488 | ret += tcrypt_test("hmac(sha224)"); |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1489 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 1491 | case 106: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1492 | ret += tcrypt_test("xcbc(aes)"); |
Herbert Xu | 38ed9ab | 2008-01-01 15:59:28 +1100 | [diff] [blame] | 1493 | break; |
| 1494 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1495 | case 107: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1496 | ret += tcrypt_test("hmac(rmd128)"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1497 | break; |
| 1498 | |
| 1499 | case 108: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1500 | ret += tcrypt_test("hmac(rmd160)"); |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1501 | break; |
| 1502 | |
Shane Wang | f1939f7 | 2009-09-02 20:05:22 +1000 | [diff] [blame] | 1503 | case 109: |
| 1504 | ret += tcrypt_test("vmac(aes)"); |
| 1505 | break; |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 1506 | |
Sonic Zhang | a482b08 | 2012-05-25 17:54:13 +0800 | [diff] [blame] | 1507 | case 110: |
| 1508 | ret += tcrypt_test("hmac(crc32)"); |
| 1509 | break; |
Shane Wang | f1939f7 | 2009-09-02 20:05:22 +1000 | [diff] [blame] | 1510 | |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 1511 | case 150: |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 1512 | ret += tcrypt_test("ansi_cprng"); |
Jarod Wilson | e08ca2d | 2009-05-04 19:46:29 +0800 | [diff] [blame] | 1513 | break; |
| 1514 | |
Adrian Hoban | 69435b9 | 2010-11-04 15:02:04 -0400 | [diff] [blame] | 1515 | case 151: |
| 1516 | ret += tcrypt_test("rfc4106(gcm(aes))"); |
| 1517 | break; |
| 1518 | |
Jussi Kivilinna | e9b7441 | 2013-04-07 16:43:51 +0300 | [diff] [blame] | 1519 | case 152: |
| 1520 | ret += tcrypt_test("rfc4543(gcm(aes))"); |
| 1521 | break; |
| 1522 | |
Jussi Kivilinna | 93b5e86 | 2013-04-08 10:48:44 +0300 | [diff] [blame] | 1523 | case 153: |
| 1524 | ret += tcrypt_test("cmac(aes)"); |
| 1525 | break; |
| 1526 | |
| 1527 | case 154: |
| 1528 | ret += tcrypt_test("cmac(des3_ede)"); |
| 1529 | break; |
| 1530 | |
Horia Geanta | bbf9c89 | 2013-11-28 15:11:16 +0200 | [diff] [blame] | 1531 | case 155: |
| 1532 | ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))"); |
| 1533 | break; |
| 1534 | |
Horia Geanta | bca4feb | 2014-03-14 17:46:51 +0200 | [diff] [blame] | 1535 | case 156: |
| 1536 | ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"); |
| 1537 | break; |
| 1538 | |
| 1539 | case 157: |
| 1540 | ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"); |
| 1541 | break; |
Nitesh Lal | 5208ed2 | 2014-05-21 17:09:08 +0530 | [diff] [blame] | 1542 | case 181: |
| 1543 | ret += tcrypt_test("authenc(hmac(sha1),cbc(des))"); |
| 1544 | break; |
| 1545 | case 182: |
| 1546 | ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"); |
| 1547 | break; |
| 1548 | case 183: |
| 1549 | ret += tcrypt_test("authenc(hmac(sha224),cbc(des))"); |
| 1550 | break; |
| 1551 | case 184: |
| 1552 | ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"); |
| 1553 | break; |
| 1554 | case 185: |
| 1555 | ret += tcrypt_test("authenc(hmac(sha256),cbc(des))"); |
| 1556 | break; |
| 1557 | case 186: |
| 1558 | ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"); |
| 1559 | break; |
| 1560 | case 187: |
| 1561 | ret += tcrypt_test("authenc(hmac(sha384),cbc(des))"); |
| 1562 | break; |
| 1563 | case 188: |
| 1564 | ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"); |
| 1565 | break; |
| 1566 | case 189: |
| 1567 | ret += tcrypt_test("authenc(hmac(sha512),cbc(des))"); |
| 1568 | break; |
| 1569 | case 190: |
| 1570 | ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"); |
| 1571 | break; |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1572 | case 200: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1573 | test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1574 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1575 | test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1576 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1577 | test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1578 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1579 | test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1580 | speed_template_16_24_32); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1581 | test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1582 | speed_template_32_40_48); |
Rik Snel | f3d1044 | 2006-11-29 19:01:41 +1100 | [diff] [blame] | 1583 | test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1584 | speed_template_32_40_48); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1585 | test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1586 | speed_template_32_48_64); |
Rik Snel | f19f511 | 2007-09-19 20:23:13 +0800 | [diff] [blame] | 1587 | test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1588 | speed_template_32_48_64); |
Jan Glauber | 9996e34 | 2011-04-26 16:34:01 +1000 | [diff] [blame] | 1589 | test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
| 1590 | speed_template_16_24_32); |
| 1591 | test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, |
| 1592 | speed_template_16_24_32); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1593 | break; |
| 1594 | |
| 1595 | case 201: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1596 | test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1597 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1598 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1599 | test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1600 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1601 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1602 | test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1603 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1604 | speed_template_24); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1605 | test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, |
Herbert Xu | da7f033 | 2008-07-31 17:08:25 +0800 | [diff] [blame] | 1606 | des3_speed_template, DES3_SPEED_VECTORS, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1607 | speed_template_24); |
Jussi Kivilinna | 8713150 | 2014-06-09 20:59:49 +0300 | [diff] [blame] | 1608 | test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec, |
| 1609 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1610 | speed_template_24); |
| 1611 | test_cipher_speed("ctr(des3_ede)", DECRYPT, sec, |
| 1612 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1613 | speed_template_24); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1614 | break; |
| 1615 | |
| 1616 | case 202: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1617 | test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1618 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1619 | test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1620 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1621 | test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1622 | speed_template_16_24_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1623 | test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1624 | speed_template_16_24_32); |
Jussi Kivilinna | ee5002a | 2011-09-26 16:47:15 +0300 | [diff] [blame] | 1625 | test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
| 1626 | speed_template_16_24_32); |
| 1627 | test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, |
| 1628 | speed_template_16_24_32); |
Jussi Kivilinna | bee3a90 | 2011-10-18 13:32:56 +0300 | [diff] [blame] | 1629 | test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
| 1630 | speed_template_32_40_48); |
| 1631 | test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, |
| 1632 | speed_template_32_40_48); |
Jussi Kivilinna | 131f754 | 2011-10-18 13:33:38 +0300 | [diff] [blame] | 1633 | test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
| 1634 | speed_template_32_48_64); |
| 1635 | test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, |
| 1636 | speed_template_32_48_64); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1637 | break; |
| 1638 | |
| 1639 | case 203: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1640 | test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1641 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1642 | test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1643 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1644 | test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1645 | speed_template_8_32); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1646 | test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1647 | speed_template_8_32); |
Jussi Kivilinna | 7d47b86 | 2011-09-02 01:45:17 +0300 | [diff] [blame] | 1648 | test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
| 1649 | speed_template_8_32); |
| 1650 | test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, |
| 1651 | speed_template_8_32); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1652 | break; |
| 1653 | |
| 1654 | case 204: |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1655 | test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1656 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1657 | test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1658 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1659 | test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1660 | speed_template_8); |
Herbert Xu | cba8356 | 2006-08-13 08:26:09 +1000 | [diff] [blame] | 1661 | test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1662 | speed_template_8); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 1663 | break; |
| 1664 | |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1665 | case 205: |
| 1666 | test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1667 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1668 | test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1669 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1670 | test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1671 | speed_template_16_24_32); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1672 | test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1673 | speed_template_16_24_32); |
Jussi Kivilinna | 4de5933 | 2012-03-05 20:26:26 +0200 | [diff] [blame] | 1674 | test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
| 1675 | speed_template_16_24_32); |
| 1676 | test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, |
| 1677 | speed_template_16_24_32); |
| 1678 | test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, |
| 1679 | speed_template_32_40_48); |
| 1680 | test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, |
| 1681 | speed_template_32_40_48); |
| 1682 | test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, |
| 1683 | speed_template_32_48_64); |
| 1684 | test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, |
| 1685 | speed_template_32_48_64); |
Noriaki TAKAMIYA | 02ab5a7 | 2007-01-24 21:48:19 +1100 | [diff] [blame] | 1686 | break; |
| 1687 | |
Tan Swee Heng | 5de8f1b | 2007-12-07 17:17:43 +0800 | [diff] [blame] | 1688 | case 206: |
| 1689 | test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, |
Sebastian Siewior | 477035c | 2008-03-11 21:24:26 +0800 | [diff] [blame] | 1690 | speed_template_16_32); |
Tan Swee Heng | 5de8f1b | 2007-12-07 17:17:43 +0800 | [diff] [blame] | 1691 | break; |
| 1692 | |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 1693 | case 207: |
| 1694 | test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, |
| 1695 | speed_template_16_32); |
| 1696 | test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, |
| 1697 | speed_template_16_32); |
| 1698 | test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, |
| 1699 | speed_template_16_32); |
| 1700 | test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, |
| 1701 | speed_template_16_32); |
| 1702 | test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, |
| 1703 | speed_template_16_32); |
| 1704 | test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, |
| 1705 | speed_template_16_32); |
Jussi Kivilinna | 87aae4b | 2011-10-18 13:32:39 +0300 | [diff] [blame] | 1706 | test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
| 1707 | speed_template_32_48); |
| 1708 | test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, |
| 1709 | speed_template_32_48); |
Jussi Kivilinna | 5209c07 | 2011-10-18 13:33:22 +0300 | [diff] [blame] | 1710 | test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
| 1711 | speed_template_32_64); |
| 1712 | test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, |
| 1713 | speed_template_32_64); |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 1714 | break; |
| 1715 | |
Jussi Kivilinna | 31b4cd29 | 2012-06-12 16:52:04 +0800 | [diff] [blame] | 1716 | case 208: |
| 1717 | test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, |
| 1718 | speed_template_8); |
| 1719 | break; |
| 1720 | |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 1721 | case 209: |
| 1722 | test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, |
| 1723 | speed_template_8_16); |
| 1724 | test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, |
| 1725 | speed_template_8_16); |
| 1726 | test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, |
| 1727 | speed_template_8_16); |
| 1728 | test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, |
| 1729 | speed_template_8_16); |
| 1730 | test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, |
| 1731 | speed_template_8_16); |
| 1732 | test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, |
| 1733 | speed_template_8_16); |
| 1734 | break; |
| 1735 | |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 1736 | case 210: |
| 1737 | test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, |
| 1738 | speed_template_16_32); |
| 1739 | test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, |
| 1740 | speed_template_16_32); |
| 1741 | test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, |
| 1742 | speed_template_16_32); |
| 1743 | test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, |
| 1744 | speed_template_16_32); |
| 1745 | test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, |
| 1746 | speed_template_16_32); |
| 1747 | test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, |
| 1748 | speed_template_16_32); |
| 1749 | test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, |
| 1750 | speed_template_32_48); |
| 1751 | test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, |
| 1752 | speed_template_32_48); |
| 1753 | test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, |
| 1754 | speed_template_32_64); |
| 1755 | test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, |
| 1756 | speed_template_32_64); |
| 1757 | break; |
| 1758 | |
Tim Chen | 53f52d7 | 2013-12-11 14:28:47 -0800 | [diff] [blame] | 1759 | case 211: |
| 1760 | test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, |
| 1761 | NULL, 0, 16, 8, aead_speed_template_20); |
| 1762 | break; |
| 1763 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1764 | case 300: |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 1765 | if (alg) { |
| 1766 | test_hash_speed(alg, sec, generic_hash_speed_template); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1770 | /* fall through */ |
| 1771 | |
| 1772 | case 301: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1773 | test_hash_speed("md4", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1774 | if (mode > 300 && mode < 400) break; |
| 1775 | |
| 1776 | case 302: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1777 | test_hash_speed("md5", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1778 | if (mode > 300 && mode < 400) break; |
| 1779 | |
| 1780 | case 303: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1781 | test_hash_speed("sha1", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1782 | if (mode > 300 && mode < 400) break; |
| 1783 | |
| 1784 | case 304: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1785 | test_hash_speed("sha256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1786 | if (mode > 300 && mode < 400) break; |
| 1787 | |
| 1788 | case 305: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1789 | test_hash_speed("sha384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1790 | if (mode > 300 && mode < 400) break; |
| 1791 | |
| 1792 | case 306: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1793 | test_hash_speed("sha512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1794 | if (mode > 300 && mode < 400) break; |
| 1795 | |
| 1796 | case 307: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1797 | test_hash_speed("wp256", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1798 | if (mode > 300 && mode < 400) break; |
| 1799 | |
| 1800 | case 308: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1801 | test_hash_speed("wp384", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1802 | if (mode > 300 && mode < 400) break; |
| 1803 | |
| 1804 | case 309: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1805 | test_hash_speed("wp512", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1806 | if (mode > 300 && mode < 400) break; |
| 1807 | |
| 1808 | case 310: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1809 | test_hash_speed("tgr128", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1810 | if (mode > 300 && mode < 400) break; |
| 1811 | |
| 1812 | case 311: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1813 | test_hash_speed("tgr160", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1814 | if (mode > 300 && mode < 400) break; |
| 1815 | |
| 1816 | case 312: |
Herbert Xu | e9d4116 | 2006-08-19 21:38:49 +1000 | [diff] [blame] | 1817 | test_hash_speed("tgr192", sec, generic_hash_speed_template); |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1818 | if (mode > 300 && mode < 400) break; |
| 1819 | |
Jonathan Lynch | cd12fb90 | 2007-11-10 20:08:25 +0800 | [diff] [blame] | 1820 | case 313: |
| 1821 | test_hash_speed("sha224", sec, generic_hash_speed_template); |
| 1822 | if (mode > 300 && mode < 400) break; |
| 1823 | |
Adrian-Ken Rueegsegger | fd4adf1 | 2008-05-07 22:16:36 +0800 | [diff] [blame] | 1824 | case 314: |
| 1825 | test_hash_speed("rmd128", sec, generic_hash_speed_template); |
| 1826 | if (mode > 300 && mode < 400) break; |
| 1827 | |
| 1828 | case 315: |
| 1829 | test_hash_speed("rmd160", sec, generic_hash_speed_template); |
| 1830 | if (mode > 300 && mode < 400) break; |
| 1831 | |
Adrian-Ken Rueegsegger | 2998db3 | 2008-05-09 21:29:35 +0800 | [diff] [blame] | 1832 | case 316: |
| 1833 | test_hash_speed("rmd256", sec, generic_hash_speed_template); |
| 1834 | if (mode > 300 && mode < 400) break; |
| 1835 | |
| 1836 | case 317: |
| 1837 | test_hash_speed("rmd320", sec, generic_hash_speed_template); |
| 1838 | if (mode > 300 && mode < 400) break; |
| 1839 | |
Huang Ying | 18bcc91 | 2010-03-10 18:30:32 +0800 | [diff] [blame] | 1840 | case 318: |
| 1841 | test_hash_speed("ghash-generic", sec, hash_speed_template_16); |
| 1842 | if (mode > 300 && mode < 400) break; |
| 1843 | |
Tim Chen | e3899e4 | 2012-09-27 15:44:24 -0700 | [diff] [blame] | 1844 | case 319: |
| 1845 | test_hash_speed("crc32c", sec, generic_hash_speed_template); |
| 1846 | if (mode > 300 && mode < 400) break; |
| 1847 | |
Herbert Xu | 68411521 | 2013-09-07 12:56:26 +1000 | [diff] [blame] | 1848 | case 320: |
| 1849 | test_hash_speed("crct10dif", sec, generic_hash_speed_template); |
| 1850 | if (mode > 300 && mode < 400) break; |
| 1851 | |
Michal Ludvig | e805792 | 2006-05-30 22:04:19 +1000 | [diff] [blame] | 1852 | case 399: |
| 1853 | break; |
| 1854 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1855 | case 400: |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 1856 | if (alg) { |
| 1857 | test_ahash_speed(alg, sec, generic_hash_speed_template); |
| 1858 | break; |
| 1859 | } |
| 1860 | |
David S. Miller | beb63da | 2010-05-19 14:11:21 +1000 | [diff] [blame] | 1861 | /* fall through */ |
| 1862 | |
| 1863 | case 401: |
| 1864 | test_ahash_speed("md4", sec, generic_hash_speed_template); |
| 1865 | if (mode > 400 && mode < 500) break; |
| 1866 | |
| 1867 | case 402: |
| 1868 | test_ahash_speed("md5", sec, generic_hash_speed_template); |
| 1869 | if (mode > 400 && mode < 500) break; |
| 1870 | |
| 1871 | case 403: |
| 1872 | test_ahash_speed("sha1", sec, generic_hash_speed_template); |
| 1873 | if (mode > 400 && mode < 500) break; |
| 1874 | |
| 1875 | case 404: |
| 1876 | test_ahash_speed("sha256", sec, generic_hash_speed_template); |
| 1877 | if (mode > 400 && mode < 500) break; |
| 1878 | |
| 1879 | case 405: |
| 1880 | test_ahash_speed("sha384", sec, generic_hash_speed_template); |
| 1881 | if (mode > 400 && mode < 500) break; |
| 1882 | |
| 1883 | case 406: |
| 1884 | test_ahash_speed("sha512", sec, generic_hash_speed_template); |
| 1885 | if (mode > 400 && mode < 500) break; |
| 1886 | |
| 1887 | case 407: |
| 1888 | test_ahash_speed("wp256", sec, generic_hash_speed_template); |
| 1889 | if (mode > 400 && mode < 500) break; |
| 1890 | |
| 1891 | case 408: |
| 1892 | test_ahash_speed("wp384", sec, generic_hash_speed_template); |
| 1893 | if (mode > 400 && mode < 500) break; |
| 1894 | |
| 1895 | case 409: |
| 1896 | test_ahash_speed("wp512", sec, generic_hash_speed_template); |
| 1897 | if (mode > 400 && mode < 500) break; |
| 1898 | |
| 1899 | case 410: |
| 1900 | test_ahash_speed("tgr128", sec, generic_hash_speed_template); |
| 1901 | if (mode > 400 && mode < 500) break; |
| 1902 | |
| 1903 | case 411: |
| 1904 | test_ahash_speed("tgr160", sec, generic_hash_speed_template); |
| 1905 | if (mode > 400 && mode < 500) break; |
| 1906 | |
| 1907 | case 412: |
| 1908 | test_ahash_speed("tgr192", sec, generic_hash_speed_template); |
| 1909 | if (mode > 400 && mode < 500) break; |
| 1910 | |
| 1911 | case 413: |
| 1912 | test_ahash_speed("sha224", sec, generic_hash_speed_template); |
| 1913 | if (mode > 400 && mode < 500) break; |
| 1914 | |
| 1915 | case 414: |
| 1916 | test_ahash_speed("rmd128", sec, generic_hash_speed_template); |
| 1917 | if (mode > 400 && mode < 500) break; |
| 1918 | |
| 1919 | case 415: |
| 1920 | test_ahash_speed("rmd160", sec, generic_hash_speed_template); |
| 1921 | if (mode > 400 && mode < 500) break; |
| 1922 | |
| 1923 | case 416: |
| 1924 | test_ahash_speed("rmd256", sec, generic_hash_speed_template); |
| 1925 | if (mode > 400 && mode < 500) break; |
| 1926 | |
| 1927 | case 417: |
| 1928 | test_ahash_speed("rmd320", sec, generic_hash_speed_template); |
| 1929 | if (mode > 400 && mode < 500) break; |
| 1930 | |
| 1931 | case 499: |
| 1932 | break; |
| 1933 | |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1934 | case 500: |
| 1935 | test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, |
| 1936 | speed_template_16_24_32); |
| 1937 | test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, |
| 1938 | speed_template_16_24_32); |
| 1939 | test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, |
| 1940 | speed_template_16_24_32); |
| 1941 | test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, |
| 1942 | speed_template_16_24_32); |
| 1943 | test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, |
| 1944 | speed_template_32_40_48); |
| 1945 | test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, |
| 1946 | speed_template_32_40_48); |
| 1947 | test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, |
| 1948 | speed_template_32_48_64); |
| 1949 | test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, |
| 1950 | speed_template_32_48_64); |
| 1951 | test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, |
| 1952 | speed_template_16_24_32); |
| 1953 | test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, |
| 1954 | speed_template_16_24_32); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1955 | test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, |
| 1956 | speed_template_16_24_32); |
| 1957 | test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, |
| 1958 | speed_template_16_24_32); |
| 1959 | test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, |
| 1960 | speed_template_16_24_32); |
| 1961 | test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, |
| 1962 | speed_template_16_24_32); |
Jussi Kivilinna | 69d3150 | 2012-12-28 12:04:58 +0200 | [diff] [blame] | 1963 | test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0, |
| 1964 | speed_template_20_28_36); |
| 1965 | test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0, |
| 1966 | speed_template_20_28_36); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1967 | break; |
| 1968 | |
| 1969 | case 501: |
| 1970 | test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec, |
| 1971 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1972 | speed_template_24); |
| 1973 | test_acipher_speed("ecb(des3_ede)", DECRYPT, sec, |
| 1974 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1975 | speed_template_24); |
| 1976 | test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec, |
| 1977 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1978 | speed_template_24); |
| 1979 | test_acipher_speed("cbc(des3_ede)", DECRYPT, sec, |
| 1980 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1981 | speed_template_24); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 1982 | test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec, |
| 1983 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1984 | speed_template_24); |
| 1985 | test_acipher_speed("cfb(des3_ede)", DECRYPT, sec, |
| 1986 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1987 | speed_template_24); |
| 1988 | test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec, |
| 1989 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1990 | speed_template_24); |
| 1991 | test_acipher_speed("ofb(des3_ede)", DECRYPT, sec, |
| 1992 | des3_speed_template, DES3_SPEED_VECTORS, |
| 1993 | speed_template_24); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 1994 | break; |
| 1995 | |
| 1996 | case 502: |
| 1997 | test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, |
| 1998 | speed_template_8); |
| 1999 | test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, |
| 2000 | speed_template_8); |
| 2001 | test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, |
| 2002 | speed_template_8); |
| 2003 | test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, |
| 2004 | speed_template_8); |
Nicolas Royer | de197533 | 2012-07-01 19:19:47 +0200 | [diff] [blame] | 2005 | test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, |
| 2006 | speed_template_8); |
| 2007 | test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, |
| 2008 | speed_template_8); |
| 2009 | test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, |
| 2010 | speed_template_8); |
| 2011 | test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, |
| 2012 | speed_template_8); |
Jussi Kivilinna | 3f3baf3 | 2011-10-18 00:02:58 +0300 | [diff] [blame] | 2013 | break; |
| 2014 | |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 2015 | case 503: |
| 2016 | test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, |
| 2017 | speed_template_16_32); |
| 2018 | test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, |
| 2019 | speed_template_16_32); |
| 2020 | test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, |
| 2021 | speed_template_16_32); |
| 2022 | test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, |
| 2023 | speed_template_16_32); |
| 2024 | test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, |
| 2025 | speed_template_16_32); |
| 2026 | test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, |
| 2027 | speed_template_16_32); |
Jussi Kivilinna | 87aae4b | 2011-10-18 13:32:39 +0300 | [diff] [blame] | 2028 | test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, |
| 2029 | speed_template_32_48); |
| 2030 | test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, |
| 2031 | speed_template_32_48); |
Jussi Kivilinna | 5209c07 | 2011-10-18 13:33:22 +0300 | [diff] [blame] | 2032 | test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, |
| 2033 | speed_template_32_64); |
| 2034 | test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, |
| 2035 | speed_template_32_64); |
Jussi Kivilinna | 7fb7fe4 | 2011-10-18 00:03:03 +0300 | [diff] [blame] | 2036 | break; |
| 2037 | |
Johannes Goetzfried | 107778b | 2012-05-28 15:54:24 +0200 | [diff] [blame] | 2038 | case 504: |
| 2039 | test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, |
| 2040 | speed_template_16_24_32); |
| 2041 | test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, |
| 2042 | speed_template_16_24_32); |
| 2043 | test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, |
| 2044 | speed_template_16_24_32); |
| 2045 | test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, |
| 2046 | speed_template_16_24_32); |
| 2047 | test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, |
| 2048 | speed_template_16_24_32); |
| 2049 | test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, |
| 2050 | speed_template_16_24_32); |
| 2051 | test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, |
| 2052 | speed_template_32_40_48); |
| 2053 | test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, |
| 2054 | speed_template_32_40_48); |
| 2055 | test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, |
| 2056 | speed_template_32_48_64); |
| 2057 | test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, |
| 2058 | speed_template_32_48_64); |
| 2059 | break; |
| 2060 | |
Jussi Kivilinna | 31b4cd29 | 2012-06-12 16:52:04 +0800 | [diff] [blame] | 2061 | case 505: |
| 2062 | test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, |
| 2063 | speed_template_8); |
| 2064 | break; |
| 2065 | |
Johannes Goetzfried | a2c5826 | 2012-07-11 19:37:21 +0200 | [diff] [blame] | 2066 | case 506: |
| 2067 | test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, |
| 2068 | speed_template_8_16); |
| 2069 | test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, |
| 2070 | speed_template_8_16); |
| 2071 | test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, |
| 2072 | speed_template_8_16); |
| 2073 | test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, |
| 2074 | speed_template_8_16); |
| 2075 | test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, |
| 2076 | speed_template_8_16); |
| 2077 | test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, |
| 2078 | speed_template_8_16); |
| 2079 | break; |
| 2080 | |
Johannes Goetzfried | 9b8b040 | 2012-07-11 19:38:29 +0200 | [diff] [blame] | 2081 | case 507: |
| 2082 | test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, |
| 2083 | speed_template_16_32); |
| 2084 | test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, |
| 2085 | speed_template_16_32); |
| 2086 | test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, |
| 2087 | speed_template_16_32); |
| 2088 | test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, |
| 2089 | speed_template_16_32); |
| 2090 | test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, |
| 2091 | speed_template_16_32); |
| 2092 | test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, |
| 2093 | speed_template_16_32); |
| 2094 | test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, |
| 2095 | speed_template_32_48); |
| 2096 | test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, |
| 2097 | speed_template_32_48); |
| 2098 | test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, |
| 2099 | speed_template_32_64); |
| 2100 | test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, |
| 2101 | speed_template_32_64); |
| 2102 | break; |
| 2103 | |
Jussi Kivilinna | bf9c518 | 2012-10-26 14:48:51 +0300 | [diff] [blame] | 2104 | case 508: |
| 2105 | test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, |
| 2106 | speed_template_16_32); |
| 2107 | test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, |
| 2108 | speed_template_16_32); |
| 2109 | test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, |
| 2110 | speed_template_16_32); |
| 2111 | test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, |
| 2112 | speed_template_16_32); |
| 2113 | test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, |
| 2114 | speed_template_16_32); |
| 2115 | test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, |
| 2116 | speed_template_16_32); |
| 2117 | test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, |
| 2118 | speed_template_32_48); |
| 2119 | test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, |
| 2120 | speed_template_32_48); |
| 2121 | test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, |
| 2122 | speed_template_32_64); |
| 2123 | test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, |
| 2124 | speed_template_32_64); |
| 2125 | break; |
| 2126 | |
Jussi Kivilinna | ad8b7c3 | 2013-04-13 13:46:40 +0300 | [diff] [blame] | 2127 | case 509: |
| 2128 | test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2129 | speed_template_8_32); |
| 2130 | test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, |
| 2131 | speed_template_8_32); |
| 2132 | test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2133 | speed_template_8_32); |
| 2134 | test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, |
| 2135 | speed_template_8_32); |
| 2136 | test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, |
| 2137 | speed_template_8_32); |
| 2138 | test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, |
| 2139 | speed_template_8_32); |
| 2140 | break; |
| 2141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | case 1000: |
| 2143 | test_available(); |
| 2144 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | } |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 2146 | |
| 2147 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 2150 | static int __init tcrypt_mod_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | { |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 2152 | int err = -ENOMEM; |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 2153 | int i; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 2154 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 2155 | for (i = 0; i < TVMEMSIZE; i++) { |
| 2156 | tvmem[i] = (void *)__get_free_page(GFP_KERNEL); |
| 2157 | if (!tvmem[i]) |
| 2158 | goto err_free_tv; |
| 2159 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | |
Herbert Xu | 8606813 | 2014-12-04 16:43:29 +0800 | [diff] [blame] | 2161 | err = do_test(alg, type, mask, mode); |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 2162 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 2163 | if (err) { |
| 2164 | printk(KERN_ERR "tcrypt: one or more tests failed!\n"); |
| 2165 | goto err_free_tv; |
| 2166 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 2168 | /* We intentionaly return -EAGAIN to prevent keeping the module, |
| 2169 | * unless we're running in fips mode. It does all its work from |
| 2170 | * init() and doesn't offer any runtime functionality, but in |
| 2171 | * the fips case, checking for a successful load is helpful. |
Michal Ludvig | 14fdf47 | 2006-05-30 14:49:38 +1000 | [diff] [blame] | 2172 | * => we don't need it in the memory, do we? |
| 2173 | * -- mludvig |
| 2174 | */ |
Jarod Wilson | 4e033a6 | 2009-05-27 15:10:21 +1000 | [diff] [blame] | 2175 | if (!fips_enabled) |
| 2176 | err = -EAGAIN; |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 2177 | |
Herbert Xu | f139cfa | 2008-07-31 12:23:53 +0800 | [diff] [blame] | 2178 | err_free_tv: |
| 2179 | for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) |
| 2180 | free_page((unsigned long)tvmem[i]); |
Mikko Herranen | e3a4ea4 | 2007-11-26 22:12:07 +0800 | [diff] [blame] | 2181 | |
| 2182 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | /* |
| 2186 | * If an init function is provided, an exit function must also be provided |
| 2187 | * to allow module unload. |
| 2188 | */ |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 2189 | static void __exit tcrypt_mod_fini(void) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | |
Kamalesh Babulal | 3af5b90 | 2008-04-05 21:00:57 +0800 | [diff] [blame] | 2191 | module_init(tcrypt_mod_init); |
| 2192 | module_exit(tcrypt_mod_fini); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | |
Steffen Klassert | a873a5f | 2009-06-19 19:46:53 +0800 | [diff] [blame] | 2194 | module_param(alg, charp, 0); |
| 2195 | module_param(type, uint, 0); |
Herbert Xu | 7be380f | 2009-07-14 16:06:54 +0800 | [diff] [blame] | 2196 | module_param(mask, uint, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | module_param(mode, int, 0); |
Harald Welte | ebfd9bc | 2005-06-22 13:27:23 -0700 | [diff] [blame] | 2198 | module_param(sec, uint, 0); |
Herbert Xu | 6a17944 | 2005-06-22 13:29:03 -0700 | [diff] [blame] | 2199 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " |
| 2200 | "(defaults to zero which uses CPU cycles instead)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | |
| 2202 | MODULE_LICENSE("GPL"); |
| 2203 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
| 2204 | MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); |