diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-12-01 00:58:27 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-12-01 00:58:27 +0700 |
commit | f693a6cd892ea8a4747d5cff60ad2051458ad5f5 (patch) | |
tree | c26d517c68bb9969e2eeb099f814b6a6edc8d1a4 /crypto/src/math/raw/Nat.cs | |
parent | sect233r1 perf. opts. (diff) | |
download | BouncyCastle.NET-ed25519-f693a6cd892ea8a4747d5cff60ad2051458ad5f5.tar.xz |
Tnaf perf. opts.
Diffstat (limited to 'crypto/src/math/raw/Nat.cs')
-rw-r--r-- | crypto/src/math/raw/Nat.cs | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs index 4600f247f..fa76f305e 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs @@ -14,7 +14,7 @@ namespace Org.BouncyCastle.Math.Raw public static uint Add(int len, uint[] x, uint[] y, uint[] z) { - ulong c = 0; + ulong c = 0UL; for (int i = 0; i < len; ++i) { c += (ulong)x[i] + y[i]; @@ -27,7 +27,7 @@ namespace Org.BouncyCastle.Math.Raw #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER public static uint Add(int len, ReadOnlySpan<uint> x, ReadOnlySpan<uint> y, Span<uint> z) { - ulong c = 0; + ulong c = 0UL; for (int i = 0; i < len; ++i) { c += (ulong)x[i] + y[i]; @@ -1398,6 +1398,32 @@ namespace Org.BouncyCastle.Math.Raw } #endif + public static int Negate(int len, uint[] x, uint[] z) + { + long c = 0L; + for (int i = 0; i < len; ++i) + { + c -= x[i]; + z[i] = (uint)c; + c >>= 32; + } + return (int)c; + } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static int Negate(int len, ReadOnlySpan<uint> x, Span<uint> z) + { + long c = 0L; + for (int i = 0; i < len; ++i) + { + c -= x[i]; + z[i] = (uint)c; + c >>= 32; + } + return (int)c; + } +#endif + public static uint ShiftDownBit(int len, uint[] z, uint c) { int i = len; @@ -2610,6 +2636,25 @@ namespace Org.BouncyCastle.Math.Raw } #endif +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static int SubInt32From(int len, int x, Span<uint> z) + { + long c = (long)z[0] - x; + z[0] = (uint)c; + c >>= 32; + + int i = 1; + while (c != 0L && i < len) + { + c += z[i]; + z[i++] = (uint)c; + c >>= 32; + } + + return (int)c; + } +#endif + public static int SubWordAt(int len, uint x, uint[] z, int zPos) { Debug.Assert(zPos <= (len - 1)); |