summary refs log tree commit diff
path: root/crypto/src/math/raw
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-08-22 16:16:21 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-08-22 16:16:21 +0700
commitc3c24f0b1cf7342922e76ca8bad6065ab38262c4 (patch)
tree893326f04d4f264728b7aed41f9c99829b7b36a9 /crypto/src/math/raw
parentComment an alternative unoptimized impl for ScalarMultBase (diff)
downloadBouncyCastle.NET-ed25519-c3c24f0b1cf7342922e76ca8bad6065ab38262c4.tar.xz
Ed25519 refactoring
Diffstat (limited to 'crypto/src/math/raw')
-rw-r--r--crypto/src/math/raw/Nat.cs30
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto/src/math/raw/Nat.cs b/crypto/src/math/raw/Nat.cs
index d748e04c5..0f53b1a8b 100644
--- a/crypto/src/math/raw/Nat.cs
+++ b/crypto/src/math/raw/Nat.cs
@@ -400,6 +400,36 @@ namespace Org.BouncyCastle.Math.Raw
         }
 #endif
 
+        public static uint CAddTo(int len, int mask, uint[] x, uint[] z)
+        {
+            uint MASK = (uint)-(mask & 1);
+
+            ulong c = 0;
+            for (int i = 0; i < len; ++i)
+            {
+                c += (ulong)z[i] + (x[i] & MASK);
+                z[i] = (uint)c;
+                c >>= 32;
+            }
+            return (uint)c;
+        }
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public static uint CAddTo(int len, int mask, ReadOnlySpan<uint> x, Span<uint> z)
+        {
+            uint MASK = (uint)-(mask & 1);
+
+            ulong c = 0;
+            for (int i = 0; i < len; ++i)
+            {
+                c += (ulong)z[i] + (x[i] & MASK);
+                z[i] = (uint)c;
+                c >>= 32;
+            }
+            return (uint)c;
+        }
+#endif
+
         public static void CMov(int len, int mask, uint[] x, int xOff, uint[] z, int zOff)
         {
             uint MASK = (uint)-(mask & 1);