summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs')
-rw-r--r--crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs b/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
new file mode 100644
index 000000000..51ed5d7c5
--- /dev/null
+++ b/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
@@ -0,0 +1,38 @@
+using System;
+
+namespace Org.BouncyCastle.Math.EC.Multiplier
+{
+    public class FixedPointCombMultiplier
+        : AbstractECMultiplier
+    {
+        protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
+        {
+            int width = 4;
+
+            FixedPointPreCompInfo info = FixedPointUtilities.Precompute(p, width);
+            ECPoint[] lookupTable = info.PreComp;
+
+            ECCurve c = p.Curve;
+            int d = (c.Order.BitLength + width - 1) / width;
+
+            ECPoint R = c.Infinity;
+
+            for (int i = d - 1; i >= 0; --i)
+            {
+                int index = 0;
+                for (int j = width - 1; j >= 0; --j)
+                {
+                    index <<= 1;
+                    if (k.TestBit(j * d + i))
+                    {
+                        index |= 1;
+                    }
+                }
+
+                R = R.TwicePlus(lookupTable[index]);
+            }
+
+            return R;
+        }
+    }
+}