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