chacha20poly1305
[oweals/openssl.git] / apps / speed.c
1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3  * All rights reserved.
4  *
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.
8  * 
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).
15  * 
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.
22  * 
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
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)"
40  * 
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
51  * SUCH DAMAGE.
52  * 
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.]
57  */
58 /* ====================================================================
59  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60  *
61  * Portions of the attached software ("Contribution") are developed by 
62  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63  *
64  * The Contribution is licensed pursuant to the OpenSSL open source
65  * license provided above.
66  *
67  * The ECDH and ECDSA speed test software is originally written by 
68  * Sumit Gupta of Sun Microsystems Laboratories.
69  *
70  */
71
72 /* most of this code has been pilfered from my libdes speed.c program */
73
74 #ifndef OPENSSL_NO_SPEED
75
76 #undef SECONDS
77 #define SECONDS         3       
78 #define RSA_SECONDS     10
79 #define DSA_SECONDS     10
80 #define ECDSA_SECONDS   10
81 #define ECDH_SECONDS    10
82
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 */
85
86 #undef PROG
87 #define PROG speed_main
88
89 #include <stdio.h>
90 #include <stdlib.h>
91
92 #include <string.h>
93 #include <math.h>
94 #include "apps.h"
95 #ifdef OPENSSL_NO_STDIO
96 #define APPS_WIN16
97 #endif
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
105 #endif
106
107 #ifndef OPENSSL_SYS_NETWARE
108 #include <signal.h>
109 #endif
110
111 #if defined(_WIN32) || defined(__CYGWIN__)
112 #include <windows.h>
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... */
116 #  define _WIN32
117   /* this is done because Cygwin alarm() fails sometimes. */
118 # endif
119 #endif
120
121 #include <openssl/bn.h>
122 #ifndef OPENSSL_NO_DES
123 #include <openssl/des.h>
124 #endif
125 #ifndef OPENSSL_NO_AES
126 #include <openssl/aes.h>
127 #endif
128 #ifndef OPENSSL_NO_CAMELLIA
129 #include <openssl/camellia.h>
130 #endif
131 #ifndef OPENSSL_NO_MD2
132 #include <openssl/md2.h>
133 #endif
134 #ifndef OPENSSL_NO_MDC2
135 #include <openssl/mdc2.h>
136 #endif
137 #ifndef OPENSSL_NO_MD4
138 #include <openssl/md4.h>
139 #endif
140 #ifndef OPENSSL_NO_MD5
141 #include <openssl/md5.h>
142 #endif
143 #ifndef OPENSSL_NO_HMAC
144 #include <openssl/hmac.h>
145 #endif
146 #include <openssl/evp.h>
147 #ifndef OPENSSL_NO_SHA
148 #include <openssl/sha.h>
149 #endif
150 #ifndef OPENSSL_NO_RIPEMD
151 #include <openssl/ripemd.h>
152 #endif
153 #ifndef OPENSSL_NO_WHIRLPOOL
154 #include <openssl/whrlpool.h>
155 #endif
156 #ifndef OPENSSL_NO_RC4
157 #include <openssl/rc4.h>
158 #endif
159 #ifndef OPENSSL_NO_RC5
160 #include <openssl/rc5.h>
161 #endif
162 #ifndef OPENSSL_NO_RC2
163 #include <openssl/rc2.h>
164 #endif
165 #ifndef OPENSSL_NO_IDEA
166 #include <openssl/idea.h>
167 #endif
168 #ifndef OPENSSL_NO_SEED
169 #include <openssl/seed.h>
170 #endif
171 #ifndef OPENSSL_NO_BF
172 #include <openssl/blowfish.h>
173 #endif
174 #ifndef OPENSSL_NO_CAST
175 #include <openssl/cast.h>
176 #endif
177 #ifndef OPENSSL_NO_RSA
178 #include <openssl/rsa.h>
179 #include "./testrsa.h"
180 #endif
181 #include <openssl/x509.h>
182 #ifndef OPENSSL_NO_DSA
183 #include <openssl/dsa.h>
184 #include "./testdsa.h"
185 #endif
186 #ifndef OPENSSL_NO_ECDSA
187 #include <openssl/ecdsa.h>
188 #endif
189 #ifndef OPENSSL_NO_ECDH
190 #include <openssl/ecdh.h>
191 #endif
192 #include <openssl/modes.h>
193
194 #ifdef OPENSSL_FIPS
195 #ifdef OPENSSL_DOING_MAKEDEPEND
196 #undef AES_set_encrypt_key
197 #undef AES_set_decrypt_key
198 #undef DES_set_key_unchecked
199 #endif
200 #define BF_set_key      private_BF_set_key
201 #define CAST_set_key    private_CAST_set_key
202 #define idea_set_encrypt_key    private_idea_set_encrypt_key
203 #define SEED_set_key    private_SEED_set_key
204 #define RC2_set_key     private_RC2_set_key
205 #define RC4_set_key     private_RC4_set_key
206 #define DES_set_key_unchecked   private_DES_set_key_unchecked
207 #define AES_set_encrypt_key     private_AES_set_encrypt_key
208 #define AES_set_decrypt_key     private_AES_set_decrypt_key
209 #define Camellia_set_key        private_Camellia_set_key
210 #endif
211
212 #ifndef HAVE_FORK
213 # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
214 #  define HAVE_FORK 0
215 # else
216 #  define HAVE_FORK 1
217 # endif
218 #endif
219
220 #if HAVE_FORK
221 #undef NO_FORK
222 #else
223 #define NO_FORK
224 #endif
225
226 #undef BUFSIZE
227 #define BUFSIZE ((long)1024*8+64)
228 int run=0;
229
230 static int mr=0;
231 static int usertime=1;
232
233 static double Time_F(int s);
234 static void print_message(const char *s,long num,int length);
235 static void pkey_print_message(const char *str, const char *str2,
236         long num, int bits, int sec);
237 static void print_result(int alg,int run_no,int count,double time_used);
238 #ifndef NO_FORK
239 static int do_multi(int multi);
240 #endif
241
242 #define ALGOR_NUM       33
243 #define SIZE_NUM        5
244 #define RSA_NUM         4
245 #define DSA_NUM         3
246
247 #define EC_NUM       16
248 #define MAX_ECDH_SIZE 256
249
250 static const char *names[ALGOR_NUM]={
251   "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
252   "des cbc","des ede3","idea cbc","seed cbc",
253   "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
254   "aes-128 cbc","aes-192 cbc","aes-256 cbc",
255   "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc",
256   "evp","sha256","sha512","whirlpool",
257   "aes-128 ige","aes-192 ige","aes-256 ige","ghash",
258   "aes-128 gcm", "aes-256 gcm", "chacha20 poly1305",
259 };
260 static double results[ALGOR_NUM][SIZE_NUM];
261 static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
262 #ifndef OPENSSL_NO_RSA
263 static double rsa_results[RSA_NUM][2];
264 #endif
265 #ifndef OPENSSL_NO_DSA
266 static double dsa_results[DSA_NUM][2];
267 #endif
268 #ifndef OPENSSL_NO_ECDSA
269 static double ecdsa_results[EC_NUM][2];
270 #endif
271 #ifndef OPENSSL_NO_ECDH
272 static double ecdh_results[EC_NUM][1];
273 #endif
274
275 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
276 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
277 static int rnd_fake = 0;
278 #endif
279
280 #ifdef SIGALRM
281 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
282 #define SIGRETTYPE void
283 #else
284 #define SIGRETTYPE int
285 #endif 
286
287 static SIGRETTYPE sig_done(int sig);
288 static SIGRETTYPE sig_done(int sig)
289         {
290         signal(SIGALRM,sig_done);
291         run=0;
292 #ifdef LINT
293         sig=sig;
294 #endif
295         }
296 #endif
297
298 #define START   0
299 #define STOP    1
300
301 #if defined(_WIN32)
302
303 #if !defined(SIGALRM)
304 # define SIGALRM
305 #endif
306 static unsigned int lapse,schlock;
307 static void alarm_win32(unsigned int secs) { lapse = secs*1000; }
308 #define alarm alarm_win32
309
310 static DWORD WINAPI sleepy(VOID *arg)
311         {
312         schlock = 1;
313         Sleep(lapse);
314         run = 0;
315         return 0;
316         }
317
318 static double Time_F(int s)
319         {
320         if (s == START)
321                 {
322                 HANDLE  thr;
323                 schlock = 0;
324                 thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL);
325                 if (thr==NULL)
326                         {
327                         DWORD ret=GetLastError();
328                         BIO_printf(bio_err,"unable to CreateThread (%d)",ret);
329                         ExitProcess(ret);
330                         }
331                 CloseHandle(thr);               /* detach the thread    */
332                 while (!schlock) Sleep(0);      /* scheduler spinlock   */
333                 }
334
335         return app_tminterval(s,usertime);
336         }
337 #else
338
339 static double Time_F(int s)
340         {
341         return app_tminterval(s,usertime);
342         }
343 #endif
344
345
346 #ifndef OPENSSL_NO_ECDH
347 static const int KDF1_SHA1_len = 20;
348 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
349         {
350 #ifndef OPENSSL_NO_SHA
351         if (*outlen < SHA_DIGEST_LENGTH)
352                 return NULL;
353         else
354                 *outlen = SHA_DIGEST_LENGTH;
355         return SHA1(in, inlen, out);
356 #else
357         return NULL;
358 #endif  /* OPENSSL_NO_SHA */
359         }
360 #endif  /* OPENSSL_NO_ECDH */
361
362
363 int MAIN(int, char **);
364
365 int MAIN(int argc, char **argv)
366         {
367         unsigned char *buf=NULL,*buf2=NULL;
368         int mret=1;
369         long count=0,save_count=0;
370         int i,j,k;
371 #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
372         long rsa_count;
373 #endif
374 #ifndef OPENSSL_NO_RSA
375         unsigned rsa_num;
376 #endif
377         unsigned char md[EVP_MAX_MD_SIZE];
378 #ifndef OPENSSL_NO_MD2
379         unsigned char md2[MD2_DIGEST_LENGTH];
380 #endif
381 #ifndef OPENSSL_NO_MDC2
382         unsigned char mdc2[MDC2_DIGEST_LENGTH];
383 #endif
384 #ifndef OPENSSL_NO_MD4
385         unsigned char md4[MD4_DIGEST_LENGTH];
386 #endif
387 #ifndef OPENSSL_NO_MD5
388         unsigned char md5[MD5_DIGEST_LENGTH];
389         unsigned char hmac[MD5_DIGEST_LENGTH];
390 #endif
391 #ifndef OPENSSL_NO_SHA
392         unsigned char sha[SHA_DIGEST_LENGTH];
393 #ifndef OPENSSL_NO_SHA256
394         unsigned char sha256[SHA256_DIGEST_LENGTH];
395 #endif
396 #ifndef OPENSSL_NO_SHA512
397         unsigned char sha512[SHA512_DIGEST_LENGTH];
398 #endif
399 #endif
400 #ifndef OPENSSL_NO_WHIRLPOOL
401         unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
402 #endif
403 #ifndef OPENSSL_NO_RIPEMD
404         unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
405 #endif
406 #ifndef OPENSSL_NO_RC4
407         RC4_KEY rc4_ks;
408 #endif
409 #ifndef OPENSSL_NO_RC5
410         RC5_32_KEY rc5_ks;
411 #endif
412 #ifndef OPENSSL_NO_RC2
413         RC2_KEY rc2_ks;
414 #endif
415 #ifndef OPENSSL_NO_IDEA
416         IDEA_KEY_SCHEDULE idea_ks;
417 #endif
418 #ifndef OPENSSL_NO_SEED
419         SEED_KEY_SCHEDULE seed_ks;
420 #endif
421 #ifndef OPENSSL_NO_BF
422         BF_KEY bf_ks;
423 #endif
424 #ifndef OPENSSL_NO_CAST
425         CAST_KEY cast_ks;
426 #endif
427         static const unsigned char key16[16]=
428                 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
429                  0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
430 #ifndef OPENSSL_NO_AES
431         static const unsigned char key24[24]=
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         static const unsigned char key32[32]=
436                 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
437                  0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
438                  0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
439                  0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
440 #endif
441 #ifndef OPENSSL_NO_CAMELLIA
442         static const unsigned char ckey24[24]=
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         static const unsigned char ckey32[32]=
447                 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
448                  0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
449                  0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
450                  0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
451 #endif
452 #ifndef OPENSSL_NO_AES
453 #define MAX_BLOCK_SIZE 128
454 #else
455 #define MAX_BLOCK_SIZE 64
456 #endif
457         unsigned char DES_iv[8];
458         unsigned char iv[2*MAX_BLOCK_SIZE/8];
459 #ifndef OPENSSL_NO_DES
460         static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
461         static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
462         static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
463         DES_key_schedule sch;
464         DES_key_schedule sch2;
465         DES_key_schedule sch3;
466 #endif
467 #ifndef OPENSSL_NO_AES
468         AES_KEY aes_ks1, aes_ks2, aes_ks3;
469 #endif
470 #ifndef OPENSSL_NO_CAMELLIA
471         CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
472 #endif
473 #define D_MD2           0
474 #define D_MDC2          1
475 #define D_MD4           2
476 #define D_MD5           3
477 #define D_HMAC          4
478 #define D_SHA1          5
479 #define D_RMD160        6
480 #define D_RC4           7
481 #define D_CBC_DES       8
482 #define D_EDE3_DES      9
483 #define D_CBC_IDEA      10
484 #define D_CBC_SEED      11
485 #define D_CBC_RC2       12
486 #define D_CBC_RC5       13
487 #define D_CBC_BF        14
488 #define D_CBC_CAST      15
489 #define D_CBC_128_AES   16
490 #define D_CBC_192_AES   17
491 #define D_CBC_256_AES   18
492 #define D_CBC_128_CML   19 
493 #define D_CBC_192_CML   20
494 #define D_CBC_256_CML   21 
495 #define D_EVP           22
496 #define D_SHA256        23      
497 #define D_SHA512        24
498 #define D_WHIRLPOOL     25
499 #define D_IGE_128_AES   26
500 #define D_IGE_192_AES   27
501 #define D_IGE_256_AES   28
502 #define D_GHASH         29
503 #define D_AES_128_GCM   30
504 #define D_AES_256_GCM   31
505 #define D_CHACHA20_POLY1305     32
506         double d=0.0;
507         long c[ALGOR_NUM][SIZE_NUM];
508 #define R_DSA_512       0
509 #define R_DSA_1024      1
510 #define R_DSA_2048      2
511 #define R_RSA_512       0
512 #define R_RSA_1024      1
513 #define R_RSA_2048      2
514 #define R_RSA_4096      3
515
516 #define R_EC_P160    0
517 #define R_EC_P192    1  
518 #define R_EC_P224    2
519 #define R_EC_P256    3
520 #define R_EC_P384    4
521 #define R_EC_P521    5
522 #define R_EC_K163    6
523 #define R_EC_K233    7
524 #define R_EC_K283    8
525 #define R_EC_K409    9
526 #define R_EC_K571    10
527 #define R_EC_B163    11
528 #define R_EC_B233    12
529 #define R_EC_B283    13
530 #define R_EC_B409    14
531 #define R_EC_B571    15
532
533 #ifndef OPENSSL_NO_RSA
534         RSA *rsa_key[RSA_NUM];
535         long rsa_c[RSA_NUM][2];
536         static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
537         static unsigned char *rsa_data[RSA_NUM]=
538                 {test512,test1024,test2048,test4096};
539         static int rsa_data_length[RSA_NUM]={
540                 sizeof(test512),sizeof(test1024),
541                 sizeof(test2048),sizeof(test4096)};
542 #endif
543 #ifndef OPENSSL_NO_DSA
544         DSA *dsa_key[DSA_NUM];
545         long dsa_c[DSA_NUM][2];
546         static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
547 #endif
548 #ifndef OPENSSL_NO_EC
549         /* We only test over the following curves as they are representative, 
550          * To add tests over more curves, simply add the curve NID
551          * and curve name to the following arrays and increase the 
552          * EC_NUM value accordingly. 
553          */
554         static unsigned int test_curves[EC_NUM] = 
555         {       
556         /* Prime Curves */
557         NID_secp160r1,
558         NID_X9_62_prime192v1,
559         NID_secp224r1,
560         NID_X9_62_prime256v1,
561         NID_secp384r1,
562         NID_secp521r1,
563         /* Binary Curves */
564         NID_sect163k1,
565         NID_sect233k1,
566         NID_sect283k1,
567         NID_sect409k1,
568         NID_sect571k1,
569         NID_sect163r2,
570         NID_sect233r1,
571         NID_sect283r1,
572         NID_sect409r1,
573         NID_sect571r1
574         }; 
575         static const char * test_curves_names[EC_NUM] = 
576         {
577         /* Prime Curves */
578         "secp160r1",
579         "nistp192",
580         "nistp224",
581         "nistp256",
582         "nistp384",
583         "nistp521",
584         /* Binary Curves */
585         "nistk163",
586         "nistk233",
587         "nistk283",
588         "nistk409",
589         "nistk571",
590         "nistb163",
591         "nistb233",
592         "nistb283",
593         "nistb409",
594         "nistb571"
595         };
596         static int test_curves_bits[EC_NUM] =
597         {
598         160, 192, 224, 256, 384, 521,
599         163, 233, 283, 409, 571,
600         163, 233, 283, 409, 571
601         };
602
603 #endif
604
605 #ifndef OPENSSL_NO_ECDSA
606         unsigned char ecdsasig[256];
607         unsigned int ecdsasiglen;
608         EC_KEY *ecdsa[EC_NUM];
609         long ecdsa_c[EC_NUM][2];
610 #endif
611
612 #ifndef OPENSSL_NO_ECDH
613         EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
614         unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
615         int secret_size_a, secret_size_b;
616         int ecdh_checks = 0;
617         int secret_idx = 0;
618         long ecdh_c[EC_NUM][2];
619 #endif
620
621         int rsa_doit[RSA_NUM];
622         int dsa_doit[DSA_NUM];
623 #ifndef OPENSSL_NO_ECDSA
624         int ecdsa_doit[EC_NUM];
625 #endif
626 #ifndef OPENSSL_NO_ECDH
627         int ecdh_doit[EC_NUM];
628 #endif
629         int doit[ALGOR_NUM];
630         int pr_header=0;
631         const EVP_CIPHER *evp_cipher=NULL;
632         const EVP_MD *evp_md=NULL;
633         int decrypt=0;
634 #ifndef NO_FORK
635         int multi=0;
636 #endif
637
638 #ifndef TIMES
639         usertime=-1;
640 #endif
641
642         apps_startup();
643         memset(results, 0, sizeof(results));
644 #ifndef OPENSSL_NO_DSA
645         memset(dsa_key,0,sizeof(dsa_key));
646 #endif
647 #ifndef OPENSSL_NO_ECDSA
648         for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
649 #endif
650 #ifndef OPENSSL_NO_ECDH
651         for (i=0; i<EC_NUM; i++)
652                 {
653                 ecdh_a[i] = NULL;
654                 ecdh_b[i] = NULL;
655                 }
656 #endif
657
658
659         if (bio_err == NULL)
660                 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
661                         BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
662
663         if (!load_config(bio_err, NULL))
664                 goto end;
665
666 #ifndef OPENSSL_NO_RSA
667         memset(rsa_key,0,sizeof(rsa_key));
668         for (i=0; i<RSA_NUM; i++)
669                 rsa_key[i]=NULL;
670 #endif
671
672         if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
673                 {
674                 BIO_printf(bio_err,"out of memory\n");
675                 goto end;
676                 }
677         if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
678                 {
679                 BIO_printf(bio_err,"out of memory\n");
680                 goto end;
681                 }
682
683         memset(c,0,sizeof(c));
684         memset(DES_iv,0,sizeof(DES_iv));
685         memset(iv,0,sizeof(iv));
686
687         for (i=0; i<ALGOR_NUM; i++)
688                 doit[i]=0;
689         for (i=0; i<RSA_NUM; i++)
690                 rsa_doit[i]=0;
691         for (i=0; i<DSA_NUM; i++)
692                 dsa_doit[i]=0;
693 #ifndef OPENSSL_NO_ECDSA
694         for (i=0; i<EC_NUM; i++)
695                 ecdsa_doit[i]=0;
696 #endif
697 #ifndef OPENSSL_NO_ECDH
698         for (i=0; i<EC_NUM; i++)
699                 ecdh_doit[i]=0;
700 #endif
701
702         
703         j=0;
704         argc--;
705         argv++;
706         while (argc)
707                 {
708                 if      ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
709                         {
710                         usertime = 0;
711                         j--;    /* Otherwise, -elapsed gets confused with
712                                    an algorithm. */
713                         }
714                 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
715                         {
716                         argc--;
717                         argv++;
718                         if(argc == 0)
719                                 {
720                                 BIO_printf(bio_err,"no EVP given\n");
721                                 goto end;
722                                 }
723                         evp_cipher=EVP_get_cipherbyname(*argv);
724                         if(!evp_cipher)
725                                 {
726                                 evp_md=EVP_get_digestbyname(*argv);
727                                 }
728                         if(!evp_cipher && !evp_md)
729                                 {
730                                 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
731                                 goto end;
732                                 }
733                         doit[D_EVP]=1;
734                         }
735                 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
736                         {
737                         decrypt=1;
738                         j--;    /* Otherwise, -elapsed gets confused with
739                                    an algorithm. */
740                         }
741 #ifndef OPENSSL_NO_ENGINE
742                 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
743                         {
744                         argc--;
745                         argv++;
746                         if(argc == 0)
747                                 {
748                                 BIO_printf(bio_err,"no engine given\n");
749                                 goto end;
750                                 }
751                         setup_engine(bio_err, *argv, 0);
752                         /* j will be increased again further down.  We just
753                            don't want speed to confuse an engine with an
754                            algorithm, especially when none is given (which
755                            means all of them should be run) */
756                         j--;
757                         }
758 #endif
759 #ifndef NO_FORK
760                 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
761                         {
762                         argc--;
763                         argv++;
764                         if(argc == 0)
765                                 {
766                                 BIO_printf(bio_err,"no multi count given\n");
767                                 goto end;
768                                 }
769                         multi=atoi(argv[0]);
770                         if(multi <= 0)
771                             {
772                                 BIO_printf(bio_err,"bad multi count\n");
773                                 goto end;
774                                 }                               
775                         j--;    /* Otherwise, -mr gets confused with
776                                    an algorithm. */
777                         }
778 #endif
779                 else if (argc > 0 && !strcmp(*argv,"-mr"))
780                         {
781                         mr=1;
782                         j--;    /* Otherwise, -mr gets confused with
783                                    an algorithm. */
784                         }
785                 else
786 #ifndef OPENSSL_NO_MD2
787                 if      (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
788                 else
789 #endif
790 #ifndef OPENSSL_NO_MDC2
791                         if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
792                 else
793 #endif
794 #ifndef OPENSSL_NO_MD4
795                         if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
796                 else
797 #endif
798 #ifndef OPENSSL_NO_MD5
799                         if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
800                 else
801 #endif
802 #ifndef OPENSSL_NO_MD5
803                         if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
804                 else
805 #endif
806 #ifndef OPENSSL_NO_SHA
807                         if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
808                 else
809                         if (strcmp(*argv,"sha") == 0)   doit[D_SHA1]=1,
810                                                         doit[D_SHA256]=1,
811                                                         doit[D_SHA512]=1;
812                 else
813 #ifndef OPENSSL_NO_SHA256
814                         if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
815                 else
816 #endif
817 #ifndef OPENSSL_NO_SHA512
818                         if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
819                 else
820 #endif
821 #endif
822 #ifndef OPENSSL_NO_WHIRLPOOL
823                         if (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;
824                 else
825 #endif
826 #ifndef OPENSSL_NO_RIPEMD
827                         if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
828                 else
829                         if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
830                 else
831                         if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
832                 else
833 #endif
834 #ifndef OPENSSL_NO_RC4
835                         if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
836                 else 
837 #endif
838 #ifndef OPENSSL_NO_DES
839                         if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
840                 else    if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
841                 else
842 #endif
843 #ifndef OPENSSL_NO_AES
844                         if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
845                 else    if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
846                 else    if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
847                 else    if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;
848                 else    if (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;
849                 else    if (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;
850                 else
851 #endif
852 #ifndef OPENSSL_NO_CAMELLIA
853                         if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
854                 else    if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
855                 else    if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
856                 else
857 #endif
858 #ifndef OPENSSL_NO_RSA
859 #if 0 /* was: #ifdef RSAref */
860                         if (strcmp(*argv,"rsaref") == 0) 
861                         {
862                         RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
863                         j--;
864                         }
865                 else
866 #endif
867 #ifndef RSA_NULL
868                         if (strcmp(*argv,"openssl") == 0) 
869                         {
870                         RSA_set_default_method(RSA_PKCS1_SSLeay());
871                         j--;
872                         }
873                 else
874 #endif
875 #endif /* !OPENSSL_NO_RSA */
876                      if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
877                 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
878                 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
879                 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
880                 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
881                 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
882                 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
883                 else
884 #ifndef OPENSSL_NO_RC2
885                      if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
886                 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
887                 else
888 #endif
889 #ifndef OPENSSL_NO_RC5
890                      if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
891                 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
892                 else
893 #endif
894 #ifndef OPENSSL_NO_IDEA
895                      if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
896                 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
897                 else
898 #endif
899 #ifndef OPENSSL_NO_SEED
900                      if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;
901                 else if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;
902                 else
903 #endif
904 #ifndef OPENSSL_NO_BF
905                      if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
906                 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
907                 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
908                 else
909 #endif
910 #ifndef OPENSSL_NO_CAST
911                      if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
912                 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
913                 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
914                 else
915 #endif
916 #ifndef OPENSSL_NO_DES
917                         if (strcmp(*argv,"des") == 0)
918                         {
919                         doit[D_CBC_DES]=1;
920                         doit[D_EDE3_DES]=1;
921                         }
922                 else
923 #endif
924 #ifndef OPENSSL_NO_AES
925                         if (strcmp(*argv,"aes") == 0)
926                         {
927                         doit[D_CBC_128_AES]=1;
928                         doit[D_CBC_192_AES]=1;
929                         doit[D_CBC_256_AES]=1;
930                         }
931                 else if (strcmp(*argv,"ghash") == 0)
932                         {
933                         doit[D_GHASH]=1;
934                         }
935                 else if (strcmp(*argv,"aes-128-gcm") == 0)
936                         {
937                         doit[D_AES_128_GCM]=1;
938                         }
939                 else if (strcmp(*argv,"aes-256-gcm") == 0)
940                         {
941                         doit[D_AES_256_GCM]=1;
942                         }
943                 else
944 #endif
945 #ifndef OPENSSL_NO_CAMELLIA
946                         if (strcmp(*argv,"camellia") == 0)
947                         {
948                         doit[D_CBC_128_CML]=1;
949                         doit[D_CBC_192_CML]=1;
950                         doit[D_CBC_256_CML]=1;
951                         }
952                 else
953 #endif
954 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
955                         if (strcmp(*argv,"chacha20-poly1305") == 0)
956                         {
957                         doit[D_CHACHA20_POLY1305]=1;
958                         }
959                 else
960 #endif
961 #ifndef OPENSSL_NO_RSA
962                         if (strcmp(*argv,"rsa") == 0)
963                         {
964                         rsa_doit[R_RSA_512]=1;
965                         rsa_doit[R_RSA_1024]=1;
966                         rsa_doit[R_RSA_2048]=1;
967                         rsa_doit[R_RSA_4096]=1;
968                         }
969                 else
970 #endif
971 #ifndef OPENSSL_NO_DSA
972                         if (strcmp(*argv,"dsa") == 0)
973                         {
974                         dsa_doit[R_DSA_512]=1;
975                         dsa_doit[R_DSA_1024]=1;
976                         dsa_doit[R_DSA_2048]=1;
977                         }
978                 else
979 #endif
980 #ifndef OPENSSL_NO_ECDSA
981                      if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
982                 else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
983                 else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
984                 else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
985                 else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
986                 else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
987                 else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
988                 else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
989                 else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
990                 else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
991                 else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
992                 else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
993                 else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
994                 else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
995                 else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
996                 else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
997                 else if (strcmp(*argv,"ecdsa") == 0)
998                         {
999                         for (i=0; i < EC_NUM; i++)
1000                                 ecdsa_doit[i]=1;
1001                         }
1002                 else
1003 #endif
1004 #ifndef OPENSSL_NO_ECDH
1005                      if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1006                 else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1007                 else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1008                 else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1009                 else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1010                 else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1011                 else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1012                 else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1013                 else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1014                 else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1015                 else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1016                 else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1017                 else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1018                 else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1019                 else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1020                 else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1021                 else if (strcmp(*argv,"ecdh") == 0)
1022                         {
1023                         for (i=0; i < EC_NUM; i++)
1024                                 ecdh_doit[i]=1;
1025                         }
1026                 else
1027 #endif
1028                         {
1029                         BIO_printf(bio_err,"Error: bad option or value\n");
1030                         BIO_printf(bio_err,"\n");
1031                         BIO_printf(bio_err,"Available values:\n");
1032 #ifndef OPENSSL_NO_MD2
1033                         BIO_printf(bio_err,"md2      ");
1034 #endif
1035 #ifndef OPENSSL_NO_MDC2
1036                         BIO_printf(bio_err,"mdc2     ");
1037 #endif
1038 #ifndef OPENSSL_NO_MD4
1039                         BIO_printf(bio_err,"md4      ");
1040 #endif
1041 #ifndef OPENSSL_NO_MD5
1042                         BIO_printf(bio_err,"md5      ");
1043 #ifndef OPENSSL_NO_HMAC
1044                         BIO_printf(bio_err,"hmac     ");
1045 #endif
1046 #endif
1047 #ifndef OPENSSL_NO_SHA1
1048                         BIO_printf(bio_err,"sha1     ");
1049 #endif
1050 #ifndef OPENSSL_NO_SHA256
1051                         BIO_printf(bio_err,"sha256   ");
1052 #endif
1053 #ifndef OPENSSL_NO_SHA512
1054                         BIO_printf(bio_err,"sha512   ");
1055 #endif
1056 #ifndef OPENSSL_NO_WHIRLPOOL
1057                         BIO_printf(bio_err,"whirlpool");
1058 #endif
1059 #ifndef OPENSSL_NO_RIPEMD160
1060                         BIO_printf(bio_err,"rmd160");
1061 #endif
1062 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
1063     !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
1064     !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \
1065     !defined(OPENSSL_NO_WHIRLPOOL)
1066                         BIO_printf(bio_err,"\n");
1067 #endif
1068
1069 #ifndef OPENSSL_NO_IDEA
1070                         BIO_printf(bio_err,"idea-cbc ");
1071 #endif
1072 #ifndef OPENSSL_NO_SEED
1073                         BIO_printf(bio_err,"seed-cbc ");
1074 #endif
1075 #ifndef OPENSSL_NO_RC2
1076                         BIO_printf(bio_err,"rc2-cbc  ");
1077 #endif
1078 #ifndef OPENSSL_NO_RC5
1079                         BIO_printf(bio_err,"rc5-cbc  ");
1080 #endif
1081 #ifndef OPENSSL_NO_BF
1082                         BIO_printf(bio_err,"bf-cbc");
1083 #endif
1084 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
1085     !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
1086                         BIO_printf(bio_err,"\n");
1087 #endif
1088 #ifndef OPENSSL_NO_DES
1089                         BIO_printf(bio_err,"des-cbc  des-ede3 ");
1090 #endif
1091 #ifndef OPENSSL_NO_AES
1092                         BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
1093                         BIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige\n");
1094                         BIO_printf(bio_err,"aes-128-gcm aes-256-gcm ");
1095 #endif
1096 #ifndef OPENSSL_NO_CAMELLIA
1097                         BIO_printf(bio_err,"\n");
1098                         BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
1099 #endif
1100 #ifndef OPENSSL_NO_RC4
1101                         BIO_printf(bio_err,"rc4");
1102 #endif
1103 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1104                         BIO_printf(bio_err," chacha20-poly1305");
1105 #endif
1106                         BIO_printf(bio_err,"\n");
1107
1108 #ifndef OPENSSL_NO_RSA
1109                         BIO_printf(bio_err,"rsa512   rsa1024  rsa2048  rsa4096\n");
1110 #endif
1111
1112 #ifndef OPENSSL_NO_DSA
1113                         BIO_printf(bio_err,"dsa512   dsa1024  dsa2048\n");
1114 #endif
1115 #ifndef OPENSSL_NO_ECDSA
1116                         BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1117                         BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1118                         BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1119                         BIO_printf(bio_err,"ecdsa\n");
1120 #endif
1121 #ifndef OPENSSL_NO_ECDH
1122                         BIO_printf(bio_err,"ecdhp160  ecdhp192  ecdhp224  ecdhp256  ecdhp384  ecdhp521\n");
1123                         BIO_printf(bio_err,"ecdhk163  ecdhk233  ecdhk283  ecdhk409  ecdhk571\n");
1124                         BIO_printf(bio_err,"ecdhb163  ecdhb233  ecdhb283  ecdhb409  ecdhb571\n");
1125                         BIO_printf(bio_err,"ecdh\n");
1126 #endif
1127
1128 #ifndef OPENSSL_NO_IDEA
1129                         BIO_printf(bio_err,"idea     ");
1130 #endif
1131 #ifndef OPENSSL_NO_SEED
1132                         BIO_printf(bio_err,"seed     ");
1133 #endif
1134 #ifndef OPENSSL_NO_RC2
1135                         BIO_printf(bio_err,"rc2      ");
1136 #endif
1137 #ifndef OPENSSL_NO_DES
1138                         BIO_printf(bio_err,"des      ");
1139 #endif
1140 #ifndef OPENSSL_NO_AES
1141                         BIO_printf(bio_err,"aes      ");
1142 #endif
1143 #ifndef OPENSSL_NO_CAMELLIA
1144                         BIO_printf(bio_err,"camellia ");
1145 #endif
1146 #ifndef OPENSSL_NO_RSA
1147                         BIO_printf(bio_err,"rsa      ");
1148 #endif
1149 #ifndef OPENSSL_NO_BF
1150                         BIO_printf(bio_err,"blowfish");
1151 #endif
1152 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
1153     !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
1154     !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
1155     !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
1156                         BIO_printf(bio_err,"\n");
1157 #endif
1158
1159                         BIO_printf(bio_err,"\n");
1160                         BIO_printf(bio_err,"Available options:\n");
1161 #if defined(TIMES) || defined(USE_TOD)
1162                         BIO_printf(bio_err,"-elapsed        measure time in real time instead of CPU user time.\n");
1163 #endif
1164 #ifndef OPENSSL_NO_ENGINE
1165                         BIO_printf(bio_err,"-engine e       use engine e, possibly a hardware device.\n");
1166 #endif
1167                         BIO_printf(bio_err,"-evp e          use EVP e.\n");
1168                         BIO_printf(bio_err,"-decrypt        time decryption instead of encryption (only EVP).\n");
1169                         BIO_printf(bio_err,"-mr             produce machine readable output.\n");
1170 #ifndef NO_FORK
1171                         BIO_printf(bio_err,"-multi n        run n benchmarks in parallel.\n");
1172 #endif
1173                         goto end;
1174                         }
1175                 argc--;
1176                 argv++;
1177                 j++;
1178                 }
1179
1180 #ifndef NO_FORK
1181         if(multi && do_multi(multi))
1182                 goto show_res;
1183 #endif
1184
1185         if (j == 0)
1186                 {
1187                 for (i=0; i<ALGOR_NUM; i++)
1188                         {
1189                         if (i != D_EVP)
1190                                 doit[i]=1;
1191                         }
1192                 for (i=0; i<RSA_NUM; i++)
1193                         rsa_doit[i]=1;
1194                 for (i=0; i<DSA_NUM; i++)
1195                         dsa_doit[i]=1;
1196 #ifndef OPENSSL_NO_ECDSA
1197                 for (i=0; i<EC_NUM; i++)
1198                         ecdsa_doit[i]=1;
1199 #endif
1200 #ifndef OPENSSL_NO_ECDH
1201                 for (i=0; i<EC_NUM; i++)
1202                         ecdh_doit[i]=1;
1203 #endif
1204                 }
1205         for (i=0; i<ALGOR_NUM; i++)
1206                 if (doit[i]) pr_header++;
1207
1208         if (usertime == 0 && !mr)
1209                 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
1210
1211 #ifndef OPENSSL_NO_RSA
1212         for (i=0; i<RSA_NUM; i++)
1213                 {
1214                 const unsigned char *p;
1215
1216                 p=rsa_data[i];
1217                 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
1218                 if (rsa_key[i] == NULL)
1219                         {
1220                         BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
1221                         goto end;
1222                         }
1223 #if 0
1224                 else
1225                         {
1226                         BIO_printf(bio_err,mr ? "+RK:%d:"
1227                                    : "Loaded RSA key, %d bit modulus and e= 0x",
1228                                    BN_num_bits(rsa_key[i]->n));
1229                         BN_print(bio_err,rsa_key[i]->e);
1230                         BIO_printf(bio_err,"\n");
1231                         }
1232 #endif
1233                 }
1234 #endif
1235
1236 #ifndef OPENSSL_NO_DSA
1237         dsa_key[0]=get_dsa512();
1238         dsa_key[1]=get_dsa1024();
1239         dsa_key[2]=get_dsa2048();
1240 #endif
1241
1242 #ifndef OPENSSL_NO_DES
1243         DES_set_key_unchecked(&key,&sch);
1244         DES_set_key_unchecked(&key2,&sch2);
1245         DES_set_key_unchecked(&key3,&sch3);
1246 #endif
1247 #ifndef OPENSSL_NO_AES
1248         AES_set_encrypt_key(key16,128,&aes_ks1);
1249         AES_set_encrypt_key(key24,192,&aes_ks2);
1250         AES_set_encrypt_key(key32,256,&aes_ks3);
1251 #endif
1252 #ifndef OPENSSL_NO_CAMELLIA
1253         Camellia_set_key(key16,128,&camellia_ks1);
1254         Camellia_set_key(ckey24,192,&camellia_ks2);
1255         Camellia_set_key(ckey32,256,&camellia_ks3);
1256 #endif
1257 #ifndef OPENSSL_NO_IDEA
1258         idea_set_encrypt_key(key16,&idea_ks);
1259 #endif
1260 #ifndef OPENSSL_NO_SEED
1261         SEED_set_key(key16,&seed_ks);
1262 #endif
1263 #ifndef OPENSSL_NO_RC4
1264         RC4_set_key(&rc4_ks,16,key16);
1265 #endif
1266 #ifndef OPENSSL_NO_RC2
1267         RC2_set_key(&rc2_ks,16,key16,128);
1268 #endif
1269 #ifndef OPENSSL_NO_RC5
1270         RC5_32_set_key(&rc5_ks,16,key16,12);
1271 #endif
1272 #ifndef OPENSSL_NO_BF
1273         BF_set_key(&bf_ks,16,key16);
1274 #endif
1275 #ifndef OPENSSL_NO_CAST
1276         CAST_set_key(&cast_ks,16,key16);
1277 #endif
1278 #ifndef OPENSSL_NO_RSA
1279         memset(rsa_c,0,sizeof(rsa_c));
1280 #endif
1281 #ifndef SIGALRM
1282 #ifndef OPENSSL_NO_DES
1283         BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
1284         count=10;
1285         do      {
1286                 long it;
1287                 count*=2;
1288                 Time_F(START);
1289                 for (it=count; it; it--)
1290                         DES_ecb_encrypt((DES_cblock *)buf,
1291                                 (DES_cblock *)buf,
1292                                 &sch,DES_ENCRYPT);
1293                 d=Time_F(STOP);
1294                 } while (d <3);
1295         save_count=count;
1296         c[D_MD2][0]=count/10;
1297         c[D_MDC2][0]=count/10;
1298         c[D_MD4][0]=count;
1299         c[D_MD5][0]=count;
1300         c[D_HMAC][0]=count;
1301         c[D_SHA1][0]=count;
1302         c[D_RMD160][0]=count;
1303         c[D_RC4][0]=count*5;
1304         c[D_CBC_DES][0]=count;
1305         c[D_EDE3_DES][0]=count/3;
1306         c[D_CBC_IDEA][0]=count;
1307         c[D_CBC_SEED][0]=count;
1308         c[D_CBC_RC2][0]=count;
1309         c[D_CBC_RC5][0]=count;
1310         c[D_CBC_BF][0]=count;
1311         c[D_CBC_CAST][0]=count;
1312         c[D_CBC_128_AES][0]=count;
1313         c[D_CBC_192_AES][0]=count;
1314         c[D_CBC_256_AES][0]=count;
1315         c[D_CBC_128_CML][0]=count;
1316         c[D_CBC_192_CML][0]=count;
1317         c[D_CBC_256_CML][0]=count;
1318         c[D_SHA256][0]=count;
1319         c[D_SHA512][0]=count;
1320         c[D_WHIRLPOOL][0]=count;
1321         c[D_IGE_128_AES][0]=count;
1322         c[D_IGE_192_AES][0]=count;
1323         c[D_IGE_256_AES][0]=count;
1324         c[D_GHASH][0]=count;
1325         c[D_AES_128_GCM][0]=count;
1326         c[D_CHACHA20_POLY1305][0]=count;
1327
1328         for (i=1; i<SIZE_NUM; i++)
1329                 {
1330                 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
1331                 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
1332                 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
1333                 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
1334                 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
1335                 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
1336                 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1337                 c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1338                 c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
1339                 c[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];
1340                 }
1341         for (i=1; i<SIZE_NUM; i++)
1342                 {
1343                 long l0,l1;
1344
1345                 l0=(long)lengths[i-1];
1346                 l1=(long)lengths[i];
1347                 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
1348                 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
1349                 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
1350                 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
1351                 c[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;
1352                 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
1353                 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
1354                 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
1355                 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
1356                 c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
1357                 c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
1358                 c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
1359                 c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
1360                 c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
1361                 c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
1362                 c[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;
1363                 c[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;
1364                 c[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;
1365                 }
1366 #ifndef OPENSSL_NO_RSA
1367         rsa_c[R_RSA_512][0]=count/2000;
1368         rsa_c[R_RSA_512][1]=count/400;
1369         for (i=1; i<RSA_NUM; i++)
1370                 {
1371                 rsa_c[i][0]=rsa_c[i-1][0]/8;
1372                 rsa_c[i][1]=rsa_c[i-1][1]/4;
1373                 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
1374                         rsa_doit[i]=0;
1375                 else
1376                         {
1377                         if (rsa_c[i][0] == 0)
1378                                 {
1379                                 rsa_c[i][0]=1;
1380                                 rsa_c[i][1]=20;
1381                                 }
1382                         }                               
1383                 }
1384 #endif
1385
1386 #ifndef OPENSSL_NO_DSA
1387         dsa_c[R_DSA_512][0]=count/1000;
1388         dsa_c[R_DSA_512][1]=count/1000/2;
1389         for (i=1; i<DSA_NUM; i++)
1390                 {
1391                 dsa_c[i][0]=dsa_c[i-1][0]/4;
1392                 dsa_c[i][1]=dsa_c[i-1][1]/4;
1393                 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
1394                         dsa_doit[i]=0;
1395                 else
1396                         {
1397                         if (dsa_c[i] == 0)
1398                                 {
1399                                 dsa_c[i][0]=1;
1400                                 dsa_c[i][1]=1;
1401                                 }
1402                         }                               
1403                 }
1404 #endif
1405
1406 #ifndef OPENSSL_NO_ECDSA
1407         ecdsa_c[R_EC_P160][0]=count/1000;
1408         ecdsa_c[R_EC_P160][1]=count/1000/2;
1409         for (i=R_EC_P192; i<=R_EC_P521; i++)
1410                 {
1411                 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1412                 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1413                 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1414                         ecdsa_doit[i]=0;
1415                 else
1416                         {
1417                         if (ecdsa_c[i] == 0)
1418                                 {
1419                                 ecdsa_c[i][0]=1;
1420                                 ecdsa_c[i][1]=1;
1421                                 }
1422                         }
1423                 }
1424         ecdsa_c[R_EC_K163][0]=count/1000;
1425         ecdsa_c[R_EC_K163][1]=count/1000/2;
1426         for (i=R_EC_K233; i<=R_EC_K571; i++)
1427                 {
1428                 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1429                 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1430                 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1431                         ecdsa_doit[i]=0;
1432                 else
1433                         {
1434                         if (ecdsa_c[i] == 0)
1435                                 {
1436                                 ecdsa_c[i][0]=1;
1437                                 ecdsa_c[i][1]=1;
1438                                 }
1439                         }
1440                 }
1441         ecdsa_c[R_EC_B163][0]=count/1000;
1442         ecdsa_c[R_EC_B163][1]=count/1000/2;
1443         for (i=R_EC_B233; i<=R_EC_B571; i++)
1444                 {
1445                 ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1446                 ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1447                 if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1448                         ecdsa_doit[i]=0;
1449                 else
1450                         {
1451                         if (ecdsa_c[i] == 0)
1452                                 {
1453                                 ecdsa_c[i][0]=1;
1454                                 ecdsa_c[i][1]=1;
1455                                 }
1456                         }
1457                 }
1458 #endif
1459
1460 #ifndef OPENSSL_NO_ECDH
1461         ecdh_c[R_EC_P160][0]=count/1000;
1462         ecdh_c[R_EC_P160][1]=count/1000;
1463         for (i=R_EC_P192; i<=R_EC_P521; i++)
1464                 {
1465                 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1466                 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1467                 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1468                         ecdh_doit[i]=0;
1469                 else
1470                         {
1471                         if (ecdh_c[i] == 0)
1472                                 {
1473                                 ecdh_c[i][0]=1;
1474                                 ecdh_c[i][1]=1;
1475                                 }
1476                         }
1477                 }
1478         ecdh_c[R_EC_K163][0]=count/1000;
1479         ecdh_c[R_EC_K163][1]=count/1000;
1480         for (i=R_EC_K233; i<=R_EC_K571; i++)
1481                 {
1482                 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1483                 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1484                 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1485                         ecdh_doit[i]=0;
1486                 else
1487                         {
1488                         if (ecdh_c[i] == 0)
1489                                 {
1490                                 ecdh_c[i][0]=1;
1491                                 ecdh_c[i][1]=1;
1492                                 }
1493                         }
1494                 }
1495         ecdh_c[R_EC_B163][0]=count/1000;
1496         ecdh_c[R_EC_B163][1]=count/1000;
1497         for (i=R_EC_B233; i<=R_EC_B571; i++)
1498                 {
1499                 ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1500                 ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1501                 if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1502                         ecdh_doit[i]=0;
1503                 else
1504                         {
1505                         if (ecdh_c[i] == 0)
1506                                 {
1507                                 ecdh_c[i][0]=1;
1508                                 ecdh_c[i][1]=1;
1509                                 }
1510                         }
1511                 }
1512 #endif
1513
1514 #define COND(d) (count < (d))
1515 #define COUNT(d) (d)
1516 #else
1517 /* not worth fixing */
1518 # error "You cannot disable DES on systems without SIGALRM."
1519 #endif /* OPENSSL_NO_DES */
1520 #else
1521 #define COND(c) (run && count<0x7fffffff)
1522 #define COUNT(d) (count)
1523 #ifndef _WIN32
1524         signal(SIGALRM,sig_done);
1525 #endif
1526 #endif /* SIGALRM */
1527
1528 #ifndef OPENSSL_NO_MD2
1529         if (doit[D_MD2])
1530                 {
1531                 for (j=0; j<SIZE_NUM; j++)
1532                         {
1533                         print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1534                         Time_F(START);
1535                         for (count=0,run=1; COND(c[D_MD2][j]); count++)
1536                                 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1537                         d=Time_F(STOP);
1538                         print_result(D_MD2,j,count,d);
1539                         }
1540                 }
1541 #endif
1542 #ifndef OPENSSL_NO_MDC2
1543         if (doit[D_MDC2])
1544                 {
1545                 for (j=0; j<SIZE_NUM; j++)
1546                         {
1547                         print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1548                         Time_F(START);
1549                         for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1550                                 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1551                         d=Time_F(STOP);
1552                         print_result(D_MDC2,j,count,d);
1553                         }
1554                 }
1555 #endif
1556
1557 #ifndef OPENSSL_NO_MD4
1558         if (doit[D_MD4])
1559                 {
1560                 for (j=0; j<SIZE_NUM; j++)
1561                         {
1562                         print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1563                         Time_F(START);
1564                         for (count=0,run=1; COND(c[D_MD4][j]); count++)
1565                                 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1566                         d=Time_F(STOP);
1567                         print_result(D_MD4,j,count,d);
1568                         }
1569                 }
1570 #endif
1571
1572 #ifndef OPENSSL_NO_MD5
1573         if (doit[D_MD5])
1574                 {
1575                 for (j=0; j<SIZE_NUM; j++)
1576                         {
1577                         print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1578                         Time_F(START);
1579                         for (count=0,run=1; COND(c[D_MD5][j]); count++)
1580                                 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1581                         d=Time_F(STOP);
1582                         print_result(D_MD5,j,count,d);
1583                         }
1584                 }
1585 #endif
1586
1587 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1588         if (doit[D_HMAC])
1589                 {
1590                 HMAC_CTX hctx;
1591
1592                 HMAC_CTX_init(&hctx);
1593                 HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
1594                         16,EVP_md5(), NULL);
1595
1596                 for (j=0; j<SIZE_NUM; j++)
1597                         {
1598                         print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1599                         Time_F(START);
1600                         for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1601                                 {
1602                                 HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
1603                                 HMAC_Update(&hctx,buf,lengths[j]);
1604                                 HMAC_Final(&hctx,&(hmac[0]),NULL);
1605                                 }
1606                         d=Time_F(STOP);
1607                         print_result(D_HMAC,j,count,d);
1608                         }
1609                 HMAC_CTX_cleanup(&hctx);
1610                 }
1611 #endif
1612 #ifndef OPENSSL_NO_SHA
1613         if (doit[D_SHA1])
1614                 {
1615                 for (j=0; j<SIZE_NUM; j++)
1616                         {
1617                         print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1618                         Time_F(START);
1619                         for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1620                                 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1621                         d=Time_F(STOP);
1622                         print_result(D_SHA1,j,count,d);
1623                         }
1624                 }
1625
1626 #ifndef OPENSSL_NO_SHA256
1627         if (doit[D_SHA256])
1628                 {
1629                 for (j=0; j<SIZE_NUM; j++)
1630                         {
1631                         print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1632                         Time_F(START);
1633                         for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1634                                 SHA256(buf,lengths[j],sha256);
1635                         d=Time_F(STOP);
1636                         print_result(D_SHA256,j,count,d);
1637                         }
1638                 }
1639 #endif
1640
1641 #ifndef OPENSSL_NO_SHA512
1642         if (doit[D_SHA512])
1643                 {
1644                 for (j=0; j<SIZE_NUM; j++)
1645                         {
1646                         print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1647                         Time_F(START);
1648                         for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1649                                 SHA512(buf,lengths[j],sha512);
1650                         d=Time_F(STOP);
1651                         print_result(D_SHA512,j,count,d);
1652                         }
1653                 }
1654 #endif
1655 #endif
1656
1657 #ifndef OPENSSL_NO_WHIRLPOOL
1658         if (doit[D_WHIRLPOOL])
1659                 {
1660                 for (j=0; j<SIZE_NUM; j++)
1661                         {
1662                         print_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);
1663                         Time_F(START);
1664                         for (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)
1665                                 WHIRLPOOL(buf,lengths[j],whirlpool);
1666                         d=Time_F(STOP);
1667                         print_result(D_WHIRLPOOL,j,count,d);
1668                         }
1669                 }
1670 #endif
1671
1672 #ifndef OPENSSL_NO_RIPEMD
1673         if (doit[D_RMD160])
1674                 {
1675                 for (j=0; j<SIZE_NUM; j++)
1676                         {
1677                         print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1678                         Time_F(START);
1679                         for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1680                                 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1681                         d=Time_F(STOP);
1682                         print_result(D_RMD160,j,count,d);
1683                         }
1684                 }
1685 #endif
1686 #ifndef OPENSSL_NO_RC4
1687         if (doit[D_RC4])
1688                 {
1689                 for (j=0; j<SIZE_NUM; j++)
1690                         {
1691                         print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1692                         Time_F(START);
1693                         for (count=0,run=1; COND(c[D_RC4][j]); count++)
1694                                 RC4(&rc4_ks,(unsigned int)lengths[j],
1695                                         buf,buf);
1696                         d=Time_F(STOP);
1697                         print_result(D_RC4,j,count,d);
1698                         }
1699                 }
1700 #endif
1701 #ifndef OPENSSL_NO_DES
1702         if (doit[D_CBC_DES])
1703                 {
1704                 for (j=0; j<SIZE_NUM; j++)
1705                         {
1706                         print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1707                         Time_F(START);
1708                         for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1709                                 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1710                                                  &DES_iv,DES_ENCRYPT);
1711                         d=Time_F(STOP);
1712                         print_result(D_CBC_DES,j,count,d);
1713                         }
1714                 }
1715
1716         if (doit[D_EDE3_DES])
1717                 {
1718                 for (j=0; j<SIZE_NUM; j++)
1719                         {
1720                         print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1721                         Time_F(START);
1722                         for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1723                                 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1724                                                      &sch,&sch2,&sch3,
1725                                                      &DES_iv,DES_ENCRYPT);
1726                         d=Time_F(STOP);
1727                         print_result(D_EDE3_DES,j,count,d);
1728                         }
1729                 }
1730 #endif
1731 #ifndef OPENSSL_NO_AES
1732         if (doit[D_CBC_128_AES])
1733                 {
1734                 for (j=0; j<SIZE_NUM; j++)
1735                         {
1736                         print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
1737                         Time_F(START);
1738                         for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
1739                                 AES_cbc_encrypt(buf,buf,
1740                                         (unsigned long)lengths[j],&aes_ks1,
1741                                         iv,AES_ENCRYPT);
1742                         d=Time_F(STOP);
1743                         print_result(D_CBC_128_AES,j,count,d);
1744                         }
1745                 }
1746         if (doit[D_CBC_192_AES])
1747                 {
1748                 for (j=0; j<SIZE_NUM; j++)
1749                         {
1750                         print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
1751                         Time_F(START);
1752                         for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
1753                                 AES_cbc_encrypt(buf,buf,
1754                                         (unsigned long)lengths[j],&aes_ks2,
1755                                         iv,AES_ENCRYPT);
1756                         d=Time_F(STOP);
1757                         print_result(D_CBC_192_AES,j,count,d);
1758                         }
1759                 }
1760         if (doit[D_CBC_256_AES])
1761                 {
1762                 for (j=0; j<SIZE_NUM; j++)
1763                         {
1764                         print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
1765                         Time_F(START);
1766                         for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
1767                                 AES_cbc_encrypt(buf,buf,
1768                                         (unsigned long)lengths[j],&aes_ks3,
1769                                         iv,AES_ENCRYPT);
1770                         d=Time_F(STOP);
1771                         print_result(D_CBC_256_AES,j,count,d);
1772                         }
1773                 }
1774
1775         if (doit[D_IGE_128_AES])
1776                 {
1777                 for (j=0; j<SIZE_NUM; j++)
1778                         {
1779                         print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
1780                         Time_F(START);
1781                         for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
1782                                 AES_ige_encrypt(buf,buf2,
1783                                         (unsigned long)lengths[j],&aes_ks1,
1784                                         iv,AES_ENCRYPT);
1785                         d=Time_F(STOP);
1786                         print_result(D_IGE_128_AES,j,count,d);
1787                         }
1788                 }
1789         if (doit[D_IGE_192_AES])
1790                 {
1791                 for (j=0; j<SIZE_NUM; j++)
1792                         {
1793                         print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
1794                         Time_F(START);
1795                         for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
1796                                 AES_ige_encrypt(buf,buf2,
1797                                         (unsigned long)lengths[j],&aes_ks2,
1798                                         iv,AES_ENCRYPT);
1799                         d=Time_F(STOP);
1800                         print_result(D_IGE_192_AES,j,count,d);
1801                         }
1802                 }
1803         if (doit[D_IGE_256_AES])
1804                 {
1805                 for (j=0; j<SIZE_NUM; j++)
1806                         {
1807                         print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
1808                         Time_F(START);
1809                         for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
1810                                 AES_ige_encrypt(buf,buf2,
1811                                         (unsigned long)lengths[j],&aes_ks3,
1812                                         iv,AES_ENCRYPT);
1813                         d=Time_F(STOP);
1814                         print_result(D_IGE_256_AES,j,count,d);
1815                         }
1816                 }
1817         if (doit[D_GHASH])
1818                 {
1819                 GCM128_CONTEXT *ctx = CRYPTO_gcm128_new(&aes_ks1,(block128_f)AES_encrypt);
1820                 CRYPTO_gcm128_setiv (ctx,(unsigned char *)"0123456789ab",12);
1821
1822                 for (j=0; j<SIZE_NUM; j++)
1823                         {
1824                         print_message(names[D_GHASH],c[D_GHASH][j],lengths[j]);
1825                         Time_F(START);
1826                         for (count=0,run=1; COND(c[D_GHASH][j]); count++)
1827                                 CRYPTO_gcm128_aad(ctx,buf,lengths[j]);
1828                         d=Time_F(STOP);
1829                         print_result(D_GHASH,j,count,d);
1830                         }
1831                 CRYPTO_gcm128_release(ctx);
1832                 }
1833
1834         if (doit[D_AES_128_GCM])
1835                 {
1836                 const EVP_AEAD *aead = EVP_aead_aes_128_gcm();
1837                 static const unsigned char nonce[32] = {0};
1838                 size_t nonce_len;
1839                 EVP_AEAD_CTX ctx;
1840
1841                 EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1842                 nonce_len = EVP_AEAD_nonce_length(aead);
1843
1844                 for (j=0; j<SIZE_NUM; j++)
1845                         {
1846                         print_message(names[D_AES_128_GCM],c[D_AES_128_GCM][j],lengths[j]);
1847                         Time_F(START);
1848                         for (count=0,run=1; COND(c[D_AES_128_GCM][j]); count++)
1849                                 EVP_AEAD_CTX_seal(&ctx,buf, BUFSIZE, nonce, nonce_len, buf, lengths[j], NULL, 0);
1850                         d=Time_F(STOP);
1851                         print_result(D_AES_128_GCM,j,count,d);
1852                         }
1853                 EVP_AEAD_CTX_cleanup(&ctx);
1854                 }
1855
1856         if (doit[D_AES_256_GCM])
1857                 {
1858                 const EVP_AEAD *aead = EVP_aead_aes_256_gcm();
1859                 static const unsigned char nonce[32] = {0};
1860                 size_t nonce_len;
1861                 EVP_AEAD_CTX ctx;
1862
1863                 EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1864                 nonce_len = EVP_AEAD_nonce_length(aead);
1865
1866                 for (j=0; j<SIZE_NUM; j++)
1867                         {
1868                         print_message(names[D_AES_256_GCM],c[D_AES_256_GCM][j],lengths[j]);
1869                         Time_F(START);
1870                         for (count=0,run=1; COND(c[D_AES_256_GCM][j]); count++)
1871                                 EVP_AEAD_CTX_seal(&ctx,buf, BUFSIZE, nonce, nonce_len, buf, lengths[j], NULL, 0);
1872                         d=Time_F(STOP);
1873                         print_result(D_AES_256_GCM,j,count,d);
1874                         }
1875                 EVP_AEAD_CTX_cleanup(&ctx);
1876                 }
1877 #endif
1878
1879 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1880         if (doit[D_CHACHA20_POLY1305])
1881                 {
1882                 const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
1883                 static const unsigned char nonce[32] = {0};
1884                 size_t nonce_len;
1885                 EVP_AEAD_CTX ctx;
1886
1887                 EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead), EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1888                 nonce_len = EVP_AEAD_nonce_length(aead);
1889
1890                 for (j=0; j<SIZE_NUM; j++)
1891                         {
1892                         print_message(names[D_CHACHA20_POLY1305],c[D_CHACHA20_POLY1305][j],lengths[j]);
1893                         Time_F(START);
1894                         for (count=0,run=1; COND(c[D_CHACHA20_POLY1305][j]); count++)
1895                                 EVP_AEAD_CTX_seal(&ctx,buf, BUFSIZE, nonce, nonce_len, buf, lengths[j], NULL, 0);
1896                         d=Time_F(STOP);
1897                         print_result(D_CHACHA20_POLY1305,j,count,d);
1898                         }
1899                 EVP_AEAD_CTX_cleanup(&ctx);
1900                 }
1901 #endif
1902
1903 #ifndef OPENSSL_NO_CAMELLIA
1904         if (doit[D_CBC_128_CML])
1905                 {
1906                 for (j=0; j<SIZE_NUM; j++)
1907                         {
1908                         print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1909                         Time_F(START);
1910                         for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1911                                 Camellia_cbc_encrypt(buf,buf,
1912                                         (unsigned long)lengths[j],&camellia_ks1,
1913                                         iv,CAMELLIA_ENCRYPT);
1914                         d=Time_F(STOP);
1915                         print_result(D_CBC_128_CML,j,count,d);
1916                         }
1917                 }
1918         if (doit[D_CBC_192_CML])
1919                 {
1920                 for (j=0; j<SIZE_NUM; j++)
1921                         {
1922                         print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1923                         Time_F(START);
1924                         for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1925                                 Camellia_cbc_encrypt(buf,buf,
1926                                         (unsigned long)lengths[j],&camellia_ks2,
1927                                         iv,CAMELLIA_ENCRYPT);
1928                         d=Time_F(STOP);
1929                         print_result(D_CBC_192_CML,j,count,d);
1930                         }
1931                 }
1932         if (doit[D_CBC_256_CML])
1933                 {
1934                 for (j=0; j<SIZE_NUM; j++)
1935                         {
1936                         print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1937                         Time_F(START);
1938                         for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1939                                 Camellia_cbc_encrypt(buf,buf,
1940                                         (unsigned long)lengths[j],&camellia_ks3,
1941                                         iv,CAMELLIA_ENCRYPT);
1942                         d=Time_F(STOP);
1943                         print_result(D_CBC_256_CML,j,count,d);
1944                         }
1945                 }
1946
1947 #endif
1948 #ifndef OPENSSL_NO_IDEA
1949         if (doit[D_CBC_IDEA])
1950                 {
1951                 for (j=0; j<SIZE_NUM; j++)
1952                         {
1953                         print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1954                         Time_F(START);
1955                         for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1956                                 idea_cbc_encrypt(buf,buf,
1957                                         (unsigned long)lengths[j],&idea_ks,
1958                                         iv,IDEA_ENCRYPT);
1959                         d=Time_F(STOP);
1960                         print_result(D_CBC_IDEA,j,count,d);
1961                         }
1962                 }
1963 #endif
1964 #ifndef OPENSSL_NO_SEED
1965         if (doit[D_CBC_SEED])
1966                 {
1967                 for (j=0; j<SIZE_NUM; j++)
1968                         {
1969                         print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1970                         Time_F(START);
1971                         for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1972                                 SEED_cbc_encrypt(buf,buf,
1973                                         (unsigned long)lengths[j],&seed_ks,iv,1);
1974                         d=Time_F(STOP);
1975                         print_result(D_CBC_SEED,j,count,d);
1976                         }
1977                 }
1978 #endif
1979 #ifndef OPENSSL_NO_RC2
1980         if (doit[D_CBC_RC2])
1981                 {
1982                 for (j=0; j<SIZE_NUM; j++)
1983                         {
1984                         print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1985                         Time_F(START);
1986                         for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1987                                 RC2_cbc_encrypt(buf,buf,
1988                                         (unsigned long)lengths[j],&rc2_ks,
1989                                         iv,RC2_ENCRYPT);
1990                         d=Time_F(STOP);
1991                         print_result(D_CBC_RC2,j,count,d);
1992                         }
1993                 }
1994 #endif
1995 #ifndef OPENSSL_NO_RC5
1996         if (doit[D_CBC_RC5])
1997                 {
1998                 for (j=0; j<SIZE_NUM; j++)
1999                         {
2000                         print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
2001                         Time_F(START);
2002                         for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
2003                                 RC5_32_cbc_encrypt(buf,buf,
2004                                         (unsigned long)lengths[j],&rc5_ks,
2005                                         iv,RC5_ENCRYPT);
2006                         d=Time_F(STOP);
2007                         print_result(D_CBC_RC5,j,count,d);
2008                         }
2009                 }
2010 #endif
2011 #ifndef OPENSSL_NO_BF
2012         if (doit[D_CBC_BF])
2013                 {
2014                 for (j=0; j<SIZE_NUM; j++)
2015                         {
2016                         print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
2017                         Time_F(START);
2018                         for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
2019                                 BF_cbc_encrypt(buf,buf,
2020                                         (unsigned long)lengths[j],&bf_ks,
2021                                         iv,BF_ENCRYPT);
2022                         d=Time_F(STOP);
2023                         print_result(D_CBC_BF,j,count,d);
2024                         }
2025                 }
2026 #endif
2027 #ifndef OPENSSL_NO_CAST
2028         if (doit[D_CBC_CAST])
2029                 {
2030                 for (j=0; j<SIZE_NUM; j++)
2031                         {
2032                         print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
2033                         Time_F(START);
2034                         for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
2035                                 CAST_cbc_encrypt(buf,buf,
2036                                         (unsigned long)lengths[j],&cast_ks,
2037                                         iv,CAST_ENCRYPT);
2038                         d=Time_F(STOP);
2039                         print_result(D_CBC_CAST,j,count,d);
2040                         }
2041                 }
2042 #endif
2043
2044         if (doit[D_EVP])
2045                 {
2046                 for (j=0; j<SIZE_NUM; j++)
2047                         {
2048                         if (evp_cipher)
2049                                 {
2050                                 EVP_CIPHER_CTX ctx;
2051                                 int outl;
2052
2053                                 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2054                                 /* -O3 -fschedule-insns messes up an
2055                                  * optimization here!  names[D_EVP]
2056                                  * somehow becomes NULL */
2057                                 print_message(names[D_EVP],save_count,
2058                                         lengths[j]);
2059
2060                                 EVP_CIPHER_CTX_init(&ctx);
2061                                 if(decrypt)
2062                                         EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2063                                 else
2064                                         EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2065                                 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2066
2067                                 Time_F(START);
2068                                 if(decrypt)
2069                                         for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2070                                                 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2071                                 else
2072                                         for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2073                                                 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2074                                 if(decrypt)
2075                                         EVP_DecryptFinal_ex(&ctx,buf,&outl);
2076                                 else
2077                                         EVP_EncryptFinal_ex(&ctx,buf,&outl);
2078                                 d=Time_F(STOP);
2079                                 EVP_CIPHER_CTX_cleanup(&ctx);
2080                                 }
2081                         if (evp_md)
2082                                 {
2083                                 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2084                                 print_message(names[D_EVP],save_count,
2085                                         lengths[j]);
2086
2087                                 Time_F(START);
2088                                 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2089                                         EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2090
2091                                 d=Time_F(STOP);
2092                                 }
2093                         print_result(D_EVP,j,count,d);
2094                         }
2095                 }
2096
2097         RAND_pseudo_bytes(buf,36);
2098 #ifndef OPENSSL_NO_RSA
2099         for (j=0; j<RSA_NUM; j++)
2100                 {
2101                 int ret;
2102                 if (!rsa_doit[j]) continue;
2103                 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2104                 if (ret == 0)
2105                         {
2106                         BIO_printf(bio_err,"RSA sign failure.  No RSA sign will be done.\n");
2107                         ERR_print_errors(bio_err);
2108                         rsa_count=1;
2109                         }
2110                 else
2111                         {
2112                         pkey_print_message("private","rsa",
2113                                 rsa_c[j][0],rsa_bits[j],
2114                                 RSA_SECONDS);
2115 /*                      RSA_blinding_on(rsa_key[j],NULL); */
2116                         Time_F(START);
2117                         for (count=0,run=1; COND(rsa_c[j][0]); count++)
2118                                 {
2119                                 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2120                                         &rsa_num, rsa_key[j]);
2121                                 if (ret == 0)
2122                                         {
2123                                         BIO_printf(bio_err,
2124                                                 "RSA sign failure\n");
2125                                         ERR_print_errors(bio_err);
2126                                         count=1;
2127                                         break;
2128                                         }
2129                                 }
2130                         d=Time_F(STOP);
2131                         BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2132                                    : "%ld %d bit private RSA's in %.2fs\n",
2133                                    count,rsa_bits[j],d);
2134                         rsa_results[j][0]=d/(double)count;
2135                         rsa_count=count;
2136                         }
2137
2138 #if 1
2139                 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2140                 if (ret <= 0)
2141                         {
2142                         BIO_printf(bio_err,"RSA verify failure.  No RSA verify will be done.\n");
2143                         ERR_print_errors(bio_err);
2144                         rsa_doit[j] = 0;
2145                         }
2146                 else
2147                         {
2148                         pkey_print_message("public","rsa",
2149                                 rsa_c[j][1],rsa_bits[j],
2150                                 RSA_SECONDS);
2151                         Time_F(START);
2152                         for (count=0,run=1; COND(rsa_c[j][1]); count++)
2153                                 {
2154                                 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2155                                         rsa_num, rsa_key[j]);
2156                                 if (ret <= 0)
2157                                         {
2158                                         BIO_printf(bio_err,
2159                                                 "RSA verify failure\n");
2160                                         ERR_print_errors(bio_err);
2161                                         count=1;
2162                                         break;
2163                                         }
2164                                 }
2165                         d=Time_F(STOP);
2166                         BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2167                                    : "%ld %d bit public RSA's in %.2fs\n",
2168                                    count,rsa_bits[j],d);
2169                         rsa_results[j][1]=d/(double)count;
2170                         }
2171 #endif
2172
2173                 if (rsa_count <= 1)
2174                         {
2175                         /* if longer than 10s, don't do any more */
2176                         for (j++; j<RSA_NUM; j++)
2177                                 rsa_doit[j]=0;
2178                         }
2179                 }
2180 #endif
2181
2182         RAND_pseudo_bytes(buf,20);
2183 #ifndef OPENSSL_NO_DSA
2184         if (RAND_status() != 1)
2185                 {
2186                 RAND_seed(rnd_seed, sizeof rnd_seed);
2187                 rnd_fake = 1;
2188                 }
2189         for (j=0; j<DSA_NUM; j++)
2190                 {
2191                 unsigned int kk;
2192                 int ret;
2193
2194                 if (!dsa_doit[j]) continue;
2195 /*              DSA_generate_key(dsa_key[j]); */
2196 /*              DSA_sign_setup(dsa_key[j],NULL); */
2197                 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2198                         &kk,dsa_key[j]);
2199                 if (ret == 0)
2200                         {
2201                         BIO_printf(bio_err,"DSA sign failure.  No DSA sign will be done.\n");
2202                         ERR_print_errors(bio_err);
2203                         rsa_count=1;
2204                         }
2205                 else
2206                         {
2207                         pkey_print_message("sign","dsa",
2208                                 dsa_c[j][0],dsa_bits[j],
2209                                 DSA_SECONDS);
2210                         Time_F(START);
2211                         for (count=0,run=1; COND(dsa_c[j][0]); count++)
2212                                 {
2213                                 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2214                                         &kk,dsa_key[j]);
2215                                 if (ret == 0)
2216                                         {
2217                                         BIO_printf(bio_err,
2218                                                 "DSA sign failure\n");
2219                                         ERR_print_errors(bio_err);
2220                                         count=1;
2221                                         break;
2222                                         }
2223                                 }
2224                         d=Time_F(STOP);
2225                         BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2226                                    : "%ld %d bit DSA signs in %.2fs\n",
2227                                    count,dsa_bits[j],d);
2228                         dsa_results[j][0]=d/(double)count;
2229                         rsa_count=count;
2230                         }
2231
2232                 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2233                         kk,dsa_key[j]);
2234                 if (ret <= 0)
2235                         {
2236                         BIO_printf(bio_err,"DSA verify failure.  No DSA verify will be done.\n");
2237                         ERR_print_errors(bio_err);
2238                         dsa_doit[j] = 0;
2239                         }
2240                 else
2241                         {
2242                         pkey_print_message("verify","dsa",
2243                                 dsa_c[j][1],dsa_bits[j],
2244                                 DSA_SECONDS);
2245                         Time_F(START);
2246                         for (count=0,run=1; COND(dsa_c[j][1]); count++)
2247                                 {
2248                                 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2249                                         kk,dsa_key[j]);
2250                                 if (ret <= 0)
2251                                         {
2252                                         BIO_printf(bio_err,
2253                                                 "DSA verify failure\n");
2254                                         ERR_print_errors(bio_err);
2255                                         count=1;
2256                                         break;
2257                                         }
2258                                 }
2259                         d=Time_F(STOP);
2260                         BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2261                                    : "%ld %d bit DSA verify in %.2fs\n",
2262                                    count,dsa_bits[j],d);
2263                         dsa_results[j][1]=d/(double)count;
2264                         }
2265
2266                 if (rsa_count <= 1)
2267                         {
2268                         /* if longer than 10s, don't do any more */
2269                         for (j++; j<DSA_NUM; j++)
2270                                 dsa_doit[j]=0;
2271                         }
2272                 }
2273         if (rnd_fake) RAND_cleanup();
2274 #endif
2275
2276 #ifndef OPENSSL_NO_ECDSA
2277         if (RAND_status() != 1) 
2278                 {
2279                 RAND_seed(rnd_seed, sizeof rnd_seed);
2280                 rnd_fake = 1;
2281                 }
2282         for (j=0; j<EC_NUM; j++) 
2283                 {
2284                 int ret;
2285
2286                 if (!ecdsa_doit[j]) continue; /* Ignore Curve */ 
2287                 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2288                 if (ecdsa[j] == NULL) 
2289                         {
2290                         BIO_printf(bio_err,"ECDSA failure.\n");
2291                         ERR_print_errors(bio_err);
2292                         rsa_count=1;
2293                         } 
2294                 else 
2295                         {
2296 #if 1
2297                         EC_KEY_precompute_mult(ecdsa[j], NULL);
2298 #endif
2299                         /* Perform ECDSA signature test */
2300                         EC_KEY_generate_key(ecdsa[j]);
2301                         ret = ECDSA_sign(0, buf, 20, ecdsasig, 
2302                                 &ecdsasiglen, ecdsa[j]);
2303                         if (ret == 0) 
2304                                 {
2305                                 BIO_printf(bio_err,"ECDSA sign failure.  No ECDSA sign will be done.\n");
2306                                 ERR_print_errors(bio_err);
2307                                 rsa_count=1;
2308                                 } 
2309                         else 
2310                                 {
2311                                 pkey_print_message("sign","ecdsa",
2312                                         ecdsa_c[j][0], 
2313                                         test_curves_bits[j],
2314                                         ECDSA_SECONDS);
2315
2316                                 Time_F(START);
2317                                 for (count=0,run=1; COND(ecdsa_c[j][0]);
2318                                         count++) 
2319                                         {
2320                                         ret=ECDSA_sign(0, buf, 20, 
2321                                                 ecdsasig, &ecdsasiglen,
2322                                                 ecdsa[j]);
2323                                         if (ret == 0) 
2324                                                 {
2325                                                 BIO_printf(bio_err, "ECDSA sign failure\n");
2326                                                 ERR_print_errors(bio_err);
2327                                                 count=1;
2328                                                 break;
2329                                                 }
2330                                         }
2331                                 d=Time_F(STOP);
2332
2333                                 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2334                                         "%ld %d bit ECDSA signs in %.2fs \n", 
2335                                         count, test_curves_bits[j], d);
2336                                 ecdsa_results[j][0]=d/(double)count;
2337                                 rsa_count=count;
2338                                 }
2339
2340                         /* Perform ECDSA verification test */
2341                         ret=ECDSA_verify(0, buf, 20, ecdsasig, 
2342                                 ecdsasiglen, ecdsa[j]);
2343                         if (ret != 1) 
2344                                 {
2345                                 BIO_printf(bio_err,"ECDSA verify failure.  No ECDSA verify will be done.\n");
2346                                 ERR_print_errors(bio_err);
2347                                 ecdsa_doit[j] = 0;
2348                                 } 
2349                         else 
2350                                 {
2351                                 pkey_print_message("verify","ecdsa",
2352                                 ecdsa_c[j][1],
2353                                 test_curves_bits[j],
2354                                 ECDSA_SECONDS);
2355                                 Time_F(START);
2356                                 for (count=0,run=1; COND(ecdsa_c[j][1]); count++) 
2357                                         {
2358                                         ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2359                                         if (ret != 1) 
2360                                                 {
2361                                                 BIO_printf(bio_err, "ECDSA verify failure\n");
2362                                                 ERR_print_errors(bio_err);
2363                                                 count=1;
2364                                                 break;
2365                                                 }
2366                                         }
2367                                 d=Time_F(STOP);
2368                                 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2369                                                 : "%ld %d bit ECDSA verify in %.2fs\n",
2370                                 count, test_curves_bits[j], d);
2371                                 ecdsa_results[j][1]=d/(double)count;
2372                                 }
2373
2374                         if (rsa_count <= 1) 
2375                                 {
2376                                 /* if longer than 10s, don't do any more */
2377                                 for (j++; j<EC_NUM; j++)
2378                                 ecdsa_doit[j]=0;
2379                                 }
2380                         }
2381                 }
2382         if (rnd_fake) RAND_cleanup();
2383 #endif
2384
2385 #ifndef OPENSSL_NO_ECDH
2386         if (RAND_status() != 1)
2387                 {
2388                 RAND_seed(rnd_seed, sizeof rnd_seed);
2389                 rnd_fake = 1;
2390                 }
2391         for (j=0; j<EC_NUM; j++)
2392                 {
2393                 if (!ecdh_doit[j]) continue;
2394                 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2395                 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2396                 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2397                         {
2398                         BIO_printf(bio_err,"ECDH failure.\n");
2399                         ERR_print_errors(bio_err);
2400                         rsa_count=1;
2401                         }
2402                 else
2403                         {
2404                         /* generate two ECDH key pairs */
2405                         if (!EC_KEY_generate_key(ecdh_a[j]) ||
2406                                 !EC_KEY_generate_key(ecdh_b[j]))
2407                                 {
2408                                 BIO_printf(bio_err,"ECDH key generation failure.\n");
2409                                 ERR_print_errors(bio_err);
2410                                 rsa_count=1;            
2411                                 }
2412                         else
2413                                 {
2414                                 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2415                                  * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2416                                  */
2417                                 int field_size, outlen;
2418                                 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2419                                 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2420                                 if (field_size <= 24 * 8)
2421                                         {
2422                                         outlen = KDF1_SHA1_len;
2423                                         kdf = KDF1_SHA1;
2424                                         }
2425                                 else
2426                                         {
2427                                         outlen = (field_size+7)/8;
2428                                         kdf = NULL;
2429                                         }
2430                                 secret_size_a = ECDH_compute_key(secret_a, outlen,
2431                                         EC_KEY_get0_public_key(ecdh_b[j]),
2432                                         ecdh_a[j], kdf);
2433                                 secret_size_b = ECDH_compute_key(secret_b, outlen,
2434                                         EC_KEY_get0_public_key(ecdh_a[j]),
2435                                         ecdh_b[j], kdf);
2436                                 if (secret_size_a != secret_size_b) 
2437                                         ecdh_checks = 0;
2438                                 else
2439                                         ecdh_checks = 1;
2440
2441                                 for (secret_idx = 0; 
2442                                     (secret_idx < secret_size_a)
2443                                         && (ecdh_checks == 1);
2444                                     secret_idx++)
2445                                         {
2446                                         if (secret_a[secret_idx] != secret_b[secret_idx])
2447                                         ecdh_checks = 0;
2448                                         }
2449
2450                                 if (ecdh_checks == 0)
2451                                         {
2452                                         BIO_printf(bio_err,"ECDH computations don't match.\n");
2453                                         ERR_print_errors(bio_err);
2454                                         rsa_count=1;            
2455                                         }
2456
2457                                 pkey_print_message("","ecdh",
2458                                 ecdh_c[j][0], 
2459                                 test_curves_bits[j],
2460                                 ECDH_SECONDS);
2461                                 Time_F(START);
2462                                 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2463                                         {
2464                                         ECDH_compute_key(secret_a, outlen,
2465                                         EC_KEY_get0_public_key(ecdh_b[j]),
2466                                         ecdh_a[j], kdf);
2467                                         }
2468                                 d=Time_F(STOP);
2469                                 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2470                                 count, test_curves_bits[j], d);
2471                                 ecdh_results[j][0]=d/(double)count;
2472                                 rsa_count=count;
2473                                 }
2474                         }
2475
2476
2477                 if (rsa_count <= 1)
2478                         {
2479                         /* if longer than 10s, don't do any more */
2480                         for (j++; j<EC_NUM; j++)
2481                         ecdh_doit[j]=0;
2482                         }
2483                 }
2484         if (rnd_fake) RAND_cleanup();
2485 #endif
2486 #ifndef NO_FORK
2487 show_res:
2488 #endif
2489         if(!mr)
2490                 {
2491                 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2492         fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2493                 printf("options:");
2494                 printf("%s ",BN_options());
2495 #ifndef OPENSSL_NO_MD2
2496                 printf("%s ",MD2_options());
2497 #endif
2498 #ifndef OPENSSL_NO_RC4
2499                 printf("%s ",RC4_options());
2500 #endif
2501 #ifndef OPENSSL_NO_DES
2502                 printf("%s ",DES_options());
2503 #endif
2504 #ifndef OPENSSL_NO_AES
2505                 printf("%s ",AES_options());
2506 #endif
2507 #ifndef OPENSSL_NO_IDEA
2508                 printf("%s ",idea_options());
2509 #endif
2510 #ifndef OPENSSL_NO_BF
2511                 printf("%s ",BF_options());
2512 #endif
2513                 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2514                 }
2515
2516         if (pr_header)
2517                 {
2518                 if(mr)
2519                         fprintf(stdout,"+H");
2520                 else
2521                         {
2522                         fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); 
2523                         fprintf(stdout,"type        ");
2524                         }
2525                 for (j=0;  j<SIZE_NUM; j++)
2526                         fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2527                 fprintf(stdout,"\n");
2528                 }
2529
2530         for (k=0; k<ALGOR_NUM; k++)
2531                 {
2532                 if (!doit[k]) continue;
2533                 if(mr)
2534                         fprintf(stdout,"+F:%d:%s",k,names[k]);
2535                 else
2536                         fprintf(stdout,"%-13s",names[k]);
2537                 for (j=0; j<SIZE_NUM; j++)
2538                         {
2539                         if (results[k][j] > 10000 && !mr)
2540                                 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2541                         else
2542                                 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2543                         }
2544                 fprintf(stdout,"\n");
2545                 }
2546 #ifndef OPENSSL_NO_RSA
2547         j=1;
2548         for (k=0; k<RSA_NUM; k++)
2549                 {
2550                 if (!rsa_doit[k]) continue;
2551                 if (j && !mr)
2552                         {
2553                         printf("%18ssign    verify    sign/s verify/s\n"," ");
2554                         j=0;
2555                         }
2556                 if(mr)
2557                         fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2558                                 k,rsa_bits[k],rsa_results[k][0],
2559                                 rsa_results[k][1]);
2560                 else
2561                         fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2562                                 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2563                                 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2564                 }
2565 #endif
2566 #ifndef OPENSSL_NO_DSA
2567         j=1;
2568         for (k=0; k<DSA_NUM; k++)
2569                 {
2570                 if (!dsa_doit[k]) continue;
2571                 if (j && !mr)
2572                         {
2573                         printf("%18ssign    verify    sign/s verify/s\n"," ");
2574                         j=0;
2575                         }
2576                 if(mr)
2577                         fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2578                                 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2579                 else
2580                         fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2581                                 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2582                                 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2583                 }
2584 #endif
2585 #ifndef OPENSSL_NO_ECDSA
2586         j=1;
2587         for (k=0; k<EC_NUM; k++)
2588                 {
2589                 if (!ecdsa_doit[k]) continue;
2590                 if (j && !mr)
2591                         {
2592                         printf("%30ssign    verify    sign/s verify/s\n"," ");
2593                         j=0;
2594                         }
2595
2596                 if (mr)
2597                         fprintf(stdout,"+F4:%u:%u:%f:%f\n", 
2598                                 k, test_curves_bits[k],
2599                                 ecdsa_results[k][0],ecdsa_results[k][1]);
2600                 else
2601                         fprintf(stdout,
2602                                 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", 
2603                                 test_curves_bits[k],
2604                                 test_curves_names[k],
2605                                 ecdsa_results[k][0],ecdsa_results[k][1], 
2606                                 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2607                 }
2608 #endif
2609
2610
2611 #ifndef OPENSSL_NO_ECDH
2612         j=1;
2613         for (k=0; k<EC_NUM; k++)
2614                 {
2615                 if (!ecdh_doit[k]) continue;
2616                 if (j && !mr)
2617                         {
2618                         printf("%30sop      op/s\n"," ");
2619                         j=0;
2620                         }
2621                 if (mr)
2622                         fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2623                                 k, test_curves_bits[k],
2624                                 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2625
2626                 else
2627                         fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2628                                 test_curves_bits[k],
2629                                 test_curves_names[k],
2630                                 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2631                 }
2632 #endif
2633
2634         mret=0;
2635
2636 end:
2637         ERR_print_errors(bio_err);
2638         if (buf != NULL) OPENSSL_free(buf);
2639         if (buf2 != NULL) OPENSSL_free(buf2);
2640 #ifndef OPENSSL_NO_RSA
2641         for (i=0; i<RSA_NUM; i++)
2642                 if (rsa_key[i] != NULL)
2643                         RSA_free(rsa_key[i]);
2644 #endif
2645 #ifndef OPENSSL_NO_DSA
2646         for (i=0; i<DSA_NUM; i++)
2647                 if (dsa_key[i] != NULL)
2648                         DSA_free(dsa_key[i]);
2649 #endif
2650
2651 #ifndef OPENSSL_NO_ECDSA
2652         for (i=0; i<EC_NUM; i++)
2653                 if (ecdsa[i] != NULL)
2654                         EC_KEY_free(ecdsa[i]);
2655 #endif
2656 #ifndef OPENSSL_NO_ECDH
2657         for (i=0; i<EC_NUM; i++)
2658         {
2659                 if (ecdh_a[i] != NULL)
2660                         EC_KEY_free(ecdh_a[i]);
2661                 if (ecdh_b[i] != NULL)
2662                         EC_KEY_free(ecdh_b[i]);
2663         }
2664 #endif
2665
2666         apps_shutdown();
2667         OPENSSL_EXIT(mret);
2668         }
2669
2670 static void print_message(const char *s, long num, int length)
2671         {
2672 #ifdef SIGALRM
2673         BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2674                    : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2675         (void)BIO_flush(bio_err);
2676         alarm(SECONDS);
2677 #else
2678         BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2679                    : "Doing %s %ld times on %d size blocks: ",s,num,length);
2680         (void)BIO_flush(bio_err);
2681 #endif
2682 #ifdef LINT
2683         num=num;
2684 #endif
2685         }
2686
2687 static void pkey_print_message(const char *str, const char *str2, long num,
2688         int bits, int tm)
2689         {
2690 #ifdef SIGALRM
2691         BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2692                            : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2693         (void)BIO_flush(bio_err);
2694         alarm(tm);
2695 #else
2696         BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2697                            : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2698         (void)BIO_flush(bio_err);
2699 #endif
2700 #ifdef LINT
2701         num=num;
2702 #endif
2703         }
2704
2705 static void print_result(int alg,int run_no,int count,double time_used)
2706         {
2707         BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2708                    : "%d %s's in %.2fs\n",count,names[alg],time_used);
2709         results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2710         }
2711
2712 #ifndef NO_FORK
2713 static char *sstrsep(char **string, const char *delim)
2714     {
2715     char isdelim[256];
2716     char *token = *string;
2717
2718     if (**string == 0)
2719         return NULL;
2720
2721     memset(isdelim, 0, sizeof isdelim);
2722     isdelim[0] = 1;
2723
2724     while (*delim)
2725         {
2726         isdelim[(unsigned char)(*delim)] = 1;
2727         delim++;
2728         }
2729
2730     while (!isdelim[(unsigned char)(**string)])
2731         {
2732         (*string)++;
2733         }
2734
2735     if (**string)
2736         {
2737         **string = 0;
2738         (*string)++;
2739         }
2740
2741     return token;
2742     }
2743
2744 static int do_multi(int multi)
2745         {
2746         int n;
2747         int fd[2];
2748         int *fds;
2749         static char sep[]=":";
2750
2751         fds=malloc(multi*sizeof *fds);
2752         for(n=0 ; n < multi ; ++n)
2753                 {
2754                 if (pipe(fd) == -1)
2755                         {
2756                         fprintf(stderr, "pipe failure\n");
2757                         exit(1);
2758                         }
2759                 fflush(stdout);
2760                 fflush(stderr);
2761                 if(fork())
2762                         {
2763                         close(fd[1]);
2764                         fds[n]=fd[0];
2765                         }
2766                 else
2767                         {
2768                         close(fd[0]);
2769                         close(1);
2770                         if (dup(fd[1]) == -1)
2771                                 {
2772                                 fprintf(stderr, "dup failed\n");
2773                                 exit(1);
2774                                 }
2775                         close(fd[1]);
2776                         mr=1;
2777                         usertime=0;
2778                         free(fds);
2779                         return 0;
2780                         }
2781                 printf("Forked child %d\n",n);
2782                 }
2783
2784         /* for now, assume the pipe is long enough to take all the output */
2785         for(n=0 ; n < multi ; ++n)
2786                 {
2787                 FILE *f;
2788                 char buf[1024];
2789                 char *p;
2790
2791                 f=fdopen(fds[n],"r");
2792                 while(fgets(buf,sizeof buf,f))
2793                         {
2794                         p=strchr(buf,'\n');
2795                         if(p)
2796                                 *p='\0';
2797                         if(buf[0] != '+')
2798                                 {
2799                                 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2800                                                 buf,n);
2801                                 continue;
2802                                 }
2803                         printf("Got: %s from %d\n",buf,n);
2804                         if(!strncmp(buf,"+F:",3))
2805                                 {
2806                                 int alg;
2807                                 int j;
2808
2809                                 p=buf+3;
2810                                 alg=atoi(sstrsep(&p,sep));
2811                                 sstrsep(&p,sep);
2812                                 for(j=0 ; j < SIZE_NUM ; ++j)
2813                                         results[alg][j]+=atof(sstrsep(&p,sep));
2814                                 }
2815                         else if(!strncmp(buf,"+F2:",4))
2816                                 {
2817                                 int k;
2818                                 double d;
2819                                 
2820                                 p=buf+4;
2821                                 k=atoi(sstrsep(&p,sep));
2822                                 sstrsep(&p,sep);
2823
2824                                 d=atof(sstrsep(&p,sep));
2825                                 if(n)
2826                                         rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2827                                 else
2828                                         rsa_results[k][0]=d;
2829
2830                                 d=atof(sstrsep(&p,sep));
2831                                 if(n)
2832                                         rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2833                                 else
2834                                         rsa_results[k][1]=d;
2835                                 }
2836                         else if(!strncmp(buf,"+F2:",4))
2837                                 {
2838                                 int k;
2839                                 double d;
2840                                 
2841                                 p=buf+4;
2842                                 k=atoi(sstrsep(&p,sep));
2843                                 sstrsep(&p,sep);
2844
2845                                 d=atof(sstrsep(&p,sep));
2846                                 if(n)
2847                                         rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2848                                 else
2849                                         rsa_results[k][0]=d;
2850
2851                                 d=atof(sstrsep(&p,sep));
2852                                 if(n)
2853                                         rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2854                                 else
2855                                         rsa_results[k][1]=d;
2856                                 }
2857 #ifndef OPENSSL_NO_DSA
2858                         else if(!strncmp(buf,"+F3:",4))
2859                                 {
2860                                 int k;
2861                                 double d;
2862                                 
2863                                 p=buf+4;
2864                                 k=atoi(sstrsep(&p,sep));
2865                                 sstrsep(&p,sep);
2866
2867                                 d=atof(sstrsep(&p,sep));
2868                                 if(n)
2869                                         dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2870                                 else
2871                                         dsa_results[k][0]=d;
2872
2873                                 d=atof(sstrsep(&p,sep));
2874                                 if(n)
2875                                         dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2876                                 else
2877                                         dsa_results[k][1]=d;
2878                                 }
2879 #endif
2880 #ifndef OPENSSL_NO_ECDSA
2881                         else if(!strncmp(buf,"+F4:",4))
2882                                 {
2883                                 int k;
2884                                 double d;
2885                                 
2886                                 p=buf+4;
2887                                 k=atoi(sstrsep(&p,sep));
2888                                 sstrsep(&p,sep);
2889
2890                                 d=atof(sstrsep(&p,sep));
2891                                 if(n)
2892                                         ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2893                                 else
2894                                         ecdsa_results[k][0]=d;
2895
2896                                 d=atof(sstrsep(&p,sep));
2897                                 if(n)
2898                                         ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2899                                 else
2900                                         ecdsa_results[k][1]=d;
2901                                 }
2902 #endif 
2903
2904 #ifndef OPENSSL_NO_ECDH
2905                         else if(!strncmp(buf,"+F5:",4))
2906                                 {
2907                                 int k;
2908                                 double d;
2909                                 
2910                                 p=buf+4;
2911                                 k=atoi(sstrsep(&p,sep));
2912                                 sstrsep(&p,sep);
2913
2914                                 d=atof(sstrsep(&p,sep));
2915                                 if(n)
2916                                         ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2917                                 else
2918                                         ecdh_results[k][0]=d;
2919
2920                                 }
2921 #endif
2922
2923                         else if(!strncmp(buf,"+H:",3))
2924                                 {
2925                                 }
2926                         else
2927                                 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2928                         }
2929
2930                 fclose(f);
2931                 }
2932         free(fds);
2933         return 1;
2934         }
2935 #endif
2936 #endif