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