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