mpz_t is GMP’s type for arbitrary-precision integers. Finite-field routines use it for operands, results, and moduli, combining GMP operations such as addition, multiplication, division, inversion, and mpz_mod(). section 2.3
Use mpz_t with an explicit lifecycle and alias-safe intermediate storage:
- Initialize variables with mpz_init() or mpz_init_set() before computation. section 2.3
- Place output before input arguments, matching the a = b op c convention. section 2.3
- Use a temporary mpz_t when calculations could overwrite an input, then release it with mpz_clear(). section 2.3
Modular addition
A modular addition routine initializes rslt, computes mpz_add(rslt, b, c), reduces it with mpz_mod(a, rslt, n), and clears rslt.
