summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/WNafUtilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/math/ec/multiplier/WNafUtilities.cs')
-rw-r--r--crypto/src/math/ec/multiplier/WNafUtilities.cs13
1 files changed, 13 insertions, 0 deletions
diff --git a/crypto/src/math/ec/multiplier/WNafUtilities.cs b/crypto/src/math/ec/multiplier/WNafUtilities.cs
index 65d876449..42265b2d6 100644
--- a/crypto/src/math/ec/multiplier/WNafUtilities.cs
+++ b/crypto/src/math/ec/multiplier/WNafUtilities.cs
@@ -425,11 +425,13 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
 
                 if (null != existingWNaf && existingWNaf.ConfWidth == m_confWidth)
                 {
+                    existingWNaf.PromotionCountdown = 0;
                     return existingWNaf;
                 }
 
                 WNafPreCompInfo result = new WNafPreCompInfo();
 
+                result.PromotionCountdown = 0;
                 result.ConfWidth = m_confWidth;
 
                 if (null != existingWNaf)
@@ -516,7 +518,10 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
                 int reqPreCompLen = 1 << (width - 2);
 
                 if (CheckExisting(existingWNaf, width, reqPreCompLen, m_includeNegated))
+                {
+                    existingWNaf.DecrementPromotionCountdown();
                     return existingWNaf;
+                }
 
                 WNafPreCompInfo result = new WNafPreCompInfo();
 
@@ -526,6 +531,9 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
 
                 if (null != existingWNaf)
                 {
+                    int promotionCountdown = existingWNaf.DecrementPromotionCountdown();
+                    result.PromotionCountdown = promotionCountdown;
+
                     int confWidth = existingWNaf.ConfWidth;
                     result.ConfWidth = confWidth;
 
@@ -700,7 +708,10 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
                 int reqPreCompLen = m_fromWNaf.PreComp.Length;
 
                 if (CheckExisting(existingWNaf, width, reqPreCompLen, m_includeNegated))
+                {
+                    existingWNaf.DecrementPromotionCountdown();
                     return existingWNaf;
+                }
 
                 /*
                  * TODO Ideally this method would support incremental calculation, but given the
@@ -708,6 +719,8 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
                  */
                 WNafPreCompInfo result = new WNafPreCompInfo();
 
+                result.PromotionCountdown = m_fromWNaf.PromotionCountdown;
+
                 ECPoint twiceFrom = m_fromWNaf.Twice;
                 if (null != twiceFrom)
                 {