summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecP192K1Field.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 18:43:12 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-01-31 18:43:12 +0700
commit7118a1a3f987cd82db0243ebcd03e844e73b7ffa (patch)
treef03753da78d3531fcf845b70c79091191fb95edf /crypto/src/math/ec/custom/sec/SecP192K1Field.cs
parentAdd custom curves for secp192k1 and secp192r1 (P-192) (diff)
downloadBouncyCastle.NET-ed25519-7118a1a3f987cd82db0243ebcd03e844e73b7ffa.tar.xz
Improve reduction speed for secp192k1 and secp256k1 custom fields
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecP192K1Field.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecP192K1Field.cs11
1 files changed, 3 insertions, 8 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP192K1Field.cs b/crypto/src/math/ec/custom/sec/SecP192K1Field.cs
index 30c107c86..9da3c0257 100644
--- a/crypto/src/math/ec/custom/sec/SecP192K1Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecP192K1Field.cs
@@ -12,7 +12,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             0x00000000, 0xFFFFDC6E, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
         private const uint PExt11 = 0xFFFFFFFF;
         private const ulong PInv = 0x00000001000011C9L;
-        private const uint PInvLow = 0x11C9;
+        private const uint PInv33 = 0x11C9;
 
         public static void Add(uint[] x, uint[] y, uint[] z)
         {
@@ -86,13 +86,8 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         public static void Reduce(uint[] tt, uint[] z)
         {
-            long extra = -(long)tt[6];
-            extra += (long)Nat192.MulWordAddExt(PInvLow, tt, 6, tt, 0);
-            extra += (long)Nat192.AddToExt(tt, 6, tt, 1) << 32;
-            extra += (long)tt[6];
-
-            ulong c = Nat192.MulWordDwordAdd(PInvLow, (ulong)extra, tt, 0);
-            c += Nat192.AddDWord((ulong)extra, tt, 1);
+            ulong c = Nat192.Mul33AddExt(PInv33, tt, 6, tt, 0);
+            c = Nat192.Mul33DWordAdd(PInv33, c, tt, 0);
 
             Debug.Assert(c == 0 || c == 1);