diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-26 20:13:52 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2014-02-26 20:13:52 +0700 |
commit | 57d401f1c1919e507eb42ac0964a8b5d61ee6049 (patch) | |
tree | 413d79b8d57700b9270ab4533787474910e44822 /crypto/src/math/ec/custom/sec/SecP256R1Field.cs | |
parent | Optimize Sqrt() for custom curve secp224k1 (diff) | |
download | BouncyCastle.NET-ed25519-57d401f1c1919e507eb42ac0964a8b5d61ee6049.tar.xz |
Optimization for custom curve reduction when only a few bits need reducing; used to delay reduction in point doubling.
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecP256R1Field.cs')
-rw-r--r-- | crypto/src/math/ec/custom/sec/SecP256R1Field.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs index 88a13f513..9e366bffe 100644 --- a/crypto/src/math/ec/custom/sec/SecP256R1Field.cs +++ b/crypto/src/math/ec/custom/sec/SecP256R1Field.cs @@ -145,6 +145,42 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec } } + public static void Reduce32(uint x, uint[] z) + { + long xx08 = x; + + long cc = 0; + cc += (long)z[0] + xx08; + z[0] = (uint)cc; + cc >>= 32; + cc += (long)z[1]; + z[1] = (uint)cc; + cc >>= 32; + cc += (long)z[2]; + z[2] = (uint)cc; + cc >>= 32; + cc += (long)z[3] - xx08; + z[3] = (uint)cc; + cc >>= 32; + cc += (long)z[4]; + z[4] = (uint)cc; + cc >>= 32; + cc += (long)z[5]; + z[5] = (uint)cc; + cc >>= 32; + cc += (long)z[6] - xx08; + z[6] = (uint)cc; + cc >>= 32; + cc += (long)z[7] + xx08; + z[7] = (uint)cc; + cc >>= 32; + + if (cc != 0 || (z[7] == P7 && Nat256.Gte(z, P))) + { + Nat256.Sub(z, P, z); + } + } + public static void Square(uint[] x, uint[] z) { uint[] tt = Nat256.CreateExt(); |