Skip to content

Validate BLAKE3 inputs at runtime - #57

Merged
Coralesoft merged 2 commits into
mainfrom
fix/blake3-input-validation
Jul 16, 2026
Merged

Validate BLAKE3 inputs at runtime#57
Coralesoft merged 2 commits into
mainfrom
fix/blake3-input-validation

Conversation

@Coralesoft

Copy link
Copy Markdown
Collaborator

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.

AlgorithmProvider also continued to report NEON after the NEON path was removed in #30.

What changed

  • The keyed constructor and SetKey now require exactly 32-byte keys. Incorrect lengths throw InvalidKeyLength, and null keys throw InvalidArgument.
  • SetKey resets any buffered input and tree state before loading the new key.
  • The keying trait is now FixedKeyLength<32>, changing MIN_KEYLENGTH from 0 to 32 and ensuring the framework SetKey path enforces the same requirement.
  • The KDF constructor rejects null contexts. Empty contexts remain accepted for compatibility.
  • All three constructors validate digest sizes from 1 to 1024 bytes, and TruncatedFinal uses the standard truncated-size check.
  • AlgorithmProvider and OptimalDataAlignment no longer report or branch on NEON.
  • ValidateBLAKE3 adds 16 cases covering rejected inputs, rekeying, empty contexts, boundary digest sizes, and oversized truncation.

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.
@Coralesoft
Coralesoft merged commit 23d23b9 into main Jul 16, 2026
47 checks passed
@Coralesoft
Coralesoft deleted the fix/blake3-input-validation branch July 16, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant