Post-quantum TLS in .NET: SslStream, Kestrel, OpenSSL 3.5 and the MLKem class
On this page
Short answer: .NET doesn't implement TLS itself. SslStream, HttpClient and Kestrel use the operating system's TLS stack, so whether they negotiate the hybrid post-quantum group X25519MLKEM768 depends on the OS. On Linux, .NET uses the system OpenSSL, so OpenSSL 3.5+ gives you hybrid key exchange by default. On Windows it's SChannel, so it depends on the Windows version. On macOS, .NET 10 has no post-quantum support. Separately, .NET 10 adds an MLKem class (FIPS 203) for application-level key encapsulation.
The 30-second check (Linux and containers)
docker run --rm your-image sh -c 'openssl version; ldconfig -p | grep libssl'.NET loads libssl from the image at runtime. The official mcr.microsoft.com/dotnet/* images are built on Debian, Ubuntu, Azure Linux and Alpine, and each ships its distribution's OpenSSL. If that is older than 3.5, SslStream can't offer the hybrid group, whatever the .NET version. Move to a base image whose distribution ships OpenSSL 3.5+, or build OpenSSL 3.5 into the image.
Kestrel and HttpClient
No code changes are needed: with OpenSSL 3.5+ on Linux, Kestrel servers and HttpClient both offer X25519MLKEM768 because it is in OpenSSL's default group list. Things that can switch it off:
- An OpenSSL config (
/etc/ssl/openssl.cnf,OPENSSL_CONF) that setsGroupsorCurvesto a classical list. Hardened base images sometimes do this. PutX25519MLKEM768first:
# openssl.cnf
[system_default_sect]
Groups = X25519MLKEM768:X25519:P-256:P-384- TLS 1.2 only. Hybrid groups exist only in TLS 1.3. Check
SslProtocolsin Kestrel'sConfigureHttpsDefaultsand in anySocketsHttpHandler.SslOptions, and allow TLS 1.3.
Behind a reverse proxy or a PaaS
If TLS terminates in front of your app, that layer decides. Azure App Service is rolling out X25519MLKEM768 automatically; Azure Front Door offers it by default; AWS ALBs need a -PQ- policy. See cloud load balancers and nginx/OpenSSL servers.
ML-KEM in code: the MLKem class (.NET 10)
.NET 10 adds System.Security.Cryptography.MLKem. Unlike MLDsa, SlhDsa and CompositeMLDsa, its core methods are not marked experimental. It needs OpenSSL 3.5+ on Linux or a Windows build with CNG post-quantum support, and is not available on macOS. Always check IsSupported:
using System.Security.Cryptography;
if (!MLKem.IsSupported)
throw new PlatformNotSupportedException("ML-KEM needs OpenSSL 3.5+ or Windows CNG PQC");
// Receiver: generate a key pair and publish the encapsulation key
using MLKem receiver = MLKem.GenerateKey(MLKemAlgorithm.MLKem768);
byte[] encapsulationKey = receiver.ExportEncapsulationKey();
// Sender: encapsulate against the published key
using MLKem sender = MLKem.ImportEncapsulationKey(MLKemAlgorithm.MLKem768, encapsulationKey);
sender.Encapsulate(out byte[] ciphertext, out byte[] senderSecret);
// Receiver: recover the same 32-byte shared secret
byte[] receiverSecret = receiver.Decapsulate(ciphertext);To replace RSA key wrapping (RSA.Encrypt with OAEP) or ECDiffieHellman, stay hybrid: combine the ML-KEM secret with an ECDiffieHellman (P-256 or X25519) secret through HKDF.DeriveKey, and add a version byte to the ciphertext format so data wrapped the old way still decrypts.
Verify the handshake
openssl s_client -connect your-app.example:443 -tls1_3 -groups X25519MLKEM768 -brief </dev/null 2>&1 | grep -i groupYou want Negotiated TLS1.3 group: X25519MLKEM768. For a .NET client, connect it to a server that only accepts the hybrid group, as described in How to check if a server uses post-quantum TLS.
FAQ
Does .NET support post-quantum TLS?
Through the operating system. On Linux, .NET uses the system OpenSSL, so OpenSSL 3.5+ negotiates X25519MLKEM768 by default for SslStream, HttpClient and Kestrel. On Windows it depends on SChannel; .NET 10 has no PQC on macOS.
How do I use ML-KEM in C#?
In .NET 10, MLKem.GenerateKey(MLKemAlgorithm.MLKem768) creates a key pair, Encapsulate(out ciphertext, out secret) runs on the sender, and Decapsulate(ciphertext) on the receiver. Check MLKem.IsSupported first.