Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/CryptoBase/FastUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,17 @@ public static void Xor16(ReadOnlySpan<byte> stream, ReadOnlySpan<byte> source, S
{
if (Vector128.IsHardwareAccelerated)
{
ref Vector128<byte> v0 = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(stream));
ref Vector128<byte> v1 = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(source));
ref Vector128<byte> dst = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(destination));
ref Vector128<byte> v0 = ref Unsafe.As<byte, Vector128<byte>>(ref stream.GetReference());
ref Vector128<byte> v1 = ref Unsafe.As<byte, Vector128<byte>>(ref source.GetReference());
ref Vector128<byte> dst = ref Unsafe.As<byte, Vector128<byte>>(ref destination.GetReference());

dst = v0 ^ v1;
}
else
{
ref UInt128 v0 = ref Unsafe.As<byte, UInt128>(ref MemoryMarshal.GetReference(stream));
ref UInt128 v1 = ref Unsafe.As<byte, UInt128>(ref MemoryMarshal.GetReference(source));
ref UInt128 dst = ref Unsafe.As<byte, UInt128>(ref MemoryMarshal.GetReference(destination));
ref UInt128 v0 = ref Unsafe.As<byte, UInt128>(ref stream.GetReference());
ref UInt128 v1 = ref Unsafe.As<byte, UInt128>(ref source.GetReference());
ref UInt128 dst = ref Unsafe.As<byte, UInt128>(ref destination.GetReference());

dst = v0 ^ v1;
}
Expand All @@ -229,15 +229,15 @@ public static void Xor16(Span<byte> source, ReadOnlySpan<byte> stream)
{
if (Vector128.IsHardwareAccelerated)
{
ref Vector128<byte> v0 = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(source));
ref Vector128<byte> v1 = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(stream));
ref Vector128<byte> v0 = ref Unsafe.As<byte, Vector128<byte>>(ref source.GetReference());
ref Vector128<byte> v1 = ref Unsafe.As<byte, Vector128<byte>>(ref stream.GetReference());

v0 ^= v1;
}
else
{
ref UInt128 v0 = ref Unsafe.As<byte, UInt128>(ref MemoryMarshal.GetReference(source));
ref UInt128 v1 = ref Unsafe.As<byte, UInt128>(ref MemoryMarshal.GetReference(stream));
ref UInt128 v0 = ref Unsafe.As<byte, UInt128>(ref source.GetReference());
ref UInt128 v1 = ref Unsafe.As<byte, UInt128>(ref stream.GetReference());

v0 ^= v1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/CryptoBase/Macs/GHash/GHashX86.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public GHashX86(scoped ReadOnlySpan<byte> key)
{
ArgumentOutOfRangeException.ThrowIfLessThan(key.Length, KeySize, nameof(key));

ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(key));
ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref key.GetReference());
_key = v.ReverseEndianness128();

Reset();
Expand All @@ -28,7 +28,7 @@ public GHashX86(scoped ReadOnlySpan<byte> key)
private void GFMul(scoped ReadOnlySpan<byte> x)
{
Vector128<ulong> a = _key.AsUInt64();
Vector128<ulong> b = (Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(x)).ReverseEndianness128() ^ _buffer).AsUInt64();
Vector128<ulong> b = (Unsafe.As<byte, Vector128<byte>>(ref x.GetReference()).ReverseEndianness128() ^ _buffer).AsUInt64();

Vector128<uint> tmp3 = Pclmulqdq.CarrylessMultiply(a, b, 0x00).AsUInt32();
Vector128<uint> tmp4 = Pclmulqdq.CarrylessMultiply(a, b, 0x10).AsUInt32();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void UpdateCore(ReadOnlySpan<byte> source, Span<byte> destination)
{
crypto.Encrypt(counter, stream);

ref UInt128 c = ref Unsafe.As<byte, UInt128>(ref MemoryMarshal.GetReference(counter));
ref UInt128 c = ref Unsafe.As<byte, UInt128>(ref counter.GetReference());
c = BinaryPrimitives.ReverseEndianness(BinaryPrimitives.ReverseEndianness(c) + 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CTR128StreamModeBlock16X86(IBlockCrypto crypto, ReadOnlySpan<byte> iv)
_counter = ArrayPool<byte>.Shared.Rent(BlockSize16);
_keyStream = ArrayPool<byte>.Shared.Rent(BlockSize16);

_iCounter = FastUtils.BroadcastVector128ToVector256(ref MemoryMarshal.GetReference(iv)).ReverseEndianness128().IncUpper128Le();
_iCounter = FastUtils.BroadcastVector128ToVector256(ref iv.GetReference()).ReverseEndianness128().IncUpper128Le();

Reset();
}
Expand Down Expand Up @@ -84,7 +84,7 @@ private void UpdateKeyStream()
Vector256<byte> v6 = _counterV6.ReverseEndianness128();
Vector256<byte> v7 = _counterV7.ReverseEndianness128();

ref byte cRef = ref MemoryMarshal.GetReference(c);
ref byte cRef = ref c.GetReference();
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 0 * 2 * BlockSize), v0);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 1 * 2 * BlockSize), v1);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 2 * 2 * BlockSize), v2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CTR128StreamModeBlock4X86(IBlockCrypto crypto, ReadOnlySpan<byte> iv)
_counter = ArrayPool<byte>.Shared.Rent(BlockSize4);
_keyStream = ArrayPool<byte>.Shared.Rent(BlockSize4);

ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(iv));
ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref iv.GetReference());
_iCounter = v.ReverseEndianness128();

Reset();
Expand Down Expand Up @@ -79,7 +79,7 @@ private void UpdateKeyStream()
Vector128<byte> v2 = _counterV2.ReverseEndianness128();
Vector128<byte> v3 = _counterV3.ReverseEndianness128();

ref byte cRef = ref MemoryMarshal.GetReference(c);
ref byte cRef = ref c.GetReference();
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 0 * BlockSize), v0);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 1 * BlockSize), v1);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 2 * BlockSize), v2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CTR128StreamModeBlock8AvxX86(IBlockCrypto crypto, ReadOnlySpan<byte> iv)
_counter = ArrayPool<byte>.Shared.Rent(BlockSize8);
_keyStream = ArrayPool<byte>.Shared.Rent(BlockSize8);

_iCounter = FastUtils.BroadcastVector128ToVector256(ref MemoryMarshal.GetReference(iv)).ReverseEndianness128().IncUpper128Le();
_iCounter = FastUtils.BroadcastVector128ToVector256(ref iv.GetReference()).ReverseEndianness128().IncUpper128Le();

Reset();
}
Expand Down Expand Up @@ -77,7 +77,7 @@ private void UpdateKeyStream()
Vector256<byte> v2 = _counterV2.ReverseEndianness128();
Vector256<byte> v3 = _counterV3.ReverseEndianness128();

ref byte cRef = ref MemoryMarshal.GetReference(c);
ref byte cRef = ref c.GetReference();
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 0 * 2 * BlockSize), v0);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 1 * 2 * BlockSize), v1);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 2 * 2 * BlockSize), v2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public CTR128StreamModeBlock8X86(IBlockCrypto crypto, ReadOnlySpan<byte> iv)
_counter = ArrayPool<byte>.Shared.Rent(BlockSize8);
_keyStream = ArrayPool<byte>.Shared.Rent(BlockSize8);

ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(iv));
ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref iv.GetReference());
_iCounter = v.ReverseEndianness128();

Reset();
Expand Down Expand Up @@ -85,7 +85,7 @@ private void UpdateKeyStream()
Vector128<byte> v6 = _counterV6.ReverseEndianness128();
Vector128<byte> v7 = _counterV7.ReverseEndianness128();

ref byte cRef = ref MemoryMarshal.GetReference(c);
ref byte cRef = ref c.GetReference();
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 0 * BlockSize), v0);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 1 * BlockSize), v1);
Unsafe.WriteUnaligned(ref Unsafe.Add(ref cRef, 2 * BlockSize), v2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CTR128StreamModeX86(IBlockCrypto crypto, ReadOnlySpan<byte> iv)

_internalBlockCrypto = crypto;

ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref MemoryMarshal.GetReference(iv));
ref Vector128<byte> v = ref Unsafe.As<byte, Vector128<byte>>(ref iv.GetReference());
_iCounter = v.ReverseEndianness128();

Reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public XtsMode(IBlockCrypto dataCrypto, IBlockCrypto tweakCrypto, ReadOnlySpan<b

_dataCrypto = dataCrypto;
_tweakCrypto = tweakCrypto;
_iv = Unsafe.ReadUnaligned<Vector128<byte>>(ref MemoryMarshal.GetReference(iv));
_iv = Unsafe.ReadUnaligned<Vector128<byte>>(ref iv.GetReference());
}

[SkipLocalsInit]
Expand Down
4 changes: 2 additions & 2 deletions src/CryptoBase/SymmetricCryptos/BlockCryptos/SM4/SM4Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ public static void Encrypt8(uint[] rk, ReadOnlySpan<byte> source, Span<byte> des

public static void Encrypt16(uint[] rk, ReadOnlySpan<byte> source, Span<byte> destination)
{
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

ref Vector256<byte> s0 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 0 * 32));
ref Vector256<byte> s1 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 1 * 32));
Expand Down
52 changes: 26 additions & 26 deletions src/CryptoBase/SymmetricCryptos/StreamCryptos/ChaCha20Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ private static void QuarterRound(ref Vector256<uint> a, ref Vector256<uint> b, r
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateKeyStream(Span<uint> state, Span<byte> stream, byte rounds)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte streamRef = ref MemoryMarshal.GetReference(stream);
ref uint stateRef = ref state.GetReference();
ref byte streamRef = ref stream.GetReference();

ref Vector128<uint> s0 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 0 * 4));
ref Vector128<uint> s1 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 1 * 4));
Expand Down Expand Up @@ -136,13 +136,13 @@ public static void UpdateKeyStream(Span<uint> state, Span<byte> stream, byte rou
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IncrementCounterOriginal(Span<uint> state)
{
++Unsafe.As<uint, ulong>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 12));
++Unsafe.As<uint, ulong>(ref Unsafe.Add(ref state.GetReference(), 12));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IncrementCounter(Span<uint> state)
{
ref uint counter = ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 12);
ref uint counter = ref Unsafe.Add(ref state.GetReference(), 12);

if (++counter is 0)
{
Expand All @@ -161,7 +161,7 @@ void Throw()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ChaChaRound(Span<uint> state, byte rounds)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref uint stateRef = ref state.GetReference();

ref Vector128<uint> x0 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 0 * 4));
ref Vector128<uint> x1 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 1 * 4));
Expand Down Expand Up @@ -217,9 +217,9 @@ private static void Shuffle1(ref Vector128<uint> a, ref Vector128<uint> b, ref V
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void ChaChaCore64Internal(byte rounds, ReadOnlySpan<uint> state, ReadOnlySpan<byte> source, Span<byte> destination)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte destRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte destRef = ref destination.GetReference();

ref Vector128<uint> s0 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 0 * 4));
ref Vector128<uint> s1 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 1 * 4));
Expand Down Expand Up @@ -286,9 +286,9 @@ public static void ChaChaCore64(byte rounds, Span<uint> state, ReadOnlySpan<byte
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ChaChaCoreOriginal128(byte rounds, Span<uint> state, ReadOnlySpan<byte> source, Span<byte> destination)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte destRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte destRef = ref destination.GetReference();

ref Vector256<byte> src0 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 0 * 32));
ref Vector256<byte> src1 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 1 * 32));
Expand Down Expand Up @@ -338,9 +338,9 @@ public static void ChaChaCoreOriginal128(byte rounds, Span<uint> state, ReadOnly
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ChaChaCore128(byte rounds, Span<uint> state, ReadOnlySpan<byte> source, Span<byte> destination)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte destRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte destRef = ref destination.GetReference();

ref Vector256<byte> src0 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 0 * 32));
ref Vector256<byte> src1 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 1 * 32));
Expand Down Expand Up @@ -401,9 +401,9 @@ public static int ChaChaCoreOriginal256(byte rounds, Span<uint> state, ReadOnlyS
int length = source.Length;
int offset = 0;

ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

Vector128<uint> o0 = Vector128.Create(Unsafe.Add(ref stateRef, 0));
Vector128<uint> o1 = Vector128.Create(Unsafe.Add(ref stateRef, 1));
Expand Down Expand Up @@ -489,9 +489,9 @@ public static int ChaChaCore256(byte rounds, Span<uint> state, ReadOnlySpan<byte
int length = source.Length;
int offset = 0;

ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

Vector128<uint> o0 = Vector128.Create(Unsafe.Add(ref stateRef, 0));
Vector128<uint> o1 = Vector128.Create(Unsafe.Add(ref stateRef, 1));
Expand Down Expand Up @@ -617,9 +617,9 @@ public static int ChaChaCoreOriginal512(byte rounds, Span<uint> state, ReadOnlyS
int length = source.Length;
int offset = 0;

ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

Vector256<uint> o0 = Vector256.Create(Unsafe.Add(ref stateRef, 0));
Vector256<uint> o1 = Vector256.Create(Unsafe.Add(ref stateRef, 1));
Expand Down Expand Up @@ -740,9 +740,9 @@ public static int ChaChaCore512(byte rounds, Span<uint> state, ReadOnlySpan<byte
int length = source.Length;
int offset = 0;

ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

Vector256<uint> o0 = Vector256.Create(Unsafe.Add(ref stateRef, 0));
Vector256<uint> o1 = Vector256.Create(Unsafe.Add(ref stateRef, 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public abstract class Salsa20Crypto : SnuffleCrypto

protected override void IncrementCounter(Span<uint> state)
{
++Unsafe.As<uint, ulong>(ref Unsafe.Add(ref MemoryMarshal.GetReference(state), 8));
++Unsafe.As<uint, ulong>(ref Unsafe.Add(ref state.GetReference(), 8));
}
}
30 changes: 15 additions & 15 deletions src/CryptoBase/SymmetricCryptos/StreamCryptos/Salsa20Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private static void QuarterRound(ref Vector256<uint> a, ref Vector256<uint> b, r
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UpdateKeyStream(Span<uint> state, Span<byte> stream, byte rounds)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte streamRef = ref MemoryMarshal.GetReference(stream);
ref uint stateRef = ref state.GetReference();
ref byte streamRef = ref stream.GetReference();

Vector128<uint> x0 = Vector128.Create(Unsafe.Add(ref stateRef, 4), Unsafe.Add(ref stateRef, 9), Unsafe.Add(ref stateRef, 14), Unsafe.Add(ref stateRef, 3));// 4 9 14 3
Vector128<uint> x1 = Vector128.Create(Unsafe.Add(ref stateRef, 0), Unsafe.Add(ref stateRef, 5), Unsafe.Add(ref stateRef, 10), Unsafe.Add(ref stateRef, 15));// 0 5 10 15
Expand Down Expand Up @@ -123,7 +123,7 @@ public static void UpdateKeyStream(Span<uint> state, Span<byte> stream, byte rou
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SalsaRound(Span<uint> state, byte rounds)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref uint stateRef = ref state.GetReference();

Vector128<uint> x0 = Vector128.Create(Unsafe.Add(ref stateRef, 4), Unsafe.Add(ref stateRef, 9), Unsafe.Add(ref stateRef, 14), Unsafe.Add(ref stateRef, 3));// 4 9 14 3
Vector128<uint> x1 = Vector128.Create(Unsafe.Add(ref stateRef, 0), Unsafe.Add(ref stateRef, 5), Unsafe.Add(ref stateRef, 10), Unsafe.Add(ref stateRef, 15));// 0 5 10 15
Expand Down Expand Up @@ -309,9 +309,9 @@ private static void Shuffle(ref Vector256<uint> a, ref Vector256<uint> b, ref Ve
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SalsaCore64(byte rounds, Span<uint> state, ReadOnlySpan<byte> source, Span<byte> destination)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte destRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte destRef = ref destination.GetReference();

ref Vector128<uint> s0 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 0 * 4));
ref Vector128<uint> s1 = ref Unsafe.As<uint, Vector128<uint>>(ref Unsafe.Add(ref stateRef, 1 * 4));
Expand Down Expand Up @@ -363,9 +363,9 @@ public static void SalsaCore64(byte rounds, Span<uint> state, ReadOnlySpan<byte>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SalsaCore128(byte rounds, Span<uint> state, ReadOnlySpan<byte> source, Span<byte> destination)
{
ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte destRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte destRef = ref destination.GetReference();

ref Vector256<byte> src0 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 0 * 32));
ref Vector256<byte> src1 = ref Unsafe.As<byte, Vector256<byte>>(ref Unsafe.Add(ref sourceRef, 1 * 32));
Expand Down Expand Up @@ -461,9 +461,9 @@ public static int SalsaCore256(byte rounds, Span<uint> state, ReadOnlySpan<byte>
int length = source.Length;
int offset = 0;

ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

#region s

Expand Down Expand Up @@ -563,9 +563,9 @@ public static int SalsaCore512(byte rounds, Span<uint> state, ReadOnlySpan<byte>
int length = source.Length;
int offset = 0;

ref uint stateRef = ref MemoryMarshal.GetReference(state);
ref byte sourceRef = ref MemoryMarshal.GetReference(source);
ref byte dstRef = ref MemoryMarshal.GetReference(destination);
ref uint stateRef = ref state.GetReference();
ref byte sourceRef = ref source.GetReference();
ref byte dstRef = ref destination.GetReference();

Vector256<uint> o0 = Vector256.Create(Unsafe.Add(ref stateRef, 0));
Vector256<uint> o1 = Vector256.Create(Unsafe.Add(ref stateRef, 1));
Expand Down