← Back to Blog

Post-Quantum SSH from Scratch: ML-KEM + X25519 Hybrid Key Exchange on Bare Metal

Matt Gates · April 3, 2026 · 14 min read

Quantum computers aren't here yet. But the data you encrypt today can be captured and decrypted later -- the "harvest now, decrypt later" attack. NIST finalized ML-KEM (formerly CRYSTALS-Kyber) and ML-DSA (formerly CRYSTALS-Dilithium) as post-quantum standards in 2024. OpenSSH 9.x added support. The industry is moving.

ClaudioOS needed SSH for remote access to agent sessions. We could have ported OpenSSH and its dependency tree (OpenSSL, zlib, PAM...) to bare metal. Instead, we wrote the entire SSH protocol stack from scratch in no_std Rust, with hybrid post-quantum key exchange as a first-class feature. Then we published 29 of the crates we built along the way.

Why Post-Quantum Matters Now

The threat model is straightforward:

  1. Today: An adversary records your encrypted SSH traffic. It's gibberish to them.
  2. 2030-2035: A cryptographically relevant quantum computer comes online.
  3. Then: They decrypt everything they captured. Session keys, commands, file transfers, credentials.

If your SSH sessions contain anything that's still sensitive in 10 years -- infrastructure access, signing keys, proprietary source code -- you need post-quantum protection now, not when quantum computers arrive.

The hybrid approach is the conservative play: combine a post-quantum algorithm (ML-KEM-768) with a classical algorithm (X25519). If the post-quantum math turns out to be broken, you still have X25519. If quantum computers arrive, you still have ML-KEM. Belt and suspenders.

The SSH Protocol Stack

SSH is four protocols stacked on top of each other:

  +--------------------------------------------------+
  |              Channel Layer (SSH-CONNECT)           |
  |   Shell sessions, port forwarding, SCP/SFTP       |
  +--------------------------------------------------+
  |            Authentication Layer (SSH-USERAUTH)     |
  |   Public key, password, keyboard-interactive       |
  +--------------------------------------------------+
  |            Transport Layer (SSH-TRANS)              |
  |   Key exchange, encryption, MAC, compression       |
  +--------------------------------------------------+
  |                 TCP Connection                     |
  +--------------------------------------------------+

We implemented all four layers. The transport layer is where the crypto lives -- key exchange, symmetric encryption, message authentication. The auth layer validates who you are. The channel layer multiplexes interactive sessions over a single encrypted connection.

Hybrid Key Exchange: ML-KEM-768 + X25519

The key exchange is the most critical part. It's where client and server agree on a shared secret without ever transmitting it. Our hybrid scheme works like this:

Step 1: Key Exchange Init

The client sends SSH_MSG_KEXINIT proposing the algorithm mlkem768x25519-sha256. This tells the server we want hybrid post-quantum KEX.

Step 2: Dual Key Generation

Both sides generate two key pairs simultaneously:

// Generating both key pairs for hybrid KEX
let x25519_secret = EphemeralSecret::random(&mut rng);
let x25519_public = PublicKey::from(&x25519_secret);

let (mlkem_dk, mlkem_ek) = ml_kem_768_keygen(&mut rng);

// Client sends both public keys concatenated
let mut client_ephemeral = Vec::new();
client_ephemeral.extend_from_slice(x25519_public.as_bytes());    // 32 bytes
client_ephemeral.extend_from_slice(mlkem_ek.as_bytes());        // 1,184 bytes

Step 3: Server Encapsulates

The server performs X25519 Diffie-Hellman with the client's classical public key, and ML-KEM encapsulation with the client's post-quantum public key. This produces two independent shared secrets:

// Server side: derive both shared secrets
let x25519_shared = server_x25519_secret
    .diffie_hellman(&client_x25519_public);         // 32 bytes

let (mlkem_ciphertext, mlkem_shared) =
    ml_kem_768_encapsulate(&client_mlkem_ek, &mut rng); // 32 bytes

// Combine: hash both secrets together
let combined = Sha256::new()
    .chain_update(x25519_shared.as_bytes())
    .chain_update(mlkem_shared.as_bytes())
    .finalize();

Step 4: Key Derivation

The combined secret feeds into SSH's standard key derivation function (RFC 4253, Section 7.2) to produce encryption keys, IV, and MAC keys for both directions. From this point forward, the session is encrypted with AES-256-GCM using keys that are quantum-resistant.

The key property: An attacker needs to break both X25519 and ML-KEM-768 to recover the session keys. A quantum computer breaks X25519 but not ML-KEM. A breakthrough in lattice cryptanalysis breaks ML-KEM but not X25519. Neither alone is sufficient.

ML-DSA-65 Host Keys: Dual Signatures

Host keys prove the server is who it claims to be. Traditional SSH uses Ed25519 or RSA. We support those for compatibility, but our primary host key type is ML-DSA-65 (formerly Dilithium3) -- a lattice-based digital signature scheme.

ML-DSA-65 signatures are larger than Ed25519 (3,293 bytes vs. 64 bytes), but the security margin against quantum attacks justifies the overhead for an SSH connection where bandwidth is not the bottleneck.

For maximum compatibility, we offer dual host key signatures during key exchange: the server signs the exchange hash with both an Ed25519 key and an ML-DSA-65 key. Clients that understand post-quantum verify both. Legacy clients fall back to Ed25519 only.

// Dual host key signature during key exchange
let exchange_hash = compute_exchange_hash(
    &client_version, &server_version,
    &client_kexinit, &server_kexinit,
    &host_key_blob,
    &client_ephemeral, &server_ephemeral,
    &shared_secret,
);

// Sign with Ed25519 (classical)
let ed25519_sig = ed25519_host_key.sign(&exchange_hash);

// Sign with ML-DSA-65 (post-quantum)
let mldsa_sig = mldsa65_host_key.sign(&exchange_hash);

// Both signatures sent in the host key proof
let signature_blob = encode_dual_signature(
    &ed25519_sig,  // 64 bytes
    &mldsa_sig,    // 3,293 bytes
);

Building It Without OpenSSL

The hardest constraint wasn't the algorithms -- it was the environment. ClaudioOS is #![no_std]. No file system for certificate stores. No OS random number generator. No dynamic linking for libcrypto. Everything had to be pure Rust, compiled for x86_64-unknown-none.

The Crypto Stack

The Protocol Implementation

The 29 Crates We Published

Building SSH from scratch on bare metal forced us to create a lot of infrastructure. Rather than keep it all internal, we published 29 crates that other no_std projects can use:

claudio-ssh-transport
SSH transport layer, no_std
claudio-ssh-auth
SSH authentication, pubkey + password
claudio-ssh-channel
SSH channel multiplexing
claudio-mlkem
ML-KEM-512/768/1024 (FIPS 203)
claudio-mldsa
ML-DSA-44/65/87 (FIPS 204)
claudio-hybrid-kex
ML-KEM + X25519 hybrid KEX
claudio-ssh-sftp
SFTP subsystem, no_std
claudio-packet
SSH binary packet framing
claudio-kdf
SSH key derivation (RFC 4253)
claudio-hostkey
Host key management + storage
claudio-rng-hw
RDRAND/RDSEED hardware RNG
claudio-aes-gcm-hw
AES-GCM via AES-NI + CLMUL
claudio-ntt
Number Theoretic Transform for lattice crypto
claudio-poly
Polynomial arithmetic for ML-KEM/ML-DSA
claudio-compress
Lattice compression/decompression
claudio-sampling
CBD and rejection sampling
cranelift-codegen-nostd
Cranelift codegen for no_std
cranelift-frontend-nostd
Cranelift frontend for no_std
cranelift-control-nostd
Cranelift control for no_std
cranelift-codegen-shared-nostd
Cranelift shared types, no_std
rustc-hash-nostd
Fast hash for no_std
arbitrary-stub
Arbitrary trait stub for no_std
claudio-virtio-net
VirtIO-net driver
claudio-terminal
Framebuffer terminal + split panes
wraith-dom
no_std HTML parser + CSS selectors
wraith-transport
HTTP/HTTPS over smoltcp
wraith-render
HTML to text-mode renderer
claudio-python-lite
Minimal Python interpreter, no_std
claudio-editor
Nano-like text editor, no_std

Lessons from the Trenches

Post-quantum key sizes are manageable. ML-KEM-768 public keys are 1,184 bytes. ML-DSA-65 signatures are 3,293 bytes. On an SSH connection that transfers megabytes of data, an extra few KB during handshake is invisible. The "post-quantum keys are too big" narrative applies to constrained IoT devices, not to x86_64 machines with gigabit networking.

Lattice crypto is fast. ML-KEM-768 encapsulation takes about 50 microseconds on our i9-11900K. That's faster than RSA-2048 key generation. The Number Theoretic Transform (NTT) at the heart of these algorithms is essentially an FFT over a finite field -- it parallelizes beautifully and has great cache behavior.

The no_std Rust crypto ecosystem is ready. Between x25519-dalek, ed25519-dalek, sha2, chacha20poly1305, and aes-gcm, the classical side is well-covered. The post-quantum side required our own implementations, but FIPS 203 and 204 are clear specifications with excellent test vectors. If you can implement AES, you can implement ML-KEM.

SSH is more protocol than crypto. The hardest part wasn't the key exchange -- it was the channel multiplexing state machine, the window size management, the terminal mode encoding, and the dozen edge cases in the SFTP subsystem. The crypto was the easy part. Getting the SSH_MSG_CHANNEL_WINDOW_ADJUST flow control right was the hard part.

Our recommendation: If you're building anything that handles SSH connections, add hybrid post-quantum key exchange now. The standards are finalized. The performance overhead is negligible. And the protection against future quantum threats is real. Don't wait for the quantum computer to ship before you start protecting against it.

What's Next

We're working on SLH-DSA (SPHINCS+) as a hash-based signature alternative for environments that want to avoid lattice assumptions entirely. We're also implementing SSH agent forwarding so that ClaudioOS can chain SSH connections for multi-hop access to cloud infrastructure.

All 29 crates are open source. If you're building no_std Rust systems that need post-quantum crypto or SSH, they're yours to use.

Matt Gates builds ClaudioOS at Ridge Cell Repair LLC. He believes the best time to adopt post-quantum crypto was yesterday; the second best time is now.

← Back to Blog · ClaudioOS Home · GitHub