summary refs log tree commit diff
path: root/crypto/src/math
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-02-07 13:03:06 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-02-07 13:03:06 +0700
commit8e39d26c70331a06dd720df7fd123df469c4941e (patch)
treee30772ea356328471379aacbc8edf45c5f586df3 /crypto/src/math
parentIndex precomputation info by name (diff)
downloadBouncyCastle.NET-ed25519-8e39d26c70331a06dd720df7fd123df469c4941e.tar.xz
Small optimization for width 4
Diffstat (limited to 'crypto/src/math')
-rw-r--r--crypto/src/math/ec/multiplier/WNafUtilities.cs36
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]);
+                    }
                 }
 
                 /*