1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
58 /* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
67 * The ECDH and ECDSA speed test software is originally written by
68 * Sumit Gupta of Sun Microsystems Laboratories.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
78 #define RSA_SECONDS 10
79 #define DSA_SECONDS 10
80 #define ECDSA_SECONDS 10
81 #define ECDH_SECONDS 10
83 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
84 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
87 #define PROG speed_main
95 #ifdef OPENSSL_NO_STDIO
98 #include <openssl/crypto.h>
99 #include <openssl/rand.h>
100 #include <openssl/err.h>
101 #include <openssl/evp.h>
102 #include <openssl/objects.h>
103 #if !defined(OPENSSL_SYS_MSDOS)
104 #include OPENSSL_UNISTD
107 #ifndef OPENSSL_SYS_NETWARE
111 #if defined(_WIN32) || defined(__CYGWIN__)
113 # if defined(__CYGWIN__) && !defined(_WIN32)
114 /* <windows.h> should define _WIN32, which normally is mutually
115 * exclusive with __CYGWIN__, but if it didn't... */
117 /* this is done because Cygwin alarm() fails sometimes. */
121 #include <openssl/bn.h>
122 #ifndef OPENSSL_NO_DES
123 #include <openssl/des.h>
125 #ifndef OPENSSL_NO_AES
126 #include <openssl/aes.h>
128 #ifndef OPENSSL_NO_CAMELLIA
129 #include <openssl/camellia.h>
131 #ifndef OPENSSL_NO_MD2
132 #include <openssl/md2.h>
134 #ifndef OPENSSL_NO_MDC2
135 #include <openssl/mdc2.h>
137 #ifndef OPENSSL_NO_MD4
138 #include <openssl/md4.h>
140 #ifndef OPENSSL_NO_MD5
141 #include <openssl/md5.h>
143 #ifndef OPENSSL_NO_HMAC
144 #include <openssl/hmac.h>
146 #include <openssl/evp.h>
147 #ifndef OPENSSL_NO_SHA
148 #include <openssl/sha.h>
150 #ifndef OPENSSL_NO_RIPEMD
151 #include <openssl/ripemd.h>
153 #ifndef OPENSSL_NO_WHIRLPOOL
154 #include <openssl/whrlpool.h>
156 #ifndef OPENSSL_NO_RC4
157 #include <openssl/rc4.h>
159 #ifndef OPENSSL_NO_RC5
160 #include <openssl/rc5.h>
162 #ifndef OPENSSL_NO_RC2
163 #include <openssl/rc2.h>
165 #ifndef OPENSSL_NO_IDEA
166 #include <openssl/idea.h>
168 #ifndef OPENSSL_NO_SEED
169 #include <openssl/seed.h>
171 #ifndef OPENSSL_NO_BF
172 #include <openssl/blowfish.h>
174 #ifndef OPENSSL_NO_CAST
175 #include <openssl/cast.h>
177 #ifndef OPENSSL_NO_RSA
178 #include <openssl/rsa.h>
179 #include "./testrsa.h"
181 #include <openssl/x509.h>
182 #ifndef OPENSSL_NO_DSA
183 #include <openssl/dsa.h>
184 #include "./testdsa.h"
186 #ifndef OPENSSL_NO_ECDSA
187 #include <openssl/ecdsa.h>
189 #ifndef OPENSSL_NO_ECDH
190 #include <openssl/ecdh.h>
192 #include <openssl/modes.h>
195 #ifdef OPENSSL_DOING_MAKEDEPEND
196 #undef AES_set_encrypt_key
197 #undef AES_set_decrypt_key
198 #undef DES_set_key_unchecked
200 #define BF_set_key private_BF_set_key
201 #define CAST_set_key private_CAST_set_key
202 #define idea_set_encrypt_key private_idea_set_encrypt_key
203 #define SEED_set_key private_SEED_set_key
204 #define RC2_set_key private_RC2_set_key
205 #define RC4_set_key private_RC4_set_key
206 #define DES_set_key_unchecked private_DES_set_key_unchecked
207 #define AES_set_encrypt_key private_AES_set_encrypt_key
208 #define AES_set_decrypt_key private_AES_set_decrypt_key
209 #define Camellia_set_key private_Camellia_set_key
213 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
227 #define BUFSIZE ((long)1024*8+1)
228 static volatile int run=0;
231 static int usertime=1;
233 static double Time_F(int s);
234 static void print_message(const char *s,long num,int length);
235 static void pkey_print_message(const char *str, const char *str2,
236 long num, int bits, int sec);
237 static void print_result(int alg,int run_no,int count,double time_used);
239 static int do_multi(int multi);
248 #define MAX_ECDH_SIZE 256
250 static const char *names[ALGOR_NUM]={
251 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
252 "des cbc","des ede3","idea cbc","seed cbc",
253 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
254 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
255 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
256 "evp","sha256","sha512","whirlpool",
257 "aes-128 ige","aes-192 ige","aes-256 ige","ghash" };
258 static double results[ALGOR_NUM][SIZE_NUM];
259 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
260 #ifndef OPENSSL_NO_RSA
261 static double rsa_results[RSA_NUM][2];
263 #ifndef OPENSSL_NO_DSA
264 static double dsa_results[DSA_NUM][2];
266 #ifndef OPENSSL_NO_ECDSA
267 static double ecdsa_results[EC_NUM][2];
269 #ifndef OPENSSL_NO_ECDH
270 static double ecdh_results[EC_NUM][1];
273 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
274 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
275 static int rnd_fake = 0;
279 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
280 #define SIGRETTYPE void
282 #define SIGRETTYPE int
285 static SIGRETTYPE sig_done(int sig);
286 static SIGRETTYPE sig_done(int sig)
288 signal(SIGALRM,sig_done);
301 #if !defined(SIGALRM)
304 static unsigned int lapse,schlock;
305 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
306 #define alarm alarm_win32
308 static DWORD WINAPI sleepy(VOID *arg)
316 static double Time_F(int s)
322 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
325 DWORD ret=GetLastError();
326 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
329 CloseHandle(thr); /* detach the thread */
330 while (!schlock) Sleep(0); /* scheduler spinlock */
333 return app_tminterval(s,usertime);
337 static double Time_F(int s)
339 return app_tminterval(s,usertime);
344 #ifndef OPENSSL_NO_ECDH
345 static const int KDF1_SHA1_len = 20;
346 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
348 #ifndef OPENSSL_NO_SHA
349 if (*outlen < SHA_DIGEST_LENGTH)
352 *outlen = SHA_DIGEST_LENGTH;
353 return SHA1(in, inlen, out);
356 #endif /* OPENSSL_NO_SHA */
358 #endif /* OPENSSL_NO_ECDH */
360 static void multiblock_speed(const EVP_CIPHER *evp_cipher);
362 int MAIN(int, char **);
364 int MAIN(int argc, char **argv)
366 unsigned char *buf=NULL,*buf2=NULL;
368 long count=0,save_count=0;
370 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
373 #ifndef OPENSSL_NO_RSA
376 unsigned char md[EVP_MAX_MD_SIZE];
377 #ifndef OPENSSL_NO_MD2
378 unsigned char md2[MD2_DIGEST_LENGTH];
380 #ifndef OPENSSL_NO_MDC2
381 unsigned char mdc2[MDC2_DIGEST_LENGTH];
383 #ifndef OPENSSL_NO_MD4
384 unsigned char md4[MD4_DIGEST_LENGTH];
386 #ifndef OPENSSL_NO_MD5
387 unsigned char md5[MD5_DIGEST_LENGTH];
388 unsigned char hmac[MD5_DIGEST_LENGTH];
390 #ifndef OPENSSL_NO_SHA
391 unsigned char sha[SHA_DIGEST_LENGTH];
392 #ifndef OPENSSL_NO_SHA256
393 unsigned char sha256[SHA256_DIGEST_LENGTH];
395 #ifndef OPENSSL_NO_SHA512
396 unsigned char sha512[SHA512_DIGEST_LENGTH];
399 #ifndef OPENSSL_NO_WHIRLPOOL
400 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
402 #ifndef OPENSSL_NO_RIPEMD
403 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
405 #ifndef OPENSSL_NO_RC4
408 #ifndef OPENSSL_NO_RC5
411 #ifndef OPENSSL_NO_RC2
414 #ifndef OPENSSL_NO_IDEA
415 IDEA_KEY_SCHEDULE idea_ks;
417 #ifndef OPENSSL_NO_SEED
418 SEED_KEY_SCHEDULE seed_ks;
420 #ifndef OPENSSL_NO_BF
423 #ifndef OPENSSL_NO_CAST
426 static const unsigned char key16[16]= {
427 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
428 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
429 #ifndef OPENSSL_NO_AES
430 static const unsigned char key24[24]= {
431 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
432 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
433 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
434 static const unsigned char key32[32]= {
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 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
440 #ifndef OPENSSL_NO_CAMELLIA
441 static const unsigned char ckey24[24]= {
442 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
443 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
444 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
445 static const unsigned char ckey32[32]= {
446 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
447 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
448 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
449 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
451 #ifndef OPENSSL_NO_AES
452 #define MAX_BLOCK_SIZE 128
454 #define MAX_BLOCK_SIZE 64
456 unsigned char DES_iv[8];
457 unsigned char iv[2*MAX_BLOCK_SIZE/8];
458 #ifndef OPENSSL_NO_DES
459 static DES_cblock key = { 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0 };
460 static DES_cblock key2= { 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12 };
461 static DES_cblock key3= { 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34 };
462 DES_key_schedule sch;
463 DES_key_schedule sch2;
464 DES_key_schedule sch3;
466 #ifndef OPENSSL_NO_AES
467 AES_KEY aes_ks1, aes_ks2, aes_ks3;
469 #ifndef OPENSSL_NO_CAMELLIA
470 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
482 #define D_CBC_IDEA 10
483 #define D_CBC_SEED 11
487 #define D_CBC_CAST 15
488 #define D_CBC_128_AES 16
489 #define D_CBC_192_AES 17
490 #define D_CBC_256_AES 18
491 #define D_CBC_128_CML 19
492 #define D_CBC_192_CML 20
493 #define D_CBC_256_CML 21
497 #define D_WHIRLPOOL 25
498 #define D_IGE_128_AES 26
499 #define D_IGE_192_AES 27
500 #define D_IGE_256_AES 28
503 long c[ALGOR_NUM][SIZE_NUM];
529 #ifndef OPENSSL_NO_RSA
530 RSA *rsa_key[RSA_NUM];
531 long rsa_c[RSA_NUM][2];
532 static unsigned int rsa_bits[RSA_NUM]={
534 static unsigned char *rsa_data[RSA_NUM]={
535 test512,test1024,test2048,test4096};
536 static int rsa_data_length[RSA_NUM]={
537 sizeof(test512),sizeof(test1024),
538 sizeof(test2048),sizeof(test4096)};
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;
641 memset(results, 0, sizeof(results));
642 #ifndef OPENSSL_NO_DSA
643 memset(dsa_key,0,sizeof(dsa_key));
645 #ifndef OPENSSL_NO_ECDSA
646 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
648 #ifndef OPENSSL_NO_ECDH
649 for (i=0; i<EC_NUM; i++)
658 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
659 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
661 if (!load_config(bio_err, NULL))
664 #ifndef OPENSSL_NO_RSA
665 memset(rsa_key,0,sizeof(rsa_key));
666 for (i=0; i<RSA_NUM; i++)
670 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
672 BIO_printf(bio_err,"out of memory\n");
675 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
677 BIO_printf(bio_err,"out of memory\n");
681 memset(c,0,sizeof(c));
682 memset(DES_iv,0,sizeof(DES_iv));
683 memset(iv,0,sizeof(iv));
685 for (i=0; i<ALGOR_NUM; i++)
687 for (i=0; i<RSA_NUM; i++)
689 for (i=0; i<DSA_NUM; i++)
691 #ifndef OPENSSL_NO_ECDSA
692 for (i=0; i<EC_NUM; i++)
695 #ifndef OPENSSL_NO_ECDH
696 for (i=0; i<EC_NUM; i++)
706 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
709 j--; /* Otherwise, -elapsed gets confused with
712 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
718 BIO_printf(bio_err,"no EVP given\n");
721 evp_cipher=EVP_get_cipherbyname(*argv);
724 evp_md=EVP_get_digestbyname(*argv);
726 if(!evp_cipher && !evp_md)
728 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
733 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
736 j--; /* Otherwise, -elapsed gets confused with
739 #ifndef OPENSSL_NO_ENGINE
740 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
746 BIO_printf(bio_err,"no engine given\n");
749 setup_engine(bio_err, *argv, 0);
750 /* j will be increased again further down. We just
751 don't want speed to confuse an engine with an
752 algorithm, especially when none is given (which
753 means all of them should be run) */
758 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
764 BIO_printf(bio_err,"no multi count given\n");
770 BIO_printf(bio_err,"bad multi count\n");
773 j--; /* Otherwise, -mr gets confused with
777 else if (argc > 0 && !strcmp(*argv,"-mr"))
780 j--; /* Otherwise, -mr gets confused with
783 else if (argc > 0 && !strcmp(*argv,"-mb"))
789 #ifndef OPENSSL_NO_MD2
790 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
793 #ifndef OPENSSL_NO_MDC2
794 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
797 #ifndef OPENSSL_NO_MD4
798 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
801 #ifndef OPENSSL_NO_MD5
802 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
805 #ifndef OPENSSL_NO_MD5
806 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
809 #ifndef OPENSSL_NO_SHA
810 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
812 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
816 #ifndef OPENSSL_NO_SHA256
817 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
820 #ifndef OPENSSL_NO_SHA512
821 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
825 #ifndef OPENSSL_NO_WHIRLPOOL
826 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
829 #ifndef OPENSSL_NO_RIPEMD
830 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
832 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
834 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
837 #ifndef OPENSSL_NO_RC4
838 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
841 #ifndef OPENSSL_NO_DES
842 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
843 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
846 #ifndef OPENSSL_NO_AES
847 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
848 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
849 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
850 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
851 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
852 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
855 #ifndef OPENSSL_NO_CAMELLIA
856 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
857 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
858 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
861 #ifndef OPENSSL_NO_RSA
862 #if 0 /* was: #ifdef RSAref */
863 if (strcmp(*argv,"rsaref") == 0)
865 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
871 if (strcmp(*argv,"openssl") == 0)
873 RSA_set_default_method(RSA_PKCS1_SSLeay());
878 #endif /* !OPENSSL_NO_RSA */
879 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
880 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
881 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
882 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
883 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
884 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
885 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
887 #ifndef OPENSSL_NO_RC2
888 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
889 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
892 #ifndef OPENSSL_NO_RC5
893 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
894 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
897 #ifndef OPENSSL_NO_IDEA
898 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
899 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
902 #ifndef OPENSSL_NO_SEED
903 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
904 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
907 #ifndef OPENSSL_NO_BF
908 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
909 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
910 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
913 #ifndef OPENSSL_NO_CAST
914 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
915 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
916 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
919 #ifndef OPENSSL_NO_DES
920 if (strcmp(*argv,"des") == 0)
927 #ifndef OPENSSL_NO_AES
928 if (strcmp(*argv,"aes") == 0)
930 doit[D_CBC_128_AES]=1;
931 doit[D_CBC_192_AES]=1;
932 doit[D_CBC_256_AES]=1;
934 else if (strcmp(*argv,"ghash") == 0)
940 #ifndef OPENSSL_NO_CAMELLIA
941 if (strcmp(*argv,"camellia") == 0)
943 doit[D_CBC_128_CML]=1;
944 doit[D_CBC_192_CML]=1;
945 doit[D_CBC_256_CML]=1;
949 #ifndef OPENSSL_NO_RSA
950 if (strcmp(*argv,"rsa") == 0)
952 rsa_doit[R_RSA_512]=1;
953 rsa_doit[R_RSA_1024]=1;
954 rsa_doit[R_RSA_2048]=1;
955 rsa_doit[R_RSA_4096]=1;
959 #ifndef OPENSSL_NO_DSA
960 if (strcmp(*argv,"dsa") == 0)
962 dsa_doit[R_DSA_512]=1;
963 dsa_doit[R_DSA_1024]=1;
964 dsa_doit[R_DSA_2048]=1;
968 #ifndef OPENSSL_NO_ECDSA
969 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
970 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
971 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
972 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
973 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
974 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
975 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
976 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
977 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
978 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
979 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
980 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
981 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
982 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
983 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
984 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
985 else if (strcmp(*argv,"ecdsa") == 0)
987 for (i=0; i < EC_NUM; i++)
992 #ifndef OPENSSL_NO_ECDH
993 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
994 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
995 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
996 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
997 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
998 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
999 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1000 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1001 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1002 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1003 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1004 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1005 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1006 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1007 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1008 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1009 else if (strcmp(*argv,"ecdh") == 0)
1011 for (i=0; i < EC_NUM; i++)
1017 BIO_printf(bio_err,"Error: bad option or value\n");
1018 BIO_printf(bio_err,"\n");
1019 BIO_printf(bio_err,"Available values:\n");
1020 #ifndef OPENSSL_NO_MD2
1021 BIO_printf(bio_err,"md2 ");
1023 #ifndef OPENSSL_NO_MDC2
1024 BIO_printf(bio_err,"mdc2 ");
1026 #ifndef OPENSSL_NO_MD4
1027 BIO_printf(bio_err,"md4 ");
1029 #ifndef OPENSSL_NO_MD5
1030 BIO_printf(bio_err,"md5 ");
1031 #ifndef OPENSSL_NO_HMAC
1032 BIO_printf(bio_err,"hmac ");
1035 #ifndef OPENSSL_NO_SHA1
1036 BIO_printf(bio_err,"sha1 ");
1038 #ifndef OPENSSL_NO_SHA256
1039 BIO_printf(bio_err,"sha256 ");
1041 #ifndef OPENSSL_NO_SHA512
1042 BIO_printf(bio_err,"sha512 ");
1044 #ifndef OPENSSL_NO_WHIRLPOOL
1045 BIO_printf(bio_err,"whirlpool");
1047 #ifndef OPENSSL_NO_RIPEMD160
1048 BIO_printf(bio_err,"rmd160");
1050 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1051 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1052 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1053 !defined(OPENSSL_NO_WHIRLPOOL)
1054 BIO_printf(bio_err,"\n");
1057 #ifndef OPENSSL_NO_IDEA
1058 BIO_printf(bio_err,"idea-cbc ");
1060 #ifndef OPENSSL_NO_SEED
1061 BIO_printf(bio_err,"seed-cbc ");
1063 #ifndef OPENSSL_NO_RC2
1064 BIO_printf(bio_err,"rc2-cbc ");
1066 #ifndef OPENSSL_NO_RC5
1067 BIO_printf(bio_err,"rc5-cbc ");
1069 #ifndef OPENSSL_NO_BF
1070 BIO_printf(bio_err,"bf-cbc");
1072 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1073 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1074 BIO_printf(bio_err,"\n");
1076 #ifndef OPENSSL_NO_DES
1077 BIO_printf(bio_err,"des-cbc des-ede3 ");
1079 #ifndef OPENSSL_NO_AES
1080 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1081 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1083 #ifndef OPENSSL_NO_CAMELLIA
1084 BIO_printf(bio_err,"\n");
1085 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1087 #ifndef OPENSSL_NO_RC4
1088 BIO_printf(bio_err,"rc4");
1090 BIO_printf(bio_err,"\n");
1092 #ifndef OPENSSL_NO_RSA
1093 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1096 #ifndef OPENSSL_NO_DSA
1097 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1099 #ifndef OPENSSL_NO_ECDSA
1100 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 "
1101 "ecdsap256 ecdsap384 ecdsap521\n");
1102 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1103 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1104 BIO_printf(bio_err,"ecdsa\n");
1106 #ifndef OPENSSL_NO_ECDH
1107 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 "
1108 "ecdhp256 ecdhp384 ecdhp521\n");
1109 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1110 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1111 BIO_printf(bio_err,"ecdh\n");
1114 #ifndef OPENSSL_NO_IDEA
1115 BIO_printf(bio_err,"idea ");
1117 #ifndef OPENSSL_NO_SEED
1118 BIO_printf(bio_err,"seed ");
1120 #ifndef OPENSSL_NO_RC2
1121 BIO_printf(bio_err,"rc2 ");
1123 #ifndef OPENSSL_NO_DES
1124 BIO_printf(bio_err,"des ");
1126 #ifndef OPENSSL_NO_AES
1127 BIO_printf(bio_err,"aes ");
1129 #ifndef OPENSSL_NO_CAMELLIA
1130 BIO_printf(bio_err,"camellia ");
1132 #ifndef OPENSSL_NO_RSA
1133 BIO_printf(bio_err,"rsa ");
1135 #ifndef OPENSSL_NO_BF
1136 BIO_printf(bio_err,"blowfish");
1138 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1139 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1140 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1141 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1142 BIO_printf(bio_err,"\n");
1145 BIO_printf(bio_err,"\n");
1146 BIO_printf(bio_err,"Available options:\n");
1147 #if defined(TIMES) || defined(USE_TOD)
1148 BIO_printf(bio_err,"-elapsed "
1149 "measure time in real time instead of CPU user time.\n");
1151 #ifndef OPENSSL_NO_ENGINE
1154 "use engine e, possibly a hardware device.\n");
1161 "time decryption instead of encryption (only EVP).\n");
1164 "produce machine readable output.\n");
1168 "run n benchmarks in parallel.\n");
1178 if(multi && do_multi(multi))
1184 for (i=0; i<ALGOR_NUM; i++)
1189 for (i=0; i<RSA_NUM; i++)
1191 for (i=0; i<DSA_NUM; i++)
1193 #ifndef OPENSSL_NO_ECDSA
1194 for (i=0; i<EC_NUM; i++)
1197 #ifndef OPENSSL_NO_ECDH
1198 for (i=0; i<EC_NUM; i++)
1202 for (i=0; i<ALGOR_NUM; i++)
1203 if (doit[i]) pr_header++;
1205 if (usertime == 0 && !mr)
1207 "You have chosen to measure elapsed time "
1208 "instead of user CPU time.\n");
1210 #ifndef OPENSSL_NO_RSA
1211 for (i=0; i<RSA_NUM; i++)
1213 const unsigned char *p;
1216 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1217 if (rsa_key[i] == NULL)
1219 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1227 : "Loaded RSA key, %d bit modulus and e= 0x",
1228 BN_num_bits(rsa_key[i]->n));
1229 BN_print(bio_err,rsa_key[i]->e);
1230 BIO_printf(bio_err,"\n");
1236 #ifndef OPENSSL_NO_DSA
1237 dsa_key[0]=get_dsa512();
1238 dsa_key[1]=get_dsa1024();
1239 dsa_key[2]=get_dsa2048();
1242 #ifndef OPENSSL_NO_DES
1243 DES_set_key_unchecked(&key,&sch);
1244 DES_set_key_unchecked(&key2,&sch2);
1245 DES_set_key_unchecked(&key3,&sch3);
1247 #ifndef OPENSSL_NO_AES
1248 AES_set_encrypt_key(key16,128,&aes_ks1);
1249 AES_set_encrypt_key(key24,192,&aes_ks2);
1250 AES_set_encrypt_key(key32,256,&aes_ks3);
1252 #ifndef OPENSSL_NO_CAMELLIA
1253 Camellia_set_key(key16,128,&camellia_ks1);
1254 Camellia_set_key(ckey24,192,&camellia_ks2);
1255 Camellia_set_key(ckey32,256,&camellia_ks3);
1257 #ifndef OPENSSL_NO_IDEA
1258 idea_set_encrypt_key(key16,&idea_ks);
1260 #ifndef OPENSSL_NO_SEED
1261 SEED_set_key(key16,&seed_ks);
1263 #ifndef OPENSSL_NO_RC4
1264 RC4_set_key(&rc4_ks,16,key16);
1266 #ifndef OPENSSL_NO_RC2
1267 RC2_set_key(&rc2_ks,16,key16,128);
1269 #ifndef OPENSSL_NO_RC5
1270 RC5_32_set_key(&rc5_ks,16,key16,12);
1272 #ifndef OPENSSL_NO_BF
1273 BF_set_key(&bf_ks,16,key16);
1275 #ifndef OPENSSL_NO_CAST
1276 CAST_set_key(&cast_ks,16,key16);
1278 #ifndef OPENSSL_NO_RSA
1279 memset(rsa_c,0,sizeof(rsa_c));
1282 #ifndef OPENSSL_NO_DES
1283 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1289 for (it=count; it; it--)
1290 DES_ecb_encrypt((DES_cblock *)buf,
1296 c[D_MD2][0]=count/10;
1297 c[D_MDC2][0]=count/10;
1302 c[D_RMD160][0]=count;
1303 c[D_RC4][0]=count*5;
1304 c[D_CBC_DES][0]=count;
1305 c[D_EDE3_DES][0]=count/3;
1306 c[D_CBC_IDEA][0]=count;
1307 c[D_CBC_SEED][0]=count;
1308 c[D_CBC_RC2][0]=count;
1309 c[D_CBC_RC5][0]=count;
1310 c[D_CBC_BF][0]=count;
1311 c[D_CBC_CAST][0]=count;
1312 c[D_CBC_128_AES][0]=count;
1313 c[D_CBC_192_AES][0]=count;
1314 c[D_CBC_256_AES][0]=count;
1315 c[D_CBC_128_CML][0]=count;
1316 c[D_CBC_192_CML][0]=count;
1317 c[D_CBC_256_CML][0]=count;
1318 c[D_SHA256][0]=count;
1319 c[D_SHA512][0]=count;
1320 c[D_WHIRLPOOL][0]=count;
1321 c[D_IGE_128_AES][0]=count;
1322 c[D_IGE_192_AES][0]=count;
1323 c[D_IGE_256_AES][0]=count;
1324 c[D_GHASH][0]=count;
1326 for (i=1; i<SIZE_NUM; i++)
1328 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1329 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1330 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1331 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1332 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1333 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1334 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1335 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1336 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1337 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1339 for (i=1; i<SIZE_NUM; i++)
1343 l0=(long)lengths[i-1];
1344 l1=(long)lengths[i];
1345 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1346 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1347 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1348 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1349 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1350 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1351 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1352 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1353 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1354 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1355 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1356 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1357 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1358 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1359 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1360 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1361 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1362 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1364 #ifndef OPENSSL_NO_RSA
1365 rsa_c[R_RSA_512][0]=count/2000;
1366 rsa_c[R_RSA_512][1]=count/400;
1367 for (i=1; i<RSA_NUM; i++)
1369 rsa_c[i][0]=rsa_c[i-1][0]/8;
1370 rsa_c[i][1]=rsa_c[i-1][1]/4;
1371 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1375 if (rsa_c[i][0] == 0)
1384 #ifndef OPENSSL_NO_DSA
1385 dsa_c[R_DSA_512][0]=count/1000;
1386 dsa_c[R_DSA_512][1]=count/1000/2;
1387 for (i=1; i<DSA_NUM; i++)
1389 dsa_c[i][0]=dsa_c[i-1][0]/4;
1390 dsa_c[i][1]=dsa_c[i-1][1]/4;
1391 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1404 #ifndef OPENSSL_NO_ECDSA
1405 ecdsa_c[R_EC_P160][0]=count/1000;
1406 ecdsa_c[R_EC_P160][1]=count/1000/2;
1407 for (i=R_EC_P192; i<=R_EC_P521; i++)
1409 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1410 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1411 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1415 if (ecdsa_c[i] == 0)
1422 ecdsa_c[R_EC_K163][0]=count/1000;
1423 ecdsa_c[R_EC_K163][1]=count/1000/2;
1424 for (i=R_EC_K233; i<=R_EC_K571; i++)
1426 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1427 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1428 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1432 if (ecdsa_c[i] == 0)
1439 ecdsa_c[R_EC_B163][0]=count/1000;
1440 ecdsa_c[R_EC_B163][1]=count/1000/2;
1441 for (i=R_EC_B233; i<=R_EC_B571; i++)
1443 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1444 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1445 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1449 if (ecdsa_c[i] == 0)
1458 #ifndef OPENSSL_NO_ECDH
1459 ecdh_c[R_EC_P160][0]=count/1000;
1460 ecdh_c[R_EC_P160][1]=count/1000;
1461 for (i=R_EC_P192; i<=R_EC_P521; i++)
1463 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1464 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1465 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1476 ecdh_c[R_EC_K163][0]=count/1000;
1477 ecdh_c[R_EC_K163][1]=count/1000;
1478 for (i=R_EC_K233; i<=R_EC_K571; i++)
1480 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1481 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1482 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1493 ecdh_c[R_EC_B163][0]=count/1000;
1494 ecdh_c[R_EC_B163][1]=count/1000;
1495 for (i=R_EC_B233; i<=R_EC_B571; i++)
1497 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1498 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1499 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1512 #define COND(d) (count < (d))
1513 #define COUNT(d) (d)
1515 /* not worth fixing */
1516 # error "You cannot disable DES on systems without SIGALRM."
1517 #endif /* OPENSSL_NO_DES */
1519 #define COND(c) (run && count<0x7fffffff)
1520 #define COUNT(d) (count)
1522 signal(SIGALRM,sig_done);
1524 #endif /* SIGALRM */
1526 #ifndef OPENSSL_NO_MD2
1529 for (j=0; j<SIZE_NUM; j++)
1531 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1533 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1534 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1536 print_result(D_MD2,j,count,d);
1540 #ifndef OPENSSL_NO_MDC2
1543 for (j=0; j<SIZE_NUM; j++)
1545 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1547 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1548 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1550 print_result(D_MDC2,j,count,d);
1555 #ifndef OPENSSL_NO_MD4
1558 for (j=0; j<SIZE_NUM; j++)
1560 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1562 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1563 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1565 print_result(D_MD4,j,count,d);
1570 #ifndef OPENSSL_NO_MD5
1573 for (j=0; j<SIZE_NUM; j++)
1575 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1577 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1578 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1580 print_result(D_MD5,j,count,d);
1585 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1590 HMAC_CTX_init(&hctx);
1591 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1592 16,EVP_md5(), NULL);
1594 for (j=0; j<SIZE_NUM; j++)
1596 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1598 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1600 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1601 HMAC_Update(&hctx,buf,lengths[j]);
1602 HMAC_Final(&hctx,&(hmac[0]),NULL);
1605 print_result(D_HMAC,j,count,d);
1607 HMAC_CTX_cleanup(&hctx);
1610 #ifndef OPENSSL_NO_SHA
1613 for (j=0; j<SIZE_NUM; j++)
1615 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1617 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1618 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1620 print_result(D_SHA1,j,count,d);
1624 #ifndef OPENSSL_NO_SHA256
1627 for (j=0; j<SIZE_NUM; j++)
1629 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1631 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1632 SHA256(buf,lengths[j],sha256);
1634 print_result(D_SHA256,j,count,d);
1639 #ifndef OPENSSL_NO_SHA512
1642 for (j=0; j<SIZE_NUM; j++)
1644 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1646 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1647 SHA512(buf,lengths[j],sha512);
1649 print_result(D_SHA512,j,count,d);
1655 #ifndef OPENSSL_NO_WHIRLPOOL
1656 if (doit[D_WHIRLPOOL])
1658 for (j=0; j<SIZE_NUM; j++)
1660 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1662 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1663 WHIRLPOOL(buf,lengths[j],whirlpool);
1665 print_result(D_WHIRLPOOL,j,count,d);
1670 #ifndef OPENSSL_NO_RIPEMD
1673 for (j=0; j<SIZE_NUM; j++)
1675 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1677 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1678 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1680 print_result(D_RMD160,j,count,d);
1684 #ifndef OPENSSL_NO_RC4
1687 for (j=0; j<SIZE_NUM; j++)
1689 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1691 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1692 RC4(&rc4_ks,(unsigned int)lengths[j],
1695 print_result(D_RC4,j,count,d);
1699 #ifndef OPENSSL_NO_DES
1700 if (doit[D_CBC_DES])
1702 for (j=0; j<SIZE_NUM; j++)
1704 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1706 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1707 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1708 &DES_iv,DES_ENCRYPT);
1710 print_result(D_CBC_DES,j,count,d);
1714 if (doit[D_EDE3_DES])
1716 for (j=0; j<SIZE_NUM; j++)
1718 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1720 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1721 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1723 &DES_iv,DES_ENCRYPT);
1725 print_result(D_EDE3_DES,j,count,d);
1729 #ifndef OPENSSL_NO_AES
1730 if (doit[D_CBC_128_AES])
1732 for (j=0; j<SIZE_NUM; j++)
1734 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1736 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1737 AES_cbc_encrypt(buf,buf,
1738 (unsigned long)lengths[j],&aes_ks1,
1741 print_result(D_CBC_128_AES,j,count,d);
1744 if (doit[D_CBC_192_AES])
1746 for (j=0; j<SIZE_NUM; j++)
1748 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1750 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1751 AES_cbc_encrypt(buf,buf,
1752 (unsigned long)lengths[j],&aes_ks2,
1755 print_result(D_CBC_192_AES,j,count,d);
1758 if (doit[D_CBC_256_AES])
1760 for (j=0; j<SIZE_NUM; j++)
1762 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1764 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1765 AES_cbc_encrypt(buf,buf,
1766 (unsigned long)lengths[j],&aes_ks3,
1769 print_result(D_CBC_256_AES,j,count,d);
1773 if (doit[D_IGE_128_AES])
1775 for (j=0; j<SIZE_NUM; j++)
1777 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1779 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1780 AES_ige_encrypt(buf,buf2,
1781 (unsigned long)lengths[j],&aes_ks1,
1784 print_result(D_IGE_128_AES,j,count,d);
1787 if (doit[D_IGE_192_AES])
1789 for (j=0; j<SIZE_NUM; j++)
1791 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1793 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1794 AES_ige_encrypt(buf,buf2,
1795 (unsigned long)lengths[j],&aes_ks2,
1798 print_result(D_IGE_192_AES,j,count,d);
1801 if (doit[D_IGE_256_AES])
1803 for (j=0; j<SIZE_NUM; j++)
1805 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1807 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1808 AES_ige_encrypt(buf,buf2,
1809 (unsigned long)lengths[j],&aes_ks3,
1812 print_result(D_IGE_256_AES,j,count,d);
1817 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1818 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1820 for (j=0; j<SIZE_NUM; j++)
1822 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1824 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1825 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1827 print_result(D_GHASH,j,count,d);
1829 CRYPTO_gcm128_release(ctx);
1833 #ifndef OPENSSL_NO_CAMELLIA
1834 if (doit[D_CBC_128_CML])
1836 for (j=0; j<SIZE_NUM; j++)
1838 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1840 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1841 Camellia_cbc_encrypt(buf,buf,
1842 (unsigned long)lengths[j],&camellia_ks1,
1843 iv,CAMELLIA_ENCRYPT);
1845 print_result(D_CBC_128_CML,j,count,d);
1848 if (doit[D_CBC_192_CML])
1850 for (j=0; j<SIZE_NUM; j++)
1852 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1854 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1855 Camellia_cbc_encrypt(buf,buf,
1856 (unsigned long)lengths[j],&camellia_ks2,
1857 iv,CAMELLIA_ENCRYPT);
1859 print_result(D_CBC_192_CML,j,count,d);
1862 if (doit[D_CBC_256_CML])
1864 for (j=0; j<SIZE_NUM; j++)
1866 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1868 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1869 Camellia_cbc_encrypt(buf,buf,
1870 (unsigned long)lengths[j],&camellia_ks3,
1871 iv,CAMELLIA_ENCRYPT);
1873 print_result(D_CBC_256_CML,j,count,d);
1878 #ifndef OPENSSL_NO_IDEA
1879 if (doit[D_CBC_IDEA])
1881 for (j=0; j<SIZE_NUM; j++)
1883 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1885 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1886 idea_cbc_encrypt(buf,buf,
1887 (unsigned long)lengths[j],&idea_ks,
1890 print_result(D_CBC_IDEA,j,count,d);
1894 #ifndef OPENSSL_NO_SEED
1895 if (doit[D_CBC_SEED])
1897 for (j=0; j<SIZE_NUM; j++)
1899 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1901 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1902 SEED_cbc_encrypt(buf,buf,
1903 (unsigned long)lengths[j],&seed_ks,iv,1);
1905 print_result(D_CBC_SEED,j,count,d);
1909 #ifndef OPENSSL_NO_RC2
1910 if (doit[D_CBC_RC2])
1912 for (j=0; j<SIZE_NUM; j++)
1914 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1916 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1917 RC2_cbc_encrypt(buf,buf,
1918 (unsigned long)lengths[j],&rc2_ks,
1921 print_result(D_CBC_RC2,j,count,d);
1925 #ifndef OPENSSL_NO_RC5
1926 if (doit[D_CBC_RC5])
1928 for (j=0; j<SIZE_NUM; j++)
1930 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1932 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1933 RC5_32_cbc_encrypt(buf,buf,
1934 (unsigned long)lengths[j],&rc5_ks,
1937 print_result(D_CBC_RC5,j,count,d);
1941 #ifndef OPENSSL_NO_BF
1944 for (j=0; j<SIZE_NUM; j++)
1946 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1948 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1949 BF_cbc_encrypt(buf,buf,
1950 (unsigned long)lengths[j],&bf_ks,
1953 print_result(D_CBC_BF,j,count,d);
1957 #ifndef OPENSSL_NO_CAST
1958 if (doit[D_CBC_CAST])
1960 for (j=0; j<SIZE_NUM; j++)
1962 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1964 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1965 CAST_cbc_encrypt(buf,buf,
1966 (unsigned long)lengths[j],&cast_ks,
1969 print_result(D_CBC_CAST,j,count,d);
1976 #ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
1977 if (multiblock && evp_cipher)
1979 if (!(EVP_CIPHER_flags(evp_cipher)&EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK))
1981 fprintf(stderr,"%s is not multi-block capable\n",OBJ_nid2ln(evp_cipher->nid));
1984 multiblock_speed(evp_cipher);
1989 for (j=0; j<SIZE_NUM; j++)
1996 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1997 /* -O3 -fschedule-insns messes up an
1998 * optimization here! names[D_EVP]
1999 * somehow becomes NULL */
2000 print_message(names[D_EVP],save_count,
2003 EVP_CIPHER_CTX_init(&ctx);
2005 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2007 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2008 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2012 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2013 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2015 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2016 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2018 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2020 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2022 EVP_CIPHER_CTX_cleanup(&ctx);
2026 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2027 print_message(names[D_EVP],save_count,
2031 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2032 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2036 print_result(D_EVP,j,count,d);
2040 RAND_pseudo_bytes(buf,36);
2041 #ifndef OPENSSL_NO_RSA
2042 for (j=0; j<RSA_NUM; j++)
2045 if (!rsa_doit[j]) continue;
2046 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2049 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2050 ERR_print_errors(bio_err);
2055 pkey_print_message("private","rsa",
2056 rsa_c[j][0],rsa_bits[j],
2058 /* RSA_blinding_on(rsa_key[j],NULL); */
2060 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2062 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2063 &rsa_num, rsa_key[j]);
2067 "RSA sign failure\n");
2068 ERR_print_errors(bio_err);
2075 mr ? "+R1:%ld:%d:%.2f\n"
2076 : "%ld %d bit private RSA's in %.2fs\n",
2077 count,rsa_bits[j],d);
2078 rsa_results[j][0]=d/(double)count;
2083 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2086 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2087 ERR_print_errors(bio_err);
2092 pkey_print_message("public","rsa",
2093 rsa_c[j][1],rsa_bits[j],
2096 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2098 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2099 rsa_num, rsa_key[j]);
2103 "RSA verify failure\n");
2104 ERR_print_errors(bio_err);
2111 mr ? "+R2:%ld:%d:%.2f\n"
2112 : "%ld %d bit public RSA's in %.2fs\n",
2113 count,rsa_bits[j],d);
2114 rsa_results[j][1]=d/(double)count;
2120 /* if longer than 10s, don't do any more */
2121 for (j++; j<RSA_NUM; j++)
2127 RAND_pseudo_bytes(buf,20);
2128 #ifndef OPENSSL_NO_DSA
2129 if (RAND_status() != 1)
2131 RAND_seed(rnd_seed, sizeof rnd_seed);
2134 for (j=0; j<DSA_NUM; j++)
2139 if (!dsa_doit[j]) continue;
2141 /* DSA_generate_key(dsa_key[j]); */
2142 /* DSA_sign_setup(dsa_key[j],NULL); */
2143 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2147 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2148 ERR_print_errors(bio_err);
2153 pkey_print_message("sign","dsa",
2154 dsa_c[j][0],dsa_bits[j],
2157 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2159 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2164 "DSA sign failure\n");
2165 ERR_print_errors(bio_err);
2172 mr ? "+R3:%ld:%d:%.2f\n"
2173 : "%ld %d bit DSA signs in %.2fs\n",
2174 count,dsa_bits[j],d);
2175 dsa_results[j][0]=d/(double)count;
2179 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2183 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2184 ERR_print_errors(bio_err);
2189 pkey_print_message("verify","dsa",
2190 dsa_c[j][1],dsa_bits[j],
2193 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2195 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2200 "DSA verify failure\n");
2201 ERR_print_errors(bio_err);
2208 mr ? "+R4:%ld:%d:%.2f\n"
2209 : "%ld %d bit DSA verify in %.2fs\n",
2210 count,dsa_bits[j],d);
2211 dsa_results[j][1]=d/(double)count;
2216 /* if longer than 10s, don't do any more */
2217 for (j++; j<DSA_NUM; j++)
2221 if (rnd_fake) RAND_cleanup();
2224 #ifndef OPENSSL_NO_ECDSA
2225 if (RAND_status() != 1)
2227 RAND_seed(rnd_seed, sizeof rnd_seed);
2230 for (j=0; j<EC_NUM; j++)
2234 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2235 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2236 if (ecdsa[j] == NULL)
2238 BIO_printf(bio_err,"ECDSA failure.\n");
2239 ERR_print_errors(bio_err);
2245 EC_KEY_precompute_mult(ecdsa[j], NULL);
2247 /* Perform ECDSA signature test */
2248 EC_KEY_generate_key(ecdsa[j]);
2249 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2250 &ecdsasiglen, ecdsa[j]);
2253 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2254 ERR_print_errors(bio_err);
2259 pkey_print_message("sign","ecdsa",
2261 test_curves_bits[j],
2265 for (count=0,run=1; COND(ecdsa_c[j][0]);
2268 ret=ECDSA_sign(0, buf, 20,
2269 ecdsasig, &ecdsasiglen,
2273 BIO_printf(bio_err, "ECDSA sign failure\n");
2274 ERR_print_errors(bio_err);
2282 mr ? "+R5:%ld:%d:%.2f\n" :
2283 "%ld %d bit ECDSA signs in %.2fs \n",
2284 count, test_curves_bits[j], d);
2285 ecdsa_results[j][0]=d/(double)count;
2289 /* Perform ECDSA verification test */
2290 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2291 ecdsasiglen, ecdsa[j]);
2294 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2295 ERR_print_errors(bio_err);
2300 pkey_print_message("verify","ecdsa",
2302 test_curves_bits[j],
2305 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2307 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2310 BIO_printf(bio_err, "ECDSA verify failure\n");
2311 ERR_print_errors(bio_err);
2318 mr ? "+R6:%ld:%d:%.2f\n"
2319 : "%ld %d bit ECDSA verify in %.2fs\n",
2320 count, test_curves_bits[j], d);
2321 ecdsa_results[j][1]=d/(double)count;
2326 /* if longer than 10s, don't do any more */
2327 for (j++; j<EC_NUM; j++)
2332 if (rnd_fake) RAND_cleanup();
2335 #ifndef OPENSSL_NO_ECDH
2336 if (RAND_status() != 1)
2338 RAND_seed(rnd_seed, sizeof rnd_seed);
2341 for (j=0; j<EC_NUM; j++)
2343 if (!ecdh_doit[j]) continue;
2344 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2345 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2346 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2348 BIO_printf(bio_err,"ECDH failure.\n");
2349 ERR_print_errors(bio_err);
2354 /* generate two ECDH key pairs */
2355 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2356 !EC_KEY_generate_key(ecdh_b[j]))
2358 BIO_printf(bio_err,"ECDH key generation failure.\n");
2359 ERR_print_errors(bio_err);
2364 /* If field size is not more than 24 octets,
2365 * then use SHA-1 hash of result; otherwise,
2366 * use result (see section 4.8 of
2367 * draft-ietf-tls-ecc-03.txt).
2369 int field_size, outlen;
2370 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2371 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2372 if (field_size <= 24 * 8)
2374 outlen = KDF1_SHA1_len;
2379 outlen = (field_size+7)/8;
2383 ECDH_compute_key(secret_a, outlen,
2384 EC_KEY_get0_public_key(ecdh_b[j]),
2387 ECDH_compute_key(secret_b, outlen,
2388 EC_KEY_get0_public_key(ecdh_a[j]),
2390 if (secret_size_a != secret_size_b)
2395 for (secret_idx = 0;
2396 (secret_idx < secret_size_a)
2397 && (ecdh_checks == 1);
2400 if (secret_a[secret_idx] != secret_b[secret_idx])
2404 if (ecdh_checks == 0)
2406 BIO_printf(bio_err,"ECDH computations don't match.\n");
2407 ERR_print_errors(bio_err);
2411 pkey_print_message("","ecdh",
2413 test_curves_bits[j],
2416 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2418 ECDH_compute_key(secret_a, outlen,
2419 EC_KEY_get0_public_key(ecdh_b[j]),
2424 mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2425 count, test_curves_bits[j], d);
2426 ecdh_results[j][0]=d/(double)count;
2434 /* if longer than 10s, don't do any more */
2435 for (j++; j<EC_NUM; j++)
2439 if (rnd_fake) RAND_cleanup();
2446 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2447 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2449 printf("%s ",BN_options());
2450 #ifndef OPENSSL_NO_MD2
2451 printf("%s ",MD2_options());
2453 #ifndef OPENSSL_NO_RC4
2454 printf("%s ",RC4_options());
2456 #ifndef OPENSSL_NO_DES
2457 printf("%s ",DES_options());
2459 #ifndef OPENSSL_NO_AES
2460 printf("%s ",AES_options());
2462 #ifndef OPENSSL_NO_IDEA
2463 printf("%s ",idea_options());
2465 #ifndef OPENSSL_NO_BF
2466 printf("%s ",BF_options());
2468 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2474 fprintf(stdout,"+H");
2477 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2478 fprintf(stdout,"type ");
2480 for (j=0; j<SIZE_NUM; j++)
2481 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2482 fprintf(stdout,"\n");
2485 for (k=0; k<ALGOR_NUM; k++)
2487 if (!doit[k]) continue;
2489 fprintf(stdout,"+F:%d:%s",k,names[k]);
2491 fprintf(stdout,"%-13s",names[k]);
2492 for (j=0; j<SIZE_NUM; j++)
2494 if (results[k][j] > 10000 && !mr)
2495 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2497 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2499 fprintf(stdout,"\n");
2501 #ifndef OPENSSL_NO_RSA
2503 for (k=0; k<RSA_NUM; k++)
2505 if (!rsa_doit[k]) continue;
2508 printf("%18ssign verify sign/s verify/s\n"," ");
2512 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2513 k,rsa_bits[k],rsa_results[k][0],
2516 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2517 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2518 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2521 #ifndef OPENSSL_NO_DSA
2523 for (k=0; k<DSA_NUM; k++)
2525 if (!dsa_doit[k]) continue;
2528 printf("%18ssign verify sign/s verify/s\n"," ");
2532 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2533 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2535 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2536 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2537 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2540 #ifndef OPENSSL_NO_ECDSA
2542 for (k=0; k<EC_NUM; k++)
2544 if (!ecdsa_doit[k]) continue;
2547 printf("%30ssign verify sign/s verify/s\n"," ");
2552 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2553 k, test_curves_bits[k],
2554 ecdsa_results[k][0],ecdsa_results[k][1]);
2557 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2558 test_curves_bits[k],
2559 test_curves_names[k],
2560 ecdsa_results[k][0],ecdsa_results[k][1],
2561 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2566 #ifndef OPENSSL_NO_ECDH
2568 for (k=0; k<EC_NUM; k++)
2570 if (!ecdh_doit[k]) continue;
2573 printf("%30sop op/s\n"," ");
2577 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2578 k, test_curves_bits[k],
2579 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2582 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2583 test_curves_bits[k],
2584 test_curves_names[k],
2585 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2592 ERR_print_errors(bio_err);
2593 if (buf != NULL) OPENSSL_free(buf);
2594 if (buf2 != NULL) OPENSSL_free(buf2);
2595 #ifndef OPENSSL_NO_RSA
2596 for (i=0; i<RSA_NUM; i++)
2597 if (rsa_key[i] != NULL)
2598 RSA_free(rsa_key[i]);
2600 #ifndef OPENSSL_NO_DSA
2601 for (i=0; i<DSA_NUM; i++)
2602 if (dsa_key[i] != NULL)
2603 DSA_free(dsa_key[i]);
2606 #ifndef OPENSSL_NO_ECDSA
2607 for (i=0; i<EC_NUM; i++)
2608 if (ecdsa[i] != NULL)
2609 EC_KEY_free(ecdsa[i]);
2611 #ifndef OPENSSL_NO_ECDH
2612 for (i=0; i<EC_NUM; i++)
2614 if (ecdh_a[i] != NULL)
2615 EC_KEY_free(ecdh_a[i]);
2616 if (ecdh_b[i] != NULL)
2617 EC_KEY_free(ecdh_b[i]);
2625 static void print_message(const char *s, long num, int length)
2629 mr ? "+DT:%s:%d:%d\n"
2630 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2631 (void)BIO_flush(bio_err);
2635 mr ? "+DN:%s:%ld:%d\n"
2636 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2637 (void)BIO_flush(bio_err);
2644 static void pkey_print_message(const char *str, const char *str2, long num,
2649 mr ? "+DTP:%d:%s:%s:%d\n"
2650 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2651 (void)BIO_flush(bio_err);
2655 mr ? "+DNP:%ld:%d:%s:%s\n"
2656 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2657 (void)BIO_flush(bio_err);
2664 static void print_result(int alg,int run_no,int count,double time_used)
2667 mr ? "+R:%d:%s:%f\n"
2668 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2669 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2673 static char *sstrsep(char **string, const char *delim)
2676 char *token = *string;
2681 memset(isdelim, 0, sizeof isdelim);
2686 isdelim[(unsigned char)(*delim)] = 1;
2690 while (!isdelim[(unsigned char)(**string)])
2704 static int do_multi(int multi)
2709 static char sep[]=":";
2711 fds=malloc(multi*sizeof *fds);
2712 for(n=0 ; n < multi ; ++n)
2716 fprintf(stderr, "pipe failure\n");
2730 if (dup(fd[1]) == -1)
2732 fprintf(stderr, "dup failed\n");
2741 printf("Forked child %d\n",n);
2744 /* for now, assume the pipe is long enough to take all the output */
2745 for(n=0 ; n < multi ; ++n)
2751 f=fdopen(fds[n],"r");
2752 while(fgets(buf,sizeof buf,f))
2759 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2763 printf("Got: %s from %d\n",buf,n);
2764 if(!strncmp(buf,"+F:",3))
2770 alg=atoi(sstrsep(&p,sep));
2772 for(j=0 ; j < SIZE_NUM ; ++j)
2773 results[alg][j]+=atof(sstrsep(&p,sep));
2775 else if(!strncmp(buf,"+F2:",4))
2781 k=atoi(sstrsep(&p,sep));
2784 d=atof(sstrsep(&p,sep));
2786 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2788 rsa_results[k][0]=d;
2790 d=atof(sstrsep(&p,sep));
2792 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2794 rsa_results[k][1]=d;
2796 #ifndef OPENSSL_NO_DSA
2797 else if(!strncmp(buf,"+F3:",4))
2803 k=atoi(sstrsep(&p,sep));
2806 d=atof(sstrsep(&p,sep));
2808 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2810 dsa_results[k][0]=d;
2812 d=atof(sstrsep(&p,sep));
2814 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2816 dsa_results[k][1]=d;
2819 #ifndef OPENSSL_NO_ECDSA
2820 else if(!strncmp(buf,"+F4:",4))
2826 k=atoi(sstrsep(&p,sep));
2829 d=atof(sstrsep(&p,sep));
2831 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2833 ecdsa_results[k][0]=d;
2835 d=atof(sstrsep(&p,sep));
2837 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2839 ecdsa_results[k][1]=d;
2843 #ifndef OPENSSL_NO_ECDH
2844 else if(!strncmp(buf,"+F5:",4))
2850 k=atoi(sstrsep(&p,sep));
2853 d=atof(sstrsep(&p,sep));
2855 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2857 ecdh_results[k][0]=d;
2862 else if(!strncmp(buf,"+H:",3))
2866 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2876 static void multiblock_speed(const EVP_CIPHER *evp_cipher)
2878 static int mblengths[]={8*1024,2*8*1024,4*8*1024,8*8*1024,8*16*1024};
2879 int j,count,num=sizeof(lengths)/sizeof(lengths[0]);
2880 const char *alg_name;
2881 unsigned char *inp,*out,no_key[32],no_iv[16];
2885 inp = OPENSSL_malloc(mblengths[num-1]);
2886 out = OPENSSL_malloc(mblengths[num-1]+1024);
2888 EVP_CIPHER_CTX_init(&ctx);
2889 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,no_key,no_iv);
2890 EVP_CIPHER_CTX_ctrl(&ctx,EVP_CTRL_AEAD_SET_MAC_KEY,sizeof(no_key),no_key);
2891 alg_name=OBJ_nid2ln(evp_cipher->nid);
2893 for (j=0; j<num; j++)
2895 print_message(alg_name,0,mblengths[j]);
2897 for (count=0,run=1; run && count<0x7fffffff; count++)
2899 unsigned char aad[13];
2900 EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
2901 size_t len = mblengths[j];
2904 memset(aad,0,8);/* avoid uninitialized values */
2905 aad[8] = 23; /* SSL3_RT_APPLICATION_DATA */
2906 aad[9] = 3; /* version */
2908 aad[11] = 0; /* length */
2910 mb_param.out = NULL;
2913 mb_param.interleave = 8;
2915 packlen=EVP_CIPHER_CTX_ctrl(&ctx,
2916 EVP_CTRL_TLS1_1_MULTIBLOCK_AAD,
2917 sizeof(mb_param),&mb_param);
2924 EVP_CIPHER_CTX_ctrl(&ctx,
2925 EVP_CTRL_TLS1_1_MULTIBLOCK_ENCRYPT,
2926 sizeof(mb_param),&mb_param);
2936 pad=EVP_CIPHER_CTX_ctrl(&ctx,
2937 EVP_CTRL_AEAD_TLS1_AAD,13,aad);
2938 EVP_Cipher(&ctx,out,inp,len+pad);
2943 mr ? "+R:%d:%s:%f\n"
2944 : "%d %s's in %.2fs\n",count,"evp",d);
2945 results[D_EVP][j]=((double)count)/d*mblengths[j];
2950 fprintf(stdout,"+H");
2951 for (j=0; j<num; j++)
2952 fprintf(stdout,":%d",mblengths[j]);
2953 fprintf(stdout,"\n");
2954 fprintf(stdout,"+F:%d:%s",D_EVP,alg_name);
2955 for (j=0; j<num; j++)
2956 fprintf(stdout,":%.2f",results[D_EVP][j]);
2957 fprintf(stdout,"\n");
2961 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2962 fprintf(stdout,"type ");
2963 for (j=0; j<num; j++)
2964 fprintf(stdout,"%7d bytes",mblengths[j]);
2965 fprintf(stdout,"\n");
2966 fprintf(stdout,"%-24s",alg_name);
2968 for (j=0; j<num; j++)
2970 if (results[D_EVP][j] > 10000)
2971 fprintf(stdout," %11.2fk",results[D_EVP][j]/1e3);
2973 fprintf(stdout," %11.2f ",results[D_EVP][j]);
2975 fprintf(stdout,"\n");