xref: /onnv-gate/usr/src/common/openssl/crypto/bn/exp.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /* unused */
2*0Sstevel@tonic-gate 
3*0Sstevel@tonic-gate #include <stdio.h>
4*0Sstevel@tonic-gate #include <openssl/tmdiff.h>
5*0Sstevel@tonic-gate #include "bn_lcl.h"
6*0Sstevel@tonic-gate 
7*0Sstevel@tonic-gate #define SIZE	256
8*0Sstevel@tonic-gate #define NUM	(8*8*8)
9*0Sstevel@tonic-gate #define MOD	(8*8*8*8*8)
10*0Sstevel@tonic-gate 
main(argc,argv)11*0Sstevel@tonic-gate main(argc,argv)
12*0Sstevel@tonic-gate int argc;
13*0Sstevel@tonic-gate char *argv[];
14*0Sstevel@tonic-gate 	{
15*0Sstevel@tonic-gate 	BN_CTX ctx;
16*0Sstevel@tonic-gate 	BIGNUM a,b,c,r,rr,t,l;
17*0Sstevel@tonic-gate 	int j,i,size=SIZE,num=NUM,mod=MOD;
18*0Sstevel@tonic-gate 	char *start,*end;
19*0Sstevel@tonic-gate 	BN_MONT_CTX mont;
20*0Sstevel@tonic-gate 	double d,md;
21*0Sstevel@tonic-gate 
22*0Sstevel@tonic-gate 	BN_MONT_CTX_init(&mont);
23*0Sstevel@tonic-gate 	BN_CTX_init(&ctx);
24*0Sstevel@tonic-gate 	BN_init(&a);
25*0Sstevel@tonic-gate 	BN_init(&b);
26*0Sstevel@tonic-gate 	BN_init(&c);
27*0Sstevel@tonic-gate 	BN_init(&r);
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate 	start=ms_time_new();
30*0Sstevel@tonic-gate 	end=ms_time_new();
31*0Sstevel@tonic-gate 	while (size <= 1024*8)
32*0Sstevel@tonic-gate 		{
33*0Sstevel@tonic-gate 		BN_rand(&a,size,0,0);
34*0Sstevel@tonic-gate 		BN_rand(&b,size,1,0);
35*0Sstevel@tonic-gate 		BN_rand(&c,size,0,1);
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate 		BN_mod(&a,&a,&c,&ctx);
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate 		ms_time_get(start);
40*0Sstevel@tonic-gate 		for (i=0; i<10; i++)
41*0Sstevel@tonic-gate 			BN_MONT_CTX_set(&mont,&c,&ctx);
42*0Sstevel@tonic-gate 		ms_time_get(end);
43*0Sstevel@tonic-gate 		md=ms_time_diff(start,end);
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate 		ms_time_get(start);
46*0Sstevel@tonic-gate 		for (i=0; i<num; i++)
47*0Sstevel@tonic-gate 			{
48*0Sstevel@tonic-gate 			/* bn_mull(&r,&a,&b,&ctx); */
49*0Sstevel@tonic-gate 			/* BN_sqr(&r,&a,&ctx); */
50*0Sstevel@tonic-gate 			BN_mod_exp_mont(&r,&a,&b,&c,&ctx,&mont);
51*0Sstevel@tonic-gate 			}
52*0Sstevel@tonic-gate 		ms_time_get(end);
53*0Sstevel@tonic-gate 		d=ms_time_diff(start,end)/* *50/33 */;
54*0Sstevel@tonic-gate 		printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n",size,
55*0Sstevel@tonic-gate 			d,num,d/num,(int)((d/num)*mod),md/10.0);
56*0Sstevel@tonic-gate 		num/=8;
57*0Sstevel@tonic-gate 		mod/=8;
58*0Sstevel@tonic-gate 		if (num <= 0) num=1;
59*0Sstevel@tonic-gate 		size*=2;
60*0Sstevel@tonic-gate 		}
61*0Sstevel@tonic-gate 
62*0Sstevel@tonic-gate 	}
63