In my last post, Post-Quantum SSH Just Got Urgent, I wrote that ML-KEM was coming to LogRaker “as soon as it’s properly tested”.
Well… it’s tested. My fork of swift-nio-ssh now speaks mlkem768x25519-sha256, the hybrid key exchange OpenSSH has used by default since 10.0, and it’s tagged 0.15.0-rsa.5 for anybody else who builds on swift-nio-ssh.
Same two messages, just bigger
What I like about this hybrid is how little of SSH it actually touches. A classic ECDH key exchange is two messages, the client sends its public key and the server sends back its own (plus its host key and a signature), and from those two keys both sides work out the same secret without ever sending it over the wire. The hybrid uses those exact same two messages (numbers 30 and 31, if you’re into that sort of thing). It just stuffs more into them.
The client sends an ML-KEM-768 public key, 1,184 bytes, with a 32-byte X25519 key glued to the end. The server uses the ML-KEM key to lock up a fresh random secret, sends back the locked box (1,088 bytes) with its own X25519 key glued on, and the client unlocks it. Now both sides hold two secrets, one from ML-KEM and one from X25519, and they hash them together with SHA-256 into the one secret all the session keys come from, which is why the connection stays safe as long as either half holds.
A P-384 key is 97 bytes. So yeah, a tad bigger, but it’s a couple of kb once per connection (and once per re-key), and nobody’s gonna notice that in reality.
CryptoKit did the hard part
I didn’t write a single line of lattice math, and I wouldn’t want to. Thankfully Apple added ML-KEM to CryptoKit with macOS 26, so the fork asks CryptoKit for a key pair, hands it the server’s reply and gets a secret back. Everything around that is SSH plumbing (message layout, length checks, hashing and so on), and that much I can manage.
On macOS 15, CryptoKit has no ML-KEM, so the fork simply doesn’t offer the hybrid there, and LogRaker keeps using P-384 exactly as before.
One gotcha: An ML-KEM public key is basically a long list of numbers, and every single one of them has to be smaller than 3,329 (the FIPS 203 standard says to reject the key otherwise). CryptoKit happily loads a key with a 4,095 in it and only complains once you try to use it. For SSH that is fine, since using it is the very next thing the server does, but there’s a test for it now, just in case that ever changes.
While I was in there I also moved P-521 ahead of P-256 in the list of classical fallbacks, since Filippo Valsorda’s reading of the NSA advisory puts the 256-bit curves under suspicion. P-384 still comes right after the hybrid.
Both ends were mine…
In the last post I mentioned that the trickiest bit was one tiny encoding detail. Every key exchange the fork already had puts the shared secret into the handshake hash as a big int (SSH calls that an mpint), and this one puts it in as a plain string, length first and then the bytes. Get that wrong and the fork’s own tests would never notice, because those tests run a client and a server, both of them my code, so they’d make the exact same mistake together and agree perfectly ;-)
Only a real server tells you.
Now, conveniently, macOS 27 ships OpenSSH 10.5, sshd included, so I ran a private copy of it on my Mac mini that allowed nothing but mlkem768x25519-sha256 and rekeyed after every megabyte (RekeyLimit 1M), which means a brand new key exchange over and over again. Then I read 8 mb through the fork. Every byte came back intact, across 58 rekeys, every one of them on the hybrid. Then I turned it around and pointed OpenSSH’s own ssh at the little example server that ships with swift-nio-ssh, and pushed 3 MB through 25 key exchanges without a hitch. And against a server that only offers P-384, the fork falls back to P-384, as it should.
…and so was the compression
Before publishing anything I had the whole fork reviewed one more time, in depth. The ML-KEM part came out clean.
The compression I added two weeks ago however did not.
OpenSSH starts a brand new compression stream every time the keys change after login, and my code kept the old one running. In that very post I even wrote, with a straight face, “A rekey changes the keys but leaves the streams alone.”
Oops.
So the moment a server rekeyed, it started compressing from scratch while the code was still waiting for the next bit of the old stream, zlib choked, and the connection died. My tests never caught it for the exact same reason as above (both ends mine, same mistake on both), and the NVIDIA Jetson I tested against back then never rekeyed during the test, because a stock OpenSSH server rarely does. Same lesson twice in one week!
Well, it’s fixed now. The fork starts a fresh stream with every new set of keys, just like OpenSSH, and with compression on, that same kind of test against sshd read 10.9 MB through 71 rekeys without a hiccup. The two new tests for it build the OpenSSH side by hand, so they’d actually catch this one now. If you turned ‘Compress SSH traffic’ on in LogRaker (it’s been off by default since 4.0) and saw connections drop every now and then on a server that rekeys, that was me. Sorry about that.
What changes in LogRaker
Both go into the next LogRaker update. On macOS 26 or later, connecting to a server that runs OpenSSH 9.9 or later, your connection is post-quantum from then on, and there’s nothing for you to set up. Older servers, and anything on macOS 15, stay on P-384.
There’s one gap I can’t close for now. OpenSSH 9.0 through 9.9 used a different post-quantum key exchange by default, sntrup761x25519-sha512, and nobody has written that one in Swift yet, so servers from 8.5 to 9.8 still end up on P-384. My Jetson runs 8.9, so it’s one of them.
If you set up that Monitor for *post-quantum* from the last post, LogRaker should drop off its list once you’ve updated, on macOS 26 and later anyway. OpenSSH only writes that warning from 10.6 on, and anything that new has ML-KEM.
Your keys are still the harder problem, and I still haven’t decided what Key Manager should create by default.
The fork
It’s all in the fork on GitHub, Apache 2.0 like upstream. As always, every change is marked with a LOGRAKER FORK: comment, and FORK.md explains what changed and how it was tested. There are 16 new tests (14 for the hybrid, 2 for the compression fix) and all 381 pass.
One heads-up if you depend on it. Building it now needs Xcode 26 or later, because older Xcode versions don’t know about ML-KEM at all.
So, if you look after servers, update OpenSSH, and if you tail their logs with LogRaker, the next update takes care of the key exchange for you (on macOS 26 or later, that is). Building SSH in Swift yourself? Grab the fork and let me know how it goes!
Thanks for reading!