
Post-Quantum Cryptography in PHP: A Beginner’s Guide
I’m not convinced that the newest algorithm keeps anyone safe. Many people assume it does. Today we hash our passwords, we serve everything over HTTPS, and we call it done. Still, my worry is that powerful quantum computers, maybe combined with AI, may (or might not) turn that upside down. I can’t say which. The AI part stays a guess in my text, because I can’t back it with facts.
What a quantum computer would break
Two algorithms matter here. Shor’s algorithm, from 1994, lets a large enough quantum computer factor numbers and solve discrete logarithms quickly. That breaks RSA, ECDH and ECDSA, so it hits most of the public key crypto that we rely on in TLS and in signed tokens.
Grover’s algorithm only speeds up brute force search by a square root, so it weakens AES and SHA-2 in theory but doesn’t break them in practice, and we don’t need to panic about hashes. NIST’s 2024 draft says AES-128 and up stay fine. So in my view the hash behind your password column isn’t where the quantum trouble sits. A weak password is still weak, quantum or not.
No such computer exists today. The estimates keep falling, though. A 2025 preprint puts RSA-2048 under one million noisy qubits, where a 2019 estimate said 20 million. That’s theory, not an attack anyone has shown. The best known timeline survey comes from authors at a PQC vendor, so in my reading its numbers are opinions.
Still, waiting isn’t harmless in my book. The reason is harvest now, decrypt later: someone records our encrypted traffic today and decrypts it when the machine exists. NIST says this hits encryption and key exchange, not authentication done before such a computer exists. Key exchange is the urgent part, and that’s where my attention goes first.
What post-quantum cryptography is
Post-quantum cryptography (PQC) is normal software. You don’t need quantum hardware. It uses math problems that, as far as anyone knows, neither classical nor quantum computers solve fast. It runs on your PHP server like any other crypto, so we need nothing new in the rack.
NIST published three final standards on 13 August 2024. FIPS 203 is ML-KEM, formerly Kyber, and it handles key exchange. ML-DSA, formerly Dilithium, is FIPS 204, and it signs things. The third one, FIPS 205, is SLH-DSA, formerly SPHINCS+. It also signs, but it is built on different math, so it works as a backup if the first signature scheme ever falls over.
FN-DSA (Falcon, FIPS 206) isn’t published yet. HQC, a backup key exchange picked in March 2025, is planned for 2027.
A key exchange of this kind is called a KEM, and it works differently from RSA encryption. You don’t encrypt a message. The sender takes the receiver’s public key and gets two things back: a ciphertext and a shared secret. The receiver turns the ciphertext into the same secret with their private key. Then both sides use that secret with fast symmetric encryption, as we do today.
Everything gets bigger. A public key for the middle ML-KEM size is 1184 bytes and its ciphertext is 1088 bytes, against 32 bytes for an X25519 key. That’s about 37 times. A signature of the middle ML-DSA size is 3309 bytes, and an Ed25519 signature is 64. That’s about 52 times.
Edge cases come to my mind early. A VARCHAR(255) column for a public key won’t survive. Neither will a token that carries a signature, if a proxy or a cookie limit cuts it off on the way. That could bite us in a place nobody looks at. Not great.
Why people believe it’s secure
Believed is the honest word. NIST says the new schemes are believed to be secure, even against quantum attackers. It means nobody has found an attack. It doesn’t mean anyone has proved there is none.
The key exchange rests on a problem called Module LWE. Solving a set of linear equations is school math. Add a small random error to every equation and finding the secret gets very hard. Nobody knows a fast way to do that, on a classical computer or on a quantum one.
SLH-DSA relies only on properties of hash functions, and that’s why NIST keeps it as a second option next to the lattice schemes, in case someone breaks lattices one day. A hash based scheme wouldn’t fall with them.
Belief can still fail, and it has. SIKE was a NIST candidate for a key exchange. In July 2022 two researchers broke it with an ordinary classical attack, in about ten minutes on one core. A 2024 preprint claimed a quantum attack on LWE, and the author withdrew it after finding a bug. That calms me down a bit. It also shows how quickly a claim can appear, and why we shouldn’t bet on one idea.
The code is the other risk. Some Kyber implementations leaked secrets through division timing, a flaw called KyberSlash. The math was fine and the software leaked, so we have to look at the code too. This matters for the PHP libraries below, because most of them are young.
I also wouldn’t trust one new assumption alone. That’s the idea behind a hybrid key exchange: run X25519 and ML-KEM together, and an attacker has to break both. For my taste a hybrid is the sane default, because it costs little.
What you can run in PHP today
Short version: nothing that we can call audited and ready for production. I haven’t tried any of the code below, so my snippets come from reading the sources. Test them before you trust them.
PHP 8.6 adds sodium_crypto_kem_*, which is X-Wing, a hybrid of ML-KEM and X25519. It also adds sodium_crypto_kem_mlkem768_* for plain ML-KEM. Both need libsodium 1.0.22 or newer, and PHP 8.5 has neither. X-Wing is an individual Internet-Draft, not a standard. If we want standards only, I’d take the mlkem768 variant.
$kp = sodium_crypto_kem_keypair();
$sk = sodium_crypto_kem_secretkey($kp);
$pk = sodium_crypto_kem_publickey($kp);
[$ct, $senderSecret] = sodium_crypto_kem_enc($pk);
$receiverSecret = sodium_crypto_kem_dec($ct, $sk);
var_dump(hash_equals($senderSecret, $receiverSecret));The sender keeps $senderSecret and sends $ct. The receiver gets the same secret from $ct and their secret key. libsodium is a mature project, so this is the option on my watch list.
The Composer package paragonie/pqcrypto_compat is pure PHP. It covers ML-KEM and ML-DSA, needs PHP 8.1 or newer on 64 bit, and uses the Rust extension when it’s loaded. It’s at version 0.3.2, and its README says it has never been independently audited.
use ParagonIE\PQCrypto\Compat;
['signingKey' => $sk, 'verificationKey' => $vk] = Compat::mldsa65_keygen();
$sig = Compat::mldsa65_sign($sk, $message);
$ok = Compat::mldsa65_verify($vk, $sig, $message);The signature comes back as an object, so call $sig->bytes() when you want to store it. One more thing: the README example for the biggest ML-KEM size calls the 768 decaps function. I’d check snippets against the source before copying them.
The same author ships paragonie/ext-pqcrypto, a Rust extension that adds SLH-DSA. It needs a nightly Rust toolchain, and the RustCrypto crates under it say they were never audited either.
The liboqs bindings are small community projects, not an official wrapper. liboqs itself says it is for research and prototyping, not for protecting sensitive data. And the openssl_* functions have nothing, not even in 8.6. The php-src issue 22862 is open and needs an RFC.
What I’d do, and what would change my mind
I think hybrid TLS plus watching is good enough for now. TLS comes first because harvest now, decrypt later hits key exchange, and TLS is where our users’ data travels. NIST and the UK NCSC both support that order. The NCSC also says don’t build your own PQC, but rely on trusted libraries and vendor upgrades.
The hybrid group is X25519MLKEM768, standardised for TLS 1.3 in RFC 10024 in August 2026. OpenSSL 3.5 offers it by default, and that release is LTS. Chrome 131 and later, and Firefox, use it by default. For nginx you need a build against OpenSSL 3.5 or newer. The nginx blog’s example is ssl_ecdh_curve X25519MLKEM768:X25519:prime256v1.
I’d check my servers first. According to the same blog, Ubuntu 22.04 and 24.04 and Debian 12 ship OpenSSL 3.0 with no PQC. Cloudflare says about 70 percent of the browser traffic it sees is hybrid, but only about 15 percent of the origins it talks to. So browsers are ready and servers lag.
Apache has no PQC directive. Its SSLOpenSSLConfCmd passes OpenSSL’s Groups setting through, and I’d expect that to work, but I haven’t tested it. I also expect our PHP code stays untouched behind nginx or Apache, though I’m not sure for every setup.
For the app level I’d wait. Everything above is pre-1.0 or unaudited, and I’d rather not put it in front of real user data. A young library without an audit can fail in ways nobody has found yet. I’m less sure about this if your data must stay secret for a decade or more. Then the harvest problem is real, and waiting costs something. The NCSC asks for a plan by 2028, priority migrations by 2031 and full migration by 2035.
Four things would change my mind: a FIPS 206 or HQC draft, an audit of the Paragon libraries, libsodium 1.0.22 reaching distro packages, or a shown quantum attack on RSA.
What would make you move on app level crypto first?


