Add optional AAD support to encrypt/decrypt - #159
Conversation
Additive API: encrypt_with_aad/decrypt_with_aad on all three symmetric backends (aes-rust, aes-openssl, xchacha20). The legacy encrypt/decrypt delegate with empty AAD, so existing behavior and wire compatibility are unchanged.
There was a problem hiding this comment.
Pull request overview
This PR adds optional Additional Authenticated Data (AAD) support to the crate’s ECIES encryption/decryption public API, enabling callers to authenticate external context alongside ciphertext without changing the wire format or breaking existing users.
Changes:
- Introduces
encrypt_with_aad/decrypt_with_aadand wires AAD through the symmetric backends (pure Rust AEAD and OpenSSL AES-GCM). - Keeps legacy
encrypt/decryptbehavior by delegating to the AAD variants with empty AAD. - Adds tests (including layout/KAT-style coverage) and expands README with an AAD usage example.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/integration.rs | Adds an integration test covering correct AAD round-trip and failure on wrong/missing AAD. |
| src/symmetric/openssl_aes.rs | Adds AES-256-GCM encrypt_with_aad / decrypt_with_aad and makes legacy wrappers use empty AAD. |
| src/symmetric/mod.rs | Adds sym_encrypt_with_aad / sym_decrypt_with_aad wrappers and AAD-focused unit tests (incl. wire layout check). |
| src/symmetric/aead.rs | Extends pure-Rust AEAD backend with AAD-capable encrypt/decrypt wrappers. |
| src/lib.rs | Exposes public encrypt_with_aad / decrypt_with_aad and routes legacy APIs through empty-AAD delegation. |
| README.md | Documents AAD usage with an example snippet. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Drops the redundant all(all(..)) nesting; rustfmt's canonical form applies. Semantics unchanged.
|
Heads-up for when the workflows get approved: the The repo has no committed For what it's worth, the code in this PR builds cleanly on 1.81.0 in all four Possible fixes, maintainer's call: bump the MSRV toolchain to one whose cargo understands edition2024 (1.85+), or commit a lockfile and build the MSRV leg with |
…tion - keychain reads described as "via security(1)" -> Security.framework API (README, architecture/postmaster.md, getting-started/key-provisioning.md) [A17] - launcher-contract key_var_for: lossy suffix mapping -> hard error for anything outside [A-Za-z0-9_] (no aliasing) [A20] - threat-model fd-closure: drop the "5 sites" count; dotenvy no longer opens its own fds (from_read_iter on postmaster-opened fds) [A13] - dependency policy: 8 -> 10 direct deps, add security-framework (macOS) and a note on the ecies fork git+rev pin (ecies/rs#159) - materialization-abi conformance list: drop the cryptographically unbound "or profile" leg of the replay case - cleanup: document the .postmaster-managed sentinel guard in the cleanup rustdoc, HELP_CLEANUP, Invocation::Cleanup, and cli.md [A19] - ramdisk.rs: drop the obsolete /usr/bin/security analogy mdbook build, fmt, clippy, full locked test suite green.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #159 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 778 832 +54
=========================================
+ Hits 778 832 +54 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thank you for the pr (it seems from Claude though). As it's a library not an app, cargo.lock is intentionally gitignored. I'll do some housekeeping before reconciling |
that's fair, I had gpt-5.6-sol handle the pr text, doc strings and comment replies, the rest was me. I'd be happy to adjust the new API surface however you'd prefer, or throw in similar pr's (ie, AAD support) to the other repo's in this org. ran a lap around it and I see that you like to keep things consistent between each as much as possible. |
Summary
Adds optional additional authenticated data (AAD) support to the public API:
encrypt_with_aad/decrypt_with_aadfunctions, wired through all three symmetric backends (aes-rust,aes-openssl,xchacha20).encrypt/decryptdelegate with empty AAD, so behavior and wire compatibility for current users are unchanged (all pre-existing known-answer vectors pass untouched).Motivation
Nothing in an ECIES ciphertext binds it to the context it was produced for: a ciphertext copied into a different envelope, map entry, or label still decrypts fine. AAD closes that gap — decryption authenticates the context string alongside the ciphertext, so a ciphertext presented under the wrong context fails instead of silently resolving. Useful for protocols that store many ciphertexts in one container and want each bound to its own name/label, without changing the wire format.
The AAD is never stored in or transmitted with the ciphertext; the same value must be supplied at decryption time.
Compatibility
decrypt_with_aad(.., b"")and vice versa, so mixed deployments interoperate.Tests
aes-rust,xchacha20,aes-short-nonce,aes-openssl(default),x25519/ed25519compile checks.