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_BF
205 #include <openssl/blowfish.h>
207 #ifndef OPENSSL_NO_CAST
208 #include <openssl/cast.h>
210 #ifndef OPENSSL_NO_RSA
211 #include <openssl/rsa.h>
212 #include "./testrsa.h"
214 #include <openssl/x509.h>
215 #ifndef OPENSSL_NO_DSA
216 #include <openssl/dsa.h>
217 #include "./testdsa.h"
219 #ifndef OPENSSL_NO_ECDSA
220 #include <openssl/ecdsa.h>
222 #ifndef OPENSSL_NO_ECDH
223 #include <openssl/ecdh.h>
227 * The following "HZ" timing stuff should be sync'd up with the code in
228 * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
229 * this code is more up to date than libcrypto's so there may be features to
230 * migrate over first. This is used in two places further down AFAICS.
231 * The point is that nothing in openssl actually *uses* that tmdiff stuff, so
232 * either speed.c should be using it or it should go because it's obviously not
233 * useful enough. Anyone want to do a janitorial job on this?
236 /* The following if from times(3) man page. It may need to be changed */
238 # if defined(_SC_CLK_TCK) \
239 && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
240 # define HZ sysconf(_SC_CLK_TCK)
243 # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
245 # else /* _BSD_CLK_TCK_ */
246 # define HZ ((double)_BSD_CLK_TCK_)
249 # define HZ ((double)CLK_TCK)
254 #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE)
259 #define BUFSIZE ((long)1024*8+1)
262 static char ftime_used
= 0, times_used
= 0, gettimeofday_used
= 0, getrusage_used
= 0;
264 static int usertime
=1;
266 static double Time_F(int s
);
267 static void print_message(const char *s
,long num
,int length
);
268 static void pkey_print_message(const char *str
, const char *str2
,
269 long num
, int bits
, int sec
);
270 static void print_result(int alg
,int run_no
,int count
,double time_used
);
272 static int do_multi(int multi
);
281 #define MAX_ECDH_SIZE 256
283 static const char *names
[ALGOR_NUM
]={
284 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
285 "des cbc","des ede3","idea cbc",
286 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
287 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
288 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
289 "evp","sha256","sha512"};
290 static double results
[ALGOR_NUM
][SIZE_NUM
];
291 static int lengths
[SIZE_NUM
]={16,64,256,1024,8*1024};
292 static double rsa_results
[RSA_NUM
][2];
293 static double dsa_results
[DSA_NUM
][2];
294 #ifndef OPENSSL_NO_ECDSA
295 static double ecdsa_results
[EC_NUM
][2];
297 #ifndef OPENSSL_NO_ECDH
298 static double ecdh_results
[EC_NUM
][1];
301 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
302 static const char rnd_seed
[] = "string to make the random number generator think it has entropy";
303 static int rnd_fake
= 0;
307 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
308 #define SIGRETTYPE void
310 #define SIGRETTYPE int
313 static SIGRETTYPE
sig_done(int sig
);
314 static SIGRETTYPE
sig_done(int sig
)
316 signal(SIGALRM
,sig_done
);
327 #if defined(OPENSSL_SYS_NETWARE)
329 /* for NetWare the best we can do is use clock() which returns the
330 * time, in hundredths of a second, since the NLM began executing
332 static double Time_F(int s
)
336 static clock_t tstart
,tend
;
346 ret
=(double)((double)(tend
)-(double)(tstart
));
347 return((ret
< 0.001)?0.001:ret
);
353 static double Time_F(int s
)
360 static struct rusage tstart
,tend
;
365 getrusage(RUSAGE_SELF
,&tstart
);
372 getrusage(RUSAGE_SELF
,&tend
);
373 i
=(long)tend
.ru_utime
.tv_usec
-(long)tstart
.ru_utime
.tv_usec
;
374 ret
=((double)(tend
.ru_utime
.tv_sec
-tstart
.ru_utime
.tv_sec
))
375 +((double)i
)/1000000.0;
376 return((ret
< 0.001)?0.001:ret
);
381 static struct timeval tstart
,tend
;
384 gettimeofday_used
= 1;
387 gettimeofday(&tstart
,NULL
);
392 gettimeofday(&tend
,NULL
);
393 i
=(long)tend
.tv_usec
-(long)tstart
.tv_usec
;
394 ret
=((double)(tend
.tv_sec
-tstart
.tv_sec
))+((double)i
)/1000000.0;
395 return((ret
< 0.001)?0.001:ret
);
398 #else /* ndef USE_TOD */
403 static struct tms tstart
,tend
;
415 ret
=(double)(tend
.tms_utime
-tstart
.tms_utime
) / ret
;
416 return((ret
< 1e-3)?1e-3:ret
);
419 # endif /* times() */
420 # if defined(TIMES) && defined(TIMEB)
423 # ifdef OPENSSL_SYS_VXWORKS
425 static unsigned long tick_start
, tick_end
;
429 tick_start
= tickGet();
434 tick_end
= tickGet();
435 ret
= (double)(tick_end
- tick_start
) / (double)sysClkRateGet();
436 return((ret
< 0.001)?0.001:ret
);
439 # elif defined(TIMEB)
441 static struct timeb tstart
,tend
;
453 i
=(long)tend
.millitm
-(long)tstart
.millitm
;
454 ret
=((double)(tend
.time
-tstart
.time
))+((double)i
)/1000.0;
455 return((ret
< 0.001)?0.001:ret
);
461 #endif /* if defined(OPENSSL_SYS_NETWARE) */
464 #ifndef OPENSSL_NO_ECDH
465 static const int KDF1_SHA1_len
= 20;
466 static void *KDF1_SHA1(const void *in
, size_t inlen
, void *out
, size_t *outlen
)
468 #ifndef OPENSSL_NO_SHA
469 if (*outlen
< SHA_DIGEST_LENGTH
)
472 *outlen
= SHA_DIGEST_LENGTH
;
473 return SHA1(in
, inlen
, out
);
476 #endif /* OPENSSL_NO_SHA */
478 #endif /* OPENSSL_NO_ECDH */
481 int MAIN(int, char **);
483 int MAIN(int argc
, char **argv
)
485 #ifndef OPENSSL_NO_ENGINE
488 unsigned char *buf
=NULL
,*buf2
=NULL
;
490 long count
=0,save_count
=0;
492 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
495 #ifndef OPENSSL_NO_RSA
498 unsigned char md
[EVP_MAX_MD_SIZE
];
499 #ifndef OPENSSL_NO_MD2
500 unsigned char md2
[MD2_DIGEST_LENGTH
];
502 #ifndef OPENSSL_NO_MDC2
503 unsigned char mdc2
[MDC2_DIGEST_LENGTH
];
505 #ifndef OPENSSL_NO_MD4
506 unsigned char md4
[MD4_DIGEST_LENGTH
];
508 #ifndef OPENSSL_NO_MD5
509 unsigned char md5
[MD5_DIGEST_LENGTH
];
510 unsigned char hmac
[MD5_DIGEST_LENGTH
];
512 #ifndef OPENSSL_NO_SHA
513 unsigned char sha
[SHA_DIGEST_LENGTH
];
514 #ifndef OPENSSL_NO_SHA256
515 unsigned char sha256
[SHA256_DIGEST_LENGTH
];
517 #ifndef OPENSSL_NO_SHA512
518 unsigned char sha512
[SHA512_DIGEST_LENGTH
];
521 #ifndef OPENSSL_NO_RIPEMD
522 unsigned char rmd160
[RIPEMD160_DIGEST_LENGTH
];
524 #ifndef OPENSSL_NO_RC4
527 #ifndef OPENSSL_NO_RC5
530 #ifndef OPENSSL_NO_RC2
533 #ifndef OPENSSL_NO_IDEA
534 IDEA_KEY_SCHEDULE idea_ks
;
536 #ifndef OPENSSL_NO_BF
539 #ifndef OPENSSL_NO_CAST
542 static const unsigned char key16
[16]=
543 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
544 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
545 #ifndef OPENSSL_NO_AES
546 static const unsigned char key24
[24]=
547 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
548 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
549 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
550 static const unsigned char key32
[32]=
551 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
552 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
553 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
554 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
556 #ifndef OPENSSL_NO_CAMELLIA
557 static const unsigned char ckey24
[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 ckey32
[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_AES
568 #define MAX_BLOCK_SIZE 128
570 #define MAX_BLOCK_SIZE 64
572 unsigned char DES_iv
[8];
573 unsigned char iv
[MAX_BLOCK_SIZE
/8];
574 #ifndef OPENSSL_NO_DES
575 DES_cblock
*buf_as_des_cblock
= NULL
;
576 static DES_cblock key
={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
577 static DES_cblock key2
={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
578 static DES_cblock key3
={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
579 DES_key_schedule sch
;
580 DES_key_schedule sch2
;
581 DES_key_schedule sch3
;
583 #ifndef OPENSSL_NO_AES
584 AES_KEY aes_ks1
, aes_ks2
, aes_ks3
;
586 #ifndef OPENSSL_NO_CAMELLIA
587 CAMELLIA_KEY camellia_ks1
, camellia_ks2
, camellia_ks3
;
599 #define D_CBC_IDEA 10
603 #define D_CBC_CAST 14
604 #define D_CBC_128_AES 15
605 #define D_CBC_192_AES 16
606 #define D_CBC_256_AES 17
607 #define D_CBC_128_CML 18
608 #define D_CBC_192_CML 19
609 #define D_CBC_256_CML 20
614 long c
[ALGOR_NUM
][SIZE_NUM
];
640 #ifndef OPENSSL_NO_RSA
641 RSA
*rsa_key
[RSA_NUM
];
642 long rsa_c
[RSA_NUM
][2];
643 static unsigned int rsa_bits
[RSA_NUM
]={512,1024,2048,4096};
644 static unsigned char *rsa_data
[RSA_NUM
]=
645 {test512
,test1024
,test2048
,test4096
};
646 static int rsa_data_length
[RSA_NUM
]={
647 sizeof(test512
),sizeof(test1024
),
648 sizeof(test2048
),sizeof(test4096
)};
650 #ifndef OPENSSL_NO_DSA
651 DSA
*dsa_key
[DSA_NUM
];
652 long dsa_c
[DSA_NUM
][2];
653 static unsigned int dsa_bits
[DSA_NUM
]={512,1024,2048};
655 #ifndef OPENSSL_NO_EC
656 /* We only test over the following curves as they are representative,
657 * To add tests over more curves, simply add the curve NID
658 * and curve name to the following arrays and increase the
659 * EC_NUM value accordingly.
661 static unsigned int test_curves
[EC_NUM
] =
665 NID_X9_62_prime192v1
,
667 NID_X9_62_prime256v1
,
682 static const char * test_curves_names
[EC_NUM
] =
703 static int test_curves_bits
[EC_NUM
] =
705 160, 192, 224, 256, 384, 521,
706 163, 233, 283, 409, 571,
707 163, 233, 283, 409, 571
712 #ifndef OPENSSL_NO_ECDSA
713 unsigned char ecdsasig
[256];
714 unsigned int ecdsasiglen
;
715 EC_KEY
*ecdsa
[EC_NUM
];
716 long ecdsa_c
[EC_NUM
][2];
719 #ifndef OPENSSL_NO_ECDH
720 EC_KEY
*ecdh_a
[EC_NUM
], *ecdh_b
[EC_NUM
];
721 unsigned char secret_a
[MAX_ECDH_SIZE
], secret_b
[MAX_ECDH_SIZE
];
722 int secret_size_a
, secret_size_b
;
725 long ecdh_c
[EC_NUM
][2];
728 int rsa_doit
[RSA_NUM
];
729 int dsa_doit
[DSA_NUM
];
730 #ifndef OPENSSL_NO_ECDSA
731 int ecdsa_doit
[EC_NUM
];
733 #ifndef OPENSSL_NO_ECDH
734 int ecdh_doit
[EC_NUM
];
738 const EVP_CIPHER
*evp_cipher
=NULL
;
739 const EVP_MD
*evp_md
=NULL
;
750 memset(results
, 0, sizeof(results
));
751 #ifndef OPENSSL_NO_DSA
752 memset(dsa_key
,0,sizeof(dsa_key
));
754 #ifndef OPENSSL_NO_ECDSA
755 for (i
=0; i
<EC_NUM
; i
++) ecdsa
[i
] = NULL
;
757 #ifndef OPENSSL_NO_ECDH
758 for (i
=0; i
<EC_NUM
; i
++)
767 if ((bio_err
=BIO_new(BIO_s_file())) != NULL
)
768 BIO_set_fp(bio_err
,stderr
,BIO_NOCLOSE
|BIO_FP_TEXT
);
770 if (!load_config(bio_err
, NULL
))
773 #ifndef OPENSSL_NO_RSA
774 memset(rsa_key
,0,sizeof(rsa_key
));
775 for (i
=0; i
<RSA_NUM
; i
++)
779 if ((buf
=(unsigned char *)OPENSSL_malloc((int)BUFSIZE
)) == NULL
)
781 BIO_printf(bio_err
,"out of memory\n");
784 #ifndef OPENSSL_NO_DES
785 buf_as_des_cblock
= (DES_cblock
*)buf
;
787 if ((buf2
=(unsigned char *)OPENSSL_malloc((int)BUFSIZE
)) == NULL
)
789 BIO_printf(bio_err
,"out of memory\n");
793 memset(c
,0,sizeof(c
));
794 memset(DES_iv
,0,sizeof(DES_iv
));
795 memset(iv
,0,sizeof(iv
));
797 for (i
=0; i
<ALGOR_NUM
; i
++)
799 for (i
=0; i
<RSA_NUM
; i
++)
801 for (i
=0; i
<DSA_NUM
; i
++)
803 #ifndef OPENSSL_NO_ECDSA
804 for (i
=0; i
<EC_NUM
; i
++)
807 #ifndef OPENSSL_NO_ECDH
808 for (i
=0; i
<EC_NUM
; i
++)
818 if ((argc
> 0) && (strcmp(*argv
,"-elapsed") == 0))
821 j
--; /* Otherwise, -elapsed gets confused with
824 else if ((argc
> 0) && (strcmp(*argv
,"-evp") == 0))
830 BIO_printf(bio_err
,"no EVP given\n");
833 evp_cipher
=EVP_get_cipherbyname(*argv
);
836 evp_md
=EVP_get_digestbyname(*argv
);
838 if(!evp_cipher
&& !evp_md
)
840 BIO_printf(bio_err
,"%s is an unknown cipher or digest\n",*argv
);
845 else if (argc
> 0 && !strcmp(*argv
,"-decrypt"))
848 j
--; /* Otherwise, -elapsed gets confused with
851 #ifndef OPENSSL_NO_ENGINE
852 else if ((argc
> 0) && (strcmp(*argv
,"-engine") == 0))
858 BIO_printf(bio_err
,"no engine given\n");
861 e
= setup_engine(bio_err
, *argv
, 0);
862 /* j will be increased again further down. We just
863 don't want speed to confuse an engine with an
864 algorithm, especially when none is given (which
865 means all of them should be run) */
870 else if ((argc
> 0) && (strcmp(*argv
,"-multi") == 0))
876 BIO_printf(bio_err
,"no multi count given\n");
882 BIO_printf(bio_err
,"bad multi count\n");
885 j
--; /* Otherwise, -mr gets confused with
889 else if (argc
> 0 && !strcmp(*argv
,"-mr"))
892 j
--; /* Otherwise, -mr gets confused with
896 #ifndef OPENSSL_NO_MD2
897 if (strcmp(*argv
,"md2") == 0) doit
[D_MD2
]=1;
900 #ifndef OPENSSL_NO_MDC2
901 if (strcmp(*argv
,"mdc2") == 0) doit
[D_MDC2
]=1;
904 #ifndef OPENSSL_NO_MD4
905 if (strcmp(*argv
,"md4") == 0) doit
[D_MD4
]=1;
908 #ifndef OPENSSL_NO_MD5
909 if (strcmp(*argv
,"md5") == 0) doit
[D_MD5
]=1;
912 #ifndef OPENSSL_NO_MD5
913 if (strcmp(*argv
,"hmac") == 0) doit
[D_HMAC
]=1;
916 #ifndef OPENSSL_NO_SHA
917 if (strcmp(*argv
,"sha1") == 0) doit
[D_SHA1
]=1;
919 if (strcmp(*argv
,"sha") == 0) doit
[D_SHA1
]=1,
923 #ifndef OPENSSL_NO_SHA256
924 if (strcmp(*argv
,"sha256") == 0) doit
[D_SHA256
]=1;
927 #ifndef OPENSSL_NO_SHA512
928 if (strcmp(*argv
,"sha512") == 0) doit
[D_SHA512
]=1;
932 #ifndef OPENSSL_NO_RIPEMD
933 if (strcmp(*argv
,"ripemd") == 0) doit
[D_RMD160
]=1;
935 if (strcmp(*argv
,"rmd160") == 0) doit
[D_RMD160
]=1;
937 if (strcmp(*argv
,"ripemd160") == 0) doit
[D_RMD160
]=1;
940 #ifndef OPENSSL_NO_RC4
941 if (strcmp(*argv
,"rc4") == 0) doit
[D_RC4
]=1;
944 #ifndef OPENSSL_NO_DES
945 if (strcmp(*argv
,"des-cbc") == 0) doit
[D_CBC_DES
]=1;
946 else if (strcmp(*argv
,"des-ede3") == 0) doit
[D_EDE3_DES
]=1;
949 #ifndef OPENSSL_NO_AES
950 if (strcmp(*argv
,"aes-128-cbc") == 0) doit
[D_CBC_128_AES
]=1;
951 else if (strcmp(*argv
,"aes-192-cbc") == 0) doit
[D_CBC_192_AES
]=1;
952 else if (strcmp(*argv
,"aes-256-cbc") == 0) doit
[D_CBC_256_AES
]=1;
955 #ifndef OPENSSL_NO_CAMELLIA
956 if (strcmp(*argv
,"camellia-128-cbc") == 0) doit
[D_CBC_128_CML
]=1;
957 else if (strcmp(*argv
,"camellia-192-cbc") == 0) doit
[D_CBC_192_CML
]=1;
958 else if (strcmp(*argv
,"camellia-256-cbc") == 0) doit
[D_CBC_256_CML
]=1;
961 #ifndef OPENSSL_NO_RSA
962 #if 0 /* was: #ifdef RSAref */
963 if (strcmp(*argv
,"rsaref") == 0)
965 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
971 if (strcmp(*argv
,"openssl") == 0)
973 RSA_set_default_method(RSA_PKCS1_SSLeay());
978 #endif /* !OPENSSL_NO_RSA */
979 if (strcmp(*argv
,"dsa512") == 0) dsa_doit
[R_DSA_512
]=2;
980 else if (strcmp(*argv
,"dsa1024") == 0) dsa_doit
[R_DSA_1024
]=2;
981 else if (strcmp(*argv
,"dsa2048") == 0) dsa_doit
[R_DSA_2048
]=2;
982 else if (strcmp(*argv
,"rsa512") == 0) rsa_doit
[R_RSA_512
]=2;
983 else if (strcmp(*argv
,"rsa1024") == 0) rsa_doit
[R_RSA_1024
]=2;
984 else if (strcmp(*argv
,"rsa2048") == 0) rsa_doit
[R_RSA_2048
]=2;
985 else if (strcmp(*argv
,"rsa4096") == 0) rsa_doit
[R_RSA_4096
]=2;
987 #ifndef OPENSSL_NO_RC2
988 if (strcmp(*argv
,"rc2-cbc") == 0) doit
[D_CBC_RC2
]=1;
989 else if (strcmp(*argv
,"rc2") == 0) doit
[D_CBC_RC2
]=1;
992 #ifndef OPENSSL_NO_RC5
993 if (strcmp(*argv
,"rc5-cbc") == 0) doit
[D_CBC_RC5
]=1;
994 else if (strcmp(*argv
,"rc5") == 0) doit
[D_CBC_RC5
]=1;
997 #ifndef OPENSSL_NO_IDEA
998 if (strcmp(*argv
,"idea-cbc") == 0) doit
[D_CBC_IDEA
]=1;
999 else if (strcmp(*argv
,"idea") == 0) doit
[D_CBC_IDEA
]=1;
1002 #ifndef OPENSSL_NO_BF
1003 if (strcmp(*argv
,"bf-cbc") == 0) doit
[D_CBC_BF
]=1;
1004 else if (strcmp(*argv
,"blowfish") == 0) doit
[D_CBC_BF
]=1;
1005 else if (strcmp(*argv
,"bf") == 0) doit
[D_CBC_BF
]=1;
1008 #ifndef OPENSSL_NO_CAST
1009 if (strcmp(*argv
,"cast-cbc") == 0) doit
[D_CBC_CAST
]=1;
1010 else if (strcmp(*argv
,"cast") == 0) doit
[D_CBC_CAST
]=1;
1011 else if (strcmp(*argv
,"cast5") == 0) doit
[D_CBC_CAST
]=1;
1014 #ifndef OPENSSL_NO_DES
1015 if (strcmp(*argv
,"des") == 0)
1022 #ifndef OPENSSL_NO_AES
1023 if (strcmp(*argv
,"aes") == 0)
1025 doit
[D_CBC_128_AES
]=1;
1026 doit
[D_CBC_192_AES
]=1;
1027 doit
[D_CBC_256_AES
]=1;
1031 #ifndef OPENSSL_NO_CAMELLIA
1032 if (strcmp(*argv
,"camellia") == 0)
1034 doit
[D_CBC_128_CML
]=1;
1035 doit
[D_CBC_192_CML
]=1;
1036 doit
[D_CBC_256_CML
]=1;
1040 #ifndef OPENSSL_NO_RSA
1041 if (strcmp(*argv
,"rsa") == 0)
1043 rsa_doit
[R_RSA_512
]=1;
1044 rsa_doit
[R_RSA_1024
]=1;
1045 rsa_doit
[R_RSA_2048
]=1;
1046 rsa_doit
[R_RSA_4096
]=1;
1050 #ifndef OPENSSL_NO_DSA
1051 if (strcmp(*argv
,"dsa") == 0)
1053 dsa_doit
[R_DSA_512
]=1;
1054 dsa_doit
[R_DSA_1024
]=1;
1055 dsa_doit
[R_DSA_2048
]=1;
1059 #ifndef OPENSSL_NO_ECDSA
1060 if (strcmp(*argv
,"ecdsap160") == 0) ecdsa_doit
[R_EC_P160
]=2;
1061 else if (strcmp(*argv
,"ecdsap192") == 0) ecdsa_doit
[R_EC_P192
]=2;
1062 else if (strcmp(*argv
,"ecdsap224") == 0) ecdsa_doit
[R_EC_P224
]=2;
1063 else if (strcmp(*argv
,"ecdsap256") == 0) ecdsa_doit
[R_EC_P256
]=2;
1064 else if (strcmp(*argv
,"ecdsap384") == 0) ecdsa_doit
[R_EC_P384
]=2;
1065 else if (strcmp(*argv
,"ecdsap521") == 0) ecdsa_doit
[R_EC_P521
]=2;
1066 else if (strcmp(*argv
,"ecdsak163") == 0) ecdsa_doit
[R_EC_K163
]=2;
1067 else if (strcmp(*argv
,"ecdsak233") == 0) ecdsa_doit
[R_EC_K233
]=2;
1068 else if (strcmp(*argv
,"ecdsak283") == 0) ecdsa_doit
[R_EC_K283
]=2;
1069 else if (strcmp(*argv
,"ecdsak409") == 0) ecdsa_doit
[R_EC_K409
]=2;
1070 else if (strcmp(*argv
,"ecdsak571") == 0) ecdsa_doit
[R_EC_K571
]=2;
1071 else if (strcmp(*argv
,"ecdsab163") == 0) ecdsa_doit
[R_EC_B163
]=2;
1072 else if (strcmp(*argv
,"ecdsab233") == 0) ecdsa_doit
[R_EC_B233
]=2;
1073 else if (strcmp(*argv
,"ecdsab283") == 0) ecdsa_doit
[R_EC_B283
]=2;
1074 else if (strcmp(*argv
,"ecdsab409") == 0) ecdsa_doit
[R_EC_B409
]=2;
1075 else if (strcmp(*argv
,"ecdsab571") == 0) ecdsa_doit
[R_EC_B571
]=2;
1076 else if (strcmp(*argv
,"ecdsa") == 0)
1078 for (i
=0; i
< EC_NUM
; i
++)
1083 #ifndef OPENSSL_NO_ECDH
1084 if (strcmp(*argv
,"ecdhp160") == 0) ecdh_doit
[R_EC_P160
]=2;
1085 else if (strcmp(*argv
,"ecdhp192") == 0) ecdh_doit
[R_EC_P192
]=2;
1086 else if (strcmp(*argv
,"ecdhp224") == 0) ecdh_doit
[R_EC_P224
]=2;
1087 else if (strcmp(*argv
,"ecdhp256") == 0) ecdh_doit
[R_EC_P256
]=2;
1088 else if (strcmp(*argv
,"ecdhp384") == 0) ecdh_doit
[R_EC_P384
]=2;
1089 else if (strcmp(*argv
,"ecdhp521") == 0) ecdh_doit
[R_EC_P521
]=2;
1090 else if (strcmp(*argv
,"ecdhk163") == 0) ecdh_doit
[R_EC_K163
]=2;
1091 else if (strcmp(*argv
,"ecdhk233") == 0) ecdh_doit
[R_EC_K233
]=2;
1092 else if (strcmp(*argv
,"ecdhk283") == 0) ecdh_doit
[R_EC_K283
]=2;
1093 else if (strcmp(*argv
,"ecdhk409") == 0) ecdh_doit
[R_EC_K409
]=2;
1094 else if (strcmp(*argv
,"ecdhk571") == 0) ecdh_doit
[R_EC_K571
]=2;
1095 else if (strcmp(*argv
,"ecdhb163") == 0) ecdh_doit
[R_EC_B163
]=2;
1096 else if (strcmp(*argv
,"ecdhb233") == 0) ecdh_doit
[R_EC_B233
]=2;
1097 else if (strcmp(*argv
,"ecdhb283") == 0) ecdh_doit
[R_EC_B283
]=2;
1098 else if (strcmp(*argv
,"ecdhb409") == 0) ecdh_doit
[R_EC_B409
]=2;
1099 else if (strcmp(*argv
,"ecdhb571") == 0) ecdh_doit
[R_EC_B571
]=2;
1100 else if (strcmp(*argv
,"ecdh") == 0)
1102 for (i
=0; i
< EC_NUM
; i
++)
1108 BIO_printf(bio_err
,"Error: bad option or value\n");
1109 BIO_printf(bio_err
,"\n");
1110 BIO_printf(bio_err
,"Available values:\n");
1111 #ifndef OPENSSL_NO_MD2
1112 BIO_printf(bio_err
,"md2 ");
1114 #ifndef OPENSSL_NO_MDC2
1115 BIO_printf(bio_err
,"mdc2 ");
1117 #ifndef OPENSSL_NO_MD4
1118 BIO_printf(bio_err
,"md4 ");
1120 #ifndef OPENSSL_NO_MD5
1121 BIO_printf(bio_err
,"md5 ");
1122 #ifndef OPENSSL_NO_HMAC
1123 BIO_printf(bio_err
,"hmac ");
1126 #ifndef OPENSSL_NO_SHA1
1127 BIO_printf(bio_err
,"sha1 ");
1129 #ifndef OPENSSL_NO_SHA256
1130 BIO_printf(bio_err
,"sha256 ");
1132 #ifndef OPENSSL_NO_SHA512
1133 BIO_printf(bio_err
,"sha512 ");
1135 #ifndef OPENSSL_NO_RIPEMD160
1136 BIO_printf(bio_err
,"rmd160");
1138 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1139 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1140 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
1141 BIO_printf(bio_err
,"\n");
1144 #ifndef OPENSSL_NO_IDEA
1145 BIO_printf(bio_err
,"idea-cbc ");
1147 #ifndef OPENSSL_NO_RC2
1148 BIO_printf(bio_err
,"rc2-cbc ");
1150 #ifndef OPENSSL_NO_RC5
1151 BIO_printf(bio_err
,"rc5-cbc ");
1153 #ifndef OPENSSL_NO_BF
1154 BIO_printf(bio_err
,"bf-cbc");
1156 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
1157 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1158 BIO_printf(bio_err
,"\n");
1160 #ifndef OPENSSL_NO_DES
1161 BIO_printf(bio_err
,"des-cbc des-ede3 ");
1163 #ifndef OPENSSL_NO_AES
1164 BIO_printf(bio_err
,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1166 #ifndef OPENSSL_NO_CAMELLIA
1167 BIO_printf(bio_err
,"\n");
1168 BIO_printf(bio_err
,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1170 #ifndef OPENSSL_NO_RC4
1171 BIO_printf(bio_err
,"rc4");
1173 BIO_printf(bio_err
,"\n");
1175 #ifndef OPENSSL_NO_RSA
1176 BIO_printf(bio_err
,"rsa512 rsa1024 rsa2048 rsa4096\n");
1179 #ifndef OPENSSL_NO_DSA
1180 BIO_printf(bio_err
,"dsa512 dsa1024 dsa2048\n");
1182 #ifndef OPENSSL_NO_ECDSA
1183 BIO_printf(bio_err
,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1184 BIO_printf(bio_err
,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1185 BIO_printf(bio_err
,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1186 BIO_printf(bio_err
,"ecdsa\n");
1188 #ifndef OPENSSL_NO_ECDH
1189 BIO_printf(bio_err
,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1190 BIO_printf(bio_err
,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1191 BIO_printf(bio_err
,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1192 BIO_printf(bio_err
,"ecdh\n");
1195 #ifndef OPENSSL_NO_IDEA
1196 BIO_printf(bio_err
,"idea ");
1198 #ifndef OPENSSL_NO_RC2
1199 BIO_printf(bio_err
,"rc2 ");
1201 #ifndef OPENSSL_NO_DES
1202 BIO_printf(bio_err
,"des ");
1204 #ifndef OPENSSL_NO_AES
1205 BIO_printf(bio_err
,"aes ");
1207 #ifndef OPENSSL_NO_CAMELLIA
1208 BIO_printf(bio_err
,"camellia ");
1210 #ifndef OPENSSL_NO_RSA
1211 BIO_printf(bio_err
,"rsa ");
1213 #ifndef OPENSSL_NO_BF
1214 BIO_printf(bio_err
,"blowfish");
1216 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
1217 !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
1218 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES) || \
1219 !defined(OPENSSL_NO_CAMELLIA)
1220 BIO_printf(bio_err
,"\n");
1223 BIO_printf(bio_err
,"\n");
1224 BIO_printf(bio_err
,"Available options:\n");
1225 #if defined(TIMES) || defined(USE_TOD)
1226 BIO_printf(bio_err
,"-elapsed measure time in real time instead of CPU user time.\n");
1228 #ifndef OPENSSL_NO_ENGINE
1229 BIO_printf(bio_err
,"-engine e use engine e, possibly a hardware device.\n");
1231 BIO_printf(bio_err
,"-evp e use EVP e.\n");
1232 BIO_printf(bio_err
,"-decrypt time decryption instead of encryption (only EVP).\n");
1233 BIO_printf(bio_err
,"-mr produce machine readable output.\n");
1235 BIO_printf(bio_err
,"-multi n run n benchmarks in parallel.\n");
1245 if(multi
&& do_multi(multi
))
1251 for (i
=0; i
<ALGOR_NUM
; i
++)
1256 for (i
=0; i
<RSA_NUM
; i
++)
1258 for (i
=0; i
<DSA_NUM
; i
++)
1261 for (i
=0; i
<ALGOR_NUM
; i
++)
1262 if (doit
[i
]) pr_header
++;
1264 if (usertime
== 0 && !mr
)
1265 BIO_printf(bio_err
,"You have chosen to measure elapsed time instead of user CPU time.\n");
1266 if (usertime
<= 0 && !mr
)
1268 BIO_printf(bio_err
,"To get the most accurate results, try to run this\n");
1269 BIO_printf(bio_err
,"program when this computer is idle.\n");
1272 #ifndef OPENSSL_NO_RSA
1273 for (i
=0; i
<RSA_NUM
; i
++)
1275 const unsigned char *p
;
1278 rsa_key
[i
]=d2i_RSAPrivateKey(NULL
,&p
,rsa_data_length
[i
]);
1279 if (rsa_key
[i
] == NULL
)
1281 BIO_printf(bio_err
,"internal error loading RSA key number %d\n",i
);
1287 BIO_printf(bio_err
,mr
? "+RK:%d:"
1288 : "Loaded RSA key, %d bit modulus and e= 0x",
1289 BN_num_bits(rsa_key
[i
]->n
));
1290 BN_print(bio_err
,rsa_key
[i
]->e
);
1291 BIO_printf(bio_err
,"\n");
1297 #ifndef OPENSSL_NO_DSA
1298 dsa_key
[0]=get_dsa512();
1299 dsa_key
[1]=get_dsa1024();
1300 dsa_key
[2]=get_dsa2048();
1303 #ifndef OPENSSL_NO_DES
1304 DES_set_key_unchecked(&key
,&sch
);
1305 DES_set_key_unchecked(&key2
,&sch2
);
1306 DES_set_key_unchecked(&key3
,&sch3
);
1308 #ifndef OPENSSL_NO_AES
1309 AES_set_encrypt_key(key16
,128,&aes_ks1
);
1310 AES_set_encrypt_key(key24
,192,&aes_ks2
);
1311 AES_set_encrypt_key(key32
,256,&aes_ks3
);
1313 #ifndef OPENSSL_NO_CAMELLIA
1314 Camellia_set_key(key16
,128,&camellia_ks1
);
1315 Camellia_set_key(ckey24
,192,&camellia_ks2
);
1316 Camellia_set_key(ckey32
,256,&camellia_ks3
);
1318 #ifndef OPENSSL_NO_IDEA
1319 idea_set_encrypt_key(key16
,&idea_ks
);
1321 #ifndef OPENSSL_NO_RC4
1322 RC4_set_key(&rc4_ks
,16,key16
);
1324 #ifndef OPENSSL_NO_RC2
1325 RC2_set_key(&rc2_ks
,16,key16
,128);
1327 #ifndef OPENSSL_NO_RC5
1328 RC5_32_set_key(&rc5_ks
,16,key16
,12);
1330 #ifndef OPENSSL_NO_BF
1331 BF_set_key(&bf_ks
,16,key16
);
1333 #ifndef OPENSSL_NO_CAST
1334 CAST_set_key(&cast_ks
,16,key16
);
1336 #ifndef OPENSSL_NO_RSA
1337 memset(rsa_c
,0,sizeof(rsa_c
));
1340 #ifndef OPENSSL_NO_DES
1341 BIO_printf(bio_err
,"First we calculate the approximate speed ...\n");
1347 for (it
=count
; it
; it
--)
1348 DES_ecb_encrypt(buf_as_des_cblock
,buf_as_des_cblock
,
1353 c
[D_MD2
][0]=count
/10;
1354 c
[D_MDC2
][0]=count
/10;
1359 c
[D_RMD160
][0]=count
;
1360 c
[D_RC4
][0]=count
*5;
1361 c
[D_CBC_DES
][0]=count
;
1362 c
[D_EDE3_DES
][0]=count
/3;
1363 c
[D_CBC_IDEA
][0]=count
;
1364 c
[D_CBC_RC2
][0]=count
;
1365 c
[D_CBC_RC5
][0]=count
;
1366 c
[D_CBC_BF
][0]=count
;
1367 c
[D_CBC_CAST
][0]=count
;
1368 c
[D_CBC_128_AES
][0]=count
;
1369 c
[D_CBC_192_AES
][0]=count
;
1370 c
[D_CBC_256_AES
][0]=count
;
1371 c
[D_CBC_128_CML
][0]=count
;
1372 c
[D_CBC_192_CML
][0]=count
;
1373 c
[D_CBC_256_CML
][0]=count
;
1374 c
[D_SHA256
][0]=count
;
1375 c
[D_SHA512
][0]=count
;
1377 for (i
=1; i
<SIZE_NUM
; i
++)
1379 c
[D_MD2
][i
]=c
[D_MD2
][0]*4*lengths
[0]/lengths
[i
];
1380 c
[D_MDC2
][i
]=c
[D_MDC2
][0]*4*lengths
[0]/lengths
[i
];
1381 c
[D_MD4
][i
]=c
[D_MD4
][0]*4*lengths
[0]/lengths
[i
];
1382 c
[D_MD5
][i
]=c
[D_MD5
][0]*4*lengths
[0]/lengths
[i
];
1383 c
[D_HMAC
][i
]=c
[D_HMAC
][0]*4*lengths
[0]/lengths
[i
];
1384 c
[D_SHA1
][i
]=c
[D_SHA1
][0]*4*lengths
[0]/lengths
[i
];
1385 c
[D_RMD160
][i
]=c
[D_RMD160
][0]*4*lengths
[0]/lengths
[i
];
1386 c
[D_SHA256
][i
]=c
[D_SHA256
][0]*4*lengths
[0]/lengths
[i
];
1387 c
[D_SHA512
][i
]=c
[D_SHA512
][0]*4*lengths
[0]/lengths
[i
];
1389 for (i
=1; i
<SIZE_NUM
; i
++)
1393 l0
=(long)lengths
[i
-1];
1394 l1
=(long)lengths
[i
];
1395 c
[D_RC4
][i
]=c
[D_RC4
][i
-1]*l0
/l1
;
1396 c
[D_CBC_DES
][i
]=c
[D_CBC_DES
][i
-1]*l0
/l1
;
1397 c
[D_EDE3_DES
][i
]=c
[D_EDE3_DES
][i
-1]*l0
/l1
;
1398 c
[D_CBC_IDEA
][i
]=c
[D_CBC_IDEA
][i
-1]*l0
/l1
;
1399 c
[D_CBC_RC2
][i
]=c
[D_CBC_RC2
][i
-1]*l0
/l1
;
1400 c
[D_CBC_RC5
][i
]=c
[D_CBC_RC5
][i
-1]*l0
/l1
;
1401 c
[D_CBC_BF
][i
]=c
[D_CBC_BF
][i
-1]*l0
/l1
;
1402 c
[D_CBC_CAST
][i
]=c
[D_CBC_CAST
][i
-1]*l0
/l1
;
1403 c
[D_CBC_128_AES
][i
]=c
[D_CBC_128_AES
][i
-1]*l0
/l1
;
1404 c
[D_CBC_192_AES
][i
]=c
[D_CBC_192_AES
][i
-1]*l0
/l1
;
1405 c
[D_CBC_256_AES
][i
]=c
[D_CBC_256_AES
][i
-1]*l0
/l1
;
1406 c
[D_CBC_128_CML
][i
]=c
[D_CBC_128_CML
][i
-1]*l0
/l1
;
1407 c
[D_CBC_192_CML
][i
]=c
[D_CBC_192_CML
][i
-1]*l0
/l1
;
1408 c
[D_CBC_256_CML
][i
]=c
[D_CBC_256_CML
][i
-1]*l0
/l1
;
1410 #ifndef OPENSSL_NO_RSA
1411 rsa_c
[R_RSA_512
][0]=count
/2000;
1412 rsa_c
[R_RSA_512
][1]=count
/400;
1413 for (i
=1; i
<RSA_NUM
; i
++)
1415 rsa_c
[i
][0]=rsa_c
[i
-1][0]/8;
1416 rsa_c
[i
][1]=rsa_c
[i
-1][1]/4;
1417 if ((rsa_doit
[i
] <= 1) && (rsa_c
[i
][0] == 0))
1421 if (rsa_c
[i
][0] == 0)
1430 #ifndef OPENSSL_NO_DSA
1431 dsa_c
[R_DSA_512
][0]=count
/1000;
1432 dsa_c
[R_DSA_512
][1]=count
/1000/2;
1433 for (i
=1; i
<DSA_NUM
; i
++)
1435 dsa_c
[i
][0]=dsa_c
[i
-1][0]/4;
1436 dsa_c
[i
][1]=dsa_c
[i
-1][1]/4;
1437 if ((dsa_doit
[i
] <= 1) && (dsa_c
[i
][0] == 0))
1450 #ifndef OPENSSL_NO_ECDSA
1451 ecdsa_c
[R_EC_P160
][0]=count
/1000;
1452 ecdsa_c
[R_EC_P160
][1]=count
/1000/2;
1453 for (i
=R_EC_P192
; i
<=R_EC_P521
; i
++)
1455 ecdsa_c
[i
][0]=ecdsa_c
[i
-1][0]/2;
1456 ecdsa_c
[i
][1]=ecdsa_c
[i
-1][1]/2;
1457 if ((ecdsa_doit
[i
] <= 1) && (ecdsa_c
[i
][0] == 0))
1461 if (ecdsa_c
[i
] == 0)
1468 ecdsa_c
[R_EC_K163
][0]=count
/1000;
1469 ecdsa_c
[R_EC_K163
][1]=count
/1000/2;
1470 for (i
=R_EC_K233
; i
<=R_EC_K571
; i
++)
1472 ecdsa_c
[i
][0]=ecdsa_c
[i
-1][0]/2;
1473 ecdsa_c
[i
][1]=ecdsa_c
[i
-1][1]/2;
1474 if ((ecdsa_doit
[i
] <= 1) && (ecdsa_c
[i
][0] == 0))
1478 if (ecdsa_c
[i
] == 0)
1485 ecdsa_c
[R_EC_B163
][0]=count
/1000;
1486 ecdsa_c
[R_EC_B163
][1]=count
/1000/2;
1487 for (i
=R_EC_B233
; i
<=R_EC_B571
; i
++)
1489 ecdsa_c
[i
][0]=ecdsa_c
[i
-1][0]/2;
1490 ecdsa_c
[i
][1]=ecdsa_c
[i
-1][1]/2;
1491 if ((ecdsa_doit
[i
] <= 1) && (ecdsa_c
[i
][0] == 0))
1495 if (ecdsa_c
[i
] == 0)
1504 #ifndef OPENSSL_NO_ECDH
1505 ecdh_c
[R_EC_P160
][0]=count
/1000;
1506 ecdh_c
[R_EC_P160
][1]=count
/1000;
1507 for (i
=R_EC_P192
; i
<=R_EC_P521
; i
++)
1509 ecdh_c
[i
][0]=ecdh_c
[i
-1][0]/2;
1510 ecdh_c
[i
][1]=ecdh_c
[i
-1][1]/2;
1511 if ((ecdh_doit
[i
] <= 1) && (ecdh_c
[i
][0] == 0))
1522 ecdh_c
[R_EC_K163
][0]=count
/1000;
1523 ecdh_c
[R_EC_K163
][1]=count
/1000;
1524 for (i
=R_EC_K233
; i
<=R_EC_K571
; i
++)
1526 ecdh_c
[i
][0]=ecdh_c
[i
-1][0]/2;
1527 ecdh_c
[i
][1]=ecdh_c
[i
-1][1]/2;
1528 if ((ecdh_doit
[i
] <= 1) && (ecdh_c
[i
][0] == 0))
1539 ecdh_c
[R_EC_B163
][0]=count
/1000;
1540 ecdh_c
[R_EC_B163
][1]=count
/1000;
1541 for (i
=R_EC_B233
; i
<=R_EC_B571
; i
++)
1543 ecdh_c
[i
][0]=ecdh_c
[i
-1][0]/2;
1544 ecdh_c
[i
][1]=ecdh_c
[i
-1][1]/2;
1545 if ((ecdh_doit
[i
] <= 1) && (ecdh_c
[i
][0] == 0))
1558 #define COND(d) (count < (d))
1559 #define COUNT(d) (d)
1561 /* not worth fixing */
1562 # error "You cannot disable DES on systems without SIGALRM."
1563 #endif /* OPENSSL_NO_DES */
1565 #define COND(c) (run)
1566 #define COUNT(d) (count)
1567 signal(SIGALRM
,sig_done
);
1568 #endif /* SIGALRM */
1570 #ifndef OPENSSL_NO_MD2
1573 for (j
=0; j
<SIZE_NUM
; j
++)
1575 print_message(names
[D_MD2
],c
[D_MD2
][j
],lengths
[j
]);
1577 for (count
=0,run
=1; COND(c
[D_MD2
][j
]); count
++)
1578 EVP_Digest(buf
,(unsigned long)lengths
[j
],&(md2
[0]),NULL
,EVP_md2(),NULL
);
1580 print_result(D_MD2
,j
,count
,d
);
1584 #ifndef OPENSSL_NO_MDC2
1587 for (j
=0; j
<SIZE_NUM
; j
++)
1589 print_message(names
[D_MDC2
],c
[D_MDC2
][j
],lengths
[j
]);
1591 for (count
=0,run
=1; COND(c
[D_MDC2
][j
]); count
++)
1592 EVP_Digest(buf
,(unsigned long)lengths
[j
],&(mdc2
[0]),NULL
,EVP_mdc2(),NULL
);
1594 print_result(D_MDC2
,j
,count
,d
);
1599 #ifndef OPENSSL_NO_MD4
1602 for (j
=0; j
<SIZE_NUM
; j
++)
1604 print_message(names
[D_MD4
],c
[D_MD4
][j
],lengths
[j
]);
1606 for (count
=0,run
=1; COND(c
[D_MD4
][j
]); count
++)
1607 EVP_Digest(&(buf
[0]),(unsigned long)lengths
[j
],&(md4
[0]),NULL
,EVP_md4(),NULL
);
1609 print_result(D_MD4
,j
,count
,d
);
1614 #ifndef OPENSSL_NO_MD5
1617 for (j
=0; j
<SIZE_NUM
; j
++)
1619 print_message(names
[D_MD5
],c
[D_MD5
][j
],lengths
[j
]);
1621 for (count
=0,run
=1; COND(c
[D_MD5
][j
]); count
++)
1622 EVP_Digest(&(buf
[0]),(unsigned long)lengths
[j
],&(md5
[0]),NULL
,EVP_get_digestbyname("md5"),NULL
);
1624 print_result(D_MD5
,j
,count
,d
);
1629 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1634 HMAC_CTX_init(&hctx
);
1635 HMAC_Init_ex(&hctx
,(unsigned char *)"This is a key...",
1636 16,EVP_md5(), NULL
);
1638 for (j
=0; j
<SIZE_NUM
; j
++)
1640 print_message(names
[D_HMAC
],c
[D_HMAC
][j
],lengths
[j
]);
1642 for (count
=0,run
=1; COND(c
[D_HMAC
][j
]); count
++)
1644 HMAC_Init_ex(&hctx
,NULL
,0,NULL
,NULL
);
1645 HMAC_Update(&hctx
,buf
,lengths
[j
]);
1646 HMAC_Final(&hctx
,&(hmac
[0]),NULL
);
1649 print_result(D_HMAC
,j
,count
,d
);
1651 HMAC_CTX_cleanup(&hctx
);
1654 #ifndef OPENSSL_NO_SHA
1657 for (j
=0; j
<SIZE_NUM
; j
++)
1659 print_message(names
[D_SHA1
],c
[D_SHA1
][j
],lengths
[j
]);
1661 for (count
=0,run
=1; COND(c
[D_SHA1
][j
]); count
++)
1662 EVP_Digest(buf
,(unsigned long)lengths
[j
],&(sha
[0]),NULL
,EVP_sha1(),NULL
);
1664 print_result(D_SHA1
,j
,count
,d
);
1668 #ifndef OPENSSL_NO_SHA256
1671 for (j
=0; j
<SIZE_NUM
; j
++)
1673 print_message(names
[D_SHA256
],c
[D_SHA256
][j
],lengths
[j
]);
1675 for (count
=0,run
=1; COND(c
[D_SHA256
][j
]); count
++)
1676 SHA256(buf
,lengths
[j
],sha256
);
1678 print_result(D_SHA256
,j
,count
,d
);
1683 #ifndef OPENSSL_NO_SHA512
1686 for (j
=0; j
<SIZE_NUM
; j
++)
1688 print_message(names
[D_SHA512
],c
[D_SHA512
][j
],lengths
[j
]);
1690 for (count
=0,run
=1; COND(c
[D_SHA512
][j
]); count
++)
1691 SHA512(buf
,lengths
[j
],sha512
);
1693 print_result(D_SHA512
,j
,count
,d
);
1699 #ifndef OPENSSL_NO_RIPEMD
1702 for (j
=0; j
<SIZE_NUM
; j
++)
1704 print_message(names
[D_RMD160
],c
[D_RMD160
][j
],lengths
[j
]);
1706 for (count
=0,run
=1; COND(c
[D_RMD160
][j
]); count
++)
1707 EVP_Digest(buf
,(unsigned long)lengths
[j
],&(rmd160
[0]),NULL
,EVP_ripemd160(),NULL
);
1709 print_result(D_RMD160
,j
,count
,d
);
1713 #ifndef OPENSSL_NO_RC4
1716 for (j
=0; j
<SIZE_NUM
; j
++)
1718 print_message(names
[D_RC4
],c
[D_RC4
][j
],lengths
[j
]);
1720 for (count
=0,run
=1; COND(c
[D_RC4
][j
]); count
++)
1721 RC4(&rc4_ks
,(unsigned int)lengths
[j
],
1724 print_result(D_RC4
,j
,count
,d
);
1728 #ifndef OPENSSL_NO_DES
1729 if (doit
[D_CBC_DES
])
1731 for (j
=0; j
<SIZE_NUM
; j
++)
1733 print_message(names
[D_CBC_DES
],c
[D_CBC_DES
][j
],lengths
[j
]);
1735 for (count
=0,run
=1; COND(c
[D_CBC_DES
][j
]); count
++)
1736 DES_ncbc_encrypt(buf
,buf
,lengths
[j
],&sch
,
1737 &DES_iv
,DES_ENCRYPT
);
1739 print_result(D_CBC_DES
,j
,count
,d
);
1743 if (doit
[D_EDE3_DES
])
1745 for (j
=0; j
<SIZE_NUM
; j
++)
1747 print_message(names
[D_EDE3_DES
],c
[D_EDE3_DES
][j
],lengths
[j
]);
1749 for (count
=0,run
=1; COND(c
[D_EDE3_DES
][j
]); count
++)
1750 DES_ede3_cbc_encrypt(buf
,buf
,lengths
[j
],
1752 &DES_iv
,DES_ENCRYPT
);
1754 print_result(D_EDE3_DES
,j
,count
,d
);
1758 #ifndef OPENSSL_NO_AES
1759 if (doit
[D_CBC_128_AES
])
1761 for (j
=0; j
<SIZE_NUM
; j
++)
1763 print_message(names
[D_CBC_128_AES
],c
[D_CBC_128_AES
][j
],lengths
[j
]);
1765 for (count
=0,run
=1; COND(c
[D_CBC_128_AES
][j
]); count
++)
1766 AES_cbc_encrypt(buf
,buf
,
1767 (unsigned long)lengths
[j
],&aes_ks1
,
1770 print_result(D_CBC_128_AES
,j
,count
,d
);
1773 if (doit
[D_CBC_192_AES
])
1775 for (j
=0; j
<SIZE_NUM
; j
++)
1777 print_message(names
[D_CBC_192_AES
],c
[D_CBC_192_AES
][j
],lengths
[j
]);
1779 for (count
=0,run
=1; COND(c
[D_CBC_192_AES
][j
]); count
++)
1780 AES_cbc_encrypt(buf
,buf
,
1781 (unsigned long)lengths
[j
],&aes_ks2
,
1784 print_result(D_CBC_192_AES
,j
,count
,d
);
1787 if (doit
[D_CBC_256_AES
])
1789 for (j
=0; j
<SIZE_NUM
; j
++)
1791 print_message(names
[D_CBC_256_AES
],c
[D_CBC_256_AES
][j
],lengths
[j
]);
1793 for (count
=0,run
=1; COND(c
[D_CBC_256_AES
][j
]); count
++)
1794 AES_cbc_encrypt(buf
,buf
,
1795 (unsigned long)lengths
[j
],&aes_ks3
,
1798 print_result(D_CBC_256_AES
,j
,count
,d
);
1803 #ifndef OPENSSL_NO_CAMELLIA
1804 if (doit
[D_CBC_128_CML
])
1806 for (j
=0; j
<SIZE_NUM
; j
++)
1808 print_message(names
[D_CBC_128_CML
],c
[D_CBC_128_CML
][j
],lengths
[j
]);
1810 for (count
=0,run
=1; COND(c
[D_CBC_128_CML
][j
]); count
++)
1811 Camellia_cbc_encrypt(buf
,buf
,
1812 (unsigned long)lengths
[j
],&camellia_ks1
,
1813 iv
,CAMELLIA_ENCRYPT
);
1815 print_result(D_CBC_128_CML
,j
,count
,d
);
1818 if (doit
[D_CBC_192_CML
])
1820 for (j
=0; j
<SIZE_NUM
; j
++)
1822 print_message(names
[D_CBC_192_CML
],c
[D_CBC_192_CML
][j
],lengths
[j
]);
1824 for (count
=0,run
=1; COND(c
[D_CBC_192_CML
][j
]); count
++)
1825 Camellia_cbc_encrypt(buf
,buf
,
1826 (unsigned long)lengths
[j
],&camellia_ks2
,
1827 iv
,CAMELLIA_ENCRYPT
);
1829 print_result(D_CBC_192_CML
,j
,count
,d
);
1832 if (doit
[D_CBC_256_CML
])
1834 for (j
=0; j
<SIZE_NUM
; j
++)
1836 print_message(names
[D_CBC_256_CML
],c
[D_CBC_256_CML
][j
],lengths
[j
]);
1838 for (count
=0,run
=1; COND(c
[D_CBC_256_CML
][j
]); count
++)
1839 Camellia_cbc_encrypt(buf
,buf
,
1840 (unsigned long)lengths
[j
],&camellia_ks3
,
1841 iv
,CAMELLIA_ENCRYPT
);
1843 print_result(D_CBC_256_CML
,j
,count
,d
);
1848 #ifndef OPENSSL_NO_IDEA
1849 if (doit
[D_CBC_IDEA
])
1851 for (j
=0; j
<SIZE_NUM
; j
++)
1853 print_message(names
[D_CBC_IDEA
],c
[D_CBC_IDEA
][j
],lengths
[j
]);
1855 for (count
=0,run
=1; COND(c
[D_CBC_IDEA
][j
]); count
++)
1856 idea_cbc_encrypt(buf
,buf
,
1857 (unsigned long)lengths
[j
],&idea_ks
,
1860 print_result(D_CBC_IDEA
,j
,count
,d
);
1864 #ifndef OPENSSL_NO_RC2
1865 if (doit
[D_CBC_RC2
])
1867 for (j
=0; j
<SIZE_NUM
; j
++)
1869 print_message(names
[D_CBC_RC2
],c
[D_CBC_RC2
][j
],lengths
[j
]);
1871 for (count
=0,run
=1; COND(c
[D_CBC_RC2
][j
]); count
++)
1872 RC2_cbc_encrypt(buf
,buf
,
1873 (unsigned long)lengths
[j
],&rc2_ks
,
1876 print_result(D_CBC_RC2
,j
,count
,d
);
1880 #ifndef OPENSSL_NO_RC5
1881 if (doit
[D_CBC_RC5
])
1883 for (j
=0; j
<SIZE_NUM
; j
++)
1885 print_message(names
[D_CBC_RC5
],c
[D_CBC_RC5
][j
],lengths
[j
]);
1887 for (count
=0,run
=1; COND(c
[D_CBC_RC5
][j
]); count
++)
1888 RC5_32_cbc_encrypt(buf
,buf
,
1889 (unsigned long)lengths
[j
],&rc5_ks
,
1892 print_result(D_CBC_RC5
,j
,count
,d
);
1896 #ifndef OPENSSL_NO_BF
1899 for (j
=0; j
<SIZE_NUM
; j
++)
1901 print_message(names
[D_CBC_BF
],c
[D_CBC_BF
][j
],lengths
[j
]);
1903 for (count
=0,run
=1; COND(c
[D_CBC_BF
][j
]); count
++)
1904 BF_cbc_encrypt(buf
,buf
,
1905 (unsigned long)lengths
[j
],&bf_ks
,
1908 print_result(D_CBC_BF
,j
,count
,d
);
1912 #ifndef OPENSSL_NO_CAST
1913 if (doit
[D_CBC_CAST
])
1915 for (j
=0; j
<SIZE_NUM
; j
++)
1917 print_message(names
[D_CBC_CAST
],c
[D_CBC_CAST
][j
],lengths
[j
]);
1919 for (count
=0,run
=1; COND(c
[D_CBC_CAST
][j
]); count
++)
1920 CAST_cbc_encrypt(buf
,buf
,
1921 (unsigned long)lengths
[j
],&cast_ks
,
1924 print_result(D_CBC_CAST
,j
,count
,d
);
1931 for (j
=0; j
<SIZE_NUM
; j
++)
1938 names
[D_EVP
]=OBJ_nid2ln(evp_cipher
->nid
);
1939 /* -O3 -fschedule-insns messes up an
1940 * optimization here! names[D_EVP]
1941 * somehow becomes NULL */
1942 print_message(names
[D_EVP
],save_count
,
1945 EVP_CIPHER_CTX_init(&ctx
);
1947 EVP_DecryptInit_ex(&ctx
,evp_cipher
,NULL
,key16
,iv
);
1949 EVP_EncryptInit_ex(&ctx
,evp_cipher
,NULL
,key16
,iv
);
1950 EVP_CIPHER_CTX_set_padding(&ctx
, 0);
1954 for (count
=0,run
=1; COND(save_count
*4*lengths
[0]/lengths
[j
]); count
++)
1955 EVP_DecryptUpdate(&ctx
,buf
,&outl
,buf
,lengths
[j
]);
1957 for (count
=0,run
=1; COND(save_count
*4*lengths
[0]/lengths
[j
]); count
++)
1958 EVP_EncryptUpdate(&ctx
,buf
,&outl
,buf
,lengths
[j
]);
1960 EVP_DecryptFinal_ex(&ctx
,buf
,&outl
);
1962 EVP_EncryptFinal_ex(&ctx
,buf
,&outl
);
1964 EVP_CIPHER_CTX_cleanup(&ctx
);
1968 names
[D_EVP
]=OBJ_nid2ln(evp_md
->type
);
1969 print_message(names
[D_EVP
],save_count
,
1973 for (count
=0,run
=1; COND(save_count
*4*lengths
[0]/lengths
[j
]); count
++)
1974 EVP_Digest(buf
,lengths
[j
],&(md
[0]),NULL
,evp_md
,NULL
);
1978 print_result(D_EVP
,j
,count
,d
);
1982 RAND_pseudo_bytes(buf
,36);
1983 #ifndef OPENSSL_NO_RSA
1984 for (j
=0; j
<RSA_NUM
; j
++)
1987 if (!rsa_doit
[j
]) continue;
1988 ret
=RSA_sign(NID_md5_sha1
, buf
,36, buf2
, &rsa_num
, rsa_key
[j
]);
1991 BIO_printf(bio_err
,"RSA sign failure. No RSA sign will be done.\n");
1992 ERR_print_errors(bio_err
);
1997 pkey_print_message("private","rsa",
1998 rsa_c
[j
][0],rsa_bits
[j
],
2000 /* RSA_blinding_on(rsa_key[j],NULL); */
2002 for (count
=0,run
=1; COND(rsa_c
[j
][0]); count
++)
2004 ret
=RSA_sign(NID_md5_sha1
, buf
,36, buf2
,
2005 &rsa_num
, rsa_key
[j
]);
2009 "RSA sign failure\n");
2010 ERR_print_errors(bio_err
);
2016 BIO_printf(bio_err
,mr
? "+R1:%ld:%d:%.2f\n"
2017 : "%ld %d bit private RSA's in %.2fs\n",
2018 count
,rsa_bits
[j
],d
);
2019 rsa_results
[j
][0]=d
/(double)count
;
2024 ret
=RSA_verify(NID_md5_sha1
, buf
,36, buf2
, rsa_num
, rsa_key
[j
]);
2027 BIO_printf(bio_err
,"RSA verify failure. No RSA verify will be done.\n");
2028 ERR_print_errors(bio_err
);
2033 pkey_print_message("public","rsa",
2034 rsa_c
[j
][1],rsa_bits
[j
],
2037 for (count
=0,run
=1; COND(rsa_c
[j
][1]); count
++)
2039 ret
=RSA_verify(NID_md5_sha1
, buf
,36, buf2
,
2040 rsa_num
, rsa_key
[j
]);
2044 "RSA verify failure\n");
2045 ERR_print_errors(bio_err
);
2051 BIO_printf(bio_err
,mr
? "+R2:%ld:%d:%.2f\n"
2052 : "%ld %d bit public RSA's in %.2fs\n",
2053 count
,rsa_bits
[j
],d
);
2054 rsa_results
[j
][1]=d
/(double)count
;
2060 /* if longer than 10s, don't do any more */
2061 for (j
++; j
<RSA_NUM
; j
++)
2067 RAND_pseudo_bytes(buf
,20);
2068 #ifndef OPENSSL_NO_DSA
2069 if (RAND_status() != 1)
2071 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2074 for (j
=0; j
<DSA_NUM
; j
++)
2079 if (!dsa_doit
[j
]) continue;
2080 /* DSA_generate_key(dsa_key[j]); */
2081 /* DSA_sign_setup(dsa_key[j],NULL); */
2082 ret
=DSA_sign(EVP_PKEY_DSA
,buf
,20,buf2
,
2086 BIO_printf(bio_err
,"DSA sign failure. No DSA sign will be done.\n");
2087 ERR_print_errors(bio_err
);
2092 pkey_print_message("sign","dsa",
2093 dsa_c
[j
][0],dsa_bits
[j
],
2096 for (count
=0,run
=1; COND(dsa_c
[j
][0]); count
++)
2098 ret
=DSA_sign(EVP_PKEY_DSA
,buf
,20,buf2
,
2103 "DSA sign failure\n");
2104 ERR_print_errors(bio_err
);
2110 BIO_printf(bio_err
,mr
? "+R3:%ld:%d:%.2f\n"
2111 : "%ld %d bit DSA signs in %.2fs\n",
2112 count
,dsa_bits
[j
],d
);
2113 dsa_results
[j
][0]=d
/(double)count
;
2117 ret
=DSA_verify(EVP_PKEY_DSA
,buf
,20,buf2
,
2121 BIO_printf(bio_err
,"DSA verify failure. No DSA verify will be done.\n");
2122 ERR_print_errors(bio_err
);
2127 pkey_print_message("verify","dsa",
2128 dsa_c
[j
][1],dsa_bits
[j
],
2131 for (count
=0,run
=1; COND(dsa_c
[j
][1]); count
++)
2133 ret
=DSA_verify(EVP_PKEY_DSA
,buf
,20,buf2
,
2138 "DSA verify failure\n");
2139 ERR_print_errors(bio_err
);
2145 BIO_printf(bio_err
,mr
? "+R4:%ld:%d:%.2f\n"
2146 : "%ld %d bit DSA verify in %.2fs\n",
2147 count
,dsa_bits
[j
],d
);
2148 dsa_results
[j
][1]=d
/(double)count
;
2153 /* if longer than 10s, don't do any more */
2154 for (j
++; j
<DSA_NUM
; j
++)
2158 if (rnd_fake
) RAND_cleanup();
2161 #ifndef OPENSSL_NO_ECDSA
2162 if (RAND_status() != 1)
2164 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2167 for (j
=0; j
<EC_NUM
; j
++)
2171 if (!ecdsa_doit
[j
]) continue; /* Ignore Curve */
2172 ecdsa
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
2173 if (ecdsa
[j
] == NULL
)
2175 BIO_printf(bio_err
,"ECDSA failure.\n");
2176 ERR_print_errors(bio_err
);
2182 EC_KEY_precompute_mult(ecdsa
[j
], NULL
);
2184 /* Perform ECDSA signature test */
2185 EC_KEY_generate_key(ecdsa
[j
]);
2186 ret
= ECDSA_sign(0, buf
, 20, ecdsasig
,
2187 &ecdsasiglen
, ecdsa
[j
]);
2190 BIO_printf(bio_err
,"ECDSA sign failure. No ECDSA sign will be done.\n");
2191 ERR_print_errors(bio_err
);
2196 pkey_print_message("sign","ecdsa",
2198 test_curves_bits
[j
],
2202 for (count
=0,run
=1; COND(ecdsa_c
[j
][0]);
2205 ret
=ECDSA_sign(0, buf
, 20,
2206 ecdsasig
, &ecdsasiglen
,
2210 BIO_printf(bio_err
, "ECDSA sign failure\n");
2211 ERR_print_errors(bio_err
);
2218 BIO_printf(bio_err
, mr
? "+R5:%ld:%d:%.2f\n" :
2219 "%ld %d bit ECDSA signs in %.2fs \n",
2220 count
, test_curves_bits
[j
], d
);
2221 ecdsa_results
[j
][0]=d
/(double)count
;
2225 /* Perform ECDSA verification test */
2226 ret
=ECDSA_verify(0, buf
, 20, ecdsasig
,
2227 ecdsasiglen
, ecdsa
[j
]);
2230 BIO_printf(bio_err
,"ECDSA verify failure. No ECDSA verify will be done.\n");
2231 ERR_print_errors(bio_err
);
2236 pkey_print_message("verify","ecdsa",
2238 test_curves_bits
[j
],
2241 for (count
=0,run
=1; COND(ecdsa_c
[j
][1]); count
++)
2243 ret
=ECDSA_verify(0, buf
, 20, ecdsasig
, ecdsasiglen
, ecdsa
[j
]);
2246 BIO_printf(bio_err
, "ECDSA verify failure\n");
2247 ERR_print_errors(bio_err
);
2253 BIO_printf(bio_err
, mr
? "+R6:%ld:%d:%.2f\n"
2254 : "%ld %d bit ECDSA verify in %.2fs\n",
2255 count
, test_curves_bits
[j
], d
);
2256 ecdsa_results
[j
][1]=d
/(double)count
;
2261 /* if longer than 10s, don't do any more */
2262 for (j
++; j
<EC_NUM
; j
++)
2267 if (rnd_fake
) RAND_cleanup();
2270 #ifndef OPENSSL_NO_ECDH
2271 if (RAND_status() != 1)
2273 RAND_seed(rnd_seed
, sizeof rnd_seed
);
2276 for (j
=0; j
<EC_NUM
; j
++)
2278 if (!ecdh_doit
[j
]) continue;
2279 ecdh_a
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
2280 ecdh_b
[j
] = EC_KEY_new_by_curve_name(test_curves
[j
]);
2281 if ((ecdh_a
[j
] == NULL
) || (ecdh_b
[j
] == NULL
))
2283 BIO_printf(bio_err
,"ECDH failure.\n");
2284 ERR_print_errors(bio_err
);
2289 /* generate two ECDH key pairs */
2290 if (!EC_KEY_generate_key(ecdh_a
[j
]) ||
2291 !EC_KEY_generate_key(ecdh_b
[j
]))
2293 BIO_printf(bio_err
,"ECDH key generation failure.\n");
2294 ERR_print_errors(bio_err
);
2299 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2300 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2302 int field_size
, outlen
;
2303 void *(*kdf
)(const void *in
, size_t inlen
, void *out
, size_t *xoutlen
);
2304 field_size
= EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a
[j
]));
2305 if (field_size
<= 24 * 8)
2307 outlen
= KDF1_SHA1_len
;
2312 outlen
= (field_size
+7)/8;
2315 secret_size_a
= ECDH_compute_key(secret_a
, outlen
,
2316 EC_KEY_get0_public_key(ecdh_b
[j
]),
2318 secret_size_b
= ECDH_compute_key(secret_b
, outlen
,
2319 EC_KEY_get0_public_key(ecdh_a
[j
]),
2321 if (secret_size_a
!= secret_size_b
)
2326 for (secret_idx
= 0;
2327 (secret_idx
< secret_size_a
)
2328 && (ecdh_checks
== 1);
2331 if (secret_a
[secret_idx
] != secret_b
[secret_idx
])
2335 if (ecdh_checks
== 0)
2337 BIO_printf(bio_err
,"ECDH computations don't match.\n");
2338 ERR_print_errors(bio_err
);
2342 pkey_print_message("","ecdh",
2344 test_curves_bits
[j
],
2347 for (count
=0,run
=1; COND(ecdh_c
[j
][0]); count
++)
2349 ECDH_compute_key(secret_a
, outlen
,
2350 EC_KEY_get0_public_key(ecdh_b
[j
]),
2354 BIO_printf(bio_err
, mr
? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2355 count
, test_curves_bits
[j
], d
);
2356 ecdh_results
[j
][0]=d
/(double)count
;
2364 /* if longer than 10s, don't do any more */
2365 for (j
++; j
<EC_NUM
; j
++)
2369 if (rnd_fake
) RAND_cleanup();
2376 fprintf(stdout
,"%s\n",SSLeay_version(SSLEAY_VERSION
));
2377 fprintf(stdout
,"%s\n",SSLeay_version(SSLEAY_BUILT_ON
));
2379 printf("%s ",BN_options());
2380 #ifndef OPENSSL_NO_MD2
2381 printf("%s ",MD2_options());
2383 #ifndef OPENSSL_NO_RC4
2384 printf("%s ",RC4_options());
2386 #ifndef OPENSSL_NO_DES
2387 printf("%s ",DES_options());
2389 #ifndef OPENSSL_NO_AES
2390 printf("%s ",AES_options());
2392 #ifndef OPENSSL_NO_IDEA
2393 printf("%s ",idea_options());
2395 #ifndef OPENSSL_NO_BF
2396 printf("%s ",BF_options());
2398 fprintf(stdout
,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS
));
2399 printf("available timing options: ");
2410 #define as_string(s) (#s)
2413 printf("HZ=%g", dbl
);
2416 printf(" [sysconf value]");
2420 printf("timing function used: %s%s%s%s%s%s%s\n",
2421 (ftime_used
? "ftime" : ""),
2422 (ftime_used
+ times_used
> 1 ? "," : ""),
2423 (times_used
? "times" : ""),
2424 (ftime_used
+ times_used
+ gettimeofday_used
> 1 ? "," : ""),
2425 (gettimeofday_used
? "gettimeofday" : ""),
2426 (ftime_used
+ times_used
+ gettimeofday_used
+ getrusage_used
> 1 ? "," : ""),
2427 (getrusage_used
? "getrusage" : ""));
2433 fprintf(stdout
,"+H");
2436 fprintf(stdout
,"The 'numbers' are in 1000s of bytes per second processed.\n");
2437 fprintf(stdout
,"type ");
2439 for (j
=0; j
<SIZE_NUM
; j
++)
2440 fprintf(stdout
,mr
? ":%d" : "%7d bytes",lengths
[j
]);
2441 fprintf(stdout
,"\n");
2444 for (k
=0; k
<ALGOR_NUM
; k
++)
2446 if (!doit
[k
]) continue;
2448 fprintf(stdout
,"+F:%d:%s",k
,names
[k
]);
2450 fprintf(stdout
,"%-13s",names
[k
]);
2451 for (j
=0; j
<SIZE_NUM
; j
++)
2453 if (results
[k
][j
] > 10000 && !mr
)
2454 fprintf(stdout
," %11.2fk",results
[k
][j
]/1e3
);
2456 fprintf(stdout
,mr
? ":%.2f" : " %11.2f ",results
[k
][j
]);
2458 fprintf(stdout
,"\n");
2460 #ifndef OPENSSL_NO_RSA
2462 for (k
=0; k
<RSA_NUM
; k
++)
2464 if (!rsa_doit
[k
]) continue;
2467 printf("%18ssign verify sign/s verify/s\n"," ");
2471 fprintf(stdout
,"+F2:%u:%u:%f:%f\n",
2472 k
,rsa_bits
[k
],rsa_results
[k
][0],
2475 fprintf(stdout
,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2476 rsa_bits
[k
],rsa_results
[k
][0],rsa_results
[k
][1],
2477 1.0/rsa_results
[k
][0],1.0/rsa_results
[k
][1]);
2480 #ifndef OPENSSL_NO_DSA
2482 for (k
=0; k
<DSA_NUM
; k
++)
2484 if (!dsa_doit
[k
]) continue;
2487 printf("%18ssign verify sign/s verify/s\n"," ");
2491 fprintf(stdout
,"+F3:%u:%u:%f:%f\n",
2492 k
,dsa_bits
[k
],dsa_results
[k
][0],dsa_results
[k
][1]);
2494 fprintf(stdout
,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2495 dsa_bits
[k
],dsa_results
[k
][0],dsa_results
[k
][1],
2496 1.0/dsa_results
[k
][0],1.0/dsa_results
[k
][1]);
2499 #ifndef OPENSSL_NO_ECDSA
2501 for (k
=0; k
<EC_NUM
; k
++)
2503 if (!ecdsa_doit
[k
]) continue;
2506 printf("%30ssign verify sign/s verify/s\n"," ");
2511 fprintf(stdout
,"+F4:%u:%u:%f:%f\n",
2512 k
, test_curves_bits
[k
],
2513 ecdsa_results
[k
][0],ecdsa_results
[k
][1]);
2516 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2517 test_curves_bits
[k
],
2518 test_curves_names
[k
],
2519 ecdsa_results
[k
][0],ecdsa_results
[k
][1],
2520 1.0/ecdsa_results
[k
][0],1.0/ecdsa_results
[k
][1]);
2525 #ifndef OPENSSL_NO_ECDH
2527 for (k
=0; k
<EC_NUM
; k
++)
2529 if (!ecdh_doit
[k
]) continue;
2532 printf("%30sop op/s\n"," ");
2536 fprintf(stdout
,"+F5:%u:%u:%f:%f\n",
2537 k
, test_curves_bits
[k
],
2538 ecdh_results
[k
][0], 1.0/ecdh_results
[k
][0]);
2541 fprintf(stdout
,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2542 test_curves_bits
[k
],
2543 test_curves_names
[k
],
2544 ecdh_results
[k
][0], 1.0/ecdh_results
[k
][0]);
2551 ERR_print_errors(bio_err
);
2552 if (buf
!= NULL
) OPENSSL_free(buf
);
2553 if (buf2
!= NULL
) OPENSSL_free(buf2
);
2554 #ifndef OPENSSL_NO_RSA
2555 for (i
=0; i
<RSA_NUM
; i
++)
2556 if (rsa_key
[i
] != NULL
)
2557 RSA_free(rsa_key
[i
]);
2559 #ifndef OPENSSL_NO_DSA
2560 for (i
=0; i
<DSA_NUM
; i
++)
2561 if (dsa_key
[i
] != NULL
)
2562 DSA_free(dsa_key
[i
]);
2565 #ifndef OPENSSL_NO_ECDSA
2566 for (i
=0; i
<EC_NUM
; i
++)
2567 if (ecdsa
[i
] != NULL
)
2568 EC_KEY_free(ecdsa
[i
]);
2570 #ifndef OPENSSL_NO_ECDH
2571 for (i
=0; i
<EC_NUM
; i
++)
2573 if (ecdh_a
[i
] != NULL
)
2574 EC_KEY_free(ecdh_a
[i
]);
2575 if (ecdh_b
[i
] != NULL
)
2576 EC_KEY_free(ecdh_b
[i
]);
2584 static void print_message(const char *s
, long num
, int length
)
2587 BIO_printf(bio_err
,mr
? "+DT:%s:%d:%d\n"
2588 : "Doing %s for %ds on %d size blocks: ",s
,SECONDS
,length
);
2589 (void)BIO_flush(bio_err
);
2592 BIO_printf(bio_err
,mr
? "+DN:%s:%ld:%d\n"
2593 : "Doing %s %ld times on %d size blocks: ",s
,num
,length
);
2594 (void)BIO_flush(bio_err
);
2601 static void pkey_print_message(const char *str
, const char *str2
, long num
,
2605 BIO_printf(bio_err
,mr
? "+DTP:%d:%s:%s:%d\n"
2606 : "Doing %d bit %s %s's for %ds: ",bits
,str
,str2
,tm
);
2607 (void)BIO_flush(bio_err
);
2610 BIO_printf(bio_err
,mr
? "+DNP:%ld:%d:%s:%s\n"
2611 : "Doing %ld %d bit %s %s's: ",num
,bits
,str
,str2
);
2612 (void)BIO_flush(bio_err
);
2619 static void print_result(int alg
,int run_no
,int count
,double time_used
)
2621 BIO_printf(bio_err
,mr
? "+R:%d:%s:%f\n"
2622 : "%d %s's in %.2fs\n",count
,names
[alg
],time_used
);
2623 results
[alg
][run_no
]=((double)count
)/time_used
*lengths
[run_no
];
2627 static char *sstrsep(char **string
, const char *delim
)
2630 char *token
= *string
;
2635 memset(isdelim
, 0, sizeof isdelim
);
2640 isdelim
[(unsigned char)(*delim
)] = 1;
2644 while (!isdelim
[(unsigned char)(**string
)])
2658 static int do_multi(int multi
)
2663 static char sep
[]=":";
2665 fds
=malloc(multi
*sizeof *fds
);
2666 for(n
=0 ; n
< multi
; ++n
)
2684 printf("Forked child %d\n",n
);
2687 /* for now, assume the pipe is long enough to take all the output */
2688 for(n
=0 ; n
< multi
; ++n
)
2694 f
=fdopen(fds
[n
],"r");
2695 while(fgets(buf
,sizeof buf
,f
))
2702 fprintf(stderr
,"Don't understand line '%s' from child %d\n",
2706 printf("Got: %s from %d\n",buf
,n
);
2707 if(!strncmp(buf
,"+F:",3))
2713 alg
=atoi(sstrsep(&p
,sep
));
2715 for(j
=0 ; j
< SIZE_NUM
; ++j
)
2716 results
[alg
][j
]+=atof(sstrsep(&p
,sep
));
2718 else if(!strncmp(buf
,"+F2:",4))
2724 k
=atoi(sstrsep(&p
,sep
));
2727 d
=atof(sstrsep(&p
,sep
));
2729 rsa_results
[k
][0]=1/(1/rsa_results
[k
][0]+1/d
);
2731 rsa_results
[k
][0]=d
;
2733 d
=atof(sstrsep(&p
,sep
));
2735 rsa_results
[k
][1]=1/(1/rsa_results
[k
][1]+1/d
);
2737 rsa_results
[k
][1]=d
;
2739 else if(!strncmp(buf
,"+F2:",4))
2745 k
=atoi(sstrsep(&p
,sep
));
2748 d
=atof(sstrsep(&p
,sep
));
2750 rsa_results
[k
][0]=1/(1/rsa_results
[k
][0]+1/d
);
2752 rsa_results
[k
][0]=d
;
2754 d
=atof(sstrsep(&p
,sep
));
2756 rsa_results
[k
][1]=1/(1/rsa_results
[k
][1]+1/d
);
2758 rsa_results
[k
][1]=d
;
2760 else if(!strncmp(buf
,"+F3:",4))
2766 k
=atoi(sstrsep(&p
,sep
));
2769 d
=atof(sstrsep(&p
,sep
));
2771 dsa_results
[k
][0]=1/(1/dsa_results
[k
][0]+1/d
);
2773 dsa_results
[k
][0]=d
;
2775 d
=atof(sstrsep(&p
,sep
));
2777 dsa_results
[k
][1]=1/(1/dsa_results
[k
][1]+1/d
);
2779 dsa_results
[k
][1]=d
;
2781 #ifndef OPENSSL_NO_ECDSA
2782 else if(!strncmp(buf
,"+F4:",4))
2788 k
=atoi(sstrsep(&p
,sep
));
2791 d
=atof(sstrsep(&p
,sep
));
2793 ecdsa_results
[k
][0]=1/(1/ecdsa_results
[k
][0]+1/d
);
2795 ecdsa_results
[k
][0]=d
;
2797 d
=atof(sstrsep(&p
,sep
));
2799 ecdsa_results
[k
][1]=1/(1/ecdsa_results
[k
][1]+1/d
);
2801 ecdsa_results
[k
][1]=d
;
2805 #ifndef OPENSSL_NO_ECDH
2806 else if(!strncmp(buf
,"+F5:",4))
2812 k
=atoi(sstrsep(&p
,sep
));
2815 d
=atof(sstrsep(&p
,sep
));
2817 ecdh_results
[k
][0]=1/(1/ecdh_results
[k
][0]+1/d
);
2819 ecdh_results
[k
][0]=d
;
2824 else if(!strncmp(buf
,"+H:",3))
2828 fprintf(stderr
,"Unknown type '%s' from child %d\n",buf
,n
);