shithub: tlsclient

ref: d76925e3a63f4a275fd0d05f6b1d088fb88a9203
dir: /libmp/mpinvert.c/

View raw version
#include "os.h"
#include <mp.h>

// use extended gcd to find the multiplicative inverse
// res = b**-1 mod m
void
mpinvert(mpint *b, mpint *m, mpint *res)
{
	mpint *v;

	v = mpnew(0);
	mpextendedgcd(b, m, v, res, nil);
	if(mpcmp(v, mpone) != 0)
		abort();
	mpfree(v);
	mpmod(res, m, res);
}