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(_WIN32) || defined(__CYGWIN__)
113 # if defined(__CYGWIN__) && !defined(_WIN32)
114 /* <windows.h> should define _WIN32, which normally is mutually
115 * exclusive with __CYGWIN__, but if it didn't... */
117 /* this is done because Cygwin alarm() fails sometimes. */
121 #include <openssl/bn.h>
122 #ifndef OPENSSL_NO_DES
123 #include <openssl/des.h>
125 #ifndef OPENSSL_NO_AES
126 #include <openssl/aes.h>
128 #ifndef OPENSSL_NO_CAMELLIA
129 #include <openssl/camellia.h>
131 #ifndef OPENSSL_NO_MD2
132 #include <openssl/md2.h>
134 #ifndef OPENSSL_NO_MDC2
135 #include <openssl/mdc2.h>
137 #ifndef OPENSSL_NO_MD4
138 #include <openssl/md4.h>
140 #ifndef OPENSSL_NO_MD5
141 #include <openssl/md5.h>
143 #ifndef OPENSSL_NO_HMAC
144 #include <openssl/hmac.h>
146 #include <openssl/evp.h>
147 #ifndef OPENSSL_NO_SHA
148 #include <openssl/sha.h>
150 #ifndef OPENSSL_NO_RIPEMD
151 #include <openssl/ripemd.h>
153 #ifndef OPENSSL_NO_WHIRLPOOL
154 #include <openssl/whrlpool.h>
156 #ifndef OPENSSL_NO_RC4
157 #include <openssl/rc4.h>
159 #ifndef OPENSSL_NO_RC5
160 #include <openssl/rc5.h>
162 #ifndef OPENSSL_NO_RC2
163 #include <openssl/rc2.h>
165 #ifndef OPENSSL_NO_IDEA
166 #include <openssl/idea.h>
168 #ifndef OPENSSL_NO_SEED
169 #include <openssl/seed.h>
171 #ifndef OPENSSL_NO_BF
172 #include <openssl/blowfish.h>
174 #ifndef OPENSSL_NO_CAST
175 #include <openssl/cast.h>
177 #ifndef OPENSSL_NO_RSA
178 #include <openssl/rsa.h>
179 #include "./testrsa.h"
181 #include <openssl/x509.h>
182 #ifndef OPENSSL_NO_DSA
183 #include <openssl/dsa.h>
184 #include "./testdsa.h"
186 #ifndef OPENSSL_NO_ECDSA
187 #include <openssl/ecdsa.h>
189 #ifndef OPENSSL_NO_ECDH
190 #include <openssl/ecdh.h>
192 #include <openssl/modes.h>
194 #include "../crypto/bn/bn_lcl.h"
197 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
211 #define BUFSIZE ((long)1024*8+1)
215 static int usertime=1;
217 static double Time_F(int s);
218 static void print_message(const char *s,long num,int length);
219 static void prime_print_message(const char *s, long num);
220 static void pkey_print_message(const char *str, const char *str2,
221 long num, int bits, int sec);
222 static void print_result(int alg,int run_no,int count,double time_used);
224 static int do_multi(int multi);
234 #define MAX_ECDH_SIZE 256
236 static const char *names[ALGOR_NUM]={
237 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
238 "des cbc","des ede3","idea cbc","seed cbc",
239 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
240 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
241 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
242 "evp","sha256","sha512","whirlpool",
243 "aes-128 ige","aes-192 ige","aes-256 ige","ghash" };
244 static double results[ALGOR_NUM][SIZE_NUM];
245 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
246 static const char *prime_names[PRIME_NUM]={
247 "prime trial division", "prime coprime" };
248 #ifndef OPENSSL_NO_RSA
249 static double rsa_results[RSA_NUM][2];
251 #ifndef OPENSSL_NO_DSA
252 static double dsa_results[DSA_NUM][2];
254 #ifndef OPENSSL_NO_ECDSA
255 static double ecdsa_results[EC_NUM][2];
257 #ifndef OPENSSL_NO_ECDH
258 static double ecdh_results[EC_NUM][1];
261 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
262 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
263 static int rnd_fake = 0;
267 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
268 #define SIGRETTYPE void
270 #define SIGRETTYPE int
273 static SIGRETTYPE sig_done(int sig);
274 static SIGRETTYPE sig_done(int sig)
276 signal(SIGALRM,sig_done);
289 #if !defined(SIGALRM)
292 static unsigned int lapse,schlock;
293 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
294 #define alarm alarm_win32
296 static DWORD WINAPI sleepy(VOID *arg)
304 static double Time_F(int s)
312 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
315 DWORD ret=GetLastError();
316 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
319 while (!schlock) Sleep(0); /* scheduler spinlock */
320 ret = app_tminterval(s,usertime);
324 ret = app_tminterval(s,usertime);
325 if (run) TerminateThread(thr,0);
333 static double Time_F(int s)
335 double ret = app_tminterval(s,usertime);
336 if (s == STOP) alarm(0);
342 #ifndef OPENSSL_NO_ECDH
343 static const int KDF1_SHA1_len = 20;
344 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
346 #ifndef OPENSSL_NO_SHA
347 if (*outlen < SHA_DIGEST_LENGTH)
350 *outlen = SHA_DIGEST_LENGTH;
351 return SHA1(in, inlen, out);
354 #endif /* OPENSSL_NO_SHA */
356 #endif /* OPENSSL_NO_ECDH */
359 int MAIN(int, char **);
361 int MAIN(int argc, char **argv)
363 unsigned char *buf=NULL,*buf2=NULL;
365 long count=0,save_count=0;
367 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
370 #ifndef OPENSSL_NO_RSA
373 unsigned char md[EVP_MAX_MD_SIZE];
374 #ifndef OPENSSL_NO_MD2
375 unsigned char md2[MD2_DIGEST_LENGTH];
377 #ifndef OPENSSL_NO_MDC2
378 unsigned char mdc2[MDC2_DIGEST_LENGTH];
380 #ifndef OPENSSL_NO_MD4
381 unsigned char md4[MD4_DIGEST_LENGTH];
383 #ifndef OPENSSL_NO_MD5
384 unsigned char md5[MD5_DIGEST_LENGTH];
385 unsigned char hmac[MD5_DIGEST_LENGTH];
387 #ifndef OPENSSL_NO_SHA
388 unsigned char sha[SHA_DIGEST_LENGTH];
389 #ifndef OPENSSL_NO_SHA256
390 unsigned char sha256[SHA256_DIGEST_LENGTH];
392 #ifndef OPENSSL_NO_SHA512
393 unsigned char sha512[SHA512_DIGEST_LENGTH];
396 #ifndef OPENSSL_NO_WHIRLPOOL
397 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
399 #ifndef OPENSSL_NO_RIPEMD
400 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
402 #ifndef OPENSSL_NO_RC4
405 #ifndef OPENSSL_NO_RC5
408 #ifndef OPENSSL_NO_RC2
411 #ifndef OPENSSL_NO_IDEA
412 IDEA_KEY_SCHEDULE idea_ks;
414 #ifndef OPENSSL_NO_SEED
415 SEED_KEY_SCHEDULE seed_ks;
417 #ifndef OPENSSL_NO_BF
420 #ifndef OPENSSL_NO_CAST
423 static const unsigned char key16[16]=
424 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
425 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
426 #ifndef OPENSSL_NO_AES
427 static const unsigned char key24[24]=
428 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
429 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
430 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
431 static const unsigned char key32[32]=
432 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
433 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
434 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
435 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
437 #ifndef OPENSSL_NO_CAMELLIA
438 static const unsigned char ckey24[24]=
439 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
440 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
441 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
442 static const unsigned char ckey32[32]=
443 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
444 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
445 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
446 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
448 #ifndef OPENSSL_NO_AES
449 #define MAX_BLOCK_SIZE 128
451 #define MAX_BLOCK_SIZE 64
453 unsigned char DES_iv[8];
454 unsigned char iv[2*MAX_BLOCK_SIZE/8];
455 #ifndef OPENSSL_NO_DES
456 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
457 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
458 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
459 DES_key_schedule sch;
460 DES_key_schedule sch2;
461 DES_key_schedule sch3;
463 #ifndef OPENSSL_NO_AES
464 AES_KEY aes_ks1, aes_ks2, aes_ks3;
466 #ifndef OPENSSL_NO_CAMELLIA
467 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
479 #define D_CBC_IDEA 10
480 #define D_CBC_SEED 11
484 #define D_CBC_CAST 15
485 #define D_CBC_128_AES 16
486 #define D_CBC_192_AES 17
487 #define D_CBC_256_AES 18
488 #define D_CBC_128_CML 19
489 #define D_CBC_192_CML 20
490 #define D_CBC_256_CML 21
494 #define D_WHIRLPOOL 25
495 #define D_IGE_128_AES 26
496 #define D_IGE_192_AES 27
497 #define D_IGE_256_AES 28
500 long c[ALGOR_NUM][SIZE_NUM];
502 #define D_PRIME_TRIAL_DIVISION 0
503 #define D_PRIME_COPRIME 1
504 long prime_c[PRIME_NUM];
531 #ifndef OPENSSL_NO_RSA
532 RSA *rsa_key[RSA_NUM];
533 long rsa_c[RSA_NUM][2];
534 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
535 static unsigned char *rsa_data[RSA_NUM]=
536 {test512,test1024,test2048,test4096};
537 static int rsa_data_length[RSA_NUM]={
538 sizeof(test512),sizeof(test1024),
539 sizeof(test2048),sizeof(test4096)};
541 #ifndef OPENSSL_NO_DSA
542 DSA *dsa_key[DSA_NUM];
543 long dsa_c[DSA_NUM][2];
544 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
546 #ifndef OPENSSL_NO_EC
547 /* We only test over the following curves as they are representative,
548 * To add tests over more curves, simply add the curve NID
549 * and curve name to the following arrays and increase the
550 * EC_NUM value accordingly.
552 static unsigned int test_curves[EC_NUM] =
556 NID_X9_62_prime192v1,
558 NID_X9_62_prime256v1,
573 static const char * test_curves_names[EC_NUM] =
594 static int test_curves_bits[EC_NUM] =
596 160, 192, 224, 256, 384, 521,
597 163, 233, 283, 409, 571,
598 163, 233, 283, 409, 571
603 #ifndef OPENSSL_NO_ECDSA
604 unsigned char ecdsasig[256];
605 unsigned int ecdsasiglen;
606 EC_KEY *ecdsa[EC_NUM];
607 long ecdsa_c[EC_NUM][2];
610 #ifndef OPENSSL_NO_ECDH
611 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
612 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
613 int secret_size_a, secret_size_b;
616 long ecdh_c[EC_NUM][2];
619 int prime_doit[PRIME_NUM];
620 int rsa_doit[RSA_NUM];
621 int dsa_doit[DSA_NUM];
622 #ifndef OPENSSL_NO_ECDSA
623 int ecdsa_doit[EC_NUM];
625 #ifndef OPENSSL_NO_ECDH
626 int ecdh_doit[EC_NUM];
630 const EVP_CIPHER *evp_cipher=NULL;
631 const EVP_MD *evp_md=NULL;
642 memset(results, 0, sizeof(results));
643 #ifndef OPENSSL_NO_DSA
644 memset(dsa_key,0,sizeof(dsa_key));
646 #ifndef OPENSSL_NO_ECDSA
647 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
649 #ifndef OPENSSL_NO_ECDH
650 for (i=0; i<EC_NUM; i++)
659 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
660 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
662 if (!load_config(bio_err, NULL))
665 #ifndef OPENSSL_NO_RSA
666 memset(rsa_key,0,sizeof(rsa_key));
667 for (i=0; i<RSA_NUM; i++)
671 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
673 BIO_printf(bio_err,"out of memory\n");
676 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
678 BIO_printf(bio_err,"out of memory\n");
682 memset(c,0,sizeof(c));
683 memset(DES_iv,0,sizeof(DES_iv));
684 memset(iv,0,sizeof(iv));
686 for (i=0; i<ALGOR_NUM; i++)
688 for (i=0; i<RSA_NUM; i++)
690 for (i=0; i<DSA_NUM; i++)
692 #ifndef OPENSSL_NO_ECDSA
693 for (i=0; i<EC_NUM; i++)
696 #ifndef OPENSSL_NO_ECDH
697 for (i=0; i<EC_NUM; i++)
707 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
710 j--; /* Otherwise, -elapsed gets confused with
713 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
719 BIO_printf(bio_err,"no EVP given\n");
722 evp_cipher=EVP_get_cipherbyname(*argv);
725 evp_md=EVP_get_digestbyname(*argv);
727 if(!evp_cipher && !evp_md)
729 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
734 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
737 j--; /* Otherwise, -elapsed gets confused with
740 #ifndef OPENSSL_NO_ENGINE
741 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
747 BIO_printf(bio_err,"no engine given\n");
750 setup_engine(bio_err, *argv, 0);
751 /* j will be increased again further down. We just
752 don't want speed to confuse an engine with an
753 algorithm, especially when none is given (which
754 means all of them should be run) */
759 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
765 BIO_printf(bio_err,"no multi count given\n");
771 BIO_printf(bio_err,"bad multi count\n");
774 j--; /* Otherwise, -mr gets confused with
778 else if (argc > 0 && !strcmp(*argv,"-mr"))
781 j--; /* Otherwise, -mr gets confused with
785 #ifndef OPENSSL_NO_MD2
786 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
789 #ifndef OPENSSL_NO_MDC2
790 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
793 #ifndef OPENSSL_NO_MD4
794 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
797 #ifndef OPENSSL_NO_MD5
798 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
801 #ifndef OPENSSL_NO_MD5
802 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
805 #ifndef OPENSSL_NO_SHA
806 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
808 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
812 #ifndef OPENSSL_NO_SHA256
813 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
816 #ifndef OPENSSL_NO_SHA512
817 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
821 #ifndef OPENSSL_NO_WHIRLPOOL
822 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
825 #ifndef OPENSSL_NO_RIPEMD
826 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
828 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
830 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
833 #ifndef OPENSSL_NO_RC4
834 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
837 #ifndef OPENSSL_NO_DES
838 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
839 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
842 #ifndef OPENSSL_NO_AES
843 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
844 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
845 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
846 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
847 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
848 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
851 #ifndef OPENSSL_NO_CAMELLIA
852 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
853 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
854 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
857 #ifndef OPENSSL_NO_RSA
858 #if 0 /* was: #ifdef RSAref */
859 if (strcmp(*argv,"rsaref") == 0)
861 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
867 if (strcmp(*argv,"openssl") == 0)
869 RSA_set_default_method(RSA_PKCS1_SSLeay());
874 #endif /* !OPENSSL_NO_RSA */
875 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
876 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
877 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
878 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
879 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
880 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
881 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
883 #ifndef OPENSSL_NO_RC2
884 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
885 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
888 #ifndef OPENSSL_NO_RC5
889 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
890 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
893 #ifndef OPENSSL_NO_IDEA
894 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
895 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
898 #ifndef OPENSSL_NO_SEED
899 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
900 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
903 #ifndef OPENSSL_NO_BF
904 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
905 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
906 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
909 #ifndef OPENSSL_NO_CAST
910 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
911 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
912 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
915 #ifndef OPENSSL_NO_DES
916 if (strcmp(*argv,"des") == 0)
923 #ifndef OPENSSL_NO_AES
924 if (strcmp(*argv,"aes") == 0)
926 doit[D_CBC_128_AES]=1;
927 doit[D_CBC_192_AES]=1;
928 doit[D_CBC_256_AES]=1;
930 else if (strcmp(*argv,"ghash") == 0)
936 #ifndef OPENSSL_NO_CAMELLIA
937 if (strcmp(*argv,"camellia") == 0)
939 doit[D_CBC_128_CML]=1;
940 doit[D_CBC_192_CML]=1;
941 doit[D_CBC_256_CML]=1;
945 #ifndef OPENSSL_NO_RSA
946 if (strcmp(*argv,"rsa") == 0)
948 rsa_doit[R_RSA_512]=1;
949 rsa_doit[R_RSA_1024]=1;
950 rsa_doit[R_RSA_2048]=1;
951 rsa_doit[R_RSA_4096]=1;
955 #ifndef OPENSSL_NO_DSA
956 if (strcmp(*argv,"dsa") == 0)
958 dsa_doit[R_DSA_512]=1;
959 dsa_doit[R_DSA_1024]=1;
960 dsa_doit[R_DSA_2048]=1;
964 #ifndef OPENSSL_NO_ECDSA
965 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
966 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
967 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
968 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
969 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
970 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
971 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
972 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
973 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
974 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
975 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
976 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
977 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
978 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
979 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
980 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
981 else if (strcmp(*argv,"ecdsa") == 0)
983 for (i=0; i < EC_NUM; i++)
988 #ifndef OPENSSL_NO_ECDH
989 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
990 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
991 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
992 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
993 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
994 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
995 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
996 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
997 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
998 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
999 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1000 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1001 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1002 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1003 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1004 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1005 else if (strcmp(*argv,"ecdh") == 0)
1007 for (i=0; i < EC_NUM; i++)
1012 if (strcmp(*argv,"prime-trial-division") == 0) prime_doit[D_PRIME_TRIAL_DIVISION]=1;
1013 else if (strcmp(*argv,"prime-coprime") == 0) prime_doit[D_PRIME_COPRIME]=1;
1016 BIO_printf(bio_err,"Error: bad option or value\n");
1017 BIO_printf(bio_err,"\n");
1018 BIO_printf(bio_err,"Available values:\n");
1019 #ifndef OPENSSL_NO_MD2
1020 BIO_printf(bio_err,"md2 ");
1022 #ifndef OPENSSL_NO_MDC2
1023 BIO_printf(bio_err,"mdc2 ");
1025 #ifndef OPENSSL_NO_MD4
1026 BIO_printf(bio_err,"md4 ");
1028 #ifndef OPENSSL_NO_MD5
1029 BIO_printf(bio_err,"md5 ");
1030 #ifndef OPENSSL_NO_HMAC
1031 BIO_printf(bio_err,"hmac ");
1034 #ifndef OPENSSL_NO_SHA1
1035 BIO_printf(bio_err,"sha1 ");
1037 #ifndef OPENSSL_NO_SHA256
1038 BIO_printf(bio_err,"sha256 ");
1040 #ifndef OPENSSL_NO_SHA512
1041 BIO_printf(bio_err,"sha512 ");
1043 #ifndef OPENSSL_NO_WHIRLPOOL
1044 BIO_printf(bio_err,"whirlpool");
1046 #ifndef OPENSSL_NO_RIPEMD160
1047 BIO_printf(bio_err,"rmd160");
1049 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1050 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1051 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1052 !defined(OPENSSL_NO_WHIRLPOOL)
1053 BIO_printf(bio_err,"\n");
1056 #ifndef OPENSSL_NO_IDEA
1057 BIO_printf(bio_err,"idea-cbc ");
1059 #ifndef OPENSSL_NO_SEED
1060 BIO_printf(bio_err,"seed-cbc ");
1062 #ifndef OPENSSL_NO_RC2
1063 BIO_printf(bio_err,"rc2-cbc ");
1065 #ifndef OPENSSL_NO_RC5
1066 BIO_printf(bio_err,"rc5-cbc ");
1068 #ifndef OPENSSL_NO_BF
1069 BIO_printf(bio_err,"bf-cbc");
1071 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1072 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1073 BIO_printf(bio_err,"\n");
1075 #ifndef OPENSSL_NO_DES
1076 BIO_printf(bio_err,"des-cbc des-ede3 ");
1078 #ifndef OPENSSL_NO_AES
1079 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1080 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1082 #ifndef OPENSSL_NO_CAMELLIA
1083 BIO_printf(bio_err,"\n");
1084 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1086 #ifndef OPENSSL_NO_RC4
1087 BIO_printf(bio_err,"rc4");
1089 BIO_printf(bio_err,"\n");
1091 #ifndef OPENSSL_NO_RSA
1092 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1095 #ifndef OPENSSL_NO_DSA
1096 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1098 #ifndef OPENSSL_NO_ECDSA
1099 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1100 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1101 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1102 BIO_printf(bio_err,"ecdsa\n");
1104 #ifndef OPENSSL_NO_ECDH
1105 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1106 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1107 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1108 BIO_printf(bio_err,"ecdh\n");
1111 #ifndef OPENSSL_NO_IDEA
1112 BIO_printf(bio_err,"idea ");
1114 #ifndef OPENSSL_NO_SEED
1115 BIO_printf(bio_err,"seed ");
1117 #ifndef OPENSSL_NO_RC2
1118 BIO_printf(bio_err,"rc2 ");
1120 #ifndef OPENSSL_NO_DES
1121 BIO_printf(bio_err,"des ");
1123 #ifndef OPENSSL_NO_AES
1124 BIO_printf(bio_err,"aes ");
1126 #ifndef OPENSSL_NO_CAMELLIA
1127 BIO_printf(bio_err,"camellia ");
1129 #ifndef OPENSSL_NO_RSA
1130 BIO_printf(bio_err,"rsa ");
1132 #ifndef OPENSSL_NO_BF
1133 BIO_printf(bio_err,"blowfish");
1135 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1136 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1137 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1138 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1139 BIO_printf(bio_err,"\n");
1141 BIO_printf(bio_err,"prime-trial-division prime-coprime\n");
1143 BIO_printf(bio_err,"\n");
1144 BIO_printf(bio_err,"Available options:\n");
1145 #if defined(TIMES) || defined(USE_TOD)
1146 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1148 #ifndef OPENSSL_NO_ENGINE
1149 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1151 BIO_printf(bio_err,"-evp e use EVP e.\n");
1152 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1153 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1155 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1165 if(multi && do_multi(multi))
1171 for (i=0; i<ALGOR_NUM; i++)
1176 for (i=0; i<RSA_NUM; i++)
1178 for (i=0; i<DSA_NUM; i++)
1180 #ifndef OPENSSL_NO_ECDSA
1181 for (i=0; i<EC_NUM; i++)
1184 #ifndef OPENSSL_NO_ECDH
1185 for (i=0; i<EC_NUM; i++)
1189 for (i=0; i<ALGOR_NUM; i++)
1190 if (doit[i]) pr_header++;
1192 if (usertime == 0 && !mr)
1193 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1195 #ifndef OPENSSL_NO_RSA
1196 for (i=0; i<RSA_NUM; i++)
1198 const unsigned char *p;
1201 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1202 if (rsa_key[i] == NULL)
1204 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1210 BIO_printf(bio_err,mr ? "+RK:%d:"
1211 : "Loaded RSA key, %d bit modulus and e= 0x",
1212 BN_num_bits(rsa_key[i]->n));
1213 BN_print(bio_err,rsa_key[i]->e);
1214 BIO_printf(bio_err,"\n");
1220 #ifndef OPENSSL_NO_DSA
1221 dsa_key[0]=get_dsa512();
1222 dsa_key[1]=get_dsa1024();
1223 dsa_key[2]=get_dsa2048();
1226 #ifndef OPENSSL_NO_DES
1227 DES_set_key_unchecked(&key,&sch);
1228 DES_set_key_unchecked(&key2,&sch2);
1229 DES_set_key_unchecked(&key3,&sch3);
1231 #ifndef OPENSSL_NO_AES
1232 AES_set_encrypt_key(key16,128,&aes_ks1);
1233 AES_set_encrypt_key(key24,192,&aes_ks2);
1234 AES_set_encrypt_key(key32,256,&aes_ks3);
1236 #ifndef OPENSSL_NO_CAMELLIA
1237 Camellia_set_key(key16,128,&camellia_ks1);
1238 Camellia_set_key(ckey24,192,&camellia_ks2);
1239 Camellia_set_key(ckey32,256,&camellia_ks3);
1241 #ifndef OPENSSL_NO_IDEA
1242 idea_set_encrypt_key(key16,&idea_ks);
1244 #ifndef OPENSSL_NO_SEED
1245 SEED_set_key(key16,&seed_ks);
1247 #ifndef OPENSSL_NO_RC4
1248 RC4_set_key(&rc4_ks,16,key16);
1250 #ifndef OPENSSL_NO_RC2
1251 RC2_set_key(&rc2_ks,16,key16,128);
1253 #ifndef OPENSSL_NO_RC5
1254 RC5_32_set_key(&rc5_ks,16,key16,12);
1256 #ifndef OPENSSL_NO_BF
1257 BF_set_key(&bf_ks,16,key16);
1259 #ifndef OPENSSL_NO_CAST
1260 CAST_set_key(&cast_ks,16,key16);
1262 #ifndef OPENSSL_NO_RSA
1263 memset(rsa_c,0,sizeof(rsa_c));
1266 #ifndef OPENSSL_NO_DES
1267 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1273 for (it=count; it; it--)
1274 DES_ecb_encrypt((DES_cblock *)buf,
1280 c[D_MD2][0]=count/10;
1281 c[D_MDC2][0]=count/10;
1286 c[D_RMD160][0]=count;
1287 c[D_RC4][0]=count*5;
1288 c[D_CBC_DES][0]=count;
1289 c[D_EDE3_DES][0]=count/3;
1290 c[D_CBC_IDEA][0]=count;
1291 c[D_CBC_SEED][0]=count;
1292 c[D_CBC_RC2][0]=count;
1293 c[D_CBC_RC5][0]=count;
1294 c[D_CBC_BF][0]=count;
1295 c[D_CBC_CAST][0]=count;
1296 c[D_CBC_128_AES][0]=count;
1297 c[D_CBC_192_AES][0]=count;
1298 c[D_CBC_256_AES][0]=count;
1299 c[D_CBC_128_CML][0]=count;
1300 c[D_CBC_192_CML][0]=count;
1301 c[D_CBC_256_CML][0]=count;
1302 c[D_SHA256][0]=count;
1303 c[D_SHA512][0]=count;
1304 c[D_WHIRLPOOL][0]=count;
1305 c[D_IGE_128_AES][0]=count;
1306 c[D_IGE_192_AES][0]=count;
1307 c[D_IGE_256_AES][0]=count;
1308 c[D_GHASH][0]=count;
1310 for (i=1; i<SIZE_NUM; i++)
1312 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1313 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1314 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1315 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1316 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1317 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1318 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1319 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1320 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1321 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1323 for (i=1; i<SIZE_NUM; i++)
1327 l0=(long)lengths[i-1];
1328 l1=(long)lengths[i];
1329 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1330 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1331 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1332 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1333 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1334 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1335 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1336 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1337 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1338 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1339 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1340 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1341 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1342 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1343 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1344 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1345 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1346 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1349 prime_c[D_PRIME_TRIAL_DIVISION]=count;
1350 prime_c[D_PRIME_COPRIME]=count;
1352 #ifndef OPENSSL_NO_RSA
1353 rsa_c[R_RSA_512][0]=count/2000;
1354 rsa_c[R_RSA_512][1]=count/400;
1355 for (i=1; i<RSA_NUM; i++)
1357 rsa_c[i][0]=rsa_c[i-1][0]/8;
1358 rsa_c[i][1]=rsa_c[i-1][1]/4;
1359 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1363 if (rsa_c[i][0] == 0)
1372 #ifndef OPENSSL_NO_DSA
1373 dsa_c[R_DSA_512][0]=count/1000;
1374 dsa_c[R_DSA_512][1]=count/1000/2;
1375 for (i=1; i<DSA_NUM; i++)
1377 dsa_c[i][0]=dsa_c[i-1][0]/4;
1378 dsa_c[i][1]=dsa_c[i-1][1]/4;
1379 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1392 #ifndef OPENSSL_NO_ECDSA
1393 ecdsa_c[R_EC_P160][0]=count/1000;
1394 ecdsa_c[R_EC_P160][1]=count/1000/2;
1395 for (i=R_EC_P192; i<=R_EC_P521; i++)
1397 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1398 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1399 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1403 if (ecdsa_c[i] == 0)
1410 ecdsa_c[R_EC_K163][0]=count/1000;
1411 ecdsa_c[R_EC_K163][1]=count/1000/2;
1412 for (i=R_EC_K233; i<=R_EC_K571; i++)
1414 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1415 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1416 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1420 if (ecdsa_c[i] == 0)
1427 ecdsa_c[R_EC_B163][0]=count/1000;
1428 ecdsa_c[R_EC_B163][1]=count/1000/2;
1429 for (i=R_EC_B233; i<=R_EC_B571; i++)
1431 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1432 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1433 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1437 if (ecdsa_c[i] == 0)
1446 #ifndef OPENSSL_NO_ECDH
1447 ecdh_c[R_EC_P160][0]=count/1000;
1448 ecdh_c[R_EC_P160][1]=count/1000;
1449 for (i=R_EC_P192; i<=R_EC_P521; i++)
1451 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1452 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1453 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1464 ecdh_c[R_EC_K163][0]=count/1000;
1465 ecdh_c[R_EC_K163][1]=count/1000;
1466 for (i=R_EC_K233; i<=R_EC_K571; i++)
1468 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1469 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1470 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1481 ecdh_c[R_EC_B163][0]=count/1000;
1482 ecdh_c[R_EC_B163][1]=count/1000;
1483 for (i=R_EC_B233; i<=R_EC_B571; i++)
1485 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1486 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1487 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1500 #define COND(d) (count < (d))
1501 #define COUNT(d) (d)
1503 /* not worth fixing */
1504 # error "You cannot disable DES on systems without SIGALRM."
1505 #endif /* OPENSSL_NO_DES */
1507 #define COND(c) (run && count<0x7fffffff)
1508 #define COUNT(d) (count)
1510 signal(SIGALRM,sig_done);
1512 #endif /* SIGALRM */
1514 #ifndef OPENSSL_NO_MD2
1517 for (j=0; j<SIZE_NUM; j++)
1519 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1521 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1522 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1524 print_result(D_MD2,j,count,d);
1528 #ifndef OPENSSL_NO_MDC2
1531 for (j=0; j<SIZE_NUM; j++)
1533 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1535 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1536 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1538 print_result(D_MDC2,j,count,d);
1543 #ifndef OPENSSL_NO_MD4
1546 for (j=0; j<SIZE_NUM; j++)
1548 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1550 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1551 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1553 print_result(D_MD4,j,count,d);
1558 #ifndef OPENSSL_NO_MD5
1561 for (j=0; j<SIZE_NUM; j++)
1563 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1565 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1566 MD5(buf,lengths[j],md5);
1568 print_result(D_MD5,j,count,d);
1573 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1578 HMAC_CTX_init(&hctx);
1579 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1580 16,EVP_md5(), NULL);
1582 for (j=0; j<SIZE_NUM; j++)
1584 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1586 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1588 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1589 HMAC_Update(&hctx,buf,lengths[j]);
1590 HMAC_Final(&hctx,&(hmac[0]),NULL);
1593 print_result(D_HMAC,j,count,d);
1595 HMAC_CTX_cleanup(&hctx);
1598 #ifndef OPENSSL_NO_SHA
1601 for (j=0; j<SIZE_NUM; j++)
1603 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1605 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1607 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1609 SHA1(buf,lengths[j],sha);
1612 print_result(D_SHA1,j,count,d);
1616 #ifndef OPENSSL_NO_SHA256
1619 for (j=0; j<SIZE_NUM; j++)
1621 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1623 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1624 SHA256(buf,lengths[j],sha256);
1626 print_result(D_SHA256,j,count,d);
1631 #ifndef OPENSSL_NO_SHA512
1634 for (j=0; j<SIZE_NUM; j++)
1636 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1638 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1639 SHA512(buf,lengths[j],sha512);
1641 print_result(D_SHA512,j,count,d);
1647 #ifndef OPENSSL_NO_WHIRLPOOL
1648 if (doit[D_WHIRLPOOL])
1650 for (j=0; j<SIZE_NUM; j++)
1652 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1654 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1655 WHIRLPOOL(buf,lengths[j],whirlpool);
1657 print_result(D_WHIRLPOOL,j,count,d);
1662 #ifndef OPENSSL_NO_RIPEMD
1665 for (j=0; j<SIZE_NUM; j++)
1667 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1669 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1670 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1672 print_result(D_RMD160,j,count,d);
1676 #ifndef OPENSSL_NO_RC4
1679 for (j=0; j<SIZE_NUM; j++)
1681 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1683 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1684 RC4(&rc4_ks,(unsigned int)lengths[j],
1687 print_result(D_RC4,j,count,d);
1691 #ifndef OPENSSL_NO_DES
1692 if (doit[D_CBC_DES])
1694 for (j=0; j<SIZE_NUM; j++)
1696 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1698 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1699 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1700 &DES_iv,DES_ENCRYPT);
1702 print_result(D_CBC_DES,j,count,d);
1706 if (doit[D_EDE3_DES])
1708 for (j=0; j<SIZE_NUM; j++)
1710 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1712 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1713 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1715 &DES_iv,DES_ENCRYPT);
1717 print_result(D_EDE3_DES,j,count,d);
1721 #ifndef OPENSSL_NO_AES
1722 if (doit[D_CBC_128_AES])
1724 for (j=0; j<SIZE_NUM; j++)
1726 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1728 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1729 AES_cbc_encrypt(buf,buf,
1730 (unsigned long)lengths[j],&aes_ks1,
1733 print_result(D_CBC_128_AES,j,count,d);
1736 if (doit[D_CBC_192_AES])
1738 for (j=0; j<SIZE_NUM; j++)
1740 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1742 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1743 AES_cbc_encrypt(buf,buf,
1744 (unsigned long)lengths[j],&aes_ks2,
1747 print_result(D_CBC_192_AES,j,count,d);
1750 if (doit[D_CBC_256_AES])
1752 for (j=0; j<SIZE_NUM; j++)
1754 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1756 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1757 AES_cbc_encrypt(buf,buf,
1758 (unsigned long)lengths[j],&aes_ks3,
1761 print_result(D_CBC_256_AES,j,count,d);
1765 if (doit[D_IGE_128_AES])
1767 for (j=0; j<SIZE_NUM; j++)
1769 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1771 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1772 AES_ige_encrypt(buf,buf2,
1773 (unsigned long)lengths[j],&aes_ks1,
1776 print_result(D_IGE_128_AES,j,count,d);
1779 if (doit[D_IGE_192_AES])
1781 for (j=0; j<SIZE_NUM; j++)
1783 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1785 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1786 AES_ige_encrypt(buf,buf2,
1787 (unsigned long)lengths[j],&aes_ks2,
1790 print_result(D_IGE_192_AES,j,count,d);
1793 if (doit[D_IGE_256_AES])
1795 for (j=0; j<SIZE_NUM; j++)
1797 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1799 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1800 AES_ige_encrypt(buf,buf2,
1801 (unsigned long)lengths[j],&aes_ks3,
1804 print_result(D_IGE_256_AES,j,count,d);
1809 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1810 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1812 for (j=0; j<SIZE_NUM; j++)
1814 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1816 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1817 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1819 print_result(D_GHASH,j,count,d);
1821 CRYPTO_gcm128_release(ctx);
1825 #ifndef OPENSSL_NO_CAMELLIA
1826 if (doit[D_CBC_128_CML])
1828 for (j=0; j<SIZE_NUM; j++)
1830 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1832 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1833 Camellia_cbc_encrypt(buf,buf,
1834 (unsigned long)lengths[j],&camellia_ks1,
1835 iv,CAMELLIA_ENCRYPT);
1837 print_result(D_CBC_128_CML,j,count,d);
1840 if (doit[D_CBC_192_CML])
1842 for (j=0; j<SIZE_NUM; j++)
1844 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1846 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1847 Camellia_cbc_encrypt(buf,buf,
1848 (unsigned long)lengths[j],&camellia_ks2,
1849 iv,CAMELLIA_ENCRYPT);
1851 print_result(D_CBC_192_CML,j,count,d);
1854 if (doit[D_CBC_256_CML])
1856 for (j=0; j<SIZE_NUM; j++)
1858 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1860 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1861 Camellia_cbc_encrypt(buf,buf,
1862 (unsigned long)lengths[j],&camellia_ks3,
1863 iv,CAMELLIA_ENCRYPT);
1865 print_result(D_CBC_256_CML,j,count,d);
1870 #ifndef OPENSSL_NO_IDEA
1871 if (doit[D_CBC_IDEA])
1873 for (j=0; j<SIZE_NUM; j++)
1875 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1877 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1878 idea_cbc_encrypt(buf,buf,
1879 (unsigned long)lengths[j],&idea_ks,
1882 print_result(D_CBC_IDEA,j,count,d);
1886 #ifndef OPENSSL_NO_SEED
1887 if (doit[D_CBC_SEED])
1889 for (j=0; j<SIZE_NUM; j++)
1891 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1893 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1894 SEED_cbc_encrypt(buf,buf,
1895 (unsigned long)lengths[j],&seed_ks,iv,1);
1897 print_result(D_CBC_SEED,j,count,d);
1901 #ifndef OPENSSL_NO_RC2
1902 if (doit[D_CBC_RC2])
1904 for (j=0; j<SIZE_NUM; j++)
1906 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1908 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1909 RC2_cbc_encrypt(buf,buf,
1910 (unsigned long)lengths[j],&rc2_ks,
1913 print_result(D_CBC_RC2,j,count,d);
1917 #ifndef OPENSSL_NO_RC5
1918 if (doit[D_CBC_RC5])
1920 for (j=0; j<SIZE_NUM; j++)
1922 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1924 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1925 RC5_32_cbc_encrypt(buf,buf,
1926 (unsigned long)lengths[j],&rc5_ks,
1929 print_result(D_CBC_RC5,j,count,d);
1933 #ifndef OPENSSL_NO_BF
1936 for (j=0; j<SIZE_NUM; j++)
1938 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1940 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1941 BF_cbc_encrypt(buf,buf,
1942 (unsigned long)lengths[j],&bf_ks,
1945 print_result(D_CBC_BF,j,count,d);
1949 #ifndef OPENSSL_NO_CAST
1950 if (doit[D_CBC_CAST])
1952 for (j=0; j<SIZE_NUM; j++)
1954 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1956 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1957 CAST_cbc_encrypt(buf,buf,
1958 (unsigned long)lengths[j],&cast_ks,
1961 print_result(D_CBC_CAST,j,count,d);
1968 for (j=0; j<SIZE_NUM; j++)
1975 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1976 /* -O3 -fschedule-insns messes up an
1977 * optimization here! names[D_EVP]
1978 * somehow becomes NULL */
1979 print_message(names[D_EVP],save_count,
1982 EVP_CIPHER_CTX_init(&ctx);
1984 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1986 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1987 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1991 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1992 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1994 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1995 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1997 EVP_DecryptFinal_ex(&ctx,buf,&outl);
1999 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2001 EVP_CIPHER_CTX_cleanup(&ctx);
2005 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2006 print_message(names[D_EVP],save_count,
2010 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2011 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2015 print_result(D_EVP,j,count,d);
2019 for (j=0; j<PRIME_NUM; j++)
2021 BIGNUM *rnd = BN_new();
2022 BIGNUM *add = BN_new();
2023 BN_CTX *ctx = BN_CTX_new();
2027 BN_set_word(add, 2);
2029 prime_print_message(prime_names[j], prime_c[j]);
2032 for (count=0, run=1; COND(prime_c[j]); count++)
2033 bn_probable_prime_dh(rnd,1024,add,NULL,ctx);
2037 mr ? "+R:%ld:%s:%f\n" : "%ld %s's in %.2fs\n",
2038 count, prime_names[j], d);
2046 RAND_pseudo_bytes(buf,36);
2047 #ifndef OPENSSL_NO_RSA
2048 for (j=0; j<RSA_NUM; j++)
2051 if (!rsa_doit[j]) continue;
2052 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2055 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2056 ERR_print_errors(bio_err);
2061 pkey_print_message("private","rsa",
2062 rsa_c[j][0],rsa_bits[j],
2064 /* RSA_blinding_on(rsa_key[j],NULL); */
2066 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2068 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2069 &rsa_num, rsa_key[j]);
2073 "RSA sign failure\n");
2074 ERR_print_errors(bio_err);
2080 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2081 : "%ld %d bit private RSA's in %.2fs\n",
2082 count,rsa_bits[j],d);
2083 rsa_results[j][0]=d/(double)count;
2088 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2091 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2092 ERR_print_errors(bio_err);
2097 pkey_print_message("public","rsa",
2098 rsa_c[j][1],rsa_bits[j],
2101 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2103 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2104 rsa_num, rsa_key[j]);
2108 "RSA verify failure\n");
2109 ERR_print_errors(bio_err);
2115 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2116 : "%ld %d bit public RSA's in %.2fs\n",
2117 count,rsa_bits[j],d);
2118 rsa_results[j][1]=d/(double)count;
2124 /* if longer than 10s, don't do any more */
2125 for (j++; j<RSA_NUM; j++)
2131 RAND_pseudo_bytes(buf,20);
2132 #ifndef OPENSSL_NO_DSA
2133 if (RAND_status() != 1)
2135 RAND_seed(rnd_seed, sizeof rnd_seed);
2138 for (j=0; j<DSA_NUM; j++)
2143 if (!dsa_doit[j]) continue;
2144 /* DSA_generate_key(dsa_key[j]); */
2145 /* DSA_sign_setup(dsa_key[j],NULL); */
2146 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2150 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2151 ERR_print_errors(bio_err);
2156 pkey_print_message("sign","dsa",
2157 dsa_c[j][0],dsa_bits[j],
2160 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2162 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2167 "DSA sign failure\n");
2168 ERR_print_errors(bio_err);
2174 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2175 : "%ld %d bit DSA signs in %.2fs\n",
2176 count,dsa_bits[j],d);
2177 dsa_results[j][0]=d/(double)count;
2181 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2185 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2186 ERR_print_errors(bio_err);
2191 pkey_print_message("verify","dsa",
2192 dsa_c[j][1],dsa_bits[j],
2195 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2197 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2202 "DSA verify failure\n");
2203 ERR_print_errors(bio_err);
2209 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2210 : "%ld %d bit DSA verify in %.2fs\n",
2211 count,dsa_bits[j],d);
2212 dsa_results[j][1]=d/(double)count;
2217 /* if longer than 10s, don't do any more */
2218 for (j++; j<DSA_NUM; j++)
2222 if (rnd_fake) RAND_cleanup();
2225 #ifndef OPENSSL_NO_ECDSA
2226 if (RAND_status() != 1)
2228 RAND_seed(rnd_seed, sizeof rnd_seed);
2231 for (j=0; j<EC_NUM; j++)
2235 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2236 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2237 if (ecdsa[j] == NULL)
2239 BIO_printf(bio_err,"ECDSA failure.\n");
2240 ERR_print_errors(bio_err);
2246 EC_KEY_precompute_mult(ecdsa[j], NULL);
2248 /* Perform ECDSA signature test */
2249 EC_KEY_generate_key(ecdsa[j]);
2250 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2251 &ecdsasiglen, ecdsa[j]);
2254 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2255 ERR_print_errors(bio_err);
2260 pkey_print_message("sign","ecdsa",
2262 test_curves_bits[j],
2266 for (count=0,run=1; COND(ecdsa_c[j][0]);
2269 ret=ECDSA_sign(0, buf, 20,
2270 ecdsasig, &ecdsasiglen,
2274 BIO_printf(bio_err, "ECDSA sign failure\n");
2275 ERR_print_errors(bio_err);
2282 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2283 "%ld %d bit ECDSA signs in %.2fs \n",
2284 count, test_curves_bits[j], d);
2285 ecdsa_results[j][0]=d/(double)count;
2289 /* Perform ECDSA verification test */
2290 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2291 ecdsasiglen, ecdsa[j]);
2294 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2295 ERR_print_errors(bio_err);
2300 pkey_print_message("verify","ecdsa",
2302 test_curves_bits[j],
2305 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2307 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2310 BIO_printf(bio_err, "ECDSA verify failure\n");
2311 ERR_print_errors(bio_err);
2317 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2318 : "%ld %d bit ECDSA verify in %.2fs\n",
2319 count, test_curves_bits[j], d);
2320 ecdsa_results[j][1]=d/(double)count;
2325 /* if longer than 10s, don't do any more */
2326 for (j++; j<EC_NUM; j++)
2331 if (rnd_fake) RAND_cleanup();
2334 #ifndef OPENSSL_NO_ECDH
2335 if (RAND_status() != 1)
2337 RAND_seed(rnd_seed, sizeof rnd_seed);
2340 for (j=0; j<EC_NUM; j++)
2342 if (!ecdh_doit[j]) continue;
2343 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2344 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2345 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2347 BIO_printf(bio_err,"ECDH failure.\n");
2348 ERR_print_errors(bio_err);
2353 /* generate two ECDH key pairs */
2354 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2355 !EC_KEY_generate_key(ecdh_b[j]))
2357 BIO_printf(bio_err,"ECDH key generation failure.\n");
2358 ERR_print_errors(bio_err);
2363 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2364 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2366 int field_size, outlen;
2367 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2368 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2369 if (field_size <= 24 * 8)
2371 outlen = KDF1_SHA1_len;
2376 outlen = (field_size+7)/8;
2379 secret_size_a = ECDH_compute_key(secret_a, outlen,
2380 EC_KEY_get0_public_key(ecdh_b[j]),
2382 secret_size_b = ECDH_compute_key(secret_b, outlen,
2383 EC_KEY_get0_public_key(ecdh_a[j]),
2385 if (secret_size_a != secret_size_b)
2390 for (secret_idx = 0;
2391 (secret_idx < secret_size_a)
2392 && (ecdh_checks == 1);
2395 if (secret_a[secret_idx] != secret_b[secret_idx])
2399 if (ecdh_checks == 0)
2401 BIO_printf(bio_err,"ECDH computations don't match.\n");
2402 ERR_print_errors(bio_err);
2406 pkey_print_message("","ecdh",
2408 test_curves_bits[j],
2411 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2413 ECDH_compute_key(secret_a, outlen,
2414 EC_KEY_get0_public_key(ecdh_b[j]),
2418 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2419 count, test_curves_bits[j], d);
2420 ecdh_results[j][0]=d/(double)count;
2428 /* if longer than 10s, don't do any more */
2429 for (j++; j<EC_NUM; j++)
2433 if (rnd_fake) RAND_cleanup();
2440 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2441 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2443 printf("%s ",BN_options());
2444 #ifndef OPENSSL_NO_MD2
2445 printf("%s ",MD2_options());
2447 #ifndef OPENSSL_NO_RC4
2448 printf("%s ",RC4_options());
2450 #ifndef OPENSSL_NO_DES
2451 printf("%s ",DES_options());
2453 #ifndef OPENSSL_NO_AES
2454 printf("%s ",AES_options());
2456 #ifndef OPENSSL_NO_IDEA
2457 printf("%s ",idea_options());
2459 #ifndef OPENSSL_NO_BF
2460 printf("%s ",BF_options());
2462 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2468 fprintf(stdout,"+H");
2471 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2472 fprintf(stdout,"type ");
2474 for (j=0; j<SIZE_NUM; j++)
2475 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2476 fprintf(stdout,"\n");
2479 for (k=0; k<ALGOR_NUM; k++)
2481 if (!doit[k]) continue;
2483 fprintf(stdout,"+F:%d:%s",k,names[k]);
2485 fprintf(stdout,"%-13s",names[k]);
2486 for (j=0; j<SIZE_NUM; j++)
2488 if (results[k][j] > 10000 && !mr)
2489 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2491 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2493 fprintf(stdout,"\n");
2495 #ifndef OPENSSL_NO_RSA
2497 for (k=0; k<RSA_NUM; k++)
2499 if (!rsa_doit[k]) continue;
2502 printf("%18ssign verify sign/s verify/s\n"," ");
2506 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2507 k,rsa_bits[k],rsa_results[k][0],
2510 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2511 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2512 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2515 #ifndef OPENSSL_NO_DSA
2517 for (k=0; k<DSA_NUM; k++)
2519 if (!dsa_doit[k]) continue;
2522 printf("%18ssign verify sign/s verify/s\n"," ");
2526 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2527 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2529 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2530 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2531 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2534 #ifndef OPENSSL_NO_ECDSA
2536 for (k=0; k<EC_NUM; k++)
2538 if (!ecdsa_doit[k]) continue;
2541 printf("%30ssign verify sign/s verify/s\n"," ");
2546 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2547 k, test_curves_bits[k],
2548 ecdsa_results[k][0],ecdsa_results[k][1]);
2551 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2552 test_curves_bits[k],
2553 test_curves_names[k],
2554 ecdsa_results[k][0],ecdsa_results[k][1],
2555 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2560 #ifndef OPENSSL_NO_ECDH
2562 for (k=0; k<EC_NUM; k++)
2564 if (!ecdh_doit[k]) continue;
2567 printf("%30sop op/s\n"," ");
2571 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2572 k, test_curves_bits[k],
2573 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2576 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2577 test_curves_bits[k],
2578 test_curves_names[k],
2579 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2586 ERR_print_errors(bio_err);
2587 if (buf != NULL) OPENSSL_free(buf);
2588 if (buf2 != NULL) OPENSSL_free(buf2);
2589 #ifndef OPENSSL_NO_RSA
2590 for (i=0; i<RSA_NUM; i++)
2591 if (rsa_key[i] != NULL)
2592 RSA_free(rsa_key[i]);
2594 #ifndef OPENSSL_NO_DSA
2595 for (i=0; i<DSA_NUM; i++)
2596 if (dsa_key[i] != NULL)
2597 DSA_free(dsa_key[i]);
2600 #ifndef OPENSSL_NO_ECDSA
2601 for (i=0; i<EC_NUM; i++)
2602 if (ecdsa[i] != NULL)
2603 EC_KEY_free(ecdsa[i]);
2605 #ifndef OPENSSL_NO_ECDH
2606 for (i=0; i<EC_NUM; i++)
2608 if (ecdh_a[i] != NULL)
2609 EC_KEY_free(ecdh_a[i]);
2610 if (ecdh_b[i] != NULL)
2611 EC_KEY_free(ecdh_b[i]);
2619 static void print_message(const char *s, long num, int length)
2622 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2623 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2624 (void)BIO_flush(bio_err);
2627 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2628 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2629 (void)BIO_flush(bio_err);
2636 static void prime_print_message(const char *s, long num)
2639 BIO_printf(bio_err,mr ? "+DT:%s:%d\n"
2640 : "Doing %s for %ds: ", s, SECONDS);
2641 (void)BIO_flush(bio_err);
2644 BIO_printf(bio_err,mr ? "+DN:%s:%ld\n"
2645 : "Doing %s %ld times: ", s, num);
2646 (void)BIO_flush(bio_err);
2653 static void pkey_print_message(const char *str, const char *str2, long num,
2657 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2658 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2659 (void)BIO_flush(bio_err);
2662 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2663 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2664 (void)BIO_flush(bio_err);
2671 static void print_result(int alg,int run_no,int count,double time_used)
2673 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2674 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2675 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2679 static char *sstrsep(char **string, const char *delim)
2682 char *token = *string;
2687 memset(isdelim, 0, sizeof isdelim);
2692 isdelim[(unsigned char)(*delim)] = 1;
2696 while (!isdelim[(unsigned char)(**string)])
2710 static int do_multi(int multi)
2715 static char sep[]=":";
2717 fds=malloc(multi*sizeof *fds);
2718 for(n=0 ; n < multi ; ++n)
2722 fprintf(stderr, "pipe failure\n");
2736 if (dup(fd[1]) == -1)
2738 fprintf(stderr, "dup failed\n");
2747 printf("Forked child %d\n",n);
2750 /* for now, assume the pipe is long enough to take all the output */
2751 for(n=0 ; n < multi ; ++n)
2757 f=fdopen(fds[n],"r");
2758 while(fgets(buf,sizeof buf,f))
2765 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2769 printf("Got: %s from %d\n",buf,n);
2770 if(!strncmp(buf,"+F:",3))
2776 alg=atoi(sstrsep(&p,sep));
2778 for(j=0 ; j < SIZE_NUM ; ++j)
2779 results[alg][j]+=atof(sstrsep(&p,sep));
2781 else if(!strncmp(buf,"+F2:",4))
2787 k=atoi(sstrsep(&p,sep));
2790 d=atof(sstrsep(&p,sep));
2792 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2794 rsa_results[k][0]=d;
2796 d=atof(sstrsep(&p,sep));
2798 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2800 rsa_results[k][1]=d;
2802 else if(!strncmp(buf,"+F2:",4))
2808 k=atoi(sstrsep(&p,sep));
2811 d=atof(sstrsep(&p,sep));
2813 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2815 rsa_results[k][0]=d;
2817 d=atof(sstrsep(&p,sep));
2819 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2821 rsa_results[k][1]=d;
2823 #ifndef OPENSSL_NO_DSA
2824 else if(!strncmp(buf,"+F3:",4))
2830 k=atoi(sstrsep(&p,sep));
2833 d=atof(sstrsep(&p,sep));
2835 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2837 dsa_results[k][0]=d;
2839 d=atof(sstrsep(&p,sep));
2841 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2843 dsa_results[k][1]=d;
2846 #ifndef OPENSSL_NO_ECDSA
2847 else if(!strncmp(buf,"+F4:",4))
2853 k=atoi(sstrsep(&p,sep));
2856 d=atof(sstrsep(&p,sep));
2858 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2860 ecdsa_results[k][0]=d;
2862 d=atof(sstrsep(&p,sep));
2864 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2866 ecdsa_results[k][1]=d;
2870 #ifndef OPENSSL_NO_ECDH
2871 else if(!strncmp(buf,"+F5:",4))
2877 k=atoi(sstrsep(&p,sep));
2880 d=atof(sstrsep(&p,sep));
2882 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2884 ecdh_results[k][0]=d;
2889 else if(!strncmp(buf,"+H:",3))
2893 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);