diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-11-06 17:25:12 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-11-06 17:25:12 +0700 |
commit | df651f2abe8711de81ffb4d7e0fddee36a298e70 (patch) | |
tree | 666aba534a9373a76489d48eccc5557d4eb4406b /crypto/src/math/ec/rfc7748/X25519Field.cs | |
parent | Refactoring in tests (diff) | |
download | BouncyCastle.NET-ed25519-df651f2abe8711de81ffb4d7e0fddee36a298e70.tar.xz |
Create indirection layer for intrinsics support
Diffstat (limited to 'crypto/src/math/ec/rfc7748/X25519Field.cs')
-rw-r--r-- | crypto/src/math/ec/rfc7748/X25519Field.cs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/crypto/src/math/ec/rfc7748/X25519Field.cs b/crypto/src/math/ec/rfc7748/X25519Field.cs index 47bca9935..ffe468f73 100644 --- a/crypto/src/math/ec/rfc7748/X25519Field.cs +++ b/crypto/src/math/ec/rfc7748/X25519Field.cs @@ -35,7 +35,8 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748 public static void Add(int[] x, int[] y, int[] z) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector256<int>>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPackedLittleEndian) { var X = MemoryMarshal.AsBytes(x.AsSpan(0, 8)); var Y = MemoryMarshal.AsBytes(y.AsSpan(0, 8)); @@ -54,7 +55,8 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748 return; } - if (Sse2.IsSupported && BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector128<int>>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPackedLittleEndian) { var X = MemoryMarshal.AsBytes(x.AsSpan(0, 8)); var Y = MemoryMarshal.AsBytes(y.AsSpan(0, 8)); @@ -105,7 +107,8 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748 public static void Apm(int[] x, int[] y, int[] zp, int[] zm) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector256<int>>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPackedLittleEndian) { var X = MemoryMarshal.AsBytes(x.AsSpan(0, 8)); var Y = MemoryMarshal.AsBytes(y.AsSpan(0, 8)); @@ -132,7 +135,8 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748 return; } - if (Sse2.IsSupported && BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector128<int>>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPackedLittleEndian) { var X = MemoryMarshal.AsBytes(x.AsSpan(0, 8)); var Y = MemoryMarshal.AsBytes(y.AsSpan(0, 8)); @@ -1101,7 +1105,8 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748 public static void Sub(int[] x, int[] y, int[] z) { #if NETCOREAPP3_0_OR_GREATER - if (Avx2.IsSupported && BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector256<int>>() == 32) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Avx2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPackedLittleEndian) { var X = MemoryMarshal.AsBytes(x.AsSpan(0, 8)); var Y = MemoryMarshal.AsBytes(y.AsSpan(0, 8)); @@ -1120,7 +1125,8 @@ namespace Org.BouncyCastle.Math.EC.Rfc7748 return; } - if (Sse2.IsSupported && BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector128<int>>() == 16) + if (Org.BouncyCastle.Runtime.Intrinsics.X86.Sse2.IsEnabled && + Org.BouncyCastle.Runtime.Intrinsics.Vector.IsPackedLittleEndian) { var X = MemoryMarshal.AsBytes(x.AsSpan(0, 8)); var Y = MemoryMarshal.AsBytes(y.AsSpan(0, 8)); |