Skip to content

Negotiate post-quantum X25519MLKEM768 key exchange by moving TLS from ring to aws-lc-rs - #102

Merged
kriszyp merged 11 commits into
mainfrom
feat/aws-lc-rs-post-quantum-kex
Dec 4, 2026
Merged

kriszyp merged 11 commits into
mainfrom
feat/aws-lc-rs-post-quantum-kex

Conversation

@kriszyp

@kriszyp kriszyp commented Dec 4, 2026 •

Copy link
Copy Markdown
Member
Kyle fits a double lock of a brass key and a glowing crystal key on the loading bay door while Kris looks on, the old key ring hangs retired on its hook, and a sand-crow's rubbings get it nothing.

⊙ Problem

Symphony's TLS used rustls's ring provider, which has no ML-KEM. Every session it terminated used classical key exchange, which a future quantum computer could break from recorded traffic. Current browsers and Node 22.20+ and 24.5+ already offer the hybrid post-quantum group X25519MLKEM768 first.

🤔 Is a client-ordered group list acceptable?

The task asked for X25519MLKEM768, then X25519, then P-256. rustls 0.23 cannot prefer the server's order: it takes the client's first group that is on KX_GROUPS. Browsers and Node rank the hybrid first and get it; a client ranking X25519 first gets X25519. P-384 stays because ring offered it.

💡 Solution

  • TLS 1.3 clients preferring X25519MLKEM768 now get it. Others get X25519, P-256 or P-384, whichever of those they rank first.
  • rustls now uses the aws-lc-rs provider, and ring is gone.
  • Each prebuilt addon carries its own static AWS-LC. CI fails an artifact that would load a system libcrypto.
  • No API or config change. A hybrid ServerHello is 1,088 bytes larger, and the addon grows by 1.3–2.3 MB per target.

⚖️ Alternatives

  • Keep ring, add aws-lc-rs for the hybrid — two crypto libraries, which the task rules out.
  • rustls's default aws-lc-rs groups — they change between patch releases, and the lockfile is not committed (Commit Cargo.lock so release builds ship the dependency versions CI tested #99).
  • A system libcrypto — the prebuilt addon would not load on hosts without it.
  • Only the process-default provider — cargo test never installs it.

🤔 Is the extra CPU on ECDSA and resumed handshakes worth it?

On macOS arm64 the hybrid costs the proxy 7.2% more CPU per full ECDSA-cert handshake and 7.5–7.8% more per resumed one. RSA handshakes got 7–9% cheaper, AES-GCM records 2–6% cheaper. Dropping the hybrid from KX_GROUPS undoes the cost and the protection.

🤔 Should mTLS accept the wider signature set?

Client certificate checks now use aws-lc-rs's default signature algorithms, adding ECDSA P-521, SHA-512 variants and ML-DSA to ring's. A cert chaining to the configured CA and signed with one of those now verifies, where ring rejected it. An explicit list on the verifier restores ring's set.

🔧 Changes

✅ Verification

  • Rust tests in src/tls.rs and the key exchange suite in proxy.spec.ts negotiate each group, including the client's order deciding. cargo test: 279 pass (1 macOS-only thread_cpu failure, also on main). npm test: 247 pass, 0 fail, 3 skipped, with the JA3/JA4 and resumption suites unchanged.
  • CI builds all six targets, which pass the linkage check and the Linux and macOS test jobs.

Performance: on macOS arm64, benchmark-tls.ts measured proxy CPU changes of −9% to +7% per full handshake, +7.5–7.8% per resumed one, and −5.5% to +0.9% per MiB of records. The largest increases are on hybrid handshakes. Linux is not measured (#100).

Test cases and wire sizes
  • Through the proxy, a hybrid handshake's server flight is 2,358 bytes against 1,270 for X25519, and its ClientHello 1,437 against 253.
  • src/tls.rs, against configs from TlsConfigCache: a client offering the hybrid and X25519, or the production list, gets the hybrid; classical TLS 1.2 and 1.3 clients get their group; TLS 1.2 takes the first classical group offered; the client's order decides among shared groups.
  • __test__/proxy.spec.ts, Node clients through a real TLS-terminating proxy: hybrid only, hybrid ranked first, X25519 ranked above the hybrid, X25519 / P-256 / P-384 only, and TLS 1.2. The hybrid cases skip below OpenSSL 3.5 (opensslOffersMlKem); tlsKeyExchange returns Node's key exchange info, which Node 22 leaves empty for the hybrid. They pass on Node 26 (OpenSSL 4.1) and, 7/7, on Node 22.23 (OpenSSL 3.5).
  • cargo clippy --all-targets and cargo fmt --check are clean on macOS; CI runs them on Linux.
Handshake and record-encryption benchmark, ring → aws-lc-rs

macOS arm64 (M3), Node 26.13, proxy workerThreads: 2, 8 client processes × 6 in flight, 1,200 handshakes per handshake arm, 3 GiB each way per bulk arm. Each build ran 4 times, alternating; medians. The ring build is main with this branch's benchmark script copied in.

Cert Arm handshakes/s Δ proxy µs/handshake Δ group
RSA-2048 full, client default groups 3843 → 4108 +6.9% 504.5 → 470.5 −6.7% X25519 → X25519MLKEM768
RSA-2048 full, X25519 only 3826.5 → 4190 +9.5% 506.5 → 461 −9.0% X25519
RSA-2048 full, P-256 only 3794.5 → 4080.5 +7.5% 511 → 474 −7.2% P-256
RSA-2048 resumed, client default groups 12781.5 → 11655 −8.8% 134 → 144 +7.5% X25519 → X25519MLKEM768
ECDSA P-256 full, client default groups 10851 → 10149 −6.5% 146 → 156.5 +7.2% X25519 → X25519MLKEM768
ECDSA P-256 full, X25519 only 11561 → 12083 +4.5% 133.5 → 130 −2.6% X25519
ECDSA P-256 full, P-256 only 11775.5 → 11771.5 0.0% 132 → 137.5 +4.2% P-256
ECDSA P-256 resumed, client default groups 12206 → 11509 −5.7% 135 → 145.5 +7.8% X25519 → X25519MLKEM768
Protocol Suite (RSA cert) MiB/s each way Δ proxy µs/MiB Δ
TLS 1.3 AES-256-GCM 1488 → 1505 +1.1% 1291.5 → 1244.5 −3.6%
TLS 1.3 AES-128-GCM 1452 → 1521 +4.8% 1274 → 1224.5 −3.9%
TLS 1.3 ChaCha20-Poly1305 921 → 915.5 −0.6% 2124 → 2139 +0.7%
TLS 1.2 ECDHE-RSA AES-256-GCM 1438 → 1461.5 +1.6% 1290.5 → 1266.5 −1.9%
TLS 1.2 ECDHE-RSA AES-128-GCM 1443.5 → 1517.5 +5.1% 1298.5 → 1227 −5.5%
TLS 1.2 ECDHE-RSA ChaCha20-Poly1305 922.5 → 914 −0.9% 2123.5 → 2142.5 +0.9%
Native addon size per target, bytes

CI artifacts, as published: main's last run (611f225) against this PR's run. The Linux ones are stripped.

Target main (ring) this PR (aws-lc-rs) Δ
linux-x64-gnu 4,108,016 6,405,952 +2,297,936 (+55.9%)
linux-x64-musl 4,275,800 6,479,480 +2,203,680 (+51.5%)
linux-arm64-gnu 3,603,968 4,935,200 +1,331,232 (+36.9%)
linux-arm64-musl 3,714,456 5,000,600 +1,286,144 (+34.6%)
darwin-arm64 3,172,112 4,616,864 +1,444,752 (+45.5%)
darwin-x64 3,495,776 5,715,692 +2,219,916 (+63.5%)
Known limits left as they are
  • The 200 ms wait before the closing CPU sample also applies to the bulk arms, so their CPU per MiB includes connection teardown. Both builds run the same wait (TLS benchmark's bulk-echo CPU per MiB includes connection teardown #103).
  • The linkage check matches four unprefixed symbol families (OPENSSL_, EVP_, CRYPTO_, SSL_). A regression to an unprefixed or system libcrypto would import some of them; a full allowlist of undefined symbols is not attempted.

PR QA: skipped @ b0f025e — not a harper or harper-pro PR.

Framing-Verdict: chosen-approach-sound

🤖 Generated by Claude Code (Claude Opus 5.5); posted via @kriszyp.

🤖 Generated with Claude Code

Related PRs: #66 overlaps (edits its jemalloc build comment; the linkage check runs beside its artifact steps), 1 others independent
Complexity: medium

Deferred findings

Origin — the dispatch brief this PR was written from

Switch Symphony's rustls crypto provider from ring to aws-lc-rs and enable the X25519MLKEM768 hybrid post-quantum key exchange for TLS connections that Symphony terminates. Today Symphony can only negotiate classical X25519/P-256 because ring has no ML-KEM, while current browsers and current Node already offer X25519MLKEM768. Key-exchange preference order: X25519MLKEM768 first, then X25519, then SECP256R1 as fallbacks. Preserve any existing per-config key-exchange-group restriction behavior. Open a draft PR.

Acceptance

  1. A test proving a client that offers X25519MLKEM768 negotiates it, and a classical-only client still negotiates X25519 (and P-256-only still works). 2) napi prebuild CI green on every target triple in package.json. 3) PR description carries before/after numbers for full-handshake throughput or CPU and for native binary size per target. 4) Existing tests pass unchanged in intent, including JA3 fingerprinting and session ticket/resumption tests. 5) No remaining ring references in src or Cargo.toml unless a concrete blocker is documented in the PR. Follow the harper-engineering-guidelines PR conventions; leave the PR as draft.

Dispatch: task symphony-pq-kex · queued by kris-session · ran by claude/opus/xhigh · worker kris-mac-m3-fleet-18b9c6

Ready-For-Promotion: b0f025e urgency=normal late=folded

Review-Coverage: authored=claude; ran=cursor-composer,codex,gemini,cursor-grok; late=cursor-grok:adjudicated; adjudicated=domain; declined=muse; rounds=9; full=3 @ b0f025e

Review-Attention: read ~7m (decisions: bulk-grace-kept, linkage-gate-breadth, perf-cost) @ b0f025e

kriszyp and others added 11 commits December 3, 2026 16:13
…ws-lc-rs

ring has no ML-KEM, so symphony could only negotiate classical groups with
clients that offer the hybrid X25519MLKEM768 first (current browsers, Node
22.20+). rustls 0.23.48 also deprecates ring's default provider for that reason.

- One provider, tls::crypto_provider(): aws-lc-rs with key exchange groups
  X25519MLKEM768, X25519, P-256, P-384, passed explicitly to every ServerConfig
  and to the mTLS verifier, and installed as the process default.
- ring is gone: the ticketer is aws-lc-rs's, the cache-key SHA-256 uses sha2,
  and tarpit jitter draws from the provider's RNG.
- .cargo/config.toml forces aws-lc-sys to build its static AWS-LC from source;
  CI and release check each artifact links no system libcrypto and exports no
  OpenSSL symbol.
- Tests: Rust negotiation tests against TlsConfigCache configs, and Node cases
  through a real proxy (the hybrid ones skip below OpenSSL 3.5).
- benchmark:handshake measures full and resumed handshake cost per group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
The Linux check no longer drops undefined symbols, so an import of
OpenSSL resolving against Node's copy fails it too; macOS now also checks
exported symbols and a shared aws-lc. The benchmark reports handshakes it
completed, rejects non-positive options, and fails instead of hanging when
a seed connection closes without a ticket or a child exits early.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
The benchmark becomes benchmark-tls with a bulk echo arm per TLS 1.3
suite, and tears its children down when a run fails. AWS_LC_SYS_STATIC
is forced beside USE_SYSTEM. The JS tests offer explicit group lists
instead of the runtime's default, including a client that ranks X25519
first; the Rust ALPN test clients offer the production groups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
The parent gives a child 30 s to answer a ready, port or CPU request,
sends through a checked channel, and kills a proxy that does not stop in
10 s; a nonzero proxy exit fails the run. A child whose parent goes away
exits. Bulk arms now cover the three TLS 1.2 ECDHE-RSA AEAD suites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
Bulk clients connect before reporting ready, so the CPU window holds only
record encryption. Drops the stock-rustls offer from the hybrid test,
which the production offer covers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
Bulk lanes warm up with one echo before ready and reject a socket that
closed before its echo; the benchmark route sends no PROXY header, so the
echo is byte-exact. SECURITY.md says a FIPS build also drops X25519, and
the CI comment names what the linkage check matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
SECURITY.md and CLAUDE.md no longer call every sha2 digest a label:
tls::sha256 keys the config cache and compares mTLS CA bundles, so a
FIPS build moves it to the provider. CLAUDE.md names what the linkage
check matches. Benchmark children send through one helper that exits on
a closed channel, the proxy child handles a disconnect from its start,
and a settled echo drops its drain listener.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
…hooks

aws-lc-sys compiles with the image's TARGET_CC (aarch64-unknown-linux-gnu-gcc)
ahead of CC_<target>, so the clang-only --gcc-toolchain flag that main kept for
ring's assembly broke the aarch64-gnu build. With ring gone, that target now
compiles jemalloc with the same cross GCC and carries no clang flags.

The Linux linkage check matched AWS-LC's OPENSSL_memory_* allocator hooks:
weak undefined references on ELF that a host may define and OpenSSL does not,
so they cannot bind to Node's libcrypto. The check now skips exactly those four.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
…c claims

- handshake() rejects on close and after 5 s, removes its listeners once
  settled, and leaves an error handler that closes the socket.
- A bulk client refuses to report ready if any lane closed after warm-up, not
  only the first; the parent bounds each report wait.
- The upstream listen rejects on error, and a proxy child whose parent left
  during start() lets the disconnect handler finish its stop.
- SECURITY.md and CLAUDE.md name Node 22.20+ and 24.5+ (24.0-24.4 predate
  OpenSSL 3.5), and .cargo/config.toml no longer claims to override every
  form of the AWS-LC variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatch-Task: symphony-pq-kex
@kriszyp
kriszyp marked this pull request as ready for review December 4, 2026 14:21
@kriszyp
kriszyp merged commit dbebbbc into main Dec 4, 2026
14 checks passed
@kriszyp
kriszyp deleted the feat/aws-lc-rs-post-quantum-kex branch December 4, 2026 15:28
kriszyp added a commit that referenced this pull request Dec 4, 2026
After rebasing onto main (dbebbbc), regenerate Cargo.lock minimally via
`cargo fetch` from the PR's previous lockfile so it matches main's
Cargo.toml: adds aws-lc-rs 1.19.0 / aws-lc-sys 0.47.0 and its build
dependencies, updates rustls 0.23.47 -> 0.23.48 (required by main's
Cargo.toml; #102 removed ring so the 0.23.47 pin is no longer needed),
and drops ring from symphony and rustls dependencies.

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-105-relock
kriszyp added a commit that referenced this pull request Dec 4, 2026
#102 added a note on CLAUDE.md:428-429 saying KX_GROUPS is pinned
because the lockfile is not committed, which this PR invalidates.
Reword it to reflect that a lock update can still pull in a rustls
patch release with a different default list.

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-105-relock
kriszyp added a commit that referenced this pull request Dec 4, 2026
* Commit Cargo.lock and pass --locked in CI and release workflows

Stop ignoring Cargo.lock and commit a lockfile pinning rustls 0.23.47 so
main builds and passes clippy without the 0.23.48 deprecation warning on
rustls::crypto::ring::default_provider(). Pass --locked (directly or via
--cargo-flags=--locked for napi build) across CI and release workflow
builds so tag releases compile the exact dependency versions CI tested.

Refs #99

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-99

* Document --locked checks and Cargo.lock version sync

Align the local Rust CI check commands in CLAUDE.md and the Docker
cross-compilation examples in README.md with the --locked workflow
invocations, and note that Cargo.toml edits (including release version
bumps) must update and commit Cargo.lock (cargo update --workspace).

Refs #99

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-99

* Enforce Cargo.lock with cargo fetch --locked before napi build

@napi-rs/cli 2.18.4 invokes an unlocked `cargo metadata` before
`cargo build`, which rewrites a stale Cargo.lock before `--cargo-flags=--locked`
is ever checked. Run `cargo fetch --locked --target ...` before
`npm run build` in CI and release workflows (and the README cross-compile
examples) so a stale lockfile fails before napi build runs, and update the
remaining local check and Rust version notes in CLAUDE.md and README.md.

Refs #99

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-99

* Regenerate Cargo.lock for aws-lc-rs and rustls 0.23.48 (#102)

After rebasing onto main (dbebbbc), regenerate Cargo.lock minimally via
`cargo fetch` from the PR's previous lockfile so it matches main's
Cargo.toml: adds aws-lc-rs 1.19.0 / aws-lc-sys 0.47.0 and its build
dependencies, updates rustls 0.23.47 -> 0.23.48 (required by main's
Cargo.toml; #102 removed ring so the 0.23.47 pin is no longer needed),
and drops ring from symphony and rustls dependencies.

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-105-relock

* Update CLAUDE.md KX_GROUPS note after rebasing onto #102

#102 added a note on CLAUDE.md:428-429 saying KX_GROUPS is pinned
because the lockfile is not committed, which this PR invalidates.
Reword it to reflect that a lock update can still pull in a rustls
patch release with a different default list.

Co-Authored-By: Gemini <noreply@google.com>
Dispatch-Task: symphony-105-relock

---------

Co-authored-by: Gemini <noreply@google.com>
kriszyp added a commit that referenced this pull request Dec 4, 2026
Sync package + platform + crate versions to 1.9.0. TLS moves from ring to aws-lc-rs and negotiates the hybrid post-quantum X25519MLKEM768 key exchange (#102); Cargo.lock is now committed and enforced with --locked in CI and release builds (#105).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant