xref: /onnv-gate/usr/src/common/openssl/apps/speed.c (revision 2139:6243c3338933)
10Sstevel@tonic-gate /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate  * All rights reserved.
40Sstevel@tonic-gate  *
50Sstevel@tonic-gate  * This package is an SSL implementation written
60Sstevel@tonic-gate  * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate  * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate  * the following conditions are aheared to.  The following conditions
110Sstevel@tonic-gate  * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
130Sstevel@tonic-gate  * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate  *
160Sstevel@tonic-gate  * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate  * the code are not to be removed.
180Sstevel@tonic-gate  * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate  * as the author of the parts of the library used.
200Sstevel@tonic-gate  * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate  * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate  *
230Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate  * are met:
260Sstevel@tonic-gate  * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate  *    must display the following acknowledgement:
330Sstevel@tonic-gate  *    "This product includes cryptographic software written by
340Sstevel@tonic-gate  *     Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate  *    The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate  *    being used are not cryptographic related :-).
370Sstevel@tonic-gate  * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate  *    the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate  * SUCH DAMAGE.
520Sstevel@tonic-gate  *
530Sstevel@tonic-gate  * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate  * derivative of this code cannot be changed.  i.e. this code cannot simply be
550Sstevel@tonic-gate  * copied and put under another distribution licence
560Sstevel@tonic-gate  * [including the GNU Public Licence.]
570Sstevel@tonic-gate  */
58*2139Sjp161948 /* ====================================================================
59*2139Sjp161948  * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60*2139Sjp161948  *
61*2139Sjp161948  * Portions of the attached software ("Contribution") are developed by
62*2139Sjp161948  * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63*2139Sjp161948  *
64*2139Sjp161948  * The Contribution is licensed pursuant to the OpenSSL open source
65*2139Sjp161948  * license provided above.
66*2139Sjp161948  *
67*2139Sjp161948  * The ECDH and ECDSA speed test software is originally written by
68*2139Sjp161948  * Sumit Gupta of Sun Microsystems Laboratories.
69*2139Sjp161948  *
70*2139Sjp161948  */
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * The portions of this code that are #ifdef SOLARIS_OPENSSL are
730Sstevel@tonic-gate  *
74*2139Sjp161948  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
750Sstevel@tonic-gate  * Use is subject to license terms.
760Sstevel@tonic-gate  *
770Sstevel@tonic-gate  */
78*2139Sjp161948 
790Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
800Sstevel@tonic-gate 
810Sstevel@tonic-gate /* most of this code has been pilfered from my libdes speed.c program */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate #ifndef OPENSSL_NO_SPEED
840Sstevel@tonic-gate 
850Sstevel@tonic-gate #undef SECONDS
860Sstevel@tonic-gate #define SECONDS		3
870Sstevel@tonic-gate #define RSA_SECONDS	10
880Sstevel@tonic-gate #define DSA_SECONDS	10
89*2139Sjp161948 #define ECDSA_SECONDS   10
90*2139Sjp161948 #define ECDH_SECONDS    10
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /* 11-Sep-92 Andrew Daviel   Support for Silicon Graphics IRIX added */
930Sstevel@tonic-gate /* 06-Apr-92 Luke Brennan    Support for VMS and add extra signal calls */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate #undef PROG
960Sstevel@tonic-gate #define PROG speed_main
970Sstevel@tonic-gate 
980Sstevel@tonic-gate #include <stdio.h>
990Sstevel@tonic-gate #include <stdlib.h>
100*2139Sjp161948 
1010Sstevel@tonic-gate #include <string.h>
1020Sstevel@tonic-gate #include <math.h>
1030Sstevel@tonic-gate #include "apps.h"
1040Sstevel@tonic-gate #ifdef OPENSSL_NO_STDIO
1050Sstevel@tonic-gate #define APPS_WIN16
1060Sstevel@tonic-gate #endif
1070Sstevel@tonic-gate #include <openssl/crypto.h>
1080Sstevel@tonic-gate #include <openssl/rand.h>
1090Sstevel@tonic-gate #include <openssl/err.h>
1100Sstevel@tonic-gate #include <openssl/evp.h>
1110Sstevel@tonic-gate #include <openssl/objects.h>
1120Sstevel@tonic-gate #if !defined(OPENSSL_SYS_MSDOS)
1130Sstevel@tonic-gate #include OPENSSL_UNISTD
1140Sstevel@tonic-gate #endif
1150Sstevel@tonic-gate #ifdef SOLARIS_OPENSSL
116688Sjp161948 extern int SUNWcry_installed;
1170Sstevel@tonic-gate #endif
1180Sstevel@tonic-gate 
119*2139Sjp161948 #ifndef OPENSSL_SYS_NETWARE
120*2139Sjp161948 #include <signal.h>
121*2139Sjp161948 #endif
122*2139Sjp161948 
1230Sstevel@tonic-gate #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
1240Sstevel@tonic-gate # define USE_TOD
1250Sstevel@tonic-gate #elif !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
1260Sstevel@tonic-gate # define TIMES
1270Sstevel@tonic-gate #endif
1280Sstevel@tonic-gate #if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) && !defined(OPENSSL_SYS_VXWORKS) /* FIXME */
1290Sstevel@tonic-gate # define TIMEB
1300Sstevel@tonic-gate #endif
1310Sstevel@tonic-gate 
132*2139Sjp161948 #if defined(OPENSSL_SYS_NETWARE)
133*2139Sjp161948 #undef TIMES
134*2139Sjp161948 #undef TIMEB
135*2139Sjp161948 #include <time.h>
136*2139Sjp161948 #endif
137*2139Sjp161948 
1380Sstevel@tonic-gate #ifndef _IRIX
1390Sstevel@tonic-gate # include <time.h>
1400Sstevel@tonic-gate #endif
1410Sstevel@tonic-gate #ifdef TIMES
1420Sstevel@tonic-gate # include <sys/types.h>
1430Sstevel@tonic-gate # include <sys/times.h>
1440Sstevel@tonic-gate #endif
1450Sstevel@tonic-gate #ifdef USE_TOD
1460Sstevel@tonic-gate # include <sys/time.h>
1470Sstevel@tonic-gate # include <sys/resource.h>
1480Sstevel@tonic-gate #endif
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /* Depending on the VMS version, the tms structure is perhaps defined.
1510Sstevel@tonic-gate    The __TMS macro will show if it was.  If it wasn't defined, we should
1520Sstevel@tonic-gate    undefine TIMES, since that tells the rest of the program how things
1530Sstevel@tonic-gate    should be handled.				-- Richard Levitte */
1540Sstevel@tonic-gate #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
1550Sstevel@tonic-gate #undef TIMES
1560Sstevel@tonic-gate #endif
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate #ifdef TIMEB
1590Sstevel@tonic-gate #include <sys/timeb.h>
1600Sstevel@tonic-gate #endif
1610Sstevel@tonic-gate 
162*2139Sjp161948 #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD) && !defined(OPENSSL_SYS_VXWORKS) && !defined(OPENSSL_SYS_NETWARE)
1630Sstevel@tonic-gate #error "It seems neither struct tms nor struct timeb is supported in this platform!"
1640Sstevel@tonic-gate #endif
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate #if defined(sun) || defined(__ultrix)
1670Sstevel@tonic-gate #define _POSIX_SOURCE
1680Sstevel@tonic-gate #include <limits.h>
1690Sstevel@tonic-gate #include <sys/param.h>
1700Sstevel@tonic-gate #endif
1710Sstevel@tonic-gate 
172*2139Sjp161948 #include <openssl/bn.h>
1730Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
1740Sstevel@tonic-gate #include <openssl/des.h>
1750Sstevel@tonic-gate #endif
1760Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
1770Sstevel@tonic-gate #include <openssl/aes.h>
1780Sstevel@tonic-gate #endif
1790Sstevel@tonic-gate #ifndef OPENSSL_NO_MD2
1800Sstevel@tonic-gate #include <openssl/md2.h>
1810Sstevel@tonic-gate #endif
1820Sstevel@tonic-gate #ifndef OPENSSL_NO_MDC2
1830Sstevel@tonic-gate #include <openssl/mdc2.h>
1840Sstevel@tonic-gate #endif
1850Sstevel@tonic-gate #ifndef OPENSSL_NO_MD4
1860Sstevel@tonic-gate #include <openssl/md4.h>
1870Sstevel@tonic-gate #endif
1880Sstevel@tonic-gate #ifndef OPENSSL_NO_MD5
1890Sstevel@tonic-gate #include <openssl/md5.h>
1900Sstevel@tonic-gate #endif
1910Sstevel@tonic-gate #ifndef OPENSSL_NO_HMAC
1920Sstevel@tonic-gate #include <openssl/hmac.h>
1930Sstevel@tonic-gate #endif
1940Sstevel@tonic-gate #include <openssl/evp.h>
1950Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA
1960Sstevel@tonic-gate #include <openssl/sha.h>
1970Sstevel@tonic-gate #endif
1980Sstevel@tonic-gate #ifndef OPENSSL_NO_RIPEMD
1990Sstevel@tonic-gate #include <openssl/ripemd.h>
2000Sstevel@tonic-gate #endif
2010Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
2020Sstevel@tonic-gate #include <openssl/rc4.h>
2030Sstevel@tonic-gate #endif
2040Sstevel@tonic-gate #ifndef OPENSSL_NO_RC5
2050Sstevel@tonic-gate #include <openssl/rc5.h>
2060Sstevel@tonic-gate #endif
2070Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
2080Sstevel@tonic-gate #include <openssl/rc2.h>
2090Sstevel@tonic-gate #endif
2100Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
2110Sstevel@tonic-gate #include <openssl/idea.h>
2120Sstevel@tonic-gate #endif
2130Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
2140Sstevel@tonic-gate #include <openssl/blowfish.h>
2150Sstevel@tonic-gate #endif
2160Sstevel@tonic-gate #ifndef OPENSSL_NO_CAST
2170Sstevel@tonic-gate #include <openssl/cast.h>
2180Sstevel@tonic-gate #endif
2190Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
2200Sstevel@tonic-gate #include <openssl/rsa.h>
2210Sstevel@tonic-gate #include "./testrsa.h"
2220Sstevel@tonic-gate #endif
2230Sstevel@tonic-gate #include <openssl/x509.h>
2240Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
225*2139Sjp161948 #include <openssl/dsa.h>
2260Sstevel@tonic-gate #include "./testdsa.h"
2270Sstevel@tonic-gate #endif
228*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
229*2139Sjp161948 #include <openssl/ecdsa.h>
230*2139Sjp161948 #endif
231*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
232*2139Sjp161948 #include <openssl/ecdh.h>
233*2139Sjp161948 #endif
234*2139Sjp161948 
235*2139Sjp161948 /*
236*2139Sjp161948  * The following "HZ" timing stuff should be sync'd up with the code in
237*2139Sjp161948  * crypto/tmdiff.[ch]. That appears to try to do the same job, though I think
238*2139Sjp161948  * this code is more up to date than libcrypto's so there may be features to
239*2139Sjp161948  * migrate over first. This is used in two places further down AFAICS.
240*2139Sjp161948  * The point is that nothing in openssl actually *uses* that tmdiff stuff, so
241*2139Sjp161948  * either speed.c should be using it or it should go because it's obviously not
242*2139Sjp161948  * useful enough. Anyone want to do a janitorial job on this?
243*2139Sjp161948  */
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate /* The following if from times(3) man page.  It may need to be changed */
2460Sstevel@tonic-gate #ifndef HZ
2470Sstevel@tonic-gate # if defined(_SC_CLK_TCK) \
2480Sstevel@tonic-gate      && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
249*2139Sjp161948 #  define HZ sysconf(_SC_CLK_TCK)
2500Sstevel@tonic-gate # else
2510Sstevel@tonic-gate #  ifndef CLK_TCK
2520Sstevel@tonic-gate #   ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
2530Sstevel@tonic-gate #    define HZ	100.0
2540Sstevel@tonic-gate #   else /* _BSD_CLK_TCK_ */
2550Sstevel@tonic-gate #    define HZ ((double)_BSD_CLK_TCK_)
2560Sstevel@tonic-gate #   endif
2570Sstevel@tonic-gate #  else /* CLK_TCK */
2580Sstevel@tonic-gate #   define HZ ((double)CLK_TCK)
2590Sstevel@tonic-gate #  endif
2600Sstevel@tonic-gate # endif
2610Sstevel@tonic-gate #endif
2620Sstevel@tonic-gate 
263*2139Sjp161948 #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE)
2640Sstevel@tonic-gate # define HAVE_FORK 1
2650Sstevel@tonic-gate #endif
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate #undef BUFSIZE
2680Sstevel@tonic-gate #define BUFSIZE	((long)1024*8+1)
2690Sstevel@tonic-gate int run=0;
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0;
2720Sstevel@tonic-gate static int mr=0;
2730Sstevel@tonic-gate static int usertime=1;
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate static double Time_F(int s);
2760Sstevel@tonic-gate static void print_message(const char *s,long num,int length);
277*2139Sjp161948 static void pkey_print_message(const char *str, const char *str2,
278*2139Sjp161948 	long num, int bits, int sec);
2790Sstevel@tonic-gate static void print_result(int alg,int run_no,int count,double time_used);
2800Sstevel@tonic-gate #ifdef HAVE_FORK
2810Sstevel@tonic-gate static int do_multi(int multi);
2820Sstevel@tonic-gate #endif
2830Sstevel@tonic-gate 
284*2139Sjp161948 #define ALGOR_NUM	21
2850Sstevel@tonic-gate #define SIZE_NUM	5
2860Sstevel@tonic-gate #define RSA_NUM		4
2870Sstevel@tonic-gate #define DSA_NUM		3
288*2139Sjp161948 
289*2139Sjp161948 #define EC_NUM       16
290*2139Sjp161948 #define MAX_ECDH_SIZE 256
291*2139Sjp161948 
2920Sstevel@tonic-gate static const char *names[ALGOR_NUM]={
2930Sstevel@tonic-gate   "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
2940Sstevel@tonic-gate   "des cbc","des ede3","idea cbc",
2950Sstevel@tonic-gate   "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc",
296*2139Sjp161948   "aes-128 cbc","aes-192 cbc","aes-256 cbc","evp","sha256","sha512"};
2970Sstevel@tonic-gate static double results[ALGOR_NUM][SIZE_NUM];
2980Sstevel@tonic-gate static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
2990Sstevel@tonic-gate static double rsa_results[RSA_NUM][2];
3000Sstevel@tonic-gate static double dsa_results[DSA_NUM][2];
301*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
302*2139Sjp161948 static double ecdsa_results[EC_NUM][2];
303*2139Sjp161948 #endif
304*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
305*2139Sjp161948 static double ecdh_results[EC_NUM][1];
306*2139Sjp161948 #endif
307*2139Sjp161948 
308*2139Sjp161948 #if defined(OPENSSL_NO_DSA) && !(defined(OPENSSL_NO_ECDSA) && defined(OPENSSL_NO_ECDH))
309*2139Sjp161948 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
310*2139Sjp161948 static int rnd_fake = 0;
311*2139Sjp161948 #endif
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate #ifdef SIGALRM
3140Sstevel@tonic-gate #if defined(__STDC__) || defined(sgi) || defined(_AIX)
3150Sstevel@tonic-gate #define SIGRETTYPE void
3160Sstevel@tonic-gate #else
3170Sstevel@tonic-gate #define SIGRETTYPE int
3180Sstevel@tonic-gate #endif
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate static SIGRETTYPE sig_done(int sig);
3210Sstevel@tonic-gate static SIGRETTYPE sig_done(int sig)
3220Sstevel@tonic-gate 	{
3230Sstevel@tonic-gate 	signal(SIGALRM,sig_done);
3240Sstevel@tonic-gate 	run=0;
3250Sstevel@tonic-gate #ifdef LINT
3260Sstevel@tonic-gate 	sig=sig;
3270Sstevel@tonic-gate #endif
3280Sstevel@tonic-gate 	}
3290Sstevel@tonic-gate #endif
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate #define START	0
3320Sstevel@tonic-gate #define STOP	1
3330Sstevel@tonic-gate 
334*2139Sjp161948 #if defined(OPENSSL_SYS_NETWARE)
335*2139Sjp161948 
336*2139Sjp161948    /* for NetWare the best we can do is use clock() which returns the
337*2139Sjp161948     * time, in hundredths of a second, since the NLM began executing
338*2139Sjp161948    */
339*2139Sjp161948 static double Time_F(int s)
340*2139Sjp161948 	{
341*2139Sjp161948 	double ret;
342*2139Sjp161948 
343*2139Sjp161948    static clock_t tstart,tend;
344*2139Sjp161948 
345*2139Sjp161948    if (s == START)
346*2139Sjp161948    {
347*2139Sjp161948       tstart=clock();
348*2139Sjp161948       return(0);
349*2139Sjp161948    }
350*2139Sjp161948    else
351*2139Sjp161948    {
352*2139Sjp161948       tend=clock();
353*2139Sjp161948       ret=(double)((double)(tend)-(double)(tstart));
354*2139Sjp161948       return((ret < 0.001)?0.001:ret);
355*2139Sjp161948    }
356*2139Sjp161948    }
357*2139Sjp161948 
358*2139Sjp161948 #else
359*2139Sjp161948 
3600Sstevel@tonic-gate static double Time_F(int s)
3610Sstevel@tonic-gate 	{
3620Sstevel@tonic-gate 	double ret;
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate #ifdef USE_TOD
3650Sstevel@tonic-gate 	if(usertime)
366*2139Sjp161948 		{
3670Sstevel@tonic-gate 		static struct rusage tstart,tend;
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 		getrusage_used = 1;
3700Sstevel@tonic-gate 		if (s == START)
3710Sstevel@tonic-gate 			{
3720Sstevel@tonic-gate 			getrusage(RUSAGE_SELF,&tstart);
3730Sstevel@tonic-gate 			return(0);
3740Sstevel@tonic-gate 			}
3750Sstevel@tonic-gate 		else
3760Sstevel@tonic-gate 			{
3770Sstevel@tonic-gate 			long i;
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 			getrusage(RUSAGE_SELF,&tend);
3800Sstevel@tonic-gate 			i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
3810Sstevel@tonic-gate 			ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
3820Sstevel@tonic-gate 			  +((double)i)/1000000.0;
3830Sstevel@tonic-gate 			return((ret < 0.001)?0.001:ret);
3840Sstevel@tonic-gate 			}
3850Sstevel@tonic-gate 		}
3860Sstevel@tonic-gate 	else
3870Sstevel@tonic-gate 		{
3880Sstevel@tonic-gate 		static struct timeval tstart,tend;
3890Sstevel@tonic-gate 		long i;
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 		gettimeofday_used = 1;
3920Sstevel@tonic-gate 		if (s == START)
3930Sstevel@tonic-gate 			{
3940Sstevel@tonic-gate 			gettimeofday(&tstart,NULL);
3950Sstevel@tonic-gate 			return(0);
3960Sstevel@tonic-gate 			}
3970Sstevel@tonic-gate 		else
3980Sstevel@tonic-gate 			{
3990Sstevel@tonic-gate 			gettimeofday(&tend,NULL);
4000Sstevel@tonic-gate 			i=(long)tend.tv_usec-(long)tstart.tv_usec;
4010Sstevel@tonic-gate 			ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
4020Sstevel@tonic-gate 			return((ret < 0.001)?0.001:ret);
4030Sstevel@tonic-gate 			}
4040Sstevel@tonic-gate 		}
4050Sstevel@tonic-gate #else  /* ndef USE_TOD */
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate # ifdef TIMES
4080Sstevel@tonic-gate 	if (usertime)
4090Sstevel@tonic-gate 		{
4100Sstevel@tonic-gate 		static struct tms tstart,tend;
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate 		times_used = 1;
4130Sstevel@tonic-gate 		if (s == START)
4140Sstevel@tonic-gate 			{
4150Sstevel@tonic-gate 			times(&tstart);
4160Sstevel@tonic-gate 			return(0);
4170Sstevel@tonic-gate 			}
4180Sstevel@tonic-gate 		else
4190Sstevel@tonic-gate 			{
4200Sstevel@tonic-gate 			times(&tend);
421*2139Sjp161948 			ret = HZ;
422*2139Sjp161948 			ret=(double)(tend.tms_utime-tstart.tms_utime) / ret;
4230Sstevel@tonic-gate 			return((ret < 1e-3)?1e-3:ret);
4240Sstevel@tonic-gate 			}
4250Sstevel@tonic-gate 		}
4260Sstevel@tonic-gate # endif /* times() */
4270Sstevel@tonic-gate # if defined(TIMES) && defined(TIMEB)
4280Sstevel@tonic-gate 	else
4290Sstevel@tonic-gate # endif
4300Sstevel@tonic-gate # ifdef OPENSSL_SYS_VXWORKS
4310Sstevel@tonic-gate                 {
4320Sstevel@tonic-gate 		static unsigned long tick_start, tick_end;
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate 		if( s == START )
4350Sstevel@tonic-gate 			{
4360Sstevel@tonic-gate 			tick_start = tickGet();
4370Sstevel@tonic-gate 			return 0;
4380Sstevel@tonic-gate 			}
4390Sstevel@tonic-gate 		else
4400Sstevel@tonic-gate 			{
4410Sstevel@tonic-gate 			tick_end = tickGet();
4420Sstevel@tonic-gate 			ret = (double)(tick_end - tick_start) / (double)sysClkRateGet();
4430Sstevel@tonic-gate 			return((ret < 0.001)?0.001:ret);
4440Sstevel@tonic-gate 			}
4450Sstevel@tonic-gate                 }
4460Sstevel@tonic-gate # elif defined(TIMEB)
4470Sstevel@tonic-gate 		{
4480Sstevel@tonic-gate 		static struct timeb tstart,tend;
4490Sstevel@tonic-gate 		long i;
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 		ftime_used = 1;
4520Sstevel@tonic-gate 		if (s == START)
4530Sstevel@tonic-gate 			{
4540Sstevel@tonic-gate 			ftime(&tstart);
4550Sstevel@tonic-gate 			return(0);
4560Sstevel@tonic-gate 			}
4570Sstevel@tonic-gate 		else
4580Sstevel@tonic-gate 			{
4590Sstevel@tonic-gate 			ftime(&tend);
4600Sstevel@tonic-gate 			i=(long)tend.millitm-(long)tstart.millitm;
4610Sstevel@tonic-gate 			ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
4620Sstevel@tonic-gate 			return((ret < 0.001)?0.001:ret);
4630Sstevel@tonic-gate 			}
4640Sstevel@tonic-gate 		}
4650Sstevel@tonic-gate # endif
4660Sstevel@tonic-gate #endif
4670Sstevel@tonic-gate 	}
468*2139Sjp161948 #endif /* if defined(OPENSSL_SYS_NETWARE) */
469*2139Sjp161948 
470*2139Sjp161948 
471*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
472*2139Sjp161948 static const int KDF1_SHA1_len = 20;
473*2139Sjp161948 static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
474*2139Sjp161948 	{
475*2139Sjp161948 #ifndef OPENSSL_NO_SHA
476*2139Sjp161948 	if (*outlen < SHA_DIGEST_LENGTH)
477*2139Sjp161948 		return NULL;
478*2139Sjp161948 	else
479*2139Sjp161948 		*outlen = SHA_DIGEST_LENGTH;
480*2139Sjp161948 	return SHA1(in, inlen, out);
481*2139Sjp161948 #else
482*2139Sjp161948 	return NULL;
483*2139Sjp161948 #endif	/* OPENSSL_NO_SHA */
484*2139Sjp161948 	}
485*2139Sjp161948 #endif	/* OPENSSL_NO_ECDH */
486*2139Sjp161948 
4870Sstevel@tonic-gate 
4880Sstevel@tonic-gate int MAIN(int, char **);
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate int MAIN(int argc, char **argv)
4910Sstevel@tonic-gate 	{
4920Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE
4930Sstevel@tonic-gate 	ENGINE *e = NULL;
4940Sstevel@tonic-gate #endif
4950Sstevel@tonic-gate 	unsigned char *buf=NULL,*buf2=NULL;
4960Sstevel@tonic-gate 	int mret=1;
4970Sstevel@tonic-gate 	long count=0,save_count=0;
4980Sstevel@tonic-gate 	int i,j,k;
4990Sstevel@tonic-gate #if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
5000Sstevel@tonic-gate 	long rsa_count;
5010Sstevel@tonic-gate #endif
5020Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
5030Sstevel@tonic-gate 	unsigned rsa_num;
5040Sstevel@tonic-gate #endif
5050Sstevel@tonic-gate 	unsigned char md[EVP_MAX_MD_SIZE];
5060Sstevel@tonic-gate #ifndef OPENSSL_NO_MD2
5070Sstevel@tonic-gate 	unsigned char md2[MD2_DIGEST_LENGTH];
5080Sstevel@tonic-gate #endif
5090Sstevel@tonic-gate #ifndef OPENSSL_NO_MDC2
5100Sstevel@tonic-gate 	unsigned char mdc2[MDC2_DIGEST_LENGTH];
5110Sstevel@tonic-gate #endif
5120Sstevel@tonic-gate #ifndef OPENSSL_NO_MD4
5130Sstevel@tonic-gate 	unsigned char md4[MD4_DIGEST_LENGTH];
5140Sstevel@tonic-gate #endif
5150Sstevel@tonic-gate #ifndef OPENSSL_NO_MD5
5160Sstevel@tonic-gate 	unsigned char md5[MD5_DIGEST_LENGTH];
5170Sstevel@tonic-gate 	unsigned char hmac[MD5_DIGEST_LENGTH];
5180Sstevel@tonic-gate #endif
5190Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA
5200Sstevel@tonic-gate 	unsigned char sha[SHA_DIGEST_LENGTH];
521*2139Sjp161948 #ifndef OPENSSL_NO_SHA256
522*2139Sjp161948 	unsigned char sha256[SHA256_DIGEST_LENGTH];
523*2139Sjp161948 #endif
524*2139Sjp161948 #ifndef OPENSSL_NO_SHA512
525*2139Sjp161948 	unsigned char sha512[SHA512_DIGEST_LENGTH];
526*2139Sjp161948 #endif
5270Sstevel@tonic-gate #endif
5280Sstevel@tonic-gate #ifndef OPENSSL_NO_RIPEMD
5290Sstevel@tonic-gate 	unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
5300Sstevel@tonic-gate #endif
5310Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
5320Sstevel@tonic-gate 	RC4_KEY rc4_ks;
5330Sstevel@tonic-gate #endif
5340Sstevel@tonic-gate #ifndef OPENSSL_NO_RC5
5350Sstevel@tonic-gate 	RC5_32_KEY rc5_ks;
5360Sstevel@tonic-gate #endif
5370Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
5380Sstevel@tonic-gate 	RC2_KEY rc2_ks;
5390Sstevel@tonic-gate #endif
5400Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
5410Sstevel@tonic-gate 	IDEA_KEY_SCHEDULE idea_ks;
5420Sstevel@tonic-gate #endif
5430Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
5440Sstevel@tonic-gate 	BF_KEY bf_ks;
5450Sstevel@tonic-gate #endif
5460Sstevel@tonic-gate #ifndef OPENSSL_NO_CAST
5470Sstevel@tonic-gate 	CAST_KEY cast_ks;
5480Sstevel@tonic-gate #endif
5490Sstevel@tonic-gate 	static const unsigned char key16[16]=
5500Sstevel@tonic-gate 		{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
5510Sstevel@tonic-gate 		 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
552*2139Sjp161948 #ifndef OPENSSL_NO_AES
5530Sstevel@tonic-gate 	static const unsigned char key24[24]=
5540Sstevel@tonic-gate 		{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
5550Sstevel@tonic-gate 		 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
5560Sstevel@tonic-gate 		 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
5570Sstevel@tonic-gate 	static const unsigned char key32[32]=
5580Sstevel@tonic-gate 		{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
5590Sstevel@tonic-gate 		 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
5600Sstevel@tonic-gate 		 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
5610Sstevel@tonic-gate 		 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
562*2139Sjp161948 #endif
5630Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
5640Sstevel@tonic-gate #define MAX_BLOCK_SIZE 128
5650Sstevel@tonic-gate #else
5660Sstevel@tonic-gate #define MAX_BLOCK_SIZE 64
5670Sstevel@tonic-gate #endif
5680Sstevel@tonic-gate 	unsigned char DES_iv[8];
5690Sstevel@tonic-gate 	unsigned char iv[MAX_BLOCK_SIZE/8];
5700Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
5710Sstevel@tonic-gate 	DES_cblock *buf_as_des_cblock = NULL;
5720Sstevel@tonic-gate 	static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
5730Sstevel@tonic-gate 	static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
5740Sstevel@tonic-gate 	static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
5750Sstevel@tonic-gate 	DES_key_schedule sch;
5760Sstevel@tonic-gate 	DES_key_schedule sch2;
5770Sstevel@tonic-gate 	DES_key_schedule sch3;
5780Sstevel@tonic-gate #endif
5790Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
5800Sstevel@tonic-gate 	AES_KEY aes_ks1, aes_ks2, aes_ks3;
5810Sstevel@tonic-gate #endif
5820Sstevel@tonic-gate #define	D_MD2		0
5830Sstevel@tonic-gate #define	D_MDC2		1
5840Sstevel@tonic-gate #define	D_MD4		2
5850Sstevel@tonic-gate #define	D_MD5		3
5860Sstevel@tonic-gate #define	D_HMAC		4
5870Sstevel@tonic-gate #define	D_SHA1		5
5880Sstevel@tonic-gate #define D_RMD160	6
5890Sstevel@tonic-gate #define	D_RC4		7
5900Sstevel@tonic-gate #define	D_CBC_DES	8
5910Sstevel@tonic-gate #define	D_EDE3_DES	9
5920Sstevel@tonic-gate #define	D_CBC_IDEA	10
5930Sstevel@tonic-gate #define	D_CBC_RC2	11
5940Sstevel@tonic-gate #define	D_CBC_RC5	12
5950Sstevel@tonic-gate #define	D_CBC_BF	13
5960Sstevel@tonic-gate #define	D_CBC_CAST	14
5970Sstevel@tonic-gate #define D_CBC_128_AES	15
5980Sstevel@tonic-gate #define D_CBC_192_AES	16
5990Sstevel@tonic-gate #define D_CBC_256_AES	17
6000Sstevel@tonic-gate #define D_EVP		18
601*2139Sjp161948 #define D_SHA256	19
602*2139Sjp161948 #define D_SHA512	20
6030Sstevel@tonic-gate 	double d=0.0;
6040Sstevel@tonic-gate 	long c[ALGOR_NUM][SIZE_NUM];
6050Sstevel@tonic-gate #define	R_DSA_512	0
6060Sstevel@tonic-gate #define	R_DSA_1024	1
6070Sstevel@tonic-gate #define	R_DSA_2048	2
6080Sstevel@tonic-gate #define	R_RSA_512	0
6090Sstevel@tonic-gate #define	R_RSA_1024	1
6100Sstevel@tonic-gate #define	R_RSA_2048	2
6110Sstevel@tonic-gate #define	R_RSA_4096	3
612*2139Sjp161948 
613*2139Sjp161948 #define R_EC_P160    0
614*2139Sjp161948 #define R_EC_P192    1
615*2139Sjp161948 #define R_EC_P224    2
616*2139Sjp161948 #define R_EC_P256    3
617*2139Sjp161948 #define R_EC_P384    4
618*2139Sjp161948 #define R_EC_P521    5
619*2139Sjp161948 #define R_EC_K163    6
620*2139Sjp161948 #define R_EC_K233    7
621*2139Sjp161948 #define R_EC_K283    8
622*2139Sjp161948 #define R_EC_K409    9
623*2139Sjp161948 #define R_EC_K571    10
624*2139Sjp161948 #define R_EC_B163    11
625*2139Sjp161948 #define R_EC_B233    12
626*2139Sjp161948 #define R_EC_B283    13
627*2139Sjp161948 #define R_EC_B409    14
628*2139Sjp161948 #define R_EC_B571    15
629*2139Sjp161948 
6300Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
6310Sstevel@tonic-gate 	RSA *rsa_key[RSA_NUM];
6320Sstevel@tonic-gate 	long rsa_c[RSA_NUM][2];
6330Sstevel@tonic-gate 	static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
6340Sstevel@tonic-gate 	static unsigned char *rsa_data[RSA_NUM]=
6350Sstevel@tonic-gate 		{test512,test1024,test2048,test4096};
6360Sstevel@tonic-gate 	static int rsa_data_length[RSA_NUM]={
6370Sstevel@tonic-gate 		sizeof(test512),sizeof(test1024),
6380Sstevel@tonic-gate 		sizeof(test2048),sizeof(test4096)};
6390Sstevel@tonic-gate #endif
6400Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
6410Sstevel@tonic-gate 	DSA *dsa_key[DSA_NUM];
6420Sstevel@tonic-gate 	long dsa_c[DSA_NUM][2];
6430Sstevel@tonic-gate 	static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
6440Sstevel@tonic-gate #endif
645*2139Sjp161948 #ifndef OPENSSL_NO_EC
646*2139Sjp161948 	/* We only test over the following curves as they are representative,
647*2139Sjp161948 	 * To add tests over more curves, simply add the curve NID
648*2139Sjp161948 	 * and curve name to the following arrays and increase the
649*2139Sjp161948 	 * EC_NUM value accordingly.
650*2139Sjp161948 	 */
651*2139Sjp161948 	static unsigned int test_curves[EC_NUM] =
652*2139Sjp161948 	{
653*2139Sjp161948 	/* Prime Curves */
654*2139Sjp161948 	NID_secp160r1,
655*2139Sjp161948 	NID_X9_62_prime192v1,
656*2139Sjp161948 	NID_secp224r1,
657*2139Sjp161948 	NID_X9_62_prime256v1,
658*2139Sjp161948 	NID_secp384r1,
659*2139Sjp161948 	NID_secp521r1,
660*2139Sjp161948 	/* Binary Curves */
661*2139Sjp161948 	NID_sect163k1,
662*2139Sjp161948 	NID_sect233k1,
663*2139Sjp161948 	NID_sect283k1,
664*2139Sjp161948 	NID_sect409k1,
665*2139Sjp161948 	NID_sect571k1,
666*2139Sjp161948 	NID_sect163r2,
667*2139Sjp161948 	NID_sect233r1,
668*2139Sjp161948 	NID_sect283r1,
669*2139Sjp161948 	NID_sect409r1,
670*2139Sjp161948 	NID_sect571r1
671*2139Sjp161948 	};
672*2139Sjp161948 	static const char * test_curves_names[EC_NUM] =
673*2139Sjp161948 	{
674*2139Sjp161948 	/* Prime Curves */
675*2139Sjp161948 	"secp160r1",
676*2139Sjp161948 	"nistp192",
677*2139Sjp161948 	"nistp224",
678*2139Sjp161948 	"nistp256",
679*2139Sjp161948 	"nistp384",
680*2139Sjp161948 	"nistp521",
681*2139Sjp161948 	/* Binary Curves */
682*2139Sjp161948 	"nistk163",
683*2139Sjp161948 	"nistk233",
684*2139Sjp161948 	"nistk283",
685*2139Sjp161948 	"nistk409",
686*2139Sjp161948 	"nistk571",
687*2139Sjp161948 	"nistb163",
688*2139Sjp161948 	"nistb233",
689*2139Sjp161948 	"nistb283",
690*2139Sjp161948 	"nistb409",
691*2139Sjp161948 	"nistb571"
692*2139Sjp161948 	};
693*2139Sjp161948 	static int test_curves_bits[EC_NUM] =
694*2139Sjp161948         {
695*2139Sjp161948         160, 192, 224, 256, 384, 521,
696*2139Sjp161948         163, 233, 283, 409, 571,
697*2139Sjp161948         163, 233, 283, 409, 571
698*2139Sjp161948         };
699*2139Sjp161948 
700*2139Sjp161948 #endif
701*2139Sjp161948 
702*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
703*2139Sjp161948 	unsigned char ecdsasig[256];
704*2139Sjp161948 	unsigned int ecdsasiglen;
705*2139Sjp161948 	EC_KEY *ecdsa[EC_NUM];
706*2139Sjp161948 	long ecdsa_c[EC_NUM][2];
707*2139Sjp161948 #endif
708*2139Sjp161948 
709*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
710*2139Sjp161948 	EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
711*2139Sjp161948 	unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
712*2139Sjp161948 	int secret_size_a, secret_size_b;
713*2139Sjp161948 	int ecdh_checks = 0;
714*2139Sjp161948 	int secret_idx = 0;
715*2139Sjp161948 	long ecdh_c[EC_NUM][2];
716*2139Sjp161948 #endif
717*2139Sjp161948 
7180Sstevel@tonic-gate 	int rsa_doit[RSA_NUM];
7190Sstevel@tonic-gate 	int dsa_doit[DSA_NUM];
720*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
721*2139Sjp161948 	int ecdsa_doit[EC_NUM];
722*2139Sjp161948 #endif
723*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
724*2139Sjp161948         int ecdh_doit[EC_NUM];
725*2139Sjp161948 #endif
7260Sstevel@tonic-gate 	int doit[ALGOR_NUM];
7270Sstevel@tonic-gate 	int pr_header=0;
7280Sstevel@tonic-gate 	const EVP_CIPHER *evp_cipher=NULL;
7290Sstevel@tonic-gate 	const EVP_MD *evp_md=NULL;
7300Sstevel@tonic-gate 	int decrypt=0;
7310Sstevel@tonic-gate #ifdef HAVE_FORK
7320Sstevel@tonic-gate 	int multi=0;
7330Sstevel@tonic-gate #endif
7340Sstevel@tonic-gate 
7350Sstevel@tonic-gate #ifndef TIMES
7360Sstevel@tonic-gate 	usertime=-1;
7370Sstevel@tonic-gate #endif
7380Sstevel@tonic-gate 
7390Sstevel@tonic-gate 	apps_startup();
7400Sstevel@tonic-gate 	memset(results, 0, sizeof(results));
7410Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
7420Sstevel@tonic-gate 	memset(dsa_key,0,sizeof(dsa_key));
7430Sstevel@tonic-gate #endif
744*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
745*2139Sjp161948 	for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
746*2139Sjp161948 #endif
747*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
748*2139Sjp161948 	for (i=0; i<EC_NUM; i++)
749*2139Sjp161948 		{
750*2139Sjp161948 		ecdh_a[i] = NULL;
751*2139Sjp161948 		ecdh_b[i] = NULL;
752*2139Sjp161948 		}
753*2139Sjp161948 #endif
754*2139Sjp161948 
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 	if (bio_err == NULL)
7570Sstevel@tonic-gate 		if ((bio_err=BIO_new(BIO_s_file())) != NULL)
7580Sstevel@tonic-gate 			BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate 	if (!load_config(bio_err, NULL))
7610Sstevel@tonic-gate 		goto end;
7620Sstevel@tonic-gate 
7630Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
7640Sstevel@tonic-gate 	memset(rsa_key,0,sizeof(rsa_key));
7650Sstevel@tonic-gate 	for (i=0; i<RSA_NUM; i++)
7660Sstevel@tonic-gate 		rsa_key[i]=NULL;
7670Sstevel@tonic-gate #endif
7680Sstevel@tonic-gate 
7690Sstevel@tonic-gate 	if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
7700Sstevel@tonic-gate 		{
7710Sstevel@tonic-gate 		BIO_printf(bio_err,"out of memory\n");
7720Sstevel@tonic-gate 		goto end;
7730Sstevel@tonic-gate 		}
7740Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
7750Sstevel@tonic-gate 	buf_as_des_cblock = (DES_cblock *)buf;
7760Sstevel@tonic-gate #endif
7770Sstevel@tonic-gate 	if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
7780Sstevel@tonic-gate 		{
7790Sstevel@tonic-gate 		BIO_printf(bio_err,"out of memory\n");
7800Sstevel@tonic-gate 		goto end;
7810Sstevel@tonic-gate 		}
7820Sstevel@tonic-gate 
7830Sstevel@tonic-gate 	memset(c,0,sizeof(c));
7840Sstevel@tonic-gate 	memset(DES_iv,0,sizeof(DES_iv));
7850Sstevel@tonic-gate 	memset(iv,0,sizeof(iv));
7860Sstevel@tonic-gate 
7870Sstevel@tonic-gate 	for (i=0; i<ALGOR_NUM; i++)
7880Sstevel@tonic-gate 		doit[i]=0;
7890Sstevel@tonic-gate 	for (i=0; i<RSA_NUM; i++)
7900Sstevel@tonic-gate 		rsa_doit[i]=0;
7910Sstevel@tonic-gate 	for (i=0; i<DSA_NUM; i++)
7920Sstevel@tonic-gate 		dsa_doit[i]=0;
793*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
794*2139Sjp161948 	for (i=0; i<EC_NUM; i++)
795*2139Sjp161948 		ecdsa_doit[i]=0;
796*2139Sjp161948 #endif
797*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
798*2139Sjp161948 	for (i=0; i<EC_NUM; i++)
799*2139Sjp161948 		ecdh_doit[i]=0;
800*2139Sjp161948 #endif
801*2139Sjp161948 
8020Sstevel@tonic-gate 
8030Sstevel@tonic-gate 	j=0;
8040Sstevel@tonic-gate 	argc--;
8050Sstevel@tonic-gate 	argv++;
8060Sstevel@tonic-gate 	while (argc)
8070Sstevel@tonic-gate 		{
8080Sstevel@tonic-gate 		if	((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
8090Sstevel@tonic-gate 			{
8100Sstevel@tonic-gate 			usertime = 0;
8110Sstevel@tonic-gate 			j--;	/* Otherwise, -elapsed gets confused with
8120Sstevel@tonic-gate 				   an algorithm. */
8130Sstevel@tonic-gate 			}
8140Sstevel@tonic-gate 		else if	((argc > 0) && (strcmp(*argv,"-evp") == 0))
8150Sstevel@tonic-gate 			{
8160Sstevel@tonic-gate 			argc--;
8170Sstevel@tonic-gate 			argv++;
8180Sstevel@tonic-gate 			if(argc == 0)
8190Sstevel@tonic-gate 				{
8200Sstevel@tonic-gate 				BIO_printf(bio_err,"no EVP given\n");
8210Sstevel@tonic-gate 				goto end;
8220Sstevel@tonic-gate 				}
8230Sstevel@tonic-gate 			evp_cipher=EVP_get_cipherbyname(*argv);
8240Sstevel@tonic-gate 			if(!evp_cipher)
8250Sstevel@tonic-gate 				{
8260Sstevel@tonic-gate 				evp_md=EVP_get_digestbyname(*argv);
8270Sstevel@tonic-gate 				}
8280Sstevel@tonic-gate 			if(!evp_cipher && !evp_md)
8290Sstevel@tonic-gate 				{
8300Sstevel@tonic-gate 				BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
8310Sstevel@tonic-gate 				goto end;
8320Sstevel@tonic-gate 				}
8330Sstevel@tonic-gate 			doit[D_EVP]=1;
8340Sstevel@tonic-gate 			}
8350Sstevel@tonic-gate 		else if (argc > 0 && !strcmp(*argv,"-decrypt"))
8360Sstevel@tonic-gate 			{
8370Sstevel@tonic-gate 			decrypt=1;
8380Sstevel@tonic-gate 			j--;	/* Otherwise, -elapsed gets confused with
8390Sstevel@tonic-gate 				   an algorithm. */
8400Sstevel@tonic-gate 			}
8410Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE
8420Sstevel@tonic-gate 		else if	((argc > 0) && (strcmp(*argv,"-engine") == 0))
8430Sstevel@tonic-gate 			{
8440Sstevel@tonic-gate 			argc--;
8450Sstevel@tonic-gate 			argv++;
8460Sstevel@tonic-gate 			if(argc == 0)
8470Sstevel@tonic-gate 				{
8480Sstevel@tonic-gate 				BIO_printf(bio_err,"no engine given\n");
8490Sstevel@tonic-gate 				goto end;
8500Sstevel@tonic-gate 				}
8510Sstevel@tonic-gate                         e = setup_engine(bio_err, *argv, 0);
8520Sstevel@tonic-gate 			/* j will be increased again further down.  We just
8530Sstevel@tonic-gate 			   don't want speed to confuse an engine with an
8540Sstevel@tonic-gate 			   algorithm, especially when none is given (which
8550Sstevel@tonic-gate 			   means all of them should be run) */
8560Sstevel@tonic-gate 			j--;
8570Sstevel@tonic-gate 			}
8580Sstevel@tonic-gate #endif
8590Sstevel@tonic-gate #ifdef HAVE_FORK
8600Sstevel@tonic-gate 		else if	((argc > 0) && (strcmp(*argv,"-multi") == 0))
8610Sstevel@tonic-gate 			{
8620Sstevel@tonic-gate 			argc--;
8630Sstevel@tonic-gate 			argv++;
8640Sstevel@tonic-gate 			if(argc == 0)
8650Sstevel@tonic-gate 				{
8660Sstevel@tonic-gate 				BIO_printf(bio_err,"no multi count given\n");
8670Sstevel@tonic-gate 				goto end;
8680Sstevel@tonic-gate 				}
8690Sstevel@tonic-gate 			multi=atoi(argv[0]);
8700Sstevel@tonic-gate 			if(multi <= 0)
8710Sstevel@tonic-gate 			    {
8720Sstevel@tonic-gate 				BIO_printf(bio_err,"bad multi count\n");
8730Sstevel@tonic-gate 				goto end;
8740Sstevel@tonic-gate 				}
8750Sstevel@tonic-gate 			j--;	/* Otherwise, -mr gets confused with
8760Sstevel@tonic-gate 				   an algorithm. */
8770Sstevel@tonic-gate 			}
8780Sstevel@tonic-gate #endif
8790Sstevel@tonic-gate 		else if (argc > 0 && !strcmp(*argv,"-mr"))
8800Sstevel@tonic-gate 			{
8810Sstevel@tonic-gate 			mr=1;
8820Sstevel@tonic-gate 			j--;	/* Otherwise, -mr gets confused with
8830Sstevel@tonic-gate 				   an algorithm. */
8840Sstevel@tonic-gate 			}
8850Sstevel@tonic-gate 		else
8860Sstevel@tonic-gate #ifndef OPENSSL_NO_MD2
8870Sstevel@tonic-gate 		if	(strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
8880Sstevel@tonic-gate 		else
8890Sstevel@tonic-gate #endif
8900Sstevel@tonic-gate #ifndef OPENSSL_NO_MDC2
8910Sstevel@tonic-gate 			if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
8920Sstevel@tonic-gate 		else
8930Sstevel@tonic-gate #endif
8940Sstevel@tonic-gate #ifndef OPENSSL_NO_MD4
8950Sstevel@tonic-gate 			if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
8960Sstevel@tonic-gate 		else
8970Sstevel@tonic-gate #endif
8980Sstevel@tonic-gate #ifndef OPENSSL_NO_MD5
8990Sstevel@tonic-gate 			if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
9000Sstevel@tonic-gate 		else
9010Sstevel@tonic-gate #endif
9020Sstevel@tonic-gate #ifndef OPENSSL_NO_MD5
9030Sstevel@tonic-gate 			if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
9040Sstevel@tonic-gate 		else
9050Sstevel@tonic-gate #endif
9060Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA
9070Sstevel@tonic-gate 			if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
9080Sstevel@tonic-gate 		else
909*2139Sjp161948 			if (strcmp(*argv,"sha") == 0)	doit[D_SHA1]=1,
910*2139Sjp161948 							doit[D_SHA256]=1,
911*2139Sjp161948 							doit[D_SHA512]=1;
9120Sstevel@tonic-gate 		else
913*2139Sjp161948 #ifndef OPENSSL_NO_SHA256
914*2139Sjp161948 			if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
915*2139Sjp161948 		else
916*2139Sjp161948 #endif
917*2139Sjp161948 #ifndef OPENSSL_NO_SHA512
918*2139Sjp161948 			if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
919*2139Sjp161948 		else
920*2139Sjp161948 #endif
9210Sstevel@tonic-gate #endif
9220Sstevel@tonic-gate #ifndef OPENSSL_NO_RIPEMD
9230Sstevel@tonic-gate 			if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
9240Sstevel@tonic-gate 		else
9250Sstevel@tonic-gate 			if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
9260Sstevel@tonic-gate 		else
9270Sstevel@tonic-gate 			if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
9280Sstevel@tonic-gate 		else
9290Sstevel@tonic-gate #endif
9300Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
9310Sstevel@tonic-gate 			if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
9320Sstevel@tonic-gate 		else
9330Sstevel@tonic-gate #endif
9340Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
9350Sstevel@tonic-gate 			if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
9360Sstevel@tonic-gate 		else	if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
9370Sstevel@tonic-gate 		else
9380Sstevel@tonic-gate #endif
9390Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
9400Sstevel@tonic-gate 			if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
9410Sstevel@tonic-gate #ifdef SOLARIS_OPENSSL
9420Sstevel@tonic-gate 		else	if (strcmp(*argv,"aes-192-cbc") == 0)
943688Sjp161948 				if (!SUNWcry_installed)
9440Sstevel@tonic-gate 					{
9450Sstevel@tonic-gate 					BIO_printf(bio_err,
9460Sstevel@tonic-gate 					  "aes-192-cbc not available."
9470Sstevel@tonic-gate 					  " SUNWcry not installed.\n");
9480Sstevel@tonic-gate 					goto end;
9490Sstevel@tonic-gate 					}
9500Sstevel@tonic-gate 				else
9510Sstevel@tonic-gate 					doit[D_CBC_192_AES]=1;
9520Sstevel@tonic-gate 		else	if (strcmp(*argv,"aes-256-cbc") == 0)
953688Sjp161948 				if (!SUNWcry_installed)
9540Sstevel@tonic-gate 					{
9550Sstevel@tonic-gate 					BIO_printf(bio_err,
9560Sstevel@tonic-gate 					  "aes-256-cbc not available."
9570Sstevel@tonic-gate 					  " SUNWcry not installed.\n");
9580Sstevel@tonic-gate 					goto end;
9590Sstevel@tonic-gate 					}
9600Sstevel@tonic-gate 				else
9610Sstevel@tonic-gate 					doit[D_CBC_256_AES]=1;
9620Sstevel@tonic-gate #else
9630Sstevel@tonic-gate 		else	if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
9640Sstevel@tonic-gate 		else	if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
9650Sstevel@tonic-gate #endif
9660Sstevel@tonic-gate 		else
9670Sstevel@tonic-gate #endif
9680Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
9690Sstevel@tonic-gate #if 0 /* was: #ifdef RSAref */
9700Sstevel@tonic-gate 			if (strcmp(*argv,"rsaref") == 0)
9710Sstevel@tonic-gate 			{
9720Sstevel@tonic-gate 			RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
9730Sstevel@tonic-gate 			j--;
9740Sstevel@tonic-gate 			}
9750Sstevel@tonic-gate 		else
9760Sstevel@tonic-gate #endif
9770Sstevel@tonic-gate #ifndef RSA_NULL
9780Sstevel@tonic-gate 			if (strcmp(*argv,"openssl") == 0)
9790Sstevel@tonic-gate 			{
9800Sstevel@tonic-gate 			RSA_set_default_method(RSA_PKCS1_SSLeay());
9810Sstevel@tonic-gate 			j--;
9820Sstevel@tonic-gate 			}
9830Sstevel@tonic-gate 		else
9840Sstevel@tonic-gate #endif
9850Sstevel@tonic-gate #endif /* !OPENSSL_NO_RSA */
9860Sstevel@tonic-gate 		     if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
9870Sstevel@tonic-gate 		else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
9880Sstevel@tonic-gate 		else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
9890Sstevel@tonic-gate 		else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
9900Sstevel@tonic-gate 		else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
9910Sstevel@tonic-gate 		else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
9920Sstevel@tonic-gate 		else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
9930Sstevel@tonic-gate 		else
9940Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
9950Sstevel@tonic-gate 		     if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
9960Sstevel@tonic-gate 		else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
9970Sstevel@tonic-gate 		else
9980Sstevel@tonic-gate #endif
9990Sstevel@tonic-gate #ifndef OPENSSL_NO_RC5
10000Sstevel@tonic-gate 		     if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
10010Sstevel@tonic-gate 		else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
10020Sstevel@tonic-gate 		else
10030Sstevel@tonic-gate #endif
10040Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
10050Sstevel@tonic-gate 		     if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
10060Sstevel@tonic-gate 		else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
10070Sstevel@tonic-gate 		else
10080Sstevel@tonic-gate #endif
10090Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
10100Sstevel@tonic-gate 		     if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
10110Sstevel@tonic-gate 		else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
10120Sstevel@tonic-gate 		else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
10130Sstevel@tonic-gate 		else
10140Sstevel@tonic-gate #endif
10150Sstevel@tonic-gate #ifndef OPENSSL_NO_CAST
10160Sstevel@tonic-gate 		     if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
10170Sstevel@tonic-gate 		else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
10180Sstevel@tonic-gate 		else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
10190Sstevel@tonic-gate 		else
10200Sstevel@tonic-gate #endif
10210Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
10220Sstevel@tonic-gate 			if (strcmp(*argv,"des") == 0)
10230Sstevel@tonic-gate 			{
10240Sstevel@tonic-gate 			doit[D_CBC_DES]=1;
10250Sstevel@tonic-gate 			doit[D_EDE3_DES]=1;
10260Sstevel@tonic-gate 			}
10270Sstevel@tonic-gate 		else
10280Sstevel@tonic-gate #endif
10290Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
10300Sstevel@tonic-gate 			if (strcmp(*argv,"aes") == 0)
10310Sstevel@tonic-gate 			{
10320Sstevel@tonic-gate 			doit[D_CBC_128_AES]=1;
10330Sstevel@tonic-gate #ifdef SOLARIS_OPENSSL
1034688Sjp161948 			doit[D_CBC_192_AES]= SUNWcry_installed;
1035688Sjp161948 			doit[D_CBC_256_AES]= SUNWcry_installed;
10360Sstevel@tonic-gate #else
10370Sstevel@tonic-gate 			doit[D_CBC_192_AES]=1;
10380Sstevel@tonic-gate 			doit[D_CBC_256_AES]=1;
10390Sstevel@tonic-gate #endif
10400Sstevel@tonic-gate 			}
10410Sstevel@tonic-gate 		else
10420Sstevel@tonic-gate #endif
10430Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
10440Sstevel@tonic-gate 			if (strcmp(*argv,"rsa") == 0)
10450Sstevel@tonic-gate 			{
10460Sstevel@tonic-gate 			rsa_doit[R_RSA_512]=1;
10470Sstevel@tonic-gate 			rsa_doit[R_RSA_1024]=1;
10480Sstevel@tonic-gate 			rsa_doit[R_RSA_2048]=1;
10490Sstevel@tonic-gate 			rsa_doit[R_RSA_4096]=1;
10500Sstevel@tonic-gate 			}
10510Sstevel@tonic-gate 		else
10520Sstevel@tonic-gate #endif
10530Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
10540Sstevel@tonic-gate 			if (strcmp(*argv,"dsa") == 0)
10550Sstevel@tonic-gate 			{
10560Sstevel@tonic-gate 			dsa_doit[R_DSA_512]=1;
10570Sstevel@tonic-gate 			dsa_doit[R_DSA_1024]=1;
10580Sstevel@tonic-gate 			dsa_doit[R_DSA_2048]=1;
10590Sstevel@tonic-gate 			}
10600Sstevel@tonic-gate 		else
10610Sstevel@tonic-gate #endif
1062*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
1063*2139Sjp161948 		     if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
1064*2139Sjp161948 		else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
1065*2139Sjp161948 		else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
1066*2139Sjp161948 		else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
1067*2139Sjp161948 		else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
1068*2139Sjp161948 		else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
1069*2139Sjp161948 		else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
1070*2139Sjp161948 		else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
1071*2139Sjp161948 		else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
1072*2139Sjp161948 		else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
1073*2139Sjp161948 		else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
1074*2139Sjp161948 		else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
1075*2139Sjp161948 		else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
1076*2139Sjp161948 		else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
1077*2139Sjp161948 		else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
1078*2139Sjp161948 		else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
1079*2139Sjp161948 		else if (strcmp(*argv,"ecdsa") == 0)
1080*2139Sjp161948 			{
1081*2139Sjp161948 			for (i=0; i < EC_NUM; i++)
1082*2139Sjp161948 				ecdsa_doit[i]=1;
1083*2139Sjp161948 			}
1084*2139Sjp161948 		else
1085*2139Sjp161948 #endif
1086*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
1087*2139Sjp161948 		     if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
1088*2139Sjp161948 		else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
1089*2139Sjp161948 		else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
1090*2139Sjp161948 		else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
1091*2139Sjp161948 		else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
1092*2139Sjp161948 		else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
1093*2139Sjp161948 		else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
1094*2139Sjp161948 		else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
1095*2139Sjp161948 		else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
1096*2139Sjp161948 		else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
1097*2139Sjp161948 		else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
1098*2139Sjp161948 		else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
1099*2139Sjp161948 		else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
1100*2139Sjp161948 		else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
1101*2139Sjp161948 		else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
1102*2139Sjp161948 		else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
1103*2139Sjp161948 		else if (strcmp(*argv,"ecdh") == 0)
1104*2139Sjp161948 			{
1105*2139Sjp161948 			for (i=0; i < EC_NUM; i++)
1106*2139Sjp161948 				ecdh_doit[i]=1;
1107*2139Sjp161948 			}
1108*2139Sjp161948 		else
1109*2139Sjp161948 #endif
11100Sstevel@tonic-gate 			{
11110Sstevel@tonic-gate 			BIO_printf(bio_err,"Error: bad option or value\n");
11120Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
11130Sstevel@tonic-gate 			BIO_printf(bio_err,"Available values:\n");
11140Sstevel@tonic-gate #ifndef OPENSSL_NO_MD2
11150Sstevel@tonic-gate 			BIO_printf(bio_err,"md2      ");
11160Sstevel@tonic-gate #endif
11170Sstevel@tonic-gate #ifndef OPENSSL_NO_MDC2
11180Sstevel@tonic-gate 			BIO_printf(bio_err,"mdc2     ");
11190Sstevel@tonic-gate #endif
11200Sstevel@tonic-gate #ifndef OPENSSL_NO_MD4
11210Sstevel@tonic-gate 			BIO_printf(bio_err,"md4      ");
11220Sstevel@tonic-gate #endif
11230Sstevel@tonic-gate #ifndef OPENSSL_NO_MD5
11240Sstevel@tonic-gate 			BIO_printf(bio_err,"md5      ");
11250Sstevel@tonic-gate #ifndef OPENSSL_NO_HMAC
11260Sstevel@tonic-gate 			BIO_printf(bio_err,"hmac     ");
11270Sstevel@tonic-gate #endif
11280Sstevel@tonic-gate #endif
11290Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA1
11300Sstevel@tonic-gate 			BIO_printf(bio_err,"sha1     ");
11310Sstevel@tonic-gate #endif
1132*2139Sjp161948 #ifndef OPENSSL_NO_SHA256
1133*2139Sjp161948 			BIO_printf(bio_err,"sha256   ");
1134*2139Sjp161948 #endif
1135*2139Sjp161948 #ifndef OPENSSL_NO_SHA512
1136*2139Sjp161948 			BIO_printf(bio_err,"sha512   ");
1137*2139Sjp161948 #endif
11380Sstevel@tonic-gate #ifndef OPENSSL_NO_RIPEMD160
11390Sstevel@tonic-gate 			BIO_printf(bio_err,"rmd160");
11400Sstevel@tonic-gate #endif
11410Sstevel@tonic-gate #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
11420Sstevel@tonic-gate     !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
11430Sstevel@tonic-gate     !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
11440Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
11450Sstevel@tonic-gate #endif
11460Sstevel@tonic-gate 
11470Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
11480Sstevel@tonic-gate 			BIO_printf(bio_err,"idea-cbc ");
11490Sstevel@tonic-gate #endif
11500Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
11510Sstevel@tonic-gate 			BIO_printf(bio_err,"rc2-cbc  ");
11520Sstevel@tonic-gate #endif
11530Sstevel@tonic-gate #ifndef OPENSSL_NO_RC5
11540Sstevel@tonic-gate 			BIO_printf(bio_err,"rc5-cbc  ");
11550Sstevel@tonic-gate #endif
11560Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
11570Sstevel@tonic-gate 			BIO_printf(bio_err,"bf-cbc");
11580Sstevel@tonic-gate #endif
11590Sstevel@tonic-gate #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
11600Sstevel@tonic-gate     !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
11610Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
11620Sstevel@tonic-gate #endif
11630Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
11640Sstevel@tonic-gate 			BIO_printf(bio_err,"des-cbc  des-ede3 ");
11650Sstevel@tonic-gate #endif
11660Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
11670Sstevel@tonic-gate #ifdef SOLARIS_OPENSSL
1168688Sjp161948 			if (SUNWcry_installed)
11690Sstevel@tonic-gate 				BIO_printf(bio_err,
11700Sstevel@tonic-gate 				  "aes-128-cbc aes-192-cbc aes-256-cbc ");
11710Sstevel@tonic-gate 			else
11720Sstevel@tonic-gate 				BIO_printf(bio_err, "aes-128-cbc ");
11730Sstevel@tonic-gate #else
11740Sstevel@tonic-gate 			BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
11750Sstevel@tonic-gate #endif
11760Sstevel@tonic-gate #endif
11770Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
11780Sstevel@tonic-gate 			BIO_printf(bio_err,"rc4");
11790Sstevel@tonic-gate #endif
11800Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
11810Sstevel@tonic-gate 
11820Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
11830Sstevel@tonic-gate 			BIO_printf(bio_err,"rsa512   rsa1024  rsa2048  rsa4096\n");
11840Sstevel@tonic-gate #endif
11850Sstevel@tonic-gate 
11860Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
11870Sstevel@tonic-gate 			BIO_printf(bio_err,"dsa512   dsa1024  dsa2048\n");
11880Sstevel@tonic-gate #endif
1189*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
1190*2139Sjp161948 			BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
1191*2139Sjp161948 			BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
1192*2139Sjp161948 			BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
1193*2139Sjp161948 			BIO_printf(bio_err,"ecdsa\n");
1194*2139Sjp161948 #endif
1195*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
1196*2139Sjp161948 			BIO_printf(bio_err,"ecdhp160  ecdhp192  ecdhp224  ecdhp256  ecdhp384  ecdhp521\n");
1197*2139Sjp161948 			BIO_printf(bio_err,"ecdhk163  ecdhk233  ecdhk283  ecdhk409  ecdhk571\n");
1198*2139Sjp161948 			BIO_printf(bio_err,"ecdhb163  ecdhb233  ecdhb283  ecdhb409  ecdhb571\n");
1199*2139Sjp161948 			BIO_printf(bio_err,"ecdh\n");
1200*2139Sjp161948 #endif
12010Sstevel@tonic-gate 
12020Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
12030Sstevel@tonic-gate 			BIO_printf(bio_err,"idea     ");
12040Sstevel@tonic-gate #endif
12050Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
12060Sstevel@tonic-gate 			BIO_printf(bio_err,"rc2      ");
12070Sstevel@tonic-gate #endif
12080Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
12090Sstevel@tonic-gate 			BIO_printf(bio_err,"des      ");
12100Sstevel@tonic-gate #endif
12110Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
12120Sstevel@tonic-gate 			BIO_printf(bio_err,"aes      ");
12130Sstevel@tonic-gate #endif
12140Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
12150Sstevel@tonic-gate 			BIO_printf(bio_err,"rsa      ");
12160Sstevel@tonic-gate #endif
12170Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
12180Sstevel@tonic-gate 			BIO_printf(bio_err,"blowfish");
12190Sstevel@tonic-gate #endif
12200Sstevel@tonic-gate #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
12210Sstevel@tonic-gate     !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
12220Sstevel@tonic-gate     !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES)
12230Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
12240Sstevel@tonic-gate #endif
12250Sstevel@tonic-gate 
12260Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
12270Sstevel@tonic-gate 			BIO_printf(bio_err,"Available options:\n");
12280Sstevel@tonic-gate #if defined(TIMES) || defined(USE_TOD)
12290Sstevel@tonic-gate 			BIO_printf(bio_err,"-elapsed        measure time in real time instead of CPU user time.\n");
12300Sstevel@tonic-gate #endif
12310Sstevel@tonic-gate #ifndef OPENSSL_NO_ENGINE
12320Sstevel@tonic-gate 			BIO_printf(bio_err,"-engine e       use engine e, possibly a hardware device.\n");
12330Sstevel@tonic-gate #endif
12340Sstevel@tonic-gate 			BIO_printf(bio_err,"-evp e          use EVP e.\n");
12350Sstevel@tonic-gate 			BIO_printf(bio_err,"-decrypt        time decryption instead of encryption (only EVP).\n");
12360Sstevel@tonic-gate 			BIO_printf(bio_err,"-mr             produce machine readable output.\n");
12370Sstevel@tonic-gate #ifdef HAVE_FORK
12380Sstevel@tonic-gate 			BIO_printf(bio_err,"-multi n        run n benchmarks in parallel.\n");
12390Sstevel@tonic-gate #endif
12400Sstevel@tonic-gate 			goto end;
12410Sstevel@tonic-gate 			}
12420Sstevel@tonic-gate 		argc--;
12430Sstevel@tonic-gate 		argv++;
12440Sstevel@tonic-gate 		j++;
12450Sstevel@tonic-gate 		}
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate #ifdef HAVE_FORK
12480Sstevel@tonic-gate 	if(multi && do_multi(multi))
12490Sstevel@tonic-gate 		goto show_res;
12500Sstevel@tonic-gate #endif
12510Sstevel@tonic-gate 
12520Sstevel@tonic-gate 	if (j == 0)
12530Sstevel@tonic-gate 		{
12540Sstevel@tonic-gate 		for (i=0; i<ALGOR_NUM; i++)
12550Sstevel@tonic-gate 			{
12560Sstevel@tonic-gate 			if (i != D_EVP)
12570Sstevel@tonic-gate 				doit[i]=1;
12580Sstevel@tonic-gate 			}
12590Sstevel@tonic-gate 		for (i=0; i<RSA_NUM; i++)
12600Sstevel@tonic-gate 			rsa_doit[i]=1;
12610Sstevel@tonic-gate 		for (i=0; i<DSA_NUM; i++)
12620Sstevel@tonic-gate 			dsa_doit[i]=1;
12630Sstevel@tonic-gate 		}
12640Sstevel@tonic-gate 	for (i=0; i<ALGOR_NUM; i++)
12650Sstevel@tonic-gate 		if (doit[i]) pr_header++;
12660Sstevel@tonic-gate 
12670Sstevel@tonic-gate 	if (usertime == 0 && !mr)
12680Sstevel@tonic-gate 		BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
12690Sstevel@tonic-gate 	if (usertime <= 0 && !mr)
12700Sstevel@tonic-gate 		{
12710Sstevel@tonic-gate 		BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
12720Sstevel@tonic-gate 		BIO_printf(bio_err,"program when this computer is idle.\n");
12730Sstevel@tonic-gate 		}
12740Sstevel@tonic-gate 
12750Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
12760Sstevel@tonic-gate 	for (i=0; i<RSA_NUM; i++)
12770Sstevel@tonic-gate 		{
12780Sstevel@tonic-gate 		const unsigned char *p;
12790Sstevel@tonic-gate 
12800Sstevel@tonic-gate 		p=rsa_data[i];
12810Sstevel@tonic-gate 		rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
12820Sstevel@tonic-gate 		if (rsa_key[i] == NULL)
12830Sstevel@tonic-gate 			{
12840Sstevel@tonic-gate 			BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
12850Sstevel@tonic-gate 			goto end;
12860Sstevel@tonic-gate 			}
12870Sstevel@tonic-gate #if 0
12880Sstevel@tonic-gate 		else
12890Sstevel@tonic-gate 			{
12900Sstevel@tonic-gate 			BIO_printf(bio_err,mr ? "+RK:%d:"
12910Sstevel@tonic-gate 				   : "Loaded RSA key, %d bit modulus and e= 0x",
12920Sstevel@tonic-gate 				   BN_num_bits(rsa_key[i]->n));
12930Sstevel@tonic-gate 			BN_print(bio_err,rsa_key[i]->e);
12940Sstevel@tonic-gate 			BIO_printf(bio_err,"\n");
12950Sstevel@tonic-gate 			}
12960Sstevel@tonic-gate #endif
12970Sstevel@tonic-gate 		}
12980Sstevel@tonic-gate #endif
12990Sstevel@tonic-gate 
13000Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
13010Sstevel@tonic-gate 	dsa_key[0]=get_dsa512();
13020Sstevel@tonic-gate 	dsa_key[1]=get_dsa1024();
13030Sstevel@tonic-gate 	dsa_key[2]=get_dsa2048();
13040Sstevel@tonic-gate #endif
13050Sstevel@tonic-gate 
13060Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
13070Sstevel@tonic-gate 	DES_set_key_unchecked(&key,&sch);
13080Sstevel@tonic-gate 	DES_set_key_unchecked(&key2,&sch2);
13090Sstevel@tonic-gate 	DES_set_key_unchecked(&key3,&sch3);
13100Sstevel@tonic-gate #endif
13110Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
13120Sstevel@tonic-gate 	AES_set_encrypt_key(key16,128,&aes_ks1);
13130Sstevel@tonic-gate 	AES_set_encrypt_key(key24,192,&aes_ks2);
13140Sstevel@tonic-gate 	AES_set_encrypt_key(key32,256,&aes_ks3);
13150Sstevel@tonic-gate #endif
13160Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
13170Sstevel@tonic-gate 	idea_set_encrypt_key(key16,&idea_ks);
13180Sstevel@tonic-gate #endif
13190Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
13200Sstevel@tonic-gate 	RC4_set_key(&rc4_ks,16,key16);
13210Sstevel@tonic-gate #endif
13220Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
13230Sstevel@tonic-gate 	RC2_set_key(&rc2_ks,16,key16,128);
13240Sstevel@tonic-gate #endif
13250Sstevel@tonic-gate #ifndef OPENSSL_NO_RC5
13260Sstevel@tonic-gate 	RC5_32_set_key(&rc5_ks,16,key16,12);
13270Sstevel@tonic-gate #endif
13280Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
13290Sstevel@tonic-gate 	BF_set_key(&bf_ks,16,key16);
13300Sstevel@tonic-gate #endif
13310Sstevel@tonic-gate #ifndef OPENSSL_NO_CAST
13320Sstevel@tonic-gate 	CAST_set_key(&cast_ks,16,key16);
13330Sstevel@tonic-gate #endif
13340Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
13350Sstevel@tonic-gate 	memset(rsa_c,0,sizeof(rsa_c));
13360Sstevel@tonic-gate #endif
13370Sstevel@tonic-gate #ifndef SIGALRM
13380Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
13390Sstevel@tonic-gate 	BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
13400Sstevel@tonic-gate 	count=10;
13410Sstevel@tonic-gate 	do	{
1342*2139Sjp161948 		long it;
13430Sstevel@tonic-gate 		count*=2;
13440Sstevel@tonic-gate 		Time_F(START);
1345*2139Sjp161948 		for (it=count; it; it--)
13460Sstevel@tonic-gate 			DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
13470Sstevel@tonic-gate 				&sch,DES_ENCRYPT);
13480Sstevel@tonic-gate 		d=Time_F(STOP);
13490Sstevel@tonic-gate 		} while (d <3);
13500Sstevel@tonic-gate 	save_count=count;
13510Sstevel@tonic-gate 	c[D_MD2][0]=count/10;
13520Sstevel@tonic-gate 	c[D_MDC2][0]=count/10;
13530Sstevel@tonic-gate 	c[D_MD4][0]=count;
13540Sstevel@tonic-gate 	c[D_MD5][0]=count;
13550Sstevel@tonic-gate 	c[D_HMAC][0]=count;
13560Sstevel@tonic-gate 	c[D_SHA1][0]=count;
13570Sstevel@tonic-gate 	c[D_RMD160][0]=count;
13580Sstevel@tonic-gate 	c[D_RC4][0]=count*5;
13590Sstevel@tonic-gate 	c[D_CBC_DES][0]=count;
13600Sstevel@tonic-gate 	c[D_EDE3_DES][0]=count/3;
13610Sstevel@tonic-gate 	c[D_CBC_IDEA][0]=count;
13620Sstevel@tonic-gate 	c[D_CBC_RC2][0]=count;
13630Sstevel@tonic-gate 	c[D_CBC_RC5][0]=count;
13640Sstevel@tonic-gate 	c[D_CBC_BF][0]=count;
13650Sstevel@tonic-gate 	c[D_CBC_CAST][0]=count;
13660Sstevel@tonic-gate 	c[D_CBC_128_AES][0]=count;
13670Sstevel@tonic-gate 	c[D_CBC_192_AES][0]=count;
13680Sstevel@tonic-gate 	c[D_CBC_256_AES][0]=count;
1369*2139Sjp161948 	c[D_SHA256][0]=count;
1370*2139Sjp161948 	c[D_SHA512][0]=count;
13710Sstevel@tonic-gate 
13720Sstevel@tonic-gate 	for (i=1; i<SIZE_NUM; i++)
13730Sstevel@tonic-gate 		{
13740Sstevel@tonic-gate 		c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
13750Sstevel@tonic-gate 		c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
13760Sstevel@tonic-gate 		c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
13770Sstevel@tonic-gate 		c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
13780Sstevel@tonic-gate 		c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
13790Sstevel@tonic-gate 		c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
13800Sstevel@tonic-gate 		c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
1381*2139Sjp161948 		c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
1382*2139Sjp161948 		c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
13830Sstevel@tonic-gate 		}
13840Sstevel@tonic-gate 	for (i=1; i<SIZE_NUM; i++)
13850Sstevel@tonic-gate 		{
13860Sstevel@tonic-gate 		long l0,l1;
13870Sstevel@tonic-gate 
13880Sstevel@tonic-gate 		l0=(long)lengths[i-1];
13890Sstevel@tonic-gate 		l1=(long)lengths[i];
13900Sstevel@tonic-gate 		c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
13910Sstevel@tonic-gate 		c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
13920Sstevel@tonic-gate 		c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
13930Sstevel@tonic-gate 		c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
13940Sstevel@tonic-gate 		c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
13950Sstevel@tonic-gate 		c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
13960Sstevel@tonic-gate 		c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
13970Sstevel@tonic-gate 		c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
13980Sstevel@tonic-gate 		c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
13990Sstevel@tonic-gate 		c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
14000Sstevel@tonic-gate 		c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
14010Sstevel@tonic-gate 		}
14020Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
14030Sstevel@tonic-gate 	rsa_c[R_RSA_512][0]=count/2000;
14040Sstevel@tonic-gate 	rsa_c[R_RSA_512][1]=count/400;
14050Sstevel@tonic-gate 	for (i=1; i<RSA_NUM; i++)
14060Sstevel@tonic-gate 		{
14070Sstevel@tonic-gate 		rsa_c[i][0]=rsa_c[i-1][0]/8;
14080Sstevel@tonic-gate 		rsa_c[i][1]=rsa_c[i-1][1]/4;
14090Sstevel@tonic-gate 		if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
14100Sstevel@tonic-gate 			rsa_doit[i]=0;
14110Sstevel@tonic-gate 		else
14120Sstevel@tonic-gate 			{
14130Sstevel@tonic-gate 			if (rsa_c[i][0] == 0)
14140Sstevel@tonic-gate 				{
14150Sstevel@tonic-gate 				rsa_c[i][0]=1;
14160Sstevel@tonic-gate 				rsa_c[i][1]=20;
14170Sstevel@tonic-gate 				}
14180Sstevel@tonic-gate 			}
14190Sstevel@tonic-gate 		}
14200Sstevel@tonic-gate #endif
14210Sstevel@tonic-gate 
14220Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
14230Sstevel@tonic-gate 	dsa_c[R_DSA_512][0]=count/1000;
14240Sstevel@tonic-gate 	dsa_c[R_DSA_512][1]=count/1000/2;
14250Sstevel@tonic-gate 	for (i=1; i<DSA_NUM; i++)
14260Sstevel@tonic-gate 		{
14270Sstevel@tonic-gate 		dsa_c[i][0]=dsa_c[i-1][0]/4;
14280Sstevel@tonic-gate 		dsa_c[i][1]=dsa_c[i-1][1]/4;
14290Sstevel@tonic-gate 		if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
14300Sstevel@tonic-gate 			dsa_doit[i]=0;
14310Sstevel@tonic-gate 		else
14320Sstevel@tonic-gate 			{
14330Sstevel@tonic-gate 			if (dsa_c[i] == 0)
14340Sstevel@tonic-gate 				{
14350Sstevel@tonic-gate 				dsa_c[i][0]=1;
14360Sstevel@tonic-gate 				dsa_c[i][1]=1;
14370Sstevel@tonic-gate 				}
14380Sstevel@tonic-gate 			}
14390Sstevel@tonic-gate 		}
14400Sstevel@tonic-gate #endif
14410Sstevel@tonic-gate 
1442*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
1443*2139Sjp161948 	ecdsa_c[R_EC_P160][0]=count/1000;
1444*2139Sjp161948 	ecdsa_c[R_EC_P160][1]=count/1000/2;
1445*2139Sjp161948 	for (i=R_EC_P192; i<=R_EC_P521; i++)
1446*2139Sjp161948 		{
1447*2139Sjp161948 		ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1448*2139Sjp161948 		ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1449*2139Sjp161948 		if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1450*2139Sjp161948 			ecdsa_doit[i]=0;
1451*2139Sjp161948 		else
1452*2139Sjp161948 			{
1453*2139Sjp161948 			if (ecdsa_c[i] == 0)
1454*2139Sjp161948 				{
1455*2139Sjp161948 				ecdsa_c[i][0]=1;
1456*2139Sjp161948 				ecdsa_c[i][1]=1;
1457*2139Sjp161948 				}
1458*2139Sjp161948 			}
1459*2139Sjp161948 		}
1460*2139Sjp161948 	ecdsa_c[R_EC_K163][0]=count/1000;
1461*2139Sjp161948 	ecdsa_c[R_EC_K163][1]=count/1000/2;
1462*2139Sjp161948 	for (i=R_EC_K233; i<=R_EC_K571; i++)
1463*2139Sjp161948 		{
1464*2139Sjp161948 		ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1465*2139Sjp161948 		ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1466*2139Sjp161948 		if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1467*2139Sjp161948 			ecdsa_doit[i]=0;
1468*2139Sjp161948 		else
1469*2139Sjp161948 			{
1470*2139Sjp161948 			if (ecdsa_c[i] == 0)
1471*2139Sjp161948 				{
1472*2139Sjp161948 				ecdsa_c[i][0]=1;
1473*2139Sjp161948 				ecdsa_c[i][1]=1;
1474*2139Sjp161948 				}
1475*2139Sjp161948 			}
1476*2139Sjp161948 		}
1477*2139Sjp161948 	ecdsa_c[R_EC_B163][0]=count/1000;
1478*2139Sjp161948 	ecdsa_c[R_EC_B163][1]=count/1000/2;
1479*2139Sjp161948 	for (i=R_EC_B233; i<=R_EC_B571; i++)
1480*2139Sjp161948 		{
1481*2139Sjp161948 		ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
1482*2139Sjp161948 		ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
1483*2139Sjp161948 		if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
1484*2139Sjp161948 			ecdsa_doit[i]=0;
1485*2139Sjp161948 		else
1486*2139Sjp161948 			{
1487*2139Sjp161948 			if (ecdsa_c[i] == 0)
1488*2139Sjp161948 				{
1489*2139Sjp161948 				ecdsa_c[i][0]=1;
1490*2139Sjp161948 				ecdsa_c[i][1]=1;
1491*2139Sjp161948 				}
1492*2139Sjp161948 			}
1493*2139Sjp161948 		}
1494*2139Sjp161948 #endif
1495*2139Sjp161948 
1496*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
1497*2139Sjp161948 	ecdh_c[R_EC_P160][0]=count/1000;
1498*2139Sjp161948 	ecdh_c[R_EC_P160][1]=count/1000;
1499*2139Sjp161948 	for (i=R_EC_P192; i<=R_EC_P521; i++)
1500*2139Sjp161948 		{
1501*2139Sjp161948 		ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1502*2139Sjp161948 		ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1503*2139Sjp161948 		if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1504*2139Sjp161948 			ecdh_doit[i]=0;
1505*2139Sjp161948 		else
1506*2139Sjp161948 			{
1507*2139Sjp161948 			if (ecdh_c[i] == 0)
1508*2139Sjp161948 				{
1509*2139Sjp161948 				ecdh_c[i][0]=1;
1510*2139Sjp161948 				ecdh_c[i][1]=1;
1511*2139Sjp161948 				}
1512*2139Sjp161948 			}
1513*2139Sjp161948 		}
1514*2139Sjp161948 	ecdh_c[R_EC_K163][0]=count/1000;
1515*2139Sjp161948 	ecdh_c[R_EC_K163][1]=count/1000;
1516*2139Sjp161948 	for (i=R_EC_K233; i<=R_EC_K571; i++)
1517*2139Sjp161948 		{
1518*2139Sjp161948 		ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1519*2139Sjp161948 		ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1520*2139Sjp161948 		if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1521*2139Sjp161948 			ecdh_doit[i]=0;
1522*2139Sjp161948 		else
1523*2139Sjp161948 			{
1524*2139Sjp161948 			if (ecdh_c[i] == 0)
1525*2139Sjp161948 				{
1526*2139Sjp161948 				ecdh_c[i][0]=1;
1527*2139Sjp161948 				ecdh_c[i][1]=1;
1528*2139Sjp161948 				}
1529*2139Sjp161948 			}
1530*2139Sjp161948 		}
1531*2139Sjp161948 	ecdh_c[R_EC_B163][0]=count/1000;
1532*2139Sjp161948 	ecdh_c[R_EC_B163][1]=count/1000;
1533*2139Sjp161948 	for (i=R_EC_B233; i<=R_EC_B571; i++)
1534*2139Sjp161948 		{
1535*2139Sjp161948 		ecdh_c[i][0]=ecdh_c[i-1][0]/2;
1536*2139Sjp161948 		ecdh_c[i][1]=ecdh_c[i-1][1]/2;
1537*2139Sjp161948 		if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
1538*2139Sjp161948 			ecdh_doit[i]=0;
1539*2139Sjp161948 		else
1540*2139Sjp161948 			{
1541*2139Sjp161948 			if (ecdh_c[i] == 0)
1542*2139Sjp161948 				{
1543*2139Sjp161948 				ecdh_c[i][0]=1;
1544*2139Sjp161948 				ecdh_c[i][1]=1;
1545*2139Sjp161948 				}
1546*2139Sjp161948 			}
1547*2139Sjp161948 		}
1548*2139Sjp161948 #endif
1549*2139Sjp161948 
15500Sstevel@tonic-gate #define COND(d)	(count < (d))
15510Sstevel@tonic-gate #define COUNT(d) (d)
15520Sstevel@tonic-gate #else
15530Sstevel@tonic-gate /* not worth fixing */
15540Sstevel@tonic-gate # error "You cannot disable DES on systems without SIGALRM."
15550Sstevel@tonic-gate #endif /* OPENSSL_NO_DES */
15560Sstevel@tonic-gate #else
15570Sstevel@tonic-gate #define COND(c)	(run)
15580Sstevel@tonic-gate #define COUNT(d) (count)
15590Sstevel@tonic-gate 	signal(SIGALRM,sig_done);
15600Sstevel@tonic-gate #endif /* SIGALRM */
15610Sstevel@tonic-gate 
15620Sstevel@tonic-gate #ifndef OPENSSL_NO_MD2
15630Sstevel@tonic-gate 	if (doit[D_MD2])
15640Sstevel@tonic-gate 		{
15650Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
15660Sstevel@tonic-gate 			{
15670Sstevel@tonic-gate 			print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
15680Sstevel@tonic-gate 			Time_F(START);
15690Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_MD2][j]); count++)
15700Sstevel@tonic-gate 				EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
15710Sstevel@tonic-gate 			d=Time_F(STOP);
15720Sstevel@tonic-gate 			print_result(D_MD2,j,count,d);
15730Sstevel@tonic-gate 			}
15740Sstevel@tonic-gate 		}
15750Sstevel@tonic-gate #endif
15760Sstevel@tonic-gate #ifndef OPENSSL_NO_MDC2
15770Sstevel@tonic-gate 	if (doit[D_MDC2])
15780Sstevel@tonic-gate 		{
15790Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
15800Sstevel@tonic-gate 			{
15810Sstevel@tonic-gate 			print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
15820Sstevel@tonic-gate 			Time_F(START);
15830Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_MDC2][j]); count++)
15840Sstevel@tonic-gate 				EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
15850Sstevel@tonic-gate 			d=Time_F(STOP);
15860Sstevel@tonic-gate 			print_result(D_MDC2,j,count,d);
15870Sstevel@tonic-gate 			}
15880Sstevel@tonic-gate 		}
15890Sstevel@tonic-gate #endif
15900Sstevel@tonic-gate 
15910Sstevel@tonic-gate #ifndef OPENSSL_NO_MD4
15920Sstevel@tonic-gate 	if (doit[D_MD4])
15930Sstevel@tonic-gate 		{
15940Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
15950Sstevel@tonic-gate 			{
15960Sstevel@tonic-gate 			print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
15970Sstevel@tonic-gate 			Time_F(START);
15980Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_MD4][j]); count++)
15990Sstevel@tonic-gate 				EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
16000Sstevel@tonic-gate 			d=Time_F(STOP);
16010Sstevel@tonic-gate 			print_result(D_MD4,j,count,d);
16020Sstevel@tonic-gate 			}
16030Sstevel@tonic-gate 		}
16040Sstevel@tonic-gate #endif
16050Sstevel@tonic-gate 
16060Sstevel@tonic-gate #ifndef OPENSSL_NO_MD5
16070Sstevel@tonic-gate 	if (doit[D_MD5])
16080Sstevel@tonic-gate 		{
16090Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
16100Sstevel@tonic-gate 			{
16110Sstevel@tonic-gate 			print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
16120Sstevel@tonic-gate 			Time_F(START);
16130Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_MD5][j]); count++)
16140Sstevel@tonic-gate 				EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
16150Sstevel@tonic-gate 			d=Time_F(STOP);
16160Sstevel@tonic-gate 			print_result(D_MD5,j,count,d);
16170Sstevel@tonic-gate 			}
16180Sstevel@tonic-gate 		}
16190Sstevel@tonic-gate #endif
16200Sstevel@tonic-gate 
16210Sstevel@tonic-gate #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
16220Sstevel@tonic-gate 	if (doit[D_HMAC])
16230Sstevel@tonic-gate 		{
16240Sstevel@tonic-gate 		HMAC_CTX hctx;
16250Sstevel@tonic-gate 
16260Sstevel@tonic-gate 		HMAC_CTX_init(&hctx);
16270Sstevel@tonic-gate 		HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
16280Sstevel@tonic-gate 			16,EVP_md5(), NULL);
16290Sstevel@tonic-gate 
16300Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
16310Sstevel@tonic-gate 			{
16320Sstevel@tonic-gate 			print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
16330Sstevel@tonic-gate 			Time_F(START);
16340Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_HMAC][j]); count++)
16350Sstevel@tonic-gate 				{
16360Sstevel@tonic-gate 				HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
16370Sstevel@tonic-gate 				HMAC_Update(&hctx,buf,lengths[j]);
16380Sstevel@tonic-gate 				HMAC_Final(&hctx,&(hmac[0]),NULL);
16390Sstevel@tonic-gate 				}
16400Sstevel@tonic-gate 			d=Time_F(STOP);
16410Sstevel@tonic-gate 			print_result(D_HMAC,j,count,d);
16420Sstevel@tonic-gate 			}
16430Sstevel@tonic-gate 		HMAC_CTX_cleanup(&hctx);
16440Sstevel@tonic-gate 		}
16450Sstevel@tonic-gate #endif
16460Sstevel@tonic-gate #ifndef OPENSSL_NO_SHA
16470Sstevel@tonic-gate 	if (doit[D_SHA1])
16480Sstevel@tonic-gate 		{
16490Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
16500Sstevel@tonic-gate 			{
16510Sstevel@tonic-gate 			print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
16520Sstevel@tonic-gate 			Time_F(START);
16530Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_SHA1][j]); count++)
16540Sstevel@tonic-gate 				EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
16550Sstevel@tonic-gate 			d=Time_F(STOP);
16560Sstevel@tonic-gate 			print_result(D_SHA1,j,count,d);
16570Sstevel@tonic-gate 			}
16580Sstevel@tonic-gate 		}
1659*2139Sjp161948 
1660*2139Sjp161948 #ifndef OPENSSL_NO_SHA256
1661*2139Sjp161948 	if (doit[D_SHA256])
1662*2139Sjp161948 		{
1663*2139Sjp161948 		for (j=0; j<SIZE_NUM; j++)
1664*2139Sjp161948 			{
1665*2139Sjp161948 			print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
1666*2139Sjp161948 			Time_F(START);
1667*2139Sjp161948 			for (count=0,run=1; COND(c[D_SHA256][j]); count++)
1668*2139Sjp161948 				SHA256(buf,lengths[j],sha256);
1669*2139Sjp161948 			d=Time_F(STOP);
1670*2139Sjp161948 			print_result(D_SHA256,j,count,d);
1671*2139Sjp161948 			}
1672*2139Sjp161948 		}
1673*2139Sjp161948 #endif
1674*2139Sjp161948 
1675*2139Sjp161948 #ifndef OPENSSL_NO_SHA512
1676*2139Sjp161948 	if (doit[D_SHA512])
1677*2139Sjp161948 		{
1678*2139Sjp161948 		for (j=0; j<SIZE_NUM; j++)
1679*2139Sjp161948 			{
1680*2139Sjp161948 			print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
1681*2139Sjp161948 			Time_F(START);
1682*2139Sjp161948 			for (count=0,run=1; COND(c[D_SHA512][j]); count++)
1683*2139Sjp161948 				SHA512(buf,lengths[j],sha512);
1684*2139Sjp161948 			d=Time_F(STOP);
1685*2139Sjp161948 			print_result(D_SHA512,j,count,d);
1686*2139Sjp161948 			}
1687*2139Sjp161948 		}
1688*2139Sjp161948 #endif
1689*2139Sjp161948 
16900Sstevel@tonic-gate #endif
16910Sstevel@tonic-gate #ifndef OPENSSL_NO_RIPEMD
16920Sstevel@tonic-gate 	if (doit[D_RMD160])
16930Sstevel@tonic-gate 		{
16940Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
16950Sstevel@tonic-gate 			{
16960Sstevel@tonic-gate 			print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
16970Sstevel@tonic-gate 			Time_F(START);
16980Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_RMD160][j]); count++)
16990Sstevel@tonic-gate 				EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
17000Sstevel@tonic-gate 			d=Time_F(STOP);
17010Sstevel@tonic-gate 			print_result(D_RMD160,j,count,d);
17020Sstevel@tonic-gate 			}
17030Sstevel@tonic-gate 		}
17040Sstevel@tonic-gate #endif
17050Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
17060Sstevel@tonic-gate 	if (doit[D_RC4])
17070Sstevel@tonic-gate 		{
17080Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
17090Sstevel@tonic-gate 			{
17100Sstevel@tonic-gate 			print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
17110Sstevel@tonic-gate 			Time_F(START);
17120Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_RC4][j]); count++)
17130Sstevel@tonic-gate 				RC4(&rc4_ks,(unsigned int)lengths[j],
17140Sstevel@tonic-gate 					buf,buf);
17150Sstevel@tonic-gate 			d=Time_F(STOP);
17160Sstevel@tonic-gate 			print_result(D_RC4,j,count,d);
17170Sstevel@tonic-gate 			}
17180Sstevel@tonic-gate 		}
17190Sstevel@tonic-gate #endif
17200Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
17210Sstevel@tonic-gate 	if (doit[D_CBC_DES])
17220Sstevel@tonic-gate 		{
17230Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
17240Sstevel@tonic-gate 			{
17250Sstevel@tonic-gate 			print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
17260Sstevel@tonic-gate 			Time_F(START);
17270Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
17280Sstevel@tonic-gate 				DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
17290Sstevel@tonic-gate 						 &DES_iv,DES_ENCRYPT);
17300Sstevel@tonic-gate 			d=Time_F(STOP);
17310Sstevel@tonic-gate 			print_result(D_CBC_DES,j,count,d);
17320Sstevel@tonic-gate 			}
17330Sstevel@tonic-gate 		}
17340Sstevel@tonic-gate 
17350Sstevel@tonic-gate 	if (doit[D_EDE3_DES])
17360Sstevel@tonic-gate 		{
17370Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
17380Sstevel@tonic-gate 			{
17390Sstevel@tonic-gate 			print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
17400Sstevel@tonic-gate 			Time_F(START);
17410Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
17420Sstevel@tonic-gate 				DES_ede3_cbc_encrypt(buf,buf,lengths[j],
17430Sstevel@tonic-gate 						     &sch,&sch2,&sch3,
17440Sstevel@tonic-gate 						     &DES_iv,DES_ENCRYPT);
17450Sstevel@tonic-gate 			d=Time_F(STOP);
17460Sstevel@tonic-gate 			print_result(D_EDE3_DES,j,count,d);
17470Sstevel@tonic-gate 			}
17480Sstevel@tonic-gate 		}
17490Sstevel@tonic-gate #endif
17500Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
17510Sstevel@tonic-gate 	if (doit[D_CBC_128_AES])
17520Sstevel@tonic-gate 		{
17530Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
17540Sstevel@tonic-gate 			{
17550Sstevel@tonic-gate 			print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
17560Sstevel@tonic-gate 			Time_F(START);
17570Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
17580Sstevel@tonic-gate 				AES_cbc_encrypt(buf,buf,
17590Sstevel@tonic-gate 					(unsigned long)lengths[j],&aes_ks1,
17600Sstevel@tonic-gate 					iv,AES_ENCRYPT);
17610Sstevel@tonic-gate 			d=Time_F(STOP);
17620Sstevel@tonic-gate 			print_result(D_CBC_128_AES,j,count,d);
17630Sstevel@tonic-gate 			}
17640Sstevel@tonic-gate 		}
1765688Sjp161948 #ifdef SOLARIS_OPENSSL
1766688Sjp161948 	if (doit[D_CBC_192_AES] && SUNWcry_installed)
1767688Sjp161948 #else
17680Sstevel@tonic-gate 	if (doit[D_CBC_192_AES])
1769688Sjp161948 #endif
17700Sstevel@tonic-gate 		{
17710Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
17720Sstevel@tonic-gate 			{
17730Sstevel@tonic-gate 			print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
17740Sstevel@tonic-gate 			Time_F(START);
17750Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
17760Sstevel@tonic-gate 				AES_cbc_encrypt(buf,buf,
17770Sstevel@tonic-gate 					(unsigned long)lengths[j],&aes_ks2,
17780Sstevel@tonic-gate 					iv,AES_ENCRYPT);
17790Sstevel@tonic-gate 			d=Time_F(STOP);
17800Sstevel@tonic-gate 			print_result(D_CBC_192_AES,j,count,d);
17810Sstevel@tonic-gate 			}
17820Sstevel@tonic-gate 		}
1783688Sjp161948 #ifdef SOLARIS_OPENSSL
1784688Sjp161948 	if (doit[D_CBC_256_AES] && SUNWcry_installed)
1785688Sjp161948 #else
17860Sstevel@tonic-gate 	if (doit[D_CBC_256_AES])
1787688Sjp161948 #endif
17880Sstevel@tonic-gate 		{
17890Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
17900Sstevel@tonic-gate 			{
17910Sstevel@tonic-gate 			print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
17920Sstevel@tonic-gate 			Time_F(START);
17930Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
17940Sstevel@tonic-gate 				AES_cbc_encrypt(buf,buf,
17950Sstevel@tonic-gate 					(unsigned long)lengths[j],&aes_ks3,
17960Sstevel@tonic-gate 					iv,AES_ENCRYPT);
17970Sstevel@tonic-gate 			d=Time_F(STOP);
17980Sstevel@tonic-gate 			print_result(D_CBC_256_AES,j,count,d);
17990Sstevel@tonic-gate 			}
18000Sstevel@tonic-gate 		}
18010Sstevel@tonic-gate 
18020Sstevel@tonic-gate #endif
18030Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
18040Sstevel@tonic-gate 	if (doit[D_CBC_IDEA])
18050Sstevel@tonic-gate 		{
18060Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
18070Sstevel@tonic-gate 			{
18080Sstevel@tonic-gate 			print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
18090Sstevel@tonic-gate 			Time_F(START);
18100Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
18110Sstevel@tonic-gate 				idea_cbc_encrypt(buf,buf,
18120Sstevel@tonic-gate 					(unsigned long)lengths[j],&idea_ks,
18130Sstevel@tonic-gate 					iv,IDEA_ENCRYPT);
18140Sstevel@tonic-gate 			d=Time_F(STOP);
18150Sstevel@tonic-gate 			print_result(D_CBC_IDEA,j,count,d);
18160Sstevel@tonic-gate 			}
18170Sstevel@tonic-gate 		}
18180Sstevel@tonic-gate #endif
18190Sstevel@tonic-gate #ifndef OPENSSL_NO_RC2
18200Sstevel@tonic-gate 	if (doit[D_CBC_RC2])
18210Sstevel@tonic-gate 		{
18220Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
18230Sstevel@tonic-gate 			{
18240Sstevel@tonic-gate 			print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
18250Sstevel@tonic-gate 			Time_F(START);
18260Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
18270Sstevel@tonic-gate 				RC2_cbc_encrypt(buf,buf,
18280Sstevel@tonic-gate 					(unsigned long)lengths[j],&rc2_ks,
18290Sstevel@tonic-gate 					iv,RC2_ENCRYPT);
18300Sstevel@tonic-gate 			d=Time_F(STOP);
18310Sstevel@tonic-gate 			print_result(D_CBC_RC2,j,count,d);
18320Sstevel@tonic-gate 			}
18330Sstevel@tonic-gate 		}
18340Sstevel@tonic-gate #endif
18350Sstevel@tonic-gate #ifndef OPENSSL_NO_RC5
18360Sstevel@tonic-gate 	if (doit[D_CBC_RC5])
18370Sstevel@tonic-gate 		{
18380Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
18390Sstevel@tonic-gate 			{
18400Sstevel@tonic-gate 			print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
18410Sstevel@tonic-gate 			Time_F(START);
18420Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
18430Sstevel@tonic-gate 				RC5_32_cbc_encrypt(buf,buf,
18440Sstevel@tonic-gate 					(unsigned long)lengths[j],&rc5_ks,
18450Sstevel@tonic-gate 					iv,RC5_ENCRYPT);
18460Sstevel@tonic-gate 			d=Time_F(STOP);
18470Sstevel@tonic-gate 			print_result(D_CBC_RC5,j,count,d);
18480Sstevel@tonic-gate 			}
18490Sstevel@tonic-gate 		}
18500Sstevel@tonic-gate #endif
18510Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
18520Sstevel@tonic-gate 	if (doit[D_CBC_BF])
18530Sstevel@tonic-gate 		{
18540Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
18550Sstevel@tonic-gate 			{
18560Sstevel@tonic-gate 			print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
18570Sstevel@tonic-gate 			Time_F(START);
18580Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
18590Sstevel@tonic-gate 				BF_cbc_encrypt(buf,buf,
18600Sstevel@tonic-gate 					(unsigned long)lengths[j],&bf_ks,
18610Sstevel@tonic-gate 					iv,BF_ENCRYPT);
18620Sstevel@tonic-gate 			d=Time_F(STOP);
18630Sstevel@tonic-gate 			print_result(D_CBC_BF,j,count,d);
18640Sstevel@tonic-gate 			}
18650Sstevel@tonic-gate 		}
18660Sstevel@tonic-gate #endif
18670Sstevel@tonic-gate #ifndef OPENSSL_NO_CAST
18680Sstevel@tonic-gate 	if (doit[D_CBC_CAST])
18690Sstevel@tonic-gate 		{
18700Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
18710Sstevel@tonic-gate 			{
18720Sstevel@tonic-gate 			print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
18730Sstevel@tonic-gate 			Time_F(START);
18740Sstevel@tonic-gate 			for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
18750Sstevel@tonic-gate 				CAST_cbc_encrypt(buf,buf,
18760Sstevel@tonic-gate 					(unsigned long)lengths[j],&cast_ks,
18770Sstevel@tonic-gate 					iv,CAST_ENCRYPT);
18780Sstevel@tonic-gate 			d=Time_F(STOP);
18790Sstevel@tonic-gate 			print_result(D_CBC_CAST,j,count,d);
18800Sstevel@tonic-gate 			}
18810Sstevel@tonic-gate 		}
18820Sstevel@tonic-gate #endif
18830Sstevel@tonic-gate 
18840Sstevel@tonic-gate 	if (doit[D_EVP])
18850Sstevel@tonic-gate 		{
18860Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
18870Sstevel@tonic-gate 			{
18880Sstevel@tonic-gate 			if (evp_cipher)
18890Sstevel@tonic-gate 				{
18900Sstevel@tonic-gate 				EVP_CIPHER_CTX ctx;
18910Sstevel@tonic-gate 				int outl;
18920Sstevel@tonic-gate 
18930Sstevel@tonic-gate 				names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
18940Sstevel@tonic-gate 				/* -O3 -fschedule-insns messes up an
18950Sstevel@tonic-gate 				 * optimization here!  names[D_EVP]
18960Sstevel@tonic-gate 				 * somehow becomes NULL */
18970Sstevel@tonic-gate 				print_message(names[D_EVP],save_count,
18980Sstevel@tonic-gate 					lengths[j]);
18990Sstevel@tonic-gate 
19000Sstevel@tonic-gate 				EVP_CIPHER_CTX_init(&ctx);
19010Sstevel@tonic-gate 				if(decrypt)
19020Sstevel@tonic-gate 					EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
19030Sstevel@tonic-gate 				else
19040Sstevel@tonic-gate 					EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1905*2139Sjp161948 				EVP_CIPHER_CTX_set_padding(&ctx, 0);
19060Sstevel@tonic-gate 
19070Sstevel@tonic-gate 				Time_F(START);
19080Sstevel@tonic-gate 				if(decrypt)
19090Sstevel@tonic-gate 					for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
19100Sstevel@tonic-gate 						EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
19110Sstevel@tonic-gate 				else
19120Sstevel@tonic-gate 					for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
19130Sstevel@tonic-gate 						EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
19140Sstevel@tonic-gate 				if(decrypt)
19150Sstevel@tonic-gate 					EVP_DecryptFinal_ex(&ctx,buf,&outl);
19160Sstevel@tonic-gate 				else
19170Sstevel@tonic-gate 					EVP_EncryptFinal_ex(&ctx,buf,&outl);
19180Sstevel@tonic-gate 				d=Time_F(STOP);
19190Sstevel@tonic-gate 				EVP_CIPHER_CTX_cleanup(&ctx);
19200Sstevel@tonic-gate 				}
19210Sstevel@tonic-gate 			if (evp_md)
19220Sstevel@tonic-gate 				{
19230Sstevel@tonic-gate 				names[D_EVP]=OBJ_nid2ln(evp_md->type);
19240Sstevel@tonic-gate 				print_message(names[D_EVP],save_count,
19250Sstevel@tonic-gate 					lengths[j]);
19260Sstevel@tonic-gate 
19270Sstevel@tonic-gate 				Time_F(START);
19280Sstevel@tonic-gate 				for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
19290Sstevel@tonic-gate 					EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
19300Sstevel@tonic-gate 
19310Sstevel@tonic-gate 				d=Time_F(STOP);
19320Sstevel@tonic-gate 				}
19330Sstevel@tonic-gate 			print_result(D_EVP,j,count,d);
19340Sstevel@tonic-gate 			}
19350Sstevel@tonic-gate 		}
19360Sstevel@tonic-gate 
19370Sstevel@tonic-gate 	RAND_pseudo_bytes(buf,36);
19380Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
19390Sstevel@tonic-gate 	for (j=0; j<RSA_NUM; j++)
19400Sstevel@tonic-gate 		{
19410Sstevel@tonic-gate 		int ret;
19420Sstevel@tonic-gate 		if (!rsa_doit[j]) continue;
19430Sstevel@tonic-gate 		ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
19440Sstevel@tonic-gate 		if (ret == 0)
19450Sstevel@tonic-gate 			{
19460Sstevel@tonic-gate 			BIO_printf(bio_err,"RSA sign failure.  No RSA sign will be done.\n");
19470Sstevel@tonic-gate 			ERR_print_errors(bio_err);
19480Sstevel@tonic-gate 			rsa_count=1;
19490Sstevel@tonic-gate 			}
19500Sstevel@tonic-gate 		else
19510Sstevel@tonic-gate 			{
19520Sstevel@tonic-gate 			pkey_print_message("private","rsa",
19530Sstevel@tonic-gate 				rsa_c[j][0],rsa_bits[j],
19540Sstevel@tonic-gate 				RSA_SECONDS);
19550Sstevel@tonic-gate /*			RSA_blinding_on(rsa_key[j],NULL); */
19560Sstevel@tonic-gate 			Time_F(START);
19570Sstevel@tonic-gate 			for (count=0,run=1; COND(rsa_c[j][0]); count++)
19580Sstevel@tonic-gate 				{
19590Sstevel@tonic-gate 				ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
19600Sstevel@tonic-gate 					&rsa_num, rsa_key[j]);
19610Sstevel@tonic-gate 				if (ret == 0)
19620Sstevel@tonic-gate 					{
19630Sstevel@tonic-gate 					BIO_printf(bio_err,
19640Sstevel@tonic-gate 						"RSA sign failure\n");
19650Sstevel@tonic-gate 					ERR_print_errors(bio_err);
19660Sstevel@tonic-gate 					count=1;
19670Sstevel@tonic-gate 					break;
19680Sstevel@tonic-gate 					}
19690Sstevel@tonic-gate 				}
19700Sstevel@tonic-gate 			d=Time_F(STOP);
19710Sstevel@tonic-gate 			BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
19720Sstevel@tonic-gate 				   : "%ld %d bit private RSA's in %.2fs\n",
19730Sstevel@tonic-gate 				   count,rsa_bits[j],d);
19740Sstevel@tonic-gate 			rsa_results[j][0]=d/(double)count;
19750Sstevel@tonic-gate 			rsa_count=count;
19760Sstevel@tonic-gate 			}
19770Sstevel@tonic-gate 
19780Sstevel@tonic-gate #if 1
19790Sstevel@tonic-gate 		ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
19800Sstevel@tonic-gate 		if (ret <= 0)
19810Sstevel@tonic-gate 			{
19820Sstevel@tonic-gate 			BIO_printf(bio_err,"RSA verify failure.  No RSA verify will be done.\n");
19830Sstevel@tonic-gate 			ERR_print_errors(bio_err);
19840Sstevel@tonic-gate 			rsa_doit[j] = 0;
19850Sstevel@tonic-gate 			}
19860Sstevel@tonic-gate 		else
19870Sstevel@tonic-gate 			{
19880Sstevel@tonic-gate 			pkey_print_message("public","rsa",
19890Sstevel@tonic-gate 				rsa_c[j][1],rsa_bits[j],
19900Sstevel@tonic-gate 				RSA_SECONDS);
19910Sstevel@tonic-gate 			Time_F(START);
19920Sstevel@tonic-gate 			for (count=0,run=1; COND(rsa_c[j][1]); count++)
19930Sstevel@tonic-gate 				{
19940Sstevel@tonic-gate 				ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
19950Sstevel@tonic-gate 					rsa_num, rsa_key[j]);
19960Sstevel@tonic-gate 				if (ret == 0)
19970Sstevel@tonic-gate 					{
19980Sstevel@tonic-gate 					BIO_printf(bio_err,
19990Sstevel@tonic-gate 						"RSA verify failure\n");
20000Sstevel@tonic-gate 					ERR_print_errors(bio_err);
20010Sstevel@tonic-gate 					count=1;
20020Sstevel@tonic-gate 					break;
20030Sstevel@tonic-gate 					}
20040Sstevel@tonic-gate 				}
20050Sstevel@tonic-gate 			d=Time_F(STOP);
20060Sstevel@tonic-gate 			BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
20070Sstevel@tonic-gate 				   : "%ld %d bit public RSA's in %.2fs\n",
20080Sstevel@tonic-gate 				   count,rsa_bits[j],d);
20090Sstevel@tonic-gate 			rsa_results[j][1]=d/(double)count;
20100Sstevel@tonic-gate 			}
20110Sstevel@tonic-gate #endif
20120Sstevel@tonic-gate 
20130Sstevel@tonic-gate 		if (rsa_count <= 1)
20140Sstevel@tonic-gate 			{
20150Sstevel@tonic-gate 			/* if longer than 10s, don't do any more */
20160Sstevel@tonic-gate 			for (j++; j<RSA_NUM; j++)
20170Sstevel@tonic-gate 				rsa_doit[j]=0;
20180Sstevel@tonic-gate 			}
20190Sstevel@tonic-gate 		}
20200Sstevel@tonic-gate #endif
20210Sstevel@tonic-gate 
20220Sstevel@tonic-gate 	RAND_pseudo_bytes(buf,20);
20230Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
20240Sstevel@tonic-gate 	if (RAND_status() != 1)
20250Sstevel@tonic-gate 		{
20260Sstevel@tonic-gate 		RAND_seed(rnd_seed, sizeof rnd_seed);
20270Sstevel@tonic-gate 		rnd_fake = 1;
20280Sstevel@tonic-gate 		}
20290Sstevel@tonic-gate 	for (j=0; j<DSA_NUM; j++)
20300Sstevel@tonic-gate 		{
20310Sstevel@tonic-gate 		unsigned int kk;
20320Sstevel@tonic-gate 		int ret;
20330Sstevel@tonic-gate 
20340Sstevel@tonic-gate 		if (!dsa_doit[j]) continue;
20350Sstevel@tonic-gate /*		DSA_generate_key(dsa_key[j]); */
20360Sstevel@tonic-gate /*		DSA_sign_setup(dsa_key[j],NULL); */
20370Sstevel@tonic-gate 		ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
20380Sstevel@tonic-gate 			&kk,dsa_key[j]);
20390Sstevel@tonic-gate 		if (ret == 0)
20400Sstevel@tonic-gate 			{
20410Sstevel@tonic-gate 			BIO_printf(bio_err,"DSA sign failure.  No DSA sign will be done.\n");
20420Sstevel@tonic-gate 			ERR_print_errors(bio_err);
20430Sstevel@tonic-gate 			rsa_count=1;
20440Sstevel@tonic-gate 			}
20450Sstevel@tonic-gate 		else
20460Sstevel@tonic-gate 			{
20470Sstevel@tonic-gate 			pkey_print_message("sign","dsa",
20480Sstevel@tonic-gate 				dsa_c[j][0],dsa_bits[j],
20490Sstevel@tonic-gate 				DSA_SECONDS);
20500Sstevel@tonic-gate 			Time_F(START);
20510Sstevel@tonic-gate 			for (count=0,run=1; COND(dsa_c[j][0]); count++)
20520Sstevel@tonic-gate 				{
20530Sstevel@tonic-gate 				ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
20540Sstevel@tonic-gate 					&kk,dsa_key[j]);
20550Sstevel@tonic-gate 				if (ret == 0)
20560Sstevel@tonic-gate 					{
20570Sstevel@tonic-gate 					BIO_printf(bio_err,
20580Sstevel@tonic-gate 						"DSA sign failure\n");
20590Sstevel@tonic-gate 					ERR_print_errors(bio_err);
20600Sstevel@tonic-gate 					count=1;
20610Sstevel@tonic-gate 					break;
20620Sstevel@tonic-gate 					}
20630Sstevel@tonic-gate 				}
20640Sstevel@tonic-gate 			d=Time_F(STOP);
20650Sstevel@tonic-gate 			BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
20660Sstevel@tonic-gate 				   : "%ld %d bit DSA signs in %.2fs\n",
20670Sstevel@tonic-gate 				   count,dsa_bits[j],d);
20680Sstevel@tonic-gate 			dsa_results[j][0]=d/(double)count;
20690Sstevel@tonic-gate 			rsa_count=count;
20700Sstevel@tonic-gate 			}
20710Sstevel@tonic-gate 
20720Sstevel@tonic-gate 		ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
20730Sstevel@tonic-gate 			kk,dsa_key[j]);
20740Sstevel@tonic-gate 		if (ret <= 0)
20750Sstevel@tonic-gate 			{
20760Sstevel@tonic-gate 			BIO_printf(bio_err,"DSA verify failure.  No DSA verify will be done.\n");
20770Sstevel@tonic-gate 			ERR_print_errors(bio_err);
20780Sstevel@tonic-gate 			dsa_doit[j] = 0;
20790Sstevel@tonic-gate 			}
20800Sstevel@tonic-gate 		else
20810Sstevel@tonic-gate 			{
20820Sstevel@tonic-gate 			pkey_print_message("verify","dsa",
20830Sstevel@tonic-gate 				dsa_c[j][1],dsa_bits[j],
20840Sstevel@tonic-gate 				DSA_SECONDS);
20850Sstevel@tonic-gate 			Time_F(START);
20860Sstevel@tonic-gate 			for (count=0,run=1; COND(dsa_c[j][1]); count++)
20870Sstevel@tonic-gate 				{
20880Sstevel@tonic-gate 				ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
20890Sstevel@tonic-gate 					kk,dsa_key[j]);
20900Sstevel@tonic-gate 				if (ret <= 0)
20910Sstevel@tonic-gate 					{
20920Sstevel@tonic-gate 					BIO_printf(bio_err,
20930Sstevel@tonic-gate 						"DSA verify failure\n");
20940Sstevel@tonic-gate 					ERR_print_errors(bio_err);
20950Sstevel@tonic-gate 					count=1;
20960Sstevel@tonic-gate 					break;
20970Sstevel@tonic-gate 					}
20980Sstevel@tonic-gate 				}
20990Sstevel@tonic-gate 			d=Time_F(STOP);
21000Sstevel@tonic-gate 			BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
21010Sstevel@tonic-gate 				   : "%ld %d bit DSA verify in %.2fs\n",
21020Sstevel@tonic-gate 				   count,dsa_bits[j],d);
21030Sstevel@tonic-gate 			dsa_results[j][1]=d/(double)count;
21040Sstevel@tonic-gate 			}
21050Sstevel@tonic-gate 
21060Sstevel@tonic-gate 		if (rsa_count <= 1)
21070Sstevel@tonic-gate 			{
21080Sstevel@tonic-gate 			/* if longer than 10s, don't do any more */
21090Sstevel@tonic-gate 			for (j++; j<DSA_NUM; j++)
21100Sstevel@tonic-gate 				dsa_doit[j]=0;
21110Sstevel@tonic-gate 			}
21120Sstevel@tonic-gate 		}
21130Sstevel@tonic-gate 	if (rnd_fake) RAND_cleanup();
21140Sstevel@tonic-gate #endif
2115*2139Sjp161948 
2116*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
2117*2139Sjp161948 	if (RAND_status() != 1)
2118*2139Sjp161948 		{
2119*2139Sjp161948 		RAND_seed(rnd_seed, sizeof rnd_seed);
2120*2139Sjp161948 		rnd_fake = 1;
2121*2139Sjp161948 		}
2122*2139Sjp161948 	for (j=0; j<EC_NUM; j++)
2123*2139Sjp161948 		{
2124*2139Sjp161948 		int ret;
2125*2139Sjp161948 
2126*2139Sjp161948 		if (!ecdsa_doit[j]) continue; /* Ignore Curve */
2127*2139Sjp161948 		ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2128*2139Sjp161948 		if (ecdsa[j] == NULL)
2129*2139Sjp161948 			{
2130*2139Sjp161948 			BIO_printf(bio_err,"ECDSA failure.\n");
2131*2139Sjp161948 			ERR_print_errors(bio_err);
2132*2139Sjp161948 			rsa_count=1;
2133*2139Sjp161948 			}
2134*2139Sjp161948 		else
2135*2139Sjp161948 			{
2136*2139Sjp161948 #if 1
2137*2139Sjp161948 			EC_KEY_precompute_mult(ecdsa[j], NULL);
2138*2139Sjp161948 #endif
2139*2139Sjp161948 			/* Perform ECDSA signature test */
2140*2139Sjp161948 			EC_KEY_generate_key(ecdsa[j]);
2141*2139Sjp161948 			ret = ECDSA_sign(0, buf, 20, ecdsasig,
2142*2139Sjp161948 				&ecdsasiglen, ecdsa[j]);
2143*2139Sjp161948 			if (ret == 0)
2144*2139Sjp161948 				{
2145*2139Sjp161948 				BIO_printf(bio_err,"ECDSA sign failure.  No ECDSA sign will be done.\n");
2146*2139Sjp161948 				ERR_print_errors(bio_err);
2147*2139Sjp161948 				rsa_count=1;
2148*2139Sjp161948 				}
2149*2139Sjp161948 			else
2150*2139Sjp161948 				{
2151*2139Sjp161948 				pkey_print_message("sign","ecdsa",
2152*2139Sjp161948 					ecdsa_c[j][0],
2153*2139Sjp161948 					test_curves_bits[j],
2154*2139Sjp161948 					ECDSA_SECONDS);
2155*2139Sjp161948 
2156*2139Sjp161948 				Time_F(START);
2157*2139Sjp161948 				for (count=0,run=1; COND(ecdsa_c[j][0]);
2158*2139Sjp161948 					count++)
2159*2139Sjp161948 					{
2160*2139Sjp161948 					ret=ECDSA_sign(0, buf, 20,
2161*2139Sjp161948 						ecdsasig, &ecdsasiglen,
2162*2139Sjp161948 						ecdsa[j]);
2163*2139Sjp161948 					if (ret == 0)
2164*2139Sjp161948 						{
2165*2139Sjp161948 						BIO_printf(bio_err, "ECDSA sign failure\n");
2166*2139Sjp161948 						ERR_print_errors(bio_err);
2167*2139Sjp161948 						count=1;
2168*2139Sjp161948 						break;
2169*2139Sjp161948 						}
2170*2139Sjp161948 					}
2171*2139Sjp161948 				d=Time_F(STOP);
2172*2139Sjp161948 
2173*2139Sjp161948 				BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
2174*2139Sjp161948 					"%ld %d bit ECDSA signs in %.2fs \n",
2175*2139Sjp161948 					count, test_curves_bits[j], d);
2176*2139Sjp161948 				ecdsa_results[j][0]=d/(double)count;
2177*2139Sjp161948 				rsa_count=count;
2178*2139Sjp161948 				}
2179*2139Sjp161948 
2180*2139Sjp161948 			/* Perform ECDSA verification test */
2181*2139Sjp161948 			ret=ECDSA_verify(0, buf, 20, ecdsasig,
2182*2139Sjp161948 				ecdsasiglen, ecdsa[j]);
2183*2139Sjp161948 			if (ret != 1)
2184*2139Sjp161948 				{
2185*2139Sjp161948 				BIO_printf(bio_err,"ECDSA verify failure.  No ECDSA verify will be done.\n");
2186*2139Sjp161948 				ERR_print_errors(bio_err);
2187*2139Sjp161948 				ecdsa_doit[j] = 0;
2188*2139Sjp161948 				}
2189*2139Sjp161948 			else
2190*2139Sjp161948 				{
2191*2139Sjp161948 				pkey_print_message("verify","ecdsa",
2192*2139Sjp161948 				ecdsa_c[j][1],
2193*2139Sjp161948 				test_curves_bits[j],
2194*2139Sjp161948 				ECDSA_SECONDS);
2195*2139Sjp161948 				Time_F(START);
2196*2139Sjp161948 				for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
2197*2139Sjp161948 					{
2198*2139Sjp161948 					ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
2199*2139Sjp161948 					if (ret != 1)
2200*2139Sjp161948 						{
2201*2139Sjp161948 						BIO_printf(bio_err, "ECDSA verify failure\n");
2202*2139Sjp161948 						ERR_print_errors(bio_err);
2203*2139Sjp161948 						count=1;
2204*2139Sjp161948 						break;
2205*2139Sjp161948 						}
2206*2139Sjp161948 					}
2207*2139Sjp161948 				d=Time_F(STOP);
2208*2139Sjp161948 				BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
2209*2139Sjp161948 						: "%ld %d bit ECDSA verify in %.2fs\n",
2210*2139Sjp161948 				count, test_curves_bits[j], d);
2211*2139Sjp161948 				ecdsa_results[j][1]=d/(double)count;
2212*2139Sjp161948 				}
2213*2139Sjp161948 
2214*2139Sjp161948 			if (rsa_count <= 1)
2215*2139Sjp161948 				{
2216*2139Sjp161948 				/* if longer than 10s, don't do any more */
2217*2139Sjp161948 				for (j++; j<EC_NUM; j++)
2218*2139Sjp161948 				ecdsa_doit[j]=0;
2219*2139Sjp161948 				}
2220*2139Sjp161948 			}
2221*2139Sjp161948 		}
2222*2139Sjp161948 	if (rnd_fake) RAND_cleanup();
2223*2139Sjp161948 #endif
2224*2139Sjp161948 
2225*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
2226*2139Sjp161948 	if (RAND_status() != 1)
2227*2139Sjp161948 		{
2228*2139Sjp161948 		RAND_seed(rnd_seed, sizeof rnd_seed);
2229*2139Sjp161948 		rnd_fake = 1;
2230*2139Sjp161948 		}
2231*2139Sjp161948 	for (j=0; j<EC_NUM; j++)
2232*2139Sjp161948 		{
2233*2139Sjp161948 		if (!ecdh_doit[j]) continue;
2234*2139Sjp161948 		ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2235*2139Sjp161948 		ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
2236*2139Sjp161948 		if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
2237*2139Sjp161948 			{
2238*2139Sjp161948 			BIO_printf(bio_err,"ECDH failure.\n");
2239*2139Sjp161948 			ERR_print_errors(bio_err);
2240*2139Sjp161948 			rsa_count=1;
2241*2139Sjp161948 			}
2242*2139Sjp161948 		else
2243*2139Sjp161948 			{
2244*2139Sjp161948 			/* generate two ECDH key pairs */
2245*2139Sjp161948 			if (!EC_KEY_generate_key(ecdh_a[j]) ||
2246*2139Sjp161948 				!EC_KEY_generate_key(ecdh_b[j]))
2247*2139Sjp161948 				{
2248*2139Sjp161948 				BIO_printf(bio_err,"ECDH key generation failure.\n");
2249*2139Sjp161948 				ERR_print_errors(bio_err);
2250*2139Sjp161948 				rsa_count=1;
2251*2139Sjp161948 				}
2252*2139Sjp161948 			else
2253*2139Sjp161948 				{
2254*2139Sjp161948 				/* If field size is not more than 24 octets, then use SHA-1 hash of result;
2255*2139Sjp161948 				 * otherwise, use result (see section 4.8 of draft-ietf-tls-ecc-03.txt).
2256*2139Sjp161948 				 */
2257*2139Sjp161948 				int field_size, outlen;
2258*2139Sjp161948 				void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
2259*2139Sjp161948 				field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
2260*2139Sjp161948 				if (field_size <= 24 * 8)
2261*2139Sjp161948 					{
2262*2139Sjp161948 					outlen = KDF1_SHA1_len;
2263*2139Sjp161948 					kdf = KDF1_SHA1;
2264*2139Sjp161948 					}
2265*2139Sjp161948 				else
2266*2139Sjp161948 					{
2267*2139Sjp161948 					outlen = (field_size+7)/8;
2268*2139Sjp161948 					kdf = NULL;
2269*2139Sjp161948 					}
2270*2139Sjp161948 				secret_size_a = ECDH_compute_key(secret_a, outlen,
2271*2139Sjp161948 					EC_KEY_get0_public_key(ecdh_b[j]),
2272*2139Sjp161948 					ecdh_a[j], kdf);
2273*2139Sjp161948 				secret_size_b = ECDH_compute_key(secret_b, outlen,
2274*2139Sjp161948 					EC_KEY_get0_public_key(ecdh_a[j]),
2275*2139Sjp161948 					ecdh_b[j], kdf);
2276*2139Sjp161948 				if (secret_size_a != secret_size_b)
2277*2139Sjp161948 					ecdh_checks = 0;
2278*2139Sjp161948 				else
2279*2139Sjp161948 					ecdh_checks = 1;
2280*2139Sjp161948 
2281*2139Sjp161948 				for (secret_idx = 0;
2282*2139Sjp161948 				    (secret_idx < secret_size_a)
2283*2139Sjp161948 					&& (ecdh_checks == 1);
2284*2139Sjp161948 				    secret_idx++)
2285*2139Sjp161948 					{
2286*2139Sjp161948 					if (secret_a[secret_idx] != secret_b[secret_idx])
2287*2139Sjp161948 					ecdh_checks = 0;
2288*2139Sjp161948 					}
2289*2139Sjp161948 
2290*2139Sjp161948 				if (ecdh_checks == 0)
2291*2139Sjp161948 					{
2292*2139Sjp161948 					BIO_printf(bio_err,"ECDH computations don't match.\n");
2293*2139Sjp161948 					ERR_print_errors(bio_err);
2294*2139Sjp161948 					rsa_count=1;
2295*2139Sjp161948 					}
2296*2139Sjp161948 
2297*2139Sjp161948 				pkey_print_message("","ecdh",
2298*2139Sjp161948 				ecdh_c[j][0],
2299*2139Sjp161948 				test_curves_bits[j],
2300*2139Sjp161948 				ECDH_SECONDS);
2301*2139Sjp161948 				Time_F(START);
2302*2139Sjp161948 				for (count=0,run=1; COND(ecdh_c[j][0]); count++)
2303*2139Sjp161948 					{
2304*2139Sjp161948 					ECDH_compute_key(secret_a, outlen,
2305*2139Sjp161948 					EC_KEY_get0_public_key(ecdh_b[j]),
2306*2139Sjp161948 					ecdh_a[j], kdf);
2307*2139Sjp161948 					}
2308*2139Sjp161948 				d=Time_F(STOP);
2309*2139Sjp161948 				BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
2310*2139Sjp161948 				count, test_curves_bits[j], d);
2311*2139Sjp161948 				ecdh_results[j][0]=d/(double)count;
2312*2139Sjp161948 				rsa_count=count;
2313*2139Sjp161948 				}
2314*2139Sjp161948 			}
2315*2139Sjp161948 
2316*2139Sjp161948 
2317*2139Sjp161948 		if (rsa_count <= 1)
2318*2139Sjp161948 			{
2319*2139Sjp161948 			/* if longer than 10s, don't do any more */
2320*2139Sjp161948 			for (j++; j<EC_NUM; j++)
2321*2139Sjp161948 			ecdh_doit[j]=0;
2322*2139Sjp161948 			}
2323*2139Sjp161948 		}
2324*2139Sjp161948 	if (rnd_fake) RAND_cleanup();
2325*2139Sjp161948 #endif
23260Sstevel@tonic-gate #ifdef HAVE_FORK
23270Sstevel@tonic-gate show_res:
23280Sstevel@tonic-gate #endif
23290Sstevel@tonic-gate 	if(!mr)
23300Sstevel@tonic-gate 		{
23310Sstevel@tonic-gate 		fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
23320Sstevel@tonic-gate         fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
23330Sstevel@tonic-gate 		printf("options:");
23340Sstevel@tonic-gate 		printf("%s ",BN_options());
23350Sstevel@tonic-gate #ifndef OPENSSL_NO_MD2
23360Sstevel@tonic-gate 		printf("%s ",MD2_options());
23370Sstevel@tonic-gate #endif
23380Sstevel@tonic-gate #ifndef OPENSSL_NO_RC4
23390Sstevel@tonic-gate 		printf("%s ",RC4_options());
23400Sstevel@tonic-gate #endif
23410Sstevel@tonic-gate #ifndef OPENSSL_NO_DES
23420Sstevel@tonic-gate 		printf("%s ",DES_options());
23430Sstevel@tonic-gate #endif
23440Sstevel@tonic-gate #ifndef OPENSSL_NO_AES
23450Sstevel@tonic-gate 		printf("%s ",AES_options());
23460Sstevel@tonic-gate #endif
23470Sstevel@tonic-gate #ifndef OPENSSL_NO_IDEA
23480Sstevel@tonic-gate 		printf("%s ",idea_options());
23490Sstevel@tonic-gate #endif
23500Sstevel@tonic-gate #ifndef OPENSSL_NO_BF
23510Sstevel@tonic-gate 		printf("%s ",BF_options());
23520Sstevel@tonic-gate #endif
23530Sstevel@tonic-gate 		fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
23540Sstevel@tonic-gate 		printf("available timing options: ");
23550Sstevel@tonic-gate #ifdef TIMES
23560Sstevel@tonic-gate 		printf("TIMES ");
23570Sstevel@tonic-gate #endif
23580Sstevel@tonic-gate #ifdef TIMEB
23590Sstevel@tonic-gate 		printf("TIMEB ");
23600Sstevel@tonic-gate #endif
23610Sstevel@tonic-gate #ifdef USE_TOD
23620Sstevel@tonic-gate 		printf("USE_TOD ");
23630Sstevel@tonic-gate #endif
23640Sstevel@tonic-gate #ifdef HZ
23650Sstevel@tonic-gate #define as_string(s) (#s)
2366*2139Sjp161948 		{
2367*2139Sjp161948 		double dbl = HZ;
2368*2139Sjp161948 		printf("HZ=%g", dbl);
2369*2139Sjp161948 		}
23700Sstevel@tonic-gate # ifdef _SC_CLK_TCK
23710Sstevel@tonic-gate 		printf(" [sysconf value]");
23720Sstevel@tonic-gate # endif
23730Sstevel@tonic-gate #endif
23740Sstevel@tonic-gate 		printf("\n");
23750Sstevel@tonic-gate 		printf("timing function used: %s%s%s%s%s%s%s\n",
23760Sstevel@tonic-gate 		       (ftime_used ? "ftime" : ""),
23770Sstevel@tonic-gate 		       (ftime_used + times_used > 1 ? "," : ""),
23780Sstevel@tonic-gate 		       (times_used ? "times" : ""),
23790Sstevel@tonic-gate 		       (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
23800Sstevel@tonic-gate 		       (gettimeofday_used ? "gettimeofday" : ""),
23810Sstevel@tonic-gate 		       (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
23820Sstevel@tonic-gate 		       (getrusage_used ? "getrusage" : ""));
23830Sstevel@tonic-gate 		}
23840Sstevel@tonic-gate 
23850Sstevel@tonic-gate 	if (pr_header)
23860Sstevel@tonic-gate 		{
23870Sstevel@tonic-gate 		if(mr)
23880Sstevel@tonic-gate 			fprintf(stdout,"+H");
23890Sstevel@tonic-gate 		else
23900Sstevel@tonic-gate 			{
23910Sstevel@tonic-gate 			fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
23920Sstevel@tonic-gate 			fprintf(stdout,"type        ");
23930Sstevel@tonic-gate 			}
23940Sstevel@tonic-gate 		for (j=0;  j<SIZE_NUM; j++)
23950Sstevel@tonic-gate 			fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
23960Sstevel@tonic-gate 		fprintf(stdout,"\n");
23970Sstevel@tonic-gate 		}
23980Sstevel@tonic-gate 
23990Sstevel@tonic-gate 	for (k=0; k<ALGOR_NUM; k++)
24000Sstevel@tonic-gate 		{
24010Sstevel@tonic-gate 		if (!doit[k]) continue;
2402688Sjp161948 #ifdef SOLARIS_OPENSSL
2403688Sjp161948 		if ((k == D_CBC_192_AES || k == D_CBC_256_AES) && !SUNWcry_installed) continue;
2404688Sjp161948 #endif
24050Sstevel@tonic-gate 		if(mr)
24060Sstevel@tonic-gate 			fprintf(stdout,"+F:%d:%s",k,names[k]);
24070Sstevel@tonic-gate 		else
24080Sstevel@tonic-gate 			fprintf(stdout,"%-13s",names[k]);
24090Sstevel@tonic-gate 		for (j=0; j<SIZE_NUM; j++)
24100Sstevel@tonic-gate 			{
24110Sstevel@tonic-gate 			if (results[k][j] > 10000 && !mr)
24120Sstevel@tonic-gate 				fprintf(stdout," %11.2fk",results[k][j]/1e3);
24130Sstevel@tonic-gate 			else
24140Sstevel@tonic-gate 				fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
24150Sstevel@tonic-gate 			}
24160Sstevel@tonic-gate 		fprintf(stdout,"\n");
24170Sstevel@tonic-gate 		}
24180Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
24190Sstevel@tonic-gate 	j=1;
24200Sstevel@tonic-gate 	for (k=0; k<RSA_NUM; k++)
24210Sstevel@tonic-gate 		{
24220Sstevel@tonic-gate 		if (!rsa_doit[k]) continue;
24230Sstevel@tonic-gate 		if (j && !mr)
24240Sstevel@tonic-gate 			{
24250Sstevel@tonic-gate 			printf("%18ssign    verify    sign/s verify/s\n"," ");
24260Sstevel@tonic-gate 			j=0;
24270Sstevel@tonic-gate 			}
24280Sstevel@tonic-gate 		if(mr)
24290Sstevel@tonic-gate 			fprintf(stdout,"+F2:%u:%u:%f:%f\n",
24300Sstevel@tonic-gate 				k,rsa_bits[k],rsa_results[k][0],
24310Sstevel@tonic-gate 				rsa_results[k][1]);
24320Sstevel@tonic-gate 		else
2433*2139Sjp161948 			fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
24340Sstevel@tonic-gate 				rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
24350Sstevel@tonic-gate 				1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
24360Sstevel@tonic-gate 		}
24370Sstevel@tonic-gate #endif
24380Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
24390Sstevel@tonic-gate 	j=1;
24400Sstevel@tonic-gate 	for (k=0; k<DSA_NUM; k++)
24410Sstevel@tonic-gate 		{
24420Sstevel@tonic-gate 		if (!dsa_doit[k]) continue;
24430Sstevel@tonic-gate 		if (j && !mr)
24440Sstevel@tonic-gate 			{
24450Sstevel@tonic-gate 			printf("%18ssign    verify    sign/s verify/s\n"," ");
24460Sstevel@tonic-gate 			j=0;
24470Sstevel@tonic-gate 			}
24480Sstevel@tonic-gate 		if(mr)
24490Sstevel@tonic-gate 			fprintf(stdout,"+F3:%u:%u:%f:%f\n",
24500Sstevel@tonic-gate 				k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
24510Sstevel@tonic-gate 		else
2452*2139Sjp161948 			fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
24530Sstevel@tonic-gate 				dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
24540Sstevel@tonic-gate 				1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
24550Sstevel@tonic-gate 		}
24560Sstevel@tonic-gate #endif
2457*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
2458*2139Sjp161948 	j=1;
2459*2139Sjp161948 	for (k=0; k<EC_NUM; k++)
2460*2139Sjp161948 		{
2461*2139Sjp161948 		if (!ecdsa_doit[k]) continue;
2462*2139Sjp161948 		if (j && !mr)
2463*2139Sjp161948 			{
2464*2139Sjp161948 			printf("%30ssign    verify    sign/s verify/s\n"," ");
2465*2139Sjp161948 			j=0;
2466*2139Sjp161948 			}
2467*2139Sjp161948 
2468*2139Sjp161948 		if (mr)
2469*2139Sjp161948 			fprintf(stdout,"+F4:%u:%u:%f:%f\n",
2470*2139Sjp161948 				k, test_curves_bits[k],
2471*2139Sjp161948 				ecdsa_results[k][0],ecdsa_results[k][1]);
2472*2139Sjp161948 		else
2473*2139Sjp161948 			fprintf(stdout,
2474*2139Sjp161948 				"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
2475*2139Sjp161948 				test_curves_bits[k],
2476*2139Sjp161948 				test_curves_names[k],
2477*2139Sjp161948 				ecdsa_results[k][0],ecdsa_results[k][1],
2478*2139Sjp161948 				1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
2479*2139Sjp161948 		}
2480*2139Sjp161948 #endif
2481*2139Sjp161948 
2482*2139Sjp161948 
2483*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
2484*2139Sjp161948 	j=1;
2485*2139Sjp161948 	for (k=0; k<EC_NUM; k++)
2486*2139Sjp161948 		{
2487*2139Sjp161948 		if (!ecdh_doit[k]) continue;
2488*2139Sjp161948 		if (j && !mr)
2489*2139Sjp161948 			{
2490*2139Sjp161948 			printf("%30sop      op/s\n"," ");
2491*2139Sjp161948 			j=0;
2492*2139Sjp161948 			}
2493*2139Sjp161948 		if (mr)
2494*2139Sjp161948 			fprintf(stdout,"+F5:%u:%u:%f:%f\n",
2495*2139Sjp161948 				k, test_curves_bits[k],
2496*2139Sjp161948 				ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2497*2139Sjp161948 
2498*2139Sjp161948 		else
2499*2139Sjp161948 			fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
2500*2139Sjp161948 				test_curves_bits[k],
2501*2139Sjp161948 				test_curves_names[k],
2502*2139Sjp161948 				ecdh_results[k][0], 1.0/ecdh_results[k][0]);
2503*2139Sjp161948 		}
2504*2139Sjp161948 #endif
2505*2139Sjp161948 
25060Sstevel@tonic-gate 	mret=0;
2507*2139Sjp161948 
25080Sstevel@tonic-gate end:
25090Sstevel@tonic-gate 	ERR_print_errors(bio_err);
25100Sstevel@tonic-gate 	if (buf != NULL) OPENSSL_free(buf);
25110Sstevel@tonic-gate 	if (buf2 != NULL) OPENSSL_free(buf2);
25120Sstevel@tonic-gate #ifndef OPENSSL_NO_RSA
25130Sstevel@tonic-gate 	for (i=0; i<RSA_NUM; i++)
25140Sstevel@tonic-gate 		if (rsa_key[i] != NULL)
25150Sstevel@tonic-gate 			RSA_free(rsa_key[i]);
25160Sstevel@tonic-gate #endif
25170Sstevel@tonic-gate #ifndef OPENSSL_NO_DSA
25180Sstevel@tonic-gate 	for (i=0; i<DSA_NUM; i++)
25190Sstevel@tonic-gate 		if (dsa_key[i] != NULL)
25200Sstevel@tonic-gate 			DSA_free(dsa_key[i]);
25210Sstevel@tonic-gate #endif
2522*2139Sjp161948 
2523*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
2524*2139Sjp161948 	for (i=0; i<EC_NUM; i++)
2525*2139Sjp161948 		if (ecdsa[i] != NULL)
2526*2139Sjp161948 			EC_KEY_free(ecdsa[i]);
2527*2139Sjp161948 #endif
2528*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
2529*2139Sjp161948 	for (i=0; i<EC_NUM; i++)
2530*2139Sjp161948 	{
2531*2139Sjp161948 		if (ecdh_a[i] != NULL)
2532*2139Sjp161948 			EC_KEY_free(ecdh_a[i]);
2533*2139Sjp161948 		if (ecdh_b[i] != NULL)
2534*2139Sjp161948 			EC_KEY_free(ecdh_b[i]);
2535*2139Sjp161948 	}
2536*2139Sjp161948 #endif
2537*2139Sjp161948 
25380Sstevel@tonic-gate 	apps_shutdown();
25390Sstevel@tonic-gate 	OPENSSL_EXIT(mret);
25400Sstevel@tonic-gate 	}
25410Sstevel@tonic-gate 
25420Sstevel@tonic-gate static void print_message(const char *s, long num, int length)
25430Sstevel@tonic-gate 	{
25440Sstevel@tonic-gate #ifdef SIGALRM
25450Sstevel@tonic-gate 	BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
25460Sstevel@tonic-gate 		   : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
25470Sstevel@tonic-gate 	(void)BIO_flush(bio_err);
25480Sstevel@tonic-gate 	alarm(SECONDS);
25490Sstevel@tonic-gate #else
25500Sstevel@tonic-gate 	BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
25510Sstevel@tonic-gate 		   : "Doing %s %ld times on %d size blocks: ",s,num,length);
25520Sstevel@tonic-gate 	(void)BIO_flush(bio_err);
25530Sstevel@tonic-gate #endif
25540Sstevel@tonic-gate #ifdef LINT
25550Sstevel@tonic-gate 	num=num;
25560Sstevel@tonic-gate #endif
25570Sstevel@tonic-gate 	}
25580Sstevel@tonic-gate 
2559*2139Sjp161948 static void pkey_print_message(const char *str, const char *str2, long num,
2560*2139Sjp161948 	int bits, int tm)
25610Sstevel@tonic-gate 	{
25620Sstevel@tonic-gate #ifdef SIGALRM
25630Sstevel@tonic-gate 	BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
25640Sstevel@tonic-gate 			   : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
25650Sstevel@tonic-gate 	(void)BIO_flush(bio_err);
25660Sstevel@tonic-gate 	alarm(RSA_SECONDS);
25670Sstevel@tonic-gate #else
25680Sstevel@tonic-gate 	BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
25690Sstevel@tonic-gate 			   : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
25700Sstevel@tonic-gate 	(void)BIO_flush(bio_err);
25710Sstevel@tonic-gate #endif
25720Sstevel@tonic-gate #ifdef LINT
25730Sstevel@tonic-gate 	num=num;
25740Sstevel@tonic-gate #endif
25750Sstevel@tonic-gate 	}
25760Sstevel@tonic-gate 
25770Sstevel@tonic-gate static void print_result(int alg,int run_no,int count,double time_used)
25780Sstevel@tonic-gate 	{
2579*2139Sjp161948 	BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
2580*2139Sjp161948 		   : "%d %s's in %.2fs\n",count,names[alg],time_used);
25810Sstevel@tonic-gate 	results[alg][run_no]=((double)count)/time_used*lengths[run_no];
25820Sstevel@tonic-gate 	}
25830Sstevel@tonic-gate 
25840Sstevel@tonic-gate static char *sstrsep(char **string, const char *delim)
25850Sstevel@tonic-gate     {
25860Sstevel@tonic-gate     char isdelim[256];
25870Sstevel@tonic-gate     char *token = *string;
25880Sstevel@tonic-gate 
25890Sstevel@tonic-gate     if (**string == 0)
25900Sstevel@tonic-gate         return NULL;
25910Sstevel@tonic-gate 
25920Sstevel@tonic-gate     memset(isdelim, 0, sizeof isdelim);
25930Sstevel@tonic-gate     isdelim[0] = 1;
25940Sstevel@tonic-gate 
25950Sstevel@tonic-gate     while (*delim)
25960Sstevel@tonic-gate         {
25970Sstevel@tonic-gate         isdelim[(unsigned char)(*delim)] = 1;
25980Sstevel@tonic-gate         delim++;
25990Sstevel@tonic-gate         }
26000Sstevel@tonic-gate 
26010Sstevel@tonic-gate     while (!isdelim[(unsigned char)(**string)])
26020Sstevel@tonic-gate         {
26030Sstevel@tonic-gate         (*string)++;
26040Sstevel@tonic-gate         }
26050Sstevel@tonic-gate 
26060Sstevel@tonic-gate     if (**string)
26070Sstevel@tonic-gate         {
26080Sstevel@tonic-gate         **string = 0;
26090Sstevel@tonic-gate         (*string)++;
26100Sstevel@tonic-gate         }
26110Sstevel@tonic-gate 
26120Sstevel@tonic-gate     return token;
26130Sstevel@tonic-gate     }
26140Sstevel@tonic-gate 
26150Sstevel@tonic-gate #ifdef HAVE_FORK
26160Sstevel@tonic-gate static int do_multi(int multi)
26170Sstevel@tonic-gate 	{
26180Sstevel@tonic-gate 	int n;
26190Sstevel@tonic-gate 	int fd[2];
26200Sstevel@tonic-gate 	int *fds;
26210Sstevel@tonic-gate 	static char sep[]=":";
26220Sstevel@tonic-gate 
26230Sstevel@tonic-gate 	fds=malloc(multi*sizeof *fds);
26240Sstevel@tonic-gate 	for(n=0 ; n < multi ; ++n)
26250Sstevel@tonic-gate 		{
26260Sstevel@tonic-gate 		pipe(fd);
26270Sstevel@tonic-gate 		if(fork())
26280Sstevel@tonic-gate 			{
26290Sstevel@tonic-gate 			close(fd[1]);
26300Sstevel@tonic-gate 			fds[n]=fd[0];
26310Sstevel@tonic-gate 			}
26320Sstevel@tonic-gate 		else
26330Sstevel@tonic-gate 			{
26340Sstevel@tonic-gate 			close(fd[0]);
26350Sstevel@tonic-gate 			close(1);
26360Sstevel@tonic-gate 			dup(fd[1]);
26370Sstevel@tonic-gate 			close(fd[1]);
26380Sstevel@tonic-gate 			mr=1;
26390Sstevel@tonic-gate 			usertime=0;
26400Sstevel@tonic-gate 			return 0;
26410Sstevel@tonic-gate 			}
26420Sstevel@tonic-gate 		printf("Forked child %d\n",n);
26430Sstevel@tonic-gate 		}
26440Sstevel@tonic-gate 
26450Sstevel@tonic-gate 	/* for now, assume the pipe is long enough to take all the output */
26460Sstevel@tonic-gate 	for(n=0 ; n < multi ; ++n)
26470Sstevel@tonic-gate 		{
26480Sstevel@tonic-gate 		FILE *f;
26490Sstevel@tonic-gate 		char buf[1024];
26500Sstevel@tonic-gate 		char *p;
26510Sstevel@tonic-gate 
26520Sstevel@tonic-gate 		f=fdopen(fds[n],"r");
26530Sstevel@tonic-gate 		while(fgets(buf,sizeof buf,f))
26540Sstevel@tonic-gate 			{
26550Sstevel@tonic-gate 			p=strchr(buf,'\n');
26560Sstevel@tonic-gate 			if(p)
26570Sstevel@tonic-gate 				*p='\0';
26580Sstevel@tonic-gate 			if(buf[0] != '+')
26590Sstevel@tonic-gate 				{
26600Sstevel@tonic-gate 				fprintf(stderr,"Don't understand line '%s' from child %d\n",
26610Sstevel@tonic-gate 						buf,n);
26620Sstevel@tonic-gate 				continue;
26630Sstevel@tonic-gate 				}
26640Sstevel@tonic-gate 			printf("Got: %s from %d\n",buf,n);
26650Sstevel@tonic-gate 			if(!strncmp(buf,"+F:",3))
26660Sstevel@tonic-gate 				{
26670Sstevel@tonic-gate 				int alg;
26680Sstevel@tonic-gate 				int j;
26690Sstevel@tonic-gate 
26700Sstevel@tonic-gate 				p=buf+3;
26710Sstevel@tonic-gate 				alg=atoi(sstrsep(&p,sep));
26720Sstevel@tonic-gate 				sstrsep(&p,sep);
26730Sstevel@tonic-gate 				for(j=0 ; j < SIZE_NUM ; ++j)
26740Sstevel@tonic-gate 					results[alg][j]+=atof(sstrsep(&p,sep));
26750Sstevel@tonic-gate 				}
26760Sstevel@tonic-gate 			else if(!strncmp(buf,"+F2:",4))
26770Sstevel@tonic-gate 				{
26780Sstevel@tonic-gate 				int k;
26790Sstevel@tonic-gate 				double d;
26800Sstevel@tonic-gate 
26810Sstevel@tonic-gate 				p=buf+4;
26820Sstevel@tonic-gate 				k=atoi(sstrsep(&p,sep));
26830Sstevel@tonic-gate 				sstrsep(&p,sep);
26840Sstevel@tonic-gate 
26850Sstevel@tonic-gate 				d=atof(sstrsep(&p,sep));
26860Sstevel@tonic-gate 				if(n)
26870Sstevel@tonic-gate 					rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
26880Sstevel@tonic-gate 				else
26890Sstevel@tonic-gate 					rsa_results[k][0]=d;
26900Sstevel@tonic-gate 
26910Sstevel@tonic-gate 				d=atof(sstrsep(&p,sep));
26920Sstevel@tonic-gate 				if(n)
26930Sstevel@tonic-gate 					rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
26940Sstevel@tonic-gate 				else
26950Sstevel@tonic-gate 					rsa_results[k][1]=d;
26960Sstevel@tonic-gate 				}
26970Sstevel@tonic-gate 			else if(!strncmp(buf,"+F2:",4))
26980Sstevel@tonic-gate 				{
26990Sstevel@tonic-gate 				int k;
27000Sstevel@tonic-gate 				double d;
27010Sstevel@tonic-gate 
27020Sstevel@tonic-gate 				p=buf+4;
27030Sstevel@tonic-gate 				k=atoi(sstrsep(&p,sep));
27040Sstevel@tonic-gate 				sstrsep(&p,sep);
27050Sstevel@tonic-gate 
27060Sstevel@tonic-gate 				d=atof(sstrsep(&p,sep));
27070Sstevel@tonic-gate 				if(n)
27080Sstevel@tonic-gate 					rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
27090Sstevel@tonic-gate 				else
27100Sstevel@tonic-gate 					rsa_results[k][0]=d;
27110Sstevel@tonic-gate 
27120Sstevel@tonic-gate 				d=atof(sstrsep(&p,sep));
27130Sstevel@tonic-gate 				if(n)
27140Sstevel@tonic-gate 					rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
27150Sstevel@tonic-gate 				else
27160Sstevel@tonic-gate 					rsa_results[k][1]=d;
27170Sstevel@tonic-gate 				}
27180Sstevel@tonic-gate 			else if(!strncmp(buf,"+F3:",4))
27190Sstevel@tonic-gate 				{
27200Sstevel@tonic-gate 				int k;
27210Sstevel@tonic-gate 				double d;
27220Sstevel@tonic-gate 
27230Sstevel@tonic-gate 				p=buf+4;
27240Sstevel@tonic-gate 				k=atoi(sstrsep(&p,sep));
27250Sstevel@tonic-gate 				sstrsep(&p,sep);
27260Sstevel@tonic-gate 
27270Sstevel@tonic-gate 				d=atof(sstrsep(&p,sep));
27280Sstevel@tonic-gate 				if(n)
27290Sstevel@tonic-gate 					dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
27300Sstevel@tonic-gate 				else
27310Sstevel@tonic-gate 					dsa_results[k][0]=d;
27320Sstevel@tonic-gate 
27330Sstevel@tonic-gate 				d=atof(sstrsep(&p,sep));
27340Sstevel@tonic-gate 				if(n)
27350Sstevel@tonic-gate 					dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
27360Sstevel@tonic-gate 				else
27370Sstevel@tonic-gate 					dsa_results[k][1]=d;
27380Sstevel@tonic-gate 				}
2739*2139Sjp161948 #ifndef OPENSSL_NO_ECDSA
2740*2139Sjp161948 			else if(!strncmp(buf,"+F4:",4))
2741*2139Sjp161948 				{
2742*2139Sjp161948 				int k;
2743*2139Sjp161948 				double d;
2744*2139Sjp161948 
2745*2139Sjp161948 				p=buf+4;
2746*2139Sjp161948 				k=atoi(sstrsep(&p,sep));
2747*2139Sjp161948 				sstrsep(&p,sep);
2748*2139Sjp161948 
2749*2139Sjp161948 				d=atof(sstrsep(&p,sep));
2750*2139Sjp161948 				if(n)
2751*2139Sjp161948 					ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);
2752*2139Sjp161948 				else
2753*2139Sjp161948 					ecdsa_results[k][0]=d;
2754*2139Sjp161948 
2755*2139Sjp161948 				d=atof(sstrsep(&p,sep));
2756*2139Sjp161948 				if(n)
2757*2139Sjp161948 					ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);
2758*2139Sjp161948 				else
2759*2139Sjp161948 					ecdsa_results[k][1]=d;
2760*2139Sjp161948 				}
2761*2139Sjp161948 #endif
2762*2139Sjp161948 
2763*2139Sjp161948 #ifndef OPENSSL_NO_ECDH
2764*2139Sjp161948 			else if(!strncmp(buf,"+F5:",4))
2765*2139Sjp161948 				{
2766*2139Sjp161948 				int k;
2767*2139Sjp161948 				double d;
2768*2139Sjp161948 
2769*2139Sjp161948 				p=buf+4;
2770*2139Sjp161948 				k=atoi(sstrsep(&p,sep));
2771*2139Sjp161948 				sstrsep(&p,sep);
2772*2139Sjp161948 
2773*2139Sjp161948 				d=atof(sstrsep(&p,sep));
2774*2139Sjp161948 				if(n)
2775*2139Sjp161948 					ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);
2776*2139Sjp161948 				else
2777*2139Sjp161948 					ecdh_results[k][0]=d;
2778*2139Sjp161948 
2779*2139Sjp161948 				}
2780*2139Sjp161948 #endif
2781*2139Sjp161948 
27820Sstevel@tonic-gate 			else if(!strncmp(buf,"+H:",3))
27830Sstevel@tonic-gate 				{
27840Sstevel@tonic-gate 				}
27850Sstevel@tonic-gate 			else
27860Sstevel@tonic-gate 				fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);
27870Sstevel@tonic-gate 			}
27880Sstevel@tonic-gate 		}
27890Sstevel@tonic-gate 	return 1;
27900Sstevel@tonic-gate 	}
27910Sstevel@tonic-gate #endif
27920Sstevel@tonic-gate #endif
2793