# Enable post-quantum TLS on a Go server

Source: https://pq-scan.com/fix/go-post-quantum-tls
Fixes: pq-kex-missing, pq-kex-supported-not-preferred. Server: Go (crypto/tls). Effort: 5 min.
Requires: Go 1.24+ toolchain and a go.mod "go" line of 1.24 or newer. Lab-tested on Go 1.26.11, 2026-12-05 (PQ Scan Docker lab).

Build with Go 1.24+, keep go.mod at go 1.24 or newer, and keep the hybrid groups in CurvePreferences if you set it.

## The fix

Go 1.24 and newer prefer the X25519MLKEM768 hybrid by default. Most Go servers only need three things:

1. Build with Go 1.24 or newer.
2. Make sure `go.mod` says `go 1.24` or newer. An older `go` line turns the hybrid off, even with a new toolchain.
3. Leave `CurvePreferences` unset. If you need a list, keep the hybrid groups in it:

```go title="main.go"
srv := &http.Server{
	Addr: ":443",
	TLSConfig: &tls.Config{
		CurvePreferences: []tls.CurveID{
			tls.X25519MLKEM768, tls.SecP256r1MLKEM768, tls.SecP384r1MLKEM1024, // SecP* need Go 1.26+
			tls.X25519, tls.CurveP256, tls.CurveP384,
		},
	},
}
```

On Go 1.24 and 1.25, drop the two `SecP` names: they do not exist yet.

If you cannot raise the `go` line yet, add this line above `package main`:

```go title="main.go"
//go:debug tlsmlkem=1
```

## Check your Go first

```sh
go version -m ./yourserver | grep -E "go1|tlsmlkem"
# ./yourserver: go1.26.11
```

The first line is the toolchain: you need go1.24 or newer. If a second line appears with `DefaultGODEBUG=...tlsmlkem=0...`, the `go` line in `go.mod` is older than 1.24 and the hybrid is off. On Go 1.26+ that line also has `tlssecpmlkem=0`, which turns off the SecP hybrids. A `GODEBUG=tlsmlkem=0` environment variable turns the hybrid off at run time too.

| Official `golang` image | Go | Default post-quantum groups |
|---|---|---|
| `golang:1.23` | 1.23.12 | None: upgrade Go |
| `golang:1.24` | 1.24.13 | X25519MLKEM768 |
| `golang:1.25` | 1.25.14 | X25519MLKEM768 |
| `golang:1.26` | 1.26.11 | X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024 |
| `golang:1.27` | 1.27.4 | X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024 |

Checked by building a server with each image and connecting with OpenSSL 3.5 on 2026-12-06. Go has its own TLS stack, so the OS and its OpenSSL do not matter.

## What the common configs actually do

Tested in Docker against five client offers, including the exact one browsers send. "Preferred" means the server asks for post-quantum even when the client led with a classical key share. A Go server does this: it sends a HelloRetryRequest for X25519MLKEM768.

| Config (Go 1.26 unless noted) | Post-quantum | What browsers get |
|---|---|---|
| No `CurvePreferences` (default) | Preferred | X25519MLKEM768 |
| `CurvePreferences` with the hybrids (this fix) | Preferred | X25519MLKEM768 |
| `CurvePreferences` with X25519MLKEM768 listed last | Preferred | X25519MLKEM768 |
| No `CurvePreferences`, Go 1.24 | Preferred | X25519MLKEM768 |
| `go.mod` says `go 1.23` | Off | X25519 (classical) |
| `go.mod` says `go 1.23`, plus `//go:debug tlsmlkem=1` | Preferred | X25519MLKEM768 |
| `CurvePreferences: {X25519, CurveP256, CurveP384}` (old hardening guides) | Off | X25519 (classical) |
| No `CurvePreferences`, Go 1.23 | Off | X25519 (classical) |

Go ignores the order of `CurvePreferences`: it always prefers the hybrid when both sides support it. So the only thing that matters is whether the hybrid is in the list.

A classical `CurvePreferences` list, or an old `go` line in `go.mod`, is a common reason a Go server built with a new toolchain is still classical-only.

## Verify

```sh
openssl s_client -connect example.com:443 -groups X25519MLKEM768 </dev/null 2>&1 | grep "Negotiated TLS1.3 group"
# Negotiated TLS1.3 group: X25519MLKEM768
```

Or rescan with PQ Scan: the Confidentiality axis should read **PQ preferred**.

## Things that don't change
- Your certificate stays the same (post-quantum certificates are not available for public websites yet).
- Clients without post-quantum support still connect with X25519 or P-256.
- If a CDN, load balancer or reverse proxy terminates TLS in front of your Go server, visitors see its TLS, not this config. Fix it there too.

Verify after deploying: https://pq-scan.com/r/<your-domain>?fresh=1
