Add known answer and differential crypto tests to CI - #33
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a dedicated CI job to validate the patched libsodium submodule by applying the patch stack, building the generic CMake target, and running a new C-based crypto test binary that performs an RFC 8439 known-answer test and (when available) fast-path differential checks.
Changes:
- Add
tests/kat.ccontaining an RFC 8439 AEAD known-answer vector test plus optional ESPHome fast-path differential/counter-continuation tests gated behind a capability macro. - Add a
crypto-testsGitHub Actions job to checkout submodules, applypatches/*, build the library, compilekat, and execute it on every PR.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/kat.c |
Introduces known-answer and (optionally) differential tests to validate patched-tree crypto behavior. |
.github/workflows/ci.yml |
Adds a new CI job that applies patches, builds libsodium, and runs the new KAT/differential test binary. |
Suppressed comments (1)
tests/kat.c:138
- In the differential test, the MAC comparison uses a hard-coded length (16). Using
sizeof ref_macmakes this resilient to refactors and keeps the comparison consistent with the buffer size.
check(memcmp(ref_c, fast_c, clen) == 0 &&
memcmp(ref_mac, fast_mac, 16) == 0, what);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+82
to
+84
| crypto_aead_chacha20poly1305_ietf_encrypt_detached( | ||
| c, mac, &maclen, (const unsigned char *) kat_msg, 114, | ||
| kat_ad, 12, NULL, kat_npub, kat_key); |
Comment on lines
+52
to
+56
| for f in patches/*.patch; do | ||
| echo "Checking $f" | ||
| git -C libsodium apply --check "../$f" | ||
| git -C libsodium apply "../$f" | ||
| done |
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.
Summary
Adds a CI job that exercises the patch stack and the crypto on every PR instead of first at release time: it applies
patches/*.patchwithgit apply --check, builds the generic CMake target on the patched tree, and runstests/kat.c, which asserts the RFC 8439 section 2.8.2 known answer vector (ciphertext and tag) against the reference AEAD.The test also contains a differential suite for the session fast path (#32):
crypto_stream_chacha20_ietf_session_block0_xorpluscrypto_onetimeauth_poly1305_aead_macbyte compared againstcrypto_aead_chacha20poly1305_ietf_encrypt_detachedfor payload lengths 0 to 130 crossed with seven ad lengths, plus a counter continuation check. Those tests are gated on the capability macro, so on current main they compile out and the job runs the reference vector only; once #32 lands they activate automatically with no further changes.Verified locally in both modes: patches 01 to 04 with the reference vector passing, and with #32's patches applied the full differential suite passing.