summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-12-06 21:43:08 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-12-06 21:43:08 +0700
commit91ceccf8c48e56aea7cdf531dbf49a209f0366a1 (patch)
tree02cac76ce1b35092c71268f894bdab279ae78cb0
parentRefactoring around Math.Raw.Mod (diff)
downloadBouncyCastle.NET-ed25519-91ceccf8c48e56aea7cdf531dbf49a209f0366a1.tar.xz
Refactoring in Math.Raw.Nat
-rw-r--r--crypto/src/math/raw/Nat.cs48
1 files 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<uint> 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<uint> 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<uint> x, ReadOnlySpan<uint> 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<uint> x, ReadOnlySpan<uint> 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<uint> 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<uint> 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)