summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecP192K1Point.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-10 19:19:52 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-10 19:19:52 +0700
commit84e8dad1309ad2d247af6cfd9038bff5ac5ce941 (patch)
treecec106af064d73325907ce8309cecbc083f8a741 /crypto/src/math/ec/custom/sec/SecP192K1Point.cs
parentAdapt performance test to exclude outliers form average (diff)
downloadBouncyCastle.NET-ed25519-84e8dad1309ad2d247af6cfd9038bff5ac5ce941.tar.xz
Optimize some of the addition/doubling internals
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecP192K1Point.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecP192K1Point.cs33
1 files changed, 18 insertions, 15 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP192K1Point.cs b/crypto/src/math/ec/custom/sec/SecP192K1Point.cs
index 1c6573aca..561324f8e 100644
--- a/crypto/src/math/ec/custom/sec/SecP192K1Point.cs
+++ b/crypto/src/math/ec/custom/sec/SecP192K1Point.cs
@@ -77,8 +77,9 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             SecP192K1FieldElement Z1 = (SecP192K1FieldElement)this.RawZCoords[0];
             SecP192K1FieldElement Z2 = (SecP192K1FieldElement)b.RawZCoords[0];
 
+            uint c;
             uint[] tt1 = Nat192.CreateExt();
-            uint[] tt2 = Nat192.CreateExt();
+            uint[] t2 = Nat192.Create();
             uint[] t3 = Nat192.Create();
             uint[] t4 = Nat192.Create();
 
@@ -94,7 +95,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                 S2 = t3;
                 SecP192K1Field.Square(Z1.x, S2);
 
-                U2 = tt2;
+                U2 = t2;
                 SecP192K1Field.Multiply(S2, X2.x, U2);
 
                 SecP192K1Field.Multiply(S2, Z1.x, S2);
@@ -123,7 +124,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             uint[] H = Nat192.Create();
             SecP192K1Field.Subtract(U1, U2, H);
 
-            uint[] R = tt2;
+            uint[] R = t2;
             SecP192K1Field.Subtract(S1, S2, R);
 
             // Check if b == this or b == -this
@@ -148,19 +149,20 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             uint[] V = t3;
             SecP192K1Field.Multiply(HSquared, U1, V);
 
+            SecP192K1Field.Negate(G, G);
             Nat192.Mul(S1, G, tt1);
 
+            c = Nat192.AddBothTo(V, V, G);
+            SecP192K1Field.Reduce32(c, G);
+
             SecP192K1FieldElement X3 = new SecP192K1FieldElement(t4);
             SecP192K1Field.Square(R, X3.x);
-            SecP192K1Field.Add(X3.x, G, X3.x);
-            SecP192K1Field.Subtract(X3.x, V, X3.x);
-            SecP192K1Field.Subtract(X3.x, V, X3.x);
+            SecP192K1Field.Subtract(X3.x, G, X3.x);
 
             SecP192K1FieldElement Y3 = new SecP192K1FieldElement(G);
             SecP192K1Field.Subtract(V, X3.x, Y3.x);
-            Nat192.Mul(Y3.x, R, tt2);
-            SecP192K1Field.SubtractExt(tt2, tt1, tt2);
-            SecP192K1Field.Reduce(tt2, Y3.x);
+            SecP192K1Field.MultiplyAddToExt(Y3.x, R, tt1);
+            SecP192K1Field.Reduce(tt1, Y3.x);
 
             SecP192K1FieldElement Z3 = new SecP192K1FieldElement(H);
             if (!Z1IsOne)
@@ -190,24 +192,25 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
             SecP192K1FieldElement X1 = (SecP192K1FieldElement)this.RawXCoord, Z1 = (SecP192K1FieldElement)this.RawZCoords[0];
 
+            uint c;
+
             uint[] Y1Squared = Nat192.Create();
             SecP192K1Field.Square(Y1.x, Y1Squared);
 
             uint[] T = Nat192.Create();
             SecP192K1Field.Square(Y1Squared, T);
 
-            uint[] t1 = Nat192.Create();
-            SecP192K1Field.Square(X1.x, t1);
-
             uint[] M = Nat192.Create();
-            SecP192K1Field.Twice(t1, M);
-            SecP192K1Field.Add(M, t1, M);
+            SecP192K1Field.Square(X1.x, M);
+            c = Nat192.AddBothTo(M, M, M);
+            SecP192K1Field.Reduce32(c, M);
 
             uint[] S = Y1Squared;
             SecP192K1Field.Multiply(Y1Squared, X1.x, S);
-            uint c = Nat.ShiftUpBits(6, S, 2, 0);
+            c = Nat.ShiftUpBits(6, S, 2, 0);
             SecP192K1Field.Reduce32(c, S);
 
+            uint[] t1 = Nat192.Create();
             c = Nat.ShiftUpBits(6, T, 3, 0, t1);
             SecP192K1Field.Reduce32(c, t1);