summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs')
-rw-r--r--crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs25
1 files changed, 8 insertions, 17 deletions
diff --git a/crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs b/crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs
index f671f6a5c..833bbb5ea 100644
--- a/crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs
+++ b/crypto/src/math/ec/multiplier/WNafL2RMultiplier.cs
@@ -1,5 +1,7 @@
 using System;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Math.EC.Multiplier
 {
     /**
@@ -18,12 +20,12 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
          */
         protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
         {
-            // Clamp the window width in the range [2, 16]
-            int width = System.Math.Max(2, System.Math.Min(16, GetWindowSize(k.BitLength)));
+            int minWidth = WNafUtilities.GetWindowSize(k.BitLength);
 
-            WNafPreCompInfo wnafPreCompInfo = WNafUtilities.Precompute(p, width, true);
-            ECPoint[] preComp = wnafPreCompInfo.PreComp;
-            ECPoint[] preCompNeg = wnafPreCompInfo.PreCompNeg;
+            WNafPreCompInfo info = WNafUtilities.Precompute(p, minWidth, true);
+            ECPoint[] preComp = info.PreComp;
+            ECPoint[] preCompNeg = info.PreCompNeg;
+            int width = info.Width;
 
             int[] wnaf = WNafUtilities.GenerateCompactWindowNaf(width, k);
 
@@ -46,7 +48,7 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
                 // Optimization can only be used for values in the lower half of the table
                 if ((n << 2) < (1 << width))
                 {
-                    int highest = LongArray.BitLengths[n];
+                    int highest = 32 - Integers.NumberOfLeadingZeros(n);
 
                     // TODO Get addition/doubling cost ratio from curve and compare to 'scale' to see if worth substituting?
                     int scale = width - highest;
@@ -83,16 +85,5 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
 
             return R;
         }
-
-        /**
-         * Determine window width to use for a scalar multiplication of the given size.
-         * 
-         * @param bits the bit-length of the scalar to multiply by
-         * @return the window size to use
-         */
-        protected virtual int GetWindowSize(int bits)
-        {
-            return WNafUtilities.GetWindowSize(bits);
-        }
     }
 }