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