diff options
Diffstat (limited to 'crypto/src/math/ec/ECCurve.cs')
-rw-r--r-- | crypto/src/math/ec/ECCurve.cs | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/crypto/src/math/ec/ECCurve.cs b/crypto/src/math/ec/ECCurve.cs index 73b70f6de..3999ba4f0 100644 --- a/crypto/src/math/ec/ECCurve.cs +++ b/crypto/src/math/ec/ECCurve.cs @@ -90,6 +90,8 @@ namespace Org.BouncyCastle.Math.EC protected ECEndomorphism m_endomorphism = null; protected ECMultiplier m_multiplier = null; + private IDictionary<string, PreCompInfo> m_preCompTable = null; + protected ECCurve(IFiniteField field) { this.m_field = field; @@ -160,6 +162,32 @@ namespace Org.BouncyCastle.Math.EC } } + internal virtual PreCompInfo Precompute(string name, IPreCompCallback callback) + { + IDictionary<string, PreCompInfo> table; + lock (this) + { + table = m_preCompTable; + if (null == table) + { + m_preCompTable = table = new Dictionary<string, PreCompInfo>(); + } + } + + lock (table) + { + PreCompInfo existing = table.TryGetValue(name, out var preCompInfo) ? preCompInfo : null; + PreCompInfo result = callback.Precompute(existing); + + if (result != existing) + { + table[name] = result; + } + + return result; + } + } + /** * Compute a <code>PreCompInfo</code> for a point on this curve, under a given name. Used by * <code>ECMultiplier</code>s to save the precomputation for this <code>ECPoint</code> for use @@ -929,13 +957,6 @@ namespace Org.BouncyCastle.Math.EC return new LongArray(x).ModInverse(m, ks).ToBigInteger(); } - /** - * The auxiliary values <code>s<sub>0</sub></code> and - * <code>s<sub>1</sub></code> used for partial modular reduction for - * Koblitz curves. - */ - private BigInteger[] si = null; - private static IFiniteField BuildField(int m, int k1, int k2, int k3) { int[] exponents = (k2 | k3) == 0 @@ -1102,26 +1123,6 @@ namespace Org.BouncyCastle.Math.EC } /** - * @return the auxiliary values <code>s<sub>0</sub></code> and - * <code>s<sub>1</sub></code> used for partial modular reduction for - * Koblitz curves. - */ - internal virtual BigInteger[] GetSi() - { - if (si == null) - { - lock (this) - { - if (si == null) - { - si = Tnaf.GetSi(this); - } - } - } - return si; - } - - /** * Returns true if this is a Koblitz curve (ABC curve). * @return true if this is a Koblitz curve (ABC curve), false otherwise */ |