# Step-by-step: enabling post-quantum ML-KEM (X25519MLKEM768) key exchange in OpenSSL 3.5 and nginx

> AI Release · @ai_releaseorg · https://ai-release.org/guides/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme_en.html

## AI summary

Time to complete: 30–45 minutes (plus nginx rebuild time if your package links an older OpenSSL) Difficulty: Intermediate

### Key facts

1. Time to complete: 30–45 minutes (plus nginx rebuild time if your package links an older OpenSSL) (source: #tldr; status: заявление источника)
2. Difficulty: Intermediate (source: #tldr; status: заявление источника)
3. You will need: a Linux host with root/sudo, OpenSSL 3.5.x, nginx with the ssl_conf_command directive, a TLS certificate for <your-domain>, and a way to reach port 443 from a test machine (source: #tldr; status: заявление источника)
4. OS: any Linux distribution with a package manager; commands below use apt paths (/etc/nginx/conf.d/). On RHEL-family systems the equivalent include directory is usually /etc/nginx/conf.d/ as well — verify with nginx -V. (source: #requirements; status: заявление источника)
5. OpenSSL 3.5.x installed or built from source. ML-KEM (Module-Lattice-Based Key-Encapsulation Mechanism, the NIST post-quantum standard) first appears in this line; older 1.1.1/3.0 builds do not have it. (source: #requirements; status: заявление источника)
6. nginx new enough to support the ssl_conf_command directive (it passes arbitrary OpenSSL configuration commands into the SSL context). If nginx -V does not show your OpenSSL 3.5 build, you must rebuild nginx against it — see Step 2. (source: #requirements; status: заявление источника)

### Direct answers

**What is required?** — OS: any Linux distribution with a package manager; commands below use apt paths (/etc/nginx/conf.d/). On RHEL-family systems the equivalent include directory is usually /etc/nginx/conf.d/ as well — verify with nginx -V.; OpenSSL 3.5.x installed or built from source. ML-KEM (Module-Lattice-Based Key-Encapsulation… (#requirements)
**How to do it?** — Step 1. Confirm your OpenSSL 3.5 provides ML-KEM and the hybrid group → Step 2. Point nginx at OpenSSL 3.5 and add the group directive → Step 3. Verify the negotiated group from a client (#step-1)
**Which topics does it cover?** — как включить ML-KEM в OpenSSL, постквантовый TLS настройка nginx, X25519MLKEM768 проверка handshake, openssl 3.5 quantum safe (#entities)
**What are the key points?** — Time to complete: 30–45 minutes (plus nginx rebuild time if your package links an older OpenSSL) Difficulty: Intermediate (#tldr)

- Canonical: https://ai-release.org/guides/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme_en.html
- Markdown: https://ai-release.org/guides/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme_en.md
- JSON: https://ai-release.org/guides/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme_en.json

## TL;DR
- Time to complete: 30–45 minutes (plus nginx rebuild time if your package links an older OpenSSL)
- Difficulty: Intermediate
- You will need: a Linux host with root/sudo, OpenSSL 3.5.x, nginx with the `ssl_conf_command` directive, a TLS certificate for `<your-domain>`, and a way to reach port 443 from a test machine

## What you will get
- An nginx virtual host that negotiates the hybrid post-quantum group `X25519MLKEM768` on TLS 1.3, configured in `/etc/nginx/conf.d/pq.conf`.
- A reproducible verification command whose output shows `X25519MLKEM768` in the negotiated key exchange, so you can prove the setting is live.
- A checked OpenSSL 3.5 install (`openssl list -kem-algorithms` lists ML-KEM), so you know whether the failure — if any — is in the library or in nginx.

## Quick start
```bash
openssl version -a
openssl list -kem-algorithms | grep -i ml-kem
sudo nginx -V 2>&1 | tr ' ' '\n' | grep -i openssl
openssl s_client -connect <your-domain>:443 -tls1_3 -groups X25519MLKEM768 </dev/null 2>/dev/null | grep -E "Protocol|Group|Server Temp Key"
```
Details and checks are in the steps below.

## Requirements and setup
![Illustration: Requirements and setup](https://ai-release.org/guides/img/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme-en-1.jpg?v=1796567852)

- **OS:** any Linux distribution with a package manager; commands below use `apt` paths (`/etc/nginx/conf.d/`). On RHEL-family systems the equivalent include directory is usually `/etc/nginx/conf.d/` as well — verify with `nginx -V`.
- **OpenSSL 3.5.x** installed or built from source. ML-KEM (Module-Lattice-Based Key-Encapsulation Mechanism, the NIST post-quantum standard) first appears in this line; older 1.1.1/3.0 builds do not have it.
- **nginx** new enough to support the `ssl_conf_command` directive (it passes arbitrary OpenSSL configuration commands into the SSL context). If `nginx -V` does not show your OpenSSL 3.5 build, you must rebuild nginx against it — see Step 2.
- **Certificate and key** for `<your-domain>`. Replace `<your-domain>` with the DNS name in your certificate, e.g. `nginx.example.com`.
- **Root access** to reload nginx and to install build dependencies (`build-essential`, `libpcre2-dev`, `zlib1g-dev`).

If nginx runs on a self-hosted or home box and you also plan to put other services behind it, the layout described in [How to add AI to your home server: self-hosted services guide](https://ai-release.org/guides/kak-podklyuchit-ii-k-domashnemu-serveru-poshagovoe-ruko.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide) keeps ports and reverse-proxy rules in one place.

**Example:** on Ubuntu, `sudo apt install build-essential libpcre2-dev zlib1g-dev` gives you the toolchain needed for an nginx source build.

## Step 1. Confirm your OpenSSL 3.5 provides ML-KEM and the hybrid group

**What to do:** check the library version, list the KEM algorithms, and run a local loopback handshake that forces the hybrid group.

**Why:** a huge share of "it doesn't work" cases are simply an old library. If the library has no ML-KEM, no nginx directive will produce it. Testing on `127.0.0.1` first isolates the library from nginx configuration.

```bash
openssl version -a
openssl list -kem-algorithms | grep -i ml-kem
```

Expected: the version line reports `OpenSSL 3.5.x`, and the second command prints ML-KEM entries (for example `ML-KEM-768`). If the second command prints nothing, the provider is missing — see Troubleshooting.

Now create a throwaway certificate and run a local TLS 1.3 server limited to the hybrid group:

```bash
openssl req -x509 -newkey rsa:2048 -nodes -days 1 \
  -keyout /tmp/server.key -out /tmp/server.crt -subj "/CN=localhost"
openssl s_server -accept 4433 -cert /tmp/server.crt -key /tmp/server.key \
  -tls1_3 -groups X25519MLKEM768
```

In a second terminal:

```bash
openssl s_client -connect 127.0.0.1:4433 -tls1_3 -groups X25519MLKEM768 </dev/null 2>/dev/null \
  | grep -E "Protocol|Group|Server Temp Key"
```

**How to check:** the client output contains a line with `X25519MLKEM768` (typically a `Server Temp Key:` or `Group:` line) and `Protocol: TLSv1.3`. Press `Ctrl+C` in the `s_server` terminal when done. This works because both sides are the same 3.5 library, so the group is guaranteed to be offered.

## Step 2. Point nginx at OpenSSL 3.5 and add the group directive
![Illustration: Step 2. Point nginx at OpenSSL 3.5 and add the group directive](https://ai-release.org/guides/img/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme-en-2.jpg?v=1796567859)


**What to do:** verify which OpenSSL nginx is actually linked against, rebuild nginx if needed, then add one config file.

**Why:** nginx does not use the `openssl` binary; it links the library at build time. A system nginx can be linked to 3.0 while `/usr/local/bin/openssl` reports 3.5 — the `openssl s_client` test passes, the browser handshake does not.

Check the linkage:

```bash
nginx -V 2>&1 | tr ' ' '\n' | grep -i openssl
ldd "$(command -v nginx)" | grep -i ssl
```

If both show 3.5, skip the rebuild. Otherwise build nginx against the 3.5 tree:

```bash
cd /usr/local/src
tar xf nginx-<nginx-version>.tar.gz && cd nginx-<nginx-version>
./configure --with-http_ssl_module \
  --with-openssl=/usr/local/src/openssl-3.5.x \
  --with-openssl-opt=shared
make -j"$(nproc)" && sudo make install
```

`<nginx-version>` is the release you downloaded; `--with-openssl=` points at the OpenSSL 3.5 source directory. Check your nginx release notes for the exact configure flags you need — the directive set depends on the build.

Now the server block. Create `/etc/nginx/conf.d/pq.conf`:

```nginx
server {
    listen 443 ssl;
    server_name <your-domain>;

    ssl_certificate     /etc/nginx/ssl/<your-domain>.crt;
    ssl_certificate_key /etc/nginx/ssl/<your-domain>.key;

    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_prefer_server_ciphers off;

    # Offer the hybrid post-quantum group first, classical groups as fallback
    ssl_conf_command Groups X25519MLKEM768:X25519:P-256;

    location / {
        return 200 "pq-ok\n";
        add_header Content-Type text/plain;
    }
}
```

The `Groups` list is an OpenSSL setting, not an nginx one — `ssl_conf_command` is the pipe that hands it to the SSL context. Keeping `X25519` and `P-256` in the list means clients without ML-KEM still connect, just classically.

Load it:

```bash
sudo nginx -t && sudo systemctl reload nginx
```

**How to check:** `sudo nginx -t` prints `syntax is ok` and `test is successful`. Then `curl -s https://<your-domain>/` returns `pq-ok`. If you see `unknown directive "ssl_conf_command"`, your nginx is too old — see Troubleshooting.

## Step 3. Verify the negotiated group from a client
![Illustration: Step 3. Verify the negotiated group from a client](https://ai-release.org/guides/img/poshagovoe-rukovodstvo-kak-vklyuchit-postkvantovyy-obme-en-3.jpg?v=1796567864)


**What to do:** handshake against the live server with the hybrid group forced, and inspect what was negotiated.

**Why:** a reload proves the config parsed; only the handshake proves the group was offered and accepted.

```bash
openssl s_client -connect <your-domain>:443 -servername <your-domain> -tls1_3 \
  -groups X25519MLKEM768 </dev/null 2>/dev/null \
  | grep -E "Protocol|Group|Server Temp Key|Cipher"
```

**How to check:** success looks like `Protocol: TLSv1.3` plus a line naming `X25519MLKEM768` (for example `Server Temp Key: X25519MLKEM768`). If the output shows only `X25519` or `P-256`, the server did not offer the hybrid group — the library linked into nginx is not 3.5, or the directive was not applied to that `server` block.

Run this checklist before you call it done:

- [ ] `openssl version -a` reports 3.5.x
- [ ] `openssl list -kem-algorithms` lists ML-KEM
- [ ] `nginx -V` and `ldd` both show the 3.5 library
- [ ] `nginx -t` passes after adding `ssl_conf_command Groups ...`
- [ ] `s_client` shows `Protocol: TLSv1.3` and `X25519MLKEM768`
- [ ] a client without ML-KEM still connects (`openssl s_client -connect <your-domain>:443 -groups X25519`)

| What to verify | Command | Expected |
|---|---|---|
| Library has ML-KEM | `openssl list -kem-algorithms` | ML-KEM entries |
| nginx linkage | `nginx -V` | `built with OpenSSL 3.5.x` |
| Server offers hybrid | `openssl s_client ... -groups X25519MLKEM768` | `X25519MLKEM768` in output |
| Fallback works | `openssl s_client ... -groups X25519` | handshake succeeds |

## Troubleshooting

**Problem. nginx refuses to start with an unknown directive**
- Error: `nginx: [emerg] unknown directive "ssl_conf_command" in /etc/nginx/conf.d/pq.conf:11`
- Cause: the installed nginx is older than the release that introduced `ssl_conf_command`, so the parser stops at that line.
- Solution: run `nginx -v` to see the release, upgrade nginx from your distribution or build the newer source tree as shown in Step 2, then re-run `sudo nginx -t`. As a temporary measure, comment the line out — nginx will then negotiate whatever groups its linked OpenSSL offers by default.

**Problem. Config loads, but the handshake still shows a classical group**
- Output: `Server Temp Key: X25519, 253 bits` where you expected `X25519MLKEM768`
- Cause: nginx's worker process loaded an older `libssl` (the `nginx -V` line may even say `built with OpenSSL 3.5.x` while `ldd` points to a 3.0 `libssl.so`), or the `ssl_conf_command` line sits in a different `server` block than the one serving `<your-domain>`.
- Solution: check the runtime linkage with `ldd "$(command -v nginx)" | grep -i ssl`, confirm the library path is the 3.5 one, then `sudo systemctl restart nginx` (a reload keeps old libraries mapped) and re-run the Step 3 command. Also confirm `grep -rn ssl_conf_command /etc/nginx/` hits the block that matches your `server_name`.

**Problem. Browser or old client fails while `s_client` succeeds**
- Output: `sslv3 alert handshake failure` on the client side
- Cause: the client is capped at TLS 1.2, and the hybrid group is negotiated only in TLS 1.3.
- Solution: verify with `openssl s_client -connect <your-domain>:443 -tls1_2` — if that succeeds, the fallback path is fine and only the TLS 1.3-capable clients get ML-KEM. If you need to serve TLS 1.2 clients, keep `TLSv1.2` in `ssl_protocols` and keep classical groups in the `Groups` list, as in the Step 2 config.

While you are in the host's patch routine, note that the same discipline — verifying what is actually running rather than what is installed — applies to OS updates; the mechanics for Windows hosts are covered in [How to Enable Hotpatch Updates on Windows Server: Step-by-Step Guide](https://ai-release.org/guides/poshagovoe-rukovodstvo-kak-vklyuchit-hotpatch-obnovleni.html?utm_source=tg&utm_medium=channel&utm_campaign=guide_inline&utm_content=guide_to_guide).

## Summary and next steps
You now have nginx serving TLS 1.3 with `X25519MLKEM768` offered first and classical groups as fallback, verified end to end with `openssl s_client`. Next, re-run the Step 3 command after every nginx upgrade, because a distro update can silently relink nginx against an older OpenSSL and drop the hybrid group.

## FAQ

**What is X25519MLKEM768?**
It is a hybrid key-exchange group: a classical X25519 exchange combined with ML-KEM-768, a post-quantum KEM. The handshake stays secure if either half is broken, which is why it is deployed as a hybrid rather than ML-KEM alone.

**Does enabling it break old clients?**
No, provided you keep classical groups in the `Groups` list and `TLSv1.2` in `ssl_protocols`. Legacy clients simply negotiate X25519 or P-256; only TLS 1.3 clients that also support ML-KEM get the hybrid group.

**Why does `openssl s_client` show ML-KEM but my browser does not?**
The browser must support the same group and must use TLS 1.3. If `s_client` succeeds and the browser does not, the limitation is on the client side — check the browser's TLS key-exchange support in its release notes.

**Do I need to change my certificate?**
No. ML-KEM here affects key exchange only; your existing RSA or ECDSA certificate and key are used unchanged. Post-quantum signatures are a separate topic — check the OpenSSL 3.5 documentation for what your build supports.
