Post-quantum TLS in Rust: reqwest does not prefer it by default
reqwest 0.13.4 with its default rustls backend supports the hybrid post-quantum key exchange X25519MLKEM768, but offers it last. Servers that prefer the hybrid have to ask for it with a HelloRetryRequest, which costs an
reqwest 0.13.4 with its default rustls backend supports the hybrid post-quantum key exchange X25519MLKEM768, but offers it last. Servers that prefer the hybrid have to ask for it with a HelloRetryRequest, which costs an extra round trip, and some servers settle on plain X25519 instead. The fix is one dependency line:
cargo add [email protected] --no-default-features --features prefer-post-quantum
Cargo merges features across the dependency graph, so the rustls that reqwest uses gets prefer-post-quantum too and offers X25519MLKEM768 first. Use the rustls version your lockfile already has, so there is still one copy of rustls in the build.
Everything below applies to reqwest 0.13.4 and rustls 0.23.41 with the aws-lc-rs provider. reqwest 0.12 is different and has its own section near the end.
What X25519MLKEM768 is and why it matters now
Every TLS 1.3 connection starts with a key exchange that agrees on the keys for the session. X25519 is the classical key exchange most connections use today. X25519MLKEM768 runs X25519 and ML-KEM-768, a key encapsulation mechanism standardized by NIST in FIPS 203, together and combines both results. An attacker has to break both to recover the session keys.
The reason to use it before large quantum computers exist is "record now, decrypt later". Someone who records encrypted traffic today can keep it. If X25519 is broken in the future, a recording of a classical handshake can be decrypted then. A recording of a hybrid handshake would also need ML-KEM-768 to be broken. That matters for traffic whose content still needs to be private years from now, such as personal data or credentials in request bodies.
Why reqwest offers it last
rustls 0.23.41 turns prefer-post-quantum on by default, but reqwest depends on rustls with default-features = false and enables only std and tls12 (reqwest-0.13.4 Cargo.toml, lines 384 to 391). The feature stays off unless something else in your build turns it on.
The feature only changes the order in the aws-lc-rs provider's default key exchange groups (rustls-0.23.41 src/crypto/aws_lc_rs/mod.rs, lines 247 to 256):
pub static DEFAULT_KX_GROUPS: &[&dyn SupportedKxGroup] = &[
#[cfg(feature = "prefer-post-quantum")]
kx_group::X25519MLKEM768,
kx_group::X25519,
kx_group::SECP256R1,
kx_group::SECP384R1,
#[cfg(not(feature = "prefer-post-quantum"))]
kx_group::X25519MLKEM768,
];
reqwest 0.13.4 uses the process-wide default rustls provider if your program installed one, and otherwise rustls::crypto::aws_lc_rs::default_provider() (reqwest-0.13.4 src/async_impl/client.rs, lines 719 to 721 and 2482 to 2494). Its default rustls feature turns on rustls's aws-lc-rs feature (reqwest-0.13.4 Cargo.toml, lines 86 to 90 and 169 to 173). Without the feature, the client offers:
X25519, secp256r1, secp384r1, X25519MLKEM768
rustls sends a key share only for the group it prefers, here X25519. A server that would rather use the hybrid sends a HelloRetryRequest naming X25519MLKEM768, and the client sends a second ClientHello with that share. That is a full extra round trip before the handshake can continue. Other servers accept the X25519 share they already have.
Check your own build
See which rustls features Cargo enables:
cargo tree -e features -i rustls
If no line reads rustls feature "prefer-post-quantum", the hybrid is offered last. Also run cargo tree -d and check that rustls is not listed: two copies of rustls would mean the feature might land on a different copy from the one reqwest uses.
To print the order directly, take the provider the same way reqwest does. This needs rustls as a direct dependency, which the fix below adds anyway:
use std::sync::Arc;
use rustls::crypto::{aws_lc_rs, CryptoProvider};
fn main() {
let provider = CryptoProvider::get_default()
.cloned()
.unwrap_or_else(|| Arc::new(aws_lc_rs::default_provider()));
for group in &provider.kx_groups {
println!("{:?}", group.name());
}
}
Without the feature it prints X25519, secp256r1, secp384r1, X25519MLKEM768. If your program installs its own provider with install_default(), call this after that, because reqwest will use that provider instead.
The fix
Add rustls as a direct dependency with the feature and nothing else:
cargo add [email protected] --no-default-features --features prefer-post-quantum
rustls = { version = "0.23.41", default-features = false, features = ["prefer-post-quantum"] }
prefer-post-quantum also turns on aws_lc_rs, which reqwest already enables, so no new crypto backend comes in. Then confirm:
-
cargo tree -e features -i rustlsnow includesrustls feature "prefer-post-quantum". -
cargo tree -dstill shows no second rustls. - The program above prints
X25519MLKEM768,X25519,secp256r1,secp384r1.
We checked these three results with reqwest 0.13.4 (default-features = false, features = ["rustls"]) and rustls 0.23.41.
Nothing in your code uses the new dependency, so a later upgrade or a dependency cleanup can drop it without anyone noticing. A small test keeps it in place:
#[cfg(test)]
mod tests {
use std::sync::Arc;
#[test]
fn outbound_tls_prefers_post_quantum_key_exchange() {
let provider = rustls::crypto::CryptoProvider::get_default()
.cloned()
.unwrap_or_else(|| Arc::new(rustls::crypto::aws_lc_rs::default_provider()));
let first = provider.kx_groups.first().map(|group| group.name());
assert_eq!(first, Some(rustls::NamedGroup::X25519MLKEM768));
}
}
Measured handshakes
We measured 14 HTTPS hosts from Stormedo's production delivery server on 2026-12-05. A small program built with rustls 0.23.41, the aws-lc-rs default provider and the platform certificate verifier connected to each host twice: once with the old group order and once with the hybrid first. It recorded the negotiated group and whether a HelloRetryRequest happened. We ran it twice and both runs were identical. Every handshake was TLS 1.3.
| Host | Before: group | Before: retry | After: group | After: retry |
|---|---|---|---|---|
| cloudflare.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| www.google.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| aws.amazon.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| api.github.com | X25519 | no | X25519 | no |
| hooks.slack.com | X25519 | no | X25519 | no |
| api.stripe.com | X25519 | no | X25519 | no |
| www.microsoft.com | X25519 | no | X25519MLKEM768 | no |
| api.zeptomail.com | X25519 | no | X25519MLKEM768 | no |
| discord.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| api.openai.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| hooks.zapier.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| api.vercel.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
| api.axiom.co | X25519 | no | X25519 | no |
| live.dodopayments.com | X25519MLKEM768 | yes | X25519MLKEM768 | no |
Before the fix, 8 of 14 hosts negotiated X25519MLKEM768, and all 8 needed a HelloRetryRequest first. After it, 10 of 14 negotiated the hybrid and none needed a retry. www.microsoft.com and api.zeptomail.com moved from X25519 to the hybrid: they accept it when it is offered first but do not ask for it. GitHub, Slack, Stripe and Axiom stayed on X25519 either way.
The cost is size. With the hybrid first, rustls sends an X25519MLKEM768 key share of 1216 bytes plus a separate X25519 share, so servers that only want X25519 can still use it without a retry (rustls-0.23.41 src/client/hs.rs, lines 276 to 296). The first client flight grew from about 245 bytes to about 1465 bytes. That no longer fits in one TCP segment on a 1500-byte MTU path, so it goes out as two. For a server that supports the hybrid, two segments in one flight cost less than the full extra round trip of a HelloRetryRequest. For a server that does not, the larger ClientHello is pure overhead. We saw no failed handshakes on any of the 14 hosts.
What this does not do
- It protects the key exchange only. Certificates and their signatures are still classical. A future attacker who can break them could impersonate a server in a live connection. That does not help decrypt traffic recorded earlier, which is the risk this change addresses.
- Servers without the hybrid stay classical. Four of the 14 hosts above still use X25519. The client cannot change that.
- It is not "quantum safe". It removes one known way that recorded traffic could be read later. It says nothing about the rest of the system, and nobody can promise how ML-KEM will hold up over decades.
-
It needs the aws-lc-rs provider. The rustls 0.23.41
ringprovider offers only X25519, secp256r1 and secp384r1 (rustls-0.23.41src/crypto/ring/mod.rs, lines 176 to 180). Withring, this feature does nothing for your connections.
What about reqwest 0.12?
reqwest 0.12 behaves differently. We read the 0.12.28 source but did not measure it:
- Its
default-tlsfeature uses native-tls, not rustls (reqwest-0.12.28Cargo.toml, lines 107 to 111). Which groups it offers depends on the platform's TLS library, and this guide does not cover it. - Its
rustls-tlsfeatures select theringprovider (reqwest-0.12.28Cargo.toml, lines 148 to 167), and without a process-wide default it usesrustls::crypto::ring::default_provider()(reqwest-0.12.28src/async_impl/client.rs, lines 763 to 770).ringoffers no X25519MLKEM768 at all, soprefer-post-quantumalone changes nothing. reqwest 0.12 does use a provider installed withrustls::crypto::aws_lc_rs::default_provider().install_default()before the client is built. That provider offers the hybrid, but puts it first only if rustls'sprefer-post-quantumfeature is also on, so you need both.
If you can, upgrade to reqwest 0.13 and use the fix above.
Where this came from
We found this while checking the outbound TLS of Stormedo, a service we build that sends HTTP requests for you and retries them. Its delivery workers use reqwest 0.13.4, and we made this change to them, so deliveries to HTTPS destinations now offer X25519MLKEM768 first. The measurements above were taken from the same servers. The entry is in the changelog.
This post first appeared on the Stormedo guides.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.