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>
195 #ifdef OPENSSL_DOING_MAKEDEPEND
196 #undef AES_set_encrypt_key
197 #undef AES_set_decrypt_key
198 #undef DES_set_key_unchecked
200 #define BF_set_key private_BF_set_key
201 #define CAST_set_key private_CAST_set_key
202 #define idea_set_encrypt_key private_idea_set_encrypt_key
203 #define SEED_set_key private_SEED_set_key
204 #define RC2_set_key private_RC2_set_key
205 #define RC4_set_key private_RC4_set_key
206 #define DES_set_key_unchecked private_DES_set_key_unchecked
207 #define AES_set_encrypt_key private_AES_set_encrypt_key
208 #define AES_set_decrypt_key private_AES_set_decrypt_key
209 #define Camellia_set_key private_Camellia_set_key
213 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
227 #define BUFSIZE ((long)1024*8+1)
231 static int usertime=1;
233 static double Time_F(int s);
234 static void print_message(const char *s,long num,int length);
235 static void pkey_print_message(const char *str, const char *str2,
236 long num, int bits, int sec);
237 static void print_result(int alg,int run_no,int count,double time_used);
239 static int do_multi(int multi);
248 #define MAX_ECDH_SIZE 256
250 static const char *names[ALGOR_NUM]={
251 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
252 "des cbc","des ede3","idea cbc","seed cbc",
253 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
254 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
255 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
256 "evp","sha256","sha512","whirlpool",
257 "aes-128 ige","aes-192 ige","aes-256 ige","ghash"};
258 static double results[ALGOR_NUM][SIZE_NUM];
259 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
260 #ifndef OPENSSL_NO_RSA
261 static double rsa_results[RSA_NUM][2];
263 #ifndef OPENSSL_NO_DSA
264 static double dsa_results[DSA_NUM][2];
266 #ifndef OPENSSL_NO_ECDSA
267 static double ecdsa_results[EC_NUM][2];
269 #ifndef OPENSSL_NO_ECDH
270 static double ecdh_results[EC_NUM][1];
273 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
274 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
275 static int rnd_fake = 0;
279 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
280 #define SIGRETTYPE void
282 #define SIGRETTYPE int
285 static SIGRETTYPE sig_done(int sig);
286 static SIGRETTYPE sig_done(int sig)
288 signal(SIGALRM,sig_done);
301 #if !defined(SIGALRM)
304 static unsigned int lapse,schlock;
305 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
306 #define alarm alarm_win32
308 static DWORD WINAPI sleepy(VOID *arg)
316 static double Time_F(int s)
322 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
325 DWORD ret=GetLastError();
326 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
329 CloseHandle(thr); /* detach the thread */
330 while (!schlock) Sleep(0); /* scheduler spinlock */
333 return app_tminterval(s,usertime);
337 static double Time_F(int s)
339 return app_tminterval(s,usertime);
344 #ifndef OPENSSL_NO_ECDH
345 static const int KDF1_SHA1_len = 20;
346 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
348 #ifndef OPENSSL_NO_SHA
349 if (*outlen < SHA_DIGEST_LENGTH)
352 *outlen = SHA_DIGEST_LENGTH;
353 return SHA1(in, inlen, out);
356 #endif /* OPENSSL_NO_SHA */
358 #endif /* OPENSSL_NO_ECDH */
361 int MAIN(int, char **);
363 int MAIN(int argc, char **argv)
365 unsigned char *buf=NULL,*buf2=NULL;
367 long count=0,save_count=0;
369 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
372 #ifndef OPENSSL_NO_RSA
375 unsigned char md[EVP_MAX_MD_SIZE];
376 #ifndef OPENSSL_NO_MD2
377 unsigned char md2[MD2_DIGEST_LENGTH];
379 #ifndef OPENSSL_NO_MDC2
380 unsigned char mdc2[MDC2_DIGEST_LENGTH];
382 #ifndef OPENSSL_NO_MD4
383 unsigned char md4[MD4_DIGEST_LENGTH];
385 #ifndef OPENSSL_NO_MD5
386 unsigned char md5[MD5_DIGEST_LENGTH];
387 unsigned char hmac[MD5_DIGEST_LENGTH];
389 #ifndef OPENSSL_NO_SHA
390 unsigned char sha[SHA_DIGEST_LENGTH];
391 #ifndef OPENSSL_NO_SHA256
392 unsigned char sha256[SHA256_DIGEST_LENGTH];
394 #ifndef OPENSSL_NO_SHA512
395 unsigned char sha512[SHA512_DIGEST_LENGTH];
398 #ifndef OPENSSL_NO_WHIRLPOOL
399 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
401 #ifndef OPENSSL_NO_RIPEMD
402 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
404 #ifndef OPENSSL_NO_RC4
407 #ifndef OPENSSL_NO_RC5
410 #ifndef OPENSSL_NO_RC2
413 #ifndef OPENSSL_NO_IDEA
414 IDEA_KEY_SCHEDULE idea_ks;
416 #ifndef OPENSSL_NO_SEED
417 SEED_KEY_SCHEDULE seed_ks;
419 #ifndef OPENSSL_NO_BF
422 #ifndef OPENSSL_NO_CAST
425 static const unsigned char key16[16]=
426 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
427 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
428 #ifndef OPENSSL_NO_AES
429 static const unsigned char key24[24]=
430 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
431 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
432 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
433 static const unsigned char key32[32]=
434 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
435 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
436 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
437 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
439 #ifndef OPENSSL_NO_CAMELLIA
440 static const unsigned char ckey24[24]=
441 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
442 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
443 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
444 static const unsigned char ckey32[32]=
445 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
446 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
447 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
448 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
450 #ifndef OPENSSL_NO_AES
451 #define MAX_BLOCK_SIZE 128
453 #define MAX_BLOCK_SIZE 64
455 unsigned char DES_iv[8];
456 unsigned char iv[2*MAX_BLOCK_SIZE/8];
457 #ifndef OPENSSL_NO_DES
458 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
459 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
460 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
461 DES_key_schedule sch;
462 DES_key_schedule sch2;
463 DES_key_schedule sch3;
465 #ifndef OPENSSL_NO_AES
466 AES_KEY aes_ks1, aes_ks2, aes_ks3;
468 #ifndef OPENSSL_NO_CAMELLIA
469 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
481 #define D_CBC_IDEA 10
482 #define D_CBC_SEED 11
486 #define D_CBC_CAST 15
487 #define D_CBC_128_AES 16
488 #define D_CBC_192_AES 17
489 #define D_CBC_256_AES 18
490 #define D_CBC_128_CML 19
491 #define D_CBC_192_CML 20
492 #define D_CBC_256_CML 21
496 #define D_WHIRLPOOL 25
497 #define D_IGE_128_AES 26
498 #define D_IGE_192_AES 27
499 #define D_IGE_256_AES 28
502 long c[ALGOR_NUM][SIZE_NUM];
528 #ifndef OPENSSL_NO_RSA
529 RSA *rsa_key[RSA_NUM];
530 long rsa_c[RSA_NUM][2];
531 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
532 static unsigned char *rsa_data[RSA_NUM]=
533 {test512,test1024,test2048,test4096};
534 static int rsa_data_length[RSA_NUM]={
535 sizeof(test512),sizeof(test1024),
536 sizeof(test2048),sizeof(test4096)};
538 #ifndef OPENSSL_NO_DSA
539 DSA *dsa_key[DSA_NUM];
540 long dsa_c[DSA_NUM][2];
541 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
543 #ifndef OPENSSL_NO_EC
544 /* We only test over the following curves as they are representative,
545 * To add tests over more curves, simply add the curve NID
546 * and curve name to the following arrays and increase the
547 * EC_NUM value accordingly.
549 static unsigned int test_curves[EC_NUM] =
553 NID_X9_62_prime192v1,
555 NID_X9_62_prime256v1,
570 static const char * test_curves_names[EC_NUM] =
591 static int test_curves_bits[EC_NUM] =
593 160, 192, 224, 256, 384, 521,
594 163, 233, 283, 409, 571,
595 163, 233, 283, 409, 571
600 #ifndef OPENSSL_NO_ECDSA
601 unsigned char ecdsasig[256];
602 unsigned int ecdsasiglen;
603 EC_KEY *ecdsa[EC_NUM];
604 long ecdsa_c[EC_NUM][2];
607 #ifndef OPENSSL_NO_ECDH
608 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
609 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
610 int secret_size_a, secret_size_b;
613 long ecdh_c[EC_NUM][2];
616 int rsa_doit[RSA_NUM];
617 int dsa_doit[DSA_NUM];
618 #ifndef OPENSSL_NO_ECDSA
619 int ecdsa_doit[EC_NUM];
621 #ifndef OPENSSL_NO_ECDH
622 int ecdh_doit[EC_NUM];
626 const EVP_CIPHER *evp_cipher=NULL;
627 const EVP_MD *evp_md=NULL;
638 memset(results, 0, sizeof(results));
639 #ifndef OPENSSL_NO_DSA
640 memset(dsa_key,0,sizeof(dsa_key));
642 #ifndef OPENSSL_NO_ECDSA
643 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
645 #ifndef OPENSSL_NO_ECDH
646 for (i=0; i<EC_NUM; i++)
655 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
656 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
658 if (!load_config(bio_err, NULL))
661 #ifndef OPENSSL_NO_RSA
662 memset(rsa_key,0,sizeof(rsa_key));
663 for (i=0; i<RSA_NUM; i++)
667 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
669 BIO_printf(bio_err,"out of memory\n");
672 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
674 BIO_printf(bio_err,"out of memory\n");
678 memset(c,0,sizeof(c));
679 memset(DES_iv,0,sizeof(DES_iv));
680 memset(iv,0,sizeof(iv));
682 for (i=0; i<ALGOR_NUM; i++)
684 for (i=0; i<RSA_NUM; i++)
686 for (i=0; i<DSA_NUM; i++)
688 #ifndef OPENSSL_NO_ECDSA
689 for (i=0; i<EC_NUM; i++)
692 #ifndef OPENSSL_NO_ECDH
693 for (i=0; i<EC_NUM; i++)
703 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
706 j--; /* Otherwise, -elapsed gets confused with
709 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
715 BIO_printf(bio_err,"no EVP given\n");
718 evp_cipher=EVP_get_cipherbyname(*argv);
721 evp_md=EVP_get_digestbyname(*argv);
723 if(!evp_cipher && !evp_md)
725 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
730 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
733 j--; /* Otherwise, -elapsed gets confused with
736 #ifndef OPENSSL_NO_ENGINE
737 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
743 BIO_printf(bio_err,"no engine given\n");
746 setup_engine(bio_err, *argv, 0);
747 /* j will be increased again further down. We just
748 don't want speed to confuse an engine with an
749 algorithm, especially when none is given (which
750 means all of them should be run) */
755 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
761 BIO_printf(bio_err,"no multi count given\n");
767 BIO_printf(bio_err,"bad multi count\n");
770 j--; /* Otherwise, -mr gets confused with
774 else if (argc > 0 && !strcmp(*argv,"-mr"))
777 j--; /* Otherwise, -mr gets confused with
781 #ifndef OPENSSL_NO_MD2
782 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
785 #ifndef OPENSSL_NO_MDC2
786 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
789 #ifndef OPENSSL_NO_MD4
790 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
793 #ifndef OPENSSL_NO_MD5
794 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
797 #ifndef OPENSSL_NO_MD5
798 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
801 #ifndef OPENSSL_NO_SHA
802 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
804 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
808 #ifndef OPENSSL_NO_SHA256
809 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
812 #ifndef OPENSSL_NO_SHA512
813 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
817 #ifndef OPENSSL_NO_WHIRLPOOL
818 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
821 #ifndef OPENSSL_NO_RIPEMD
822 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
824 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
826 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
829 #ifndef OPENSSL_NO_RC4
830 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
833 #ifndef OPENSSL_NO_DES
834 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
835 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
838 #ifndef OPENSSL_NO_AES
839 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
840 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
841 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
842 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
843 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
844 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
847 #ifndef OPENSSL_NO_CAMELLIA
848 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
849 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
850 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
853 #ifndef OPENSSL_NO_RSA
854 #if 0 /* was: #ifdef RSAref */
855 if (strcmp(*argv,"rsaref") == 0)
857 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
863 if (strcmp(*argv,"openssl") == 0)
865 RSA_set_default_method(RSA_PKCS1_SSLeay());
870 #endif /* !OPENSSL_NO_RSA */
871 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
872 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
873 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
874 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
875 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
876 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
877 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
879 #ifndef OPENSSL_NO_RC2
880 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
881 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
884 #ifndef OPENSSL_NO_RC5
885 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
886 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
889 #ifndef OPENSSL_NO_IDEA
890 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
891 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
894 #ifndef OPENSSL_NO_SEED
895 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
896 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
899 #ifndef OPENSSL_NO_BF
900 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
901 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
902 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
905 #ifndef OPENSSL_NO_CAST
906 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
907 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
908 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
911 #ifndef OPENSSL_NO_DES
912 if (strcmp(*argv,"des") == 0)
919 #ifndef OPENSSL_NO_AES
920 if (strcmp(*argv,"aes") == 0)
922 doit[D_CBC_128_AES]=1;
923 doit[D_CBC_192_AES]=1;
924 doit[D_CBC_256_AES]=1;
926 else if (strcmp(*argv,"ghash") == 0)
932 #ifndef OPENSSL_NO_CAMELLIA
933 if (strcmp(*argv,"camellia") == 0)
935 doit[D_CBC_128_CML]=1;
936 doit[D_CBC_192_CML]=1;
937 doit[D_CBC_256_CML]=1;
941 #ifndef OPENSSL_NO_RSA
942 if (strcmp(*argv,"rsa") == 0)
944 rsa_doit[R_RSA_512]=1;
945 rsa_doit[R_RSA_1024]=1;
946 rsa_doit[R_RSA_2048]=1;
947 rsa_doit[R_RSA_4096]=1;
951 #ifndef OPENSSL_NO_DSA
952 if (strcmp(*argv,"dsa") == 0)
954 dsa_doit[R_DSA_512]=1;
955 dsa_doit[R_DSA_1024]=1;
956 dsa_doit[R_DSA_2048]=1;
960 #ifndef OPENSSL_NO_ECDSA
961 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
962 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
963 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
964 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
965 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
966 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
967 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
968 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
969 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
970 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
971 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
972 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
973 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
974 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
975 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
976 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
977 else if (strcmp(*argv,"ecdsa") == 0)
979 for (i=0; i < EC_NUM; i++)
984 #ifndef OPENSSL_NO_ECDH
985 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
986 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
987 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
988 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
989 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
990 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
991 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
992 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
993 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
994 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
995 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
996 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
997 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
998 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
999 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1000 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1001 else if (strcmp(*argv,"ecdh") == 0)
1003 for (i=0; i < EC_NUM; i++)
1009 BIO_printf(bio_err,"Error: bad option or value\n");
1010 BIO_printf(bio_err,"\n");
1011 BIO_printf(bio_err,"Available values:\n");
1012 #ifndef OPENSSL_NO_MD2
1013 BIO_printf(bio_err,"md2 ");
1015 #ifndef OPENSSL_NO_MDC2
1016 BIO_printf(bio_err,"mdc2 ");
1018 #ifndef OPENSSL_NO_MD4
1019 BIO_printf(bio_err,"md4 ");
1021 #ifndef OPENSSL_NO_MD5
1022 BIO_printf(bio_err,"md5 ");
1023 #ifndef OPENSSL_NO_HMAC
1024 BIO_printf(bio_err,"hmac ");
1027 #ifndef OPENSSL_NO_SHA1
1028 BIO_printf(bio_err,"sha1 ");
1030 #ifndef OPENSSL_NO_SHA256
1031 BIO_printf(bio_err,"sha256 ");
1033 #ifndef OPENSSL_NO_SHA512
1034 BIO_printf(bio_err,"sha512 ");
1036 #ifndef OPENSSL_NO_WHIRLPOOL
1037 BIO_printf(bio_err,"whirlpool");
1039 #ifndef OPENSSL_NO_RIPEMD160
1040 BIO_printf(bio_err,"rmd160");
1042 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1043 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1044 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1045 !defined(OPENSSL_NO_WHIRLPOOL)
1046 BIO_printf(bio_err,"\n");
1049 #ifndef OPENSSL_NO_IDEA
1050 BIO_printf(bio_err,"idea-cbc ");
1052 #ifndef OPENSSL_NO_SEED
1053 BIO_printf(bio_err,"seed-cbc ");
1055 #ifndef OPENSSL_NO_RC2
1056 BIO_printf(bio_err,"rc2-cbc ");
1058 #ifndef OPENSSL_NO_RC5
1059 BIO_printf(bio_err,"rc5-cbc ");
1061 #ifndef OPENSSL_NO_BF
1062 BIO_printf(bio_err,"bf-cbc");
1064 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1065 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1066 BIO_printf(bio_err,"\n");
1068 #ifndef OPENSSL_NO_DES
1069 BIO_printf(bio_err,"des-cbc des-ede3 ");
1071 #ifndef OPENSSL_NO_AES
1072 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1073 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1075 #ifndef OPENSSL_NO_CAMELLIA
1076 BIO_printf(bio_err,"\n");
1077 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1079 #ifndef OPENSSL_NO_RC4
1080 BIO_printf(bio_err,"rc4");
1082 BIO_printf(bio_err,"\n");
1084 #ifndef OPENSSL_NO_RSA
1085 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1088 #ifndef OPENSSL_NO_DSA
1089 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1091 #ifndef OPENSSL_NO_ECDSA
1092 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1093 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1094 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1095 BIO_printf(bio_err,"ecdsa\n");
1097 #ifndef OPENSSL_NO_ECDH
1098 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1099 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1100 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1101 BIO_printf(bio_err,"ecdh\n");
1104 #ifndef OPENSSL_NO_IDEA
1105 BIO_printf(bio_err,"idea ");
1107 #ifndef OPENSSL_NO_SEED
1108 BIO_printf(bio_err,"seed ");
1110 #ifndef OPENSSL_NO_RC2
1111 BIO_printf(bio_err,"rc2 ");
1113 #ifndef OPENSSL_NO_DES
1114 BIO_printf(bio_err,"des ");
1116 #ifndef OPENSSL_NO_AES
1117 BIO_printf(bio_err,"aes ");
1119 #ifndef OPENSSL_NO_CAMELLIA
1120 BIO_printf(bio_err,"camellia ");
1122 #ifndef OPENSSL_NO_RSA
1123 BIO_printf(bio_err,"rsa ");
1125 #ifndef OPENSSL_NO_BF
1126 BIO_printf(bio_err,"blowfish");
1128 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1129 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1130 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1131 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1132 BIO_printf(bio_err,"\n");
1135 BIO_printf(bio_err,"\n");
1136 BIO_printf(bio_err,"Available options:\n");
1137 #if defined(TIMES) || defined(USE_TOD)
1138 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1140 #ifndef OPENSSL_NO_ENGINE
1141 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1143 BIO_printf(bio_err,"-evp e use EVP e.\n");
1144 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1145 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1147 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1157 if(multi && do_multi(multi))
1163 for (i=0; i<ALGOR_NUM; i++)
1168 for (i=0; i<RSA_NUM; i++)
1170 for (i=0; i<DSA_NUM; i++)
1172 #ifndef OPENSSL_NO_ECDSA
1173 for (i=0; i<EC_NUM; i++)
1176 #ifndef OPENSSL_NO_ECDH
1177 for (i=0; i<EC_NUM; i++)
1181 for (i=0; i<ALGOR_NUM; i++)
1182 if (doit[i]) pr_header++;
1184 if (usertime == 0 && !mr)
1185 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1187 #ifndef OPENSSL_NO_RSA
1188 for (i=0; i<RSA_NUM; i++)
1190 const unsigned char *p;
1193 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1194 if (rsa_key[i] == NULL)
1196 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1202 BIO_printf(bio_err,mr ? "+RK:%d:"
1203 : "Loaded RSA key, %d bit modulus and e= 0x",
1204 BN_num_bits(rsa_key[i]->n));
1205 BN_print(bio_err,rsa_key[i]->e);
1206 BIO_printf(bio_err,"\n");
1212 #ifndef OPENSSL_NO_DSA
1213 dsa_key[0]=get_dsa512();
1214 dsa_key[1]=get_dsa1024();
1215 dsa_key[2]=get_dsa2048();
1218 #ifndef OPENSSL_NO_DES
1219 DES_set_key_unchecked(&key,&sch);
1220 DES_set_key_unchecked(&key2,&sch2);
1221 DES_set_key_unchecked(&key3,&sch3);
1223 #ifndef OPENSSL_NO_AES
1224 AES_set_encrypt_key(key16,128,&aes_ks1);
1225 AES_set_encrypt_key(key24,192,&aes_ks2);
1226 AES_set_encrypt_key(key32,256,&aes_ks3);
1228 #ifndef OPENSSL_NO_CAMELLIA
1229 Camellia_set_key(key16,128,&camellia_ks1);
1230 Camellia_set_key(ckey24,192,&camellia_ks2);
1231 Camellia_set_key(ckey32,256,&camellia_ks3);
1233 #ifndef OPENSSL_NO_IDEA
1234 idea_set_encrypt_key(key16,&idea_ks);
1236 #ifndef OPENSSL_NO_SEED
1237 SEED_set_key(key16,&seed_ks);
1239 #ifndef OPENSSL_NO_RC4
1240 RC4_set_key(&rc4_ks,16,key16);
1242 #ifndef OPENSSL_NO_RC2
1243 RC2_set_key(&rc2_ks,16,key16,128);
1245 #ifndef OPENSSL_NO_RC5
1246 RC5_32_set_key(&rc5_ks,16,key16,12);
1248 #ifndef OPENSSL_NO_BF
1249 BF_set_key(&bf_ks,16,key16);
1251 #ifndef OPENSSL_NO_CAST
1252 CAST_set_key(&cast_ks,16,key16);
1254 #ifndef OPENSSL_NO_RSA
1255 memset(rsa_c,0,sizeof(rsa_c));
1258 #ifndef OPENSSL_NO_DES
1259 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1265 for (it=count; it; it--)
1266 DES_ecb_encrypt((DES_cblock *)buf,
1272 c[D_MD2][0]=count/10;
1273 c[D_MDC2][0]=count/10;
1278 c[D_RMD160][0]=count;
1279 c[D_RC4][0]=count*5;
1280 c[D_CBC_DES][0]=count;
1281 c[D_EDE3_DES][0]=count/3;
1282 c[D_CBC_IDEA][0]=count;
1283 c[D_CBC_SEED][0]=count;
1284 c[D_CBC_RC2][0]=count;
1285 c[D_CBC_RC5][0]=count;
1286 c[D_CBC_BF][0]=count;
1287 c[D_CBC_CAST][0]=count;
1288 c[D_CBC_128_AES][0]=count;
1289 c[D_CBC_192_AES][0]=count;
1290 c[D_CBC_256_AES][0]=count;
1291 c[D_CBC_128_CML][0]=count;
1292 c[D_CBC_192_CML][0]=count;
1293 c[D_CBC_256_CML][0]=count;
1294 c[D_SHA256][0]=count;
1295 c[D_SHA512][0]=count;
1296 c[D_WHIRLPOOL][0]=count;
1297 c[D_IGE_128_AES][0]=count;
1298 c[D_IGE_192_AES][0]=count;
1299 c[D_IGE_256_AES][0]=count;
1300 c[D_GHASH][0]=count;
1302 for (i=1; i<SIZE_NUM; i++)
1304 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1305 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1306 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1307 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1308 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1309 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1310 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1311 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1312 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1313 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1315 for (i=1; i<SIZE_NUM; i++)
1319 l0=(long)lengths[i-1];
1320 l1=(long)lengths[i];
1321 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1322 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1323 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1324 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1325 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1326 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1327 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1328 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1329 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1330 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1331 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1332 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1333 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1334 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1335 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1336 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1337 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1338 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1340 #ifndef OPENSSL_NO_RSA
1341 rsa_c[R_RSA_512][0]=count/2000;
1342 rsa_c[R_RSA_512][1]=count/400;
1343 for (i=1; i<RSA_NUM; i++)
1345 rsa_c[i][0]=rsa_c[i-1][0]/8;
1346 rsa_c[i][1]=rsa_c[i-1][1]/4;
1347 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1351 if (rsa_c[i][0] == 0)
1360 #ifndef OPENSSL_NO_DSA
1361 dsa_c[R_DSA_512][0]=count/1000;
1362 dsa_c[R_DSA_512][1]=count/1000/2;
1363 for (i=1; i<DSA_NUM; i++)
1365 dsa_c[i][0]=dsa_c[i-1][0]/4;
1366 dsa_c[i][1]=dsa_c[i-1][1]/4;
1367 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1380 #ifndef OPENSSL_NO_ECDSA
1381 ecdsa_c[R_EC_P160][0]=count/1000;
1382 ecdsa_c[R_EC_P160][1]=count/1000/2;
1383 for (i=R_EC_P192; i<=R_EC_P521; i++)
1385 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1386 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1387 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1391 if (ecdsa_c[i] == 0)
1398 ecdsa_c[R_EC_K163][0]=count/1000;
1399 ecdsa_c[R_EC_K163][1]=count/1000/2;
1400 for (i=R_EC_K233; i<=R_EC_K571; i++)
1402 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1403 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1404 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1408 if (ecdsa_c[i] == 0)
1415 ecdsa_c[R_EC_B163][0]=count/1000;
1416 ecdsa_c[R_EC_B163][1]=count/1000/2;
1417 for (i=R_EC_B233; i<=R_EC_B571; i++)
1419 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1420 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1421 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1425 if (ecdsa_c[i] == 0)
1434 #ifndef OPENSSL_NO_ECDH
1435 ecdh_c[R_EC_P160][0]=count/1000;
1436 ecdh_c[R_EC_P160][1]=count/1000;
1437 for (i=R_EC_P192; i<=R_EC_P521; i++)
1439 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1440 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1441 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1452 ecdh_c[R_EC_K163][0]=count/1000;
1453 ecdh_c[R_EC_K163][1]=count/1000;
1454 for (i=R_EC_K233; i<=R_EC_K571; i++)
1456 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1457 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1458 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1469 ecdh_c[R_EC_B163][0]=count/1000;
1470 ecdh_c[R_EC_B163][1]=count/1000;
1471 for (i=R_EC_B233; i<=R_EC_B571; i++)
1473 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1474 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1475 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1488 #define COND(d) (count < (d))
1489 #define COUNT(d) (d)
1491 /* not worth fixing */
1492 # error "You cannot disable DES on systems without SIGALRM."
1493 #endif /* OPENSSL_NO_DES */
1495 #define COND(c) (run && count<0x7fffffff)
1496 #define COUNT(d) (count)
1498 signal(SIGALRM,sig_done);
1500 #endif /* SIGALRM */
1502 #ifndef OPENSSL_NO_MD2
1505 for (j=0; j<SIZE_NUM; j++)
1507 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1509 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1510 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1512 print_result(D_MD2,j,count,d);
1516 #ifndef OPENSSL_NO_MDC2
1519 for (j=0; j<SIZE_NUM; j++)
1521 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1523 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1524 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1526 print_result(D_MDC2,j,count,d);
1531 #ifndef OPENSSL_NO_MD4
1534 for (j=0; j<SIZE_NUM; j++)
1536 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1538 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1539 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1541 print_result(D_MD4,j,count,d);
1546 #ifndef OPENSSL_NO_MD5
1549 for (j=0; j<SIZE_NUM; j++)
1551 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1553 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1554 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1556 print_result(D_MD5,j,count,d);
1561 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1566 HMAC_CTX_init(&hctx);
1567 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1568 16,EVP_md5(), NULL);
1570 for (j=0; j<SIZE_NUM; j++)
1572 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1574 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1576 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1577 HMAC_Update(&hctx,buf,lengths[j]);
1578 HMAC_Final(&hctx,&(hmac[0]),NULL);
1581 print_result(D_HMAC,j,count,d);
1583 HMAC_CTX_cleanup(&hctx);
1586 #ifndef OPENSSL_NO_SHA
1589 for (j=0; j<SIZE_NUM; j++)
1591 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1593 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1594 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1596 print_result(D_SHA1,j,count,d);
1600 #ifndef OPENSSL_NO_SHA256
1603 for (j=0; j<SIZE_NUM; j++)
1605 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1607 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1608 SHA256(buf,lengths[j],sha256);
1610 print_result(D_SHA256,j,count,d);
1615 #ifndef OPENSSL_NO_SHA512
1618 for (j=0; j<SIZE_NUM; j++)
1620 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1622 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1623 SHA512(buf,lengths[j],sha512);
1625 print_result(D_SHA512,j,count,d);
1631 #ifndef OPENSSL_NO_WHIRLPOOL
1632 if (doit[D_WHIRLPOOL])
1634 for (j=0; j<SIZE_NUM; j++)
1636 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1638 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1639 WHIRLPOOL(buf,lengths[j],whirlpool);
1641 print_result(D_WHIRLPOOL,j,count,d);
1646 #ifndef OPENSSL_NO_RIPEMD
1649 for (j=0; j<SIZE_NUM; j++)
1651 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1653 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1654 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1656 print_result(D_RMD160,j,count,d);
1660 #ifndef OPENSSL_NO_RC4
1663 for (j=0; j<SIZE_NUM; j++)
1665 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1667 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1668 RC4(&rc4_ks,(unsigned int)lengths[j],
1671 print_result(D_RC4,j,count,d);
1675 #ifndef OPENSSL_NO_DES
1676 if (doit[D_CBC_DES])
1678 for (j=0; j<SIZE_NUM; j++)
1680 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1682 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1683 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1684 &DES_iv,DES_ENCRYPT);
1686 print_result(D_CBC_DES,j,count,d);
1690 if (doit[D_EDE3_DES])
1692 for (j=0; j<SIZE_NUM; j++)
1694 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1696 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1697 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1699 &DES_iv,DES_ENCRYPT);
1701 print_result(D_EDE3_DES,j,count,d);
1705 #ifndef OPENSSL_NO_AES
1706 if (doit[D_CBC_128_AES])
1708 for (j=0; j<SIZE_NUM; j++)
1710 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1712 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1713 AES_cbc_encrypt(buf,buf,
1714 (unsigned long)lengths[j],&aes_ks1,
1717 print_result(D_CBC_128_AES,j,count,d);
1720 if (doit[D_CBC_192_AES])
1722 for (j=0; j<SIZE_NUM; j++)
1724 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1726 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1727 AES_cbc_encrypt(buf,buf,
1728 (unsigned long)lengths[j],&aes_ks2,
1731 print_result(D_CBC_192_AES,j,count,d);
1734 if (doit[D_CBC_256_AES])
1736 for (j=0; j<SIZE_NUM; j++)
1738 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1740 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1741 AES_cbc_encrypt(buf,buf,
1742 (unsigned long)lengths[j],&aes_ks3,
1745 print_result(D_CBC_256_AES,j,count,d);
1749 if (doit[D_IGE_128_AES])
1751 for (j=0; j<SIZE_NUM; j++)
1753 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1755 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1756 AES_ige_encrypt(buf,buf2,
1757 (unsigned long)lengths[j],&aes_ks1,
1760 print_result(D_IGE_128_AES,j,count,d);
1763 if (doit[D_IGE_192_AES])
1765 for (j=0; j<SIZE_NUM; j++)
1767 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1769 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1770 AES_ige_encrypt(buf,buf2,
1771 (unsigned long)lengths[j],&aes_ks2,
1774 print_result(D_IGE_192_AES,j,count,d);
1777 if (doit[D_IGE_256_AES])
1779 for (j=0; j<SIZE_NUM; j++)
1781 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1783 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1784 AES_ige_encrypt(buf,buf2,
1785 (unsigned long)lengths[j],&aes_ks3,
1788 print_result(D_IGE_256_AES,j,count,d);
1793 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1794 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1796 for (j=0; j<SIZE_NUM; j++)
1798 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1800 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1801 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1803 print_result(D_GHASH,j,count,d);
1805 CRYPTO_gcm128_release(ctx);
1809 #ifndef OPENSSL_NO_CAMELLIA
1810 if (doit[D_CBC_128_CML])
1812 for (j=0; j<SIZE_NUM; j++)
1814 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1816 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1817 Camellia_cbc_encrypt(buf,buf,
1818 (unsigned long)lengths[j],&camellia_ks1,
1819 iv,CAMELLIA_ENCRYPT);
1821 print_result(D_CBC_128_CML,j,count,d);
1824 if (doit[D_CBC_192_CML])
1826 for (j=0; j<SIZE_NUM; j++)
1828 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1830 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1831 Camellia_cbc_encrypt(buf,buf,
1832 (unsigned long)lengths[j],&camellia_ks2,
1833 iv,CAMELLIA_ENCRYPT);
1835 print_result(D_CBC_192_CML,j,count,d);
1838 if (doit[D_CBC_256_CML])
1840 for (j=0; j<SIZE_NUM; j++)
1842 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1844 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1845 Camellia_cbc_encrypt(buf,buf,
1846 (unsigned long)lengths[j],&camellia_ks3,
1847 iv,CAMELLIA_ENCRYPT);
1849 print_result(D_CBC_256_CML,j,count,d);
1854 #ifndef OPENSSL_NO_IDEA
1855 if (doit[D_CBC_IDEA])
1857 for (j=0; j<SIZE_NUM; j++)
1859 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1861 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1862 idea_cbc_encrypt(buf,buf,
1863 (unsigned long)lengths[j],&idea_ks,
1866 print_result(D_CBC_IDEA,j,count,d);
1870 #ifndef OPENSSL_NO_SEED
1871 if (doit[D_CBC_SEED])
1873 for (j=0; j<SIZE_NUM; j++)
1875 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1877 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1878 SEED_cbc_encrypt(buf,buf,
1879 (unsigned long)lengths[j],&seed_ks,iv,1);
1881 print_result(D_CBC_SEED,j,count,d);
1885 #ifndef OPENSSL_NO_RC2
1886 if (doit[D_CBC_RC2])
1888 for (j=0; j<SIZE_NUM; j++)
1890 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1892 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1893 RC2_cbc_encrypt(buf,buf,
1894 (unsigned long)lengths[j],&rc2_ks,
1897 print_result(D_CBC_RC2,j,count,d);
1901 #ifndef OPENSSL_NO_RC5
1902 if (doit[D_CBC_RC5])
1904 for (j=0; j<SIZE_NUM; j++)
1906 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1908 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1909 RC5_32_cbc_encrypt(buf,buf,
1910 (unsigned long)lengths[j],&rc5_ks,
1913 print_result(D_CBC_RC5,j,count,d);
1917 #ifndef OPENSSL_NO_BF
1920 for (j=0; j<SIZE_NUM; j++)
1922 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1924 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1925 BF_cbc_encrypt(buf,buf,
1926 (unsigned long)lengths[j],&bf_ks,
1929 print_result(D_CBC_BF,j,count,d);
1933 #ifndef OPENSSL_NO_CAST
1934 if (doit[D_CBC_CAST])
1936 for (j=0; j<SIZE_NUM; j++)
1938 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1940 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1941 CAST_cbc_encrypt(buf,buf,
1942 (unsigned long)lengths[j],&cast_ks,
1945 print_result(D_CBC_CAST,j,count,d);
1952 for (j=0; j<SIZE_NUM; j++)
1959 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1960 /* -O3 -fschedule-insns messes up an
1961 * optimization here! names[D_EVP]
1962 * somehow becomes NULL */
1963 print_message(names[D_EVP],save_count,
1966 EVP_CIPHER_CTX_init(&ctx);
1968 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1970 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1971 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1975 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1976 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1978 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1979 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1981 EVP_DecryptFinal_ex(&ctx,buf,&outl);
1983 EVP_EncryptFinal_ex(&ctx,buf,&outl);
1985 EVP_CIPHER_CTX_cleanup(&ctx);
1989 names[D_EVP]=OBJ_nid2ln(evp_md->type);
1990 print_message(names[D_EVP],save_count,
1994 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1995 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
1999 print_result(D_EVP,j,count,d);
2003 RAND_pseudo_bytes(buf,36);
2004 #ifndef OPENSSL_NO_RSA
2005 for (j=0; j<RSA_NUM; j++)
2008 if (!rsa_doit[j]) continue;
2009 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2012 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2013 ERR_print_errors(bio_err);
2018 pkey_print_message("private","rsa",
2019 rsa_c[j][0],rsa_bits[j],
2021 /* RSA_blinding_on(rsa_key[j],NULL); */
2023 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2025 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2026 &rsa_num, rsa_key[j]);
2030 "RSA sign failure\n");
2031 ERR_print_errors(bio_err);
2037 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2038 : "%ld %d bit private RSA's in %.2fs\n",
2039 count,rsa_bits[j],d);
2040 rsa_results[j][0]=d/(double)count;
2045 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2048 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2049 ERR_print_errors(bio_err);
2054 pkey_print_message("public","rsa",
2055 rsa_c[j][1],rsa_bits[j],
2058 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2060 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2061 rsa_num, rsa_key[j]);
2065 "RSA verify failure\n");
2066 ERR_print_errors(bio_err);
2072 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2073 : "%ld %d bit public RSA's in %.2fs\n",
2074 count,rsa_bits[j],d);
2075 rsa_results[j][1]=d/(double)count;
2081 /* if longer than 10s, don't do any more */
2082 for (j++; j<RSA_NUM; j++)
2088 RAND_pseudo_bytes(buf,20);
2089 #ifndef OPENSSL_NO_DSA
2090 if (RAND_status() != 1)
2092 RAND_seed(rnd_seed, sizeof rnd_seed);
2095 for (j=0; j<DSA_NUM; j++)
2100 if (!dsa_doit[j]) continue;
2101 /* DSA_generate_key(dsa_key[j]); */
2102 /* DSA_sign_setup(dsa_key[j],NULL); */
2103 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2107 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2108 ERR_print_errors(bio_err);
2113 pkey_print_message("sign","dsa",
2114 dsa_c[j][0],dsa_bits[j],
2117 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2119 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2124 "DSA sign failure\n");
2125 ERR_print_errors(bio_err);
2131 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2132 : "%ld %d bit DSA signs in %.2fs\n",
2133 count,dsa_bits[j],d);
2134 dsa_results[j][0]=d/(double)count;
2138 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2142 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2143 ERR_print_errors(bio_err);
2148 pkey_print_message("verify","dsa",
2149 dsa_c[j][1],dsa_bits[j],
2152 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2154 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2159 "DSA verify failure\n");
2160 ERR_print_errors(bio_err);
2166 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2167 : "%ld %d bit DSA verify in %.2fs\n",
2168 count,dsa_bits[j],d);
2169 dsa_results[j][1]=d/(double)count;
2174 /* if longer than 10s, don't do any more */
2175 for (j++; j<DSA_NUM; j++)
2179 if (rnd_fake) RAND_cleanup();
2182 #ifndef OPENSSL_NO_ECDSA
2183 if (RAND_status() != 1)
2185 RAND_seed(rnd_seed, sizeof rnd_seed);
2188 for (j=0; j<EC_NUM; j++)
2192 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2193 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2194 if (ecdsa[j] == NULL)
2196 BIO_printf(bio_err,"ECDSA failure.\n");
2197 ERR_print_errors(bio_err);
2203 EC_KEY_precompute_mult(ecdsa[j], NULL);
2205 /* Perform ECDSA signature test */
2206 EC_KEY_generate_key(ecdsa[j]);
2207 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2208 &ecdsasiglen, ecdsa[j]);
2211 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2212 ERR_print_errors(bio_err);
2217 pkey_print_message("sign","ecdsa",
2219 test_curves_bits[j],
2223 for (count=0,run=1; COND(ecdsa_c[j][0]);
2226 ret=ECDSA_sign(0, buf, 20,
2227 ecdsasig, &ecdsasiglen,
2231 BIO_printf(bio_err, "ECDSA sign failure\n");
2232 ERR_print_errors(bio_err);
2239 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2240 "%ld %d bit ECDSA signs in %.2fs \n",
2241 count, test_curves_bits[j], d);
2242 ecdsa_results[j][0]=d/(double)count;
2246 /* Perform ECDSA verification test */
2247 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2248 ecdsasiglen, ecdsa[j]);
2251 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2252 ERR_print_errors(bio_err);
2257 pkey_print_message("verify","ecdsa",
2259 test_curves_bits[j],
2262 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2264 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2267 BIO_printf(bio_err, "ECDSA verify failure\n");
2268 ERR_print_errors(bio_err);
2274 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2275 : "%ld %d bit ECDSA verify in %.2fs\n",
2276 count, test_curves_bits[j], d);
2277 ecdsa_results[j][1]=d/(double)count;
2282 /* if longer than 10s, don't do any more */
2283 for (j++; j<EC_NUM; j++)
2288 if (rnd_fake) RAND_cleanup();
2291 #ifndef OPENSSL_NO_ECDH
2292 if (RAND_status() != 1)
2294 RAND_seed(rnd_seed, sizeof rnd_seed);
2297 for (j=0; j<EC_NUM; j++)
2299 if (!ecdh_doit[j]) continue;
2300 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2301 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2302 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2304 BIO_printf(bio_err,"ECDH failure.\n");
2305 ERR_print_errors(bio_err);
2310 /* generate two ECDH key pairs */
2311 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2312 !EC_KEY_generate_key(ecdh_b[j]))
2314 BIO_printf(bio_err,"ECDH key generation failure.\n");
2315 ERR_print_errors(bio_err);
2320 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2321 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2323 int field_size, outlen;
2324 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2325 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2326 if (field_size <= 24 * 8)
2328 outlen = KDF1_SHA1_len;
2333 outlen = (field_size+7)/8;
2336 secret_size_a = ECDH_compute_key(secret_a, outlen,
2337 EC_KEY_get0_public_key(ecdh_b[j]),
2339 secret_size_b = ECDH_compute_key(secret_b, outlen,
2340 EC_KEY_get0_public_key(ecdh_a[j]),
2342 if (secret_size_a != secret_size_b)
2347 for (secret_idx = 0;
2348 (secret_idx < secret_size_a)
2349 && (ecdh_checks == 1);
2352 if (secret_a[secret_idx] != secret_b[secret_idx])
2356 if (ecdh_checks == 0)
2358 BIO_printf(bio_err,"ECDH computations don't match.\n");
2359 ERR_print_errors(bio_err);
2363 pkey_print_message("","ecdh",
2365 test_curves_bits[j],
2368 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2370 ECDH_compute_key(secret_a, outlen,
2371 EC_KEY_get0_public_key(ecdh_b[j]),
2375 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2376 count, test_curves_bits[j], d);
2377 ecdh_results[j][0]=d/(double)count;
2385 /* if longer than 10s, don't do any more */
2386 for (j++; j<EC_NUM; j++)
2390 if (rnd_fake) RAND_cleanup();
2397 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2398 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2400 printf("%s ",BN_options());
2401 #ifndef OPENSSL_NO_MD2
2402 printf("%s ",MD2_options());
2404 #ifndef OPENSSL_NO_RC4
2405 printf("%s ",RC4_options());
2407 #ifndef OPENSSL_NO_DES
2408 printf("%s ",DES_options());
2410 #ifndef OPENSSL_NO_AES
2411 printf("%s ",AES_options());
2413 #ifndef OPENSSL_NO_IDEA
2414 printf("%s ",idea_options());
2416 #ifndef OPENSSL_NO_BF
2417 printf("%s ",BF_options());
2419 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2425 fprintf(stdout,"+H");
2428 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2429 fprintf(stdout,"type ");
2431 for (j=0; j<SIZE_NUM; j++)
2432 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2433 fprintf(stdout,"\n");
2436 for (k=0; k<ALGOR_NUM; k++)
2438 if (!doit[k]) continue;
2440 fprintf(stdout,"+F:%d:%s",k,names[k]);
2442 fprintf(stdout,"%-13s",names[k]);
2443 for (j=0; j<SIZE_NUM; j++)
2445 if (results[k][j] > 10000 && !mr)
2446 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2448 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2450 fprintf(stdout,"\n");
2452 #ifndef OPENSSL_NO_RSA
2454 for (k=0; k<RSA_NUM; k++)
2456 if (!rsa_doit[k]) continue;
2459 printf("%18ssign verify sign/s verify/s\n"," ");
2463 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2464 k,rsa_bits[k],rsa_results[k][0],
2467 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2468 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2469 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2472 #ifndef OPENSSL_NO_DSA
2474 for (k=0; k<DSA_NUM; k++)
2476 if (!dsa_doit[k]) continue;
2479 printf("%18ssign verify sign/s verify/s\n"," ");
2483 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2484 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2486 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2487 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2488 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2491 #ifndef OPENSSL_NO_ECDSA
2493 for (k=0; k<EC_NUM; k++)
2495 if (!ecdsa_doit[k]) continue;
2498 printf("%30ssign verify sign/s verify/s\n"," ");
2503 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2504 k, test_curves_bits[k],
2505 ecdsa_results[k][0],ecdsa_results[k][1]);
2508 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2509 test_curves_bits[k],
2510 test_curves_names[k],
2511 ecdsa_results[k][0],ecdsa_results[k][1],
2512 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2517 #ifndef OPENSSL_NO_ECDH
2519 for (k=0; k<EC_NUM; k++)
2521 if (!ecdh_doit[k]) continue;
2524 printf("%30sop op/s\n"," ");
2528 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2529 k, test_curves_bits[k],
2530 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2533 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2534 test_curves_bits[k],
2535 test_curves_names[k],
2536 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2543 ERR_print_errors(bio_err);
2544 if (buf != NULL) OPENSSL_free(buf);
2545 if (buf2 != NULL) OPENSSL_free(buf2);
2546 #ifndef OPENSSL_NO_RSA
2547 for (i=0; i<RSA_NUM; i++)
2548 if (rsa_key[i] != NULL)
2549 RSA_free(rsa_key[i]);
2551 #ifndef OPENSSL_NO_DSA
2552 for (i=0; i<DSA_NUM; i++)
2553 if (dsa_key[i] != NULL)
2554 DSA_free(dsa_key[i]);
2557 #ifndef OPENSSL_NO_ECDSA
2558 for (i=0; i<EC_NUM; i++)
2559 if (ecdsa[i] != NULL)
2560 EC_KEY_free(ecdsa[i]);
2562 #ifndef OPENSSL_NO_ECDH
2563 for (i=0; i<EC_NUM; i++)
2565 if (ecdh_a[i] != NULL)
2566 EC_KEY_free(ecdh_a[i]);
2567 if (ecdh_b[i] != NULL)
2568 EC_KEY_free(ecdh_b[i]);
2576 static void print_message(const char *s, long num, int length)
2579 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2580 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2581 (void)BIO_flush(bio_err);
2584 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2585 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2586 (void)BIO_flush(bio_err);
2593 static void pkey_print_message(const char *str, const char *str2, long num,
2597 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2598 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2599 (void)BIO_flush(bio_err);
2602 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2603 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2604 (void)BIO_flush(bio_err);
2611 static void print_result(int alg,int run_no,int count,double time_used)
2613 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2614 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2615 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2619 static char *sstrsep(char **string, const char *delim)
2622 char *token = *string;
2627 memset(isdelim, 0, sizeof isdelim);
2632 isdelim[(unsigned char)(*delim)] = 1;
2636 while (!isdelim[(unsigned char)(**string)])
2650 static int do_multi(int multi)
2655 static char sep[]=":";
2657 fds=malloc(multi*sizeof *fds);
2658 for(n=0 ; n < multi ; ++n)
2662 fprintf(stderr, "pipe failure\n");
2676 if (dup(fd[1]) == -1)
2678 fprintf(stderr, "dup failed\n");
2687 printf("Forked child %d\n",n);
2690 /* for now, assume the pipe is long enough to take all the output */
2691 for(n=0 ; n < multi ; ++n)
2697 f=fdopen(fds[n],"r");
2698 while(fgets(buf,sizeof buf,f))
2705 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2709 printf("Got: %s from %d\n",buf,n);
2710 if(!strncmp(buf,"+F:",3))
2716 alg=atoi(sstrsep(&p,sep));
2718 for(j=0 ; j < SIZE_NUM ; ++j)
2719 results[alg][j]+=atof(sstrsep(&p,sep));
2721 else if(!strncmp(buf,"+F2:",4))
2727 k=atoi(sstrsep(&p,sep));
2730 d=atof(sstrsep(&p,sep));
2732 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2734 rsa_results[k][0]=d;
2736 d=atof(sstrsep(&p,sep));
2738 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2740 rsa_results[k][1]=d;
2742 else if(!strncmp(buf,"+F2:",4))
2748 k=atoi(sstrsep(&p,sep));
2751 d=atof(sstrsep(&p,sep));
2753 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2755 rsa_results[k][0]=d;
2757 d=atof(sstrsep(&p,sep));
2759 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2761 rsa_results[k][1]=d;
2763 #ifndef OPENSSL_NO_DSA
2764 else if(!strncmp(buf,"+F3:",4))
2770 k=atoi(sstrsep(&p,sep));
2773 d=atof(sstrsep(&p,sep));
2775 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2777 dsa_results[k][0]=d;
2779 d=atof(sstrsep(&p,sep));
2781 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2783 dsa_results[k][1]=d;
2786 #ifndef OPENSSL_NO_ECDSA
2787 else if(!strncmp(buf,"+F4:",4))
2793 k=atoi(sstrsep(&p,sep));
2796 d=atof(sstrsep(&p,sep));
2798 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2800 ecdsa_results[k][0]=d;
2802 d=atof(sstrsep(&p,sep));
2804 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2806 ecdsa_results[k][1]=d;
2810 #ifndef OPENSSL_NO_ECDH
2811 else if(!strncmp(buf,"+F5:",4))
2817 k=atoi(sstrsep(&p,sep));
2820 d=atof(sstrsep(&p,sep));
2822 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2824 ecdh_results[k][0]=d;
2829 else if(!strncmp(buf,"+H:",3))
2833 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);