Put the first stage of my bignum debugging adventures into CVS. This code
[openssl.git] / crypto / bn / bnspeed.c
index 3b83a26dea98fc7620b312edb395c7692e1ad038..b554ac8cf857bc19033650918a50d8ecf7e4068b 100644 (file)
@@ -1,5 +1,7 @@
+/* unused */
+
 /* crypto/bn/bnspeed.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
  * This package is an SSL implementation written
@@ -58,6 +60,7 @@
 
 /* most of this code has been pilfered from my libdes speed.c program */
 
+#define BASENUM        1000000
 #undef PROG
 #define PROG bnspeed_main
 
 #include <stdlib.h>
 #include <signal.h>
 #include <string.h>
-#include "crypto.h"
-#include "err.h"
+#include <openssl/crypto.h>
+#include <openssl/err.h>
 
-#ifndef MSDOS
+#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
 #define TIMES
 #endif
 
-#ifndef VMS
 #ifndef _IRIX
 #include <time.h>
 #endif
 #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 "bn.h"
-#include "x509.h"
+#include <openssl/bn.h>
+#include <openssl/x509.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 hack */
-#   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
@@ -122,17 +121,11 @@ struct tms {
 #define BUFSIZE        ((long)1024*8)
 int run=0;
 
-#ifndef NOPROTO
 static double Time_F(int s);
-#else
-static double Time_F();
-#endif
-
 #define START  0
 #define STOP   1
 
-static double Time_F(s)
-int s;
+static double Time_F(int s)
        {
        double ret;
 #ifdef TIMES
@@ -169,63 +162,63 @@ int s;
        }
 
 #define NUM_SIZES      5
-/*static int sizes[NUM_SIZES]={256,512,1024,2048};*/
-static int sizes[NUM_SIZES]={59,179,299,419,539};
+static int sizes[NUM_SIZES]={128,256,512,1024,2048};
+/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
 
 void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx); 
 
-int main(argc,argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
        {
        BN_CTX *ctx;
-       BIGNUM *a,*b,*c,*r;
+       BIGNUM a,b,c;
 
        ctx=BN_CTX_new();
-       a=BN_new();
-       b=BN_new();
-       c=BN_new();
-       r=BN_new();
+       BN_init(&a);
+       BN_init(&b);
+       BN_init(&c);
 
-       do_mul(a,b,c,ctx);
+       do_mul(&a,&b,&c,ctx);
        }
 
-void do_mul(r,a,b,ctx)
-BIGNUM *r;
-BIGNUM *a;
-BIGNUM *b;
-BN_CTX *ctx;
+void do_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
        {
        int i,j,k;
        double tm;
+       long num;
 
        for (i=0; i<NUM_SIZES; i++)
                {
+               num=BASENUM;
+               if (i) num/=(i*3);
                BN_rand(a,sizes[i],1,0);
                for (j=i; j<NUM_SIZES; j++)
                        {
                        BN_rand(b,sizes[j],1,0);
                        Time_F(START);
-                       for (k=0; k<100000; k++)
-                               BN_mul(r,b,a);
+                       for (k=0; k<num; k++)
+                               BN_mul(r,b,a,ctx);
                        tm=Time_F(STOP);
-                       printf("mul %3d x %3d -> %7.4f\n",sizes[i],sizes[j],tm/10.0);
+                       printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num);
                        }
                }
 
        for (i=0; i<NUM_SIZES; i++)
                {
+               num=BASENUM;
+               if (i) num/=(i*3);
                BN_rand(a,sizes[i],1,0);
                Time_F(START);
-               for (k=0; k<100000; k++)
+               for (k=0; k<num; k++)
                        BN_sqr(r,a,ctx);
                tm=Time_F(STOP);
-               printf("sqr %3d x %3d -> %7.4f\n",sizes[i],sizes[i],tm/10.0);
+               printf("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num);
                }
 
        for (i=0; i<NUM_SIZES; i++)
                {
-               BN_rand(a,sizes[i],1,0);
+               num=BASENUM/10;
+               if (i) num/=(i*3);
+               BN_rand(a,sizes[i]-1,1,0);
                for (j=i; j<NUM_SIZES; j++)
                        {
                        BN_rand(b,sizes[j],1,0);
@@ -233,7 +226,7 @@ BN_CTX *ctx;
                        for (k=0; k<100000; k++)
                                BN_div(r, NULL, b, a,ctx);
                        tm=Time_F(STOP);
-                       printf("div %3d / %3d -> %7.4f\n",sizes[j],sizes[i],tm/10.0);
+                       printf("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num);
                        }
                }
        }