group_test.c 672 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <assert.h>
  2. #include <gmp.h>
  3. #include "group.h"
  4. #include "entropy.h"
  5. mpz_t test, expected, x, y;
  6. int main()
  7. {
  8. group_init();
  9. mpz_entropy_init();
  10. mpz_inits(test, expected, x, y, NULL);
  11. for (int i = 0; i < 1e4; i++) {
  12. mpz_urandomm(x, _rstate, p);
  13. mpz_urandomm(y, _rstate, p);
  14. mpz_mul(expected, x, y);
  15. mpz_mod(expected, expected, p);
  16. mul_modp(test, y, x);
  17. if (mpz_cmp(test, expected)) {
  18. gmp_printf("%lu %lu\n%lu %lu\n",
  19. PTR(test)[1], PTR(test)[0],
  20. PTR(expected)[1], PTR(expected)[0]);
  21. assert(0);
  22. }
  23. }
  24. mpz_clears(test, expected, x, y, NULL);
  25. group_clear();
  26. return 0;
  27. }