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
115 #include <openssl/bn.h>
116 #ifndef OPENSSL_NO_DES
117 #include <openssl/des.h>
119 #ifndef OPENSSL_NO_AES
120 #include <openssl/aes.h>
122 #ifndef OPENSSL_NO_CAMELLIA
123 #include <openssl/camellia.h>
125 #ifndef OPENSSL_NO_MD2
126 #include <openssl/md2.h>
128 #ifndef OPENSSL_NO_MDC2
129 #include <openssl/mdc2.h>
131 #ifndef OPENSSL_NO_MD4
132 #include <openssl/md4.h>
134 #ifndef OPENSSL_NO_MD5
135 #include <openssl/md5.h>
137 #ifndef OPENSSL_NO_HMAC
138 #include <openssl/hmac.h>
140 #include <openssl/evp.h>
141 #ifndef OPENSSL_NO_SHA
142 #include <openssl/sha.h>
144 #ifndef OPENSSL_NO_RIPEMD
145 #include <openssl/ripemd.h>
147 #ifndef OPENSSL_NO_WHIRLPOOL
148 #include <openssl/whrlpool.h>
150 #ifndef OPENSSL_NO_RC4
151 #include <openssl/rc4.h>
153 #ifndef OPENSSL_NO_RC5
154 #include <openssl/rc5.h>
156 #ifndef OPENSSL_NO_RC2
157 #include <openssl/rc2.h>
159 #ifndef OPENSSL_NO_IDEA
160 #include <openssl/idea.h>
162 #ifndef OPENSSL_NO_SEED
163 #include <openssl/seed.h>
165 #ifndef OPENSSL_NO_BF
166 #include <openssl/blowfish.h>
168 #ifndef OPENSSL_NO_CAST
169 #include <openssl/cast.h>
171 #ifndef OPENSSL_NO_RSA
172 #include <openssl/rsa.h>
173 #include "./testrsa.h"
175 #include <openssl/x509.h>
176 #ifndef OPENSSL_NO_DSA
177 #include <openssl/dsa.h>
178 #include "./testdsa.h"
180 #ifndef OPENSSL_NO_ECDSA
181 #include <openssl/ecdsa.h>
183 #ifndef OPENSSL_NO_ECDH
184 #include <openssl/ecdh.h>
187 #if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
196 #define BUFSIZE ((long)1024*8+1)
200 static int usertime=1;
202 static double Time_F(int s);
203 static void print_message(const char *s,long num,int length);
204 static void pkey_print_message(const char *str, const char *str2,
205 long num, int bits, int sec);
206 static void print_result(int alg,int run_no,int count,double time_used);
208 static int do_multi(int multi);
217 #define MAX_ECDH_SIZE 256
219 static const char *names[ALGOR_NUM]={
220 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
221 "des cbc","des ede3","idea cbc","seed cbc",
222 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
223 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
224 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
225 "evp","sha256","sha512","whirlpool",
226 "aes-128 ige","aes-192 ige","aes-256 ige"};
227 static double results[ALGOR_NUM][SIZE_NUM];
228 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
229 static double rsa_results[RSA_NUM][2];
230 static double dsa_results[DSA_NUM][2];
231 #ifndef OPENSSL_NO_ECDSA
232 static double ecdsa_results[EC_NUM][2];
234 #ifndef OPENSSL_NO_ECDH
235 static double ecdh_results[EC_NUM][1];
238 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
239 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
240 static int rnd_fake = 0;
244 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
245 #define SIGRETTYPE void
247 #define SIGRETTYPE int
250 static SIGRETTYPE sig_done(int sig);
251 static SIGRETTYPE sig_done(int sig)
253 signal(SIGALRM,sig_done);
267 static unsigned int lapse,schlock;
268 static void alarm(unsigned int secs) { lapse = secs*1000; }
270 static DWORD WINAPI sleepy(VOID *arg)
278 static double Time_F(int s)
284 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
287 DWORD ret=GetLastError();
288 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
291 CloseHandle(thr); /* detach the thread */
292 while (!schlock) Sleep(0); /* scheduler spinlock */
295 return app_tminterval(s,usertime);
299 static double Time_F(int s)
301 return app_tminterval(s,usertime);
306 #ifndef OPENSSL_NO_ECDH
307 static const int KDF1_SHA1_len = 20;
308 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
310 #ifndef OPENSSL_NO_SHA
311 if (*outlen < SHA_DIGEST_LENGTH)
314 *outlen = SHA_DIGEST_LENGTH;
315 return SHA1(in, inlen, out);
318 #endif /* OPENSSL_NO_SHA */
320 #endif /* OPENSSL_NO_ECDH */
323 int MAIN(int, char **);
325 int MAIN(int argc, char **argv)
327 #ifndef OPENSSL_NO_ENGINE
330 unsigned char *buf=NULL,*buf2=NULL;
332 long count=0,save_count=0;
334 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
337 #ifndef OPENSSL_NO_RSA
340 unsigned char md[EVP_MAX_MD_SIZE];
341 #ifndef OPENSSL_NO_MD2
342 unsigned char md2[MD2_DIGEST_LENGTH];
344 #ifndef OPENSSL_NO_MDC2
345 unsigned char mdc2[MDC2_DIGEST_LENGTH];
347 #ifndef OPENSSL_NO_MD4
348 unsigned char md4[MD4_DIGEST_LENGTH];
350 #ifndef OPENSSL_NO_MD5
351 unsigned char md5[MD5_DIGEST_LENGTH];
352 unsigned char hmac[MD5_DIGEST_LENGTH];
354 #ifndef OPENSSL_NO_SHA
355 unsigned char sha[SHA_DIGEST_LENGTH];
356 #ifndef OPENSSL_NO_SHA256
357 unsigned char sha256[SHA256_DIGEST_LENGTH];
359 #ifndef OPENSSL_NO_SHA512
360 unsigned char sha512[SHA512_DIGEST_LENGTH];
363 #ifndef OPENSSL_NO_WHIRLPOOL
364 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
366 #ifndef OPENSSL_NO_RIPEMD
367 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
369 #ifndef OPENSSL_NO_RC4
372 #ifndef OPENSSL_NO_RC5
375 #ifndef OPENSSL_NO_RC2
378 #ifndef OPENSSL_NO_IDEA
379 IDEA_KEY_SCHEDULE idea_ks;
381 #ifndef OPENSSL_NO_SEED
382 SEED_KEY_SCHEDULE seed_ks;
384 #ifndef OPENSSL_NO_BF
387 #ifndef OPENSSL_NO_CAST
390 static const unsigned char key16[16]=
391 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
392 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
393 #ifndef OPENSSL_NO_AES
394 static const unsigned char key24[24]=
395 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
396 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
397 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
398 static const unsigned char key32[32]=
399 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
400 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
401 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
402 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
404 #ifndef OPENSSL_NO_CAMELLIA
405 static const unsigned char ckey24[24]=
406 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
407 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
408 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
409 static const unsigned char ckey32[32]=
410 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
411 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
412 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
413 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
415 #ifndef OPENSSL_NO_AES
416 #define MAX_BLOCK_SIZE 128
418 #define MAX_BLOCK_SIZE 64
420 unsigned char DES_iv[8];
421 unsigned char iv[2*MAX_BLOCK_SIZE/8];
422 #ifndef OPENSSL_NO_DES
423 DES_cblock *buf_as_des_cblock = NULL;
424 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
425 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
426 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
427 DES_key_schedule sch;
428 DES_key_schedule sch2;
429 DES_key_schedule sch3;
431 #ifndef OPENSSL_NO_AES
432 AES_KEY aes_ks1, aes_ks2, aes_ks3;
434 #ifndef OPENSSL_NO_CAMELLIA
435 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
447 #define D_CBC_IDEA 10
448 #define D_CBC_SEED 11
452 #define D_CBC_CAST 15
453 #define D_CBC_128_AES 16
454 #define D_CBC_192_AES 17
455 #define D_CBC_256_AES 18
456 #define D_CBC_128_CML 19
457 #define D_CBC_192_CML 20
458 #define D_CBC_256_CML 21
462 #define D_WHIRLPOOL 25
463 #define D_IGE_128_AES 26
464 #define D_IGE_192_AES 27
465 #define D_IGE_256_AES 28
467 long c[ALGOR_NUM][SIZE_NUM];
493 #ifndef OPENSSL_NO_RSA
494 RSA *rsa_key[RSA_NUM];
495 long rsa_c[RSA_NUM][2];
496 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
497 static unsigned char *rsa_data[RSA_NUM]=
498 {test512,test1024,test2048,test4096};
499 static int rsa_data_length[RSA_NUM]={
500 sizeof(test512),sizeof(test1024),
501 sizeof(test2048),sizeof(test4096)};
503 #ifndef OPENSSL_NO_DSA
504 DSA *dsa_key[DSA_NUM];
505 long dsa_c[DSA_NUM][2];
506 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
508 #ifndef OPENSSL_NO_EC
509 /* We only test over the following curves as they are representative,
510 * To add tests over more curves, simply add the curve NID
511 * and curve name to the following arrays and increase the
512 * EC_NUM value accordingly.
514 static unsigned int test_curves[EC_NUM] =
518 NID_X9_62_prime192v1,
520 NID_X9_62_prime256v1,
535 static const char * test_curves_names[EC_NUM] =
556 static int test_curves_bits[EC_NUM] =
558 160, 192, 224, 256, 384, 521,
559 163, 233, 283, 409, 571,
560 163, 233, 283, 409, 571
565 #ifndef OPENSSL_NO_ECDSA
566 unsigned char ecdsasig[256];
567 unsigned int ecdsasiglen;
568 EC_KEY *ecdsa[EC_NUM];
569 long ecdsa_c[EC_NUM][2];
572 #ifndef OPENSSL_NO_ECDH
573 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
574 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
575 int secret_size_a, secret_size_b;
578 long ecdh_c[EC_NUM][2];
581 int rsa_doit[RSA_NUM];
582 int dsa_doit[DSA_NUM];
583 #ifndef OPENSSL_NO_ECDSA
584 int ecdsa_doit[EC_NUM];
586 #ifndef OPENSSL_NO_ECDH
587 int ecdh_doit[EC_NUM];
591 const EVP_CIPHER *evp_cipher=NULL;
592 const EVP_MD *evp_md=NULL;
603 memset(results, 0, sizeof(results));
604 #ifndef OPENSSL_NO_DSA
605 memset(dsa_key,0,sizeof(dsa_key));
607 #ifndef OPENSSL_NO_ECDSA
608 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
610 #ifndef OPENSSL_NO_ECDH
611 for (i=0; i<EC_NUM; i++)
620 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
621 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
623 if (!load_config(bio_err, NULL))
626 #ifndef OPENSSL_NO_RSA
627 memset(rsa_key,0,sizeof(rsa_key));
628 for (i=0; i<RSA_NUM; i++)
632 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
634 BIO_printf(bio_err,"out of memory\n");
637 #ifndef OPENSSL_NO_DES
638 buf_as_des_cblock = (DES_cblock *)buf;
640 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
642 BIO_printf(bio_err,"out of memory\n");
646 memset(c,0,sizeof(c));
647 memset(DES_iv,0,sizeof(DES_iv));
648 memset(iv,0,sizeof(iv));
650 for (i=0; i<ALGOR_NUM; i++)
652 for (i=0; i<RSA_NUM; i++)
654 for (i=0; i<DSA_NUM; i++)
656 #ifndef OPENSSL_NO_ECDSA
657 for (i=0; i<EC_NUM; i++)
660 #ifndef OPENSSL_NO_ECDH
661 for (i=0; i<EC_NUM; i++)
671 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
674 j--; /* Otherwise, -elapsed gets confused with
677 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
683 BIO_printf(bio_err,"no EVP given\n");
686 evp_cipher=EVP_get_cipherbyname(*argv);
689 evp_md=EVP_get_digestbyname(*argv);
691 if(!evp_cipher && !evp_md)
693 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
698 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
701 j--; /* Otherwise, -elapsed gets confused with
704 #ifndef OPENSSL_NO_ENGINE
705 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
711 BIO_printf(bio_err,"no engine given\n");
714 e = setup_engine(bio_err, *argv, 0);
715 /* j will be increased again further down. We just
716 don't want speed to confuse an engine with an
717 algorithm, especially when none is given (which
718 means all of them should be run) */
723 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
729 BIO_printf(bio_err,"no multi count given\n");
735 BIO_printf(bio_err,"bad multi count\n");
738 j--; /* Otherwise, -mr gets confused with
742 else if (argc > 0 && !strcmp(*argv,"-mr"))
745 j--; /* Otherwise, -mr gets confused with
749 #ifndef OPENSSL_NO_MD2
750 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
753 #ifndef OPENSSL_NO_MDC2
754 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
757 #ifndef OPENSSL_NO_MD4
758 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
761 #ifndef OPENSSL_NO_MD5
762 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
765 #ifndef OPENSSL_NO_MD5
766 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
769 #ifndef OPENSSL_NO_SHA
770 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
772 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
776 #ifndef OPENSSL_NO_SHA256
777 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
780 #ifndef OPENSSL_NO_SHA512
781 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
785 #ifndef OPENSSL_NO_WHIRLPOOL
786 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
789 #ifndef OPENSSL_NO_RIPEMD
790 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
792 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
794 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
797 #ifndef OPENSSL_NO_RC4
798 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
801 #ifndef OPENSSL_NO_DES
802 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
803 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
806 #ifndef OPENSSL_NO_AES
807 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
808 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
809 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
810 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
811 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
812 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
815 #ifndef OPENSSL_NO_CAMELLIA
816 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
817 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
818 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
821 #ifndef OPENSSL_NO_RSA
822 #if 0 /* was: #ifdef RSAref */
823 if (strcmp(*argv,"rsaref") == 0)
825 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
831 if (strcmp(*argv,"openssl") == 0)
833 RSA_set_default_method(RSA_PKCS1_SSLeay());
838 #endif /* !OPENSSL_NO_RSA */
839 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
840 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
841 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
842 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
843 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
844 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
845 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
847 #ifndef OPENSSL_NO_RC2
848 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
849 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
852 #ifndef OPENSSL_NO_RC5
853 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
854 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
857 #ifndef OPENSSL_NO_IDEA
858 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
859 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
862 #ifndef OPENSSL_NO_SEED
863 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
864 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
867 #ifndef OPENSSL_NO_BF
868 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
869 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
870 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
873 #ifndef OPENSSL_NO_CAST
874 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
875 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
876 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
879 #ifndef OPENSSL_NO_DES
880 if (strcmp(*argv,"des") == 0)
887 #ifndef OPENSSL_NO_AES
888 if (strcmp(*argv,"aes") == 0)
890 doit[D_CBC_128_AES]=1;
891 doit[D_CBC_192_AES]=1;
892 doit[D_CBC_256_AES]=1;
896 #ifndef OPENSSL_NO_CAMELLIA
897 if (strcmp(*argv,"camellia") == 0)
899 doit[D_CBC_128_CML]=1;
900 doit[D_CBC_192_CML]=1;
901 doit[D_CBC_256_CML]=1;
905 #ifndef OPENSSL_NO_RSA
906 if (strcmp(*argv,"rsa") == 0)
908 rsa_doit[R_RSA_512]=1;
909 rsa_doit[R_RSA_1024]=1;
910 rsa_doit[R_RSA_2048]=1;
911 rsa_doit[R_RSA_4096]=1;
915 #ifndef OPENSSL_NO_DSA
916 if (strcmp(*argv,"dsa") == 0)
918 dsa_doit[R_DSA_512]=1;
919 dsa_doit[R_DSA_1024]=1;
920 dsa_doit[R_DSA_2048]=1;
924 #ifndef OPENSSL_NO_ECDSA
925 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
926 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
927 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
928 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
929 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
930 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
931 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
932 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
933 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
934 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
935 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
936 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
937 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
938 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
939 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
940 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
941 else if (strcmp(*argv,"ecdsa") == 0)
943 for (i=0; i < EC_NUM; i++)
948 #ifndef OPENSSL_NO_ECDH
949 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
950 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
951 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
952 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
953 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
954 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
955 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
956 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
957 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
958 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
959 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
960 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
961 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
962 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
963 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
964 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
965 else if (strcmp(*argv,"ecdh") == 0)
967 for (i=0; i < EC_NUM; i++)
973 BIO_printf(bio_err,"Error: bad option or value\n");
974 BIO_printf(bio_err,"\n");
975 BIO_printf(bio_err,"Available values:\n");
976 #ifndef OPENSSL_NO_MD2
977 BIO_printf(bio_err,"md2 ");
979 #ifndef OPENSSL_NO_MDC2
980 BIO_printf(bio_err,"mdc2 ");
982 #ifndef OPENSSL_NO_MD4
983 BIO_printf(bio_err,"md4 ");
985 #ifndef OPENSSL_NO_MD5
986 BIO_printf(bio_err,"md5 ");
987 #ifndef OPENSSL_NO_HMAC
988 BIO_printf(bio_err,"hmac ");
991 #ifndef OPENSSL_NO_SHA1
992 BIO_printf(bio_err,"sha1 ");
994 #ifndef OPENSSL_NO_SHA256
995 BIO_printf(bio_err,"sha256 ");
997 #ifndef OPENSSL_NO_SHA512
998 BIO_printf(bio_err,"sha512 ");
1000 #ifndef OPENSSL_NO_WHIRLPOOL
1001 BIO_printf(bio_err,"whirlpool");
1003 #ifndef OPENSSL_NO_RIPEMD160
1004 BIO_printf(bio_err,"rmd160");
1006 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1007 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1008 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1009 !defined(OPENSSL_NO_WHIRLPOOL)
1010 BIO_printf(bio_err,"\n");
1013 #ifndef OPENSSL_NO_IDEA
1014 BIO_printf(bio_err,"idea-cbc ");
1016 #ifndef OPENSSL_NO_SEED
1017 BIO_printf(bio_err,"seed-cbc ");
1019 #ifndef OPENSSL_NO_RC2
1020 BIO_printf(bio_err,"rc2-cbc ");
1022 #ifndef OPENSSL_NO_RC5
1023 BIO_printf(bio_err,"rc5-cbc ");
1025 #ifndef OPENSSL_NO_BF
1026 BIO_printf(bio_err,"bf-cbc");
1028 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1029 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1030 BIO_printf(bio_err,"\n");
1032 #ifndef OPENSSL_NO_DES
1033 BIO_printf(bio_err,"des-cbc des-ede3 ");
1035 #ifndef OPENSSL_NO_AES
1036 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1037 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1039 #ifndef OPENSSL_NO_CAMELLIA
1040 BIO_printf(bio_err,"\n");
1041 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1043 #ifndef OPENSSL_NO_RC4
1044 BIO_printf(bio_err,"rc4");
1046 BIO_printf(bio_err,"\n");
1048 #ifndef OPENSSL_NO_RSA
1049 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1052 #ifndef OPENSSL_NO_DSA
1053 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1055 #ifndef OPENSSL_NO_ECDSA
1056 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1057 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1058 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1059 BIO_printf(bio_err,"ecdsa\n");
1061 #ifndef OPENSSL_NO_ECDH
1062 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1063 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1064 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1065 BIO_printf(bio_err,"ecdh\n");
1068 #ifndef OPENSSL_NO_IDEA
1069 BIO_printf(bio_err,"idea ");
1071 #ifndef OPENSSL_NO_SEED
1072 BIO_printf(bio_err,"seed ");
1074 #ifndef OPENSSL_NO_RC2
1075 BIO_printf(bio_err,"rc2 ");
1077 #ifndef OPENSSL_NO_DES
1078 BIO_printf(bio_err,"des ");
1080 #ifndef OPENSSL_NO_AES
1081 BIO_printf(bio_err,"aes ");
1083 #ifndef OPENSSL_NO_CAMELLIA
1084 BIO_printf(bio_err,"camellia ");
1086 #ifndef OPENSSL_NO_RSA
1087 BIO_printf(bio_err,"rsa ");
1089 #ifndef OPENSSL_NO_BF
1090 BIO_printf(bio_err,"blowfish");
1092 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1093 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1094 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1095 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1096 BIO_printf(bio_err,"\n");
1099 BIO_printf(bio_err,"\n");
1100 BIO_printf(bio_err,"Available options:\n");
1101 #if defined(TIMES) || defined(USE_TOD)
1102 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1104 #ifndef OPENSSL_NO_ENGINE
1105 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1107 BIO_printf(bio_err,"-evp e use EVP e.\n");
1108 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1109 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1111 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1121 if(multi && do_multi(multi))
1127 for (i=0; i<ALGOR_NUM; i++)
1132 for (i=0; i<RSA_NUM; i++)
1134 for (i=0; i<DSA_NUM; i++)
1136 #ifndef OPENSSL_NO_ECDSA
1137 for (i=0; i<EC_NUM; i++)
1140 #ifndef OPENSSL_NO_ECDH
1141 for (i=0; i<EC_NUM; i++)
1145 for (i=0; i<ALGOR_NUM; i++)
1146 if (doit[i]) pr_header++;
1148 if (usertime == 0 && !mr)
1149 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1151 #ifndef OPENSSL_NO_RSA
1152 for (i=0; i<RSA_NUM; i++)
1154 const unsigned char *p;
1157 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1158 if (rsa_key[i] == NULL)
1160 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1166 BIO_printf(bio_err,mr ? "+RK:%d:"
1167 : "Loaded RSA key, %d bit modulus and e= 0x",
1168 BN_num_bits(rsa_key[i]->n));
1169 BN_print(bio_err,rsa_key[i]->e);
1170 BIO_printf(bio_err,"\n");
1176 #ifndef OPENSSL_NO_DSA
1177 dsa_key[0]=get_dsa512();
1178 dsa_key[1]=get_dsa1024();
1179 dsa_key[2]=get_dsa2048();
1182 #ifndef OPENSSL_NO_DES
1183 DES_set_key_unchecked(&key,&sch);
1184 DES_set_key_unchecked(&key2,&sch2);
1185 DES_set_key_unchecked(&key3,&sch3);
1187 #ifndef OPENSSL_NO_AES
1188 AES_set_encrypt_key(key16,128,&aes_ks1);
1189 AES_set_encrypt_key(key24,192,&aes_ks2);
1190 AES_set_encrypt_key(key32,256,&aes_ks3);
1192 #ifndef OPENSSL_NO_CAMELLIA
1193 Camellia_set_key(key16,128,&camellia_ks1);
1194 Camellia_set_key(ckey24,192,&camellia_ks2);
1195 Camellia_set_key(ckey32,256,&camellia_ks3);
1197 #ifndef OPENSSL_NO_IDEA
1198 idea_set_encrypt_key(key16,&idea_ks);
1200 #ifndef OPENSSL_NO_SEED
1201 SEED_set_key(key16,&seed_ks);
1203 #ifndef OPENSSL_NO_RC4
1204 RC4_set_key(&rc4_ks,16,key16);
1206 #ifndef OPENSSL_NO_RC2
1207 RC2_set_key(&rc2_ks,16,key16,128);
1209 #ifndef OPENSSL_NO_RC5
1210 RC5_32_set_key(&rc5_ks,16,key16,12);
1212 #ifndef OPENSSL_NO_BF
1213 BF_set_key(&bf_ks,16,key16);
1215 #ifndef OPENSSL_NO_CAST
1216 CAST_set_key(&cast_ks,16,key16);
1218 #ifndef OPENSSL_NO_RSA
1219 memset(rsa_c,0,sizeof(rsa_c));
1222 #ifndef OPENSSL_NO_DES
1223 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1229 for (it=count; it; it--)
1230 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
1235 c[D_MD2][0]=count/10;
1236 c[D_MDC2][0]=count/10;
1241 c[D_RMD160][0]=count;
1242 c[D_RC4][0]=count*5;
1243 c[D_CBC_DES][0]=count;
1244 c[D_EDE3_DES][0]=count/3;
1245 c[D_CBC_IDEA][0]=count;
1246 c[D_CBC_SEED][0]=count;
1247 c[D_CBC_RC2][0]=count;
1248 c[D_CBC_RC5][0]=count;
1249 c[D_CBC_BF][0]=count;
1250 c[D_CBC_CAST][0]=count;
1251 c[D_CBC_128_AES][0]=count;
1252 c[D_CBC_192_AES][0]=count;
1253 c[D_CBC_256_AES][0]=count;
1254 c[D_CBC_128_CML][0]=count;
1255 c[D_CBC_192_CML][0]=count;
1256 c[D_CBC_256_CML][0]=count;
1257 c[D_SHA256][0]=count;
1258 c[D_SHA512][0]=count;
1259 c[D_WHIRLPOOL][0]=count;
1260 c[D_IGE_128_AES][0]=count;
1261 c[D_IGE_192_AES][0]=count;
1262 c[D_IGE_256_AES][0]=count;
1264 for (i=1; i<SIZE_NUM; i++)
1266 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1267 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1268 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1269 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1270 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1271 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1272 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1273 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1274 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1275 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1277 for (i=1; i<SIZE_NUM; i++)
1281 l0=(long)lengths[i-1];
1282 l1=(long)lengths[i];
1283 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1284 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1285 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1286 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1287 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1288 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1289 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1290 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1291 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1292 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1293 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1294 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1295 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1296 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1297 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1298 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1299 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1300 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1302 #ifndef OPENSSL_NO_RSA
1303 rsa_c[R_RSA_512][0]=count/2000;
1304 rsa_c[R_RSA_512][1]=count/400;
1305 for (i=1; i<RSA_NUM; i++)
1307 rsa_c[i][0]=rsa_c[i-1][0]/8;
1308 rsa_c[i][1]=rsa_c[i-1][1]/4;
1309 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1313 if (rsa_c[i][0] == 0)
1322 #ifndef OPENSSL_NO_DSA
1323 dsa_c[R_DSA_512][0]=count/1000;
1324 dsa_c[R_DSA_512][1]=count/1000/2;
1325 for (i=1; i<DSA_NUM; i++)
1327 dsa_c[i][0]=dsa_c[i-1][0]/4;
1328 dsa_c[i][1]=dsa_c[i-1][1]/4;
1329 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1342 #ifndef OPENSSL_NO_ECDSA
1343 ecdsa_c[R_EC_P160][0]=count/1000;
1344 ecdsa_c[R_EC_P160][1]=count/1000/2;
1345 for (i=R_EC_P192; i<=R_EC_P521; i++)
1347 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1348 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1349 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1353 if (ecdsa_c[i] == 0)
1360 ecdsa_c[R_EC_K163][0]=count/1000;
1361 ecdsa_c[R_EC_K163][1]=count/1000/2;
1362 for (i=R_EC_K233; i<=R_EC_K571; i++)
1364 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1365 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1366 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1370 if (ecdsa_c[i] == 0)
1377 ecdsa_c[R_EC_B163][0]=count/1000;
1378 ecdsa_c[R_EC_B163][1]=count/1000/2;
1379 for (i=R_EC_B233; i<=R_EC_B571; i++)
1381 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1382 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1383 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1387 if (ecdsa_c[i] == 0)
1396 #ifndef OPENSSL_NO_ECDH
1397 ecdh_c[R_EC_P160][0]=count/1000;
1398 ecdh_c[R_EC_P160][1]=count/1000;
1399 for (i=R_EC_P192; i<=R_EC_P521; i++)
1401 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1402 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1403 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1414 ecdh_c[R_EC_K163][0]=count/1000;
1415 ecdh_c[R_EC_K163][1]=count/1000;
1416 for (i=R_EC_K233; i<=R_EC_K571; i++)
1418 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1419 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1420 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1431 ecdh_c[R_EC_B163][0]=count/1000;
1432 ecdh_c[R_EC_B163][1]=count/1000;
1433 for (i=R_EC_B233; i<=R_EC_B571; i++)
1435 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1436 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1437 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1450 #define COND(d) (count < (d))
1451 #define COUNT(d) (d)
1453 /* not worth fixing */
1454 # error "You cannot disable DES on systems without SIGALRM."
1455 #endif /* OPENSSL_NO_DES */
1457 #define COND(c) (run)
1458 #define COUNT(d) (count)
1460 signal(SIGALRM,sig_done);
1462 #endif /* SIGALRM */
1464 #ifndef OPENSSL_NO_MD2
1467 for (j=0; j<SIZE_NUM; j++)
1469 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1471 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1472 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1474 print_result(D_MD2,j,count,d);
1478 #ifndef OPENSSL_NO_MDC2
1481 for (j=0; j<SIZE_NUM; j++)
1483 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1485 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1486 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1488 print_result(D_MDC2,j,count,d);
1493 #ifndef OPENSSL_NO_MD4
1496 for (j=0; j<SIZE_NUM; j++)
1498 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1500 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1501 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1503 print_result(D_MD4,j,count,d);
1508 #ifndef OPENSSL_NO_MD5
1511 for (j=0; j<SIZE_NUM; j++)
1513 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1515 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1516 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1518 print_result(D_MD5,j,count,d);
1523 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1528 HMAC_CTX_init(&hctx);
1529 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1530 16,EVP_md5(), NULL);
1532 for (j=0; j<SIZE_NUM; j++)
1534 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1536 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1538 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1539 HMAC_Update(&hctx,buf,lengths[j]);
1540 HMAC_Final(&hctx,&(hmac[0]),NULL);
1543 print_result(D_HMAC,j,count,d);
1545 HMAC_CTX_cleanup(&hctx);
1548 #ifndef OPENSSL_NO_SHA
1551 for (j=0; j<SIZE_NUM; j++)
1553 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1555 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1556 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1558 print_result(D_SHA1,j,count,d);
1562 #ifndef OPENSSL_NO_SHA256
1565 for (j=0; j<SIZE_NUM; j++)
1567 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1569 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1570 SHA256(buf,lengths[j],sha256);
1572 print_result(D_SHA256,j,count,d);
1577 #ifndef OPENSSL_NO_SHA512
1580 for (j=0; j<SIZE_NUM; j++)
1582 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1584 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1585 SHA512(buf,lengths[j],sha512);
1587 print_result(D_SHA512,j,count,d);
1593 #ifndef OPENSSL_NO_WHIRLPOOL
1594 if (doit[D_WHIRLPOOL])
1596 for (j=0; j<SIZE_NUM; j++)
1598 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1600 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1601 WHIRLPOOL(buf,lengths[j],whirlpool);
1603 print_result(D_WHIRLPOOL,j,count,d);
1608 #ifndef OPENSSL_NO_RIPEMD
1611 for (j=0; j<SIZE_NUM; j++)
1613 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1615 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1616 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1618 print_result(D_RMD160,j,count,d);
1622 #ifndef OPENSSL_NO_RC4
1625 for (j=0; j<SIZE_NUM; j++)
1627 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1629 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1630 RC4(&rc4_ks,(unsigned int)lengths[j],
1633 print_result(D_RC4,j,count,d);
1637 #ifndef OPENSSL_NO_DES
1638 if (doit[D_CBC_DES])
1640 for (j=0; j<SIZE_NUM; j++)
1642 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1644 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1645 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1646 &DES_iv,DES_ENCRYPT);
1648 print_result(D_CBC_DES,j,count,d);
1652 if (doit[D_EDE3_DES])
1654 for (j=0; j<SIZE_NUM; j++)
1656 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1658 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1659 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1661 &DES_iv,DES_ENCRYPT);
1663 print_result(D_EDE3_DES,j,count,d);
1667 #ifndef OPENSSL_NO_AES
1668 if (doit[D_CBC_128_AES])
1670 for (j=0; j<SIZE_NUM; j++)
1672 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1674 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1675 AES_cbc_encrypt(buf,buf,
1676 (unsigned long)lengths[j],&aes_ks1,
1679 print_result(D_CBC_128_AES,j,count,d);
1682 if (doit[D_CBC_192_AES])
1684 for (j=0; j<SIZE_NUM; j++)
1686 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1688 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1689 AES_cbc_encrypt(buf,buf,
1690 (unsigned long)lengths[j],&aes_ks2,
1693 print_result(D_CBC_192_AES,j,count,d);
1696 if (doit[D_CBC_256_AES])
1698 for (j=0; j<SIZE_NUM; j++)
1700 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1702 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1703 AES_cbc_encrypt(buf,buf,
1704 (unsigned long)lengths[j],&aes_ks3,
1707 print_result(D_CBC_256_AES,j,count,d);
1711 if (doit[D_IGE_128_AES])
1713 for (j=0; j<SIZE_NUM; j++)
1715 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1717 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1718 AES_ige_encrypt(buf,buf2,
1719 (unsigned long)lengths[j],&aes_ks1,
1722 print_result(D_IGE_128_AES,j,count,d);
1725 if (doit[D_IGE_192_AES])
1727 for (j=0; j<SIZE_NUM; j++)
1729 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1731 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1732 AES_ige_encrypt(buf,buf2,
1733 (unsigned long)lengths[j],&aes_ks2,
1736 print_result(D_IGE_192_AES,j,count,d);
1739 if (doit[D_IGE_256_AES])
1741 for (j=0; j<SIZE_NUM; j++)
1743 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1745 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1746 AES_ige_encrypt(buf,buf2,
1747 (unsigned long)lengths[j],&aes_ks3,
1750 print_result(D_IGE_256_AES,j,count,d);
1756 #ifndef OPENSSL_NO_CAMELLIA
1757 if (doit[D_CBC_128_CML])
1759 for (j=0; j<SIZE_NUM; j++)
1761 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1763 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1764 Camellia_cbc_encrypt(buf,buf,
1765 (unsigned long)lengths[j],&camellia_ks1,
1766 iv,CAMELLIA_ENCRYPT);
1768 print_result(D_CBC_128_CML,j,count,d);
1771 if (doit[D_CBC_192_CML])
1773 for (j=0; j<SIZE_NUM; j++)
1775 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1777 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1778 Camellia_cbc_encrypt(buf,buf,
1779 (unsigned long)lengths[j],&camellia_ks2,
1780 iv,CAMELLIA_ENCRYPT);
1782 print_result(D_CBC_192_CML,j,count,d);
1785 if (doit[D_CBC_256_CML])
1787 for (j=0; j<SIZE_NUM; j++)
1789 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1791 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1792 Camellia_cbc_encrypt(buf,buf,
1793 (unsigned long)lengths[j],&camellia_ks3,
1794 iv,CAMELLIA_ENCRYPT);
1796 print_result(D_CBC_256_CML,j,count,d);
1801 #ifndef OPENSSL_NO_IDEA
1802 if (doit[D_CBC_IDEA])
1804 for (j=0; j<SIZE_NUM; j++)
1806 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1808 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1809 idea_cbc_encrypt(buf,buf,
1810 (unsigned long)lengths[j],&idea_ks,
1813 print_result(D_CBC_IDEA,j,count,d);
1817 #ifndef OPENSSL_NO_SEED
1818 if (doit[D_CBC_SEED])
1820 for (j=0; j<SIZE_NUM; j++)
1822 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1824 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1825 SEED_cbc_encrypt(buf,buf,
1826 (unsigned long)lengths[j],&seed_ks,iv,1);
1828 print_result(D_CBC_SEED,j,count,d);
1832 #ifndef OPENSSL_NO_RC2
1833 if (doit[D_CBC_RC2])
1835 for (j=0; j<SIZE_NUM; j++)
1837 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1839 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1840 RC2_cbc_encrypt(buf,buf,
1841 (unsigned long)lengths[j],&rc2_ks,
1844 print_result(D_CBC_RC2,j,count,d);
1848 #ifndef OPENSSL_NO_RC5
1849 if (doit[D_CBC_RC5])
1851 for (j=0; j<SIZE_NUM; j++)
1853 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1855 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1856 RC5_32_cbc_encrypt(buf,buf,
1857 (unsigned long)lengths[j],&rc5_ks,
1860 print_result(D_CBC_RC5,j,count,d);
1864 #ifndef OPENSSL_NO_BF
1867 for (j=0; j<SIZE_NUM; j++)
1869 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1871 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1872 BF_cbc_encrypt(buf,buf,
1873 (unsigned long)lengths[j],&bf_ks,
1876 print_result(D_CBC_BF,j,count,d);
1880 #ifndef OPENSSL_NO_CAST
1881 if (doit[D_CBC_CAST])
1883 for (j=0; j<SIZE_NUM; j++)
1885 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1887 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1888 CAST_cbc_encrypt(buf,buf,
1889 (unsigned long)lengths[j],&cast_ks,
1892 print_result(D_CBC_CAST,j,count,d);
1899 for (j=0; j<SIZE_NUM; j++)
1906 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1907 /* -O3 -fschedule-insns messes up an
1908 * optimization here! names[D_EVP]
1909 * somehow becomes NULL */
1910 print_message(names[D_EVP],save_count,
1913 EVP_CIPHER_CTX_init(&ctx);
1915 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1917 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1918 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1922 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1923 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1925 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1926 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1928 EVP_DecryptFinal_ex(&ctx,buf,&outl);
1930 EVP_EncryptFinal_ex(&ctx,buf,&outl);
1932 EVP_CIPHER_CTX_cleanup(&ctx);
1936 names[D_EVP]=OBJ_nid2ln(evp_md->type);
1937 print_message(names[D_EVP],save_count,
1941 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1942 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
1946 print_result(D_EVP,j,count,d);
1950 RAND_pseudo_bytes(buf,36);
1951 #ifndef OPENSSL_NO_RSA
1952 for (j=0; j<RSA_NUM; j++)
1955 if (!rsa_doit[j]) continue;
1956 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
1959 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
1960 ERR_print_errors(bio_err);
1965 pkey_print_message("private","rsa",
1966 rsa_c[j][0],rsa_bits[j],
1968 /* RSA_blinding_on(rsa_key[j],NULL); */
1970 for (count=0,run=1; COND(rsa_c[j][0]); count++)
1972 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
1973 &rsa_num, rsa_key[j]);
1977 "RSA sign failure\n");
1978 ERR_print_errors(bio_err);
1984 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
1985 : "%ld %d bit private RSA's in %.2fs\n",
1986 count,rsa_bits[j],d);
1987 rsa_results[j][0]=d/(double)count;
1992 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
1995 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
1996 ERR_print_errors(bio_err);
2001 pkey_print_message("public","rsa",
2002 rsa_c[j][1],rsa_bits[j],
2005 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2007 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2008 rsa_num, rsa_key[j]);
2012 "RSA verify failure\n");
2013 ERR_print_errors(bio_err);
2019 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2020 : "%ld %d bit public RSA's in %.2fs\n",
2021 count,rsa_bits[j],d);
2022 rsa_results[j][1]=d/(double)count;
2028 /* if longer than 10s, don't do any more */
2029 for (j++; j<RSA_NUM; j++)
2035 RAND_pseudo_bytes(buf,20);
2036 #ifndef OPENSSL_NO_DSA
2037 if (RAND_status() != 1)
2039 RAND_seed(rnd_seed, sizeof rnd_seed);
2042 for (j=0; j<DSA_NUM; j++)
2047 if (!dsa_doit[j]) continue;
2048 /* DSA_generate_key(dsa_key[j]); */
2049 /* DSA_sign_setup(dsa_key[j],NULL); */
2050 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2054 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2055 ERR_print_errors(bio_err);
2060 pkey_print_message("sign","dsa",
2061 dsa_c[j][0],dsa_bits[j],
2064 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2066 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2071 "DSA sign failure\n");
2072 ERR_print_errors(bio_err);
2078 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2079 : "%ld %d bit DSA signs in %.2fs\n",
2080 count,dsa_bits[j],d);
2081 dsa_results[j][0]=d/(double)count;
2085 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2089 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2090 ERR_print_errors(bio_err);
2095 pkey_print_message("verify","dsa",
2096 dsa_c[j][1],dsa_bits[j],
2099 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2101 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2106 "DSA verify failure\n");
2107 ERR_print_errors(bio_err);
2113 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2114 : "%ld %d bit DSA verify in %.2fs\n",
2115 count,dsa_bits[j],d);
2116 dsa_results[j][1]=d/(double)count;
2121 /* if longer than 10s, don't do any more */
2122 for (j++; j<DSA_NUM; j++)
2126 if (rnd_fake) RAND_cleanup();
2129 #ifndef OPENSSL_NO_ECDSA
2130 if (RAND_status() != 1)
2132 RAND_seed(rnd_seed, sizeof rnd_seed);
2135 for (j=0; j<EC_NUM; j++)
2139 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2140 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2141 if (ecdsa[j] == NULL)
2143 BIO_printf(bio_err,"ECDSA failure.\n");
2144 ERR_print_errors(bio_err);
2150 EC_KEY_precompute_mult(ecdsa[j], NULL);
2152 /* Perform ECDSA signature test */
2153 EC_KEY_generate_key(ecdsa[j]);
2154 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2155 &ecdsasiglen, ecdsa[j]);
2158 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2159 ERR_print_errors(bio_err);
2164 pkey_print_message("sign","ecdsa",
2166 test_curves_bits[j],
2170 for (count=0,run=1; COND(ecdsa_c[j][0]);
2173 ret=ECDSA_sign(0, buf, 20,
2174 ecdsasig, &ecdsasiglen,
2178 BIO_printf(bio_err, "ECDSA sign failure\n");
2179 ERR_print_errors(bio_err);
2186 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2187 "%ld %d bit ECDSA signs in %.2fs \n",
2188 count, test_curves_bits[j], d);
2189 ecdsa_results[j][0]=d/(double)count;
2193 /* Perform ECDSA verification test */
2194 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2195 ecdsasiglen, ecdsa[j]);
2198 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2199 ERR_print_errors(bio_err);
2204 pkey_print_message("verify","ecdsa",
2206 test_curves_bits[j],
2209 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2211 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2214 BIO_printf(bio_err, "ECDSA verify failure\n");
2215 ERR_print_errors(bio_err);
2221 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2222 : "%ld %d bit ECDSA verify in %.2fs\n",
2223 count, test_curves_bits[j], d);
2224 ecdsa_results[j][1]=d/(double)count;
2229 /* if longer than 10s, don't do any more */
2230 for (j++; j<EC_NUM; j++)
2235 if (rnd_fake) RAND_cleanup();
2238 #ifndef OPENSSL_NO_ECDH
2239 if (RAND_status() != 1)
2241 RAND_seed(rnd_seed, sizeof rnd_seed);
2244 for (j=0; j<EC_NUM; j++)
2246 if (!ecdh_doit[j]) continue;
2247 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2248 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2249 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2251 BIO_printf(bio_err,"ECDH failure.\n");
2252 ERR_print_errors(bio_err);
2257 /* generate two ECDH key pairs */
2258 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2259 !EC_KEY_generate_key(ecdh_b[j]))
2261 BIO_printf(bio_err,"ECDH key generation failure.\n");
2262 ERR_print_errors(bio_err);
2267 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2268 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2270 int field_size, outlen;
2271 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2272 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2273 if (field_size <= 24 * 8)
2275 outlen = KDF1_SHA1_len;
2280 outlen = (field_size+7)/8;
2283 secret_size_a = ECDH_compute_key(secret_a, outlen,
2284 EC_KEY_get0_public_key(ecdh_b[j]),
2286 secret_size_b = ECDH_compute_key(secret_b, outlen,
2287 EC_KEY_get0_public_key(ecdh_a[j]),
2289 if (secret_size_a != secret_size_b)
2294 for (secret_idx = 0;
2295 (secret_idx < secret_size_a)
2296 && (ecdh_checks == 1);
2299 if (secret_a[secret_idx] != secret_b[secret_idx])
2303 if (ecdh_checks == 0)
2305 BIO_printf(bio_err,"ECDH computations don't match.\n");
2306 ERR_print_errors(bio_err);
2310 pkey_print_message("","ecdh",
2312 test_curves_bits[j],
2315 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2317 ECDH_compute_key(secret_a, outlen,
2318 EC_KEY_get0_public_key(ecdh_b[j]),
2322 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2323 count, test_curves_bits[j], d);
2324 ecdh_results[j][0]=d/(double)count;
2332 /* if longer than 10s, don't do any more */
2333 for (j++; j<EC_NUM; j++)
2337 if (rnd_fake) RAND_cleanup();
2344 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2345 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2347 printf("%s ",BN_options());
2348 #ifndef OPENSSL_NO_MD2
2349 printf("%s ",MD2_options());
2351 #ifndef OPENSSL_NO_RC4
2352 printf("%s ",RC4_options());
2354 #ifndef OPENSSL_NO_DES
2355 printf("%s ",DES_options());
2357 #ifndef OPENSSL_NO_AES
2358 printf("%s ",AES_options());
2360 #ifndef OPENSSL_NO_IDEA
2361 printf("%s ",idea_options());
2363 #ifndef OPENSSL_NO_BF
2364 printf("%s ",BF_options());
2366 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2372 fprintf(stdout,"+H");
2375 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2376 fprintf(stdout,"type ");
2378 for (j=0; j<SIZE_NUM; j++)
2379 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2380 fprintf(stdout,"\n");
2383 for (k=0; k<ALGOR_NUM; k++)
2385 if (!doit[k]) continue;
2387 fprintf(stdout,"+F:%d:%s",k,names[k]);
2389 fprintf(stdout,"%-13s",names[k]);
2390 for (j=0; j<SIZE_NUM; j++)
2392 if (results[k][j] > 10000 && !mr)
2393 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2395 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2397 fprintf(stdout,"\n");
2399 #ifndef OPENSSL_NO_RSA
2401 for (k=0; k<RSA_NUM; k++)
2403 if (!rsa_doit[k]) continue;
2406 printf("%18ssign verify sign/s verify/s\n"," ");
2410 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2411 k,rsa_bits[k],rsa_results[k][0],
2414 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2415 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2416 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2419 #ifndef OPENSSL_NO_DSA
2421 for (k=0; k<DSA_NUM; k++)
2423 if (!dsa_doit[k]) continue;
2426 printf("%18ssign verify sign/s verify/s\n"," ");
2430 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2431 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2433 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2434 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2435 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2438 #ifndef OPENSSL_NO_ECDSA
2440 for (k=0; k<EC_NUM; k++)
2442 if (!ecdsa_doit[k]) continue;
2445 printf("%30ssign verify sign/s verify/s\n"," ");
2450 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2451 k, test_curves_bits[k],
2452 ecdsa_results[k][0],ecdsa_results[k][1]);
2455 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2456 test_curves_bits[k],
2457 test_curves_names[k],
2458 ecdsa_results[k][0],ecdsa_results[k][1],
2459 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2464 #ifndef OPENSSL_NO_ECDH
2466 for (k=0; k<EC_NUM; k++)
2468 if (!ecdh_doit[k]) continue;
2471 printf("%30sop op/s\n"," ");
2475 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2476 k, test_curves_bits[k],
2477 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2480 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2481 test_curves_bits[k],
2482 test_curves_names[k],
2483 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2490 ERR_print_errors(bio_err);
2491 if (buf != NULL) OPENSSL_free(buf);
2492 if (buf2 != NULL) OPENSSL_free(buf2);
2493 #ifndef OPENSSL_NO_RSA
2494 for (i=0; i<RSA_NUM; i++)
2495 if (rsa_key[i] != NULL)
2496 RSA_free(rsa_key[i]);
2498 #ifndef OPENSSL_NO_DSA
2499 for (i=0; i<DSA_NUM; i++)
2500 if (dsa_key[i] != NULL)
2501 DSA_free(dsa_key[i]);
2504 #ifndef OPENSSL_NO_ECDSA
2505 for (i=0; i<EC_NUM; i++)
2506 if (ecdsa[i] != NULL)
2507 EC_KEY_free(ecdsa[i]);
2509 #ifndef OPENSSL_NO_ECDH
2510 for (i=0; i<EC_NUM; i++)
2512 if (ecdh_a[i] != NULL)
2513 EC_KEY_free(ecdh_a[i]);
2514 if (ecdh_b[i] != NULL)
2515 EC_KEY_free(ecdh_b[i]);
2523 static void print_message(const char *s, long num, int length)
2526 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2527 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2528 (void)BIO_flush(bio_err);
2531 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2532 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2533 (void)BIO_flush(bio_err);
2540 static void pkey_print_message(const char *str, const char *str2, long num,
2544 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2545 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2546 (void)BIO_flush(bio_err);
2549 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2550 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2551 (void)BIO_flush(bio_err);
2558 static void print_result(int alg,int run_no,int count,double time_used)
2560 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2561 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2562 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2566 static char *sstrsep(char **string, const char *delim)
2569 char *token = *string;
2574 memset(isdelim, 0, sizeof isdelim);
2579 isdelim[(unsigned char)(*delim)] = 1;
2583 while (!isdelim[(unsigned char)(**string)])
2597 static int do_multi(int multi)
2602 static char sep[]=":";
2604 fds=malloc(multi*sizeof *fds);
2605 for(n=0 ; n < multi ; ++n)
2626 printf("Forked child %d\n",n);
2629 /* for now, assume the pipe is long enough to take all the output */
2630 for(n=0 ; n < multi ; ++n)
2636 f=fdopen(fds[n],"r");
2637 while(fgets(buf,sizeof buf,f))
2644 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2648 printf("Got: %s from %d\n",buf,n);
2649 if(!strncmp(buf,"+F:",3))
2655 alg=atoi(sstrsep(&p,sep));
2657 for(j=0 ; j < SIZE_NUM ; ++j)
2658 results[alg][j]+=atof(sstrsep(&p,sep));
2660 else if(!strncmp(buf,"+F2:",4))
2666 k=atoi(sstrsep(&p,sep));
2669 d=atof(sstrsep(&p,sep));
2671 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2673 rsa_results[k][0]=d;
2675 d=atof(sstrsep(&p,sep));
2677 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2679 rsa_results[k][1]=d;
2681 else if(!strncmp(buf,"+F2:",4))
2687 k=atoi(sstrsep(&p,sep));
2690 d=atof(sstrsep(&p,sep));
2692 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2694 rsa_results[k][0]=d;
2696 d=atof(sstrsep(&p,sep));
2698 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2700 rsa_results[k][1]=d;
2702 else if(!strncmp(buf,"+F3:",4))
2708 k=atoi(sstrsep(&p,sep));
2711 d=atof(sstrsep(&p,sep));
2713 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2715 dsa_results[k][0]=d;
2717 d=atof(sstrsep(&p,sep));
2719 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2721 dsa_results[k][1]=d;
2723 #ifndef OPENSSL_NO_ECDSA
2724 else if(!strncmp(buf,"+F4:",4))
2730 k=atoi(sstrsep(&p,sep));
2733 d=atof(sstrsep(&p,sep));
2735 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2737 ecdsa_results[k][0]=d;
2739 d=atof(sstrsep(&p,sep));
2741 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2743 ecdsa_results[k][1]=d;
2747 #ifndef OPENSSL_NO_ECDH
2748 else if(!strncmp(buf,"+F5:",4))
2754 k=atoi(sstrsep(&p,sep));
2757 d=atof(sstrsep(&p,sep));
2759 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2761 ecdh_results[k][0]=d;
2766 else if(!strncmp(buf,"+H:",3))
2770 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);