1 b3f61791 2004-03-21 devnull #include "os.h"
2 b3f61791 2004-03-21 devnull #include <mp.h>
4 b3f61791 2004-03-21 devnull #define iseven(a) (((a)->p[0] & 1) == 0)
6 cbeb0b26 2006-04-01 devnull /* use extended gcd to find the multiplicative inverse */
7 cbeb0b26 2006-04-01 devnull /* res = b**-1 mod m */
9 b3f61791 2004-03-21 devnull mpinvert(mpint *b, mpint *m, mpint *res)
11 cbeb0b26 2006-04-01 devnull mpint *dc1, *dc2; /* don't care */
13 b3f61791 2004-03-21 devnull dc1 = mpnew(0);
14 b3f61791 2004-03-21 devnull dc2 = mpnew(0);
15 b3f61791 2004-03-21 devnull mpextendedgcd(b, m, dc1, res, dc2);
16 b3f61791 2004-03-21 devnull if(mpcmp(dc1, mpone) != 0)
18 b3f61791 2004-03-21 devnull mpmod(res, m, res);
19 b3f61791 2004-03-21 devnull mpfree(dc1);
20 b3f61791 2004-03-21 devnull mpfree(dc2);