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