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