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:
Diffstat (limited to 'core/src/main/java/org/spongycastle/math/ec/endo')
-rw-r--r--core/src/main/java/org/spongycastle/math/ec/endo/ECEndomorphism.java10
-rw-r--r--core/src/main/java/org/spongycastle/math/ec/endo/GLVEndomorphism.java8
-rw-r--r--core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBEndomorphism.java58
-rw-r--r--core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBParameters.java59
4 files changed, 135 insertions, 0 deletions
diff --git a/core/src/main/java/org/spongycastle/math/ec/endo/ECEndomorphism.java b/core/src/main/java/org/spongycastle/math/ec/endo/ECEndomorphism.java
new file mode 100644
index 00000000..7396bf33
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/math/ec/endo/ECEndomorphism.java
@@ -0,0 +1,10 @@
+package org.spongycastle.math.ec.endo;
+
+import org.spongycastle.math.ec.ECPointMap;
+
+public interface ECEndomorphism
+{
+ ECPointMap getPointMap();
+
+ boolean hasEfficientPointMap();
+}
diff --git a/core/src/main/java/org/spongycastle/math/ec/endo/GLVEndomorphism.java b/core/src/main/java/org/spongycastle/math/ec/endo/GLVEndomorphism.java
new file mode 100644
index 00000000..9c251a1e
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/math/ec/endo/GLVEndomorphism.java
@@ -0,0 +1,8 @@
+package org.spongycastle.math.ec.endo;
+
+import java.math.BigInteger;
+
+public interface GLVEndomorphism extends ECEndomorphism
+{
+ BigInteger[] decomposeScalar(BigInteger k);
+}
diff --git a/core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBEndomorphism.java b/core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBEndomorphism.java
new file mode 100644
index 00000000..884cbf53
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBEndomorphism.java
@@ -0,0 +1,58 @@
+package org.spongycastle.math.ec.endo;
+
+import java.math.BigInteger;
+
+import org.spongycastle.math.ec.ECConstants;
+import org.spongycastle.math.ec.ECCurve;
+import org.spongycastle.math.ec.ECPointMap;
+import org.spongycastle.math.ec.ScaleXPointMap;
+
+public class GLVTypeBEndomorphism implements GLVEndomorphism
+{
+ protected final ECCurve curve;
+ protected final GLVTypeBParameters parameters;
+ protected final ECPointMap pointMap;
+
+ public GLVTypeBEndomorphism(ECCurve curve, GLVTypeBParameters parameters)
+ {
+ this.curve = curve;
+ this.parameters = parameters;
+ this.pointMap = new ScaleXPointMap(curve.fromBigInteger(parameters.getBeta()));
+ }
+
+ public BigInteger[] decomposeScalar(BigInteger k)
+ {
+ int bits = parameters.getBits();
+ BigInteger b1 = calculateB(k, parameters.getG1(), bits);
+ BigInteger b2 = calculateB(k, parameters.getG2(), bits);
+
+ BigInteger[] v1 = parameters.getV1(), v2 = parameters.getV2();
+ BigInteger a = k.subtract((b1.multiply(v1[0])).add(b2.multiply(v2[0])));
+ BigInteger b = (b1.multiply(v1[1])).add(b2.multiply(v2[1])).negate();
+
+ return new BigInteger[]{ a, b };
+ }
+
+ public ECPointMap getPointMap()
+ {
+ return pointMap;
+ }
+
+ public boolean hasEfficientPointMap()
+ {
+ return true;
+ }
+
+ protected BigInteger calculateB(BigInteger k, BigInteger g, int t)
+ {
+ boolean negative = (g.signum() < 0);
+ BigInteger b = k.multiply(g.abs());
+ boolean extra = b.testBit(t - 1);
+ b = b.shiftRight(t);
+ if (extra)
+ {
+ b = b.add(ECConstants.ONE);
+ }
+ return negative ? b.negate() : b;
+ }
+}
diff --git a/core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBParameters.java b/core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBParameters.java
new file mode 100644
index 00000000..92dbfd0e
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/math/ec/endo/GLVTypeBParameters.java
@@ -0,0 +1,59 @@
+package org.spongycastle.math.ec.endo;
+
+import java.math.BigInteger;
+
+public class GLVTypeBParameters
+{
+ protected final BigInteger beta;
+ protected final BigInteger lambda;
+ protected final BigInteger[] v1, v2;
+ protected final BigInteger g1, g2;
+ protected final int bits;
+
+ public GLVTypeBParameters(BigInteger beta, BigInteger lambda, BigInteger[] v1, BigInteger[] v2, BigInteger g1,
+ BigInteger g2, int bits)
+ {
+ this.beta = beta;
+ this.lambda = lambda;
+ this.v1 = v1;
+ this.v2 = v2;
+ this.g1 = g1;
+ this.g2 = g2;
+ this.bits = bits;
+ }
+
+ public BigInteger getBeta()
+ {
+ return beta;
+ }
+
+ public BigInteger getLambda()
+ {
+ return lambda;
+ }
+
+ public BigInteger[] getV1()
+ {
+ return v1;
+ }
+
+ public BigInteger[] getV2()
+ {
+ return v2;
+ }
+
+ public BigInteger getG1()
+ {
+ return g1;
+ }
+
+ public BigInteger getG2()
+ {
+ return g2;
+ }
+
+ public int getBits()
+ {
+ return bits;
+ }
+}