summary refs log tree commit diff
path: root/crypto/src/math/raw/Nat448.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-26 13:20:35 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-26 13:20:35 +0700
commit4f151774bd05b3855e573accf63a0f8ecfda43ac (patch)
tree89fcf3d1e06b6282e6d470f19cdb07fe7d84064e /crypto/src/math/raw/Nat448.cs
parentCode cleanup (diff)
downloadBouncyCastle.NET-ed25519-4f151774bd05b3855e573accf63a0f8ecfda43ac.tar.xz
Refactoring in Math.EC.Rfc8032
Diffstat (limited to 'crypto/src/math/raw/Nat448.cs')
-rw-r--r--crypto/src/math/raw/Nat448.cs45
1 files changed, 44 insertions, 1 deletions
diff --git a/crypto/src/math/raw/Nat448.cs b/crypto/src/math/raw/Nat448.cs
index 898e33199..5189d8936 100644
--- a/crypto/src/math/raw/Nat448.cs
+++ b/crypto/src/math/raw/Nat448.cs
@@ -98,13 +98,35 @@ namespace Org.BouncyCastle.Math.Raw
             Nat.AddWordAt(28, c21, zz, 21);
         }
 
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public static void Mul(ReadOnlySpan<uint> x, ReadOnlySpan<uint> y, Span<uint> zz)
+        {
+            Nat224.Mul(x, y, zz);
+            Nat224.Mul(x[7..], y[7..], zz[14..]);
+
+            uint c21 = Nat224.AddToEachOther(zz[7..], zz[14..]);
+            uint c14 = c21 + Nat224.AddTo(zz, zz[7..], 0U);
+            c21 += Nat224.AddTo(zz[21..], zz[14..], c14);
+
+            Span<uint> dx = stackalloc uint[7];
+            Span<uint> dy = stackalloc uint[7];
+            bool neg = Nat224.Diff(x[7..], x, dx) != Nat224.Diff(y[7..], y, dy);
+
+            Span<uint> tt = stackalloc uint[14];
+            Nat224.Mul(dx, dy, tt);
+
+            c21 += neg ? Nat.AddTo(14, tt, zz[7..]) : (uint)Nat.SubFrom(14, tt, zz[7..]);
+            Nat.AddWordAt(28, c21, zz, 21);
+        }
+#endif
+
         public static void Square(uint[] x, uint[] zz)
         {
             Nat224.Square(x, zz);
             Nat224.Square(x, 7, zz, 14);
 
             uint c21 = Nat224.AddToEachOther(zz, 7, zz, 14);
-            uint c14 = c21 + Nat224.AddTo(zz, 0, zz, 7, 0);
+            uint c14 = c21 + Nat224.AddTo(zz, 0, zz, 7, 0U);
             c21 += Nat224.AddTo(zz, 21, zz, 14, c14);
 
             uint[] dx = Nat224.Create();
@@ -117,6 +139,27 @@ namespace Org.BouncyCastle.Math.Raw
             Nat.AddWordAt(28, c21, zz, 21);
         }
 
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public static void Square(ReadOnlySpan<uint> x, Span<uint> zz)
+        {
+            Nat224.Square(x, zz);
+            Nat224.Square(x[7..], zz[14..]);
+
+            uint c21 = Nat224.AddToEachOther(zz[7..], zz[14..]);
+            uint c14 = c21 + Nat224.AddTo(zz, zz[7..], 0U);
+            c21 += Nat224.AddTo(zz[21..], zz[14..], c14);
+
+            Span<uint> dx = stackalloc uint[7];
+            Nat224.Diff(x[7..], x, dx);
+
+            Span<uint> tt = stackalloc uint[14];
+            Nat224.Square(dx, tt);
+
+            c21 += (uint)Nat.SubFrom(14, tt, zz[7..]);
+            Nat.AddWordAt(28, c21, zz, 21);
+        }
+#endif
+
         public static BigInteger ToBigInteger64(ulong[] x)
         {
             byte[] bs = new byte[56];