summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-14 11:46:03 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-14 11:46:03 +0700
commit2271696c780b55d0da8400319048d64980b3d3f0 (patch)
tree25127146f56ced5c52108eb05664ea5a344891aa
parentPort GLV implementation from Java (diff)
downloadBouncyCastle.NET-ed25519-2271696c780b55d0da8400319048d64980b3d3f0.tar.xz
GlvMultiplier.cs missed in last commit
-rw-r--r--crypto/crypto.csproj5
-rw-r--r--crypto/src/math/ec/multiplier/GlvMultiplier.cs40
2 files changed, 45 insertions, 0 deletions
diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj
index 195d69a23..b58f1221a 100644
--- a/crypto/crypto.csproj
+++ b/crypto/crypto.csproj
@@ -4934,6 +4934,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "src\math\ec\multiplier\GlvMultiplier.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "src\math\ec\multiplier\MixedNafR2LMultiplier.cs"
                     SubType = "Code"
                     BuildAction = "Compile"
diff --git a/crypto/src/math/ec/multiplier/GlvMultiplier.cs b/crypto/src/math/ec/multiplier/GlvMultiplier.cs
new file mode 100644
index 000000000..f19049474
--- /dev/null
+++ b/crypto/src/math/ec/multiplier/GlvMultiplier.cs
@@ -0,0 +1,40 @@
+using System;
+
+using Org.BouncyCastle.Math.EC.Endo;
+
+namespace Org.BouncyCastle.Math.EC.Multiplier
+{
+    public class GlvMultiplier
+        :   AbstractECMultiplier
+    {
+        protected readonly ECCurve curve;
+        protected readonly GlvEndomorphism glvEndomorphism;
+
+        public GlvMultiplier(ECCurve curve, GlvEndomorphism glvEndomorphism)
+        {
+            if (curve == null || curve.Order == null)
+                throw new ArgumentException("Need curve with known group order", "curve");
+
+            this.curve = curve;
+            this.glvEndomorphism = glvEndomorphism;
+        }
+
+        protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
+        {
+            if (!curve.Equals(p.Curve))
+                throw new InvalidOperationException();
+
+            BigInteger n = p.Curve.Order;
+            BigInteger[] ab = glvEndomorphism.DecomposeScalar(k.Mod(n));
+            BigInteger a = ab[0], b = ab[1];
+
+            ECPointMap pointMap = glvEndomorphism.PointMap;
+            if (glvEndomorphism.HasEfficientPointMap)
+            {
+                return ECAlgorithms.ImplShamirsTrickWNaf(p, a, pointMap, b);
+            }
+
+            return ECAlgorithms.ImplShamirsTrickWNaf(p, a, pointMap.Map(p), b);
+        }
+    }
+}