Blob
1 #include "os.h"2 #include <mp.h>3 #include <libsec.h>5 void6 testcrt(mpint **p)7 {8 CRTpre *crt;9 CRTres *res;10 mpint *m, *x, *y;11 int i;13 fmtinstall('B', mpconv);15 // get a modulus and a test number16 m = mpnew(1024+160);17 mpmul(p[0], p[1], m);18 x = mpnew(1024+160);19 mpadd(m, mpone, x);21 // do the precomputation for crt conversion22 crt = crtpre(2, p);24 // convert x to residues25 res = crtin(crt, x);27 // convert back28 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 }36 void37 main(void)38 {39 int i;40 mpint *p[2];41 long start;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 }