Validate BLAKE3 inputs at runtime - #57
Merged
Merged
Conversation
Replace debug-only BLAKE3 input assertions with runtime validation. Require exactly 32-byte keys in the keyed constructor and SetKey, reject null keys and null KDF contexts, validate digest sizes, and use the standard truncation-size check in TruncatedFinal. Advertise the key as fixed-length and remove the stale NEON provider result. Add regression tests for invalid keys, contexts, digest sizes, and truncated output.
SetKey replaced the key and chunk CV but kept buffered input and tree state from prior use. Reset the state before loading the new key so rekeying matches a fresh keyed instance. Add regression coverage for rekeying and both digest-size bounds in each constructor, update the class comment, and remove stale NEON benchmark comments.
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.
Replaces BLAKE3's debug-only input assertions with runtime validation. Release builds previously allowed short or null keys, causing an out-of-bounds read in the keyed constructor, passed null KDF contexts to
strlen, and accepted invalid digest and truncation sizes.AlgorithmProvideralso continued to report NEON after the NEON path was removed in #30.What changed
SetKeynow require exactly 32-byte keys. Incorrect lengths throwInvalidKeyLength, and null keys throwInvalidArgument.SetKeyresets any buffered input and tree state before loading the new key.FixedKeyLength<32>, changingMIN_KEYLENGTHfrom 0 to 32 and ensuring the frameworkSetKeypath enforces the same requirement.TruncatedFinaluses the standard truncated-size check.AlgorithmProviderandOptimalDataAlignmentno longer report or branch on NEON.ValidateBLAKE3adds 16 cases covering rejected inputs, rekeying, empty contexts, boundary digest sizes, and oversized truncation.