Subversion Repositories planix.SVN

Rev

Rev 33 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
 
4
void
5
testcrt(mpint **p)
6
{
7
	CRTpre *crt;
8
	CRTres *res;
9
	mpint *m, *x, *y;
10
 
11
	fmtinstall('B', mpfmt);
12
 
13
	// get a modulus and a test number
14
	m = mpnew(1024+160);
15
	mpmul(p[0], p[1], m);
16
	x = mpnew(1024+160);
17
	mpadd(m, mpone, x);
18
 
19
	// do the precomputation for crt conversion
20
	crt = crtpre(2, p);
21
 
22
	// convert x to residues
23
	res = crtin(crt, x);
24
 
25
	// convert back
26
	y = mpnew(1024+160);
27
	crtout(crt, res, y);
28
	print("x %B\ny %B\n", x, y);
29
	mpfree(m);
30
	mpfree(x);
31
	mpfree(y);
32
}
33
 
34
void
35
main(void)
36
{
37
	int i;
38
	mpint *p[2];
39
	long start;
40
 
41
	start = time(0);
42
	for(i = 0; i < 10; i++){
43
		p[0] = mpnew(1024);
44
		p[1] = mpnew(1024);
45
		DSAprimes(p[0], p[1], nil);
46
		testcrt(p);
47
		mpfree(p[0]);
48
		mpfree(p[1]);
49
	}
50
	print("%ld secs with more\n", time(0)-start);
51
	exits(0);
52
}