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);
283 #if !defined(SIGALRM)
286 static unsigned int lapse,schlock;
287 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
288 #define alarm alarm_win32
290 static DWORD WINAPI sleepy(VOID *arg)
298 static double Time_F(int s)
306 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
309 DWORD ret=GetLastError();
310 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
313 while (!schlock) Sleep(0); /* scheduler spinlock */
314 ret = app_tminterval(s,usertime);
318 ret = app_tminterval(s,usertime);
319 if (run) TerminateThread(thr,0);
327 static double Time_F(int s)
329 double ret = app_tminterval(s,usertime);
330 if (s == STOP) alarm(0);
336 #ifndef OPENSSL_NO_ECDH
337 static const int KDF1_SHA1_len = 20;
338 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
340 #ifndef OPENSSL_NO_SHA
341 if (*outlen < SHA_DIGEST_LENGTH)
344 *outlen = SHA_DIGEST_LENGTH;
345 return SHA1(in, inlen, out);
348 #endif /* OPENSSL_NO_SHA */
350 #endif /* OPENSSL_NO_ECDH */
352 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
354 int MAIN(int, char **);
356 int MAIN(int argc, char **argv)
358 unsigned char *buf_malloc=NULL, *buf2_malloc=NULL;
359 unsigned char *buf=NULL,*buf2=NULL;
361 long count=0,save_count=0;
363 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
366 #ifndef OPENSSL_NO_RSA
369 unsigned char md[EVP_MAX_MD_SIZE];
370 #ifndef OPENSSL_NO_MD2
371 unsigned char md2[MD2_DIGEST_LENGTH];
373 #ifndef OPENSSL_NO_MDC2
374 unsigned char mdc2[MDC2_DIGEST_LENGTH];
376 #ifndef OPENSSL_NO_MD4
377 unsigned char md4[MD4_DIGEST_LENGTH];
379 #ifndef OPENSSL_NO_MD5
380 unsigned char md5[MD5_DIGEST_LENGTH];
381 unsigned char hmac[MD5_DIGEST_LENGTH];
383 #ifndef OPENSSL_NO_SHA
384 unsigned char sha[SHA_DIGEST_LENGTH];
385 #ifndef OPENSSL_NO_SHA256
386 unsigned char sha256[SHA256_DIGEST_LENGTH];
388 #ifndef OPENSSL_NO_SHA512
389 unsigned char sha512[SHA512_DIGEST_LENGTH];
392 #ifndef OPENSSL_NO_WHIRLPOOL
393 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
395 #ifndef OPENSSL_NO_RIPEMD
396 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
398 #ifndef OPENSSL_NO_RC4
401 #ifndef OPENSSL_NO_RC5
404 #ifndef OPENSSL_NO_RC2
407 #ifndef OPENSSL_NO_IDEA
408 IDEA_KEY_SCHEDULE idea_ks;
410 #ifndef OPENSSL_NO_SEED
411 SEED_KEY_SCHEDULE seed_ks;
413 #ifndef OPENSSL_NO_BF
416 #ifndef OPENSSL_NO_CAST
419 static const unsigned char key16[16]=
420 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
421 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
422 #ifndef OPENSSL_NO_AES
423 static const unsigned char key24[24]=
424 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
425 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
426 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
427 static const unsigned char key32[32]=
428 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
429 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
430 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
431 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
433 #ifndef OPENSSL_NO_CAMELLIA
434 static const unsigned char ckey24[24]=
435 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
436 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
437 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
438 static const unsigned char ckey32[32]=
439 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
440 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
441 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
442 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
444 #ifndef OPENSSL_NO_AES
445 #define MAX_BLOCK_SIZE 128
447 #define MAX_BLOCK_SIZE 64
449 unsigned char DES_iv[8];
450 unsigned char iv[2*MAX_BLOCK_SIZE/8];
451 #ifndef OPENSSL_NO_DES
452 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
453 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
454 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
455 DES_key_schedule sch;
456 DES_key_schedule sch2;
457 DES_key_schedule sch3;
459 #ifndef OPENSSL_NO_AES
460 AES_KEY aes_ks1, aes_ks2, aes_ks3;
462 #ifndef OPENSSL_NO_CAMELLIA
463 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
475 #define D_CBC_IDEA 10
476 #define D_CBC_SEED 11
480 #define D_CBC_CAST 15
481 #define D_CBC_128_AES 16
482 #define D_CBC_192_AES 17
483 #define D_CBC_256_AES 18
484 #define D_CBC_128_CML 19
485 #define D_CBC_192_CML 20
486 #define D_CBC_256_CML 21
490 #define D_WHIRLPOOL 25
491 #define D_IGE_128_AES 26
492 #define D_IGE_192_AES 27
493 #define D_IGE_256_AES 28
496 long c[ALGOR_NUM][SIZE_NUM];
498 #ifndef OPENSSL_SYS_WIN32
509 #define R_RSA_15360 6
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,3072,4096,7680,15360};
532 static unsigned char *rsa_data[RSA_NUM]=
533 {test512,test1024,test2048,test3072,test4096,test7680,test15360};
534 static int rsa_data_length[RSA_NUM]={
535 sizeof(test512),sizeof(test1024),
536 sizeof(test2048),sizeof(test3072),
537 sizeof(test4096),sizeof(test7680),
540 #ifndef OPENSSL_NO_DSA
541 DSA *dsa_key[DSA_NUM];
542 long dsa_c[DSA_NUM][2];
543 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
545 #ifndef OPENSSL_NO_EC
546 /* We only test over the following curves as they are representative,
547 * To add tests over more curves, simply add the curve NID
548 * and curve name to the following arrays and increase the
549 * EC_NUM value accordingly.
551 static unsigned int test_curves[EC_NUM] =
555 NID_X9_62_prime192v1,
557 NID_X9_62_prime256v1,
572 static const char * test_curves_names[EC_NUM] =
593 static int test_curves_bits[EC_NUM] =
595 160, 192, 224, 256, 384, 521,
596 163, 233, 283, 409, 571,
597 163, 233, 283, 409, 571
602 #ifndef OPENSSL_NO_ECDSA
603 unsigned char ecdsasig[256];
604 unsigned int ecdsasiglen;
605 EC_KEY *ecdsa[EC_NUM];
606 long ecdsa_c[EC_NUM][2];
609 #ifndef OPENSSL_NO_ECDH
610 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
611 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
612 int secret_size_a, secret_size_b;
615 long ecdh_c[EC_NUM][2];
618 int rsa_doit[RSA_NUM];
619 int dsa_doit[DSA_NUM];
620 #ifndef OPENSSL_NO_ECDSA
621 int ecdsa_doit[EC_NUM];
623 #ifndef OPENSSL_NO_ECDH
624 int ecdh_doit[EC_NUM];
628 const EVP_CIPHER *evp_cipher=NULL;
629 const EVP_MD *evp_md=NULL;
635 int misalign=MAX_MISALIGNMENT+1;
642 memset(results, 0, sizeof(results));
643 #ifndef OPENSSL_NO_DSA
644 memset(dsa_key,0,sizeof(dsa_key));
646 #ifndef OPENSSL_NO_ECDSA
647 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
649 #ifndef OPENSSL_NO_ECDH
650 for (i=0; i<EC_NUM; i++)
659 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
660 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
662 if (!load_config(bio_err, NULL))
665 #ifndef OPENSSL_NO_RSA
666 memset(rsa_key,0,sizeof(rsa_key));
667 for (i=0; i<RSA_NUM; i++)
671 if ((buf_malloc=(unsigned char *)OPENSSL_malloc(BUFSIZE+misalign)) == NULL)
673 BIO_printf(bio_err,"out of memory\n");
676 if ((buf2_malloc=(unsigned char *)OPENSSL_malloc(BUFSIZE+misalign)) == NULL)
678 BIO_printf(bio_err,"out of memory\n");
682 misalign = 0; /* set later and buf/buf2 are adjusted accordingly */
686 memset(c,0,sizeof(c));
687 memset(DES_iv,0,sizeof(DES_iv));
688 memset(iv,0,sizeof(iv));
690 for (i=0; i<ALGOR_NUM; i++)
692 for (i=0; i<RSA_NUM; i++)
694 for (i=0; i<DSA_NUM; i++)
696 #ifndef OPENSSL_NO_ECDSA
697 for (i=0; i<EC_NUM; i++)
700 #ifndef OPENSSL_NO_ECDH
701 for (i=0; i<EC_NUM; i++)
710 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
713 j--; /* Otherwise, -elapsed gets confused with
716 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
722 BIO_printf(bio_err,"no EVP given\n");
725 evp_cipher=EVP_get_cipherbyname(*argv);
728 evp_md=EVP_get_digestbyname(*argv);
730 if(!evp_cipher && !evp_md)
732 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
737 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
740 j--; /* Otherwise, -elapsed gets confused with
743 #ifndef OPENSSL_NO_ENGINE
744 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
750 BIO_printf(bio_err,"no engine given\n");
753 setup_engine(bio_err, *argv, 0);
754 /* j will be increased again further down. We just
755 don't want speed to confuse an engine with an
756 algorithm, especially when none is given (which
757 means all of them should be run) */
762 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
768 BIO_printf(bio_err,"no multi count given\n");
774 BIO_printf(bio_err,"bad multi count\n");
777 j--; /* Otherwise, -mr gets confused with
781 else if (argc > 0 && !strcmp(*argv,"-mr"))
784 j--; /* Otherwise, -mr gets confused with
787 else if (argc > 0 && !strcmp(*argv,"-mb"))
792 else if (argc > 0 && !strcmp(*argv,"-misalign"))
798 BIO_printf(bio_err,"no misalignment given\n");
801 misalign=atoi(argv[0]);
802 if (misalign<0 || misalign>MAX_MISALIGNMENT)
804 BIO_printf(bio_err,"misalignment is outsize permitted range 0-%d\n",MAX_MISALIGNMENT);
807 buf=buf_malloc+misalign;
808 buf2=buf2_malloc+misalign;
812 #ifndef OPENSSL_NO_MD2
813 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
816 #ifndef OPENSSL_NO_MDC2
817 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
820 #ifndef OPENSSL_NO_MD4
821 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
824 #ifndef OPENSSL_NO_MD5
825 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
828 #ifndef OPENSSL_NO_MD5
829 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
832 #ifndef OPENSSL_NO_SHA
833 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
835 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
839 #ifndef OPENSSL_NO_SHA256
840 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
843 #ifndef OPENSSL_NO_SHA512
844 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
848 #ifndef OPENSSL_NO_WHIRLPOOL
849 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
852 #ifndef OPENSSL_NO_RIPEMD
853 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
855 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
857 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
860 #ifndef OPENSSL_NO_RC4
861 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
864 #ifndef OPENSSL_NO_DES
865 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
866 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
869 #ifndef OPENSSL_NO_AES
870 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
871 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
872 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
873 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
874 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
875 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
878 #ifndef OPENSSL_NO_CAMELLIA
879 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
880 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
881 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
884 #ifndef OPENSSL_NO_RSA
885 #if 0 /* was: #ifdef RSAref */
886 if (strcmp(*argv,"rsaref") == 0)
888 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
894 if (strcmp(*argv,"openssl") == 0)
896 RSA_set_default_method(RSA_PKCS1_SSLeay());
901 #endif /* !OPENSSL_NO_RSA */
902 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
903 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
904 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
905 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
906 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
907 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
908 else if (strcmp(*argv,"rsa3072") == 0) rsa_doit[R_RSA_3072]=2;
909 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
910 else if (strcmp(*argv,"rsa7680") == 0) rsa_doit[R_RSA_7680]=2;
911 else if (strcmp(*argv,"rsa15360") == 0) rsa_doit[R_RSA_15360]=2;
913 #ifndef OPENSSL_NO_RC2
914 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
915 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
918 #ifndef OPENSSL_NO_RC5
919 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
920 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
923 #ifndef OPENSSL_NO_IDEA
924 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
925 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
928 #ifndef OPENSSL_NO_SEED
929 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
930 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
933 #ifndef OPENSSL_NO_BF
934 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
935 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
936 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
939 #ifndef OPENSSL_NO_CAST
940 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
941 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
942 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
945 #ifndef OPENSSL_NO_DES
946 if (strcmp(*argv,"des") == 0)
953 #ifndef OPENSSL_NO_AES
954 if (strcmp(*argv,"aes") == 0)
956 doit[D_CBC_128_AES]=1;
957 doit[D_CBC_192_AES]=1;
958 doit[D_CBC_256_AES]=1;
960 else if (strcmp(*argv,"ghash") == 0)
966 #ifndef OPENSSL_NO_CAMELLIA
967 if (strcmp(*argv,"camellia") == 0)
969 doit[D_CBC_128_CML]=1;
970 doit[D_CBC_192_CML]=1;
971 doit[D_CBC_256_CML]=1;
975 #ifndef OPENSSL_NO_RSA
976 if (strcmp(*argv,"rsa") == 0)
978 rsa_doit[R_RSA_512]=1;
979 rsa_doit[R_RSA_1024]=1;
980 rsa_doit[R_RSA_2048]=1;
981 rsa_doit[R_RSA_3072]=1;
982 rsa_doit[R_RSA_4096]=1;
983 rsa_doit[R_RSA_7680]=1;
984 rsa_doit[R_RSA_15360]=1;
988 #ifndef OPENSSL_NO_DSA
989 if (strcmp(*argv,"dsa") == 0)
991 dsa_doit[R_DSA_512]=1;
992 dsa_doit[R_DSA_1024]=1;
993 dsa_doit[R_DSA_2048]=1;
997 #ifndef OPENSSL_NO_ECDSA
998 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
999 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
1000 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
1001 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
1002 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
1003 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
1004 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
1005 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
1006 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
1007 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
1008 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
1009 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
1010 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
1011 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
1012 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
1013 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
1014 else if (strcmp(*argv,"ecdsa") == 0)
1016 for (i=0; i < EC_NUM; i++)
1021 #ifndef OPENSSL_NO_ECDH
1022 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1023 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1024 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1025 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1026 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1027 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1028 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1029 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1030 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1031 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1032 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1033 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1034 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1035 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1036 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1037 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1038 else if (strcmp(*argv,"ecdh") == 0)
1040 for (i=0; i < EC_NUM; i++)
1046 BIO_printf(bio_err,"Error: bad option or value\n");
1047 BIO_printf(bio_err,"\n");
1048 BIO_printf(bio_err,"Available values:\n");
1049 #ifndef OPENSSL_NO_MD2
1050 BIO_printf(bio_err,"md2 ");
1052 #ifndef OPENSSL_NO_MDC2
1053 BIO_printf(bio_err,"mdc2 ");
1055 #ifndef OPENSSL_NO_MD4
1056 BIO_printf(bio_err,"md4 ");
1058 #ifndef OPENSSL_NO_MD5
1059 BIO_printf(bio_err,"md5 ");
1060 #ifndef OPENSSL_NO_HMAC
1061 BIO_printf(bio_err,"hmac ");
1064 #ifndef OPENSSL_NO_SHA1
1065 BIO_printf(bio_err,"sha1 ");
1067 #ifndef OPENSSL_NO_SHA256
1068 BIO_printf(bio_err,"sha256 ");
1070 #ifndef OPENSSL_NO_SHA512
1071 BIO_printf(bio_err,"sha512 ");
1073 #ifndef OPENSSL_NO_WHIRLPOOL
1074 BIO_printf(bio_err,"whirlpool");
1076 #ifndef OPENSSL_NO_RIPEMD160
1077 BIO_printf(bio_err,"rmd160");
1079 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1080 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1081 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1082 !defined(OPENSSL_NO_WHIRLPOOL)
1083 BIO_printf(bio_err,"\n");
1086 #ifndef OPENSSL_NO_IDEA
1087 BIO_printf(bio_err,"idea-cbc ");
1089 #ifndef OPENSSL_NO_SEED
1090 BIO_printf(bio_err,"seed-cbc ");
1092 #ifndef OPENSSL_NO_RC2
1093 BIO_printf(bio_err,"rc2-cbc ");
1095 #ifndef OPENSSL_NO_RC5
1096 BIO_printf(bio_err,"rc5-cbc ");
1098 #ifndef OPENSSL_NO_BF
1099 BIO_printf(bio_err,"bf-cbc");
1101 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1102 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1103 BIO_printf(bio_err,"\n");
1105 #ifndef OPENSSL_NO_DES
1106 BIO_printf(bio_err,"des-cbc des-ede3 ");
1108 #ifndef OPENSSL_NO_AES
1109 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1110 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1112 #ifndef OPENSSL_NO_CAMELLIA
1113 BIO_printf(bio_err,"\n");
1114 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1116 #ifndef OPENSSL_NO_RC4
1117 BIO_printf(bio_err,"rc4");
1119 BIO_printf(bio_err,"\n");
1121 #ifndef OPENSSL_NO_RSA
1122 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1123 BIO_printf(bio_err,"rsa7680 rsa15360\n");
1126 #ifndef OPENSSL_NO_DSA
1127 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1129 #ifndef OPENSSL_NO_ECDSA
1130 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1131 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1132 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1133 BIO_printf(bio_err,"ecdsa\n");
1135 #ifndef OPENSSL_NO_ECDH
1136 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1137 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1138 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1139 BIO_printf(bio_err,"ecdh\n");
1142 #ifndef OPENSSL_NO_IDEA
1143 BIO_printf(bio_err,"idea ");
1145 #ifndef OPENSSL_NO_SEED
1146 BIO_printf(bio_err,"seed ");
1148 #ifndef OPENSSL_NO_RC2
1149 BIO_printf(bio_err,"rc2 ");
1151 #ifndef OPENSSL_NO_DES
1152 BIO_printf(bio_err,"des ");
1154 #ifndef OPENSSL_NO_AES
1155 BIO_printf(bio_err,"aes ");
1157 #ifndef OPENSSL_NO_CAMELLIA
1158 BIO_printf(bio_err,"camellia ");
1160 #ifndef OPENSSL_NO_RSA
1161 BIO_printf(bio_err,"rsa ");
1163 #ifndef OPENSSL_NO_BF
1164 BIO_printf(bio_err,"blowfish");
1166 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1167 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1168 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1169 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1170 BIO_printf(bio_err,"\n");
1173 BIO_printf(bio_err,"\n");
1174 BIO_printf(bio_err,"Available options:\n");
1175 #if defined(TIMES) || defined(USE_TOD)
1176 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1178 #ifndef OPENSSL_NO_ENGINE
1179 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1181 BIO_printf(bio_err,"-evp e use EVP e.\n");
1182 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1183 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1184 BIO_printf(bio_err,"-mb perform multi-block benchmark (for specific ciphers)\n");
1185 BIO_printf(bio_err,"-misalign n perform benchmark with misaligned data\n");
1187 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1197 if(multi && do_multi(multi))
1203 for (i=0; i<ALGOR_NUM; i++)
1208 for (i=0; i<RSA_NUM; i++)
1210 for (i=0; i<DSA_NUM; i++)
1212 #ifndef OPENSSL_NO_ECDSA
1213 for (i=0; i<EC_NUM; i++)
1216 #ifndef OPENSSL_NO_ECDH
1217 for (i=0; i<EC_NUM; i++)
1221 for (i=0; i<ALGOR_NUM; i++)
1222 if (doit[i]) pr_header++;
1224 if (usertime == 0 && !mr)
1225 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1227 #ifndef OPENSSL_NO_RSA
1228 for (i=0; i<RSA_NUM; i++)
1230 const unsigned char *p;
1233 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1234 if (rsa_key[i] == NULL)
1236 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1242 BIO_printf(bio_err,mr ? "+RK:%d:"
1243 : "Loaded RSA key, %d bit modulus and e= 0x",
1244 BN_num_bits(rsa_key[i]->n));
1245 BN_print(bio_err,rsa_key[i]->e);
1246 BIO_printf(bio_err,"\n");
1252 #ifndef OPENSSL_NO_DSA
1253 dsa_key[0]=get_dsa512();
1254 dsa_key[1]=get_dsa1024();
1255 dsa_key[2]=get_dsa2048();
1258 #ifndef OPENSSL_NO_DES
1259 DES_set_key_unchecked(&key,&sch);
1260 DES_set_key_unchecked(&key2,&sch2);
1261 DES_set_key_unchecked(&key3,&sch3);
1263 #ifndef OPENSSL_NO_AES
1264 AES_set_encrypt_key(key16,128,&aes_ks1);
1265 AES_set_encrypt_key(key24,192,&aes_ks2);
1266 AES_set_encrypt_key(key32,256,&aes_ks3);
1268 #ifndef OPENSSL_NO_CAMELLIA
1269 Camellia_set_key(key16,128,&camellia_ks1);
1270 Camellia_set_key(ckey24,192,&camellia_ks2);
1271 Camellia_set_key(ckey32,256,&camellia_ks3);
1273 #ifndef OPENSSL_NO_IDEA
1274 idea_set_encrypt_key(key16,&idea_ks);
1276 #ifndef OPENSSL_NO_SEED
1277 SEED_set_key(key16,&seed_ks);
1279 #ifndef OPENSSL_NO_RC4
1280 RC4_set_key(&rc4_ks,16,key16);
1282 #ifndef OPENSSL_NO_RC2
1283 RC2_set_key(&rc2_ks,16,key16,128);
1285 #ifndef OPENSSL_NO_RC5
1286 RC5_32_set_key(&rc5_ks,16,key16,12);
1288 #ifndef OPENSSL_NO_BF
1289 BF_set_key(&bf_ks,16,key16);
1291 #ifndef OPENSSL_NO_CAST
1292 CAST_set_key(&cast_ks,16,key16);
1294 #ifndef OPENSSL_NO_RSA
1295 memset(rsa_c,0,sizeof(rsa_c));
1298 #ifndef OPENSSL_NO_DES
1299 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1305 for (it=count; it; it--)
1306 DES_ecb_encrypt((DES_cblock *)buf,
1312 c[D_MD2][0]=count/10;
1313 c[D_MDC2][0]=count/10;
1318 c[D_RMD160][0]=count;
1319 c[D_RC4][0]=count*5;
1320 c[D_CBC_DES][0]=count;
1321 c[D_EDE3_DES][0]=count/3;
1322 c[D_CBC_IDEA][0]=count;
1323 c[D_CBC_SEED][0]=count;
1324 c[D_CBC_RC2][0]=count;
1325 c[D_CBC_RC5][0]=count;
1326 c[D_CBC_BF][0]=count;
1327 c[D_CBC_CAST][0]=count;
1328 c[D_CBC_128_AES][0]=count;
1329 c[D_CBC_192_AES][0]=count;
1330 c[D_CBC_256_AES][0]=count;
1331 c[D_CBC_128_CML][0]=count;
1332 c[D_CBC_192_CML][0]=count;
1333 c[D_CBC_256_CML][0]=count;
1334 c[D_SHA256][0]=count;
1335 c[D_SHA512][0]=count;
1336 c[D_WHIRLPOOL][0]=count;
1337 c[D_IGE_128_AES][0]=count;
1338 c[D_IGE_192_AES][0]=count;
1339 c[D_IGE_256_AES][0]=count;
1340 c[D_GHASH][0]=count;
1342 for (i=1; i<SIZE_NUM; i++)
1346 l0=(long)lengths[0];
1347 l1=(long)lengths[i];
1349 c[D_MD2][i]=c[D_MD2][0]*4*l0/l1;
1350 c[D_MDC2][i]=c[D_MDC2][0]*4*l0/l1;
1351 c[D_MD4][i]=c[D_MD4][0]*4*l0/l1;
1352 c[D_MD5][i]=c[D_MD5][0]*4*l0/l1;
1353 c[D_HMAC][i]=c[D_HMAC][0]*4*l0/l1;
1354 c[D_SHA1][i]=c[D_SHA1][0]*4*l0/l1;
1355 c[D_RMD160][i]=c[D_RMD160][0]*4*l0/l1;
1356 c[D_SHA256][i]=c[D_SHA256][0]*4*l0/l1;
1357 c[D_SHA512][i]=c[D_SHA512][0]*4*l0/l1;
1358 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*l0/l1;
1360 l0=(long)lengths[i-1];
1362 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1363 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1364 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1365 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1366 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1367 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1368 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1369 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1370 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1371 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1372 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1373 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1374 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1375 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1376 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1377 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1378 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1379 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1383 #ifndef OPENSSL_NO_RSA
1384 rsa_c[R_RSA_512][0]=count/2000;
1385 rsa_c[R_RSA_512][1]=count/400;
1386 for (i=1; i<RSA_NUM; i++)
1388 rsa_c[i][0]=rsa_c[i-1][0]/8;
1389 rsa_c[i][1]=rsa_c[i-1][1]/4;
1390 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1394 if (rsa_c[i][0] == 0)
1403 #ifndef OPENSSL_NO_DSA
1404 dsa_c[R_DSA_512][0]=count/1000;
1405 dsa_c[R_DSA_512][1]=count/1000/2;
1406 for (i=1; i<DSA_NUM; i++)
1408 dsa_c[i][0]=dsa_c[i-1][0]/4;
1409 dsa_c[i][1]=dsa_c[i-1][1]/4;
1410 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1423 #ifndef OPENSSL_NO_ECDSA
1424 ecdsa_c[R_EC_P160][0]=count/1000;
1425 ecdsa_c[R_EC_P160][1]=count/1000/2;
1426 for (i=R_EC_P192; i<=R_EC_P521; i++)
1428 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1429 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1430 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1434 if (ecdsa_c[i] == 0)
1441 ecdsa_c[R_EC_K163][0]=count/1000;
1442 ecdsa_c[R_EC_K163][1]=count/1000/2;
1443 for (i=R_EC_K233; i<=R_EC_K571; i++)
1445 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1446 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1447 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1451 if (ecdsa_c[i] == 0)
1458 ecdsa_c[R_EC_B163][0]=count/1000;
1459 ecdsa_c[R_EC_B163][1]=count/1000/2;
1460 for (i=R_EC_B233; i<=R_EC_B571; i++)
1462 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1463 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1464 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1468 if (ecdsa_c[i] == 0)
1477 #ifndef OPENSSL_NO_ECDH
1478 ecdh_c[R_EC_P160][0]=count/1000;
1479 ecdh_c[R_EC_P160][1]=count/1000;
1480 for (i=R_EC_P192; i<=R_EC_P521; i++)
1482 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1483 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1484 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1495 ecdh_c[R_EC_K163][0]=count/1000;
1496 ecdh_c[R_EC_K163][1]=count/1000;
1497 for (i=R_EC_K233; i<=R_EC_K571; i++)
1499 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1500 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1501 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1512 ecdh_c[R_EC_B163][0]=count/1000;
1513 ecdh_c[R_EC_B163][1]=count/1000;
1514 for (i=R_EC_B233; i<=R_EC_B571; i++)
1516 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1517 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1518 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1531 #define COND(d) (count < (d))
1532 #define COUNT(d) (d)
1534 /* not worth fixing */
1535 # error "You cannot disable DES on systems without SIGALRM."
1536 #endif /* OPENSSL_NO_DES */
1538 #define COND(c) (run && count<0x7fffffff)
1539 #define COUNT(d) (count)
1541 signal(SIGALRM,sig_done);
1543 #endif /* SIGALRM */
1545 #ifndef OPENSSL_NO_MD2
1548 for (j=0; j<SIZE_NUM; j++)
1550 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1552 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1553 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1555 print_result(D_MD2,j,count,d);
1559 #ifndef OPENSSL_NO_MDC2
1562 for (j=0; j<SIZE_NUM; j++)
1564 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1566 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1567 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1569 print_result(D_MDC2,j,count,d);
1574 #ifndef OPENSSL_NO_MD4
1577 for (j=0; j<SIZE_NUM; j++)
1579 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1581 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1582 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1584 print_result(D_MD4,j,count,d);
1589 #ifndef OPENSSL_NO_MD5
1592 for (j=0; j<SIZE_NUM; j++)
1594 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1596 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1597 MD5(buf,lengths[j],md5);
1599 print_result(D_MD5,j,count,d);
1604 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1609 HMAC_CTX_init(&hctx);
1610 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1611 16,EVP_md5(), NULL);
1613 for (j=0; j<SIZE_NUM; j++)
1615 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1617 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1619 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1620 HMAC_Update(&hctx,buf,lengths[j]);
1621 HMAC_Final(&hctx,&(hmac[0]),NULL);
1624 print_result(D_HMAC,j,count,d);
1626 HMAC_CTX_cleanup(&hctx);
1629 #ifndef OPENSSL_NO_SHA
1632 for (j=0; j<SIZE_NUM; j++)
1634 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1636 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1638 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1640 SHA1(buf,lengths[j],sha);
1643 print_result(D_SHA1,j,count,d);
1647 #ifndef OPENSSL_NO_SHA256
1650 for (j=0; j<SIZE_NUM; j++)
1652 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1654 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1655 SHA256(buf,lengths[j],sha256);
1657 print_result(D_SHA256,j,count,d);
1662 #ifndef OPENSSL_NO_SHA512
1665 for (j=0; j<SIZE_NUM; j++)
1667 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1669 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1670 SHA512(buf,lengths[j],sha512);
1672 print_result(D_SHA512,j,count,d);
1678 #ifndef OPENSSL_NO_WHIRLPOOL
1679 if (doit[D_WHIRLPOOL])
1681 for (j=0; j<SIZE_NUM; j++)
1683 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1685 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1686 WHIRLPOOL(buf,lengths[j],whirlpool);
1688 print_result(D_WHIRLPOOL,j,count,d);
1693 #ifndef OPENSSL_NO_RIPEMD
1696 for (j=0; j<SIZE_NUM; j++)
1698 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1700 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1701 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1703 print_result(D_RMD160,j,count,d);
1707 #ifndef OPENSSL_NO_RC4
1710 for (j=0; j<SIZE_NUM; j++)
1712 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1714 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1715 RC4(&rc4_ks,(unsigned int)lengths[j],
1718 print_result(D_RC4,j,count,d);
1722 #ifndef OPENSSL_NO_DES
1723 if (doit[D_CBC_DES])
1725 for (j=0; j<SIZE_NUM; j++)
1727 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1729 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1730 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1731 &DES_iv,DES_ENCRYPT);
1733 print_result(D_CBC_DES,j,count,d);
1737 if (doit[D_EDE3_DES])
1739 for (j=0; j<SIZE_NUM; j++)
1741 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1743 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1744 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1746 &DES_iv,DES_ENCRYPT);
1748 print_result(D_EDE3_DES,j,count,d);
1752 #ifndef OPENSSL_NO_AES
1753 if (doit[D_CBC_128_AES])
1755 for (j=0; j<SIZE_NUM; j++)
1757 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1759 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1760 AES_cbc_encrypt(buf,buf,
1761 (unsigned long)lengths[j],&aes_ks1,
1764 print_result(D_CBC_128_AES,j,count,d);
1767 if (doit[D_CBC_192_AES])
1769 for (j=0; j<SIZE_NUM; j++)
1771 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1773 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1774 AES_cbc_encrypt(buf,buf,
1775 (unsigned long)lengths[j],&aes_ks2,
1778 print_result(D_CBC_192_AES,j,count,d);
1781 if (doit[D_CBC_256_AES])
1783 for (j=0; j<SIZE_NUM; j++)
1785 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1787 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1788 AES_cbc_encrypt(buf,buf,
1789 (unsigned long)lengths[j],&aes_ks3,
1792 print_result(D_CBC_256_AES,j,count,d);
1796 if (doit[D_IGE_128_AES])
1798 for (j=0; j<SIZE_NUM; j++)
1800 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1802 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1803 AES_ige_encrypt(buf,buf2,
1804 (unsigned long)lengths[j],&aes_ks1,
1807 print_result(D_IGE_128_AES,j,count,d);
1810 if (doit[D_IGE_192_AES])
1812 for (j=0; j<SIZE_NUM; j++)
1814 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1816 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1817 AES_ige_encrypt(buf,buf2,
1818 (unsigned long)lengths[j],&aes_ks2,
1821 print_result(D_IGE_192_AES,j,count,d);
1824 if (doit[D_IGE_256_AES])
1826 for (j=0; j<SIZE_NUM; j++)
1828 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1830 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1831 AES_ige_encrypt(buf,buf2,
1832 (unsigned long)lengths[j],&aes_ks3,
1835 print_result(D_IGE_256_AES,j,count,d);
1840 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1841 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1843 for (j=0; j<SIZE_NUM; j++)
1845 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1847 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1848 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1850 print_result(D_GHASH,j,count,d);
1852 CRYPTO_gcm128_release(ctx);
1856 #ifndef OPENSSL_NO_CAMELLIA
1857 if (doit[D_CBC_128_CML])
1859 for (j=0; j<SIZE_NUM; j++)
1861 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1863 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1864 Camellia_cbc_encrypt(buf,buf,
1865 (unsigned long)lengths[j],&camellia_ks1,
1866 iv,CAMELLIA_ENCRYPT);
1868 print_result(D_CBC_128_CML,j,count,d);
1871 if (doit[D_CBC_192_CML])
1873 for (j=0; j<SIZE_NUM; j++)
1875 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1877 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1878 Camellia_cbc_encrypt(buf,buf,
1879 (unsigned long)lengths[j],&camellia_ks2,
1880 iv,CAMELLIA_ENCRYPT);
1882 print_result(D_CBC_192_CML,j,count,d);
1885 if (doit[D_CBC_256_CML])
1887 for (j=0; j<SIZE_NUM; j++)
1889 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1891 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1892 Camellia_cbc_encrypt(buf,buf,
1893 (unsigned long)lengths[j],&camellia_ks3,
1894 iv,CAMELLIA_ENCRYPT);
1896 print_result(D_CBC_256_CML,j,count,d);
1901 #ifndef OPENSSL_NO_IDEA
1902 if (doit[D_CBC_IDEA])
1904 for (j=0; j<SIZE_NUM; j++)
1906 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1908 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1909 idea_cbc_encrypt(buf,buf,
1910 (unsigned long)lengths[j],&idea_ks,
1913 print_result(D_CBC_IDEA,j,count,d);
1917 #ifndef OPENSSL_NO_SEED
1918 if (doit[D_CBC_SEED])
1920 for (j=0; j<SIZE_NUM; j++)
1922 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1924 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1925 SEED_cbc_encrypt(buf,buf,
1926 (unsigned long)lengths[j],&seed_ks,iv,1);
1928 print_result(D_CBC_SEED,j,count,d);
1932 #ifndef OPENSSL_NO_RC2
1933 if (doit[D_CBC_RC2])
1935 for (j=0; j<SIZE_NUM; j++)
1937 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1939 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1940 RC2_cbc_encrypt(buf,buf,
1941 (unsigned long)lengths[j],&rc2_ks,
1944 print_result(D_CBC_RC2,j,count,d);
1948 #ifndef OPENSSL_NO_RC5
1949 if (doit[D_CBC_RC5])
1951 for (j=0; j<SIZE_NUM; j++)
1953 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1955 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1956 RC5_32_cbc_encrypt(buf,buf,
1957 (unsigned long)lengths[j],&rc5_ks,
1960 print_result(D_CBC_RC5,j,count,d);
1964 #ifndef OPENSSL_NO_BF
1967 for (j=0; j<SIZE_NUM; j++)
1969 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1971 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1972 BF_cbc_encrypt(buf,buf,
1973 (unsigned long)lengths[j],&bf_ks,
1976 print_result(D_CBC_BF,j,count,d);
1980 #ifndef OPENSSL_NO_CAST
1981 if (doit[D_CBC_CAST])
1983 for (j=0; j<SIZE_NUM; j++)
1985 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1987 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1988 CAST_cbc_encrypt(buf,buf,
1989 (unsigned long)lengths[j],&cast_ks,
1992 print_result(D_CBC_CAST,j,count,d);
1999 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2000 if (multiblock && evp_cipher)
2002 if (!(EVP_CIPHER_flags(evp_cipher)&EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK))
2004 fprintf(stderr,"%s is not multi-block capable\n",OBJ_nid2ln(evp_cipher->nid));
2007 multiblock_speed(evp_cipher);
2012 for (j=0; j<SIZE_NUM; j++)
2019 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2020 /* -O3 -fschedule-insns messes up an
2021 * optimization here! names[D_EVP]
2022 * somehow becomes NULL */
2023 print_message(names[D_EVP],save_count,
2026 EVP_CIPHER_CTX_init(&ctx);
2028 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2030 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2031 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2035 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2036 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2038 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2039 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2041 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2043 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2045 EVP_CIPHER_CTX_cleanup(&ctx);
2049 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2050 print_message(names[D_EVP],save_count,
2054 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2055 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2059 print_result(D_EVP,j,count,d);
2062 #ifndef OPENSSL_SYS_WIN32
2064 RAND_pseudo_bytes(buf,36);
2065 #ifndef OPENSSL_NO_RSA
2066 for (j=0; j<RSA_NUM; j++)
2069 if (!rsa_doit[j]) continue;
2070 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2073 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2074 ERR_print_errors(bio_err);
2079 pkey_print_message("private","rsa",
2080 rsa_c[j][0],rsa_bits[j],
2082 /* RSA_blinding_on(rsa_key[j],NULL); */
2084 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2086 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2087 &rsa_num, rsa_key[j]);
2091 "RSA sign failure\n");
2092 ERR_print_errors(bio_err);
2098 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2099 : "%ld %d bit private RSA's in %.2fs\n",
2100 count,rsa_bits[j],d);
2101 rsa_results[j][0]=d/(double)count;
2106 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2109 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2110 ERR_print_errors(bio_err);
2115 pkey_print_message("public","rsa",
2116 rsa_c[j][1],rsa_bits[j],
2119 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2121 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2122 rsa_num, rsa_key[j]);
2126 "RSA verify failure\n");
2127 ERR_print_errors(bio_err);
2133 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2134 : "%ld %d bit public RSA's in %.2fs\n",
2135 count,rsa_bits[j],d);
2136 rsa_results[j][1]=d/(double)count;
2142 /* if longer than 10s, don't do any more */
2143 for (j++; j<RSA_NUM; j++)
2149 RAND_pseudo_bytes(buf,20);
2150 #ifndef OPENSSL_NO_DSA
2151 if (RAND_status() != 1)
2153 RAND_seed(rnd_seed, sizeof rnd_seed);
2156 for (j=0; j<DSA_NUM; j++)
2161 if (!dsa_doit[j]) continue;
2162 /* DSA_generate_key(dsa_key[j]); */
2163 /* DSA_sign_setup(dsa_key[j],NULL); */
2164 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2168 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2169 ERR_print_errors(bio_err);
2174 pkey_print_message("sign","dsa",
2175 dsa_c[j][0],dsa_bits[j],
2178 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2180 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2185 "DSA sign failure\n");
2186 ERR_print_errors(bio_err);
2192 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2193 : "%ld %d bit DSA signs in %.2fs\n",
2194 count,dsa_bits[j],d);
2195 dsa_results[j][0]=d/(double)count;
2199 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2203 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2204 ERR_print_errors(bio_err);
2209 pkey_print_message("verify","dsa",
2210 dsa_c[j][1],dsa_bits[j],
2213 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2215 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2220 "DSA verify failure\n");
2221 ERR_print_errors(bio_err);
2227 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2228 : "%ld %d bit DSA verify in %.2fs\n",
2229 count,dsa_bits[j],d);
2230 dsa_results[j][1]=d/(double)count;
2235 /* if longer than 10s, don't do any more */
2236 for (j++; j<DSA_NUM; j++)
2240 if (rnd_fake) RAND_cleanup();
2243 #ifndef OPENSSL_NO_ECDSA
2244 if (RAND_status() != 1)
2246 RAND_seed(rnd_seed, sizeof rnd_seed);
2249 for (j=0; j<EC_NUM; j++)
2253 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2254 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2255 if (ecdsa[j] == NULL)
2257 BIO_printf(bio_err,"ECDSA failure.\n");
2258 ERR_print_errors(bio_err);
2264 EC_KEY_precompute_mult(ecdsa[j], NULL);
2266 /* Perform ECDSA signature test */
2267 EC_KEY_generate_key(ecdsa[j]);
2268 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2269 &ecdsasiglen, ecdsa[j]);
2272 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2273 ERR_print_errors(bio_err);
2278 pkey_print_message("sign","ecdsa",
2280 test_curves_bits[j],
2284 for (count=0,run=1; COND(ecdsa_c[j][0]);
2287 ret=ECDSA_sign(0, buf, 20,
2288 ecdsasig, &ecdsasiglen,
2292 BIO_printf(bio_err, "ECDSA sign failure\n");
2293 ERR_print_errors(bio_err);
2300 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2301 "%ld %d bit ECDSA signs in %.2fs \n",
2302 count, test_curves_bits[j], d);
2303 ecdsa_results[j][0]=d/(double)count;
2307 /* Perform ECDSA verification test */
2308 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2309 ecdsasiglen, ecdsa[j]);
2312 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2313 ERR_print_errors(bio_err);
2318 pkey_print_message("verify","ecdsa",
2320 test_curves_bits[j],
2323 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2325 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2328 BIO_printf(bio_err, "ECDSA verify failure\n");
2329 ERR_print_errors(bio_err);
2335 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2336 : "%ld %d bit ECDSA verify in %.2fs\n",
2337 count, test_curves_bits[j], d);
2338 ecdsa_results[j][1]=d/(double)count;
2343 /* if longer than 10s, don't do any more */
2344 for (j++; j<EC_NUM; j++)
2349 if (rnd_fake) RAND_cleanup();
2352 #ifndef OPENSSL_NO_ECDH
2353 if (RAND_status() != 1)
2355 RAND_seed(rnd_seed, sizeof rnd_seed);
2358 for (j=0; j<EC_NUM; j++)
2360 if (!ecdh_doit[j]) continue;
2361 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2362 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2363 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2365 BIO_printf(bio_err,"ECDH failure.\n");
2366 ERR_print_errors(bio_err);
2371 /* generate two ECDH key pairs */
2372 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2373 !EC_KEY_generate_key(ecdh_b[j]))
2375 BIO_printf(bio_err,"ECDH key generation failure.\n");
2376 ERR_print_errors(bio_err);
2381 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2382 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2384 int field_size, outlen;
2385 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2386 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2387 if (field_size <= 24 * 8)
2389 outlen = KDF1_SHA1_len;
2394 outlen = (field_size+7)/8;
2397 secret_size_a = ECDH_compute_key(secret_a, outlen,
2398 EC_KEY_get0_public_key(ecdh_b[j]),
2400 secret_size_b = ECDH_compute_key(secret_b, outlen,
2401 EC_KEY_get0_public_key(ecdh_a[j]),
2403 if (secret_size_a != secret_size_b)
2408 for (secret_idx = 0;
2409 (secret_idx < secret_size_a)
2410 && (ecdh_checks == 1);
2413 if (secret_a[secret_idx] != secret_b[secret_idx])
2417 if (ecdh_checks == 0)
2419 BIO_printf(bio_err,"ECDH computations don't match.\n");
2420 ERR_print_errors(bio_err);
2424 pkey_print_message("","ecdh",
2426 test_curves_bits[j],
2429 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2431 ECDH_compute_key(secret_a, outlen,
2432 EC_KEY_get0_public_key(ecdh_b[j]),
2436 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2437 count, test_curves_bits[j], d);
2438 ecdh_results[j][0]=d/(double)count;
2446 /* if longer than 10s, don't do any more */
2447 for (j++; j<EC_NUM; j++)
2451 if (rnd_fake) RAND_cleanup();
2458 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2459 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2461 printf("%s ",BN_options());
2462 #ifndef OPENSSL_NO_MD2
2463 printf("%s ",MD2_options());
2465 #ifndef OPENSSL_NO_RC4
2466 printf("%s ",RC4_options());
2468 #ifndef OPENSSL_NO_DES
2469 printf("%s ",DES_options());
2471 #ifndef OPENSSL_NO_AES
2472 printf("%s ",AES_options());
2474 #ifndef OPENSSL_NO_IDEA
2475 printf("%s ",idea_options());
2477 #ifndef OPENSSL_NO_BF
2478 printf("%s ",BF_options());
2480 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2486 fprintf(stdout,"+H");
2489 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2490 fprintf(stdout,"type ");
2492 for (j=0; j<SIZE_NUM; j++)
2493 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2494 fprintf(stdout,"\n");
2497 for (k=0; k<ALGOR_NUM; k++)
2499 if (!doit[k]) continue;
2501 fprintf(stdout,"+F:%d:%s",k,names[k]);
2503 fprintf(stdout,"%-13s",names[k]);
2504 for (j=0; j<SIZE_NUM; j++)
2506 if (results[k][j] > 10000 && !mr)
2507 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2509 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2511 fprintf(stdout,"\n");
2513 #ifndef OPENSSL_NO_RSA
2515 for (k=0; k<RSA_NUM; k++)
2517 if (!rsa_doit[k]) continue;
2520 printf("%18ssign verify sign/s verify/s\n"," ");
2524 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2525 k,rsa_bits[k],rsa_results[k][0],
2528 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2529 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2530 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2533 #ifndef OPENSSL_NO_DSA
2535 for (k=0; k<DSA_NUM; k++)
2537 if (!dsa_doit[k]) continue;
2540 printf("%18ssign verify sign/s verify/s\n"," ");
2544 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2545 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2547 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2548 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2549 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2552 #ifndef OPENSSL_NO_ECDSA
2554 for (k=0; k<EC_NUM; k++)
2556 if (!ecdsa_doit[k]) continue;
2559 printf("%30ssign verify sign/s verify/s\n"," ");
2564 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2565 k, test_curves_bits[k],
2566 ecdsa_results[k][0],ecdsa_results[k][1]);
2569 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2570 test_curves_bits[k],
2571 test_curves_names[k],
2572 ecdsa_results[k][0],ecdsa_results[k][1],
2573 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2578 #ifndef OPENSSL_NO_ECDH
2580 for (k=0; k<EC_NUM; k++)
2582 if (!ecdh_doit[k]) continue;
2585 printf("%30sop op/s\n"," ");
2589 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2590 k, test_curves_bits[k],
2591 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2594 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2595 test_curves_bits[k],
2596 test_curves_names[k],
2597 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2604 ERR_print_errors(bio_err);
2605 if (buf_malloc != NULL) OPENSSL_free(buf_malloc);
2606 if (buf2_malloc != NULL) OPENSSL_free(buf2_malloc);
2607 #ifndef OPENSSL_NO_RSA
2608 for (i=0; i<RSA_NUM; i++)
2609 if (rsa_key[i] != NULL)
2610 RSA_free(rsa_key[i]);
2612 #ifndef OPENSSL_NO_DSA
2613 for (i=0; i<DSA_NUM; i++)
2614 if (dsa_key[i] != NULL)
2615 DSA_free(dsa_key[i]);
2618 #ifndef OPENSSL_NO_ECDSA
2619 for (i=0; i<EC_NUM; i++)
2620 if (ecdsa[i] != NULL)
2621 EC_KEY_free(ecdsa[i]);
2623 #ifndef OPENSSL_NO_ECDH
2624 for (i=0; i<EC_NUM; i++)
2626 if (ecdh_a[i] != NULL)
2627 EC_KEY_free(ecdh_a[i]);
2628 if (ecdh_b[i] != NULL)
2629 EC_KEY_free(ecdh_b[i]);
2637 static void print_message(const char *s, long num, int length)
2640 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2641 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2642 (void)BIO_flush(bio_err);
2645 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2646 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2647 (void)BIO_flush(bio_err);
2651 static void pkey_print_message(const char *str, const char *str2, long num,
2655 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2656 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2657 (void)BIO_flush(bio_err);
2660 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2661 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2662 (void)BIO_flush(bio_err);
2666 static void print_result(int alg,int run_no,int count,double time_used)
2668 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2669 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2670 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2674 static char *sstrsep(char **string, const char *delim)
2677 char *token = *string;
2682 memset(isdelim, 0, sizeof isdelim);
2687 isdelim[(unsigned char)(*delim)] = 1;
2691 while (!isdelim[(unsigned char)(**string)])
2705 static int do_multi(int multi)
2710 static char sep[]=":";
2712 fds=malloc(multi*sizeof *fds);
2713 for(n=0 ; n < multi ; ++n)
2717 fprintf(stderr, "pipe failure\n");
2731 if (dup(fd[1]) == -1)
2733 fprintf(stderr, "dup failed\n");
2742 printf("Forked child %d\n",n);
2745 /* for now, assume the pipe is long enough to take all the output */
2746 for(n=0 ; n < multi ; ++n)
2752 f=fdopen(fds[n],"r");
2753 while(fgets(buf,sizeof buf,f))
2760 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2764 printf("Got: %s from %d\n",buf,n);
2765 if(!strncmp(buf,"+F:",3))
2771 alg=atoi(sstrsep(&p,sep));
2773 for(j=0 ; j < SIZE_NUM ; ++j)
2774 results[alg][j]+=atof(sstrsep(&p,sep));
2776 else if(!strncmp(buf,"+F2:",4))
2782 k=atoi(sstrsep(&p,sep));
2785 d=atof(sstrsep(&p,sep));
2787 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2789 rsa_results[k][0]=d;
2791 d=atof(sstrsep(&p,sep));
2793 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2795 rsa_results[k][1]=d;
2797 else if(!strncmp(buf,"+F2:",4))
2803 k=atoi(sstrsep(&p,sep));
2806 d=atof(sstrsep(&p,sep));
2808 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2810 rsa_results[k][0]=d;
2812 d=atof(sstrsep(&p,sep));
2814 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2816 rsa_results[k][1]=d;
2818 #ifndef OPENSSL_NO_DSA
2819 else if(!strncmp(buf,"+F3:",4))
2825 k=atoi(sstrsep(&p,sep));
2828 d=atof(sstrsep(&p,sep));
2830 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2832 dsa_results[k][0]=d;
2834 d=atof(sstrsep(&p,sep));
2836 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2838 dsa_results[k][1]=d;
2841 #ifndef OPENSSL_NO_ECDSA
2842 else if(!strncmp(buf,"+F4:",4))
2848 k=atoi(sstrsep(&p,sep));
2851 d=atof(sstrsep(&p,sep));
2853 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2855 ecdsa_results[k][0]=d;
2857 d=atof(sstrsep(&p,sep));
2859 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2861 ecdsa_results[k][1]=d;
2865 #ifndef OPENSSL_NO_ECDH
2866 else if(!strncmp(buf,"+F5:",4))
2872 k=atoi(sstrsep(&p,sep));
2875 d=atof(sstrsep(&p,sep));
2877 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2879 ecdh_results[k][0]=d;
2884 else if(!strncmp(buf,"+H:",3))
2888 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2898 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2900 static int mblengths[]={8*1024,2*8*1024,4*8*1024,8*8*1024,8*16*1024};
2901 int j,count,num=sizeof(lengths)/sizeof(lengths[0]);
2902 const char *alg_name;
2903 unsigned char *inp,*out,no_key[32],no_iv[16];
2907 inp = OPENSSL_malloc(mblengths[num-1]);
2908 out = OPENSSL_malloc(mblengths[num-1]+1024);
2910 EVP_CIPHER_CTX_init(&ctx);
2911 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,no_key,no_iv);
2912 EVP_CIPHER_CTX_ctrl(&ctx,EVP_CTRL_AEAD_SET_MAC_KEY,sizeof(no_key),no_key);
2913 alg_name=OBJ_nid2ln(evp_cipher->nid);
2915 for (j=0; j<num; j++)
2917 print_message(alg_name,0,mblengths[j]);
2919 for (count=0,run=1; run && count<0x7fffffff; count++)
2921 unsigned char aad[13];
2922 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2923 size_t len = mblengths[j];
2926 memset(aad,0,8);/* avoid uninitialized values */
2927 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2928 aad[9] = 3; /* version */
2930 aad[11] = 0; /* length */
2932 mb_param.out = NULL;
2935 mb_param.interleave = 8;
2937 packlen=EVP_CIPHER_CTX_ctrl(&ctx,
2938 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2939 sizeof(mb_param),&mb_param);
2946 EVP_CIPHER_CTX_ctrl(&ctx,
2947 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2948 sizeof(mb_param),&mb_param);
2958 pad=EVP_CIPHER_CTX_ctrl(&ctx,
2959 EVP_CTRL_AEAD_TLS1_AAD,13,aad);
2960 EVP_Cipher(&ctx,out,inp,len+pad);
2964 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2965 : "%d %s's in %.2fs\n",count,"evp",d);
2966 results[D_EVP][j]=((double)count)/d*mblengths[j];
2971 fprintf(stdout,"+H");
2972 for (j=0; j<num; j++)
2973 fprintf(stdout,":%d",mblengths[j]);
2974 fprintf(stdout,"\n");
2975 fprintf(stdout,"+F:%d:%s",D_EVP,alg_name);
2976 for (j=0; j<num; j++)
2977 fprintf(stdout,":%.2f",results[D_EVP][j]);
2978 fprintf(stdout,"\n");
2982 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2983 fprintf(stdout,"type ");
2984 for (j=0; j<num; j++)
2985 fprintf(stdout,"%7d bytes",mblengths[j]);
2986 fprintf(stdout,"\n");
2987 fprintf(stdout,"%-24s",alg_name);
2989 for (j=0; j<num; j++)
2991 if (results[D_EVP][j] > 10000)
2992 fprintf(stdout," %11.2fk",results[D_EVP][j]/1e3);
2994 fprintf(stdout," %11.2f ",results[D_EVP][j]);
2996 fprintf(stdout,"\n");