summary refs log tree commit diff
path: root/crypto/src/math/ec/custom/sec/SecT113Field.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-12-28 14:59:52 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-12-28 14:59:52 +0700
commit125e93ac90fab535316f55695f14dde8e9c76c97 (patch)
tree2dff432202163117d5012448b977c87c6f44a218 /crypto/src/math/ec/custom/sec/SecT113Field.cs
parentXML doc for TlsClient.ClientHelloRecordLayerVersion (diff)
downloadBouncyCastle.NET-ed25519-125e93ac90fab535316f55695f14dde8e9c76c97.tar.xz
Optimized Sqrt and Trace for custom binary curves
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecT113Field.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecT113Field.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecT113Field.cs b/crypto/src/math/ec/custom/sec/SecT113Field.cs
index 640c6e787..49773b66d 100644
--- a/crypto/src/math/ec/custom/sec/SecT113Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT113Field.cs
@@ -102,6 +102,16 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             z[zOff + 1]  = z1 & M49;
         }
 
+        public static void Sqrt(ulong[] x, ulong[] z)
+        {
+            ulong u0 = Interleave.Unshuffle(x[0]), u1 = Interleave.Unshuffle(x[1]);
+            ulong e0 = (u0 & 0x00000000FFFFFFFFUL) | (u1 << 32);
+            ulong c0  = (u0 >> 32) | (u1 & 0xFFFFFFFF00000000UL);
+
+            z[0] = e0 ^ (c0 << 57) ^ (c0 <<  5);
+            z[1] =      (c0 >>  7) ^ (c0 >> 59); 
+        }
+
         public static void Square(ulong[] x, ulong[] z)
         {
             ulong[] tt = Nat128.CreateExt64();
@@ -131,6 +141,12 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             }
         }
 
+        public static uint Trace(ulong[] x)
+        {
+            // Non-zero-trace bits: 0
+            return (uint)(x[0]) & 1U;
+        }
+
         protected static void ImplMultiply(ulong[] x, ulong[] y, ulong[] zz)
         {
             /*