PR: 1999
[openssl.git] / apps / speed.c
index 4447f73c493403b5de16022d530a72e7f926deed..444a0e6361964e3aa47cc6cb71c7dcd88f9db0bd 100644 (file)
 #include <openssl/ecdh.h>
 #endif
 
-#if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2) && !defined(OPENSSL_SYS_NETWARE)
-# define HAVE_FORK 1
-#endif
+#if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE)
+# define NO_FORK 1
+#elif HAVE_FORK
+# undef NO_FORK
+#else
+# define NO_FORK 1
+#endef
 
 #undef BUFSIZE
 #define BUFSIZE        ((long)1024*8+1)
@@ -200,7 +204,7 @@ static void print_message(const char *s,long num,int length);
 static void pkey_print_message(const char *str, const char *str2,
        long num, int bits, int sec);
 static void print_result(int alg,int run_no,int count,double time_used);
-#ifdef HAVE_FORK
+#ifndef NO_FORK
 static int do_multi(int multi);
 #endif
 
@@ -414,7 +418,7 @@ int MAIN(int argc, char **argv)
 #define MAX_BLOCK_SIZE 64
 #endif
        unsigned char DES_iv[8];
-       unsigned char iv[MAX_BLOCK_SIZE/8];
+       unsigned char iv[2*MAX_BLOCK_SIZE/8];
 #ifndef OPENSSL_NO_DES
        DES_cblock *buf_as_des_cblock = NULL;
        static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
@@ -587,7 +591,7 @@ int MAIN(int argc, char **argv)
        const EVP_CIPHER *evp_cipher=NULL;
        const EVP_MD *evp_md=NULL;
        int decrypt=0;
-#ifdef HAVE_FORK
+#ifndef NO_FORK
        int multi=0;
 #endif
 
@@ -715,7 +719,7 @@ int MAIN(int argc, char **argv)
                        j--;
                        }
 #endif
-#ifdef HAVE_FORK
+#ifndef NO_FORK
                else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
                        {
                        argc--;
@@ -1103,7 +1107,7 @@ int MAIN(int argc, char **argv)
                        BIO_printf(bio_err,"-evp e          use EVP e.\n");
                        BIO_printf(bio_err,"-decrypt        time decryption instead of encryption (only EVP).\n");
                        BIO_printf(bio_err,"-mr             produce machine readable output.\n");
-#ifdef HAVE_FORK
+#ifndef NO_FORK
                        BIO_printf(bio_err,"-multi n        run n benchmarks in parallel.\n");
 #endif
                        goto end;
@@ -1113,7 +1117,7 @@ int MAIN(int argc, char **argv)
                j++;
                }
 
-#ifdef HAVE_FORK
+#ifndef NO_FORK
        if(multi && do_multi(multi))
                goto show_res;
 #endif
@@ -1129,6 +1133,14 @@ int MAIN(int argc, char **argv)
                        rsa_doit[i]=1;
                for (i=0; i<DSA_NUM; i++)
                        dsa_doit[i]=1;
+#ifndef OPENSSL_NO_ECDSA
+               for (i=0; i<EC_NUM; i++)
+                       ecdsa_doit[i]=1;
+#endif
+#ifndef OPENSSL_NO_ECDH
+               for (i=0; i<EC_NUM; i++)
+                       ecdh_doit[i]=1;
+#endif
                }
        for (i=0; i<ALGOR_NUM; i++)
                if (doit[i]) pr_header++;
@@ -1703,7 +1715,7 @@ int MAIN(int argc, char **argv)
                        print_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);
                        Time_F(START);
                        for (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)
-                               AES_ige_encrypt(buf,buf,
+                               AES_ige_encrypt(buf,buf2,
                                        (unsigned long)lengths[j],&aes_ks1,
                                        iv,AES_ENCRYPT);
                        d=Time_F(STOP);
@@ -1717,7 +1729,7 @@ int MAIN(int argc, char **argv)
                        print_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);
                        Time_F(START);
                        for (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)
-                               AES_ige_encrypt(buf,buf,
+                               AES_ige_encrypt(buf,buf2,
                                        (unsigned long)lengths[j],&aes_ks2,
                                        iv,AES_ENCRYPT);
                        d=Time_F(STOP);
@@ -1731,7 +1743,7 @@ int MAIN(int argc, char **argv)
                        print_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);
                        Time_F(START);
                        for (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)
-                               AES_ige_encrypt(buf,buf,
+                               AES_ige_encrypt(buf,buf2,
                                        (unsigned long)lengths[j],&aes_ks3,
                                        iv,AES_ENCRYPT);
                        d=Time_F(STOP);
@@ -1994,7 +2006,7 @@ int MAIN(int argc, char **argv)
                                {
                                ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
                                        rsa_num, rsa_key[j]);
-                               if (ret == 0)
+                               if (ret <= 0)
                                        {
                                        BIO_printf(bio_err,
                                                "RSA verify failure\n");
@@ -2324,7 +2336,7 @@ int MAIN(int argc, char **argv)
                }
        if (rnd_fake) RAND_cleanup();
 #endif
-#ifdef HAVE_FORK
+#ifndef NO_FORK
 show_res:
 #endif
        if(!mr)
@@ -2550,7 +2562,7 @@ static void print_result(int alg,int run_no,int count,double time_used)
        results[alg][run_no]=((double)count)/time_used*lengths[run_no];
        }
 
-#ifdef HAVE_FORK
+#ifndef NO_FORK
 static char *sstrsep(char **string, const char *delim)
     {
     char isdelim[256];
@@ -2593,6 +2605,8 @@ static int do_multi(int multi)
        for(n=0 ; n < multi ; ++n)
                {
                pipe(fd);
+               fflush(stdout);
+               fflush(stderr);
                if(fork())
                        {
                        close(fd[1]);