summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-02-04 16:08:03 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-04 16:08:03 +0700
commit26f31767019ceb2f113a280aa7ad64cbbfa3b55f (patch)
tree64ffe40f3b960ef9eeedc5a88bb29a6d24eb420b /crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
parentFor repeated doublings, use jacobian-modified coordinates internally irrespec... (diff)
downloadBouncyCastle.NET-ed25519-26f31767019ceb2f113a280aa7ad64cbbfa3b55f.tar.xz
Initial work on a fixed-point comb multiplier
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;
+        }
+    }
+}