summary refs log tree commit diff
path: root/crypto/src/math/raw
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-04 19:44:44 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-04 19:44:44 +0700
commit286b626903b2e3de5610b6cdff9ec196fcf2244e (patch)
treed1200531c206693630dc7edd0182cdee2342ecc4 /crypto/src/math/raw
parentAvoid some allocations around MPInteger (diff)
downloadBouncyCastle.NET-ed25519-286b626903b2e3de5610b6cdff9ec196fcf2244e.tar.xz
Span-based variants for XDH/EdDSA
Diffstat (limited to 'crypto/src/math/raw')
-rw-r--r--crypto/src/math/raw/Nat.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs

index 8e5b7a04c..469d16d55 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs
@@ -234,6 +234,22 @@ namespace Org.BouncyCastle.Math.Raw return (uint)c; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static uint CAdd(int len, int mask, ReadOnlySpan<uint> x, ReadOnlySpan<uint> y, Span<uint> z) + { + uint MASK = (uint)-(mask & 1); + + ulong c = 0; + for (int i = 0; i < len; ++i) + { + c += (ulong)x[i] + (y[i] & MASK); + z[i] = (uint)c; + c >>= 32; + } + return (uint)c; + } +#endif + public static void CMov(int len, int mask, uint[] x, int xOff, uint[] z, int zOff) { uint MASK = (uint)-(mask & 1); @@ -839,6 +855,20 @@ namespace Org.BouncyCastle.Math.Raw return c << 31; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static uint ShiftDownBit(int len, Span<uint> z, uint c) + { + int i = len; + while (--i >= 0) + { + uint next = z[i]; + z[i] = (next >> 1) | (c << 31); + c = next; + } + return c << 31; + } +#endif + public static uint ShiftDownBit(int len, uint[] z, int zOff, uint c) { int i = len;