Skip to content

Commit d7e4442

Browse files
committed
Use TConverters for endian-safe block loads in Blake3 and XXHash3 dispatch
Replace raw memory copies and unchecked PUInt64 loads in scalar dispatch fallbacks with TConverters helpers so byte streams are interpreted as little-endian words consistently with the rest of HashLib. - HlpBlake3Dispatch: load HashMany compress blocks via le32_copy instead of System.Move - HlpXXHash3Dispatch: read input/secret bytes in scalar Accumulate512, ScrambleAcc, and InitSecret via ReadBytesAsUInt64LE Behavior is unchanged on little-endian targets; big-endian portability is improved. SIMD/asm paths are untouched.
1 parent 714a526 commit d7e4442

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

HashLib/src/Crypto/HlpBlake3Dispatch.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ implementation
2626

2727
uses
2828
HlpBits,
29+
HlpConverters,
2930
HlpCpuFeatures,
3031
HlpSimdLevels;
3132

@@ -579,8 +580,7 @@ procedure Blake3_HashMany_Scalar(AInput, AKey, AOut: Pointer;
579580
// Process 16 blocks per chunk
580581
for LBlock := 0 to 15 do
581582
begin
582-
// Convert block bytes to words (assume little-endian)
583-
System.Move(LPInput^, LBlockWords[0], 64);
583+
TConverters.le32_copy(LPInput, 0, @LBlockWords[0], 0, 64);
584584

585585
// Set flags for this block
586586
LBlockFlags := AFlags;

HashLib/src/Hash64/HlpXXHash3Dispatch.pas

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface
2222
implementation
2323

2424
uses
25+
HlpConverters,
2526
HlpCpuFeatures,
2627
HlpSimdLevels;
2728

@@ -48,8 +49,8 @@ procedure XXH3_Accumulate512_Scalar(AAcc: Pointer; AInput: Pointer;
4849
LPSecret := PByte(ASecret);
4950
for I := 0 to XXH_ACC_NB - 1 do
5051
begin
51-
LDataVal := PUInt64(LPInput + I * 8)^;
52-
LDataKey := LDataVal xor PUInt64(LPSecret + I * 8)^;
52+
LDataVal := TConverters.ReadBytesAsUInt64LE(LPInput, I * 8);
53+
LDataKey := LDataVal xor TConverters.ReadBytesAsUInt64LE(LPSecret, I * 8);
5354
PUInt64(PByte(LPAcc) + (I xor 1) * 8)^ :=
5455
PUInt64(PByte(LPAcc) + (I xor 1) * 8)^ + LDataVal;
5556
PUInt64(PByte(LPAcc) + I * 8)^ :=
@@ -69,7 +70,7 @@ procedure XXH3_ScrambleAcc_Scalar(AAcc: Pointer; ASecret: Pointer);
6970
LPSecret := PByte(ASecret);
7071
for I := 0 to XXH_ACC_NB - 1 do
7172
begin
72-
LKey64 := PUInt64(LPSecret + I * 8)^;
73+
LKey64 := TConverters.ReadBytesAsUInt64LE(LPSecret, I * 8);
7374
LAcc64 := PUInt64(PByte(LPAcc) + I * 8)^;
7475
LAcc64 := LAcc64 xor (LAcc64 shr 47);
7576
LAcc64 := LAcc64 xor LKey64;
@@ -88,8 +89,10 @@ procedure XXH3_InitSecret_Scalar(ACustomSecret: Pointer;
8889
LPDst := PByte(ACustomSecret);
8990
for I := 0 to (192 div 16) - 1 do
9091
begin
91-
PUInt64(LPDst + 16 * I)^ := PUInt64(LPSrc + 16 * I)^ + ASeed;
92-
PUInt64(LPDst + 16 * I + 8)^ := PUInt64(LPSrc + 16 * I + 8)^ - ASeed;
92+
PUInt64(LPDst + 16 * I)^ :=
93+
TConverters.ReadBytesAsUInt64LE(LPSrc, 16 * I) + ASeed;
94+
PUInt64(LPDst + 16 * I + 8)^ :=
95+
TConverters.ReadBytesAsUInt64LE(LPSrc, 16 * I + 8) - ASeed;
9396
end;
9497
end;
9598

0 commit comments

Comments
 (0)