summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/WNafUtilities.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2019-08-04 18:50:38 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2019-08-04 18:50:38 +0700
commitce8597dc3267380910f383106ece66c4f1b15756 (patch)
tree466fd6e981d191edb5ee2f2fc0e3029fa491887b /crypto/src/math/ec/multiplier/WNafUtilities.cs
parentUse Arrays.Reverse utility method in several places (diff)
downloadBouncyCastle.NET-ed25519-ce8597dc3267380910f383106ece66c4f1b15756.tar.xz
Implement promotion for ECPoint precomputations
- a point is promoted after repeated use (e.g. in ECDSA verification)
- promoted points are eligible for extra precomp => faster algorithms
Diffstat (limited to '')
-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)
                 {