summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecP160K1Curve.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecP160K1Curve.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecP160K1Curve.cs28
1 files changed, 24 insertions, 4 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecP160K1Curve.cs b/crypto/src/math/ec/custom/sec/SecP160K1Curve.cs
index 234c86b87..4bacd55c6 100644
--- a/crypto/src/math/ec/custom/sec/SecP160K1Curve.cs
+++ b/crypto/src/math/ec/custom/sec/SecP160K1Curve.cs
@@ -12,6 +12,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
 
         private const int SECP160K1_DEFAULT_COORDS = COORD_JACOBIAN;
         private const int SECP160K1_FE_INTS = 5;
+        private static readonly ECFieldElement[] SECP160K1_AFFINE_ZS = new ECFieldElement[] { new SecP160R2FieldElement(BigInteger.One) };
 
         protected readonly SecP160K1Point m_infinity;
 
@@ -90,7 +91,7 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
         }
 
         private class SecP160K1LookupTable
-            : ECLookupTable
+            : AbstractECLookupTable
         {
             private readonly SecP160K1Curve m_outer;
             private readonly uint[] m_table;
@@ -103,12 +104,12 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                 this.m_size = size;
             }
 
-            public virtual int Size
+            public override int Size
             {
                 get { return m_size; }
             }
 
-            public virtual ECPoint Lookup(int index)
+            public override ECPoint Lookup(int index)
             {
                 uint[] x = Nat256.Create(), y = Nat256.Create();
                 int pos = 0;
@@ -126,7 +127,26 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
                     pos += (SECP160K1_FE_INTS * 2);
                 }
 
-                return m_outer.CreateRawPoint(new SecP160R2FieldElement(x), new SecP160R2FieldElement(y), false);
+                return CreatePoint(x, y);
+            }
+
+            public override ECPoint LookupVar(int index)
+            {
+                uint[] x = Nat256.Create(), y = Nat256.Create();
+                int pos = index * SECP160K1_FE_INTS * 2;
+
+                for (int j = 0; j < SECP160K1_FE_INTS; ++j)
+                {
+                    x[j] = m_table[pos + j];
+                    y[j] = m_table[pos + SECP160K1_FE_INTS + j];
+                }
+
+                return CreatePoint(x, y);
+            }
+
+            private ECPoint CreatePoint(uint[] x, uint[] y)
+            {
+                return m_outer.CreateRawPoint(new SecP160R2FieldElement(x), new SecP160R2FieldElement(y), SECP160K1_AFFINE_ZS, false);
             }
         }
     }