From 0d3d5efb92682537a15015aa7f09e89b16e76543 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 14 Jan 2005 03:00:42 +0000 Subject: [PATCH] merge http://www.tartarus.org/~simon-anonsvn/viewcvs.cgi/putty/sshbn.c?rev=4372&r1=3760&r2=4372 --- stepmania/src/crypto/CryptBn.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/stepmania/src/crypto/CryptBn.cpp b/stepmania/src/crypto/CryptBn.cpp index bb5615a5e3..9b4e77e8fd 100644 --- a/stepmania/src/crypto/CryptBn.cpp +++ b/stepmania/src/crypto/CryptBn.cpp @@ -195,16 +195,25 @@ h:a[i]:a[i+1] / m0:m1 */ /* * 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; int mshift; 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 */ /* We use big endian internally */ @@ -300,6 +309,8 @@ Bignum modpow(Bignum base, Bignum exp, Bignum mod) n[i] = 0; delete [] n; + freebn(base); + return result; }