78 #if defined(TEST_EXP) + defined(TEST_MUL) + defined(TEST_SQR) + defined(TEST_GCD) + defined(TEST_KRON) + defined(TEST_INV) +defined(TEST_SQRT) != 1
79 # error "choose one test"
82 #if defined(TEST_INV) || defined(TEST_SQRT)
84 static void genprime_cb(
int p,
int n,
void *
arg);
90 #define PROG bnspeed_main
100 #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
108 #include <sys/types.h>
109 #include <sys/times.h>
116 #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
121 #include <sys/timeb.h>
124 #if defined(sun) || defined(__ultrix)
125 #define _POSIX_SOURCE
127 #include <sys/param.h>
136 # ifndef _BSD_CLK_TCK_
139 # define HZ ((double)_BSD_CLK_TCK_)
142 # define HZ ((double)CLK_TCK)
147 #define BUFSIZE ((long)1024*8)
150 static double Time_F(
int s);
154 static double Time_F(
int s)
158 static struct tms tstart,tend;
168 ret=((double)(tend.tms_utime-tstart.tms_utime))/
HZ;
169 return((ret < 1
e-3)?1
e-3:ret);
172 static struct timeb tstart,tend;
183 i=(long)tend.millitm-(
long)tstart.millitm;
184 ret=((double)(tend.time-tstart.time))+((
double)i)/1000.0;
185 return((ret < 0.001)?0.001:ret);
191 #if NUM_START > NUM_SIZES
192 # error "NUM_START > NUM_SIZES"
194 static int sizes[
NUM_SIZES]={128,256,512,1024,2048,4096,8192};
195 static int mul_c[
NUM_SIZES]={8*8*8*8*8*8,8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1};
198 #define RAND_SEED(string) { const char str[] = string; RAND_seed(string, sizeof str); }
202 int main(
int argc,
char **argv)
250 for (k=0; k<
num; k++)
274 #if defined(TEST_EXP)
276 #elif defined(TEST_MUL)
279 for (i = 0; i < 50; i++)
282 #elif defined(TEST_SQR)
285 for (i = 0; i < 50; i++)
291 #elif defined(TEST_GCD)
292 if (!
BN_gcd(r,a,b,ctx))
goto err;
293 if (!
BN_gcd(r,b,c,ctx))
goto err;
294 if (!
BN_gcd(r,c,a,ctx))
goto err;
295 #elif defined(TEST_KRON)
299 #elif defined(TEST_INV)
310 "modexp %4d ^ %4d %% %4d"
311 #elif defined(TEST_MUL)
312 "50*modmul %4d %4d %4d"
313 #elif defined(TEST_SQR)
314 "100*modsqr %4d %4d %4d"
315 #elif defined(TEST_GCD)
317 #elif defined(TEST_KRON)
318 "3*kronecker %4d %4d %4d"
319 #elif defined(TEST_INV)
320 "2*inv %4d %4d mod %4d"
322 "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d"
324 " -> %8.6fms %5.1f (%ld)\n",
328 sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num, num);
340 static void genprime_cb(
int p,
int n,
void *
arg)