This commit is contained in:
@@ -195,16 +195,25 @@ h:a[i]:a[i+1] / m0:m1 */
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute (base ^ exp) % mod.
|
* Compute (base ^ exp) % mod.
|
||||||
* The base MUST be smaller than the modulus.
|
|
||||||
* The most significant word of mod MUST be non-zero.
|
|
||||||
* We assume that the result array is the same size as the mod array.
|
|
||||||
*/
|
*/
|
||||||
Bignum modpow(Bignum base, Bignum exp, Bignum mod)
|
Bignum modpow(Bignum base_in, Bignum exp, Bignum mod)
|
||||||
{
|
{
|
||||||
BignumInt *a, *b, *n, *m;
|
BignumInt *a, *b, *n, *m;
|
||||||
int mshift;
|
int mshift;
|
||||||
int i,j,mlen;
|
int i,j,mlen;
|
||||||
Bignum result;
|
Bignum base, result;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The most significant word of mod needs to be non-zero. It
|
||||||
|
* should already be, but let's make sure.
|
||||||
|
*/
|
||||||
|
ASSERT(mod[mod[0]] != 0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make sure the base is smaller than the modulus, by reducing
|
||||||
|
* it modulo the modulus if not.
|
||||||
|
*/
|
||||||
|
base = bigmod(base_in, mod);
|
||||||
|
|
||||||
/* Allocate m of size mlen, copy mod to m */
|
/* Allocate m of size mlen, copy mod to m */
|
||||||
/* We use big endian internally */
|
/* We use big endian internally */
|
||||||
@@ -300,6 +309,8 @@ Bignum modpow(Bignum base, Bignum exp, Bignum mod)
|
|||||||
n[i] = 0;
|
n[i] = 0;
|
||||||
delete [] n;
|
delete [] n;
|
||||||
|
|
||||||
|
freebn(base);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user