Skip to content

Commit 22256ec

Browse files
committed
fix stripe calculation
1 parent 933627c commit 22256ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/XXHash.XXH3.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static void accumulate(Span<ulong> acc, ReadOnlySpan<byte> input, ReadOnlySpan<b
310310
static void hashLongInternalLoop(Span<ulong> acc, ReadOnlySpan<byte> input, ReadOnlySpan<byte> secret)
311311
{
312312
int nbStripesPerBlock = (secret.Length - stripeLength) / secretConsumeRate;
313-
int blockLen = stripeLength / nbStripesPerBlock;
313+
int blockLen = stripeLength * nbStripesPerBlock;
314314
int nbBlocks = (input.Length - 1) / blockLen;
315315

316316
for (int n = 0; n < nbBlocks; n++)
@@ -319,8 +319,11 @@ static void hashLongInternalLoop(Span<ulong> acc, ReadOnlySpan<byte> input, Read
319319
scrambleAcc(acc, secret[^stripeLength..]);
320320
}
321321

322-
int nbStripes = (input.Length - 1 - (blockLen - nbBlocks)) / stripeLength;
323-
accumulate(acc, input[(nbBlocks * blockLen)..], secret, nbStripes);
322+
// Process remaining stripes
323+
int nbStripesLeft = ((input.Length - 1) - (nbBlocks * blockLen)) / stripeLength;
324+
accumulate(acc, input[(nbBlocks * blockLen)..], secret, nbStripesLeft);
325+
326+
// last stripe
324327
accumulate512(acc, input[^stripeLength..], secret[^(stripeLength + secretLastAccStart)..]);
325328
}
326329

0 commit comments

Comments
 (0)