Redundant now as it's moved to ./Makefile.org.
[openssl.git] / crypto / des / speed.c
index 5bbe8b01d6e8e635289d05d9502ab22ff8e59da9..48fc1d49fc24c9bd0a0500eb3bd7f2fc8415bdc6 100644 (file)
 /* 11-Sep-92 Andrew Daviel   Support for Silicon Graphics IRIX added */
 /* 06-Apr-92 Luke Brennan    Support for VMS and add extra signal calls */
 
-#ifndef MSDOS
+#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
 #define TIMES
 #endif
 
 #include <stdio.h>
-#ifndef MSDOS
-#include <unistd.h>
-#else
-#include <io.h>
-extern int exit();
-#endif
+
+#include <openssl/e_os2.h>
+#include OPENSSL_UNISTD_IO
+OPENSSL_DECLARE_EXIT
+
 #include <signal.h>
-#ifndef VMS
 #ifndef _IRIX
 #include <time.h>
 #endif
@@ -79,35 +77,32 @@ extern int exit();
 #include <sys/types.h>
 #include <sys/times.h>
 #endif
-#else /* VMS */
-#include <types.h>
-struct tms {
-       time_t tms_utime;
-       time_t tms_stime;
-       time_t tms_uchild;      /* I dunno...  */
-       time_t tms_uchildsys;   /* so these names are a guess :-) */
-       }
+
+/* Depending on the VMS version, the tms structure is perhaps defined.
+   The __TMS macro will show if it was.  If it wasn't defined, we should
+   undefine TIMES, since that tells the rest of the program how things
+   should be handled.                          -- Richard Levitte */
+#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
+#undef TIMES
 #endif
+
 #ifndef TIMES
 #include <sys/timeb.h>
 #endif
 
-#ifdef sun
+#if defined(sun) || defined(__ultrix)
+#define _POSIX_SOURCE
 #include <limits.h>
 #include <sys/param.h>
 #endif
 
-#include "des.h"
+#include <openssl/des.h>
 
 /* The following if from times(3) man page.  It may need to be changed */
 #ifndef HZ
 # ifndef CLK_TCK
 #  ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
-#   ifndef VMS
-#    define HZ 100.0
-#   else /* VMS */
-#    define HZ 100.0
-#   endif
+#   define HZ  100.0
 #  else /* _BSD_CLK_TCK_ */
 #   define HZ ((double)_BSD_CLK_TCK_)
 #  endif
@@ -119,12 +114,7 @@ struct tms {
 #define BUFSIZE        ((long)1024)
 long run=0;
 
-#ifndef NOPROTO
 double Time_F(int s);
-#else
-double Time_F();
-#endif
-
 #ifdef SIGALRM
 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
 #define SIGRETTYPE void
@@ -132,14 +122,8 @@ double Time_F();
 #define SIGRETTYPE int
 #endif
 
-#ifndef NOPROTO
 SIGRETTYPE sig_done(int sig);
-#else
-SIGRETTYPE sig_done();
-#endif
-
-SIGRETTYPE sig_done(sig)
-int sig;
+SIGRETTYPE sig_done(int sig)
        {
        signal(SIGALRM,sig_done);
        run=0;
@@ -152,8 +136,7 @@ int sig;
 #define START  0
 #define STOP   1
 
-double Time_F(s)
-int s;
+double Time_F(int s)
        {
        double ret;
 #ifdef TIMES
@@ -189,32 +172,30 @@ int s;
 #endif
        }
 
-int main(argc,argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
        {
        long count;
        static unsigned char buf[BUFSIZE];
-       static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
-       static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
-       static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
-       des_key_schedule sch,sch2,sch3;
+       static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
+       static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
+       static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
+       DES_key_schedule sch,sch2,sch3;
        double a,b,c,d,e;
 #ifndef SIGALRM
        long ca,cb,cc,cd,ce;
 #endif
 
 #ifndef TIMES
-       printf("To get the most acurate results, try to run this\n");
+       printf("To get the most accurate results, try to run this\n");
        printf("program when this computer is idle.\n");
 #endif
 
-       des_set_key((C_Block *)key2,sch2);
-       des_set_key((C_Block *)key3,sch3);
+       DES_set_key_unchecked(&key2,&sch2);
+       DES_set_key_unchecked(&key3,&sch3);
 
 #ifndef SIGALRM
        printf("First we calculate the approximate speed ...\n");
-       des_set_key((C_Block *)key,sch);
+       DES_set_key_unchecked(&key,&sch);
        count=10;
        do      {
                long i;
@@ -223,7 +204,7 @@ char **argv;
                count*=2;
                Time_F(START);
                for (i=count; i; i--)
-                       des_encrypt(data,&(sch[0]),DES_ENCRYPT);
+                       DES_encrypt1(data,&sch,DES_ENCRYPT);
                d=Time_F(STOP);
                } while (d < 3.0);
        ca=count;
@@ -244,63 +225,63 @@ char **argv;
 
        Time_F(START);
        for (count=0,run=1; COND(ca); count++)
-               des_set_key((C_Block *)key,sch);
+               DES_set_key_unchecked(&key,&sch);
        d=Time_F(STOP);
        printf("%ld set_key's in %.2f seconds\n",count,d);
        a=((double)COUNT(ca))/d;
 
 #ifdef SIGALRM
-       printf("Doing des_encrypt's for 10 seconds\n");
+       printf("Doing DES_encrypt's for 10 seconds\n");
        alarm(10);
 #else
-       printf("Doing des_encrypt %ld times\n",cb);
+       printf("Doing DES_encrypt %ld times\n",cb);
 #endif
        Time_F(START);
        for (count=0,run=1; COND(cb); count++)
                {
                DES_LONG data[2];
 
-               des_encrypt(data,&(sch[0]),DES_ENCRYPT);
+               DES_encrypt1(data,&sch,DES_ENCRYPT);
                }
        d=Time_F(STOP);
-       printf("%ld des_encrypt's in %.2f second\n",count,d);
+       printf("%ld DES_encrypt's in %.2f second\n",count,d);
        b=((double)COUNT(cb)*8)/d;
 
 #ifdef SIGALRM
-       printf("Doing des_cbc_encrypt on %ld byte blocks for 10 seconds\n",
+       printf("Doing DES_cbc_encrypt on %ld byte blocks for 10 seconds\n",
                BUFSIZE);
        alarm(10);
 #else
-       printf("Doing des_cbc_encrypt %ld times on %ld byte blocks\n",cc,
+       printf("Doing DES_cbc_encrypt %ld times on %ld byte blocks\n",cc,
                BUFSIZE);
 #endif
        Time_F(START);
        for (count=0,run=1; COND(cc); count++)
-               des_ncbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]),
-                       (C_Block *)&(key[0]),DES_ENCRYPT);
+               DES_ncbc_encrypt(buf,buf,BUFSIZE,&sch,
+                       &key,DES_ENCRYPT);
        d=Time_F(STOP);
-       printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n",
+       printf("%ld DES_cbc_encrypt's of %ld byte blocks in %.2f second\n",
                count,BUFSIZE,d);
        c=((double)COUNT(cc)*BUFSIZE)/d;
 
 #ifdef SIGALRM
-       printf("Doing des_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
+       printf("Doing DES_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
                BUFSIZE);
        alarm(10);
 #else
-       printf("Doing des_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
+       printf("Doing DES_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
                BUFSIZE);
 #endif
        Time_F(START);
        for (count=0,run=1; COND(cd); count++)
-               des_ede3_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,
-                       &(sch[0]),
-                       &(sch2[0]),
-                       &(sch3[0]),
-                       (C_Block *)&(key[0]),
+               DES_ede3_cbc_encrypt(buf,buf,BUFSIZE,
+                       &sch,
+                       &sch2,
+                       &sch3,
+                       &key,
                        DES_ENCRYPT);
        d=Time_F(STOP);
-       printf("%ld des_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
+       printf("%ld DES_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
                count,BUFSIZE,d);
        d=((double)COUNT(cd)*BUFSIZE)/d;
 
@@ -323,7 +304,7 @@ char **argv;
        printf("DES ede cbc bytes  per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
        printf("crypt              per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
        exit(0);
-#if defined(LINT) || defined(MSDOS)
+#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
        return(0);
 #endif
        }