mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -05:00
mpint: add a gcd function.
This is another application of the existing mp_bezout_into, which needed a tweak or two to cope with the numbers not necessarily being coprime, plus a wrapper function to deal with shared factors of 2. It reindents the entire second half of mp_bezout_into, so the patch is best viewed with whitespace differences ignored.
This commit is contained in:
19
mpint.h
19
mpint.h
@ -270,6 +270,25 @@ void mp_reduce_mod_2to(mp_int *x, size_t p);
|
||||
mp_int *mp_invert_mod_2to(mp_int *x, size_t p);
|
||||
mp_int *mp_invert(mp_int *x, mp_int *modulus);
|
||||
|
||||
/*
|
||||
* Greatest common divisor.
|
||||
*
|
||||
* mp_gcd_into also returns a pair of Bezout coefficients, namely A,B
|
||||
* such that a*A - b*B = gcd. (The minus sign is so that both returned
|
||||
* coefficients can be positive.)
|
||||
*
|
||||
* You can pass any of mp_gcd_into's output pointers as NULL if you
|
||||
* don't need that output value.
|
||||
*
|
||||
* mp_gcd is a wrapper with a less cumbersome API, for the case where
|
||||
* the only output value you need is the gcd itself. mp_coprime is
|
||||
* even easier, if all you care about is whether or not that gcd is 1.
|
||||
*/
|
||||
mp_int *mp_gcd(mp_int *a, mp_int *b);
|
||||
void mp_gcd_into(mp_int *a, mp_int *b,
|
||||
mp_int *gcd_out, mp_int *A_out, mp_int *B_out);
|
||||
unsigned mp_coprime(mp_int *a, mp_int *b);
|
||||
|
||||
/*
|
||||
* System for taking square roots modulo an odd prime.
|
||||
*
|
||||
|
Reference in New Issue
Block a user