diff --git a/include/field.h b/include/field.h index 6c09690403863ca250fb39d1e0230a42404d1e2b..3e29303929a38ad75e527823cc0ab987f9b7cfaf 100644 --- a/include/field.h +++ b/include/field.h @@ -9,6 +9,8 @@ void rand_zp(zp x); void zp_zero(zp x); +void zp_one(zp x); + void zp_copy(zp x_copy, zp x); void zp_from_int(zp x, int x_int); @@ -19,4 +21,6 @@ void zp_multiply(zp p, zp x, zp y); void zp_inverse(zp xi, zp x); +int zp_is_int(zp x, int x_int); + #endif //PPANN_FIELD_H \ No newline at end of file diff --git a/src/field.c b/src/field.c index 82b6d370b121be34e7fff521e4cc7db25d457683..c0bb4b5e8f8c9bfc75cd817ea51ab6c3568a3823 100644 --- a/src/field.c +++ b/src/field.c @@ -8,6 +8,10 @@ void zp_zero(dig_t *x) { fp_zero(x); } +void zp_one(dig_t *x) { + zp_from_int(x, 1); +} + void zp_copy(dig_t *x_copy, dig_t *x) { fp_copy(x_copy, x); } @@ -26,4 +30,8 @@ void zp_multiply(dig_t *p, dig_t *x, dig_t *y) { void zp_inverse(dig_t *xi, dig_t *x) { fp_inv(xi, x); -} \ No newline at end of file +} + +int zp_is_int(dig_t *x, int x_int) { + return fp_cmp_dig(x, x_int) == RLC_EQ; +} diff --git a/tests/test_field.c b/tests/test_field.c index d51f818903662e5e5df494182e56d5bc61373979..08411cc39ea320b86ab2e33240d8c73e54fa4cf4 100644 --- a/tests/test_field.c +++ b/tests/test_field.c @@ -1,10 +1,15 @@ #include "field.h" int test_zp_zero() { - zp x, y; + zp x; zp_zero(x); - fp_zero(y); - return fp_cmp(x, y); + return zp_is_int(x, 0); +} + +int test_zp_one() { + zp x; + zp_one(x); + return zp_is_int(x, 1); } int test_zp_copy() { @@ -51,7 +56,8 @@ int main() { pc_param_set_any(); // Perform tests. - if (test_zp_zero() != RLC_EQ) return 1; + if (test_zp_zero() != 1) return 1; + if (test_zp_one() != 1) return 1; if (test_zp_copy() != RLC_EQ) return 1; if (test_zp_from_int() != RLC_EQ) return 1; if (test_zp_add() != RLC_EQ) return 1;