summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-30 21:26:02 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-30 21:26:02 +0700
commit410a99b2871b3ec203affe141bd17dbc1312ed07 (patch)
treef41e97fdbea388ec33f53ab016fa31546483bf22
parentFix GetBit range-check (diff)
downloadBouncyCastle.NET-ed25519-410a99b2871b3ec203affe141bd17dbc1312ed07.tar.xz
Fix final step of Reduce()
-rw-r--r--crypto/src/math/ec/custom/sec/SecP256R1Field.cs19
1 files changed, 9 insertions, 10 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs
index cb9874bfd..eab4af956 100644
--- a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs
@@ -115,27 +115,26 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             cc >>= 32;
 
             int c = (int)cc;
-            if (c > 0)
+            if (c < 0)
             {
                 do
                 {
+                    c += (int)Nat256.Add(z, P, z);
+                }
+                while (c < 0);
+            }
+            else
+            {
+                while (c > 0)
+                {
                     c += Nat256.Sub(z, P, z);
                 }
-                while (c != 0);
 
                 if (z[7] == P7 && Nat256.Gte(z, P))
                 {
                     Nat256.Sub(z, P, z);
                 }
             }
-            else if (c < 0)
-            {
-                do
-                {
-                    c += (int)Nat256.Add(z, P, z);
-                }
-                while (c != 0);
-            }
         }
 
         public static void Square(uint[] x, uint[] z)