Tidy.
[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),
1842                                   EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1843                 nonce_len = EVP_AEAD_nonce_length(aead);
1844
1845                 for (j=0; j<SIZE_NUM; j++)
1846                         {
1847                         print_message(names[D_AES_128_GCM], c[D_AES_128_GCM][j],
1848                                       lengths[j]);
1849                         Time_F(START);
1850                         for (count=0,run=1; COND(c[D_AES_128_GCM][j]); count++)
1851                                 EVP_AEAD_CTX_seal(&ctx, buf, BUFSIZE, nonce,
1852                                                   nonce_len, buf, lengths[j],
1853                                                   NULL, 0);
1854                         d=Time_F(STOP);
1855                         print_result(D_AES_128_GCM,j,count,d);
1856                         }
1857                 EVP_AEAD_CTX_cleanup(&ctx);
1858                 }
1859
1860         if (doit[D_AES_256_GCM])
1861                 {
1862                 const EVP_AEAD *aead = EVP_aead_aes_256_gcm();
1863                 static const unsigned char nonce[32] = {0};
1864                 size_t nonce_len;
1865                 EVP_AEAD_CTX ctx;
1866
1867                 EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1868                                   EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1869                 nonce_len = EVP_AEAD_nonce_length(aead);
1870
1871                 for (j=0; j<SIZE_NUM; j++)
1872                         {
1873                         print_message(names[D_AES_256_GCM], c[D_AES_256_GCM][j],
1874                                       lengths[j]);
1875                         Time_F(START);
1876                         for (count=0,run=1; COND(c[D_AES_256_GCM][j]); count++)
1877                                 EVP_AEAD_CTX_seal(&ctx, buf, BUFSIZE, nonce,
1878                                                   nonce_len, buf, lengths[j],
1879                                                   NULL, 0);
1880                         d=Time_F(STOP);
1881                         print_result(D_AES_256_GCM,j,count,d);
1882                         }
1883                 EVP_AEAD_CTX_cleanup(&ctx);
1884                 }
1885 #endif
1886
1887 #if !defined(OPENSSL_NO_CHACHA) && !defined(OPENSSL_NO_POLY1305)
1888         if (doit[D_CHACHA20_POLY1305])
1889                 {
1890                 const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();
1891                 static const unsigned char nonce[32] = {0};
1892                 size_t nonce_len;
1893                 EVP_AEAD_CTX ctx;
1894
1895                 EVP_AEAD_CTX_init(&ctx, aead, key32, EVP_AEAD_key_length(aead),
1896                                   EVP_AEAD_DEFAULT_TAG_LENGTH, NULL);
1897                 nonce_len = EVP_AEAD_nonce_length(aead);
1898
1899                 for (j=0; j<SIZE_NUM; j++)
1900                         {
1901                         print_message(names[D_CHACHA20_POLY1305],
1902                                       c[D_CHACHA20_POLY1305][j], lengths[j]);
1903                         Time_F(START);
1904                         for (count=0,run=1; COND(c[D_CHACHA20_POLY1305][j]);
1905                              count++)
1906                                 EVP_AEAD_CTX_seal(&ctx, buf, BUFSIZE, nonce,
1907                                                   nonce_len, buf, lengths[j],
1908                                                   NULL, 0);
1909                         d=Time_F(STOP);
1910                         print_result(D_CHACHA20_POLY1305,j,count,d);
1911                         }
1912                 EVP_AEAD_CTX_cleanup(&ctx);
1913                 }
1914 #endif
1915
1916 #ifndef OPENSSL_NO_CAMELLIA
1917         if (doit[D_CBC_128_CML])
1918                 {
1919                 for (j=0; j<SIZE_NUM; j++)
1920                         {
1921                         print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
1922                         Time_F(START);
1923                         for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
1924                                 Camellia_cbc_encrypt(buf,buf,
1925                                         (unsigned long)lengths[j],&camellia_ks1,
1926                                         iv,CAMELLIA_ENCRYPT);
1927                         d=Time_F(STOP);
1928                         print_result(D_CBC_128_CML,j,count,d);
1929                         }
1930                 }
1931         if (doit[D_CBC_192_CML])
1932                 {
1933                 for (j=0; j<SIZE_NUM; j++)
1934                         {
1935                         print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
1936                         Time_F(START);
1937                         for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
1938                                 Camellia_cbc_encrypt(buf,buf,
1939                                         (unsigned long)lengths[j],&camellia_ks2,
1940                                         iv,CAMELLIA_ENCRYPT);
1941                         d=Time_F(STOP);
1942                         print_result(D_CBC_192_CML,j,count,d);
1943                         }
1944                 }
1945         if (doit[D_CBC_256_CML])
1946                 {
1947                 for (j=0; j<SIZE_NUM; j++)
1948                         {
1949                         print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
1950                         Time_F(START);
1951                         for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
1952                                 Camellia_cbc_encrypt(buf,buf,
1953                                         (unsigned long)lengths[j],&camellia_ks3,
1954                                         iv,CAMELLIA_ENCRYPT);
1955                         d=Time_F(STOP);
1956                         print_result(D_CBC_256_CML,j,count,d);
1957                         }
1958                 }
1959
1960 #endif
1961 #ifndef OPENSSL_NO_IDEA
1962         if (doit[D_CBC_IDEA])
1963                 {
1964                 for (j=0; j<SIZE_NUM; j++)
1965                         {
1966                         print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1967                         Time_F(START);
1968                         for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1969                                 idea_cbc_encrypt(buf,buf,
1970                                         (unsigned long)lengths[j],&idea_ks,
1971                                         iv,IDEA_ENCRYPT);
1972                         d=Time_F(STOP);
1973                         print_result(D_CBC_IDEA,j,count,d);
1974                         }
1975                 }
1976 #endif
1977 #ifndef OPENSSL_NO_SEED
1978         if (doit[D_CBC_SEED])
1979                 {
1980                 for (j=0; j<SIZE_NUM; j++)
1981                         {
1982                         print_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);
1983                         Time_F(START);
1984                         for (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)
1985                                 SEED_cbc_encrypt(buf,buf,
1986                                         (unsigned long)lengths[j],&seed_ks,iv,1);
1987                         d=Time_F(STOP);
1988                         print_result(D_CBC_SEED,j,count,d);
1989                         }
1990                 }
1991 #endif
1992 #ifndef OPENSSL_NO_RC2
1993         if (doit[D_CBC_RC2])
1994                 {
1995                 for (j=0; j<SIZE_NUM; j++)
1996                         {
1997                         print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1998                         Time_F(START);
1999                         for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
2000                                 RC2_cbc_encrypt(buf,buf,
2001                                         (unsigned long)lengths[j],&rc2_ks,
2002                                         iv,RC2_ENCRYPT);
2003                         d=Time_F(STOP);
2004                         print_result(D_CBC_RC2,j,count,d);
2005                         }
2006                 }
2007 #endif
2008 #ifndef OPENSSL_NO_RC5
2009         if (doit[D_CBC_RC5])
2010                 {
2011                 for (j=0; j<SIZE_NUM; j++)
2012                         {
2013                         print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
2014                         Time_F(START);
2015                         for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
2016                                 RC5_32_cbc_encrypt(buf,buf,
2017                                         (unsigned long)lengths[j],&rc5_ks,
2018                                         iv,RC5_ENCRYPT);
2019                         d=Time_F(STOP);
2020                         print_result(D_CBC_RC5,j,count,d);
2021                         }
2022                 }
2023 #endif
2024 #ifndef OPENSSL_NO_BF
2025         if (doit[D_CBC_BF])
2026                 {
2027                 for (j=0; j<SIZE_NUM; j++)
2028                         {
2029                         print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
2030                         Time_F(START);
2031                         for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
2032                                 BF_cbc_encrypt(buf,buf,
2033                                         (unsigned long)lengths[j],&bf_ks,
2034                                         iv,BF_ENCRYPT);
2035                         d=Time_F(STOP);
2036                         print_result(D_CBC_BF,j,count,d);
2037                         }
2038                 }
2039 #endif
2040 #ifndef OPENSSL_NO_CAST
2041         if (doit[D_CBC_CAST])
2042                 {
2043                 for (j=0; j<SIZE_NUM; j++)
2044                         {
2045                         print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
2046                         Time_F(START);
2047                         for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
2048                                 CAST_cbc_encrypt(buf,buf,
2049                                         (unsigned long)lengths[j],&cast_ks,
2050                                         iv,CAST_ENCRYPT);
2051                         d=Time_F(STOP);
2052                         print_result(D_CBC_CAST,j,count,d);
2053                         }
2054                 }
2055 #endif
2056
2057         if (doit[D_EVP])
2058                 {
2059                 for (j=0; j<SIZE_NUM; j++)
2060                         {
2061                         if (evp_cipher)
2062                                 {
2063                                 EVP_CIPHER_CTX ctx;
2064                                 int outl;
2065
2066                                 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
2067                                 /* -O3 -fschedule-insns messes up an
2068                                  * optimization here!  names[D_EVP]
2069                                  * somehow becomes NULL */
2070                                 print_message(names[D_EVP],save_count,
2071                                         lengths[j]);
2072
2073                                 EVP_CIPHER_CTX_init(&ctx);
2074                                 if(decrypt)
2075                                         EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2076                                 else
2077                                         EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
2078                                 EVP_CIPHER_CTX_set_padding(&ctx, 0);
2079
2080                                 Time_F(START);
2081                                 if(decrypt)
2082                                         for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2083                                                 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2084                                 else
2085                                         for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2086                                                 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
2087                                 if(decrypt)
2088                                         EVP_DecryptFinal_ex(&ctx,buf,&outl);
2089                                 else
2090                                         EVP_EncryptFinal_ex(&ctx,buf,&outl);
2091                                 d=Time_F(STOP);
2092                                 EVP_CIPHER_CTX_cleanup(&ctx);
2093                                 }
2094                         if (evp_md)
2095                                 {
2096                                 names[D_EVP]=OBJ_nid2ln(evp_md->type);
2097                                 print_message(names[D_EVP],save_count,
2098                                         lengths[j]);
2099
2100                                 Time_F(START);
2101                                 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
2102                                         EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
2103
2104                                 d=Time_F(STOP);
2105                                 }
2106                         print_result(D_EVP,j,count,d);
2107                         }
2108                 }
2109
2110         RAND_pseudo_bytes(buf,36);
2111 #ifndef OPENSSL_NO_RSA
2112         for (j=0; j<RSA_NUM; j++)
2113                 {
2114                 int ret;
2115                 if (!rsa_doit[j]) continue;
2116                 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
2117                 if (ret == 0)
2118                         {
2119                         BIO_printf(bio_err,"RSA sign failure.  No RSA sign will be done.\n");
2120                         ERR_print_errors(bio_err);
2121                         rsa_count=1;
2122                         }
2123                 else
2124                         {
2125                         pkey_print_message("private","rsa",
2126                                 rsa_c[j][0],rsa_bits[j],
2127                                 RSA_SECONDS);
2128 /*                      RSA_blinding_on(rsa_key[j],NULL); */
2129                         Time_F(START);
2130                         for (count=0,run=1; COND(rsa_c[j][0]); count++)
2131                                 {
2132                                 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
2133                                         &rsa_num, rsa_key[j]);
2134                                 if (ret == 0)
2135                                         {
2136                                         BIO_printf(bio_err,
2137                                                 "RSA sign failure\n");
2138                                         ERR_print_errors(bio_err);
2139                                         count=1;
2140                                         break;
2141                                         }
2142                                 }
2143                         d=Time_F(STOP);
2144                         BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
2145                                    : "%ld %d bit private RSA's in %.2fs\n",
2146                                    count,rsa_bits[j],d);
2147                         rsa_results[j][0]=d/(double)count;
2148                         rsa_count=count;
2149                         }
2150
2151 #if 1
2152                 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
2153                 if (ret <= 0)
2154                         {
2155                         BIO_printf(bio_err,"RSA verify failure.  No RSA verify will be done.\n");
2156                         ERR_print_errors(bio_err);
2157                         rsa_doit[j] = 0;
2158                         }
2159                 else
2160                         {
2161                         pkey_print_message("public","rsa",
2162                                 rsa_c[j][1],rsa_bits[j],
2163                                 RSA_SECONDS);
2164                         Time_F(START);
2165                         for (count=0,run=1; COND(rsa_c[j][1]); count++)
2166                                 {
2167                                 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
2168                                         rsa_num, rsa_key[j]);
2169                                 if (ret <= 0)
2170                                         {
2171                                         BIO_printf(bio_err,
2172                                                 "RSA verify failure\n");
2173                                         ERR_print_errors(bio_err);
2174                                         count=1;
2175                                         break;
2176                                         }
2177                                 }
2178                         d=Time_F(STOP);
2179                         BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
2180                                    : "%ld %d bit public RSA's in %.2fs\n",
2181                                    count,rsa_bits[j],d);
2182                         rsa_results[j][1]=d/(double)count;
2183                         }
2184 #endif
2185
2186                 if (rsa_count <= 1)
2187                         {
2188                         /* if longer than 10s, don't do any more */
2189                         for (j++; j<RSA_NUM; j++)
2190                                 rsa_doit[j]=0;
2191                         }
2192                 }
2193 #endif
2194
2195         RAND_pseudo_bytes(buf,20);
2196 #ifndef OPENSSL_NO_DSA
2197         if (RAND_status() != 1)
2198                 {
2199                 RAND_seed(rnd_seed, sizeof rnd_seed);
2200                 rnd_fake = 1;
2201                 }
2202         for (j=0; j<DSA_NUM; j++)
2203                 {
2204                 unsigned int kk;
2205                 int ret;
2206
2207                 if (!dsa_doit[j]) continue;
2208 /*              DSA_generate_key(dsa_key[j]); */
2209 /*              DSA_sign_setup(dsa_key[j],NULL); */
2210                 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2211                         &kk,dsa_key[j]);
2212                 if (ret == 0)
2213                         {
2214                         BIO_printf(bio_err,"DSA sign failure.  No DSA sign will be done.\n");
2215                         ERR_print_errors(bio_err);
2216                         rsa_count=1;
2217                         }
2218                 else
2219                         {
2220                         pkey_print_message("sign","dsa",
2221                                 dsa_c[j][0],dsa_bits[j],
2222                                 DSA_SECONDS);
2223                         Time_F(START);
2224                         for (count=0,run=1; COND(dsa_c[j][0]); count++)
2225                                 {
2226                                 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
2227                                         &kk,dsa_key[j]);
2228                                 if (ret == 0)
2229                                         {
2230                                         BIO_printf(bio_err,
2231                                                 "DSA sign failure\n");
2232                                         ERR_print_errors(bio_err);
2233                                         count=1;
2234                                         break;
2235                                         }
2236                                 }
2237                         d=Time_F(STOP);
2238                         BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
2239                                    : "%ld %d bit DSA signs in %.2fs\n",
2240                                    count,dsa_bits[j],d);
2241                         dsa_results[j][0]=d/(double)count;
2242                         rsa_count=count;
2243                         }
2244
2245                 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2246                         kk,dsa_key[j]);
2247                 if (ret <= 0)
2248                         {
2249                         BIO_printf(bio_err,"DSA verify failure.  No DSA verify will be done.\n");
2250                         ERR_print_errors(bio_err);
2251                         dsa_doit[j] = 0;
2252                         }
2253                 else
2254                         {
2255                         pkey_print_message("verify","dsa",
2256                                 dsa_c[j][1],dsa_bits[j],
2257                                 DSA_SECONDS);
2258                         Time_F(START);
2259                         for (count=0,run=1; COND(dsa_c[j][1]); count++)
2260                                 {
2261                                 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
2262                                         kk,dsa_key[j]);
2263                                 if (ret <= 0)
2264                                         {
2265                                         BIO_printf(bio_err,
2266                                                 "DSA verify failure\n");
2267                                         ERR_print_errors(bio_err);
2268                                         count=1;
2269                                         break;
2270                                         }
2271                                 }
2272                         d=Time_F(STOP);
2273                         BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
2274                                    : "%ld %d bit DSA verify in %.2fs\n",
2275                                    count,dsa_bits[j],d);
2276                         dsa_results[j][1]=d/(double)count;
2277                         }
2278
2279                 if (rsa_count <= 1)
2280                         {
2281                         /* if longer than 10s, don't do any more */
2282                         for (j++; j<DSA_NUM; j++)
2283                                 dsa_doit[j]=0;
2284                         }
2285                 }
2286         if (rnd_fake) RAND_cleanup();
2287 #endif
2288
2289 #ifndef OPENSSL_NO_ECDSA
2290         if (RAND_status() != 1) 
2291                 {
2292                 RAND_seed(rnd_seed, sizeof rnd_seed);
2293                 rnd_fake = 1;
2294                 }
2295         for (j=0; j<EC_NUM; j++) 
2296                 {
2297                 int ret;
2298
2299                 if (!ecdsa_doit[j]) continue; /* Ignore Curve */ 
2300                 ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2301                 if (ecdsa[j] == NULL) 
2302                         {
2303                         BIO_printf(bio_err,"ECDSA failure.\n");
2304                         ERR_print_errors(bio_err);
2305                         rsa_count=1;
2306                         } 
2307                 else 
2308                         {
2309 #if 1
2310                         EC_KEY_precompute_mult(ecdsa[j], NULL);
2311 #endif
2312                         /* Perform ECDSA signature test */
2313                         EC_KEY_generate_key(ecdsa[j]);
2314                         ret = ECDSA_sign(0, buf, 20, ecdsasig, 
2315                                 &ecdsasiglen, ecdsa[j]);
2316                         if (ret == 0) 
2317                                 {
2318                                 BIO_printf(bio_err,"ECDSA sign failure.  No ECDSA sign will be done.\n");
2319                                 ERR_print_errors(bio_err);
2320                                 rsa_count=1;
2321                                 } 
2322                         else 
2323                                 {
2324                                 pkey_print_message("sign","ecdsa",
2325                                         ecdsa_c[j][0], 
2326                                         test_curves_bits[j],
2327                                         ECDSA_SECONDS);
2328
2329                                 Time_F(START);
2330                                 for (count=0,run=1; COND(ecdsa_c[j][0]);
2331                                         count++) 
2332                                         {
2333                                         ret=ECDSA_sign(0, buf, 20, 
2334                                                 ecdsasig, &ecdsasiglen,
2335                                                 ecdsa[j]);
2336                                         if (ret == 0) 
2337                                                 {
2338                                                 BIO_printf(bio_err, "ECDSA sign failure\n");
2339                                                 ERR_print_errors(bio_err);
2340                                                 count=1;
2341                                                 break;
2342                                                 }
2343                                         }
2344                                 d=Time_F(STOP);
2345
2346                                 BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2347                                         "%ld %d bit ECDSA signs in %.2fs \n", 
2348                                         count, test_curves_bits[j], d);
2349                                 ecdsa_results[j][0]=d/(double)count;
2350                                 rsa_count=count;
2351                                 }
2352
2353                         /* Perform ECDSA verification test */
2354                         ret=ECDSA_verify(0, buf, 20, ecdsasig, 
2355                                 ecdsasiglen, ecdsa[j]);
2356                         if (ret != 1) 
2357                                 {
2358                                 BIO_printf(bio_err,"ECDSA verify failure.  No ECDSA verify will be done.\n");
2359                                 ERR_print_errors(bio_err);
2360                                 ecdsa_doit[j] = 0;
2361                                 } 
2362                         else 
2363                                 {
2364                                 pkey_print_message("verify","ecdsa",
2365                                 ecdsa_c[j][1],
2366                                 test_curves_bits[j],
2367                                 ECDSA_SECONDS);
2368                                 Time_F(START);
2369                                 for (count=0,run=1; COND(ecdsa_c[j][1]); count++) 
2370                                         {
2371                                         ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2372                                         if (ret != 1) 
2373                                                 {
2374                                                 BIO_printf(bio_err, "ECDSA verify failure\n");
2375                                                 ERR_print_errors(bio_err);
2376                                                 count=1;
2377                                                 break;
2378                                                 }
2379                                         }
2380                                 d=Time_F(STOP);
2381                                 BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2382                                                 : "%ld %d bit ECDSA verify in %.2fs\n",
2383                                 count, test_curves_bits[j], d);
2384                                 ecdsa_results[j][1]=d/(double)count;
2385                                 }
2386
2387                         if (rsa_count <= 1) 
2388                                 {
2389                                 /* if longer than 10s, don't do any more */
2390                                 for (j++; j<EC_NUM; j++)
2391                                 ecdsa_doit[j]=0;
2392                                 }
2393                         }
2394                 }
2395         if (rnd_fake) RAND_cleanup();
2396 #endif
2397
2398 #ifndef OPENSSL_NO_ECDH
2399         if (RAND_status() != 1)
2400                 {
2401                 RAND_seed(rnd_seed, sizeof rnd_seed);
2402                 rnd_fake = 1;
2403                 }
2404         for (j=0; j<EC_NUM; j++)
2405                 {
2406                 if (!ecdh_doit[j]) continue;
2407                 ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2408                 ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2409                 if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2410                         {
2411                         BIO_printf(bio_err,"ECDH failure.\n");
2412                         ERR_print_errors(bio_err);
2413                         rsa_count=1;
2414                         }
2415                 else
2416                         {
2417                         /* generate two ECDH key pairs */
2418                         if (!EC_KEY_generate_key(ecdh_a[j]) ||
2419                                 !EC_KEY_generate_key(ecdh_b[j]))
2420                                 {
2421                                 BIO_printf(bio_err,"ECDH key generation failure.\n");
2422                                 ERR_print_errors(bio_err);
2423                                 rsa_count=1;            
2424                                 }
2425                         else
2426                                 {
2427                                 /* If field size is not more than 24 octets, then use SHA-1 hash of result;
2428                                  * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2429                                  */
2430                                 int field_size, outlen;
2431                                 void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2432                                 field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2433                                 if (field_size <= 24 * 8)
2434                                         {
2435                                         outlen = KDF1_SHA1_len;
2436                                         kdf = KDF1_SHA1;
2437                                         }
2438                                 else
2439                                         {
2440                                         outlen = (field_size+7)/8;
2441                                         kdf = NULL;
2442                                         }
2443                                 secret_size_a = ECDH_compute_key(secret_a, outlen,
2444                                         EC_KEY_get0_public_key(ecdh_b[j]),
2445                                         ecdh_a[j], kdf);
2446                                 secret_size_b = ECDH_compute_key(secret_b, outlen,
2447                                         EC_KEY_get0_public_key(ecdh_a[j]),
2448                                         ecdh_b[j], kdf);
2449                                 if (secret_size_a != secret_size_b) 
2450                                         ecdh_checks = 0;
2451                                 else
2452                                         ecdh_checks = 1;
2453
2454                                 for (secret_idx = 0; 
2455                                     (secret_idx < secret_size_a)
2456                                         && (ecdh_checks == 1);
2457                                     secret_idx++)
2458                                         {
2459                                         if (secret_a[secret_idx] != secret_b[secret_idx])
2460                                         ecdh_checks = 0;
2461                                         }
2462
2463                                 if (ecdh_checks == 0)
2464                                         {
2465                                         BIO_printf(bio_err,"ECDH computations don't match.\n");
2466                                         ERR_print_errors(bio_err);
2467                                         rsa_count=1;            
2468                                         }
2469
2470                                 pkey_print_message("","ecdh",
2471                                 ecdh_c[j][0], 
2472                                 test_curves_bits[j],
2473                                 ECDH_SECONDS);
2474                                 Time_F(START);
2475                                 for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2476                                         {
2477                                         ECDH_compute_key(secret_a, outlen,
2478                                         EC_KEY_get0_public_key(ecdh_b[j]),
2479                                         ecdh_a[j], kdf);
2480                                         }
2481                                 d=Time_F(STOP);
2482                                 BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2483                                 count, test_curves_bits[j], d);
2484                                 ecdh_results[j][0]=d/(double)count;
2485                                 rsa_count=count;
2486                                 }
2487                         }
2488
2489
2490                 if (rsa_count <= 1)
2491                         {
2492                         /* if longer than 10s, don't do any more */
2493                         for (j++; j<EC_NUM; j++)
2494                         ecdh_doit[j]=0;
2495                         }
2496                 }
2497         if (rnd_fake) RAND_cleanup();
2498 #endif
2499 #ifndef NO_FORK
2500 show_res:
2501 #endif
2502         if(!mr)
2503                 {
2504                 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
2505         fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
2506                 printf("options:");
2507                 printf("%s ",BN_options());
2508 #ifndef OPENSSL_NO_MD2
2509                 printf("%s ",MD2_options());
2510 #endif
2511 #ifndef OPENSSL_NO_RC4
2512                 printf("%s ",RC4_options());
2513 #endif
2514 #ifndef OPENSSL_NO_DES
2515                 printf("%s ",DES_options());
2516 #endif
2517 #ifndef OPENSSL_NO_AES
2518                 printf("%s ",AES_options());
2519 #endif
2520 #ifndef OPENSSL_NO_IDEA
2521                 printf("%s ",idea_options());
2522 #endif
2523 #ifndef OPENSSL_NO_BF
2524                 printf("%s ",BF_options());
2525 #endif
2526                 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
2527                 }
2528
2529         if (pr_header)
2530                 {
2531                 if(mr)
2532                         fprintf(stdout,"+H");
2533                 else
2534                         {
2535                         fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); 
2536                         fprintf(stdout,"type        ");
2537                         }
2538                 for (j=0;  j<SIZE_NUM; j++)
2539                         fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
2540                 fprintf(stdout,"\n");
2541                 }
2542
2543         for (k=0; k<ALGOR_NUM; k++)
2544                 {
2545                 if (!doit[k]) continue;
2546                 if(mr)
2547                         fprintf(stdout,"+F:%d:%s",k,names[k]);
2548                 else
2549                         fprintf(stdout,"%-13s",names[k]);
2550                 for (j=0; j<SIZE_NUM; j++)
2551                         {
2552                         if (results[k][j] > 10000 && !mr)
2553                                 fprintf(stdout," %11.2fk",results[k][j]/1e3);
2554                         else
2555                                 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
2556                         }
2557                 fprintf(stdout,"\n");
2558                 }
2559 #ifndef OPENSSL_NO_RSA
2560         j=1;
2561         for (k=0; k<RSA_NUM; k++)
2562                 {
2563                 if (!rsa_doit[k]) continue;
2564                 if (j && !mr)
2565                         {
2566                         printf("%18ssign    verify    sign/s verify/s\n"," ");
2567                         j=0;
2568                         }
2569                 if(mr)
2570                         fprintf(stdout,"+F2:%u:%u:%f:%f\n",
2571                                 k,rsa_bits[k],rsa_results[k][0],
2572                                 rsa_results[k][1]);
2573                 else
2574                         fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2575                                 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
2576                                 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
2577                 }
2578 #endif
2579 #ifndef OPENSSL_NO_DSA
2580         j=1;
2581         for (k=0; k<DSA_NUM; k++)
2582                 {
2583                 if (!dsa_doit[k]) continue;
2584                 if (j && !mr)
2585                         {
2586                         printf("%18ssign    verify    sign/s verify/s\n"," ");
2587                         j=0;
2588                         }
2589                 if(mr)
2590                         fprintf(stdout,"+F3:%u:%u:%f:%f\n",
2591                                 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
2592                 else
2593                         fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
2594                                 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
2595                                 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
2596                 }
2597 #endif
2598 #ifndef OPENSSL_NO_ECDSA
2599         j=1;
2600         for (k=0; k<EC_NUM; k++)
2601                 {
2602                 if (!ecdsa_doit[k]) continue;
2603                 if (j && !mr)
2604                         {
2605                         printf("%30ssign    verify    sign/s verify/s\n"," ");
2606                         j=0;
2607                         }
2608
2609                 if (mr)
2610                         fprintf(stdout,"+F4:%u:%u:%f:%f\n", 
2611                                 k, test_curves_bits[k],
2612                                 ecdsa_results[k][0],ecdsa_results[k][1]);
2613                 else
2614                         fprintf(stdout,
2615                                 "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n", 
2616                                 test_curves_bits[k],
2617                                 test_curves_names[k],
2618                                 ecdsa_results[k][0],ecdsa_results[k][1], 
2619                                 1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2620                 }
2621 #endif
2622
2623
2624 #ifndef OPENSSL_NO_ECDH
2625         j=1;
2626         for (k=0; k<EC_NUM; k++)
2627                 {
2628                 if (!ecdh_doit[k]) continue;
2629                 if (j && !mr)
2630                         {
2631                         printf("%30sop      op/s\n"," ");
2632                         j=0;
2633                         }
2634                 if (mr)
2635                         fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2636                                 k, test_curves_bits[k],
2637                                 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2638
2639                 else
2640                         fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2641                                 test_curves_bits[k],
2642                                 test_curves_names[k],
2643                                 ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2644                 }
2645 #endif
2646
2647         mret=0;
2648
2649 end:
2650         ERR_print_errors(bio_err);
2651         if (buf != NULL) OPENSSL_free(buf);
2652         if (buf2 != NULL) OPENSSL_free(buf2);
2653 #ifndef OPENSSL_NO_RSA
2654         for (i=0; i<RSA_NUM; i++)
2655                 if (rsa_key[i] != NULL)
2656                         RSA_free(rsa_key[i]);
2657 #endif
2658 #ifndef OPENSSL_NO_DSA
2659         for (i=0; i<DSA_NUM; i++)
2660                 if (dsa_key[i] != NULL)
2661                         DSA_free(dsa_key[i]);
2662 #endif
2663
2664 #ifndef OPENSSL_NO_ECDSA
2665         for (i=0; i<EC_NUM; i++)
2666                 if (ecdsa[i] != NULL)
2667                         EC_KEY_free(ecdsa[i]);
2668 #endif
2669 #ifndef OPENSSL_NO_ECDH
2670         for (i=0; i<EC_NUM; i++)
2671         {
2672                 if (ecdh_a[i] != NULL)
2673                         EC_KEY_free(ecdh_a[i]);
2674                 if (ecdh_b[i] != NULL)
2675                         EC_KEY_free(ecdh_b[i]);
2676         }
2677 #endif
2678
2679         apps_shutdown();
2680         OPENSSL_EXIT(mret);
2681         }
2682
2683 static void print_message(const char *s, long num, int length)
2684         {
2685 #ifdef SIGALRM
2686         BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
2687                    : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
2688         (void)BIO_flush(bio_err);
2689         alarm(SECONDS);
2690 #else
2691         BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
2692                    : "Doing %s %ld times on %d size blocks: ",s,num,length);
2693         (void)BIO_flush(bio_err);
2694 #endif
2695 #ifdef LINT
2696         num=num;
2697 #endif
2698         }
2699
2700 static void pkey_print_message(const char *str, const char *str2, long num,
2701         int bits, int tm)
2702         {
2703 #ifdef SIGALRM
2704         BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
2705                            : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
2706         (void)BIO_flush(bio_err);
2707         alarm(tm);
2708 #else
2709         BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
2710                            : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
2711         (void)BIO_flush(bio_err);
2712 #endif
2713 #ifdef LINT
2714         num=num;
2715 #endif
2716         }
2717
2718 static void print_result(int alg,int run_no,int count,double time_used)
2719         {
2720         BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2721                    : "%d %s's in %.2fs\n",count,names[alg],time_used);
2722         results[alg][run_no]=((double)count)/time_used*lengths[run_no];
2723         }
2724
2725 #ifndef NO_FORK
2726 static char *sstrsep(char **string, const char *delim)
2727     {
2728     char isdelim[256];
2729     char *token = *string;
2730
2731     if (**string == 0)
2732         return NULL;
2733
2734     memset(isdelim, 0, sizeof isdelim);
2735     isdelim[0] = 1;
2736
2737     while (*delim)
2738         {
2739         isdelim[(unsigned char)(*delim)] = 1;
2740         delim++;
2741         }
2742
2743     while (!isdelim[(unsigned char)(**string)])
2744         {
2745         (*string)++;
2746         }
2747
2748     if (**string)
2749         {
2750         **string = 0;
2751         (*string)++;
2752         }
2753
2754     return token;
2755     }
2756
2757 static int do_multi(int multi)
2758         {
2759         int n;
2760         int fd[2];
2761         int *fds;
2762         static char sep[]=":";
2763
2764         fds=malloc(multi*sizeof *fds);
2765         for(n=0 ; n < multi ; ++n)
2766                 {
2767                 if (pipe(fd) == -1)
2768                         {
2769                         fprintf(stderr, "pipe failure\n");
2770                         exit(1);
2771                         }
2772                 fflush(stdout);
2773                 fflush(stderr);
2774                 if(fork())
2775                         {
2776                         close(fd[1]);
2777                         fds[n]=fd[0];
2778                         }
2779                 else
2780                         {
2781                         close(fd[0]);
2782                         close(1);
2783                         if (dup(fd[1]) == -1)
2784                                 {
2785                                 fprintf(stderr, "dup failed\n");
2786                                 exit(1);
2787                                 }
2788                         close(fd[1]);
2789                         mr=1;
2790                         usertime=0;
2791                         free(fds);
2792                         return 0;
2793                         }
2794                 printf("Forked child %d\n",n);
2795                 }
2796
2797         /* for now, assume the pipe is long enough to take all the output */
2798         for(n=0 ; n < multi ; ++n)
2799                 {
2800                 FILE *f;
2801                 char buf[1024];
2802                 char *p;
2803
2804                 f=fdopen(fds[n],"r");
2805                 while(fgets(buf,sizeof buf,f))
2806                         {
2807                         p=strchr(buf,'\n');
2808                         if(p)
2809                                 *p='\0';
2810                         if(buf[0] != '+')
2811                                 {
2812                                 fprintf(stderr,"Don't understand line '%s' from child %d\n",
2813                                                 buf,n);
2814                                 continue;
2815                                 }
2816                         printf("Got: %s from %d\n",buf,n);
2817                         if(!strncmp(buf,"+F:",3))
2818                                 {
2819                                 int alg;
2820                                 int j;
2821
2822                                 p=buf+3;
2823                                 alg=atoi(sstrsep(&p,sep));
2824                                 sstrsep(&p,sep);
2825                                 for(j=0 ; j < SIZE_NUM ; ++j)
2826                                         results[alg][j]+=atof(sstrsep(&p,sep));
2827                                 }
2828                         else if(!strncmp(buf,"+F2:",4))
2829                                 {
2830                                 int k;
2831                                 double d;
2832                                 
2833                                 p=buf+4;
2834                                 k=atoi(sstrsep(&p,sep));
2835                                 sstrsep(&p,sep);
2836
2837                                 d=atof(sstrsep(&p,sep));
2838                                 if(n)
2839                                         rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2840                                 else
2841                                         rsa_results[k][0]=d;
2842
2843                                 d=atof(sstrsep(&p,sep));
2844                                 if(n)
2845                                         rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2846                                 else
2847                                         rsa_results[k][1]=d;
2848                                 }
2849                         else if(!strncmp(buf,"+F2:",4))
2850                                 {
2851                                 int k;
2852                                 double d;
2853                                 
2854                                 p=buf+4;
2855                                 k=atoi(sstrsep(&p,sep));
2856                                 sstrsep(&p,sep);
2857
2858                                 d=atof(sstrsep(&p,sep));
2859                                 if(n)
2860                                         rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
2861                                 else
2862                                         rsa_results[k][0]=d;
2863
2864                                 d=atof(sstrsep(&p,sep));
2865                                 if(n)
2866                                         rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
2867                                 else
2868                                         rsa_results[k][1]=d;
2869                                 }
2870 #ifndef OPENSSL_NO_DSA
2871                         else if(!strncmp(buf,"+F3:",4))
2872                                 {
2873                                 int k;
2874                                 double d;
2875                                 
2876                                 p=buf+4;
2877                                 k=atoi(sstrsep(&p,sep));
2878                                 sstrsep(&p,sep);
2879
2880                                 d=atof(sstrsep(&p,sep));
2881                                 if(n)
2882                                         dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
2883                                 else
2884                                         dsa_results[k][0]=d;
2885
2886                                 d=atof(sstrsep(&p,sep));
2887                                 if(n)
2888                                         dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
2889                                 else
2890                                         dsa_results[k][1]=d;
2891                                 }
2892 #endif
2893 #ifndef OPENSSL_NO_ECDSA
2894                         else if(!strncmp(buf,"+F4:",4))
2895                                 {
2896                                 int k;
2897                                 double d;
2898                                 
2899                                 p=buf+4;
2900                                 k=atoi(sstrsep(&p,sep));
2901                                 sstrsep(&p,sep);
2902
2903                                 d=atof(sstrsep(&p,sep));
2904                                 if(n)
2905                                         ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2906                                 else
2907                                         ecdsa_results[k][0]=d;
2908
2909                                 d=atof(sstrsep(&p,sep));
2910                                 if(n)
2911                                         ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2912                                 else
2913                                         ecdsa_results[k][1]=d;
2914                                 }
2915 #endif 
2916
2917 #ifndef OPENSSL_NO_ECDH
2918                         else if(!strncmp(buf,"+F5:",4))
2919                                 {
2920                                 int k;
2921                                 double d;
2922                                 
2923                                 p=buf+4;
2924                                 k=atoi(sstrsep(&p,sep));
2925                                 sstrsep(&p,sep);
2926
2927                                 d=atof(sstrsep(&p,sep));
2928                                 if(n)
2929                                         ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2930                                 else
2931                                         ecdh_results[k][0]=d;
2932
2933                                 }
2934 #endif
2935
2936                         else if(!strncmp(buf,"+H:",3))
2937                                 {
2938                                 }
2939                         else
2940                                 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
2941                         }
2942
2943                 fclose(f);
2944                 }
2945         free(fds);
2946         return 1;
2947         }
2948 #endif
2949 #endif