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