summary refs log tree commit diff
path: root/crypto/src/math/BigInteger.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-03 13:10:23 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-03 13:10:23 +0700
commit9a6645ec73dc40ddb37c92222f78df625fd19bb4 (patch)
tree701daba9b01d667b4799c00b3e7a13519f85a080 /crypto/src/math/BigInteger.cs
parentFix tabs (diff)
downloadBouncyCastle.NET-ed25519-9a6645ec73dc40ddb37c92222f78df625fd19bb4.tar.xz
Registerize top accumulator word in Montgomery multiplication/squaring
Diffstat (limited to 'crypto/src/math/BigInteger.cs')
-rw-r--r--crypto/src/math/BigInteger.cs18
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);