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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 26 27 #include <crypto/aead.h> 28 #include <crypto/hash.h> 29 #include <crypto/skcipher.h> 30 #include <linux/err.h> 31 #include <linux/fips.h> 32 #include <linux/init.h> 33 #include <linux/gfp.h> 34 #include <linux/module.h> 35 #include <linux/scatterlist.h> 36 #include <linux/string.h> 37 #include <linux/moduleparam.h> 38 #include <linux/jiffies.h> 39 #include <linux/timex.h> 40 #include <linux/interrupt.h> 41 #include "tcrypt.h" 42 43 /* 44 * Need slab memory for testing (size in number of pages). 45 */ 46 #define TVMEMSIZE 4 47 48 /* 49 * Used by test_cipher_speed() 50 */ 51 #define ENCRYPT 1 52 #define DECRYPT 0 53 54 #define MAX_DIGEST_SIZE 64 55 56 /* 57 * return a string with the driver name 58 */ 59 #define get_driver_name(tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm)) 60 61 /* 62 * Used by test_cipher_speed() 63 */ 64 static unsigned int sec; 65 66 static char *alg = NULL; 67 static u32 type; 68 static u32 mask; 69 static int mode; 70 static u32 num_mb = 8; 71 static char *tvmem[TVMEMSIZE]; 72 73 static char *check[] = { 74 "des", "md5", "des3_ede", "rot13", "sha1", "sha224", "sha256", "sm3", 75 "blowfish", "twofish", "serpent", "sha384", "sha512", "md4", "aes", 76 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", 77 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", 78 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", 79 "lzo", "cts", "zlib", "sha3-224", "sha3-256", "sha3-384", "sha3-512", 80 NULL 81 }; 82 83 static u32 block_sizes[] = { 16, 64, 256, 1024, 8192, 0 }; 84 static u32 aead_sizes[] = { 16, 64, 256, 512, 1024, 2048, 4096, 8192, 0 }; 85 86 #define XBUFSIZE 8 87 #define MAX_IVLEN 32 88 89 static int testmgr_alloc_buf(char *buf[XBUFSIZE]) 90 { 91 int i; 92 93 for (i = 0; i < XBUFSIZE; i++) { 94 buf[i] = (void *)__get_free_page(GFP_KERNEL); 95 if (!buf[i]) 96 goto err_free_buf; 97 } 98 99 return 0; 100 101 err_free_buf: 102 while (i-- > 0) 103 free_page((unsigned long)buf[i]); 104 105 return -ENOMEM; 106 } 107 108 static void testmgr_free_buf(char *buf[XBUFSIZE]) 109 { 110 int i; 111 112 for (i = 0; i < XBUFSIZE; i++) 113 free_page((unsigned long)buf[i]); 114 } 115 116 static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE], 117 unsigned int buflen, const void *assoc, 118 unsigned int aad_size) 119 { 120 int np = (buflen + PAGE_SIZE - 1)/PAGE_SIZE; 121 int k, rem; 122 123 if (np > XBUFSIZE) { 124 rem = PAGE_SIZE; 125 np = XBUFSIZE; 126 } else { 127 rem = buflen % PAGE_SIZE; 128 } 129 130 sg_init_table(sg, np + 1); 131 132 sg_set_buf(&sg[0], assoc, aad_size); 133 134 if (rem) 135 np--; 136 for (k = 0; k < np; k++) 137 sg_set_buf(&sg[k + 1], xbuf[k], PAGE_SIZE); 138 139 if (rem) 140 sg_set_buf(&sg[k + 1], xbuf[k], rem); 141 } 142 143 static inline int do_one_aead_op(struct aead_request *req, int ret) 144 { 145 struct crypto_wait *wait = req->base.data; 146 147 return crypto_wait_req(ret, wait); 148 } 149 150 struct test_mb_aead_data { 151 struct scatterlist sg[XBUFSIZE]; 152 struct scatterlist sgout[XBUFSIZE]; 153 struct aead_request *req; 154 struct crypto_wait wait; 155 char *xbuf[XBUFSIZE]; 156 char *xoutbuf[XBUFSIZE]; 157 char *axbuf[XBUFSIZE]; 158 }; 159 160 static int do_mult_aead_op(struct test_mb_aead_data *data, int enc, 161 u32 num_mb, int *rc) 162 { 163 int i, err = 0; 164 165 /* Fire up a bunch of concurrent requests */ 166 for (i = 0; i < num_mb; i++) { 167 if (enc == ENCRYPT) 168 rc[i] = crypto_aead_encrypt(data[i].req); 169 else 170 rc[i] = crypto_aead_decrypt(data[i].req); 171 } 172 173 /* Wait for all requests to finish */ 174 for (i = 0; i < num_mb; i++) { 175 rc[i] = crypto_wait_req(rc[i], &data[i].wait); 176 177 if (rc[i]) { 178 pr_info("concurrent request %d error %d\n", i, rc[i]); 179 err = rc[i]; 180 } 181 } 182 183 return err; 184 } 185 186 static int test_mb_aead_jiffies(struct test_mb_aead_data *data, int enc, 187 int blen, int secs, u32 num_mb) 188 { 189 unsigned long start, end; 190 int bcount; 191 int ret = 0; 192 int *rc; 193 194 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); 195 if (!rc) 196 return -ENOMEM; 197 198 for (start = jiffies, end = start + secs * HZ, bcount = 0; 199 time_before(jiffies, end); bcount++) { 200 ret = do_mult_aead_op(data, enc, num_mb, rc); 201 if (ret) 202 goto out; 203 } 204 205 pr_cont("%d operations in %d seconds (%ld bytes)\n", 206 bcount * num_mb, secs, (long)bcount * blen * num_mb); 207 208 out: 209 kfree(rc); 210 return ret; 211 } 212 213 static int test_mb_aead_cycles(struct test_mb_aead_data *data, int enc, 214 int blen, u32 num_mb) 215 { 216 unsigned long cycles = 0; 217 int ret = 0; 218 int i; 219 int *rc; 220 221 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); 222 if (!rc) 223 return -ENOMEM; 224 225 /* Warm-up run. */ 226 for (i = 0; i < 4; i++) { 227 ret = do_mult_aead_op(data, enc, num_mb, rc); 228 if (ret) 229 goto out; 230 } 231 232 /* The real thing. */ 233 for (i = 0; i < 8; i++) { 234 cycles_t start, end; 235 236 start = get_cycles(); 237 ret = do_mult_aead_op(data, enc, num_mb, rc); 238 end = get_cycles(); 239 240 if (ret) 241 goto out; 242 243 cycles += end - start; 244 } 245 246 pr_cont("1 operation in %lu cycles (%d bytes)\n", 247 (cycles + 4) / (8 * num_mb), blen); 248 249 out: 250 kfree(rc); 251 return ret; 252 } 253 254 static void test_mb_aead_speed(const char *algo, int enc, int secs, 255 struct aead_speed_template *template, 256 unsigned int tcount, u8 authsize, 257 unsigned int aad_size, u8 *keysize, u32 num_mb) 258 { 259 struct test_mb_aead_data *data; 260 struct crypto_aead *tfm; 261 unsigned int i, j, iv_len; 262 const char *key; 263 const char *e; 264 void *assoc; 265 u32 *b_size; 266 char *iv; 267 int ret; 268 269 270 if (aad_size >= PAGE_SIZE) { 271 pr_err("associate data length (%u) too big\n", aad_size); 272 return; 273 } 274 275 iv = kzalloc(MAX_IVLEN, GFP_KERNEL); 276 if (!iv) 277 return; 278 279 if (enc == ENCRYPT) 280 e = "encryption"; 281 else 282 e = "decryption"; 283 284 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL); 285 if (!data) 286 goto out_free_iv; 287 288 tfm = crypto_alloc_aead(algo, 0, 0); 289 if (IS_ERR(tfm)) { 290 pr_err("failed to load transform for %s: %ld\n", 291 algo, PTR_ERR(tfm)); 292 goto out_free_data; 293 } 294 295 ret = crypto_aead_setauthsize(tfm, authsize); 296 297 for (i = 0; i < num_mb; ++i) 298 if (testmgr_alloc_buf(data[i].xbuf)) { 299 while (i--) 300 testmgr_free_buf(data[i].xbuf); 301 goto out_free_tfm; 302 } 303 304 for (i = 0; i < num_mb; ++i) 305 if (testmgr_alloc_buf(data[i].axbuf)) { 306 while (i--) 307 testmgr_free_buf(data[i].axbuf); 308 goto out_free_xbuf; 309 } 310 311 for (i = 0; i < num_mb; ++i) 312 if (testmgr_alloc_buf(data[i].xoutbuf)) { 313 while (i--) 314 testmgr_free_buf(data[i].xoutbuf); 315 goto out_free_axbuf; 316 } 317 318 for (i = 0; i < num_mb; ++i) { 319 data[i].req = aead_request_alloc(tfm, GFP_KERNEL); 320 if (!data[i].req) { 321 pr_err("alg: skcipher: Failed to allocate request for %s\n", 322 algo); 323 while (i--) 324 aead_request_free(data[i].req); 325 goto out_free_xoutbuf; 326 } 327 } 328 329 for (i = 0; i < num_mb; ++i) { 330 crypto_init_wait(&data[i].wait); 331 aead_request_set_callback(data[i].req, 332 CRYPTO_TFM_REQ_MAY_BACKLOG, 333 crypto_req_done, &data[i].wait); 334 } 335 336 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo, 337 get_driver_name(crypto_aead, tfm), e); 338 339 i = 0; 340 do { 341 b_size = aead_sizes; 342 do { 343 if (*b_size + authsize > XBUFSIZE * PAGE_SIZE) { 344 pr_err("template (%u) too big for buffer (%lu)\n", 345 authsize + *b_size, 346 XBUFSIZE * PAGE_SIZE); 347 goto out; 348 } 349 350 pr_info("test %u (%d bit key, %d byte blocks): ", i, 351 *keysize * 8, *b_size); 352 353 /* Set up tfm global state, i.e. the key */ 354 355 memset(tvmem[0], 0xff, PAGE_SIZE); 356 key = tvmem[0]; 357 for (j = 0; j < tcount; j++) { 358 if (template[j].klen == *keysize) { 359 key = template[j].key; 360 break; 361 } 362 } 363 364 crypto_aead_clear_flags(tfm, ~0); 365 366 ret = crypto_aead_setkey(tfm, key, *keysize); 367 if (ret) { 368 pr_err("setkey() failed flags=%x\n", 369 crypto_aead_get_flags(tfm)); 370 goto out; 371 } 372 373 iv_len = crypto_aead_ivsize(tfm); 374 if (iv_len) 375 memset(iv, 0xff, iv_len); 376 377 /* Now setup per request stuff, i.e. buffers */ 378 379 for (j = 0; j < num_mb; ++j) { 380 struct test_mb_aead_data *cur = &data[j]; 381 382 assoc = cur->axbuf[0]; 383 memset(assoc, 0xff, aad_size); 384 385 sg_init_aead(cur->sg, cur->xbuf, 386 *b_size + (enc ? 0 : authsize), 387 assoc, aad_size); 388 389 sg_init_aead(cur->sgout, cur->xoutbuf, 390 *b_size + (enc ? authsize : 0), 391 assoc, aad_size); 392 393 aead_request_set_ad(cur->req, aad_size); 394 395 if (!enc) { 396 397 aead_request_set_crypt(cur->req, 398 cur->sgout, 399 cur->sg, 400 *b_size, iv); 401 ret = crypto_aead_encrypt(cur->req); 402 ret = do_one_aead_op(cur->req, ret); 403 404 if (ret) { 405 pr_err("calculating auth failed failed (%d)\n", 406 ret); 407 break; 408 } 409 } 410 411 aead_request_set_crypt(cur->req, cur->sg, 412 cur->sgout, *b_size + 413 (enc ? 0 : authsize), 414 iv); 415 416 } 417 418 if (secs) { 419 ret = test_mb_aead_jiffies(data, enc, *b_size, 420 secs, num_mb); 421 cond_resched(); 422 } else { 423 ret = test_mb_aead_cycles(data, enc, *b_size, 424 num_mb); 425 } 426 427 if (ret) { 428 pr_err("%s() failed return code=%d\n", e, ret); 429 break; 430 } 431 b_size++; 432 i++; 433 } while (*b_size); 434 keysize++; 435 } while (*keysize); 436 437 out: 438 for (i = 0; i < num_mb; ++i) 439 aead_request_free(data[i].req); 440 out_free_xoutbuf: 441 for (i = 0; i < num_mb; ++i) 442 testmgr_free_buf(data[i].xoutbuf); 443 out_free_axbuf: 444 for (i = 0; i < num_mb; ++i) 445 testmgr_free_buf(data[i].axbuf); 446 out_free_xbuf: 447 for (i = 0; i < num_mb; ++i) 448 testmgr_free_buf(data[i].xbuf); 449 out_free_tfm: 450 crypto_free_aead(tfm); 451 out_free_data: 452 kfree(data); 453 out_free_iv: 454 kfree(iv); 455 } 456 457 static int test_aead_jiffies(struct aead_request *req, int enc, 458 int blen, int secs) 459 { 460 unsigned long start, end; 461 int bcount; 462 int ret; 463 464 for (start = jiffies, end = start + secs * HZ, bcount = 0; 465 time_before(jiffies, end); bcount++) { 466 if (enc) 467 ret = do_one_aead_op(req, crypto_aead_encrypt(req)); 468 else 469 ret = do_one_aead_op(req, crypto_aead_decrypt(req)); 470 471 if (ret) 472 return ret; 473 } 474 475 printk("%d operations in %d seconds (%ld bytes)\n", 476 bcount, secs, (long)bcount * blen); 477 return 0; 478 } 479 480 static int test_aead_cycles(struct aead_request *req, int enc, int blen) 481 { 482 unsigned long cycles = 0; 483 int ret = 0; 484 int i; 485 486 /* Warm-up run. */ 487 for (i = 0; i < 4; i++) { 488 if (enc) 489 ret = do_one_aead_op(req, crypto_aead_encrypt(req)); 490 else 491 ret = do_one_aead_op(req, crypto_aead_decrypt(req)); 492 493 if (ret) 494 goto out; 495 } 496 497 /* The real thing. */ 498 for (i = 0; i < 8; i++) { 499 cycles_t start, end; 500 501 start = get_cycles(); 502 if (enc) 503 ret = do_one_aead_op(req, crypto_aead_encrypt(req)); 504 else 505 ret = do_one_aead_op(req, crypto_aead_decrypt(req)); 506 end = get_cycles(); 507 508 if (ret) 509 goto out; 510 511 cycles += end - start; 512 } 513 514 out: 515 if (ret == 0) 516 printk("1 operation in %lu cycles (%d bytes)\n", 517 (cycles + 4) / 8, blen); 518 519 return ret; 520 } 521 522 static void test_aead_speed(const char *algo, int enc, unsigned int secs, 523 struct aead_speed_template *template, 524 unsigned int tcount, u8 authsize, 525 unsigned int aad_size, u8 *keysize) 526 { 527 unsigned int i, j; 528 struct crypto_aead *tfm; 529 int ret = -ENOMEM; 530 const char *key; 531 struct aead_request *req; 532 struct scatterlist *sg; 533 struct scatterlist *sgout; 534 const char *e; 535 void *assoc; 536 char *iv; 537 char *xbuf[XBUFSIZE]; 538 char *xoutbuf[XBUFSIZE]; 539 char *axbuf[XBUFSIZE]; 540 unsigned int *b_size; 541 unsigned int iv_len; 542 struct crypto_wait wait; 543 544 iv = kzalloc(MAX_IVLEN, GFP_KERNEL); 545 if (!iv) 546 return; 547 548 if (aad_size >= PAGE_SIZE) { 549 pr_err("associate data length (%u) too big\n", aad_size); 550 goto out_noxbuf; 551 } 552 553 if (enc == ENCRYPT) 554 e = "encryption"; 555 else 556 e = "decryption"; 557 558 if (testmgr_alloc_buf(xbuf)) 559 goto out_noxbuf; 560 if (testmgr_alloc_buf(axbuf)) 561 goto out_noaxbuf; 562 if (testmgr_alloc_buf(xoutbuf)) 563 goto out_nooutbuf; 564 565 sg = kmalloc(sizeof(*sg) * 9 * 2, GFP_KERNEL); 566 if (!sg) 567 goto out_nosg; 568 sgout = &sg[9]; 569 570 tfm = crypto_alloc_aead(algo, 0, 0); 571 572 if (IS_ERR(tfm)) { 573 pr_err("alg: aead: Failed to load transform for %s: %ld\n", algo, 574 PTR_ERR(tfm)); 575 goto out_notfm; 576 } 577 578 crypto_init_wait(&wait); 579 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, 580 get_driver_name(crypto_aead, tfm), e); 581 582 req = aead_request_alloc(tfm, GFP_KERNEL); 583 if (!req) { 584 pr_err("alg: aead: Failed to allocate request for %s\n", 585 algo); 586 goto out_noreq; 587 } 588 589 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 590 crypto_req_done, &wait); 591 592 i = 0; 593 do { 594 b_size = aead_sizes; 595 do { 596 assoc = axbuf[0]; 597 memset(assoc, 0xff, aad_size); 598 599 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { 600 pr_err("template (%u) too big for tvmem (%lu)\n", 601 *keysize + *b_size, 602 TVMEMSIZE * PAGE_SIZE); 603 goto out; 604 } 605 606 key = tvmem[0]; 607 for (j = 0; j < tcount; j++) { 608 if (template[j].klen == *keysize) { 609 key = template[j].key; 610 break; 611 } 612 } 613 ret = crypto_aead_setkey(tfm, key, *keysize); 614 ret = crypto_aead_setauthsize(tfm, authsize); 615 616 iv_len = crypto_aead_ivsize(tfm); 617 if (iv_len) 618 memset(iv, 0xff, iv_len); 619 620 crypto_aead_clear_flags(tfm, ~0); 621 printk(KERN_INFO "test %u (%d bit key, %d byte blocks): ", 622 i, *keysize * 8, *b_size); 623 624 625 memset(tvmem[0], 0xff, PAGE_SIZE); 626 627 if (ret) { 628 pr_err("setkey() failed flags=%x\n", 629 crypto_aead_get_flags(tfm)); 630 goto out; 631 } 632 633 sg_init_aead(sg, xbuf, *b_size + (enc ? 0 : authsize), 634 assoc, aad_size); 635 636 sg_init_aead(sgout, xoutbuf, 637 *b_size + (enc ? authsize : 0), assoc, 638 aad_size); 639 640 aead_request_set_ad(req, aad_size); 641 642 if (!enc) { 643 644 /* 645 * For decryption we need a proper auth so 646 * we do the encryption path once with buffers 647 * reversed (input <-> output) to calculate it 648 */ 649 aead_request_set_crypt(req, sgout, sg, 650 *b_size, iv); 651 ret = do_one_aead_op(req, 652 crypto_aead_encrypt(req)); 653 654 if (ret) { 655 pr_err("calculating auth failed failed (%d)\n", 656 ret); 657 break; 658 } 659 } 660 661 aead_request_set_crypt(req, sg, sgout, 662 *b_size + (enc ? 0 : authsize), 663 iv); 664 665 if (secs) { 666 ret = test_aead_jiffies(req, enc, *b_size, 667 secs); 668 cond_resched(); 669 } else { 670 ret = test_aead_cycles(req, enc, *b_size); 671 } 672 673 if (ret) { 674 pr_err("%s() failed return code=%d\n", e, ret); 675 break; 676 } 677 b_size++; 678 i++; 679 } while (*b_size); 680 keysize++; 681 } while (*keysize); 682 683 out: 684 aead_request_free(req); 685 out_noreq: 686 crypto_free_aead(tfm); 687 out_notfm: 688 kfree(sg); 689 out_nosg: 690 testmgr_free_buf(xoutbuf); 691 out_nooutbuf: 692 testmgr_free_buf(axbuf); 693 out_noaxbuf: 694 testmgr_free_buf(xbuf); 695 out_noxbuf: 696 kfree(iv); 697 } 698 699 static void test_hash_sg_init(struct scatterlist *sg) 700 { 701 int i; 702 703 sg_init_table(sg, TVMEMSIZE); 704 for (i = 0; i < TVMEMSIZE; i++) { 705 sg_set_buf(sg + i, tvmem[i], PAGE_SIZE); 706 memset(tvmem[i], 0xff, PAGE_SIZE); 707 } 708 } 709 710 static inline int do_one_ahash_op(struct ahash_request *req, int ret) 711 { 712 struct crypto_wait *wait = req->base.data; 713 714 return crypto_wait_req(ret, wait); 715 } 716 717 struct test_mb_ahash_data { 718 struct scatterlist sg[XBUFSIZE]; 719 char result[64]; 720 struct ahash_request *req; 721 struct crypto_wait wait; 722 char *xbuf[XBUFSIZE]; 723 }; 724 725 static inline int do_mult_ahash_op(struct test_mb_ahash_data *data, u32 num_mb, 726 int *rc) 727 { 728 int i, err = 0; 729 730 /* Fire up a bunch of concurrent requests */ 731 for (i = 0; i < num_mb; i++) 732 rc[i] = crypto_ahash_digest(data[i].req); 733 734 /* Wait for all requests to finish */ 735 for (i = 0; i < num_mb; i++) { 736 rc[i] = crypto_wait_req(rc[i], &data[i].wait); 737 738 if (rc[i]) { 739 pr_info("concurrent request %d error %d\n", i, rc[i]); 740 err = rc[i]; 741 } 742 } 743 744 return err; 745 } 746 747 static int test_mb_ahash_jiffies(struct test_mb_ahash_data *data, int blen, 748 int secs, u32 num_mb) 749 { 750 unsigned long start, end; 751 int bcount; 752 int ret = 0; 753 int *rc; 754 755 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); 756 if (!rc) 757 return -ENOMEM; 758 759 for (start = jiffies, end = start + secs * HZ, bcount = 0; 760 time_before(jiffies, end); bcount++) { 761 ret = do_mult_ahash_op(data, num_mb, rc); 762 if (ret) 763 goto out; 764 } 765 766 pr_cont("%d operations in %d seconds (%ld bytes)\n", 767 bcount * num_mb, secs, (long)bcount * blen * num_mb); 768 769 out: 770 kfree(rc); 771 return ret; 772 } 773 774 static int test_mb_ahash_cycles(struct test_mb_ahash_data *data, int blen, 775 u32 num_mb) 776 { 777 unsigned long cycles = 0; 778 int ret = 0; 779 int i; 780 int *rc; 781 782 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); 783 if (!rc) 784 return -ENOMEM; 785 786 /* Warm-up run. */ 787 for (i = 0; i < 4; i++) { 788 ret = do_mult_ahash_op(data, num_mb, rc); 789 if (ret) 790 goto out; 791 } 792 793 /* The real thing. */ 794 for (i = 0; i < 8; i++) { 795 cycles_t start, end; 796 797 start = get_cycles(); 798 ret = do_mult_ahash_op(data, num_mb, rc); 799 end = get_cycles(); 800 801 if (ret) 802 goto out; 803 804 cycles += end - start; 805 } 806 807 pr_cont("1 operation in %lu cycles (%d bytes)\n", 808 (cycles + 4) / (8 * num_mb), blen); 809 810 out: 811 kfree(rc); 812 return ret; 813 } 814 815 static void test_mb_ahash_speed(const char *algo, unsigned int secs, 816 struct hash_speed *speed, u32 num_mb) 817 { 818 struct test_mb_ahash_data *data; 819 struct crypto_ahash *tfm; 820 unsigned int i, j, k; 821 int ret; 822 823 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL); 824 if (!data) 825 return; 826 827 tfm = crypto_alloc_ahash(algo, 0, 0); 828 if (IS_ERR(tfm)) { 829 pr_err("failed to load transform for %s: %ld\n", 830 algo, PTR_ERR(tfm)); 831 goto free_data; 832 } 833 834 for (i = 0; i < num_mb; ++i) { 835 if (testmgr_alloc_buf(data[i].xbuf)) 836 goto out; 837 838 crypto_init_wait(&data[i].wait); 839 840 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL); 841 if (!data[i].req) { 842 pr_err("alg: hash: Failed to allocate request for %s\n", 843 algo); 844 goto out; 845 } 846 847 ahash_request_set_callback(data[i].req, 0, crypto_req_done, 848 &data[i].wait); 849 850 sg_init_table(data[i].sg, XBUFSIZE); 851 for (j = 0; j < XBUFSIZE; j++) { 852 sg_set_buf(data[i].sg + j, data[i].xbuf[j], PAGE_SIZE); 853 memset(data[i].xbuf[j], 0xff, PAGE_SIZE); 854 } 855 } 856 857 pr_info("\ntesting speed of multibuffer %s (%s)\n", algo, 858 get_driver_name(crypto_ahash, tfm)); 859 860 for (i = 0; speed[i].blen != 0; i++) { 861 /* For some reason this only tests digests. */ 862 if (speed[i].blen != speed[i].plen) 863 continue; 864 865 if (speed[i].blen > XBUFSIZE * PAGE_SIZE) { 866 pr_err("template (%u) too big for tvmem (%lu)\n", 867 speed[i].blen, XBUFSIZE * PAGE_SIZE); 868 goto out; 869 } 870 871 if (speed[i].klen) 872 crypto_ahash_setkey(tfm, tvmem[0], speed[i].klen); 873 874 for (k = 0; k < num_mb; k++) 875 ahash_request_set_crypt(data[k].req, data[k].sg, 876 data[k].result, speed[i].blen); 877 878 pr_info("test%3u " 879 "(%5u byte blocks,%5u bytes per update,%4u updates): ", 880 i, speed[i].blen, speed[i].plen, 881 speed[i].blen / speed[i].plen); 882 883 if (secs) { 884 ret = test_mb_ahash_jiffies(data, speed[i].blen, secs, 885 num_mb); 886 cond_resched(); 887 } else { 888 ret = test_mb_ahash_cycles(data, speed[i].blen, num_mb); 889 } 890 891 892 if (ret) { 893 pr_err("At least one hashing failed ret=%d\n", ret); 894 break; 895 } 896 } 897 898 out: 899 for (k = 0; k < num_mb; ++k) 900 ahash_request_free(data[k].req); 901 902 for (k = 0; k < num_mb; ++k) 903 testmgr_free_buf(data[k].xbuf); 904 905 crypto_free_ahash(tfm); 906 907 free_data: 908 kfree(data); 909 } 910 911 static int test_ahash_jiffies_digest(struct ahash_request *req, int blen, 912 char *out, int secs) 913 { 914 unsigned long start, end; 915 int bcount; 916 int ret; 917 918 for (start = jiffies, end = start + secs * HZ, bcount = 0; 919 time_before(jiffies, end); bcount++) { 920 ret = do_one_ahash_op(req, crypto_ahash_digest(req)); 921 if (ret) 922 return ret; 923 } 924 925 printk("%6u opers/sec, %9lu bytes/sec\n", 926 bcount / secs, ((long)bcount * blen) / secs); 927 928 return 0; 929 } 930 931 static int test_ahash_jiffies(struct ahash_request *req, int blen, 932 int plen, char *out, int secs) 933 { 934 unsigned long start, end; 935 int bcount, pcount; 936 int ret; 937 938 if (plen == blen) 939 return test_ahash_jiffies_digest(req, blen, out, secs); 940 941 for (start = jiffies, end = start + secs * HZ, bcount = 0; 942 time_before(jiffies, end); bcount++) { 943 ret = do_one_ahash_op(req, crypto_ahash_init(req)); 944 if (ret) 945 return ret; 946 for (pcount = 0; pcount < blen; pcount += plen) { 947 ret = do_one_ahash_op(req, crypto_ahash_update(req)); 948 if (ret) 949 return ret; 950 } 951 /* we assume there is enough space in 'out' for the result */ 952 ret = do_one_ahash_op(req, crypto_ahash_final(req)); 953 if (ret) 954 return ret; 955 } 956 957 pr_cont("%6u opers/sec, %9lu bytes/sec\n", 958 bcount / secs, ((long)bcount * blen) / secs); 959 960 return 0; 961 } 962 963 static int test_ahash_cycles_digest(struct ahash_request *req, int blen, 964 char *out) 965 { 966 unsigned long cycles = 0; 967 int ret, i; 968 969 /* Warm-up run. */ 970 for (i = 0; i < 4; i++) { 971 ret = do_one_ahash_op(req, crypto_ahash_digest(req)); 972 if (ret) 973 goto out; 974 } 975 976 /* The real thing. */ 977 for (i = 0; i < 8; i++) { 978 cycles_t start, end; 979 980 start = get_cycles(); 981 982 ret = do_one_ahash_op(req, crypto_ahash_digest(req)); 983 if (ret) 984 goto out; 985 986 end = get_cycles(); 987 988 cycles += end - start; 989 } 990 991 out: 992 if (ret) 993 return ret; 994 995 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", 996 cycles / 8, cycles / (8 * blen)); 997 998 return 0; 999 } 1000 1001 static int test_ahash_cycles(struct ahash_request *req, int blen, 1002 int plen, char *out) 1003 { 1004 unsigned long cycles = 0; 1005 int i, pcount, ret; 1006 1007 if (plen == blen) 1008 return test_ahash_cycles_digest(req, blen, out); 1009 1010 /* Warm-up run. */ 1011 for (i = 0; i < 4; i++) { 1012 ret = do_one_ahash_op(req, crypto_ahash_init(req)); 1013 if (ret) 1014 goto out; 1015 for (pcount = 0; pcount < blen; pcount += plen) { 1016 ret = do_one_ahash_op(req, crypto_ahash_update(req)); 1017 if (ret) 1018 goto out; 1019 } 1020 ret = do_one_ahash_op(req, crypto_ahash_final(req)); 1021 if (ret) 1022 goto out; 1023 } 1024 1025 /* The real thing. */ 1026 for (i = 0; i < 8; i++) { 1027 cycles_t start, end; 1028 1029 start = get_cycles(); 1030 1031 ret = do_one_ahash_op(req, crypto_ahash_init(req)); 1032 if (ret) 1033 goto out; 1034 for (pcount = 0; pcount < blen; pcount += plen) { 1035 ret = do_one_ahash_op(req, crypto_ahash_update(req)); 1036 if (ret) 1037 goto out; 1038 } 1039 ret = do_one_ahash_op(req, crypto_ahash_final(req)); 1040 if (ret) 1041 goto out; 1042 1043 end = get_cycles(); 1044 1045 cycles += end - start; 1046 } 1047 1048 out: 1049 if (ret) 1050 return ret; 1051 1052 pr_cont("%6lu cycles/operation, %4lu cycles/byte\n", 1053 cycles / 8, cycles / (8 * blen)); 1054 1055 return 0; 1056 } 1057 1058 static void test_ahash_speed_common(const char *algo, unsigned int secs, 1059 struct hash_speed *speed, unsigned mask) 1060 { 1061 struct scatterlist sg[TVMEMSIZE]; 1062 struct crypto_wait wait; 1063 struct ahash_request *req; 1064 struct crypto_ahash *tfm; 1065 char *output; 1066 int i, ret; 1067 1068 tfm = crypto_alloc_ahash(algo, 0, mask); 1069 if (IS_ERR(tfm)) { 1070 pr_err("failed to load transform for %s: %ld\n", 1071 algo, PTR_ERR(tfm)); 1072 return; 1073 } 1074 1075 printk(KERN_INFO "\ntesting speed of async %s (%s)\n", algo, 1076 get_driver_name(crypto_ahash, tfm)); 1077 1078 if (crypto_ahash_digestsize(tfm) > MAX_DIGEST_SIZE) { 1079 pr_err("digestsize(%u) > %d\n", crypto_ahash_digestsize(tfm), 1080 MAX_DIGEST_SIZE); 1081 goto out; 1082 } 1083 1084 test_hash_sg_init(sg); 1085 req = ahash_request_alloc(tfm, GFP_KERNEL); 1086 if (!req) { 1087 pr_err("ahash request allocation failure\n"); 1088 goto out; 1089 } 1090 1091 crypto_init_wait(&wait); 1092 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1093 crypto_req_done, &wait); 1094 1095 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); 1096 if (!output) 1097 goto out_nomem; 1098 1099 for (i = 0; speed[i].blen != 0; i++) { 1100 if (speed[i].blen > TVMEMSIZE * PAGE_SIZE) { 1101 pr_err("template (%u) too big for tvmem (%lu)\n", 1102 speed[i].blen, TVMEMSIZE * PAGE_SIZE); 1103 break; 1104 } 1105 1106 pr_info("test%3u " 1107 "(%5u byte blocks,%5u bytes per update,%4u updates): ", 1108 i, speed[i].blen, speed[i].plen, speed[i].blen / speed[i].plen); 1109 1110 ahash_request_set_crypt(req, sg, output, speed[i].plen); 1111 1112 if (secs) { 1113 ret = test_ahash_jiffies(req, speed[i].blen, 1114 speed[i].plen, output, secs); 1115 cond_resched(); 1116 } else { 1117 ret = test_ahash_cycles(req, speed[i].blen, 1118 speed[i].plen, output); 1119 } 1120 1121 if (ret) { 1122 pr_err("hashing failed ret=%d\n", ret); 1123 break; 1124 } 1125 } 1126 1127 kfree(output); 1128 1129 out_nomem: 1130 ahash_request_free(req); 1131 1132 out: 1133 crypto_free_ahash(tfm); 1134 } 1135 1136 static void test_ahash_speed(const char *algo, unsigned int secs, 1137 struct hash_speed *speed) 1138 { 1139 return test_ahash_speed_common(algo, secs, speed, 0); 1140 } 1141 1142 static void test_hash_speed(const char *algo, unsigned int secs, 1143 struct hash_speed *speed) 1144 { 1145 return test_ahash_speed_common(algo, secs, speed, CRYPTO_ALG_ASYNC); 1146 } 1147 1148 struct test_mb_skcipher_data { 1149 struct scatterlist sg[XBUFSIZE]; 1150 struct skcipher_request *req; 1151 struct crypto_wait wait; 1152 char *xbuf[XBUFSIZE]; 1153 }; 1154 1155 static int do_mult_acipher_op(struct test_mb_skcipher_data *data, int enc, 1156 u32 num_mb, int *rc) 1157 { 1158 int i, err = 0; 1159 1160 /* Fire up a bunch of concurrent requests */ 1161 for (i = 0; i < num_mb; i++) { 1162 if (enc == ENCRYPT) 1163 rc[i] = crypto_skcipher_encrypt(data[i].req); 1164 else 1165 rc[i] = crypto_skcipher_decrypt(data[i].req); 1166 } 1167 1168 /* Wait for all requests to finish */ 1169 for (i = 0; i < num_mb; i++) { 1170 rc[i] = crypto_wait_req(rc[i], &data[i].wait); 1171 1172 if (rc[i]) { 1173 pr_info("concurrent request %d error %d\n", i, rc[i]); 1174 err = rc[i]; 1175 } 1176 } 1177 1178 return err; 1179 } 1180 1181 static int test_mb_acipher_jiffies(struct test_mb_skcipher_data *data, int enc, 1182 int blen, int secs, u32 num_mb) 1183 { 1184 unsigned long start, end; 1185 int bcount; 1186 int ret = 0; 1187 int *rc; 1188 1189 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); 1190 if (!rc) 1191 return -ENOMEM; 1192 1193 for (start = jiffies, end = start + secs * HZ, bcount = 0; 1194 time_before(jiffies, end); bcount++) { 1195 ret = do_mult_acipher_op(data, enc, num_mb, rc); 1196 if (ret) 1197 goto out; 1198 } 1199 1200 pr_cont("%d operations in %d seconds (%ld bytes)\n", 1201 bcount * num_mb, secs, (long)bcount * blen * num_mb); 1202 1203 out: 1204 kfree(rc); 1205 return ret; 1206 } 1207 1208 static int test_mb_acipher_cycles(struct test_mb_skcipher_data *data, int enc, 1209 int blen, u32 num_mb) 1210 { 1211 unsigned long cycles = 0; 1212 int ret = 0; 1213 int i; 1214 int *rc; 1215 1216 rc = kcalloc(num_mb, sizeof(*rc), GFP_KERNEL); 1217 if (!rc) 1218 return -ENOMEM; 1219 1220 /* Warm-up run. */ 1221 for (i = 0; i < 4; i++) { 1222 ret = do_mult_acipher_op(data, enc, num_mb, rc); 1223 if (ret) 1224 goto out; 1225 } 1226 1227 /* The real thing. */ 1228 for (i = 0; i < 8; i++) { 1229 cycles_t start, end; 1230 1231 start = get_cycles(); 1232 ret = do_mult_acipher_op(data, enc, num_mb, rc); 1233 end = get_cycles(); 1234 1235 if (ret) 1236 goto out; 1237 1238 cycles += end - start; 1239 } 1240 1241 pr_cont("1 operation in %lu cycles (%d bytes)\n", 1242 (cycles + 4) / (8 * num_mb), blen); 1243 1244 out: 1245 kfree(rc); 1246 return ret; 1247 } 1248 1249 static void test_mb_skcipher_speed(const char *algo, int enc, int secs, 1250 struct cipher_speed_template *template, 1251 unsigned int tcount, u8 *keysize, u32 num_mb) 1252 { 1253 struct test_mb_skcipher_data *data; 1254 struct crypto_skcipher *tfm; 1255 unsigned int i, j, iv_len; 1256 const char *key; 1257 const char *e; 1258 u32 *b_size; 1259 char iv[128]; 1260 int ret; 1261 1262 if (enc == ENCRYPT) 1263 e = "encryption"; 1264 else 1265 e = "decryption"; 1266 1267 data = kcalloc(num_mb, sizeof(*data), GFP_KERNEL); 1268 if (!data) 1269 return; 1270 1271 tfm = crypto_alloc_skcipher(algo, 0, 0); 1272 if (IS_ERR(tfm)) { 1273 pr_err("failed to load transform for %s: %ld\n", 1274 algo, PTR_ERR(tfm)); 1275 goto out_free_data; 1276 } 1277 1278 for (i = 0; i < num_mb; ++i) 1279 if (testmgr_alloc_buf(data[i].xbuf)) { 1280 while (i--) 1281 testmgr_free_buf(data[i].xbuf); 1282 goto out_free_tfm; 1283 } 1284 1285 1286 for (i = 0; i < num_mb; ++i) 1287 if (testmgr_alloc_buf(data[i].xbuf)) { 1288 while (i--) 1289 testmgr_free_buf(data[i].xbuf); 1290 goto out_free_tfm; 1291 } 1292 1293 1294 for (i = 0; i < num_mb; ++i) { 1295 data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL); 1296 if (!data[i].req) { 1297 pr_err("alg: skcipher: Failed to allocate request for %s\n", 1298 algo); 1299 while (i--) 1300 skcipher_request_free(data[i].req); 1301 goto out_free_xbuf; 1302 } 1303 } 1304 1305 for (i = 0; i < num_mb; ++i) { 1306 skcipher_request_set_callback(data[i].req, 1307 CRYPTO_TFM_REQ_MAY_BACKLOG, 1308 crypto_req_done, &data[i].wait); 1309 crypto_init_wait(&data[i].wait); 1310 } 1311 1312 pr_info("\ntesting speed of multibuffer %s (%s) %s\n", algo, 1313 get_driver_name(crypto_skcipher, tfm), e); 1314 1315 i = 0; 1316 do { 1317 b_size = block_sizes; 1318 do { 1319 if (*b_size > XBUFSIZE * PAGE_SIZE) { 1320 pr_err("template (%u) too big for buffer (%lu)\n", 1321 *b_size, XBUFSIZE * PAGE_SIZE); 1322 goto out; 1323 } 1324 1325 pr_info("test %u (%d bit key, %d byte blocks): ", i, 1326 *keysize * 8, *b_size); 1327 1328 /* Set up tfm global state, i.e. the key */ 1329 1330 memset(tvmem[0], 0xff, PAGE_SIZE); 1331 key = tvmem[0]; 1332 for (j = 0; j < tcount; j++) { 1333 if (template[j].klen == *keysize) { 1334 key = template[j].key; 1335 break; 1336 } 1337 } 1338 1339 crypto_skcipher_clear_flags(tfm, ~0); 1340 1341 ret = crypto_skcipher_setkey(tfm, key, *keysize); 1342 if (ret) { 1343 pr_err("setkey() failed flags=%x\n", 1344 crypto_skcipher_get_flags(tfm)); 1345 goto out; 1346 } 1347 1348 iv_len = crypto_skcipher_ivsize(tfm); 1349 if (iv_len) 1350 memset(&iv, 0xff, iv_len); 1351 1352 /* Now setup per request stuff, i.e. buffers */ 1353 1354 for (j = 0; j < num_mb; ++j) { 1355 struct test_mb_skcipher_data *cur = &data[j]; 1356 unsigned int k = *b_size; 1357 unsigned int pages = DIV_ROUND_UP(k, PAGE_SIZE); 1358 unsigned int p = 0; 1359 1360 sg_init_table(cur->sg, pages); 1361 1362 while (k > PAGE_SIZE) { 1363 sg_set_buf(cur->sg + p, cur->xbuf[p], 1364 PAGE_SIZE); 1365 memset(cur->xbuf[p], 0xff, PAGE_SIZE); 1366 p++; 1367 k -= PAGE_SIZE; 1368 } 1369 1370 sg_set_buf(cur->sg + p, cur->xbuf[p], k); 1371 memset(cur->xbuf[p], 0xff, k); 1372 1373 skcipher_request_set_crypt(cur->req, cur->sg, 1374 cur->sg, *b_size, 1375 iv); 1376 } 1377 1378 if (secs) { 1379 ret = test_mb_acipher_jiffies(data, enc, 1380 *b_size, secs, 1381 num_mb); 1382 cond_resched(); 1383 } else { 1384 ret = test_mb_acipher_cycles(data, enc, 1385 *b_size, num_mb); 1386 } 1387 1388 if (ret) { 1389 pr_err("%s() failed flags=%x\n", e, 1390 crypto_skcipher_get_flags(tfm)); 1391 break; 1392 } 1393 b_size++; 1394 i++; 1395 } while (*b_size); 1396 keysize++; 1397 } while (*keysize); 1398 1399 out: 1400 for (i = 0; i < num_mb; ++i) 1401 skcipher_request_free(data[i].req); 1402 out_free_xbuf: 1403 for (i = 0; i < num_mb; ++i) 1404 testmgr_free_buf(data[i].xbuf); 1405 out_free_tfm: 1406 crypto_free_skcipher(tfm); 1407 out_free_data: 1408 kfree(data); 1409 } 1410 1411 static inline int do_one_acipher_op(struct skcipher_request *req, int ret) 1412 { 1413 struct crypto_wait *wait = req->base.data; 1414 1415 return crypto_wait_req(ret, wait); 1416 } 1417 1418 static int test_acipher_jiffies(struct skcipher_request *req, int enc, 1419 int blen, int secs) 1420 { 1421 unsigned long start, end; 1422 int bcount; 1423 int ret; 1424 1425 for (start = jiffies, end = start + secs * HZ, bcount = 0; 1426 time_before(jiffies, end); bcount++) { 1427 if (enc) 1428 ret = do_one_acipher_op(req, 1429 crypto_skcipher_encrypt(req)); 1430 else 1431 ret = do_one_acipher_op(req, 1432 crypto_skcipher_decrypt(req)); 1433 1434 if (ret) 1435 return ret; 1436 } 1437 1438 pr_cont("%d operations in %d seconds (%ld bytes)\n", 1439 bcount, secs, (long)bcount * blen); 1440 return 0; 1441 } 1442 1443 static int test_acipher_cycles(struct skcipher_request *req, int enc, 1444 int blen) 1445 { 1446 unsigned long cycles = 0; 1447 int ret = 0; 1448 int i; 1449 1450 /* Warm-up run. */ 1451 for (i = 0; i < 4; i++) { 1452 if (enc) 1453 ret = do_one_acipher_op(req, 1454 crypto_skcipher_encrypt(req)); 1455 else 1456 ret = do_one_acipher_op(req, 1457 crypto_skcipher_decrypt(req)); 1458 1459 if (ret) 1460 goto out; 1461 } 1462 1463 /* The real thing. */ 1464 for (i = 0; i < 8; i++) { 1465 cycles_t start, end; 1466 1467 start = get_cycles(); 1468 if (enc) 1469 ret = do_one_acipher_op(req, 1470 crypto_skcipher_encrypt(req)); 1471 else 1472 ret = do_one_acipher_op(req, 1473 crypto_skcipher_decrypt(req)); 1474 end = get_cycles(); 1475 1476 if (ret) 1477 goto out; 1478 1479 cycles += end - start; 1480 } 1481 1482 out: 1483 if (ret == 0) 1484 pr_cont("1 operation in %lu cycles (%d bytes)\n", 1485 (cycles + 4) / 8, blen); 1486 1487 return ret; 1488 } 1489 1490 static void test_skcipher_speed(const char *algo, int enc, unsigned int secs, 1491 struct cipher_speed_template *template, 1492 unsigned int tcount, u8 *keysize, bool async) 1493 { 1494 unsigned int ret, i, j, k, iv_len; 1495 struct crypto_wait wait; 1496 const char *key; 1497 char iv[128]; 1498 struct skcipher_request *req; 1499 struct crypto_skcipher *tfm; 1500 const char *e; 1501 u32 *b_size; 1502 1503 if (enc == ENCRYPT) 1504 e = "encryption"; 1505 else 1506 e = "decryption"; 1507 1508 crypto_init_wait(&wait); 1509 1510 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC); 1511 1512 if (IS_ERR(tfm)) { 1513 pr_err("failed to load transform for %s: %ld\n", algo, 1514 PTR_ERR(tfm)); 1515 return; 1516 } 1517 1518 pr_info("\ntesting speed of async %s (%s) %s\n", algo, 1519 get_driver_name(crypto_skcipher, tfm), e); 1520 1521 req = skcipher_request_alloc(tfm, GFP_KERNEL); 1522 if (!req) { 1523 pr_err("tcrypt: skcipher: Failed to allocate request for %s\n", 1524 algo); 1525 goto out; 1526 } 1527 1528 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 1529 crypto_req_done, &wait); 1530 1531 i = 0; 1532 do { 1533 b_size = block_sizes; 1534 1535 do { 1536 struct scatterlist sg[TVMEMSIZE]; 1537 1538 if ((*keysize + *b_size) > TVMEMSIZE * PAGE_SIZE) { 1539 pr_err("template (%u) too big for " 1540 "tvmem (%lu)\n", *keysize + *b_size, 1541 TVMEMSIZE * PAGE_SIZE); 1542 goto out_free_req; 1543 } 1544 1545 pr_info("test %u (%d bit key, %d byte blocks): ", i, 1546 *keysize * 8, *b_size); 1547 1548 memset(tvmem[0], 0xff, PAGE_SIZE); 1549 1550 /* set key, plain text and IV */ 1551 key = tvmem[0]; 1552 for (j = 0; j < tcount; j++) { 1553 if (template[j].klen == *keysize) { 1554 key = template[j].key; 1555 break; 1556 } 1557 } 1558 1559 crypto_skcipher_clear_flags(tfm, ~0); 1560 1561 ret = crypto_skcipher_setkey(tfm, key, *keysize); 1562 if (ret) { 1563 pr_err("setkey() failed flags=%x\n", 1564 crypto_skcipher_get_flags(tfm)); 1565 goto out_free_req; 1566 } 1567 1568 k = *keysize + *b_size; 1569 sg_init_table(sg, DIV_ROUND_UP(k, PAGE_SIZE)); 1570 1571 if (k > PAGE_SIZE) { 1572 sg_set_buf(sg, tvmem[0] + *keysize, 1573 PAGE_SIZE - *keysize); 1574 k -= PAGE_SIZE; 1575 j = 1; 1576 while (k > PAGE_SIZE) { 1577 sg_set_buf(sg + j, tvmem[j], PAGE_SIZE); 1578 memset(tvmem[j], 0xff, PAGE_SIZE); 1579 j++; 1580 k -= PAGE_SIZE; 1581 } 1582 sg_set_buf(sg + j, tvmem[j], k); 1583 memset(tvmem[j], 0xff, k); 1584 } else { 1585 sg_set_buf(sg, tvmem[0] + *keysize, *b_size); 1586 } 1587 1588 iv_len = crypto_skcipher_ivsize(tfm); 1589 if (iv_len) 1590 memset(&iv, 0xff, iv_len); 1591 1592 skcipher_request_set_crypt(req, sg, sg, *b_size, iv); 1593 1594 if (secs) { 1595 ret = test_acipher_jiffies(req, enc, 1596 *b_size, secs); 1597 cond_resched(); 1598 } else { 1599 ret = test_acipher_cycles(req, enc, 1600 *b_size); 1601 } 1602 1603 if (ret) { 1604 pr_err("%s() failed flags=%x\n", e, 1605 crypto_skcipher_get_flags(tfm)); 1606 break; 1607 } 1608 b_size++; 1609 i++; 1610 } while (*b_size); 1611 keysize++; 1612 } while (*keysize); 1613 1614 out_free_req: 1615 skcipher_request_free(req); 1616 out: 1617 crypto_free_skcipher(tfm); 1618 } 1619 1620 static void test_acipher_speed(const char *algo, int enc, unsigned int secs, 1621 struct cipher_speed_template *template, 1622 unsigned int tcount, u8 *keysize) 1623 { 1624 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize, 1625 true); 1626 } 1627 1628 static void test_cipher_speed(const char *algo, int enc, unsigned int secs, 1629 struct cipher_speed_template *template, 1630 unsigned int tcount, u8 *keysize) 1631 { 1632 return test_skcipher_speed(algo, enc, secs, template, tcount, keysize, 1633 false); 1634 } 1635 1636 static void test_available(void) 1637 { 1638 char **name = check; 1639 1640 while (*name) { 1641 printk("alg %s ", *name); 1642 printk(crypto_has_alg(*name, 0, 0) ? 1643 "found\n" : "not found\n"); 1644 name++; 1645 } 1646 } 1647 1648 static inline int tcrypt_test(const char *alg) 1649 { 1650 int ret; 1651 1652 pr_debug("testing %s\n", alg); 1653 1654 ret = alg_test(alg, alg, 0, 0); 1655 /* non-fips algs return -EINVAL in fips mode */ 1656 if (fips_enabled && ret == -EINVAL) 1657 ret = 0; 1658 return ret; 1659 } 1660 1661 static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb) 1662 { 1663 int i; 1664 int ret = 0; 1665 1666 switch (m) { 1667 case 0: 1668 if (alg) { 1669 if (!crypto_has_alg(alg, type, 1670 mask ?: CRYPTO_ALG_TYPE_MASK)) 1671 ret = -ENOENT; 1672 break; 1673 } 1674 1675 for (i = 1; i < 200; i++) 1676 ret += do_test(NULL, 0, 0, i, num_mb); 1677 break; 1678 1679 case 1: 1680 ret += tcrypt_test("md5"); 1681 break; 1682 1683 case 2: 1684 ret += tcrypt_test("sha1"); 1685 break; 1686 1687 case 3: 1688 ret += tcrypt_test("ecb(des)"); 1689 ret += tcrypt_test("cbc(des)"); 1690 ret += tcrypt_test("ctr(des)"); 1691 break; 1692 1693 case 4: 1694 ret += tcrypt_test("ecb(des3_ede)"); 1695 ret += tcrypt_test("cbc(des3_ede)"); 1696 ret += tcrypt_test("ctr(des3_ede)"); 1697 break; 1698 1699 case 5: 1700 ret += tcrypt_test("md4"); 1701 break; 1702 1703 case 6: 1704 ret += tcrypt_test("sha256"); 1705 break; 1706 1707 case 7: 1708 ret += tcrypt_test("ecb(blowfish)"); 1709 ret += tcrypt_test("cbc(blowfish)"); 1710 ret += tcrypt_test("ctr(blowfish)"); 1711 break; 1712 1713 case 8: 1714 ret += tcrypt_test("ecb(twofish)"); 1715 ret += tcrypt_test("cbc(twofish)"); 1716 ret += tcrypt_test("ctr(twofish)"); 1717 ret += tcrypt_test("lrw(twofish)"); 1718 ret += tcrypt_test("xts(twofish)"); 1719 break; 1720 1721 case 9: 1722 ret += tcrypt_test("ecb(serpent)"); 1723 ret += tcrypt_test("cbc(serpent)"); 1724 ret += tcrypt_test("ctr(serpent)"); 1725 ret += tcrypt_test("lrw(serpent)"); 1726 ret += tcrypt_test("xts(serpent)"); 1727 break; 1728 1729 case 10: 1730 ret += tcrypt_test("ecb(aes)"); 1731 ret += tcrypt_test("cbc(aes)"); 1732 ret += tcrypt_test("lrw(aes)"); 1733 ret += tcrypt_test("xts(aes)"); 1734 ret += tcrypt_test("ctr(aes)"); 1735 ret += tcrypt_test("rfc3686(ctr(aes))"); 1736 break; 1737 1738 case 11: 1739 ret += tcrypt_test("sha384"); 1740 break; 1741 1742 case 12: 1743 ret += tcrypt_test("sha512"); 1744 break; 1745 1746 case 13: 1747 ret += tcrypt_test("deflate"); 1748 break; 1749 1750 case 14: 1751 ret += tcrypt_test("ecb(cast5)"); 1752 ret += tcrypt_test("cbc(cast5)"); 1753 ret += tcrypt_test("ctr(cast5)"); 1754 break; 1755 1756 case 15: 1757 ret += tcrypt_test("ecb(cast6)"); 1758 ret += tcrypt_test("cbc(cast6)"); 1759 ret += tcrypt_test("ctr(cast6)"); 1760 ret += tcrypt_test("lrw(cast6)"); 1761 ret += tcrypt_test("xts(cast6)"); 1762 break; 1763 1764 case 16: 1765 ret += tcrypt_test("ecb(arc4)"); 1766 break; 1767 1768 case 17: 1769 ret += tcrypt_test("michael_mic"); 1770 break; 1771 1772 case 18: 1773 ret += tcrypt_test("crc32c"); 1774 break; 1775 1776 case 19: 1777 ret += tcrypt_test("ecb(tea)"); 1778 break; 1779 1780 case 20: 1781 ret += tcrypt_test("ecb(xtea)"); 1782 break; 1783 1784 case 21: 1785 ret += tcrypt_test("ecb(khazad)"); 1786 break; 1787 1788 case 22: 1789 ret += tcrypt_test("wp512"); 1790 break; 1791 1792 case 23: 1793 ret += tcrypt_test("wp384"); 1794 break; 1795 1796 case 24: 1797 ret += tcrypt_test("wp256"); 1798 break; 1799 1800 case 25: 1801 ret += tcrypt_test("ecb(tnepres)"); 1802 break; 1803 1804 case 26: 1805 ret += tcrypt_test("ecb(anubis)"); 1806 ret += tcrypt_test("cbc(anubis)"); 1807 break; 1808 1809 case 27: 1810 ret += tcrypt_test("tgr192"); 1811 break; 1812 1813 case 28: 1814 ret += tcrypt_test("tgr160"); 1815 break; 1816 1817 case 29: 1818 ret += tcrypt_test("tgr128"); 1819 break; 1820 1821 case 30: 1822 ret += tcrypt_test("ecb(xeta)"); 1823 break; 1824 1825 case 31: 1826 ret += tcrypt_test("pcbc(fcrypt)"); 1827 break; 1828 1829 case 32: 1830 ret += tcrypt_test("ecb(camellia)"); 1831 ret += tcrypt_test("cbc(camellia)"); 1832 ret += tcrypt_test("ctr(camellia)"); 1833 ret += tcrypt_test("lrw(camellia)"); 1834 ret += tcrypt_test("xts(camellia)"); 1835 break; 1836 1837 case 33: 1838 ret += tcrypt_test("sha224"); 1839 break; 1840 1841 case 34: 1842 ret += tcrypt_test("salsa20"); 1843 break; 1844 1845 case 35: 1846 ret += tcrypt_test("gcm(aes)"); 1847 break; 1848 1849 case 36: 1850 ret += tcrypt_test("lzo"); 1851 break; 1852 1853 case 37: 1854 ret += tcrypt_test("ccm(aes)"); 1855 break; 1856 1857 case 38: 1858 ret += tcrypt_test("cts(cbc(aes))"); 1859 break; 1860 1861 case 39: 1862 ret += tcrypt_test("rmd128"); 1863 break; 1864 1865 case 40: 1866 ret += tcrypt_test("rmd160"); 1867 break; 1868 1869 case 41: 1870 ret += tcrypt_test("rmd256"); 1871 break; 1872 1873 case 42: 1874 ret += tcrypt_test("rmd320"); 1875 break; 1876 1877 case 43: 1878 ret += tcrypt_test("ecb(seed)"); 1879 break; 1880 1881 case 44: 1882 ret += tcrypt_test("zlib"); 1883 break; 1884 1885 case 45: 1886 ret += tcrypt_test("rfc4309(ccm(aes))"); 1887 break; 1888 1889 case 46: 1890 ret += tcrypt_test("ghash"); 1891 break; 1892 1893 case 47: 1894 ret += tcrypt_test("crct10dif"); 1895 break; 1896 1897 case 48: 1898 ret += tcrypt_test("sha3-224"); 1899 break; 1900 1901 case 49: 1902 ret += tcrypt_test("sha3-256"); 1903 break; 1904 1905 case 50: 1906 ret += tcrypt_test("sha3-384"); 1907 break; 1908 1909 case 51: 1910 ret += tcrypt_test("sha3-512"); 1911 break; 1912 1913 case 52: 1914 ret += tcrypt_test("sm3"); 1915 break; 1916 1917 case 100: 1918 ret += tcrypt_test("hmac(md5)"); 1919 break; 1920 1921 case 101: 1922 ret += tcrypt_test("hmac(sha1)"); 1923 break; 1924 1925 case 102: 1926 ret += tcrypt_test("hmac(sha256)"); 1927 break; 1928 1929 case 103: 1930 ret += tcrypt_test("hmac(sha384)"); 1931 break; 1932 1933 case 104: 1934 ret += tcrypt_test("hmac(sha512)"); 1935 break; 1936 1937 case 105: 1938 ret += tcrypt_test("hmac(sha224)"); 1939 break; 1940 1941 case 106: 1942 ret += tcrypt_test("xcbc(aes)"); 1943 break; 1944 1945 case 107: 1946 ret += tcrypt_test("hmac(rmd128)"); 1947 break; 1948 1949 case 108: 1950 ret += tcrypt_test("hmac(rmd160)"); 1951 break; 1952 1953 case 109: 1954 ret += tcrypt_test("vmac64(aes)"); 1955 break; 1956 1957 case 111: 1958 ret += tcrypt_test("hmac(sha3-224)"); 1959 break; 1960 1961 case 112: 1962 ret += tcrypt_test("hmac(sha3-256)"); 1963 break; 1964 1965 case 113: 1966 ret += tcrypt_test("hmac(sha3-384)"); 1967 break; 1968 1969 case 114: 1970 ret += tcrypt_test("hmac(sha3-512)"); 1971 break; 1972 1973 case 150: 1974 ret += tcrypt_test("ansi_cprng"); 1975 break; 1976 1977 case 151: 1978 ret += tcrypt_test("rfc4106(gcm(aes))"); 1979 break; 1980 1981 case 152: 1982 ret += tcrypt_test("rfc4543(gcm(aes))"); 1983 break; 1984 1985 case 153: 1986 ret += tcrypt_test("cmac(aes)"); 1987 break; 1988 1989 case 154: 1990 ret += tcrypt_test("cmac(des3_ede)"); 1991 break; 1992 1993 case 155: 1994 ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))"); 1995 break; 1996 1997 case 156: 1998 ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"); 1999 break; 2000 2001 case 157: 2002 ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"); 2003 break; 2004 case 181: 2005 ret += tcrypt_test("authenc(hmac(sha1),cbc(des))"); 2006 break; 2007 case 182: 2008 ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"); 2009 break; 2010 case 183: 2011 ret += tcrypt_test("authenc(hmac(sha224),cbc(des))"); 2012 break; 2013 case 184: 2014 ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"); 2015 break; 2016 case 185: 2017 ret += tcrypt_test("authenc(hmac(sha256),cbc(des))"); 2018 break; 2019 case 186: 2020 ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"); 2021 break; 2022 case 187: 2023 ret += tcrypt_test("authenc(hmac(sha384),cbc(des))"); 2024 break; 2025 case 188: 2026 ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"); 2027 break; 2028 case 189: 2029 ret += tcrypt_test("authenc(hmac(sha512),cbc(des))"); 2030 break; 2031 case 190: 2032 ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"); 2033 break; 2034 case 191: 2035 ret += tcrypt_test("ecb(sm4)"); 2036 break; 2037 case 200: 2038 test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 2039 speed_template_16_24_32); 2040 test_cipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, 2041 speed_template_16_24_32); 2042 test_cipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, 2043 speed_template_16_24_32); 2044 test_cipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, 2045 speed_template_16_24_32); 2046 test_cipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, 2047 speed_template_32_40_48); 2048 test_cipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, 2049 speed_template_32_40_48); 2050 test_cipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, 2051 speed_template_32_64); 2052 test_cipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, 2053 speed_template_32_64); 2054 test_cipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0, 2055 speed_template_16_24_32); 2056 test_cipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0, 2057 speed_template_16_24_32); 2058 test_cipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, 2059 speed_template_16_24_32); 2060 test_cipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, 2061 speed_template_16_24_32); 2062 break; 2063 2064 case 201: 2065 test_cipher_speed("ecb(des3_ede)", ENCRYPT, sec, 2066 des3_speed_template, DES3_SPEED_VECTORS, 2067 speed_template_24); 2068 test_cipher_speed("ecb(des3_ede)", DECRYPT, sec, 2069 des3_speed_template, DES3_SPEED_VECTORS, 2070 speed_template_24); 2071 test_cipher_speed("cbc(des3_ede)", ENCRYPT, sec, 2072 des3_speed_template, DES3_SPEED_VECTORS, 2073 speed_template_24); 2074 test_cipher_speed("cbc(des3_ede)", DECRYPT, sec, 2075 des3_speed_template, DES3_SPEED_VECTORS, 2076 speed_template_24); 2077 test_cipher_speed("ctr(des3_ede)", ENCRYPT, sec, 2078 des3_speed_template, DES3_SPEED_VECTORS, 2079 speed_template_24); 2080 test_cipher_speed("ctr(des3_ede)", DECRYPT, sec, 2081 des3_speed_template, DES3_SPEED_VECTORS, 2082 speed_template_24); 2083 break; 2084 2085 case 202: 2086 test_cipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, 2087 speed_template_16_24_32); 2088 test_cipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, 2089 speed_template_16_24_32); 2090 test_cipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, 2091 speed_template_16_24_32); 2092 test_cipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, 2093 speed_template_16_24_32); 2094 test_cipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, 2095 speed_template_16_24_32); 2096 test_cipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, 2097 speed_template_16_24_32); 2098 test_cipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, 2099 speed_template_32_40_48); 2100 test_cipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, 2101 speed_template_32_40_48); 2102 test_cipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, 2103 speed_template_32_48_64); 2104 test_cipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, 2105 speed_template_32_48_64); 2106 break; 2107 2108 case 203: 2109 test_cipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, 2110 speed_template_8_32); 2111 test_cipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, 2112 speed_template_8_32); 2113 test_cipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, 2114 speed_template_8_32); 2115 test_cipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, 2116 speed_template_8_32); 2117 test_cipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, 2118 speed_template_8_32); 2119 test_cipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, 2120 speed_template_8_32); 2121 break; 2122 2123 case 204: 2124 test_cipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, 2125 speed_template_8); 2126 test_cipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, 2127 speed_template_8); 2128 test_cipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, 2129 speed_template_8); 2130 test_cipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, 2131 speed_template_8); 2132 break; 2133 2134 case 205: 2135 test_cipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, 2136 speed_template_16_24_32); 2137 test_cipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, 2138 speed_template_16_24_32); 2139 test_cipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, 2140 speed_template_16_24_32); 2141 test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, 2142 speed_template_16_24_32); 2143 test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, 2144 speed_template_16_24_32); 2145 test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, 2146 speed_template_16_24_32); 2147 test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, 2148 speed_template_32_40_48); 2149 test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, 2150 speed_template_32_40_48); 2151 test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, 2152 speed_template_32_48_64); 2153 test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, 2154 speed_template_32_48_64); 2155 break; 2156 2157 case 206: 2158 test_cipher_speed("salsa20", ENCRYPT, sec, NULL, 0, 2159 speed_template_16_32); 2160 break; 2161 2162 case 207: 2163 test_cipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, 2164 speed_template_16_32); 2165 test_cipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, 2166 speed_template_16_32); 2167 test_cipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, 2168 speed_template_16_32); 2169 test_cipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, 2170 speed_template_16_32); 2171 test_cipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, 2172 speed_template_16_32); 2173 test_cipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, 2174 speed_template_16_32); 2175 test_cipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, 2176 speed_template_32_48); 2177 test_cipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, 2178 speed_template_32_48); 2179 test_cipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, 2180 speed_template_32_64); 2181 test_cipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, 2182 speed_template_32_64); 2183 break; 2184 2185 case 208: 2186 test_cipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, 2187 speed_template_8); 2188 break; 2189 2190 case 209: 2191 test_cipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, 2192 speed_template_8_16); 2193 test_cipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, 2194 speed_template_8_16); 2195 test_cipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, 2196 speed_template_8_16); 2197 test_cipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, 2198 speed_template_8_16); 2199 test_cipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, 2200 speed_template_8_16); 2201 test_cipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, 2202 speed_template_8_16); 2203 break; 2204 2205 case 210: 2206 test_cipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, 2207 speed_template_16_32); 2208 test_cipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, 2209 speed_template_16_32); 2210 test_cipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, 2211 speed_template_16_32); 2212 test_cipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, 2213 speed_template_16_32); 2214 test_cipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, 2215 speed_template_16_32); 2216 test_cipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, 2217 speed_template_16_32); 2218 test_cipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, 2219 speed_template_32_48); 2220 test_cipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, 2221 speed_template_32_48); 2222 test_cipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, 2223 speed_template_32_64); 2224 test_cipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, 2225 speed_template_32_64); 2226 break; 2227 2228 case 211: 2229 test_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, 2230 NULL, 0, 16, 16, aead_speed_template_20); 2231 test_aead_speed("gcm(aes)", ENCRYPT, sec, 2232 NULL, 0, 16, 8, speed_template_16_24_32); 2233 test_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, 2234 NULL, 0, 16, 16, aead_speed_template_20); 2235 test_aead_speed("gcm(aes)", DECRYPT, sec, 2236 NULL, 0, 16, 8, speed_template_16_24_32); 2237 break; 2238 2239 case 212: 2240 test_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, 2241 NULL, 0, 16, 16, aead_speed_template_19); 2242 test_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, 2243 NULL, 0, 16, 16, aead_speed_template_19); 2244 break; 2245 2246 case 213: 2247 test_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, sec, 2248 NULL, 0, 16, 8, aead_speed_template_36); 2249 test_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, sec, 2250 NULL, 0, 16, 8, aead_speed_template_36); 2251 break; 2252 2253 case 214: 2254 test_cipher_speed("chacha20", ENCRYPT, sec, NULL, 0, 2255 speed_template_32); 2256 break; 2257 2258 case 215: 2259 test_mb_aead_speed("rfc4106(gcm(aes))", ENCRYPT, sec, NULL, 2260 0, 16, 16, aead_speed_template_20, num_mb); 2261 test_mb_aead_speed("gcm(aes)", ENCRYPT, sec, NULL, 0, 16, 8, 2262 speed_template_16_24_32, num_mb); 2263 test_mb_aead_speed("rfc4106(gcm(aes))", DECRYPT, sec, NULL, 2264 0, 16, 16, aead_speed_template_20, num_mb); 2265 test_mb_aead_speed("gcm(aes)", DECRYPT, sec, NULL, 0, 16, 8, 2266 speed_template_16_24_32, num_mb); 2267 break; 2268 2269 case 216: 2270 test_mb_aead_speed("rfc4309(ccm(aes))", ENCRYPT, sec, NULL, 0, 2271 16, 16, aead_speed_template_19, num_mb); 2272 test_mb_aead_speed("rfc4309(ccm(aes))", DECRYPT, sec, NULL, 0, 2273 16, 16, aead_speed_template_19, num_mb); 2274 break; 2275 2276 case 217: 2277 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", ENCRYPT, 2278 sec, NULL, 0, 16, 8, aead_speed_template_36, 2279 num_mb); 2280 test_mb_aead_speed("rfc7539esp(chacha20,poly1305)", DECRYPT, 2281 sec, NULL, 0, 16, 8, aead_speed_template_36, 2282 num_mb); 2283 break; 2284 2285 case 300: 2286 if (alg) { 2287 test_hash_speed(alg, sec, generic_hash_speed_template); 2288 break; 2289 } 2290 /* fall through */ 2291 case 301: 2292 test_hash_speed("md4", sec, generic_hash_speed_template); 2293 if (mode > 300 && mode < 400) break; 2294 /* fall through */ 2295 case 302: 2296 test_hash_speed("md5", sec, generic_hash_speed_template); 2297 if (mode > 300 && mode < 400) break; 2298 /* fall through */ 2299 case 303: 2300 test_hash_speed("sha1", sec, generic_hash_speed_template); 2301 if (mode > 300 && mode < 400) break; 2302 /* fall through */ 2303 case 304: 2304 test_hash_speed("sha256", sec, generic_hash_speed_template); 2305 if (mode > 300 && mode < 400) break; 2306 /* fall through */ 2307 case 305: 2308 test_hash_speed("sha384", sec, generic_hash_speed_template); 2309 if (mode > 300 && mode < 400) break; 2310 /* fall through */ 2311 case 306: 2312 test_hash_speed("sha512", sec, generic_hash_speed_template); 2313 if (mode > 300 && mode < 400) break; 2314 /* fall through */ 2315 case 307: 2316 test_hash_speed("wp256", sec, generic_hash_speed_template); 2317 if (mode > 300 && mode < 400) break; 2318 /* fall through */ 2319 case 308: 2320 test_hash_speed("wp384", sec, generic_hash_speed_template); 2321 if (mode > 300 && mode < 400) break; 2322 /* fall through */ 2323 case 309: 2324 test_hash_speed("wp512", sec, generic_hash_speed_template); 2325 if (mode > 300 && mode < 400) break; 2326 /* fall through */ 2327 case 310: 2328 test_hash_speed("tgr128", sec, generic_hash_speed_template); 2329 if (mode > 300 && mode < 400) break; 2330 /* fall through */ 2331 case 311: 2332 test_hash_speed("tgr160", sec, generic_hash_speed_template); 2333 if (mode > 300 && mode < 400) break; 2334 /* fall through */ 2335 case 312: 2336 test_hash_speed("tgr192", sec, generic_hash_speed_template); 2337 if (mode > 300 && mode < 400) break; 2338 /* fall through */ 2339 case 313: 2340 test_hash_speed("sha224", sec, generic_hash_speed_template); 2341 if (mode > 300 && mode < 400) break; 2342 /* fall through */ 2343 case 314: 2344 test_hash_speed("rmd128", sec, generic_hash_speed_template); 2345 if (mode > 300 && mode < 400) break; 2346 /* fall through */ 2347 case 315: 2348 test_hash_speed("rmd160", sec, generic_hash_speed_template); 2349 if (mode > 300 && mode < 400) break; 2350 /* fall through */ 2351 case 316: 2352 test_hash_speed("rmd256", sec, generic_hash_speed_template); 2353 if (mode > 300 && mode < 400) break; 2354 /* fall through */ 2355 case 317: 2356 test_hash_speed("rmd320", sec, generic_hash_speed_template); 2357 if (mode > 300 && mode < 400) break; 2358 /* fall through */ 2359 case 318: 2360 test_hash_speed("ghash-generic", sec, hash_speed_template_16); 2361 if (mode > 300 && mode < 400) break; 2362 /* fall through */ 2363 case 319: 2364 test_hash_speed("crc32c", sec, generic_hash_speed_template); 2365 if (mode > 300 && mode < 400) break; 2366 /* fall through */ 2367 case 320: 2368 test_hash_speed("crct10dif", sec, generic_hash_speed_template); 2369 if (mode > 300 && mode < 400) break; 2370 /* fall through */ 2371 case 321: 2372 test_hash_speed("poly1305", sec, poly1305_speed_template); 2373 if (mode > 300 && mode < 400) break; 2374 /* fall through */ 2375 case 322: 2376 test_hash_speed("sha3-224", sec, generic_hash_speed_template); 2377 if (mode > 300 && mode < 400) break; 2378 /* fall through */ 2379 case 323: 2380 test_hash_speed("sha3-256", sec, generic_hash_speed_template); 2381 if (mode > 300 && mode < 400) break; 2382 /* fall through */ 2383 case 324: 2384 test_hash_speed("sha3-384", sec, generic_hash_speed_template); 2385 if (mode > 300 && mode < 400) break; 2386 /* fall through */ 2387 case 325: 2388 test_hash_speed("sha3-512", sec, generic_hash_speed_template); 2389 if (mode > 300 && mode < 400) break; 2390 /* fall through */ 2391 case 326: 2392 test_hash_speed("sm3", sec, generic_hash_speed_template); 2393 if (mode > 300 && mode < 400) break; 2394 /* fall through */ 2395 case 399: 2396 break; 2397 2398 case 400: 2399 if (alg) { 2400 test_ahash_speed(alg, sec, generic_hash_speed_template); 2401 break; 2402 } 2403 /* fall through */ 2404 case 401: 2405 test_ahash_speed("md4", sec, generic_hash_speed_template); 2406 if (mode > 400 && mode < 500) break; 2407 /* fall through */ 2408 case 402: 2409 test_ahash_speed("md5", sec, generic_hash_speed_template); 2410 if (mode > 400 && mode < 500) break; 2411 /* fall through */ 2412 case 403: 2413 test_ahash_speed("sha1", sec, generic_hash_speed_template); 2414 if (mode > 400 && mode < 500) break; 2415 /* fall through */ 2416 case 404: 2417 test_ahash_speed("sha256", sec, generic_hash_speed_template); 2418 if (mode > 400 && mode < 500) break; 2419 /* fall through */ 2420 case 405: 2421 test_ahash_speed("sha384", sec, generic_hash_speed_template); 2422 if (mode > 400 && mode < 500) break; 2423 /* fall through */ 2424 case 406: 2425 test_ahash_speed("sha512", sec, generic_hash_speed_template); 2426 if (mode > 400 && mode < 500) break; 2427 /* fall through */ 2428 case 407: 2429 test_ahash_speed("wp256", sec, generic_hash_speed_template); 2430 if (mode > 400 && mode < 500) break; 2431 /* fall through */ 2432 case 408: 2433 test_ahash_speed("wp384", sec, generic_hash_speed_template); 2434 if (mode > 400 && mode < 500) break; 2435 /* fall through */ 2436 case 409: 2437 test_ahash_speed("wp512", sec, generic_hash_speed_template); 2438 if (mode > 400 && mode < 500) break; 2439 /* fall through */ 2440 case 410: 2441 test_ahash_speed("tgr128", sec, generic_hash_speed_template); 2442 if (mode > 400 && mode < 500) break; 2443 /* fall through */ 2444 case 411: 2445 test_ahash_speed("tgr160", sec, generic_hash_speed_template); 2446 if (mode > 400 && mode < 500) break; 2447 /* fall through */ 2448 case 412: 2449 test_ahash_speed("tgr192", sec, generic_hash_speed_template); 2450 if (mode > 400 && mode < 500) break; 2451 /* fall through */ 2452 case 413: 2453 test_ahash_speed("sha224", sec, generic_hash_speed_template); 2454 if (mode > 400 && mode < 500) break; 2455 /* fall through */ 2456 case 414: 2457 test_ahash_speed("rmd128", sec, generic_hash_speed_template); 2458 if (mode > 400 && mode < 500) break; 2459 /* fall through */ 2460 case 415: 2461 test_ahash_speed("rmd160", sec, generic_hash_speed_template); 2462 if (mode > 400 && mode < 500) break; 2463 /* fall through */ 2464 case 416: 2465 test_ahash_speed("rmd256", sec, generic_hash_speed_template); 2466 if (mode > 400 && mode < 500) break; 2467 /* fall through */ 2468 case 417: 2469 test_ahash_speed("rmd320", sec, generic_hash_speed_template); 2470 if (mode > 400 && mode < 500) break; 2471 /* fall through */ 2472 case 418: 2473 test_ahash_speed("sha3-224", sec, generic_hash_speed_template); 2474 if (mode > 400 && mode < 500) break; 2475 /* fall through */ 2476 case 419: 2477 test_ahash_speed("sha3-256", sec, generic_hash_speed_template); 2478 if (mode > 400 && mode < 500) break; 2479 /* fall through */ 2480 case 420: 2481 test_ahash_speed("sha3-384", sec, generic_hash_speed_template); 2482 if (mode > 400 && mode < 500) break; 2483 /* fall through */ 2484 case 421: 2485 test_ahash_speed("sha3-512", sec, generic_hash_speed_template); 2486 if (mode > 400 && mode < 500) break; 2487 /* fall through */ 2488 case 422: 2489 test_mb_ahash_speed("sha1", sec, generic_hash_speed_template, 2490 num_mb); 2491 if (mode > 400 && mode < 500) break; 2492 /* fall through */ 2493 case 423: 2494 test_mb_ahash_speed("sha256", sec, generic_hash_speed_template, 2495 num_mb); 2496 if (mode > 400 && mode < 500) break; 2497 /* fall through */ 2498 case 424: 2499 test_mb_ahash_speed("sha512", sec, generic_hash_speed_template, 2500 num_mb); 2501 if (mode > 400 && mode < 500) break; 2502 /* fall through */ 2503 case 425: 2504 test_mb_ahash_speed("sm3", sec, generic_hash_speed_template, 2505 num_mb); 2506 if (mode > 400 && mode < 500) break; 2507 /* fall through */ 2508 case 499: 2509 break; 2510 2511 case 500: 2512 test_acipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 2513 speed_template_16_24_32); 2514 test_acipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, 2515 speed_template_16_24_32); 2516 test_acipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, 2517 speed_template_16_24_32); 2518 test_acipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, 2519 speed_template_16_24_32); 2520 test_acipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, 2521 speed_template_32_40_48); 2522 test_acipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, 2523 speed_template_32_40_48); 2524 test_acipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, 2525 speed_template_32_64); 2526 test_acipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, 2527 speed_template_32_64); 2528 test_acipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0, 2529 speed_template_16_24_32); 2530 test_acipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0, 2531 speed_template_16_24_32); 2532 test_acipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, 2533 speed_template_16_24_32); 2534 test_acipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, 2535 speed_template_16_24_32); 2536 test_acipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, 2537 speed_template_16_24_32); 2538 test_acipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, 2539 speed_template_16_24_32); 2540 test_acipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, 2541 speed_template_16_24_32); 2542 test_acipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, 2543 speed_template_16_24_32); 2544 test_acipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 0, 2545 speed_template_20_28_36); 2546 test_acipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 0, 2547 speed_template_20_28_36); 2548 break; 2549 2550 case 501: 2551 test_acipher_speed("ecb(des3_ede)", ENCRYPT, sec, 2552 des3_speed_template, DES3_SPEED_VECTORS, 2553 speed_template_24); 2554 test_acipher_speed("ecb(des3_ede)", DECRYPT, sec, 2555 des3_speed_template, DES3_SPEED_VECTORS, 2556 speed_template_24); 2557 test_acipher_speed("cbc(des3_ede)", ENCRYPT, sec, 2558 des3_speed_template, DES3_SPEED_VECTORS, 2559 speed_template_24); 2560 test_acipher_speed("cbc(des3_ede)", DECRYPT, sec, 2561 des3_speed_template, DES3_SPEED_VECTORS, 2562 speed_template_24); 2563 test_acipher_speed("cfb(des3_ede)", ENCRYPT, sec, 2564 des3_speed_template, DES3_SPEED_VECTORS, 2565 speed_template_24); 2566 test_acipher_speed("cfb(des3_ede)", DECRYPT, sec, 2567 des3_speed_template, DES3_SPEED_VECTORS, 2568 speed_template_24); 2569 test_acipher_speed("ofb(des3_ede)", ENCRYPT, sec, 2570 des3_speed_template, DES3_SPEED_VECTORS, 2571 speed_template_24); 2572 test_acipher_speed("ofb(des3_ede)", DECRYPT, sec, 2573 des3_speed_template, DES3_SPEED_VECTORS, 2574 speed_template_24); 2575 break; 2576 2577 case 502: 2578 test_acipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, 2579 speed_template_8); 2580 test_acipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, 2581 speed_template_8); 2582 test_acipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, 2583 speed_template_8); 2584 test_acipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, 2585 speed_template_8); 2586 test_acipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, 2587 speed_template_8); 2588 test_acipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, 2589 speed_template_8); 2590 test_acipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, 2591 speed_template_8); 2592 test_acipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, 2593 speed_template_8); 2594 break; 2595 2596 case 503: 2597 test_acipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, 2598 speed_template_16_32); 2599 test_acipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, 2600 speed_template_16_32); 2601 test_acipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, 2602 speed_template_16_32); 2603 test_acipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, 2604 speed_template_16_32); 2605 test_acipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, 2606 speed_template_16_32); 2607 test_acipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, 2608 speed_template_16_32); 2609 test_acipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, 2610 speed_template_32_48); 2611 test_acipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, 2612 speed_template_32_48); 2613 test_acipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, 2614 speed_template_32_64); 2615 test_acipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, 2616 speed_template_32_64); 2617 break; 2618 2619 case 504: 2620 test_acipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, 2621 speed_template_16_24_32); 2622 test_acipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, 2623 speed_template_16_24_32); 2624 test_acipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, 2625 speed_template_16_24_32); 2626 test_acipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, 2627 speed_template_16_24_32); 2628 test_acipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, 2629 speed_template_16_24_32); 2630 test_acipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, 2631 speed_template_16_24_32); 2632 test_acipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, 2633 speed_template_32_40_48); 2634 test_acipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, 2635 speed_template_32_40_48); 2636 test_acipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, 2637 speed_template_32_48_64); 2638 test_acipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, 2639 speed_template_32_48_64); 2640 break; 2641 2642 case 505: 2643 test_acipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, 2644 speed_template_8); 2645 break; 2646 2647 case 506: 2648 test_acipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, 2649 speed_template_8_16); 2650 test_acipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, 2651 speed_template_8_16); 2652 test_acipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, 2653 speed_template_8_16); 2654 test_acipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, 2655 speed_template_8_16); 2656 test_acipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, 2657 speed_template_8_16); 2658 test_acipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, 2659 speed_template_8_16); 2660 break; 2661 2662 case 507: 2663 test_acipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, 2664 speed_template_16_32); 2665 test_acipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, 2666 speed_template_16_32); 2667 test_acipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, 2668 speed_template_16_32); 2669 test_acipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, 2670 speed_template_16_32); 2671 test_acipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, 2672 speed_template_16_32); 2673 test_acipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, 2674 speed_template_16_32); 2675 test_acipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, 2676 speed_template_32_48); 2677 test_acipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, 2678 speed_template_32_48); 2679 test_acipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, 2680 speed_template_32_64); 2681 test_acipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, 2682 speed_template_32_64); 2683 break; 2684 2685 case 508: 2686 test_acipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, 2687 speed_template_16_32); 2688 test_acipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, 2689 speed_template_16_32); 2690 test_acipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, 2691 speed_template_16_32); 2692 test_acipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, 2693 speed_template_16_32); 2694 test_acipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, 2695 speed_template_16_32); 2696 test_acipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, 2697 speed_template_16_32); 2698 test_acipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, 2699 speed_template_32_48); 2700 test_acipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, 2701 speed_template_32_48); 2702 test_acipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, 2703 speed_template_32_64); 2704 test_acipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, 2705 speed_template_32_64); 2706 break; 2707 2708 case 509: 2709 test_acipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, 2710 speed_template_8_32); 2711 test_acipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, 2712 speed_template_8_32); 2713 test_acipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, 2714 speed_template_8_32); 2715 test_acipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, 2716 speed_template_8_32); 2717 test_acipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, 2718 speed_template_8_32); 2719 test_acipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, 2720 speed_template_8_32); 2721 break; 2722 2723 case 600: 2724 test_mb_skcipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0, 2725 speed_template_16_24_32, num_mb); 2726 test_mb_skcipher_speed("ecb(aes)", DECRYPT, sec, NULL, 0, 2727 speed_template_16_24_32, num_mb); 2728 test_mb_skcipher_speed("cbc(aes)", ENCRYPT, sec, NULL, 0, 2729 speed_template_16_24_32, num_mb); 2730 test_mb_skcipher_speed("cbc(aes)", DECRYPT, sec, NULL, 0, 2731 speed_template_16_24_32, num_mb); 2732 test_mb_skcipher_speed("lrw(aes)", ENCRYPT, sec, NULL, 0, 2733 speed_template_32_40_48, num_mb); 2734 test_mb_skcipher_speed("lrw(aes)", DECRYPT, sec, NULL, 0, 2735 speed_template_32_40_48, num_mb); 2736 test_mb_skcipher_speed("xts(aes)", ENCRYPT, sec, NULL, 0, 2737 speed_template_32_64, num_mb); 2738 test_mb_skcipher_speed("xts(aes)", DECRYPT, sec, NULL, 0, 2739 speed_template_32_64, num_mb); 2740 test_mb_skcipher_speed("cts(cbc(aes))", ENCRYPT, sec, NULL, 0, 2741 speed_template_16_24_32, num_mb); 2742 test_mb_skcipher_speed("cts(cbc(aes))", DECRYPT, sec, NULL, 0, 2743 speed_template_16_24_32, num_mb); 2744 test_mb_skcipher_speed("ctr(aes)", ENCRYPT, sec, NULL, 0, 2745 speed_template_16_24_32, num_mb); 2746 test_mb_skcipher_speed("ctr(aes)", DECRYPT, sec, NULL, 0, 2747 speed_template_16_24_32, num_mb); 2748 test_mb_skcipher_speed("cfb(aes)", ENCRYPT, sec, NULL, 0, 2749 speed_template_16_24_32, num_mb); 2750 test_mb_skcipher_speed("cfb(aes)", DECRYPT, sec, NULL, 0, 2751 speed_template_16_24_32, num_mb); 2752 test_mb_skcipher_speed("ofb(aes)", ENCRYPT, sec, NULL, 0, 2753 speed_template_16_24_32, num_mb); 2754 test_mb_skcipher_speed("ofb(aes)", DECRYPT, sec, NULL, 0, 2755 speed_template_16_24_32, num_mb); 2756 test_mb_skcipher_speed("rfc3686(ctr(aes))", ENCRYPT, sec, NULL, 2757 0, speed_template_20_28_36, num_mb); 2758 test_mb_skcipher_speed("rfc3686(ctr(aes))", DECRYPT, sec, NULL, 2759 0, speed_template_20_28_36, num_mb); 2760 break; 2761 2762 case 601: 2763 test_mb_skcipher_speed("ecb(des3_ede)", ENCRYPT, sec, 2764 des3_speed_template, DES3_SPEED_VECTORS, 2765 speed_template_24, num_mb); 2766 test_mb_skcipher_speed("ecb(des3_ede)", DECRYPT, sec, 2767 des3_speed_template, DES3_SPEED_VECTORS, 2768 speed_template_24, num_mb); 2769 test_mb_skcipher_speed("cbc(des3_ede)", ENCRYPT, sec, 2770 des3_speed_template, DES3_SPEED_VECTORS, 2771 speed_template_24, num_mb); 2772 test_mb_skcipher_speed("cbc(des3_ede)", DECRYPT, sec, 2773 des3_speed_template, DES3_SPEED_VECTORS, 2774 speed_template_24, num_mb); 2775 test_mb_skcipher_speed("cfb(des3_ede)", ENCRYPT, sec, 2776 des3_speed_template, DES3_SPEED_VECTORS, 2777 speed_template_24, num_mb); 2778 test_mb_skcipher_speed("cfb(des3_ede)", DECRYPT, sec, 2779 des3_speed_template, DES3_SPEED_VECTORS, 2780 speed_template_24, num_mb); 2781 test_mb_skcipher_speed("ofb(des3_ede)", ENCRYPT, sec, 2782 des3_speed_template, DES3_SPEED_VECTORS, 2783 speed_template_24, num_mb); 2784 test_mb_skcipher_speed("ofb(des3_ede)", DECRYPT, sec, 2785 des3_speed_template, DES3_SPEED_VECTORS, 2786 speed_template_24, num_mb); 2787 break; 2788 2789 case 602: 2790 test_mb_skcipher_speed("ecb(des)", ENCRYPT, sec, NULL, 0, 2791 speed_template_8, num_mb); 2792 test_mb_skcipher_speed("ecb(des)", DECRYPT, sec, NULL, 0, 2793 speed_template_8, num_mb); 2794 test_mb_skcipher_speed("cbc(des)", ENCRYPT, sec, NULL, 0, 2795 speed_template_8, num_mb); 2796 test_mb_skcipher_speed("cbc(des)", DECRYPT, sec, NULL, 0, 2797 speed_template_8, num_mb); 2798 test_mb_skcipher_speed("cfb(des)", ENCRYPT, sec, NULL, 0, 2799 speed_template_8, num_mb); 2800 test_mb_skcipher_speed("cfb(des)", DECRYPT, sec, NULL, 0, 2801 speed_template_8, num_mb); 2802 test_mb_skcipher_speed("ofb(des)", ENCRYPT, sec, NULL, 0, 2803 speed_template_8, num_mb); 2804 test_mb_skcipher_speed("ofb(des)", DECRYPT, sec, NULL, 0, 2805 speed_template_8, num_mb); 2806 break; 2807 2808 case 603: 2809 test_mb_skcipher_speed("ecb(serpent)", ENCRYPT, sec, NULL, 0, 2810 speed_template_16_32, num_mb); 2811 test_mb_skcipher_speed("ecb(serpent)", DECRYPT, sec, NULL, 0, 2812 speed_template_16_32, num_mb); 2813 test_mb_skcipher_speed("cbc(serpent)", ENCRYPT, sec, NULL, 0, 2814 speed_template_16_32, num_mb); 2815 test_mb_skcipher_speed("cbc(serpent)", DECRYPT, sec, NULL, 0, 2816 speed_template_16_32, num_mb); 2817 test_mb_skcipher_speed("ctr(serpent)", ENCRYPT, sec, NULL, 0, 2818 speed_template_16_32, num_mb); 2819 test_mb_skcipher_speed("ctr(serpent)", DECRYPT, sec, NULL, 0, 2820 speed_template_16_32, num_mb); 2821 test_mb_skcipher_speed("lrw(serpent)", ENCRYPT, sec, NULL, 0, 2822 speed_template_32_48, num_mb); 2823 test_mb_skcipher_speed("lrw(serpent)", DECRYPT, sec, NULL, 0, 2824 speed_template_32_48, num_mb); 2825 test_mb_skcipher_speed("xts(serpent)", ENCRYPT, sec, NULL, 0, 2826 speed_template_32_64, num_mb); 2827 test_mb_skcipher_speed("xts(serpent)", DECRYPT, sec, NULL, 0, 2828 speed_template_32_64, num_mb); 2829 break; 2830 2831 case 604: 2832 test_mb_skcipher_speed("ecb(twofish)", ENCRYPT, sec, NULL, 0, 2833 speed_template_16_24_32, num_mb); 2834 test_mb_skcipher_speed("ecb(twofish)", DECRYPT, sec, NULL, 0, 2835 speed_template_16_24_32, num_mb); 2836 test_mb_skcipher_speed("cbc(twofish)", ENCRYPT, sec, NULL, 0, 2837 speed_template_16_24_32, num_mb); 2838 test_mb_skcipher_speed("cbc(twofish)", DECRYPT, sec, NULL, 0, 2839 speed_template_16_24_32, num_mb); 2840 test_mb_skcipher_speed("ctr(twofish)", ENCRYPT, sec, NULL, 0, 2841 speed_template_16_24_32, num_mb); 2842 test_mb_skcipher_speed("ctr(twofish)", DECRYPT, sec, NULL, 0, 2843 speed_template_16_24_32, num_mb); 2844 test_mb_skcipher_speed("lrw(twofish)", ENCRYPT, sec, NULL, 0, 2845 speed_template_32_40_48, num_mb); 2846 test_mb_skcipher_speed("lrw(twofish)", DECRYPT, sec, NULL, 0, 2847 speed_template_32_40_48, num_mb); 2848 test_mb_skcipher_speed("xts(twofish)", ENCRYPT, sec, NULL, 0, 2849 speed_template_32_48_64, num_mb); 2850 test_mb_skcipher_speed("xts(twofish)", DECRYPT, sec, NULL, 0, 2851 speed_template_32_48_64, num_mb); 2852 break; 2853 2854 case 605: 2855 test_mb_skcipher_speed("ecb(arc4)", ENCRYPT, sec, NULL, 0, 2856 speed_template_8, num_mb); 2857 break; 2858 2859 case 606: 2860 test_mb_skcipher_speed("ecb(cast5)", ENCRYPT, sec, NULL, 0, 2861 speed_template_8_16, num_mb); 2862 test_mb_skcipher_speed("ecb(cast5)", DECRYPT, sec, NULL, 0, 2863 speed_template_8_16, num_mb); 2864 test_mb_skcipher_speed("cbc(cast5)", ENCRYPT, sec, NULL, 0, 2865 speed_template_8_16, num_mb); 2866 test_mb_skcipher_speed("cbc(cast5)", DECRYPT, sec, NULL, 0, 2867 speed_template_8_16, num_mb); 2868 test_mb_skcipher_speed("ctr(cast5)", ENCRYPT, sec, NULL, 0, 2869 speed_template_8_16, num_mb); 2870 test_mb_skcipher_speed("ctr(cast5)", DECRYPT, sec, NULL, 0, 2871 speed_template_8_16, num_mb); 2872 break; 2873 2874 case 607: 2875 test_mb_skcipher_speed("ecb(cast6)", ENCRYPT, sec, NULL, 0, 2876 speed_template_16_32, num_mb); 2877 test_mb_skcipher_speed("ecb(cast6)", DECRYPT, sec, NULL, 0, 2878 speed_template_16_32, num_mb); 2879 test_mb_skcipher_speed("cbc(cast6)", ENCRYPT, sec, NULL, 0, 2880 speed_template_16_32, num_mb); 2881 test_mb_skcipher_speed("cbc(cast6)", DECRYPT, sec, NULL, 0, 2882 speed_template_16_32, num_mb); 2883 test_mb_skcipher_speed("ctr(cast6)", ENCRYPT, sec, NULL, 0, 2884 speed_template_16_32, num_mb); 2885 test_mb_skcipher_speed("ctr(cast6)", DECRYPT, sec, NULL, 0, 2886 speed_template_16_32, num_mb); 2887 test_mb_skcipher_speed("lrw(cast6)", ENCRYPT, sec, NULL, 0, 2888 speed_template_32_48, num_mb); 2889 test_mb_skcipher_speed("lrw(cast6)", DECRYPT, sec, NULL, 0, 2890 speed_template_32_48, num_mb); 2891 test_mb_skcipher_speed("xts(cast6)", ENCRYPT, sec, NULL, 0, 2892 speed_template_32_64, num_mb); 2893 test_mb_skcipher_speed("xts(cast6)", DECRYPT, sec, NULL, 0, 2894 speed_template_32_64, num_mb); 2895 break; 2896 2897 case 608: 2898 test_mb_skcipher_speed("ecb(camellia)", ENCRYPT, sec, NULL, 0, 2899 speed_template_16_32, num_mb); 2900 test_mb_skcipher_speed("ecb(camellia)", DECRYPT, sec, NULL, 0, 2901 speed_template_16_32, num_mb); 2902 test_mb_skcipher_speed("cbc(camellia)", ENCRYPT, sec, NULL, 0, 2903 speed_template_16_32, num_mb); 2904 test_mb_skcipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0, 2905 speed_template_16_32, num_mb); 2906 test_mb_skcipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0, 2907 speed_template_16_32, num_mb); 2908 test_mb_skcipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0, 2909 speed_template_16_32, num_mb); 2910 test_mb_skcipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0, 2911 speed_template_32_48, num_mb); 2912 test_mb_skcipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0, 2913 speed_template_32_48, num_mb); 2914 test_mb_skcipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0, 2915 speed_template_32_64, num_mb); 2916 test_mb_skcipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0, 2917 speed_template_32_64, num_mb); 2918 break; 2919 2920 case 609: 2921 test_mb_skcipher_speed("ecb(blowfish)", ENCRYPT, sec, NULL, 0, 2922 speed_template_8_32, num_mb); 2923 test_mb_skcipher_speed("ecb(blowfish)", DECRYPT, sec, NULL, 0, 2924 speed_template_8_32, num_mb); 2925 test_mb_skcipher_speed("cbc(blowfish)", ENCRYPT, sec, NULL, 0, 2926 speed_template_8_32, num_mb); 2927 test_mb_skcipher_speed("cbc(blowfish)", DECRYPT, sec, NULL, 0, 2928 speed_template_8_32, num_mb); 2929 test_mb_skcipher_speed("ctr(blowfish)", ENCRYPT, sec, NULL, 0, 2930 speed_template_8_32, num_mb); 2931 test_mb_skcipher_speed("ctr(blowfish)", DECRYPT, sec, NULL, 0, 2932 speed_template_8_32, num_mb); 2933 break; 2934 2935 case 1000: 2936 test_available(); 2937 break; 2938 } 2939 2940 return ret; 2941 } 2942 2943 static int __init tcrypt_mod_init(void) 2944 { 2945 int err = -ENOMEM; 2946 int i; 2947 2948 for (i = 0; i < TVMEMSIZE; i++) { 2949 tvmem[i] = (void *)__get_free_page(GFP_KERNEL); 2950 if (!tvmem[i]) 2951 goto err_free_tv; 2952 } 2953 2954 err = do_test(alg, type, mask, mode, num_mb); 2955 2956 if (err) { 2957 printk(KERN_ERR "tcrypt: one or more tests failed!\n"); 2958 goto err_free_tv; 2959 } else { 2960 pr_debug("all tests passed\n"); 2961 } 2962 2963 /* We intentionaly return -EAGAIN to prevent keeping the module, 2964 * unless we're running in fips mode. It does all its work from 2965 * init() and doesn't offer any runtime functionality, but in 2966 * the fips case, checking for a successful load is helpful. 2967 * => we don't need it in the memory, do we? 2968 * -- mludvig 2969 */ 2970 if (!fips_enabled) 2971 err = -EAGAIN; 2972 2973 err_free_tv: 2974 for (i = 0; i < TVMEMSIZE && tvmem[i]; i++) 2975 free_page((unsigned long)tvmem[i]); 2976 2977 return err; 2978 } 2979 2980 /* 2981 * If an init function is provided, an exit function must also be provided 2982 * to allow module unload. 2983 */ 2984 static void __exit tcrypt_mod_fini(void) { } 2985 2986 module_init(tcrypt_mod_init); 2987 module_exit(tcrypt_mod_fini); 2988 2989 module_param(alg, charp, 0); 2990 module_param(type, uint, 0); 2991 module_param(mask, uint, 0); 2992 module_param(mode, int, 0); 2993 module_param(sec, uint, 0); 2994 MODULE_PARM_DESC(sec, "Length in seconds of speed tests " 2995 "(defaults to zero which uses CPU cycles instead)"); 2996 module_param(num_mb, uint, 0000); 2997 MODULE_PARM_DESC(num_mb, "Number of concurrent requests to be used in mb speed tests (defaults to 8)"); 2998 2999 MODULE_LICENSE("GPL"); 3000 MODULE_DESCRIPTION("Quick & dirty crypto testing module"); 3001 MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>"); 3002