Subversion Repositories planix.SVN

Rev

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