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.

29 lines
579 B

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