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-04-10 06:41:41 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-04-10 06:41:41 +0400
commit6703d5e37da115f1d0d1b75ce083da6244ae43f6 (patch)
tree783b546631c9fd4d798765957985d1bb645a2dac
parentbde0643867e66ab5080ff228e7e432e7f6667a97 (diff)
Fixed-point-comb uses existing precomputation info if it's for the same
_or greater_ width as requested
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/FixedPointCombMultiplier.java5
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/FixedPointPreCompInfo.java17
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/FixedPointUtil.java17
3 files changed, 29 insertions, 10 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/FixedPointCombMultiplier.java b/core/src/main/java/org/bouncycastle/math/ec/FixedPointCombMultiplier.java
index d2cc2e3b..9fe00b9b 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/FixedPointCombMultiplier.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/FixedPointCombMultiplier.java
@@ -20,10 +20,11 @@ public class FixedPointCombMultiplier extends AbstractECMultiplier
throw new IllegalStateException("fixed-point comb doesn't support scalars larger than the curve order");
}
- int width = getWidthForCombSize(size);
+ int minWidth = getWidthForCombSize(size);
- FixedPointPreCompInfo info = FixedPointUtil.precompute(p, width);
+ FixedPointPreCompInfo info = FixedPointUtil.precompute(p, minWidth);
ECPoint[] lookupTable = info.getPreComp();
+ int width = info.getWidth();
int d = (size + width - 1) / width;
diff --git a/core/src/main/java/org/bouncycastle/math/ec/FixedPointPreCompInfo.java b/core/src/main/java/org/bouncycastle/math/ec/FixedPointPreCompInfo.java
index 7cfb7f47..b7569aae 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/FixedPointPreCompInfo.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/FixedPointPreCompInfo.java
@@ -11,6 +11,13 @@ public class FixedPointPreCompInfo implements PreCompInfo
*/
protected ECPoint[] preComp = null;
+ /**
+ * The width used for the precomputation. If a larger width precomputation
+ * is already available this may be larger than was requested, so calling
+ * code should refer to the actual width.
+ */
+ protected int width = -1;
+
public ECPoint[] getPreComp()
{
return preComp;
@@ -20,4 +27,14 @@ public class FixedPointPreCompInfo implements PreCompInfo
{
this.preComp = preComp;
}
+
+ public int getWidth()
+ {
+ return width;
+ }
+
+ public void setWidth(int width)
+ {
+ this.width = width;
+ }
}
diff --git a/core/src/main/java/org/bouncycastle/math/ec/FixedPointUtil.java b/core/src/main/java/org/bouncycastle/math/ec/FixedPointUtil.java
index aba9143f..e4fbb8d0 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/FixedPointUtil.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/FixedPointUtil.java
@@ -22,22 +22,22 @@ public class FixedPointUtil
return new FixedPointPreCompInfo();
}
- public static FixedPointPreCompInfo precompute(ECPoint p, int width)
+ public static FixedPointPreCompInfo precompute(ECPoint p, int minWidth)
{
ECCurve c = p.getCurve();
- int n = 1 << width;
+ int n = 1 << minWidth;
FixedPointPreCompInfo info = getFixedPointPreCompInfo(c.getPreCompInfo(p, PRECOMP_NAME));
ECPoint[] lookupTable = info.getPreComp();
- if (lookupTable == null || lookupTable.length != n)
+ if (lookupTable == null || lookupTable.length < n)
{
int bits = getCombSize(c);
- int d = (bits + width - 1) / width;
+ int d = (bits + minWidth - 1) / minWidth;
- ECPoint[] pow2Table = new ECPoint[width];
+ ECPoint[] pow2Table = new ECPoint[minWidth];
pow2Table[0] = p;
- for (int i = 1; i < width; ++i)
+ for (int i = 1; i < minWidth; ++i)
{
pow2Table[i] = pow2Table[i - 1].timesPow2(d);
}
@@ -47,7 +47,7 @@ public class FixedPointUtil
lookupTable = new ECPoint[n];
lookupTable[0] = c.getInfinity();
- for (int bit = width - 1; bit >= 0; --bit)
+ for (int bit = minWidth - 1; bit >= 0; --bit)
{
ECPoint pow2 = pow2Table[bit];
@@ -57,10 +57,11 @@ public class FixedPointUtil
lookupTable[i] = lookupTable[i - step].add(pow2);
}
}
-
+
c.normalizeAll(lookupTable);
info.setPreComp(lookupTable);
+ info.setWidth(minWidth);
c.setPreCompInfo(p, PRECOMP_NAME, info);
}