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>2022-08-02 01:22:48 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-08-02 01:22:48 +0700
commit17b0cc528f52df638d1261fb872fea7bf4228c95 (patch)
treee361f6e9d10f85a61a06a5bf134a7a883c25b110 /crypto/src/math/ec/custom/sec/SecT113Field.cs
parentTLS: 'tls-exporter' channel binding (diff)
downloadBouncyCastle.NET-ed25519-17b0cc528f52df638d1261fb872fea7bf4228c95.tar.xz
Use intrinsics in custom binary curves
Diffstat (limited to 'crypto/src/math/ec/custom/sec/SecT113Field.cs')
-rw-r--r--crypto/src/math/ec/custom/sec/SecT113Field.cs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crypto/src/math/ec/custom/sec/SecT113Field.cs b/crypto/src/math/ec/custom/sec/SecT113Field.cs
index c41d9f7d7..1b3fcc542 100644
--- a/crypto/src/math/ec/custom/sec/SecT113Field.cs
+++ b/crypto/src/math/ec/custom/sec/SecT113Field.cs
@@ -1,5 +1,9 @@
 using System;
 using System.Diagnostics;
+#if NETCOREAPP3_0_OR_GREATER
+using System.Runtime.Intrinsics;
+using System.Runtime.Intrinsics.X86;
+#endif
 
 using Org.BouncyCastle.Math.Raw;
 
@@ -202,6 +206,20 @@ namespace Org.BouncyCastle.Math.EC.Custom.Sec
             Debug.Assert(x >> 57 == 0);
             Debug.Assert(y >> 57 == 0);
 
+#if NETCOREAPP3_0_OR_GREATER
+            if (Pclmulqdq.IsSupported)
+            {
+                var X = Vector128.CreateScalar(x);
+                var Y = Vector128.CreateScalar(y);
+                var Z = Pclmulqdq.CarrylessMultiply(X, Y, 0x00);
+                ulong z0 = Z.GetElement(0);
+                ulong z1 = Z.GetElement(1);
+                z[zOff    ] = z0 & M57;
+                z[zOff + 1] = (z0 >> 57) ^ (z1 << 7);
+                return;
+            }
+#endif
+
             //u[0] = 0;
             u[1] = y;
             u[2] = u[1] << 1;