Skip to content

Add known answer and differential crypto tests to CI - #33

Merged
bdraco merged 1 commit into
mainfrom
ci-crypto-tests
Aug 18, 2026
Merged

Add known answer and differential crypto tests to CI#33
bdraco merged 1 commit into
mainfrom
ci-crypto-tests

Conversation

@bdraco

@bdraco bdraco commented Aug 18, 2026

Copy link
Copy Markdown
Member

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/*.patch with git apply --check, builds the generic CMake target on the patched tree, and runs tests/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_xor plus crypto_onetimeauth_poly1305_aead_mac byte compared against crypto_aead_chacha20poly1305_ietf_encrypt_detached for 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.

@bdraco
bdraco marked this pull request as ready for review August 18, 2026 04:00
Copilot AI lite review requested due to automatic review settings August 18, 2026 04:00
@bdraco
bdraco merged commit 8ccd1ba into main Aug 18, 2026
7 checks passed
@bdraco
bdraco deleted the ci-crypto-tests branch August 18, 2026 04:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.c containing 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-tests GitHub Actions job to checkout submodules, apply patches/*, build the library, compile kat, 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_mac makes 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 thread tests/kat.c
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 thread .github/workflows/ci.yml
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
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.

2 participants