diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-03 13:10:23 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-01-03 13:10:23 +0700 |
commit | 9a6645ec73dc40ddb37c92222f78df625fd19bb4 (patch) | |
tree | 701daba9b01d667b4799c00b3e7a13519f85a080 | |
parent | Fix tabs (diff) | |
download | BouncyCastle.NET-ed25519-9a6645ec73dc40ddb37c92222f78df625fd19bb4.tar.xz |
Registerize top accumulator word in Montgomery multiplication/squaring
-rw-r--r-- | crypto/src/math/BigInteger.cs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crypto/src/math/BigInteger.cs b/crypto/src/math/BigInteger.cs index fa7cdda3e..04c04a55d 100644 --- a/crypto/src/math/BigInteger.cs +++ b/crypto/src/math/BigInteger.cs @@ -2269,6 +2269,7 @@ namespace Org.BouncyCastle.Math } uint y0 = (uint)y[n - 1]; + int aMax; { ulong xi = (uint)x[n - 1]; @@ -2292,7 +2293,7 @@ namespace Org.BouncyCastle.Math } a[1] = (int)carry; - a[0] = (int)(carry >> 32); + aMax = (int)(carry >> 32); } for (int i = n - 2; i >= 0; --i) @@ -2319,11 +2320,13 @@ namespace Org.BouncyCastle.Math carry = (carry >> 32) + (prod1 >> 32) + (prod2 >> 32); } - carry += (uint)a[0]; + carry += (uint)aMax; a[1] = (int)carry; - a[0] = (int)(carry >> 32); + aMax = (int)(carry >> 32); } + a[0] = aMax; + if (!smallMontyModulus && CompareTo(0, a, 0, m) >= 0) { Subtract(0, a, 0, m); @@ -2345,6 +2348,7 @@ namespace Org.BouncyCastle.Math } ulong x0 = (uint)x[n - 1]; + int aMax; { ulong carry = x0 * x0; @@ -2366,7 +2370,7 @@ namespace Org.BouncyCastle.Math } a[1] = (int)carry; - a[0] = (int)(carry >> 32); + aMax = (int)(carry >> 32); } for (int i = n - 2; i >= 0; --i) @@ -2406,11 +2410,13 @@ namespace Org.BouncyCastle.Math carry = (carry >> 32) + (prod1 >> 31) + (prod2 >> 32); } - carry += (uint)a[0]; + carry += (uint)aMax; a[1] = (int)carry; - a[0] = (int)(carry >> 32); + aMax = (int)(carry >> 32); } + a[0] = aMax; + if (!smallMontyModulus && CompareTo(0, a, 0, m) >= 0) { Subtract(0, a, 0, m); |