Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_posix/sys/src/libmp/port/mpinvert.c – Rev 33

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | 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
{
33 7u83 9
	mpint *v;
2 - 10
 
33 7u83 11
	v = mpnew(0);
12
	mpextendedgcd(b, m, v, res, nil);
13
	if(mpcmp(v, mpone) != 0)
2 - 14
		abort();
33 7u83 15
	mpfree(v);
2 - 16
	mpmod(res, m, res);
17
}