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_RMD160
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
212 static volatile int run=0;
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_RMD160
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]={
532 512,1024,2048,3072,4096,7680,15360};
533 static unsigned char *rsa_data[RSA_NUM]= {
534 test512,test1024,test2048,test3072,test4096,test7680,test15360};
535 static int rsa_data_length[RSA_NUM]={
536 sizeof(test512),sizeof(test1024),
537 sizeof(test2048),sizeof(test3072),
538 sizeof(test4096),sizeof(test7680),
541 #ifndef OPENSSL_NO_DSA
542 DSA *dsa_key[DSA_NUM];
543 long dsa_c[DSA_NUM][2];
544 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
546 #ifndef OPENSSL_NO_EC
547 /* We only test over the following curves as they are representative,
548 * To add tests over more curves, simply add the curve NID
549 * and curve name to the following arrays and increase the
550 * EC_NUM value accordingly.
552 static unsigned int test_curves[EC_NUM] =
556 NID_X9_62_prime192v1,
558 NID_X9_62_prime256v1,
573 static const char * test_curves_names[EC_NUM] =
594 static int test_curves_bits[EC_NUM] =
596 160, 192, 224, 256, 384, 521,
597 163, 233, 283, 409, 571,
598 163, 233, 283, 409, 571
603 #ifndef OPENSSL_NO_ECDSA
604 unsigned char ecdsasig[256];
605 unsigned int ecdsasiglen;
606 EC_KEY *ecdsa[EC_NUM];
607 long ecdsa_c[EC_NUM][2];
610 #ifndef OPENSSL_NO_ECDH
611 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
612 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
613 int secret_size_a, secret_size_b;
616 long ecdh_c[EC_NUM][2];
619 int rsa_doit[RSA_NUM];
620 int dsa_doit[DSA_NUM];
621 #ifndef OPENSSL_NO_ECDSA
622 int ecdsa_doit[EC_NUM];
624 #ifndef OPENSSL_NO_ECDH
625 int ecdh_doit[EC_NUM];
629 const EVP_CIPHER *evp_cipher=NULL;
630 const EVP_MD *evp_md=NULL;
636 int misalign=MAX_MISALIGNMENT+1;
643 memset(results, 0, sizeof(results));
644 #ifndef OPENSSL_NO_DSA
645 memset(dsa_key,0,sizeof(dsa_key));
647 #ifndef OPENSSL_NO_ECDSA
648 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
650 #ifndef OPENSSL_NO_ECDH
651 for (i=0; i<EC_NUM; i++)
660 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
661 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
663 if (!load_config(bio_err, NULL))
666 #ifndef OPENSSL_NO_RSA
667 memset(rsa_key,0,sizeof(rsa_key));
668 for (i=0; i<RSA_NUM; i++)
672 if ((buf_malloc=(unsigned char *)OPENSSL_malloc(BUFSIZE+misalign)) == NULL)
674 BIO_printf(bio_err,"out of memory\n");
677 if ((buf2_malloc=(unsigned char *)OPENSSL_malloc(BUFSIZE+misalign)) == NULL)
679 BIO_printf(bio_err,"out of memory\n");
683 misalign = 0; /* set later and buf/buf2 are adjusted accordingly */
687 memset(c,0,sizeof(c));
688 memset(DES_iv,0,sizeof(DES_iv));
689 memset(iv,0,sizeof(iv));
691 for (i=0; i<ALGOR_NUM; i++)
693 for (i=0; i<RSA_NUM; i++)
695 for (i=0; i<DSA_NUM; i++)
697 #ifndef OPENSSL_NO_ECDSA
698 for (i=0; i<EC_NUM; i++)
701 #ifndef OPENSSL_NO_ECDH
702 for (i=0; i<EC_NUM; i++)
711 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
714 j--; /* Otherwise, -elapsed gets confused with
717 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
723 BIO_printf(bio_err,"no EVP given\n");
726 evp_cipher=EVP_get_cipherbyname(*argv);
729 evp_md=EVP_get_digestbyname(*argv);
731 if(!evp_cipher && !evp_md)
733 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
738 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
741 j--; /* Otherwise, -elapsed gets confused with
744 #ifndef OPENSSL_NO_ENGINE
745 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
751 BIO_printf(bio_err,"no engine given\n");
754 setup_engine(bio_err, *argv, 0);
755 /* j will be increased again further down. We just
756 don't want speed to confuse an engine with an
757 algorithm, especially when none is given (which
758 means all of them should be run) */
763 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
769 BIO_printf(bio_err,"no multi count given\n");
775 BIO_printf(bio_err,"bad multi count\n");
778 j--; /* Otherwise, -mr gets confused with
782 else if (argc > 0 && !strcmp(*argv,"-mr"))
785 j--; /* Otherwise, -mr gets confused with
788 else if (argc > 0 && !strcmp(*argv,"-mb"))
793 else if (argc > 0 && !strcmp(*argv,"-misalign"))
799 BIO_printf(bio_err,"no misalignment given\n");
802 misalign=atoi(argv[0]);
803 if (misalign<0 || misalign>MAX_MISALIGNMENT)
805 BIO_printf(bio_err,"misalignment is outsize permitted range 0-%d\n",MAX_MISALIGNMENT);
808 buf=buf_malloc+misalign;
809 buf2=buf2_malloc+misalign;
813 #ifndef OPENSSL_NO_MD2
814 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
817 #ifndef OPENSSL_NO_MDC2
818 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
821 #ifndef OPENSSL_NO_MD4
822 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
825 #ifndef OPENSSL_NO_MD5
826 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
829 #ifndef OPENSSL_NO_MD5
830 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
833 #ifndef OPENSSL_NO_SHA
834 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
836 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
840 #ifndef OPENSSL_NO_SHA256
841 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
844 #ifndef OPENSSL_NO_SHA512
845 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
849 #ifndef OPENSSL_NO_WHIRLPOOL
850 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
853 #ifndef OPENSSL_NO_RMD160
854 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
856 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
858 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
861 #ifndef OPENSSL_NO_RC4
862 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
865 #ifndef OPENSSL_NO_DES
866 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
867 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
870 #ifndef OPENSSL_NO_AES
871 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
872 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
873 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
874 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
875 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
876 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
879 #ifndef OPENSSL_NO_CAMELLIA
880 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
881 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
882 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
885 #ifndef OPENSSL_NO_RSA
886 #if 0 /* was: #ifdef RSAref */
887 if (strcmp(*argv,"rsaref") == 0)
889 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
895 if (strcmp(*argv,"openssl") == 0)
897 RSA_set_default_method(RSA_PKCS1_SSLeay());
902 #endif /* !OPENSSL_NO_RSA */
903 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
904 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
905 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
906 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
907 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
908 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
909 else if (strcmp(*argv,"rsa3072") == 0) rsa_doit[R_RSA_3072]=2;
910 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
911 else if (strcmp(*argv,"rsa7680") == 0) rsa_doit[R_RSA_7680]=2;
912 else if (strcmp(*argv,"rsa15360") == 0) rsa_doit[R_RSA_15360]=2;
914 #ifndef OPENSSL_NO_RC2
915 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
916 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
919 #ifndef OPENSSL_NO_RC5
920 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
921 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
924 #ifndef OPENSSL_NO_IDEA
925 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
926 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
929 #ifndef OPENSSL_NO_SEED
930 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
931 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
934 #ifndef OPENSSL_NO_BF
935 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
936 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
937 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
940 #ifndef OPENSSL_NO_CAST
941 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
942 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
943 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
946 #ifndef OPENSSL_NO_DES
947 if (strcmp(*argv,"des") == 0)
954 #ifndef OPENSSL_NO_AES
955 if (strcmp(*argv,"aes") == 0)
957 doit[D_CBC_128_AES]=1;
958 doit[D_CBC_192_AES]=1;
959 doit[D_CBC_256_AES]=1;
961 else if (strcmp(*argv,"ghash") == 0)
967 #ifndef OPENSSL_NO_CAMELLIA
968 if (strcmp(*argv,"camellia") == 0)
970 doit[D_CBC_128_CML]=1;
971 doit[D_CBC_192_CML]=1;
972 doit[D_CBC_256_CML]=1;
976 #ifndef OPENSSL_NO_RSA
977 if (strcmp(*argv,"rsa") == 0)
979 rsa_doit[R_RSA_512]=1;
980 rsa_doit[R_RSA_1024]=1;
981 rsa_doit[R_RSA_2048]=1;
982 rsa_doit[R_RSA_3072]=1;
983 rsa_doit[R_RSA_4096]=1;
984 rsa_doit[R_RSA_7680]=1;
985 rsa_doit[R_RSA_15360]=1;
989 #ifndef OPENSSL_NO_DSA
990 if (strcmp(*argv,"dsa") == 0)
992 dsa_doit[R_DSA_512]=1;
993 dsa_doit[R_DSA_1024]=1;
994 dsa_doit[R_DSA_2048]=1;
998 #ifndef OPENSSL_NO_ECDSA
999 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
1000 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
1001 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
1002 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
1003 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
1004 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
1005 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
1006 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
1007 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
1008 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
1009 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
1010 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
1011 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
1012 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
1013 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
1014 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
1015 else if (strcmp(*argv,"ecdsa") == 0)
1017 for (i=0; i < EC_NUM; i++)
1022 #ifndef OPENSSL_NO_ECDH
1023 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1024 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1025 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1026 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1027 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1028 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1029 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1030 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1031 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1032 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1033 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1034 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1035 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1036 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1037 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1038 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1039 else if (strcmp(*argv,"ecdh") == 0)
1041 for (i=0; i < EC_NUM; i++)
1047 BIO_printf(bio_err,"Error: bad option or value\n");
1048 BIO_printf(bio_err,"\n");
1049 BIO_printf(bio_err,"Available values:\n");
1050 #ifndef OPENSSL_NO_MD2
1051 BIO_printf(bio_err,"md2 ");
1053 #ifndef OPENSSL_NO_MDC2
1054 BIO_printf(bio_err,"mdc2 ");
1056 #ifndef OPENSSL_NO_MD4
1057 BIO_printf(bio_err,"md4 ");
1059 #ifndef OPENSSL_NO_MD5
1060 BIO_printf(bio_err,"md5 ");
1061 #ifndef OPENSSL_NO_HMAC
1062 BIO_printf(bio_err,"hmac ");
1065 #ifndef OPENSSL_NO_SHA1
1066 BIO_printf(bio_err,"sha1 ");
1068 #ifndef OPENSSL_NO_SHA256
1069 BIO_printf(bio_err,"sha256 ");
1071 #ifndef OPENSSL_NO_SHA512
1072 BIO_printf(bio_err,"sha512 ");
1074 #ifndef OPENSSL_NO_WHIRLPOOL
1075 BIO_printf(bio_err,"whirlpool");
1077 #ifndef OPENSSL_NO_RMD160
1078 BIO_printf(bio_err,"rmd160");
1080 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1081 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1082 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \
1083 !defined(OPENSSL_NO_WHIRLPOOL)
1084 BIO_printf(bio_err,"\n");
1087 #ifndef OPENSSL_NO_IDEA
1088 BIO_printf(bio_err,"idea-cbc ");
1090 #ifndef OPENSSL_NO_SEED
1091 BIO_printf(bio_err,"seed-cbc ");
1093 #ifndef OPENSSL_NO_RC2
1094 BIO_printf(bio_err,"rc2-cbc ");
1096 #ifndef OPENSSL_NO_RC5
1097 BIO_printf(bio_err,"rc5-cbc ");
1099 #ifndef OPENSSL_NO_BF
1100 BIO_printf(bio_err,"bf-cbc");
1102 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1103 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1104 BIO_printf(bio_err,"\n");
1106 #ifndef OPENSSL_NO_DES
1107 BIO_printf(bio_err,"des-cbc des-ede3 ");
1109 #ifndef OPENSSL_NO_AES
1110 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1111 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1113 #ifndef OPENSSL_NO_CAMELLIA
1114 BIO_printf(bio_err,"\n");
1115 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1117 #ifndef OPENSSL_NO_RC4
1118 BIO_printf(bio_err,"rc4");
1120 BIO_printf(bio_err,"\n");
1122 #ifndef OPENSSL_NO_RSA
1123 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
1124 BIO_printf(bio_err,"rsa7680 rsa15360\n");
1127 #ifndef OPENSSL_NO_DSA
1128 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1130 #ifndef OPENSSL_NO_ECDSA
1131 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 "
1132 "ecdsap256 ecdsap384 ecdsap521\n");
1133 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1134 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1135 BIO_printf(bio_err,"ecdsa\n");
1137 #ifndef OPENSSL_NO_ECDH
1138 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 "
1139 "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 "
1180 "measure time in real time instead of CPU user time.\n");
1182 #ifndef OPENSSL_NO_ENGINE
1185 "use engine e, possibly a hardware device.\n");
1192 "time decryption instead of encryption (only EVP).\n");
1195 "produce machine readable output.\n");
1198 "perform multi-block benchmark (for specific ciphers)\n");
1201 "perform benchmark with misaligned data\n");
1205 "run n benchmarks in parallel.\n");
1215 if(multi && do_multi(multi))
1221 for (i=0; i<ALGOR_NUM; i++)
1226 for (i=0; i<RSA_NUM; i++)
1228 for (i=0; i<DSA_NUM; i++)
1230 #ifndef OPENSSL_NO_ECDSA
1231 for (i=0; i<EC_NUM; i++)
1234 #ifndef OPENSSL_NO_ECDH
1235 for (i=0; i<EC_NUM; i++)
1239 for (i=0; i<ALGOR_NUM; i++)
1240 if (doit[i]) pr_header++;
1242 if (usertime == 0 && !mr)
1244 "You have chosen to measure elapsed time "
1245 "instead of user CPU time.\n");
1247 #ifndef OPENSSL_NO_RSA
1248 for (i=0; i<RSA_NUM; i++)
1250 const unsigned char *p;
1253 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1254 if (rsa_key[i] == NULL)
1256 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1264 : "Loaded RSA key, %d bit modulus and e= 0x",
1265 BN_num_bits(rsa_key[i]->n));
1266 BN_print(bio_err,rsa_key[i]->e);
1267 BIO_printf(bio_err,"\n");
1273 #ifndef OPENSSL_NO_DSA
1274 dsa_key[0]=get_dsa512();
1275 dsa_key[1]=get_dsa1024();
1276 dsa_key[2]=get_dsa2048();
1279 #ifndef OPENSSL_NO_DES
1280 DES_set_key_unchecked(&key,&sch);
1281 DES_set_key_unchecked(&key2,&sch2);
1282 DES_set_key_unchecked(&key3,&sch3);
1284 #ifndef OPENSSL_NO_AES
1285 AES_set_encrypt_key(key16,128,&aes_ks1);
1286 AES_set_encrypt_key(key24,192,&aes_ks2);
1287 AES_set_encrypt_key(key32,256,&aes_ks3);
1289 #ifndef OPENSSL_NO_CAMELLIA
1290 Camellia_set_key(key16,128,&camellia_ks1);
1291 Camellia_set_key(ckey24,192,&camellia_ks2);
1292 Camellia_set_key(ckey32,256,&camellia_ks3);
1294 #ifndef OPENSSL_NO_IDEA
1295 idea_set_encrypt_key(key16,&idea_ks);
1297 #ifndef OPENSSL_NO_SEED
1298 SEED_set_key(key16,&seed_ks);
1300 #ifndef OPENSSL_NO_RC4
1301 RC4_set_key(&rc4_ks,16,key16);
1303 #ifndef OPENSSL_NO_RC2
1304 RC2_set_key(&rc2_ks,16,key16,128);
1306 #ifndef OPENSSL_NO_RC5
1307 RC5_32_set_key(&rc5_ks,16,key16,12);
1309 #ifndef OPENSSL_NO_BF
1310 BF_set_key(&bf_ks,16,key16);
1312 #ifndef OPENSSL_NO_CAST
1313 CAST_set_key(&cast_ks,16,key16);
1315 #ifndef OPENSSL_NO_RSA
1316 memset(rsa_c,0,sizeof(rsa_c));
1319 #ifndef OPENSSL_NO_DES
1320 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1326 for (it=count; it; it--)
1327 DES_ecb_encrypt((DES_cblock *)buf,
1333 c[D_MD2][0]=count/10;
1334 c[D_MDC2][0]=count/10;
1339 c[D_RMD160][0]=count;
1340 c[D_RC4][0]=count*5;
1341 c[D_CBC_DES][0]=count;
1342 c[D_EDE3_DES][0]=count/3;
1343 c[D_CBC_IDEA][0]=count;
1344 c[D_CBC_SEED][0]=count;
1345 c[D_CBC_RC2][0]=count;
1346 c[D_CBC_RC5][0]=count;
1347 c[D_CBC_BF][0]=count;
1348 c[D_CBC_CAST][0]=count;
1349 c[D_CBC_128_AES][0]=count;
1350 c[D_CBC_192_AES][0]=count;
1351 c[D_CBC_256_AES][0]=count;
1352 c[D_CBC_128_CML][0]=count;
1353 c[D_CBC_192_CML][0]=count;
1354 c[D_CBC_256_CML][0]=count;
1355 c[D_SHA256][0]=count;
1356 c[D_SHA512][0]=count;
1357 c[D_WHIRLPOOL][0]=count;
1358 c[D_IGE_128_AES][0]=count;
1359 c[D_IGE_192_AES][0]=count;
1360 c[D_IGE_256_AES][0]=count;
1361 c[D_GHASH][0]=count;
1363 for (i=1; i<SIZE_NUM; i++)
1367 l0=(long)lengths[0];
1368 l1=(long)lengths[i];
1370 c[D_MD2][i]=c[D_MD2][0]*4*l0/l1;
1371 c[D_MDC2][i]=c[D_MDC2][0]*4*l0/l1;
1372 c[D_MD4][i]=c[D_MD4][0]*4*l0/l1;
1373 c[D_MD5][i]=c[D_MD5][0]*4*l0/l1;
1374 c[D_HMAC][i]=c[D_HMAC][0]*4*l0/l1;
1375 c[D_SHA1][i]=c[D_SHA1][0]*4*l0/l1;
1376 c[D_RMD160][i]=c[D_RMD160][0]*4*l0/l1;
1377 c[D_SHA256][i]=c[D_SHA256][0]*4*l0/l1;
1378 c[D_SHA512][i]=c[D_SHA512][0]*4*l0/l1;
1379 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*l0/l1;
1381 l0=(long)lengths[i-1];
1383 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1384 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1385 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1386 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1387 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1388 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1389 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1390 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1391 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1392 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1393 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1394 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1395 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1396 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1397 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1398 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1399 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1400 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1404 #ifndef OPENSSL_NO_RSA
1405 rsa_c[R_RSA_512][0]=count/2000;
1406 rsa_c[R_RSA_512][1]=count/400;
1407 for (i=1; i<RSA_NUM; i++)
1409 rsa_c[i][0]=rsa_c[i-1][0]/8;
1410 rsa_c[i][1]=rsa_c[i-1][1]/4;
1411 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1415 if (rsa_c[i][0] == 0)
1424 #ifndef OPENSSL_NO_DSA
1425 dsa_c[R_DSA_512][0]=count/1000;
1426 dsa_c[R_DSA_512][1]=count/1000/2;
1427 for (i=1; i<DSA_NUM; i++)
1429 dsa_c[i][0]=dsa_c[i-1][0]/4;
1430 dsa_c[i][1]=dsa_c[i-1][1]/4;
1431 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1444 #ifndef OPENSSL_NO_ECDSA
1445 ecdsa_c[R_EC_P160][0]=count/1000;
1446 ecdsa_c[R_EC_P160][1]=count/1000/2;
1447 for (i=R_EC_P192; i<=R_EC_P521; i++)
1449 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1450 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1451 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1455 if (ecdsa_c[i] == 0)
1462 ecdsa_c[R_EC_K163][0]=count/1000;
1463 ecdsa_c[R_EC_K163][1]=count/1000/2;
1464 for (i=R_EC_K233; i<=R_EC_K571; i++)
1466 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1467 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1468 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1472 if (ecdsa_c[i] == 0)
1479 ecdsa_c[R_EC_B163][0]=count/1000;
1480 ecdsa_c[R_EC_B163][1]=count/1000/2;
1481 for (i=R_EC_B233; i<=R_EC_B571; i++)
1483 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1484 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1485 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1489 if (ecdsa_c[i] == 0)
1498 #ifndef OPENSSL_NO_ECDH
1499 ecdh_c[R_EC_P160][0]=count/1000;
1500 ecdh_c[R_EC_P160][1]=count/1000;
1501 for (i=R_EC_P192; i<=R_EC_P521; i++)
1503 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1504 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1505 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1516 ecdh_c[R_EC_K163][0]=count/1000;
1517 ecdh_c[R_EC_K163][1]=count/1000;
1518 for (i=R_EC_K233; i<=R_EC_K571; i++)
1520 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1521 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1522 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1533 ecdh_c[R_EC_B163][0]=count/1000;
1534 ecdh_c[R_EC_B163][1]=count/1000;
1535 for (i=R_EC_B233; i<=R_EC_B571; i++)
1537 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1538 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1539 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1552 #define COND(d) (count < (d))
1553 #define COUNT(d) (d)
1555 /* not worth fixing */
1556 # error "You cannot disable DES on systems without SIGALRM."
1557 #endif /* OPENSSL_NO_DES */
1559 #define COND(c) (run && count<0x7fffffff)
1560 #define COUNT(d) (count)
1562 signal(SIGALRM,sig_done);
1564 #endif /* SIGALRM */
1566 #ifndef OPENSSL_NO_MD2
1569 for (j=0; j<SIZE_NUM; j++)
1571 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1573 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1574 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1576 print_result(D_MD2,j,count,d);
1580 #ifndef OPENSSL_NO_MDC2
1583 for (j=0; j<SIZE_NUM; j++)
1585 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1587 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1588 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1590 print_result(D_MDC2,j,count,d);
1595 #ifndef OPENSSL_NO_MD4
1598 for (j=0; j<SIZE_NUM; j++)
1600 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1602 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1603 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1605 print_result(D_MD4,j,count,d);
1610 #ifndef OPENSSL_NO_MD5
1613 for (j=0; j<SIZE_NUM; j++)
1615 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1617 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1618 MD5(buf,lengths[j],md5);
1620 print_result(D_MD5,j,count,d);
1625 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1630 HMAC_CTX_init(&hctx);
1631 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1632 16,EVP_md5(), NULL);
1634 for (j=0; j<SIZE_NUM; j++)
1636 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1638 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1640 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1641 HMAC_Update(&hctx,buf,lengths[j]);
1642 HMAC_Final(&hctx,&(hmac[0]),NULL);
1645 print_result(D_HMAC,j,count,d);
1647 HMAC_CTX_cleanup(&hctx);
1650 #ifndef OPENSSL_NO_SHA
1653 for (j=0; j<SIZE_NUM; j++)
1655 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1657 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1659 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1661 SHA1(buf,lengths[j],sha);
1664 print_result(D_SHA1,j,count,d);
1668 #ifndef OPENSSL_NO_SHA256
1671 for (j=0; j<SIZE_NUM; j++)
1673 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1675 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1676 SHA256(buf,lengths[j],sha256);
1678 print_result(D_SHA256,j,count,d);
1683 #ifndef OPENSSL_NO_SHA512
1686 for (j=0; j<SIZE_NUM; j++)
1688 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1690 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1691 SHA512(buf,lengths[j],sha512);
1693 print_result(D_SHA512,j,count,d);
1699 #ifndef OPENSSL_NO_WHIRLPOOL
1700 if (doit[D_WHIRLPOOL])
1702 for (j=0; j<SIZE_NUM; j++)
1704 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1706 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1707 WHIRLPOOL(buf,lengths[j],whirlpool);
1709 print_result(D_WHIRLPOOL,j,count,d);
1714 #ifndef OPENSSL_NO_RMD160
1717 for (j=0; j<SIZE_NUM; j++)
1719 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1721 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1722 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1724 print_result(D_RMD160,j,count,d);
1728 #ifndef OPENSSL_NO_RC4
1731 for (j=0; j<SIZE_NUM; j++)
1733 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1735 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1736 RC4(&rc4_ks,(unsigned int)lengths[j],
1739 print_result(D_RC4,j,count,d);
1743 #ifndef OPENSSL_NO_DES
1744 if (doit[D_CBC_DES])
1746 for (j=0; j<SIZE_NUM; j++)
1748 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1750 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1751 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1752 &DES_iv,DES_ENCRYPT);
1754 print_result(D_CBC_DES,j,count,d);
1758 if (doit[D_EDE3_DES])
1760 for (j=0; j<SIZE_NUM; j++)
1762 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1764 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1765 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1767 &DES_iv,DES_ENCRYPT);
1769 print_result(D_EDE3_DES,j,count,d);
1773 #ifndef OPENSSL_NO_AES
1774 if (doit[D_CBC_128_AES])
1776 for (j=0; j<SIZE_NUM; j++)
1778 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1780 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1781 AES_cbc_encrypt(buf,buf,
1782 (unsigned long)lengths[j],&aes_ks1,
1785 print_result(D_CBC_128_AES,j,count,d);
1788 if (doit[D_CBC_192_AES])
1790 for (j=0; j<SIZE_NUM; j++)
1792 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1794 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1795 AES_cbc_encrypt(buf,buf,
1796 (unsigned long)lengths[j],&aes_ks2,
1799 print_result(D_CBC_192_AES,j,count,d);
1802 if (doit[D_CBC_256_AES])
1804 for (j=0; j<SIZE_NUM; j++)
1806 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1808 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1809 AES_cbc_encrypt(buf,buf,
1810 (unsigned long)lengths[j],&aes_ks3,
1813 print_result(D_CBC_256_AES,j,count,d);
1817 if (doit[D_IGE_128_AES])
1819 for (j=0; j<SIZE_NUM; j++)
1821 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1823 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1824 AES_ige_encrypt(buf,buf2,
1825 (unsigned long)lengths[j],&aes_ks1,
1828 print_result(D_IGE_128_AES,j,count,d);
1831 if (doit[D_IGE_192_AES])
1833 for (j=0; j<SIZE_NUM; j++)
1835 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1837 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1838 AES_ige_encrypt(buf,buf2,
1839 (unsigned long)lengths[j],&aes_ks2,
1842 print_result(D_IGE_192_AES,j,count,d);
1845 if (doit[D_IGE_256_AES])
1847 for (j=0; j<SIZE_NUM; j++)
1849 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1851 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1852 AES_ige_encrypt(buf,buf2,
1853 (unsigned long)lengths[j],&aes_ks3,
1856 print_result(D_IGE_256_AES,j,count,d);
1861 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1862 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1864 for (j=0; j<SIZE_NUM; j++)
1866 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1868 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1869 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1871 print_result(D_GHASH,j,count,d);
1873 CRYPTO_gcm128_release(ctx);
1877 #ifndef OPENSSL_NO_CAMELLIA
1878 if (doit[D_CBC_128_CML])
1880 for (j=0; j<SIZE_NUM; j++)
1882 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1884 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1885 Camellia_cbc_encrypt(buf,buf,
1886 (unsigned long)lengths[j],&camellia_ks1,
1887 iv,CAMELLIA_ENCRYPT);
1889 print_result(D_CBC_128_CML,j,count,d);
1892 if (doit[D_CBC_192_CML])
1894 for (j=0; j<SIZE_NUM; j++)
1896 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1898 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1899 Camellia_cbc_encrypt(buf,buf,
1900 (unsigned long)lengths[j],&camellia_ks2,
1901 iv,CAMELLIA_ENCRYPT);
1903 print_result(D_CBC_192_CML,j,count,d);
1906 if (doit[D_CBC_256_CML])
1908 for (j=0; j<SIZE_NUM; j++)
1910 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1912 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1913 Camellia_cbc_encrypt(buf,buf,
1914 (unsigned long)lengths[j],&camellia_ks3,
1915 iv,CAMELLIA_ENCRYPT);
1917 print_result(D_CBC_256_CML,j,count,d);
1922 #ifndef OPENSSL_NO_IDEA
1923 if (doit[D_CBC_IDEA])
1925 for (j=0; j<SIZE_NUM; j++)
1927 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1929 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1930 idea_cbc_encrypt(buf,buf,
1931 (unsigned long)lengths[j],&idea_ks,
1934 print_result(D_CBC_IDEA,j,count,d);
1938 #ifndef OPENSSL_NO_SEED
1939 if (doit[D_CBC_SEED])
1941 for (j=0; j<SIZE_NUM; j++)
1943 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1945 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1946 SEED_cbc_encrypt(buf,buf,
1947 (unsigned long)lengths[j],&seed_ks,iv,1);
1949 print_result(D_CBC_SEED,j,count,d);
1953 #ifndef OPENSSL_NO_RC2
1954 if (doit[D_CBC_RC2])
1956 for (j=0; j<SIZE_NUM; j++)
1958 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1960 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1961 RC2_cbc_encrypt(buf,buf,
1962 (unsigned long)lengths[j],&rc2_ks,
1965 print_result(D_CBC_RC2,j,count,d);
1969 #ifndef OPENSSL_NO_RC5
1970 if (doit[D_CBC_RC5])
1972 for (j=0; j<SIZE_NUM; j++)
1974 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1976 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1977 RC5_32_cbc_encrypt(buf,buf,
1978 (unsigned long)lengths[j],&rc5_ks,
1981 print_result(D_CBC_RC5,j,count,d);
1985 #ifndef OPENSSL_NO_BF
1988 for (j=0; j<SIZE_NUM; j++)
1990 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1992 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1993 BF_cbc_encrypt(buf,buf,
1994 (unsigned long)lengths[j],&bf_ks,
1997 print_result(D_CBC_BF,j,count,d);
2001 #ifndef OPENSSL_NO_CAST
2002 if (doit[D_CBC_CAST])
2004 for (j=0; j<SIZE_NUM; j++)
2006 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
2008 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
2009 CAST_cbc_encrypt(buf,buf,
2010 (unsigned long)lengths[j],&cast_ks,
2013 print_result(D_CBC_CAST,j,count,d);
2020 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
2021 if (multiblock && evp_cipher)
2023 if (!(EVP_CIPHER_flags(evp_cipher)&EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK))
2025 fprintf(stderr,"%s is not multi-block capable\n",OBJ_nid2ln(evp_cipher->nid));
2028 multiblock_speed(evp_cipher);
2033 for (j=0; j<SIZE_NUM; j++)
2040 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2041 /* -O3 -fschedule-insns messes up an
2042 * optimization here! names[D_EVP]
2043 * somehow becomes NULL */
2044 print_message(names[D_EVP],save_count,
2047 EVP_CIPHER_CTX_init(&ctx);
2049 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2051 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2052 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2056 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2057 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2059 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2060 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2062 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2064 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2066 EVP_CIPHER_CTX_cleanup(&ctx);
2070 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2071 print_message(names[D_EVP],save_count,
2075 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2076 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2080 print_result(D_EVP,j,count,d);
2083 #ifndef OPENSSL_SYS_WIN32
2085 RAND_pseudo_bytes(buf,36);
2086 #ifndef OPENSSL_NO_RSA
2087 for (j=0; j<RSA_NUM; j++)
2090 if (!rsa_doit[j]) continue;
2091 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2094 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2095 ERR_print_errors(bio_err);
2100 pkey_print_message("private","rsa",
2101 rsa_c[j][0],rsa_bits[j],
2103 /* RSA_blinding_on(rsa_key[j],NULL); */
2105 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2107 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2108 &rsa_num, rsa_key[j]);
2112 "RSA sign failure\n");
2113 ERR_print_errors(bio_err);
2120 mr ? "+R1:%ld:%d:%.2f\n"
2121 : "%ld %d bit private RSA's in %.2fs\n",
2122 count,rsa_bits[j],d);
2123 rsa_results[j][0]=d/(double)count;
2128 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2131 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2132 ERR_print_errors(bio_err);
2137 pkey_print_message("public","rsa",
2138 rsa_c[j][1],rsa_bits[j],
2141 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2143 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2144 rsa_num, rsa_key[j]);
2148 "RSA verify failure\n");
2149 ERR_print_errors(bio_err);
2156 mr ? "+R2:%ld:%d:%.2f\n"
2157 : "%ld %d bit public RSA's in %.2fs\n",
2158 count,rsa_bits[j],d);
2159 rsa_results[j][1]=d/(double)count;
2165 /* if longer than 10s, don't do any more */
2166 for (j++; j<RSA_NUM; j++)
2172 RAND_pseudo_bytes(buf,20);
2173 #ifndef OPENSSL_NO_DSA
2174 if (RAND_status() != 1)
2176 RAND_seed(rnd_seed, sizeof rnd_seed);
2179 for (j=0; j<DSA_NUM; j++)
2184 if (!dsa_doit[j]) continue;
2186 /* DSA_generate_key(dsa_key[j]); */
2187 /* DSA_sign_setup(dsa_key[j],NULL); */
2188 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2192 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2193 ERR_print_errors(bio_err);
2198 pkey_print_message("sign","dsa",
2199 dsa_c[j][0],dsa_bits[j],
2202 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2204 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2209 "DSA sign failure\n");
2210 ERR_print_errors(bio_err);
2217 mr ? "+R3:%ld:%d:%.2f\n"
2218 : "%ld %d bit DSA signs in %.2fs\n",
2219 count,dsa_bits[j],d);
2220 dsa_results[j][0]=d/(double)count;
2224 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2228 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2229 ERR_print_errors(bio_err);
2234 pkey_print_message("verify","dsa",
2235 dsa_c[j][1],dsa_bits[j],
2238 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2240 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2245 "DSA verify failure\n");
2246 ERR_print_errors(bio_err);
2253 mr ? "+R4:%ld:%d:%.2f\n"
2254 : "%ld %d bit DSA verify in %.2fs\n",
2255 count,dsa_bits[j],d);
2256 dsa_results[j][1]=d/(double)count;
2261 /* if longer than 10s, don't do any more */
2262 for (j++; j<DSA_NUM; j++)
2266 if (rnd_fake) RAND_cleanup();
2269 #ifndef OPENSSL_NO_ECDSA
2270 if (RAND_status() != 1)
2272 RAND_seed(rnd_seed, sizeof rnd_seed);
2275 for (j=0; j<EC_NUM; j++)
2279 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2280 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2281 if (ecdsa[j] == NULL)
2283 BIO_printf(bio_err,"ECDSA failure.\n");
2284 ERR_print_errors(bio_err);
2290 EC_KEY_precompute_mult(ecdsa[j], NULL);
2292 /* Perform ECDSA signature test */
2293 EC_KEY_generate_key(ecdsa[j]);
2294 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2295 &ecdsasiglen, ecdsa[j]);
2298 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2299 ERR_print_errors(bio_err);
2304 pkey_print_message("sign","ecdsa",
2306 test_curves_bits[j],
2310 for (count=0,run=1; COND(ecdsa_c[j][0]);
2313 ret=ECDSA_sign(0, buf, 20,
2314 ecdsasig, &ecdsasiglen,
2318 BIO_printf(bio_err, "ECDSA sign failure\n");
2319 ERR_print_errors(bio_err);
2327 mr ? "+R5:%ld:%d:%.2f\n" :
2328 "%ld %d bit ECDSA signs in %.2fs \n",
2329 count, test_curves_bits[j], d);
2330 ecdsa_results[j][0]=d/(double)count;
2334 /* Perform ECDSA verification test */
2335 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2336 ecdsasiglen, ecdsa[j]);
2339 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2340 ERR_print_errors(bio_err);
2345 pkey_print_message("verify","ecdsa",
2347 test_curves_bits[j],
2350 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2352 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2355 BIO_printf(bio_err, "ECDSA verify failure\n");
2356 ERR_print_errors(bio_err);
2363 mr ? "+R6:%ld:%d:%.2f\n"
2364 : "%ld %d bit ECDSA verify in %.2fs\n",
2365 count, test_curves_bits[j], d);
2366 ecdsa_results[j][1]=d/(double)count;
2371 /* if longer than 10s, don't do any more */
2372 for (j++; j<EC_NUM; j++)
2377 if (rnd_fake) RAND_cleanup();
2380 #ifndef OPENSSL_NO_ECDH
2381 if (RAND_status() != 1)
2383 RAND_seed(rnd_seed, sizeof rnd_seed);
2386 for (j=0; j<EC_NUM; j++)
2388 if (!ecdh_doit[j]) continue;
2389 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2390 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2391 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2393 BIO_printf(bio_err,"ECDH failure.\n");
2394 ERR_print_errors(bio_err);
2399 /* generate two ECDH key pairs */
2400 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2401 !EC_KEY_generate_key(ecdh_b[j]))
2403 BIO_printf(bio_err,"ECDH key generation failure.\n");
2404 ERR_print_errors(bio_err);
2409 /* If field size is not more than 24 octets,
2410 * then use SHA-1 hash of result; otherwise,
2411 * use result (see section 4.8 of
2412 * draft-ietf-tls-ecc-03.txt).
2414 int field_size, outlen;
2415 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2416 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2417 if (field_size <= 24 * 8)
2419 outlen = KDF1_SHA1_len;
2424 outlen = (field_size+7)/8;
2428 ECDH_compute_key(secret_a, outlen,
2429 EC_KEY_get0_public_key(ecdh_b[j]),
2432 ECDH_compute_key(secret_b, outlen,
2433 EC_KEY_get0_public_key(ecdh_a[j]),
2435 if (secret_size_a != secret_size_b)
2440 for (secret_idx = 0;
2441 (secret_idx < secret_size_a)
2442 && (ecdh_checks == 1);
2445 if (secret_a[secret_idx] != secret_b[secret_idx])
2449 if (ecdh_checks == 0)
2451 BIO_printf(bio_err,"ECDH computations don't match.\n");
2452 ERR_print_errors(bio_err);
2456 pkey_print_message("","ecdh",
2458 test_curves_bits[j],
2461 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2463 ECDH_compute_key(secret_a, outlen,
2464 EC_KEY_get0_public_key(ecdh_b[j]),
2469 mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2470 count, test_curves_bits[j], d);
2471 ecdh_results[j][0]=d/(double)count;
2479 /* if longer than 10s, don't do any more */
2480 for (j++; j<EC_NUM; j++)
2484 if (rnd_fake) RAND_cleanup();
2491 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2492 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2494 printf("%s ",BN_options());
2495 #ifndef OPENSSL_NO_MD2
2496 printf("%s ",MD2_options());
2498 #ifndef OPENSSL_NO_RC4
2499 printf("%s ",RC4_options());
2501 #ifndef OPENSSL_NO_DES
2502 printf("%s ",DES_options());
2504 #ifndef OPENSSL_NO_AES
2505 printf("%s ",AES_options());
2507 #ifndef OPENSSL_NO_IDEA
2508 printf("%s ",idea_options());
2510 #ifndef OPENSSL_NO_BF
2511 printf("%s ",BF_options());
2513 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2519 fprintf(stdout,"+H");
2522 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2523 fprintf(stdout,"type ");
2525 for (j=0; j<SIZE_NUM; j++)
2526 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2527 fprintf(stdout,"\n");
2530 for (k=0; k<ALGOR_NUM; k++)
2532 if (!doit[k]) continue;
2534 fprintf(stdout,"+F:%d:%s",k,names[k]);
2536 fprintf(stdout,"%-13s",names[k]);
2537 for (j=0; j<SIZE_NUM; j++)
2539 if (results[k][j] > 10000 && !mr)
2540 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2542 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2544 fprintf(stdout,"\n");
2546 #ifndef OPENSSL_NO_RSA
2548 for (k=0; k<RSA_NUM; k++)
2550 if (!rsa_doit[k]) continue;
2553 printf("%18ssign verify sign/s verify/s\n"," ");
2557 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2558 k,rsa_bits[k],rsa_results[k][0],
2561 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2562 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2563 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2566 #ifndef OPENSSL_NO_DSA
2568 for (k=0; k<DSA_NUM; k++)
2570 if (!dsa_doit[k]) continue;
2573 printf("%18ssign verify sign/s verify/s\n"," ");
2577 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2578 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2580 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2581 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2582 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2585 #ifndef OPENSSL_NO_ECDSA
2587 for (k=0; k<EC_NUM; k++)
2589 if (!ecdsa_doit[k]) continue;
2592 printf("%30ssign verify sign/s verify/s\n"," ");
2597 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2598 k, test_curves_bits[k],
2599 ecdsa_results[k][0],ecdsa_results[k][1]);
2602 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2603 test_curves_bits[k],
2604 test_curves_names[k],
2605 ecdsa_results[k][0],ecdsa_results[k][1],
2606 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2611 #ifndef OPENSSL_NO_ECDH
2613 for (k=0; k<EC_NUM; k++)
2615 if (!ecdh_doit[k]) continue;
2618 printf("%30sop op/s\n"," ");
2622 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2623 k, test_curves_bits[k],
2624 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2627 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2628 test_curves_bits[k],
2629 test_curves_names[k],
2630 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2637 ERR_print_errors(bio_err);
2638 if (buf_malloc != NULL) OPENSSL_free(buf_malloc);
2639 if (buf2_malloc != NULL) OPENSSL_free(buf2_malloc);
2640 #ifndef OPENSSL_NO_RSA
2641 for (i=0; i<RSA_NUM; i++)
2642 if (rsa_key[i] != NULL)
2643 RSA_free(rsa_key[i]);
2645 #ifndef OPENSSL_NO_DSA
2646 for (i=0; i<DSA_NUM; i++)
2647 if (dsa_key[i] != NULL)
2648 DSA_free(dsa_key[i]);
2651 #ifndef OPENSSL_NO_ECDSA
2652 for (i=0; i<EC_NUM; i++)
2653 if (ecdsa[i] != NULL)
2654 EC_KEY_free(ecdsa[i]);
2656 #ifndef OPENSSL_NO_ECDH
2657 for (i=0; i<EC_NUM; i++)
2659 if (ecdh_a[i] != NULL)
2660 EC_KEY_free(ecdh_a[i]);
2661 if (ecdh_b[i] != NULL)
2662 EC_KEY_free(ecdh_b[i]);
2670 static void print_message(const char *s, long num, int length)
2674 mr ? "+DT:%s:%d:%d\n"
2675 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2676 (void)BIO_flush(bio_err);
2680 mr ? "+DN:%s:%ld:%d\n"
2681 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2682 (void)BIO_flush(bio_err);
2686 static void pkey_print_message(const char *str, const char *str2, long num,
2691 mr ? "+DTP:%d:%s:%s:%d\n"
2692 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2693 (void)BIO_flush(bio_err);
2697 mr ? "+DNP:%ld:%d:%s:%s\n"
2698 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2699 (void)BIO_flush(bio_err);
2703 static void print_result(int alg,int run_no,int count,double time_used)
2706 mr ? "+R:%d:%s:%f\n"
2707 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2708 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2712 static char *sstrsep(char **string, const char *delim)
2715 char *token = *string;
2720 memset(isdelim, 0, sizeof isdelim);
2725 isdelim[(unsigned char)(*delim)] = 1;
2729 while (!isdelim[(unsigned char)(**string)])
2743 static int do_multi(int multi)
2748 static char sep[]=":";
2750 fds=malloc(multi*sizeof *fds);
2751 for(n=0 ; n < multi ; ++n)
2755 fprintf(stderr, "pipe failure\n");
2769 if (dup(fd[1]) == -1)
2771 fprintf(stderr, "dup failed\n");
2780 printf("Forked child %d\n",n);
2783 /* for now, assume the pipe is long enough to take all the output */
2784 for(n=0 ; n < multi ; ++n)
2790 f=fdopen(fds[n],"r");
2791 while(fgets(buf,sizeof buf,f))
2798 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2802 printf("Got: %s from %d\n",buf,n);
2803 if(!strncmp(buf,"+F:",3))
2809 alg=atoi(sstrsep(&p,sep));
2811 for(j=0 ; j < SIZE_NUM ; ++j)
2812 results[alg][j]+=atof(sstrsep(&p,sep));
2814 else if(!strncmp(buf,"+F2:",4))
2820 k=atoi(sstrsep(&p,sep));
2823 d=atof(sstrsep(&p,sep));
2825 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2827 rsa_results[k][0]=d;
2829 d=atof(sstrsep(&p,sep));
2831 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2833 rsa_results[k][1]=d;
2835 else if(!strncmp(buf,"+F2:",4))
2841 k=atoi(sstrsep(&p,sep));
2844 d=atof(sstrsep(&p,sep));
2846 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2848 rsa_results[k][0]=d;
2850 d=atof(sstrsep(&p,sep));
2852 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2854 rsa_results[k][1]=d;
2856 #ifndef OPENSSL_NO_DSA
2857 else if(!strncmp(buf,"+F3:",4))
2863 k=atoi(sstrsep(&p,sep));
2866 d=atof(sstrsep(&p,sep));
2868 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2870 dsa_results[k][0]=d;
2872 d=atof(sstrsep(&p,sep));
2874 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2876 dsa_results[k][1]=d;
2879 #ifndef OPENSSL_NO_ECDSA
2880 else if(!strncmp(buf,"+F4:",4))
2886 k=atoi(sstrsep(&p,sep));
2889 d=atof(sstrsep(&p,sep));
2891 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2893 ecdsa_results[k][0]=d;
2895 d=atof(sstrsep(&p,sep));
2897 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2899 ecdsa_results[k][1]=d;
2903 #ifndef OPENSSL_NO_ECDH
2904 else if(!strncmp(buf,"+F5:",4))
2910 k=atoi(sstrsep(&p,sep));
2913 d=atof(sstrsep(&p,sep));
2915 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2917 ecdh_results[k][0]=d;
2922 else if(!strncmp(buf,"+H:",3))
2926 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2936 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2938 static int mblengths[]={8*1024,2*8*1024,4*8*1024,8*8*1024,8*16*1024};
2939 int j,count,num=sizeof(lengths)/sizeof(lengths[0]);
2940 const char *alg_name;
2941 unsigned char *inp,*out,no_key[32],no_iv[16];
2945 inp = OPENSSL_malloc(mblengths[num-1]);
2946 out = OPENSSL_malloc(mblengths[num-1]+1024);
2948 EVP_CIPHER_CTX_init(&ctx);
2949 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,no_key,no_iv);
2950 EVP_CIPHER_CTX_ctrl(&ctx,EVP_CTRL_AEAD_SET_MAC_KEY,sizeof(no_key),no_key);
2951 alg_name=OBJ_nid2ln(evp_cipher->nid);
2953 for (j=0; j<num; j++)
2955 print_message(alg_name,0,mblengths[j]);
2957 for (count=0,run=1; run && count<0x7fffffff; count++)
2959 unsigned char aad[13];
2960 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2961 size_t len = mblengths[j];
2964 memset(aad,0,8);/* avoid uninitialized values */
2965 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2966 aad[9] = 3; /* version */
2968 aad[11] = 0; /* length */
2970 mb_param.out = NULL;
2973 mb_param.interleave = 8;
2975 packlen=EVP_CIPHER_CTX_ctrl(&ctx,
2976 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2977 sizeof(mb_param),&mb_param);
2984 EVP_CIPHER_CTX_ctrl(&ctx,
2985 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2986 sizeof(mb_param),&mb_param);
2996 pad=EVP_CIPHER_CTX_ctrl(&ctx,
2997 EVP_CTRL_AEAD_TLS1_AAD,13,aad);
2998 EVP_Cipher(&ctx,out,inp,len+pad);
3003 mr ? "+R:%d:%s:%f\n"
3004 : "%d %s's in %.2fs\n",count,"evp",d);
3005 results[D_EVP][j]=((double)count)/d*mblengths[j];
3010 fprintf(stdout,"+H");
3011 for (j=0; j<num; j++)
3012 fprintf(stdout,":%d",mblengths[j]);
3013 fprintf(stdout,"\n");
3014 fprintf(stdout,"+F:%d:%s",D_EVP,alg_name);
3015 for (j=0; j<num; j++)
3016 fprintf(stdout,":%.2f",results[D_EVP][j]);
3017 fprintf(stdout,"\n");
3021 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
3022 fprintf(stdout,"type ");
3023 for (j=0; j<num; j++)
3024 fprintf(stdout,"%7d bytes",mblengths[j]);
3025 fprintf(stdout,"\n");
3026 fprintf(stdout,"%-24s",alg_name);
3028 for (j=0; j<num; j++)
3030 if (results[D_EVP][j] > 10000)
3031 fprintf(stdout," %11.2fk",results[D_EVP][j]/1e3);
3033 fprintf(stdout," %11.2f ",results[D_EVP][j]);
3035 fprintf(stdout,"\n");