1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
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.
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).
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.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
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)"
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
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.]
58 /* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
67 * The ECDH and ECDSA speed test software is originally written by
68 * Sumit Gupta of Sun Microsystems Laboratories.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
78 #define RSA_SECONDS 10
79 #define DSA_SECONDS 10
80 #define ECDSA_SECONDS 10
81 #define ECDH_SECONDS 10
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 */
87 #define PROG speed_main
95 #ifdef OPENSSL_NO_STDIO
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
107 #ifndef OPENSSL_SYS_NETWARE
111 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
113 #elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
116 #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 */
120 #if defined(OPENSSL_SYS_NETWARE)
130 # include <sys/types.h>
131 # include <sys/times.h>
134 # include <sys/time.h>
135 # include <sys/resource.h>
138 /* Depending on the VMS version, the tms structure is perhaps defined.
139 The __TMS macro will show if it was. If it wasn't defined, we should
140 undefine TIMES, since that tells the rest of the program how things
141 should be handled. -- Richard Levitte */
142 #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
147 #include <sys/timeb.h>
150 #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
151 #error "It seems neither struct tms nor struct timeb is supported in this platform!"
154 #if defined(sun) || defined(__ultrix)
155 #define _POSIX_SOURCE
157 #include <sys/param.h>
160 #include <openssl/bn.h>
161 #ifndef OPENSSL_NO_DES
162 #include <openssl/des.h>
164 #ifndef OPENSSL_NO_AES
165 #include <openssl/aes.h>
167 #ifndef OPENSSL_NO_CAMELLIA
168 #include <openssl/camellia.h>
170 #ifndef OPENSSL_NO_MD2
171 #include <openssl/md2.h>
173 #ifndef OPENSSL_NO_MDC2
174 #include <openssl/mdc2.h>
176 #ifndef OPENSSL_NO_MD4
177 #include <openssl/md4.h>
179 #ifndef OPENSSL_NO_MD5
180 #include <openssl/md5.h>
182 #ifndef OPENSSL_NO_HMAC
183 #include <openssl/hmac.h>
185 #include <openssl/evp.h>
186 #ifndef OPENSSL_NO_SHA
187 #include <openssl/sha.h>
189 #ifndef OPENSSL_NO_RIPEMD
190 #include <openssl/ripemd.h>
192 #ifndef OPENSSL_NO_RC4
193 #include <openssl/rc4.h>
195 #ifndef OPENSSL_NO_RC5
196 #include <openssl/rc5.h>
198 #ifndef OPENSSL_NO_RC2
199 #include <openssl/rc2.h>
201 #ifndef OPENSSL_NO_IDEA
202 #include <openssl/idea.h>
204 #ifndef OPENSSL_NO_SEED
205 #include <openssl/seed.h>
207 #ifndef OPENSSL_NO_BF
208 #include <openssl/blowfish.h>
210 #ifndef OPENSSL_NO_CAST
211 #include <openssl/cast.h>
213 #ifndef OPENSSL_NO_RSA
214 #include <openssl/rsa.h>
215 #include "./testrsa.h"
217 #include <openssl/x509.h>
218 #ifndef OPENSSL_NO_DSA
219 #include <openssl/dsa.h>
220 #include "./testdsa.h"
222 #ifndef OPENSSL_NO_ECDSA
223 #include <openssl/ecdsa.h>
225 #ifndef OPENSSL_NO_ECDH
226 #include <openssl/ecdh.h>
230 * The following "HZ" timing stuff should be sync'd up with the code in
231 * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
232 * this code is more up to date than libcrypto's so there may be features to
233 * migrate over first. This is used in two places further down AFAICS.
234 * The point is that nothing in openssl actually *uses* that tmdiff stuff, so
235 * either speed.c should be using it or it should go because it's obviously not
236 * useful enough. Anyone want to do a janitorial job on this?
239 /* The following if from times(3) man page. It may need to be changed */
241 # if defined(_SC_CLK_TCK) \
242 && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
243 # define HZ sysconf(_SC_CLK_TCK)
246 # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
248 # else /* _BSD_CLK_TCK_ */
249 # define HZ ((double)_BSD_CLK_TCK_)
252 # define HZ ((double)CLK_TCK)
257 #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE)
262 #define BUFSIZE ((long)1024*8+1)
265 static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0;
267 static int usertime=1;
269 static double Time_F(int s);
270 static void print_message(const char *s,long num,int length);
271 static void pkey_print_message(const char *str, const char *str2,
272 long num, int bits, int sec);
273 static void print_result(int alg,int run_no,int count,double time_used);
275 static int do_multi(int multi);
284 #define MAX_ECDH_SIZE 256
286 static const char *names[ALGOR_NUM]={
287 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
288 "des cbc","des ede3","idea cbc","seed cbc",
289 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
290 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
291 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
292 "evp","sha256","sha512",
293 "aes-128 ige","aes-192 ige","aes-256 ige"};
294 static double results[ALGOR_NUM][SIZE_NUM];
295 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
296 static double rsa_results[RSA_NUM][2];
297 static double dsa_results[DSA_NUM][2];
298 #ifndef OPENSSL_NO_ECDSA
299 static double ecdsa_results[EC_NUM][2];
301 #ifndef OPENSSL_NO_ECDH
302 static double ecdh_results[EC_NUM][1];
305 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
306 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
307 static int rnd_fake = 0;
311 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
312 #define SIGRETTYPE void
314 #define SIGRETTYPE int
317 static SIGRETTYPE sig_done(int sig);
318 static SIGRETTYPE sig_done(int sig)
320 signal(SIGALRM,sig_done);
331 #if defined(OPENSSL_SYS_NETWARE)
333 /* for NetWare the best we can do is use clock() which returns the
334 * time, in hundredths of a second, since the NLM began executing
336 static double Time_F(int s)
340 static clock_t tstart,tend;
350 ret=(double)((double)(tend)-(double)(tstart));
351 return((ret < 0.001)?0.001:ret);
357 static double Time_F(int s)
364 static struct rusage tstart,tend;
369 getrusage(RUSAGE_SELF,&tstart);
376 getrusage(RUSAGE_SELF,&tend);
377 i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
378 ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
379 +((double)i)/1000000.0;
380 return((ret < 0.001)?0.001:ret);
385 static struct timeval tstart,tend;
388 gettimeofday_used = 1;
391 gettimeofday(&tstart,NULL);
396 gettimeofday(&tend,NULL);
397 i=(long)tend.tv_usec-(long)tstart.tv_usec;
398 ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
399 return((ret < 0.001)?0.001:ret);
402 #else /* ndef USE_TOD */
407 static struct tms tstart,tend;
419 ret=(double)(tend.tms_utime-tstart.tms_utime) / ret;
420 return((ret < 1e-3)?1e-3:ret);
423 # endif /* times() */
424 # if defined(TIMES) && defined(TIMEB)
427 # ifdef OPENSSL_SYS_VXWORKS
429 static unsigned long tick_start, tick_end;
433 tick_start = tickGet();
438 tick_end = tickGet();
439 ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
440 return((ret < 0.001)?0.001:ret);
443 # elif defined(TIMEB)
445 static struct timeb tstart,tend;
457 i=(long)tend.millitm-(long)tstart.millitm;
458 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
459 return((ret < 0.001)?0.001:ret);
465 #endif /* if defined(OPENSSL_SYS_NETWARE) */
468 #ifndef OPENSSL_NO_ECDH
469 static const int KDF1_SHA1_len = 20;
470 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
472 #ifndef OPENSSL_NO_SHA
473 if (*outlen < SHA_DIGEST_LENGTH)
476 *outlen = SHA_DIGEST_LENGTH;
477 return SHA1(in, inlen, out);
480 #endif /* OPENSSL_NO_SHA */
482 #endif /* OPENSSL_NO_ECDH */
485 int MAIN(int, char **);
487 int MAIN(int argc, char **argv)
489 #ifndef OPENSSL_NO_ENGINE
492 unsigned char *buf=NULL,*buf2=NULL;
494 long count=0,save_count=0;
496 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
499 #ifndef OPENSSL_NO_RSA
502 unsigned char md[EVP_MAX_MD_SIZE];
503 #ifndef OPENSSL_NO_MD2
504 unsigned char md2[MD2_DIGEST_LENGTH];
506 #ifndef OPENSSL_NO_MDC2
507 unsigned char mdc2[MDC2_DIGEST_LENGTH];
509 #ifndef OPENSSL_NO_MD4
510 unsigned char md4[MD4_DIGEST_LENGTH];
512 #ifndef OPENSSL_NO_MD5
513 unsigned char md5[MD5_DIGEST_LENGTH];
514 unsigned char hmac[MD5_DIGEST_LENGTH];
516 #ifndef OPENSSL_NO_SHA
517 unsigned char sha[SHA_DIGEST_LENGTH];
518 #ifndef OPENSSL_NO_SHA256
519 unsigned char sha256[SHA256_DIGEST_LENGTH];
521 #ifndef OPENSSL_NO_SHA512
522 unsigned char sha512[SHA512_DIGEST_LENGTH];
525 #ifndef OPENSSL_NO_RIPEMD
526 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
528 #ifndef OPENSSL_NO_RC4
531 #ifndef OPENSSL_NO_RC5
534 #ifndef OPENSSL_NO_RC2
537 #ifndef OPENSSL_NO_IDEA
538 IDEA_KEY_SCHEDULE idea_ks;
540 #ifndef OPENSSL_NO_SEED
541 SEED_KEY_SCHEDULE seed_ks;
543 #ifndef OPENSSL_NO_BF
546 #ifndef OPENSSL_NO_CAST
549 static const unsigned char key16[16]=
550 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
551 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
552 #ifndef OPENSSL_NO_AES
553 static const unsigned char key24[24]=
554 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
555 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
556 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
557 static const unsigned char key32[32]=
558 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
559 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
560 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
561 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
563 #ifndef OPENSSL_NO_CAMELLIA
564 static const unsigned char ckey24[24]=
565 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
566 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
567 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
568 static const unsigned char ckey32[32]=
569 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
570 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
571 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
572 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
574 #ifndef OPENSSL_NO_AES
575 #define MAX_BLOCK_SIZE 128
577 #define MAX_BLOCK_SIZE 64
579 unsigned char DES_iv[8];
580 unsigned char iv[2*MAX_BLOCK_SIZE/8];
581 #ifndef OPENSSL_NO_DES
582 DES_cblock *buf_as_des_cblock = NULL;
583 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
584 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
585 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
586 DES_key_schedule sch;
587 DES_key_schedule sch2;
588 DES_key_schedule sch3;
590 #ifndef OPENSSL_NO_AES
591 AES_KEY aes_ks1, aes_ks2, aes_ks3;
593 #ifndef OPENSSL_NO_CAMELLIA
594 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
606 #define D_CBC_IDEA 10
607 #define D_CBC_SEED 11
611 #define D_CBC_CAST 15
612 #define D_CBC_128_AES 16
613 #define D_CBC_192_AES 17
614 #define D_CBC_256_AES 18
615 #define D_CBC_128_CML 19
616 #define D_CBC_192_CML 20
617 #define D_CBC_256_CML 21
621 #define D_IGE_128_AES 25
622 #define D_IGE_192_AES 26
623 #define D_IGE_256_AES 27
625 long c[ALGOR_NUM][SIZE_NUM];
651 #ifndef OPENSSL_NO_RSA
652 RSA *rsa_key[RSA_NUM];
653 long rsa_c[RSA_NUM][2];
654 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
655 static unsigned char *rsa_data[RSA_NUM]=
656 {test512,test1024,test2048,test4096};
657 static int rsa_data_length[RSA_NUM]={
658 sizeof(test512),sizeof(test1024),
659 sizeof(test2048),sizeof(test4096)};
661 #ifndef OPENSSL_NO_DSA
662 DSA *dsa_key[DSA_NUM];
663 long dsa_c[DSA_NUM][2];
664 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
666 #ifndef OPENSSL_NO_EC
667 /* We only test over the following curves as they are representative,
668 * To add tests over more curves, simply add the curve NID
669 * and curve name to the following arrays and increase the
670 * EC_NUM value accordingly.
672 static unsigned int test_curves[EC_NUM] =
676 NID_X9_62_prime192v1,
678 NID_X9_62_prime256v1,
693 static const char * test_curves_names[EC_NUM] =
714 static int test_curves_bits[EC_NUM] =
716 160, 192, 224, 256, 384, 521,
717 163, 233, 283, 409, 571,
718 163, 233, 283, 409, 571
723 #ifndef OPENSSL_NO_ECDSA
724 unsigned char ecdsasig[256];
725 unsigned int ecdsasiglen;
726 EC_KEY *ecdsa[EC_NUM];
727 long ecdsa_c[EC_NUM][2];
730 #ifndef OPENSSL_NO_ECDH
731 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
732 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
733 int secret_size_a, secret_size_b;
736 long ecdh_c[EC_NUM][2];
739 int rsa_doit[RSA_NUM];
740 int dsa_doit[DSA_NUM];
741 #ifndef OPENSSL_NO_ECDSA
742 int ecdsa_doit[EC_NUM];
744 #ifndef OPENSSL_NO_ECDH
745 int ecdh_doit[EC_NUM];
749 const EVP_CIPHER *evp_cipher=NULL;
750 const EVP_MD *evp_md=NULL;
761 memset(results, 0, sizeof(results));
762 #ifndef OPENSSL_NO_DSA
763 memset(dsa_key,0,sizeof(dsa_key));
765 #ifndef OPENSSL_NO_ECDSA
766 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
768 #ifndef OPENSSL_NO_ECDH
769 for (i=0; i<EC_NUM; i++)
778 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
779 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
781 if (!load_config(bio_err, NULL))
784 #ifndef OPENSSL_NO_RSA
785 memset(rsa_key,0,sizeof(rsa_key));
786 for (i=0; i<RSA_NUM; i++)
790 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
792 BIO_printf(bio_err,"out of memory\n");
795 #ifndef OPENSSL_NO_DES
796 buf_as_des_cblock = (DES_cblock *)buf;
798 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
800 BIO_printf(bio_err,"out of memory\n");
804 memset(c,0,sizeof(c));
805 memset(DES_iv,0,sizeof(DES_iv));
806 memset(iv,0,sizeof(iv));
808 for (i=0; i<ALGOR_NUM; i++)
810 for (i=0; i<RSA_NUM; i++)
812 for (i=0; i<DSA_NUM; i++)
814 #ifndef OPENSSL_NO_ECDSA
815 for (i=0; i<EC_NUM; i++)
818 #ifndef OPENSSL_NO_ECDH
819 for (i=0; i<EC_NUM; i++)
829 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
832 j--; /* Otherwise, -elapsed gets confused with
835 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
841 BIO_printf(bio_err,"no EVP given\n");
844 evp_cipher=EVP_get_cipherbyname(*argv);
847 evp_md=EVP_get_digestbyname(*argv);
849 if(!evp_cipher && !evp_md)
851 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
856 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
859 j--; /* Otherwise, -elapsed gets confused with
862 #ifndef OPENSSL_NO_ENGINE
863 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
869 BIO_printf(bio_err,"no engine given\n");
872 e = setup_engine(bio_err, *argv, 0);
873 /* j will be increased again further down. We just
874 don't want speed to confuse an engine with an
875 algorithm, especially when none is given (which
876 means all of them should be run) */
881 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
887 BIO_printf(bio_err,"no multi count given\n");
893 BIO_printf(bio_err,"bad multi count\n");
896 j--; /* Otherwise, -mr gets confused with
900 else if (argc > 0 && !strcmp(*argv,"-mr"))
903 j--; /* Otherwise, -mr gets confused with
907 #ifndef OPENSSL_NO_MD2
908 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
911 #ifndef OPENSSL_NO_MDC2
912 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
915 #ifndef OPENSSL_NO_MD4
916 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
919 #ifndef OPENSSL_NO_MD5
920 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
923 #ifndef OPENSSL_NO_MD5
924 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
927 #ifndef OPENSSL_NO_SHA
928 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
930 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
934 #ifndef OPENSSL_NO_SHA256
935 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
938 #ifndef OPENSSL_NO_SHA512
939 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
943 #ifndef OPENSSL_NO_RIPEMD
944 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
946 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
948 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
951 #ifndef OPENSSL_NO_RC4
952 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
955 #ifndef OPENSSL_NO_DES
956 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
957 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
960 #ifndef OPENSSL_NO_AES
961 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
962 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
963 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
964 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
965 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
966 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
969 #ifndef OPENSSL_NO_CAMELLIA
970 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
971 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
972 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
975 #ifndef OPENSSL_NO_RSA
976 #if 0 /* was: #ifdef RSAref */
977 if (strcmp(*argv,"rsaref") == 0)
979 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
985 if (strcmp(*argv,"openssl") == 0)
987 RSA_set_default_method(RSA_PKCS1_SSLeay());
992 #endif /* !OPENSSL_NO_RSA */
993 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
994 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
995 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
996 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
997 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
998 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
999 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
1001 #ifndef OPENSSL_NO_RC2
1002 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
1003 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
1006 #ifndef OPENSSL_NO_RC5
1007 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
1008 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
1011 #ifndef OPENSSL_NO_IDEA
1012 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
1013 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
1016 #ifndef OPENSSL_NO_SEED
1017 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
1018 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
1021 #ifndef OPENSSL_NO_BF
1022 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
1023 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
1024 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
1027 #ifndef OPENSSL_NO_CAST
1028 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
1029 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
1030 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
1033 #ifndef OPENSSL_NO_DES
1034 if (strcmp(*argv,"des") == 0)
1041 #ifndef OPENSSL_NO_AES
1042 if (strcmp(*argv,"aes") == 0)
1044 doit[D_CBC_128_AES]=1;
1045 doit[D_CBC_192_AES]=1;
1046 doit[D_CBC_256_AES]=1;
1050 #ifndef OPENSSL_NO_CAMELLIA
1051 if (strcmp(*argv,"camellia") == 0)
1053 doit[D_CBC_128_CML]=1;
1054 doit[D_CBC_192_CML]=1;
1055 doit[D_CBC_256_CML]=1;
1059 #ifndef OPENSSL_NO_RSA
1060 if (strcmp(*argv,"rsa") == 0)
1062 rsa_doit[R_RSA_512]=1;
1063 rsa_doit[R_RSA_1024]=1;
1064 rsa_doit[R_RSA_2048]=1;
1065 rsa_doit[R_RSA_4096]=1;
1069 #ifndef OPENSSL_NO_DSA
1070 if (strcmp(*argv,"dsa") == 0)
1072 dsa_doit[R_DSA_512]=1;
1073 dsa_doit[R_DSA_1024]=1;
1074 dsa_doit[R_DSA_2048]=1;
1078 #ifndef OPENSSL_NO_ECDSA
1079 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
1080 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
1081 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
1082 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
1083 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
1084 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
1085 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
1086 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
1087 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
1088 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
1089 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
1090 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
1091 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
1092 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
1093 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
1094 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
1095 else if (strcmp(*argv,"ecdsa") == 0)
1097 for (i=0; i < EC_NUM; i++)
1102 #ifndef OPENSSL_NO_ECDH
1103 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1104 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1105 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1106 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1107 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1108 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1109 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1110 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1111 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1112 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1113 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1114 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1115 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1116 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1117 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1118 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1119 else if (strcmp(*argv,"ecdh") == 0)
1121 for (i=0; i < EC_NUM; i++)
1127 BIO_printf(bio_err,"Error: bad option or value\n");
1128 BIO_printf(bio_err,"\n");
1129 BIO_printf(bio_err,"Available values:\n");
1130 #ifndef OPENSSL_NO_MD2
1131 BIO_printf(bio_err,"md2 ");
1133 #ifndef OPENSSL_NO_MDC2
1134 BIO_printf(bio_err,"mdc2 ");
1136 #ifndef OPENSSL_NO_MD4
1137 BIO_printf(bio_err,"md4 ");
1139 #ifndef OPENSSL_NO_MD5
1140 BIO_printf(bio_err,"md5 ");
1141 #ifndef OPENSSL_NO_HMAC
1142 BIO_printf(bio_err,"hmac ");
1145 #ifndef OPENSSL_NO_SHA1
1146 BIO_printf(bio_err,"sha1 ");
1148 #ifndef OPENSSL_NO_SHA256
1149 BIO_printf(bio_err,"sha256 ");
1151 #ifndef OPENSSL_NO_SHA512
1152 BIO_printf(bio_err,"sha512 ");
1154 #ifndef OPENSSL_NO_RIPEMD160
1155 BIO_printf(bio_err,"rmd160");
1157 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1158 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1159 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
1160 BIO_printf(bio_err,"\n");
1163 #ifndef OPENSSL_NO_IDEA
1164 BIO_printf(bio_err,"idea-cbc ");
1166 #ifndef OPENSSL_NO_SEED
1167 BIO_printf(bio_err,"seed-cbc ");
1169 #ifndef OPENSSL_NO_RC2
1170 BIO_printf(bio_err,"rc2-cbc ");
1172 #ifndef OPENSSL_NO_RC5
1173 BIO_printf(bio_err,"rc5-cbc ");
1175 #ifndef OPENSSL_NO_BF
1176 BIO_printf(bio_err,"bf-cbc");
1178 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1179 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1180 BIO_printf(bio_err,"\n");
1182 #ifndef OPENSSL_NO_DES
1183 BIO_printf(bio_err,"des-cbc des-ede3 ");
1185 #ifndef OPENSSL_NO_AES
1186 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1187 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1189 #ifndef OPENSSL_NO_CAMELLIA
1190 BIO_printf(bio_err,"\n");
1191 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1193 #ifndef OPENSSL_NO_RC4
1194 BIO_printf(bio_err,"rc4");
1196 BIO_printf(bio_err,"\n");
1198 #ifndef OPENSSL_NO_RSA
1199 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1202 #ifndef OPENSSL_NO_DSA
1203 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1205 #ifndef OPENSSL_NO_ECDSA
1206 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1207 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1208 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1209 BIO_printf(bio_err,"ecdsa\n");
1211 #ifndef OPENSSL_NO_ECDH
1212 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1213 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1214 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1215 BIO_printf(bio_err,"ecdh\n");
1218 #ifndef OPENSSL_NO_IDEA
1219 BIO_printf(bio_err,"idea ");
1221 #ifndef OPENSSL_NO_SEED
1222 BIO_printf(bio_err,"seed ");
1224 #ifndef OPENSSL_NO_RC2
1225 BIO_printf(bio_err,"rc2 ");
1227 #ifndef OPENSSL_NO_DES
1228 BIO_printf(bio_err,"des ");
1230 #ifndef OPENSSL_NO_AES
1231 BIO_printf(bio_err,"aes ");
1233 #ifndef OPENSSL_NO_CAMELLIA
1234 BIO_printf(bio_err,"camellia ");
1236 #ifndef OPENSSL_NO_RSA
1237 BIO_printf(bio_err,"rsa ");
1239 #ifndef OPENSSL_NO_BF
1240 BIO_printf(bio_err,"blowfish");
1242 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1243 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1244 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1245 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1246 BIO_printf(bio_err,"\n");
1249 BIO_printf(bio_err,"\n");
1250 BIO_printf(bio_err,"Available options:\n");
1251 #if defined(TIMES) || defined(USE_TOD)
1252 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1254 #ifndef OPENSSL_NO_ENGINE
1255 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1257 BIO_printf(bio_err,"-evp e use EVP e.\n");
1258 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1259 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1261 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1271 if(multi && do_multi(multi))
1277 for (i=0; i<ALGOR_NUM; i++)
1282 for (i=0; i<RSA_NUM; i++)
1284 for (i=0; i<DSA_NUM; i++)
1287 for (i=0; i<ALGOR_NUM; i++)
1288 if (doit[i]) pr_header++;
1290 if (usertime == 0 && !mr)
1291 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1292 if (usertime <= 0 && !mr)
1294 BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
1295 BIO_printf(bio_err,"program when this computer is idle.\n");
1298 #ifndef OPENSSL_NO_RSA
1299 for (i=0; i<RSA_NUM; i++)
1301 const unsigned char *p;
1304 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1305 if (rsa_key[i] == NULL)
1307 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1313 BIO_printf(bio_err,mr ? "+RK:%d:"
1314 : "Loaded RSA key, %d bit modulus and e= 0x",
1315 BN_num_bits(rsa_key[i]->n));
1316 BN_print(bio_err,rsa_key[i]->e);
1317 BIO_printf(bio_err,"\n");
1323 #ifndef OPENSSL_NO_DSA
1324 dsa_key[0]=get_dsa512();
1325 dsa_key[1]=get_dsa1024();
1326 dsa_key[2]=get_dsa2048();
1329 #ifndef OPENSSL_NO_DES
1330 DES_set_key_unchecked(&key,&sch);
1331 DES_set_key_unchecked(&key2,&sch2);
1332 DES_set_key_unchecked(&key3,&sch3);
1334 #ifndef OPENSSL_NO_AES
1335 AES_set_encrypt_key(key16,128,&aes_ks1);
1336 AES_set_encrypt_key(key24,192,&aes_ks2);
1337 AES_set_encrypt_key(key32,256,&aes_ks3);
1339 #ifndef OPENSSL_NO_CAMELLIA
1340 Camellia_set_key(key16,128,&camellia_ks1);
1341 Camellia_set_key(ckey24,192,&camellia_ks2);
1342 Camellia_set_key(ckey32,256,&camellia_ks3);
1344 #ifndef OPENSSL_NO_IDEA
1345 idea_set_encrypt_key(key16,&idea_ks);
1347 #ifndef OPENSSL_NO_SEED
1348 SEED_set_key(key16,&seed_ks);
1350 #ifndef OPENSSL_NO_RC4
1351 RC4_set_key(&rc4_ks,16,key16);
1353 #ifndef OPENSSL_NO_RC2
1354 RC2_set_key(&rc2_ks,16,key16,128);
1356 #ifndef OPENSSL_NO_RC5
1357 RC5_32_set_key(&rc5_ks,16,key16,12);
1359 #ifndef OPENSSL_NO_BF
1360 BF_set_key(&bf_ks,16,key16);
1362 #ifndef OPENSSL_NO_CAST
1363 CAST_set_key(&cast_ks,16,key16);
1365 #ifndef OPENSSL_NO_RSA
1366 memset(rsa_c,0,sizeof(rsa_c));
1369 #ifndef OPENSSL_NO_DES
1370 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1376 for (it=count; it; it--)
1377 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
1382 c[D_MD2][0]=count/10;
1383 c[D_MDC2][0]=count/10;
1388 c[D_RMD160][0]=count;
1389 c[D_RC4][0]=count*5;
1390 c[D_CBC_DES][0]=count;
1391 c[D_EDE3_DES][0]=count/3;
1392 c[D_CBC_IDEA][0]=count;
1393 c[D_CBC_SEED][0]=count;
1394 c[D_CBC_RC2][0]=count;
1395 c[D_CBC_RC5][0]=count;
1396 c[D_CBC_BF][0]=count;
1397 c[D_CBC_CAST][0]=count;
1398 c[D_CBC_128_AES][0]=count;
1399 c[D_CBC_192_AES][0]=count;
1400 c[D_CBC_256_AES][0]=count;
1401 c[D_CBC_128_CML][0]=count;
1402 c[D_CBC_192_CML][0]=count;
1403 c[D_CBC_256_CML][0]=count;
1404 c[D_SHA256][0]=count;
1405 c[D_SHA512][0]=count;
1406 c[D_IGE_128_AES][0]=count;
1407 c[D_IGE_192_AES][0]=count;
1408 c[D_IGE_256_AES][0]=count;
1410 for (i=1; i<SIZE_NUM; i++)
1412 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1413 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1414 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1415 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1416 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1417 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1418 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1419 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1420 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1422 for (i=1; i<SIZE_NUM; i++)
1426 l0=(long)lengths[i-1];
1427 l1=(long)lengths[i];
1428 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1429 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1430 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1431 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1432 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1433 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1434 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1435 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1436 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1437 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1438 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1439 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1440 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1441 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1442 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1443 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1444 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1445 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1447 #ifndef OPENSSL_NO_RSA
1448 rsa_c[R_RSA_512][0]=count/2000;
1449 rsa_c[R_RSA_512][1]=count/400;
1450 for (i=1; i<RSA_NUM; i++)
1452 rsa_c[i][0]=rsa_c[i-1][0]/8;
1453 rsa_c[i][1]=rsa_c[i-1][1]/4;
1454 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1458 if (rsa_c[i][0] == 0)
1467 #ifndef OPENSSL_NO_DSA
1468 dsa_c[R_DSA_512][0]=count/1000;
1469 dsa_c[R_DSA_512][1]=count/1000/2;
1470 for (i=1; i<DSA_NUM; i++)
1472 dsa_c[i][0]=dsa_c[i-1][0]/4;
1473 dsa_c[i][1]=dsa_c[i-1][1]/4;
1474 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1487 #ifndef OPENSSL_NO_ECDSA
1488 ecdsa_c[R_EC_P160][0]=count/1000;
1489 ecdsa_c[R_EC_P160][1]=count/1000/2;
1490 for (i=R_EC_P192; i<=R_EC_P521; i++)
1492 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1493 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1494 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1498 if (ecdsa_c[i] == 0)
1505 ecdsa_c[R_EC_K163][0]=count/1000;
1506 ecdsa_c[R_EC_K163][1]=count/1000/2;
1507 for (i=R_EC_K233; i<=R_EC_K571; i++)
1509 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1510 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1511 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1515 if (ecdsa_c[i] == 0)
1522 ecdsa_c[R_EC_B163][0]=count/1000;
1523 ecdsa_c[R_EC_B163][1]=count/1000/2;
1524 for (i=R_EC_B233; i<=R_EC_B571; i++)
1526 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1527 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1528 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1532 if (ecdsa_c[i] == 0)
1541 #ifndef OPENSSL_NO_ECDH
1542 ecdh_c[R_EC_P160][0]=count/1000;
1543 ecdh_c[R_EC_P160][1]=count/1000;
1544 for (i=R_EC_P192; i<=R_EC_P521; i++)
1546 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1547 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1548 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1559 ecdh_c[R_EC_K163][0]=count/1000;
1560 ecdh_c[R_EC_K163][1]=count/1000;
1561 for (i=R_EC_K233; i<=R_EC_K571; i++)
1563 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1564 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1565 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1576 ecdh_c[R_EC_B163][0]=count/1000;
1577 ecdh_c[R_EC_B163][1]=count/1000;
1578 for (i=R_EC_B233; i<=R_EC_B571; i++)
1580 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1581 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1582 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1595 #define COND(d) (count < (d))
1596 #define COUNT(d) (d)
1598 /* not worth fixing */
1599 # error "You cannot disable DES on systems without SIGALRM."
1600 #endif /* OPENSSL_NO_DES */
1602 #define COND(c) (run)
1603 #define COUNT(d) (count)
1604 signal(SIGALRM,sig_done);
1605 #endif /* SIGALRM */
1607 #ifndef OPENSSL_NO_MD2
1610 for (j=0; j<SIZE_NUM; j++)
1612 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1614 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1615 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1617 print_result(D_MD2,j,count,d);
1621 #ifndef OPENSSL_NO_MDC2
1624 for (j=0; j<SIZE_NUM; j++)
1626 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1628 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1629 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1631 print_result(D_MDC2,j,count,d);
1636 #ifndef OPENSSL_NO_MD4
1639 for (j=0; j<SIZE_NUM; j++)
1641 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1643 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1644 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1646 print_result(D_MD4,j,count,d);
1651 #ifndef OPENSSL_NO_MD5
1654 for (j=0; j<SIZE_NUM; j++)
1656 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1658 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1659 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1661 print_result(D_MD5,j,count,d);
1666 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1671 HMAC_CTX_init(&hctx);
1672 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1673 16,EVP_md5(), NULL);
1675 for (j=0; j<SIZE_NUM; j++)
1677 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1679 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1681 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1682 HMAC_Update(&hctx,buf,lengths[j]);
1683 HMAC_Final(&hctx,&(hmac[0]),NULL);
1686 print_result(D_HMAC,j,count,d);
1688 HMAC_CTX_cleanup(&hctx);
1691 #ifndef OPENSSL_NO_SHA
1694 for (j=0; j<SIZE_NUM; j++)
1696 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1698 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1699 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1701 print_result(D_SHA1,j,count,d);
1705 #ifndef OPENSSL_NO_SHA256
1708 for (j=0; j<SIZE_NUM; j++)
1710 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1712 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1713 SHA256(buf,lengths[j],sha256);
1715 print_result(D_SHA256,j,count,d);
1720 #ifndef OPENSSL_NO_SHA512
1723 for (j=0; j<SIZE_NUM; j++)
1725 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1727 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1728 SHA512(buf,lengths[j],sha512);
1730 print_result(D_SHA512,j,count,d);
1736 #ifndef OPENSSL_NO_RIPEMD
1739 for (j=0; j<SIZE_NUM; j++)
1741 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1743 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1744 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1746 print_result(D_RMD160,j,count,d);
1750 #ifndef OPENSSL_NO_RC4
1753 for (j=0; j<SIZE_NUM; j++)
1755 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1757 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1758 RC4(&rc4_ks,(unsigned int)lengths[j],
1761 print_result(D_RC4,j,count,d);
1765 #ifndef OPENSSL_NO_DES
1766 if (doit[D_CBC_DES])
1768 for (j=0; j<SIZE_NUM; j++)
1770 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1772 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1773 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1774 &DES_iv,DES_ENCRYPT);
1776 print_result(D_CBC_DES,j,count,d);
1780 if (doit[D_EDE3_DES])
1782 for (j=0; j<SIZE_NUM; j++)
1784 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1786 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1787 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1789 &DES_iv,DES_ENCRYPT);
1791 print_result(D_EDE3_DES,j,count,d);
1795 #ifndef OPENSSL_NO_AES
1796 if (doit[D_CBC_128_AES])
1798 for (j=0; j<SIZE_NUM; j++)
1800 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1802 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1803 AES_cbc_encrypt(buf,buf,
1804 (unsigned long)lengths[j],&aes_ks1,
1807 print_result(D_CBC_128_AES,j,count,d);
1810 if (doit[D_CBC_192_AES])
1812 for (j=0; j<SIZE_NUM; j++)
1814 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1816 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1817 AES_cbc_encrypt(buf,buf,
1818 (unsigned long)lengths[j],&aes_ks2,
1821 print_result(D_CBC_192_AES,j,count,d);
1824 if (doit[D_CBC_256_AES])
1826 for (j=0; j<SIZE_NUM; j++)
1828 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1830 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1831 AES_cbc_encrypt(buf,buf,
1832 (unsigned long)lengths[j],&aes_ks3,
1835 print_result(D_CBC_256_AES,j,count,d);
1839 if (doit[D_IGE_128_AES])
1841 for (j=0; j<SIZE_NUM; j++)
1843 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1845 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1846 AES_ige_encrypt(buf,buf2,
1847 (unsigned long)lengths[j],&aes_ks1,
1850 print_result(D_IGE_128_AES,j,count,d);
1853 if (doit[D_IGE_192_AES])
1855 for (j=0; j<SIZE_NUM; j++)
1857 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1859 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1860 AES_ige_encrypt(buf,buf2,
1861 (unsigned long)lengths[j],&aes_ks2,
1864 print_result(D_IGE_192_AES,j,count,d);
1867 if (doit[D_IGE_256_AES])
1869 for (j=0; j<SIZE_NUM; j++)
1871 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1873 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1874 AES_ige_encrypt(buf,buf2,
1875 (unsigned long)lengths[j],&aes_ks3,
1878 print_result(D_IGE_256_AES,j,count,d);
1882 #ifndef OPENSSL_NO_CAMELLIA
1883 if (doit[D_CBC_128_CML])
1885 for (j=0; j<SIZE_NUM; j++)
1887 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1889 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1890 Camellia_cbc_encrypt(buf,buf,
1891 (unsigned long)lengths[j],&camellia_ks1,
1892 iv,CAMELLIA_ENCRYPT);
1894 print_result(D_CBC_128_CML,j,count,d);
1897 if (doit[D_CBC_192_CML])
1899 for (j=0; j<SIZE_NUM; j++)
1901 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1903 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1904 Camellia_cbc_encrypt(buf,buf,
1905 (unsigned long)lengths[j],&camellia_ks2,
1906 iv,CAMELLIA_ENCRYPT);
1908 print_result(D_CBC_192_CML,j,count,d);
1911 if (doit[D_CBC_256_CML])
1913 for (j=0; j<SIZE_NUM; j++)
1915 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1917 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1918 Camellia_cbc_encrypt(buf,buf,
1919 (unsigned long)lengths[j],&camellia_ks3,
1920 iv,CAMELLIA_ENCRYPT);
1922 print_result(D_CBC_256_CML,j,count,d);
1927 #ifndef OPENSSL_NO_IDEA
1928 if (doit[D_CBC_IDEA])
1930 for (j=0; j<SIZE_NUM; j++)
1932 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1934 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1935 idea_cbc_encrypt(buf,buf,
1936 (unsigned long)lengths[j],&idea_ks,
1939 print_result(D_CBC_IDEA,j,count,d);
1943 #ifndef OPENSSL_NO_SEED
1944 if (doit[D_CBC_SEED])
1946 for (j=0; j<SIZE_NUM; j++)
1948 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1950 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1951 SEED_cbc_encrypt(buf,buf,
1952 (unsigned long)lengths[j],&seed_ks,iv,1);
1954 print_result(D_CBC_SEED,j,count,d);
1958 #ifndef OPENSSL_NO_RC2
1959 if (doit[D_CBC_RC2])
1961 for (j=0; j<SIZE_NUM; j++)
1963 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1965 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1966 RC2_cbc_encrypt(buf,buf,
1967 (unsigned long)lengths[j],&rc2_ks,
1970 print_result(D_CBC_RC2,j,count,d);
1974 #ifndef OPENSSL_NO_RC5
1975 if (doit[D_CBC_RC5])
1977 for (j=0; j<SIZE_NUM; j++)
1979 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1981 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1982 RC5_32_cbc_encrypt(buf,buf,
1983 (unsigned long)lengths[j],&rc5_ks,
1986 print_result(D_CBC_RC5,j,count,d);
1990 #ifndef OPENSSL_NO_BF
1993 for (j=0; j<SIZE_NUM; j++)
1995 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1997 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1998 BF_cbc_encrypt(buf,buf,
1999 (unsigned long)lengths[j],&bf_ks,
2002 print_result(D_CBC_BF,j,count,d);
2006 #ifndef OPENSSL_NO_CAST
2007 if (doit[D_CBC_CAST])
2009 for (j=0; j<SIZE_NUM; j++)
2011 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
2013 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
2014 CAST_cbc_encrypt(buf,buf,
2015 (unsigned long)lengths[j],&cast_ks,
2018 print_result(D_CBC_CAST,j,count,d);
2025 for (j=0; j<SIZE_NUM; j++)
2032 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2033 /* -O3 -fschedule-insns messes up an
2034 * optimization here! names[D_EVP]
2035 * somehow becomes NULL */
2036 print_message(names[D_EVP],save_count,
2039 EVP_CIPHER_CTX_init(&ctx);
2041 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2043 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2044 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2048 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2049 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2051 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2052 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2054 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2056 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2058 EVP_CIPHER_CTX_cleanup(&ctx);
2062 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2063 print_message(names[D_EVP],save_count,
2067 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2068 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2072 print_result(D_EVP,j,count,d);
2076 RAND_pseudo_bytes(buf,36);
2077 #ifndef OPENSSL_NO_RSA
2078 for (j=0; j<RSA_NUM; j++)
2081 if (!rsa_doit[j]) continue;
2082 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2085 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2086 ERR_print_errors(bio_err);
2091 pkey_print_message("private","rsa",
2092 rsa_c[j][0],rsa_bits[j],
2094 /* RSA_blinding_on(rsa_key[j],NULL); */
2096 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2098 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2099 &rsa_num, rsa_key[j]);
2103 "RSA sign failure\n");
2104 ERR_print_errors(bio_err);
2110 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2111 : "%ld %d bit private RSA's in %.2fs\n",
2112 count,rsa_bits[j],d);
2113 rsa_results[j][0]=d/(double)count;
2118 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2121 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2122 ERR_print_errors(bio_err);
2127 pkey_print_message("public","rsa",
2128 rsa_c[j][1],rsa_bits[j],
2131 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2133 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2134 rsa_num, rsa_key[j]);
2138 "RSA verify failure\n");
2139 ERR_print_errors(bio_err);
2145 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2146 : "%ld %d bit public RSA's in %.2fs\n",
2147 count,rsa_bits[j],d);
2148 rsa_results[j][1]=d/(double)count;
2154 /* if longer than 10s, don't do any more */
2155 for (j++; j<RSA_NUM; j++)
2161 RAND_pseudo_bytes(buf,20);
2162 #ifndef OPENSSL_NO_DSA
2163 if (RAND_status() != 1)
2165 RAND_seed(rnd_seed, sizeof rnd_seed);
2168 for (j=0; j<DSA_NUM; j++)
2173 if (!dsa_doit[j]) continue;
2174 /* DSA_generate_key(dsa_key[j]); */
2175 /* DSA_sign_setup(dsa_key[j],NULL); */
2176 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2180 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2181 ERR_print_errors(bio_err);
2186 pkey_print_message("sign","dsa",
2187 dsa_c[j][0],dsa_bits[j],
2190 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2192 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2197 "DSA sign failure\n");
2198 ERR_print_errors(bio_err);
2204 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2205 : "%ld %d bit DSA signs in %.2fs\n",
2206 count,dsa_bits[j],d);
2207 dsa_results[j][0]=d/(double)count;
2211 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2215 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2216 ERR_print_errors(bio_err);
2221 pkey_print_message("verify","dsa",
2222 dsa_c[j][1],dsa_bits[j],
2225 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2227 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2232 "DSA verify failure\n");
2233 ERR_print_errors(bio_err);
2239 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2240 : "%ld %d bit DSA verify in %.2fs\n",
2241 count,dsa_bits[j],d);
2242 dsa_results[j][1]=d/(double)count;
2247 /* if longer than 10s, don't do any more */
2248 for (j++; j<DSA_NUM; j++)
2252 if (rnd_fake) RAND_cleanup();
2255 #ifndef OPENSSL_NO_ECDSA
2256 if (RAND_status() != 1)
2258 RAND_seed(rnd_seed, sizeof rnd_seed);
2261 for (j=0; j<EC_NUM; j++)
2265 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2266 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2267 if (ecdsa[j] == NULL)
2269 BIO_printf(bio_err,"ECDSA failure.\n");
2270 ERR_print_errors(bio_err);
2276 EC_KEY_precompute_mult(ecdsa[j], NULL);
2278 /* Perform ECDSA signature test */
2279 EC_KEY_generate_key(ecdsa[j]);
2280 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2281 &ecdsasiglen, ecdsa[j]);
2284 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2285 ERR_print_errors(bio_err);
2290 pkey_print_message("sign","ecdsa",
2292 test_curves_bits[j],
2296 for (count=0,run=1; COND(ecdsa_c[j][0]);
2299 ret=ECDSA_sign(0, buf, 20,
2300 ecdsasig, &ecdsasiglen,
2304 BIO_printf(bio_err, "ECDSA sign failure\n");
2305 ERR_print_errors(bio_err);
2312 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2313 "%ld %d bit ECDSA signs in %.2fs \n",
2314 count, test_curves_bits[j], d);
2315 ecdsa_results[j][0]=d/(double)count;
2319 /* Perform ECDSA verification test */
2320 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2321 ecdsasiglen, ecdsa[j]);
2324 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2325 ERR_print_errors(bio_err);
2330 pkey_print_message("verify","ecdsa",
2332 test_curves_bits[j],
2335 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2337 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2340 BIO_printf(bio_err, "ECDSA verify failure\n");
2341 ERR_print_errors(bio_err);
2347 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2348 : "%ld %d bit ECDSA verify in %.2fs\n",
2349 count, test_curves_bits[j], d);
2350 ecdsa_results[j][1]=d/(double)count;
2355 /* if longer than 10s, don't do any more */
2356 for (j++; j<EC_NUM; j++)
2361 if (rnd_fake) RAND_cleanup();
2364 #ifndef OPENSSL_NO_ECDH
2365 if (RAND_status() != 1)
2367 RAND_seed(rnd_seed, sizeof rnd_seed);
2370 for (j=0; j<EC_NUM; j++)
2372 if (!ecdh_doit[j]) continue;
2373 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2374 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2375 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2377 BIO_printf(bio_err,"ECDH failure.\n");
2378 ERR_print_errors(bio_err);
2383 /* generate two ECDH key pairs */
2384 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2385 !EC_KEY_generate_key(ecdh_b[j]))
2387 BIO_printf(bio_err,"ECDH key generation failure.\n");
2388 ERR_print_errors(bio_err);
2393 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2394 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2396 int field_size, outlen;
2397 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2398 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2399 if (field_size <= 24 * 8)
2401 outlen = KDF1_SHA1_len;
2406 outlen = (field_size+7)/8;
2409 secret_size_a = ECDH_compute_key(secret_a, outlen,
2410 EC_KEY_get0_public_key(ecdh_b[j]),
2412 secret_size_b = ECDH_compute_key(secret_b, outlen,
2413 EC_KEY_get0_public_key(ecdh_a[j]),
2415 if (secret_size_a != secret_size_b)
2420 for (secret_idx = 0;
2421 (secret_idx < secret_size_a)
2422 && (ecdh_checks == 1);
2425 if (secret_a[secret_idx] != secret_b[secret_idx])
2429 if (ecdh_checks == 0)
2431 BIO_printf(bio_err,"ECDH computations don't match.\n");
2432 ERR_print_errors(bio_err);
2436 pkey_print_message("","ecdh",
2438 test_curves_bits[j],
2441 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2443 ECDH_compute_key(secret_a, outlen,
2444 EC_KEY_get0_public_key(ecdh_b[j]),
2448 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2449 count, test_curves_bits[j], d);
2450 ecdh_results[j][0]=d/(double)count;
2458 /* if longer than 10s, don't do any more */
2459 for (j++; j<EC_NUM; j++)
2463 if (rnd_fake) RAND_cleanup();
2470 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2471 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2473 printf("%s ",BN_options());
2474 #ifndef OPENSSL_NO_MD2
2475 printf("%s ",MD2_options());
2477 #ifndef OPENSSL_NO_RC4
2478 printf("%s ",RC4_options());
2480 #ifndef OPENSSL_NO_DES
2481 printf("%s ",DES_options());
2483 #ifndef OPENSSL_NO_AES
2484 printf("%s ",AES_options());
2486 #ifndef OPENSSL_NO_IDEA
2487 printf("%s ",idea_options());
2489 #ifndef OPENSSL_NO_BF
2490 printf("%s ",BF_options());
2492 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2493 printf("available timing options: ");
2504 #define as_string(s) (#s)
2507 printf("HZ=%g", dbl);
2510 printf(" [sysconf value]");
2514 printf("timing function used: %s%s%s%s%s%s%s\n",
2515 (ftime_used ? "ftime" : ""),
2516 (ftime_used + times_used > 1 ? "," : ""),
2517 (times_used ? "times" : ""),
2518 (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
2519 (gettimeofday_used ? "gettimeofday" : ""),
2520 (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
2521 (getrusage_used ? "getrusage" : ""));
2527 fprintf(stdout,"+H");
2530 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2531 fprintf(stdout,"type ");
2533 for (j=0; j<SIZE_NUM; j++)
2534 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2535 fprintf(stdout,"\n");
2538 for (k=0; k<ALGOR_NUM; k++)
2540 if (!doit[k]) continue;
2542 fprintf(stdout,"+F:%d:%s",k,names[k]);
2544 fprintf(stdout,"%-13s",names[k]);
2545 for (j=0; j<SIZE_NUM; j++)
2547 if (results[k][j] > 10000 && !mr)
2548 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2550 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2552 fprintf(stdout,"\n");
2554 #ifndef OPENSSL_NO_RSA
2556 for (k=0; k<RSA_NUM; k++)
2558 if (!rsa_doit[k]) continue;
2561 printf("%18ssign verify sign/s verify/s\n"," ");
2565 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2566 k,rsa_bits[k],rsa_results[k][0],
2569 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2570 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2571 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2574 #ifndef OPENSSL_NO_DSA
2576 for (k=0; k<DSA_NUM; k++)
2578 if (!dsa_doit[k]) continue;
2581 printf("%18ssign verify sign/s verify/s\n"," ");
2585 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2586 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2588 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2589 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2590 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2593 #ifndef OPENSSL_NO_ECDSA
2595 for (k=0; k<EC_NUM; k++)
2597 if (!ecdsa_doit[k]) continue;
2600 printf("%30ssign verify sign/s verify/s\n"," ");
2605 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2606 k, test_curves_bits[k],
2607 ecdsa_results[k][0],ecdsa_results[k][1]);
2610 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2611 test_curves_bits[k],
2612 test_curves_names[k],
2613 ecdsa_results[k][0],ecdsa_results[k][1],
2614 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2619 #ifndef OPENSSL_NO_ECDH
2621 for (k=0; k<EC_NUM; k++)
2623 if (!ecdh_doit[k]) continue;
2626 printf("%30sop op/s\n"," ");
2630 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2631 k, test_curves_bits[k],
2632 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2635 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2636 test_curves_bits[k],
2637 test_curves_names[k],
2638 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2645 ERR_print_errors(bio_err);
2646 if (buf != NULL) OPENSSL_free(buf);
2647 if (buf2 != NULL) OPENSSL_free(buf2);
2648 #ifndef OPENSSL_NO_RSA
2649 for (i=0; i<RSA_NUM; i++)
2650 if (rsa_key[i] != NULL)
2651 RSA_free(rsa_key[i]);
2653 #ifndef OPENSSL_NO_DSA
2654 for (i=0; i<DSA_NUM; i++)
2655 if (dsa_key[i] != NULL)
2656 DSA_free(dsa_key[i]);
2659 #ifndef OPENSSL_NO_ECDSA
2660 for (i=0; i<EC_NUM; i++)
2661 if (ecdsa[i] != NULL)
2662 EC_KEY_free(ecdsa[i]);
2664 #ifndef OPENSSL_NO_ECDH
2665 for (i=0; i<EC_NUM; i++)
2667 if (ecdh_a[i] != NULL)
2668 EC_KEY_free(ecdh_a[i]);
2669 if (ecdh_b[i] != NULL)
2670 EC_KEY_free(ecdh_b[i]);
2678 static void print_message(const char *s, long num, int length)
2681 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2682 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2683 (void)BIO_flush(bio_err);
2686 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2687 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2688 (void)BIO_flush(bio_err);
2695 static void pkey_print_message(const char *str, const char *str2, long num,
2699 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2700 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2701 (void)BIO_flush(bio_err);
2704 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2705 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2706 (void)BIO_flush(bio_err);
2713 static void print_result(int alg,int run_no,int count,double time_used)
2715 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2716 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2717 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2721 static char *sstrsep(char **string, const char *delim)
2724 char *token = *string;
2729 memset(isdelim, 0, sizeof isdelim);
2734 isdelim[(unsigned char)(*delim)] = 1;
2738 while (!isdelim[(unsigned char)(**string)])
2752 static int do_multi(int multi)
2757 static char sep[]=":";
2759 fds=malloc(multi*sizeof *fds);
2760 for(n=0 ; n < multi ; ++n)
2780 printf("Forked child %d\n",n);
2783 /* for now, assume the pipe is long enough to take all the output */
2784 for(n=0 ; n < multi ; ++n)
2790 f=fdopen(fds[n],"r");
2791 while(fgets(buf,sizeof buf,f))
2798 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2802 printf("Got: %s from %d\n",buf,n);
2803 if(!strncmp(buf,"+F:",3))
2809 alg=atoi(sstrsep(&p,sep));
2811 for(j=0 ; j < SIZE_NUM ; ++j)
2812 results[alg][j]+=atof(sstrsep(&p,sep));
2814 else if(!strncmp(buf,"+F2:",4))
2820 k=atoi(sstrsep(&p,sep));
2823 d=atof(sstrsep(&p,sep));
2825 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2827 rsa_results[k][0]=d;
2829 d=atof(sstrsep(&p,sep));
2831 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2833 rsa_results[k][1]=d;
2835 else if(!strncmp(buf,"+F2:",4))
2841 k=atoi(sstrsep(&p,sep));
2844 d=atof(sstrsep(&p,sep));
2846 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2848 rsa_results[k][0]=d;
2850 d=atof(sstrsep(&p,sep));
2852 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2854 rsa_results[k][1]=d;
2856 else if(!strncmp(buf,"+F3:",4))
2862 k=atoi(sstrsep(&p,sep));
2865 d=atof(sstrsep(&p,sep));
2867 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2869 dsa_results[k][0]=d;
2871 d=atof(sstrsep(&p,sep));
2873 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2875 dsa_results[k][1]=d;
2877 #ifndef OPENSSL_NO_ECDSA
2878 else if(!strncmp(buf,"+F4:",4))
2884 k=atoi(sstrsep(&p,sep));
2887 d=atof(sstrsep(&p,sep));
2889 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2891 ecdsa_results[k][0]=d;
2893 d=atof(sstrsep(&p,sep));
2895 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2897 ecdsa_results[k][1]=d;
2901 #ifndef OPENSSL_NO_ECDH
2902 else if(!strncmp(buf,"+F5:",4))
2908 k=atoi(sstrsep(&p,sep));
2911 d=atof(sstrsep(&p,sep));
2913 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2915 ecdh_results[k][0]=d;
2920 else if(!strncmp(buf,"+H:",3))
2924 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);