From 91ceccf8c48e56aea7cdf531dbf49a209f0366a1 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 6 Dec 2023 21:43:08 +0700 Subject: Refactoring in Math.Raw.Nat --- crypto/src/math/raw/Nat.cs | 48 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs index 80ea6d7ce..b524750d8 100644 --- a/crypto/src/math/raw/Nat.cs +++ b/crypto/src/math/raw/Nat.cs @@ -743,7 +743,11 @@ namespace Org.BouncyCastle.Math.Raw } #endif +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static uint EqualTo(int len, ReadOnlySpan x, uint y) +#else public static uint EqualTo(int len, uint[] x, uint y) +#endif { uint d = x[0] ^ y; for (int i = 1; i < len; ++i) @@ -766,19 +770,10 @@ namespace Org.BouncyCastle.Math.Raw } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public static uint EqualTo(int len, ReadOnlySpan x, uint y) - { - uint d = x[0] ^ y; - for (int i = 1; i < len; ++i) - { - d |= x[i]; - } - d = (d >> 1) | (d & 1); - return (uint)(((int)d - 1) >> 31); - } -#endif - + public static uint EqualTo(int len, ReadOnlySpan x, ReadOnlySpan y) +#else public static uint EqualTo(int len, uint[] x, uint[] y) +#endif { uint d = 0; for (int i = 0; i < len; ++i) @@ -800,20 +795,12 @@ namespace Org.BouncyCastle.Math.Raw return (uint)(((int)d - 1) >> 31); } -#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public static uint EqualTo(int len, ReadOnlySpan x, ReadOnlySpan y) - { - uint d = 0; - for (int i = 0; i < len; ++i) - { - d |= x[i] ^ y[i]; - } - d = (d >> 1) | (d & 1); - return (uint)(((int)d - 1) >> 31); - } -#endif +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + public static uint EqualToZero(int len, ReadOnlySpan x) +#else public static uint EqualToZero(int len, uint[] x) +#endif { uint d = 0; for (int i = 0; i < len; ++i) @@ -835,19 +822,6 @@ namespace Org.BouncyCastle.Math.Raw return (uint)(((int)d - 1) >> 31); } -#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public static uint EqualToZero(int len, ReadOnlySpan x) - { - uint d = 0; - for (int i = 0; i < len; ++i) - { - d |= x[i]; - } - d = (d >> 1) | (d & 1); - return (uint)(((int)d - 1) >> 31); - } -#endif - public static uint[] FromBigInteger(int bits, BigInteger x) { if (x.SignValue < 0 || x.BitLength > bits) -- cgit 1.4.1