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:27:38 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 15:27:38 +0400
commit054d103f591f878c8a7ff8c2d8352f4f97427f15 (patch)
tree3dea81cf1064e6cf7a34aa08663dd5023573e1af /core/src/main/java/org
parent46533014857a7f9c26c9a15a177188d5202dbcd3 (diff)
Add support for use of ECPointMap to support GLV
Diffstat (limited to 'core/src/main/java/org')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/ECAlgorithms.java45
1 files changed, 40 insertions, 5 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/ECAlgorithms.java b/core/src/main/java/org/bouncycastle/math/ec/ECAlgorithms.java
index 63ba1ac1..aaec5276 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/ECAlgorithms.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/ECAlgorithms.java
@@ -178,23 +178,58 @@ public class ECAlgorithms
static ECPoint implShamirsTrickWNaf(ECPoint P, BigInteger k,
ECPoint Q, BigInteger l)
{
+ boolean negK = k.signum() < 0, negL = l.signum() < 0;
+
+ k = k.abs();
+ l = l.abs();
+
int widthP = Math.max(2, Math.min(16, WNafUtil.getWindowSize(k.bitLength())));
int widthQ = Math.max(2, Math.min(16, WNafUtil.getWindowSize(l.bitLength())));
WNafPreCompInfo infoP = WNafUtil.precompute(P, widthP, true);
WNafPreCompInfo infoQ = WNafUtil.precompute(Q, widthQ, true);
- ECPoint[] preCompP = infoP.getPreComp();
- ECPoint[] preCompQ = infoQ.getPreComp();
- ECPoint[] preCompNegP = infoP.getPreCompNeg();
- ECPoint[] preCompNegQ = infoQ.getPreCompNeg();
+ ECPoint[] preCompP = negK ? infoP.getPreCompNeg() : infoP.getPreComp();
+ ECPoint[] preCompQ = negL ? infoQ.getPreCompNeg() : infoQ.getPreComp();
+ ECPoint[] preCompNegP = negK ? infoP.getPreComp() : infoP.getPreCompNeg();
+ ECPoint[] preCompNegQ = negL ? infoQ.getPreComp() : infoQ.getPreCompNeg();
byte[] wnafP = WNafUtil.generateWindowNaf(widthP, k);
byte[] wnafQ = WNafUtil.generateWindowNaf(widthQ, l);
+ return implShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ, preCompNegQ, wnafQ);
+ }
+
+ static ECPoint implShamirsTrickWNaf(ECPoint P, BigInteger k, ECPointMap mapQ, BigInteger l)
+ {
+ boolean negK = k.signum() < 0, negL = l.signum() < 0;
+
+ k = k.abs();
+ l = l.abs();
+
+ int width = Math.max(2, Math.min(16, WNafUtil.getWindowSize(Math.max(k.bitLength(), l.bitLength()))));
+
+ ECPoint Q = WNafUtil.mapPointWithPrecomp(P, width, true, mapQ);
+ WNafPreCompInfo infoP = WNafUtil.getWNafPreCompInfo(P);
+ WNafPreCompInfo infoQ = WNafUtil.getWNafPreCompInfo(Q);
+
+ ECPoint[] preCompP = negK ? infoP.getPreCompNeg() : infoP.getPreComp();
+ ECPoint[] preCompQ = negL ? infoQ.getPreCompNeg() : infoQ.getPreComp();
+ ECPoint[] preCompNegP = negK ? infoP.getPreComp() : infoP.getPreCompNeg();
+ ECPoint[] preCompNegQ = negL ? infoQ.getPreComp() : infoQ.getPreCompNeg();
+
+ byte[] wnafP = WNafUtil.generateWindowNaf(width, k);
+ byte[] wnafQ = WNafUtil.generateWindowNaf(width, l);
+
+ return implShamirsTrickWNaf(preCompP, preCompNegP, wnafP, preCompQ, preCompNegQ, wnafQ);
+ }
+
+ private static ECPoint implShamirsTrickWNaf(ECPoint[] preCompP, ECPoint[] preCompNegP, byte[] wnafP,
+ ECPoint[] preCompQ, ECPoint[] preCompNegQ, byte[] wnafQ)
+ {
int len = Math.max(wnafP.length, wnafQ.length);
- ECCurve curve = P.getCurve();
+ ECCurve curve = preCompP[0].getCurve();
ECPoint infinity = curve.getInfinity();
ECPoint R = infinity;