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