diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-10 11:12:13 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-03-10 11:12:13 +0700 |
commit | 2c6c7ebd4b95663e839729ef7f1ee0b1a94c36af (patch) | |
tree | 709b7d41aa50592ee2d528c94f7619b164b25435 /crypto/src/math/ec/custom/sec/SecP192R1Field.cs | |
parent | Use more specific Nat methods (diff) | |
download | BouncyCastle.NET-ed25519-2c6c7ebd4b95663e839729ef7f1ee0b1a94c36af.tar.xz |
Inline Reduce32 calls and registerize some values to avoid extra writes
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecP192R1Field.cs')
-rw-r--r-- | crypto/src/math/ec/custom/sec/SecP192R1Field.cs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP192R1Field.cs b/crypto/src/math/ec/custom/sec/SecP192R1Field.cs index 078ef94f8..5878749cf 100644 --- a/crypto/src/math/ec/custom/sec/SecP192R1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP192R1Field.cs @@ -96,7 +96,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec ulong cc = 0; cc += (ulong)xx[0] + t0; - z[0] = (uint)cc; + uint z0 = (uint)cc; cc >>= 32; cc += (ulong)xx[1] + t1; z[1] = (uint)cc; @@ -106,7 +106,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec t1 += xx09; cc += (ulong)xx[2] + t0; - z[2] = (uint)cc; + ulong z2 = (uint)cc; cc >>= 32; cc += (ulong)xx[3] + t1; z[3] = (uint)cc; @@ -122,27 +122,45 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec z[5] = (uint)cc; cc >>= 32; - Reduce32((uint)cc, z); + z2 += cc; + + cc += z0; + z[0] = (uint)cc; + cc >>= 32; + if (cc != 0) + { + cc += z[1]; + z[1] = (uint)cc; + z2 += cc >> 32; + } + z[2] = (uint)z2; + cc = z2 >> 32; + + Debug.Assert(cc == 0 || cc == 1); + + if ((cc != 0 && Nat.IncAt(6, z, 3) != 0) + || (z[5] == P5 && Nat192.Gte(z, P))) + { + AddPInvTo(z); + } } public static void Reduce32(uint x, uint[] z) { - long cc = 0; + ulong cc = 0; if (x != 0) { - long xx06 = x; - - cc += (long)z[0] + xx06; + cc += (ulong)z[0] + x; z[0] = (uint)cc; cc >>= 32; if (cc != 0) { - cc += (long)z[1]; + cc += (ulong)z[1]; z[1] = (uint)cc; cc >>= 32; } - cc += (long)z[2] + xx06; + cc += (ulong)z[2] + x; z[2] = (uint)cc; cc >>= 32; |