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 PRIME_SECONDS 10
79 #define RSA_SECONDS 10
80 #define DSA_SECONDS 10
81 #define ECDSA_SECONDS 10
82 #define ECDH_SECONDS 10
84 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
85 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
88 #define PROG speed_main
96 #include <openssl/crypto.h>
97 #include <openssl/rand.h>
98 #include <openssl/err.h>
99 #include <openssl/evp.h>
100 #include <openssl/objects.h>
101 #if !defined(OPENSSL_SYS_MSDOS)
102 #include OPENSSL_UNISTD
105 #ifndef OPENSSL_SYS_NETWARE
109 #if defined(_WIN32) || defined(__CYGWIN__)
111 # if defined(__CYGWIN__) && !defined(_WIN32)
112 /* <windows.h> should define _WIN32, which normally is mutually
113 * exclusive with __CYGWIN__, but if it didn't... */
115 /* this is done because Cygwin alarm() fails sometimes. */
119 #include <openssl/bn.h>
120 #ifndef OPENSSL_NO_DES
121 #include <openssl/des.h>
123 #ifndef OPENSSL_NO_AES
124 #include <openssl/aes.h>
126 #ifndef OPENSSL_NO_CAMELLIA
127 #include <openssl/camellia.h>
129 #ifndef OPENSSL_NO_MD2
130 #include <openssl/md2.h>
132 #ifndef OPENSSL_NO_MDC2
133 #include <openssl/mdc2.h>
135 #ifndef OPENSSL_NO_MD4
136 #include <openssl/md4.h>
138 #ifndef OPENSSL_NO_MD5
139 #include <openssl/md5.h>
141 #ifndef OPENSSL_NO_HMAC
142 #include <openssl/hmac.h>
144 #include <openssl/evp.h>
145 #ifndef OPENSSL_NO_SHA
146 #include <openssl/sha.h>
148 #ifndef OPENSSL_NO_RIPEMD
149 #include <openssl/ripemd.h>
151 #ifndef OPENSSL_NO_WHIRLPOOL
152 #include <openssl/whrlpool.h>
154 #ifndef OPENSSL_NO_RC4
155 #include <openssl/rc4.h>
157 #ifndef OPENSSL_NO_RC5
158 #include <openssl/rc5.h>
160 #ifndef OPENSSL_NO_RC2
161 #include <openssl/rc2.h>
163 #ifndef OPENSSL_NO_IDEA
164 #include <openssl/idea.h>
166 #ifndef OPENSSL_NO_SEED
167 #include <openssl/seed.h>
169 #ifndef OPENSSL_NO_BF
170 #include <openssl/blowfish.h>
172 #ifndef OPENSSL_NO_CAST
173 #include <openssl/cast.h>
175 #ifndef OPENSSL_NO_RSA
176 #include <openssl/rsa.h>
177 #include "./testrsa.h"
179 #include <openssl/x509.h>
180 #ifndef OPENSSL_NO_DSA
181 #include <openssl/dsa.h>
182 #include "./testdsa.h"
184 #ifndef OPENSSL_NO_ECDSA
185 #include <openssl/ecdsa.h>
187 #ifndef OPENSSL_NO_ECDH
188 #include <openssl/ecdh.h>
190 #include <openssl/modes.h>
192 #include <openssl/bn.h>
195 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
209 #define BUFSIZE (1024*8+1)
210 #define MAX_MISALIGNMENT 63
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 pkey_print_message(const char *str, const char *str2,
220 long num, int bits, int sec);
221 static void print_result(int alg,int run_no,int count,double time_used);
223 static int do_multi(int multi);
233 #define MAX_ECDH_SIZE 256
235 static const char *names[ALGOR_NUM]={
236 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
237 "des cbc","des ede3","idea cbc","seed cbc",
238 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
239 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
240 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
241 "evp","sha256","sha512","whirlpool",
242 "aes-128 ige","aes-192 ige","aes-256 ige","ghash" };
243 static double results[ALGOR_NUM][SIZE_NUM];
244 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
245 #ifndef OPENSSL_NO_RSA
246 static double rsa_results[RSA_NUM][2];
248 #ifndef OPENSSL_NO_DSA
249 static double dsa_results[DSA_NUM][2];
251 #ifndef OPENSSL_NO_ECDSA
252 static double ecdsa_results[EC_NUM][2];
254 #ifndef OPENSSL_NO_ECDH
255 static double ecdh_results[EC_NUM][1];
258 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
259 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
260 static int rnd_fake = 0;
264 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
265 #define SIGRETTYPE void
267 #define SIGRETTYPE int
270 static SIGRETTYPE sig_done(int sig);
271 static SIGRETTYPE sig_done(int sig)
273 signal(SIGALRM,sig_done);
286 #if !defined(SIGALRM)
289 static unsigned int lapse,schlock;
290 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
291 #define alarm alarm_win32
293 static DWORD WINAPI sleepy(VOID *arg)
301 static double Time_F(int s)
309 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
312 DWORD ret=GetLastError();
313 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
316 while (!schlock) Sleep(0); /* scheduler spinlock */
317 ret = app_tminterval(s,usertime);
321 ret = app_tminterval(s,usertime);
322 if (run) TerminateThread(thr,0);
330 static double Time_F(int s)
332 double ret = app_tminterval(s,usertime);
333 if (s == STOP) alarm(0);
339 #ifndef OPENSSL_NO_ECDH
340 static const int KDF1_SHA1_len = 20;
341 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
343 #ifndef OPENSSL_NO_SHA
344 if (*outlen < SHA_DIGEST_LENGTH)
347 *outlen = SHA_DIGEST_LENGTH;
348 return SHA1(in, inlen, out);
351 #endif /* OPENSSL_NO_SHA */
353 #endif /* OPENSSL_NO_ECDH */
355 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
357 int MAIN(int, char **);
359 int MAIN(int argc, char **argv)
361 unsigned char *buf_malloc=NULL, *buf2_malloc=NULL;
362 unsigned char *buf=NULL,*buf2=NULL;
364 long count=0,save_count=0;
366 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
369 #ifndef OPENSSL_NO_RSA
372 unsigned char md[EVP_MAX_MD_SIZE];
373 #ifndef OPENSSL_NO_MD2
374 unsigned char md2[MD2_DIGEST_LENGTH];
376 #ifndef OPENSSL_NO_MDC2
377 unsigned char mdc2[MDC2_DIGEST_LENGTH];
379 #ifndef OPENSSL_NO_MD4
380 unsigned char md4[MD4_DIGEST_LENGTH];
382 #ifndef OPENSSL_NO_MD5
383 unsigned char md5[MD5_DIGEST_LENGTH];
384 unsigned char hmac[MD5_DIGEST_LENGTH];
386 #ifndef OPENSSL_NO_SHA
387 unsigned char sha[SHA_DIGEST_LENGTH];
388 #ifndef OPENSSL_NO_SHA256
389 unsigned char sha256[SHA256_DIGEST_LENGTH];
391 #ifndef OPENSSL_NO_SHA512
392 unsigned char sha512[SHA512_DIGEST_LENGTH];
395 #ifndef OPENSSL_NO_WHIRLPOOL
396 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
398 #ifndef OPENSSL_NO_RIPEMD
399 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
401 #ifndef OPENSSL_NO_RC4
404 #ifndef OPENSSL_NO_RC5
407 #ifndef OPENSSL_NO_RC2
410 #ifndef OPENSSL_NO_IDEA
411 IDEA_KEY_SCHEDULE idea_ks;
413 #ifndef OPENSSL_NO_SEED
414 SEED_KEY_SCHEDULE seed_ks;
416 #ifndef OPENSSL_NO_BF
419 #ifndef OPENSSL_NO_CAST
422 static const unsigned char key16[16]=
423 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
424 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
425 #ifndef OPENSSL_NO_AES
426 static const unsigned char key24[24]=
427 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
428 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
429 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
430 static const unsigned char key32[32]=
431 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
432 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
433 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
434 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
436 #ifndef OPENSSL_NO_CAMELLIA
437 static const unsigned char ckey24[24]=
438 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
439 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
440 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
441 static const unsigned char ckey32[32]=
442 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
443 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
444 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
445 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
447 #ifndef OPENSSL_NO_AES
448 #define MAX_BLOCK_SIZE 128
450 #define MAX_BLOCK_SIZE 64
452 unsigned char DES_iv[8];
453 unsigned char iv[2*MAX_BLOCK_SIZE/8];
454 #ifndef OPENSSL_NO_DES
455 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
456 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
457 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
458 DES_key_schedule sch;
459 DES_key_schedule sch2;
460 DES_key_schedule sch3;
462 #ifndef OPENSSL_NO_AES
463 AES_KEY aes_ks1, aes_ks2, aes_ks3;
465 #ifndef OPENSSL_NO_CAMELLIA
466 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
478 #define D_CBC_IDEA 10
479 #define D_CBC_SEED 11
483 #define D_CBC_CAST 15
484 #define D_CBC_128_AES 16
485 #define D_CBC_192_AES 17
486 #define D_CBC_256_AES 18
487 #define D_CBC_128_CML 19
488 #define D_CBC_192_CML 20
489 #define D_CBC_256_CML 21
493 #define D_WHIRLPOOL 25
494 #define D_IGE_128_AES 26
495 #define D_IGE_192_AES 27
496 #define D_IGE_256_AES 28
499 long c[ALGOR_NUM][SIZE_NUM];
501 #ifndef OPENSSL_SYS_WIN32
512 #define R_RSA_15360 6
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,3072,4096,7680,15360};
535 static unsigned char *rsa_data[RSA_NUM]=
536 {test512,test1024,test2048,test3072,test4096,test7680,test15360};
537 static int rsa_data_length[RSA_NUM]={
538 sizeof(test512),sizeof(test1024),
539 sizeof(test2048),sizeof(test3072),
540 sizeof(test4096),sizeof(test7680),
543 #ifndef OPENSSL_NO_DSA
544 DSA *dsa_key[DSA_NUM];
545 long dsa_c[DSA_NUM][2];
546 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
548 #ifndef OPENSSL_NO_EC
549 /* We only test over the following curves as they are representative,
550 * To add tests over more curves, simply add the curve NID
551 * and curve name to the following arrays and increase the
552 * EC_NUM value accordingly.
554 static unsigned int test_curves[EC_NUM] =
558 NID_X9_62_prime192v1,
560 NID_X9_62_prime256v1,
575 static const char * test_curves_names[EC_NUM] =
596 static int test_curves_bits[EC_NUM] =
598 160, 192, 224, 256, 384, 521,
599 163, 233, 283, 409, 571,
600 163, 233, 283, 409, 571
605 #ifndef OPENSSL_NO_ECDSA
606 unsigned char ecdsasig[256];
607 unsigned int ecdsasiglen;
608 EC_KEY *ecdsa[EC_NUM];
609 long ecdsa_c[EC_NUM][2];
612 #ifndef OPENSSL_NO_ECDH
613 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
614 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
615 int secret_size_a, secret_size_b;
618 long ecdh_c[EC_NUM][2];
621 int rsa_doit[RSA_NUM];
622 int dsa_doit[DSA_NUM];
623 #ifndef OPENSSL_NO_ECDSA
624 int ecdsa_doit[EC_NUM];
626 #ifndef OPENSSL_NO_ECDH
627 int ecdh_doit[EC_NUM];
631 const EVP_CIPHER *evp_cipher=NULL;
632 const EVP_MD *evp_md=NULL;
638 int misalign=MAX_MISALIGNMENT+1;
645 memset(results, 0, sizeof(results));
646 #ifndef OPENSSL_NO_DSA
647 memset(dsa_key,0,sizeof(dsa_key));
649 #ifndef OPENSSL_NO_ECDSA
650 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
652 #ifndef OPENSSL_NO_ECDH
653 for (i=0; i<EC_NUM; i++)
662 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
663 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
665 if (!load_config(bio_err, NULL))
668 #ifndef OPENSSL_NO_RSA
669 memset(rsa_key,0,sizeof(rsa_key));
670 for (i=0; i<RSA_NUM; i++)
674 if ((buf_malloc=(unsigned char *)OPENSSL_malloc(BUFSIZE+misalign)) == NULL)
676 BIO_printf(bio_err,"out of memory\n");
679 if ((buf2_malloc=(unsigned char *)OPENSSL_malloc(BUFSIZE+misalign)) == NULL)
681 BIO_printf(bio_err,"out of memory\n");
685 misalign = 0; /* set later and buf/buf2 are adjusted accordingly */
689 memset(c,0,sizeof(c));
690 memset(DES_iv,0,sizeof(DES_iv));
691 memset(iv,0,sizeof(iv));
693 for (i=0; i<ALGOR_NUM; i++)
695 for (i=0; i<RSA_NUM; i++)
697 for (i=0; i<DSA_NUM; i++)
699 #ifndef OPENSSL_NO_ECDSA
700 for (i=0; i<EC_NUM; i++)
703 #ifndef OPENSSL_NO_ECDH
704 for (i=0; i<EC_NUM; i++)
713 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
716 j--; /* Otherwise, -elapsed gets confused with
719 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
725 BIO_printf(bio_err,"no EVP given\n");
728 evp_cipher=EVP_get_cipherbyname(*argv);
731 evp_md=EVP_get_digestbyname(*argv);
733 if(!evp_cipher && !evp_md)
735 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
740 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
743 j--; /* Otherwise, -elapsed gets confused with
746 #ifndef OPENSSL_NO_ENGINE
747 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
753 BIO_printf(bio_err,"no engine given\n");
756 setup_engine(bio_err, *argv, 0);
757 /* j will be increased again further down. We just
758 don't want speed to confuse an engine with an
759 algorithm, especially when none is given (which
760 means all of them should be run) */
765 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
771 BIO_printf(bio_err,"no multi count given\n");
777 BIO_printf(bio_err,"bad multi count\n");
780 j--; /* Otherwise, -mr gets confused with
784 else if (argc > 0 && !strcmp(*argv,"-mr"))
787 j--; /* Otherwise, -mr gets confused with
790 else if (argc > 0 && !strcmp(*argv,"-mb"))
795 else if (argc > 0 && !strcmp(*argv,"-misalign"))
801 BIO_printf(bio_err,"no misalignment given\n");
804 misalign=atoi(argv[0]);
805 if (misalign<0 || misalign>MAX_MISALIGNMENT)
807 BIO_printf(bio_err,"misalignment is outsize permitted range 0-%d\n",MAX_MISALIGNMENT);
810 buf=buf_malloc+misalign;
811 buf2=buf2_malloc+misalign;
815 #ifndef OPENSSL_NO_MD2
816 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
819 #ifndef OPENSSL_NO_MDC2
820 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
823 #ifndef OPENSSL_NO_MD4
824 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
827 #ifndef OPENSSL_NO_MD5
828 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
831 #ifndef OPENSSL_NO_MD5
832 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
835 #ifndef OPENSSL_NO_SHA
836 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
838 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
842 #ifndef OPENSSL_NO_SHA256
843 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
846 #ifndef OPENSSL_NO_SHA512
847 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
851 #ifndef OPENSSL_NO_WHIRLPOOL
852 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
855 #ifndef OPENSSL_NO_RIPEMD
856 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
858 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
860 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
863 #ifndef OPENSSL_NO_RC4
864 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
867 #ifndef OPENSSL_NO_DES
868 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
869 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
872 #ifndef OPENSSL_NO_AES
873 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
874 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
875 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
876 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
877 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
878 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
881 #ifndef OPENSSL_NO_CAMELLIA
882 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
883 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
884 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
887 #ifndef OPENSSL_NO_RSA
888 #if 0 /* was: #ifdef RSAref */
889 if (strcmp(*argv,"rsaref") == 0)
891 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
897 if (strcmp(*argv,"openssl") == 0)
899 RSA_set_default_method(RSA_PKCS1_SSLeay());
904 #endif /* !OPENSSL_NO_RSA */
905 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
906 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
907 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
908 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
909 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
910 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
911 else if (strcmp(*argv,"rsa3072") == 0) rsa_doit[R_RSA_3072]=2;
912 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
913 else if (strcmp(*argv,"rsa7680") == 0) rsa_doit[R_RSA_7680]=2;
914 else if (strcmp(*argv,"rsa15360") == 0) rsa_doit[R_RSA_15360]=2;
916 #ifndef OPENSSL_NO_RC2
917 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
918 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
921 #ifndef OPENSSL_NO_RC5
922 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
923 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
926 #ifndef OPENSSL_NO_IDEA
927 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
928 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
931 #ifndef OPENSSL_NO_SEED
932 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
933 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
936 #ifndef OPENSSL_NO_BF
937 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
938 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
939 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
942 #ifndef OPENSSL_NO_CAST
943 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
944 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
945 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
948 #ifndef OPENSSL_NO_DES
949 if (strcmp(*argv,"des") == 0)
956 #ifndef OPENSSL_NO_AES
957 if (strcmp(*argv,"aes") == 0)
959 doit[D_CBC_128_AES]=1;
960 doit[D_CBC_192_AES]=1;
961 doit[D_CBC_256_AES]=1;
963 else if (strcmp(*argv,"ghash") == 0)
969 #ifndef OPENSSL_NO_CAMELLIA
970 if (strcmp(*argv,"camellia") == 0)
972 doit[D_CBC_128_CML]=1;
973 doit[D_CBC_192_CML]=1;
974 doit[D_CBC_256_CML]=1;
978 #ifndef OPENSSL_NO_RSA
979 if (strcmp(*argv,"rsa") == 0)
981 rsa_doit[R_RSA_512]=1;
982 rsa_doit[R_RSA_1024]=1;
983 rsa_doit[R_RSA_2048]=1;
984 rsa_doit[R_RSA_3072]=1;
985 rsa_doit[R_RSA_4096]=1;
986 rsa_doit[R_RSA_7680]=1;
987 rsa_doit[R_RSA_15360]=1;
991 #ifndef OPENSSL_NO_DSA
992 if (strcmp(*argv,"dsa") == 0)
994 dsa_doit[R_DSA_512]=1;
995 dsa_doit[R_DSA_1024]=1;
996 dsa_doit[R_DSA_2048]=1;
1000 #ifndef OPENSSL_NO_ECDSA
1001 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
1002 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
1003 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
1004 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
1005 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
1006 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
1007 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
1008 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
1009 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
1010 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
1011 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
1012 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
1013 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
1014 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
1015 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
1016 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
1017 else if (strcmp(*argv,"ecdsa") == 0)
1019 for (i=0; i < EC_NUM; i++)
1024 #ifndef OPENSSL_NO_ECDH
1025 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1026 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1027 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1028 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1029 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1030 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1031 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1032 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1033 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1034 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1035 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1036 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1037 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1038 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1039 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1040 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1041 else if (strcmp(*argv,"ecdh") == 0)
1043 for (i=0; i < EC_NUM; i++)
1049 BIO_printf(bio_err,"Error: bad option or value\n");
1050 BIO_printf(bio_err,"\n");
1051 BIO_printf(bio_err,"Available values:\n");
1052 #ifndef OPENSSL_NO_MD2
1053 BIO_printf(bio_err,"md2 ");
1055 #ifndef OPENSSL_NO_MDC2
1056 BIO_printf(bio_err,"mdc2 ");
1058 #ifndef OPENSSL_NO_MD4
1059 BIO_printf(bio_err,"md4 ");
1061 #ifndef OPENSSL_NO_MD5
1062 BIO_printf(bio_err,"md5 ");
1063 #ifndef OPENSSL_NO_HMAC
1064 BIO_printf(bio_err,"hmac ");
1067 #ifndef OPENSSL_NO_SHA1
1068 BIO_printf(bio_err,"sha1 ");
1070 #ifndef OPENSSL_NO_SHA256
1071 BIO_printf(bio_err,"sha256 ");
1073 #ifndef OPENSSL_NO_SHA512
1074 BIO_printf(bio_err,"sha512 ");
1076 #ifndef OPENSSL_NO_WHIRLPOOL
1077 BIO_printf(bio_err,"whirlpool");
1079 #ifndef OPENSSL_NO_RIPEMD160
1080 BIO_printf(bio_err,"rmd160");
1082 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1083 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1084 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1085 !defined(OPENSSL_NO_WHIRLPOOL)
1086 BIO_printf(bio_err,"\n");
1089 #ifndef OPENSSL_NO_IDEA
1090 BIO_printf(bio_err,"idea-cbc ");
1092 #ifndef OPENSSL_NO_SEED
1093 BIO_printf(bio_err,"seed-cbc ");
1095 #ifndef OPENSSL_NO_RC2
1096 BIO_printf(bio_err,"rc2-cbc ");
1098 #ifndef OPENSSL_NO_RC5
1099 BIO_printf(bio_err,"rc5-cbc ");
1101 #ifndef OPENSSL_NO_BF
1102 BIO_printf(bio_err,"bf-cbc");
1104 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1105 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1106 BIO_printf(bio_err,"\n");
1108 #ifndef OPENSSL_NO_DES
1109 BIO_printf(bio_err,"des-cbc des-ede3 ");
1111 #ifndef OPENSSL_NO_AES
1112 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1113 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1115 #ifndef OPENSSL_NO_CAMELLIA
1116 BIO_printf(bio_err,"\n");
1117 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1119 #ifndef OPENSSL_NO_RC4
1120 BIO_printf(bio_err,"rc4");
1122 BIO_printf(bio_err,"\n");
1124 #ifndef OPENSSL_NO_RSA
1125 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1126 BIO_printf(bio_err,"rsa7680 rsa15360\n");
1129 #ifndef OPENSSL_NO_DSA
1130 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1132 #ifndef OPENSSL_NO_ECDSA
1133 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1134 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1135 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1136 BIO_printf(bio_err,"ecdsa\n");
1138 #ifndef OPENSSL_NO_ECDH
1139 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1140 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1141 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1142 BIO_printf(bio_err,"ecdh\n");
1145 #ifndef OPENSSL_NO_IDEA
1146 BIO_printf(bio_err,"idea ");
1148 #ifndef OPENSSL_NO_SEED
1149 BIO_printf(bio_err,"seed ");
1151 #ifndef OPENSSL_NO_RC2
1152 BIO_printf(bio_err,"rc2 ");
1154 #ifndef OPENSSL_NO_DES
1155 BIO_printf(bio_err,"des ");
1157 #ifndef OPENSSL_NO_AES
1158 BIO_printf(bio_err,"aes ");
1160 #ifndef OPENSSL_NO_CAMELLIA
1161 BIO_printf(bio_err,"camellia ");
1163 #ifndef OPENSSL_NO_RSA
1164 BIO_printf(bio_err,"rsa ");
1166 #ifndef OPENSSL_NO_BF
1167 BIO_printf(bio_err,"blowfish");
1169 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1170 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1171 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1172 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1173 BIO_printf(bio_err,"\n");
1176 BIO_printf(bio_err,"\n");
1177 BIO_printf(bio_err,"Available options:\n");
1178 #if defined(TIMES) || defined(USE_TOD)
1179 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1181 #ifndef OPENSSL_NO_ENGINE
1182 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1184 BIO_printf(bio_err,"-evp e use EVP e.\n");
1185 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1186 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1187 BIO_printf(bio_err,"-mb perform multi-block benchmark (for specific ciphers)\n");
1188 BIO_printf(bio_err,"-misalign n perform benchmark with misaligned data\n");
1190 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1200 if(multi && do_multi(multi))
1206 for (i=0; i<ALGOR_NUM; i++)
1211 for (i=0; i<RSA_NUM; i++)
1213 for (i=0; i<DSA_NUM; i++)
1215 #ifndef OPENSSL_NO_ECDSA
1216 for (i=0; i<EC_NUM; i++)
1219 #ifndef OPENSSL_NO_ECDH
1220 for (i=0; i<EC_NUM; i++)
1224 for (i=0; i<ALGOR_NUM; i++)
1225 if (doit[i]) pr_header++;
1227 if (usertime == 0 && !mr)
1228 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1230 #ifndef OPENSSL_NO_RSA
1231 for (i=0; i<RSA_NUM; i++)
1233 const unsigned char *p;
1236 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1237 if (rsa_key[i] == NULL)
1239 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1245 BIO_printf(bio_err,mr ? "+RK:%d:"
1246 : "Loaded RSA key, %d bit modulus and e= 0x",
1247 BN_num_bits(rsa_key[i]->n));
1248 BN_print(bio_err,rsa_key[i]->e);
1249 BIO_printf(bio_err,"\n");
1255 #ifndef OPENSSL_NO_DSA
1256 dsa_key[0]=get_dsa512();
1257 dsa_key[1]=get_dsa1024();
1258 dsa_key[2]=get_dsa2048();
1261 #ifndef OPENSSL_NO_DES
1262 DES_set_key_unchecked(&key,&sch);
1263 DES_set_key_unchecked(&key2,&sch2);
1264 DES_set_key_unchecked(&key3,&sch3);
1266 #ifndef OPENSSL_NO_AES
1267 AES_set_encrypt_key(key16,128,&aes_ks1);
1268 AES_set_encrypt_key(key24,192,&aes_ks2);
1269 AES_set_encrypt_key(key32,256,&aes_ks3);
1271 #ifndef OPENSSL_NO_CAMELLIA
1272 Camellia_set_key(key16,128,&camellia_ks1);
1273 Camellia_set_key(ckey24,192,&camellia_ks2);
1274 Camellia_set_key(ckey32,256,&camellia_ks3);
1276 #ifndef OPENSSL_NO_IDEA
1277 idea_set_encrypt_key(key16,&idea_ks);
1279 #ifndef OPENSSL_NO_SEED
1280 SEED_set_key(key16,&seed_ks);
1282 #ifndef OPENSSL_NO_RC4
1283 RC4_set_key(&rc4_ks,16,key16);
1285 #ifndef OPENSSL_NO_RC2
1286 RC2_set_key(&rc2_ks,16,key16,128);
1288 #ifndef OPENSSL_NO_RC5
1289 RC5_32_set_key(&rc5_ks,16,key16,12);
1291 #ifndef OPENSSL_NO_BF
1292 BF_set_key(&bf_ks,16,key16);
1294 #ifndef OPENSSL_NO_CAST
1295 CAST_set_key(&cast_ks,16,key16);
1297 #ifndef OPENSSL_NO_RSA
1298 memset(rsa_c,0,sizeof(rsa_c));
1301 #ifndef OPENSSL_NO_DES
1302 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1308 for (it=count; it; it--)
1309 DES_ecb_encrypt((DES_cblock *)buf,
1315 c[D_MD2][0]=count/10;
1316 c[D_MDC2][0]=count/10;
1321 c[D_RMD160][0]=count;
1322 c[D_RC4][0]=count*5;
1323 c[D_CBC_DES][0]=count;
1324 c[D_EDE3_DES][0]=count/3;
1325 c[D_CBC_IDEA][0]=count;
1326 c[D_CBC_SEED][0]=count;
1327 c[D_CBC_RC2][0]=count;
1328 c[D_CBC_RC5][0]=count;
1329 c[D_CBC_BF][0]=count;
1330 c[D_CBC_CAST][0]=count;
1331 c[D_CBC_128_AES][0]=count;
1332 c[D_CBC_192_AES][0]=count;
1333 c[D_CBC_256_AES][0]=count;
1334 c[D_CBC_128_CML][0]=count;
1335 c[D_CBC_192_CML][0]=count;
1336 c[D_CBC_256_CML][0]=count;
1337 c[D_SHA256][0]=count;
1338 c[D_SHA512][0]=count;
1339 c[D_WHIRLPOOL][0]=count;
1340 c[D_IGE_128_AES][0]=count;
1341 c[D_IGE_192_AES][0]=count;
1342 c[D_IGE_256_AES][0]=count;
1343 c[D_GHASH][0]=count;
1345 for (i=1; i<SIZE_NUM; i++)
1349 l0=(long)lengths[0];
1350 l1=(long)lengths[i];
1352 c[D_MD2][i]=c[D_MD2][0]*4*l0/l1;
1353 c[D_MDC2][i]=c[D_MDC2][0]*4*l0/l1;
1354 c[D_MD4][i]=c[D_MD4][0]*4*l0/l1;
1355 c[D_MD5][i]=c[D_MD5][0]*4*l0/l1;
1356 c[D_HMAC][i]=c[D_HMAC][0]*4*l0/l1;
1357 c[D_SHA1][i]=c[D_SHA1][0]*4*l0/l1;
1358 c[D_RMD160][i]=c[D_RMD160][0]*4*l0/l1;
1359 c[D_SHA256][i]=c[D_SHA256][0]*4*l0/l1;
1360 c[D_SHA512][i]=c[D_SHA512][0]*4*l0/l1;
1361 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*l0/l1;
1363 l0=(long)lengths[i-1];
1365 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1366 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1367 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1368 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1369 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1370 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1371 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1372 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1373 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1374 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1375 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1376 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1377 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1378 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1379 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1380 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1381 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1382 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1386 #ifndef OPENSSL_NO_RSA
1387 rsa_c[R_RSA_512][0]=count/2000;
1388 rsa_c[R_RSA_512][1]=count/400;
1389 for (i=1; i<RSA_NUM; i++)
1391 rsa_c[i][0]=rsa_c[i-1][0]/8;
1392 rsa_c[i][1]=rsa_c[i-1][1]/4;
1393 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1397 if (rsa_c[i][0] == 0)
1406 #ifndef OPENSSL_NO_DSA
1407 dsa_c[R_DSA_512][0]=count/1000;
1408 dsa_c[R_DSA_512][1]=count/1000/2;
1409 for (i=1; i<DSA_NUM; i++)
1411 dsa_c[i][0]=dsa_c[i-1][0]/4;
1412 dsa_c[i][1]=dsa_c[i-1][1]/4;
1413 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1426 #ifndef OPENSSL_NO_ECDSA
1427 ecdsa_c[R_EC_P160][0]=count/1000;
1428 ecdsa_c[R_EC_P160][1]=count/1000/2;
1429 for (i=R_EC_P192; i<=R_EC_P521; 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)
1444 ecdsa_c[R_EC_K163][0]=count/1000;
1445 ecdsa_c[R_EC_K163][1]=count/1000/2;
1446 for (i=R_EC_K233; i<=R_EC_K571; i++)
1448 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1449 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1450 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1454 if (ecdsa_c[i] == 0)
1461 ecdsa_c[R_EC_B163][0]=count/1000;
1462 ecdsa_c[R_EC_B163][1]=count/1000/2;
1463 for (i=R_EC_B233; i<=R_EC_B571; i++)
1465 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1466 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1467 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1471 if (ecdsa_c[i] == 0)
1480 #ifndef OPENSSL_NO_ECDH
1481 ecdh_c[R_EC_P160][0]=count/1000;
1482 ecdh_c[R_EC_P160][1]=count/1000;
1483 for (i=R_EC_P192; i<=R_EC_P521; 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))
1498 ecdh_c[R_EC_K163][0]=count/1000;
1499 ecdh_c[R_EC_K163][1]=count/1000;
1500 for (i=R_EC_K233; i<=R_EC_K571; i++)
1502 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1503 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1504 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1515 ecdh_c[R_EC_B163][0]=count/1000;
1516 ecdh_c[R_EC_B163][1]=count/1000;
1517 for (i=R_EC_B233; i<=R_EC_B571; i++)
1519 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1520 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1521 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1534 #define COND(d) (count < (d))
1535 #define COUNT(d) (d)
1537 /* not worth fixing */
1538 # error "You cannot disable DES on systems without SIGALRM."
1539 #endif /* OPENSSL_NO_DES */
1541 #define COND(c) (run && count<0x7fffffff)
1542 #define COUNT(d) (count)
1544 signal(SIGALRM,sig_done);
1546 #endif /* SIGALRM */
1548 #ifndef OPENSSL_NO_MD2
1551 for (j=0; j<SIZE_NUM; j++)
1553 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1555 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1556 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1558 print_result(D_MD2,j,count,d);
1562 #ifndef OPENSSL_NO_MDC2
1565 for (j=0; j<SIZE_NUM; j++)
1567 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1569 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1570 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1572 print_result(D_MDC2,j,count,d);
1577 #ifndef OPENSSL_NO_MD4
1580 for (j=0; j<SIZE_NUM; j++)
1582 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1584 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1585 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1587 print_result(D_MD4,j,count,d);
1592 #ifndef OPENSSL_NO_MD5
1595 for (j=0; j<SIZE_NUM; j++)
1597 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1599 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1600 MD5(buf,lengths[j],md5);
1602 print_result(D_MD5,j,count,d);
1607 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1612 HMAC_CTX_init(&hctx);
1613 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1614 16,EVP_md5(), NULL);
1616 for (j=0; j<SIZE_NUM; j++)
1618 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1620 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1622 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1623 HMAC_Update(&hctx,buf,lengths[j]);
1624 HMAC_Final(&hctx,&(hmac[0]),NULL);
1627 print_result(D_HMAC,j,count,d);
1629 HMAC_CTX_cleanup(&hctx);
1632 #ifndef OPENSSL_NO_SHA
1635 for (j=0; j<SIZE_NUM; j++)
1637 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1639 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1641 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1643 SHA1(buf,lengths[j],sha);
1646 print_result(D_SHA1,j,count,d);
1650 #ifndef OPENSSL_NO_SHA256
1653 for (j=0; j<SIZE_NUM; j++)
1655 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1657 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1658 SHA256(buf,lengths[j],sha256);
1660 print_result(D_SHA256,j,count,d);
1665 #ifndef OPENSSL_NO_SHA512
1668 for (j=0; j<SIZE_NUM; j++)
1670 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1672 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1673 SHA512(buf,lengths[j],sha512);
1675 print_result(D_SHA512,j,count,d);
1681 #ifndef OPENSSL_NO_WHIRLPOOL
1682 if (doit[D_WHIRLPOOL])
1684 for (j=0; j<SIZE_NUM; j++)
1686 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1688 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1689 WHIRLPOOL(buf,lengths[j],whirlpool);
1691 print_result(D_WHIRLPOOL,j,count,d);
1696 #ifndef OPENSSL_NO_RIPEMD
1699 for (j=0; j<SIZE_NUM; j++)
1701 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1703 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1704 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1706 print_result(D_RMD160,j,count,d);
1710 #ifndef OPENSSL_NO_RC4
1713 for (j=0; j<SIZE_NUM; j++)
1715 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1717 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1718 RC4(&rc4_ks,(unsigned int)lengths[j],
1721 print_result(D_RC4,j,count,d);
1725 #ifndef OPENSSL_NO_DES
1726 if (doit[D_CBC_DES])
1728 for (j=0; j<SIZE_NUM; j++)
1730 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1732 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1733 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1734 &DES_iv,DES_ENCRYPT);
1736 print_result(D_CBC_DES,j,count,d);
1740 if (doit[D_EDE3_DES])
1742 for (j=0; j<SIZE_NUM; j++)
1744 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1746 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1747 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1749 &DES_iv,DES_ENCRYPT);
1751 print_result(D_EDE3_DES,j,count,d);
1755 #ifndef OPENSSL_NO_AES
1756 if (doit[D_CBC_128_AES])
1758 for (j=0; j<SIZE_NUM; j++)
1760 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1762 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1763 AES_cbc_encrypt(buf,buf,
1764 (unsigned long)lengths[j],&aes_ks1,
1767 print_result(D_CBC_128_AES,j,count,d);
1770 if (doit[D_CBC_192_AES])
1772 for (j=0; j<SIZE_NUM; j++)
1774 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1776 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1777 AES_cbc_encrypt(buf,buf,
1778 (unsigned long)lengths[j],&aes_ks2,
1781 print_result(D_CBC_192_AES,j,count,d);
1784 if (doit[D_CBC_256_AES])
1786 for (j=0; j<SIZE_NUM; j++)
1788 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1790 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1791 AES_cbc_encrypt(buf,buf,
1792 (unsigned long)lengths[j],&aes_ks3,
1795 print_result(D_CBC_256_AES,j,count,d);
1799 if (doit[D_IGE_128_AES])
1801 for (j=0; j<SIZE_NUM; j++)
1803 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1805 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1806 AES_ige_encrypt(buf,buf2,
1807 (unsigned long)lengths[j],&aes_ks1,
1810 print_result(D_IGE_128_AES,j,count,d);
1813 if (doit[D_IGE_192_AES])
1815 for (j=0; j<SIZE_NUM; j++)
1817 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1819 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1820 AES_ige_encrypt(buf,buf2,
1821 (unsigned long)lengths[j],&aes_ks2,
1824 print_result(D_IGE_192_AES,j,count,d);
1827 if (doit[D_IGE_256_AES])
1829 for (j=0; j<SIZE_NUM; j++)
1831 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1833 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1834 AES_ige_encrypt(buf,buf2,
1835 (unsigned long)lengths[j],&aes_ks3,
1838 print_result(D_IGE_256_AES,j,count,d);
1843 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1844 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1846 for (j=0; j<SIZE_NUM; j++)
1848 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1850 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1851 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1853 print_result(D_GHASH,j,count,d);
1855 CRYPTO_gcm128_release(ctx);
1859 #ifndef OPENSSL_NO_CAMELLIA
1860 if (doit[D_CBC_128_CML])
1862 for (j=0; j<SIZE_NUM; j++)
1864 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1866 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1867 Camellia_cbc_encrypt(buf,buf,
1868 (unsigned long)lengths[j],&camellia_ks1,
1869 iv,CAMELLIA_ENCRYPT);
1871 print_result(D_CBC_128_CML,j,count,d);
1874 if (doit[D_CBC_192_CML])
1876 for (j=0; j<SIZE_NUM; j++)
1878 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1880 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1881 Camellia_cbc_encrypt(buf,buf,
1882 (unsigned long)lengths[j],&camellia_ks2,
1883 iv,CAMELLIA_ENCRYPT);
1885 print_result(D_CBC_192_CML,j,count,d);
1888 if (doit[D_CBC_256_CML])
1890 for (j=0; j<SIZE_NUM; j++)
1892 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1894 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1895 Camellia_cbc_encrypt(buf,buf,
1896 (unsigned long)lengths[j],&camellia_ks3,
1897 iv,CAMELLIA_ENCRYPT);
1899 print_result(D_CBC_256_CML,j,count,d);
1904 #ifndef OPENSSL_NO_IDEA
1905 if (doit[D_CBC_IDEA])
1907 for (j=0; j<SIZE_NUM; j++)
1909 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1911 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1912 idea_cbc_encrypt(buf,buf,
1913 (unsigned long)lengths[j],&idea_ks,
1916 print_result(D_CBC_IDEA,j,count,d);
1920 #ifndef OPENSSL_NO_SEED
1921 if (doit[D_CBC_SEED])
1923 for (j=0; j<SIZE_NUM; j++)
1925 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1927 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1928 SEED_cbc_encrypt(buf,buf,
1929 (unsigned long)lengths[j],&seed_ks,iv,1);
1931 print_result(D_CBC_SEED,j,count,d);
1935 #ifndef OPENSSL_NO_RC2
1936 if (doit[D_CBC_RC2])
1938 for (j=0; j<SIZE_NUM; j++)
1940 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1942 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1943 RC2_cbc_encrypt(buf,buf,
1944 (unsigned long)lengths[j],&rc2_ks,
1947 print_result(D_CBC_RC2,j,count,d);
1951 #ifndef OPENSSL_NO_RC5
1952 if (doit[D_CBC_RC5])
1954 for (j=0; j<SIZE_NUM; j++)
1956 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1958 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1959 RC5_32_cbc_encrypt(buf,buf,
1960 (unsigned long)lengths[j],&rc5_ks,
1963 print_result(D_CBC_RC5,j,count,d);
1967 #ifndef OPENSSL_NO_BF
1970 for (j=0; j<SIZE_NUM; j++)
1972 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1974 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1975 BF_cbc_encrypt(buf,buf,
1976 (unsigned long)lengths[j],&bf_ks,
1979 print_result(D_CBC_BF,j,count,d);
1983 #ifndef OPENSSL_NO_CAST
1984 if (doit[D_CBC_CAST])
1986 for (j=0; j<SIZE_NUM; j++)
1988 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1990 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1991 CAST_cbc_encrypt(buf,buf,
1992 (unsigned long)lengths[j],&cast_ks,
1995 print_result(D_CBC_CAST,j,count,d);
2002 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2003 if (multiblock && evp_cipher)
2005 if (!(EVP_CIPHER_flags(evp_cipher)&EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK))
2007 fprintf(stderr,"%s is not multi-block capable\n",OBJ_nid2ln(evp_cipher->nid));
2010 multiblock_speed(evp_cipher);
2015 for (j=0; j<SIZE_NUM; j++)
2022 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2023 /* -O3 -fschedule-insns messes up an
2024 * optimization here! names[D_EVP]
2025 * somehow becomes NULL */
2026 print_message(names[D_EVP],save_count,
2029 EVP_CIPHER_CTX_init(&ctx);
2031 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2033 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2034 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2038 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2039 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2041 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2042 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2044 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2046 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2048 EVP_CIPHER_CTX_cleanup(&ctx);
2052 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2053 print_message(names[D_EVP],save_count,
2057 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2058 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2062 print_result(D_EVP,j,count,d);
2065 #ifndef OPENSSL_SYS_WIN32
2067 RAND_pseudo_bytes(buf,36);
2068 #ifndef OPENSSL_NO_RSA
2069 for (j=0; j<RSA_NUM; j++)
2072 if (!rsa_doit[j]) continue;
2073 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2076 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2077 ERR_print_errors(bio_err);
2082 pkey_print_message("private","rsa",
2083 rsa_c[j][0],rsa_bits[j],
2085 /* RSA_blinding_on(rsa_key[j],NULL); */
2087 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2089 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2090 &rsa_num, rsa_key[j]);
2094 "RSA sign failure\n");
2095 ERR_print_errors(bio_err);
2101 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2102 : "%ld %d bit private RSA's in %.2fs\n",
2103 count,rsa_bits[j],d);
2104 rsa_results[j][0]=d/(double)count;
2109 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2112 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2113 ERR_print_errors(bio_err);
2118 pkey_print_message("public","rsa",
2119 rsa_c[j][1],rsa_bits[j],
2122 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2124 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2125 rsa_num, rsa_key[j]);
2129 "RSA verify failure\n");
2130 ERR_print_errors(bio_err);
2136 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2137 : "%ld %d bit public RSA's in %.2fs\n",
2138 count,rsa_bits[j],d);
2139 rsa_results[j][1]=d/(double)count;
2145 /* if longer than 10s, don't do any more */
2146 for (j++; j<RSA_NUM; j++)
2152 RAND_pseudo_bytes(buf,20);
2153 #ifndef OPENSSL_NO_DSA
2154 if (RAND_status() != 1)
2156 RAND_seed(rnd_seed, sizeof rnd_seed);
2159 for (j=0; j<DSA_NUM; j++)
2164 if (!dsa_doit[j]) continue;
2165 /* DSA_generate_key(dsa_key[j]); */
2166 /* DSA_sign_setup(dsa_key[j],NULL); */
2167 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2171 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2172 ERR_print_errors(bio_err);
2177 pkey_print_message("sign","dsa",
2178 dsa_c[j][0],dsa_bits[j],
2181 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2183 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2188 "DSA sign failure\n");
2189 ERR_print_errors(bio_err);
2195 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2196 : "%ld %d bit DSA signs in %.2fs\n",
2197 count,dsa_bits[j],d);
2198 dsa_results[j][0]=d/(double)count;
2202 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2206 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2207 ERR_print_errors(bio_err);
2212 pkey_print_message("verify","dsa",
2213 dsa_c[j][1],dsa_bits[j],
2216 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2218 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2223 "DSA verify failure\n");
2224 ERR_print_errors(bio_err);
2230 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2231 : "%ld %d bit DSA verify in %.2fs\n",
2232 count,dsa_bits[j],d);
2233 dsa_results[j][1]=d/(double)count;
2238 /* if longer than 10s, don't do any more */
2239 for (j++; j<DSA_NUM; j++)
2243 if (rnd_fake) RAND_cleanup();
2246 #ifndef OPENSSL_NO_ECDSA
2247 if (RAND_status() != 1)
2249 RAND_seed(rnd_seed, sizeof rnd_seed);
2252 for (j=0; j<EC_NUM; j++)
2256 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2257 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2258 if (ecdsa[j] == NULL)
2260 BIO_printf(bio_err,"ECDSA failure.\n");
2261 ERR_print_errors(bio_err);
2267 EC_KEY_precompute_mult(ecdsa[j], NULL);
2269 /* Perform ECDSA signature test */
2270 EC_KEY_generate_key(ecdsa[j]);
2271 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2272 &ecdsasiglen, ecdsa[j]);
2275 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2276 ERR_print_errors(bio_err);
2281 pkey_print_message("sign","ecdsa",
2283 test_curves_bits[j],
2287 for (count=0,run=1; COND(ecdsa_c[j][0]);
2290 ret=ECDSA_sign(0, buf, 20,
2291 ecdsasig, &ecdsasiglen,
2295 BIO_printf(bio_err, "ECDSA sign failure\n");
2296 ERR_print_errors(bio_err);
2303 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2304 "%ld %d bit ECDSA signs in %.2fs \n",
2305 count, test_curves_bits[j], d);
2306 ecdsa_results[j][0]=d/(double)count;
2310 /* Perform ECDSA verification test */
2311 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2312 ecdsasiglen, ecdsa[j]);
2315 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2316 ERR_print_errors(bio_err);
2321 pkey_print_message("verify","ecdsa",
2323 test_curves_bits[j],
2326 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2328 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2331 BIO_printf(bio_err, "ECDSA verify failure\n");
2332 ERR_print_errors(bio_err);
2338 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2339 : "%ld %d bit ECDSA verify in %.2fs\n",
2340 count, test_curves_bits[j], d);
2341 ecdsa_results[j][1]=d/(double)count;
2346 /* if longer than 10s, don't do any more */
2347 for (j++; j<EC_NUM; j++)
2352 if (rnd_fake) RAND_cleanup();
2355 #ifndef OPENSSL_NO_ECDH
2356 if (RAND_status() != 1)
2358 RAND_seed(rnd_seed, sizeof rnd_seed);
2361 for (j=0; j<EC_NUM; j++)
2363 if (!ecdh_doit[j]) continue;
2364 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2365 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2366 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2368 BIO_printf(bio_err,"ECDH failure.\n");
2369 ERR_print_errors(bio_err);
2374 /* generate two ECDH key pairs */
2375 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2376 !EC_KEY_generate_key(ecdh_b[j]))
2378 BIO_printf(bio_err,"ECDH key generation failure.\n");
2379 ERR_print_errors(bio_err);
2384 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2385 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2387 int field_size, outlen;
2388 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2389 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2390 if (field_size <= 24 * 8)
2392 outlen = KDF1_SHA1_len;
2397 outlen = (field_size+7)/8;
2400 secret_size_a = ECDH_compute_key(secret_a, outlen,
2401 EC_KEY_get0_public_key(ecdh_b[j]),
2403 secret_size_b = ECDH_compute_key(secret_b, outlen,
2404 EC_KEY_get0_public_key(ecdh_a[j]),
2406 if (secret_size_a != secret_size_b)
2411 for (secret_idx = 0;
2412 (secret_idx < secret_size_a)
2413 && (ecdh_checks == 1);
2416 if (secret_a[secret_idx] != secret_b[secret_idx])
2420 if (ecdh_checks == 0)
2422 BIO_printf(bio_err,"ECDH computations don't match.\n");
2423 ERR_print_errors(bio_err);
2427 pkey_print_message("","ecdh",
2429 test_curves_bits[j],
2432 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2434 ECDH_compute_key(secret_a, outlen,
2435 EC_KEY_get0_public_key(ecdh_b[j]),
2439 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2440 count, test_curves_bits[j], d);
2441 ecdh_results[j][0]=d/(double)count;
2449 /* if longer than 10s, don't do any more */
2450 for (j++; j<EC_NUM; j++)
2454 if (rnd_fake) RAND_cleanup();
2461 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2462 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2464 printf("%s ",BN_options());
2465 #ifndef OPENSSL_NO_MD2
2466 printf("%s ",MD2_options());
2468 #ifndef OPENSSL_NO_RC4
2469 printf("%s ",RC4_options());
2471 #ifndef OPENSSL_NO_DES
2472 printf("%s ",DES_options());
2474 #ifndef OPENSSL_NO_AES
2475 printf("%s ",AES_options());
2477 #ifndef OPENSSL_NO_IDEA
2478 printf("%s ",idea_options());
2480 #ifndef OPENSSL_NO_BF
2481 printf("%s ",BF_options());
2483 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2489 fprintf(stdout,"+H");
2492 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2493 fprintf(stdout,"type ");
2495 for (j=0; j<SIZE_NUM; j++)
2496 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2497 fprintf(stdout,"\n");
2500 for (k=0; k<ALGOR_NUM; k++)
2502 if (!doit[k]) continue;
2504 fprintf(stdout,"+F:%d:%s",k,names[k]);
2506 fprintf(stdout,"%-13s",names[k]);
2507 for (j=0; j<SIZE_NUM; j++)
2509 if (results[k][j] > 10000 && !mr)
2510 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2512 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2514 fprintf(stdout,"\n");
2516 #ifndef OPENSSL_NO_RSA
2518 for (k=0; k<RSA_NUM; k++)
2520 if (!rsa_doit[k]) continue;
2523 printf("%18ssign verify sign/s verify/s\n"," ");
2527 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2528 k,rsa_bits[k],rsa_results[k][0],
2531 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2532 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2533 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2536 #ifndef OPENSSL_NO_DSA
2538 for (k=0; k<DSA_NUM; k++)
2540 if (!dsa_doit[k]) continue;
2543 printf("%18ssign verify sign/s verify/s\n"," ");
2547 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2548 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2550 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2551 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2552 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2555 #ifndef OPENSSL_NO_ECDSA
2557 for (k=0; k<EC_NUM; k++)
2559 if (!ecdsa_doit[k]) continue;
2562 printf("%30ssign verify sign/s verify/s\n"," ");
2567 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2568 k, test_curves_bits[k],
2569 ecdsa_results[k][0],ecdsa_results[k][1]);
2572 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2573 test_curves_bits[k],
2574 test_curves_names[k],
2575 ecdsa_results[k][0],ecdsa_results[k][1],
2576 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2581 #ifndef OPENSSL_NO_ECDH
2583 for (k=0; k<EC_NUM; k++)
2585 if (!ecdh_doit[k]) continue;
2588 printf("%30sop op/s\n"," ");
2592 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2593 k, test_curves_bits[k],
2594 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2597 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2598 test_curves_bits[k],
2599 test_curves_names[k],
2600 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2607 ERR_print_errors(bio_err);
2608 if (buf_malloc != NULL) OPENSSL_free(buf_malloc);
2609 if (buf2_malloc != NULL) OPENSSL_free(buf2_malloc);
2610 #ifndef OPENSSL_NO_RSA
2611 for (i=0; i<RSA_NUM; i++)
2612 if (rsa_key[i] != NULL)
2613 RSA_free(rsa_key[i]);
2615 #ifndef OPENSSL_NO_DSA
2616 for (i=0; i<DSA_NUM; i++)
2617 if (dsa_key[i] != NULL)
2618 DSA_free(dsa_key[i]);
2621 #ifndef OPENSSL_NO_ECDSA
2622 for (i=0; i<EC_NUM; i++)
2623 if (ecdsa[i] != NULL)
2624 EC_KEY_free(ecdsa[i]);
2626 #ifndef OPENSSL_NO_ECDH
2627 for (i=0; i<EC_NUM; i++)
2629 if (ecdh_a[i] != NULL)
2630 EC_KEY_free(ecdh_a[i]);
2631 if (ecdh_b[i] != NULL)
2632 EC_KEY_free(ecdh_b[i]);
2640 static void print_message(const char *s, long num, int length)
2643 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2644 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2645 (void)BIO_flush(bio_err);
2648 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2649 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2650 (void)BIO_flush(bio_err);
2657 static void pkey_print_message(const char *str, const char *str2, long num,
2661 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2662 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2663 (void)BIO_flush(bio_err);
2666 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2667 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2668 (void)BIO_flush(bio_err);
2675 static void print_result(int alg,int run_no,int count,double time_used)
2677 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2678 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2679 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2683 static char *sstrsep(char **string, const char *delim)
2686 char *token = *string;
2691 memset(isdelim, 0, sizeof isdelim);
2696 isdelim[(unsigned char)(*delim)] = 1;
2700 while (!isdelim[(unsigned char)(**string)])
2714 static int do_multi(int multi)
2719 static char sep[]=":";
2721 fds=malloc(multi*sizeof *fds);
2722 for(n=0 ; n < multi ; ++n)
2726 fprintf(stderr, "pipe failure\n");
2740 if (dup(fd[1]) == -1)
2742 fprintf(stderr, "dup failed\n");
2751 printf("Forked child %d\n",n);
2754 /* for now, assume the pipe is long enough to take all the output */
2755 for(n=0 ; n < multi ; ++n)
2761 f=fdopen(fds[n],"r");
2762 while(fgets(buf,sizeof buf,f))
2769 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2773 printf("Got: %s from %d\n",buf,n);
2774 if(!strncmp(buf,"+F:",3))
2780 alg=atoi(sstrsep(&p,sep));
2782 for(j=0 ; j < SIZE_NUM ; ++j)
2783 results[alg][j]+=atof(sstrsep(&p,sep));
2785 else if(!strncmp(buf,"+F2:",4))
2791 k=atoi(sstrsep(&p,sep));
2794 d=atof(sstrsep(&p,sep));
2796 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2798 rsa_results[k][0]=d;
2800 d=atof(sstrsep(&p,sep));
2802 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2804 rsa_results[k][1]=d;
2806 else if(!strncmp(buf,"+F2:",4))
2812 k=atoi(sstrsep(&p,sep));
2815 d=atof(sstrsep(&p,sep));
2817 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2819 rsa_results[k][0]=d;
2821 d=atof(sstrsep(&p,sep));
2823 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2825 rsa_results[k][1]=d;
2827 #ifndef OPENSSL_NO_DSA
2828 else if(!strncmp(buf,"+F3:",4))
2834 k=atoi(sstrsep(&p,sep));
2837 d=atof(sstrsep(&p,sep));
2839 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2841 dsa_results[k][0]=d;
2843 d=atof(sstrsep(&p,sep));
2845 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2847 dsa_results[k][1]=d;
2850 #ifndef OPENSSL_NO_ECDSA
2851 else if(!strncmp(buf,"+F4:",4))
2857 k=atoi(sstrsep(&p,sep));
2860 d=atof(sstrsep(&p,sep));
2862 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2864 ecdsa_results[k][0]=d;
2866 d=atof(sstrsep(&p,sep));
2868 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2870 ecdsa_results[k][1]=d;
2874 #ifndef OPENSSL_NO_ECDH
2875 else if(!strncmp(buf,"+F5:",4))
2881 k=atoi(sstrsep(&p,sep));
2884 d=atof(sstrsep(&p,sep));
2886 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2888 ecdh_results[k][0]=d;
2893 else if(!strncmp(buf,"+H:",3))
2897 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2907 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2909 static int mblengths[]={8*1024,2*8*1024,4*8*1024,8*8*1024,8*16*1024};
2910 int j,count,num=sizeof(lengths)/sizeof(lengths[0]);
2911 const char *alg_name;
2912 unsigned char *inp,*out,no_key[32],no_iv[16];
2916 inp = OPENSSL_malloc(mblengths[num-1]);
2917 out = OPENSSL_malloc(mblengths[num-1]+1024);
2919 EVP_CIPHER_CTX_init(&ctx);
2920 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,no_key,no_iv);
2921 EVP_CIPHER_CTX_ctrl(&ctx,EVP_CTRL_AEAD_SET_MAC_KEY,sizeof(no_key),no_key);
2922 alg_name=OBJ_nid2ln(evp_cipher->nid);
2924 for (j=0; j<num; j++)
2926 print_message(alg_name,0,mblengths[j]);
2928 for (count=0,run=1; run && count<0x7fffffff; count++)
2930 unsigned char aad[13];
2931 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2932 size_t len = mblengths[j];
2935 memset(aad,0,8);/* avoid uninitialized values */
2936 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2937 aad[9] = 3; /* version */
2939 aad[11] = 0; /* length */
2941 mb_param.out = NULL;
2944 mb_param.interleave = 8;
2946 packlen=EVP_CIPHER_CTX_ctrl(&ctx,
2947 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2948 sizeof(mb_param),&mb_param);
2955 EVP_CIPHER_CTX_ctrl(&ctx,
2956 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2957 sizeof(mb_param),&mb_param);
2967 pad=EVP_CIPHER_CTX_ctrl(&ctx,
2968 EVP_CTRL_AEAD_TLS1_AAD,13,aad);
2969 EVP_Cipher(&ctx,out,inp,len+pad);
2973 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2974 : "%d %s's in %.2fs\n",count,"evp",d);
2975 results[D_EVP][j]=((double)count)/d*mblengths[j];
2980 fprintf(stdout,"+H");
2981 for (j=0; j<num; j++)
2982 fprintf(stdout,":%d",mblengths[j]);
2983 fprintf(stdout,"\n");
2984 fprintf(stdout,"+F:%d:%s",D_EVP,alg_name);
2985 for (j=0; j<num; j++)
2986 fprintf(stdout,":%.2f",results[D_EVP][j]);
2987 fprintf(stdout,"\n");
2991 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2992 fprintf(stdout,"type ");
2993 for (j=0; j<num; j++)
2994 fprintf(stdout,"%7d bytes",mblengths[j]);
2995 fprintf(stdout,"\n");
2996 fprintf(stdout,"%-24s",alg_name);
2998 for (j=0; j<num; j++)
3000 if (results[D_EVP][j] > 10000)
3001 fprintf(stdout," %11.2fk",results[D_EVP][j]/1e3);
3003 fprintf(stdout," %11.2f ",results[D_EVP][j]);
3005 fprintf(stdout,"\n");