test(identity): make ciphertext tampering deterministic - #61
Merged
Conversation
Both tamper-detection tests built their payload as `'ff' + ct.slice(2)`, which is a no-op the 1-in-256 times the ciphertext already starts with `ff` — decryption then succeeds and the assertion fails for reasons unrelated to the code under test. Measured at 0.36% over 5000 samples, and it took down CI on the 1.0.0 release merge. Flipping the byte instead is a no-op for none of the 256 possible values.
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.
CI on
masterwent red on the 1.0.0 release merge (run 30407887853) attests/core/identity/crypto.test.ts— "Received function did not throw".It's a test bug, not a crypto bug. Both tamper-detection tests built their tampered payload as:
When the ciphertext already starts with
ff, that assignment changes nothing. The payload is byte-identical, AES-GCM decrypts it correctly, and.toThrow()fails. 1 in 256.Measured on the real code path: 18/5000 = 0.36%, against a predicted 1/256 = 0.39%.
Fixed by flipping the byte rather than assigning it, via a shared helper used at both sites. Verified exhaustively over all 256 possible first-byte values: the old form is a no-op for exactly 1, the new form for 0.
Targets
masterdirectly because that is the branch that is red and the release is gated behind it.