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)
266 #define BUFSIZE ((long)1024*8+1)
269 static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0;
271 static int usertime=1;
273 static double Time_F(int s);
274 static void print_message(const char *s,long num,int length);
275 static void pkey_print_message(const char *str, const char *str2,
276 long num, int bits, int sec);
277 static void print_result(int alg,int run_no,int count,double time_used);
279 static int do_multi(int multi);
288 #define MAX_ECDH_SIZE 256
290 static const char *names[ALGOR_NUM]={
291 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
292 "des cbc","des ede3","idea cbc","seed cbc",
293 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
294 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
295 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
296 "evp","sha256","sha512",
297 "aes-128 ige","aes-192 ige","aes-256 ige"};
298 static double results[ALGOR_NUM][SIZE_NUM];
299 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
300 static double rsa_results[RSA_NUM][2];
301 static double dsa_results[DSA_NUM][2];
302 #ifndef OPENSSL_NO_ECDSA
303 static double ecdsa_results[EC_NUM][2];
305 #ifndef OPENSSL_NO_ECDH
306 static double ecdh_results[EC_NUM][1];
309 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
310 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
311 static int rnd_fake = 0;
315 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
316 #define SIGRETTYPE void
318 #define SIGRETTYPE int
321 static SIGRETTYPE sig_done(int sig);
322 static SIGRETTYPE sig_done(int sig)
324 signal(SIGALRM,sig_done);
335 #if defined(OPENSSL_SYS_NETWARE)
337 /* for NetWare the best we can do is use clock() which returns the
338 * time, in hundredths of a second, since the NLM began executing
340 static double Time_F(int s)
344 static clock_t tstart,tend;
354 ret=(double)((double)(tend)-(double)(tstart));
355 return((ret < 0.001)?0.001:ret);
361 static double Time_F(int s)
368 static struct rusage tstart,tend;
373 getrusage(RUSAGE_SELF,&tstart);
380 getrusage(RUSAGE_SELF,&tend);
381 i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
382 ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
383 +((double)i)/1000000.0;
384 return((ret < 0.001)?0.001:ret);
389 static struct timeval tstart,tend;
392 gettimeofday_used = 1;
395 gettimeofday(&tstart,NULL);
400 gettimeofday(&tend,NULL);
401 i=(long)tend.tv_usec-(long)tstart.tv_usec;
402 ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
403 return((ret < 0.001)?0.001:ret);
406 #else /* ndef USE_TOD */
411 static struct tms tstart,tend;
423 ret=(double)(tend.tms_utime-tstart.tms_utime) / ret;
424 return((ret < 1e-3)?1e-3:ret);
427 # endif /* times() */
428 # if defined(TIMES) && defined(TIMEB)
431 # ifdef OPENSSL_SYS_VXWORKS
433 static unsigned long tick_start, tick_end;
437 tick_start = tickGet();
442 tick_end = tickGet();
443 ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
444 return((ret < 0.001)?0.001:ret);
447 # elif defined(TIMEB)
449 static struct timeb tstart,tend;
461 i=(long)tend.millitm-(long)tstart.millitm;
462 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
463 return((ret < 0.001)?0.001:ret);
469 #endif /* if defined(OPENSSL_SYS_NETWARE) */
472 #ifndef OPENSSL_NO_ECDH
473 static const int KDF1_SHA1_len = 20;
474 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
476 #ifndef OPENSSL_NO_SHA
477 if (*outlen < SHA_DIGEST_LENGTH)
480 *outlen = SHA_DIGEST_LENGTH;
481 return SHA1(in, inlen, out);
484 #endif /* OPENSSL_NO_SHA */
486 #endif /* OPENSSL_NO_ECDH */
489 int MAIN(int, char **);
491 int MAIN(int argc, char **argv)
493 #ifndef OPENSSL_NO_ENGINE
496 unsigned char *buf=NULL,*buf2=NULL;
498 long count=0,save_count=0;
500 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
503 #ifndef OPENSSL_NO_RSA
506 unsigned char md[EVP_MAX_MD_SIZE];
507 #ifndef OPENSSL_NO_MD2
508 unsigned char md2[MD2_DIGEST_LENGTH];
510 #ifndef OPENSSL_NO_MDC2
511 unsigned char mdc2[MDC2_DIGEST_LENGTH];
513 #ifndef OPENSSL_NO_MD4
514 unsigned char md4[MD4_DIGEST_LENGTH];
516 #ifndef OPENSSL_NO_MD5
517 unsigned char md5[MD5_DIGEST_LENGTH];
518 unsigned char hmac[MD5_DIGEST_LENGTH];
520 #ifndef OPENSSL_NO_SHA
521 unsigned char sha[SHA_DIGEST_LENGTH];
522 #ifndef OPENSSL_NO_SHA256
523 unsigned char sha256[SHA256_DIGEST_LENGTH];
525 #ifndef OPENSSL_NO_SHA512
526 unsigned char sha512[SHA512_DIGEST_LENGTH];
529 #ifndef OPENSSL_NO_RIPEMD
530 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
532 #ifndef OPENSSL_NO_RC4
535 #ifndef OPENSSL_NO_RC5
538 #ifndef OPENSSL_NO_RC2
541 #ifndef OPENSSL_NO_IDEA
542 IDEA_KEY_SCHEDULE idea_ks;
544 #ifndef OPENSSL_NO_SEED
545 SEED_KEY_SCHEDULE seed_ks;
547 #ifndef OPENSSL_NO_BF
550 #ifndef OPENSSL_NO_CAST
553 static const unsigned char key16[16]=
554 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
555 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
556 #ifndef OPENSSL_NO_AES
557 static const unsigned char key24[24]=
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 static const unsigned char key32[32]=
562 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
563 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
564 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
565 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
567 #ifndef OPENSSL_NO_CAMELLIA
568 static const unsigned char ckey24[24]=
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 static const unsigned char ckey32[32]=
573 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
574 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
575 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
576 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
578 #ifndef OPENSSL_NO_AES
579 #define MAX_BLOCK_SIZE 128
581 #define MAX_BLOCK_SIZE 64
583 unsigned char DES_iv[8];
584 unsigned char iv[2*MAX_BLOCK_SIZE/8];
585 #ifndef OPENSSL_NO_DES
586 DES_cblock *buf_as_des_cblock = NULL;
587 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
588 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
589 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
590 DES_key_schedule sch;
591 DES_key_schedule sch2;
592 DES_key_schedule sch3;
594 #ifndef OPENSSL_NO_AES
595 AES_KEY aes_ks1, aes_ks2, aes_ks3;
597 #ifndef OPENSSL_NO_CAMELLIA
598 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
610 #define D_CBC_IDEA 10
611 #define D_CBC_SEED 11
615 #define D_CBC_CAST 15
616 #define D_CBC_128_AES 16
617 #define D_CBC_192_AES 17
618 #define D_CBC_256_AES 18
619 #define D_CBC_128_CML 19
620 #define D_CBC_192_CML 20
621 #define D_CBC_256_CML 21
625 #define D_IGE_128_AES 25
626 #define D_IGE_192_AES 26
627 #define D_IGE_256_AES 27
629 long c[ALGOR_NUM][SIZE_NUM];
655 #ifndef OPENSSL_NO_RSA
656 RSA *rsa_key[RSA_NUM];
657 long rsa_c[RSA_NUM][2];
658 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
659 static unsigned char *rsa_data[RSA_NUM]=
660 {test512,test1024,test2048,test4096};
661 static int rsa_data_length[RSA_NUM]={
662 sizeof(test512),sizeof(test1024),
663 sizeof(test2048),sizeof(test4096)};
665 #ifndef OPENSSL_NO_DSA
666 DSA *dsa_key[DSA_NUM];
667 long dsa_c[DSA_NUM][2];
668 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
670 #ifndef OPENSSL_NO_EC
671 /* We only test over the following curves as they are representative,
672 * To add tests over more curves, simply add the curve NID
673 * and curve name to the following arrays and increase the
674 * EC_NUM value accordingly.
676 static unsigned int test_curves[EC_NUM] =
680 NID_X9_62_prime192v1,
682 NID_X9_62_prime256v1,
697 static const char * test_curves_names[EC_NUM] =
718 static int test_curves_bits[EC_NUM] =
720 160, 192, 224, 256, 384, 521,
721 163, 233, 283, 409, 571,
722 163, 233, 283, 409, 571
727 #ifndef OPENSSL_NO_ECDSA
728 unsigned char ecdsasig[256];
729 unsigned int ecdsasiglen;
730 EC_KEY *ecdsa[EC_NUM];
731 long ecdsa_c[EC_NUM][2];
734 #ifndef OPENSSL_NO_ECDH
735 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
736 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
737 int secret_size_a, secret_size_b;
740 long ecdh_c[EC_NUM][2];
743 int rsa_doit[RSA_NUM];
744 int dsa_doit[DSA_NUM];
745 #ifndef OPENSSL_NO_ECDSA
746 int ecdsa_doit[EC_NUM];
748 #ifndef OPENSSL_NO_ECDH
749 int ecdh_doit[EC_NUM];
753 const EVP_CIPHER *evp_cipher=NULL;
754 const EVP_MD *evp_md=NULL;
765 memset(results, 0, sizeof(results));
766 #ifndef OPENSSL_NO_DSA
767 memset(dsa_key,0,sizeof(dsa_key));
769 #ifndef OPENSSL_NO_ECDSA
770 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
772 #ifndef OPENSSL_NO_ECDH
773 for (i=0; i<EC_NUM; i++)
782 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
783 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
785 if (!load_config(bio_err, NULL))
788 #ifndef OPENSSL_NO_RSA
789 memset(rsa_key,0,sizeof(rsa_key));
790 for (i=0; i<RSA_NUM; i++)
794 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
796 BIO_printf(bio_err,"out of memory\n");
799 #ifndef OPENSSL_NO_DES
800 buf_as_des_cblock = (DES_cblock *)buf;
802 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
804 BIO_printf(bio_err,"out of memory\n");
808 memset(c,0,sizeof(c));
809 memset(DES_iv,0,sizeof(DES_iv));
810 memset(iv,0,sizeof(iv));
812 for (i=0; i<ALGOR_NUM; i++)
814 for (i=0; i<RSA_NUM; i++)
816 for (i=0; i<DSA_NUM; i++)
818 #ifndef OPENSSL_NO_ECDSA
819 for (i=0; i<EC_NUM; i++)
822 #ifndef OPENSSL_NO_ECDH
823 for (i=0; i<EC_NUM; i++)
833 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
836 j--; /* Otherwise, -elapsed gets confused with
839 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
845 BIO_printf(bio_err,"no EVP given\n");
848 evp_cipher=EVP_get_cipherbyname(*argv);
851 evp_md=EVP_get_digestbyname(*argv);
853 if(!evp_cipher && !evp_md)
855 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
860 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
863 j--; /* Otherwise, -elapsed gets confused with
866 #ifndef OPENSSL_NO_ENGINE
867 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
873 BIO_printf(bio_err,"no engine given\n");
876 e = setup_engine(bio_err, *argv, 0);
877 /* j will be increased again further down. We just
878 don't want speed to confuse an engine with an
879 algorithm, especially when none is given (which
880 means all of them should be run) */
885 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
891 BIO_printf(bio_err,"no multi count given\n");
897 BIO_printf(bio_err,"bad multi count\n");
900 j--; /* Otherwise, -mr gets confused with
904 else if (argc > 0 && !strcmp(*argv,"-mr"))
907 j--; /* Otherwise, -mr gets confused with
911 #ifndef OPENSSL_NO_MD2
912 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
915 #ifndef OPENSSL_NO_MDC2
916 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
919 #ifndef OPENSSL_NO_MD4
920 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
923 #ifndef OPENSSL_NO_MD5
924 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
927 #ifndef OPENSSL_NO_MD5
928 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
931 #ifndef OPENSSL_NO_SHA
932 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
934 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
938 #ifndef OPENSSL_NO_SHA256
939 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
942 #ifndef OPENSSL_NO_SHA512
943 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
947 #ifndef OPENSSL_NO_RIPEMD
948 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
950 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
952 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
955 #ifndef OPENSSL_NO_RC4
956 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
959 #ifndef OPENSSL_NO_DES
960 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
961 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
964 #ifndef OPENSSL_NO_AES
965 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
966 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
967 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
968 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
969 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
970 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
973 #ifndef OPENSSL_NO_CAMELLIA
974 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
975 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
976 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
979 #ifndef OPENSSL_NO_RSA
980 #if 0 /* was: #ifdef RSAref */
981 if (strcmp(*argv,"rsaref") == 0)
983 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
989 if (strcmp(*argv,"openssl") == 0)
991 RSA_set_default_method(RSA_PKCS1_SSLeay());
996 #endif /* !OPENSSL_NO_RSA */
997 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
998 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
999 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
1000 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
1001 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
1002 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
1003 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
1005 #ifndef OPENSSL_NO_RC2
1006 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
1007 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
1010 #ifndef OPENSSL_NO_RC5
1011 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
1012 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
1015 #ifndef OPENSSL_NO_IDEA
1016 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
1017 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
1020 #ifndef OPENSSL_NO_SEED
1021 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
1022 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
1025 #ifndef OPENSSL_NO_BF
1026 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
1027 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
1028 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
1031 #ifndef OPENSSL_NO_CAST
1032 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
1033 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
1034 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
1037 #ifndef OPENSSL_NO_DES
1038 if (strcmp(*argv,"des") == 0)
1045 #ifndef OPENSSL_NO_AES
1046 if (strcmp(*argv,"aes") == 0)
1048 doit[D_CBC_128_AES]=1;
1049 doit[D_CBC_192_AES]=1;
1050 doit[D_CBC_256_AES]=1;
1054 #ifndef OPENSSL_NO_CAMELLIA
1055 if (strcmp(*argv,"camellia") == 0)
1057 doit[D_CBC_128_CML]=1;
1058 doit[D_CBC_192_CML]=1;
1059 doit[D_CBC_256_CML]=1;
1063 #ifndef OPENSSL_NO_RSA
1064 if (strcmp(*argv,"rsa") == 0)
1066 rsa_doit[R_RSA_512]=1;
1067 rsa_doit[R_RSA_1024]=1;
1068 rsa_doit[R_RSA_2048]=1;
1069 rsa_doit[R_RSA_4096]=1;
1073 #ifndef OPENSSL_NO_DSA
1074 if (strcmp(*argv,"dsa") == 0)
1076 dsa_doit[R_DSA_512]=1;
1077 dsa_doit[R_DSA_1024]=1;
1078 dsa_doit[R_DSA_2048]=1;
1082 #ifndef OPENSSL_NO_ECDSA
1083 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
1084 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
1085 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
1086 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
1087 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
1088 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
1089 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
1090 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
1091 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
1092 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
1093 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
1094 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
1095 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
1096 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
1097 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
1098 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
1099 else if (strcmp(*argv,"ecdsa") == 0)
1101 for (i=0; i < EC_NUM; i++)
1106 #ifndef OPENSSL_NO_ECDH
1107 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1108 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1109 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1110 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1111 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1112 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1113 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1114 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1115 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1116 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1117 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1118 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1119 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1120 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1121 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1122 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1123 else if (strcmp(*argv,"ecdh") == 0)
1125 for (i=0; i < EC_NUM; i++)
1131 BIO_printf(bio_err,"Error: bad option or value\n");
1132 BIO_printf(bio_err,"\n");
1133 BIO_printf(bio_err,"Available values:\n");
1134 #ifndef OPENSSL_NO_MD2
1135 BIO_printf(bio_err,"md2 ");
1137 #ifndef OPENSSL_NO_MDC2
1138 BIO_printf(bio_err,"mdc2 ");
1140 #ifndef OPENSSL_NO_MD4
1141 BIO_printf(bio_err,"md4 ");
1143 #ifndef OPENSSL_NO_MD5
1144 BIO_printf(bio_err,"md5 ");
1145 #ifndef OPENSSL_NO_HMAC
1146 BIO_printf(bio_err,"hmac ");
1149 #ifndef OPENSSL_NO_SHA1
1150 BIO_printf(bio_err,"sha1 ");
1152 #ifndef OPENSSL_NO_SHA256
1153 BIO_printf(bio_err,"sha256 ");
1155 #ifndef OPENSSL_NO_SHA512
1156 BIO_printf(bio_err,"sha512 ");
1158 #ifndef OPENSSL_NO_RIPEMD160
1159 BIO_printf(bio_err,"rmd160");
1161 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1162 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1163 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
1164 BIO_printf(bio_err,"\n");
1167 #ifndef OPENSSL_NO_IDEA
1168 BIO_printf(bio_err,"idea-cbc ");
1170 #ifndef OPENSSL_NO_SEED
1171 BIO_printf(bio_err,"seed-cbc ");
1173 #ifndef OPENSSL_NO_RC2
1174 BIO_printf(bio_err,"rc2-cbc ");
1176 #ifndef OPENSSL_NO_RC5
1177 BIO_printf(bio_err,"rc5-cbc ");
1179 #ifndef OPENSSL_NO_BF
1180 BIO_printf(bio_err,"bf-cbc");
1182 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1183 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1184 BIO_printf(bio_err,"\n");
1186 #ifndef OPENSSL_NO_DES
1187 BIO_printf(bio_err,"des-cbc des-ede3 ");
1189 #ifndef OPENSSL_NO_AES
1190 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1191 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1193 #ifndef OPENSSL_NO_CAMELLIA
1194 BIO_printf(bio_err,"\n");
1195 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1197 #ifndef OPENSSL_NO_RC4
1198 BIO_printf(bio_err,"rc4");
1200 BIO_printf(bio_err,"\n");
1202 #ifndef OPENSSL_NO_RSA
1203 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1206 #ifndef OPENSSL_NO_DSA
1207 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1209 #ifndef OPENSSL_NO_ECDSA
1210 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1211 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1212 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1213 BIO_printf(bio_err,"ecdsa\n");
1215 #ifndef OPENSSL_NO_ECDH
1216 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1217 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1218 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1219 BIO_printf(bio_err,"ecdh\n");
1222 #ifndef OPENSSL_NO_IDEA
1223 BIO_printf(bio_err,"idea ");
1225 #ifndef OPENSSL_NO_SEED
1226 BIO_printf(bio_err,"seed ");
1228 #ifndef OPENSSL_NO_RC2
1229 BIO_printf(bio_err,"rc2 ");
1231 #ifndef OPENSSL_NO_DES
1232 BIO_printf(bio_err,"des ");
1234 #ifndef OPENSSL_NO_AES
1235 BIO_printf(bio_err,"aes ");
1237 #ifndef OPENSSL_NO_CAMELLIA
1238 BIO_printf(bio_err,"camellia ");
1240 #ifndef OPENSSL_NO_RSA
1241 BIO_printf(bio_err,"rsa ");
1243 #ifndef OPENSSL_NO_BF
1244 BIO_printf(bio_err,"blowfish");
1246 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1247 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1248 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1249 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1250 BIO_printf(bio_err,"\n");
1253 BIO_printf(bio_err,"\n");
1254 BIO_printf(bio_err,"Available options:\n");
1255 #if defined(TIMES) || defined(USE_TOD)
1256 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1258 #ifndef OPENSSL_NO_ENGINE
1259 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1261 BIO_printf(bio_err,"-evp e use EVP e.\n");
1262 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1263 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1265 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1275 if(multi && do_multi(multi))
1281 for (i=0; i<ALGOR_NUM; i++)
1286 for (i=0; i<RSA_NUM; i++)
1288 for (i=0; i<DSA_NUM; i++)
1291 for (i=0; i<ALGOR_NUM; i++)
1292 if (doit[i]) pr_header++;
1294 if (usertime == 0 && !mr)
1295 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1296 if (usertime <= 0 && !mr)
1298 BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
1299 BIO_printf(bio_err,"program when this computer is idle.\n");
1302 #ifndef OPENSSL_NO_RSA
1303 for (i=0; i<RSA_NUM; i++)
1305 const unsigned char *p;
1308 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1309 if (rsa_key[i] == NULL)
1311 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1317 BIO_printf(bio_err,mr ? "+RK:%d:"
1318 : "Loaded RSA key, %d bit modulus and e= 0x",
1319 BN_num_bits(rsa_key[i]->n));
1320 BN_print(bio_err,rsa_key[i]->e);
1321 BIO_printf(bio_err,"\n");
1327 #ifndef OPENSSL_NO_DSA
1328 dsa_key[0]=get_dsa512();
1329 dsa_key[1]=get_dsa1024();
1330 dsa_key[2]=get_dsa2048();
1333 #ifndef OPENSSL_NO_DES
1334 DES_set_key_unchecked(&key,&sch);
1335 DES_set_key_unchecked(&key2,&sch2);
1336 DES_set_key_unchecked(&key3,&sch3);
1338 #ifndef OPENSSL_NO_AES
1339 AES_set_encrypt_key(key16,128,&aes_ks1);
1340 AES_set_encrypt_key(key24,192,&aes_ks2);
1341 AES_set_encrypt_key(key32,256,&aes_ks3);
1343 #ifndef OPENSSL_NO_CAMELLIA
1344 Camellia_set_key(key16,128,&camellia_ks1);
1345 Camellia_set_key(ckey24,192,&camellia_ks2);
1346 Camellia_set_key(ckey32,256,&camellia_ks3);
1348 #ifndef OPENSSL_NO_IDEA
1349 idea_set_encrypt_key(key16,&idea_ks);
1351 #ifndef OPENSSL_NO_SEED
1352 SEED_set_key(key16,&seed_ks);
1354 #ifndef OPENSSL_NO_RC4
1355 RC4_set_key(&rc4_ks,16,key16);
1357 #ifndef OPENSSL_NO_RC2
1358 RC2_set_key(&rc2_ks,16,key16,128);
1360 #ifndef OPENSSL_NO_RC5
1361 RC5_32_set_key(&rc5_ks,16,key16,12);
1363 #ifndef OPENSSL_NO_BF
1364 BF_set_key(&bf_ks,16,key16);
1366 #ifndef OPENSSL_NO_CAST
1367 CAST_set_key(&cast_ks,16,key16);
1369 #ifndef OPENSSL_NO_RSA
1370 memset(rsa_c,0,sizeof(rsa_c));
1373 #ifndef OPENSSL_NO_DES
1374 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1380 for (it=count; it; it--)
1381 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
1386 c[D_MD2][0]=count/10;
1387 c[D_MDC2][0]=count/10;
1392 c[D_RMD160][0]=count;
1393 c[D_RC4][0]=count*5;
1394 c[D_CBC_DES][0]=count;
1395 c[D_EDE3_DES][0]=count/3;
1396 c[D_CBC_IDEA][0]=count;
1397 c[D_CBC_SEED][0]=count;
1398 c[D_CBC_RC2][0]=count;
1399 c[D_CBC_RC5][0]=count;
1400 c[D_CBC_BF][0]=count;
1401 c[D_CBC_CAST][0]=count;
1402 c[D_CBC_128_AES][0]=count;
1403 c[D_CBC_192_AES][0]=count;
1404 c[D_CBC_256_AES][0]=count;
1405 c[D_CBC_128_CML][0]=count;
1406 c[D_CBC_192_CML][0]=count;
1407 c[D_CBC_256_CML][0]=count;
1408 c[D_SHA256][0]=count;
1409 c[D_SHA512][0]=count;
1410 c[D_IGE_128_AES][0]=count;
1411 c[D_IGE_192_AES][0]=count;
1412 c[D_IGE_256_AES][0]=count;
1414 for (i=1; i<SIZE_NUM; i++)
1416 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1417 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1418 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1419 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1420 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1421 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1422 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1423 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1424 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1426 for (i=1; i<SIZE_NUM; i++)
1430 l0=(long)lengths[i-1];
1431 l1=(long)lengths[i];
1432 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1433 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1434 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1435 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1436 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1437 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1438 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1439 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1440 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1441 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1442 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1443 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1444 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1445 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1446 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1447 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1448 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1449 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1451 #ifndef OPENSSL_NO_RSA
1452 rsa_c[R_RSA_512][0]=count/2000;
1453 rsa_c[R_RSA_512][1]=count/400;
1454 for (i=1; i<RSA_NUM; i++)
1456 rsa_c[i][0]=rsa_c[i-1][0]/8;
1457 rsa_c[i][1]=rsa_c[i-1][1]/4;
1458 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1462 if (rsa_c[i][0] == 0)
1471 #ifndef OPENSSL_NO_DSA
1472 dsa_c[R_DSA_512][0]=count/1000;
1473 dsa_c[R_DSA_512][1]=count/1000/2;
1474 for (i=1; i<DSA_NUM; i++)
1476 dsa_c[i][0]=dsa_c[i-1][0]/4;
1477 dsa_c[i][1]=dsa_c[i-1][1]/4;
1478 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1491 #ifndef OPENSSL_NO_ECDSA
1492 ecdsa_c[R_EC_P160][0]=count/1000;
1493 ecdsa_c[R_EC_P160][1]=count/1000/2;
1494 for (i=R_EC_P192; i<=R_EC_P521; i++)
1496 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1497 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1498 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1502 if (ecdsa_c[i] == 0)
1509 ecdsa_c[R_EC_K163][0]=count/1000;
1510 ecdsa_c[R_EC_K163][1]=count/1000/2;
1511 for (i=R_EC_K233; i<=R_EC_K571; i++)
1513 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1514 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1515 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1519 if (ecdsa_c[i] == 0)
1526 ecdsa_c[R_EC_B163][0]=count/1000;
1527 ecdsa_c[R_EC_B163][1]=count/1000/2;
1528 for (i=R_EC_B233; i<=R_EC_B571; i++)
1530 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1531 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1532 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1536 if (ecdsa_c[i] == 0)
1545 #ifndef OPENSSL_NO_ECDH
1546 ecdh_c[R_EC_P160][0]=count/1000;
1547 ecdh_c[R_EC_P160][1]=count/1000;
1548 for (i=R_EC_P192; i<=R_EC_P521; i++)
1550 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1551 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1552 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1563 ecdh_c[R_EC_K163][0]=count/1000;
1564 ecdh_c[R_EC_K163][1]=count/1000;
1565 for (i=R_EC_K233; i<=R_EC_K571; i++)
1567 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1568 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1569 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1580 ecdh_c[R_EC_B163][0]=count/1000;
1581 ecdh_c[R_EC_B163][1]=count/1000;
1582 for (i=R_EC_B233; i<=R_EC_B571; i++)
1584 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1585 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1586 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1599 #define COND(d) (count < (d))
1600 #define COUNT(d) (d)
1602 /* not worth fixing */
1603 # error "You cannot disable DES on systems without SIGALRM."
1604 #endif /* OPENSSL_NO_DES */
1606 #define COND(c) (run)
1607 #define COUNT(d) (count)
1608 signal(SIGALRM,sig_done);
1609 #endif /* SIGALRM */
1611 #ifndef OPENSSL_NO_MD2
1614 for (j=0; j<SIZE_NUM; j++)
1616 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1618 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1619 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1621 print_result(D_MD2,j,count,d);
1625 #ifndef OPENSSL_NO_MDC2
1628 for (j=0; j<SIZE_NUM; j++)
1630 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1632 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1633 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1635 print_result(D_MDC2,j,count,d);
1640 #ifndef OPENSSL_NO_MD4
1643 for (j=0; j<SIZE_NUM; j++)
1645 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1647 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1648 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1650 print_result(D_MD4,j,count,d);
1655 #ifndef OPENSSL_NO_MD5
1658 for (j=0; j<SIZE_NUM; j++)
1660 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1662 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1663 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1665 print_result(D_MD5,j,count,d);
1670 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1675 HMAC_CTX_init(&hctx);
1676 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1677 16,EVP_md5(), NULL);
1679 for (j=0; j<SIZE_NUM; j++)
1681 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1683 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1685 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1686 HMAC_Update(&hctx,buf,lengths[j]);
1687 HMAC_Final(&hctx,&(hmac[0]),NULL);
1690 print_result(D_HMAC,j,count,d);
1692 HMAC_CTX_cleanup(&hctx);
1695 #ifndef OPENSSL_NO_SHA
1698 for (j=0; j<SIZE_NUM; j++)
1700 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1702 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1703 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1705 print_result(D_SHA1,j,count,d);
1709 #ifndef OPENSSL_NO_SHA256
1712 for (j=0; j<SIZE_NUM; j++)
1714 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1716 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1717 SHA256(buf,lengths[j],sha256);
1719 print_result(D_SHA256,j,count,d);
1724 #ifndef OPENSSL_NO_SHA512
1727 for (j=0; j<SIZE_NUM; j++)
1729 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1731 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1732 SHA512(buf,lengths[j],sha512);
1734 print_result(D_SHA512,j,count,d);
1740 #ifndef OPENSSL_NO_RIPEMD
1743 for (j=0; j<SIZE_NUM; j++)
1745 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1747 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1748 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1750 print_result(D_RMD160,j,count,d);
1754 #ifndef OPENSSL_NO_RC4
1757 for (j=0; j<SIZE_NUM; j++)
1759 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1761 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1762 RC4(&rc4_ks,(unsigned int)lengths[j],
1765 print_result(D_RC4,j,count,d);
1769 #ifndef OPENSSL_NO_DES
1770 if (doit[D_CBC_DES])
1772 for (j=0; j<SIZE_NUM; j++)
1774 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1776 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1777 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1778 &DES_iv,DES_ENCRYPT);
1780 print_result(D_CBC_DES,j,count,d);
1784 if (doit[D_EDE3_DES])
1786 for (j=0; j<SIZE_NUM; j++)
1788 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1790 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1791 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1793 &DES_iv,DES_ENCRYPT);
1795 print_result(D_EDE3_DES,j,count,d);
1799 #ifndef OPENSSL_NO_AES
1800 if (doit[D_CBC_128_AES])
1802 for (j=0; j<SIZE_NUM; j++)
1804 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1806 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1807 AES_cbc_encrypt(buf,buf,
1808 (unsigned long)lengths[j],&aes_ks1,
1811 print_result(D_CBC_128_AES,j,count,d);
1814 if (doit[D_CBC_192_AES])
1816 for (j=0; j<SIZE_NUM; j++)
1818 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1820 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1821 AES_cbc_encrypt(buf,buf,
1822 (unsigned long)lengths[j],&aes_ks2,
1825 print_result(D_CBC_192_AES,j,count,d);
1828 if (doit[D_CBC_256_AES])
1830 for (j=0; j<SIZE_NUM; j++)
1832 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1834 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1835 AES_cbc_encrypt(buf,buf,
1836 (unsigned long)lengths[j],&aes_ks3,
1839 print_result(D_CBC_256_AES,j,count,d);
1843 if (doit[D_IGE_128_AES])
1845 for (j=0; j<SIZE_NUM; j++)
1847 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1849 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1850 AES_ige_encrypt(buf,buf2,
1851 (unsigned long)lengths[j],&aes_ks1,
1854 print_result(D_IGE_128_AES,j,count,d);
1857 if (doit[D_IGE_192_AES])
1859 for (j=0; j<SIZE_NUM; j++)
1861 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1863 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1864 AES_ige_encrypt(buf,buf2,
1865 (unsigned long)lengths[j],&aes_ks2,
1868 print_result(D_IGE_192_AES,j,count,d);
1871 if (doit[D_IGE_256_AES])
1873 for (j=0; j<SIZE_NUM; j++)
1875 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1877 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1878 AES_ige_encrypt(buf,buf2,
1879 (unsigned long)lengths[j],&aes_ks3,
1882 print_result(D_IGE_256_AES,j,count,d);
1886 #ifndef OPENSSL_NO_CAMELLIA
1887 if (doit[D_CBC_128_CML])
1889 for (j=0; j<SIZE_NUM; j++)
1891 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1893 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1894 Camellia_cbc_encrypt(buf,buf,
1895 (unsigned long)lengths[j],&camellia_ks1,
1896 iv,CAMELLIA_ENCRYPT);
1898 print_result(D_CBC_128_CML,j,count,d);
1901 if (doit[D_CBC_192_CML])
1903 for (j=0; j<SIZE_NUM; j++)
1905 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1907 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1908 Camellia_cbc_encrypt(buf,buf,
1909 (unsigned long)lengths[j],&camellia_ks2,
1910 iv,CAMELLIA_ENCRYPT);
1912 print_result(D_CBC_192_CML,j,count,d);
1915 if (doit[D_CBC_256_CML])
1917 for (j=0; j<SIZE_NUM; j++)
1919 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1921 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1922 Camellia_cbc_encrypt(buf,buf,
1923 (unsigned long)lengths[j],&camellia_ks3,
1924 iv,CAMELLIA_ENCRYPT);
1926 print_result(D_CBC_256_CML,j,count,d);
1931 #ifndef OPENSSL_NO_IDEA
1932 if (doit[D_CBC_IDEA])
1934 for (j=0; j<SIZE_NUM; j++)
1936 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1938 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1939 idea_cbc_encrypt(buf,buf,
1940 (unsigned long)lengths[j],&idea_ks,
1943 print_result(D_CBC_IDEA,j,count,d);
1947 #ifndef OPENSSL_NO_SEED
1948 if (doit[D_CBC_SEED])
1950 for (j=0; j<SIZE_NUM; j++)
1952 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1954 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1955 SEED_cbc_encrypt(buf,buf,
1956 (unsigned long)lengths[j],&seed_ks,iv,1);
1958 print_result(D_CBC_SEED,j,count,d);
1962 #ifndef OPENSSL_NO_RC2
1963 if (doit[D_CBC_RC2])
1965 for (j=0; j<SIZE_NUM; j++)
1967 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1969 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1970 RC2_cbc_encrypt(buf,buf,
1971 (unsigned long)lengths[j],&rc2_ks,
1974 print_result(D_CBC_RC2,j,count,d);
1978 #ifndef OPENSSL_NO_RC5
1979 if (doit[D_CBC_RC5])
1981 for (j=0; j<SIZE_NUM; j++)
1983 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1985 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1986 RC5_32_cbc_encrypt(buf,buf,
1987 (unsigned long)lengths[j],&rc5_ks,
1990 print_result(D_CBC_RC5,j,count,d);
1994 #ifndef OPENSSL_NO_BF
1997 for (j=0; j<SIZE_NUM; j++)
1999 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
2001 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
2002 BF_cbc_encrypt(buf,buf,
2003 (unsigned long)lengths[j],&bf_ks,
2006 print_result(D_CBC_BF,j,count,d);
2010 #ifndef OPENSSL_NO_CAST
2011 if (doit[D_CBC_CAST])
2013 for (j=0; j<SIZE_NUM; j++)
2015 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
2017 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
2018 CAST_cbc_encrypt(buf,buf,
2019 (unsigned long)lengths[j],&cast_ks,
2022 print_result(D_CBC_CAST,j,count,d);
2029 for (j=0; j<SIZE_NUM; j++)
2036 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2037 /* -O3 -fschedule-insns messes up an
2038 * optimization here! names[D_EVP]
2039 * somehow becomes NULL */
2040 print_message(names[D_EVP],save_count,
2043 EVP_CIPHER_CTX_init(&ctx);
2045 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2047 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2048 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2052 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2053 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2055 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2056 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2058 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2060 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2062 EVP_CIPHER_CTX_cleanup(&ctx);
2066 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2067 print_message(names[D_EVP],save_count,
2071 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2072 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2076 print_result(D_EVP,j,count,d);
2080 RAND_pseudo_bytes(buf,36);
2081 #ifndef OPENSSL_NO_RSA
2082 for (j=0; j<RSA_NUM; j++)
2085 if (!rsa_doit[j]) continue;
2086 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2089 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2090 ERR_print_errors(bio_err);
2095 pkey_print_message("private","rsa",
2096 rsa_c[j][0],rsa_bits[j],
2098 /* RSA_blinding_on(rsa_key[j],NULL); */
2100 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2102 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2103 &rsa_num, rsa_key[j]);
2107 "RSA sign failure\n");
2108 ERR_print_errors(bio_err);
2114 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2115 : "%ld %d bit private RSA's in %.2fs\n",
2116 count,rsa_bits[j],d);
2117 rsa_results[j][0]=d/(double)count;
2122 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2125 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2126 ERR_print_errors(bio_err);
2131 pkey_print_message("public","rsa",
2132 rsa_c[j][1],rsa_bits[j],
2135 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2137 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2138 rsa_num, rsa_key[j]);
2142 "RSA verify failure\n");
2143 ERR_print_errors(bio_err);
2149 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2150 : "%ld %d bit public RSA's in %.2fs\n",
2151 count,rsa_bits[j],d);
2152 rsa_results[j][1]=d/(double)count;
2158 /* if longer than 10s, don't do any more */
2159 for (j++; j<RSA_NUM; j++)
2165 RAND_pseudo_bytes(buf,20);
2166 #ifndef OPENSSL_NO_DSA
2167 if (RAND_status() != 1)
2169 RAND_seed(rnd_seed, sizeof rnd_seed);
2172 for (j=0; j<DSA_NUM; j++)
2177 if (!dsa_doit[j]) continue;
2178 /* DSA_generate_key(dsa_key[j]); */
2179 /* DSA_sign_setup(dsa_key[j],NULL); */
2180 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2184 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2185 ERR_print_errors(bio_err);
2190 pkey_print_message("sign","dsa",
2191 dsa_c[j][0],dsa_bits[j],
2194 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2196 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2201 "DSA sign failure\n");
2202 ERR_print_errors(bio_err);
2208 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2209 : "%ld %d bit DSA signs in %.2fs\n",
2210 count,dsa_bits[j],d);
2211 dsa_results[j][0]=d/(double)count;
2215 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2219 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2220 ERR_print_errors(bio_err);
2225 pkey_print_message("verify","dsa",
2226 dsa_c[j][1],dsa_bits[j],
2229 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2231 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2236 "DSA verify failure\n");
2237 ERR_print_errors(bio_err);
2243 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2244 : "%ld %d bit DSA verify in %.2fs\n",
2245 count,dsa_bits[j],d);
2246 dsa_results[j][1]=d/(double)count;
2251 /* if longer than 10s, don't do any more */
2252 for (j++; j<DSA_NUM; j++)
2256 if (rnd_fake) RAND_cleanup();
2259 #ifndef OPENSSL_NO_ECDSA
2260 if (RAND_status() != 1)
2262 RAND_seed(rnd_seed, sizeof rnd_seed);
2265 for (j=0; j<EC_NUM; j++)
2269 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2270 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2271 if (ecdsa[j] == NULL)
2273 BIO_printf(bio_err,"ECDSA failure.\n");
2274 ERR_print_errors(bio_err);
2280 EC_KEY_precompute_mult(ecdsa[j], NULL);
2282 /* Perform ECDSA signature test */
2283 EC_KEY_generate_key(ecdsa[j]);
2284 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2285 &ecdsasiglen, ecdsa[j]);
2288 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2289 ERR_print_errors(bio_err);
2294 pkey_print_message("sign","ecdsa",
2296 test_curves_bits[j],
2300 for (count=0,run=1; COND(ecdsa_c[j][0]);
2303 ret=ECDSA_sign(0, buf, 20,
2304 ecdsasig, &ecdsasiglen,
2308 BIO_printf(bio_err, "ECDSA sign failure\n");
2309 ERR_print_errors(bio_err);
2316 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2317 "%ld %d bit ECDSA signs in %.2fs \n",
2318 count, test_curves_bits[j], d);
2319 ecdsa_results[j][0]=d/(double)count;
2323 /* Perform ECDSA verification test */
2324 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2325 ecdsasiglen, ecdsa[j]);
2328 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2329 ERR_print_errors(bio_err);
2334 pkey_print_message("verify","ecdsa",
2336 test_curves_bits[j],
2339 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2341 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2344 BIO_printf(bio_err, "ECDSA verify failure\n");
2345 ERR_print_errors(bio_err);
2351 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2352 : "%ld %d bit ECDSA verify in %.2fs\n",
2353 count, test_curves_bits[j], d);
2354 ecdsa_results[j][1]=d/(double)count;
2359 /* if longer than 10s, don't do any more */
2360 for (j++; j<EC_NUM; j++)
2365 if (rnd_fake) RAND_cleanup();
2368 #ifndef OPENSSL_NO_ECDH
2369 if (RAND_status() != 1)
2371 RAND_seed(rnd_seed, sizeof rnd_seed);
2374 for (j=0; j<EC_NUM; j++)
2376 if (!ecdh_doit[j]) continue;
2377 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2378 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2379 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2381 BIO_printf(bio_err,"ECDH failure.\n");
2382 ERR_print_errors(bio_err);
2387 /* generate two ECDH key pairs */
2388 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2389 !EC_KEY_generate_key(ecdh_b[j]))
2391 BIO_printf(bio_err,"ECDH key generation failure.\n");
2392 ERR_print_errors(bio_err);
2397 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2398 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2400 int field_size, outlen;
2401 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2402 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2403 if (field_size <= 24 * 8)
2405 outlen = KDF1_SHA1_len;
2410 outlen = (field_size+7)/8;
2413 secret_size_a = ECDH_compute_key(secret_a, outlen,
2414 EC_KEY_get0_public_key(ecdh_b[j]),
2416 secret_size_b = ECDH_compute_key(secret_b, outlen,
2417 EC_KEY_get0_public_key(ecdh_a[j]),
2419 if (secret_size_a != secret_size_b)
2424 for (secret_idx = 0;
2425 (secret_idx < secret_size_a)
2426 && (ecdh_checks == 1);
2429 if (secret_a[secret_idx] != secret_b[secret_idx])
2433 if (ecdh_checks == 0)
2435 BIO_printf(bio_err,"ECDH computations don't match.\n");
2436 ERR_print_errors(bio_err);
2440 pkey_print_message("","ecdh",
2442 test_curves_bits[j],
2445 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2447 ECDH_compute_key(secret_a, outlen,
2448 EC_KEY_get0_public_key(ecdh_b[j]),
2452 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2453 count, test_curves_bits[j], d);
2454 ecdh_results[j][0]=d/(double)count;
2462 /* if longer than 10s, don't do any more */
2463 for (j++; j<EC_NUM; j++)
2467 if (rnd_fake) RAND_cleanup();
2474 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2475 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2477 printf("%s ",BN_options());
2478 #ifndef OPENSSL_NO_MD2
2479 printf("%s ",MD2_options());
2481 #ifndef OPENSSL_NO_RC4
2482 printf("%s ",RC4_options());
2484 #ifndef OPENSSL_NO_DES
2485 printf("%s ",DES_options());
2487 #ifndef OPENSSL_NO_AES
2488 printf("%s ",AES_options());
2490 #ifndef OPENSSL_NO_IDEA
2491 printf("%s ",idea_options());
2493 #ifndef OPENSSL_NO_BF
2494 printf("%s ",BF_options());
2496 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2497 printf("available timing options: ");
2508 #define as_string(s) (#s)
2511 printf("HZ=%g", dbl);
2514 printf(" [sysconf value]");
2518 printf("timing function used: %s%s%s%s%s%s%s\n",
2519 (ftime_used ? "ftime" : ""),
2520 (ftime_used + times_used > 1 ? "," : ""),
2521 (times_used ? "times" : ""),
2522 (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
2523 (gettimeofday_used ? "gettimeofday" : ""),
2524 (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
2525 (getrusage_used ? "getrusage" : ""));
2531 fprintf(stdout,"+H");
2534 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2535 fprintf(stdout,"type ");
2537 for (j=0; j<SIZE_NUM; j++)
2538 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2539 fprintf(stdout,"\n");
2542 for (k=0; k<ALGOR_NUM; k++)
2544 if (!doit[k]) continue;
2546 fprintf(stdout,"+F:%d:%s",k,names[k]);
2548 fprintf(stdout,"%-13s",names[k]);
2549 for (j=0; j<SIZE_NUM; j++)
2551 if (results[k][j] > 10000 && !mr)
2552 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2554 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2556 fprintf(stdout,"\n");
2558 #ifndef OPENSSL_NO_RSA
2560 for (k=0; k<RSA_NUM; k++)
2562 if (!rsa_doit[k]) continue;
2565 printf("%18ssign verify sign/s verify/s\n"," ");
2569 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2570 k,rsa_bits[k],rsa_results[k][0],
2573 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2574 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2575 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2578 #ifndef OPENSSL_NO_DSA
2580 for (k=0; k<DSA_NUM; k++)
2582 if (!dsa_doit[k]) continue;
2585 printf("%18ssign verify sign/s verify/s\n"," ");
2589 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2590 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2592 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2593 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2594 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2597 #ifndef OPENSSL_NO_ECDSA
2599 for (k=0; k<EC_NUM; k++)
2601 if (!ecdsa_doit[k]) continue;
2604 printf("%30ssign verify sign/s verify/s\n"," ");
2609 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2610 k, test_curves_bits[k],
2611 ecdsa_results[k][0],ecdsa_results[k][1]);
2614 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2615 test_curves_bits[k],
2616 test_curves_names[k],
2617 ecdsa_results[k][0],ecdsa_results[k][1],
2618 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2623 #ifndef OPENSSL_NO_ECDH
2625 for (k=0; k<EC_NUM; k++)
2627 if (!ecdh_doit[k]) continue;
2630 printf("%30sop op/s\n"," ");
2634 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2635 k, test_curves_bits[k],
2636 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2639 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2640 test_curves_bits[k],
2641 test_curves_names[k],
2642 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2649 ERR_print_errors(bio_err);
2650 if (buf != NULL) OPENSSL_free(buf);
2651 if (buf2 != NULL) OPENSSL_free(buf2);
2652 #ifndef OPENSSL_NO_RSA
2653 for (i=0; i<RSA_NUM; i++)
2654 if (rsa_key[i] != NULL)
2655 RSA_free(rsa_key[i]);
2657 #ifndef OPENSSL_NO_DSA
2658 for (i=0; i<DSA_NUM; i++)
2659 if (dsa_key[i] != NULL)
2660 DSA_free(dsa_key[i]);
2663 #ifndef OPENSSL_NO_ECDSA
2664 for (i=0; i<EC_NUM; i++)
2665 if (ecdsa[i] != NULL)
2666 EC_KEY_free(ecdsa[i]);
2668 #ifndef OPENSSL_NO_ECDH
2669 for (i=0; i<EC_NUM; i++)
2671 if (ecdh_a[i] != NULL)
2672 EC_KEY_free(ecdh_a[i]);
2673 if (ecdh_b[i] != NULL)
2674 EC_KEY_free(ecdh_b[i]);
2682 static void print_message(const char *s, long num, int length)
2685 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2686 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2687 (void)BIO_flush(bio_err);
2690 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2691 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2692 (void)BIO_flush(bio_err);
2699 static void pkey_print_message(const char *str, const char *str2, long num,
2703 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2704 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2705 (void)BIO_flush(bio_err);
2708 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2709 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2710 (void)BIO_flush(bio_err);
2717 static void print_result(int alg,int run_no,int count,double time_used)
2719 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2720 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2721 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2725 static char *sstrsep(char **string, const char *delim)
2728 char *token = *string;
2733 memset(isdelim, 0, sizeof isdelim);
2738 isdelim[(unsigned char)(*delim)] = 1;
2742 while (!isdelim[(unsigned char)(**string)])
2756 static int do_multi(int multi)
2761 static char sep[]=":";
2763 fds=malloc(multi*sizeof *fds);
2764 for(n=0 ; n < multi ; ++n)
2784 printf("Forked child %d\n",n);
2787 /* for now, assume the pipe is long enough to take all the output */
2788 for(n=0 ; n < multi ; ++n)
2794 f=fdopen(fds[n],"r");
2795 while(fgets(buf,sizeof buf,f))
2802 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2806 printf("Got: %s from %d\n",buf,n);
2807 if(!strncmp(buf,"+F:",3))
2813 alg=atoi(sstrsep(&p,sep));
2815 for(j=0 ; j < SIZE_NUM ; ++j)
2816 results[alg][j]+=atof(sstrsep(&p,sep));
2818 else if(!strncmp(buf,"+F2:",4))
2824 k=atoi(sstrsep(&p,sep));
2827 d=atof(sstrsep(&p,sep));
2829 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2831 rsa_results[k][0]=d;
2833 d=atof(sstrsep(&p,sep));
2835 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2837 rsa_results[k][1]=d;
2839 else if(!strncmp(buf,"+F2:",4))
2845 k=atoi(sstrsep(&p,sep));
2848 d=atof(sstrsep(&p,sep));
2850 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2852 rsa_results[k][0]=d;
2854 d=atof(sstrsep(&p,sep));
2856 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2858 rsa_results[k][1]=d;
2860 else if(!strncmp(buf,"+F3:",4))
2866 k=atoi(sstrsep(&p,sep));
2869 d=atof(sstrsep(&p,sep));
2871 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2873 dsa_results[k][0]=d;
2875 d=atof(sstrsep(&p,sep));
2877 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2879 dsa_results[k][1]=d;
2881 #ifndef OPENSSL_NO_ECDSA
2882 else if(!strncmp(buf,"+F4:",4))
2888 k=atoi(sstrsep(&p,sep));
2891 d=atof(sstrsep(&p,sep));
2893 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2895 ecdsa_results[k][0]=d;
2897 d=atof(sstrsep(&p,sep));
2899 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2901 ecdsa_results[k][1]=d;
2905 #ifndef OPENSSL_NO_ECDH
2906 else if(!strncmp(buf,"+F5:",4))
2912 k=atoi(sstrsep(&p,sep));
2915 d=atof(sstrsep(&p,sep));
2917 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2919 ecdh_results[k][0]=d;
2924 else if(!strncmp(buf,"+H:",3))
2928 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);