1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */ 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3 * All rights reserved. 4 * 5 * This package is an SSL implementation written 6 * by Eric Young (eay@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@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@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@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 * The portions of this code that are #ifdef SOLARIS_OPENSSL are 60 * 61 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 62 * Use is subject to license terms. 63 * 64 */ 65 #pragma ident "%Z%%M% %I% %E% SMI" 66 67 /* most of this code has been pilfered from my libdes speed.c program */ 68 69 #ifndef OPENSSL_NO_SPEED 70 71 #undef SECONDS 72 #define SECONDS 3 73 #define RSA_SECONDS 10 74 #define DSA_SECONDS 10 75 76 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ 77 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ 78 79 #undef PROG 80 #define PROG speed_main 81 82 #include <stdio.h> 83 #include <stdlib.h> 84 #include <signal.h> 85 #include <string.h> 86 #include <math.h> 87 #include "apps.h" 88 #ifdef OPENSSL_NO_STDIO 89 #define APPS_WIN16 90 #endif 91 #include <openssl/crypto.h> 92 #include <openssl/rand.h> 93 #include <openssl/err.h> 94 #include <openssl/evp.h> 95 #include <openssl/objects.h> 96 #if !defined(OPENSSL_SYS_MSDOS) 97 #include OPENSSL_UNISTD 98 #endif 99 #ifdef SOLARIS_OPENSSL 100 extern int SUNWcry_installed; 101 #endif 102 103 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX) 104 # define USE_TOD 105 #elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) 106 # define TIMES 107 #endif 108 #if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) && !defined(OPENSSL_SYS_VXWORKS) /* FIXME */ 109 # define TIMEB 110 #endif 111 112 #ifndef _IRIX 113 # include <time.h> 114 #endif 115 #ifdef TIMES 116 # include <sys/types.h> 117 # include <sys/times.h> 118 #endif 119 #ifdef USE_TOD 120 # include <sys/time.h> 121 # include <sys/resource.h> 122 #endif 123 124 /* Depending on the VMS version, the tms structure is perhaps defined. 125 The __TMS macro will show if it was. If it wasn't defined, we should 126 undefine TIMES, since that tells the rest of the program how things 127 should be handled. -- Richard Levitte */ 128 #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) 129 #undef TIMES 130 #endif 131 132 #ifdef TIMEB 133 #include <sys/timeb.h> 134 #endif 135 136 #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) 137 #error "It seems neither struct tms nor struct timeb is supported in this platform!" 138 #endif 139 140 #if defined(sun) || defined(__ultrix) 141 #define _POSIX_SOURCE 142 #include <limits.h> 143 #include <sys/param.h> 144 #endif 145 146 #ifndef OPENSSL_NO_DES 147 #include <openssl/des.h> 148 #endif 149 #ifndef OPENSSL_NO_AES 150 #include <openssl/aes.h> 151 #endif 152 #ifndef OPENSSL_NO_MD2 153 #include <openssl/md2.h> 154 #endif 155 #ifndef OPENSSL_NO_MDC2 156 #include <openssl/mdc2.h> 157 #endif 158 #ifndef OPENSSL_NO_MD4 159 #include <openssl/md4.h> 160 #endif 161 #ifndef OPENSSL_NO_MD5 162 #include <openssl/md5.h> 163 #endif 164 #ifndef OPENSSL_NO_HMAC 165 #include <openssl/hmac.h> 166 #endif 167 #include <openssl/evp.h> 168 #ifndef OPENSSL_NO_SHA 169 #include <openssl/sha.h> 170 #endif 171 #ifndef OPENSSL_NO_RIPEMD 172 #include <openssl/ripemd.h> 173 #endif 174 #ifndef OPENSSL_NO_RC4 175 #include <openssl/rc4.h> 176 #endif 177 #ifndef OPENSSL_NO_RC5 178 #include <openssl/rc5.h> 179 #endif 180 #ifndef OPENSSL_NO_RC2 181 #include <openssl/rc2.h> 182 #endif 183 #ifndef OPENSSL_NO_IDEA 184 #include <openssl/idea.h> 185 #endif 186 #ifndef OPENSSL_NO_BF 187 #include <openssl/blowfish.h> 188 #endif 189 #ifndef OPENSSL_NO_CAST 190 #include <openssl/cast.h> 191 #endif 192 #ifndef OPENSSL_NO_RSA 193 #include <openssl/rsa.h> 194 #include "./testrsa.h" 195 #endif 196 #include <openssl/x509.h> 197 #ifndef OPENSSL_NO_DSA 198 #include "./testdsa.h" 199 #endif 200 201 /* The following if from times(3) man page. It may need to be changed */ 202 #ifndef HZ 203 # if defined(_SC_CLK_TCK) \ 204 && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000) 205 # define HZ ((double)sysconf(_SC_CLK_TCK)) 206 # else 207 # ifndef CLK_TCK 208 # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */ 209 # define HZ 100.0 210 # else /* _BSD_CLK_TCK_ */ 211 # define HZ ((double)_BSD_CLK_TCK_) 212 # endif 213 # else /* CLK_TCK */ 214 # define HZ ((double)CLK_TCK) 215 # endif 216 # endif 217 #endif 218 219 #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) 220 # define HAVE_FORK 1 221 #endif 222 223 #undef BUFSIZE 224 #define BUFSIZE ((long)1024*8+1) 225 int run=0; 226 227 static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0; 228 static int mr=0; 229 static int usertime=1; 230 231 static double Time_F(int s); 232 static void print_message(const char *s,long num,int length); 233 static void pkey_print_message(char *str,char *str2,long num,int bits,int sec); 234 static void print_result(int alg,int run_no,int count,double time_used); 235 #ifdef HAVE_FORK 236 static int do_multi(int multi); 237 #endif 238 239 #define ALGOR_NUM 19 240 #define SIZE_NUM 5 241 #define RSA_NUM 4 242 #define DSA_NUM 3 243 static const char *names[ALGOR_NUM]={ 244 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4", 245 "des cbc","des ede3","idea cbc", 246 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc", 247 "aes-128 cbc","aes-192 cbc","aes-256 cbc"}; 248 static double results[ALGOR_NUM][SIZE_NUM]; 249 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024}; 250 static double rsa_results[RSA_NUM][2]; 251 static double dsa_results[DSA_NUM][2]; 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 static double Time_F(int s) 275 { 276 double ret; 277 278 #ifdef USE_TOD 279 if(usertime) 280 { 281 static struct rusage tstart,tend; 282 283 getrusage_used = 1; 284 if (s == START) 285 { 286 getrusage(RUSAGE_SELF,&tstart); 287 return(0); 288 } 289 else 290 { 291 long i; 292 293 getrusage(RUSAGE_SELF,&tend); 294 i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec; 295 ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec)) 296 +((double)i)/1000000.0; 297 return((ret < 0.001)?0.001:ret); 298 } 299 } 300 else 301 { 302 static struct timeval tstart,tend; 303 long i; 304 305 gettimeofday_used = 1; 306 if (s == START) 307 { 308 gettimeofday(&tstart,NULL); 309 return(0); 310 } 311 else 312 { 313 gettimeofday(&tend,NULL); 314 i=(long)tend.tv_usec-(long)tstart.tv_usec; 315 ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0; 316 return((ret < 0.001)?0.001:ret); 317 } 318 } 319 #else /* ndef USE_TOD */ 320 321 # ifdef TIMES 322 if (usertime) 323 { 324 static struct tms tstart,tend; 325 326 times_used = 1; 327 if (s == START) 328 { 329 times(&tstart); 330 return(0); 331 } 332 else 333 { 334 times(&tend); 335 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; 336 return((ret < 1e-3)?1e-3:ret); 337 } 338 } 339 # endif /* times() */ 340 # if defined(TIMES) && defined(TIMEB) 341 else 342 # endif 343 # ifdef OPENSSL_SYS_VXWORKS 344 { 345 static unsigned long tick_start, tick_end; 346 347 if( s == START ) 348 { 349 tick_start = tickGet(); 350 return 0; 351 } 352 else 353 { 354 tick_end = tickGet(); 355 ret = (double)(tick_end - tick_start) / (double)sysClkRateGet(); 356 return((ret < 0.001)?0.001:ret); 357 } 358 } 359 # elif defined(TIMEB) 360 { 361 static struct timeb tstart,tend; 362 long i; 363 364 ftime_used = 1; 365 if (s == START) 366 { 367 ftime(&tstart); 368 return(0); 369 } 370 else 371 { 372 ftime(&tend); 373 i=(long)tend.millitm-(long)tstart.millitm; 374 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0; 375 return((ret < 0.001)?0.001:ret); 376 } 377 } 378 # endif 379 #endif 380 } 381 382 int MAIN(int, char **); 383 384 int MAIN(int argc, char **argv) 385 { 386 #ifndef OPENSSL_NO_ENGINE 387 ENGINE *e = NULL; 388 #endif 389 unsigned char *buf=NULL,*buf2=NULL; 390 int mret=1; 391 long count=0,save_count=0; 392 int i,j,k; 393 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA) 394 long rsa_count; 395 #endif 396 #ifndef OPENSSL_NO_RSA 397 unsigned rsa_num; 398 #endif 399 unsigned char md[EVP_MAX_MD_SIZE]; 400 #ifndef OPENSSL_NO_MD2 401 unsigned char md2[MD2_DIGEST_LENGTH]; 402 #endif 403 #ifndef OPENSSL_NO_MDC2 404 unsigned char mdc2[MDC2_DIGEST_LENGTH]; 405 #endif 406 #ifndef OPENSSL_NO_MD4 407 unsigned char md4[MD4_DIGEST_LENGTH]; 408 #endif 409 #ifndef OPENSSL_NO_MD5 410 unsigned char md5[MD5_DIGEST_LENGTH]; 411 unsigned char hmac[MD5_DIGEST_LENGTH]; 412 #endif 413 #ifndef OPENSSL_NO_SHA 414 unsigned char sha[SHA_DIGEST_LENGTH]; 415 #endif 416 #ifndef OPENSSL_NO_RIPEMD 417 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; 418 #endif 419 #ifndef OPENSSL_NO_RC4 420 RC4_KEY rc4_ks; 421 #endif 422 #ifndef OPENSSL_NO_RC5 423 RC5_32_KEY rc5_ks; 424 #endif 425 #ifndef OPENSSL_NO_RC2 426 RC2_KEY rc2_ks; 427 #endif 428 #ifndef OPENSSL_NO_IDEA 429 IDEA_KEY_SCHEDULE idea_ks; 430 #endif 431 #ifndef OPENSSL_NO_BF 432 BF_KEY bf_ks; 433 #endif 434 #ifndef OPENSSL_NO_CAST 435 CAST_KEY cast_ks; 436 #endif 437 static const unsigned char key16[16]= 438 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 439 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; 440 static const unsigned char key24[24]= 441 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 442 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, 443 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; 444 static const unsigned char key32[32]= 445 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, 446 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12, 447 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34, 448 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56}; 449 #ifndef OPENSSL_NO_AES 450 #define MAX_BLOCK_SIZE 128 451 #else 452 #define MAX_BLOCK_SIZE 64 453 #endif 454 unsigned char DES_iv[8]; 455 unsigned char iv[MAX_BLOCK_SIZE/8]; 456 #ifndef OPENSSL_NO_DES 457 DES_cblock *buf_as_des_cblock = NULL; 458 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0}; 459 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12}; 460 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34}; 461 DES_key_schedule sch; 462 DES_key_schedule sch2; 463 DES_key_schedule sch3; 464 #endif 465 #ifndef OPENSSL_NO_AES 466 AES_KEY aes_ks1, aes_ks2, aes_ks3; 467 #endif 468 #define D_MD2 0 469 #define D_MDC2 1 470 #define D_MD4 2 471 #define D_MD5 3 472 #define D_HMAC 4 473 #define D_SHA1 5 474 #define D_RMD160 6 475 #define D_RC4 7 476 #define D_CBC_DES 8 477 #define D_EDE3_DES 9 478 #define D_CBC_IDEA 10 479 #define D_CBC_RC2 11 480 #define D_CBC_RC5 12 481 #define D_CBC_BF 13 482 #define D_CBC_CAST 14 483 #define D_CBC_128_AES 15 484 #define D_CBC_192_AES 16 485 #define D_CBC_256_AES 17 486 #define D_EVP 18 487 double d=0.0; 488 long c[ALGOR_NUM][SIZE_NUM]; 489 #define R_DSA_512 0 490 #define R_DSA_1024 1 491 #define R_DSA_2048 2 492 #define R_RSA_512 0 493 #define R_RSA_1024 1 494 #define R_RSA_2048 2 495 #define R_RSA_4096 3 496 #ifndef OPENSSL_NO_RSA 497 RSA *rsa_key[RSA_NUM]; 498 long rsa_c[RSA_NUM][2]; 499 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096}; 500 static unsigned char *rsa_data[RSA_NUM]= 501 {test512,test1024,test2048,test4096}; 502 static int rsa_data_length[RSA_NUM]={ 503 sizeof(test512),sizeof(test1024), 504 sizeof(test2048),sizeof(test4096)}; 505 #endif 506 #ifndef OPENSSL_NO_DSA 507 DSA *dsa_key[DSA_NUM]; 508 long dsa_c[DSA_NUM][2]; 509 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048}; 510 #endif 511 int rsa_doit[RSA_NUM]; 512 int dsa_doit[DSA_NUM]; 513 int doit[ALGOR_NUM]; 514 int pr_header=0; 515 const EVP_CIPHER *evp_cipher=NULL; 516 const EVP_MD *evp_md=NULL; 517 int decrypt=0; 518 #ifdef HAVE_FORK 519 int multi=0; 520 #endif 521 522 #ifndef TIMES 523 usertime=-1; 524 #endif 525 526 apps_startup(); 527 memset(results, 0, sizeof(results)); 528 #ifndef OPENSSL_NO_DSA 529 memset(dsa_key,0,sizeof(dsa_key)); 530 #endif 531 532 if (bio_err == NULL) 533 if ((bio_err=BIO_new(BIO_s_file())) != NULL) 534 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); 535 536 if (!load_config(bio_err, NULL)) 537 goto end; 538 539 #ifndef OPENSSL_NO_RSA 540 memset(rsa_key,0,sizeof(rsa_key)); 541 for (i=0; i<RSA_NUM; i++) 542 rsa_key[i]=NULL; 543 #endif 544 545 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) 546 { 547 BIO_printf(bio_err,"out of memory\n"); 548 goto end; 549 } 550 #ifndef OPENSSL_NO_DES 551 buf_as_des_cblock = (DES_cblock *)buf; 552 #endif 553 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL) 554 { 555 BIO_printf(bio_err,"out of memory\n"); 556 goto end; 557 } 558 559 memset(c,0,sizeof(c)); 560 memset(DES_iv,0,sizeof(DES_iv)); 561 memset(iv,0,sizeof(iv)); 562 563 for (i=0; i<ALGOR_NUM; i++) 564 doit[i]=0; 565 for (i=0; i<RSA_NUM; i++) 566 rsa_doit[i]=0; 567 for (i=0; i<DSA_NUM; i++) 568 dsa_doit[i]=0; 569 570 j=0; 571 argc--; 572 argv++; 573 while (argc) 574 { 575 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0)) 576 { 577 usertime = 0; 578 j--; /* Otherwise, -elapsed gets confused with 579 an algorithm. */ 580 } 581 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0)) 582 { 583 argc--; 584 argv++; 585 if(argc == 0) 586 { 587 BIO_printf(bio_err,"no EVP given\n"); 588 goto end; 589 } 590 evp_cipher=EVP_get_cipherbyname(*argv); 591 if(!evp_cipher) 592 { 593 evp_md=EVP_get_digestbyname(*argv); 594 } 595 if(!evp_cipher && !evp_md) 596 { 597 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv); 598 goto end; 599 } 600 doit[D_EVP]=1; 601 } 602 else if (argc > 0 && !strcmp(*argv,"-decrypt")) 603 { 604 decrypt=1; 605 j--; /* Otherwise, -elapsed gets confused with 606 an algorithm. */ 607 } 608 #ifndef OPENSSL_NO_ENGINE 609 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0)) 610 { 611 argc--; 612 argv++; 613 if(argc == 0) 614 { 615 BIO_printf(bio_err,"no engine given\n"); 616 goto end; 617 } 618 e = setup_engine(bio_err, *argv, 0); 619 /* j will be increased again further down. We just 620 don't want speed to confuse an engine with an 621 algorithm, especially when none is given (which 622 means all of them should be run) */ 623 j--; 624 } 625 #endif 626 #ifdef HAVE_FORK 627 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0)) 628 { 629 argc--; 630 argv++; 631 if(argc == 0) 632 { 633 BIO_printf(bio_err,"no multi count given\n"); 634 goto end; 635 } 636 multi=atoi(argv[0]); 637 if(multi <= 0) 638 { 639 BIO_printf(bio_err,"bad multi count\n"); 640 goto end; 641 } 642 j--; /* Otherwise, -mr gets confused with 643 an algorithm. */ 644 } 645 #endif 646 else if (argc > 0 && !strcmp(*argv,"-mr")) 647 { 648 mr=1; 649 j--; /* Otherwise, -mr gets confused with 650 an algorithm. */ 651 } 652 else 653 #ifndef OPENSSL_NO_MD2 654 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1; 655 else 656 #endif 657 #ifndef OPENSSL_NO_MDC2 658 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1; 659 else 660 #endif 661 #ifndef OPENSSL_NO_MD4 662 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1; 663 else 664 #endif 665 #ifndef OPENSSL_NO_MD5 666 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1; 667 else 668 #endif 669 #ifndef OPENSSL_NO_MD5 670 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1; 671 else 672 #endif 673 #ifndef OPENSSL_NO_SHA 674 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1; 675 else 676 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1; 677 else 678 #endif 679 #ifndef OPENSSL_NO_RIPEMD 680 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1; 681 else 682 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1; 683 else 684 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1; 685 else 686 #endif 687 #ifndef OPENSSL_NO_RC4 688 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1; 689 else 690 #endif 691 #ifndef OPENSSL_NO_DES 692 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1; 693 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1; 694 else 695 #endif 696 #ifndef OPENSSL_NO_AES 697 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1; 698 #ifdef SOLARIS_OPENSSL 699 else if (strcmp(*argv,"aes-192-cbc") == 0) 700 if (!SUNWcry_installed) 701 { 702 BIO_printf(bio_err, 703 "aes-192-cbc not available." 704 " SUNWcry not installed.\n"); 705 goto end; 706 } 707 else 708 doit[D_CBC_192_AES]=1; 709 else if (strcmp(*argv,"aes-256-cbc") == 0) 710 if (!SUNWcry_installed) 711 { 712 BIO_printf(bio_err, 713 "aes-256-cbc not available." 714 " SUNWcry not installed.\n"); 715 goto end; 716 } 717 else 718 doit[D_CBC_256_AES]=1; 719 #else 720 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1; 721 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1; 722 #endif 723 else 724 #endif 725 #ifndef OPENSSL_NO_RSA 726 #if 0 /* was: #ifdef RSAref */ 727 if (strcmp(*argv,"rsaref") == 0) 728 { 729 RSA_set_default_openssl_method(RSA_PKCS1_RSAref()); 730 j--; 731 } 732 else 733 #endif 734 #ifndef RSA_NULL 735 if (strcmp(*argv,"openssl") == 0) 736 { 737 RSA_set_default_method(RSA_PKCS1_SSLeay()); 738 j--; 739 } 740 else 741 #endif 742 #endif /* !OPENSSL_NO_RSA */ 743 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2; 744 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2; 745 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2; 746 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2; 747 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2; 748 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2; 749 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2; 750 else 751 #ifndef OPENSSL_NO_RC2 752 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1; 753 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1; 754 else 755 #endif 756 #ifndef OPENSSL_NO_RC5 757 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1; 758 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1; 759 else 760 #endif 761 #ifndef OPENSSL_NO_IDEA 762 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1; 763 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1; 764 else 765 #endif 766 #ifndef OPENSSL_NO_BF 767 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1; 768 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1; 769 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1; 770 else 771 #endif 772 #ifndef OPENSSL_NO_CAST 773 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1; 774 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1; 775 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1; 776 else 777 #endif 778 #ifndef OPENSSL_NO_DES 779 if (strcmp(*argv,"des") == 0) 780 { 781 doit[D_CBC_DES]=1; 782 doit[D_EDE3_DES]=1; 783 } 784 else 785 #endif 786 #ifndef OPENSSL_NO_AES 787 if (strcmp(*argv,"aes") == 0) 788 { 789 doit[D_CBC_128_AES]=1; 790 #ifdef SOLARIS_OPENSSL 791 doit[D_CBC_192_AES]= SUNWcry_installed; 792 doit[D_CBC_256_AES]= SUNWcry_installed; 793 #else 794 doit[D_CBC_192_AES]=1; 795 doit[D_CBC_256_AES]=1; 796 #endif 797 } 798 else 799 #endif 800 #ifndef OPENSSL_NO_RSA 801 if (strcmp(*argv,"rsa") == 0) 802 { 803 rsa_doit[R_RSA_512]=1; 804 rsa_doit[R_RSA_1024]=1; 805 rsa_doit[R_RSA_2048]=1; 806 rsa_doit[R_RSA_4096]=1; 807 } 808 else 809 #endif 810 #ifndef OPENSSL_NO_DSA 811 if (strcmp(*argv,"dsa") == 0) 812 { 813 dsa_doit[R_DSA_512]=1; 814 dsa_doit[R_DSA_1024]=1; 815 dsa_doit[R_DSA_2048]=1; 816 } 817 else 818 #endif 819 { 820 BIO_printf(bio_err,"Error: bad option or value\n"); 821 BIO_printf(bio_err,"\n"); 822 BIO_printf(bio_err,"Available values:\n"); 823 #ifndef OPENSSL_NO_MD2 824 BIO_printf(bio_err,"md2 "); 825 #endif 826 #ifndef OPENSSL_NO_MDC2 827 BIO_printf(bio_err,"mdc2 "); 828 #endif 829 #ifndef OPENSSL_NO_MD4 830 BIO_printf(bio_err,"md4 "); 831 #endif 832 #ifndef OPENSSL_NO_MD5 833 BIO_printf(bio_err,"md5 "); 834 #ifndef OPENSSL_NO_HMAC 835 BIO_printf(bio_err,"hmac "); 836 #endif 837 #endif 838 #ifndef OPENSSL_NO_SHA1 839 BIO_printf(bio_err,"sha1 "); 840 #endif 841 #ifndef OPENSSL_NO_RIPEMD160 842 BIO_printf(bio_err,"rmd160"); 843 #endif 844 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \ 845 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \ 846 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) 847 BIO_printf(bio_err,"\n"); 848 #endif 849 850 #ifndef OPENSSL_NO_IDEA 851 BIO_printf(bio_err,"idea-cbc "); 852 #endif 853 #ifndef OPENSSL_NO_RC2 854 BIO_printf(bio_err,"rc2-cbc "); 855 #endif 856 #ifndef OPENSSL_NO_RC5 857 BIO_printf(bio_err,"rc5-cbc "); 858 #endif 859 #ifndef OPENSSL_NO_BF 860 BIO_printf(bio_err,"bf-cbc"); 861 #endif 862 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \ 863 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5) 864 BIO_printf(bio_err,"\n"); 865 #endif 866 #ifndef OPENSSL_NO_DES 867 BIO_printf(bio_err,"des-cbc des-ede3 "); 868 #endif 869 #ifndef OPENSSL_NO_AES 870 #ifdef SOLARIS_OPENSSL 871 if (SUNWcry_installed) 872 BIO_printf(bio_err, 873 "aes-128-cbc aes-192-cbc aes-256-cbc "); 874 else 875 BIO_printf(bio_err, "aes-128-cbc "); 876 #else 877 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc "); 878 #endif 879 #endif 880 #ifndef OPENSSL_NO_RC4 881 BIO_printf(bio_err,"rc4"); 882 #endif 883 BIO_printf(bio_err,"\n"); 884 885 #ifndef OPENSSL_NO_RSA 886 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n"); 887 #endif 888 889 #ifndef OPENSSL_NO_DSA 890 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n"); 891 #endif 892 893 #ifndef OPENSSL_NO_IDEA 894 BIO_printf(bio_err,"idea "); 895 #endif 896 #ifndef OPENSSL_NO_RC2 897 BIO_printf(bio_err,"rc2 "); 898 #endif 899 #ifndef OPENSSL_NO_DES 900 BIO_printf(bio_err,"des "); 901 #endif 902 #ifndef OPENSSL_NO_AES 903 BIO_printf(bio_err,"aes "); 904 #endif 905 #ifndef OPENSSL_NO_RSA 906 BIO_printf(bio_err,"rsa "); 907 #endif 908 #ifndef OPENSSL_NO_BF 909 BIO_printf(bio_err,"blowfish"); 910 #endif 911 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \ 912 !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \ 913 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES) 914 BIO_printf(bio_err,"\n"); 915 #endif 916 917 BIO_printf(bio_err,"\n"); 918 BIO_printf(bio_err,"Available options:\n"); 919 #if defined(TIMES) || defined(USE_TOD) 920 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n"); 921 #endif 922 #ifndef OPENSSL_NO_ENGINE 923 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n"); 924 #endif 925 BIO_printf(bio_err,"-evp e use EVP e.\n"); 926 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n"); 927 BIO_printf(bio_err,"-mr produce machine readable output.\n"); 928 #ifdef HAVE_FORK 929 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n"); 930 #endif 931 goto end; 932 } 933 argc--; 934 argv++; 935 j++; 936 } 937 938 #ifdef HAVE_FORK 939 if(multi && do_multi(multi)) 940 goto show_res; 941 #endif 942 943 if (j == 0) 944 { 945 for (i=0; i<ALGOR_NUM; i++) 946 { 947 if (i != D_EVP) 948 doit[i]=1; 949 } 950 for (i=0; i<RSA_NUM; i++) 951 rsa_doit[i]=1; 952 for (i=0; i<DSA_NUM; i++) 953 dsa_doit[i]=1; 954 } 955 for (i=0; i<ALGOR_NUM; i++) 956 if (doit[i]) pr_header++; 957 958 if (usertime == 0 && !mr) 959 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n"); 960 if (usertime <= 0 && !mr) 961 { 962 BIO_printf(bio_err,"To get the most accurate results, try to run this\n"); 963 BIO_printf(bio_err,"program when this computer is idle.\n"); 964 } 965 966 #ifndef OPENSSL_NO_RSA 967 for (i=0; i<RSA_NUM; i++) 968 { 969 const unsigned char *p; 970 971 p=rsa_data[i]; 972 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]); 973 if (rsa_key[i] == NULL) 974 { 975 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i); 976 goto end; 977 } 978 #if 0 979 else 980 { 981 BIO_printf(bio_err,mr ? "+RK:%d:" 982 : "Loaded RSA key, %d bit modulus and e= 0x", 983 BN_num_bits(rsa_key[i]->n)); 984 BN_print(bio_err,rsa_key[i]->e); 985 BIO_printf(bio_err,"\n"); 986 } 987 #endif 988 } 989 #endif 990 991 #ifndef OPENSSL_NO_DSA 992 dsa_key[0]=get_dsa512(); 993 dsa_key[1]=get_dsa1024(); 994 dsa_key[2]=get_dsa2048(); 995 #endif 996 997 #ifndef OPENSSL_NO_DES 998 DES_set_key_unchecked(&key,&sch); 999 DES_set_key_unchecked(&key2,&sch2); 1000 DES_set_key_unchecked(&key3,&sch3); 1001 #endif 1002 #ifndef OPENSSL_NO_AES 1003 AES_set_encrypt_key(key16,128,&aes_ks1); 1004 AES_set_encrypt_key(key24,192,&aes_ks2); 1005 AES_set_encrypt_key(key32,256,&aes_ks3); 1006 #endif 1007 #ifndef OPENSSL_NO_IDEA 1008 idea_set_encrypt_key(key16,&idea_ks); 1009 #endif 1010 #ifndef OPENSSL_NO_RC4 1011 RC4_set_key(&rc4_ks,16,key16); 1012 #endif 1013 #ifndef OPENSSL_NO_RC2 1014 RC2_set_key(&rc2_ks,16,key16,128); 1015 #endif 1016 #ifndef OPENSSL_NO_RC5 1017 RC5_32_set_key(&rc5_ks,16,key16,12); 1018 #endif 1019 #ifndef OPENSSL_NO_BF 1020 BF_set_key(&bf_ks,16,key16); 1021 #endif 1022 #ifndef OPENSSL_NO_CAST 1023 CAST_set_key(&cast_ks,16,key16); 1024 #endif 1025 #ifndef OPENSSL_NO_RSA 1026 memset(rsa_c,0,sizeof(rsa_c)); 1027 #endif 1028 #ifndef SIGALRM 1029 #ifndef OPENSSL_NO_DES 1030 BIO_printf(bio_err,"First we calculate the approximate speed ...\n"); 1031 count=10; 1032 do { 1033 long i; 1034 count*=2; 1035 Time_F(START); 1036 for (i=count; i; i--) 1037 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock, 1038 &sch,DES_ENCRYPT); 1039 d=Time_F(STOP); 1040 } while (d <3); 1041 save_count=count; 1042 c[D_MD2][0]=count/10; 1043 c[D_MDC2][0]=count/10; 1044 c[D_MD4][0]=count; 1045 c[D_MD5][0]=count; 1046 c[D_HMAC][0]=count; 1047 c[D_SHA1][0]=count; 1048 c[D_RMD160][0]=count; 1049 c[D_RC4][0]=count*5; 1050 c[D_CBC_DES][0]=count; 1051 c[D_EDE3_DES][0]=count/3; 1052 c[D_CBC_IDEA][0]=count; 1053 c[D_CBC_RC2][0]=count; 1054 c[D_CBC_RC5][0]=count; 1055 c[D_CBC_BF][0]=count; 1056 c[D_CBC_CAST][0]=count; 1057 c[D_CBC_128_AES][0]=count; 1058 c[D_CBC_192_AES][0]=count; 1059 c[D_CBC_256_AES][0]=count; 1060 1061 for (i=1; i<SIZE_NUM; i++) 1062 { 1063 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i]; 1064 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i]; 1065 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i]; 1066 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i]; 1067 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i]; 1068 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i]; 1069 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i]; 1070 } 1071 for (i=1; i<SIZE_NUM; i++) 1072 { 1073 long l0,l1; 1074 1075 l0=(long)lengths[i-1]; 1076 l1=(long)lengths[i]; 1077 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1; 1078 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1; 1079 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1; 1080 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1; 1081 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1; 1082 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1; 1083 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1; 1084 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1; 1085 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1; 1086 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1; 1087 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1; 1088 } 1089 #ifndef OPENSSL_NO_RSA 1090 rsa_c[R_RSA_512][0]=count/2000; 1091 rsa_c[R_RSA_512][1]=count/400; 1092 for (i=1; i<RSA_NUM; i++) 1093 { 1094 rsa_c[i][0]=rsa_c[i-1][0]/8; 1095 rsa_c[i][1]=rsa_c[i-1][1]/4; 1096 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0)) 1097 rsa_doit[i]=0; 1098 else 1099 { 1100 if (rsa_c[i][0] == 0) 1101 { 1102 rsa_c[i][0]=1; 1103 rsa_c[i][1]=20; 1104 } 1105 } 1106 } 1107 #endif 1108 1109 #ifndef OPENSSL_NO_DSA 1110 dsa_c[R_DSA_512][0]=count/1000; 1111 dsa_c[R_DSA_512][1]=count/1000/2; 1112 for (i=1; i<DSA_NUM; i++) 1113 { 1114 dsa_c[i][0]=dsa_c[i-1][0]/4; 1115 dsa_c[i][1]=dsa_c[i-1][1]/4; 1116 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0)) 1117 dsa_doit[i]=0; 1118 else 1119 { 1120 if (dsa_c[i] == 0) 1121 { 1122 dsa_c[i][0]=1; 1123 dsa_c[i][1]=1; 1124 } 1125 } 1126 } 1127 #endif 1128 1129 #define COND(d) (count < (d)) 1130 #define COUNT(d) (d) 1131 #else 1132 /* not worth fixing */ 1133 # error "You cannot disable DES on systems without SIGALRM." 1134 #endif /* OPENSSL_NO_DES */ 1135 #else 1136 #define COND(c) (run) 1137 #define COUNT(d) (count) 1138 signal(SIGALRM,sig_done); 1139 #endif /* SIGALRM */ 1140 1141 #ifndef OPENSSL_NO_MD2 1142 if (doit[D_MD2]) 1143 { 1144 for (j=0; j<SIZE_NUM; j++) 1145 { 1146 print_message(names[D_MD2],c[D_MD2][j],lengths[j]); 1147 Time_F(START); 1148 for (count=0,run=1; COND(c[D_MD2][j]); count++) 1149 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL); 1150 d=Time_F(STOP); 1151 print_result(D_MD2,j,count,d); 1152 } 1153 } 1154 #endif 1155 #ifndef OPENSSL_NO_MDC2 1156 if (doit[D_MDC2]) 1157 { 1158 for (j=0; j<SIZE_NUM; j++) 1159 { 1160 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]); 1161 Time_F(START); 1162 for (count=0,run=1; COND(c[D_MDC2][j]); count++) 1163 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL); 1164 d=Time_F(STOP); 1165 print_result(D_MDC2,j,count,d); 1166 } 1167 } 1168 #endif 1169 1170 #ifndef OPENSSL_NO_MD4 1171 if (doit[D_MD4]) 1172 { 1173 for (j=0; j<SIZE_NUM; j++) 1174 { 1175 print_message(names[D_MD4],c[D_MD4][j],lengths[j]); 1176 Time_F(START); 1177 for (count=0,run=1; COND(c[D_MD4][j]); count++) 1178 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL); 1179 d=Time_F(STOP); 1180 print_result(D_MD4,j,count,d); 1181 } 1182 } 1183 #endif 1184 1185 #ifndef OPENSSL_NO_MD5 1186 if (doit[D_MD5]) 1187 { 1188 for (j=0; j<SIZE_NUM; j++) 1189 { 1190 print_message(names[D_MD5],c[D_MD5][j],lengths[j]); 1191 Time_F(START); 1192 for (count=0,run=1; COND(c[D_MD5][j]); count++) 1193 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL); 1194 d=Time_F(STOP); 1195 print_result(D_MD5,j,count,d); 1196 } 1197 } 1198 #endif 1199 1200 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC) 1201 if (doit[D_HMAC]) 1202 { 1203 HMAC_CTX hctx; 1204 1205 HMAC_CTX_init(&hctx); 1206 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...", 1207 16,EVP_md5(), NULL); 1208 1209 for (j=0; j<SIZE_NUM; j++) 1210 { 1211 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]); 1212 Time_F(START); 1213 for (count=0,run=1; COND(c[D_HMAC][j]); count++) 1214 { 1215 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL); 1216 HMAC_Update(&hctx,buf,lengths[j]); 1217 HMAC_Final(&hctx,&(hmac[0]),NULL); 1218 } 1219 d=Time_F(STOP); 1220 print_result(D_HMAC,j,count,d); 1221 } 1222 HMAC_CTX_cleanup(&hctx); 1223 } 1224 #endif 1225 #ifndef OPENSSL_NO_SHA 1226 if (doit[D_SHA1]) 1227 { 1228 for (j=0; j<SIZE_NUM; j++) 1229 { 1230 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]); 1231 Time_F(START); 1232 for (count=0,run=1; COND(c[D_SHA1][j]); count++) 1233 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL); 1234 d=Time_F(STOP); 1235 print_result(D_SHA1,j,count,d); 1236 } 1237 } 1238 #endif 1239 #ifndef OPENSSL_NO_RIPEMD 1240 if (doit[D_RMD160]) 1241 { 1242 for (j=0; j<SIZE_NUM; j++) 1243 { 1244 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]); 1245 Time_F(START); 1246 for (count=0,run=1; COND(c[D_RMD160][j]); count++) 1247 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL); 1248 d=Time_F(STOP); 1249 print_result(D_RMD160,j,count,d); 1250 } 1251 } 1252 #endif 1253 #ifndef OPENSSL_NO_RC4 1254 if (doit[D_RC4]) 1255 { 1256 for (j=0; j<SIZE_NUM; j++) 1257 { 1258 print_message(names[D_RC4],c[D_RC4][j],lengths[j]); 1259 Time_F(START); 1260 for (count=0,run=1; COND(c[D_RC4][j]); count++) 1261 RC4(&rc4_ks,(unsigned int)lengths[j], 1262 buf,buf); 1263 d=Time_F(STOP); 1264 print_result(D_RC4,j,count,d); 1265 } 1266 } 1267 #endif 1268 #ifndef OPENSSL_NO_DES 1269 if (doit[D_CBC_DES]) 1270 { 1271 for (j=0; j<SIZE_NUM; j++) 1272 { 1273 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]); 1274 Time_F(START); 1275 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++) 1276 DES_ncbc_encrypt(buf,buf,lengths[j],&sch, 1277 &DES_iv,DES_ENCRYPT); 1278 d=Time_F(STOP); 1279 print_result(D_CBC_DES,j,count,d); 1280 } 1281 } 1282 1283 if (doit[D_EDE3_DES]) 1284 { 1285 for (j=0; j<SIZE_NUM; j++) 1286 { 1287 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]); 1288 Time_F(START); 1289 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++) 1290 DES_ede3_cbc_encrypt(buf,buf,lengths[j], 1291 &sch,&sch2,&sch3, 1292 &DES_iv,DES_ENCRYPT); 1293 d=Time_F(STOP); 1294 print_result(D_EDE3_DES,j,count,d); 1295 } 1296 } 1297 #endif 1298 #ifndef OPENSSL_NO_AES 1299 if (doit[D_CBC_128_AES]) 1300 { 1301 for (j=0; j<SIZE_NUM; j++) 1302 { 1303 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]); 1304 Time_F(START); 1305 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++) 1306 AES_cbc_encrypt(buf,buf, 1307 (unsigned long)lengths[j],&aes_ks1, 1308 iv,AES_ENCRYPT); 1309 d=Time_F(STOP); 1310 print_result(D_CBC_128_AES,j,count,d); 1311 } 1312 } 1313 #ifdef SOLARIS_OPENSSL 1314 if (doit[D_CBC_192_AES] && SUNWcry_installed) 1315 #else 1316 if (doit[D_CBC_192_AES]) 1317 #endif 1318 { 1319 for (j=0; j<SIZE_NUM; j++) 1320 { 1321 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]); 1322 Time_F(START); 1323 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++) 1324 AES_cbc_encrypt(buf,buf, 1325 (unsigned long)lengths[j],&aes_ks2, 1326 iv,AES_ENCRYPT); 1327 d=Time_F(STOP); 1328 print_result(D_CBC_192_AES,j,count,d); 1329 } 1330 } 1331 #ifdef SOLARIS_OPENSSL 1332 if (doit[D_CBC_256_AES] && SUNWcry_installed) 1333 #else 1334 if (doit[D_CBC_256_AES]) 1335 #endif 1336 { 1337 for (j=0; j<SIZE_NUM; j++) 1338 { 1339 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]); 1340 Time_F(START); 1341 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++) 1342 AES_cbc_encrypt(buf,buf, 1343 (unsigned long)lengths[j],&aes_ks3, 1344 iv,AES_ENCRYPT); 1345 d=Time_F(STOP); 1346 print_result(D_CBC_256_AES,j,count,d); 1347 } 1348 } 1349 1350 #endif 1351 #ifndef OPENSSL_NO_IDEA 1352 if (doit[D_CBC_IDEA]) 1353 { 1354 for (j=0; j<SIZE_NUM; j++) 1355 { 1356 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]); 1357 Time_F(START); 1358 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++) 1359 idea_cbc_encrypt(buf,buf, 1360 (unsigned long)lengths[j],&idea_ks, 1361 iv,IDEA_ENCRYPT); 1362 d=Time_F(STOP); 1363 print_result(D_CBC_IDEA,j,count,d); 1364 } 1365 } 1366 #endif 1367 #ifndef OPENSSL_NO_RC2 1368 if (doit[D_CBC_RC2]) 1369 { 1370 for (j=0; j<SIZE_NUM; j++) 1371 { 1372 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]); 1373 Time_F(START); 1374 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++) 1375 RC2_cbc_encrypt(buf,buf, 1376 (unsigned long)lengths[j],&rc2_ks, 1377 iv,RC2_ENCRYPT); 1378 d=Time_F(STOP); 1379 print_result(D_CBC_RC2,j,count,d); 1380 } 1381 } 1382 #endif 1383 #ifndef OPENSSL_NO_RC5 1384 if (doit[D_CBC_RC5]) 1385 { 1386 for (j=0; j<SIZE_NUM; j++) 1387 { 1388 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]); 1389 Time_F(START); 1390 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++) 1391 RC5_32_cbc_encrypt(buf,buf, 1392 (unsigned long)lengths[j],&rc5_ks, 1393 iv,RC5_ENCRYPT); 1394 d=Time_F(STOP); 1395 print_result(D_CBC_RC5,j,count,d); 1396 } 1397 } 1398 #endif 1399 #ifndef OPENSSL_NO_BF 1400 if (doit[D_CBC_BF]) 1401 { 1402 for (j=0; j<SIZE_NUM; j++) 1403 { 1404 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]); 1405 Time_F(START); 1406 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++) 1407 BF_cbc_encrypt(buf,buf, 1408 (unsigned long)lengths[j],&bf_ks, 1409 iv,BF_ENCRYPT); 1410 d=Time_F(STOP); 1411 print_result(D_CBC_BF,j,count,d); 1412 } 1413 } 1414 #endif 1415 #ifndef OPENSSL_NO_CAST 1416 if (doit[D_CBC_CAST]) 1417 { 1418 for (j=0; j<SIZE_NUM; j++) 1419 { 1420 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]); 1421 Time_F(START); 1422 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++) 1423 CAST_cbc_encrypt(buf,buf, 1424 (unsigned long)lengths[j],&cast_ks, 1425 iv,CAST_ENCRYPT); 1426 d=Time_F(STOP); 1427 print_result(D_CBC_CAST,j,count,d); 1428 } 1429 } 1430 #endif 1431 1432 if (doit[D_EVP]) 1433 { 1434 for (j=0; j<SIZE_NUM; j++) 1435 { 1436 if (evp_cipher) 1437 { 1438 EVP_CIPHER_CTX ctx; 1439 int outl; 1440 1441 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid); 1442 /* -O3 -fschedule-insns messes up an 1443 * optimization here! names[D_EVP] 1444 * somehow becomes NULL */ 1445 print_message(names[D_EVP],save_count, 1446 lengths[j]); 1447 1448 EVP_CIPHER_CTX_init(&ctx); 1449 if(decrypt) 1450 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv); 1451 else 1452 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv); 1453 1454 Time_F(START); 1455 if(decrypt) 1456 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) 1457 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]); 1458 else 1459 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) 1460 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]); 1461 if(decrypt) 1462 EVP_DecryptFinal_ex(&ctx,buf,&outl); 1463 else 1464 EVP_EncryptFinal_ex(&ctx,buf,&outl); 1465 d=Time_F(STOP); 1466 EVP_CIPHER_CTX_cleanup(&ctx); 1467 } 1468 if (evp_md) 1469 { 1470 names[D_EVP]=OBJ_nid2ln(evp_md->type); 1471 print_message(names[D_EVP],save_count, 1472 lengths[j]); 1473 1474 Time_F(START); 1475 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++) 1476 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL); 1477 1478 d=Time_F(STOP); 1479 } 1480 print_result(D_EVP,j,count,d); 1481 } 1482 } 1483 1484 RAND_pseudo_bytes(buf,36); 1485 #ifndef OPENSSL_NO_RSA 1486 for (j=0; j<RSA_NUM; j++) 1487 { 1488 int ret; 1489 if (!rsa_doit[j]) continue; 1490 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]); 1491 if (ret == 0) 1492 { 1493 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n"); 1494 ERR_print_errors(bio_err); 1495 rsa_count=1; 1496 } 1497 else 1498 { 1499 pkey_print_message("private","rsa", 1500 rsa_c[j][0],rsa_bits[j], 1501 RSA_SECONDS); 1502 /* RSA_blinding_on(rsa_key[j],NULL); */ 1503 Time_F(START); 1504 for (count=0,run=1; COND(rsa_c[j][0]); count++) 1505 { 1506 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, 1507 &rsa_num, rsa_key[j]); 1508 if (ret == 0) 1509 { 1510 BIO_printf(bio_err, 1511 "RSA sign failure\n"); 1512 ERR_print_errors(bio_err); 1513 count=1; 1514 break; 1515 } 1516 } 1517 d=Time_F(STOP); 1518 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n" 1519 : "%ld %d bit private RSA's in %.2fs\n", 1520 count,rsa_bits[j],d); 1521 rsa_results[j][0]=d/(double)count; 1522 rsa_count=count; 1523 } 1524 1525 #if 1 1526 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]); 1527 if (ret <= 0) 1528 { 1529 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n"); 1530 ERR_print_errors(bio_err); 1531 rsa_doit[j] = 0; 1532 } 1533 else 1534 { 1535 pkey_print_message("public","rsa", 1536 rsa_c[j][1],rsa_bits[j], 1537 RSA_SECONDS); 1538 Time_F(START); 1539 for (count=0,run=1; COND(rsa_c[j][1]); count++) 1540 { 1541 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, 1542 rsa_num, rsa_key[j]); 1543 if (ret == 0) 1544 { 1545 BIO_printf(bio_err, 1546 "RSA verify failure\n"); 1547 ERR_print_errors(bio_err); 1548 count=1; 1549 break; 1550 } 1551 } 1552 d=Time_F(STOP); 1553 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n" 1554 : "%ld %d bit public RSA's in %.2fs\n", 1555 count,rsa_bits[j],d); 1556 rsa_results[j][1]=d/(double)count; 1557 } 1558 #endif 1559 1560 if (rsa_count <= 1) 1561 { 1562 /* if longer than 10s, don't do any more */ 1563 for (j++; j<RSA_NUM; j++) 1564 rsa_doit[j]=0; 1565 } 1566 } 1567 #endif 1568 1569 RAND_pseudo_bytes(buf,20); 1570 #ifndef OPENSSL_NO_DSA 1571 if (RAND_status() != 1) 1572 { 1573 RAND_seed(rnd_seed, sizeof rnd_seed); 1574 rnd_fake = 1; 1575 } 1576 for (j=0; j<DSA_NUM; j++) 1577 { 1578 unsigned int kk; 1579 int ret; 1580 1581 if (!dsa_doit[j]) continue; 1582 /* DSA_generate_key(dsa_key[j]); */ 1583 /* DSA_sign_setup(dsa_key[j],NULL); */ 1584 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, 1585 &kk,dsa_key[j]); 1586 if (ret == 0) 1587 { 1588 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n"); 1589 ERR_print_errors(bio_err); 1590 rsa_count=1; 1591 } 1592 else 1593 { 1594 pkey_print_message("sign","dsa", 1595 dsa_c[j][0],dsa_bits[j], 1596 DSA_SECONDS); 1597 Time_F(START); 1598 for (count=0,run=1; COND(dsa_c[j][0]); count++) 1599 { 1600 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2, 1601 &kk,dsa_key[j]); 1602 if (ret == 0) 1603 { 1604 BIO_printf(bio_err, 1605 "DSA sign failure\n"); 1606 ERR_print_errors(bio_err); 1607 count=1; 1608 break; 1609 } 1610 } 1611 d=Time_F(STOP); 1612 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n" 1613 : "%ld %d bit DSA signs in %.2fs\n", 1614 count,dsa_bits[j],d); 1615 dsa_results[j][0]=d/(double)count; 1616 rsa_count=count; 1617 } 1618 1619 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, 1620 kk,dsa_key[j]); 1621 if (ret <= 0) 1622 { 1623 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n"); 1624 ERR_print_errors(bio_err); 1625 dsa_doit[j] = 0; 1626 } 1627 else 1628 { 1629 pkey_print_message("verify","dsa", 1630 dsa_c[j][1],dsa_bits[j], 1631 DSA_SECONDS); 1632 Time_F(START); 1633 for (count=0,run=1; COND(dsa_c[j][1]); count++) 1634 { 1635 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2, 1636 kk,dsa_key[j]); 1637 if (ret <= 0) 1638 { 1639 BIO_printf(bio_err, 1640 "DSA verify failure\n"); 1641 ERR_print_errors(bio_err); 1642 count=1; 1643 break; 1644 } 1645 } 1646 d=Time_F(STOP); 1647 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n" 1648 : "%ld %d bit DSA verify in %.2fs\n", 1649 count,dsa_bits[j],d); 1650 dsa_results[j][1]=d/(double)count; 1651 } 1652 1653 if (rsa_count <= 1) 1654 { 1655 /* if longer than 10s, don't do any more */ 1656 for (j++; j<DSA_NUM; j++) 1657 dsa_doit[j]=0; 1658 } 1659 } 1660 if (rnd_fake) RAND_cleanup(); 1661 #endif 1662 #ifdef HAVE_FORK 1663 show_res: 1664 #endif 1665 if(!mr) 1666 { 1667 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION)); 1668 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON)); 1669 printf("options:"); 1670 printf("%s ",BN_options()); 1671 #ifndef OPENSSL_NO_MD2 1672 printf("%s ",MD2_options()); 1673 #endif 1674 #ifndef OPENSSL_NO_RC4 1675 printf("%s ",RC4_options()); 1676 #endif 1677 #ifndef OPENSSL_NO_DES 1678 printf("%s ",DES_options()); 1679 #endif 1680 #ifndef OPENSSL_NO_AES 1681 printf("%s ",AES_options()); 1682 #endif 1683 #ifndef OPENSSL_NO_IDEA 1684 printf("%s ",idea_options()); 1685 #endif 1686 #ifndef OPENSSL_NO_BF 1687 printf("%s ",BF_options()); 1688 #endif 1689 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS)); 1690 printf("available timing options: "); 1691 #ifdef TIMES 1692 printf("TIMES "); 1693 #endif 1694 #ifdef TIMEB 1695 printf("TIMEB "); 1696 #endif 1697 #ifdef USE_TOD 1698 printf("USE_TOD "); 1699 #endif 1700 #ifdef HZ 1701 #define as_string(s) (#s) 1702 printf("HZ=%g", (double)HZ); 1703 # ifdef _SC_CLK_TCK 1704 printf(" [sysconf value]"); 1705 # endif 1706 #endif 1707 printf("\n"); 1708 printf("timing function used: %s%s%s%s%s%s%s\n", 1709 (ftime_used ? "ftime" : ""), 1710 (ftime_used + times_used > 1 ? "," : ""), 1711 (times_used ? "times" : ""), 1712 (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""), 1713 (gettimeofday_used ? "gettimeofday" : ""), 1714 (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""), 1715 (getrusage_used ? "getrusage" : "")); 1716 } 1717 1718 if (pr_header) 1719 { 1720 if(mr) 1721 fprintf(stdout,"+H"); 1722 else 1723 { 1724 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); 1725 fprintf(stdout,"type "); 1726 } 1727 for (j=0; j<SIZE_NUM; j++) 1728 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]); 1729 fprintf(stdout,"\n"); 1730 } 1731 1732 for (k=0; k<ALGOR_NUM; k++) 1733 { 1734 if (!doit[k]) continue; 1735 #ifdef SOLARIS_OPENSSL 1736 if ((k == D_CBC_192_AES || k == D_CBC_256_AES) && !SUNWcry_installed) continue; 1737 #endif 1738 if(mr) 1739 fprintf(stdout,"+F:%d:%s",k,names[k]); 1740 else 1741 fprintf(stdout,"%-13s",names[k]); 1742 for (j=0; j<SIZE_NUM; j++) 1743 { 1744 if (results[k][j] > 10000 && !mr) 1745 fprintf(stdout," %11.2fk",results[k][j]/1e3); 1746 else 1747 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]); 1748 } 1749 fprintf(stdout,"\n"); 1750 } 1751 #ifndef OPENSSL_NO_RSA 1752 j=1; 1753 for (k=0; k<RSA_NUM; k++) 1754 { 1755 if (!rsa_doit[k]) continue; 1756 if (j && !mr) 1757 { 1758 printf("%18ssign verify sign/s verify/s\n"," "); 1759 j=0; 1760 } 1761 if(mr) 1762 fprintf(stdout,"+F2:%u:%u:%f:%f\n", 1763 k,rsa_bits[k],rsa_results[k][0], 1764 rsa_results[k][1]); 1765 else 1766 fprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\n", 1767 rsa_bits[k],rsa_results[k][0],rsa_results[k][1], 1768 1.0/rsa_results[k][0],1.0/rsa_results[k][1]); 1769 } 1770 #endif 1771 #ifndef OPENSSL_NO_DSA 1772 j=1; 1773 for (k=0; k<DSA_NUM; k++) 1774 { 1775 if (!dsa_doit[k]) continue; 1776 if (j && !mr) 1777 { 1778 printf("%18ssign verify sign/s verify/s\n"," "); 1779 j=0; 1780 } 1781 if(mr) 1782 fprintf(stdout,"+F3:%u:%u:%f:%f\n", 1783 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]); 1784 else 1785 fprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\n", 1786 dsa_bits[k],dsa_results[k][0],dsa_results[k][1], 1787 1.0/dsa_results[k][0],1.0/dsa_results[k][1]); 1788 } 1789 #endif 1790 mret=0; 1791 end: 1792 ERR_print_errors(bio_err); 1793 if (buf != NULL) OPENSSL_free(buf); 1794 if (buf2 != NULL) OPENSSL_free(buf2); 1795 #ifndef OPENSSL_NO_RSA 1796 for (i=0; i<RSA_NUM; i++) 1797 if (rsa_key[i] != NULL) 1798 RSA_free(rsa_key[i]); 1799 #endif 1800 #ifndef OPENSSL_NO_DSA 1801 for (i=0; i<DSA_NUM; i++) 1802 if (dsa_key[i] != NULL) 1803 DSA_free(dsa_key[i]); 1804 #endif 1805 apps_shutdown(); 1806 OPENSSL_EXIT(mret); 1807 } 1808 1809 static void print_message(const char *s, long num, int length) 1810 { 1811 #ifdef SIGALRM 1812 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n" 1813 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length); 1814 (void)BIO_flush(bio_err); 1815 alarm(SECONDS); 1816 #else 1817 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n" 1818 : "Doing %s %ld times on %d size blocks: ",s,num,length); 1819 (void)BIO_flush(bio_err); 1820 #endif 1821 #ifdef LINT 1822 num=num; 1823 #endif 1824 } 1825 1826 static void pkey_print_message(char *str, char *str2, long num, int bits, 1827 int tm) 1828 { 1829 #ifdef SIGALRM 1830 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n" 1831 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm); 1832 (void)BIO_flush(bio_err); 1833 alarm(RSA_SECONDS); 1834 #else 1835 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n" 1836 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2); 1837 (void)BIO_flush(bio_err); 1838 #endif 1839 #ifdef LINT 1840 num=num; 1841 #endif 1842 } 1843 1844 static void print_result(int alg,int run_no,int count,double time_used) 1845 { 1846 BIO_printf(bio_err,mr ? "+R:%ld:%s:%f\n" 1847 : "%ld %s's in %.2fs\n",count,names[alg],time_used); 1848 results[alg][run_no]=((double)count)/time_used*lengths[run_no]; 1849 } 1850 1851 static char *sstrsep(char **string, const char *delim) 1852 { 1853 char isdelim[256]; 1854 char *token = *string; 1855 1856 if (**string == 0) 1857 return NULL; 1858 1859 memset(isdelim, 0, sizeof isdelim); 1860 isdelim[0] = 1; 1861 1862 while (*delim) 1863 { 1864 isdelim[(unsigned char)(*delim)] = 1; 1865 delim++; 1866 } 1867 1868 while (!isdelim[(unsigned char)(**string)]) 1869 { 1870 (*string)++; 1871 } 1872 1873 if (**string) 1874 { 1875 **string = 0; 1876 (*string)++; 1877 } 1878 1879 return token; 1880 } 1881 1882 #ifdef HAVE_FORK 1883 static int do_multi(int multi) 1884 { 1885 int n; 1886 int fd[2]; 1887 int *fds; 1888 static char sep[]=":"; 1889 1890 fds=malloc(multi*sizeof *fds); 1891 for(n=0 ; n < multi ; ++n) 1892 { 1893 pipe(fd); 1894 if(fork()) 1895 { 1896 close(fd[1]); 1897 fds[n]=fd[0]; 1898 } 1899 else 1900 { 1901 close(fd[0]); 1902 close(1); 1903 dup(fd[1]); 1904 close(fd[1]); 1905 mr=1; 1906 usertime=0; 1907 return 0; 1908 } 1909 printf("Forked child %d\n",n); 1910 } 1911 1912 /* for now, assume the pipe is long enough to take all the output */ 1913 for(n=0 ; n < multi ; ++n) 1914 { 1915 FILE *f; 1916 char buf[1024]; 1917 char *p; 1918 1919 f=fdopen(fds[n],"r"); 1920 while(fgets(buf,sizeof buf,f)) 1921 { 1922 p=strchr(buf,'\n'); 1923 if(p) 1924 *p='\0'; 1925 if(buf[0] != '+') 1926 { 1927 fprintf(stderr,"Don't understand line '%s' from child %d\n", 1928 buf,n); 1929 continue; 1930 } 1931 printf("Got: %s from %d\n",buf,n); 1932 if(!strncmp(buf,"+F:",3)) 1933 { 1934 int alg; 1935 int j; 1936 1937 p=buf+3; 1938 alg=atoi(sstrsep(&p,sep)); 1939 sstrsep(&p,sep); 1940 for(j=0 ; j < SIZE_NUM ; ++j) 1941 results[alg][j]+=atof(sstrsep(&p,sep)); 1942 } 1943 else if(!strncmp(buf,"+F2:",4)) 1944 { 1945 int k; 1946 double d; 1947 1948 p=buf+4; 1949 k=atoi(sstrsep(&p,sep)); 1950 sstrsep(&p,sep); 1951 1952 d=atof(sstrsep(&p,sep)); 1953 if(n) 1954 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); 1955 else 1956 rsa_results[k][0]=d; 1957 1958 d=atof(sstrsep(&p,sep)); 1959 if(n) 1960 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); 1961 else 1962 rsa_results[k][1]=d; 1963 } 1964 else if(!strncmp(buf,"+F2:",4)) 1965 { 1966 int k; 1967 double d; 1968 1969 p=buf+4; 1970 k=atoi(sstrsep(&p,sep)); 1971 sstrsep(&p,sep); 1972 1973 d=atof(sstrsep(&p,sep)); 1974 if(n) 1975 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); 1976 else 1977 rsa_results[k][0]=d; 1978 1979 d=atof(sstrsep(&p,sep)); 1980 if(n) 1981 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); 1982 else 1983 rsa_results[k][1]=d; 1984 } 1985 else if(!strncmp(buf,"+F3:",4)) 1986 { 1987 int k; 1988 double d; 1989 1990 p=buf+4; 1991 k=atoi(sstrsep(&p,sep)); 1992 sstrsep(&p,sep); 1993 1994 d=atof(sstrsep(&p,sep)); 1995 if(n) 1996 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); 1997 else 1998 dsa_results[k][0]=d; 1999 2000 d=atof(sstrsep(&p,sep)); 2001 if(n) 2002 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); 2003 else 2004 dsa_results[k][1]=d; 2005 } 2006 else if(!strncmp(buf,"+H:",3)) 2007 { 2008 } 2009 else 2010 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); 2011 } 2012 } 2013 return 1; 2014 } 2015 #endif 2016 #endif 2017