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>
188 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
202 #define BUFSIZE ((long)1024*8+1)
206 static int usertime=1;
208 static double Time_F(int s);
209 static void print_message(const char *s,long num,int length);
210 static void pkey_print_message(const char *str, const char *str2,
211 long num, int bits, int sec);
212 static void print_result(int alg,int run_no,int count,double time_used);
214 static int do_multi(int multi);
223 #define MAX_ECDH_SIZE 256
225 static const char *names[ALGOR_NUM]={
226 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
227 "des cbc","des ede3","idea cbc","seed cbc",
228 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
229 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
230 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
231 "evp","sha256","sha512","whirlpool",
232 "aes-128 ige","aes-192 ige","aes-256 ige"};
233 static double results[ALGOR_NUM][SIZE_NUM];
234 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
235 #ifndef OPENSSL_NO_RSA
236 static double rsa_results[RSA_NUM][2];
238 #ifndef OPENSSL_NO_DSA
239 static double dsa_results[DSA_NUM][2];
241 #ifndef OPENSSL_NO_ECDSA
242 static double ecdsa_results[EC_NUM][2];
244 #ifndef OPENSSL_NO_ECDH
245 static double ecdh_results[EC_NUM][1];
248 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
249 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
250 static int rnd_fake = 0;
254 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
255 #define SIGRETTYPE void
257 #define SIGRETTYPE int
260 static SIGRETTYPE sig_done(int sig);
261 static SIGRETTYPE sig_done(int sig)
263 signal(SIGALRM,sig_done);
277 static unsigned int lapse,schlock;
278 static void alarm(unsigned int secs) { lapse = secs*1000; }
280 static DWORD WINAPI sleepy(VOID *arg)
288 static double Time_F(int s)
294 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
297 DWORD ret=GetLastError();
298 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
301 CloseHandle(thr); /* detach the thread */
302 while (!schlock) Sleep(0); /* scheduler spinlock */
305 return app_tminterval(s,usertime);
309 static double Time_F(int s)
311 return app_tminterval(s,usertime);
316 #ifndef OPENSSL_NO_ECDH
317 static const int KDF1_SHA1_len = 20;
318 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
320 #ifndef OPENSSL_NO_SHA
321 if (*outlen < SHA_DIGEST_LENGTH)
324 *outlen = SHA_DIGEST_LENGTH;
325 return SHA1(in, inlen, out);
328 #endif /* OPENSSL_NO_SHA */
330 #endif /* OPENSSL_NO_ECDH */
333 int MAIN(int, char **);
335 int MAIN(int argc, char **argv)
337 #ifndef OPENSSL_NO_ENGINE
340 unsigned char *buf=NULL,*buf2=NULL;
342 long count=0,save_count=0;
344 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
347 #ifndef OPENSSL_NO_RSA
350 unsigned char md[EVP_MAX_MD_SIZE];
351 #ifndef OPENSSL_NO_MD2
352 unsigned char md2[MD2_DIGEST_LENGTH];
354 #ifndef OPENSSL_NO_MDC2
355 unsigned char mdc2[MDC2_DIGEST_LENGTH];
357 #ifndef OPENSSL_NO_MD4
358 unsigned char md4[MD4_DIGEST_LENGTH];
360 #ifndef OPENSSL_NO_MD5
361 unsigned char md5[MD5_DIGEST_LENGTH];
362 unsigned char hmac[MD5_DIGEST_LENGTH];
364 #ifndef OPENSSL_NO_SHA
365 unsigned char sha[SHA_DIGEST_LENGTH];
366 #ifndef OPENSSL_NO_SHA256
367 unsigned char sha256[SHA256_DIGEST_LENGTH];
369 #ifndef OPENSSL_NO_SHA512
370 unsigned char sha512[SHA512_DIGEST_LENGTH];
373 #ifndef OPENSSL_NO_WHIRLPOOL
374 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
376 #ifndef OPENSSL_NO_RIPEMD
377 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
379 #ifndef OPENSSL_NO_RC4
382 #ifndef OPENSSL_NO_RC5
385 #ifndef OPENSSL_NO_RC2
388 #ifndef OPENSSL_NO_IDEA
389 IDEA_KEY_SCHEDULE idea_ks;
391 #ifndef OPENSSL_NO_SEED
392 SEED_KEY_SCHEDULE seed_ks;
394 #ifndef OPENSSL_NO_BF
397 #ifndef OPENSSL_NO_CAST
400 static const unsigned char key16[16]=
401 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
402 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
403 #ifndef OPENSSL_NO_AES
404 static const unsigned char key24[24]=
405 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
406 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
407 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
408 static const unsigned char key32[32]=
409 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
410 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
411 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
412 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
414 #ifndef OPENSSL_NO_CAMELLIA
415 static const unsigned char ckey24[24]=
416 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
417 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
418 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
419 static const unsigned char ckey32[32]=
420 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
421 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
422 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
423 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
425 #ifndef OPENSSL_NO_AES
426 #define MAX_BLOCK_SIZE 128
428 #define MAX_BLOCK_SIZE 64
430 unsigned char DES_iv[8];
431 unsigned char iv[2*MAX_BLOCK_SIZE/8];
432 #ifndef OPENSSL_NO_DES
433 DES_cblock *buf_as_des_cblock = NULL;
434 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
435 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
436 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
437 DES_key_schedule sch;
438 DES_key_schedule sch2;
439 DES_key_schedule sch3;
441 #ifndef OPENSSL_NO_AES
442 AES_KEY aes_ks1, aes_ks2, aes_ks3;
444 #ifndef OPENSSL_NO_CAMELLIA
445 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
457 #define D_CBC_IDEA 10
458 #define D_CBC_SEED 11
462 #define D_CBC_CAST 15
463 #define D_CBC_128_AES 16
464 #define D_CBC_192_AES 17
465 #define D_CBC_256_AES 18
466 #define D_CBC_128_CML 19
467 #define D_CBC_192_CML 20
468 #define D_CBC_256_CML 21
472 #define D_WHIRLPOOL 25
473 #define D_IGE_128_AES 26
474 #define D_IGE_192_AES 27
475 #define D_IGE_256_AES 28
477 long c[ALGOR_NUM][SIZE_NUM];
503 #ifndef OPENSSL_NO_RSA
504 RSA *rsa_key[RSA_NUM];
505 long rsa_c[RSA_NUM][2];
506 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
507 static unsigned char *rsa_data[RSA_NUM]=
508 {test512,test1024,test2048,test4096};
509 static int rsa_data_length[RSA_NUM]={
510 sizeof(test512),sizeof(test1024),
511 sizeof(test2048),sizeof(test4096)};
513 #ifndef OPENSSL_NO_DSA
514 DSA *dsa_key[DSA_NUM];
515 long dsa_c[DSA_NUM][2];
516 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
518 #ifndef OPENSSL_NO_EC
519 /* We only test over the following curves as they are representative,
520 * To add tests over more curves, simply add the curve NID
521 * and curve name to the following arrays and increase the
522 * EC_NUM value accordingly.
524 static unsigned int test_curves[EC_NUM] =
528 NID_X9_62_prime192v1,
530 NID_X9_62_prime256v1,
545 static const char * test_curves_names[EC_NUM] =
566 static int test_curves_bits[EC_NUM] =
568 160, 192, 224, 256, 384, 521,
569 163, 233, 283, 409, 571,
570 163, 233, 283, 409, 571
575 #ifndef OPENSSL_NO_ECDSA
576 unsigned char ecdsasig[256];
577 unsigned int ecdsasiglen;
578 EC_KEY *ecdsa[EC_NUM];
579 long ecdsa_c[EC_NUM][2];
582 #ifndef OPENSSL_NO_ECDH
583 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
584 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
585 int secret_size_a, secret_size_b;
588 long ecdh_c[EC_NUM][2];
591 int rsa_doit[RSA_NUM];
592 int dsa_doit[DSA_NUM];
593 #ifndef OPENSSL_NO_ECDSA
594 int ecdsa_doit[EC_NUM];
596 #ifndef OPENSSL_NO_ECDH
597 int ecdh_doit[EC_NUM];
601 const EVP_CIPHER *evp_cipher=NULL;
602 const EVP_MD *evp_md=NULL;
613 memset(results, 0, sizeof(results));
614 #ifndef OPENSSL_NO_DSA
615 memset(dsa_key,0,sizeof(dsa_key));
617 #ifndef OPENSSL_NO_ECDSA
618 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
620 #ifndef OPENSSL_NO_ECDH
621 for (i=0; i<EC_NUM; i++)
630 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
631 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
633 if (!load_config(bio_err, NULL))
636 #ifndef OPENSSL_NO_RSA
637 memset(rsa_key,0,sizeof(rsa_key));
638 for (i=0; i<RSA_NUM; i++)
642 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
644 BIO_printf(bio_err,"out of memory\n");
647 #ifndef OPENSSL_NO_DES
648 buf_as_des_cblock = (DES_cblock *)buf;
650 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
652 BIO_printf(bio_err,"out of memory\n");
656 memset(c,0,sizeof(c));
657 memset(DES_iv,0,sizeof(DES_iv));
658 memset(iv,0,sizeof(iv));
660 for (i=0; i<ALGOR_NUM; i++)
662 for (i=0; i<RSA_NUM; i++)
664 for (i=0; i<DSA_NUM; i++)
666 #ifndef OPENSSL_NO_ECDSA
667 for (i=0; i<EC_NUM; i++)
670 #ifndef OPENSSL_NO_ECDH
671 for (i=0; i<EC_NUM; i++)
681 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
684 j--; /* Otherwise, -elapsed gets confused with
687 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
693 BIO_printf(bio_err,"no EVP given\n");
696 evp_cipher=EVP_get_cipherbyname(*argv);
699 evp_md=EVP_get_digestbyname(*argv);
701 if(!evp_cipher && !evp_md)
703 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
708 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
711 j--; /* Otherwise, -elapsed gets confused with
714 #ifndef OPENSSL_NO_ENGINE
715 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
721 BIO_printf(bio_err,"no engine given\n");
724 e = setup_engine(bio_err, *argv, 0);
725 /* j will be increased again further down. We just
726 don't want speed to confuse an engine with an
727 algorithm, especially when none is given (which
728 means all of them should be run) */
733 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
739 BIO_printf(bio_err,"no multi count given\n");
745 BIO_printf(bio_err,"bad multi count\n");
748 j--; /* Otherwise, -mr gets confused with
752 else if (argc > 0 && !strcmp(*argv,"-mr"))
755 j--; /* Otherwise, -mr gets confused with
759 #ifndef OPENSSL_NO_MD2
760 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
763 #ifndef OPENSSL_NO_MDC2
764 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
767 #ifndef OPENSSL_NO_MD4
768 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
771 #ifndef OPENSSL_NO_MD5
772 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
775 #ifndef OPENSSL_NO_MD5
776 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
779 #ifndef OPENSSL_NO_SHA
780 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
782 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
786 #ifndef OPENSSL_NO_SHA256
787 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
790 #ifndef OPENSSL_NO_SHA512
791 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
795 #ifndef OPENSSL_NO_WHIRLPOOL
796 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
799 #ifndef OPENSSL_NO_RIPEMD
800 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
802 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
804 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
807 #ifndef OPENSSL_NO_RC4
808 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
811 #ifndef OPENSSL_NO_DES
812 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
813 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
816 #ifndef OPENSSL_NO_AES
817 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
818 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
819 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
820 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
821 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
822 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
825 #ifndef OPENSSL_NO_CAMELLIA
826 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
827 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
828 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
831 #ifndef OPENSSL_NO_RSA
832 #if 0 /* was: #ifdef RSAref */
833 if (strcmp(*argv,"rsaref") == 0)
835 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
841 if (strcmp(*argv,"openssl") == 0)
843 RSA_set_default_method(RSA_PKCS1_SSLeay());
848 #endif /* !OPENSSL_NO_RSA */
849 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
850 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
851 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
852 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
853 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
854 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
855 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
857 #ifndef OPENSSL_NO_RC2
858 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
859 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
862 #ifndef OPENSSL_NO_RC5
863 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
864 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
867 #ifndef OPENSSL_NO_IDEA
868 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
869 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
872 #ifndef OPENSSL_NO_SEED
873 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
874 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
877 #ifndef OPENSSL_NO_BF
878 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
879 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
880 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
883 #ifndef OPENSSL_NO_CAST
884 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
885 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
886 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
889 #ifndef OPENSSL_NO_DES
890 if (strcmp(*argv,"des") == 0)
897 #ifndef OPENSSL_NO_AES
898 if (strcmp(*argv,"aes") == 0)
900 doit[D_CBC_128_AES]=1;
901 doit[D_CBC_192_AES]=1;
902 doit[D_CBC_256_AES]=1;
906 #ifndef OPENSSL_NO_CAMELLIA
907 if (strcmp(*argv,"camellia") == 0)
909 doit[D_CBC_128_CML]=1;
910 doit[D_CBC_192_CML]=1;
911 doit[D_CBC_256_CML]=1;
915 #ifndef OPENSSL_NO_RSA
916 if (strcmp(*argv,"rsa") == 0)
918 rsa_doit[R_RSA_512]=1;
919 rsa_doit[R_RSA_1024]=1;
920 rsa_doit[R_RSA_2048]=1;
921 rsa_doit[R_RSA_4096]=1;
925 #ifndef OPENSSL_NO_DSA
926 if (strcmp(*argv,"dsa") == 0)
928 dsa_doit[R_DSA_512]=1;
929 dsa_doit[R_DSA_1024]=1;
930 dsa_doit[R_DSA_2048]=1;
934 #ifndef OPENSSL_NO_ECDSA
935 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
936 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
937 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
938 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
939 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
940 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
941 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
942 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
943 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
944 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
945 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
946 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
947 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
948 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
949 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
950 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
951 else if (strcmp(*argv,"ecdsa") == 0)
953 for (i=0; i < EC_NUM; i++)
958 #ifndef OPENSSL_NO_ECDH
959 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
960 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
961 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
962 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
963 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
964 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
965 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
966 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
967 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
968 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
969 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
970 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
971 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
972 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
973 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
974 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
975 else if (strcmp(*argv,"ecdh") == 0)
977 for (i=0; i < EC_NUM; i++)
983 BIO_printf(bio_err,"Error: bad option or value\n");
984 BIO_printf(bio_err,"\n");
985 BIO_printf(bio_err,"Available values:\n");
986 #ifndef OPENSSL_NO_MD2
987 BIO_printf(bio_err,"md2 ");
989 #ifndef OPENSSL_NO_MDC2
990 BIO_printf(bio_err,"mdc2 ");
992 #ifndef OPENSSL_NO_MD4
993 BIO_printf(bio_err,"md4 ");
995 #ifndef OPENSSL_NO_MD5
996 BIO_printf(bio_err,"md5 ");
997 #ifndef OPENSSL_NO_HMAC
998 BIO_printf(bio_err,"hmac ");
1001 #ifndef OPENSSL_NO_SHA1
1002 BIO_printf(bio_err,"sha1 ");
1004 #ifndef OPENSSL_NO_SHA256
1005 BIO_printf(bio_err,"sha256 ");
1007 #ifndef OPENSSL_NO_SHA512
1008 BIO_printf(bio_err,"sha512 ");
1010 #ifndef OPENSSL_NO_WHIRLPOOL
1011 BIO_printf(bio_err,"whirlpool");
1013 #ifndef OPENSSL_NO_RIPEMD160
1014 BIO_printf(bio_err,"rmd160");
1016 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1017 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1018 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1019 !defined(OPENSSL_NO_WHIRLPOOL)
1020 BIO_printf(bio_err,"\n");
1023 #ifndef OPENSSL_NO_IDEA
1024 BIO_printf(bio_err,"idea-cbc ");
1026 #ifndef OPENSSL_NO_SEED
1027 BIO_printf(bio_err,"seed-cbc ");
1029 #ifndef OPENSSL_NO_RC2
1030 BIO_printf(bio_err,"rc2-cbc ");
1032 #ifndef OPENSSL_NO_RC5
1033 BIO_printf(bio_err,"rc5-cbc ");
1035 #ifndef OPENSSL_NO_BF
1036 BIO_printf(bio_err,"bf-cbc");
1038 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1039 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1040 BIO_printf(bio_err,"\n");
1042 #ifndef OPENSSL_NO_DES
1043 BIO_printf(bio_err,"des-cbc des-ede3 ");
1045 #ifndef OPENSSL_NO_AES
1046 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1047 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1049 #ifndef OPENSSL_NO_CAMELLIA
1050 BIO_printf(bio_err,"\n");
1051 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1053 #ifndef OPENSSL_NO_RC4
1054 BIO_printf(bio_err,"rc4");
1056 BIO_printf(bio_err,"\n");
1058 #ifndef OPENSSL_NO_RSA
1059 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1062 #ifndef OPENSSL_NO_DSA
1063 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1065 #ifndef OPENSSL_NO_ECDSA
1066 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1067 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1068 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1069 BIO_printf(bio_err,"ecdsa\n");
1071 #ifndef OPENSSL_NO_ECDH
1072 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1073 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1074 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1075 BIO_printf(bio_err,"ecdh\n");
1078 #ifndef OPENSSL_NO_IDEA
1079 BIO_printf(bio_err,"idea ");
1081 #ifndef OPENSSL_NO_SEED
1082 BIO_printf(bio_err,"seed ");
1084 #ifndef OPENSSL_NO_RC2
1085 BIO_printf(bio_err,"rc2 ");
1087 #ifndef OPENSSL_NO_DES
1088 BIO_printf(bio_err,"des ");
1090 #ifndef OPENSSL_NO_AES
1091 BIO_printf(bio_err,"aes ");
1093 #ifndef OPENSSL_NO_CAMELLIA
1094 BIO_printf(bio_err,"camellia ");
1096 #ifndef OPENSSL_NO_RSA
1097 BIO_printf(bio_err,"rsa ");
1099 #ifndef OPENSSL_NO_BF
1100 BIO_printf(bio_err,"blowfish");
1102 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1103 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1104 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1105 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1106 BIO_printf(bio_err,"\n");
1109 BIO_printf(bio_err,"\n");
1110 BIO_printf(bio_err,"Available options:\n");
1111 #if defined(TIMES) || defined(USE_TOD)
1112 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1114 #ifndef OPENSSL_NO_ENGINE
1115 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1117 BIO_printf(bio_err,"-evp e use EVP e.\n");
1118 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1119 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1121 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1131 if(multi && do_multi(multi))
1137 for (i=0; i<ALGOR_NUM; i++)
1142 for (i=0; i<RSA_NUM; i++)
1144 for (i=0; i<DSA_NUM; i++)
1146 #ifndef OPENSSL_NO_ECDSA
1147 for (i=0; i<EC_NUM; i++)
1150 #ifndef OPENSSL_NO_ECDH
1151 for (i=0; i<EC_NUM; i++)
1155 for (i=0; i<ALGOR_NUM; i++)
1156 if (doit[i]) pr_header++;
1158 if (usertime == 0 && !mr)
1159 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1161 #ifndef OPENSSL_NO_RSA
1162 for (i=0; i<RSA_NUM; i++)
1164 const unsigned char *p;
1167 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1168 if (rsa_key[i] == NULL)
1170 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1176 BIO_printf(bio_err,mr ? "+RK:%d:"
1177 : "Loaded RSA key, %d bit modulus and e= 0x",
1178 BN_num_bits(rsa_key[i]->n));
1179 BN_print(bio_err,rsa_key[i]->e);
1180 BIO_printf(bio_err,"\n");
1186 #ifndef OPENSSL_NO_DSA
1187 dsa_key[0]=get_dsa512();
1188 dsa_key[1]=get_dsa1024();
1189 dsa_key[2]=get_dsa2048();
1192 #ifndef OPENSSL_NO_DES
1193 DES_set_key_unchecked(&key,&sch);
1194 DES_set_key_unchecked(&key2,&sch2);
1195 DES_set_key_unchecked(&key3,&sch3);
1197 #ifndef OPENSSL_NO_AES
1198 AES_set_encrypt_key(key16,128,&aes_ks1);
1199 AES_set_encrypt_key(key24,192,&aes_ks2);
1200 AES_set_encrypt_key(key32,256,&aes_ks3);
1202 #ifndef OPENSSL_NO_CAMELLIA
1203 Camellia_set_key(key16,128,&camellia_ks1);
1204 Camellia_set_key(ckey24,192,&camellia_ks2);
1205 Camellia_set_key(ckey32,256,&camellia_ks3);
1207 #ifndef OPENSSL_NO_IDEA
1208 idea_set_encrypt_key(key16,&idea_ks);
1210 #ifndef OPENSSL_NO_SEED
1211 SEED_set_key(key16,&seed_ks);
1213 #ifndef OPENSSL_NO_RC4
1214 RC4_set_key(&rc4_ks,16,key16);
1216 #ifndef OPENSSL_NO_RC2
1217 RC2_set_key(&rc2_ks,16,key16,128);
1219 #ifndef OPENSSL_NO_RC5
1220 RC5_32_set_key(&rc5_ks,16,key16,12);
1222 #ifndef OPENSSL_NO_BF
1223 BF_set_key(&bf_ks,16,key16);
1225 #ifndef OPENSSL_NO_CAST
1226 CAST_set_key(&cast_ks,16,key16);
1228 #ifndef OPENSSL_NO_RSA
1229 memset(rsa_c,0,sizeof(rsa_c));
1232 #ifndef OPENSSL_NO_DES
1233 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1239 for (it=count; it; it--)
1240 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
1245 c[D_MD2][0]=count/10;
1246 c[D_MDC2][0]=count/10;
1251 c[D_RMD160][0]=count;
1252 c[D_RC4][0]=count*5;
1253 c[D_CBC_DES][0]=count;
1254 c[D_EDE3_DES][0]=count/3;
1255 c[D_CBC_IDEA][0]=count;
1256 c[D_CBC_SEED][0]=count;
1257 c[D_CBC_RC2][0]=count;
1258 c[D_CBC_RC5][0]=count;
1259 c[D_CBC_BF][0]=count;
1260 c[D_CBC_CAST][0]=count;
1261 c[D_CBC_128_AES][0]=count;
1262 c[D_CBC_192_AES][0]=count;
1263 c[D_CBC_256_AES][0]=count;
1264 c[D_CBC_128_CML][0]=count;
1265 c[D_CBC_192_CML][0]=count;
1266 c[D_CBC_256_CML][0]=count;
1267 c[D_SHA256][0]=count;
1268 c[D_SHA512][0]=count;
1269 c[D_WHIRLPOOL][0]=count;
1270 c[D_IGE_128_AES][0]=count;
1271 c[D_IGE_192_AES][0]=count;
1272 c[D_IGE_256_AES][0]=count;
1274 for (i=1; i<SIZE_NUM; i++)
1276 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1277 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1278 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1279 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1280 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1281 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1282 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1283 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1284 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1285 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1287 for (i=1; i<SIZE_NUM; i++)
1291 l0=(long)lengths[i-1];
1292 l1=(long)lengths[i];
1293 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1294 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1295 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1296 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1297 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1298 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1299 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1300 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1301 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1302 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1303 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1304 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1305 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1306 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1307 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1308 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1309 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1310 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1312 #ifndef OPENSSL_NO_RSA
1313 rsa_c[R_RSA_512][0]=count/2000;
1314 rsa_c[R_RSA_512][1]=count/400;
1315 for (i=1; i<RSA_NUM; i++)
1317 rsa_c[i][0]=rsa_c[i-1][0]/8;
1318 rsa_c[i][1]=rsa_c[i-1][1]/4;
1319 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1323 if (rsa_c[i][0] == 0)
1332 #ifndef OPENSSL_NO_DSA
1333 dsa_c[R_DSA_512][0]=count/1000;
1334 dsa_c[R_DSA_512][1]=count/1000/2;
1335 for (i=1; i<DSA_NUM; i++)
1337 dsa_c[i][0]=dsa_c[i-1][0]/4;
1338 dsa_c[i][1]=dsa_c[i-1][1]/4;
1339 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1352 #ifndef OPENSSL_NO_ECDSA
1353 ecdsa_c[R_EC_P160][0]=count/1000;
1354 ecdsa_c[R_EC_P160][1]=count/1000/2;
1355 for (i=R_EC_P192; i<=R_EC_P521; i++)
1357 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1358 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1359 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1363 if (ecdsa_c[i] == 0)
1370 ecdsa_c[R_EC_K163][0]=count/1000;
1371 ecdsa_c[R_EC_K163][1]=count/1000/2;
1372 for (i=R_EC_K233; i<=R_EC_K571; i++)
1374 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1375 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1376 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1380 if (ecdsa_c[i] == 0)
1387 ecdsa_c[R_EC_B163][0]=count/1000;
1388 ecdsa_c[R_EC_B163][1]=count/1000/2;
1389 for (i=R_EC_B233; i<=R_EC_B571; i++)
1391 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1392 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1393 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1397 if (ecdsa_c[i] == 0)
1406 #ifndef OPENSSL_NO_ECDH
1407 ecdh_c[R_EC_P160][0]=count/1000;
1408 ecdh_c[R_EC_P160][1]=count/1000;
1409 for (i=R_EC_P192; i<=R_EC_P521; i++)
1411 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1412 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1413 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1424 ecdh_c[R_EC_K163][0]=count/1000;
1425 ecdh_c[R_EC_K163][1]=count/1000;
1426 for (i=R_EC_K233; i<=R_EC_K571; i++)
1428 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1429 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1430 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1441 ecdh_c[R_EC_B163][0]=count/1000;
1442 ecdh_c[R_EC_B163][1]=count/1000;
1443 for (i=R_EC_B233; i<=R_EC_B571; i++)
1445 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1446 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1447 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1460 #define COND(d) (count < (d))
1461 #define COUNT(d) (d)
1463 /* not worth fixing */
1464 # error "You cannot disable DES on systems without SIGALRM."
1465 #endif /* OPENSSL_NO_DES */
1467 #define COND(c) (run)
1468 #define COUNT(d) (count)
1470 signal(SIGALRM,sig_done);
1472 #endif /* SIGALRM */
1474 #ifndef OPENSSL_NO_MD2
1477 for (j=0; j<SIZE_NUM; j++)
1479 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1481 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1482 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1484 print_result(D_MD2,j,count,d);
1488 #ifndef OPENSSL_NO_MDC2
1491 for (j=0; j<SIZE_NUM; j++)
1493 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1495 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1496 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1498 print_result(D_MDC2,j,count,d);
1503 #ifndef OPENSSL_NO_MD4
1506 for (j=0; j<SIZE_NUM; j++)
1508 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1510 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1511 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1513 print_result(D_MD4,j,count,d);
1518 #ifndef OPENSSL_NO_MD5
1521 for (j=0; j<SIZE_NUM; j++)
1523 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1525 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1526 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1528 print_result(D_MD5,j,count,d);
1533 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1538 HMAC_CTX_init(&hctx);
1539 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1540 16,EVP_md5(), NULL);
1542 for (j=0; j<SIZE_NUM; j++)
1544 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1546 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1548 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1549 HMAC_Update(&hctx,buf,lengths[j]);
1550 HMAC_Final(&hctx,&(hmac[0]),NULL);
1553 print_result(D_HMAC,j,count,d);
1555 HMAC_CTX_cleanup(&hctx);
1558 #ifndef OPENSSL_NO_SHA
1561 for (j=0; j<SIZE_NUM; j++)
1563 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1565 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1566 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1568 print_result(D_SHA1,j,count,d);
1572 #ifndef OPENSSL_NO_SHA256
1575 for (j=0; j<SIZE_NUM; j++)
1577 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1579 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1580 SHA256(buf,lengths[j],sha256);
1582 print_result(D_SHA256,j,count,d);
1587 #ifndef OPENSSL_NO_SHA512
1590 for (j=0; j<SIZE_NUM; j++)
1592 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1594 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1595 SHA512(buf,lengths[j],sha512);
1597 print_result(D_SHA512,j,count,d);
1603 #ifndef OPENSSL_NO_WHIRLPOOL
1604 if (doit[D_WHIRLPOOL])
1606 for (j=0; j<SIZE_NUM; j++)
1608 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1610 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1611 WHIRLPOOL(buf,lengths[j],whirlpool);
1613 print_result(D_WHIRLPOOL,j,count,d);
1618 #ifndef OPENSSL_NO_RIPEMD
1621 for (j=0; j<SIZE_NUM; j++)
1623 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1625 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1626 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1628 print_result(D_RMD160,j,count,d);
1632 #ifndef OPENSSL_NO_RC4
1635 for (j=0; j<SIZE_NUM; j++)
1637 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1639 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1640 RC4(&rc4_ks,(unsigned int)lengths[j],
1643 print_result(D_RC4,j,count,d);
1647 #ifndef OPENSSL_NO_DES
1648 if (doit[D_CBC_DES])
1650 for (j=0; j<SIZE_NUM; j++)
1652 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1654 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1655 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1656 &DES_iv,DES_ENCRYPT);
1658 print_result(D_CBC_DES,j,count,d);
1662 if (doit[D_EDE3_DES])
1664 for (j=0; j<SIZE_NUM; j++)
1666 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1668 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1669 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1671 &DES_iv,DES_ENCRYPT);
1673 print_result(D_EDE3_DES,j,count,d);
1677 #ifndef OPENSSL_NO_AES
1678 if (doit[D_CBC_128_AES])
1680 for (j=0; j<SIZE_NUM; j++)
1682 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1684 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1685 AES_cbc_encrypt(buf,buf,
1686 (unsigned long)lengths[j],&aes_ks1,
1689 print_result(D_CBC_128_AES,j,count,d);
1692 if (doit[D_CBC_192_AES])
1694 for (j=0; j<SIZE_NUM; j++)
1696 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1698 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1699 AES_cbc_encrypt(buf,buf,
1700 (unsigned long)lengths[j],&aes_ks2,
1703 print_result(D_CBC_192_AES,j,count,d);
1706 if (doit[D_CBC_256_AES])
1708 for (j=0; j<SIZE_NUM; j++)
1710 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1712 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1713 AES_cbc_encrypt(buf,buf,
1714 (unsigned long)lengths[j],&aes_ks3,
1717 print_result(D_CBC_256_AES,j,count,d);
1721 if (doit[D_IGE_128_AES])
1723 for (j=0; j<SIZE_NUM; j++)
1725 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1727 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1728 AES_ige_encrypt(buf,buf2,
1729 (unsigned long)lengths[j],&aes_ks1,
1732 print_result(D_IGE_128_AES,j,count,d);
1735 if (doit[D_IGE_192_AES])
1737 for (j=0; j<SIZE_NUM; j++)
1739 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1741 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1742 AES_ige_encrypt(buf,buf2,
1743 (unsigned long)lengths[j],&aes_ks2,
1746 print_result(D_IGE_192_AES,j,count,d);
1749 if (doit[D_IGE_256_AES])
1751 for (j=0; j<SIZE_NUM; j++)
1753 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1755 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1756 AES_ige_encrypt(buf,buf2,
1757 (unsigned long)lengths[j],&aes_ks3,
1760 print_result(D_IGE_256_AES,j,count,d);
1766 #ifndef OPENSSL_NO_CAMELLIA
1767 if (doit[D_CBC_128_CML])
1769 for (j=0; j<SIZE_NUM; j++)
1771 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1773 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1774 Camellia_cbc_encrypt(buf,buf,
1775 (unsigned long)lengths[j],&camellia_ks1,
1776 iv,CAMELLIA_ENCRYPT);
1778 print_result(D_CBC_128_CML,j,count,d);
1781 if (doit[D_CBC_192_CML])
1783 for (j=0; j<SIZE_NUM; j++)
1785 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1787 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1788 Camellia_cbc_encrypt(buf,buf,
1789 (unsigned long)lengths[j],&camellia_ks2,
1790 iv,CAMELLIA_ENCRYPT);
1792 print_result(D_CBC_192_CML,j,count,d);
1795 if (doit[D_CBC_256_CML])
1797 for (j=0; j<SIZE_NUM; j++)
1799 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1801 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1802 Camellia_cbc_encrypt(buf,buf,
1803 (unsigned long)lengths[j],&camellia_ks3,
1804 iv,CAMELLIA_ENCRYPT);
1806 print_result(D_CBC_256_CML,j,count,d);
1811 #ifndef OPENSSL_NO_IDEA
1812 if (doit[D_CBC_IDEA])
1814 for (j=0; j<SIZE_NUM; j++)
1816 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1818 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1819 idea_cbc_encrypt(buf,buf,
1820 (unsigned long)lengths[j],&idea_ks,
1823 print_result(D_CBC_IDEA,j,count,d);
1827 #ifndef OPENSSL_NO_SEED
1828 if (doit[D_CBC_SEED])
1830 for (j=0; j<SIZE_NUM; j++)
1832 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1834 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1835 SEED_cbc_encrypt(buf,buf,
1836 (unsigned long)lengths[j],&seed_ks,iv,1);
1838 print_result(D_CBC_SEED,j,count,d);
1842 #ifndef OPENSSL_NO_RC2
1843 if (doit[D_CBC_RC2])
1845 for (j=0; j<SIZE_NUM; j++)
1847 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1849 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1850 RC2_cbc_encrypt(buf,buf,
1851 (unsigned long)lengths[j],&rc2_ks,
1854 print_result(D_CBC_RC2,j,count,d);
1858 #ifndef OPENSSL_NO_RC5
1859 if (doit[D_CBC_RC5])
1861 for (j=0; j<SIZE_NUM; j++)
1863 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1865 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1866 RC5_32_cbc_encrypt(buf,buf,
1867 (unsigned long)lengths[j],&rc5_ks,
1870 print_result(D_CBC_RC5,j,count,d);
1874 #ifndef OPENSSL_NO_BF
1877 for (j=0; j<SIZE_NUM; j++)
1879 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1881 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1882 BF_cbc_encrypt(buf,buf,
1883 (unsigned long)lengths[j],&bf_ks,
1886 print_result(D_CBC_BF,j,count,d);
1890 #ifndef OPENSSL_NO_CAST
1891 if (doit[D_CBC_CAST])
1893 for (j=0; j<SIZE_NUM; j++)
1895 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1897 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1898 CAST_cbc_encrypt(buf,buf,
1899 (unsigned long)lengths[j],&cast_ks,
1902 print_result(D_CBC_CAST,j,count,d);
1909 for (j=0; j<SIZE_NUM; j++)
1916 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1917 /* -O3 -fschedule-insns messes up an
1918 * optimization here! names[D_EVP]
1919 * somehow becomes NULL */
1920 print_message(names[D_EVP],save_count,
1923 EVP_CIPHER_CTX_init(&ctx);
1925 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1927 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1928 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1932 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1933 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1935 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1936 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1938 EVP_DecryptFinal_ex(&ctx,buf,&outl);
1940 EVP_EncryptFinal_ex(&ctx,buf,&outl);
1942 EVP_CIPHER_CTX_cleanup(&ctx);
1946 names[D_EVP]=OBJ_nid2ln(evp_md->type);
1947 print_message(names[D_EVP],save_count,
1951 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1952 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
1956 print_result(D_EVP,j,count,d);
1960 RAND_pseudo_bytes(buf,36);
1961 #ifndef OPENSSL_NO_RSA
1962 for (j=0; j<RSA_NUM; j++)
1965 if (!rsa_doit[j]) continue;
1966 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
1969 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
1970 ERR_print_errors(bio_err);
1975 pkey_print_message("private","rsa",
1976 rsa_c[j][0],rsa_bits[j],
1978 /* RSA_blinding_on(rsa_key[j],NULL); */
1980 for (count=0,run=1; COND(rsa_c[j][0]); count++)
1982 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
1983 &rsa_num, rsa_key[j]);
1987 "RSA sign failure\n");
1988 ERR_print_errors(bio_err);
1994 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
1995 : "%ld %d bit private RSA's in %.2fs\n",
1996 count,rsa_bits[j],d);
1997 rsa_results[j][0]=d/(double)count;
2002 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2005 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2006 ERR_print_errors(bio_err);
2011 pkey_print_message("public","rsa",
2012 rsa_c[j][1],rsa_bits[j],
2015 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2017 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2018 rsa_num, rsa_key[j]);
2022 "RSA verify failure\n");
2023 ERR_print_errors(bio_err);
2029 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2030 : "%ld %d bit public RSA's in %.2fs\n",
2031 count,rsa_bits[j],d);
2032 rsa_results[j][1]=d/(double)count;
2038 /* if longer than 10s, don't do any more */
2039 for (j++; j<RSA_NUM; j++)
2045 RAND_pseudo_bytes(buf,20);
2046 #ifndef OPENSSL_NO_DSA
2047 if (RAND_status() != 1)
2049 RAND_seed(rnd_seed, sizeof rnd_seed);
2052 for (j=0; j<DSA_NUM; j++)
2057 if (!dsa_doit[j]) continue;
2058 /* DSA_generate_key(dsa_key[j]); */
2059 /* DSA_sign_setup(dsa_key[j],NULL); */
2060 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2064 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2065 ERR_print_errors(bio_err);
2070 pkey_print_message("sign","dsa",
2071 dsa_c[j][0],dsa_bits[j],
2074 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2076 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2081 "DSA sign failure\n");
2082 ERR_print_errors(bio_err);
2088 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2089 : "%ld %d bit DSA signs in %.2fs\n",
2090 count,dsa_bits[j],d);
2091 dsa_results[j][0]=d/(double)count;
2095 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2099 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2100 ERR_print_errors(bio_err);
2105 pkey_print_message("verify","dsa",
2106 dsa_c[j][1],dsa_bits[j],
2109 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2111 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2116 "DSA verify failure\n");
2117 ERR_print_errors(bio_err);
2123 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2124 : "%ld %d bit DSA verify in %.2fs\n",
2125 count,dsa_bits[j],d);
2126 dsa_results[j][1]=d/(double)count;
2131 /* if longer than 10s, don't do any more */
2132 for (j++; j<DSA_NUM; j++)
2136 if (rnd_fake) RAND_cleanup();
2139 #ifndef OPENSSL_NO_ECDSA
2140 if (RAND_status() != 1)
2142 RAND_seed(rnd_seed, sizeof rnd_seed);
2145 for (j=0; j<EC_NUM; j++)
2149 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2150 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2151 if (ecdsa[j] == NULL)
2153 BIO_printf(bio_err,"ECDSA failure.\n");
2154 ERR_print_errors(bio_err);
2160 EC_KEY_precompute_mult(ecdsa[j], NULL);
2162 /* Perform ECDSA signature test */
2163 EC_KEY_generate_key(ecdsa[j]);
2164 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2165 &ecdsasiglen, ecdsa[j]);
2168 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2169 ERR_print_errors(bio_err);
2174 pkey_print_message("sign","ecdsa",
2176 test_curves_bits[j],
2180 for (count=0,run=1; COND(ecdsa_c[j][0]);
2183 ret=ECDSA_sign(0, buf, 20,
2184 ecdsasig, &ecdsasiglen,
2188 BIO_printf(bio_err, "ECDSA sign failure\n");
2189 ERR_print_errors(bio_err);
2196 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2197 "%ld %d bit ECDSA signs in %.2fs \n",
2198 count, test_curves_bits[j], d);
2199 ecdsa_results[j][0]=d/(double)count;
2203 /* Perform ECDSA verification test */
2204 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2205 ecdsasiglen, ecdsa[j]);
2208 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2209 ERR_print_errors(bio_err);
2214 pkey_print_message("verify","ecdsa",
2216 test_curves_bits[j],
2219 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2221 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2224 BIO_printf(bio_err, "ECDSA verify failure\n");
2225 ERR_print_errors(bio_err);
2231 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2232 : "%ld %d bit ECDSA verify in %.2fs\n",
2233 count, test_curves_bits[j], d);
2234 ecdsa_results[j][1]=d/(double)count;
2239 /* if longer than 10s, don't do any more */
2240 for (j++; j<EC_NUM; j++)
2245 if (rnd_fake) RAND_cleanup();
2248 #ifndef OPENSSL_NO_ECDH
2249 if (RAND_status() != 1)
2251 RAND_seed(rnd_seed, sizeof rnd_seed);
2254 for (j=0; j<EC_NUM; j++)
2256 if (!ecdh_doit[j]) continue;
2257 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2258 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2259 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2261 BIO_printf(bio_err,"ECDH failure.\n");
2262 ERR_print_errors(bio_err);
2267 /* generate two ECDH key pairs */
2268 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2269 !EC_KEY_generate_key(ecdh_b[j]))
2271 BIO_printf(bio_err,"ECDH key generation failure.\n");
2272 ERR_print_errors(bio_err);
2277 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2278 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2280 int field_size, outlen;
2281 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2282 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2283 if (field_size <= 24 * 8)
2285 outlen = KDF1_SHA1_len;
2290 outlen = (field_size+7)/8;
2293 secret_size_a = ECDH_compute_key(secret_a, outlen,
2294 EC_KEY_get0_public_key(ecdh_b[j]),
2296 secret_size_b = ECDH_compute_key(secret_b, outlen,
2297 EC_KEY_get0_public_key(ecdh_a[j]),
2299 if (secret_size_a != secret_size_b)
2304 for (secret_idx = 0;
2305 (secret_idx < secret_size_a)
2306 && (ecdh_checks == 1);
2309 if (secret_a[secret_idx] != secret_b[secret_idx])
2313 if (ecdh_checks == 0)
2315 BIO_printf(bio_err,"ECDH computations don't match.\n");
2316 ERR_print_errors(bio_err);
2320 pkey_print_message("","ecdh",
2322 test_curves_bits[j],
2325 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2327 ECDH_compute_key(secret_a, outlen,
2328 EC_KEY_get0_public_key(ecdh_b[j]),
2332 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2333 count, test_curves_bits[j], d);
2334 ecdh_results[j][0]=d/(double)count;
2342 /* if longer than 10s, don't do any more */
2343 for (j++; j<EC_NUM; j++)
2347 if (rnd_fake) RAND_cleanup();
2354 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2355 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2357 printf("%s ",BN_options());
2358 #ifndef OPENSSL_NO_MD2
2359 printf("%s ",MD2_options());
2361 #ifndef OPENSSL_NO_RC4
2362 printf("%s ",RC4_options());
2364 #ifndef OPENSSL_NO_DES
2365 printf("%s ",DES_options());
2367 #ifndef OPENSSL_NO_AES
2368 printf("%s ",AES_options());
2370 #ifndef OPENSSL_NO_IDEA
2371 printf("%s ",idea_options());
2373 #ifndef OPENSSL_NO_BF
2374 printf("%s ",BF_options());
2376 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2382 fprintf(stdout,"+H");
2385 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2386 fprintf(stdout,"type ");
2388 for (j=0; j<SIZE_NUM; j++)
2389 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2390 fprintf(stdout,"\n");
2393 for (k=0; k<ALGOR_NUM; k++)
2395 if (!doit[k]) continue;
2397 fprintf(stdout,"+F:%d:%s",k,names[k]);
2399 fprintf(stdout,"%-13s",names[k]);
2400 for (j=0; j<SIZE_NUM; j++)
2402 if (results[k][j] > 10000 && !mr)
2403 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2405 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2407 fprintf(stdout,"\n");
2409 #ifndef OPENSSL_NO_RSA
2411 for (k=0; k<RSA_NUM; k++)
2413 if (!rsa_doit[k]) continue;
2416 printf("%18ssign verify sign/s verify/s\n"," ");
2420 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2421 k,rsa_bits[k],rsa_results[k][0],
2424 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2425 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2426 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2429 #ifndef OPENSSL_NO_DSA
2431 for (k=0; k<DSA_NUM; k++)
2433 if (!dsa_doit[k]) continue;
2436 printf("%18ssign verify sign/s verify/s\n"," ");
2440 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2441 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2443 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2444 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2445 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2448 #ifndef OPENSSL_NO_ECDSA
2450 for (k=0; k<EC_NUM; k++)
2452 if (!ecdsa_doit[k]) continue;
2455 printf("%30ssign verify sign/s verify/s\n"," ");
2460 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2461 k, test_curves_bits[k],
2462 ecdsa_results[k][0],ecdsa_results[k][1]);
2465 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2466 test_curves_bits[k],
2467 test_curves_names[k],
2468 ecdsa_results[k][0],ecdsa_results[k][1],
2469 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2474 #ifndef OPENSSL_NO_ECDH
2476 for (k=0; k<EC_NUM; k++)
2478 if (!ecdh_doit[k]) continue;
2481 printf("%30sop op/s\n"," ");
2485 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2486 k, test_curves_bits[k],
2487 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2490 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2491 test_curves_bits[k],
2492 test_curves_names[k],
2493 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2500 ERR_print_errors(bio_err);
2501 if (buf != NULL) OPENSSL_free(buf);
2502 if (buf2 != NULL) OPENSSL_free(buf2);
2503 #ifndef OPENSSL_NO_RSA
2504 for (i=0; i<RSA_NUM; i++)
2505 if (rsa_key[i] != NULL)
2506 RSA_free(rsa_key[i]);
2508 #ifndef OPENSSL_NO_DSA
2509 for (i=0; i<DSA_NUM; i++)
2510 if (dsa_key[i] != NULL)
2511 DSA_free(dsa_key[i]);
2514 #ifndef OPENSSL_NO_ECDSA
2515 for (i=0; i<EC_NUM; i++)
2516 if (ecdsa[i] != NULL)
2517 EC_KEY_free(ecdsa[i]);
2519 #ifndef OPENSSL_NO_ECDH
2520 for (i=0; i<EC_NUM; i++)
2522 if (ecdh_a[i] != NULL)
2523 EC_KEY_free(ecdh_a[i]);
2524 if (ecdh_b[i] != NULL)
2525 EC_KEY_free(ecdh_b[i]);
2533 static void print_message(const char *s, long num, int length)
2536 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2537 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2538 (void)BIO_flush(bio_err);
2541 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2542 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2543 (void)BIO_flush(bio_err);
2550 static void pkey_print_message(const char *str, const char *str2, long num,
2554 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2555 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2556 (void)BIO_flush(bio_err);
2559 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2560 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2561 (void)BIO_flush(bio_err);
2568 static void print_result(int alg,int run_no,int count,double time_used)
2570 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2571 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2572 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2576 static char *sstrsep(char **string, const char *delim)
2579 char *token = *string;
2584 memset(isdelim, 0, sizeof isdelim);
2589 isdelim[(unsigned char)(*delim)] = 1;
2593 while (!isdelim[(unsigned char)(**string)])
2607 static int do_multi(int multi)
2612 static char sep[]=":";
2614 fds=malloc(multi*sizeof *fds);
2615 for(n=0 ; n < multi ; ++n)
2636 printf("Forked child %d\n",n);
2639 /* for now, assume the pipe is long enough to take all the output */
2640 for(n=0 ; n < multi ; ++n)
2646 f=fdopen(fds[n],"r");
2647 while(fgets(buf,sizeof buf,f))
2654 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2658 printf("Got: %s from %d\n",buf,n);
2659 if(!strncmp(buf,"+F:",3))
2665 alg=atoi(sstrsep(&p,sep));
2667 for(j=0 ; j < SIZE_NUM ; ++j)
2668 results[alg][j]+=atof(sstrsep(&p,sep));
2670 else if(!strncmp(buf,"+F2:",4))
2676 k=atoi(sstrsep(&p,sep));
2679 d=atof(sstrsep(&p,sep));
2681 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2683 rsa_results[k][0]=d;
2685 d=atof(sstrsep(&p,sep));
2687 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2689 rsa_results[k][1]=d;
2691 else if(!strncmp(buf,"+F2:",4))
2697 k=atoi(sstrsep(&p,sep));
2700 d=atof(sstrsep(&p,sep));
2702 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2704 rsa_results[k][0]=d;
2706 d=atof(sstrsep(&p,sep));
2708 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2710 rsa_results[k][1]=d;
2712 else if(!strncmp(buf,"+F3:",4))
2718 k=atoi(sstrsep(&p,sep));
2721 d=atof(sstrsep(&p,sep));
2723 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2725 dsa_results[k][0]=d;
2727 d=atof(sstrsep(&p,sep));
2729 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2731 dsa_results[k][1]=d;
2733 #ifndef OPENSSL_NO_ECDSA
2734 else if(!strncmp(buf,"+F4:",4))
2740 k=atoi(sstrsep(&p,sep));
2743 d=atof(sstrsep(&p,sep));
2745 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2747 ecdsa_results[k][0]=d;
2749 d=atof(sstrsep(&p,sep));
2751 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2753 ecdsa_results[k][1]=d;
2757 #ifndef OPENSSL_NO_ECDH
2758 else if(!strncmp(buf,"+F5:",4))
2764 k=atoi(sstrsep(&p,sep));
2767 d=atof(sstrsep(&p,sep));
2769 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2771 ecdh_results[k][0]=d;
2776 else if(!strncmp(buf,"+H:",3))
2780 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);