diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-21 16:11:20 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-10-21 16:11:20 +0700 |
commit | d4c97933bee0ff57427c76bc99e5c6be46a1c65e (patch) | |
tree | fac63b2c4326e15304f32ac55aca39f5488edb4d /crypto/src/math/raw/Nat.cs | |
parent | Unroll ShiftUp methods (diff) | |
download | BouncyCastle.NET-ed25519-d4c97933bee0ff57427c76bc99e5c6be46a1c65e.tar.xz |
Add Xor methods to Nat classes
Diffstat (limited to 'crypto/src/math/raw/Nat.cs')
-rw-r--r-- | crypto/src/math/raw/Nat.cs | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs index 71c794197..89b6881d3 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs @@ -2640,6 +2640,110 @@ namespace Org.BouncyCastle.Math.Raw } #endif + public static void Xor(int len, uint[] x, uint[] y, uint[] z) + { + for (int i = 0; i < len; ++i) + { + z[i] = x[i] ^ y[i]; + } + } + + public static void Xor(int len, uint[] x, int xOff, uint[] y, int yOff, uint[] z, int zOff) + { + for (int i = 0; i < len; ++i) + { + z[zOff + i] = x[xOff + i] ^ y[yOff + i]; + } + } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static void Xor(int len, ReadOnlySpan<uint> x, ReadOnlySpan<uint> y, Span<uint> z) + { + for (int i = 0; i < len; ++i) + { + z[i] = x[i] ^ y[i]; + } + } +#endif + + public static void Xor64(int len, ulong[] x, ulong[] y, ulong[] z) + { + for (int i = 0; i < len; ++i) + { + z[i] = x[i] ^ y[i]; + } + } + + public static void Xor64(int len, ulong[] x, int xOff, ulong[] y, int yOff, ulong[] z, int zOff) + { + for (int i = 0; i < len; ++i) + { + z[zOff + i] = x[xOff + i] ^ y[yOff + i]; + } + } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static void Xor64(int len, ReadOnlySpan<ulong> x, ReadOnlySpan<ulong> y, Span<ulong> z) + { + for (int i = 0; i < len; ++i) + { + z[i] = x[i] ^ y[i]; + } + } +#endif + + public static void XorTo(int len, uint[] x, uint[] z) + { + for (int i = 0; i < len; ++i) + { + z[i] ^= x[i]; + } + } + + public static void XorTo(int len, uint[] x, int xOff, uint[] z, int zOff) + { + for (int i = 0; i < len; ++i) + { + z[zOff + i] ^= x[xOff + i]; + } + } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static void XorTo(int len, ReadOnlySpan<uint> x, Span<uint> z) + { + for (int i = 0; i < len; ++i) + { + z[i] ^= x[i]; + } + } +#endif + + public static void XorTo64(int len, ulong[] x, ulong[] z) + { + for (int i = 0; i < len; ++i) + { + z[i] ^= x[i]; + } + } + + public static void XorTo64(int len, ulong[] x, int xOff, ulong[] z, int zOff) + { + for (int i = 0; i < len; ++i) + { + z[zOff + i] ^= x[xOff + i]; + } + } + +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static void XorTo64(int len, ReadOnlySpan<ulong> x, Span<ulong> z) + { + for (int i = 0; i < len; ++i) + { + z[i] ^= x[i]; + } + } +#endif + public static void Zero(int len, uint[] z) { #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER |