You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
819 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #include "zqfield.h"
  2. ZqField::ZqField(PBigInt ap) {
  3. mpz_init2(tmp, 1024);
  4. mpz_init_set(p, *ap);
  5. mpz_init_set_ui(zero, 0);
  6. mpz_init_set_ui(one, 1);
  7. }
  8. ZqField::~ZqField() {
  9. mpz_clear(tmp);
  10. mpz_clear(p);
  11. mpz_clear(zero);
  12. mpz_clear(one);
  13. }
  14. void ZqField::add(PBigInt r, PBigInt a, PBigInt b) {
  15. mpz_add(tmp,*a,*b);
  16. mpz_fdiv_r(*r, tmp, p);
  17. }
  18. void ZqField::mul(PBigInt r, PBigInt a, PBigInt b) {
  19. mpz_mul(tmp,*a,*b);
  20. mpz_fdiv_r(*r, tmp, p);
  21. }
  22. void ZqField::lt(PBigInt r, PBigInt a, PBigInt b) {
  23. int c = mpz_cmp(*a, *b);
  24. if (c<0) {
  25. mpz_set(*r, one);
  26. } else {
  27. mpz_set(*r, zero);
  28. }
  29. }
  30. int ZqField::isTrue(PBigInt a) {
  31. return mpz_sgn(*a);
  32. }
  33. void ZqField::copyn(PBigInt a, PBigInt b, int n) {
  34. for (int i=0;i<n; i++) mpz_set(a[i], b[i]);
  35. }