Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 15:28:37 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 15:28:37 +0400
commit4f256c2f1bc119b208f9d35d847bf4c5b8072a5e (patch)
tree7d490defcd2930226ce6ec60a3c2550124f9ba26 /core/src/main/java/org
parent054d103f591f878c8a7ff8c2d8352f4f97427f15 (diff)
Add GLVMultiplier and supporting interfaces
Diffstat (limited to 'core/src/main/java/org')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/ECEndomorphism.java8
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/GLVEndomorphism.java8
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/GLVMultiplier.java40
3 files changed, 56 insertions, 0 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/ECEndomorphism.java b/core/src/main/java/org/bouncycastle/math/ec/ECEndomorphism.java
new file mode 100644
index 00000000..110bd2ab
--- /dev/null
+++ b/core/src/main/java/org/bouncycastle/math/ec/ECEndomorphism.java
@@ -0,0 +1,8 @@
+package org.bouncycastle.math.ec;
+
+public interface ECEndomorphism
+{
+ ECPointMap getPointMap();
+
+ boolean hasEfficientPointMap();
+}
diff --git a/core/src/main/java/org/bouncycastle/math/ec/GLVEndomorphism.java b/core/src/main/java/org/bouncycastle/math/ec/GLVEndomorphism.java
new file mode 100644
index 00000000..bf576908
--- /dev/null
+++ b/core/src/main/java/org/bouncycastle/math/ec/GLVEndomorphism.java
@@ -0,0 +1,8 @@
+package org.bouncycastle.math.ec;
+
+import java.math.BigInteger;
+
+public interface GLVEndomorphism extends ECEndomorphism
+{
+ BigInteger[] decomposeScalar(BigInteger k);
+}
diff --git a/core/src/main/java/org/bouncycastle/math/ec/GLVMultiplier.java b/core/src/main/java/org/bouncycastle/math/ec/GLVMultiplier.java
new file mode 100644
index 00000000..4a6b2343
--- /dev/null
+++ b/core/src/main/java/org/bouncycastle/math/ec/GLVMultiplier.java
@@ -0,0 +1,40 @@
+package org.bouncycastle.math.ec;
+
+import java.math.BigInteger;
+
+public class GLVMultiplier extends AbstractECMultiplier
+{
+ protected final ECCurve curve;
+ protected final GLVEndomorphism glvEndomorphism;
+
+ public GLVMultiplier(ECCurve curve, GLVEndomorphism glvEndomorphism)
+ {
+ if (curve == null || curve.getOrder() == null)
+ {
+ throw new IllegalArgumentException("Need curve with known group order");
+ }
+
+ this.curve = curve;
+ this.glvEndomorphism = glvEndomorphism;
+ }
+
+ protected ECPoint multiplyPositive(ECPoint p, BigInteger k)
+ {
+ if (!curve.equals(p.getCurve()))
+ {
+ throw new IllegalStateException();
+ }
+
+ BigInteger n = p.getCurve().getOrder();
+ BigInteger[] ab = glvEndomorphism.decomposeScalar(k.mod(n));
+ BigInteger a = ab[0], b = ab[1];
+
+ ECPointMap pointMap = glvEndomorphism.getPointMap();
+ if (glvEndomorphism.hasEfficientPointMap())
+ {
+ return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap, b);
+ }
+
+ return ECAlgorithms.implShamirsTrickWNaf(p, a, pointMap.map(p), b);
+ }
+}