Skip to content

Commit

Permalink
Fix XxHash3/XxHash128 DeriveSecretFromSeed scalar fallback on big end…
Browse files Browse the repository at this point in the history
…ian (#79186)

Backport of #78084
  • Loading branch information
xoofx authored Dec 3, 2022
1 parent 720ae03 commit 4ce23f4
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ public static void DeriveSecretFromSeed(byte* destinationSecret, ulong seed)
{
for (int i = 0; i < SecretLengthBytes; i += sizeof(ulong) * 2)
{
Unsafe.WriteUnaligned(destinationSecret + i, Unsafe.ReadUnaligned<ulong>(defaultSecret + i) + seed);
Unsafe.WriteUnaligned(destinationSecret + i + 8, Unsafe.ReadUnaligned<ulong>(defaultSecret + i + 8) - seed);
WriteUInt64LE(destinationSecret + i, ReadUInt64LE(defaultSecret + i) + seed);
WriteUInt64LE(destinationSecret + i + 8, ReadUInt64LE(defaultSecret + i + 8) - seed);
}
}
}
Expand Down Expand Up @@ -791,6 +791,16 @@ public static ulong ReadUInt64LE(byte* data) =>
Unsafe.ReadUnaligned<ulong>(data) :
BinaryPrimitives.ReverseEndianness(Unsafe.ReadUnaligned<ulong>(data));

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void WriteUInt64LE(byte* data, ulong value)
{
if (!BitConverter.IsLittleEndian)
{
value = BinaryPrimitives.ReverseEndianness(value);
}
Unsafe.WriteUnaligned(data, value);
}

[StructLayout(LayoutKind.Auto)]
public struct State
{
Expand Down

0 comments on commit 4ce23f4

Please sign in to comment.