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/.github/workflows/tests-crates.yml b/.github/workflows/tests-crates.yml index b31cbae84..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 @@ -226,6 +228,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/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/Cargo.lock b/Cargo.lock index 283ca69ad..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", @@ -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" @@ -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]] @@ -4550,6 +4547,8 @@ dependencies = [ name = "vitaminc-aead" version = "0.10.0" dependencies = [ + "aes-gcm", + "aws-lc-rs", "bytes", "futures-executor", "futures-util", @@ -4628,20 +4627,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" @@ -4826,22 +4811,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..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", @@ -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..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,13 +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_encrypt::{Aes256Cipher, Key, LocalCipherText}; use vitaminc_protected::{Controlled, Protected}; /// The wrapper classes, exported so JavaScript can make instances with 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/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..bb6b6a1d3 100644 --- a/packages/eql/tests/encryption/tests/heap_hygiene.rs +++ b/packages/eql/tests/encryption/tests/heap_hygiene.rs @@ -10,14 +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-encrypt 0.6.0's aws-lc backend -//! (`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 //! Rust slice (see [`holds_mark`]). @@ -55,16 +47,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_encrypt::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 +96,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 +136,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/eql/tests/encryption/tests/opaque_json_bytes.rs b/packages/eql/tests/encryption/tests/opaque_json_bytes.rs index 073b0717b..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_encrypt::{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..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", @@ -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/CHANGELOG.md b/packages/stack-encrypt/CHANGELOG.md index 0bf312c4a..a5138a472 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/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..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", @@ -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..e6673645a 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`] @@ -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/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..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-encrypt 0.6.0's aws-lc backend -//! (`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_encrypt::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/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..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", @@ -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" diff --git a/packages/vitaminc-aead/CHANGELOG.md b/packages/vitaminc-aead/CHANGELOG.md index 69a8e68c2..cdb975620 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. @@ -57,8 +61,21 @@ 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 + +- 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. + `LocalCipherText` and `WIRE_VERSION` are still public. + ### 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. +- 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. diff --git a/packages/vitaminc-aead/Cargo.toml b/packages/vitaminc-aead/Cargo.toml index 83f2d487a..d5101a21f 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,26 @@ 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. +# +# 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 } + +[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", "dep:aes-gcm"] jiff = ["dep:jiff"] rust_decimal = ["dep:rust_decimal"] uuid = ["dep:uuid"] @@ -75,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 @@ -89,3 +111,7 @@ trybuild = "1.0.118" futures-executor = "0.3.31" serde_json = "1" jiff = { version = "1.0.1", default-features = false } + +[[test]] +name = "aes_cipher" +required-features = ["aes"] 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 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/aes/backend.rs b/packages/vitaminc-aead/src/aes/backend.rs new file mode 100644 index 000000000..440e5c9a2 --- /dev/null +++ b/packages/vitaminc-aead/src/aes/backend.rs @@ -0,0 +1,212 @@ +//! 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 `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", vitaminc_aead_rust_crypto))] +mod rust_crypto; +#[cfg(any(target_arch = "wasm32", vitaminc_aead_rust_crypto))] +pub(crate) use rust_crypto::CipherKey; + +#[cfg(not(any(target_arch = "wasm32", vitaminc_aead_rust_crypto)))] +mod aws_lc; +#[cfg(not(any(target_arch = "wasm32", vitaminc_aead_rust_crypto)))] +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, NONCE_LEN}; + + /// Cross-backend byte-parity check. + /// + /// The same test runs against the `aws-lc-rs` backend on native targets, + /// 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() { + // 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" + ); + } + + // 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] { + [ + 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); + } + + #[test] + fn roundtrip_no_aad() { + roundtrip(b"hello world", b""); + } + + #[test] + fn roundtrip_with_aad() { + roundtrip(b"hello world", b"associated data"); + } + + #[test] + fn roundtrip_empty_plaintext() { + roundtrip(b"", b"some aad"); + } + + #[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"); + } + + #[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" + ); + } + + #[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" + ); + } + + #[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" + ); + } + + #[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 new file mode 100644 index 000000000..0f45bd6dd --- /dev/null +++ b/packages/vitaminc-aead/src/aes/backend/aws_lc.rs @@ -0,0 +1,106 @@ +//! `aws-lc-rs` backend for 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); + +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. + /// + /// 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)?; + 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) + } +} + +/// 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"); + } +} 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..e544946c7 --- /dev/null +++ b/packages/vitaminc-aead/src/aes/backend/rust_crypto.rs @@ -0,0 +1,63 @@ +//! RustCrypto `aes-gcm` backend for AES-256-GCM. + +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 +/// 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. + /// + /// 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 = 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 + /// 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..c8c00668d --- /dev/null +++ b/packages/vitaminc-aead/src/aes/cipher.rs @@ -0,0 +1,569 @@ +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` 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(WIRE_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..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] @@ -85,7 +91,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 +117,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 +135,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/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 64e044960..7c1fb22cc 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; @@ -41,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; @@ -99,17 +103,16 @@ 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; #[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; diff --git a/packages/vitaminc-aead/tasks.toml b/packages/vitaminc-aead/tasks.toml index 18c7eb06e..79d685e27 100644 --- a/packages/vitaminc-aead/tasks.toml +++ b/packages/vitaminc-aead/tasks.toml @@ -20,15 +20,27 @@ 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 +# 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 # 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 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", + '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) @@ -47,3 +59,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", +] 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); + } +} diff --git a/supply-chain/vitaminc-aead/audits.toml b/supply-chain/vitaminc-aead/audits.toml index e8c485930..95873dfb3 100644 --- a/supply-chain/vitaminc-aead/audits.toml +++ b/supply-chain/vitaminc-aead/audits.toml @@ -33,12 +33,24 @@ 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). 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 " 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"] @@ -123,6 +135,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" @@ -254,3 +272,17 @@ 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." + +[[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 111b70e27..dcbe74624 100644 --- a/supply-chain/vitaminc-aead/config.toml +++ b/supply-chain/vitaminc-aead/config.toml @@ -84,14 +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.aws-lc-sys]] -version = "0.44.0" -criteria = "safe-to-run" - [[exemptions.bitvec]] version = "1.0.1" criteria = "safe-to-deploy" @@ -116,10 +108,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" @@ -496,10 +484,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" diff --git a/supply-chain/vitaminc-aead/deny.toml b/supply-chain/vitaminc-aead/deny.toml index 8e75f6421..b9619acde 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,8 +85,21 @@ 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", + # 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", diff --git a/supply-chain/vitaminc-aead/imports.lock b/supply-chain/vitaminc-aead/imports.lock index 5fe3e01ee..c38cd07bc 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.45.0" +when = "2026-09-01" +user-id = 156764 +user-login = "justsmth" +user-name = "Justin W Smith" + [[publisher.bumpalo]] version = "3.19.1" when = "2025-12-16" @@ -8,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" @@ -435,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" @@ -970,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"] @@ -1815,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"