summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-10-24 16:04:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-10-24 16:04:27 +0700
commit0852874c0f212c00c74fa3292b92dfb557993842 (patch)
tree1986c8f8503c3e14fe69d708afd73348e83f3a28
parentUse platform compression where available (diff)
downloadBouncyCastle.NET-ed25519-0852874c0f212c00c74fa3292b92dfb557993842.tar.xz
Use MemoryMarshal.AsBytes
-rw-r--r--crypto/src/crypto/engines/ChaCha7539Engine.cs2
-rw-r--r--crypto/src/crypto/engines/ChaChaEngine.cs2
-rw-r--r--crypto/src/crypto/engines/Salsa20Engine.cs4
-rw-r--r--crypto/src/math/raw/Nat256.cs12
-rw-r--r--crypto/src/math/raw/Nat512.cs12
-rw-r--r--crypto/src/pqc/crypto/hqc/GF2PolynomialCalculator.cs2
6 files changed, 17 insertions, 17 deletions
diff --git a/crypto/src/crypto/engines/ChaCha7539Engine.cs b/crypto/src/crypto/engines/ChaCha7539Engine.cs
index e3b645c4b..d9cdac541 100644
--- a/crypto/src/crypto/engines/ChaCha7539Engine.cs
+++ b/crypto/src/crypto/engines/ChaCha7539Engine.cs
@@ -468,7 +468,7 @@ namespace Org.BouncyCastle.Crypto.Engines
 		private static Vector128<uint> Load128_UInt32(ReadOnlySpan<uint> t)
 		{
 			if (BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector128<uint>>() == 16)
-                return MemoryMarshal.Read<Vector128<uint>>(MemoryMarshal.Cast<uint, byte>(t));
+                return MemoryMarshal.Read<Vector128<uint>>(MemoryMarshal.AsBytes(t));
 
 			return Vector128.Create(t[0], t[1], t[2], t[3]);
 		}
diff --git a/crypto/src/crypto/engines/ChaChaEngine.cs b/crypto/src/crypto/engines/ChaChaEngine.cs
index bf2bf6300..093e1a250 100644
--- a/crypto/src/crypto/engines/ChaChaEngine.cs
+++ b/crypto/src/crypto/engines/ChaChaEngine.cs
@@ -218,7 +218,7 @@ namespace Org.BouncyCastle.Crypto.Engines
 		private static Vector128<uint> Load128_UInt32(ReadOnlySpan<uint> t)
 		{
             if (BitConverter.IsLittleEndian && Unsafe.SizeOf<Vector128<uint>>() == 16)
-                return MemoryMarshal.Read<Vector128<uint>>(MemoryMarshal.Cast<uint, byte>(t));
+                return MemoryMarshal.Read<Vector128<uint>>(MemoryMarshal.AsBytes(t));
 
             return Vector128.Create(t[0], t[1], t[2], t[3]);
 		}
diff --git a/crypto/src/crypto/engines/Salsa20Engine.cs b/crypto/src/crypto/engines/Salsa20Engine.cs
index fa5477ed5..1ccf68902 100644
--- a/crypto/src/crypto/engines/Salsa20Engine.cs
+++ b/crypto/src/crypto/engines/Salsa20Engine.cs
@@ -266,7 +266,7 @@ namespace Org.BouncyCastle.Crypto.Engines
 			{
 				Vector128<uint> b0, b1, b2, b3;
 				{
-                    var I = MemoryMarshal.Cast<uint, byte>(input.AsSpan(0, 16));
+                    var I = MemoryMarshal.AsBytes(input.AsSpan(0, 16));
 					var t0 = MemoryMarshal.Read<Vector128<short>>(I[0x00..0x10]);
                     var t1 = MemoryMarshal.Read<Vector128<short>>(I[0x10..0x20]);
                     var t2 = MemoryMarshal.Read<Vector128<short>>(I[0x20..0x30]);
@@ -315,7 +315,7 @@ namespace Org.BouncyCastle.Crypto.Engines
                     var v2 = Sse41.Blend(u0, u2, 0x0F);
                     var v3 = Sse41.Blend(u1, u3, 0x3C);
 
-                    var X = MemoryMarshal.Cast<uint, byte>(x.AsSpan(0, 16));
+                    var X = MemoryMarshal.AsBytes(x.AsSpan(0, 16));
                     MemoryMarshal.Write(X[0x00..0x10], ref v0);
                     MemoryMarshal.Write(X[0x10..0x20], ref v1);
                     MemoryMarshal.Write(X[0x20..0x30], ref v2);
diff --git a/crypto/src/math/raw/Nat256.cs b/crypto/src/math/raw/Nat256.cs
index 086ba53b1..47e0644f6 100644
--- a/crypto/src/math/raw/Nat256.cs
+++ b/crypto/src/math/raw/Nat256.cs
@@ -1391,9 +1391,9 @@ namespace Org.BouncyCastle.Math.Raw
 #if NETCOREAPP3_0_OR_GREATER
             if (Avx2.IsSupported && Unsafe.SizeOf<Vector256<byte>>() == 32)
             {
-                var X = MemoryMarshal.Cast<uint, byte>(x[..8]);
-                var Y = MemoryMarshal.Cast<uint, byte>(y[..8]);
-                var Z = MemoryMarshal.Cast<uint, byte>(z[..8]);
+                var X = MemoryMarshal.AsBytes(x[..8]);
+                var Y = MemoryMarshal.AsBytes(y[..8]);
+                var Z = MemoryMarshal.AsBytes(z[..8]);
 
                 var X0 = MemoryMarshal.Read<Vector256<byte>>(X[0x00..0x20]);
                 var Y0 = MemoryMarshal.Read<Vector256<byte>>(Y[0x00..0x20]);
@@ -1406,9 +1406,9 @@ namespace Org.BouncyCastle.Math.Raw
 
             if (Sse2.IsSupported && Unsafe.SizeOf<Vector128<byte>>() == 16)
             {
-                var X = MemoryMarshal.Cast<uint, byte>(x[..8]);
-                var Y = MemoryMarshal.Cast<uint, byte>(y[..8]);
-                var Z = MemoryMarshal.Cast<uint, byte>(z[..8]);
+                var X = MemoryMarshal.AsBytes(x[..8]);
+                var Y = MemoryMarshal.AsBytes(y[..8]);
+                var Z = MemoryMarshal.AsBytes(z[..8]);
 
                 var X0 = MemoryMarshal.Read<Vector128<byte>>(X[0x00..0x10]);
                 var X1 = MemoryMarshal.Read<Vector128<byte>>(X[0x10..0x20]);
diff --git a/crypto/src/math/raw/Nat512.cs b/crypto/src/math/raw/Nat512.cs
index 37cf0b6ff..d94ae40da 100644
--- a/crypto/src/math/raw/Nat512.cs
+++ b/crypto/src/math/raw/Nat512.cs
@@ -69,9 +69,9 @@ namespace Org.BouncyCastle.Math.Raw
 #if NETCOREAPP3_0_OR_GREATER
             if (Avx2.IsSupported && Unsafe.SizeOf<Vector256<byte>>() == 32)
             {
-                var X = MemoryMarshal.Cast<uint, byte>(x[..16]);
-                var Y = MemoryMarshal.Cast<uint, byte>(y[..16]);
-                var Z = MemoryMarshal.Cast<uint, byte>(z[..16]);
+                var X = MemoryMarshal.AsBytes(x[..16]);
+                var Y = MemoryMarshal.AsBytes(y[..16]);
+                var Z = MemoryMarshal.AsBytes(z[..16]);
 
                 var X0 = MemoryMarshal.Read<Vector256<byte>>(X[0x00..0x20]);
                 var X1 = MemoryMarshal.Read<Vector256<byte>>(X[0x20..0x40]);
@@ -89,9 +89,9 @@ namespace Org.BouncyCastle.Math.Raw
 
             if (Sse2.IsSupported && Unsafe.SizeOf<Vector128<byte>>() == 16)
             {
-                var X = MemoryMarshal.Cast<uint, byte>(x[..16]);
-                var Y = MemoryMarshal.Cast<uint, byte>(y[..16]);
-                var Z = MemoryMarshal.Cast<uint, byte>(z[..16]);
+                var X = MemoryMarshal.AsBytes(x[..16]);
+                var Y = MemoryMarshal.AsBytes(y[..16]);
+                var Z = MemoryMarshal.AsBytes(z[..16]);
 
                 var X0 = MemoryMarshal.Read<Vector128<byte>>(X[0x00..0x10]);
                 var X1 = MemoryMarshal.Read<Vector128<byte>>(X[0x10..0x20]);
diff --git a/crypto/src/pqc/crypto/hqc/GF2PolynomialCalculator.cs b/crypto/src/pqc/crypto/hqc/GF2PolynomialCalculator.cs
index 8a460932e..0c01ade96 100644
--- a/crypto/src/pqc/crypto/hqc/GF2PolynomialCalculator.cs
+++ b/crypto/src/pqc/crypto/hqc/GF2PolynomialCalculator.cs
@@ -79,7 +79,7 @@ namespace Org.BouncyCastle.Pqc.Crypto.Hqc
             }
 
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-            Span<byte> resBytes = MemoryMarshal.Cast<ulong, byte>(res);
+            Span<byte> resBytes = MemoryMarshal.AsBytes(res.AsSpan());
             for (int i = 0; i < weight; i++)
             {
                 int dec = a[permutedSparseVect[i]] & 0xf;