crttest.c 813 B

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