From 410a99b2871b3ec203affe141bd17dbc1312ed07 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 30 Jan 2014 21:26:02 +0700 Subject: Fix final step of Reduce() --- crypto/src/math/ec/custom/sec/SecP256R1Field.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'crypto/src/math') 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) -- cgit 1.5.1