What is the algorithm used by GMP to invert a element in a finite field?
Asked
Active
Viewed 319 times
1 Answers
4
It uses extended GCD as implemented in mpz_gcdext
: https://fossies.org/dox/gmp-6.1.0/mpz_2invert_8c_source.html .

David Eisenstat
- 64,237
- 7
- 60
- 120
-
See section 15.3.4 of the GMP manual: [https://gmplib.org/manual/Extended-GCD.html#Extended-GCD](https://gmplib.org/manual/Extended-GCD.html#Extended-GCD) – user448810 Apr 05 '16 at 21:19
-
Specifically, it calls `mpz_gcdext` with a NULL argument for one of the Bézout coefficients - since it's not required. `(g, z, NULL, x, modulus)`. The least non-negative residue (the inverse) will be within: `+/- modulus` if `(z < 0)`. This is due to gcdext returning one of two possible 'minimal' coefficient pairs. – Brett Hale Apr 11 '16 at 14:38