Small optimization for width 4
1 files changed, 19 insertions, 17 deletions
diff --git a/crypto/src/math/ec/multiplier/WNafUtilities.cs b/crypto/src/math/ec/multiplier/WNafUtilities.cs
index eac47222b..b6e32382f 100644
--- a/crypto/src/math/ec/multiplier/WNafUtilities.cs
+++ b/crypto/src/math/ec/multiplier/WNafUtilities.cs
@@ -307,26 +307,28 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
if (preCompLen < reqPreCompLen)
{
- ECPoint twiceP = wnafPreCompInfo.Twice;
- if (twiceP == null)
+ preComp = ResizeTable(preComp, reqPreCompLen);
+ if (reqPreCompLen == 2)
{
- twiceP = preComp[0].Twice().Normalize();
- wnafPreCompInfo.Twice = twiceP;
+ preComp[1] = preComp[0].ThreeTimes();
}
-
- preComp = ResizeTable(preComp, reqPreCompLen);
-
- /*
- * TODO Okeya/Sakurai paper has precomputation trick and "Montgomery's Trick" to speed this up.
- * Also, co-Z arithmetic could avoid the subsequent normalization too.
- */
- for (int i = preCompLen; i < reqPreCompLen; i++)
+ else
{
- /*
- * Compute the new ECPoints for the precomputation array. The values 1, 3, 5, ...,
- * 2^(width-1)-1 times p are computed
- */
- preComp[i] = twiceP.Add(preComp[i - 1]);
+ ECPoint twiceP = wnafPreCompInfo.Twice;
+ if (twiceP == null)
+ {
+ twiceP = preComp[0].Twice().Normalize();
+ wnafPreCompInfo.Twice = twiceP;
+ }
+
+ for (int i = preCompLen; i < reqPreCompLen; i++)
+ {
+ /*
+ * Compute the new ECPoints for the precomputation array. The values 1, 3, 5, ...,
+ * 2^(width-1)-1 times p are computed
+ */
+ preComp[i] = twiceP.Add(preComp[i - 1]);
+ }
}
/*
|