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