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