b54ed40de6e6ae3f9b6873bf5798c23c2f6c1d6f
[openssl.git] / apps / speed.c
1 /* apps/speed.c */
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 /* most of this code has been pilfered from my libdes speed.c program */
60
61 #undef SECONDS
62 #define SECONDS         3       
63 #define RSA_SECONDS     10
64 #define DSA_SECONDS     10
65
66 /* 11-Sep-92 Andrew Daviel   Support for Silicon Graphics IRIX added */
67 /* 06-Apr-92 Luke Brennan    Support for VMS and add extra signal calls */
68
69 #undef PROG
70 #define PROG speed_main
71
72 #include <stdio.h>
73 #include <stdlib.h>
74 #include <signal.h>
75 #include <string.h>
76 #include <math.h>
77 #include "apps.h"
78 #ifdef NO_STDIO
79 #define APPS_WIN16
80 #endif
81 #include <openssl/crypto.h>
82 #include <openssl/rand.h>
83 #include <openssl/err.h>
84
85 #if defined(__FreeBSD__)
86 # define USE_TOD
87 #elif !defined(MSDOS) && (!defined(VMS) || defined(__DECC))
88 # define TIMES
89 #endif
90 #if !defined(_UNICOS)
91 # define TIMEB
92 #endif
93
94 #ifndef _IRIX
95 # include <time.h>
96 #endif
97 #ifdef TIMES
98 # include <sys/types.h>
99 # include <sys/times.h>
100 #endif
101 #ifdef USE_TOD
102 # include <sys/time.h>
103 # include <sys/resource.h>
104 #endif
105
106 /* Depending on the VMS version, the tms structure is perhaps defined.
107    The __TMS macro will show if it was.  If it wasn't defined, we should
108    undefine TIMES, since that tells the rest of the program how things
109    should be handled.                           -- Richard Levitte */
110 #if defined(VMS) && defined(__DECC) && !defined(__TMS)
111 #undef TIMES
112 #endif
113
114 #ifdef TIMEB
115 #include <sys/timeb.h>
116 #endif
117
118 #if !defined(TIMES) && !defined(TIMEB)
119 #error "It seems neither struct tms nor struct timeb is supported in this platform!"
120 #endif
121
122 #if defined(sun) || defined(__ultrix)
123 #define _POSIX_SOURCE
124 #include <limits.h>
125 #include <sys/param.h>
126 #endif
127
128 #ifndef NO_DES
129 #include <openssl/des.h>
130 #endif
131 #ifndef NO_MD2
132 #include <openssl/md2.h>
133 #endif
134 #ifndef NO_MDC2
135 #include <openssl/mdc2.h>
136 #endif
137 #ifndef NO_MD5
138 #include <openssl/md5.h>
139 #endif
140 #ifndef NO_HMAC
141 #include <openssl/hmac.h>
142 #endif
143 #include <openssl/evp.h>
144 #ifndef NO_SHA
145 #include <openssl/sha.h>
146 #endif
147 #ifndef NO_RIPEMD
148 #include <openssl/ripemd.h>
149 #endif
150 #ifndef NO_RC4
151 #include <openssl/rc4.h>
152 #endif
153 #ifndef NO_RC5
154 #include <openssl/rc5.h>
155 #endif
156 #ifndef NO_RC2
157 #include <openssl/rc2.h>
158 #endif
159 #ifndef NO_IDEA
160 #include <openssl/idea.h>
161 #endif
162 #ifndef NO_BF
163 #include <openssl/blowfish.h>
164 #endif
165 #ifndef NO_CAST
166 #include <openssl/cast.h>
167 #endif
168 #ifndef NO_RSA
169 #include <openssl/rsa.h>
170 #include "./testrsa.h"
171 #endif
172 #include <openssl/x509.h>
173 #ifndef NO_DSA
174 #include "./testdsa.h"
175 #endif
176
177 /* The following if from times(3) man page.  It may need to be changed */
178 #ifndef HZ
179 # ifndef CLK_TCK
180 #  ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
181 #   define HZ   100.0
182 #  else /* _BSD_CLK_TCK_ */
183 #   define HZ ((double)_BSD_CLK_TCK_)
184 #  endif
185 # else /* CLK_TCK */
186 #  define HZ ((double)CLK_TCK)
187 # endif
188 #endif
189
190 #undef BUFSIZE
191 #define BUFSIZE ((long)1024*8+1)
192 int run=0;
193
194 static double Time_F(int s, int usertime);
195 static void print_message(char *s,long num,int length);
196 static void pkey_print_message(char *str,char *str2,long num,int bits,int sec);
197 #ifdef SIGALRM
198 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
199 #define SIGRETTYPE void
200 #else
201 #define SIGRETTYPE int
202 #endif 
203
204 static SIGRETTYPE sig_done(int sig);
205 static SIGRETTYPE sig_done(int sig)
206         {
207         signal(SIGALRM,sig_done);
208         run=0;
209 #ifdef LINT
210         sig=sig;
211 #endif
212         }
213 #endif
214
215 #define START   0
216 #define STOP    1
217
218 static double Time_F(int s, int usertime)
219         {
220         double ret;
221
222 #ifdef USE_TOD
223         if(usertime)
224             {
225                 static struct rusage tstart,tend;
226
227                 if (s == START)
228                         {
229                         getrusage(RUSAGE_SELF,&tstart);
230                         return(0);
231                         }
232                 else
233                         {
234                         long i;
235
236                         getrusage(RUSAGE_SELF,&tend);
237                         i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
238                         ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
239                           +((double)i)/1000000.0;
240                         return((ret < 0.001)?0.001:ret);
241                         }
242                 }
243         else
244                 {
245                 static struct timeval tstart,tend;
246                 long i;
247
248                 if (s == START)
249                         {
250                         gettimeofday(&tstart,NULL);
251                         return(0);
252                         }
253                 else
254                         {
255                         gettimeofday(&tend,NULL);
256                         i=(long)tend.tv_usec-(long)tstart.tv_usec;
257                         ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
258                         return((ret < 0.001)?0.001:ret);
259                         }
260                 }
261 #else  /* ndef USE_TOD */
262                 
263 # ifdef TIMES
264         if (usertime)
265                 {
266                 static struct tms tstart,tend;
267
268                 if (s == START)
269                         {
270                         times(&tstart);
271                         return(0);
272                         }
273                 else
274                         {
275                         times(&tend);
276                         ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
277                         return((ret < 1e-3)?1e-3:ret);
278                         }
279                 }
280 # endif /* times() */
281 # if defined(TIMES) && defined(TIMEB)
282         else
283 # endif
284 # ifdef TIMEB
285                 {
286                 static struct timeb tstart,tend;
287                 long i;
288
289                 if (s == START)
290                         {
291                         ftime(&tstart);
292                         return(0);
293                         }
294                 else
295                         {
296                         ftime(&tend);
297                         i=(long)tend.millitm-(long)tstart.millitm;
298                         ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
299                         return((ret < 0.001)?0.001:ret);
300                         }
301                 }
302 # endif
303 #endif
304         }
305
306 int MAIN(int, char **);
307
308 int MAIN(int argc, char **argv)
309         {
310         unsigned char *buf=NULL,*buf2=NULL;
311         int mret=1;
312 #define ALGOR_NUM       14
313 #define SIZE_NUM        5
314 #define RSA_NUM         4
315 #define DSA_NUM         3
316         long count,rsa_count;
317         int i,j,k;
318         unsigned rsa_num,rsa_num2;
319 #ifndef NO_MD2
320         unsigned char md2[MD2_DIGEST_LENGTH];
321 #endif
322 #ifndef NO_MDC2
323         unsigned char mdc2[MDC2_DIGEST_LENGTH];
324 #endif
325 #ifndef NO_MD5
326         unsigned char md5[MD5_DIGEST_LENGTH];
327         unsigned char hmac[MD5_DIGEST_LENGTH];
328 #endif
329 #ifndef NO_SHA
330         unsigned char sha[SHA_DIGEST_LENGTH];
331 #endif
332 #ifndef NO_RIPEMD
333         unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
334 #endif
335 #ifndef NO_RC4
336         RC4_KEY rc4_ks;
337 #endif
338 #ifndef NO_RC5
339         RC5_32_KEY rc5_ks;
340 #endif
341 #ifndef NO_RC2
342         RC2_KEY rc2_ks;
343 #endif
344 #ifndef NO_IDEA
345         IDEA_KEY_SCHEDULE idea_ks;
346 #endif
347 #ifndef NO_BF
348         BF_KEY bf_ks;
349 #endif
350 #ifndef NO_CAST
351         CAST_KEY cast_ks;
352 #endif
353         static unsigned char key16[16]=
354                 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
355                  0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
356         unsigned char iv[8];
357 #ifndef NO_DES
358         des_cblock *buf_as_des_cblock = NULL;
359         static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
360         static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
361         static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
362         des_key_schedule sch,sch2,sch3;
363 #endif
364 #define D_MD2           0
365 #define D_MDC2          1
366 #define D_MD5           2
367 #define D_HMAC          3
368 #define D_SHA1          4
369 #define D_RMD160        5
370 #define D_RC4           6
371 #define D_CBC_DES       7
372 #define D_EDE3_DES      8
373 #define D_CBC_IDEA      9
374 #define D_CBC_RC2       10
375 #define D_CBC_RC5       11
376 #define D_CBC_BF        12
377 #define D_CBC_CAST      13
378         double d,results[ALGOR_NUM][SIZE_NUM];
379         static int lengths[SIZE_NUM]={8,64,256,1024,8*1024};
380         long c[ALGOR_NUM][SIZE_NUM];
381         static char *names[ALGOR_NUM]={
382                 "md2","mdc2","md5","hmac(md5)","sha1","rmd160","rc4",
383                 "des cbc","des ede3","idea cbc",
384                 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"};
385 #define R_DSA_512       0
386 #define R_DSA_1024      1
387 #define R_DSA_2048      2
388 #define R_RSA_512       0
389 #define R_RSA_1024      1
390 #define R_RSA_2048      2
391 #define R_RSA_4096      3
392 #ifndef NO_RSA
393         RSA *rsa_key[RSA_NUM];
394         long rsa_c[RSA_NUM][2];
395         double rsa_results[RSA_NUM][2];
396         static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
397         static unsigned char *rsa_data[RSA_NUM]=
398                 {test512,test1024,test2048,test4096};
399         static int rsa_data_length[RSA_NUM]={
400                 sizeof(test512),sizeof(test1024),
401                 sizeof(test2048),sizeof(test4096)};
402 #endif
403 #ifndef NO_DSA
404         DSA *dsa_key[DSA_NUM];
405         long dsa_c[DSA_NUM][2];
406         double dsa_results[DSA_NUM][2];
407         static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
408 #endif
409         int rsa_doit[RSA_NUM];
410         int dsa_doit[DSA_NUM];
411         int doit[ALGOR_NUM];
412         int pr_header=0;
413         int usertime=1;
414
415 #ifndef TIMES
416         usertime=-1;
417 #endif
418
419         apps_startup();
420         memset(results, 0, sizeof(results));
421 #ifndef NO_DSA
422         memset(dsa_key,0,sizeof(dsa_key));
423 #endif
424
425         if (bio_err == NULL)
426                 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
427                         BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
428
429 #ifndef NO_RSA
430         memset(rsa_key,0,sizeof(rsa_key));
431         for (i=0; i<RSA_NUM; i++)
432                 rsa_key[i]=NULL;
433 #endif
434
435         if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
436                 {
437                 BIO_printf(bio_err,"out of memory\n");
438                 goto end;
439                 }
440 #ifndef NO_DES
441         buf_as_des_cblock = (des_cblock *)buf;
442 #endif
443         if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
444                 {
445                 BIO_printf(bio_err,"out of memory\n");
446                 goto end;
447                 }
448
449         memset(c,0,sizeof(c));
450         memset(iv,0,sizeof(iv));
451
452         for (i=0; i<ALGOR_NUM; i++)
453                 doit[i]=0;
454         for (i=0; i<RSA_NUM; i++)
455                 rsa_doit[i]=0;
456         for (i=0; i<DSA_NUM; i++)
457                 dsa_doit[i]=0;
458         
459         j=0;
460         argc--;
461         argv++;
462         while (argc)
463                 {
464                 if      ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
465                         usertime = 0;
466 #ifndef NO_MD2
467                 if      (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
468                 else
469 #endif
470 #ifndef NO_MDC2
471                         if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
472                 else
473 #endif
474 #ifndef NO_MD5
475                         if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
476                 else
477 #endif
478 #ifndef NO_MD5
479                         if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
480                 else
481 #endif
482 #ifndef NO_SHA
483                         if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
484                 else
485                         if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1;
486                 else
487 #endif
488 #ifndef NO_RIPEMD
489                         if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
490                 else
491                         if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
492                 else
493                         if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
494                 else
495 #endif
496 #ifndef NO_RC4
497                         if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
498                 else 
499 #endif
500 #ifndef NO_DES
501                         if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
502                 else    if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
503                 else
504 #endif
505 #ifndef NO_RSA
506 #ifdef RSAref
507                         if (strcmp(*argv,"rsaref") == 0) 
508                         {
509                         RSA_set_default_method(RSA_PKCS1_RSAref());
510                         j--;
511                         }
512                 else
513 #endif
514 #ifndef RSA_NULL
515                         if (strcmp(*argv,"openssl") == 0) 
516                         {
517                         RSA_set_default_method(RSA_PKCS1_SSLeay());
518                         j--;
519                         }
520                 else
521 #endif
522 #endif /* !NO_RSA */
523                      if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
524                 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
525                 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
526                 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
527                 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
528                 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
529                 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
530                 else
531 #ifndef NO_RC2
532                      if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
533                 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
534                 else
535 #endif
536 #ifndef NO_RC5
537                      if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
538                 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
539                 else
540 #endif
541 #ifndef NO_IDEA
542                      if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
543                 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
544                 else
545 #endif
546 #ifndef NO_BF
547                      if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
548                 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
549                 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
550                 else
551 #endif
552 #ifndef NO_CAST
553                      if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
554                 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
555                 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
556                 else
557 #endif
558 #ifndef NO_DES
559                         if (strcmp(*argv,"des") == 0)
560                         {
561                         doit[D_CBC_DES]=1;
562                         doit[D_EDE3_DES]=1;
563                         }
564                 else
565 #endif
566 #ifndef NO_RSA
567                         if (strcmp(*argv,"rsa") == 0)
568                         {
569                         rsa_doit[R_RSA_512]=1;
570                         rsa_doit[R_RSA_1024]=1;
571                         rsa_doit[R_RSA_2048]=1;
572                         rsa_doit[R_RSA_4096]=1;
573                         }
574                 else
575 #endif
576 #ifndef NO_DSA
577                         if (strcmp(*argv,"dsa") == 0)
578                         {
579                         dsa_doit[R_DSA_512]=1;
580                         dsa_doit[R_DSA_1024]=1;
581                         }
582                 else
583 #endif
584                         {
585                         BIO_printf(bio_err,"bad option or value, pick one of\n");
586                         BIO_printf(bio_err,"md2      mdc2       md5      hmac      sha1    rmd160\n");
587 #ifndef NO_IDEA
588                         BIO_printf(bio_err,"idea-cbc ");
589 #endif
590 #ifndef NO_RC2
591                         BIO_printf(bio_err,"rc2-cbc  ");
592 #endif
593 #ifndef NO_RC5
594                         BIO_printf(bio_err,"rc5-cbc  ");
595 #endif
596 #ifndef NO_BF
597                         BIO_printf(bio_err,"bf-cbc");
598 #endif
599 #if !defined(NO_IDEA) && !defined(NO_RC2) && !defined(NO_BF) && !defined(NO_RC5)
600                         BIO_printf(bio_err,"\n");
601 #endif
602                         BIO_printf(bio_err,"des-cbc  des-ede3 ");
603 #ifndef NO_RC4
604                         BIO_printf(bio_err,"rc4");
605 #endif
606 #ifndef NO_RSA
607                         BIO_printf(bio_err,"\nrsa512   rsa1024  rsa2048  rsa4096\n");
608 #endif
609 #ifndef NO_DSA
610                         BIO_printf(bio_err,"\ndsa512   dsa1024  dsa2048\n");
611 #endif
612                         BIO_printf(bio_err,"idea     rc2      des      rsa    blowfish\n");
613                         BIO_printf(bio_err,"\n");
614 #ifdef TIMES
615                         BIO_printf(bio_err,"Available options:\n");
616                         BIO_printf(bio_err,"\n");
617                         BIO_printf(bio_err,"-elapsed        measure time in real time instead of CPU user time.\n");
618 #endif
619                         goto end;
620                         }
621                 argc--;
622                 argv++;
623                 j++;
624                 }
625
626         if (j == 0)
627                 {
628                 for (i=0; i<ALGOR_NUM; i++)
629                         doit[i]=1;
630                 for (i=0; i<RSA_NUM; i++)
631                         rsa_doit[i]=1;
632                 for (i=0; i<DSA_NUM; i++)
633                         dsa_doit[i]=1;
634                 }
635         for (i=0; i<ALGOR_NUM; i++)
636                 if (doit[i]) pr_header++;
637
638         if (usertime == 0)
639                 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
640         if (usertime <= 0)
641                 {
642                 BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
643                 BIO_printf(bio_err,"program when this computer is idle.\n");
644                 }
645
646 #ifndef NO_RSA
647         for (i=0; i<RSA_NUM; i++)
648                 {
649                 unsigned char *p;
650
651                 p=rsa_data[i];
652                 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
653                 if (rsa_key[i] == NULL)
654                         {
655                         BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
656                         goto end;
657                         }
658 #if 0
659                 else
660                         {
661                         BIO_printf(bio_err,"Loaded RSA key, %d bit modulus and e= 0x",BN_num_bits(rsa_key[i]->n));
662                         BN_print(bio_err,rsa_key[i]->e);
663                         BIO_printf(bio_err,"\n");
664                         }
665 #endif
666                 }
667 #endif
668
669 #ifndef NO_DSA
670         dsa_key[0]=get_dsa512();
671         dsa_key[1]=get_dsa1024();
672         dsa_key[2]=get_dsa2048();
673 #endif
674
675 #ifndef NO_DES
676         des_set_key_unchecked(&key,sch);
677         des_set_key_unchecked(&key2,sch2);
678         des_set_key_unchecked(&key3,sch3);
679 #endif
680 #ifndef NO_IDEA
681         idea_set_encrypt_key(key16,&idea_ks);
682 #endif
683 #ifndef NO_RC4
684         RC4_set_key(&rc4_ks,16,key16);
685 #endif
686 #ifndef NO_RC2
687         RC2_set_key(&rc2_ks,16,key16,128);
688 #endif
689 #ifndef NO_RC5
690         RC5_32_set_key(&rc5_ks,16,key16,12);
691 #endif
692 #ifndef NO_BF
693         BF_set_key(&bf_ks,16,key16);
694 #endif
695 #ifndef NO_CAST
696         CAST_set_key(&cast_ks,16,key16);
697 #endif
698 #ifndef NO_RSA
699         memset(rsa_c,0,sizeof(rsa_c));
700 #endif
701 #ifndef SIGALRM
702 #ifndef NO_DES
703         BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
704         count=10;
705         do      {
706                 long i;
707                 count*=2;
708                 Time_F(START,usertime);
709                 for (i=count; i; i--)
710                         des_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
711                                 &(sch[0]),DES_ENCRYPT);
712                 d=Time_F(STOP,usertime);
713                 } while (d <3);
714         c[D_MD2][0]=count/10;
715         c[D_MDC2][0]=count/10;
716         c[D_MD5][0]=count;
717         c[D_HMAC][0]=count;
718         c[D_SHA1][0]=count;
719         c[D_RMD160][0]=count;
720         c[D_RC4][0]=count*5;
721         c[D_CBC_DES][0]=count;
722         c[D_EDE3_DES][0]=count/3;
723         c[D_CBC_IDEA][0]=count;
724         c[D_CBC_RC2][0]=count;
725         c[D_CBC_RC5][0]=count;
726         c[D_CBC_BF][0]=count;
727         c[D_CBC_CAST][0]=count;
728
729         for (i=1; i<SIZE_NUM; i++)
730                 {
731                 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
732                 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
733                 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
734                 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
735                 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
736                 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
737                 }
738         for (i=1; i<SIZE_NUM; i++)
739                 {
740                 long l0,l1;
741
742                 l0=(long)lengths[i-1];
743                 l1=(long)lengths[i];
744                 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
745                 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
746                 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
747                 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
748                 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
749                 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
750                 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
751                 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
752                 }
753 #ifndef NO_RSA
754         rsa_c[R_RSA_512][0]=count/2000;
755         rsa_c[R_RSA_512][1]=count/400;
756         for (i=1; i<RSA_NUM; i++)
757                 {
758                 rsa_c[i][0]=rsa_c[i-1][0]/8;
759                 rsa_c[i][1]=rsa_c[i-1][1]/4;
760                 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
761                         rsa_doit[i]=0;
762                 else
763                         {
764                         if (rsa_c[i][0] == 0)
765                                 {
766                                 rsa_c[i][0]=1;
767                                 rsa_c[i][1]=20;
768                                 }
769                         }                               
770                 }
771 #endif
772
773         dsa_c[R_DSA_512][0]=count/1000;
774         dsa_c[R_DSA_512][1]=count/1000/2;
775         for (i=1; i<DSA_NUM; i++)
776                 {
777                 dsa_c[i][0]=dsa_c[i-1][0]/4;
778                 dsa_c[i][1]=dsa_c[i-1][1]/4;
779                 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
780                         dsa_doit[i]=0;
781                 else
782                         {
783                         if (dsa_c[i] == 0)
784                                 {
785                                 dsa_c[i][0]=1;
786                                 dsa_c[i][1]=1;
787                                 }
788                         }                               
789                 }
790
791 #define COND(d) (count < (d))
792 #define COUNT(d) (d)
793 #else
794 /* not worth fixing */
795 # error "You cannot disable DES on systems without SIGALRM."
796 #endif /* NO_DES */
797 #else
798 #define COND(c) (run)
799 #define COUNT(d) (count)
800         signal(SIGALRM,sig_done);
801 #endif /* SIGALRM */
802
803 #ifndef NO_MD2
804         if (doit[D_MD2])
805                 {
806                 for (j=0; j<SIZE_NUM; j++)
807                         {
808                         print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
809                         Time_F(START,usertime);
810                         for (count=0,run=1; COND(c[D_MD2][j]); count++)
811                                 MD2(buf,(unsigned long)lengths[j],&(md2[0]));
812                         d=Time_F(STOP,usertime);
813                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
814                                 count,names[D_MD2],d);
815                         results[D_MD2][j]=((double)count)/d*lengths[j];
816                         }
817                 }
818 #endif
819 #ifndef NO_MDC2
820         if (doit[D_MDC2])
821                 {
822                 for (j=0; j<SIZE_NUM; j++)
823                         {
824                         print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
825                         Time_F(START,usertime);
826                         for (count=0,run=1; COND(c[D_MDC2][j]); count++)
827                                 MDC2(buf,(unsigned long)lengths[j],&(mdc2[0]));
828                         d=Time_F(STOP,usertime);
829                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
830                                 count,names[D_MDC2],d);
831                         results[D_MDC2][j]=((double)count)/d*lengths[j];
832                         }
833                 }
834 #endif
835
836 #ifndef NO_MD5
837         if (doit[D_MD5])
838                 {
839                 for (j=0; j<SIZE_NUM; j++)
840                         {
841                         print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
842                         Time_F(START,usertime);
843                         for (count=0,run=1; COND(c[D_MD5][j]); count++)
844                                 MD5(&(buf[0]),(unsigned long)lengths[j],&(md5[0]));
845                         d=Time_F(STOP,usertime);
846                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
847                                 count,names[D_MD5],d);
848                         results[D_MD5][j]=((double)count)/d*lengths[j];
849                         }
850                 }
851 #endif
852
853 #if !defined(NO_MD5) && !defined(NO_HMAC)
854         if (doit[D_HMAC])
855                 {
856                 HMAC_CTX hctx;
857                 HMAC_Init(&hctx,(unsigned char *)"This is a key...",
858                         16,EVP_md5());
859
860                 for (j=0; j<SIZE_NUM; j++)
861                         {
862                         print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
863                         Time_F(START,usertime);
864                         for (count=0,run=1; COND(c[D_HMAC][j]); count++)
865                                 {
866                                 HMAC_Init(&hctx,NULL,0,NULL);
867                                 HMAC_Update(&hctx,buf,lengths[j]);
868                                 HMAC_Final(&hctx,&(hmac[0]),NULL);
869                                 }
870                         d=Time_F(STOP,usertime);
871                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
872                                 count,names[D_HMAC],d);
873                         results[D_HMAC][j]=((double)count)/d*lengths[j];
874                         }
875                 }
876 #endif
877 #ifndef NO_SHA
878         if (doit[D_SHA1])
879                 {
880                 for (j=0; j<SIZE_NUM; j++)
881                         {
882                         print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
883                         Time_F(START,usertime);
884                         for (count=0,run=1; COND(c[D_SHA1][j]); count++)
885                                 SHA1(buf,(unsigned long)lengths[j],&(sha[0]));
886                         d=Time_F(STOP,usertime);
887                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
888                                 count,names[D_SHA1],d);
889                         results[D_SHA1][j]=((double)count)/d*lengths[j];
890                         }
891                 }
892 #endif
893 #ifndef NO_RIPEMD
894         if (doit[D_RMD160])
895                 {
896                 for (j=0; j<SIZE_NUM; j++)
897                         {
898                         print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
899                         Time_F(START,usertime);
900                         for (count=0,run=1; COND(c[D_RMD160][j]); count++)
901                                 RIPEMD160(buf,(unsigned long)lengths[j],&(rmd160[0]));
902                         d=Time_F(STOP,usertime);
903                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
904                                 count,names[D_RMD160],d);
905                         results[D_RMD160][j]=((double)count)/d*lengths[j];
906                         }
907                 }
908 #endif
909 #ifndef NO_RC4
910         if (doit[D_RC4])
911                 {
912                 for (j=0; j<SIZE_NUM; j++)
913                         {
914                         print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
915                         Time_F(START,usertime);
916                         for (count=0,run=1; COND(c[D_RC4][j]); count++)
917                                 RC4(&rc4_ks,(unsigned int)lengths[j],
918                                         buf,buf);
919                         d=Time_F(STOP,usertime);
920                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
921                                 count,names[D_RC4],d);
922                         results[D_RC4][j]=((double)count)/d*lengths[j];
923                         }
924                 }
925 #endif
926 #ifndef NO_DES
927         if (doit[D_CBC_DES])
928                 {
929                 for (j=0; j<SIZE_NUM; j++)
930                         {
931                         print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
932                         Time_F(START,usertime);
933                         for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
934                                 des_ncbc_encrypt(buf,buf,lengths[j],sch,
935                                                  &iv,DES_ENCRYPT);
936                         d=Time_F(STOP,usertime);
937                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
938                                 count,names[D_CBC_DES],d);
939                         results[D_CBC_DES][j]=((double)count)/d*lengths[j];
940                         }
941                 }
942
943         if (doit[D_EDE3_DES])
944                 {
945                 for (j=0; j<SIZE_NUM; j++)
946                         {
947                         print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
948                         Time_F(START,usertime);
949                         for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
950                                 des_ede3_cbc_encrypt(buf,buf,lengths[j],
951                                                      sch,sch2,sch3,
952                                                      &iv,DES_ENCRYPT);
953                         d=Time_F(STOP,usertime);
954                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
955                                 count,names[D_EDE3_DES],d);
956                         results[D_EDE3_DES][j]=((double)count)/d*lengths[j];
957                         }
958                 }
959 #endif
960 #ifndef NO_IDEA
961         if (doit[D_CBC_IDEA])
962                 {
963                 for (j=0; j<SIZE_NUM; j++)
964                         {
965                         print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
966                         Time_F(START,usertime);
967                         for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
968                                 idea_cbc_encrypt(buf,buf,
969                                         (unsigned long)lengths[j],&idea_ks,
970                                         iv,IDEA_ENCRYPT);
971                         d=Time_F(STOP,usertime);
972                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
973                                 count,names[D_CBC_IDEA],d);
974                         results[D_CBC_IDEA][j]=((double)count)/d*lengths[j];
975                         }
976                 }
977 #endif
978 #ifndef NO_RC2
979         if (doit[D_CBC_RC2])
980                 {
981                 for (j=0; j<SIZE_NUM; j++)
982                         {
983                         print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
984                         Time_F(START,usertime);
985                         for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
986                                 RC2_cbc_encrypt(buf,buf,
987                                         (unsigned long)lengths[j],&rc2_ks,
988                                         iv,RC2_ENCRYPT);
989                         d=Time_F(STOP,usertime);
990                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
991                                 count,names[D_CBC_RC2],d);
992                         results[D_CBC_RC2][j]=((double)count)/d*lengths[j];
993                         }
994                 }
995 #endif
996 #ifndef NO_RC5
997         if (doit[D_CBC_RC5])
998                 {
999                 for (j=0; j<SIZE_NUM; j++)
1000                         {
1001                         print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1002                         Time_F(START,usertime);
1003                         for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1004                                 RC5_32_cbc_encrypt(buf,buf,
1005                                         (unsigned long)lengths[j],&rc5_ks,
1006                                         iv,RC5_ENCRYPT);
1007                         d=Time_F(STOP,usertime);
1008                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
1009                                 count,names[D_CBC_RC5],d);
1010                         results[D_CBC_RC5][j]=((double)count)/d*lengths[j];
1011                         }
1012                 }
1013 #endif
1014 #ifndef NO_BF
1015         if (doit[D_CBC_BF])
1016                 {
1017                 for (j=0; j<SIZE_NUM; j++)
1018                         {
1019                         print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1020                         Time_F(START,usertime);
1021                         for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1022                                 BF_cbc_encrypt(buf,buf,
1023                                         (unsigned long)lengths[j],&bf_ks,
1024                                         iv,BF_ENCRYPT);
1025                         d=Time_F(STOP,usertime);
1026                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
1027                                 count,names[D_CBC_BF],d);
1028                         results[D_CBC_BF][j]=((double)count)/d*lengths[j];
1029                         }
1030                 }
1031 #endif
1032 #ifndef NO_CAST
1033         if (doit[D_CBC_CAST])
1034                 {
1035                 for (j=0; j<SIZE_NUM; j++)
1036                         {
1037                         print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1038                         Time_F(START,usertime);
1039                         for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1040                                 CAST_cbc_encrypt(buf,buf,
1041                                         (unsigned long)lengths[j],&cast_ks,
1042                                         iv,CAST_ENCRYPT);
1043                         d=Time_F(STOP,usertime);
1044                         BIO_printf(bio_err,"%ld %s's in %.2fs\n",
1045                                 count,names[D_CBC_CAST],d);
1046                         results[D_CBC_CAST][j]=((double)count)/d*lengths[j];
1047                         }
1048                 }
1049 #endif
1050
1051         RAND_pseudo_bytes(buf,36);
1052 #ifndef NO_RSA
1053         for (j=0; j<RSA_NUM; j++)
1054                 {
1055                 int ret;
1056                 if (!rsa_doit[j]) continue;
1057                 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
1058                 pkey_print_message("private","rsa",rsa_c[j][0],rsa_bits[j],
1059                         RSA_SECONDS);
1060 /*              RSA_blinding_on(rsa_key[j],NULL); */
1061                 Time_F(START,usertime);
1062                 for (count=0,run=1; COND(rsa_c[j][0]); count++)
1063                         {
1064                         ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num,
1065                                                                  rsa_key[j]);
1066                         if (ret <= 0)
1067                                 {
1068                                 BIO_printf(bio_err,"RSA private encrypt failure\n");
1069                                 ERR_print_errors(bio_err);
1070                                 count=1;
1071                                 break;
1072                                 }
1073                         }
1074                 d=Time_F(STOP,usertime);
1075                 BIO_printf(bio_err,"%ld %d bit private RSA's in %.2fs\n",
1076                         count,rsa_bits[j],d);
1077                 rsa_results[j][0]=d/(double)count;
1078                 rsa_count=count;
1079
1080 #if 1
1081                 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
1082                 pkey_print_message("public","rsa",rsa_c[j][1],rsa_bits[j],
1083                         RSA_SECONDS);
1084                 Time_F(START,usertime);
1085                 for (count=0,run=1; COND(rsa_c[j][1]); count++)
1086                         {
1087                         ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num,
1088                                                                 rsa_key[j]);
1089                         if (ret <= 0)
1090                                 {
1091                                 BIO_printf(bio_err,"RSA verify failure\n");
1092                                 ERR_print_errors(bio_err);
1093                                 count=1;
1094                                 break;
1095                                 }
1096                         }
1097                 d=Time_F(STOP,usertime);
1098                 BIO_printf(bio_err,"%ld %d bit public RSA's in %.2fs\n",
1099                         count,rsa_bits[j],d);
1100                 rsa_results[j][1]=d/(double)count;
1101 #endif
1102
1103                 if (rsa_count <= 1)
1104                         {
1105                         /* if longer than 10s, don't do any more */
1106                         for (j++; j<RSA_NUM; j++)
1107                                 rsa_doit[j]=0;
1108                         }
1109                 }
1110 #endif
1111
1112         RAND_pseudo_bytes(buf,20);
1113 #ifndef NO_DSA
1114         if (RAND_status() != 1)
1115                 {
1116                 RAND_seed(rnd_seed, sizeof rnd_seed);
1117                 rnd_fake = 1;
1118                 }
1119         for (j=0; j<DSA_NUM; j++)
1120                 {
1121                 unsigned int kk;
1122
1123                 if (!dsa_doit[j]) continue;
1124                 DSA_generate_key(dsa_key[j]);
1125 /*              DSA_sign_setup(dsa_key[j],NULL); */
1126                 rsa_num=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
1127                         &kk,dsa_key[j]);
1128                 pkey_print_message("sign","dsa",dsa_c[j][0],dsa_bits[j],
1129                         DSA_SECONDS);
1130                 Time_F(START,usertime);
1131                 for (count=0,run=1; COND(dsa_c[j][0]); count++)
1132                         {
1133                         rsa_num=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
1134                                 &kk,dsa_key[j]);
1135                         if (rsa_num == 0)
1136                                 {
1137                                 BIO_printf(bio_err,"DSA sign failure\n");
1138                                 ERR_print_errors(bio_err);
1139                                 count=1;
1140                                 break;
1141                                 }
1142                         }
1143                 d=Time_F(STOP,usertime);
1144                 BIO_printf(bio_err,"%ld %d bit DSA signs in %.2fs\n",
1145                         count,dsa_bits[j],d);
1146                 dsa_results[j][0]=d/(double)count;
1147                 rsa_count=count;
1148
1149                 rsa_num2=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
1150                         kk,dsa_key[j]);
1151                 pkey_print_message("verify","dsa",dsa_c[j][1],dsa_bits[j],
1152                         DSA_SECONDS);
1153                 Time_F(START,usertime);
1154                 for (count=0,run=1; COND(dsa_c[j][1]); count++)
1155                         {
1156                         rsa_num2=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
1157                                 kk,dsa_key[j]);
1158                         if (rsa_num2 == 0)
1159                                 {
1160                                 BIO_printf(bio_err,"DSA verify failure\n");
1161                                 ERR_print_errors(bio_err);
1162                                 count=1;
1163                                 break;
1164                                 }
1165                         }
1166                 d=Time_F(STOP,usertime);
1167                 BIO_printf(bio_err,"%ld %d bit DSA verify in %.2fs\n",
1168                         count,dsa_bits[j],d);
1169                 dsa_results[j][1]=d/(double)count;
1170
1171                 if (rsa_count <= 1)
1172                         {
1173                         /* if longer than 10s, don't do any more */
1174                         for (j++; j<DSA_NUM; j++)
1175                                 dsa_doit[j]=0;
1176                         }
1177                 }
1178         if (rnd_fake) RAND_cleanup();
1179 #endif
1180
1181         fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
1182         fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
1183         printf("options:");
1184         printf("%s ",BN_options());
1185 #ifndef NO_MD2
1186         printf("%s ",MD2_options());
1187 #endif
1188 #ifndef NO_RC4
1189         printf("%s ",RC4_options());
1190 #endif
1191 #ifndef NO_DES
1192         printf("%s ",des_options());
1193 #endif
1194 #ifndef NO_IDEA
1195         printf("%s ",idea_options());
1196 #endif
1197 #ifndef NO_BF
1198         printf("%s ",BF_options());
1199 #endif
1200         fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
1201
1202         if (pr_header)
1203                 {
1204                 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n"); 
1205                 fprintf(stdout,"type        ");
1206                 for (j=0;  j<SIZE_NUM; j++)
1207                         fprintf(stdout,"%7d bytes",lengths[j]);
1208                 fprintf(stdout,"\n");
1209                 }
1210
1211         for (k=0; k<ALGOR_NUM; k++)
1212                 {
1213                 if (!doit[k]) continue;
1214                 fprintf(stdout,"%-13s",names[k]);
1215                 for (j=0; j<SIZE_NUM; j++)
1216                         {
1217                         if (results[k][j] > 10000)
1218                                 fprintf(stdout," %11.2fk",results[k][j]/1e3);
1219                         else
1220                                 fprintf(stdout," %11.2f ",results[k][j]);
1221                         }
1222                 fprintf(stdout,"\n");
1223                 }
1224 #ifndef NO_RSA
1225         j=1;
1226         for (k=0; k<RSA_NUM; k++)
1227                 {
1228                 if (!rsa_doit[k]) continue;
1229                 if (j)
1230                         {
1231                         printf("%18ssign    verify    sign/s verify/s\n"," ");
1232                         j=0;
1233                         }
1234                 fprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f",
1235                         rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
1236                         1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
1237                 fprintf(stdout,"\n");
1238                 }
1239 #endif
1240 #ifndef NO_DSA
1241         j=1;
1242         for (k=0; k<DSA_NUM; k++)
1243                 {
1244                 if (!dsa_doit[k]) continue;
1245                 if (j)  {
1246                         printf("%18ssign    verify    sign/s verify/s\n"," ");
1247                         j=0;
1248                         }
1249                 fprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f",
1250                         dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
1251                         1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
1252                 fprintf(stdout,"\n");
1253                 }
1254 #endif
1255         mret=0;
1256 end:
1257         if (buf != NULL) OPENSSL_free(buf);
1258         if (buf2 != NULL) OPENSSL_free(buf2);
1259 #ifndef NO_RSA
1260         for (i=0; i<RSA_NUM; i++)
1261                 if (rsa_key[i] != NULL)
1262                         RSA_free(rsa_key[i]);
1263 #endif
1264 #ifndef NO_DSA
1265         for (i=0; i<DSA_NUM; i++)
1266                 if (dsa_key[i] != NULL)
1267                         DSA_free(dsa_key[i]);
1268 #endif
1269         EXIT(mret);
1270         }
1271
1272 static void print_message(char *s, long num, int length)
1273         {
1274 #ifdef SIGALRM
1275         BIO_printf(bio_err,"Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
1276         (void)BIO_flush(bio_err);
1277         alarm(SECONDS);
1278 #else
1279         BIO_printf(bio_err,"Doing %s %ld times on %d size blocks: ",s,num,length);
1280         (void)BIO_flush(bio_err);
1281 #endif
1282 #ifdef LINT
1283         num=num;
1284 #endif
1285         }
1286
1287 static void pkey_print_message(char *str, char *str2, long num, int bits,
1288              int tm)
1289         {
1290 #ifdef SIGALRM
1291         BIO_printf(bio_err,"Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
1292         (void)BIO_flush(bio_err);
1293         alarm(RSA_SECONDS);
1294 #else
1295         BIO_printf(bio_err,"Doing %ld %d bit %s %s's: ",num,bits,str,str2);
1296         (void)BIO_flush(bio_err);
1297 #endif
1298 #ifdef LINT
1299         num=num;
1300 #endif
1301         }
1302