Subversion Repositories planix.SVN

Rev

Rev 22 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
 
4
// use extended gcd to find the multiplicative inverse
5
// res = b**-1 mod m
6
void
7
mpinvert(mpint *b, mpint *m, mpint *res)
8
{
26 7u83 9
	mpint *v;
2 - 10
 
26 7u83 11
	v = mpnew(0);
12
	mpextendedgcd(b, m, v, res, nil);
13
	if(mpcmp(v, mpone) != 0)
2 - 14
		abort();
26 7u83 15
	mpfree(v);
2 - 16
	mpmod(res, m, res);
17
}