Fix SHA3/Keccak large-buffer Absorb OutOfRange (closes #94)#100
Open
omonien wants to merge 3 commits into
Open
Fix SHA3/Keccak large-buffer Absorb OutOfRange (closes #94)#100omonien wants to merge 3 commits into
omonien wants to merge 3 commits into
Conversation
Widen TBABytes beyond 64 KiB so {$R+} no longer raises in Absorb for
multi-megabyte messages (HashBenchmark path). HashBenchmark now uses the
correct CalcBuffer(FBenchmarkBuffer[0], Size) form without a spurious @.
Add Keccak-224 1 MiB CalcBuffer regression with known digest.
THash_SHA3Base.Calc used PBABytes for DataPtr; Inc(DataPtr, RoundSize) scaled by SizeOf(TBABytes). Walk with PByte and cast only for Absorb.
Use 64 KiB Absorb rounds so large messages exercise multi-round DataPtr advance. Extend TestCalcBufferLargeMessage to compare one-shot multi-round Calc against incremental small-chunk Init/Calc/Done plus known digest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For Markus — theme: product bug fix (HashBenchmark / large messages, GitHub #94)
Addresses issue #94 (HashBenchmark OutOfRange in Keccak Absorb) with two root causes — both fixed here.
Cause 1 — Demo API misuse (intermittent)
CalcBuffer(@FBenchmarkBuffer[0], Size)passes a pointer-to-pointer becauseconst Bufferis already by reference. Failures depended on stack layout — hard to reproduce, easy to mis-blame on the library.Fix:
CalcBuffer(FBenchmarkBuffer[0], BufferSize)+ comment; drop thePwdHashBufworkaround so password and non-password hashes share one path.Cause 2 — Library: 64 KiB typed view + multi-round pointer walk
TBABytes = array[0..65535]with{+}in the SHA-3 section →data^[i]past 64 KiB raisedERangeErroron large messages (e.g. 1 MiB).THash_SHA3Base.Calcadvanced aPBABytespointer withInc(..., RoundSize), which scales bySizeOf(TBABytes), not by bytes — multi-round absorption for large inputs walked the wrong addresses.Fix:
TBABytesbound (typed view only; no allocation change)PByte; cast only atAbsorbRegression tests
TestCalcBufferLargeMessage(Keccak-224, 1 MiB, HashBenchmark fill pattern):CalcBuffer/CalcBytesCalcvs incremental small-chunk Init/Calc/DoneFiles
Source/DECHash.pasDemos/HashBenchmark_FMX/MainFormHashBenchmark.pasCalcBufferusageUnit Tests/Tests/TestDECHashSHA3.pasScope boundary
Risk
Medium — core SHA-3 sponge path for all SHA-3/Keccak digests. Mitigated by explicit 1 MiB multi-round regression and existing KATs.
Independence
Independent of DUnitX and GCM. Complements the Keccak test PR; this one is the library large-buffer fix.
Test plan
TestCalcBufferLargeMessagegreenCloses #94 (when merged).