# Post-quantum TLS in Go: enable X25519MLKEM768 (and check you haven't turned it off)

> Go 1.24+ negotiates hybrid X25519MLKEM768 by default. Here is how to keep it on, fix CurvePreferences that disable it, use crypto/mlkem, and prove it in CI.

Source: https://pqshift.dev/learn/post-quantum-tls-go · Published 2026-12-04 · Updated 2026-12-04 · pqshift

Go 1.24 and later negotiate the hybrid post-quantum group `X25519MLKEM768` by default in `crypto/tls`, for both clients and servers. Go 1.26 also turns on `SecP256r1MLKEM768` and `SecP384r1MLKEM1024`. If your service is not post-quantum, the cause is almost always one of three things: an old toolchain, a `CurvePreferences` list that leaves the hybrid group out, or a `GODEBUG` switch.

## Is it already on?

```bash
go version                      # needs go1.24 or later
grep -rn "CurvePreferences" --include=*.go .
grep -rn "tlsmlkem" .           # GODEBUG=tlsmlkem=0 turns it off
```

If `go version` is 1.24+, nothing sets `CurvePreferences`, and no `GODEBUG` disables it, you already have hybrid key exchange. Skip to [verify it](#verify-the-handshake).

## Fix 1: CurvePreferences that drop the hybrid group

This is the most common reason a Go service on a current toolchain still uses classical key exchange. When `CurvePreferences` is set, Go uses exactly that list.

```go
// Before: classical only, even on Go 1.26
cfg := &tls.Config{
    MinVersion:       tls.VersionTLS12,
    CurvePreferences: []tls.CurveID{tls.X25519, tls.CurveP256},
}

// After: hybrid first, classical kept as a fallback
cfg := &tls.Config{
    MinVersion: tls.VersionTLS12,
    CurvePreferences: []tls.CurveID{
        tls.X25519MLKEM768, // hybrid post-quantum (TLS 1.3 only)
        tls.X25519,         // classical fallback for peers without it
        tls.CurveP256,
    },
}
```

Or delete the field. The Go 1.26 default order is `X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024, X25519, P-256, P-384, P-521`, which is a good default for almost everyone.

Keep the classical entries. A peer that doesn't support ML-KEM (or a TLS 1.2 connection, where hybrid groups don't apply) then still connects with X25519. Removing them is how a migration turns into an outage.

## Fix 2: an old toolchain

Bump the `go` line in `go.mod` and every place a version is pinned:

```bash
go mod edit -go=1.26
grep -rn "golang:1\.\(1[0-9]\|2[0-3]\)" Dockerfile* .github/ 2>/dev/null
grep -rn "go-version" .github/workflows/
```

Update `FROM golang:...` images and `actions/setup-go` `go-version` values too. A binary built with Go 1.23 never offers the hybrid group, whatever the code says.

## Fix 3: GODEBUG switches

Two settings in [defaults.go](https://go.googlesource.com/go/+/HEAD/src/crypto/tls/defaults.go) turn the defaults off:

| Setting | Effect |
|---|---|
| `tlsmlkem=0` | Restores the pre-Go 1.24 default: no `X25519MLKEM768` |
| `tlssecpmlkem=0` | Restores the pre-Go 1.26 default: no `SecP256r1MLKEM768` / `SecP384r1MLKEM1024` |

Search for them in `go.mod` (`godebug` block), `//go:debug` lines and deployment env vars. Teams sometimes added `tlsmlkem=0` in 2025 to work around a middlebox that choked on the larger ClientHello. Re-test that path and remove it.

## Verify the handshake

From any machine with OpenSSL 3.5 or later:

```bash
openssl s_client -connect your-service.example:443 -groups X25519MLKEM768 </dev/null 2>/dev/null | grep -i group
```

You want the negotiated group to read `X25519MLKEM768`. Also confirm a classical-only client still gets in:

```bash
openssl s_client -connect your-service.example:443 -groups X25519 </dev/null 2>/dev/null | grep -i group
```

For a Go **client**, point it at a server that supports the hybrid group, such as `pq.cloudflareresearch.com`. More options are in [How to check if a server uses post-quantum TLS](https://pqshift.dev/learn/test-post-quantum-tls).

## ML-KEM directly: crypto/mlkem

For application-level key exchange (wrapping a data key, a custom protocol) Go ships `crypto/mlkem`, which implements FIPS 203:

```go
import "crypto/mlkem"

// Receiver: generate a key pair and publish ek.Bytes()
dk, err := mlkem.GenerateKey768()
if err != nil { return err }
ek := dk.EncapsulationKey()

// Sender: derive a shared secret and a ciphertext for the receiver
sharedKey, ciphertext := ek.Encapsulate()

// Receiver: recover the same shared secret
got, err := dk.Decapsulate(ciphertext)
```

Note the return order: `Encapsulate()` returns the shared key **first**, then the ciphertext. Two rules if you build on it:

- **Stay hybrid.** Combine the ML-KEM secret with an X25519 (`crypto/ecdh`) secret through a KDF such as `crypto/hkdf`, so the result is safe if either primitive holds.
- **Prefer HPKE when you can.** Go 1.26 adds `crypto/hpke` (RFC 9180) with post-quantum hybrid KEMs, which handles the combiner, nonces and AEAD for you.

Version your ciphertext format (a one-byte header is enough) so data encrypted under the old RSA or ECDH scheme still decrypts after the switch.

## SSH from Go

`golang.org/x/crypto/ssh` clients and servers pick their key exchange from `Config.KeyExchanges`. If you set that list, include `mlkem768x25519-sha256` first. See the [OpenSSH guide](https://pqshift.dev/learn/post-quantum-ssh-openssh) for the server side.

## Doing this across many repos

The checks above are what [pqshift](https://pqshift.dev/) automates: it scans every repo for `CurvePreferences`, old toolchains, `GODEBUG` switches and RSA/ECDH key wrapping, opens small hybrid PRs, and adds a CI job that performs a real handshake and fails closed if the hybrid group isn't negotiated.

## FAQ

### Which Go version supports post-quantum TLS?

Go 1.24 and later negotiate X25519MLKEM768 by default in crypto/tls. Go 1.26 also enables SecP256r1MLKEM768 and SecP384r1MLKEM1024 by default.

### Why is my Go service not using X25519MLKEM768?

Usually because tls.Config.CurvePreferences is set explicitly to classical curves only, the binary was built with Go older than 1.24, or GODEBUG=tlsmlkem=0 is set. Add tls.X25519MLKEM768 to the front of CurvePreferences or remove the field.

### Does Go have an ML-KEM package?

Yes. crypto/mlkem implements ML-KEM-768 and ML-KEM-1024 from FIPS 203. Go 1.26 adds crypto/hpke with post-quantum hybrid KEMs for encrypting data.

## Sources

- [Go 1.26 release notes (crypto/tls, crypto/hpke, crypto/mlkem)](https://go.dev/doc/go1.26)
- [Go source: crypto/tls/defaults.go (default curve order and GODEBUG switches)](https://go.googlesource.com/go/+/HEAD/src/crypto/tls/defaults.go)
- [crypto/mlkem package documentation](https://pkg.go.dev/crypto/mlkem)
- [RFC 10024: Post-Quantum Traditional (PQ/T) Hybrid Key Agreement Mechanisms for TLS 1.3 (Aug 2026)](https://datatracker.ietf.org/doc/rfc10024/)
