From d491d564a693a423939d06786e3b16fee8cee7e7 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 3 Dec 2026 10:16:59 +1100 Subject: [PATCH 01/25] feat(vitaminc-aead): the AES-256-GCM cipher, behind an aes feature 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. --- Cargo.lock | 3 + packages/vitaminc-aead/CHANGELOG.md | 4 + packages/vitaminc-aead/Cargo.toml | 26 +- packages/vitaminc-aead/src/aes/backend.rs | 207 +++++++ .../vitaminc-aead/src/aes/backend/aws_lc.rs | 42 ++ .../src/aes/backend/rust_crypto.rs | 53 ++ packages/vitaminc-aead/src/aes/cipher.rs | 570 ++++++++++++++++++ packages/vitaminc-aead/src/aes/key.rs | 74 +++ packages/vitaminc-aead/src/aes/mod.rs | 25 + packages/vitaminc-aead/src/ciphertext/mod.rs | 6 +- packages/vitaminc-aead/src/lib.rs | 3 + packages/vitaminc-aead/tests/aes_cipher.rs | 201 ++++++ 12 files changed, 1210 insertions(+), 4 deletions(-) create mode 100644 packages/vitaminc-aead/src/aes/backend.rs create mode 100644 packages/vitaminc-aead/src/aes/backend/aws_lc.rs create mode 100644 packages/vitaminc-aead/src/aes/backend/rust_crypto.rs create mode 100644 packages/vitaminc-aead/src/aes/cipher.rs create mode 100644 packages/vitaminc-aead/src/aes/key.rs create mode 100644 packages/vitaminc-aead/src/aes/mod.rs create mode 100644 packages/vitaminc-aead/tests/aes_cipher.rs diff --git a/Cargo.lock b/Cargo.lock index 283ca69ad..607ffad71 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4550,6 +4550,8 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-executor", "futures-util", @@ -4567,6 +4569,7 @@ dependencies = [ "vitaminc-prf", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", + "wasm-bindgen-test", "zeroize", ] diff --git a/packages/vitaminc-aead/CHANGELOG.md b/packages/vitaminc-aead/CHANGELOG.md index 69a8e68c2..acb90e4e3 100644 --- a/packages/vitaminc-aead/CHANGELOG.md +++ b/packages/vitaminc-aead/CHANGELOG.md @@ -16,6 +16,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added +- `aes::Aes256Cipher` and `aes::Key`, behind the new `aes` feature: the AES-256-GCM cipher that seals and opens this crate's leaves. + They are the parts of `vitaminc-encrypt` 0.10 that the stack crates call: `Aes256Cipher::new`, its `Cipher` impl, and `Key::from([u8; 32])`. + The cipher uses aws-lc-rs on native targets, and RustCrypto's `aes-gcm` on wasm32. + It opens wire version 2 leaves only. - `ScalarTarget` (also `typed::ScalarTarget`): a trait for a decrypt target that is built from one scalar. `ScalarTarget` is the decrypt-side counterpart of `Scalar`. Code that decrypts exactly one leaf bounds its target on `ScalarTarget`, so a target that needs a sequence or a map does not compile. diff --git a/packages/vitaminc-aead/Cargo.toml b/packages/vitaminc-aead/Cargo.toml index 83f2d487a..9368bd2bf 100644 --- a/packages/vitaminc-aead/Cargo.toml +++ b/packages/vitaminc-aead/Cargo.toml @@ -18,7 +18,7 @@ rust-version = "1.89.0" publish = false [package.metadata.docs.rs] -features = ["jiff", "rust_decimal", "uuid", "hlist"] +features = ["aes", "jiff", "rust_decimal", "uuid", "hlist"] rustdoc-args = ["--cfg", "docsrs"] [dependencies] @@ -57,7 +57,24 @@ version = "1" default-features = false optional = true +# The AES-256-GCM cipher (`aes`): aws-lc-rs on native targets, RustCrypto's +# aes-gcm on wasm32. +[target.'cfg(not(target_arch = "wasm32"))'.dependencies.aws-lc-rs] +version = "1.17.0" +optional = true + +[dependencies.aes-gcm] +version = "0.10" +default-features = false +features = ["aes", "alloc", "zeroize"] +optional = true + [features] +# The AES-256-GCM `Cipher` and its key, in the `aes` module. +aes = ["dep:aws-lc-rs", "dep:aes-gcm"] +# Not an API. Forces the RustCrypto backend on native targets, so its tests +# run without a wasm toolchain. +_test-rust-crypto-backend = ["aes"] jiff = ["dep:jiff"] rust_decimal = ["dep:rust_decimal"] uuid = ["dep:uuid"] @@ -89,3 +106,10 @@ trybuild = "1.0.118" futures-executor = "0.3.31" serde_json = "1" jiff = { version = "1.0.1", default-features = false } + +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +wasm-bindgen-test = "0.3" + +[[test]] +name = "aes_cipher" +required-features = ["aes"] diff --git a/packages/vitaminc-aead/src/aes/backend.rs b/packages/vitaminc-aead/src/aes/backend.rs new file mode 100644 index 000000000..2f873d35f --- /dev/null +++ b/packages/vitaminc-aead/src/aes/backend.rs @@ -0,0 +1,207 @@ +//! Backend abstraction over AES-256-GCM implementations. +//! +//! Two implementations are selected via `cfg`: +//! +//! - **Native** (`cfg(not(target_arch = "wasm32"))`): `aws-lc-rs` — +//! FIPS-validated, hardware-accelerated. +//! - **Wasm32** (`cfg(target_arch = "wasm32")`): `aes-gcm` from RustCrypto — +//! pure Rust, builds without a C toolchain. +//! +//! Both implementations conform to RFC 5116 AES-256-GCM and produce +//! byte-identical ciphertext+tag output for the same inputs. +//! +//! The internal `_test-rust-crypto-backend` feature forces the RustCrypto +//! backend on native targets so CI can exercise it without wasm tooling. + +#[cfg(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend"))] +mod rust_crypto; +#[cfg(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend"))] +pub(crate) use rust_crypto::CipherKey; + +#[cfg(not(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend")))] +mod aws_lc; +#[cfg(not(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend")))] +pub(crate) use aws_lc::CipherKey; + +/// AES-256-GCM nonce length, in bytes. +pub(crate) const NONCE_LEN: usize = 12; + +#[cfg(test)] +mod tests { + use super::CipherKey; + + // wasm-pack invokes Node by default — no `wasm_bindgen_test_configure!` needed. + #[cfg(target_arch = "wasm32")] + use wasm_bindgen_test::wasm_bindgen_test; + + /// Cross-backend byte-parity check. + /// + /// The same test runs against the `aws-lc-rs` backend on native targets, + /// and against RustCrypto with the `_test-rust-crypto-backend` feature or + /// on wasm32. Both must produce the byte string in `EXPECTED`. + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn cross_backend_byte_parity() { + // Fixed inputs — chosen to exercise: non-empty plaintext, non-empty AAD, + // a plaintext length that's not a block boundary (so we cover GCM's + // partial-block handling). + let key: [u8; 32] = [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + ]; + let nonce: [u8; 12] = [ + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, + ]; + let plaintext = b"vitaminc cross-backend parity vector"; + let aad = b"vitaminc-encrypt KAT v1"; + + // Ciphertext (36 bytes) || GCM tag (16 bytes), computed deterministically + // from the inputs above by an RFC 5116 AES-256-GCM implementation. + // Verified to be produced identically by both `aws-lc-rs` and RustCrypto + // `aes-gcm` when this test was introduced. + const EXPECTED: [u8; 52] = [ + 0x90, 0x71, 0x08, 0x4c, 0x28, 0xa2, 0x6c, 0xdc, 0x42, 0x06, 0xf5, 0xbc, 0x74, 0x09, + 0xed, 0xbc, 0x11, 0xcf, 0x32, 0x75, 0xfc, 0xd3, 0x62, 0x1c, 0xfd, 0x7c, 0x4f, 0xf2, + 0x06, 0x8b, 0x03, 0x64, 0xb1, 0x02, 0x28, 0x8d, 0xed, 0x9a, 0xa3, 0xcf, 0x46, 0x3d, + 0xa6, 0xb2, 0x0e, 0x7f, 0x86, 0x23, 0x76, 0x7a, 0xfb, 0x0a, + ]; + + let cipher = CipherKey::new(&key).expect("key construction failed"); + + let mut sealed = plaintext.to_vec(); + cipher.seal(&nonce, aad, &mut sealed).expect("seal failed"); + assert_eq!( + sealed, + EXPECTED.as_slice(), + "ciphertext+tag diverged from cross-backend KAT" + ); + + let mut to_open = sealed.clone(); + let pt_len = cipher.open(&nonce, aad, &mut to_open).expect("open failed"); + assert_eq!( + &to_open[..pt_len], + plaintext, + "round-trip plaintext mismatch" + ); + } + + // Deterministic counterparts to the quickcheck round-trip tests in + // `cipher::test`. Those property tests can't run under wasm-bindgen-test + // because quickcheck's runner uses `std::thread`, which isn't available on + // wasm32-unknown-unknown — so the cases below carry the same `#[cfg_attr]` + // attribute swap as the KAT and gate all three configurations (native + // aws-lc-rs, native RustCrypto, wasm32 RustCrypto in Node) on the same + // round-trip and failure-path behaviour. + + fn fixed_key() -> [u8; 32] { + [ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, + ] + } + + fn fixed_nonce() -> [u8; 12] { + [ + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, + ] + } + + fn roundtrip(plaintext: &[u8], aad: &[u8]) { + let key = fixed_key(); + let nonce = fixed_nonce(); + let cipher = CipherKey::new(&key).expect("key"); + + let mut buf = plaintext.to_vec(); + cipher.seal(&nonce, aad, &mut buf).expect("seal"); + + let pt_len = cipher.open(&nonce, aad, &mut buf).expect("open"); + assert_eq!(&buf[..pt_len], plaintext); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn roundtrip_no_aad() { + roundtrip(b"hello world", b""); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn roundtrip_with_aad() { + roundtrip(b"hello world", b"associated data"); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn roundtrip_empty_plaintext() { + roundtrip(b"", b"some aad"); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn roundtrip_multi_block_plaintext() { + // 200 bytes — spans multiple AES blocks (16B each) plus a partial tail, + // catching any block-boundary handling regression. + let pt: Vec = (0..200u8).collect(); + roundtrip(&pt, b"multi-block aad"); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn open_fails_with_wrong_aad() { + let key = fixed_key(); + let nonce = fixed_nonce(); + let cipher = CipherKey::new(&key).expect("key"); + + let mut buf = b"payload".to_vec(); + cipher.seal(&nonce, b"correct-aad", &mut buf).expect("seal"); + + let mut tampered = buf.clone(); + assert!( + cipher.open(&nonce, b"wrong-aad", &mut tampered).is_err(), + "open must reject mismatched AAD" + ); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn open_fails_with_wrong_key() { + let nonce = fixed_nonce(); + + let key_a = fixed_key(); + let mut key_b = fixed_key(); + key_b[0] ^= 0xff; + + let cipher_a = CipherKey::new(&key_a).expect("key a"); + let cipher_b = CipherKey::new(&key_b).expect("key b"); + + let mut buf = b"payload".to_vec(); + cipher_a.seal(&nonce, b"", &mut buf).expect("seal"); + + assert!( + cipher_b.open(&nonce, b"", &mut buf).is_err(), + "open must reject ciphertext sealed under a different key" + ); + } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn open_fails_with_tampered_ciphertext() { + let key = fixed_key(); + let nonce = fixed_nonce(); + let cipher = CipherKey::new(&key).expect("key"); + + let mut buf = b"payload".to_vec(); + cipher.seal(&nonce, b"", &mut buf).expect("seal"); + + // Flip a bit in the ciphertext (not the tag) — GCM authentication + // must catch this. + buf[0] ^= 0x01; + + assert!( + cipher.open(&nonce, b"", &mut buf).is_err(), + "open must reject ciphertext whose bytes have been modified" + ); + } +} diff --git a/packages/vitaminc-aead/src/aes/backend/aws_lc.rs b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs new file mode 100644 index 000000000..91e4a26d0 --- /dev/null +++ b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs @@ -0,0 +1,42 @@ +//! `aws-lc-rs` backend for AES-256-GCM. + +use aws_lc_rs::aead::{Aad as LcAad, LessSafeKey, Nonce as LcNonce, UnboundKey, AES_256_GCM}; +use crate::Unspecified; + +pub(crate) struct CipherKey(LessSafeKey); + +impl CipherKey { + pub(crate) fn new(key_bytes: &[u8; 32]) -> Result { + let unbound = UnboundKey::new(&AES_256_GCM, key_bytes.as_ref()).map_err(|_| Unspecified)?; + Ok(Self(LessSafeKey::new(unbound))) + } + + /// Encrypts `in_out` in place and appends the authentication tag. + pub(crate) fn seal( + &self, + nonce: &[u8], + aad: &[u8], + in_out: &mut Vec, + ) -> Result<(), Unspecified> { + let nonce = LcNonce::try_assume_unique_for_key(nonce).map_err(|_| Unspecified)?; + self.0 + .seal_in_place_append_tag(nonce, LcAad::from(aad), in_out) + .map_err(|_| Unspecified)?; + Ok(()) + } + + /// Decrypts `in_out` (ciphertext || tag) in place. Returns the plaintext + /// length — `in_out[..len]` is the plaintext after the call. + pub(crate) fn open( + &self, + nonce: &[u8], + aad: &[u8], + in_out: &mut [u8], + ) -> Result { + let nonce = LcNonce::try_assume_unique_for_key(nonce).map_err(|_| Unspecified)?; + self.0 + .open_in_place(nonce, LcAad::from(aad), in_out) + .map(|plaintext| plaintext.len()) + .map_err(|_| Unspecified) + } +} diff --git a/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs b/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs new file mode 100644 index 000000000..6f856b2ad --- /dev/null +++ b/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs @@ -0,0 +1,53 @@ +//! RustCrypto `aes-gcm` backend for AES-256-GCM. + +use crate::Unspecified; +use aes_gcm::aead::{AeadInPlace, KeyInit, Tag}; +use aes_gcm::{Aes256Gcm, Key, Nonce}; + +/// The AES-GCM tag length. This backend splits the tag off the buffer +/// itself; `aws-lc-rs` handles the tag internally, so only this backend +/// needs the constant. +const TAG_LEN: usize = 16; + +pub(crate) struct CipherKey(Aes256Gcm); + +impl CipherKey { + pub(crate) fn new(key_bytes: &[u8; 32]) -> Result { + let key = Key::::from_slice(key_bytes); + Ok(Self(Aes256Gcm::new(key))) + } + + /// Encrypts `in_out` in place and appends the authentication tag. + pub(crate) fn seal( + &self, + nonce: &[u8], + aad: &[u8], + in_out: &mut Vec, + ) -> Result<(), Unspecified> { + let nonce: &[u8; super::NONCE_LEN] = nonce.try_into().map_err(|_| Unspecified)?; + let nonce = Nonce::from_slice(nonce); + self.0 + .encrypt_in_place(nonce, aad, in_out) + .map_err(|_| Unspecified) + } + + /// Decrypts `in_out` (ciphertext || tag) in place. Returns the plaintext + /// length — `in_out[..len]` is the plaintext after the call. The tag bytes + /// at the tail are left untouched. + pub(crate) fn open( + &self, + nonce: &[u8], + aad: &[u8], + in_out: &mut [u8], + ) -> Result { + let plaintext_len = in_out.len().checked_sub(TAG_LEN).ok_or(Unspecified)?; + let nonce: &[u8; super::NONCE_LEN] = nonce.try_into().map_err(|_| Unspecified)?; + let nonce = Nonce::from_slice(nonce); + let (ciphertext, tag_bytes) = in_out.split_at_mut(plaintext_len); + let tag = Tag::::from_slice(tag_bytes); + self.0 + .decrypt_in_place_detached(nonce, aad, ciphertext, tag) + .map_err(|_| Unspecified)?; + Ok(plaintext_len) + } +} diff --git a/packages/vitaminc-aead/src/aes/cipher.rs b/packages/vitaminc-aead/src/aes/cipher.rs new file mode 100644 index 000000000..1fbc0a76e --- /dev/null +++ b/packages/vitaminc-aead/src/aes/cipher.rs @@ -0,0 +1,570 @@ +use super::backend::{CipherKey, NONCE_LEN}; +use super::Key; +use crate::seal::Cipher; +use crate::{ + CipherTextBuilder, Context, IntoAad, LocalCipherText, NonceGenerator, RandomNonceGenerator, + Unspecified, WIRE_VERSION, +}; +use vitaminc_protected::Protected; + +/// Implements AES-256-GCM. Backend is selected at compile time: +/// `aws-lc-rs` on native targets, `aes-gcm` (RustCrypto) on `wasm32`. +/// +/// This [`Cipher`] seals and opens one +/// tagged leaf under the AAD the walk derived for the leaf's place in the +/// tree, and nothing else. The container logic (element and entry AAD, +/// empty markers, the nothing-sealed refusal) lives once in +/// `crate::EncryptSink` and the opening walk, so a value encrypted +/// from static Rust seals the same tagged leaves a host value does and +/// every ciphertext is self-describing. Drive it with +/// [`crate::encrypt`] and [`crate::decrypt`]. +/// +/// The nonce generator is a `RefCell`, so the cipher is `!Sync`: it is +/// used from one thread at a time. +/// +/// ```compile_fail,E0277 +/// fn assert_sync() {} +/// assert_sync::(); +/// ``` +pub struct Aes256Cipher { + pub(crate) nonce_generator: RandomNonceGenerator, + pub(crate) key: CipherKey, +} + +impl Aes256Cipher { + /// Construct a new AES-256-GCM cipher bound to the given [`Key`]. + /// + /// A fresh random nonce generator is initialised for each cipher instance. + /// Returns an error if the platform RNG cannot be seeded or the key cannot + /// be loaded into the backend. + pub fn new(key: &Key) -> Result { + Ok(Self { + nonce_generator: RandomNonceGenerator::init()?, + key: key.cipher_key()?, + }) + } +} + +/// Seal one leaf: `version(1) ‖ nonce ‖ ciphertext ‖ tag`, with the wire +/// version bound into the AAD via `Context::for_leaf`. +/// +pub(crate) fn seal_leaf<'a, A>( + cipher: &Aes256Cipher, + data: Protected>, + aad: A, +) -> Result +where + A: IntoAad<'a>, +{ + let nonce = cipher.nonce_generator.generate()?; + let nonce_bytes: [u8; NONCE_LEN] = nonce.as_ref().try_into().map_err(|_| Unspecified)?; + // Outermost derivation: bind the wire version the builder prefixes to + // the stored leaf — see `Context::for_leaf`. + let aad = aad.into_aad().for_leaf(WIRE_VERSION); + + CipherTextBuilder::new() + .append_nonce(nonce) + .append_target_plaintext(data) + .accepts_ciphertext_and_tag_ok(|mut buf| { + cipher + .key + .seal(&nonce_bytes, aad.as_bytes(), &mut buf) + .map(|()| buf) + }) + .build() +} + +/// Open one leaf sealed by [`seal_leaf`]: checks the wire version before +/// parsing, then verifies with the same `Context::for_leaf` derivation. +/// Only the current wire version opens. +pub(crate) fn open_leaf<'a, A>( + cipher: &Aes256Cipher, + ct: LocalCipherText, + aad: A, +) -> Result>, Unspecified> +where + A: IntoAad<'a>, +{ + // `read_version_in` rejects any other wire version before parsing; the + // version read is *also* bound under the tag (`for_leaf`, mirroring the + // seal side), so a relabeled byte that parses still fails. + let (version, reader) = ct.into_reader().read_version_in(&[WIRE_VERSION])?; + let (nonce, reader) = reader.read_nonce::()?; + let nonce_bytes = nonce.into_inner(); + let aad = aad.into_aad().for_leaf(version); + + reader + .accepts_plaintext_ok(|data| cipher.key.open(&nonce_bytes, aad.as_bytes(), data)) + .read() +} + +impl Cipher for Aes256Cipher { + type Leaf = LocalCipherText; + type Error = Unspecified; + + fn seal( + &self, + plaintext: Protected>, + aad: &Context<'_>, + ) -> Result { + seal_leaf(self, plaintext, aad.clone()) + } + + fn open( + &self, + leaf: LocalCipherText, + aad: &Context<'_>, + ) -> Result>, Unspecified> { + open_leaf(self, leaf, aad.clone()) + } +} + +// Split cfgs (not `all(test, …)`) so cargo-mutants recognises the test +// module and skips it. The property tests draw random keys, which the +// wasm32 test harness cannot seed. +#[cfg(test)] +#[cfg(not(target_arch = "wasm32"))] +#[allow(clippy::unwrap_used)] +mod test { + use super::super::key::tests::DifferingKeyPair; + use super::*; + use crate::{decrypt, encrypt, CipherText, DecryptError, Node}; + use quickcheck_macros::quickcheck; + use std::collections::HashMap; + use vitaminc_protected::Controlled; + + fn cipher(key: &Key) -> Aes256Cipher { + Aes256Cipher::new(key).expect("cipher") + } + + fn leaf_of(node: Node) -> LocalCipherText { + match node { + CipherText::Single(leaf) => leaf, + other => panic!("expected a single leaf, got {other:?}"), + } + } + + mod leaf_paths { + //! The sink-based `Cipher` seals the same leaf bytes as `seal_leaf`, + //! so a leaf from either path opens through the other. + use super::*; + + #[test] + fn a_leaf_sealed_by_the_cipher_opens_through_open_leaf() { + let cipher = cipher(&Key::from([3u8; 32])); + let aad = Context::from_encoded(b"ctx".as_slice()); + let leaf = cipher + .seal(Protected::new(b"\x04hi".to_vec()), &aad) + .unwrap(); + let opened = open_leaf(&cipher, leaf, aad).unwrap(); + assert_eq!(opened.risky_unwrap(), b"\x04hi"); + } + + #[test] + fn a_leaf_sealed_by_seal_leaf_opens_through_the_cipher() { + let cipher = cipher(&Key::from([3u8; 32])); + let aad = Context::from_encoded(b"ctx".as_slice()); + let leaf = seal_leaf(&cipher, Protected::new(b"\x04hi".to_vec()), aad.clone()).unwrap(); + let opened = Cipher::open(&cipher, leaf, &aad).unwrap(); + assert_eq!(opened.risky_unwrap(), b"\x04hi"); + } + + #[test] + fn the_cipher_refuses_a_leaf_under_another_aad() { + let cipher = cipher(&Key::from([3u8; 32])); + let leaf = cipher + .seal( + Protected::new(b"\x04hi".to_vec()), + &Context::from_encoded(b"right".as_slice()), + ) + .unwrap(); + assert!( + Cipher::open(&cipher, leaf, &Context::from_encoded(b"wrong".as_slice())).is_err() + ); + } + } + + // Round trips through the whole path, over random keys and values. + + #[quickcheck] + fn roundtrip_string(key: Key, plaintext: String) -> bool { + let cipher = cipher(&key); + let ct = encrypt(plaintext.clone(), &cipher, ()).unwrap(); + let back: String = decrypt(&cipher, ct, ()).unwrap(); + back == plaintext + } + + #[quickcheck] + fn roundtrip_u32(key: Key, plaintext: u32) -> bool { + let cipher = cipher(&key); + let ct = encrypt(plaintext, &cipher, ()).unwrap(); + let back: u32 = decrypt(&cipher, ct, ()).unwrap(); + back == plaintext + } + + #[quickcheck] + fn roundtrip_byte_array(key: Key, plaintext: [u8; 16]) -> bool { + let cipher = cipher(&key); + let ct = encrypt(plaintext, &cipher, ()).unwrap(); + let back: [u8; 16] = decrypt(&cipher, ct, ()).unwrap(); + back == plaintext + } + + #[quickcheck] + fn roundtrip_vec_of_strings_with_aad(key: Key, plaintext: Vec) -> bool { + let cipher = cipher(&key); + let ct = encrypt(plaintext.clone(), &cipher, "rows").unwrap(); + let back: Vec = decrypt(&cipher, ct, "rows").unwrap(); + back == plaintext + } + + #[quickcheck] + fn roundtrip_option(key: Key, plaintext: Option) -> bool { + let cipher = cipher(&key); + let ct = encrypt(plaintext.clone(), &cipher, "opt").unwrap(); + let back: Option = decrypt(&cipher, ct, "opt").unwrap(); + back == plaintext + } + + #[quickcheck] + fn roundtrip_protected_string(key: Key, plaintext: String) -> bool { + let cipher = cipher(&key); + let ct = encrypt(Protected::new(plaintext.clone()), &cipher, ()).unwrap(); + let back: Protected = decrypt(&cipher, ct, ()).unwrap(); + back.risky_unwrap() == plaintext + } + + #[test] + fn roundtrip_hashmap_with_aad() { + let cipher = cipher(&Key::from([1u8; 32])); + let mut map = HashMap::new(); + map.insert("name".to_string(), "Ada".to_string()); + map.insert("role".to_string(), "founder".to_string()); + let ct = encrypt(map.clone(), &cipher, "user:42").unwrap(); + let back: HashMap = decrypt(&cipher, ct, "user:42").unwrap(); + assert_eq!(back, map); + } + + #[test] + fn roundtrip_empty_composites_with_aad() { + let cipher = cipher(&Key::from([1u8; 32])); + let ct = encrypt(Vec::::new(), &cipher, "ctx").unwrap(); + assert!(matches!(ct, CipherText::EmptySequence(_))); + let back: Vec = decrypt(&cipher, ct, "ctx").unwrap(); + assert!(back.is_empty()); + let ct = encrypt(HashMap::::new(), &cipher, "ctx").unwrap(); + assert!(matches!(ct, CipherText::EmptyMap(_))); + let back: HashMap = decrypt(&cipher, ct, "ctx").unwrap(); + assert!(back.is_empty()); + } + + // The cipher refuses what it should. + + #[quickcheck] + fn decrypt_fails_with_wrong_aad(key: Key, plaintext: String) -> bool { + let cipher = cipher(&key); + let ct = encrypt(plaintext, &cipher, "right").unwrap(); + matches!( + decrypt::(&cipher, ct, "wrong"), + Err(DecryptError::Cipher(Unspecified)) + ) + } + + #[quickcheck] + fn decrypt_fails_with_wrong_key(keys: DifferingKeyPair, plaintext: String) -> bool { + let DifferingKeyPair(a, b) = keys; + let ct = encrypt(plaintext, &cipher(&a), ()).unwrap(); + decrypt::(&cipher(&b), ct, ()).is_err() + } + + #[test] + fn empty_composites_fail_with_wrong_aad() { + let cipher = cipher(&Key::from([2u8; 32])); + let ct = encrypt(Vec::::new(), &cipher, "right").unwrap(); + assert!(decrypt::, _, _>(&cipher, ct, "wrong").is_err()); + let ct = encrypt(HashMap::::new(), &cipher, "right").unwrap(); + assert!(decrypt::, _, _>(&cipher, ct, "wrong").is_err()); + } + + #[test] + fn empty_composite_markers_are_domain_separated() { + // The two markers seal the same empty plaintext; the AAD derivation + // is what tells them apart, so one cannot stand in for the other. + let cipher = cipher(&Key::from([42u8; 32])); + let CipherText::EmptySequence(seq_marker) = + encrypt(Vec::::new(), &cipher, "ctx").unwrap() + else { + panic!("expected an empty-sequence marker"); + }; + assert!(decrypt::, _, _>( + &cipher, + CipherText::EmptyMap(seq_marker), + "ctx" + ) + .is_err()); + let CipherText::EmptyMap(map_marker) = + encrypt(HashMap::::new(), &cipher, "ctx").unwrap() + else { + panic!("expected an empty-map marker"); + }; + assert!(decrypt::, _, _>( + &cipher, + CipherText::EmptySequence(map_marker), + "ctx" + ) + .is_err()); + } + + #[test] + fn single_rewrapped_as_sequence_fails_decryption() { + // The container shape is authenticated through the element AAD + // derivation: a top-level leaf is sealed against the bare AAD, a + // sequence element against `for_sequence_element` of it, so + // re-nesting `{Single}` as `Sequence([Single])` cannot get `["x"]` + // back where the app stored `"x"`. + let cipher = cipher(&Key::from([51u8; 32])); + let single = encrypt("x".to_string(), &cipher, ()).unwrap(); + let forged = CipherText::Sequence(vec![single]); + assert!(decrypt::, _, _>(&cipher, forged, ()).is_err()); + } + + #[test] + fn sequence_element_rehomed_to_top_level_fails_decryption() { + let cipher = cipher(&Key::from([52u8; 32])); + let CipherText::Sequence(mut items) = encrypt(vec!["x".to_string()], &cipher, ()).unwrap() + else { + panic!("expected a sequence"); + }; + let element = items.pop().unwrap(); + assert!(decrypt::(&cipher, element, ()).is_err()); + } + + #[test] + fn swapped_or_renamed_map_keys_fail_decryption() { + // Each map value is sealed against `Context::for_map_entry(aad, key)`, + // so key and value are inseparable. Leaves are not `Clone`, so each + // forgery starts from a fresh ciphertext. + let cipher = cipher(&Key::from([53u8; 32])); + let sealed = || { + let mut map = HashMap::new(); + map.insert("a".to_string(), "1".to_string()); + map.insert("b".to_string(), "2".to_string()); + match encrypt(map, &cipher, "ctx").unwrap() { + CipherText::Map(entries) => entries, + other => panic!("expected a map, got {other:?}"), + } + }; + let open = |entries| { + decrypt::, _, _>(&cipher, CipherText::Map(entries), "ctx") + }; + + let mut swapped = sealed(); + let (first, second) = (swapped[0].0.clone(), swapped[1].0.clone()); + swapped[0].0 = second; + swapped[1].0 = first; + assert!(open(swapped).is_err()); + + let mut renamed = sealed(); + for (key, _) in &mut renamed { + key.push('x'); + } + assert!(open(renamed).is_err()); + + // Order is not authenticated: the same entries reversed still open. + let mut reordered = sealed(); + reordered.reverse(); + let back = open(reordered).unwrap(); + assert_eq!(back["a"], "1"); + assert_eq!(back["b"], "2"); + } + + #[test] + fn every_leaf_carries_the_wire_version_prefix() { + // The version byte is the leaf format's first byte on every + // leaf-bearing node. `wire_version` is the keyless peek migration + // tooling relies on. + let cipher = cipher(&Key::from([54u8; 32])); + fn versions(node: &Node) -> Vec> { + match node { + CipherText::Single(l) | CipherText::EmptySequence(l) | CipherText::EmptyMap(l) => { + vec![l.wire_version()] + } + CipherText::Sequence(items) => items.iter().flat_map(versions).collect(), + CipherText::Map(entries) => entries.iter().flat_map(|(_, v)| versions(v)).collect(), + CipherText::Passthrough(_) => vec![], + } + } + let mut map = HashMap::new(); + map.insert("k".to_string(), "v".to_string()); + let nodes = [ + encrypt("single".to_string(), &cipher, ()).unwrap(), + encrypt(None::, &cipher, ()).unwrap(), + encrypt(Vec::::new(), &cipher, ()).unwrap(), + encrypt(HashMap::::new(), &cipher, ()).unwrap(), + encrypt(vec!["a".to_string(), "b".to_string()], &cipher, ()).unwrap(), + encrypt(map, &cipher, ()).unwrap(), + ]; + for node in &nodes { + let found = versions(node); + assert!(!found.is_empty()); + assert!(found.iter().all(|v| *v == Some(WIRE_VERSION))); + } + } + + #[test] + fn relabeled_wire_version_fails_decryption() { + // Flipping the version byte must fail — first at the parse check + // (unknown version), and even a version a future parser accepted + // would fail the tag, because the byte is bound into the leaf AAD + // via `Context::for_leaf`. + let cipher = cipher(&Key::from([55u8; 32])); + let leaf = leaf_of(encrypt("x".to_string(), &cipher, ()).unwrap()); + let mut bytes = leaf.as_ref().to_vec(); + bytes[0] ^= 0x02; + let relabeled = CipherText::Single(LocalCipherText::from(bytes)); + assert!(decrypt::(&cipher, relabeled, ()).is_err()); + } + + #[test] + fn tampering_any_byte_fails_decryption() { + let cipher = cipher(&Key::from([56u8; 32])); + let bytes = leaf_of(encrypt("hello".to_string(), &cipher, ()).unwrap()) + .as_ref() + .to_vec(); + for idx in 0..bytes.len() { + let mut tampered = bytes.clone(); + tampered[idx] ^= 1; + let node = CipherText::Single(LocalCipherText::from(tampered)); + assert!( + decrypt::(&cipher, node, ()).is_err(), + "tamper at byte {idx}" + ); + } + } + + #[test] + fn a_truncated_or_extended_leaf_fails_decryption() { + // A short read or a tag cut off in storage, and a stray byte on the + // end: every prefix of a sealed leaf and the leaf plus one byte fail + // closed, on both backends. + let cipher = cipher(&Key::from([58u8; 32])); + let bytes = leaf_of(encrypt("hello".to_string(), &cipher, ()).unwrap()) + .as_ref() + .to_vec(); + for len in 0..bytes.len() { + let node = CipherText::Single(LocalCipherText::from(bytes[..len].to_vec())); + assert!( + decrypt::(&cipher, node, ()).is_err(), + "truncated to {len} bytes" + ); + } + let mut extended = bytes.clone(); + extended.push(0); + let node = CipherText::Single(LocalCipherText::from(extended)); + assert!(decrypt::(&cipher, node, ()).is_err()); + } + + mod wire_versions { + //! New leaves are wire version 2. Version 1 leaves come from two + //! released writers that cannot be told apart: the `Value` path + //! sealed tagged scalars, `vitaminc-encrypt` 0.5.1's `Encrypt` path + //! sealed raw bytes. The cipher, and so the typed path, refuses + //! every version 1 leaf. + use super::*; + use crate::tags; + + /// Seal a leaf as the 0.5.1 `seal_leaf` did: version 1 in front, + /// and version 1 bound into the AAD. + fn seal_version_1( + cipher: &Aes256Cipher, + plaintext: &[u8], + aad: Context, + ) -> LocalCipherText { + let nonce = cipher.nonce_generator.generate().unwrap(); + let nonce_bytes: [u8; NONCE_LEN] = nonce.as_ref().try_into().unwrap(); + let mut buf = plaintext.to_vec(); + cipher + .key + .seal(&nonce_bytes, aad.for_leaf(1).as_bytes(), &mut buf) + .unwrap(); + let mut leaf = vec![1]; + leaf.extend_from_slice(&nonce_bytes); + leaf.extend(buf); + LocalCipherText::from(leaf) + } + + #[test] + fn a_new_leaf_is_wire_version_2() { + let cipher = cipher(&Key::from([62u8; 32])); + let leaf = leaf_of(encrypt("x", &cipher, ()).unwrap()); + assert_eq!(WIRE_VERSION, 2); + assert_eq!(leaf.wire_version(), Some(2)); + } + + #[test] + fn a_0_5_1_raw_string_leaf_is_not_read_as_a_different_string() { + // What 0.5.1's `encrypt(&key, "\nhello")` stored: raw UTF-8, + // no tag. `\n` is `tags::STRING`, so read as tagged it would + // come back as "hello". + let key = Key::from([7u8; 32]); + let cipher = cipher(&key); + let leaf = || seal_version_1(&cipher, b"\nhello", Context::empty()); + let typed = decrypt::(&cipher, CipherText::Single(leaf()), ()); + assert!(matches!(typed, Err(DecryptError::Cipher(_))), "{typed:?}"); + } + + #[test] + fn a_0_5_1_raw_bytes_leaf_is_not_read_as_different_bytes() { + let cipher = cipher(&Key::from([8u8; 32])); + let leaf = seal_version_1(&cipher, &[tags::BYTES, 1, 2, 3], Context::empty()); + let typed = decrypt::, _, _>(&cipher, CipherText::Single(leaf), ()); + assert!(matches!(typed, Err(DecryptError::Cipher(_))), "{typed:?}"); + } + + #[test] + fn the_cipher_refuses_a_tagged_version_1_leaf() { + let cipher = cipher(&Key::from([63u8; 32])); + let aad = Context::from_encoded(b"ctx".as_slice()); + let leaf = seal_version_1(&cipher, &[tags::STRING, b'h', b'i'], aad.clone()); + assert_eq!( + Cipher::open(&cipher, leaf, &aad).map(|_| ()), + Err(Unspecified) + ); + } + } + + #[quickcheck] + fn nonce_is_unique_across_encryptions(key: Key, plaintext: String) -> bool { + // Two encryptions of the same plaintext under the same cipher must + // produce different ciphertexts — each seal draws a fresh nonce. + // Running this as a property samples a fresh nonce pair per case. + let cipher = cipher(&key); + let a = leaf_of(encrypt(plaintext.clone(), &cipher, ()).unwrap()); + let b = leaf_of(encrypt(plaintext, &cipher, ()).unwrap()); + a.as_ref() != b.as_ref() && a.as_ref()[1..1 + NONCE_LEN] != b.as_ref()[1..1 + NONCE_LEN] + } + + #[test] + fn a_static_scalar_seals_the_same_leaf_plaintext_a_host_value_does() { + // A Rust `String` and a frame holding the same text open to the same + // tagged leaf plaintext, so there is one leaf format. + let cipher = cipher(&Key::from([57u8; 32])); + let aad = Context::from_encoded(b"ctx".as_slice()); + let frame = crate::to_frame("hi").unwrap(); + let from_frame = leaf_of( + encrypt( + crate::Frame::parse(frame.risky_ref()).unwrap(), + &cipher, + aad.clone(), + ) + .unwrap(), + ); + let from_rust = leaf_of(encrypt("hi".to_string(), &cipher, aad.clone()).unwrap()); + let opened_frame = Cipher::open(&cipher, from_frame, &aad).unwrap(); + let opened_rust = Cipher::open(&cipher, from_rust, &aad).unwrap(); + assert_eq!(opened_frame.risky_ref(), opened_rust.risky_ref()); + // The sealed leaf is the tagged text: `STRING` then the bytes, with + // no length prefix. + assert_eq!(opened_rust.risky_ref(), &[crate::tags::STRING, b'h', b'i']); + } +} diff --git a/packages/vitaminc-aead/src/aes/key.rs b/packages/vitaminc-aead/src/aes/key.rs new file mode 100644 index 000000000..eaa2568e8 --- /dev/null +++ b/packages/vitaminc-aead/src/aes/key.rs @@ -0,0 +1,74 @@ +use super::backend::CipherKey; +use crate::Unspecified; +use vitaminc_protected::{Controlled, Protected}; + +/// 256-bit key type for use with symmetric encryption algorithms like AES-256-GCM. +/// Vitaminc does not support smaller key sizes to ensure quantum security and compatibility with AWS-LC. +/// +/// A `Key` is deliberately not an [`Encrypt`](crate::Encrypt) +/// source or a [`Decrypt`](crate::typed::Decrypt) target. A +/// `Encrypt` walk hands each scalar to a [`Sink`](crate::Sink), +/// and any crate can write a sink, so it would be a way to copy the key +/// bytes out that a search for `risky_` does not find. +// SAFETY: Safe to implement Debug because the inner type is Protected, which does not leak sensitive data. +#[derive(Debug)] +#[cfg_attr(test, derive(Clone))] +pub struct Key(Protected<[u8; 32]>); + +impl Key { + pub(crate) fn cipher_key(&self) -> Result { + // SAFETY: the borrowed `&[u8; 32]` is consumed by `CipherKey::new` only + // for the duration of the constructor; the backend cipher-key handle + // holds an opaque copy thereafter, so no bare key material outlives this + // call. `self.0` stays owned by `Protected` and is wiped on drop. + CipherKey::new(self.0.risky_ref()) + } +} + +impl From<[u8; 32]> for Key { + fn from(key: [u8; 32]) -> Self { + Self(Protected::new(key)) + } +} + +// Quickcheck `Arbitrary` impls for the property tests in `cipher::test` — +// gated to non-wasm32 alongside their consumers (see comment in `cipher.rs`). +// Split cfgs (not `all(test, …)`) so cargo-mutants recognises the test module. +#[cfg(test)] +#[cfg(not(target_arch = "wasm32"))] +pub(crate) mod tests { + use super::*; + use quickcheck::Arbitrary; + + fn gen_array(g: &mut quickcheck::Gen) -> [u8; 32] { + let mut array = [0u8; 32]; + for byte in array.iter_mut() { + *byte = u8::arbitrary(g); + } + array + } + + impl quickcheck::Arbitrary for Key { + fn arbitrary(g: &mut quickcheck::Gen) -> Self { + Key::from(gen_array(g)) + } + } + + /// A pair of keys guaranteed to be distinct at generation time. Property + /// tests that depend on the keys differing (e.g. wrong-key rejection) use + /// this so they cannot be flaky on the astronomically unlikely event that + /// two independently random keys collide. + #[derive(Clone, Debug)] + pub(crate) struct DifferingKeyPair(pub Key, pub Key); + + impl quickcheck::Arbitrary for DifferingKeyPair { + fn arbitrary(g: &mut quickcheck::Gen) -> Self { + let raw_a = gen_array(g); + let mut raw_b = gen_array(g); + while raw_a == raw_b { + raw_b = gen_array(g); + } + Self(Key::from(raw_a), Key::from(raw_b)) + } + } +} diff --git a/packages/vitaminc-aead/src/aes/mod.rs b/packages/vitaminc-aead/src/aes/mod.rs new file mode 100644 index 000000000..86d73243e --- /dev/null +++ b/packages/vitaminc-aead/src/aes/mod.rs @@ -0,0 +1,25 @@ +//! AES-256-GCM: the [`Cipher`](crate::Cipher) that seals and opens +//! [`LocalCipherText`](crate::LocalCipherText) leaves. +//! +//! Each leaf is `version ‖ nonce ‖ ciphertext ‖ tag`, under a fresh random +//! 96-bit nonce, with the wire version bound into the leaf's AAD. +//! +//! The backend is chosen when the crate is built: `aws-lc-rs` on native +//! targets, and RustCrypto's `aes-gcm` on `wasm32`. Both produce the same +//! bytes for the same inputs. +//! +//! ```rust +//! use vitaminc_aead::aes::{Aes256Cipher, Key}; +//! use vitaminc_aead::{decrypt, encrypt}; +//! +//! let cipher = Aes256Cipher::new(&Key::from([0u8; 32])).unwrap(); +//! let sealed = encrypt("message", &cipher, "users:email").unwrap(); +//! let opened: String = decrypt(&cipher, sealed, "users:email").unwrap(); +//! assert_eq!(opened, "message"); +//! ``` +mod backend; +mod cipher; +mod key; + +pub use cipher::Aes256Cipher; +pub use key::Key; diff --git a/packages/vitaminc-aead/src/ciphertext/mod.rs b/packages/vitaminc-aead/src/ciphertext/mod.rs index 1060781d8..1e22c429a 100644 --- a/packages/vitaminc-aead/src/ciphertext/mod.rs +++ b/packages/vitaminc-aead/src/ciphertext/mod.rs @@ -85,7 +85,7 @@ mod tests { .accepts_ciphertext_and_tag_ok(|mut ciphertext| { ciphertext.copy_from_slice(&[2u8; 10]); ciphertext.extend([3u8; 16]); - Ok(ciphertext) + Ok::<_, ()>(ciphertext) }) .build()?; @@ -111,7 +111,7 @@ mod tests { .accepts_ciphertext_and_tag_ok(|mut ciphertext| { ciphertext.copy_from_slice(&[2u8; 10]); ciphertext.extend([3u8; 16]); - Ok(ciphertext) + Ok::<_, ()>(ciphertext) }) .build()?; @@ -129,7 +129,7 @@ mod tests { assert_eq!(&data[10..], [3u8; 16]); // Write in the same way as AWS-LC/Ring does data[..10].copy_from_slice(&[0u8; 10]); - Ok(10) + Ok::<_, ()>(10) }) .read()?; diff --git a/packages/vitaminc-aead/src/lib.rs b/packages/vitaminc-aead/src/lib.rs index 64e044960..f41775782 100644 --- a/packages/vitaminc-aead/src/lib.rs +++ b/packages/vitaminc-aead/src/lib.rs @@ -28,6 +28,9 @@ #![deny(clippy::unwrap_used, clippy::todo, unsafe_code, unused_imports)] #![doc = include_str!("../README.md")] mod aad; +#[cfg(feature = "aes")] +#[cfg_attr(docsrs, doc(cfg(feature = "aes")))] +pub mod aes; mod ciphertext; mod container; mod context; diff --git a/packages/vitaminc-aead/tests/aes_cipher.rs b/packages/vitaminc-aead/tests/aes_cipher.rs new file mode 100644 index 000000000..0c11f81ee --- /dev/null +++ b/packages/vitaminc-aead/tests/aes_cipher.rs @@ -0,0 +1,201 @@ +//! `Aes256Cipher` as the sink-based `Cipher`, driven through +//! `vitaminc_aead::encrypt` and `decrypt`: scalars, nested containers, +//! empty containers and passthrough round-trip through real AES-256-GCM, +//! and a wrong AAD or key fails at the cipher. + +use std::collections::BTreeMap; + +use vitaminc_aead::aes::{Aes256Cipher, Key}; +use vitaminc_aead::{ + decrypt, encrypt, CipherText, Decrypt, DecryptError, Encrypt, EncryptError, MapSink, Sink, + Unencryptable, +}; +use vitaminc_protected::{Controlled, Protected}; + +fn cipher() -> Aes256Cipher { + Aes256Cipher::new(&Key::from([42u8; 32])).expect("cipher") +} + +#[derive(Debug, Clone, PartialEq, Encrypt, Decrypt)] +struct Record { + #[aead(passthrough)] + id: u64, + name: String, + scores: Vec, + labels: BTreeMap, + nickname: Option, +} + +fn record() -> Record { + Record { + id: 7, + name: "Ada".into(), + scores: vec![1, 2, 3], + labels: BTreeMap::from([("role".to_string(), "founder".to_string())]), + nickname: None, + } +} + +mod given_a_scalar { + use super::*; + + #[test] + fn round_trips_through_aes() { + let cipher = cipher(); + let node = encrypt("hello".to_string(), &cipher, "ctx").expect("encrypt"); + assert!( + matches!(node, CipherText::Single(_)), + "a scalar seals as one leaf" + ); + let got: String = decrypt(&cipher, node, "ctx").expect("decrypt"); + assert_eq!(got, "hello"); + } + + #[test] + fn returns_a_cipher_error_under_the_wrong_aad() { + let cipher = cipher(); + let node = encrypt(42u32, &cipher, "right").expect("encrypt"); + let err = decrypt::(&cipher, node, "wrong").expect_err("wrong AAD"); + assert!(matches!(err, DecryptError::Cipher(_)), "got {err:?}"); + } + + #[test] + fn returns_a_cipher_error_under_the_wrong_key() { + let node = encrypt(42u32, &cipher(), "ctx").expect("encrypt"); + let other = Aes256Cipher::new(&Key::from([1u8; 32])).expect("cipher"); + let err = decrypt::(&other, node, "ctx").expect_err("wrong key"); + assert!(matches!(err, DecryptError::Cipher(_)), "got {err:?}"); + } +} + +mod given_a_nested_record { + use super::*; + + #[test] + fn round_trips_with_its_passthrough_in_the_clear() { + let cipher = cipher(); + let node = encrypt(record(), &cipher, "users").expect("encrypt"); + let CipherText::Map(entries) = &node else { + panic!("a struct seals as a map"); + }; + assert!( + entries + .iter() + .any(|(key, node)| key == "id" && matches!(node, CipherText::Passthrough(_))), + "the passthrough field is a cleartext entry" + ); + let got: Record = decrypt(&cipher, node, "users").expect("decrypt"); + assert_eq!(got, record()); + } + + #[test] + fn seals_empty_containers_as_authenticated_markers() { + let cipher = cipher(); + let empty = Record { + scores: Vec::new(), + labels: BTreeMap::new(), + ..record() + }; + let node = encrypt(empty.clone(), &cipher, "users").expect("encrypt"); + let CipherText::Map(entries) = &node else { + panic!("a struct seals as a map"); + }; + let shapes: BTreeMap<&str, &str> = entries + .iter() + .map(|(key, node)| { + let shape = match node { + CipherText::EmptySequence(_) => "empty-seq", + CipherText::EmptyMap(_) => "empty-map", + _ => "other", + }; + (key.as_str(), shape) + }) + .collect(); + assert_eq!(shapes["scores"], "empty-seq"); + assert_eq!(shapes["labels"], "empty-map"); + let got: Record = decrypt(&cipher, node, "users").expect("decrypt"); + assert_eq!(got, empty); + } + + #[test] + fn refuses_a_map_with_nothing_sealed() { + // The derive refuses this shape at compile time, so the source is + // written by hand: a map whose only entry is a passthrough. + struct OnlyPlain; + impl Encrypt for OnlyPlain { + fn visit(self, sink: S) -> Result { + let mut map = sink.map(Some(1))?; + map.entry("id")?.passthrough(&7u64)?; + map.end() + } + } + let err = encrypt(OnlyPlain, &cipher(), "ctx").expect_err("nothing sealed"); + assert!( + matches!( + err, + EncryptError::Shape(ref refusal) + if refusal.reason() == Unencryptable::MapHasNothingSealed + ), + "got {err:?}" + ); + } +} + +mod given_protected_bytes { + use super::*; + + #[test] + fn round_trips_without_leaving_the_wrapper() { + let cipher = cipher(); + let secret = Protected::new(vec![0xDEu8, 0xAD, 0xBE, 0xEF]); + let node = encrypt(secret, &cipher, "blob").expect("encrypt"); + let got: Protected> = decrypt(&cipher, node, "blob").expect("decrypt"); + assert_eq!(got.risky_unwrap(), vec![0xDE, 0xAD, 0xBE, 0xEF]); + } +} + +mod given_an_absent_fixed_width_value { + use super::*; + + /// The ciphertext length of the one leaf `value` seals as. + fn sealed_len(value: P) -> usize { + match encrypt(value, &cipher(), "ctx").expect("encrypt") { + CipherText::Single(leaf) => leaf.as_ref().len(), + other => panic!("not one leaf: {other:?}"), + } + } + + fn same_length(value: T) { + assert_eq!( + sealed_len(None::), + sealed_len(Some(value)), + "{}", + core::any::type_name::() + ); + } + + #[test] + fn seals_to_the_length_of_a_present_one() { + same_length(-1i8); + same_length(-1i16); + same_length(-1i32); + same_length(-1i64); + same_length(-1i128); + same_length(1u16); + same_length(1u32); + same_length(1u64); + same_length(1u128); + same_length(1.5f32); + same_length(1.5f64); + // A bool's plain null is already as long as a bool. + same_length(true); + } + + #[test] + fn round_trips_through_aes_as_none() { + let cipher = cipher(); + let node = encrypt(None::, &cipher, "ctx").expect("encrypt"); + let got: Option = decrypt(&cipher, node, "ctx").expect("decrypt"); + assert_eq!(got, None); + } +} From ca3376500c8137eac5bd45342a18fdf3bf852566 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 3 Dec 2026 10:25:02 +1100 Subject: [PATCH 02/25] refactor: stack-encrypt and its tests use vitaminc-aead's AES cipher 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. --- Cargo.lock | 37 +------- Cargo.toml | 3 +- languages/golang/auth/guest/Cargo.lock | 38 +------- languages/golang/encrypt/guest/Cargo.lock | 41 +-------- languages/golang/encrypt/guest/src/lib.rs | 2 +- .../packages/recipher-js/Cargo.lock | 41 +-------- .../value-napi/tests/addon/Cargo.lock | 17 +--- .../value-napi/tests/addon/Cargo.toml | 3 +- .../value-napi/tests/addon/src/lib.rs | 3 +- packages/eql/Cargo.lock | 38 +------- packages/eql/tests/encryption/Cargo.toml | 5 +- .../tests/encryption/tests/heap_hygiene.rs | 6 +- .../encryption/tests/opaque_json_bytes.rs | 2 +- packages/stack-auth/fuzz/Cargo.lock | 90 ++++--------------- packages/stack-encrypt/Cargo.toml | 3 +- packages/stack-encrypt/fuzz/Cargo.lock | 41 +-------- packages/stack-encrypt/src/cipher.rs | 6 +- packages/stack-encrypt/src/json/cascade.rs | 2 +- packages/stack-encrypt/src/json/derive.rs | 2 +- packages/stack-encrypt/src/json/mod.rs | 2 +- packages/stack-encrypt/src/lib.rs | 2 +- packages/stack-encrypt/tests/common/leaves.rs | 2 +- packages/stack-encrypt/tests/heap_hygiene.rs | 6 +- .../tests/json_leakage/profile.rs | 2 +- .../tests/json_leakage/simulator.rs | 2 +- packages/stack-kms/fuzz/Cargo.lock | 90 ++++--------------- 26 files changed, 75 insertions(+), 411 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 607ffad71..4dfac6a3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3665,7 +3665,6 @@ dependencies = [ "uuid", "vitaminc 0.10.0", "vitaminc-aead 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-hmac", "vitaminc-normalize", "vitaminc-ore", @@ -4511,10 +4510,10 @@ checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ "vitaminc-aead 0.5.1", "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -4525,10 +4524,8 @@ checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ "vitaminc-aead 0.10.0", "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -4631,20 +4628,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-hmac" version = "0.10.0" @@ -4829,22 +4812,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.18", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "wait-timeout" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index eb443de30..98419fe3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -155,14 +155,13 @@ web-time = "1.1" zeroize = { version = "1.8.1", features = ["derive"] } # This is needed because lock_api 0.4.6 was breaking things and the branch forces the use of 0.4.12 temp-env = { git = "https://github.com/cipherstash/temp-env", branch = "main" } -vitaminc = { version = "0.10.0", features = ["random", "protected", "encrypt"] } +vitaminc = { version = "0.10.0", features = ["random", "protected"] } # The AEAD crates live in this repository (packages/vitaminc-aead*, # packages/recipher-frame). vitaminc-aead = { path = "./packages/vitaminc-aead", version = "0.10.0" } # The transport frame and ciphertext codec every language binding carries # across its FFI boundary. Optional in stack-encrypt (the `dynamic` feature). recipher-frame = { path = "./packages/recipher-frame", version = "0.10.0" } -vitaminc-encrypt = "0.10.0" vitaminc-hmac = "0.10.0" # Normalized equality terms (Unicode 16 NFC text, one integer encoding for # every width), which `vitaminc-prf`'s `normalize` feature derives over. diff --git a/languages/golang/auth/guest/Cargo.lock b/languages/golang/auth/guest/Cargo.lock index a3cee53c5..90f14b9ad 100644 --- a/languages/golang/auth/guest/Cargo.lock +++ b/languages/golang/auth/guest/Cargo.lock @@ -2262,10 +2262,10 @@ checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ "vitaminc-aead 0.5.1", "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -2274,12 +2274,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -2366,20 +2362,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-protected" version = "0.5.1" @@ -2505,22 +2487,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.20", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/languages/golang/encrypt/guest/Cargo.lock b/languages/golang/encrypt/guest/Cargo.lock index 2c958fc08..c6e996906 100644 --- a/languages/golang/encrypt/guest/Cargo.lock +++ b/languages/golang/encrypt/guest/Cargo.lock @@ -2272,7 +2272,6 @@ dependencies = [ "uuid", "vitaminc 0.10.0", "vitaminc-aead 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-hmac", "vitaminc-normalize", "vitaminc-ore", @@ -2826,10 +2825,10 @@ checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ "vitaminc-aead 0.5.1", "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -2838,12 +2837,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -2865,6 +2860,8 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-util", "jiff", @@ -2932,20 +2929,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-hmac" version = "0.10.0" @@ -3130,22 +3113,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.20", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/languages/golang/encrypt/guest/src/lib.rs b/languages/golang/encrypt/guest/src/lib.rs index 36e33a811..2b52938ce 100644 --- a/languages/golang/encrypt/guest/src/lib.rs +++ b/languages/golang/encrypt/guest/src/lib.rs @@ -80,7 +80,7 @@ //! `stack_guest_abi`'s, and [`io`] is how this guest's steps cross; //! [`abi`]'s module docs give this guest's contract on top of them. //! -//! On wasm32 `vitaminc-encrypt` uses its pure-Rust (RustCrypto `aes-gcm`) +//! On wasm32 vitaminc-aead's `aes` cipher uses its pure-Rust (RustCrypto `aes-gcm`) //! backend; the trade-offs are documented there. Values cross the boundary //! as vitaminc transport frames and ciphertext trees in vitaminc's //! ciphertext codec (`recipher_frame` — FFI encodings, not a storage diff --git a/languages/typescript/packages/recipher-js/Cargo.lock b/languages/typescript/packages/recipher-js/Cargo.lock index eb3a9efb8..e538eb4b4 100644 --- a/languages/typescript/packages/recipher-js/Cargo.lock +++ b/languages/typescript/packages/recipher-js/Cargo.lock @@ -3135,7 +3135,6 @@ dependencies = [ "uuid", "vitaminc 0.10.0", "vitaminc-aead 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-hmac", "vitaminc-normalize", "vitaminc-ore", @@ -3747,10 +3746,10 @@ checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ "vitaminc-aead 0.5.1", "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -3759,12 +3758,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -3786,6 +3781,8 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-util", "jiff", @@ -3853,20 +3850,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-hmac" version = "0.10.0" @@ -4051,22 +4034,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.21", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "walkdir" version = "2.5.1" diff --git a/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.lock b/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.lock index fdd0c938b..1a51b9084 100644 --- a/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.lock +++ b/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.lock @@ -890,7 +890,6 @@ dependencies = [ "recipher-value-napi", "serde_json", "vitaminc-aead", - "vitaminc-encrypt", "vitaminc-protected", ] @@ -1128,6 +1127,8 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-util", "jiff", @@ -1160,20 +1161,6 @@ dependencies = [ "vitaminc-protected", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead", - "vitaminc-protected", - "vitaminc-random", - "zeroize", -] - [[package]] name = "vitaminc-protected" version = "0.10.0" diff --git a/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.toml b/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.toml index eb1609c99..54162f5e1 100644 --- a/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.toml +++ b/languages/typescript/packages/recipher-js/value-napi/tests/addon/Cargo.toml @@ -18,9 +18,8 @@ napi-derive = "3" serde_json = "1" # For a refusal's code. The code is the refusal's diagnostic code. miette = "7.5.0" -vitaminc-aead = { version = "0.10.0", features = ["rust_decimal"] } +vitaminc-aead = { version = "0.10.0", features = ["rust_decimal", "aes"] } recipher-value-napi = { path = "../.." } -vitaminc-encrypt = "0.10.0" vitaminc-protected = "0.10.0" [build-dependencies] diff --git a/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs b/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs index 9221257f4..3452bb51b 100644 --- a/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs +++ b/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs @@ -13,7 +13,8 @@ use vitaminc_aead::{ EncryptError, Float, Frame, Int, Logical, MapSink, Node, PassthroughFrame, Physical, SeqSink, Sink, TimeUnit, }; -use vitaminc_encrypt::{Aes256Cipher, Key, LocalCipherText}; +use vitaminc_aead::aes::{Aes256Cipher, Key}; +use vitaminc_aead::LocalCipherText; use vitaminc_protected::{Controlled, Protected}; /// The wrapper classes, exported so JavaScript can make instances with diff --git a/packages/eql/Cargo.lock b/packages/eql/Cargo.lock index 53fef182a..3aa6c47bf 100644 --- a/packages/eql/Cargo.lock +++ b/packages/eql/Cargo.lock @@ -1227,7 +1227,6 @@ dependencies = [ "tokio", "uuid", "vitaminc-aead 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "zeroize", ] @@ -4235,7 +4234,6 @@ dependencies = [ "uuid", "vitaminc 0.10.0", "vitaminc-aead 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-hmac", "vitaminc-normalize", "vitaminc-ore", @@ -5048,12 +5046,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -5088,6 +5082,8 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-util", "jiff", @@ -5169,20 +5165,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-hmac" version = "0.10.0" @@ -5434,22 +5416,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.20", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vsimd" version = "0.8.0" diff --git a/packages/eql/tests/encryption/Cargo.toml b/packages/eql/tests/encryption/Cargo.toml index 5265d9886..3f6fbc8c9 100644 --- a/packages/eql/tests/encryption/Cargo.toml +++ b/packages/eql/tests/encryption/Cargo.toml @@ -50,11 +50,10 @@ stack-encrypt = { path = "../../../stack-encrypt", default-features = false, fea # `plaintext::Sink`, for a plaintext type with its own `Encrypt` impl; and # jiff's and rust_decimal's own sources, which seal the leaf a date, # timestamp or decimal from any other producer seals. -vitaminc-aead = { version = "0.10.0", features = ["jiff", "rust_decimal"] } -# The AES cipher and protected buffer of the leaves stack-encrypt seals: +vitaminc-aead = { version = "0.10.0", features = ["jiff", "rust_decimal", "aes"] } +# `aes` is the AES cipher of the leaves stack-encrypt seals: # tests/opaque_json_bytes.rs opens a stored leaf with a kept test key to pin # the plaintext that was sealed. -vitaminc-encrypt = "0.10.0" vitaminc-protected = "0.10.0" jiff = "1.0.0" rust_decimal = { version = "1", default-features = false, features = ["std"] } diff --git a/packages/eql/tests/encryption/tests/heap_hygiene.rs b/packages/eql/tests/encryption/tests/heap_hygiene.rs index 0d5520fb0..968f6df96 100644 --- a/packages/eql/tests/encryption/tests/heap_hygiene.rs +++ b/packages/eql/tests/encryption/tests/heap_hygiene.rs @@ -11,8 +11,8 @@ //! pending work is dropped before its keys arrive. stack-encrypt's //! `tests/heap_hygiene.rs` holds its dynamic paths the same way. //! -//! One free is excluded by name: vitaminc-encrypt 0.6.0's aws-lc backend -//! (`backend::aws_lc::CipherKey::seal`, native builds only) frees an unwiped +//! One free is excluded by name: vitaminc-aead's aws-lc backend +//! (`aes::backend::aws_lc::CipherKey::seal`, native builds only) frees an unwiped //! plaintext buffer on every seal; that is vitaminc's to fix. It is counted //! and printed, never silent, and every other free on those paths is still //! watched. The spy recognises these frees by their backtrace, so a build @@ -62,7 +62,7 @@ static EXCLUDED: Mutex<[usize; 1]> = Mutex::new([0; 1]); /// The frames whose frees are excluded, each with what it is (see the module /// docs): vitaminc's aws-lc seal. const EXCLUSIONS: [(&str, &str); 1] = [( - "vitaminc_encrypt::backend::aws_lc::CipherKey::seal", + "vitaminc_aead::aes::backend::aws_lc::CipherKey::seal", "vitaminc's aws-lc seal", )]; diff --git a/packages/eql/tests/encryption/tests/opaque_json_bytes.rs b/packages/eql/tests/encryption/tests/opaque_json_bytes.rs index 073b0717b..888a88023 100644 --- a/packages/eql/tests/encryption/tests/opaque_json_bytes.rs +++ b/packages/eql/tests/encryption/tests/opaque_json_bytes.rs @@ -36,7 +36,7 @@ use stack_kms::{ use uuid::Uuid; use vitaminc_aead::seal::Cipher; use vitaminc_aead::{Context, FrameWriter, IntoContext, LocalCipherText, Unspecified}; -use vitaminc_encrypt::{Aes256Cipher, Key as AesKey}; +use vitaminc_aead::aes::{Aes256Cipher, Key as AesKey}; use vitaminc_protected::{Buffer, Controlled as _, Protected}; const SEED: [u8; 32] = *b"eql opaque json bytes v1 "; diff --git a/packages/stack-auth/fuzz/Cargo.lock b/packages/stack-auth/fuzz/Cargo.lock index c445c934d..913c40795 100644 --- a/packages/stack-auth/fuzz/Cargo.lock +++ b/packages/stack-auth/fuzz/Cargo.lock @@ -3173,12 +3173,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ - "vitaminc-aead 0.5.1", - "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-aead", + "vitaminc-context", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -3187,12 +3187,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -3203,28 +3199,13 @@ checksum = "62cacd4dae485e98cfe5407e919187a8468dd933ea4234be5115b7d13a30f3c6" dependencies = [ "bytes", "serde", - "vitaminc-aead-derive 0.5.1", - "vitaminc-context 0.5.1", + "vitaminc-aead-derive", + "vitaminc-context", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", "zeroize", ] -[[package]] -name = "vitaminc-aead" -version = "0.10.0" -dependencies = [ - "bytes", - "futures-util", - "serde", - "thiserror 2.0.18", - "vitaminc-aead-derive 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-aead-derive" version = "0.5.1" @@ -3236,15 +3217,6 @@ dependencies = [ "syn 3.0.3", ] -[[package]] -name = "vitaminc-aead-derive" -version = "0.10.0" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.3", -] - [[package]] name = "vitaminc-context" version = "0.5.1" @@ -3255,16 +3227,6 @@ dependencies = [ "vitaminc-protected 0.5.1", ] -[[package]] -name = "vitaminc-context" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431a7fb023688dba855e52b9c4e44c942418dde8ea08a2b115cf6a7f762fa5b9" -dependencies = [ - "mutants", - "vitaminc-protected 0.10.0", -] - [[package]] name = "vitaminc-encrypt" version = "0.5.1" @@ -3273,26 +3235,12 @@ checksum = "9fbd0e1748055e381e02033e08af385de879c4dcf32e0f6739ac0c0cf0c6f13d" dependencies = [ "aes-gcm", "aws-lc-rs", - "vitaminc-aead 0.5.1", + "vitaminc-aead", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-protected" version = "0.5.1" @@ -3418,22 +3366,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.18", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "walkdir" version = "2.5.0" @@ -4272,3 +4204,11 @@ name = "zmij" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7" + +[[patch.unused]] +name = "vitaminc-aead" +version = "0.10.0" + +[[patch.unused]] +name = "vitaminc-aead-derive" +version = "0.10.0" diff --git a/packages/stack-encrypt/Cargo.toml b/packages/stack-encrypt/Cargo.toml index 4f617651a..28d770c1c 100644 --- a/packages/stack-encrypt/Cargo.toml +++ b/packages/stack-encrypt/Cargo.toml @@ -40,8 +40,7 @@ stack-encrypt-jsonpath = { path = "../stack-encrypt-jsonpath", version = "0.3.0" # `NonEmpty::with`, `From for NonEmpty` (#314) and the parts view # (#318), all of which this crate relies on. All five must share one # version or the aead crate is duplicated. -vitaminc-aead = { workspace = true } -vitaminc-encrypt = { workspace = true } +vitaminc-aead = { workspace = true, features = ["aes"] } vitaminc-hmac = { workspace = true } # Equality terms derive over `vitaminc-normalize`'s encoding of a value # (the workspace turns on vitaminc-prf's `normalize` feature): one term per diff --git a/packages/stack-encrypt/fuzz/Cargo.lock b/packages/stack-encrypt/fuzz/Cargo.lock index 923524166..3641d40fa 100644 --- a/packages/stack-encrypt/fuzz/Cargo.lock +++ b/packages/stack-encrypt/fuzz/Cargo.lock @@ -2210,7 +2210,6 @@ dependencies = [ "uuid", "vitaminc 0.10.0", "vitaminc-aead 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-hmac", "vitaminc-normalize", "vitaminc-ore", @@ -2714,10 +2713,10 @@ checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ "vitaminc-aead 0.5.1", "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -2726,12 +2725,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -2753,6 +2748,8 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-util", "jiff", @@ -2820,20 +2817,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-hmac" version = "0.10.0" @@ -3018,22 +3001,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.18", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/packages/stack-encrypt/src/cipher.rs b/packages/stack-encrypt/src/cipher.rs index b6d2c0fe7..668977174 100644 --- a/packages/stack-encrypt/src/cipher.rs +++ b/packages/stack-encrypt/src/cipher.rs @@ -64,7 +64,7 @@ //! Each leaf ([`SealedValue`]) stores the ZeroKMS keyset id, `iv` and key //! `tag` — enough to retrieve the data key — plus a vitaminc //! [`LocalCipherText`] sealed under that key by -//! [`vitaminc_encrypt::Aes256Cipher`] (AES-256-GCM via vitaminc's backend: +//! [`vitaminc_aead::aes::Aes256Cipher`] (AES-256-GCM via vitaminc's backend: //! `aws-lc-rs` on native, RustCrypto on wasm32; vitaminc's own random nonce //! and versioned leaf layout). The leaf AAD is the labelled derivation //! `leaf_aad` (private): @@ -103,12 +103,12 @@ use stack_kms::{EnvKeyProvider, KeyProvider, StackKms, StackKmsBuilder}; #[cfg(all(feature = "http", not(target_arch = "wasm32")))] use stack_kms::{FallbackKeyProvider, ProfileKeyProvider}; use uuid::Uuid; +use vitaminc_aead::aes::{Aes256Cipher, Key as AesKey}; use vitaminc_aead::seal::seal_all; use vitaminc_aead::{ Cipher, CipherText, Context, DecodeError, Decrypt, DecryptError, Encrypt, IntoAad, IntoContext, LocalCipherText, Node, Pending, Unspecified, }; -use vitaminc_encrypt::{Aes256Cipher, Key as AesKey}; use vitaminc_protected::Protected; use crate::credential::KeySource; @@ -1719,7 +1719,7 @@ pub struct SealedValue { /// ZeroKMS key tag: required to retrieve the key, and bound into the /// leaf's AAD so the ciphertext is tied to its data key. tag: Vec, - /// The leaf sealed by [`vitaminc_encrypt::Aes256Cipher`] under the data + /// The leaf sealed by [`vitaminc_aead::aes::Aes256Cipher`] under the data /// key: `version ‖ nonce ‖ ciphertext ‖ gcm_tag`. ciphertext: LocalCipherText, } diff --git a/packages/stack-encrypt/src/json/cascade.rs b/packages/stack-encrypt/src/json/cascade.rs index 8cbb507a2..927a3a204 100644 --- a/packages/stack-encrypt/src/json/cascade.rs +++ b/packages/stack-encrypt/src/json/cascade.rs @@ -124,8 +124,8 @@ pub(crate) fn children_of( #[cfg(test)] mod tests { use super::*; + use vitaminc_aead::aes::{Aes256Cipher, Key}; use vitaminc_aead::{Cipher, Context, LocalCipherText}; - use vitaminc_encrypt::{Aes256Cipher, Key}; use vitaminc_protected::Protected; #[test] diff --git a/packages/stack-encrypt/src/json/derive.rs b/packages/stack-encrypt/src/json/derive.rs index b3e6944d8..ba15bdec4 100644 --- a/packages/stack-encrypt/src/json/derive.rs +++ b/packages/stack-encrypt/src/json/derive.rs @@ -15,8 +15,8 @@ use serde_json::{Map, Number, Value}; use sha2::{Digest, Sha256}; use uuid::Uuid; use vitaminc::random::SafeRand; +use vitaminc_aead::aes::{Aes256Cipher, Key as AesKey}; use vitaminc_aead::{Cipher, Context, IntoAad, IntoContext, LocalCipherText}; -use vitaminc_encrypt::{Aes256Cipher, Key as AesKey}; use vitaminc_hmac::HmacSha256Prf; use vitaminc_prf::{BlockVisitor, IntoPrfContext, PrfValue}; use vitaminc_protected::{AsProtectedRef, Controlled, Protected}; diff --git a/packages/stack-encrypt/src/json/mod.rs b/packages/stack-encrypt/src/json/mod.rs index 21aec47f7..21c92940f 100644 --- a/packages/stack-encrypt/src/json/mod.rs +++ b/packages/stack-encrypt/src/json/mod.rs @@ -88,7 +88,7 @@ //! # Nonces and tokens //! //! - **Nonces are random.** Every entry is sealed through the engine's one -//! AEAD path (`vitaminc-encrypt`'s `Aes256Cipher`, a fresh random 96-bit +//! AEAD path (vitaminc-aead's `Aes256Cipher`, a fresh random 96-bit //! nonce per seal, carried in the ciphertext), so there is one leaf //! cipher in the crate. Uniqueness under one document key is //! probabilistic rather than structural: at `N` entries the collision diff --git a/packages/stack-encrypt/src/lib.rs b/packages/stack-encrypt/src/lib.rs index 077268c39..77bece74d 100644 --- a/packages/stack-encrypt/src/lib.rs +++ b/packages/stack-encrypt/src/lib.rs @@ -688,7 +688,7 @@ endpoint — are `StackKmsBuilder`'s, and the two keyset-cache knobs are //! //! A `KeysetCipher` seals through a vitaminc `Cipher`; everything vitaminc //! can encrypt remains available through [`KeysetCipher::encrypt_tree`]. Its data model, AAD derivations and -//! the leaf wire format are vitaminc's (`vitaminc_encrypt::Aes256Cipher`, AES-256-GCM under a random +//! the leaf wire format are vitaminc's (`vitaminc_aead::aes::Aes256Cipher`, AES-256-GCM under a random //! per-leaf nonce vitaminc generates itself). The ZeroKMS `iv` a [`SealedValue`] //! carries is *not* that nonce: it identifies the data key, and is sent back to //! ZeroKMS with the key `tag` to re-derive it — under the same [`Descriptor`] diff --git a/packages/stack-encrypt/tests/common/leaves.rs b/packages/stack-encrypt/tests/common/leaves.rs index 41a4a276d..b91e13b50 100644 --- a/packages/stack-encrypt/tests/common/leaves.rs +++ b/packages/stack-encrypt/tests/common/leaves.rs @@ -20,9 +20,9 @@ use stack_kms::{ IndexKeySource, RetrieveKeyPayload, UnverifiedContext, }; use uuid::Uuid; +use vitaminc_aead::aes::{Aes256Cipher, Key as AesKey}; use vitaminc_aead::seal::Cipher; use vitaminc_aead::{Context, FrameWriter, IntoContext, LocalCipherText, Unspecified}; -use vitaminc_encrypt::{Aes256Cipher, Key as AesKey}; use vitaminc_protected::{Buffer, Controlled as _, Protected}; use super::{hex, DeterministicSource}; diff --git a/packages/stack-encrypt/tests/heap_hygiene.rs b/packages/stack-encrypt/tests/heap_hygiene.rs index f83a550a5..375a5d403 100644 --- a/packages/stack-encrypt/tests/heap_hygiene.rs +++ b/packages/stack-encrypt/tests/heap_hygiene.rs @@ -18,8 +18,8 @@ //! guest's linear memory after the fact, where allocator metadata and reuse //! have already overwritten most freed chunks, so it cannot see one. //! -//! One free is excluded by name: vitaminc-encrypt 0.6.0's aws-lc backend -//! (`backend::aws_lc::CipherKey::seal`, native builds only) frees an unwiped +//! One free is excluded by name: vitaminc-aead's aws-lc backend +//! (`aes::backend::aws_lc::CipherKey::seal`, native builds only) frees an unwiped //! plaintext buffer on every seal. That is vitaminc's to fix, not this //! crate's; the spy reports how many it skipped, and recognises them by //! their backtrace, so a build without symbols fails rather than passes. @@ -113,7 +113,7 @@ static COUNT_SIZE: AtomicUsize = AtomicUsize::new(0); static COUNTED: AtomicUsize = AtomicUsize::new(0); /// The vitaminc frame whose free is excluded (see the module docs). -const UPSTREAM_SEAL: &str = "vitaminc_encrypt::backend::aws_lc::CipherKey::seal"; +const UPSTREAM_SEAL: &str = "vitaminc_aead::aes::backend::aws_lc::CipherKey::seal"; /// Whether the `len` bytes at `ptr` hold [`MARK`]. A freed block can hold /// bytes Rust never initialised (a `Vec`'s spare capacity, a struct's diff --git a/packages/stack-encrypt/tests/json_leakage/profile.rs b/packages/stack-encrypt/tests/json_leakage/profile.rs index 4801bcbb7..673b0acd8 100644 --- a/packages/stack-encrypt/tests/json_leakage/profile.rs +++ b/packages/stack-encrypt/tests/json_leakage/profile.rs @@ -49,7 +49,7 @@ pub use super::chain::Rule; /// What every entry's ciphertext adds to its plaintext: the frame's version /// byte, the 96-bit random nonce and the 128-bit GCM tag -/// (`vitaminc-encrypt`'s `Aes256Cipher`). The page's "less the AEAD's fixed +/// (vitaminc-aead's `Aes256Cipher`). The page's "less the AEAD's fixed /// overhead". pub const AEAD_OVERHEAD: usize = 1 + 12 + 16; diff --git a/packages/stack-encrypt/tests/json_leakage/simulator.rs b/packages/stack-encrypt/tests/json_leakage/simulator.rs index e6ffa8f0a..8f9fdf4e9 100644 --- a/packages/stack-encrypt/tests/json_leakage/simulator.rs +++ b/packages/stack-encrypt/tests/json_leakage/simulator.rs @@ -53,7 +53,7 @@ use super::profile::{ SentOrder, Step, StoredOrder, TokenName, TokenStep, }; -/// The version byte `vitaminc-encrypt` writes at the front of every +/// The version byte vitaminc-aead's `Aes256Cipher` writes at the front of every /// ciphertext: public framing, not leakage. pub const CIPHERTEXT_FRAME: u8 = 2; diff --git a/packages/stack-kms/fuzz/Cargo.lock b/packages/stack-kms/fuzz/Cargo.lock index 389e4a957..c429c04ce 100644 --- a/packages/stack-kms/fuzz/Cargo.lock +++ b/packages/stack-kms/fuzz/Cargo.lock @@ -2375,12 +2375,12 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35042fb7a81d72dc43c53fec835e61027f18b4d01cc0f7e12d6c6a6ffbf3bfb9" dependencies = [ - "vitaminc-aead 0.5.1", - "vitaminc-context 0.5.1", - "vitaminc-encrypt 0.5.1", + "vitaminc-aead", + "vitaminc-context", + "vitaminc-encrypt", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", - "vitaminc-traits 0.5.1", + "vitaminc-traits", ] [[package]] @@ -2389,12 +2389,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60ae27c0d0e6980d2f30683384ed591a9dafa943b18faaa6bfb456757b5e10ef" dependencies = [ - "vitaminc-aead 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-encrypt 0.10.0", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "vitaminc-traits 0.10.0", ] [[package]] @@ -2405,28 +2401,13 @@ checksum = "62cacd4dae485e98cfe5407e919187a8468dd933ea4234be5115b7d13a30f3c6" dependencies = [ "bytes", "serde", - "vitaminc-aead-derive 0.5.1", - "vitaminc-context 0.5.1", + "vitaminc-aead-derive", + "vitaminc-context", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", "zeroize", ] -[[package]] -name = "vitaminc-aead" -version = "0.10.0" -dependencies = [ - "bytes", - "futures-util", - "serde", - "thiserror 2.0.18", - "vitaminc-aead-derive 0.10.0", - "vitaminc-context 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-aead-derive" version = "0.5.1" @@ -2438,15 +2419,6 @@ dependencies = [ "syn 3.0.3", ] -[[package]] -name = "vitaminc-aead-derive" -version = "0.10.0" -dependencies = [ - "proc-macro2", - "quote", - "syn 3.0.3", -] - [[package]] name = "vitaminc-context" version = "0.5.1" @@ -2457,16 +2429,6 @@ dependencies = [ "vitaminc-protected 0.5.1", ] -[[package]] -name = "vitaminc-context" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "431a7fb023688dba855e52b9c4e44c942418dde8ea08a2b115cf6a7f762fa5b9" -dependencies = [ - "mutants", - "vitaminc-protected 0.10.0", -] - [[package]] name = "vitaminc-encrypt" version = "0.5.1" @@ -2475,26 +2437,12 @@ checksum = "9fbd0e1748055e381e02033e08af385de879c4dcf32e0f6739ac0c0cf0c6f13d" dependencies = [ "aes-gcm", "aws-lc-rs", - "vitaminc-aead 0.5.1", + "vitaminc-aead", "vitaminc-protected 0.5.1", "vitaminc-random 0.5.1", "zeroize", ] -[[package]] -name = "vitaminc-encrypt" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e68d89e2587529db55a10fa59cb11be8a7505b4af473c8a0bec238c803190ec5" -dependencies = [ - "aes-gcm", - "aws-lc-rs", - "vitaminc-aead 0.10.0", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "vitaminc-protected" version = "0.5.1" @@ -2620,22 +2568,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "vitaminc-traits" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31fba5af175073f24768a8b06dd054ad696c7e6051dda1316c3814043a36d8e0" -dependencies = [ - "anyhow", - "bytes", - "rmp-serde", - "serde", - "thiserror 2.0.18", - "vitaminc-protected 0.10.0", - "vitaminc-random 0.10.0", - "zeroize", -] - [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" @@ -3263,3 +3195,11 @@ name = "zmij" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4de98dfa5d5b7fef4ee834d0073d560c9ca7b6c46a71d058c48db7960f8cfaf7" + +[[patch.unused]] +name = "vitaminc-aead" +version = "0.10.0" + +[[patch.unused]] +name = "vitaminc-aead-derive" +version = "0.10.0" From a7c280ae07bbaba82d2f36be9409bbaf6278f2e2 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 3 Dec 2026 10:31:48 +1100 Subject: [PATCH 03/25] refactor(vitaminc-aead)!: the leaf writer, reader and nonce types are 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. --- packages/vitaminc-aead/CHANGELOG.md | 7 ++++ packages/vitaminc-aead/src/aes/cipher.rs | 11 +++--- packages/vitaminc-aead/src/ciphertext/mod.rs | 20 ++++++---- .../src/ciphertext/read_monads.rs | 37 ++----------------- .../src/ciphertext/write_monads.rs | 23 +----------- packages/vitaminc-aead/src/lib.rs | 9 +++-- 6 files changed, 36 insertions(+), 71 deletions(-) diff --git a/packages/vitaminc-aead/CHANGELOG.md b/packages/vitaminc-aead/CHANGELOG.md index acb90e4e3..c315061f4 100644 --- a/packages/vitaminc-aead/CHANGELOG.md +++ b/packages/vitaminc-aead/CHANGELOG.md @@ -61,6 +61,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). The decrypt sink of `OwnedFrame` writes through them, reporting `DecodeError`. - `DecodeError` implements `From`: a scalar its logical type does not admit is `DecodeError::Expected`, a source's failure is `DecodeError::Source`, and any other refusal is `DecodeError::Source` with the writer's error as its source. +### Removed + +- `CipherTextBuilder`, `Nonce`, `NonceGenerator`, `RandomNonceGenerator` and `LocalCipherText::into_reader` are private. + They were public so that a cipher in another crate could write and read a leaf. + The only such cipher is now `aes::Aes256Cipher`, in this crate. + `LocalCipherText` and `WIRE_VERSION` are still public. + ### Security - `plaintext::SourceError` prints `SourceError(..)` in `Debug`, and none of the error it wraps. diff --git a/packages/vitaminc-aead/src/aes/cipher.rs b/packages/vitaminc-aead/src/aes/cipher.rs index 1fbc0a76e..c8c00668d 100644 --- a/packages/vitaminc-aead/src/aes/cipher.rs +++ b/packages/vitaminc-aead/src/aes/cipher.rs @@ -85,13 +85,12 @@ pub(crate) fn open_leaf<'a, A>( where A: IntoAad<'a>, { - // `read_version_in` rejects any other wire version before parsing; the - // version read is *also* bound under the tag (`for_leaf`, mirroring the - // seal side), so a relabeled byte that parses still fails. - let (version, reader) = ct.into_reader().read_version_in(&[WIRE_VERSION])?; - let (nonce, reader) = reader.read_nonce::()?; + // `read_version` rejects any other wire version before parsing; the + // version is *also* bound under the tag (`for_leaf`, mirroring the seal + // side), so a relabeled byte that parses still fails. + let (nonce, reader) = ct.into_reader().read_version()?.read_nonce::()?; let nonce_bytes = nonce.into_inner(); - let aad = aad.into_aad().for_leaf(version); + let aad = aad.into_aad().for_leaf(WIRE_VERSION); reader .accepts_plaintext_ok(|data| cipher.key.open(&nonce_bytes, aad.as_bytes(), data)) diff --git a/packages/vitaminc-aead/src/ciphertext/mod.rs b/packages/vitaminc-aead/src/ciphertext/mod.rs index 1e22c429a..8ee1e4573 100644 --- a/packages/vitaminc-aead/src/ciphertext/mod.rs +++ b/packages/vitaminc-aead/src/ciphertext/mod.rs @@ -1,9 +1,15 @@ +// The staged writer and reader of a leaf's layout. Only the `aes` cipher +// writes and reads leaves, so they are built only with it. +#[cfg(feature = "aes")] mod read_monads; +#[cfg(feature = "aes")] mod write_monads; use bytes::Bytes; +#[cfg(feature = "aes")] use read_monads::CipherTextReader; use serde::{Deserialize, Serialize}; -pub use write_monads::CipherTextBuilder; +#[cfg(feature = "aes")] +pub(crate) use write_monads::CipherTextBuilder; /// First byte of every [`LocalCipherText`] — the wire-format version. /// @@ -23,10 +29,8 @@ pub use write_monads::CipherTextBuilder; /// but what they hold depends on who sealed them: the legacy `Value` /// path (`vitaminc-aead-value` 0.5 and the Go binding) sealed tagged /// scalars, while `vitaminc-encrypt` 0.5's `Encrypt` path sealed raw, -/// untagged bytes. Nothing in a version 1 leaf tells the two apart, so a -/// reader that reads tags opens version 1 only where it knows the leaf came -/// from the `Value` path, by passing it to `read_version_in` on the reader -/// from [`LocalCipherText::into_reader`]. +/// untagged bytes. Nothing in a version 1 leaf tells the two apart, so +/// this crate's cipher opens version 2 only. pub const WIRE_VERSION: u8 = 2; /// A sealed leaf: `version(1) ‖ nonce ‖ ciphertext ‖ tag`. @@ -42,7 +46,8 @@ impl LocalCipherText { /// Consume the leaf and begin staged version/nonce parsing. /// Authentication remains the cipher implementation's responsibility. - pub fn into_reader(self) -> CipherTextReader { + #[cfg(feature = "aes")] + pub(crate) fn into_reader(self) -> CipherTextReader { CipherTextReader::new(self.0) } @@ -70,9 +75,10 @@ impl From> for LocalCipherText { } #[cfg(test)] +#[cfg(feature = "aes")] mod tests { use super::*; - use crate::Nonce; + use crate::nonce::Nonce; use vitaminc_protected::{Controlled, Protected}; #[test] diff --git a/packages/vitaminc-aead/src/ciphertext/read_monads.rs b/packages/vitaminc-aead/src/ciphertext/read_monads.rs index 098c5ad72..21c56c714 100644 --- a/packages/vitaminc-aead/src/ciphertext/read_monads.rs +++ b/packages/vitaminc-aead/src/ciphertext/read_monads.rs @@ -1,4 +1,5 @@ -use crate::{Nonce, Unspecified}; +use crate::nonce::Nonce; +use crate::Unspecified; use bytes::{Buf, Bytes}; use std::array; use vitaminc_protected::{Controlled, Protected}; @@ -21,25 +22,11 @@ impl CipherTextReader { /// leaf AAD ([`Context::for_leaf`](crate::Context::for_leaf)), so a relabeled /// version that happens to parse still fails tag verification. pub fn read_version(self) -> Result { - self.read_version_in(&[super::WIRE_VERSION]) - .map(|(_, reader)| reader) - } - - /// Like [`read_version`](Self::read_version), but accepts any version in - /// `accepted` and returns the one it read, so the caller can bind that - /// version into the leaf AAD. Only a reader that knows where its older - /// leaves came from should pass a version other than - /// [`WIRE_VERSION`](super::WIRE_VERSION); see that constant for why. - pub fn read_version_in(self, accepted: &[u8]) -> Result<(u8, VersionedReader), Unspecified> { let mut buf = self.0; - if buf.is_empty() { + if buf.is_empty() || buf.get_u8() != super::WIRE_VERSION { return Err(Unspecified); } - let version = buf.get_u8(); - if !accepted.contains(&version) { - return Err(Unspecified); - } - Ok((version, VersionedReader(buf))) + Ok(VersionedReader(buf)) } } @@ -153,22 +140,6 @@ mod tests { } } - #[test] - fn read_version_in_accepts_only_the_listed_versions() { - for version in 0..=u8::MAX { - let read = CipherTextReader::new(Bytes::from(vec![version, 9])) - .read_version_in(&[1, WIRE_VERSION]) - .map(|(read, rest)| (read, rest.0)); - if version == 1 || version == WIRE_VERSION { - assert_eq!(read, Ok((version, Bytes::from_static(&[9])))); - } else { - assert!(read.is_err(), "version {version} must be rejected"); - } - } - let empty = CipherTextReader::new(Bytes::new()).read_version_in(&[1, WIRE_VERSION]); - assert!(empty.is_err()); - } - #[test] fn read_version_strips_exactly_one_byte() { let (nonce, rest) = versioned(&[1, 2, 3, 4, 5]) diff --git a/packages/vitaminc-aead/src/ciphertext/write_monads.rs b/packages/vitaminc-aead/src/ciphertext/write_monads.rs index 30df892c2..b99a722cc 100644 --- a/packages/vitaminc-aead/src/ciphertext/write_monads.rs +++ b/packages/vitaminc-aead/src/ciphertext/write_monads.rs @@ -1,5 +1,5 @@ use super::LocalCipherText; -use crate::Nonce; +use crate::nonce::Nonce; use bytes::BytesMut; use vitaminc_protected::{Controlled, Protected}; @@ -34,27 +34,6 @@ impl NonceWritten { ) -> PlaintextWritten { PlaintextWritten::new(self.0, plaintext.into()) } - - /// Append a fixed-width array plaintext, reserving `reserve` extra bytes of - /// spare capacity in the backing buffer so an in-place AEAD seal can append - /// its tag without reallocating. Sizing the plaintext buffer is the - /// builder's job, so callers sealing fixed-width leaves route through here - /// rather than hand-rolling the `Vec` assembly at the call site. - /// - /// The array is copied out through `risky_ref` (a borrow) so `plaintext` - /// keeps ownership of the original and is wiped by `ZeroizeOnDrop` at end - /// of scope — a `risky_unwrap` would partially-move the bare `[u8; M]` out - /// and skip that wipe (see issue #170). - pub fn append_target_plaintext_array( - self, - plaintext: Protected<[u8; M]>, - reserve: usize, - ) -> PlaintextWritten { - let src = plaintext.risky_ref(); - let mut buf = Vec::with_capacity(M + reserve); - buf.extend_from_slice(src); - PlaintextWritten::new(self.0, Protected::new(buf)) - } } pub struct PlaintextWritten(Nonce, Protected>); diff --git a/packages/vitaminc-aead/src/lib.rs b/packages/vitaminc-aead/src/lib.rs index f41775782..3f525a289 100644 --- a/packages/vitaminc-aead/src/lib.rs +++ b/packages/vitaminc-aead/src/lib.rs @@ -44,6 +44,7 @@ pub mod frame; #[cfg_attr(docsrs, doc(cfg(feature = "hlist")))] pub mod hlist; pub mod leaf; +#[cfg(feature = "aes")] mod nonce; pub mod plaintext; pub mod seal; @@ -106,13 +107,15 @@ pub use uuid_value::Uuid; #[allow(deprecated)] pub use aad::{Aad, AadPiece}; pub use aad::{Context, ContextPiece, IntoAad, IntoContext, LeafTypeAad}; +#[cfg(feature = "aes")] +pub(crate) use ciphertext::CipherTextBuilder; #[doc(inline)] -pub use ciphertext::{CipherTextBuilder, LocalCipherText, WIRE_VERSION}; +pub use ciphertext::{LocalCipherText, WIRE_VERSION}; #[doc(inline)] pub use container::CipherText; #[doc(inline)] pub use context::ContextTag; -#[doc(inline)] -pub use nonce::{Nonce, NonceGenerator, RandomNonceGenerator}; +#[cfg(feature = "aes")] +pub(crate) use nonce::{NonceGenerator, RandomNonceGenerator}; #[doc(inline)] pub use unspecified::Unspecified; From 580d8c58e566a96567f648a92e9a0726e008bfc4 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 3 Dec 2026 10:32:45 +1100 Subject: [PATCH 04/25] refactor(vitaminc-aead)!: remove the deprecated Aad and AadPiece names 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. --- packages/stack-encrypt/CHANGELOG.md | 4 ++++ packages/stack-encrypt/CONTEXT.md | 2 +- packages/stack-encrypt/src/lib.rs | 4 ---- packages/vitaminc-aead/CHANGELOG.md | 1 + packages/vitaminc-aead/src/aad/mod.rs | 16 ---------------- packages/vitaminc-aead/src/lib.rs | 3 --- 6 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/stack-encrypt/CHANGELOG.md b/packages/stack-encrypt/CHANGELOG.md index 24c4bf5ab..599fa843c 100644 --- a/packages/stack-encrypt/CHANGELOG.md +++ b/packages/stack-encrypt/CHANGELOG.md @@ -571,6 +571,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking +- **The re-exports `Aad` and `AadPiece` are removed.** They were deprecated + names for `Context` and `ContextPiece`, which are still re-exported. Use + those. + - **A plan is read with `Plan::from_frame`.** Three paths have moved too. The code is the same. Only the names and the paths have changed. - `dynamic::record::plan(frame)` is now `Plan::from_frame(frame)`. diff --git a/packages/stack-encrypt/CONTEXT.md b/packages/stack-encrypt/CONTEXT.md index a075c0d8e..49478287b 100644 --- a/packages/stack-encrypt/CONTEXT.md +++ b/packages/stack-encrypt/CONTEXT.md @@ -173,7 +173,7 @@ parts joined by `/` (`users/email`; a nested list is parenthesised, so one text part can never read as two, and an empty part inside a list is the bare `b64:`. Rendered by one function, `Descriptor::from_piece`, and **frozen**: a change re-keys everything. Finer than the encodings for a -pre-encoded `Aad` (opaque bytes) and coarser for shapes that render alike +pre-encoded `Context` (opaque bytes) and coarser for shapes that render alike (`7i64` and `7u64`): seal and open must present the context in the same shape. The descriptor is derived, never authored: nothing takes a descriptor string from a caller. diff --git a/packages/stack-encrypt/src/lib.rs b/packages/stack-encrypt/src/lib.rs index 77bece74d..e6673645a 100644 --- a/packages/stack-encrypt/src/lib.rs +++ b/packages/stack-encrypt/src/lib.rs @@ -851,10 +851,6 @@ pub use vitaminc_aead::{ /// let _: Option>> = None; // bytes are not `Orderable` /// ``` pub use vitaminc_ore::Orderable; -// The vitaminc 0.4 names, deprecated there; re-exported for one transition so -// a caller that spelled them keeps compiling with a warning. -#[allow(deprecated)] -pub use vitaminc_aead::{Aad, AadPiece}; // Likewise the PRF context surface, so a caller who needs the PRF view of a // context has no direct `vitaminc-prf` dependency for it. diff --git a/packages/vitaminc-aead/CHANGELOG.md b/packages/vitaminc-aead/CHANGELOG.md index c315061f4..a2db61f12 100644 --- a/packages/vitaminc-aead/CHANGELOG.md +++ b/packages/vitaminc-aead/CHANGELOG.md @@ -63,6 +63,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Removed +- The deprecated names `Aad` and `AadPiece`. Use `Context` and `ContextPiece`. - `CipherTextBuilder`, `Nonce`, `NonceGenerator`, `RandomNonceGenerator` and `LocalCipherText::into_reader` are private. They were public so that a cipher in another crate could write and read a leaf. The only such cipher is now `aes::Aes256Cipher`, in this crate. diff --git a/packages/vitaminc-aead/src/aad/mod.rs b/packages/vitaminc-aead/src/aad/mod.rs index 20638c9ed..9bd85982e 100644 --- a/packages/vitaminc-aead/src/aad/mod.rs +++ b/packages/vitaminc-aead/src/aad/mod.rs @@ -11,22 +11,6 @@ mod leaf_type; pub use leaf_type::LeafTypeAad; pub use vitaminc_context::{Context, ContextPiece, IntoContext}; -/// The associated data a context is authenticated as. Kept as a name for -/// the transition; it is [`Context`]. -#[deprecated( - since = "0.5.0", - note = "renamed to `Context`, re-exported here from `vitaminc_context`" -)] -pub type Aad<'a> = Context<'a>; - -/// The parts view of a context. Kept as a name for the transition; it is -/// [`ContextPiece`]. -#[deprecated( - since = "0.5.0", - note = "renamed to `ContextPiece`, re-exported here from `vitaminc_context`" -)] -pub type AadPiece<'a> = ContextPiece<'a>; - /// Types that can be used as the associated data of an AEAD call. /// /// This is the AEAD's view of a context. It is implemented for every type diff --git a/packages/vitaminc-aead/src/lib.rs b/packages/vitaminc-aead/src/lib.rs index 3f525a289..7c1fb22cc 100644 --- a/packages/vitaminc-aead/src/lib.rs +++ b/packages/vitaminc-aead/src/lib.rs @@ -103,9 +103,6 @@ pub use timestamp::{OutOfRange, Timestamp}; #[cfg(feature = "uuid")] pub use uuid_value::Uuid; -#[doc(inline)] -#[allow(deprecated)] -pub use aad::{Aad, AadPiece}; pub use aad::{Context, ContextPiece, IntoAad, IntoContext, LeafTypeAad}; #[cfg(feature = "aes")] pub(crate) use ciphertext::CipherTextBuilder; From f8355a3244371fb35b548b881efc6b9629fd509f Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 3 Dec 2026 10:35:53 +1100 Subject: [PATCH 05/25] fix(vitaminc-aead): the aws-lc seal no longer frees an unwiped copy of 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. --- .../tests/encryption/tests/heap_hygiene.rs | 43 ++-------------- packages/stack-encrypt/tests/heap_hygiene.rs | 36 +++---------- packages/vitaminc-aead/CHANGELOG.md | 4 ++ .../vitaminc-aead/src/aes/backend/aws_lc.rs | 50 ++++++++++++++++++- 4 files changed, 65 insertions(+), 68 deletions(-) diff --git a/packages/eql/tests/encryption/tests/heap_hygiene.rs b/packages/eql/tests/encryption/tests/heap_hygiene.rs index 968f6df96..a701ac976 100644 --- a/packages/eql/tests/encryption/tests/heap_hygiene.rs +++ b/packages/eql/tests/encryption/tests/heap_hygiene.rs @@ -10,13 +10,6 @@ //! indexed, when the value is refused or fails to open, and when the //! pending work is dropped before its keys arrive. stack-encrypt's //! `tests/heap_hygiene.rs` holds its dynamic paths the same way. -//! -//! One free is excluded by name: vitaminc-aead's aws-lc backend -//! (`aes::backend::aws_lc::CipherKey::seal`, native builds only) frees an unwiped -//! plaintext buffer on every seal; that is vitaminc's to fix. It is counted -//! and printed, never silent, and every other free on those paths is still -//! watched. The spy recognises these frees by their backtrace, so a build -//! without symbols fails rather than passes. //! //! Unix only: the spy scans a freed block with libc's `memmem`, not as a @@ -55,16 +48,8 @@ thread_local! { /// threads, and the findings below are one set. static GATE: Mutex<()> = Mutex::new(()); -/// The marked frees seen, as backtraces; and how many each exclusion took. +/// The marked frees seen, as backtraces. static FOUND: Mutex> = Mutex::new(Vec::new()); -static EXCLUDED: Mutex<[usize; 1]> = Mutex::new([0; 1]); - -/// The frames whose frees are excluded, each with what it is (see the module -/// docs): vitaminc's aws-lc seal. -const EXCLUSIONS: [(&str, &str); 1] = [( - "vitaminc_aead::aes::backend::aws_lc::CipherKey::seal", - "vitaminc's aws-lc seal", -)]; /// Whether the `len` bytes at `ptr` hold [`MARK`]. A freed block can hold /// bytes Rust never initialised (a `Vec`'s spare capacity, a struct's @@ -112,21 +97,10 @@ unsafe impl GlobalAlloc for Spy { if holds_mark(ptr, layout.size()) { BUSY.with(|busy| busy.set(true)); let trace = std::backtrace::Backtrace::force_capture().to_string(); - // Symbol demangling differs by platform: Linux writes - // `<…::CipherKey>::seal`, macOS `…::CipherKey::seal`. Match - // with the angle brackets dropped. - let plain = trace.replace(['<', '>'], ""); - if let Some(at) = EXCLUSIONS - .iter() - .position(|(frame, _)| plain.contains(frame)) - { - EXCLUDED.lock().unwrap()[at] += 1; - } else { - FOUND - .lock() - .unwrap() - .push(format!("{} bytes freed unwiped:\n{trace}", layout.size())); - } + FOUND + .lock() + .unwrap() + .push(format!("{} bytes freed unwiped:\n{trace}", layout.size())); BUSY.with(|busy| busy.set(false)); } } @@ -163,17 +137,10 @@ fn allocations_of(size: usize, what: &str, f: impl FnOnce()) -> usize { /// [`watched`], for a caller already holding [`GATE`]. fn watched_in_gate(what: &str, f: impl FnOnce() -> T) -> T { FOUND.lock().unwrap().clear(); - *EXCLUDED.lock().unwrap() = [0; 1]; WATCHING.with(|on| on.set(true)); let out = f(); WATCHING.with(|on| on.set(false)); let found = std::mem::take(&mut *FOUND.lock().unwrap()); - let excluded = std::mem::take(&mut *EXCLUDED.lock().unwrap()); - for ((_, name), skipped) in EXCLUSIONS.iter().zip(excluded) { - if skipped > 0 { - eprintln!("{what}: skipped {skipped} unwiped frees in {name}"); - } - } assert!( found.is_empty(), "{what}: {} heap blocks were freed with plaintext in them:\n{}", diff --git a/packages/stack-encrypt/tests/heap_hygiene.rs b/packages/stack-encrypt/tests/heap_hygiene.rs index 375a5d403..e65fc12b5 100644 --- a/packages/stack-encrypt/tests/heap_hygiene.rs +++ b/packages/stack-encrypt/tests/heap_hygiene.rs @@ -18,12 +18,6 @@ //! guest's linear memory after the fact, where allocator metadata and reuse //! have already overwritten most freed chunks, so it cannot see one. //! -//! One free is excluded by name: vitaminc-aead's aws-lc backend -//! (`aes::backend::aws_lc::CipherKey::seal`, native builds only) frees an unwiped -//! plaintext buffer on every seal. That is vitaminc's to fix, not this -//! crate's; the spy reports how many it skipped, and recognises them by -//! their backtrace, so a build without symbols fails rather than passes. -//! //! The stack is not watched, and is kept out of the picture: a future the //! operation boxes (`Pending`'s `IntoFuture`) is built on the stack and //! copied into its box with every byte it does not initialise, so a watch @@ -74,9 +68,8 @@ thread_local! { /// threads, and the findings below are one set. static GATE: Mutex<()> = Mutex::new(()); -/// The marked frees seen, as backtraces; and how many were vitaminc's. +/// The marked frees seen, as backtraces. static FOUND: Mutex> = Mutex::new(Vec::new()); -static UPSTREAM: Mutex = Mutex::new(0); /// The data key the JSON tests' key source last handed out, which a freed /// block must not hold either (see [`json_index`]). Set outside any @@ -112,9 +105,6 @@ static TRACKING: AtomicBool = AtomicBool::new(false); static COUNT_SIZE: AtomicUsize = AtomicUsize::new(0); static COUNTED: AtomicUsize = AtomicUsize::new(0); -/// The vitaminc frame whose free is excluded (see the module docs). -const UPSTREAM_SEAL: &str = "vitaminc_aead::aes::backend::aws_lc::CipherKey::seal"; - /// Whether the `len` bytes at `ptr` hold [`MARK`]. A freed block can hold /// bytes Rust never initialised (a `Vec`'s spare capacity, a struct's /// padding), and reading those through a `&[u8]` is undefined behaviour, so @@ -182,7 +172,7 @@ unsafe impl GlobalAlloc for Spy { // own lifetime: the system allocator hands memory out as its last // owner left it, and a block that is only partly written (a boxed // future's state, a `Vec`'s spare capacity) would otherwise show - // what an earlier, excluded free left there and be blamed for it. + // what an earlier free left there and be blamed for it. let ptr = System.alloc_zeroed(layout); if !ptr.is_null() && layout.size() == COUNT_SIZE.load(Ordering::SeqCst) @@ -217,17 +207,10 @@ unsafe impl GlobalAlloc for Spy { if holds_mark(ptr, layout.size()) || holds_key(ptr, layout.size()) { BUSY.with(|busy| busy.set(true)); let trace = std::backtrace::Backtrace::force_capture().to_string(); - // Symbol demangling differs by platform: Linux writes - // `<…::CipherKey>::seal`, macOS `…::CipherKey::seal`. Match - // with the angle brackets dropped. - if trace.replace(['<', '>'], "").contains(UPSTREAM_SEAL) { - *UPSTREAM.lock().unwrap() += 1; - } else { - FOUND - .lock() - .unwrap() - .push(format!("{} bytes freed unwiped:\n{trace}", layout.size())); - } + FOUND + .lock() + .unwrap() + .push(format!("{} bytes freed unwiped:\n{trace}", layout.size())); BUSY.with(|busy| busy.set(false)); } } @@ -271,7 +254,7 @@ fn watched(what: &str, f: impl FnOnce() -> T) -> T { /// Take [`GATE`], which serializes every watch: the thread-local flags /// keep other threads' allocations out of a watch, but [`FOUND`], -/// [`UPSTREAM`], [`LIVE`] and [`TRACKING`] are shared, and a test running +/// [`LIVE`] and [`TRACKING`] are shared, and a test running /// alongside on another thread (plain `cargo test`) would otherwise reset /// or switch them off mid-watch. A test that panicked holding it (a /// `should_panic` control) poisons it; the state it guards is reset on @@ -283,16 +266,11 @@ fn gate() -> std::sync::MutexGuard<'static, ()> { /// [`watched`], for a caller already holding [`GATE`]. fn watched_in_gate(what: &str, f: impl FnOnce() -> T) -> T { FOUND.lock().unwrap().clear(); - *UPSTREAM.lock().unwrap() = 0; scrub_stack(); WATCHING.with(|on| on.set(true)); let out = f(); WATCHING.with(|on| on.set(false)); let found = std::mem::take(&mut *FOUND.lock().unwrap()); - let upstream = std::mem::take(&mut *UPSTREAM.lock().unwrap()); - if upstream > 0 { - eprintln!("{what}: skipped {upstream} unwiped frees in vitaminc's aws-lc seal"); - } assert!( found.is_empty(), "{what}: {} heap blocks were freed with plaintext in them:\n{}", diff --git a/packages/vitaminc-aead/CHANGELOG.md b/packages/vitaminc-aead/CHANGELOG.md index a2db61f12..d224967b8 100644 --- a/packages/vitaminc-aead/CHANGELOG.md +++ b/packages/vitaminc-aead/CHANGELOG.md @@ -71,6 +71,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Security +- The AES seal on aws-lc-rs no longer frees a copy of the plaintext without wiping it. + aws-lc-rs makes the buffer longer for the tag before it encrypts, and a buffer with no spare room moves to a new block. + The old block still held the plaintext. + The backend now makes room for the tag first, and wipes the old block before it is freed. - `plaintext::SourceError` prints `SourceError(..)` in `Debug`, and none of the error it wraps. The wrapped error comes from the caller's code, and its text can include the value that failed. Before, `Debug` printed that text, so `{:?}`, a log line, or a panic from `unwrap` could print the value. diff --git a/packages/vitaminc-aead/src/aes/backend/aws_lc.rs b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs index 91e4a26d0..c154b69e1 100644 --- a/packages/vitaminc-aead/src/aes/backend/aws_lc.rs +++ b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs @@ -1,7 +1,11 @@ //! `aws-lc-rs` backend for AES-256-GCM. -use aws_lc_rs::aead::{Aad as LcAad, LessSafeKey, Nonce as LcNonce, UnboundKey, AES_256_GCM}; use crate::Unspecified; +use aws_lc_rs::aead::{Aad as LcAad, LessSafeKey, Nonce as LcNonce, UnboundKey, AES_256_GCM}; +use zeroize::Zeroize; + +/// The AES-GCM tag length. +const TAG_LEN: usize = 16; pub(crate) struct CipherKey(LessSafeKey); @@ -18,6 +22,7 @@ impl CipherKey { aad: &[u8], in_out: &mut Vec, ) -> Result<(), Unspecified> { + reserve_tag(in_out); let nonce = LcNonce::try_assume_unique_for_key(nonce).map_err(|_| Unspecified)?; self.0 .seal_in_place_append_tag(nonce, LcAad::from(aad), in_out) @@ -40,3 +45,46 @@ impl CipherKey { .map_err(|_| Unspecified) } } + +/// Make room in `buf` for the tag without leaving its plaintext behind. +/// +/// aws-lc-rs appends the tag's space to the buffer before it encrypts, while +/// the buffer still holds plaintext. If the buffer has no room, the `Vec` +/// moves, and the block it leaves is freed with the plaintext in it. So the +/// room is made here first, and the old block is wiped before it is freed. +fn reserve_tag(buf: &mut Vec) { + if buf.capacity() - buf.len() < TAG_LEN { + let mut grown = Vec::with_capacity(buf.len() + TAG_LEN); + grown.extend_from_slice(buf); + // Zeroes the whole allocation, spare capacity too, then clears it. + buf.zeroize(); + *buf = grown; + } +} + +#[cfg(test)] +mod tests { + use super::{reserve_tag, TAG_LEN}; + + #[test] + fn a_full_buffer_gains_room_for_the_tag_and_keeps_its_bytes() { + let mut buf = b"plaintext".to_vec(); + buf.shrink_to_fit(); + reserve_tag(&mut buf); + assert_eq!(buf, b"plaintext", "the bytes should be unchanged"); + assert!( + buf.capacity() - buf.len() >= TAG_LEN, + "there should be room for the tag, capacity {}", + buf.capacity() + ); + } + + #[test] + fn a_buffer_with_room_is_not_moved() { + let mut buf = Vec::with_capacity(9 + TAG_LEN); + buf.extend_from_slice(b"plaintext"); + let before = buf.as_ptr(); + reserve_tag(&mut buf); + assert_eq!(buf.as_ptr(), before, "a buffer with room should stay put"); + } +} From 42c92e179a78f49d0cc2593947d34544b37ae17b Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Thu, 3 Dec 2026 10:45:00 +1100 Subject: [PATCH 06/25] docs(vitaminc-aead): the README describes the AES cipher 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. --- packages/vitaminc-aead/README.md | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/vitaminc-aead/README.md b/packages/vitaminc-aead/README.md index b2e785d9d..291f72921 100644 --- a/packages/vitaminc-aead/README.md +++ b/packages/vitaminc-aead/README.md @@ -35,7 +35,7 @@ This crate provides the data model and the traversals for encrypting structured ## Usage -The examples below use a cipher that keeps the plaintext in the clear and authenticates the AAD, so they run without a key. A real one is `vitaminc_encrypt::Aes256Cipher`. +The examples below use a cipher that keeps the plaintext in the clear and authenticates the AAD, so they run without a key. A real one is `aes::Aes256Cipher`, built with the `aes` feature. ```rust # use vitaminc_aead::{Cipher, Context, Unspecified}; @@ -78,7 +78,7 @@ use vitaminc_aead::{Cipher, Context, Unspecified}; use vitaminc_protected::{Controlled, Protected}; /// Not a cipher: it stores the plaintext as it is, to show the trait -/// shape only. For real data, use `vitaminc_encrypt::Aes256Cipher`. +/// shape only. For real data, use `vitaminc_aead::aes::Aes256Cipher`. struct ClearTextForExamplesOnly; impl Cipher for ClearTextForExamplesOnly { @@ -403,20 +403,9 @@ Host bindings do not convert their values into a Rust value tree. [`Frame`] is a [`Tee`] runs two sinks over one walk. `vitaminc-normalize` uses it to produce equality terms beside encryption, so a document is walked once and every term exists before any cipher is called. -### Nonce Generation +### AES-256-GCM -The crate provides nonce generation utilities for AEAD operations: - -```rust -# fn main() -> Result<(), Box> { -use vitaminc_aead::{NonceGenerator, RandomNonceGenerator}; - -// Create a random nonce generator for 12-byte nonces -let generator = RandomNonceGenerator::<12>::init()?; -let nonce = generator.generate()?; -# Ok(()) -# } -``` +With the `aes` feature, the `aes` module has the crate's cipher, `Aes256Cipher`, and its 32-byte `Key`. It seals each leaf as `version ‖ nonce ‖ ciphertext ‖ tag`, under a fresh random 96-bit nonce, and binds the wire version into the leaf's AAD. It uses `aws-lc-rs` on native targets and RustCrypto's `aes-gcm` on `wasm32`. Both produce the same bytes. ## Security Considerations From 9d5c5121080b0c7f9f0759b56f973c79b7a5d390 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 00:20:36 +1100 Subject: [PATCH 07/25] style: rustfmt the two files outside the root workspace that changed The EQL encryption tests and the recipher-js test addon are separate Cargo workspaces, so the root cargo fmt did not reach them. --- .../packages/recipher-js/value-napi/tests/addon/src/lib.rs | 4 ++-- packages/eql/tests/encryption/tests/opaque_json_bytes.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs b/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs index 3452bb51b..25add4a10 100644 --- a/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs +++ b/languages/typescript/packages/recipher-js/value-napi/tests/addon/src/lib.rs @@ -7,14 +7,14 @@ use napi::bindgen_prelude::{AsyncTask, Buffer, FnArgs, JsObjectValue, JsValue, O use napi::{Env, Error, Result, Status, Task}; use napi_derive::napi; use recipher_value_napi::{JsBuilder, JsCipherText, JsFault, JsRef, Refusal, Wrapper, Wrappers}; +use vitaminc_aead::aes::{Aes256Cipher, Key}; use vitaminc_aead::seal::Cipher; +use vitaminc_aead::LocalCipherText; use vitaminc_aead::{ decrypt, decrypt_into, encrypt, to_frame, CipherText, Context, DecryptError, Encrypt, EncryptError, Float, Frame, Int, Logical, MapSink, Node, PassthroughFrame, Physical, SeqSink, Sink, TimeUnit, }; -use vitaminc_aead::aes::{Aes256Cipher, Key}; -use vitaminc_aead::LocalCipherText; use vitaminc_protected::{Controlled, Protected}; /// The wrapper classes, exported so JavaScript can make instances with diff --git a/packages/eql/tests/encryption/tests/opaque_json_bytes.rs b/packages/eql/tests/encryption/tests/opaque_json_bytes.rs index 888a88023..ca909a2ca 100644 --- a/packages/eql/tests/encryption/tests/opaque_json_bytes.rs +++ b/packages/eql/tests/encryption/tests/opaque_json_bytes.rs @@ -34,9 +34,9 @@ use stack_kms::{ IndexKey, IndexKeySource, RetrieveKeyPayload, UnverifiedContext, }; use uuid::Uuid; +use vitaminc_aead::aes::{Aes256Cipher, Key as AesKey}; use vitaminc_aead::seal::Cipher; use vitaminc_aead::{Context, FrameWriter, IntoContext, LocalCipherText, Unspecified}; -use vitaminc_aead::aes::{Aes256Cipher, Key as AesKey}; use vitaminc_protected::{Buffer, Controlled as _, Protected}; const SEED: [u8; 32] = *b"eql opaque json bytes v1 "; From fde4aa657f109a156c451ae28f6adc6c41d18eef Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 00:20:37 +1100 Subject: [PATCH 08/25] fix(vitaminc-aead): a seal that fails wipes the plaintext from its buffer 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. --- packages/vitaminc-aead/src/aes/backend.rs | 22 ++++++++++++++++++- .../vitaminc-aead/src/aes/backend/aws_lc.rs | 16 ++++++++++++++ .../src/aes/backend/rust_crypto.rs | 20 ++++++++++++----- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/packages/vitaminc-aead/src/aes/backend.rs b/packages/vitaminc-aead/src/aes/backend.rs index 2f873d35f..4176fc9b8 100644 --- a/packages/vitaminc-aead/src/aes/backend.rs +++ b/packages/vitaminc-aead/src/aes/backend.rs @@ -28,7 +28,7 @@ pub(crate) const NONCE_LEN: usize = 12; #[cfg(test)] mod tests { - use super::CipherKey; + use super::{CipherKey, NONCE_LEN}; // wasm-pack invokes Node by default — no `wasm_bindgen_test_configure!` needed. #[cfg(target_arch = "wasm32")] @@ -204,4 +204,24 @@ mod tests { "open must reject ciphertext whose bytes have been modified" ); } + + #[cfg_attr(not(target_arch = "wasm32"), test)] + #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + fn a_seal_that_fails_leaves_no_plaintext_in_the_buffer() { + let cipher = CipherKey::new(&fixed_key()).expect("key"); + let short_nonce = [0u8; NONCE_LEN - 1]; + + let mut buf = b"payload".to_vec(); + let sealed = cipher.seal(&short_nonce, b"", &mut buf); + + assert!( + sealed.is_err(), + "a nonce of the wrong length should be refused" + ); + assert!( + buf.is_empty(), + "the buffer should be wiped and cleared when the seal fails, length {}", + buf.len() + ); + } } diff --git a/packages/vitaminc-aead/src/aes/backend/aws_lc.rs b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs index c154b69e1..0f45bd6dd 100644 --- a/packages/vitaminc-aead/src/aes/backend/aws_lc.rs +++ b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs @@ -16,11 +16,27 @@ impl CipherKey { } /// Encrypts `in_out` in place and appends the authentication tag. + /// + /// On an error, `in_out` is wiped and cleared, so no plaintext is left + /// in a buffer the caller then drops. pub(crate) fn seal( &self, nonce: &[u8], aad: &[u8], in_out: &mut Vec, + ) -> Result<(), Unspecified> { + let sealed = self.seal_unwiped(nonce, aad, in_out); + if sealed.is_err() { + in_out.zeroize(); + } + sealed + } + + fn seal_unwiped( + &self, + nonce: &[u8], + aad: &[u8], + in_out: &mut Vec, ) -> Result<(), Unspecified> { reserve_tag(in_out); let nonce = LcNonce::try_assume_unique_for_key(nonce).map_err(|_| Unspecified)?; diff --git a/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs b/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs index 6f856b2ad..e544946c7 100644 --- a/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs +++ b/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs @@ -3,6 +3,7 @@ use crate::Unspecified; use aes_gcm::aead::{AeadInPlace, KeyInit, Tag}; use aes_gcm::{Aes256Gcm, Key, Nonce}; +use zeroize::Zeroize; /// The AES-GCM tag length. This backend splits the tag off the buffer /// itself; `aws-lc-rs` handles the tag internally, so only this backend @@ -18,17 +19,26 @@ impl CipherKey { } /// Encrypts `in_out` in place and appends the authentication tag. + /// + /// On an error, `in_out` is wiped and cleared, so no plaintext is left + /// in a buffer the caller then drops. pub(crate) fn seal( &self, nonce: &[u8], aad: &[u8], in_out: &mut Vec, ) -> Result<(), Unspecified> { - let nonce: &[u8; super::NONCE_LEN] = nonce.try_into().map_err(|_| Unspecified)?; - let nonce = Nonce::from_slice(nonce); - self.0 - .encrypt_in_place(nonce, aad, in_out) - .map_err(|_| Unspecified) + let sealed = match <&[u8; super::NONCE_LEN]>::try_from(nonce) { + Ok(nonce) => self + .0 + .encrypt_in_place(Nonce::from_slice(nonce), aad, in_out) + .map_err(|_| Unspecified), + Err(_) => Err(Unspecified), + }; + if sealed.is_err() { + in_out.zeroize(); + } + sealed } /// Decrypts `in_out` (ciphertext || tag) in place. Returns the plaintext From c5a12b7c992ff749547dd9e2e33c2c824fd883f2 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 00:20:37 +1100 Subject: [PATCH 09/25] docs: AGENTS.md says where the AES cipher is now 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. --- AGENTS.md | 9 +++++---- packages/eql/tests/encryption/tests/heap_hygiene.rs | 1 - 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index eca1b8467..7830652cc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -749,10 +749,11 @@ exact pin would stop the suite sharing one `cts-common` with it. vitaminc's AEAD crates (`vitaminc-aead`, `recipher-frame`, `vitaminc-aead-derive`) live here, in `packages/`, and are not published from -here yet. The other vitaminc crates come from crates.io at 0.10, and four of -them depend on `vitaminc-aead`: `vitaminc-normalize`, `vitaminc-prf`, -`vitaminc-ore` and `vitaminc-encrypt`, with the `vitaminc` umbrella crate, -`clww-ore` and `ore-rs` above them. So every Cargo workspace that resolves +here yet. The AES-256-GCM cipher is in `vitaminc-aead`, behind its `aes` +feature, so nothing here uses `vitaminc-encrypt` 0.10. The other vitaminc +crates come from crates.io at 0.10, and three of them depend on +`vitaminc-aead`: `vitaminc-normalize`, `vitaminc-prf` and `vitaminc-ore`, +with the `vitaminc` umbrella crate, `clww-ore` and `ore-rs` above them. So every Cargo workspace that resolves `vitaminc-aead` 0.10 carries a `[patch.crates-io]` table, with relative paths, that makes those crates build against the copies here. A workspace must have exactly one `vitaminc-aead` 0.10, and it must be the path crate: check with diff --git a/packages/eql/tests/encryption/tests/heap_hygiene.rs b/packages/eql/tests/encryption/tests/heap_hygiene.rs index a701ac976..bb6b6a1d3 100644 --- a/packages/eql/tests/encryption/tests/heap_hygiene.rs +++ b/packages/eql/tests/encryption/tests/heap_hygiene.rs @@ -10,7 +10,6 @@ //! indexed, when the value is refused or fails to open, and when the //! pending work is dropped before its keys arrive. stack-encrypt's //! `tests/heap_hygiene.rs` holds its dynamic paths the same way. - //! //! Unix only: the spy scans a freed block with libc's `memmem`, not as a //! Rust slice (see [`holds_mark`]). From edb10e4398ff3cd442490ddf8556dba16b865254 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 00:20:48 +1100 Subject: [PATCH 10/25] docs(vitaminc-aead): the changelog records the wipe on a failed seal --- packages/vitaminc-aead/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/vitaminc-aead/CHANGELOG.md b/packages/vitaminc-aead/CHANGELOG.md index d224967b8..cdb975620 100644 --- a/packages/vitaminc-aead/CHANGELOG.md +++ b/packages/vitaminc-aead/CHANGELOG.md @@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). aws-lc-rs makes the buffer longer for the tag before it encrypts, and a buffer with no spare room moves to a new block. The old block still held the plaintext. The backend now makes room for the tag first, and wipes the old block before it is freed. +- A seal that fails wipes and clears its buffer, on both backends. Before, the buffer still held the plaintext when the caller dropped it. - `plaintext::SourceError` prints `SourceError(..)` in `Debug`, and none of the error it wraps. The wrapped error comes from the caller's code, and its text can include the value that failed. Before, `Debug` printed that text, so `{:?}`, a log line, or a panic from `unwrap` could print the value. From 346379fbe9ded81781984e661fdc61b0f6dd9277 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:07:33 +1100 Subject: [PATCH 11/25] test(vitaminc-aead): run the AES backend tests as plain tests 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. --- Cargo.lock | 1 - packages/vitaminc-aead/Cargo.toml | 3 -- packages/vitaminc-aead/src/aes/backend.rs | 43 ++++++++--------------- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4dfac6a3d..6e182847b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4566,7 +4566,6 @@ dependencies = [ "vitaminc-prf", "vitaminc-protected 0.10.0", "vitaminc-random 0.10.0", - "wasm-bindgen-test", "zeroize", ] diff --git a/packages/vitaminc-aead/Cargo.toml b/packages/vitaminc-aead/Cargo.toml index 9368bd2bf..908c5693a 100644 --- a/packages/vitaminc-aead/Cargo.toml +++ b/packages/vitaminc-aead/Cargo.toml @@ -107,9 +107,6 @@ futures-executor = "0.3.31" serde_json = "1" jiff = { version = "1.0.1", default-features = false } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] -wasm-bindgen-test = "0.3" - [[test]] name = "aes_cipher" required-features = ["aes"] diff --git a/packages/vitaminc-aead/src/aes/backend.rs b/packages/vitaminc-aead/src/aes/backend.rs index 4176fc9b8..a10a30c8a 100644 --- a/packages/vitaminc-aead/src/aes/backend.rs +++ b/packages/vitaminc-aead/src/aes/backend.rs @@ -30,17 +30,12 @@ pub(crate) const NONCE_LEN: usize = 12; mod tests { use super::{CipherKey, NONCE_LEN}; - // wasm-pack invokes Node by default — no `wasm_bindgen_test_configure!` needed. - #[cfg(target_arch = "wasm32")] - use wasm_bindgen_test::wasm_bindgen_test; - /// Cross-backend byte-parity check. /// /// The same test runs against the `aws-lc-rs` backend on native targets, /// and against RustCrypto with the `_test-rust-crypto-backend` feature or /// on wasm32. Both must produce the byte string in `EXPECTED`. - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn cross_backend_byte_parity() { // Fixed inputs — chosen to exercise: non-empty plaintext, non-empty AAD, // a plaintext length that's not a block boundary (so we cover GCM's @@ -86,13 +81,11 @@ mod tests { ); } - // Deterministic counterparts to the quickcheck round-trip tests in - // `cipher::test`. Those property tests can't run under wasm-bindgen-test - // because quickcheck's runner uses `std::thread`, which isn't available on - // wasm32-unknown-unknown — so the cases below carry the same `#[cfg_attr]` - // attribute swap as the KAT and gate all three configurations (native - // aws-lc-rs, native RustCrypto, wasm32 RustCrypto in Node) on the same - // round-trip and failure-path behaviour. + // Fixed-input versions of the quickcheck round-trip tests in + // `cipher::test`. Those property tests are not compiled on wasm32. The + // cases below are, so the same round-trip and failure checks run against + // all three backends: aws-lc-rs on native targets, RustCrypto on native + // targets, and RustCrypto on wasm32-wasip1 under wasmtime. fn fixed_key() -> [u8; 32] { [ @@ -120,26 +113,22 @@ mod tests { assert_eq!(&buf[..pt_len], plaintext); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn roundtrip_no_aad() { roundtrip(b"hello world", b""); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn roundtrip_with_aad() { roundtrip(b"hello world", b"associated data"); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn roundtrip_empty_plaintext() { roundtrip(b"", b"some aad"); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn roundtrip_multi_block_plaintext() { // 200 bytes — spans multiple AES blocks (16B each) plus a partial tail, // catching any block-boundary handling regression. @@ -147,8 +136,7 @@ mod tests { roundtrip(&pt, b"multi-block aad"); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn open_fails_with_wrong_aad() { let key = fixed_key(); let nonce = fixed_nonce(); @@ -164,8 +152,7 @@ mod tests { ); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn open_fails_with_wrong_key() { let nonce = fixed_nonce(); @@ -185,8 +172,7 @@ mod tests { ); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn open_fails_with_tampered_ciphertext() { let key = fixed_key(); let nonce = fixed_nonce(); @@ -205,8 +191,7 @@ mod tests { ); } - #[cfg_attr(not(target_arch = "wasm32"), test)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[test] fn a_seal_that_fails_leaves_no_plaintext_in_the_buffer() { let cipher = CipherKey::new(&fixed_key()).expect("key"); let short_nonce = [0u8; NONCE_LEN - 1]; From 31fbfff92803443d5a1d4145de8a2fa811fdcbc3 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:07:50 +1100 Subject: [PATCH 12/25] build(vitaminc-aead): build aes-gcm only on wasm32 and for the test backend 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. --- packages/vitaminc-aead/Cargo.toml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/vitaminc-aead/Cargo.toml b/packages/vitaminc-aead/Cargo.toml index 908c5693a..4fb36aeb4 100644 --- a/packages/vitaminc-aead/Cargo.toml +++ b/packages/vitaminc-aead/Cargo.toml @@ -59,22 +59,26 @@ optional = true # The AES-256-GCM cipher (`aes`): aws-lc-rs on native targets, RustCrypto's # aes-gcm on wasm32. -[target.'cfg(not(target_arch = "wasm32"))'.dependencies.aws-lc-rs] -version = "1.17.0" -optional = true +# +# On native targets aes-gcm is optional and only `_test-rust-crypto-backend` +# turns it on. On wasm32 it is always a dependency, as in vitaminc-encrypt +# 0.10, which this cipher came from. A feature turns on a dependency by name +# on every target that declares it, so if `aes` turned on aes-gcm for wasm32 +# it would turn it on for native targets too. Cargo also refuses a second, +# renamed entry for the same crate. +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +aws-lc-rs = { version = "1.17.0", optional = true } +aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "zeroize"], optional = true } -[dependencies.aes-gcm] -version = "0.10" -default-features = false -features = ["aes", "alloc", "zeroize"] -optional = true +[target.'cfg(target_arch = "wasm32")'.dependencies] +aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "zeroize"] } [features] # The AES-256-GCM `Cipher` and its key, in the `aes` module. -aes = ["dep:aws-lc-rs", "dep:aes-gcm"] +aes = ["dep:aws-lc-rs"] # Not an API. Forces the RustCrypto backend on native targets, so its tests # run without a wasm toolchain. -_test-rust-crypto-backend = ["aes"] +_test-rust-crypto-backend = ["aes", "dep:aes-gcm"] jiff = ["dep:jiff"] rust_decimal = ["dep:rust_decimal"] uuid = ["dep:uuid"] From 028cfbeeb31fb062e06ab30eb4a867e66b14a22b Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:12:26 +1100 Subject: [PATCH 13/25] ci: test vitaminc-aead's AES cipher with each backend on the host 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). --- packages/vitaminc-aead/tasks.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vitaminc-aead/tasks.toml b/packages/vitaminc-aead/tasks.toml index 18c7eb06e..eaf99a5da 100644 --- a/packages/vitaminc-aead/tasks.toml +++ b/packages/vitaminc-aead/tasks.toml @@ -20,15 +20,21 @@ run = [ # package's graph, so each feature is tested on its own here, with the # storage bench's smoke run. # +# The `aes` feature runs twice: with aws-lc-rs, the native backend, and with +# `_test-rust-crypto-backend`, the RustCrypto backend that wasm32 builds use. +# The workspace run turns every feature on, so it tests only the second. +# # Two jiff tests check that jiff refuses to parse an instant below its own # minimum. jiff 1.0.0 built one only with debug assertions off, so they also # run in a release build. `cargo test` passes when its filter matches no # test, so the step also checks that both ran. On a failure it prints the # test output before it exits. ["test:vitaminc-aead:features"] -description = "Test vitaminc-aead with each optional feature alone (jiff, rust_decimal, uuid, hlist), its release-only jiff tests, and recipher-frame with and without serde" +description = "Test vitaminc-aead with each optional feature alone (aes with each backend, jiff, rust_decimal, uuid, hlist), its release-only jiff tests, and recipher-frame with and without serde" run = [ "cargo test --locked -p vitaminc-aead", + "cargo test --locked -p vitaminc-aead --features aes", + "cargo test --locked -p vitaminc-aead --features aes,_test-rust-crypto-backend", "cargo test --locked -p vitaminc-aead --features jiff", ''' out=$(cargo test --locked --release -p vitaminc-aead --features jiff --lib an_instant_jiff_cannot_rebuild) From c3bee80394e79da08920b326973ab13a07bd0c78 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:12:35 +1100 Subject: [PATCH 14/25] ci: run vitaminc-aead's tests on wasm32-wasip1 under wasmtime 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. --- .github/workflows/tests-crates.yml | 33 ++++++++++++++++++++++++++++++ mise.test.toml | 3 +++ packages/vitaminc-aead/tasks.toml | 19 +++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/.github/workflows/tests-crates.yml b/.github/workflows/tests-crates.yml index b31cbae84..45105c586 100644 --- a/.github/workflows/tests-crates.yml +++ b/.github/workflows/tests-crates.yml @@ -226,6 +226,39 @@ jobs: rm -rf -- "${target_dir}/package" done + # vitaminc-aead's tests on wasm32-wasip1, the target the Go guests build + # for, with wasmtime as the test runner. On that target the `aes` feature + # uses RustCrypto's aes-gcm. The task says which tests it skips and why. + vitaminc-aead-wasip1: + name: vitaminc-aead tests on wasm32-wasip1 + runs-on: runs-on=${{ github.run_id }}/family=c8a+m8a/cpu=4/image=ubuntu24-full-x64/volume=80gb/extras=s3-cache + timeout-minutes: 30 + env: + RUSTFLAGS: "-D warnings" + # wasmtime is pinned in mise.test.toml, which mise loads only in the + # test environment. + MISE_ENV: test + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + with: + persist-credentials: false + + # No install_args, as in `rust`: this installs (and caches) the whole + # test toolset, wasmtime with it. + - uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # v4 + with: + version: 2026.4.0 + install: true + working_directory: . + cache: true + # Must name runs-on's image; see scripts/__tests__/workflow-mise-cache-image.test.mjs + cache_key_prefix: mise-v1-ubuntu-2404 + + - uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2 + + - name: vitaminc-aead tests on wasm32-wasip1 (wasmtime) + run: mise run test:vitaminc-aead:wasip1 + # rustdoc checks intra-doc links but never fetches a URL, so this checks # the web links in the crates' docs with lychee. It reads every crate under # packages/ except EQL, which has its own docs checks. lychee.toml holds diff --git a/mise.test.toml b/mise.test.toml index b83d7479d..ec94b9e82 100644 --- a/mise.test.toml +++ b/mise.test.toml @@ -36,6 +36,9 @@ # prebuilt. "cargo:cargo-deny" = "0.20.2" "cargo:cargo-vet" = "0.10.3" +# Runs vitaminc-aead's wasm32-wasip1 test binaries; see +# `test:vitaminc-aead:wasip1`. A prebuilt release from GitHub. +"aqua:bytecodealliance/wasmtime" = "50.0.3" [env] # Annoyingly if you pass --env test to mise it doesn't set this automatically diff --git a/packages/vitaminc-aead/tasks.toml b/packages/vitaminc-aead/tasks.toml index eaf99a5da..68ae48779 100644 --- a/packages/vitaminc-aead/tasks.toml +++ b/packages/vitaminc-aead/tasks.toml @@ -53,3 +53,22 @@ run = [ "cargo test --locked -p recipher-frame --features serde", "cargo test --locked -p recipher-frame --features serde --bench storage", ] + +# The crate's tests on wasm32-wasip1, the target the Go guests build for, with +# wasmtime as the runner. wasmtime is pinned in mise.test.toml, so the task +# runs cargo under `mise x --env test`. On wasm32 the `aes` feature uses +# RustCrypto's aes-gcm. +# +# Three tests are skipped. Each runs trybuild, which starts cargo as a child +# process, and a WASI program cannot start a process. The other runs test +# them on the host. +# +# The test harness also reports three `should_panic` tests as ignored: a +# wasm32-wasip1 build stops on a panic, so the harness cannot catch one. +["test:vitaminc-aead:wasip1"] +description = "Test vitaminc-aead with the aes feature on wasm32-wasip1, under wasmtime" +env = { CARGO_TARGET_WASM32_WASIP1_RUNNER = "wasmtime" } +run = [ + "rustup target add wasm32-wasip1", + "mise x --env test -- cargo test --locked -p vitaminc-aead --features aes --target wasm32-wasip1 -- --skip derive_ui --skip containers_and_options_are_not_scalars --skip containers_are_not_scalar_targets", +] From 72f65af48dad65b0306e28f38a12e417bb649abf Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:13:16 +1100 Subject: [PATCH 15/25] chore(supply-chain): move pin-project-lite off a yanked version 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. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e182847b..5f040e8f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2556,9 +2556,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pin-project-lite" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe" [[package]] name = "pin-utils" From 5e88bb4d0fee1f9113110d201b63f8bc17438211 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:14:59 +1100 Subject: [PATCH 16/25] chore(supply-chain): allow the aws-lc crates' licences and build scripts 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. --- supply-chain/vitaminc-aead/deny.toml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/supply-chain/vitaminc-aead/deny.toml b/supply-chain/vitaminc-aead/deny.toml index 8e75f6421..df7650c1c 100644 --- a/supply-chain/vitaminc-aead/deny.toml +++ b/supply-chain/vitaminc-aead/deny.toml @@ -49,7 +49,20 @@ allow = [ "Unlicense", ] confidence-threshold = 0.8 -exceptions = [] +# ISC is a short permissive licence, like MIT. It is allowed only for the +# crates below, so a new ISC crate still fails here and is reviewed. +exceptions = [ + # The AES-256-GCM cipher on native targets (vitaminc-aead's `aes` + # feature). Its licence is "ISC AND (Apache-2.0 OR ISC)". + { crate = "aws-lc-rs", allow = ["ISC"] }, + # aws-lc-rs's bindings to the AWS-LC C library, bundled in the crate. Its + # licence names ISC, Apache-2.0, MIT and BSD-3-Clause, for parts of + # AWS-LC; only ISC is not on the allow list above. + { crate = "aws-lc-sys", allow = ["ISC"] }, + # aws-lc-rs's default `ring-io` and `ring-sig-verify` features use it to + # read input. Licence: ISC. + { crate = "untrusted", allow = ["ISC"] }, +] [licenses.private] ignore = true @@ -72,6 +85,14 @@ deny = [] # decides whether to add it. allow-build-scripts = [ "alloca", + # aws-lc-rs: checks that `fips` and `non-fips` are not both on, and passes + # the include path aws-lc-sys exports on to crates that build against it. + # It reads environment variables only, and starts no process. + "aws-lc-rs", + # aws-lc-sys: compiles the bundled AWS-LC C library with the cc crate (or + # CMake, when asked) and links it. It starts the C compiler, and can use a + # system AWS-LC instead when AWS_LC_SYS_SYSTEM_DIR is set. + "aws-lc-sys", "borsh", "crunchy", "getrandom", From 40641e7526fb29be2864830d20c467b3319c74fe Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:17:32 +1100 Subject: [PATCH 17/25] chore(supply-chain): trust the aws-lc-sys publisher for safe-to-deploy 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. --- supply-chain/vitaminc-aead/audits.toml | 7 +++++++ supply-chain/vitaminc-aead/config.toml | 4 ---- supply-chain/vitaminc-aead/imports.lock | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/supply-chain/vitaminc-aead/audits.toml b/supply-chain/vitaminc-aead/audits.toml index e8c485930..b234b6730 100644 --- a/supply-chain/vitaminc-aead/audits.toml +++ b/supply-chain/vitaminc-aead/audits.toml @@ -254,3 +254,10 @@ who = "Dan Draper " criteria = "safe-to-run" delta = "0.2.129 -> 0.2.130" notes = "A check-cfg entry; no source change." + +[[trusted.aws-lc-sys]] +criteria = "safe-to-deploy" +user-id = 156764 # Justin W Smith (justsmth) +start = "2022-11-09" +end = "2027-12-04" +notes = "aws-lc-sys holds about 2.1 million lines: the AWS-LC C library, its Rust bindings and the build script that compiles them. Nobody here can read that much code. We accept the review AWS gives its own releases. The same account publishes aws-lc-rs. This entry trusts aws-lc-sys only: aws-lc-rs, the Rust layer vitaminc-aead calls, needs its own audit." diff --git a/supply-chain/vitaminc-aead/config.toml b/supply-chain/vitaminc-aead/config.toml index 111b70e27..abc612f24 100644 --- a/supply-chain/vitaminc-aead/config.toml +++ b/supply-chain/vitaminc-aead/config.toml @@ -88,10 +88,6 @@ criteria = "safe-to-deploy" version = "1.18.0" criteria = "safe-to-run" -[[exemptions.aws-lc-sys]] -version = "0.44.0" -criteria = "safe-to-run" - [[exemptions.bitvec]] version = "1.0.1" criteria = "safe-to-deploy" diff --git a/supply-chain/vitaminc-aead/imports.lock b/supply-chain/vitaminc-aead/imports.lock index 5fe3e01ee..7e4aad40b 100644 --- a/supply-chain/vitaminc-aead/imports.lock +++ b/supply-chain/vitaminc-aead/imports.lock @@ -1,6 +1,13 @@ # cargo-vet imports lock +[[publisher.aws-lc-sys]] +version = "0.44.0" +when = "2026-08-07" +user-id = 156764 +user-login = "justsmth" +user-name = "Justin W Smith" + [[publisher.bumpalo]] version = "3.19.1" when = "2025-12-16" From 2e12aaed8354feacc7d428717301013cb4a419d5 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:17:41 +1100 Subject: [PATCH 18/25] chore(supply-chain): remove the exemption for vitaminc-encrypt 0.10.0 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. --- supply-chain/vitaminc-aead/config.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/supply-chain/vitaminc-aead/config.toml b/supply-chain/vitaminc-aead/config.toml index abc612f24..2d6a62dbe 100644 --- a/supply-chain/vitaminc-aead/config.toml +++ b/supply-chain/vitaminc-aead/config.toml @@ -492,10 +492,6 @@ criteria = "safe-to-run" version = "0.10.0" criteria = "safe-to-deploy" -[[exemptions.vitaminc-encrypt]] -version = "0.10.0" -criteria = "safe-to-run" - [[exemptions.vitaminc-normalize]] version = "0.10.0" criteria = "safe-to-run" From 62c25b2b74028d0e751c35ae85cbd89305f2030b Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 18:18:42 +1100 Subject: [PATCH 19/25] build(auth-guest): record vitaminc-aead's aes-gcm dependency in the lock 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. --- languages/golang/auth/guest/Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/golang/auth/guest/Cargo.lock b/languages/golang/auth/guest/Cargo.lock index 90f14b9ad..e31a15ba3 100644 --- a/languages/golang/auth/guest/Cargo.lock +++ b/languages/golang/auth/guest/Cargo.lock @@ -2297,6 +2297,7 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", "bytes", "futures-util", "serde", From 76cf7407704c2579defa8f9f899dd832ad5e6cbd Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 19:00:52 +1100 Subject: [PATCH 20/25] build(vitaminc-aead): choose the RustCrypto backend with a cfg, not a 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. --- .github/workflows/tests-crates.yml | 4 +++- languages/golang/auth/guest/Cargo.lock | 1 - packages/vitaminc-aead/Cargo.toml | 27 ++++++++++++----------- packages/vitaminc-aead/src/aes/backend.rs | 14 ++++++------ packages/vitaminc-aead/tasks.toml | 14 ++++++++---- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/.github/workflows/tests-crates.yml b/.github/workflows/tests-crates.yml index 45105c586..86f2ad9c3 100644 --- a/.github/workflows/tests-crates.yml +++ b/.github/workflows/tests-crates.yml @@ -143,7 +143,9 @@ jobs: run: mise x --env test -- cargo nextest run --locked --workspace --all-features # The run above turns every feature on at once; this tests the AEAD - # crates' optional features one at a time. + # crates' optional features one at a time. The run above tests the AES + # cipher with aws-lc-rs only. This also tests it with the RustCrypto + # backend, and runs stack-encrypt's heap_hygiene test with it. - name: vitaminc-aead feature combinations run: mise run test:vitaminc-aead:features diff --git a/languages/golang/auth/guest/Cargo.lock b/languages/golang/auth/guest/Cargo.lock index e31a15ba3..90f14b9ad 100644 --- a/languages/golang/auth/guest/Cargo.lock +++ b/languages/golang/auth/guest/Cargo.lock @@ -2297,7 +2297,6 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ - "aes-gcm", "bytes", "futures-util", "serde", diff --git a/packages/vitaminc-aead/Cargo.toml b/packages/vitaminc-aead/Cargo.toml index 4fb36aeb4..d5101a21f 100644 --- a/packages/vitaminc-aead/Cargo.toml +++ b/packages/vitaminc-aead/Cargo.toml @@ -60,25 +60,23 @@ optional = true # The AES-256-GCM cipher (`aes`): aws-lc-rs on native targets, RustCrypto's # aes-gcm on wasm32. # -# On native targets aes-gcm is optional and only `_test-rust-crypto-backend` -# turns it on. On wasm32 it is always a dependency, as in vitaminc-encrypt -# 0.10, which this cipher came from. A feature turns on a dependency by name -# on every target that declares it, so if `aes` turned on aes-gcm for wasm32 -# it would turn it on for native targets too. Cargo also refuses a second, -# renamed entry for the same crate. +# Each dependency is declared only for the targets that use it, and `aes` +# turns on both. A feature turns on a dependency only on the targets that +# declare it. So a wasm32 build never has aws-lc-rs, and a native build has +# aes-gcm only with the cfg below. A build without `aes` has neither. +# +# The `vitaminc_aead_rust_crypto` cfg makes a native build use the RustCrypto +# backend, so its tests run on the host. Add it to RUSTFLAGS: +# `RUSTFLAGS="$RUSTFLAGS --cfg vitaminc_aead_rust_crypto"`. It is not an API. [target.'cfg(not(target_arch = "wasm32"))'.dependencies] aws-lc-rs = { version = "1.17.0", optional = true } -aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "zeroize"], optional = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] -aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "zeroize"] } +[target.'cfg(any(target_arch = "wasm32", vitaminc_aead_rust_crypto))'.dependencies] +aes-gcm = { version = "0.10", default-features = false, features = ["aes", "alloc", "zeroize"], optional = true } [features] # The AES-256-GCM `Cipher` and its key, in the `aes` module. -aes = ["dep:aws-lc-rs"] -# Not an API. Forces the RustCrypto backend on native targets, so its tests -# run without a wasm toolchain. -_test-rust-crypto-backend = ["aes", "dep:aes-gcm"] +aes = ["dep:aws-lc-rs", "dep:aes-gcm"] jiff = ["dep:jiff"] rust_decimal = ["dep:rust_decimal"] uuid = ["dep:uuid"] @@ -96,6 +94,9 @@ hlist = [] # dev-dependencies turn it on, so no published build has it. test-support = [] +# Declares the cfg above to rustc, so a build that tests for it does not warn. +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(vitaminc_aead_rust_crypto)'] } [dev-dependencies] # Only the test that pins `into_aad` and `into_prf_context` to the same diff --git a/packages/vitaminc-aead/src/aes/backend.rs b/packages/vitaminc-aead/src/aes/backend.rs index a10a30c8a..440e5c9a2 100644 --- a/packages/vitaminc-aead/src/aes/backend.rs +++ b/packages/vitaminc-aead/src/aes/backend.rs @@ -10,17 +10,17 @@ //! Both implementations conform to RFC 5116 AES-256-GCM and produce //! byte-identical ciphertext+tag output for the same inputs. //! -//! The internal `_test-rust-crypto-backend` feature forces the RustCrypto -//! backend on native targets so CI can exercise it without wasm tooling. +//! The `vitaminc_aead_rust_crypto` cfg makes a native build use the +//! RustCrypto backend, so its tests run on the host. -#[cfg(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend"))] +#[cfg(any(target_arch = "wasm32", vitaminc_aead_rust_crypto))] mod rust_crypto; -#[cfg(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend"))] +#[cfg(any(target_arch = "wasm32", vitaminc_aead_rust_crypto))] pub(crate) use rust_crypto::CipherKey; -#[cfg(not(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend")))] +#[cfg(not(any(target_arch = "wasm32", vitaminc_aead_rust_crypto)))] mod aws_lc; -#[cfg(not(any(target_arch = "wasm32", feature = "_test-rust-crypto-backend")))] +#[cfg(not(any(target_arch = "wasm32", vitaminc_aead_rust_crypto)))] pub(crate) use aws_lc::CipherKey; /// AES-256-GCM nonce length, in bytes. @@ -33,7 +33,7 @@ mod tests { /// Cross-backend byte-parity check. /// /// The same test runs against the `aws-lc-rs` backend on native targets, - /// and against RustCrypto with the `_test-rust-crypto-backend` feature or + /// and against RustCrypto with the `vitaminc_aead_rust_crypto` cfg or /// on wasm32. Both must produce the byte string in `EXPECTED`. #[test] fn cross_backend_byte_parity() { diff --git a/packages/vitaminc-aead/tasks.toml b/packages/vitaminc-aead/tasks.toml index 68ae48779..79d685e27 100644 --- a/packages/vitaminc-aead/tasks.toml +++ b/packages/vitaminc-aead/tasks.toml @@ -21,8 +21,13 @@ run = [ # storage bench's smoke run. # # The `aes` feature runs twice: with aws-lc-rs, the native backend, and with -# `_test-rust-crypto-backend`, the RustCrypto backend that wasm32 builds use. -# The workspace run turns every feature on, so it tests only the second. +# the `vitaminc_aead_rust_crypto` cfg, which makes a native build use the +# RustCrypto backend that wasm32 builds use. The workspace run tests only +# aws-lc-rs. The cfg is added to RUSTFLAGS, so the `-D warnings` that CI puts +# there still applies. With the cfg, stack-encrypt's heap_hygiene test runs +# too. It checks that no heap block freed while sealing or opening still +# holds plaintext, and the workspace run checks this only for aws-lc-rs. +# The test needs nextest, which mise.test.toml pins. # # Two jiff tests check that jiff refuses to parse an instant below its own # minimum. jiff 1.0.0 built one only with debug assertions off, so they also @@ -30,11 +35,12 @@ run = [ # test, so the step also checks that both ran. On a failure it prints the # test output before it exits. ["test:vitaminc-aead:features"] -description = "Test vitaminc-aead with each optional feature alone (aes with each backend, jiff, rust_decimal, uuid, hlist), its release-only jiff tests, and recipher-frame with and without serde" +description = "Test each optional feature of vitaminc-aead alone and its AES cipher with each backend. Also test recipher-frame with and without serde" run = [ "cargo test --locked -p vitaminc-aead", "cargo test --locked -p vitaminc-aead --features aes", - "cargo test --locked -p vitaminc-aead --features aes,_test-rust-crypto-backend", + 'RUSTFLAGS="$RUSTFLAGS --cfg vitaminc_aead_rust_crypto" cargo test --locked -p vitaminc-aead --features aes', + 'RUSTFLAGS="$RUSTFLAGS --cfg vitaminc_aead_rust_crypto" mise x --env test -- cargo nextest run --locked -p stack-encrypt --all-features --test heap_hygiene', "cargo test --locked -p vitaminc-aead --features jiff", ''' out=$(cargo test --locked --release -p vitaminc-aead --features jiff --lib an_instant_jiff_cannot_rebuild) From d7c39fa12caf7804d4c7cea2b300aacb9e06e24f Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 19:01:31 +1100 Subject: [PATCH 21/25] chore(supply-chain): allow generic-array's build script 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. --- supply-chain/vitaminc-aead/deny.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/supply-chain/vitaminc-aead/deny.toml b/supply-chain/vitaminc-aead/deny.toml index df7650c1c..b9619acde 100644 --- a/supply-chain/vitaminc-aead/deny.toml +++ b/supply-chain/vitaminc-aead/deny.toml @@ -95,6 +95,11 @@ allow-build-scripts = [ "aws-lc-sys", "borsh", "crunchy", + # generic-array 0.14: a dependency of RustCrypto's aes-gcm, the AES-256-GCM + # cipher on wasm32. The build script asks version_check for the rustc + # version. version_check runs `rustc --version`. The script sets one cfg + # when the version is 1.41 or later. It does nothing else. + "generic-array", "getrandom", "libc", "num-traits", From 2c0830c8d1e3c7ebeb163ed8902428f816e124bd Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 19:15:02 +1100 Subject: [PATCH 22/25] chore(supply-chain): trust the cc-rs trusted publisher for cc 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. --- supply-chain/vitaminc-aead/audits.toml | 7 +++++++ supply-chain/vitaminc-aead/config.toml | 4 ---- supply-chain/vitaminc-aead/imports.lock | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/supply-chain/vitaminc-aead/audits.toml b/supply-chain/vitaminc-aead/audits.toml index b234b6730..531dd00fd 100644 --- a/supply-chain/vitaminc-aead/audits.toml +++ b/supply-chain/vitaminc-aead/audits.toml @@ -261,3 +261,10 @@ user-id = 156764 # Justin W Smith (justsmth) start = "2022-11-09" end = "2027-12-04" notes = "aws-lc-sys holds about 2.1 million lines: the AWS-LC C library, its Rust bindings and the build script that compiles them. Nobody here can read that much code. We accept the review AWS gives its own releases. The same account publishes aws-lc-rs. This entry trusts aws-lc-sys only: aws-lc-rs, the Rust layer vitaminc-aead calls, needs its own audit." + +[[trusted.cc]] +criteria = "safe-to-deploy" +trusted-publisher = "github:rust-lang/cc-rs" +start = "2025-09-01" +end = "2027-12-04" +notes = "cc runs the C compiler for build scripts. Here aws-lc-sys uses it, directly and through cmake, to compile the AWS-LC C library. Versions up to 1.2.34 were published by the crates.io user rust-lang-owner. Later versions, 1.2.55 among them, are published by the crates.io trusted publisher of the rust-lang/cc-rs repository. 1.2.55 is the version in the graph." diff --git a/supply-chain/vitaminc-aead/config.toml b/supply-chain/vitaminc-aead/config.toml index 2d6a62dbe..21ce0c894 100644 --- a/supply-chain/vitaminc-aead/config.toml +++ b/supply-chain/vitaminc-aead/config.toml @@ -112,10 +112,6 @@ criteria = "safe-to-deploy" version = "1.12.1" criteria = "safe-to-deploy" -[[exemptions.cc]] -version = "1.2.55" -criteria = "safe-to-run" - [[exemptions.cfg_aliases]] version = "0.2.1" criteria = "safe-to-deploy" diff --git a/supply-chain/vitaminc-aead/imports.lock b/supply-chain/vitaminc-aead/imports.lock index 7e4aad40b..43a921a6e 100644 --- a/supply-chain/vitaminc-aead/imports.lock +++ b/supply-chain/vitaminc-aead/imports.lock @@ -15,6 +15,11 @@ user-id = 696 user-login = "fitzgen" user-name = "Nick Fitzgerald" +[[publisher.cc]] +version = "1.2.55" +when = "2026-01-30" +trusted-publisher = "github:rust-lang/cc-rs" + [[publisher.unicode-normalization]] version = "0.1.25" when = "2025-10-30" From 7245174b5e554b79f08bb22ba37e03a11bf85214 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Sat, 5 Dec 2026 14:48:57 +1100 Subject: [PATCH 23/25] chore(supply-chain): audit aws-lc-rs 1.18.0 and pin-project-lite 0.2.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. --- supply-chain/vitaminc-aead/audits.toml | 12 ++++++++++++ supply-chain/vitaminc-aead/config.toml | 4 ---- supply-chain/vitaminc-aead/imports.lock | 18 ++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/supply-chain/vitaminc-aead/audits.toml b/supply-chain/vitaminc-aead/audits.toml index 531dd00fd..2d181c63e 100644 --- a/supply-chain/vitaminc-aead/audits.toml +++ b/supply-chain/vitaminc-aead/audits.toml @@ -33,6 +33,12 @@ registry publishes audits under the same name, and they are imported as-is. """ implies = "crypto-reviewed" +[[audits.aws-lc-rs]] +who = "Dan Draper " +criteria = "safe-to-deploy" +version = "1.18.0" +notes = "Read build.rs and every line with unsafe in src/ (367 of 367), with the surrounding code and callers. No fs, net, process or env use; no proc macros. Soundness relies on AWS-LC's documented contracts (thread safety of EVP_PKEY/RSA/EC_KEY, ownership on success for assign/set0, output sizes), covered by trusting the aws-lc-sys publisher. Defect: with the non-default legacy-des feature, the streaming cipher API accepts an AES key with an Iv64 context, and EVP_*Init_ex then reads 16 bytes from an 8-byte buffer (only a debug_assert checks the IV length; cipher/streaming.rs). Not reachable with default features. Minor: assume_init on a partly written AES_KEY (cipher/key.rs, key_wrap.rs) and from_raw_parts_mut over fresh malloc memory (rsa/encryption/oaep.rs)." + [[audits.aws-lc-rs]] who = "Dan Draper " criteria = ["safe-to-deploy", "crypto-reviewed"] @@ -123,6 +129,12 @@ criteria = "safe-to-deploy" delta = "3.4.0 -> 3.4.1" notes = "One doc-comment path fix in src/wasi_heap_sync.rs; no code change. build.rs unchanged." +[[audits.pin-project-lite]] +who = "Dan Draper " +criteria = "safe-to-deploy" +delta = "0.2.17 -> 0.2.19" +notes = "Read the full diff (46 files) and the changed macro rules in src/lib.rs. The changes make pin_project! reject: project_replace together with PinnedDrop; a handwritten Drop when the PinnedDrop impl is removed by cfg (new GeneratedDrop/DetectDrop/verify_drop check); a PinnedDrop impl for a different type (invariant &mut *mut Self check); #[project(!X)] for X other than Unpin; and (0.2.18) a handwritten Drop on an unsized type (MustNotImplDrop blanket now ?Sized). No new unsafe operations in generated code; one new unsafe impl of a method-less marker trait. No build script, normal dependencies or features; still no_std, macro_rules only. Dev-dependency rustversion replaced by build-context. The packed UI test was moved out of the run; the packed check itself is unchanged." + [[audits.portable-atomic]] who = "Dan Draper " criteria = "safe-to-deploy" diff --git a/supply-chain/vitaminc-aead/config.toml b/supply-chain/vitaminc-aead/config.toml index 21ce0c894..dcbe74624 100644 --- a/supply-chain/vitaminc-aead/config.toml +++ b/supply-chain/vitaminc-aead/config.toml @@ -84,10 +84,6 @@ criteria = "safe-to-deploy" version = "0.6.1" criteria = "safe-to-deploy" -[[exemptions.aws-lc-rs]] -version = "1.18.0" -criteria = "safe-to-run" - [[exemptions.bitvec]] version = "1.0.1" criteria = "safe-to-deploy" diff --git a/supply-chain/vitaminc-aead/imports.lock b/supply-chain/vitaminc-aead/imports.lock index 43a921a6e..782a61efa 100644 --- a/supply-chain/vitaminc-aead/imports.lock +++ b/supply-chain/vitaminc-aead/imports.lock @@ -447,6 +447,12 @@ who = "Pat Hickey " criteria = "safe-to-deploy" version = "0.1.0" +[[audits.bytecode-alliance.audits.pkg-config]] +who = "Pat Hickey " +criteria = "safe-to-deploy" +version = "0.3.25" +notes = "This crate shells out to the pkg-config executable, but it appears to sanitize inputs reasonably." + [[audits.bytecode-alliance.audits.pkg-config]] who = "Alex Crichton " criteria = "safe-to-deploy" @@ -982,12 +988,6 @@ version = "0.1.46" notes = "Contains no unsafe" aggregated-from = "https://chromium.googlesource.com/chromium/src/+/main/third_party/rust/chromium_crates_io/supply-chain/audits.toml?format=TEXT" -[[audits.google.audits.pkg-config]] -who = "Alexandre Courbot " -criteria = "safe-to-run" -version = "0.3.26" -aggregated-from = "https://chromium.googlesource.com/chromiumos/third_party/rust_crates/+/refs/heads/main/cargo-vet/audits.toml?format=TEXT" - [[audits.google.audits.potential_utf]] who = "Manish Goregaokar " criteria = ["safe-to-deploy", "does-not-implement-crypto"] @@ -1827,6 +1827,12 @@ criteria = "safe-to-deploy" delta = "2.3.1 -> 2.3.2" aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" +[[audits.mozilla.audits.pkg-config]] +who = "Mike Hommey " +criteria = "safe-to-deploy" +delta = "0.3.25 -> 0.3.26" +aggregated-from = "https://raw.githubusercontent.com/mozilla-firefox/firefox/main/supply-chain/audits.toml" + [[audits.mozilla.audits.potential_utf]] who = "Makoto Kato " criteria = "safe-to-deploy" From e0208ea38cfe1fdaeba12f71b9a9d7be94232d60 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Sat, 5 Dec 2026 15:12:54 +1100 Subject: [PATCH 24/25] fix(deps): move aws-lc-rs to 1.18.1 and aws-lc-sys to 0.45.0 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. --- .changeset/auth-aws-lc-rs-1-18-1.md | 8 ++++++++ Cargo.lock | 8 ++++---- languages/golang/encrypt/guest/Cargo.lock | 8 ++++---- packages/stack-auth/fuzz/Cargo.lock | 8 ++++---- packages/stack-encrypt/fuzz/Cargo.lock | 8 ++++---- packages/stack-kms/fuzz/Cargo.lock | 8 ++++---- 6 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 .changeset/auth-aws-lc-rs-1-18-1.md diff --git a/.changeset/auth-aws-lc-rs-1-18-1.md b/.changeset/auth-aws-lc-rs-1-18-1.md new file mode 100644 index 000000000..47458972a --- /dev/null +++ b/.changeset/auth-aws-lc-rs-1-18-1.md @@ -0,0 +1,8 @@ +--- +"@cipherstash/auth": patch +--- + +The native binaries now use aws-lc-rs 1.18.1 and aws-lc-sys 0.45.0. These +versions fix the GitHub security advisory GHSA-xv35-xp83-5wrf. The advisory +affects aws-lc-rs 1.18.0 and aws-lc-sys before 0.45.0. The package does not +call the affected code. The package's API is unchanged. diff --git a/Cargo.lock b/Cargo.lock index 5f040e8f9..058bba2b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -202,9 +202,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" dependencies = [ "aws-lc-sys", "untrusted 0.7.1", @@ -213,9 +213,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" dependencies = [ "cc", "cmake", diff --git a/languages/golang/encrypt/guest/Cargo.lock b/languages/golang/encrypt/guest/Cargo.lock index c6e996906..a5a75f311 100644 --- a/languages/golang/encrypt/guest/Cargo.lock +++ b/languages/golang/encrypt/guest/Cargo.lock @@ -122,9 +122,9 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "aws-lc-rs" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" dependencies = [ "aws-lc-sys", "untrusted", @@ -133,9 +133,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" dependencies = [ "cc", "cmake", diff --git a/packages/stack-auth/fuzz/Cargo.lock b/packages/stack-auth/fuzz/Cargo.lock index 913c40795..ff13f4ba0 100644 --- a/packages/stack-auth/fuzz/Cargo.lock +++ b/packages/stack-auth/fuzz/Cargo.lock @@ -176,9 +176,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" dependencies = [ "aws-lc-sys", "untrusted 0.7.1", @@ -187,9 +187,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" dependencies = [ "cc", "cmake", diff --git a/packages/stack-encrypt/fuzz/Cargo.lock b/packages/stack-encrypt/fuzz/Cargo.lock index 3641d40fa..6dfb2e63f 100644 --- a/packages/stack-encrypt/fuzz/Cargo.lock +++ b/packages/stack-encrypt/fuzz/Cargo.lock @@ -131,9 +131,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" dependencies = [ "aws-lc-sys", "untrusted", @@ -142,9 +142,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" dependencies = [ "cc", "cmake", diff --git a/packages/stack-kms/fuzz/Cargo.lock b/packages/stack-kms/fuzz/Cargo.lock index c429c04ce..a9d630b28 100644 --- a/packages/stack-kms/fuzz/Cargo.lock +++ b/packages/stack-kms/fuzz/Cargo.lock @@ -133,9 +133,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-lc-rs" -version = "1.18.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce2b2dcc879c3bae0d371e77c99f2238400ef24ec001394befa67b6e543add9e" +checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" dependencies = [ "aws-lc-sys", "untrusted", @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f09fae7be8bb3174e05c6afdb34199e6dc0c7c04ba9fa237b1967adfbde27483" +checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" dependencies = [ "cc", "cmake", From 2489e58b8b3805fe3af7f725a37e5d390edf40d3 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Sat, 5 Dec 2026 15:12:54 +1100 Subject: [PATCH 25/25] chore(supply-chain): audit aws-lc-rs 1.18.0 to 1.18.1, and correct the 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. --- supply-chain/vitaminc-aead/audits.toml | 8 +++++++- supply-chain/vitaminc-aead/imports.lock | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/supply-chain/vitaminc-aead/audits.toml b/supply-chain/vitaminc-aead/audits.toml index 2d181c63e..95873dfb3 100644 --- a/supply-chain/vitaminc-aead/audits.toml +++ b/supply-chain/vitaminc-aead/audits.toml @@ -37,7 +37,7 @@ implies = "crypto-reviewed" who = "Dan Draper " criteria = "safe-to-deploy" version = "1.18.0" -notes = "Read build.rs and every line with unsafe in src/ (367 of 367), with the surrounding code and callers. No fs, net, process or env use; no proc macros. Soundness relies on AWS-LC's documented contracts (thread safety of EVP_PKEY/RSA/EC_KEY, ownership on success for assign/set0, output sizes), covered by trusting the aws-lc-sys publisher. Defect: with the non-default legacy-des feature, the streaming cipher API accepts an AES key with an Iv64 context, and EVP_*Init_ex then reads 16 bytes from an 8-byte buffer (only a debug_assert checks the IV length; cipher/streaming.rs). Not reachable with default features. Minor: assume_init on a partly written AES_KEY (cipher/key.rs, key_wrap.rs) and from_raw_parts_mut over fresh malloc memory (rsa/encryption/oaep.rs)." +notes = "Read build.rs and every line with unsafe in src/ (367 of 367), with the surrounding code and callers. No fs, net, process or env use; no proc macros. Soundness relies on AWS-LC's documented contracts (thread safety of EVP_PKEY/RSA/EC_KEY, ownership on success for assign/set0, output sizes), covered by trusting the aws-lc-sys publisher. Defect: with the non-default legacy-des feature, the streaming cipher API accepts an AES key with an Iv64 context, and EVP_*Init_ex then reads 16 bytes from an 8-byte buffer (only a debug_assert checks the IV length; cipher/streaming.rs). Not reachable with default features. Minor: assume_init on a partly written AES_KEY (cipher/key.rs, key_wrap.rs) and from_raw_parts_mut over fresh malloc memory (rsa/encryption/oaep.rs). Missed by this review and found later: 1.18.0 has GHSA-xv35-xp83-5wrf, an out-of-bounds write in StreamingDecryptingKey's padded decrypt (cbc_pkcs7, ecb_pkcs7) when update or less_safe_update is called more than once with a minimum-size buffer; the cause is EVP_DecryptUpdate in aws-lc-sys 0.44.0. Also missed: the AEAD seal_in_place_append_tag path trusts the caller's Extend and AsMut, so a safe custom InOut type can make EVP_AEAD_CTX_seal write past the slice (aead/unbound_key.rs seal_combined, seal_combined_randnonce); Vec is not affected. Both are fixed in aws-lc-rs 1.18.1 with aws-lc-sys 0.45.0." [[audits.aws-lc-rs]] who = "Dan Draper " @@ -45,6 +45,12 @@ criteria = ["safe-to-deploy", "crypto-reviewed"] delta = "1.17.3 -> 1.18.2" notes = "Full read of the delta: ML-DSA stabilised out of unstable, RSA KeyPair::from_components validated with RSA_check_key, out-of-place AEAD seal_out_of_place_scatter with every buffer length checked before EVP_AEAD_CTX_seal_scatter, and 1.18.1's fail-closed tightening of seal_in_place_append_tag (post-Extend length verified before the FFI capacity is passed), streaming-cipher IV-context validation, and RSA digest-algorithm matching enforced on the ParsedPublicKey path. Zeroization only improved (ECDH agree returns Zeroizing>, KeyEncryptionKey zeroizes on drop); no change to rand/SystemRandom, AES-GCM, HMAC, nonce or tag handling, and the new branches are on public lengths only. No feature or build.rs change; aws-lc-sys moves 0.43 to 0.46 (AWS-LC 5.2 to 5.11, including the EVP_DecryptUpdate padded-mode fix the new canary tests pin) and is audited separately. One semantic change: hkdf::Salt::from(Okm) now takes the Salt algorithm from the Okm's requested Algorithm rather than the PRK's; vitaminc does not use that path." +[[audits.aws-lc-rs]] +who = "Dan Draper " +criteria = "safe-to-deploy" +delta = "1.18.0 -> 1.18.1" +notes = "Read every changed line in build.rs (unchanged), Cargo.toml and src/. Tarball matches tag v1.18.1 (commit 22e629d5). No unsafe lines, unsafe fns, unsafe impls or FFI declarations added or removed; no fs, net, process or env use; no new dependencies or features. Changes at unsafe call sites: AEAD seal_combined now checks that Extend grew the buffer by exactly the tag and passes the slice length to EVP_AEAD_CTX_seal, and seal_combined_randnonce takes pointer and length from one slice (1.18.0 could write past the slice with a safe custom Extend or AsMut); the streaming cipher constructors now check the IV context before EVP_*Init_ex (1.18.0 read 16 bytes from an 8-byte Iv64 with legacy-des); the ECDH secret is held in Zeroizing. GHSA-xv35-xp83-5wrf (StreamingDecryptingKey padded decrypt over-write) is fixed in AWS-LC's EVP_DecryptUpdate in aws-lc-sys 0.45.0; 1.18.1 requires aws-lc-sys 0.45.0 and fips-sys 0.14.2, and its unchanged output-size checks are correct against the 0.45.0 C code. Also: RSA digest check now on the parsed-key path, new ECDSA_P256_SHA1_ASN1 constant, HKDF Salt::from(Okm) algorithm fix. The 1.18.0 findings on assume_init of AES_KEY and from_raw_parts_mut in oaep.rs remain." + [[audits.aws-lc-rs]] who = "Dan Draper " criteria = ["safe-to-deploy", "crypto-reviewed"] diff --git a/supply-chain/vitaminc-aead/imports.lock b/supply-chain/vitaminc-aead/imports.lock index 782a61efa..c38cd07bc 100644 --- a/supply-chain/vitaminc-aead/imports.lock +++ b/supply-chain/vitaminc-aead/imports.lock @@ -2,8 +2,8 @@ # cargo-vet imports lock [[publisher.aws-lc-sys]] -version = "0.44.0" -when = "2026-08-07" +version = "0.45.0" +when = "2026-09-01" user-id = 156764 user-login = "justsmth" user-name = "Justin W Smith"