diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-05 20:46:11 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-05 20:46:11 +0700 |
commit | 4847ed617571b3d3a146b3656e0189aa8f134fb1 (patch) | |
tree | 891be3998bdee0f2ae41de279b7e0a7e41a404a6 /crypto/src/math/raw/Nat.cs | |
parent | Various span usages (diff) | |
download | BouncyCastle.NET-ed25519-4847ed617571b3d3a146b3656e0189aa8f134fb1.tar.xz |
Span-bases variants for Mod methods
Diffstat (limited to '')
-rw-r--r-- | crypto/src/math/raw/Nat.cs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs index 469d16d55..4065c82c2 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs @@ -599,6 +599,21 @@ namespace Org.BouncyCastle.Math.Raw return true; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static bool Gte(int len, ReadOnlySpan<uint> x, ReadOnlySpan<uint> y) + { + for (int i = len - 1; i >= 0; --i) + { + uint x_i = x[i], y_i = y[i]; + if (x_i < y_i) + return false; + if (x_i > y_i) + return true; + } + return true; + } +#endif + public static uint Inc(int len, uint[] z) { for (int i = 0; i < len; ++i) @@ -714,6 +729,20 @@ namespace Org.BouncyCastle.Math.Raw return (int)c; } +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static int LessThan(int len, ReadOnlySpan<uint> x, ReadOnlySpan<uint> y) + { + long c = 0; + for (int i = 0; i < len; ++i) + { + c += (long)x[i] - y[i]; + c >>= 32; + } + Debug.Assert(c == 0L || c == -1L); + return (int)c; + } +#endif + public static void Mul(int len, uint[] x, uint[] y, uint[] zz) { zz[len] = MulWord(len, x[0], y, zz); |