Subversion Repositories planix.SVN

Rev

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