1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */ 2 /* Copyright (C) 1995-1998 Eric Young (eay (at) cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay (at) cryptsoft.com). 7 * The implementation was written so as to conform with Netscapes SSL. 8 * 9 * This library is free for commercial and non-commercial use as long as 10 * the following conditions are aheared to. The following conditions 11 * apply to all code found in this distribution, be it the RC4, RSA, 12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13 * included with this distribution is covered by the same copyright terms 14 * except that the holder is Tim Hudson (tjh (at) cryptsoft.com). 15 * 16 * Copyright remains Eric Young's, and as such any Copyright notices in 17 * the code are not to be removed. 18 * If this package is used in a product, Eric Young should be given attribution 19 * as the author of the parts of the library used. 20 * This can be in the form of a textual message at program startup or 21 * in documentation (online or textual) provided with the package. 22 * 23 * Redistribution and use in source and binary forms, with or without 24 * modification, are permitted provided that the following conditions 25 * are met: 26 * 1. Redistributions of source code must retain the copyright 27 * notice, this list of conditions and the following disclaimer. 28 * 2. Redistributions in binary form must reproduce the above copyright 29 * notice, this list of conditions and the following disclaimer in the 30 * documentation and/or other materials provided with the distribution. 31 * 3. All advertising materials mentioning features or use of this software 32 * must display the following acknowledgement: 33 * "This product includes cryptographic software written by 34 * Eric Young (eay (at) cryptsoft.com)" 35 * The word 'cryptographic' can be left out if the rouines from the library 36 * being used are not cryptographic related :-). 37 * 4. If you include any Windows specific code (or a derivative thereof) from 38 * the apps directory (application code) you must include an acknowledgement: 39 * "This product includes software written by Tim Hudson (tjh (at) cryptsoft.com)" 40 * 41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * 53 * The licence and distribution terms for any publically available version or 54 * derivative of this code cannot be changed. i.e. this code cannot simply be 55 * copied and put under another distribution licence 56 * [including the GNU Public Licence.] 57 */ 58 /* ==================================================================== 59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 60 * 61 * Portions of the attached software ("Contribution") are developed by 62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. 63 * 64 * The Contribution is licensed pursuant to the OpenSSL open source 65 * license provided above. 66 * 67 * The ECDH and ECDSA speed test software is originally written by 68 * Sumit Gupta of Sun Microsystems Laboratories. 69 * 70 */ 71 72 /* most of this code has been pilfered from my libdes speed.c program */ 73 74 #ifndef OPENSSL_NO_SPEED 75 76 #undef SECONDS 77 #define SECONDS 3 78 #define RSA_SECONDS 10 79 #define DSA_SECONDS 10 80 #define ECDSA_SECONDS 10 81 #define ECDH_SECONDS 10 82 83 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 84 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 85 86 #undef PROG 87 #define PROG speed_main 88 89 #include <stdio.h> 90 #include <stdlib.h> 91 92 #include <string.h> 93 #include <math.h> 94 #include "apps.h" 95 #ifdef OPENSSL_NO_STDIO 96 #define APPS_WIN16 97 #endif 98 #include <openssl/crypto.h> 99 #include <openssl/rand.h> 100 #include <openssl/err.h> 101 #include <openssl/evp.h> 102 #include <openssl/objects.h> 103 #if !defined(OPENSSL_SYS_MSDOS) 104 #include OPENSSL_UNISTD 105 #endif 106 107 #ifndef OPENSSL_SYS_NETWARE 108 #include <signal.h> 109 #endif 110 111 #ifdef _WIN32 112 #include <windows.h> 113 #endif 114 115 #include <openssl/bn.h> 116 #ifndef OPENSSL_NO_DES 117 #include <openssl/des.h> 118 #endif 119 #ifndef OPENSSL_NO_AES 120 #include <openssl/aes.h> 121 #endif 122 #ifndef OPENSSL_NO_CAMELLIA 123 #include <openssl/camellia.h> 124 #endif 125 #ifndef OPENSSL_NO_MD2 126 #include <openssl/md2.h> 127 #endif 128 #ifndef OPENSSL_NO_MDC2 129 #include <openssl/mdc2.h> 130 #endif 131 #ifndef OPENSSL_NO_MD4 132 #include <openssl/md4.h> 133 #endif 134 #ifndef OPENSSL_NO_MD5 135 #include <openssl/md5.h> 136 #endif 137 #ifndef OPENSSL_NO_HMAC 138 #include <openssl/hmac.h> 139 #endif 140 #include <openssl/evp.h> 141 #ifndef OPENSSL_NO_SHA 142 #include <openssl/sha.h> 143 #endif 144 #ifndef OPENSSL_NO_RIPEMD 145 #include <openssl/ripemd.h> 146 #endif 147 #ifndef OPENSSL_NO_WHIRLPOOL 148 #include <openssl/whrlpool.h> 149 #endif 150 #ifndef OPENSSL_NO_RC4 151 #include <openssl/rc4.h> 152 #endif 153 #ifndef OPENSSL_NO_RC5 154 #include <openssl/rc5.h> 155 #endif 156 #ifndef OPENSSL_NO_RC2 157 #include <openssl/rc2.h> 158 #endif 159 #ifndef OPENSSL_NO_IDEA 160 #include <openssl/idea.h> 161 #endif 162 #ifndef OPENSSL_NO_SEED 163 #include <openssl/seed.h> 164 #endif 165 #ifndef OPENSSL_NO_BF 166 #include <openssl/blowfish.h> 167 #endif 168 #ifndef OPENSSL_NO_CAST 169 #include <openssl/cast.h> 170 #endif 171 #ifndef OPENSSL_NO_RSA 172 #include <openssl/rsa.h> 173 #include "./testrsa.h" 174 #endif 175 #include <openssl/x509.h> 176 #ifndef OPENSSL_NO_DSA 177 #include <openssl/dsa.h> 178 #include "./testdsa.h" 179 #endif 180 #ifndef OPENSSL_NO_ECDSA 181 #include <openssl/ecdsa.h> 182 #endif 183 #ifndef OPENSSL_NO_ECDH 184 #include <openssl/ecdh.h> 185 #endif 186 187 #ifndef HAVE_FORK 188 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE) 189 # define HAVE_FORK 0 190 # else 191 # define HAVE_FORK 1 192 # endif 193 #endif 194 195 #if HAVE_FORK 196 #undef NO_FORK 197 #else 198 #define NO_FORK 199 #endif 200 201 #undef BUFSIZE 202 #define BUFSIZE ((long)1024*8+1) 203 int run=0; 204 205 static int mr=0; 206 static int usertime=1; 207 208 static double Time_F(int s); 209 static void print_message(const char *s,long num,int length); 210 static void pkey_print_message(const char *str, const char *str2, 211 long num, int bits, int sec); 212 static void print_result(int alg,int run_no,int count,double time_used); 213 #ifndef NO_FORK 214 static int do_multi(int multi); 215 #endif 216 217 #define ALGOR_NUM 29 218 #define SIZE_NUM 5 219 #define RSA_NUM 4 220 #define DSA_NUM 3 221 222 #define EC_NUM 16 223 #define MAX_ECDH_SIZE 256 224 225 static const char *names[ALGOR_NUM]={ 226 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4", 227 "des cbc","des ede3","idea cbc","seed cbc", 228 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc", 229 "aes-128 cbc","aes-192 cbc","aes-256 cbc", 230 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc", 231 "evp","sha256","sha512","whirlpool", 232 "aes-128 ige","aes-192 ige","aes-256 ige"}; 233 static double results[ALGOR_NUM][SIZE_NUM]; 234 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024}; 235 #ifndef OPENSSL_NO_RSA 236 static double rsa_results[RSA_NUM][2]; 237 #endif 238 #ifndef OPENSSL_NO_DSA 239 static double dsa_results[DSA_NUM][2]; 240 #endif 241 #ifndef OPENSSL_NO_ECDSA 242 static double ecdsa_results[EC_NUM][2]; 243 #endif 244 #ifndef OPENSSL_NO_ECDH 245 static double ecdh_results[EC_NUM][1]; 246 #endif 247 248 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH)) 249 static const char rnd_seed[] = "string to make the random number generator think it has entropy"; 250 static int rnd_fake = 0; 251 #endif 252 253 #ifdef SIGALRM 254 #if defined(__STDC__) || defined(sgi) || defined(_AIX) 255 #define SIGRETTYPE void 256 #else 257 #define SIGRETTYPE int 258 #endif 259 260 static SIGRETTYPE sig_done(int sig); 261 static SIGRETTYPE sig_done(int sig) 262 { 263 signal(SIGALRM,sig_done); 264 run=0; 265 #ifdef LINT 266 sig=sig; 267 #endif 268 } 269 #endif 270 271 #define START 0 272 #define STOP 1 273 274 #if defined(_WIN32) 275 276 #define SIGALRM 277 static unsigned int lapse,schlock; 278 static void alarm(unsigned int secs) { lapse = secs*1000; } 279 280 static DWORD WINAPI sleepy(VOID *arg) 281 { 282 schlock = 1; 283 Sleep(lapse); 284 run = 0; 285 return 0; 286 } 287 288 static double Time_F(int s) 289 { 290 if (s == START) 291 { 292 HANDLE thr; 293 schlock = 0; 294 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL); 295 if (thr==NULL) 296 { 297 DWORD ret=GetLastError(); 298 BIO_printf(bio_err,"unable to CreateThread (%d)",ret); 299 ExitProcess(ret); 300 } 301 CloseHandle(thr); /* detach the thread */ 302 while (!schlock) Sleep(0); /* scheduler spinlock */ 303 } 304 305 return app_tminterval(s,usertime); 306 } 307 #else 308 309 static double Time_F(int s) 310 { 311 return app_tminterval(s,usertime); 312 } 313 #endif 314 315 316 #ifndef OPENSSL_NO_ECDH 317 static const int KDF1_SHA1_len = 20; 318 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) 319 { 320 #ifndef OPENSSL_NO_SHA 321 if (*outlen < SHA_DIGEST_LENGTH) 322 return NULL; 323 else 324 *outlen = SHA_DIGEST_LENGTH; 325 return SHA1(in, inlen, out); 326 #else 327 return NULL; 328 #endif /* OPENSSL_NO_SHA */ 329 } 330 #endif /* OPENSSL_NO_ECDH */ 331 332 333 int MAIN(int, char **); 334 335 int MAIN(int argc, char **argv) 336 { 337 #ifndef OPENSSL_NO_ENGINE 338 ENGINE *e = NULL; 339 #endif 340 unsigned char *buf=NULL,*buf2=NULL; 341 int mret=1; 342 long count=0,save_count=0; 343 int i,j,k; 344 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) 345 long rsa_count; 346 #endif 347 #ifndef OPENSSL_NO_RSA 348 unsigned rsa_num; 349 #endif 350 unsigned char md[EVP_MAX_MD_SIZE]; 351 #ifndef OPENSSL_NO_MD2 352 unsigned char md2[MD2_DIGEST_LENGTH]; 353 #endif 354 #ifndef OPENSSL_NO_MDC2 355 unsigned char mdc2[MDC2_DIGEST_LENGTH]; 356 #endif 357 #ifndef OPENSSL_NO_MD4 358 unsigned char md4[MD4_DIGEST_LENGTH]; 359 #endif 360 #ifndef OPENSSL_NO_MD5 361 unsigned char md5[MD5_DIGEST_LENGTH]; 362 unsigned char hmac[MD5_DIGEST_LENGTH]; 363 #endif 364 #ifndef OPENSSL_NO_SHA 365 unsigned char sha[SHA_DIGEST_LENGTH]; 366 #ifndef OPENSSL_NO_SHA256 367 unsigned char sha256[SHA256_DIGEST_LENGTH]; 368 #endif 369 #ifndef OPENSSL_NO_SHA512 370 unsigned char sha512[SHA512_DIGEST_LENGTH]; 371 #endif 372 #endif 373 #ifndef OPENSSL_NO_WHIRLPOOL 374 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH]; 375 #endif 376 #ifndef OPENSSL_NO_RIPEMD 377 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; 378 #endif 379 #ifndef OPENSSL_NO_RC4 380 RC4_KEY rc4_ks; 381 #endif 382 #ifndef OPENSSL_NO_RC5 383 RC5_32_KEY rc5_ks; 384 #endif 385 #ifndef OPENSSL_NO_RC2 386 RC2_KEY rc2_ks; 387 #endif 388 #ifndef OPENSSL_NO_IDEA 389 IDEA_KEY_SCHEDULE idea_ks; 390 #endif 391 #ifndef OPENSSL_NO_SEED 392 SEED_KEY_SCHEDULE seed_ks; 393 #endif 394 #ifndef OPENSSL_NO_BF 395 BF_KEY bf_ks; 396 #endif 397 #ifndef OPENSSL_NO_CAST 398 CAST_KEY cast_ks; 399 #endif 400 static const unsigned char key16[16]= 401 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 402 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; 403 #ifndef OPENSSL_NO_AES 404 static const unsigned char key24[24]= 405 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 406 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, 407 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; 408 static const unsigned char key32[32]= 409 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 410 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, 411 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34, 412 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56}; 413 #endif 414 #ifndef OPENSSL_NO_CAMELLIA 415 static const unsigned char ckey24[24]= 416 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 417 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, 418 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; 419 static const unsigned char ckey32[32]= 420 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 421 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, 422 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34, 423 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56}; 424 #endif 425 #ifndef OPENSSL_NO_AES 426 #define MAX_BLOCK_SIZE 128 427 #else 428 #define MAX_BLOCK_SIZE 64 429 #endif 430 unsigned char DES_iv[8]; 431 unsigned char iv[2*MAX_BLOCK_SIZE/8]; 432 #ifndef OPENSSL_NO_DES 433 DES_cblock *buf_as_des_cblock = NULL; 434 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; 435 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; 436 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; 437 DES_key_schedule sch; 438 DES_key_schedule sch2; 439 DES_key_schedule sch3; 440 #endif 441 #ifndef OPENSSL_NO_AES 442 AES_KEY aes_ks1, aes_ks2, aes_ks3; 443 #endif 444 #ifndef OPENSSL_NO_CAMELLIA 445 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3; 446 #endif 447 #define D_MD2 0 448 #define D_MDC2 1 449 #define D_MD4 2 450 #define D_MD5 3 451 #define D_HMAC 4 452 #define D_SHA1 5 453 #define D_RMD160 6 454 #define D_RC4 7 455 #define D_CBC_DES 8 456 #define D_EDE3_DES 9 457 #define D_CBC_IDEA 10 458 #define D_CBC_SEED 11 459 #define D_CBC_RC2 12 460 #define D_CBC_RC5 13 461 #define D_CBC_BF 14 462 #define D_CBC_CAST 15 463 #define D_CBC_128_AES 16 464 #define D_CBC_192_AES 17 465 #define D_CBC_256_AES 18 466 #define D_CBC_128_CML 19 467 #define D_CBC_192_CML 20 468 #define D_CBC_256_CML 21 469 #define D_EVP 22 470 #define D_SHA256 23 471 #define D_SHA512 24 472 #define D_WHIRLPOOL 25 473 #define D_IGE_128_AES 26 474 #define D_IGE_192_AES 27 475 #define D_IGE_256_AES 28 476 double d=0.0; 477 long c[ALGOR_NUM][SIZE_NUM]; 478 #define R_DSA_512 0 479 #define R_DSA_1024 1 480 #define R_DSA_2048 2 481 #define R_RSA_512 0 482 #define R_RSA_1024 1 483 #define R_RSA_2048 2 484 #define R_RSA_4096 3 485 486 #define R_EC_P160 0 487 #define R_EC_P192 1 488 #define R_EC_P224 2 489 #define R_EC_P256 3 490 #define R_EC_P384 4 491 #define R_EC_P521 5 492 #define R_EC_K163 6 493 #define R_EC_K233 7 494 #define R_EC_K283 8 495 #define R_EC_K409 9 496 #define R_EC_K571 10 497 #define R_EC_B163 11 498 #define R_EC_B233 12 499 #define R_EC_B283 13 500 #define R_EC_B409 14 501 #define R_EC_B571 15 502 503 #ifndef OPENSSL_NO_RSA 504 RSA *rsa_key[RSA_NUM]; 505 long rsa_c[RSA_NUM][2]; 506 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096}; 507 static unsigned char *rsa_data[RSA_NUM]= 508 {test512,test1024,test2048,test4096}; 509 static int rsa_data_length[RSA_NUM]={ 510 sizeof(test512),sizeof(test1024), 511 sizeof(test2048),sizeof(test4096)}; 512 #endif 513 #ifndef OPENSSL_NO_DSA 514 DSA *dsa_key[DSA_NUM]; 515 long dsa_c[DSA_NUM][2]; 516 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048}; 517 #endif 518 #ifndef OPENSSL_NO_EC 519 /* We only test over the following curves as they are representative, 520 * To add tests over more curves, simply add the curve NID 521 * and curve name to the following arrays and increase the 522 * EC_NUM value accordingly. 523 */ 524 static unsigned int test_curves[EC_NUM] = 525 { 526 /* Prime Curves */ 527 NID_secp160r1, 528 NID_X9_62_prime192v1, 529 NID_secp224r1, 530 NID_X9_62_prime256v1, 531 NID_secp384r1, 532 NID_secp521r1, 533 /* Binary Curves */ 534 NID_sect163k1, 535 NID_sect233k1, 536 NID_sect283k1, 537 NID_sect409k1, 538 NID_sect571k1, 539 NID_sect163r2, 540 NID_sect233r1, 541 NID_sect283r1, 542 NID_sect409r1, 543 NID_sect571r1 544 }; 545 static const char * test_curves_names[EC_NUM] = 546 { 547 /* Prime Curves */ 548 "secp160r1", 549 "nistp192", 550 "nistp224", 551 "nistp256", 552 "nistp384", 553 "nistp521", 554 /* Binary Curves */ 555 "nistk163", 556 "nistk233", 557 "nistk283", 558 "nistk409", 559 "nistk571", 560 "nistb163", 561 "nistb233", 562 "nistb283", 563 "nistb409", 564 "nistb571" 565 }; 566 static int test_curves_bits[EC_NUM] = 567 { 568 160, 192, 224, 256, 384, 521, 569 163, 233, 283, 409, 571, 570 163, 233, 283, 409, 571 571 }; 572 573 #endif 574 575 #ifndef OPENSSL_NO_ECDSA 576 unsigned char ecdsasig[256]; 577 unsigned int ecdsasiglen; 578 EC_KEY *ecdsa[EC_NUM]; 579 long ecdsa_c[EC_NUM][2]; 580 #endif 581 582 #ifndef OPENSSL_NO_ECDH 583 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM]; 584 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE]; 585 int secret_size_a, secret_size_b; 586 int ecdh_checks = 0; 587 int secret_idx = 0; 588 long ecdh_c[EC_NUM][2]; 589 #endif 590 591 int rsa_doit[RSA_NUM]; 592 int dsa_doit[DSA_NUM]; 593 #ifndef OPENSSL_NO_ECDSA 594 int ecdsa_doit[EC_NUM]; 595 #endif 596 #ifndef OPENSSL_NO_ECDH 597 int ecdh_doit[EC_NUM]; 598 #endif 599 int doit[ALGOR_NUM]; 600 int pr_header=0; 601 const EVP_CIPHER *evp_cipher=NULL; 602 const EVP_MD *evp_md=NULL; 603 int decrypt=0; 604 #ifndef NO_FORK 605 int multi=0; 606 #endif 607 608 #ifndef TIMES 609 usertime=-1; 610 #endif 611 612 apps_startup(); 613 memset(results, 0, sizeof(results)); 614 #ifndef OPENSSL_NO_DSA 615 memset(dsa_key,0,sizeof(dsa_key)); 616 #endif 617 #ifndef OPENSSL_NO_ECDSA 618 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL; 619 #endif 620 #ifndef OPENSSL_NO_ECDH 621 for (i=0; i<EC_NUM; i++) 622 { 623 ecdh_a[i] = NULL; 624 ecdh_b[i] = NULL; 625 } 626 #endif 627 628 629 if (bio_err == NULL) 630 if ((bio_err=BIO_new(BIO_s_file())) != NULL) 631 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); 632 633 if (!load_config(bio_err, NULL)) 634 goto end; 635 636 #ifndef OPENSSL_NO_RSA 637 memset(rsa_key,0,sizeof(rsa_key)); 638 for (i=0; i<RSA_NUM; i++) 639 rsa_key[i]=NULL; 640 #endif 641 642 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) 643 { 644 BIO_printf(bio_err,"out of memory\n"); 645 goto end; 646 } 647 #ifndef OPENSSL_NO_DES 648 buf_as_des_cblock = (DES_cblock *)buf; 649 #endif 650 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) 651 { 652 BIO_printf(bio_err,"out of memory\n"); 653 goto end; 654 } 655 656 memset(c,0,sizeof(c)); 657 memset(DES_iv,0,sizeof(DES_iv)); 658 memset(iv,0,sizeof(iv)); 659 660 for (i=0; i<ALGOR_NUM; i++) 661 doit[i]=0; 662 for (i=0; i<RSA_NUM; i++) 663 rsa_doit[i]=0; 664 for (i=0; i<DSA_NUM; i++) 665 dsa_doit[i]=0; 666 #ifndef OPENSSL_NO_ECDSA 667 for (i=0; i<EC_NUM; i++) 668 ecdsa_doit[i]=0; 669 #endif 670 #ifndef OPENSSL_NO_ECDH 671 for (i=0; i<EC_NUM; i++) 672 ecdh_doit[i]=0; 673 #endif 674 675 676 j=0; 677 argc--; 678 argv++; 679 while (argc) 680 { 681 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0)) 682 { 683 usertime = 0; 684 j--; /* Otherwise, -elapsed gets confused with 685 an algorithm. */ 686 } 687 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0)) 688 { 689 argc--; 690 argv++; 691 if(argc == 0) 692 { 693 BIO_printf(bio_err,"no EVP given\n"); 694 goto end; 695 } 696 evp_cipher=EVP_get_cipherbyname(*argv); 697 if(!evp_cipher) 698 { 699 evp_md=EVP_get_digestbyname(*argv); 700 } 701 if(!evp_cipher && !evp_md) 702 { 703 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv); 704 goto end; 705 } 706 doit[D_EVP]=1; 707 } 708 else if (argc > 0 && !strcmp(*argv,"-decrypt")) 709 { 710 decrypt=1; 711 j--; /* Otherwise, -elapsed gets confused with 712 an algorithm. */ 713 } 714 #ifndef OPENSSL_NO_ENGINE 715 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0)) 716 { 717 argc--; 718 argv++; 719 if(argc == 0) 720 { 721 BIO_printf(bio_err,"no engine given\n"); 722 goto end; 723 } 724 e = setup_engine(bio_err, *argv, 0); 725 /* j will be increased again further down. We just 726 don't want speed to confuse an engine with an 727 algorithm, especially when none is given (which 728 means all of them should be run) */ 729 j--; 730 } 731 #endif 732 #ifndef NO_FORK 733 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0)) 734 { 735 argc--; 736 argv++; 737 if(argc == 0) 738 { 739 BIO_printf(bio_err,"no multi count given\n"); 740 goto end; 741 } 742 multi=atoi(argv[0]); 743 if(multi <= 0) 744 { 745 BIO_printf(bio_err,"bad multi count\n"); 746 goto end; 747 } 748 j--; /* Otherwise, -mr gets confused with 749 an algorithm. */ 750 } 751 #endif 752 else if (argc > 0 && !strcmp(*argv,"-mr")) 753 { 754 mr=1; 755 j--; /* Otherwise, -mr gets confused with 756 an algorithm. */ 757 } 758 else 759 #ifndef OPENSSL_NO_MD2 760 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1; 761 else 762 #endif 763 #ifndef OPENSSL_NO_MDC2 764 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1; 765 else 766 #endif 767 #ifndef OPENSSL_NO_MD4 768 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1; 769 else 770 #endif 771 #ifndef OPENSSL_NO_MD5 772 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1; 773 else 774 #endif 775 #ifndef OPENSSL_NO_MD5 776 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1; 777 else 778 #endif 779 #ifndef OPENSSL_NO_SHA 780 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1; 781 else 782 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1, 783 doit[D_SHA256]=1, 784 doit[D_SHA512]=1; 785 else 786 #ifndef OPENSSL_NO_SHA256 787 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1; 788 else 789 #endif 790 #ifndef OPENSSL_NO_SHA512 791 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1; 792 else 793 #endif 794 #endif 795 #ifndef OPENSSL_NO_WHIRLPOOL 796 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1; 797 else 798 #endif 799 #ifndef OPENSSL_NO_RIPEMD 800 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1; 801 else 802 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1; 803 else 804 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1; 805 else 806 #endif 807 #ifndef OPENSSL_NO_RC4 808 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1; 809 else 810 #endif 811 #ifndef OPENSSL_NO_DES 812 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1; 813 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1; 814 else 815 #endif 816 #ifndef OPENSSL_NO_AES 817 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1; 818 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1; 819 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1; 820 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1; 821 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1; 822 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1; 823 else 824 #endif 825 #ifndef OPENSSL_NO_CAMELLIA 826 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1; 827 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1; 828 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1; 829 else 830 #endif 831 #ifndef OPENSSL_NO_RSA 832 #if 0 /* was: #ifdef RSAref */ 833 if (strcmp(*argv,"rsaref") == 0) 834 { 835 RSA_set_default_openssl_method(RSA_PKCS1_RSAref()); 836 j--; 837 } 838 else 839 #endif 840 #ifndef RSA_NULL 841 if (strcmp(*argv,"openssl") == 0) 842 { 843 RSA_set_default_method(RSA_PKCS1_SSLeay()); 844 j--; 845 } 846 else 847 #endif 848 #endif /* !OPENSSL_NO_RSA */ 849 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2; 850 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2; 851 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2; 852 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2; 853 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2; 854 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2; 855 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2; 856 else 857 #ifndef OPENSSL_NO_RC2 858 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1; 859 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1; 860 else 861 #endif 862 #ifndef OPENSSL_NO_RC5 863 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1; 864 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1; 865 else 866 #endif 867 #ifndef OPENSSL_NO_IDEA 868 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1; 869 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1; 870 else 871 #endif 872 #ifndef OPENSSL_NO_SEED 873 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1; 874 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1; 875 else 876 #endif 877 #ifndef OPENSSL_NO_BF 878 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1; 879 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1; 880 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1; 881 else 882 #endif 883 #ifndef OPENSSL_NO_CAST 884 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1; 885 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1; 886 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1; 887 else 888 #endif 889 #ifndef OPENSSL_NO_DES 890 if (strcmp(*argv,"des") == 0) 891 { 892 doit[D_CBC_DES]=1; 893 doit[D_EDE3_DES]=1; 894 } 895 else 896 #endif 897 #ifndef OPENSSL_NO_AES 898 if (strcmp(*argv,"aes") == 0) 899 { 900 doit[D_CBC_128_AES]=1; 901 doit[D_CBC_192_AES]=1; 902 doit[D_CBC_256_AES]=1; 903 } 904 else 905 #endif 906 #ifndef OPENSSL_NO_CAMELLIA 907 if (strcmp(*argv,"camellia") == 0) 908 { 909 doit[D_CBC_128_CML]=1; 910 doit[D_CBC_192_CML]=1; 911 doit[D_CBC_256_CML]=1; 912 } 913 else 914 #endif 915 #ifndef OPENSSL_NO_RSA 916 if (strcmp(*argv,"rsa") == 0) 917 { 918 rsa_doit[R_RSA_512]=1; 919 rsa_doit[R_RSA_1024]=1; 920 rsa_doit[R_RSA_2048]=1; 921 rsa_doit[R_RSA_4096]=1; 922 } 923 else 924 #endif 925 #ifndef OPENSSL_NO_DSA 926 if (strcmp(*argv,"dsa") == 0) 927 { 928 dsa_doit[R_DSA_512]=1; 929 dsa_doit[R_DSA_1024]=1; 930 dsa_doit[R_DSA_2048]=1; 931 } 932 else 933 #endif 934 #ifndef OPENSSL_NO_ECDSA 935 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2; 936 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2; 937 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2; 938 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2; 939 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2; 940 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2; 941 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2; 942 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2; 943 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2; 944 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2; 945 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2; 946 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2; 947 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2; 948 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2; 949 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2; 950 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2; 951 else if (strcmp(*argv,"ecdsa") == 0) 952 { 953 for (i=0; i < EC_NUM; i++) 954 ecdsa_doit[i]=1; 955 } 956 else 957 #endif 958 #ifndef OPENSSL_NO_ECDH 959 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2; 960 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2; 961 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2; 962 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2; 963 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2; 964 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2; 965 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2; 966 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2; 967 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2; 968 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2; 969 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2; 970 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2; 971 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2; 972 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2; 973 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2; 974 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2; 975 else if (strcmp(*argv,"ecdh") == 0) 976 { 977 for (i=0; i < EC_NUM; i++) 978 ecdh_doit[i]=1; 979 } 980 else 981 #endif 982 { 983 BIO_printf(bio_err,"Error: bad option or value\n"); 984 BIO_printf(bio_err,"\n"); 985 BIO_printf(bio_err,"Available values:\n"); 986 #ifndef OPENSSL_NO_MD2 987 BIO_printf(bio_err,"md2 "); 988 #endif 989 #ifndef OPENSSL_NO_MDC2 990 BIO_printf(bio_err,"mdc2 "); 991 #endif 992 #ifndef OPENSSL_NO_MD4 993 BIO_printf(bio_err,"md4 "); 994 #endif 995 #ifndef OPENSSL_NO_MD5 996 BIO_printf(bio_err,"md5 "); 997 #ifndef OPENSSL_NO_HMAC 998 BIO_printf(bio_err,"hmac "); 999 #endif 1000 #endif 1001 #ifndef OPENSSL_NO_SHA1 1002 BIO_printf(bio_err,"sha1 "); 1003 #endif 1004 #ifndef OPENSSL_NO_SHA256 1005 BIO_printf(bio_err,"sha256 "); 1006 #endif 1007 #ifndef OPENSSL_NO_SHA512 1008 BIO_printf(bio_err,"sha512 "); 1009 #endif 1010 #ifndef OPENSSL_NO_WHIRLPOOL 1011 BIO_printf(bio_err,"whirlpool"); 1012 #endif 1013 #ifndef OPENSSL_NO_RIPEMD160 1014 BIO_printf(bio_err,"rmd160"); 1015 #endif 1016 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \ 1017 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \ 1018 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \ 1019 !defined(OPENSSL_NO_WHIRLPOOL) 1020 BIO_printf(bio_err,"\n"); 1021 #endif 1022 1023 #ifndef OPENSSL_NO_IDEA 1024 BIO_printf(bio_err,"idea-cbc "); 1025 #endif 1026 #ifndef OPENSSL_NO_SEED 1027 BIO_printf(bio_err,"seed-cbc "); 1028 #endif 1029 #ifndef OPENSSL_NO_RC2 1030 BIO_printf(bio_err,"rc2-cbc "); 1031 #endif 1032 #ifndef OPENSSL_NO_RC5 1033 BIO_printf(bio_err,"rc5-cbc "); 1034 #endif 1035 #ifndef OPENSSL_NO_BF 1036 BIO_printf(bio_err,"bf-cbc"); 1037 #endif 1038 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \ 1039 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5) 1040 BIO_printf(bio_err,"\n"); 1041 #endif 1042 #ifndef OPENSSL_NO_DES 1043 BIO_printf(bio_err,"des-cbc des-ede3 "); 1044 #endif 1045 #ifndef OPENSSL_NO_AES 1046 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc "); 1047 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige "); 1048 #endif 1049 #ifndef OPENSSL_NO_CAMELLIA 1050 BIO_printf(bio_err,"\n"); 1051 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc "); 1052 #endif 1053 #ifndef OPENSSL_NO_RC4 1054 BIO_printf(bio_err,"rc4"); 1055 #endif 1056 BIO_printf(bio_err,"\n"); 1057 1058 #ifndef OPENSSL_NO_RSA 1059 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n"); 1060 #endif 1061 1062 #ifndef OPENSSL_NO_DSA 1063 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n"); 1064 #endif 1065 #ifndef OPENSSL_NO_ECDSA 1066 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n"); 1067 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n"); 1068 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n"); 1069 BIO_printf(bio_err,"ecdsa\n"); 1070 #endif 1071 #ifndef OPENSSL_NO_ECDH 1072 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n"); 1073 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n"); 1074 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n"); 1075 BIO_printf(bio_err,"ecdh\n"); 1076 #endif 1077 1078 #ifndef OPENSSL_NO_IDEA 1079 BIO_printf(bio_err,"idea "); 1080 #endif 1081 #ifndef OPENSSL_NO_SEED 1082 BIO_printf(bio_err,"seed "); 1083 #endif 1084 #ifndef OPENSSL_NO_RC2 1085 BIO_printf(bio_err,"rc2 "); 1086 #endif 1087 #ifndef OPENSSL_NO_DES 1088 BIO_printf(bio_err,"des "); 1089 #endif 1090 #ifndef OPENSSL_NO_AES 1091 BIO_printf(bio_err,"aes "); 1092 #endif 1093 #ifndef OPENSSL_NO_CAMELLIA 1094 BIO_printf(bio_err,"camellia "); 1095 #endif 1096 #ifndef OPENSSL_NO_RSA 1097 BIO_printf(bio_err,"rsa "); 1098 #endif 1099 #ifndef OPENSSL_NO_BF 1100 BIO_printf(bio_err,"blowfish"); 1101 #endif 1102 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \ 1103 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \ 1104 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \ 1105 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA) 1106 BIO_printf(bio_err,"\n"); 1107 #endif 1108 1109 BIO_printf(bio_err,"\n"); 1110 BIO_printf(bio_err,"Available options:\n"); 1111 #if defined(TIMES) || defined(USE_TOD) 1112 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n"); 1113 #endif 1114 #ifndef OPENSSL_NO_ENGINE 1115 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n"); 1116 #endif 1117 BIO_printf(bio_err,"-evp e use EVP e.\n"); 1118 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n"); 1119 BIO_printf(bio_err,"-mr produce machine readable output.\n"); 1120 #ifndef NO_FORK 1121 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n"); 1122 #endif 1123 goto end; 1124 } 1125 argc--; 1126 argv++; 1127 j++; 1128 } 1129 1130 #ifndef NO_FORK 1131 if(multi && do_multi(multi)) 1132 goto show_res; 1133 #endif 1134 1135 if (j == 0) 1136 { 1137 for (i=0; i<ALGOR_NUM; i++) 1138 { 1139 if (i != D_EVP) 1140 doit[i]=1; 1141 } 1142 for (i=0; i<RSA_NUM; i++) 1143 rsa_doit[i]=1; 1144 for (i=0; i<DSA_NUM; i++) 1145 dsa_doit[i]=1; 1146 #ifndef OPENSSL_NO_ECDSA 1147 for (i=0; i<EC_NUM; i++) 1148 ecdsa_doit[i]=1; 1149 #endif 1150 #ifndef OPENSSL_NO_ECDH 1151 for (i=0; i<EC_NUM; i++) 1152 ecdh_doit[i]=1; 1153 #endif 1154 } 1155 for (i=0; i<ALGOR_NUM; i++) 1156 if (doit[i]) pr_header++; 1157 1158 if (usertime == 0 && !mr) 1159 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n"); 1160 1161 #ifndef OPENSSL_NO_RSA 1162 for (i=0; i<RSA_NUM; i++) 1163 { 1164 const unsigned char *p; 1165 1166 p=rsa_data[i]; 1167 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]); 1168 if (rsa_key[i] == NULL) 1169 { 1170 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i); 1171 goto end; 1172 } 1173 #if 0 1174 else 1175 { 1176 BIO_printf(bio_err,mr ? "+RK:%d:" 1177 : "Loaded RSA key, %d bit modulus and e= 0x", 1178 BN_num_bits(rsa_key[i]->n)); 1179 BN_print(bio_err,rsa_key[i]->e); 1180 BIO_printf(bio_err,"\n"); 1181 } 1182 #endif 1183 } 1184 #endif 1185 1186 #ifndef OPENSSL_NO_DSA 1187 dsa_key[0]=get_dsa512(); 1188 dsa_key[1]=get_dsa1024(); 1189 dsa_key[2]=get_dsa2048(); 1190 #endif 1191 1192 #ifndef OPENSSL_NO_DES 1193 DES_set_key_unchecked(&key,&sch); 1194 DES_set_key_unchecked(&key2,&sch2); 1195 DES_set_key_unchecked(&key3,&sch3); 1196 #endif 1197 #ifndef OPENSSL_NO_AES 1198 AES_set_encrypt_key(key16,128,&aes_ks1); 1199 AES_set_encrypt_key(key24,192,&aes_ks2); 1200 AES_set_encrypt_key(key32,256,&aes_ks3); 1201 #endif 1202 #ifndef OPENSSL_NO_CAMELLIA 1203 Camellia_set_key(key16,128,&camellia_ks1); 1204 Camellia_set_key(ckey24,192,&camellia_ks2); 1205 Camellia_set_key(ckey32,256,&camellia_ks3); 1206 #endif 1207 #ifndef OPENSSL_NO_IDEA 1208 idea_set_encrypt_key(key16,&idea_ks); 1209 #endif 1210 #ifndef OPENSSL_NO_SEED 1211 SEED_set_key(key16,&seed_ks); 1212 #endif 1213 #ifndef OPENSSL_NO_RC4 1214 RC4_set_key(&rc4_ks,16,key16); 1215 #endif 1216 #ifndef OPENSSL_NO_RC2 1217 RC2_set_key(&rc2_ks,16,key16,128); 1218 #endif 1219 #ifndef OPENSSL_NO_RC5 1220 RC5_32_set_key(&rc5_ks,16,key16,12); 1221 #endif 1222 #ifndef OPENSSL_NO_BF 1223 BF_set_key(&bf_ks,16,key16); 1224 #endif 1225 #ifndef OPENSSL_NO_CAST 1226 CAST_set_key(&cast_ks,16,key16); 1227 #endif 1228 #ifndef OPENSSL_NO_RSA 1229 memset(rsa_c,0,sizeof(rsa_c)); 1230 #endif 1231 #ifndef SIGALRM 1232 #ifndef OPENSSL_NO_DES 1233 BIO_printf(bio_err,"First we calculate the approximate speed ...\n"); 1234 count=10; 1235 do { 1236 long it; 1237 count*=2; 1238 Time_F(START); 1239 for (it=count; it; it--) 1240 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock, 1241 &sch,DES_ENCRYPT); 1242 d=Time_F(STOP); 1243 } while (d <3); 1244 save_count=count; 1245 c[D_MD2][0]=count/10; 1246 c[D_MDC2][0]=count/10; 1247 c[D_MD4][0]=count; 1248 c[D_MD5][0]=count; 1249 c[D_HMAC][0]=count; 1250 c[D_SHA1][0]=count; 1251 c[D_RMD160][0]=count; 1252 c[D_RC4][0]=count*5; 1253 c[D_CBC_DES][0]=count; 1254 c[D_EDE3_DES][0]=count/3; 1255 c[D_CBC_IDEA][0]=count; 1256 c[D_CBC_SEED][0]=count; 1257 c[D_CBC_RC2][0]=count; 1258 c[D_CBC_RC5][0]=count; 1259 c[D_CBC_BF][0]=count; 1260 c[D_CBC_CAST][0]=count; 1261 c[D_CBC_128_AES][0]=count; 1262 c[D_CBC_192_AES][0]=count; 1263 c[D_CBC_256_AES][0]=count; 1264 c[D_CBC_128_CML][0]=count; 1265 c[D_CBC_192_CML][0]=count; 1266 c[D_CBC_256_CML][0]=count; 1267 c[D_SHA256][0]=count; 1268 c[D_SHA512][0]=count; 1269 c[D_WHIRLPOOL][0]=count; 1270 c[D_IGE_128_AES][0]=count; 1271 c[D_IGE_192_AES][0]=count; 1272 c[D_IGE_256_AES][0]=count; 1273 1274 for (i=1; i<SIZE_NUM; i++) 1275 { 1276 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i]; 1277 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i]; 1278 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i]; 1279 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i]; 1280 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i]; 1281 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i]; 1282 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i]; 1283 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i]; 1284 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i]; 1285 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i]; 1286 } 1287 for (i=1; i<SIZE_NUM; i++) 1288 { 1289 long l0,l1; 1290 1291 l0=(long)lengths[i-1]; 1292 l1=(long)lengths[i]; 1293 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1; 1294 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1; 1295 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1; 1296 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1; 1297 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1; 1298 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1; 1299 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1; 1300 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1; 1301 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1; 1302 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1; 1303 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1; 1304 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1; 1305 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1; 1306 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1; 1307 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1; 1308 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1; 1309 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1; 1310 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1; 1311 } 1312 #ifndef OPENSSL_NO_RSA 1313 rsa_c[R_RSA_512][0]=count/2000; 1314 rsa_c[R_RSA_512][1]=count/400; 1315 for (i=1; i<RSA_NUM; i++) 1316 { 1317 rsa_c[i][0]=rsa_c[i-1][0]/8; 1318 rsa_c[i][1]=rsa_c[i-1][1]/4; 1319 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0)) 1320 rsa_doit[i]=0; 1321 else 1322 { 1323 if (rsa_c[i][0] == 0) 1324 { 1325 rsa_c[i][0]=1; 1326 rsa_c[i][1]=20; 1327 } 1328 } 1329 } 1330 #endif 1331 1332 #ifndef OPENSSL_NO_DSA 1333 dsa_c[R_DSA_512][0]=count/1000; 1334 dsa_c[R_DSA_512][1]=count/1000/2; 1335 for (i=1; i<DSA_NUM; i++) 1336 { 1337 dsa_c[i][0]=dsa_c[i-1][0]/4; 1338 dsa_c[i][1]=dsa_c[i-1][1]/4; 1339 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0)) 1340 dsa_doit[i]=0; 1341 else 1342 { 1343 if (dsa_c[i] == 0) 1344 { 1345 dsa_c[i][0]=1; 1346 dsa_c[i][1]=1; 1347 } 1348 } 1349 } 1350 #endif 1351 1352 #ifndef OPENSSL_NO_ECDSA 1353 ecdsa_c[R_EC_P160][0]=count/1000; 1354 ecdsa_c[R_EC_P160][1]=count/1000/2; 1355 for (i=R_EC_P192; i<=R_EC_P521; i++) 1356 { 1357 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2; 1358 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2; 1359 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) 1360 ecdsa_doit[i]=0; 1361 else 1362 { 1363 if (ecdsa_c[i] == 0) 1364 { 1365 ecdsa_c[i][0]=1; 1366 ecdsa_c[i][1]=1; 1367 } 1368 } 1369 } 1370 ecdsa_c[R_EC_K163][0]=count/1000; 1371 ecdsa_c[R_EC_K163][1]=count/1000/2; 1372 for (i=R_EC_K233; i<=R_EC_K571; i++) 1373 { 1374 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2; 1375 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2; 1376 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) 1377 ecdsa_doit[i]=0; 1378 else 1379 { 1380 if (ecdsa_c[i] == 0) 1381 { 1382 ecdsa_c[i][0]=1; 1383 ecdsa_c[i][1]=1; 1384 } 1385 } 1386 } 1387 ecdsa_c[R_EC_B163][0]=count/1000; 1388 ecdsa_c[R_EC_B163][1]=count/1000/2; 1389 for (i=R_EC_B233; i<=R_EC_B571; i++) 1390 { 1391 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2; 1392 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2; 1393 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0)) 1394 ecdsa_doit[i]=0; 1395 else 1396 { 1397 if (ecdsa_c[i] == 0) 1398 { 1399 ecdsa_c[i][0]=1; 1400 ecdsa_c[i][1]=1; 1401 } 1402 } 1403 } 1404 #endif 1405 1406 #ifndef OPENSSL_NO_ECDH 1407 ecdh_c[R_EC_P160][0]=count/1000; 1408 ecdh_c[R_EC_P160][1]=count/1000; 1409 for (i=R_EC_P192; i<=R_EC_P521; i++) 1410 { 1411 ecdh_c[i][0]=ecdh_c[i-1][0]/2; 1412 ecdh_c[i][1]=ecdh_c[i-1][1]/2; 1413 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) 1414 ecdh_doit[i]=0; 1415 else 1416 { 1417 if (ecdh_c[i] == 0) 1418 { 1419 ecdh_c[i][0]=1; 1420 ecdh_c[i][1]=1; 1421 } 1422 } 1423 } 1424 ecdh_c[R_EC_K163][0]=count/1000; 1425 ecdh_c[R_EC_K163][1]=count/1000; 1426 for (i=R_EC_K233; i<=R_EC_K571; i++) 1427 { 1428 ecdh_c[i][0]=ecdh_c[i-1][0]/2; 1429 ecdh_c[i][1]=ecdh_c[i-1][1]/2; 1430 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) 1431 ecdh_doit[i]=0; 1432 else 1433 { 1434 if (ecdh_c[i] == 0) 1435 { 1436 ecdh_c[i][0]=1; 1437 ecdh_c[i][1]=1; 1438 } 1439 } 1440 } 1441 ecdh_c[R_EC_B163][0]=count/1000; 1442 ecdh_c[R_EC_B163][1]=count/1000; 1443 for (i=R_EC_B233; i<=R_EC_B571; i++) 1444 { 1445 ecdh_c[i][0]=ecdh_c[i-1][0]/2; 1446 ecdh_c[i][1]=ecdh_c[i-1][1]/2; 1447 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0)) 1448 ecdh_doit[i]=0; 1449 else 1450 { 1451 if (ecdh_c[i] == 0) 1452 { 1453 ecdh_c[i][0]=1; 1454 ecdh_c[i][1]=1; 1455 } 1456 } 1457 } 1458 #endif 1459 1460 #define COND(d) (count < (d)) 1461 #define COUNT(d) (d) 1462 #else 1463 /* not worth fixing */ 1464 # error "You cannot disable DES on systems without SIGALRM." 1465 #endif /* OPENSSL_NO_DES */ 1466 #else 1467 #define COND(c) (run) 1468 #define COUNT(d) (count) 1469 #ifndef _WIN32 1470 signal(SIGALRM,sig_done); 1471 #endif 1472 #endif /* SIGALRM */ 1473 1474 #ifndef OPENSSL_NO_MD2 1475 if (doit[D_MD2]) 1476 { 1477 for (j=0; j<SIZE_NUM; j++) 1478 { 1479 print_message(names[D_MD2],c[D_MD2][j],lengths[j]); 1480 Time_F(START); 1481 for (count=0,run=1; COND(c[D_MD2][j]); count++) 1482 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL); 1483 d=Time_F(STOP); 1484 print_result(D_MD2,j,count,d); 1485 } 1486 } 1487 #endif 1488 #ifndef OPENSSL_NO_MDC2 1489 if (doit[D_MDC2]) 1490 { 1491 for (j=0; j<SIZE_NUM; j++) 1492 { 1493 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]); 1494 Time_F(START); 1495 for (count=0,run=1; COND(c[D_MDC2][j]); count++) 1496 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL); 1497 d=Time_F(STOP); 1498 print_result(D_MDC2,j,count,d); 1499 } 1500 } 1501 #endif 1502 1503 #ifndef OPENSSL_NO_MD4 1504 if (doit[D_MD4]) 1505 { 1506 for (j=0; j<SIZE_NUM; j++) 1507 { 1508 print_message(names[D_MD4],c[D_MD4][j],lengths[j]); 1509 Time_F(START); 1510 for (count=0,run=1; COND(c[D_MD4][j]); count++) 1511 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL); 1512 d=Time_F(STOP); 1513 print_result(D_MD4,j,count,d); 1514 } 1515 } 1516 #endif 1517 1518 #ifndef OPENSSL_NO_MD5 1519 if (doit[D_MD5]) 1520 { 1521 for (j=0; j<SIZE_NUM; j++) 1522 { 1523 print_message(names[D_MD5],c[D_MD5][j],lengths[j]); 1524 Time_F(START); 1525 for (count=0,run=1; COND(c[D_MD5][j]); count++) 1526 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL); 1527 d=Time_F(STOP); 1528 print_result(D_MD5,j,count,d); 1529 } 1530 } 1531 #endif 1532 1533 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC) 1534 if (doit[D_HMAC]) 1535 { 1536 HMAC_CTX hctx; 1537 1538 HMAC_CTX_init(&hctx); 1539 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...", 1540 16,EVP_md5(), NULL); 1541 1542 for (j=0; j<SIZE_NUM; j++) 1543 { 1544 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]); 1545 Time_F(START); 1546 for (count=0,run=1; COND(c[D_HMAC][j]); count++) 1547 { 1548 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL); 1549 HMAC_Update(&hctx,buf,lengths[j]); 1550 HMAC_Final(&hctx,&(hmac[0]),NULL); 1551 } 1552 d=Time_F(STOP); 1553 print_result(D_HMAC,j,count,d); 1554 } 1555 HMAC_CTX_cleanup(&hctx); 1556 } 1557 #endif 1558 #ifndef OPENSSL_NO_SHA 1559 if (doit[D_SHA1]) 1560 { 1561 for (j=0; j<SIZE_NUM; j++) 1562 { 1563 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]); 1564 Time_F(START); 1565 for (count=0,run=1; COND(c[D_SHA1][j]); count++) 1566 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL); 1567 d=Time_F(STOP); 1568 print_result(D_SHA1,j,count,d); 1569 } 1570 } 1571 1572 #ifndef OPENSSL_NO_SHA256 1573 if (doit[D_SHA256]) 1574 { 1575 for (j=0; j<SIZE_NUM; j++) 1576 { 1577 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]); 1578 Time_F(START); 1579 for (count=0,run=1; COND(c[D_SHA256][j]); count++) 1580 SHA256(buf,lengths[j],sha256); 1581 d=Time_F(STOP); 1582 print_result(D_SHA256,j,count,d); 1583 } 1584 } 1585 #endif 1586 1587 #ifndef OPENSSL_NO_SHA512 1588 if (doit[D_SHA512]) 1589 { 1590 for (j=0; j<SIZE_NUM; j++) 1591 { 1592 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]); 1593 Time_F(START); 1594 for (count=0,run=1; COND(c[D_SHA512][j]); count++) 1595 SHA512(buf,lengths[j],sha512); 1596 d=Time_F(STOP); 1597 print_result(D_SHA512,j,count,d); 1598 } 1599 } 1600 #endif 1601 #endif 1602 1603 #ifndef OPENSSL_NO_WHIRLPOOL 1604 if (doit[D_WHIRLPOOL]) 1605 { 1606 for (j=0; j<SIZE_NUM; j++) 1607 { 1608 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]); 1609 Time_F(START); 1610 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++) 1611 WHIRLPOOL(buf,lengths[j],whirlpool); 1612 d=Time_F(STOP); 1613 print_result(D_WHIRLPOOL,j,count,d); 1614 } 1615 } 1616 #endif 1617 1618 #ifndef OPENSSL_NO_RIPEMD 1619 if (doit[D_RMD160]) 1620 { 1621 for (j=0; j<SIZE_NUM; j++) 1622 { 1623 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]); 1624 Time_F(START); 1625 for (count=0,run=1; COND(c[D_RMD160][j]); count++) 1626 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL); 1627 d=Time_F(STOP); 1628 print_result(D_RMD160,j,count,d); 1629 } 1630 } 1631 #endif 1632 #ifndef OPENSSL_NO_RC4 1633 if (doit[D_RC4]) 1634 { 1635 for (j=0; j<SIZE_NUM; j++) 1636 { 1637 print_message(names[D_RC4],c[D_RC4][j],lengths[j]); 1638 Time_F(START); 1639 for (count=0,run=1; COND(c[D_RC4][j]); count++) 1640 RC4(&rc4_ks,(unsigned int)lengths[j], 1641 buf,buf); 1642 d=Time_F(STOP); 1643 print_result(D_RC4,j,count,d); 1644 } 1645 } 1646 #endif 1647 #ifndef OPENSSL_NO_DES 1648 if (doit[D_CBC_DES]) 1649 { 1650 for (j=0; j<SIZE_NUM; j++) 1651 { 1652 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]); 1653 Time_F(START); 1654 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++) 1655 DES_ncbc_encrypt(buf,buf,lengths[j],&sch, 1656 &DES_iv,DES_ENCRYPT); 1657 d=Time_F(STOP); 1658 print_result(D_CBC_DES,j,count,d); 1659 } 1660 } 1661 1662 if (doit[D_EDE3_DES]) 1663 { 1664 for (j=0; j<SIZE_NUM; j++) 1665 { 1666 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]); 1667 Time_F(START); 1668 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++) 1669 DES_ede3_cbc_encrypt(buf,buf,lengths[j], 1670 &sch,&sch2,&sch3, 1671 &DES_iv,DES_ENCRYPT); 1672 d=Time_F(STOP); 1673 print_result(D_EDE3_DES,j,count,d); 1674 } 1675 } 1676 #endif 1677 #ifndef OPENSSL_NO_AES 1678 if (doit[D_CBC_128_AES]) 1679 { 1680 for (j=0; j<SIZE_NUM; j++) 1681 { 1682 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]); 1683 Time_F(START); 1684 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++) 1685 AES_cbc_encrypt(buf,buf, 1686 (unsigned long)lengths[j],&aes_ks1, 1687 iv,AES_ENCRYPT); 1688 d=Time_F(STOP); 1689 print_result(D_CBC_128_AES,j,count,d); 1690 } 1691 } 1692 if (doit[D_CBC_192_AES]) 1693 { 1694 for (j=0; j<SIZE_NUM; j++) 1695 { 1696 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]); 1697 Time_F(START); 1698 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++) 1699 AES_cbc_encrypt(buf,buf, 1700 (unsigned long)lengths[j],&aes_ks2, 1701 iv,AES_ENCRYPT); 1702 d=Time_F(STOP); 1703 print_result(D_CBC_192_AES,j,count,d); 1704 } 1705 } 1706 if (doit[D_CBC_256_AES]) 1707 { 1708 for (j=0; j<SIZE_NUM; j++) 1709 { 1710 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]); 1711 Time_F(START); 1712 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++) 1713 AES_cbc_encrypt(buf,buf, 1714 (unsigned long)lengths[j],&aes_ks3, 1715 iv,AES_ENCRYPT); 1716 d=Time_F(STOP); 1717 print_result(D_CBC_256_AES,j,count,d); 1718 } 1719 } 1720 1721 #if 0 /* ANDROID */ 1722 if (doit[D_IGE_128_AES]) 1723 { 1724 for (j=0; j<SIZE_NUM; j++) 1725 { 1726 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]); 1727 Time_F(START); 1728 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++) 1729 AES_ige_encrypt(buf,buf2, 1730 (unsigned long)lengths[j],&aes_ks1, 1731 iv,AES_ENCRYPT); 1732 d=Time_F(STOP); 1733 print_result(D_IGE_128_AES,j,count,d); 1734 } 1735 } 1736 if (doit[D_IGE_192_AES]) 1737 { 1738 for (j=0; j<SIZE_NUM; j++) 1739 { 1740 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]); 1741 Time_F(START); 1742 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++) 1743 AES_ige_encrypt(buf,buf2, 1744 (unsigned long)lengths[j],&aes_ks2, 1745 iv,AES_ENCRYPT); 1746 d=Time_F(STOP); 1747 print_result(D_IGE_192_AES,j,count,d); 1748 } 1749 } 1750 if (doit[D_IGE_256_AES]) 1751 { 1752 for (j=0; j<SIZE_NUM; j++) 1753 { 1754 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]); 1755 Time_F(START); 1756 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++) 1757 AES_ige_encrypt(buf,buf2, 1758 (unsigned long)lengths[j],&aes_ks3, 1759 iv,AES_ENCRYPT); 1760 d=Time_F(STOP); 1761 print_result(D_IGE_256_AES,j,count,d); 1762 } 1763 } 1764 1765 1766 #endif 1767 #endif 1768 #ifndef OPENSSL_NO_CAMELLIA 1769 if (doit[D_CBC_128_CML]) 1770 { 1771 for (j=0; j<SIZE_NUM; j++) 1772 { 1773 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]); 1774 Time_F(START); 1775 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++) 1776 Camellia_cbc_encrypt(buf,buf, 1777 (unsigned long)lengths[j],&camellia_ks1, 1778 iv,CAMELLIA_ENCRYPT); 1779 d=Time_F(STOP); 1780 print_result(D_CBC_128_CML,j,count,d); 1781 } 1782 } 1783 if (doit[D_CBC_192_CML]) 1784 { 1785 for (j=0; j<SIZE_NUM; j++) 1786 { 1787 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]); 1788 Time_F(START); 1789 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++) 1790 Camellia_cbc_encrypt(buf,buf, 1791 (unsigned long)lengths[j],&camellia_ks2, 1792 iv,CAMELLIA_ENCRYPT); 1793 d=Time_F(STOP); 1794 print_result(D_CBC_192_CML,j,count,d); 1795 } 1796 } 1797 if (doit[D_CBC_256_CML]) 1798 { 1799 for (j=0; j<SIZE_NUM; j++) 1800 { 1801 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]); 1802 Time_F(START); 1803 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++) 1804 Camellia_cbc_encrypt(buf,buf, 1805 (unsigned long)lengths[j],&camellia_ks3, 1806 iv,CAMELLIA_ENCRYPT); 1807 d=Time_F(STOP); 1808 print_result(D_CBC_256_CML,j,count,d); 1809 } 1810 } 1811 1812 #endif 1813 #ifndef OPENSSL_NO_IDEA 1814 if (doit[D_CBC_IDEA]) 1815 { 1816 for (j=0; j<SIZE_NUM; j++) 1817 { 1818 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]); 1819 Time_F(START); 1820 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++) 1821 idea_cbc_encrypt(buf,buf, 1822 (unsigned long)lengths[j],&idea_ks, 1823 iv,IDEA_ENCRYPT); 1824 d=Time_F(STOP); 1825 print_result(D_CBC_IDEA,j,count,d); 1826 } 1827 } 1828 #endif 1829 #ifndef OPENSSL_NO_SEED 1830 if (doit[D_CBC_SEED]) 1831 { 1832 for (j=0; j<SIZE_NUM; j++) 1833 { 1834 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]); 1835 Time_F(START); 1836 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++) 1837 SEED_cbc_encrypt(buf,buf, 1838 (unsigned long)lengths[j],&seed_ks,iv,1); 1839 d=Time_F(STOP); 1840 print_result(D_CBC_SEED,j,count,d); 1841 } 1842 } 1843 #endif 1844 #ifndef OPENSSL_NO_RC2 1845 if (doit[D_CBC_RC2]) 1846 { 1847 for (j=0; j<SIZE_NUM; j++) 1848 { 1849 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]); 1850 Time_F(START); 1851 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++) 1852 RC2_cbc_encrypt(buf,buf, 1853 (unsigned long)lengths[j],&rc2_ks, 1854 iv,RC2_ENCRYPT); 1855 d=Time_F(STOP); 1856 print_result(D_CBC_RC2,j,count,d); 1857 } 1858 } 1859 #endif 1860 #ifndef OPENSSL_NO_RC5 1861 if (doit[D_CBC_RC5]) 1862 { 1863 for (j=0; j<SIZE_NUM; j++) 1864 { 1865 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]); 1866 Time_F(START); 1867 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++) 1868 RC5_32_cbc_encrypt(buf,buf, 1869 (unsigned long)lengths[j],&rc5_ks, 1870 iv,RC5_ENCRYPT); 1871 d=Time_F(STOP); 1872 print_result(D_CBC_RC5,j,count,d); 1873 } 1874 } 1875 #endif 1876 #ifndef OPENSSL_NO_BF 1877 if (doit[D_CBC_BF]) 1878 { 1879 for (j=0; j<SIZE_NUM; j++) 1880 { 1881 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]); 1882 Time_F(START); 1883 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++) 1884 BF_cbc_encrypt(buf,buf, 1885 (unsigned long)lengths[j],&bf_ks, 1886 iv,BF_ENCRYPT); 1887 d=Time_F(STOP); 1888 print_result(D_CBC_BF,j,count,d); 1889 } 1890 } 1891 #endif 1892 #ifndef OPENSSL_NO_CAST 1893 if (doit[D_CBC_CAST]) 1894 { 1895 for (j=0; j<SIZE_NUM; j++) 1896 { 1897 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]); 1898 Time_F(START); 1899 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++) 1900 CAST_cbc_encrypt(buf,buf, 1901 (unsigned long)lengths[j],&cast_ks, 1902 iv,CAST_ENCRYPT); 1903 d=Time_F(STOP); 1904 print_result(D_CBC_CAST,j,count,d); 1905 } 1906 } 1907 #endif 1908 1909 if (doit[D_EVP]) 1910 { 1911 for (j=0; j<SIZE_NUM; j++) 1912 { 1913 if (evp_cipher) 1914 { 1915 EVP_CIPHER_CTX ctx; 1916 int outl; 1917 1918 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid); 1919 /* -O3 -fschedule-insns messes up an 1920 * optimization here! names[D_EVP] 1921 * somehow becomes NULL */ 1922 print_message(names[D_EVP],save_count, 1923 lengths[j]); 1924 1925 EVP_CIPHER_CTX_init(&ctx); 1926 if(decrypt) 1927 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv); 1928 else 1929 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv); 1930 EVP_CIPHER_CTX_set_padding(&ctx, 0); 1931 1932 Time_F(START); 1933 if(decrypt) 1934 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) 1935 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]); 1936 else 1937 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) 1938 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]); 1939 if(decrypt) 1940 EVP_DecryptFinal_ex(&ctx,buf,&outl); 1941 else 1942 EVP_EncryptFinal_ex(&ctx,buf,&outl); 1943 d=Time_F(STOP); 1944 EVP_CIPHER_CTX_cleanup(&ctx); 1945 } 1946 if (evp_md) 1947 { 1948 names[D_EVP]=OBJ_nid2ln(evp_md->type); 1949 print_message(names[D_EVP],save_count, 1950 lengths[j]); 1951 1952 Time_F(START); 1953 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) 1954 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL); 1955 1956 d=Time_F(STOP); 1957 } 1958 print_result(D_EVP,j,count,d); 1959 } 1960 } 1961 1962 RAND_pseudo_bytes(buf,36); 1963 #ifndef OPENSSL_NO_RSA 1964 for (j=0; j<RSA_NUM; j++) 1965 { 1966 int ret; 1967 if (!rsa_doit[j]) continue; 1968 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]); 1969 if (ret == 0) 1970 { 1971 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n"); 1972 ERR_print_errors(bio_err); 1973 rsa_count=1; 1974 } 1975 else 1976 { 1977 pkey_print_message("private","rsa", 1978 rsa_c[j][0],rsa_bits[j], 1979 RSA_SECONDS); 1980 /* RSA_blinding_on(rsa_key[j],NULL); */ 1981 Time_F(START); 1982 for (count=0,run=1; COND(rsa_c[j][0]); count++) 1983 { 1984 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, 1985 &rsa_num, rsa_key[j]); 1986 if (ret == 0) 1987 { 1988 BIO_printf(bio_err, 1989 "RSA sign failure\n"); 1990 ERR_print_errors(bio_err); 1991 count=1; 1992 break; 1993 } 1994 } 1995 d=Time_F(STOP); 1996 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n" 1997 : "%ld %d bit private RSA's in %.2fs\n", 1998 count,rsa_bits[j],d); 1999 rsa_results[j][0]=d/(double)count; 2000 rsa_count=count; 2001 } 2002 2003 #if 1 2004 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]); 2005 if (ret <= 0) 2006 { 2007 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n"); 2008 ERR_print_errors(bio_err); 2009 rsa_doit[j] = 0; 2010 } 2011 else 2012 { 2013 pkey_print_message("public","rsa", 2014 rsa_c[j][1],rsa_bits[j], 2015 RSA_SECONDS); 2016 Time_F(START); 2017 for (count=0,run=1; COND(rsa_c[j][1]); count++) 2018 { 2019 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, 2020 rsa_num, rsa_key[j]); 2021 if (ret <= 0) 2022 { 2023 BIO_printf(bio_err, 2024 "RSA verify failure\n"); 2025 ERR_print_errors(bio_err); 2026 count=1; 2027 break; 2028 } 2029 } 2030 d=Time_F(STOP); 2031 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n" 2032 : "%ld %d bit public RSA's in %.2fs\n", 2033 count,rsa_bits[j],d); 2034 rsa_results[j][1]=d/(double)count; 2035 } 2036 #endif 2037 2038 if (rsa_count <= 1) 2039 { 2040 /* if longer than 10s, don't do any more */ 2041 for (j++; j<RSA_NUM; j++) 2042 rsa_doit[j]=0; 2043 } 2044 } 2045 #endif 2046 2047 RAND_pseudo_bytes(buf,20); 2048 #ifndef OPENSSL_NO_DSA 2049 if (RAND_status() != 1) 2050 { 2051 RAND_seed(rnd_seed, sizeof rnd_seed); 2052 rnd_fake = 1; 2053 } 2054 for (j=0; j<DSA_NUM; j++) 2055 { 2056 unsigned int kk; 2057 int ret; 2058 2059 if (!dsa_doit[j]) continue; 2060 /* DSA_generate_key(dsa_key[j]); */ 2061 /* DSA_sign_setup(dsa_key[j],NULL); */ 2062 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, 2063 &kk,dsa_key[j]); 2064 if (ret == 0) 2065 { 2066 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n"); 2067 ERR_print_errors(bio_err); 2068 rsa_count=1; 2069 } 2070 else 2071 { 2072 pkey_print_message("sign","dsa", 2073 dsa_c[j][0],dsa_bits[j], 2074 DSA_SECONDS); 2075 Time_F(START); 2076 for (count=0,run=1; COND(dsa_c[j][0]); count++) 2077 { 2078 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, 2079 &kk,dsa_key[j]); 2080 if (ret == 0) 2081 { 2082 BIO_printf(bio_err, 2083 "DSA sign failure\n"); 2084 ERR_print_errors(bio_err); 2085 count=1; 2086 break; 2087 } 2088 } 2089 d=Time_F(STOP); 2090 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n" 2091 : "%ld %d bit DSA signs in %.2fs\n", 2092 count,dsa_bits[j],d); 2093 dsa_results[j][0]=d/(double)count; 2094 rsa_count=count; 2095 } 2096 2097 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, 2098 kk,dsa_key[j]); 2099 if (ret <= 0) 2100 { 2101 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n"); 2102 ERR_print_errors(bio_err); 2103 dsa_doit[j] = 0; 2104 } 2105 else 2106 { 2107 pkey_print_message("verify","dsa", 2108 dsa_c[j][1],dsa_bits[j], 2109 DSA_SECONDS); 2110 Time_F(START); 2111 for (count=0,run=1; COND(dsa_c[j][1]); count++) 2112 { 2113 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, 2114 kk,dsa_key[j]); 2115 if (ret <= 0) 2116 { 2117 BIO_printf(bio_err, 2118 "DSA verify failure\n"); 2119 ERR_print_errors(bio_err); 2120 count=1; 2121 break; 2122 } 2123 } 2124 d=Time_F(STOP); 2125 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n" 2126 : "%ld %d bit DSA verify in %.2fs\n", 2127 count,dsa_bits[j],d); 2128 dsa_results[j][1]=d/(double)count; 2129 } 2130 2131 if (rsa_count <= 1) 2132 { 2133 /* if longer than 10s, don't do any more */ 2134 for (j++; j<DSA_NUM; j++) 2135 dsa_doit[j]=0; 2136 } 2137 } 2138 if (rnd_fake) RAND_cleanup(); 2139 #endif 2140 2141 #ifndef OPENSSL_NO_ECDSA 2142 if (RAND_status() != 1) 2143 { 2144 RAND_seed(rnd_seed, sizeof rnd_seed); 2145 rnd_fake = 1; 2146 } 2147 for (j=0; j<EC_NUM; j++) 2148 { 2149 int ret; 2150 2151 if (!ecdsa_doit[j]) continue; /* Ignore Curve */ 2152 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]); 2153 if (ecdsa[j] == NULL) 2154 { 2155 BIO_printf(bio_err,"ECDSA failure.\n"); 2156 ERR_print_errors(bio_err); 2157 rsa_count=1; 2158 } 2159 else 2160 { 2161 #if 1 2162 EC_KEY_precompute_mult(ecdsa[j], NULL); 2163 #endif 2164 /* Perform ECDSA signature test */ 2165 EC_KEY_generate_key(ecdsa[j]); 2166 ret = ECDSA_sign(0, buf, 20, ecdsasig, 2167 &ecdsasiglen, ecdsa[j]); 2168 if (ret == 0) 2169 { 2170 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n"); 2171 ERR_print_errors(bio_err); 2172 rsa_count=1; 2173 } 2174 else 2175 { 2176 pkey_print_message("sign","ecdsa", 2177 ecdsa_c[j][0], 2178 test_curves_bits[j], 2179 ECDSA_SECONDS); 2180 2181 Time_F(START); 2182 for (count=0,run=1; COND(ecdsa_c[j][0]); 2183 count++) 2184 { 2185 ret=ECDSA_sign(0, buf, 20, 2186 ecdsasig, &ecdsasiglen, 2187 ecdsa[j]); 2188 if (ret == 0) 2189 { 2190 BIO_printf(bio_err, "ECDSA sign failure\n"); 2191 ERR_print_errors(bio_err); 2192 count=1; 2193 break; 2194 } 2195 } 2196 d=Time_F(STOP); 2197 2198 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" : 2199 "%ld %d bit ECDSA signs in %.2fs \n", 2200 count, test_curves_bits[j], d); 2201 ecdsa_results[j][0]=d/(double)count; 2202 rsa_count=count; 2203 } 2204 2205 /* Perform ECDSA verification test */ 2206 ret=ECDSA_verify(0, buf, 20, ecdsasig, 2207 ecdsasiglen, ecdsa[j]); 2208 if (ret != 1) 2209 { 2210 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n"); 2211 ERR_print_errors(bio_err); 2212 ecdsa_doit[j] = 0; 2213 } 2214 else 2215 { 2216 pkey_print_message("verify","ecdsa", 2217 ecdsa_c[j][1], 2218 test_curves_bits[j], 2219 ECDSA_SECONDS); 2220 Time_F(START); 2221 for (count=0,run=1; COND(ecdsa_c[j][1]); count++) 2222 { 2223 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]); 2224 if (ret != 1) 2225 { 2226 BIO_printf(bio_err, "ECDSA verify failure\n"); 2227 ERR_print_errors(bio_err); 2228 count=1; 2229 break; 2230 } 2231 } 2232 d=Time_F(STOP); 2233 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n" 2234 : "%ld %d bit ECDSA verify in %.2fs\n", 2235 count, test_curves_bits[j], d); 2236 ecdsa_results[j][1]=d/(double)count; 2237 } 2238 2239 if (rsa_count <= 1) 2240 { 2241 /* if longer than 10s, don't do any more */ 2242 for (j++; j<EC_NUM; j++) 2243 ecdsa_doit[j]=0; 2244 } 2245 } 2246 } 2247 if (rnd_fake) RAND_cleanup(); 2248 #endif 2249 2250 #ifndef OPENSSL_NO_ECDH 2251 if (RAND_status() != 1) 2252 { 2253 RAND_seed(rnd_seed, sizeof rnd_seed); 2254 rnd_fake = 1; 2255 } 2256 for (j=0; j<EC_NUM; j++) 2257 { 2258 if (!ecdh_doit[j]) continue; 2259 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]); 2260 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]); 2261 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) 2262 { 2263 BIO_printf(bio_err,"ECDH failure.\n"); 2264 ERR_print_errors(bio_err); 2265 rsa_count=1; 2266 } 2267 else 2268 { 2269 /* generate two ECDH key pairs */ 2270 if (!EC_KEY_generate_key(ecdh_a[j]) || 2271 !EC_KEY_generate_key(ecdh_b[j])) 2272 { 2273 BIO_printf(bio_err,"ECDH key generation failure.\n"); 2274 ERR_print_errors(bio_err); 2275 rsa_count=1; 2276 } 2277 else 2278 { 2279 /* If field size is not more than 24 octets, then use SHA-1 hash of result; 2280 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt). 2281 */ 2282 int field_size, outlen; 2283 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen); 2284 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j])); 2285 if (field_size <= 24 * 8) 2286 { 2287 outlen = KDF1_SHA1_len; 2288 kdf = KDF1_SHA1; 2289 } 2290 else 2291 { 2292 outlen = (field_size+7)/8; 2293 kdf = NULL; 2294 } 2295 secret_size_a = ECDH_compute_key(secret_a, outlen, 2296 EC_KEY_get0_public_key(ecdh_b[j]), 2297 ecdh_a[j], kdf); 2298 secret_size_b = ECDH_compute_key(secret_b, outlen, 2299 EC_KEY_get0_public_key(ecdh_a[j]), 2300 ecdh_b[j], kdf); 2301 if (secret_size_a != secret_size_b) 2302 ecdh_checks = 0; 2303 else 2304 ecdh_checks = 1; 2305 2306 for (secret_idx = 0; 2307 (secret_idx < secret_size_a) 2308 && (ecdh_checks == 1); 2309 secret_idx++) 2310 { 2311 if (secret_a[secret_idx] != secret_b[secret_idx]) 2312 ecdh_checks = 0; 2313 } 2314 2315 if (ecdh_checks == 0) 2316 { 2317 BIO_printf(bio_err,"ECDH computations don't match.\n"); 2318 ERR_print_errors(bio_err); 2319 rsa_count=1; 2320 } 2321 2322 pkey_print_message("","ecdh", 2323 ecdh_c[j][0], 2324 test_curves_bits[j], 2325 ECDH_SECONDS); 2326 Time_F(START); 2327 for (count=0,run=1; COND(ecdh_c[j][0]); count++) 2328 { 2329 ECDH_compute_key(secret_a, outlen, 2330 EC_KEY_get0_public_key(ecdh_b[j]), 2331 ecdh_a[j], kdf); 2332 } 2333 d=Time_F(STOP); 2334 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n", 2335 count, test_curves_bits[j], d); 2336 ecdh_results[j][0]=d/(double)count; 2337 rsa_count=count; 2338 } 2339 } 2340 2341 2342 if (rsa_count <= 1) 2343 { 2344 /* if longer than 10s, don't do any more */ 2345 for (j++; j<EC_NUM; j++) 2346 ecdh_doit[j]=0; 2347 } 2348 } 2349 if (rnd_fake) RAND_cleanup(); 2350 #endif 2351 #ifndef NO_FORK 2352 show_res: 2353 #endif 2354 if(!mr) 2355 { 2356 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION)); 2357 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON)); 2358 printf("options:"); 2359 printf("%s ",BN_options()); 2360 #ifndef OPENSSL_NO_MD2 2361 printf("%s ",MD2_options()); 2362 #endif 2363 #ifndef OPENSSL_NO_RC4 2364 printf("%s ",RC4_options()); 2365 #endif 2366 #ifndef OPENSSL_NO_DES 2367 printf("%s ",DES_options()); 2368 #endif 2369 #ifndef OPENSSL_NO_AES 2370 printf("%s ",AES_options()); 2371 #endif 2372 #ifndef OPENSSL_NO_IDEA 2373 printf("%s ",idea_options()); 2374 #endif 2375 #ifndef OPENSSL_NO_BF 2376 printf("%s ",BF_options()); 2377 #endif 2378 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS)); 2379 } 2380 2381 if (pr_header) 2382 { 2383 if(mr) 2384 fprintf(stdout,"+H"); 2385 else 2386 { 2387 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); 2388 fprintf(stdout,"type "); 2389 } 2390 for (j=0; j<SIZE_NUM; j++) 2391 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]); 2392 fprintf(stdout,"\n"); 2393 } 2394 2395 for (k=0; k<ALGOR_NUM; k++) 2396 { 2397 if (!doit[k]) continue; 2398 if(mr) 2399 fprintf(stdout,"+F:%d:%s",k,names[k]); 2400 else 2401 fprintf(stdout,"%-13s",names[k]); 2402 for (j=0; j<SIZE_NUM; j++) 2403 { 2404 if (results[k][j] > 10000 && !mr) 2405 fprintf(stdout," %11.2fk",results[k][j]/1e3); 2406 else 2407 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]); 2408 } 2409 fprintf(stdout,"\n"); 2410 } 2411 #ifndef OPENSSL_NO_RSA 2412 j=1; 2413 for (k=0; k<RSA_NUM; k++) 2414 { 2415 if (!rsa_doit[k]) continue; 2416 if (j && !mr) 2417 { 2418 printf("%18ssign verify sign/s verify/s\n"," "); 2419 j=0; 2420 } 2421 if(mr) 2422 fprintf(stdout,"+F2:%u:%u:%f:%f\n", 2423 k,rsa_bits[k],rsa_results[k][0], 2424 rsa_results[k][1]); 2425 else 2426 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", 2427 rsa_bits[k],rsa_results[k][0],rsa_results[k][1], 2428 1.0/rsa_results[k][0],1.0/rsa_results[k][1]); 2429 } 2430 #endif 2431 #ifndef OPENSSL_NO_DSA 2432 j=1; 2433 for (k=0; k<DSA_NUM; k++) 2434 { 2435 if (!dsa_doit[k]) continue; 2436 if (j && !mr) 2437 { 2438 printf("%18ssign verify sign/s verify/s\n"," "); 2439 j=0; 2440 } 2441 if(mr) 2442 fprintf(stdout,"+F3:%u:%u:%f:%f\n", 2443 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]); 2444 else 2445 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n", 2446 dsa_bits[k],dsa_results[k][0],dsa_results[k][1], 2447 1.0/dsa_results[k][0],1.0/dsa_results[k][1]); 2448 } 2449 #endif 2450 #ifndef OPENSSL_NO_ECDSA 2451 j=1; 2452 for (k=0; k<EC_NUM; k++) 2453 { 2454 if (!ecdsa_doit[k]) continue; 2455 if (j && !mr) 2456 { 2457 printf("%30ssign verify sign/s verify/s\n"," "); 2458 j=0; 2459 } 2460 2461 if (mr) 2462 fprintf(stdout,"+F4:%u:%u:%f:%f\n", 2463 k, test_curves_bits[k], 2464 ecdsa_results[k][0],ecdsa_results[k][1]); 2465 else 2466 fprintf(stdout, 2467 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", 2468 test_curves_bits[k], 2469 test_curves_names[k], 2470 ecdsa_results[k][0],ecdsa_results[k][1], 2471 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]); 2472 } 2473 #endif 2474 2475 2476 #ifndef OPENSSL_NO_ECDH 2477 j=1; 2478 for (k=0; k<EC_NUM; k++) 2479 { 2480 if (!ecdh_doit[k]) continue; 2481 if (j && !mr) 2482 { 2483 printf("%30sop op/s\n"," "); 2484 j=0; 2485 } 2486 if (mr) 2487 fprintf(stdout,"+F5:%u:%u:%f:%f\n", 2488 k, test_curves_bits[k], 2489 ecdh_results[k][0], 1.0/ecdh_results[k][0]); 2490 2491 else 2492 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n", 2493 test_curves_bits[k], 2494 test_curves_names[k], 2495 ecdh_results[k][0], 1.0/ecdh_results[k][0]); 2496 } 2497 #endif 2498 2499 mret=0; 2500 2501 end: 2502 ERR_print_errors(bio_err); 2503 if (buf != NULL) OPENSSL_free(buf); 2504 if (buf2 != NULL) OPENSSL_free(buf2); 2505 #ifndef OPENSSL_NO_RSA 2506 for (i=0; i<RSA_NUM; i++) 2507 if (rsa_key[i] != NULL) 2508 RSA_free(rsa_key[i]); 2509 #endif 2510 #ifndef OPENSSL_NO_DSA 2511 for (i=0; i<DSA_NUM; i++) 2512 if (dsa_key[i] != NULL) 2513 DSA_free(dsa_key[i]); 2514 #endif 2515 2516 #ifndef OPENSSL_NO_ECDSA 2517 for (i=0; i<EC_NUM; i++) 2518 if (ecdsa[i] != NULL) 2519 EC_KEY_free(ecdsa[i]); 2520 #endif 2521 #ifndef OPENSSL_NO_ECDH 2522 for (i=0; i<EC_NUM; i++) 2523 { 2524 if (ecdh_a[i] != NULL) 2525 EC_KEY_free(ecdh_a[i]); 2526 if (ecdh_b[i] != NULL) 2527 EC_KEY_free(ecdh_b[i]); 2528 } 2529 #endif 2530 2531 apps_shutdown(); 2532 OPENSSL_EXIT(mret); 2533 } 2534 2535 static void print_message(const char *s, long num, int length) 2536 { 2537 #ifdef SIGALRM 2538 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n" 2539 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length); 2540 (void)BIO_flush(bio_err); 2541 alarm(SECONDS); 2542 #else 2543 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n" 2544 : "Doing %s %ld times on %d size blocks: ",s,num,length); 2545 (void)BIO_flush(bio_err); 2546 #endif 2547 #ifdef LINT 2548 num=num; 2549 #endif 2550 } 2551 2552 static void pkey_print_message(const char *str, const char *str2, long num, 2553 int bits, int tm) 2554 { 2555 #ifdef SIGALRM 2556 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n" 2557 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm); 2558 (void)BIO_flush(bio_err); 2559 alarm(RSA_SECONDS); 2560 #else 2561 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n" 2562 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2); 2563 (void)BIO_flush(bio_err); 2564 #endif 2565 #ifdef LINT 2566 num=num; 2567 #endif 2568 } 2569 2570 static void print_result(int alg,int run_no,int count,double time_used) 2571 { 2572 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n" 2573 : "%d %s's in %.2fs\n",count,names[alg],time_used); 2574 results[alg][run_no]=((double)count)/time_used*lengths[run_no]; 2575 } 2576 2577 #ifndef NO_FORK 2578 static char *sstrsep(char **string, const char *delim) 2579 { 2580 char isdelim[256]; 2581 char *token = *string; 2582 2583 if (**string == 0) 2584 return NULL; 2585 2586 memset(isdelim, 0, sizeof isdelim); 2587 isdelim[0] = 1; 2588 2589 while (*delim) 2590 { 2591 isdelim[(unsigned char)(*delim)] = 1; 2592 delim++; 2593 } 2594 2595 while (!isdelim[(unsigned char)(**string)]) 2596 { 2597 (*string)++; 2598 } 2599 2600 if (**string) 2601 { 2602 **string = 0; 2603 (*string)++; 2604 } 2605 2606 return token; 2607 } 2608 2609 static int do_multi(int multi) 2610 { 2611 int n; 2612 int fd[2]; 2613 int *fds; 2614 static char sep[]=":"; 2615 2616 fds=malloc(multi*sizeof *fds); 2617 for(n=0 ; n < multi ; ++n) 2618 { 2619 pipe(fd); 2620 fflush(stdout); 2621 fflush(stderr); 2622 if(fork()) 2623 { 2624 close(fd[1]); 2625 fds[n]=fd[0]; 2626 } 2627 else 2628 { 2629 close(fd[0]); 2630 close(1); 2631 dup(fd[1]); 2632 close(fd[1]); 2633 mr=1; 2634 usertime=0; 2635 free(fds); 2636 return 0; 2637 } 2638 printf("Forked child %d\n",n); 2639 } 2640 2641 /* for now, assume the pipe is long enough to take all the output */ 2642 for(n=0 ; n < multi ; ++n) 2643 { 2644 FILE *f; 2645 char buf[1024]; 2646 char *p; 2647 2648 f=fdopen(fds[n],"r"); 2649 while(fgets(buf,sizeof buf,f)) 2650 { 2651 p=strchr(buf,'\n'); 2652 if(p) 2653 *p='\0'; 2654 if(buf[0] != '+') 2655 { 2656 fprintf(stderr,"Don't understand line '%s' from child %d\n", 2657 buf,n); 2658 continue; 2659 } 2660 printf("Got: %s from %d\n",buf,n); 2661 if(!strncmp(buf,"+F:",3)) 2662 { 2663 int alg; 2664 int j; 2665 2666 p=buf+3; 2667 alg=atoi(sstrsep(&p,sep)); 2668 sstrsep(&p,sep); 2669 for(j=0 ; j < SIZE_NUM ; ++j) 2670 results[alg][j]+=atof(sstrsep(&p,sep)); 2671 } 2672 else if(!strncmp(buf,"+F2:",4)) 2673 { 2674 int k; 2675 double d; 2676 2677 p=buf+4; 2678 k=atoi(sstrsep(&p,sep)); 2679 sstrsep(&p,sep); 2680 2681 d=atof(sstrsep(&p,sep)); 2682 if(n) 2683 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); 2684 else 2685 rsa_results[k][0]=d; 2686 2687 d=atof(sstrsep(&p,sep)); 2688 if(n) 2689 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); 2690 else 2691 rsa_results[k][1]=d; 2692 } 2693 else if(!strncmp(buf,"+F2:",4)) 2694 { 2695 int k; 2696 double d; 2697 2698 p=buf+4; 2699 k=atoi(sstrsep(&p,sep)); 2700 sstrsep(&p,sep); 2701 2702 d=atof(sstrsep(&p,sep)); 2703 if(n) 2704 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); 2705 else 2706 rsa_results[k][0]=d; 2707 2708 d=atof(sstrsep(&p,sep)); 2709 if(n) 2710 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); 2711 else 2712 rsa_results[k][1]=d; 2713 } 2714 else if(!strncmp(buf,"+F3:",4)) 2715 { 2716 int k; 2717 double d; 2718 2719 p=buf+4; 2720 k=atoi(sstrsep(&p,sep)); 2721 sstrsep(&p,sep); 2722 2723 d=atof(sstrsep(&p,sep)); 2724 if(n) 2725 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); 2726 else 2727 dsa_results[k][0]=d; 2728 2729 d=atof(sstrsep(&p,sep)); 2730 if(n) 2731 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); 2732 else 2733 dsa_results[k][1]=d; 2734 } 2735 #ifndef OPENSSL_NO_ECDSA 2736 else if(!strncmp(buf,"+F4:",4)) 2737 { 2738 int k; 2739 double d; 2740 2741 p=buf+4; 2742 k=atoi(sstrsep(&p,sep)); 2743 sstrsep(&p,sep); 2744 2745 d=atof(sstrsep(&p,sep)); 2746 if(n) 2747 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d); 2748 else 2749 ecdsa_results[k][0]=d; 2750 2751 d=atof(sstrsep(&p,sep)); 2752 if(n) 2753 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d); 2754 else 2755 ecdsa_results[k][1]=d; 2756 } 2757 #endif 2758 2759 #ifndef OPENSSL_NO_ECDH 2760 else if(!strncmp(buf,"+F5:",4)) 2761 { 2762 int k; 2763 double d; 2764 2765 p=buf+4; 2766 k=atoi(sstrsep(&p,sep)); 2767 sstrsep(&p,sep); 2768 2769 d=atof(sstrsep(&p,sep)); 2770 if(n) 2771 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d); 2772 else 2773 ecdh_results[k][0]=d; 2774 2775 } 2776 #endif 2777 2778 else if(!strncmp(buf,"+H:",3)) 2779 { 2780 } 2781 else 2782 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); 2783 } 2784 2785 fclose(f); 2786 } 2787 free(fds); 2788 return 1; 2789 } 2790 #endif 2791 #endif 2792