Repository navigation
feat(vitaminc-aead): the AES-256-GCM cipher moves into vitaminc-aead - #2044
Conversation
Copied from the published vitaminc-encrypt 0.10.0, behind a new `aes`
feature, as `vitaminc_aead::aes::{Aes256Cipher, Key}`. It sits next to
the leaf format it writes (`LocalCipherText`, the nonce and the wire
version), which is already in this crate.
Only what this repository uses came across: `Aes256Cipher::new`, its
`Cipher` impl, `Key::from([u8; 32])`, and the two backends (aws-lc-rs on
native targets, RustCrypto's aes-gcm on wasm32 or with the
`_test-rust-crypto-backend` feature). Left behind: `opening_version_1`
and `OpensVersion1` (reading wire version 1 leaves), `Key::wrap` and
`Key::from_wrapped`, `Generatable for Key`, `encrypt_with_key`,
`decrypt_with_key`, `AesCipherText`, and the `hlist` static cipher.
Their tests stayed behind with them.
With aws-lc-rs in the graph, `(): From<_>` has two impls, so three
existing tests of the ciphertext builder name their error type.
stack-encrypt, the EQL encryption tests and the recipher-js test addon use `vitaminc_aead::aes` instead, with its `aes` feature on. The workspace's `vitaminc` umbrella no longer turns on its `encrypt` feature: nothing here names `vitaminc::encrypt`. The two heap-hygiene tests exclude the aws-lc seal's free by its new path, `vitaminc_aead::aes::backend::aws_lc::CipherKey::seal`. vitaminc-encrypt 0.5.1 is still in the graph, through cts-common and vitaminc 0.5.1. That is the older line and is not changed here.
… private `CipherTextBuilder`, `Nonce`, `NonceGenerator`, `RandomNonceGenerator` and `LocalCipherText::into_reader` were public so that a cipher in another crate could write and read the leaf layout. The only such cipher is now `aes::Aes256Cipher`, in this crate, so they are crate-private and built only with the `aes` feature. `LocalCipherText` and `WIRE_VERSION` stay public: stack-encrypt stores the leaf, and eql-bindings reads the version. `read_version_in`, which accepted older wire versions, is folded into `read_version`: nothing opens version 1 leaves any more. `append_target_plaintext_array` had no caller and is removed.
They were renamed to `Context` and `ContextPiece` in vitaminc 0.5 and kept for one transition. The published vitaminc-encrypt was the last thing that named `Aad`; nothing in the build depends on it now. stack-encrypt's re-export of both goes with them.
…f the plaintext aws-lc-rs's `seal_in_place_append_tag` appends the tag's space to the buffer before it encrypts (aws-lc-rs 1.18.0, `aead/unbound_key.rs:403`). A buffer with no spare room moves at that point, and the block it leaves holds the plaintext. The backend now makes the room first and wipes the old block before it is freed. Both heap-hygiene tests excluded that free by name, as a fault in a crate outside this repository. The backend is in vitaminc-aead now, so the exclusion goes. Before the fix, 14 of stack-encrypt's 49 heap-hygiene tests fail without the exclusion; with it, all 49 pass.
The nonce types are private now, so the README's nonce example no longer compiled. It names the cipher in the aes module where it named vitaminc-encrypt's.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
🦋 Changeset detectedLatest commit: 2489e58 The changes in this PR will be included in the next version bump. This PR includes changesets to release 19 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The EQL encryption tests and the recipher-js test addon are separate Cargo workspaces, so the root cargo fmt did not reach them.
…ffer When a backend's seal returned an error, the buffer still held the plaintext, and the closure that called it dropped the buffer unwiped. Both backends now wipe and clear the buffer on any error. The test forces the error with a nonce of the wrong length, and runs on both backends.
Nothing here uses vitaminc-encrypt 0.10 now, so three crates.io vitaminc crates depend on vitaminc-aead, not four. The EQL heap test's module docs lose a stray empty line.
coderdan
left a comment
There was a problem hiding this comment.
Code review at 42c92e179, by /code-review medium in Claude Code (Claude Opus 5.5). I checked each finding against the code and the CI logs.
Two findings are failing checks: cargo vet and cargo deny for the vitaminc-aead crates. Four are minor. One minor finding is in a file this pull request does not change:
AGENTS.md:754: the paragraph on the[patch.crates-io]tables still listsvitaminc-encryptas one of four crates.io crates that depend onvitaminc-aead. No workspace here resolves it now.
CI also found one more failure: cargo fmt in the recipher-js test addon and the EQL encryption tests. Those are separate Cargo workspaces, so the root cargo fmt did not check them.
|
The backend tests ran under wasm-bindgen-test on wasm32. That runner is for wasm32-unknown-unknown in a JavaScript host. Nothing we ship targets wasm32-unknown-unknown: our wasm32 target is wasm32-wasip1, for the Go guests. Under WASI the standard test harness runs, so these tests are now plain #[test] functions on every target. This drops wasm-bindgen-test and the six crates under it from the crate's dev-dependencies. cargo vet had no audit for any of them.
…ackend The `aes` feature turned on aes-gcm on every target, so a native build compiled RustCrypto's AES-GCM next to aws-lc-rs and never used it. Its graph also brought generic-array's build script into the native build. aes-gcm is now declared per target, as vitaminc-encrypt 0.10 declared it. On native targets it is optional and only `_test-rust-crypto-backend` turns it on. On wasm32 it is a plain dependency. A feature turns on a dependency by name on every target that declares it. Cargo also refuses a second, renamed entry for the same crate. So `aes` cannot turn it on for wasm32 alone.
The workspace test run turns every feature on, `_test-rust-crypto-backend` included. So CI tested the AES cipher only with RustCrypto's aes-gcm, and never with aws-lc-rs, the backend native builds use. `test:vitaminc-aead:features` now also runs the crate's tests with `aes` alone (aws-lc-rs) and with `aes,_test-rust-crypto-backend` (RustCrypto).
wasm32-wasip1 is the target the Go guests build for, and on wasm32 the `aes` feature uses RustCrypto's aes-gcm. CI only checked that the crate compiles for that target. The new `vitaminc-aead-wasip1` job runs the crate's tests there, with wasmtime as the test runner. wasmtime 50.0.3 is pinned in mise.test.toml with the other test tools, as a prebuilt release. The task `test:vitaminc-aead:wasip1` skips the three trybuild tests: trybuild starts cargo as a child process, and a WASI program cannot start a process. The other test runs cover them on the host.
crates.io has yanked every pin-project-lite before 0.2.19, the root Cargo.lock's 0.2.17 included. cargo deny refuses a yanked version, and vitaminc-aead reaches pin-project-lite through futures-util. `next` is still on 0.2.17. `cargo update -p pin-project-lite` moves the root Cargo.lock to 0.2.19 and changes nothing else. The other Cargo workspaces still carry yanked versions, as `next` does; cargo deny does not read their lock files.
vitaminc-aead's `aes` feature uses aws-lc-rs on native targets. cargo deny refused it for two reasons. The licences of aws-lc-rs, aws-lc-sys and untrusted each need ISC. ISC is not on the allow list. It is a short permissive licence, like MIT. It is now allowed for those three crates only, so a new ISC crate is still reviewed. The build scripts of aws-lc-rs and aws-lc-sys were not allowed. The first checks the crate's features and passes on an include path. The second compiles and links the AWS-LC C library. deny.toml says what each one does beside its entry.
aws-lc-sys bundles the AWS-LC C library, its Rust bindings and the build script that compiles them: about 2.1 million lines. Nobody here can read that much code. cargo vet now trusts the account that publishes it, justsmth (Justin W Smith, crates.io user 156764), at safe-to-deploy. That accepts AWS's own review of its releases. The entry, its dates and the publisher record in imports.lock were written by `cargo vet trust`. The trust covers aws-lc-sys only. aws-lc-rs, the Rust layer vitaminc-aead calls, still needs an audit. The safe-to-run exemption for aws-lc-sys 0.44.0 is gone: the trust entry covers more than it did.
The AES cipher moved from vitaminc-encrypt 0.10 into vitaminc-aead. The root workspace no longer depends on vitaminc-encrypt 0.10.0. Cargo.lock holds only vitaminc-encrypt 0.5.1, for cts-common. The exemption covered nothing.
On wasm32, aes-gcm is now always a dependency of vitaminc-aead, not only with its `aes` feature. The credential guest builds vitaminc-aead without `aes`, so its Cargo.lock gains the edge from vitaminc-aead to aes-gcm. The lock already held aes-gcm 0.10.3, so no new crate comes in.
The spike in #2043 showed that a target can be declared once, as a sink for one walk of the value and a finishing step, and that the one declaration encrypts the target, decrypts it and gives its query terms. The combinators become adapters over that trait, as the standard library's iterator adapters are. This is how the plan's third decision is built, so the question of whether it still stands is answered. The plan now has: - the decisions made during the spike; - the declaration design, and what the compiler checks; - what the spike checked for encrypt, decrypt and query, what it did not cover, and the four ways it differs from today's code; - the layout of stack-encrypt and vitaminc-aead: the three calls as top-level modules, one place for each index, the order of the modules, and the crate root's 29 names; - the groundwork that can start now: #2042, the AES cipher in #2044, vitaminc-normalize and the layout moves; - step 1.4 as eight pull requests; - twelve new open questions, and answers to questions 1, 6 and 17. It replaces the record-sink design of the last commit, which the declaration design superseded.
… feature CI runs the workspace tests with --all-features. That turned on `_test-rust-crypto-backend`, so the main test run used RustCrypto for every crate. It never tested aws-lc-rs, the backend that native builds use, except in vitaminc-aead's own tests. stack-encrypt's heap_hygiene test ran only against RustCrypto. A feature also cannot turn on a dependency for one target only. So aes-gcm was a plain dependency on wasm32. The Go auth guest compiled it through vitaminc-aead without using it, and cargo deny failed for recipher-frame and vitaminc-aead-derive on generic-array's build script. The `vitaminc_aead_rust_crypto` cfg replaces the feature. aes-gcm is now declared only for wasm32 and for builds with the cfg. `aes` turns it on with aws-lc-rs. A native build with --all-features now has aws-lc-rs and no aes-gcm. A wasm32 build has aes-gcm only with `aes`, so the auth guest's lock file loses the dependency again. `test:vitaminc-aead:features` adds the cfg to RUSTFLAGS and keeps the `-D warnings` that CI sets there. With it, the task runs vitaminc-aead's tests with `aes` and stack-encrypt's heap_hygiene test. So CI tests both backends on the host.
RustCrypto's aes-gcm depends on generic-array 0.14.7. The aes-gcm crate is the AES-256-GCM cipher on wasm32. cargo deny checks the graph for every target with every feature on. So with `aes` on, vitaminc-aead's graph has generic-array, and the check failed on its build script. The build script asks version_check for the rustc version. The version_check crate runs `rustc --version`. The script sets one cfg when the version is 1.41 or later. It does nothing else.
The cc crate runs the C compiler for build scripts. The aws-lc-sys build uses it, directly and through cmake, to compile the AWS-LC C library. The store had no audit or trust that covered cc 1.2.55 at safe-to-deploy. The crates.io user rust-lang-owner published cc up to 1.2.34. Later versions are published by the crates.io trusted publisher of the rust-lang/cc-rs repository. 1.2.55 is the version in the graph. So a trust of rust-lang-owner covers nothing here. This entry trusts github:rust-lang/cc-rs at safe-to-deploy instead. `cargo vet trust` wrote the entry and the publisher record for cc 1.2.55 in imports.lock. It also removed the safe-to-run exemption for cc 1.2.55. The trust entry covers that version at a higher level. The command also rewrote the rest of imports.lock for the whole workspace. Only the cc record is kept.
…17 to 0.2.19 The aes feature brings aws-lc-rs into vitaminc-aead's graph, and the move off a yanked pin-project-lite brought 0.2.19. cargo vet needed both at safe-to-deploy. aws-lc-rs 1.18.0: the build script and every line with unsafe in src/ were read, 367 of 367. The notes record one defect, an out-of-bounds read from safe code in the streaming cipher API. It needs the legacy-des feature, which no crate here turns on. pin-project-lite 0.2.17 to 0.2.19: the whole diff was read. The changes make the macro reject more input, and add no unsafe operation. The safe-to-run exemption for aws-lc-rs 1.18.0 goes, because the audit covers it. imports.lock gains the imported audits that cover pkg-config 0.3.32. cargo vet writes those only when vetting passes.
aws-lc-rs 1.18.0 and aws-lc-sys before 0.45.0 are affected by GHSA-xv35-xp83-5wrf, an out-of-bounds write in StreamingDecryptingKey's padded decrypt. Nothing here calls that code, but vitaminc-aead's aes feature should not depend on a release with a known memory-safety bug. The same five lock files move as in #2053, which makes this change on main, with the same @cipherstash/auth changeset. Its native binaries link aws-lc-rs through stack-auth.
…e 1.18.0 notes The delta audit covers every changed line. No unsafe line, build-script change, dependency or feature was added. The changes at unsafe call sites close two bugs: the AEAD seal now checks that the buffer grew by the tag before AWS-LC writes to it, and the streaming cipher constructors check the IV before AWS-LC reads it. GHSA-xv35-xp83-5wrf itself is fixed in AWS-LC's EVP_DecryptUpdate, in aws-lc-sys 0.45.0, which the trusted publisher covers. The notes of the 1.18.0 audit now say what that reading missed: the advisory, and the AEAD seal's trust in the caller's buffer type. Neither is on vitaminc-aead's path, which passes a Vec.
#2044 moved the AES-256-GCM cipher into vitaminc-aead. Its only caller outside tests is stack-encrypt, which builds a one-key Aes256Cipher for each leaf inside its own key-per-leaf cipher, and seeds a random number generator for each leaf while doing so. Step 1.4's first pull request now moves the cipher into stack-encrypt as crate-private functions, with the stored layout of a leaf. vitaminc-aead then has no encryption primitive and no key. Before that, cargo deny and cargo vet cover stack-encrypt (#1842), so that aws-lc-rs, aws-lc-sys and aes-gcm stay checked. Two open questions are new: where the leaf layout sits in stack-encrypt, and what the two tests outside stack-encrypt that build an Aes256Cipher seal with afterwards.
Summary
This pull request moves the AES-256-GCM cipher into vitaminc-aead, the crate that already has the format of a sealed leaf. Nothing in this repository depends on the published
vitaminc-encrypt0.10 after it. Stored bytes do not change.It also fixes a leak. On aws-lc-rs, the seal freed a copy of the plaintext without wiping it, on almost every seal. Both heap tests excluded that free, because the code was in another repository. The exclusion is gone.
This is the second pull request of the groundwork in #2040. It is based on
next, after #2042.Changes
The cipher
aes::Aes256Cipherandaes::Key, behind a newaesfeature.vitaminc-encrypt0.10 that this repository calls:Aes256Cipher::new, itsCipherimpl,Key::from([u8; 32]), and the two backends. The backends are aws-lc-rs on native targets and RustCrypto'saes-gcmon wasm32.--cfg vitaminc_aead_rust_crypto. The tests use it to run that backend on the host. It is not a Cargo feature: CI runs the workspace's tests with every feature on, so a feature would change the backend for every test.encrypt_with_key,decrypt_with_key, and thehlistcipher.vitaminc-encrypt0.10.What else goes
CipherTextBuilder,Nonce,NonceGenerator,RandomNonceGeneratorandLocalCipherText::into_readerare private to vitaminc-aead. They were public only so that a cipher in another crate could use them.AadandAadPieceare removed from vitaminc-aead, and stack-encrypt no longer re-exports them.ContextandContextPieceare the names to use.The leak
aead/unbound_key.rs:403in aws-lc-rs 1.18.0). A buffer with no spare room moves, and the old block still has the plaintext in it.CI
tests-crates.ymlruns vitaminc-aead'saestests on each backend, and stack-encrypt's heap tests on the RustCrypto backend.wasm32-wasip1under wasmtime. That is the target of the Go guests. wasmtime 50.0.3 is pinned inmise.test.toml.#[test]functions, sowasm-bindgen-testis gone.Supply chain
deny.tomlallows the ISC licence for aws-lc-rs, aws-lc-sys and untrusted only. It allows the build scripts of aws-lc-rs, aws-lc-sys and generic-array, and says what each one does.cargo vetstore trusts the publisher of aws-lc-sys, and the crates.io trusted publisher ofrust-lang/cc-rsfor cc.main.@cipherstash/authpatch changeset releases its native binaries with the fixed versions.safe-to-deploy: aws-lc-rs 1.18.0, the delta from 1.18.0 to 1.18.1, and the delta of pin-project-lite from 0.2.17 to 0.2.19. The 1.18.0 audit's notes record two bugs that its reading missed, both fixed in 1.18.1.imports.lockhas the imported audits that cover pkg-config 0.3.32.vitaminc-encrypt0.10.0 is removed.Docs
Verification
On a Mac, with Rust 1.94.1. The checks ran before I added the changelog entries and reworded the commit messages. Neither of those changed any code.
-D warnings.nexton this machine too, a different set on each run. This branch changes no stack-auth file.vitaminc-aeadcompiler-message test that failed while another such test held the build directory. It passes when run alone, as do the other two.aesfeature. The crate builds forwasm32-unknown-unknown.-D warnings.go testpasses for every package.init is never usedin code this branch does not change. The same warning is there before the spike.After the review fixes and the CI and supply-chain changes
At 2c0830c, on the same machine:
aeson aws-lc-rs, 394 on RustCrypto, and 339 with no features. The RustCrypto run has two fewer tests because the aws-lc-rs backend is not compiled.wasm32-unknown-unknownandwasm32-wasip1. Its tests pass onwasm32-wasip1under wasmtime 50.0.3.go testpass.cargo metadata --locked.aes-gcmis built:cargo treeshows it under vitaminc-aead on wasm32 withaes, and on a native build with the flag. It is absent on a native build with all features and no flag.cargo deny: passes for the three crates, here and in CI.cargo vet: passes with and without--locked.Related
nextbefore this.main.Review notes
vitaminc-encrypt0.10'ssrc/cipher.rs,src/key.rsandsrc/backend/shows what was left behind.reserve_taginpackages/vitaminc-aead/src/aes/backend/aws_lc.rs, with two unit tests.