1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
58 /* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
67 * The ECDH and ECDSA speed test software is originally written by
68 * Sumit Gupta of Sun Microsystems Laboratories.
72 /* most of this code has been pilfered from my libdes speed.c program */
74 #ifndef OPENSSL_NO_SPEED
78 #define RSA_SECONDS 10
79 #define DSA_SECONDS 10
80 #define ECDSA_SECONDS 10
81 #define ECDH_SECONDS 10
83 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
84 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
87 #define PROG speed_main
95 #ifdef OPENSSL_NO_STDIO
98 #include <openssl/crypto.h>
99 #include <openssl/rand.h>
100 #include <openssl/err.h>
101 #include <openssl/evp.h>
102 #include <openssl/objects.h>
103 #if !defined(OPENSSL_SYS_MSDOS)
104 #include OPENSSL_UNISTD
107 #ifndef OPENSSL_SYS_NETWARE
111 #if defined(_WIN32) || defined(__CYGWIN__)
113 # if defined(__CYGWIN__) && !defined(_WIN32)
114 /* <windows.h> should define _WIN32, which normally is mutually
115 * exclusive with __CYGWIN__, but if it didn't... */
117 /* this is done because Cygwin alarm() fails sometimes. */
121 #include <openssl/bn.h>
122 #ifndef OPENSSL_NO_DES
123 #include <openssl/des.h>
125 #ifndef OPENSSL_NO_AES
126 #include <openssl/aes.h>
128 #ifndef OPENSSL_NO_CAMELLIA
129 #include <openssl/camellia.h>
131 #ifndef OPENSSL_NO_MD2
132 #include <openssl/md2.h>
134 #ifndef OPENSSL_NO_MDC2
135 #include <openssl/mdc2.h>
137 #ifndef OPENSSL_NO_MD4
138 #include <openssl/md4.h>
140 #ifndef OPENSSL_NO_MD5
141 #include <openssl/md5.h>
143 #ifndef OPENSSL_NO_HMAC
144 #include <openssl/hmac.h>
146 #include <openssl/evp.h>
147 #ifndef OPENSSL_NO_SHA
148 #include <openssl/sha.h>
150 #ifndef OPENSSL_NO_RIPEMD
151 #include <openssl/ripemd.h>
153 #ifndef OPENSSL_NO_WHIRLPOOL
154 #include <openssl/whrlpool.h>
156 #ifndef OPENSSL_NO_RC4
157 #include <openssl/rc4.h>
159 #ifndef OPENSSL_NO_RC5
160 #include <openssl/rc5.h>
162 #ifndef OPENSSL_NO_RC2
163 #include <openssl/rc2.h>
165 #ifndef OPENSSL_NO_IDEA
166 #include <openssl/idea.h>
168 #ifndef OPENSSL_NO_SEED
169 #include <openssl/seed.h>
171 #ifndef OPENSSL_NO_BF
172 #include <openssl/blowfish.h>
174 #ifndef OPENSSL_NO_CAST
175 #include <openssl/cast.h>
177 #ifndef OPENSSL_NO_RSA
178 #include <openssl/rsa.h>
179 #include "./testrsa.h"
181 #include <openssl/x509.h>
182 #ifndef OPENSSL_NO_DSA
183 #include <openssl/dsa.h>
184 #include "./testdsa.h"
186 #ifndef OPENSSL_NO_ECDSA
187 #include <openssl/ecdsa.h>
189 #ifndef OPENSSL_NO_ECDH
190 #include <openssl/ecdh.h>
192 #include <openssl/modes.h>
194 #include "../crypto/bn/bn_lcl.h"
197 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
211 #define BUFSIZE ((long)1024*8+1)
215 static int usertime=1;
217 static double Time_F(int s);
218 static void print_message(const char *s,long num,int length);
219 static void prime_print_message(const char *s, long num);
220 static void pkey_print_message(const char *str, const char *str2,
221 long num, int bits, int sec);
222 static void print_result(int alg,int run_no,int count,double time_used);
224 static int do_multi(int multi);
234 #define MAX_ECDH_SIZE 256
236 static const char *names[ALGOR_NUM]={
237 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
238 "des cbc","des ede3","idea cbc","seed cbc",
239 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
240 "aes-128 cbc","aes-192 cbc","aes-256 cbc",
241 "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
242 "evp","sha256","sha512","whirlpool",
243 "aes-128 ige","aes-192 ige","aes-256 ige","ghash" };
244 static double results[ALGOR_NUM][SIZE_NUM];
245 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
246 static const char *prime_names[PRIME_NUM]={
247 "prime trial division", "prime coprime" };
248 #ifndef OPENSSL_NO_RSA
249 static double rsa_results[RSA_NUM][2];
251 #ifndef OPENSSL_NO_DSA
252 static double dsa_results[DSA_NUM][2];
254 #ifndef OPENSSL_NO_ECDSA
255 static double ecdsa_results[EC_NUM][2];
257 #ifndef OPENSSL_NO_ECDH
258 static double ecdh_results[EC_NUM][1];
261 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
262 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
263 static int rnd_fake = 0;
267 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
268 #define SIGRETTYPE void
270 #define SIGRETTYPE int
273 static SIGRETTYPE sig_done(int sig);
274 static SIGRETTYPE sig_done(int sig)
276 signal(SIGALRM,sig_done);
289 #if !defined(SIGALRM)
292 static unsigned int lapse,schlock;
293 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
294 #define alarm alarm_win32
296 static DWORD WINAPI sleepy(VOID *arg)
304 static double Time_F(int s)
312 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
315 DWORD ret=GetLastError();
316 BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
319 while (!schlock) Sleep(0); /* scheduler spinlock */
320 ret = app_tminterval(s,usertime);
324 ret = app_tminterval(s,usertime);
325 if (run) TerminateThread(thr,0);
333 static double Time_F(int s)
335 double ret = app_tminterval(s,usertime);
336 if (s == STOP) alarm(0);
342 #ifndef OPENSSL_NO_ECDH
343 static const int KDF1_SHA1_len = 20;
344 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
346 #ifndef OPENSSL_NO_SHA
347 if (*outlen < SHA_DIGEST_LENGTH)
350 *outlen = SHA_DIGEST_LENGTH;
351 return SHA1(in, inlen, out);
354 #endif /* OPENSSL_NO_SHA */
356 #endif /* OPENSSL_NO_ECDH */
359 int MAIN(int, char **);
361 int MAIN(int argc, char **argv)
363 unsigned char *buf=NULL,*buf2=NULL;
365 long count=0,save_count=0;
367 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
370 #ifndef OPENSSL_NO_RSA
373 unsigned char md[EVP_MAX_MD_SIZE];
374 #ifndef OPENSSL_NO_MD2
375 unsigned char md2[MD2_DIGEST_LENGTH];
377 #ifndef OPENSSL_NO_MDC2
378 unsigned char mdc2[MDC2_DIGEST_LENGTH];
380 #ifndef OPENSSL_NO_MD4
381 unsigned char md4[MD4_DIGEST_LENGTH];
383 #ifndef OPENSSL_NO_MD5
384 unsigned char md5[MD5_DIGEST_LENGTH];
385 unsigned char hmac[MD5_DIGEST_LENGTH];
387 #ifndef OPENSSL_NO_SHA
388 unsigned char sha[SHA_DIGEST_LENGTH];
389 #ifndef OPENSSL_NO_SHA256
390 unsigned char sha256[SHA256_DIGEST_LENGTH];
392 #ifndef OPENSSL_NO_SHA512
393 unsigned char sha512[SHA512_DIGEST_LENGTH];
396 #ifndef OPENSSL_NO_WHIRLPOOL
397 unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
399 #ifndef OPENSSL_NO_RIPEMD
400 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
402 #ifndef OPENSSL_NO_RC4
405 #ifndef OPENSSL_NO_RC5
408 #ifndef OPENSSL_NO_RC2
411 #ifndef OPENSSL_NO_IDEA
412 IDEA_KEY_SCHEDULE idea_ks;
414 #ifndef OPENSSL_NO_SEED
415 SEED_KEY_SCHEDULE seed_ks;
417 #ifndef OPENSSL_NO_BF
420 #ifndef OPENSSL_NO_CAST
423 static const unsigned char key16[16]=
424 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
425 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
426 #ifndef OPENSSL_NO_AES
427 static const unsigned char key24[24]=
428 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
429 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
430 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
431 static const unsigned char key32[32]=
432 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
433 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
434 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
435 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
437 #ifndef OPENSSL_NO_CAMELLIA
438 static const unsigned char ckey24[24]=
439 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
440 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
441 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
442 static const unsigned char ckey32[32]=
443 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
444 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
445 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
446 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
448 #ifndef OPENSSL_NO_AES
449 #define MAX_BLOCK_SIZE 128
451 #define MAX_BLOCK_SIZE 64
453 unsigned char DES_iv[8];
454 unsigned char iv[2*MAX_BLOCK_SIZE/8];
455 #ifndef OPENSSL_NO_DES
456 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
457 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
458 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
459 DES_key_schedule sch;
460 DES_key_schedule sch2;
461 DES_key_schedule sch3;
463 #ifndef OPENSSL_NO_AES
464 AES_KEY aes_ks1, aes_ks2, aes_ks3;
466 #ifndef OPENSSL_NO_CAMELLIA
467 CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
479 #define D_CBC_IDEA 10
480 #define D_CBC_SEED 11
484 #define D_CBC_CAST 15
485 #define D_CBC_128_AES 16
486 #define D_CBC_192_AES 17
487 #define D_CBC_256_AES 18
488 #define D_CBC_128_CML 19
489 #define D_CBC_192_CML 20
490 #define D_CBC_256_CML 21
494 #define D_WHIRLPOOL 25
495 #define D_IGE_128_AES 26
496 #define D_IGE_192_AES 27
497 #define D_IGE_256_AES 28
500 long c[ALGOR_NUM][SIZE_NUM];
502 #define D_PRIME_TRIAL_DIVISION 0
503 #define D_PRIME_COPRIME 1
504 long prime_c[PRIME_NUM];
531 #ifndef OPENSSL_NO_RSA
532 RSA *rsa_key[RSA_NUM];
533 long rsa_c[RSA_NUM][2];
534 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
535 static unsigned char *rsa_data[RSA_NUM]=
536 {test512,test1024,test2048,test4096};
537 static int rsa_data_length[RSA_NUM]={
538 sizeof(test512),sizeof(test1024),
539 sizeof(test2048),sizeof(test4096)};
541 #ifndef OPENSSL_NO_DSA
542 DSA *dsa_key[DSA_NUM];
543 long dsa_c[DSA_NUM][2];
544 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
546 #ifndef OPENSSL_NO_EC
547 /* We only test over the following curves as they are representative,
548 * To add tests over more curves, simply add the curve NID
549 * and curve name to the following arrays and increase the
550 * EC_NUM value accordingly.
552 static unsigned int test_curves[EC_NUM] =
556 NID_X9_62_prime192v1,
558 NID_X9_62_prime256v1,
573 static const char * test_curves_names[EC_NUM] =
594 static int test_curves_bits[EC_NUM] =
596 160, 192, 224, 256, 384, 521,
597 163, 233, 283, 409, 571,
598 163, 233, 283, 409, 571
603 #ifndef OPENSSL_NO_ECDSA
604 unsigned char ecdsasig[256];
605 unsigned int ecdsasiglen;
606 EC_KEY *ecdsa[EC_NUM];
607 long ecdsa_c[EC_NUM][2];
610 #ifndef OPENSSL_NO_ECDH
611 EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
612 unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
613 int secret_size_a, secret_size_b;
616 long ecdh_c[EC_NUM][2];
619 int prime_doit[PRIME_NUM];
620 int rsa_doit[RSA_NUM];
621 int dsa_doit[DSA_NUM];
622 #ifndef OPENSSL_NO_ECDSA
623 int ecdsa_doit[EC_NUM];
625 #ifndef OPENSSL_NO_ECDH
626 int ecdh_doit[EC_NUM];
630 const EVP_CIPHER *evp_cipher=NULL;
631 const EVP_MD *evp_md=NULL;
642 memset(results, 0, sizeof(results));
643 #ifndef OPENSSL_NO_DSA
644 memset(dsa_key,0,sizeof(dsa_key));
646 #ifndef OPENSSL_NO_ECDSA
647 for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
649 #ifndef OPENSSL_NO_ECDH
650 for (i=0; i<EC_NUM; i++)
659 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
660 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
662 if (!load_config(bio_err, NULL))
665 #ifndef OPENSSL_NO_RSA
666 memset(rsa_key,0,sizeof(rsa_key));
667 for (i=0; i<RSA_NUM; i++)
671 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
673 BIO_printf(bio_err,"out of memory\n");
676 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
678 BIO_printf(bio_err,"out of memory\n");
682 memset(c,0,sizeof(c));
683 memset(DES_iv,0,sizeof(DES_iv));
684 memset(iv,0,sizeof(iv));
686 for (i=0; i<ALGOR_NUM; i++)
688 for (i=0; i<RSA_NUM; i++)
690 for (i=0; i<DSA_NUM; i++)
692 #ifndef OPENSSL_NO_ECDSA
693 for (i=0; i<EC_NUM; i++)
696 #ifndef OPENSSL_NO_ECDH
697 for (i=0; i<EC_NUM; i++)
707 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
710 j--; /* Otherwise, -elapsed gets confused with
713 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
719 BIO_printf(bio_err,"no EVP given\n");
722 evp_cipher=EVP_get_cipherbyname(*argv);
725 evp_md=EVP_get_digestbyname(*argv);
727 if(!evp_cipher && !evp_md)
729 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
734 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
737 j--; /* Otherwise, -elapsed gets confused with
740 #ifndef OPENSSL_NO_ENGINE
741 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
747 BIO_printf(bio_err,"no engine given\n");
750 setup_engine(bio_err, *argv, 0);
751 /* j will be increased again further down. We just
752 don't want speed to confuse an engine with an
753 algorithm, especially when none is given (which
754 means all of them should be run) */
759 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
765 BIO_printf(bio_err,"no multi count given\n");
771 BIO_printf(bio_err,"bad multi count\n");
774 j--; /* Otherwise, -mr gets confused with
778 else if (argc > 0 && !strcmp(*argv,"-mr"))
781 j--; /* Otherwise, -mr gets confused with
785 #ifndef OPENSSL_NO_MD2
786 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
789 #ifndef OPENSSL_NO_MDC2
790 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
793 #ifndef OPENSSL_NO_MD4
794 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
797 #ifndef OPENSSL_NO_MD5
798 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
801 #ifndef OPENSSL_NO_MD5
802 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
805 #ifndef OPENSSL_NO_SHA
806 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
808 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
812 #ifndef OPENSSL_NO_SHA256
813 if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
816 #ifndef OPENSSL_NO_SHA512
817 if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
821 #ifndef OPENSSL_NO_WHIRLPOOL
822 if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
825 #ifndef OPENSSL_NO_RIPEMD
826 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
828 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
830 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
833 #ifndef OPENSSL_NO_RC4
834 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
837 #ifndef OPENSSL_NO_DES
838 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
839 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
842 #ifndef OPENSSL_NO_AES
843 if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
844 else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
845 else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
846 else if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
847 else if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
848 else if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
851 #ifndef OPENSSL_NO_CAMELLIA
852 if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
853 else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
854 else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
857 #ifndef OPENSSL_NO_RSA
858 #if 0 /* was: #ifdef RSAref */
859 if (strcmp(*argv,"rsaref") == 0)
861 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
867 if (strcmp(*argv,"openssl") == 0)
869 RSA_set_default_method(RSA_PKCS1_SSLeay());
874 #endif /* !OPENSSL_NO_RSA */
875 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
876 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
877 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
878 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
879 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
880 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
881 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
883 #ifndef OPENSSL_NO_RC2
884 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
885 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
888 #ifndef OPENSSL_NO_RC5
889 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
890 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
893 #ifndef OPENSSL_NO_IDEA
894 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
895 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
898 #ifndef OPENSSL_NO_SEED
899 if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
900 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
903 #ifndef OPENSSL_NO_BF
904 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
905 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
906 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
909 #ifndef OPENSSL_NO_CAST
910 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
911 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
912 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
915 #ifndef OPENSSL_NO_DES
916 if (strcmp(*argv,"des") == 0)
923 #ifndef OPENSSL_NO_AES
924 if (strcmp(*argv,"aes") == 0)
926 doit[D_CBC_128_AES]=1;
927 doit[D_CBC_192_AES]=1;
928 doit[D_CBC_256_AES]=1;
930 else if (strcmp(*argv,"ghash") == 0)
936 #ifndef OPENSSL_NO_CAMELLIA
937 if (strcmp(*argv,"camellia") == 0)
939 doit[D_CBC_128_CML]=1;
940 doit[D_CBC_192_CML]=1;
941 doit[D_CBC_256_CML]=1;
945 #ifndef OPENSSL_NO_RSA
946 if (strcmp(*argv,"rsa") == 0)
948 rsa_doit[R_RSA_512]=1;
949 rsa_doit[R_RSA_1024]=1;
950 rsa_doit[R_RSA_2048]=1;
951 rsa_doit[R_RSA_4096]=1;
955 #ifndef OPENSSL_NO_DSA
956 if (strcmp(*argv,"dsa") == 0)
958 dsa_doit[R_DSA_512]=1;
959 dsa_doit[R_DSA_1024]=1;
960 dsa_doit[R_DSA_2048]=1;
964 #ifndef OPENSSL_NO_ECDSA
965 if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
966 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
967 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
968 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
969 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
970 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
971 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
972 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
973 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
974 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
975 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
976 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
977 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
978 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
979 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
980 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
981 else if (strcmp(*argv,"ecdsa") == 0)
983 for (i=0; i < EC_NUM; i++)
988 #ifndef OPENSSL_NO_ECDH
989 if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
990 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
991 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
992 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
993 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
994 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
995 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
996 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
997 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
998 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
999 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1000 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1001 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1002 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1003 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1004 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1005 else if (strcmp(*argv,"ecdh") == 0)
1007 for (i=0; i < EC_NUM; i++)
1012 if (strcmp(*argv,"prime-trial-division") == 0) prime_doit[D_PRIME_TRIAL_DIVISION]=1;
1013 else if (strcmp(*argv,"prime-coprime") == 0) prime_doit[D_PRIME_COPRIME]=1;
1016 BIO_printf(bio_err,"Error: bad option or value\n");
1017 BIO_printf(bio_err,"\n");
1018 BIO_printf(bio_err,"Available values:\n");
1019 #ifndef OPENSSL_NO_MD2
1020 BIO_printf(bio_err,"md2 ");
1022 #ifndef OPENSSL_NO_MDC2
1023 BIO_printf(bio_err,"mdc2 ");
1025 #ifndef OPENSSL_NO_MD4
1026 BIO_printf(bio_err,"md4 ");
1028 #ifndef OPENSSL_NO_MD5
1029 BIO_printf(bio_err,"md5 ");
1030 #ifndef OPENSSL_NO_HMAC
1031 BIO_printf(bio_err,"hmac ");
1034 #ifndef OPENSSL_NO_SHA1
1035 BIO_printf(bio_err,"sha1 ");
1037 #ifndef OPENSSL_NO_SHA256
1038 BIO_printf(bio_err,"sha256 ");
1040 #ifndef OPENSSL_NO_SHA512
1041 BIO_printf(bio_err,"sha512 ");
1043 #ifndef OPENSSL_NO_WHIRLPOOL
1044 BIO_printf(bio_err,"whirlpool");
1046 #ifndef OPENSSL_NO_RIPEMD160
1047 BIO_printf(bio_err,"rmd160");
1049 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1050 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1051 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1052 !defined(OPENSSL_NO_WHIRLPOOL)
1053 BIO_printf(bio_err,"\n");
1056 #ifndef OPENSSL_NO_IDEA
1057 BIO_printf(bio_err,"idea-cbc ");
1059 #ifndef OPENSSL_NO_SEED
1060 BIO_printf(bio_err,"seed-cbc ");
1062 #ifndef OPENSSL_NO_RC2
1063 BIO_printf(bio_err,"rc2-cbc ");
1065 #ifndef OPENSSL_NO_RC5
1066 BIO_printf(bio_err,"rc5-cbc ");
1068 #ifndef OPENSSL_NO_BF
1069 BIO_printf(bio_err,"bf-cbc");
1071 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1072 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1073 BIO_printf(bio_err,"\n");
1075 #ifndef OPENSSL_NO_DES
1076 BIO_printf(bio_err,"des-cbc des-ede3 ");
1078 #ifndef OPENSSL_NO_AES
1079 BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1080 BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");
1082 #ifndef OPENSSL_NO_CAMELLIA
1083 BIO_printf(bio_err,"\n");
1084 BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1086 #ifndef OPENSSL_NO_RC4
1087 BIO_printf(bio_err,"rc4");
1089 BIO_printf(bio_err,"\n");
1091 #ifndef OPENSSL_NO_RSA
1092 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
1095 #ifndef OPENSSL_NO_DSA
1096 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
1098 #ifndef OPENSSL_NO_ECDSA
1099 BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1100 BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1101 BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1102 BIO_printf(bio_err,"ecdsa\n");
1104 #ifndef OPENSSL_NO_ECDH
1105 BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
1106 BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
1107 BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
1108 BIO_printf(bio_err,"ecdh\n");
1111 #ifndef OPENSSL_NO_IDEA
1112 BIO_printf(bio_err,"idea ");
1114 #ifndef OPENSSL_NO_SEED
1115 BIO_printf(bio_err,"seed ");
1117 #ifndef OPENSSL_NO_RC2
1118 BIO_printf(bio_err,"rc2 ");
1120 #ifndef OPENSSL_NO_DES
1121 BIO_printf(bio_err,"des ");
1123 #ifndef OPENSSL_NO_AES
1124 BIO_printf(bio_err,"aes ");
1126 #ifndef OPENSSL_NO_CAMELLIA
1127 BIO_printf(bio_err,"camellia ");
1129 #ifndef OPENSSL_NO_RSA
1130 BIO_printf(bio_err,"rsa ");
1132 #ifndef OPENSSL_NO_BF
1133 BIO_printf(bio_err,"blowfish");
1135 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1136 !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1137 !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1138 !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1139 BIO_printf(bio_err,"\n");
1141 BIO_printf(bio_err,"prime-trial-division prime-coprime\n");
1143 BIO_printf(bio_err,"\n");
1144 BIO_printf(bio_err,"Available options:\n");
1145 #if defined(TIMES) || defined(USE_TOD)
1146 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
1148 #ifndef OPENSSL_NO_ENGINE
1149 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
1151 BIO_printf(bio_err,"-evp e use EVP e.\n");
1152 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
1153 BIO_printf(bio_err,"-mr produce machine readable output.\n");
1155 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
1165 if(multi && do_multi(multi))
1171 for (i=0; i<ALGOR_NUM; i++)
1176 for (i=0; i<RSA_NUM; i++)
1178 for (i=0; i<DSA_NUM; i++)
1180 #ifndef OPENSSL_NO_ECDSA
1181 for (i=0; i<EC_NUM; i++)
1184 #ifndef OPENSSL_NO_ECDH
1185 for (i=0; i<EC_NUM; i++)
1189 for (i=0; i<ALGOR_NUM; i++)
1190 if (doit[i]) pr_header++;
1192 if (usertime == 0 && !mr)
1193 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1195 #ifndef OPENSSL_NO_RSA
1196 for (i=0; i<RSA_NUM; i++)
1198 const unsigned char *p;
1201 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1202 if (rsa_key[i] == NULL)
1204 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1210 BIO_printf(bio_err,mr ? "+RK:%d:"
1211 : "Loaded RSA key, %d bit modulus and e= 0x",
1212 BN_num_bits(rsa_key[i]->n));
1213 BN_print(bio_err,rsa_key[i]->e);
1214 BIO_printf(bio_err,"\n");
1220 #ifndef OPENSSL_NO_DSA
1221 dsa_key[0]=get_dsa512();
1222 dsa_key[1]=get_dsa1024();
1223 dsa_key[2]=get_dsa2048();
1226 #ifndef OPENSSL_NO_DES
1227 DES_set_key_unchecked(&key,&sch);
1228 DES_set_key_unchecked(&key2,&sch2);
1229 DES_set_key_unchecked(&key3,&sch3);
1231 #ifndef OPENSSL_NO_AES
1232 AES_set_encrypt_key(key16,128,&aes_ks1);
1233 AES_set_encrypt_key(key24,192,&aes_ks2);
1234 AES_set_encrypt_key(key32,256,&aes_ks3);
1236 #ifndef OPENSSL_NO_CAMELLIA
1237 Camellia_set_key(key16,128,&camellia_ks1);
1238 Camellia_set_key(ckey24,192,&camellia_ks2);
1239 Camellia_set_key(ckey32,256,&camellia_ks3);
1241 #ifndef OPENSSL_NO_IDEA
1242 idea_set_encrypt_key(key16,&idea_ks);
1244 #ifndef OPENSSL_NO_SEED
1245 SEED_set_key(key16,&seed_ks);
1247 #ifndef OPENSSL_NO_RC4
1248 RC4_set_key(&rc4_ks,16,key16);
1250 #ifndef OPENSSL_NO_RC2
1251 RC2_set_key(&rc2_ks,16,key16,128);
1253 #ifndef OPENSSL_NO_RC5
1254 RC5_32_set_key(&rc5_ks,16,key16,12);
1256 #ifndef OPENSSL_NO_BF
1257 BF_set_key(&bf_ks,16,key16);
1259 #ifndef OPENSSL_NO_CAST
1260 CAST_set_key(&cast_ks,16,key16);
1262 #ifndef OPENSSL_NO_RSA
1263 memset(rsa_c,0,sizeof(rsa_c));
1266 #ifndef OPENSSL_NO_DES
1267 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1273 for (it=count; it; it--)
1274 DES_ecb_encrypt((DES_cblock *)buf,
1280 c[D_MD2][0]=count/10;
1281 c[D_MDC2][0]=count/10;
1286 c[D_RMD160][0]=count;
1287 c[D_RC4][0]=count*5;
1288 c[D_CBC_DES][0]=count;
1289 c[D_EDE3_DES][0]=count/3;
1290 c[D_CBC_IDEA][0]=count;
1291 c[D_CBC_SEED][0]=count;
1292 c[D_CBC_RC2][0]=count;
1293 c[D_CBC_RC5][0]=count;
1294 c[D_CBC_BF][0]=count;
1295 c[D_CBC_CAST][0]=count;
1296 c[D_CBC_128_AES][0]=count;
1297 c[D_CBC_192_AES][0]=count;
1298 c[D_CBC_256_AES][0]=count;
1299 c[D_CBC_128_CML][0]=count;
1300 c[D_CBC_192_CML][0]=count;
1301 c[D_CBC_256_CML][0]=count;
1302 c[D_SHA256][0]=count;
1303 c[D_SHA512][0]=count;
1304 c[D_WHIRLPOOL][0]=count;
1305 c[D_IGE_128_AES][0]=count;
1306 c[D_IGE_192_AES][0]=count;
1307 c[D_IGE_256_AES][0]=count;
1308 c[D_GHASH][0]=count;
1310 for (i=1; i<SIZE_NUM; i++)
1314 l0=(long)lengths[0];
1315 l1=(long)lengths[i];
1317 c[D_MD2][i]=c[D_MD2][0]*4*l0/l1;
1318 c[D_MDC2][i]=c[D_MDC2][0]*4*l0/l1;
1319 c[D_MD4][i]=c[D_MD4][0]*4*l0/l1;
1320 c[D_MD5][i]=c[D_MD5][0]*4*l0/l1;
1321 c[D_HMAC][i]=c[D_HMAC][0]*4*l0/l1;
1322 c[D_SHA1][i]=c[D_SHA1][0]*4*l0/l1;
1323 c[D_RMD160][i]=c[D_RMD160][0]*4*l0/l1;
1324 c[D_SHA256][i]=c[D_SHA256][0]*4*l0/l1;
1325 c[D_SHA512][i]=c[D_SHA512][0]*4*l0/l1;
1326 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*l0/l1;
1328 l0=(long)lengths[i-1];
1330 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1331 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1332 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1333 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1334 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1335 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1336 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1337 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1338 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1339 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1340 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1341 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1342 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1343 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1344 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1345 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1346 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1347 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1350 prime_c[D_PRIME_TRIAL_DIVISION]=count;
1351 prime_c[D_PRIME_COPRIME]=count;
1353 #ifndef OPENSSL_NO_RSA
1354 rsa_c[R_RSA_512][0]=count/2000;
1355 rsa_c[R_RSA_512][1]=count/400;
1356 for (i=1; i<RSA_NUM; i++)
1358 rsa_c[i][0]=rsa_c[i-1][0]/8;
1359 rsa_c[i][1]=rsa_c[i-1][1]/4;
1360 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1364 if (rsa_c[i][0] == 0)
1373 #ifndef OPENSSL_NO_DSA
1374 dsa_c[R_DSA_512][0]=count/1000;
1375 dsa_c[R_DSA_512][1]=count/1000/2;
1376 for (i=1; i<DSA_NUM; i++)
1378 dsa_c[i][0]=dsa_c[i-1][0]/4;
1379 dsa_c[i][1]=dsa_c[i-1][1]/4;
1380 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1393 #ifndef OPENSSL_NO_ECDSA
1394 ecdsa_c[R_EC_P160][0]=count/1000;
1395 ecdsa_c[R_EC_P160][1]=count/1000/2;
1396 for (i=R_EC_P192; i<=R_EC_P521; i++)
1398 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1399 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1400 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1404 if (ecdsa_c[i] == 0)
1411 ecdsa_c[R_EC_K163][0]=count/1000;
1412 ecdsa_c[R_EC_K163][1]=count/1000/2;
1413 for (i=R_EC_K233; i<=R_EC_K571; i++)
1415 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1416 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1417 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1421 if (ecdsa_c[i] == 0)
1428 ecdsa_c[R_EC_B163][0]=count/1000;
1429 ecdsa_c[R_EC_B163][1]=count/1000/2;
1430 for (i=R_EC_B233; i<=R_EC_B571; i++)
1432 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1433 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1434 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1438 if (ecdsa_c[i] == 0)
1447 #ifndef OPENSSL_NO_ECDH
1448 ecdh_c[R_EC_P160][0]=count/1000;
1449 ecdh_c[R_EC_P160][1]=count/1000;
1450 for (i=R_EC_P192; i<=R_EC_P521; i++)
1452 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1453 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1454 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1465 ecdh_c[R_EC_K163][0]=count/1000;
1466 ecdh_c[R_EC_K163][1]=count/1000;
1467 for (i=R_EC_K233; i<=R_EC_K571; i++)
1469 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1470 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1471 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1482 ecdh_c[R_EC_B163][0]=count/1000;
1483 ecdh_c[R_EC_B163][1]=count/1000;
1484 for (i=R_EC_B233; i<=R_EC_B571; i++)
1486 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1487 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1488 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1501 #define COND(d) (count < (d))
1502 #define COUNT(d) (d)
1504 /* not worth fixing */
1505 # error "You cannot disable DES on systems without SIGALRM."
1506 #endif /* OPENSSL_NO_DES */
1508 #define COND(c) (run && count<0x7fffffff)
1509 #define COUNT(d) (count)
1511 signal(SIGALRM,sig_done);
1513 #endif /* SIGALRM */
1515 #ifndef OPENSSL_NO_MD2
1518 for (j=0; j<SIZE_NUM; j++)
1520 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1522 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1523 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1525 print_result(D_MD2,j,count,d);
1529 #ifndef OPENSSL_NO_MDC2
1532 for (j=0; j<SIZE_NUM; j++)
1534 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1536 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1537 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1539 print_result(D_MDC2,j,count,d);
1544 #ifndef OPENSSL_NO_MD4
1547 for (j=0; j<SIZE_NUM; j++)
1549 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1551 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1552 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1554 print_result(D_MD4,j,count,d);
1559 #ifndef OPENSSL_NO_MD5
1562 for (j=0; j<SIZE_NUM; j++)
1564 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1566 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1567 MD5(buf,lengths[j],md5);
1569 print_result(D_MD5,j,count,d);
1574 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1579 HMAC_CTX_init(&hctx);
1580 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1581 16,EVP_md5(), NULL);
1583 for (j=0; j<SIZE_NUM; j++)
1585 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1587 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1589 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1590 HMAC_Update(&hctx,buf,lengths[j]);
1591 HMAC_Final(&hctx,&(hmac[0]),NULL);
1594 print_result(D_HMAC,j,count,d);
1596 HMAC_CTX_cleanup(&hctx);
1599 #ifndef OPENSSL_NO_SHA
1602 for (j=0; j<SIZE_NUM; j++)
1604 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1606 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1608 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1610 SHA1(buf,lengths[j],sha);
1613 print_result(D_SHA1,j,count,d);
1617 #ifndef OPENSSL_NO_SHA256
1620 for (j=0; j<SIZE_NUM; j++)
1622 print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1624 for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1625 SHA256(buf,lengths[j],sha256);
1627 print_result(D_SHA256,j,count,d);
1632 #ifndef OPENSSL_NO_SHA512
1635 for (j=0; j<SIZE_NUM; j++)
1637 print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1639 for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1640 SHA512(buf,lengths[j],sha512);
1642 print_result(D_SHA512,j,count,d);
1648 #ifndef OPENSSL_NO_WHIRLPOOL
1649 if (doit[D_WHIRLPOOL])
1651 for (j=0; j<SIZE_NUM; j++)
1653 print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1655 for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1656 WHIRLPOOL(buf,lengths[j],whirlpool);
1658 print_result(D_WHIRLPOOL,j,count,d);
1663 #ifndef OPENSSL_NO_RIPEMD
1666 for (j=0; j<SIZE_NUM; j++)
1668 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1670 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1671 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1673 print_result(D_RMD160,j,count,d);
1677 #ifndef OPENSSL_NO_RC4
1680 for (j=0; j<SIZE_NUM; j++)
1682 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1684 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1685 RC4(&rc4_ks,(unsigned int)lengths[j],
1688 print_result(D_RC4,j,count,d);
1692 #ifndef OPENSSL_NO_DES
1693 if (doit[D_CBC_DES])
1695 for (j=0; j<SIZE_NUM; j++)
1697 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1699 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1700 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1701 &DES_iv,DES_ENCRYPT);
1703 print_result(D_CBC_DES,j,count,d);
1707 if (doit[D_EDE3_DES])
1709 for (j=0; j<SIZE_NUM; j++)
1711 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1713 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1714 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1716 &DES_iv,DES_ENCRYPT);
1718 print_result(D_EDE3_DES,j,count,d);
1722 #ifndef OPENSSL_NO_AES
1723 if (doit[D_CBC_128_AES])
1725 for (j=0; j<SIZE_NUM; j++)
1727 print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1729 for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1730 AES_cbc_encrypt(buf,buf,
1731 (unsigned long)lengths[j],&aes_ks1,
1734 print_result(D_CBC_128_AES,j,count,d);
1737 if (doit[D_CBC_192_AES])
1739 for (j=0; j<SIZE_NUM; j++)
1741 print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1743 for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1744 AES_cbc_encrypt(buf,buf,
1745 (unsigned long)lengths[j],&aes_ks2,
1748 print_result(D_CBC_192_AES,j,count,d);
1751 if (doit[D_CBC_256_AES])
1753 for (j=0; j<SIZE_NUM; j++)
1755 print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1757 for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1758 AES_cbc_encrypt(buf,buf,
1759 (unsigned long)lengths[j],&aes_ks3,
1762 print_result(D_CBC_256_AES,j,count,d);
1766 if (doit[D_IGE_128_AES])
1768 for (j=0; j<SIZE_NUM; j++)
1770 print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1772 for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1773 AES_ige_encrypt(buf,buf2,
1774 (unsigned long)lengths[j],&aes_ks1,
1777 print_result(D_IGE_128_AES,j,count,d);
1780 if (doit[D_IGE_192_AES])
1782 for (j=0; j<SIZE_NUM; j++)
1784 print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1786 for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1787 AES_ige_encrypt(buf,buf2,
1788 (unsigned long)lengths[j],&aes_ks2,
1791 print_result(D_IGE_192_AES,j,count,d);
1794 if (doit[D_IGE_256_AES])
1796 for (j=0; j<SIZE_NUM; j++)
1798 print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1800 for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1801 AES_ige_encrypt(buf,buf2,
1802 (unsigned long)lengths[j],&aes_ks3,
1805 print_result(D_IGE_256_AES,j,count,d);
1810 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1811 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1813 for (j=0; j<SIZE_NUM; j++)
1815 print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1817 for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1818 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1820 print_result(D_GHASH,j,count,d);
1822 CRYPTO_gcm128_release(ctx);
1826 #ifndef OPENSSL_NO_CAMELLIA
1827 if (doit[D_CBC_128_CML])
1829 for (j=0; j<SIZE_NUM; j++)
1831 print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1833 for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1834 Camellia_cbc_encrypt(buf,buf,
1835 (unsigned long)lengths[j],&camellia_ks1,
1836 iv,CAMELLIA_ENCRYPT);
1838 print_result(D_CBC_128_CML,j,count,d);
1841 if (doit[D_CBC_192_CML])
1843 for (j=0; j<SIZE_NUM; j++)
1845 print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1847 for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1848 Camellia_cbc_encrypt(buf,buf,
1849 (unsigned long)lengths[j],&camellia_ks2,
1850 iv,CAMELLIA_ENCRYPT);
1852 print_result(D_CBC_192_CML,j,count,d);
1855 if (doit[D_CBC_256_CML])
1857 for (j=0; j<SIZE_NUM; j++)
1859 print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1861 for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1862 Camellia_cbc_encrypt(buf,buf,
1863 (unsigned long)lengths[j],&camellia_ks3,
1864 iv,CAMELLIA_ENCRYPT);
1866 print_result(D_CBC_256_CML,j,count,d);
1871 #ifndef OPENSSL_NO_IDEA
1872 if (doit[D_CBC_IDEA])
1874 for (j=0; j<SIZE_NUM; j++)
1876 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1878 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1879 idea_cbc_encrypt(buf,buf,
1880 (unsigned long)lengths[j],&idea_ks,
1883 print_result(D_CBC_IDEA,j,count,d);
1887 #ifndef OPENSSL_NO_SEED
1888 if (doit[D_CBC_SEED])
1890 for (j=0; j<SIZE_NUM; j++)
1892 print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1894 for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1895 SEED_cbc_encrypt(buf,buf,
1896 (unsigned long)lengths[j],&seed_ks,iv,1);
1898 print_result(D_CBC_SEED,j,count,d);
1902 #ifndef OPENSSL_NO_RC2
1903 if (doit[D_CBC_RC2])
1905 for (j=0; j<SIZE_NUM; j++)
1907 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1909 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1910 RC2_cbc_encrypt(buf,buf,
1911 (unsigned long)lengths[j],&rc2_ks,
1914 print_result(D_CBC_RC2,j,count,d);
1918 #ifndef OPENSSL_NO_RC5
1919 if (doit[D_CBC_RC5])
1921 for (j=0; j<SIZE_NUM; j++)
1923 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1925 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1926 RC5_32_cbc_encrypt(buf,buf,
1927 (unsigned long)lengths[j],&rc5_ks,
1930 print_result(D_CBC_RC5,j,count,d);
1934 #ifndef OPENSSL_NO_BF
1937 for (j=0; j<SIZE_NUM; j++)
1939 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1941 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1942 BF_cbc_encrypt(buf,buf,
1943 (unsigned long)lengths[j],&bf_ks,
1946 print_result(D_CBC_BF,j,count,d);
1950 #ifndef OPENSSL_NO_CAST
1951 if (doit[D_CBC_CAST])
1953 for (j=0; j<SIZE_NUM; j++)
1955 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1957 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1958 CAST_cbc_encrypt(buf,buf,
1959 (unsigned long)lengths[j],&cast_ks,
1962 print_result(D_CBC_CAST,j,count,d);
1969 for (j=0; j<SIZE_NUM; j++)
1976 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1977 /* -O3 -fschedule-insns messes up an
1978 * optimization here! names[D_EVP]
1979 * somehow becomes NULL */
1980 print_message(names[D_EVP],save_count,
1983 EVP_CIPHER_CTX_init(&ctx);
1985 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1987 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1988 EVP_CIPHER_CTX_set_padding(&ctx, 0);
1992 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1993 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1995 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1996 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1998 EVP_DecryptFinal_ex(&ctx,buf,&outl);
2000 EVP_EncryptFinal_ex(&ctx,buf,&outl);
2002 EVP_CIPHER_CTX_cleanup(&ctx);
2006 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2007 print_message(names[D_EVP],save_count,
2011 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2012 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2016 print_result(D_EVP,j,count,d);
2020 for (j=0; j<PRIME_NUM; j++)
2022 BIGNUM *rnd = BN_new();
2023 BIGNUM *add = BN_new();
2024 BN_CTX *ctx = BN_CTX_new();
2028 BN_set_word(add, 2);
2030 prime_print_message(prime_names[j], prime_c[j]);
2033 for (count=0, run=1; COND(prime_c[j]); count++)
2034 bn_probable_prime_dh(rnd, 1024, add, NULL, ctx);
2038 mr ? "+R:%ld:%s:%f\n" : "%ld %s's in %.2fs\n",
2039 count, prime_names[j], d);
2047 RAND_pseudo_bytes(buf,36);
2048 #ifndef OPENSSL_NO_RSA
2049 for (j=0; j<RSA_NUM; j++)
2052 if (!rsa_doit[j]) continue;
2053 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2056 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
2057 ERR_print_errors(bio_err);
2062 pkey_print_message("private","rsa",
2063 rsa_c[j][0],rsa_bits[j],
2065 /* RSA_blinding_on(rsa_key[j],NULL); */
2067 for (count=0,run=1; COND(rsa_c[j][0]); count++)
2069 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2070 &rsa_num, rsa_key[j]);
2074 "RSA sign failure\n");
2075 ERR_print_errors(bio_err);
2081 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2082 : "%ld %d bit private RSA's in %.2fs\n",
2083 count,rsa_bits[j],d);
2084 rsa_results[j][0]=d/(double)count;
2089 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2092 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
2093 ERR_print_errors(bio_err);
2098 pkey_print_message("public","rsa",
2099 rsa_c[j][1],rsa_bits[j],
2102 for (count=0,run=1; COND(rsa_c[j][1]); count++)
2104 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2105 rsa_num, rsa_key[j]);
2109 "RSA verify failure\n");
2110 ERR_print_errors(bio_err);
2116 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2117 : "%ld %d bit public RSA's in %.2fs\n",
2118 count,rsa_bits[j],d);
2119 rsa_results[j][1]=d/(double)count;
2125 /* if longer than 10s, don't do any more */
2126 for (j++; j<RSA_NUM; j++)
2132 RAND_pseudo_bytes(buf,20);
2133 #ifndef OPENSSL_NO_DSA
2134 if (RAND_status() != 1)
2136 RAND_seed(rnd_seed, sizeof rnd_seed);
2139 for (j=0; j<DSA_NUM; j++)
2144 if (!dsa_doit[j]) continue;
2145 /* DSA_generate_key(dsa_key[j]); */
2146 /* DSA_sign_setup(dsa_key[j],NULL); */
2147 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2151 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
2152 ERR_print_errors(bio_err);
2157 pkey_print_message("sign","dsa",
2158 dsa_c[j][0],dsa_bits[j],
2161 for (count=0,run=1; COND(dsa_c[j][0]); count++)
2163 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2168 "DSA sign failure\n");
2169 ERR_print_errors(bio_err);
2175 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2176 : "%ld %d bit DSA signs in %.2fs\n",
2177 count,dsa_bits[j],d);
2178 dsa_results[j][0]=d/(double)count;
2182 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2186 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
2187 ERR_print_errors(bio_err);
2192 pkey_print_message("verify","dsa",
2193 dsa_c[j][1],dsa_bits[j],
2196 for (count=0,run=1; COND(dsa_c[j][1]); count++)
2198 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2203 "DSA verify failure\n");
2204 ERR_print_errors(bio_err);
2210 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2211 : "%ld %d bit DSA verify in %.2fs\n",
2212 count,dsa_bits[j],d);
2213 dsa_results[j][1]=d/(double)count;
2218 /* if longer than 10s, don't do any more */
2219 for (j++; j<DSA_NUM; j++)
2223 if (rnd_fake) RAND_cleanup();
2226 #ifndef OPENSSL_NO_ECDSA
2227 if (RAND_status() != 1)
2229 RAND_seed(rnd_seed, sizeof rnd_seed);
2232 for (j=0; j<EC_NUM; j++)
2236 if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2237 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2238 if (ecdsa[j] == NULL)
2240 BIO_printf(bio_err,"ECDSA failure.\n");
2241 ERR_print_errors(bio_err);
2247 EC_KEY_precompute_mult(ecdsa[j], NULL);
2249 /* Perform ECDSA signature test */
2250 EC_KEY_generate_key(ecdsa[j]);
2251 ret = ECDSA_sign(0, buf, 20, ecdsasig,
2252 &ecdsasiglen, ecdsa[j]);
2255 BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
2256 ERR_print_errors(bio_err);
2261 pkey_print_message("sign","ecdsa",
2263 test_curves_bits[j],
2267 for (count=0,run=1; COND(ecdsa_c[j][0]);
2270 ret=ECDSA_sign(0, buf, 20,
2271 ecdsasig, &ecdsasiglen,
2275 BIO_printf(bio_err, "ECDSA sign failure\n");
2276 ERR_print_errors(bio_err);
2283 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2284 "%ld %d bit ECDSA signs in %.2fs \n",
2285 count, test_curves_bits[j], d);
2286 ecdsa_results[j][0]=d/(double)count;
2290 /* Perform ECDSA verification test */
2291 ret=ECDSA_verify(0, buf, 20, ecdsasig,
2292 ecdsasiglen, ecdsa[j]);
2295 BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
2296 ERR_print_errors(bio_err);
2301 pkey_print_message("verify","ecdsa",
2303 test_curves_bits[j],
2306 for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2308 ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2311 BIO_printf(bio_err, "ECDSA verify failure\n");
2312 ERR_print_errors(bio_err);
2318 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2319 : "%ld %d bit ECDSA verify in %.2fs\n",
2320 count, test_curves_bits[j], d);
2321 ecdsa_results[j][1]=d/(double)count;
2326 /* if longer than 10s, don't do any more */
2327 for (j++; j<EC_NUM; j++)
2332 if (rnd_fake) RAND_cleanup();
2335 #ifndef OPENSSL_NO_ECDH
2336 if (RAND_status() != 1)
2338 RAND_seed(rnd_seed, sizeof rnd_seed);
2341 for (j=0; j<EC_NUM; j++)
2343 if (!ecdh_doit[j]) continue;
2344 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2345 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2346 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2348 BIO_printf(bio_err,"ECDH failure.\n");
2349 ERR_print_errors(bio_err);
2354 /* generate two ECDH key pairs */
2355 if (!EC_KEY_generate_key(ecdh_a[j]) ||
2356 !EC_KEY_generate_key(ecdh_b[j]))
2358 BIO_printf(bio_err,"ECDH key generation failure.\n");
2359 ERR_print_errors(bio_err);
2364 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2365 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2367 int field_size, outlen;
2368 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2369 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2370 if (field_size <= 24 * 8)
2372 outlen = KDF1_SHA1_len;
2377 outlen = (field_size+7)/8;
2380 secret_size_a = ECDH_compute_key(secret_a, outlen,
2381 EC_KEY_get0_public_key(ecdh_b[j]),
2383 secret_size_b = ECDH_compute_key(secret_b, outlen,
2384 EC_KEY_get0_public_key(ecdh_a[j]),
2386 if (secret_size_a != secret_size_b)
2391 for (secret_idx = 0;
2392 (secret_idx < secret_size_a)
2393 && (ecdh_checks == 1);
2396 if (secret_a[secret_idx] != secret_b[secret_idx])
2400 if (ecdh_checks == 0)
2402 BIO_printf(bio_err,"ECDH computations don't match.\n");
2403 ERR_print_errors(bio_err);
2407 pkey_print_message("","ecdh",
2409 test_curves_bits[j],
2412 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2414 ECDH_compute_key(secret_a, outlen,
2415 EC_KEY_get0_public_key(ecdh_b[j]),
2419 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2420 count, test_curves_bits[j], d);
2421 ecdh_results[j][0]=d/(double)count;
2429 /* if longer than 10s, don't do any more */
2430 for (j++; j<EC_NUM; j++)
2434 if (rnd_fake) RAND_cleanup();
2441 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2442 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2444 printf("%s ",BN_options());
2445 #ifndef OPENSSL_NO_MD2
2446 printf("%s ",MD2_options());
2448 #ifndef OPENSSL_NO_RC4
2449 printf("%s ",RC4_options());
2451 #ifndef OPENSSL_NO_DES
2452 printf("%s ",DES_options());
2454 #ifndef OPENSSL_NO_AES
2455 printf("%s ",AES_options());
2457 #ifndef OPENSSL_NO_IDEA
2458 printf("%s ",idea_options());
2460 #ifndef OPENSSL_NO_BF
2461 printf("%s ",BF_options());
2463 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2469 fprintf(stdout,"+H");
2472 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
2473 fprintf(stdout,"type ");
2475 for (j=0; j<SIZE_NUM; j++)
2476 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2477 fprintf(stdout,"\n");
2480 for (k=0; k<ALGOR_NUM; k++)
2482 if (!doit[k]) continue;
2484 fprintf(stdout,"+F:%d:%s",k,names[k]);
2486 fprintf(stdout,"%-13s",names[k]);
2487 for (j=0; j<SIZE_NUM; j++)
2489 if (results[k][j] > 10000 && !mr)
2490 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2492 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2494 fprintf(stdout,"\n");
2496 #ifndef OPENSSL_NO_RSA
2498 for (k=0; k<RSA_NUM; k++)
2500 if (!rsa_doit[k]) continue;
2503 printf("%18ssign verify sign/s verify/s\n"," ");
2507 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2508 k,rsa_bits[k],rsa_results[k][0],
2511 fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2512 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2513 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2516 #ifndef OPENSSL_NO_DSA
2518 for (k=0; k<DSA_NUM; k++)
2520 if (!dsa_doit[k]) continue;
2523 printf("%18ssign verify sign/s verify/s\n"," ");
2527 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2528 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2530 fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2531 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2532 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2535 #ifndef OPENSSL_NO_ECDSA
2537 for (k=0; k<EC_NUM; k++)
2539 if (!ecdsa_doit[k]) continue;
2542 printf("%30ssign verify sign/s verify/s\n"," ");
2547 fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2548 k, test_curves_bits[k],
2549 ecdsa_results[k][0],ecdsa_results[k][1]);
2552 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2553 test_curves_bits[k],
2554 test_curves_names[k],
2555 ecdsa_results[k][0],ecdsa_results[k][1],
2556 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2561 #ifndef OPENSSL_NO_ECDH
2563 for (k=0; k<EC_NUM; k++)
2565 if (!ecdh_doit[k]) continue;
2568 printf("%30sop op/s\n"," ");
2572 fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2573 k, test_curves_bits[k],
2574 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2577 fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2578 test_curves_bits[k],
2579 test_curves_names[k],
2580 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2587 ERR_print_errors(bio_err);
2588 if (buf != NULL) OPENSSL_free(buf);
2589 if (buf2 != NULL) OPENSSL_free(buf2);
2590 #ifndef OPENSSL_NO_RSA
2591 for (i=0; i<RSA_NUM; i++)
2592 if (rsa_key[i] != NULL)
2593 RSA_free(rsa_key[i]);
2595 #ifndef OPENSSL_NO_DSA
2596 for (i=0; i<DSA_NUM; i++)
2597 if (dsa_key[i] != NULL)
2598 DSA_free(dsa_key[i]);
2601 #ifndef OPENSSL_NO_ECDSA
2602 for (i=0; i<EC_NUM; i++)
2603 if (ecdsa[i] != NULL)
2604 EC_KEY_free(ecdsa[i]);
2606 #ifndef OPENSSL_NO_ECDH
2607 for (i=0; i<EC_NUM; i++)
2609 if (ecdh_a[i] != NULL)
2610 EC_KEY_free(ecdh_a[i]);
2611 if (ecdh_b[i] != NULL)
2612 EC_KEY_free(ecdh_b[i]);
2620 static void print_message(const char *s, long num, int length)
2623 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2624 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2625 (void)BIO_flush(bio_err);
2628 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2629 : "Doing %s %ld times on %d size blocks: ",s,num,length);
2630 (void)BIO_flush(bio_err);
2637 static void prime_print_message(const char *s, long num)
2640 BIO_printf(bio_err,mr ? "+DT:%s:%d\n"
2641 : "Doing %s for %ds: ", s, SECONDS);
2642 (void)BIO_flush(bio_err);
2645 BIO_printf(bio_err,mr ? "+DN:%s:%ld\n"
2646 : "Doing %s %ld times: ", s, num);
2647 (void)BIO_flush(bio_err);
2654 static void pkey_print_message(const char *str, const char *str2, long num,
2658 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2659 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2660 (void)BIO_flush(bio_err);
2663 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2664 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2665 (void)BIO_flush(bio_err);
2672 static void print_result(int alg,int run_no,int count,double time_used)
2674 BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2675 : "%d %s's in %.2fs\n",count,names[alg],time_used);
2676 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2680 static char *sstrsep(char **string, const char *delim)
2683 char *token = *string;
2688 memset(isdelim, 0, sizeof isdelim);
2693 isdelim[(unsigned char)(*delim)] = 1;
2697 while (!isdelim[(unsigned char)(**string)])
2711 static int do_multi(int multi)
2716 static char sep[]=":";
2718 fds=malloc(multi*sizeof *fds);
2719 for(n=0 ; n < multi ; ++n)
2723 fprintf(stderr, "pipe failure\n");
2737 if (dup(fd[1]) == -1)
2739 fprintf(stderr, "dup failed\n");
2748 printf("Forked child %d\n",n);
2751 /* for now, assume the pipe is long enough to take all the output */
2752 for(n=0 ; n < multi ; ++n)
2758 f=fdopen(fds[n],"r");
2759 while(fgets(buf,sizeof buf,f))
2766 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2770 printf("Got: %s from %d\n",buf,n);
2771 if(!strncmp(buf,"+F:",3))
2777 alg=atoi(sstrsep(&p,sep));
2779 for(j=0 ; j < SIZE_NUM ; ++j)
2780 results[alg][j]+=atof(sstrsep(&p,sep));
2782 else if(!strncmp(buf,"+F2:",4))
2788 k=atoi(sstrsep(&p,sep));
2791 d=atof(sstrsep(&p,sep));
2793 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2795 rsa_results[k][0]=d;
2797 d=atof(sstrsep(&p,sep));
2799 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2801 rsa_results[k][1]=d;
2803 else if(!strncmp(buf,"+F2:",4))
2809 k=atoi(sstrsep(&p,sep));
2812 d=atof(sstrsep(&p,sep));
2814 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2816 rsa_results[k][0]=d;
2818 d=atof(sstrsep(&p,sep));
2820 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2822 rsa_results[k][1]=d;
2824 #ifndef OPENSSL_NO_DSA
2825 else if(!strncmp(buf,"+F3:",4))
2831 k=atoi(sstrsep(&p,sep));
2834 d=atof(sstrsep(&p,sep));
2836 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2838 dsa_results[k][0]=d;
2840 d=atof(sstrsep(&p,sep));
2842 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2844 dsa_results[k][1]=d;
2847 #ifndef OPENSSL_NO_ECDSA
2848 else if(!strncmp(buf,"+F4:",4))
2854 k=atoi(sstrsep(&p,sep));
2857 d=atof(sstrsep(&p,sep));
2859 ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2861 ecdsa_results[k][0]=d;
2863 d=atof(sstrsep(&p,sep));
2865 ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2867 ecdsa_results[k][1]=d;
2871 #ifndef OPENSSL_NO_ECDH
2872 else if(!strncmp(buf,"+F5:",4))
2878 k=atoi(sstrsep(&p,sep));
2881 d=atof(sstrsep(&p,sep));
2883 ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2885 ecdh_results[k][0]=d;
2890 else if(!strncmp(buf,"+H:",3))
2894 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);