summary refs log tree commit diff
path: root/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-07 20:05:14 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-07 20:05:14 +0700
commit782382c6f665a022effa71a3f7738cf1e09d9866 (patch)
tree66311deab21b35bc671561cbb419a0122c1b14f5 /crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
parentFix exception type (diff)
downloadBouncyCastle.NET-ed25519-782382c6f665a022effa71a3f7738cf1e09d9866.tar.xz
Span usage in Math.Raw
Diffstat (limited to 'crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs')
-rw-r--r--crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs15
1 files changed, 11 insertions, 4 deletions
diff --git a/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs b/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
index 37e5b5c29..6449e1d8b 100644
--- a/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
+++ b/crypto/src/math/ec/multiplier/FixedPointCombMultiplier.cs
@@ -28,18 +28,25 @@ namespace Org.BouncyCastle.Math.EC.Multiplier
             int width = info.Width;
 
             int d = (size + width - 1) / width;
+            int fullComb = d * width;
 
             ECPoint R = c.Infinity;
 
-            int fullComb = d * width;
+#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];
+            Nat.FromBigInteger(fullComb, k, K);
+#else
             uint[] K = Nat.FromBigInteger(fullComb, k);
+#endif
 
-            int top = fullComb - 1;
-            for (int i = 0; i < d; ++i)
+            for (int i = 1; i <= d; ++i)
             {
                 uint secretIndex = 0;
 
-                for (int j = top - i; j >= 0; j -= d)
+                for (int j = fullComb - i; j >= 0; j -= d)
                 {
                     uint secretBit = K[j >> 5] >> (j & 0x1F);
                     secretIndex ^= secretBit >> 1;