diff options
Diffstat (limited to 'crypto/src/math/ec')
-rw-r--r-- | crypto/src/math/ec/ECAlgorithms.cs | 19 | ||||
-rw-r--r-- | crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs | 13 |
2 files changed, 21 insertions, 11 deletions
diff --git a/crypto/src/math/ec/ECAlgorithms.cs b/crypto/src/math/ec/ECAlgorithms.cs index 3059ca3b3..15204e4ed 100644 --- a/crypto/src/math/ec/ECAlgorithms.cs +++ b/crypto/src/math/ec/ECAlgorithms.cs @@ -569,14 +569,25 @@ namespace Org.BouncyCastle.Math.EC } int width = widthP; - int d = (combSize + width - 1) / width; - - ECPoint R = c.Infinity; - int fullComb = d * width; + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + int len = Nat.GetLengthForBits(fullComb); + Span<uint> K = len <= 64 + ? stackalloc uint[len] + : new uint[len]; + Nat.FromBigInteger(fullComb, k, K); + Span<uint> L = len <= 64 + ? stackalloc uint[len] + : new uint[len]; + Nat.FromBigInteger(fullComb, l, L); +#else uint[] K = Nat.FromBigInteger(fullComb, k); uint[] L = Nat.FromBigInteger(fullComb, l); +#endif + + ECPoint R = c.Infinity; int top = fullComb - 1; for (int i = 0; i < d; ++i) diff --git a/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs b/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs index 6449e1d8b..049c36f11 100644 --- a/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs +++ b/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs @@ -26,22 +26,21 @@ namespace Org.BouncyCastle.Math.EC.Multiplier FixedPointPreCompInfo info = FixedPointUtilities.Precompute(p); ECLookupTable lookupTable = info.LookupTable; int width = info.Width; - int d = (size + width - 1) / width; int fullComb = d * width; - ECPoint R = c.Infinity; - #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - int KLen = Nat.GetLengthForBits(fullComb); - Span<uint> K = KLen <= 32 - ? stackalloc uint[KLen] - : new uint[KLen]; + int len = Nat.GetLengthForBits(fullComb); + Span<uint> K = len <= 64 + ? stackalloc uint[len] + : new uint[len]; Nat.FromBigInteger(fullComb, k, K); #else uint[] K = Nat.FromBigInteger(fullComb, k); #endif + ECPoint R = c.Infinity; + for (int i = 1; i <= d; ++i) { uint secretIndex = 0; |