Skip to content
jshacks.dev
Security

Post Quantum Cryptography Migration Guide for Node

Move Node.js apps to post-quantum crypto after the NSA advisory: hybrid TLS, ML-KEM and ML-DSA in node:crypto, WebCrypto, jose, SSH, Deno and Bun.

24 min read
Summarize in AI
Flat illustration of a database table gaining a new column, with the Node.js, MySQL and SQLite logos.

Every Node.js release since 24.5.0 and 22.20.0 bundles OpenSSL 3.5, and OpenSSL 3.5 sends a hybrid post-quantum key share in every TLS 1.3 ClientHello unless something tells it not to. So if your service runs the official Node.js 26.14.0 or 24.23.0 binaries and you never set ecdhCurve, its outbound HTTPS to a server that supports X25519MLKEM768 is already post-quantum. If it runs a distro build of Node linked against the system's OpenSSL 3.0, or a config that sets ecdhCurve: 'P-256:P-384' from an old hardening guide, none of it is. That difference decides more of your migration than anything else in the NSA advisory of 2 December 2026, and it is the first thing this guide checks.

The rest of the stack is less automatic. Node.js 24.7.0 added crypto.encapsulate() and crypto.decapsulate() for ML-KEM, 24.6.0 added ML-DSA signing, and WebCrypto gained both, plus hybrid KEMs in 26.10.0 and 24.22.0. jose has signed JWTs with ML-DSA since 6.1.0. jsonwebtoken 9.0.3 has no post-quantum algorithm at all, and neither does the ssh2 package. This guide goes through each place a Node.js application uses public-key cryptography, shows the API that replaces it where one exists, says plainly where none does, and ends with an order of work. The code is ES modules for Node.js 26 (Active LTS), with the differences for 24 and 22 called out where they matter.

What the advisory says and what it does not

The NSA press release tells owners, operators and vendors of National Security Systems "to immediately accelerate the transition to post-quantum cryptography (PQC)". Its first reason is the familiar one: adversaries are recording encrypted traffic now to decrypt it once a large quantum computer exists, usually called harvest now, decrypt later. Its second is new: frontier AI companies "responsibly disclose[d] recent discoveries that impact the security of some cryptographic systems currently in use". A joint statement by ONCD, NSA and CISA the same day says those discoveries "do not present an immediate and widespread threat" and asks organizations to "expeditiously upgrade". No algorithm is named in either.

So do not tell your team that RSA or elliptic curves were broken. Nobody has publicly demonstrated a practical break of RSA-2048 or of ECC. What is true is that RSA, ECDH, ECDSA, Ed25519 and X25519 all fall to Shor's algorithm on a large enough quantum computer, and that traffic recorded today is exposed from the day that machine exists.

The research in the news is about lattices, which ML-KEM and ML-DSA are built on. Four papers published on 30 November 2026 describe a quantum algorithm for some structured lattice problems. The CIRG assessment found no improvement in classical attacks on mainstream lattice schemes, and against ML-KEM and ML-DSA the new attack needs vastly more computation than the best ones already known, because its advantage grows with the ring dimension, which ML-KEM and ML-DSA fix at 256. The UK NCSC sees no threat to deployed ML-KEM or ML-DSA. Cloudflare says quantum computers are far more likely to break elliptic curves and RSA before lattices, and moved its own full post-quantum target forward to 2027.

The working position for this guide follows from that: ML-KEM and ML-DSA are the replacements, you use the highest security level your stack supports, you prefer hybrid modes that pair them with a classical algorithm, and you design so that the next change is configuration.

The NSA also issued a companion Cybersecurity Advisory whose PDF was not available to us. According to public reporting on it, it asks for TLS 1.3 with post-quantum settings turned on where available, certificate authorities ready for the new algorithms, vendor updates applied, isolation of what cannot be upgraded, and CNSA 1.0 algorithms (P-384, RSA of 3072 bits or more, AES-256, SHA-384) as the interim floor. CNSA 2.0 itself names ML-KEM-1024, ML-DSA-87, AES-256 and SHA-384 or SHA-512.

For civilian federal work, Executive Order 14412 sets post-quantum key establishment for high-value and high-impact systems by 31 December 2030 and post-quantum signatures by 31 December 2031, with contractors bound through the FAR by the end of 2030. NIST IR 8547 deprecates the 112-bit quantum-vulnerable algorithms after 2030 and disallows them after 2035.

Where a Node.js app uses public-key cryptography

A typical Express, Fastify or Nest service never calls an RSA function, and still depends on public-key cryptography in a dozen places. This map is the outline of the rest of the guide.

WhereWhat it uses todayHarvest now, decrypt later riskPost-quantum path in December 2026
Outbound HTTPS (fetch, undici, axios, got, gRPC)ECDHE key exchange, RSA or ECDSA certificatesHighX25519MLKEM768 by default on OpenSSL 3.5 builds
Inbound HTTPS (https.createServer, frameworks)The same, at whatever terminates TLSHighecdhCurve on a 3.5 build, or the proxy in front
Database and cache clients (pg, mysql2, ioredis)TLS through node:tlsHighClient side automatic; the server often needs a setting
SSH (ssh2, deploy tooling)Curve25519 key exchange, Ed25519 or RSA keysHigh for the sessionNot in ssh2; OpenSSH 10 has it
JWT, OAuth, OpenID ConnectRS256, ES256, EdDSALow: signatures cannot be decrypted laterML-DSA in jose 6.1.0 and later
Your own encryption to a public keyRSA-OAEP, ECDH plus AESHigh if the data outlives the algorithmML-KEM in node:crypto and WebCrypto
Package and release signingnpm provenance, Sigstore, GPGLow, but forged updates are the worst caseTooling-dependent; plan now

The distinction between the third column's highs and lows runs through everything else. Key exchange is what harvest now, decrypt later attacks, because a recorded handshake can be decrypted by a future machine. A signature can only be forged by someone who has a quantum computer at the moment of forging, so an ES256 JWT that expired in 2026 cannot be attacked by recording it. That is why the work starts with TLS and stored ciphertext, and why short-lived signatures come last.

What you do not need to change

AES-256-GCM, ChaCha20-Poly1305, SHA-256, SHA-384, SHA-512, SHA-3, HMAC and HKDF are not affected by Shor's algorithm. Grover's algorithm speeds up brute-force key search quadratically in theory, which is why CNSA 2.0 asks for AES-256 rather than AES-128, but AES-256 is the CNSA 2.0 cipher, not a migration target.

AES-128 is the one to think about. NIST still allows it and a quantum search against a 128-bit key is not practical. If a contract says CNSA 2.0, though, AES-128 is out, so code that calls createCipheriv('aes-128-gcm', ...) needs a 32-byte key and aes-256-gcm for that customer. Everyone else can schedule it with ordinary maintenance.

Password hashing does not change. bcrypt, argon2, crypto.scrypt() and crypto.pbkdf2() are symmetric. WebCrypto's Argon2 support (Node.js 24.8.0) is a nice addition for new code, not a quantum fix. Cookie signing in Express and Fastify uses HMAC, and HS256 JWTs are HMAC too, so they are safe against a quantum attacker. Do not convert RS256 tokens to HS256 for this reason: the shared secret then lives on every verifier, which is a worse problem than the one you were solving.

crypto.randomBytes(), crypto.randomUUID() and crypto.getRandomValues() are random sources and stay as they are.

Step 1: find out what your runtime can do

Start with the process. This script reports the Node.js and OpenSSL versions, the default group setting, whether node:crypto can generate ML-KEM and ML-DSA keys in this build, whether WebCrypto has the hybrid KEM, and the versions of the packages this guide discusses, read from package-lock.json.

pq-inventory.mjsJavaScript
import crypto from 'node:crypto';
import { readFileSync } from 'node:fs';
import tls from 'node:tls';

function canGenerate(type) {
  try {
    crypto.generateKeyPairSync(type);
    return 'yes';
  } catch (err) {
    return `no (${err.code ?? err.name})`;
  }
}

const hybridKem = globalThis.SubtleCrypto.supports?.('encapsulateBits', 'MLKEM768-X25519') ?? false;

const lock = JSON.parse(readFileSync('package-lock.json', 'utf8'));
const installed = (name) => lock.packages?.[`node_modules/${name}`]?.version ?? 'not installed';

const rows = [
  ['node', process.versions.node],
  ['openssl', process.versions.openssl],
  ['ecdhCurve', tls.DEFAULT_ECDH_CURVE],
  ['ML-KEM', canGenerate('ml-kem-768')],
  ['ML-DSA', canGenerate('ml-dsa-65')],
  ['hybrid KEM', String(hybridKem)],
  ...['jose', 'jsonwebtoken', 'ssh2', 'undici', 'axios'].map((name) => [name, installed(name)]),
];
for (const [label, value] of rows) console.log(label.padEnd(14) + value);

On the official Node.js 26.14.0 binary, in a project with the current releases of those packages installed, it prints:

Text
node          26.14.0
openssl       3.5.9
ecdhCurve     auto
ML-KEM        yes
ML-DSA        yes
hybrid KEM    true
jose          6.2.19
jsonwebtoken  9.0.3
ssh2          1.17.0
undici        8.14.0
axios         1.22.0

Each line answers a question the later sections depend on. openssl decides whether hybrid TLS is possible at all. ecdhCurve reads auto unless some code in the process has assigned tls.DEFAULT_ECDH_CURVE; any other value is worth tracing, because it overrides OpenSSL's default list for every server context. ML-KEM and ML-DSA say whether the build can do the new algorithms, and on a Node.js build linked against OpenSSL 3.0 both report no with the error's code. hybrid KEM uses SubtleCrypto.supports(), which itself is new, so the optional call returns undefined on older runtimes and the line reads false.

Run it in every image you deploy, not on your laptop. The interesting results come from the build agents and the containers.

Which OpenSSL your Node.js uses

The official binaries from nodejs.org, the node Docker images and the installers all bundle their own OpenSSL, so the Node.js version decides it. The release index records the version for every build.

Node.js releaseBundled OpenSSLHybrid TLS by default
26.14.0 (Active LTS)3.5.9Yes
24.23.0 (LTS)3.5.9Yes
24.5.0 to 24.22.x3.5.1 to 3.5.9Yes
24.0.0 to 24.4.x3.0.16No
22.23.5 (maintenance LTS)3.5.9Yes
22.20.0 to 22.23.43.5.2 to 3.5.9Yes
22.19.0 and earlier3.0.xNo
27.0.0 alpha builds4.1.0Yes

The exception is a Node.js built with --shared-openssl, which is how several Linux distributions package it. Those builds use the system library, so a distro nodejs package on a system with OpenSSL 3.0 cannot do ML-KEM or hybrid TLS whatever its version number says. The issue that led to the TLS group reporting fix was found on exactly such a build. process.versions.openssl tells you which one you have; the inventory script prints it.

Node.js 22 is the line to watch. It has the OpenSSL 3.5 TLS behavior from 22.20.0, but the node:crypto ML-KEM and ML-DSA APIs never landed there: the 22.23.5 documentation has no crypto.encapsulate() and no ML-DSA key type. So a 22.x service can negotiate hybrid TLS and cannot use ML-KEM in application code. Node.js 22 reaches end of life in April 2027, which is a better reason to move than either.

Outbound TLS: what the default does

tls.connect(), https.request(), the built-in fetch() and undici all build a secure context with ecdhCurve defaulting to [tls.DEFAULT_ECDH_CURVE](https://nodejs.org/docs/latest-v26.x/api/tls.html#tlsdefault_ecdh_curve), which is 'auto'. In the Node.js 26.14.0 source, SecureContext::SetECDHCurve() in src/crypto/crypto_context.cc calls OpenSSL only when the value is not 'auto', so the default leaves OpenSSL's built-in group list untouched. And for OpenSSL 3.5, the documentation of that list says "The DEFAULT list selects X25519MLKEM768 as one of the predicted keyshares", alongside X25519.

The practical effect: a Node.js 24.5 or later client offers the hybrid group to every server, and a server that supports it picks it. A server that does not picks X25519 from the second key share, with no extra round trip. Axios uses Node's https module, got and gRPC's @grpc/grpc-js use node:tls, and the pg, mysql2 and ioredis clients wrap tls.connect(), so all of them inherit this without any change.

You still need to know which servers accept the hybrid group, because those are the connections that are protected. tlsSocket.getEphemeralKeyInfo() reports it, and since Node.js 26.5.0 and 24.19.0 it understands the new groups. Before those releases it returned an empty object for hybrid and ML-KEM groups; the fix made it return { type: 'TLSGroup', name }.

check-group.mjsJavaScript
import tls from 'node:tls';

const host = process.argv[2] ?? 'pq.example.test';
const socket = tls.connect({ host, port: 443, servername: host }, () => {
  console.log(socket.getProtocol(), socket.getEphemeralKeyInfo());
  socket.end();
});

Against a server on OpenSSL 3.5 with its default groups, Node.js 26.14.0 prints:

Text
TLSv1.3 { type: 'TLSGroup', name: 'X25519MLKEM768' }

Against a server that only does classical groups, the same script prints the older shape:

Text
TLSv1.3 { type: 'ECDH', name: 'X25519', size: 253 }

Running that once per host does not scale to a real service, which makes dozens of outbound connections through fetch(), SDKs and database drivers. Auditing every one of them from inside the process, with a diagnostics channel and a CI check, has its own walkthrough in checking whether Node uses post-quantum TLS key exchange.

Setting the group list explicitly

Most services should leave ecdhCurve alone. There are three reasons not to: requiring the hybrid group for a specific internal service, preferring ML-KEM-1024 for a CNSA 2.0 track, and working around a middlebox that drops large ClientHello messages. The [ecdhCurve documentation](https://nodejs.org/docs/latest-v26.x/api/tls.html#tlscreatesecurecontextoptions) accepts "a named curve, TLS group, or colon-separated list", and gives X25519MLKEM768 as an example.

agents.mjsJavaScript
import https from 'node:https';
import { Agent, fetch } from 'undici';

const GROUPS = '*X25519MLKEM768:*X25519:P-256:P-384';

// node:https, and anything built on it (axios, got)
export const httpsAgent = new https.Agent({
  keepAlive: true,
  minVersion: 'TLSv1.3',
  ecdhCurve: GROUPS,
});

// undici 8: TLS options go under connect
export const dispatcher = new Agent({
  connect: { minVersion: 'TLSv1.3', ecdhCurve: GROUPS },
});

const res = await fetch('https://pq.example.test/health', { dispatcher });
console.log(res.status);
Text
200

The value is passed to OpenSSL's group list parser, so OpenSSL 3.5's syntax applies. A * before a name asks the client to send a key share for that group in its first message. Without any *, OpenSSL sends one key share for the leftmost group, and a server that lacks ML-KEM has to answer with a HelloRetryRequest before the handshake can continue. Two key shares avoid that round trip at the cost of about 32 extra bytes. minVersion: 'TLSv1.3' matters because the ML-KEM groups exist only in TLS 1.3, and a TLS 1.2 fallback would negotiate classical ECDHE without complaint.

The two failures you will meet

The first is loud. On a Node.js linked against OpenSSL 3.0, the same ecdhCurve string throws when the context is created:

Text
Error: Failed to set ECDH curve

That message comes from SetECDHCurve() whenever OpenSSL rejects the list, and OpenSSL 3.0 does not know X25519MLKEM768. The error code is ERR_CRYPTO_OPERATION_FAILED. OpenSSL lets you prefix a group with ? so that an unknown name is skipped instead of rejected, but its documentation dates that feature to OpenSSL 3.3, so it makes a list portable between 3.5 and later releases, not down to 3.0. If code has to run on both, branch on process.versions.openssl, or on the inventory's canGenerate('ml-kem-768') result, before passing a list.

The second failure is silent, and more common. Search your code and your config files for ecdhCurve and DEFAULT_ECDH_CURVE. A TLS 1.2-era hardening guide that set ecdhCurve: 'P-256:P-384' or 'secp384r1' replaces OpenSSL's entire default list, so the hybrid group disappears from both the client and the server. Handshakes work, logs are clean, and the traffic is as exposed as it was in 2020. Delete the setting or prepend the hybrid groups to it.

Large ClientHello messages and middleboxes

A hybrid key share adds about 1,200 bytes to the ClientHello for X25519MLKEM768 and close to 1,700 for SecP384r1MLKEM1024, according to the OpenSSL documentation, and the message no longer fits in one TCP segment. OpenSSL's docs warn that "firewall software may erroneously disrupt the TLS handshake" as a result. In a Node.js service that shows up as timeouts to one internal host while everything else works.

Fix the firewall if you can. If you cannot, the OpenSSL docs give a narrow workaround for the one client that crosses it: ecdhCurve: '?X25519MLKEM768:DEFAULT'. The leading entry without * suppresses the hybrid key share while keeping the group in the supported list, so a server that wants it can still ask for it with a HelloRetryRequest.

Inbound TLS for Node.js servers

When Node.js terminates TLS itself, the server's ecdhCurve decides which groups it accepts. With the default 'auto' on OpenSSL 3.5, a Node.js https or http2 server already accepts X25519MLKEM768 from clients that offer it. You set the list when you want an explicit preference or a CNSA 2.0 order:

server.mjsJavaScript
import { readFileSync } from 'node:fs';
import https from 'node:https';

const server = https.createServer(
  {
    key: readFileSync('key.pem'),
    cert: readFileSync('cert.pem'),
    minVersion: 'TLSv1.3',
    ecdhCurve: 'X25519MLKEM768:SecP384r1MLKEM1024:X25519:P-384',
  },
  (req, res) => {
    res.end('ok\n');
  },
);

server.listen(8443);

On a server the * markers have no effect and the order is a preference. The same option works on tls.createServer() and http2.createSecureServer(). Note that getEphemeralKeyInfo() returns null on a server-side socket, per the TLS docs, so verify an inbound listener from a client, for example with check-group.mjs pointed at it.

Most production Node.js services sit behind nginx, a cloud load balancer or a CDN, and then the TLS handshake an attacker records is the proxy's, not Node's. For nginx, the [ssl_ecdh_curve](https://nginx.org/en/docs/http/ngx_http_ssl_module.html) directive defaults to auto, which uses OpenSSL's built-in list, so nginx on OpenSSL 3.5 offers the hybrid group already, and an old ssl_ecdh_curve secp384r1; line removes it. For a managed load balancer, the vendor's TLS policy decides; read its documentation and test the public hostname from outside.

Databases need a server-side change

This is where Node.js differs from many other stacks. The pg client uses node:tls, so on Node.js 24.5 or later it offers X25519MLKEM768 to PostgreSQL without any configuration. The server is the problem. In PostgreSQL 18 the setting is ssl_groups, and its default is X25519:prime256v1, with no ML-KEM group in it. A PostgreSQL 18 server linked against OpenSSL 3.5 therefore negotiates classical X25519 with your hybrid-capable client until someone edits postgresql.conf:

postgresql.confINI
ssl_min_protocol_version = 'TLSv1.3'
ssl_groups = 'X25519MLKEM768:X25519:prime256v1'

PostgreSQL 17 and earlier have only ssl_ecdh_curve, which takes a single group, so you cannot offer the hybrid and keep a fallback. Managed PostgreSQL services decide this for you; ask your provider. MySQL, Redis and message brokers each have their own setting, and each belongs in the inventory with the OpenSSL version on both ends.

Certificates stay classical for now

A hybrid handshake protects the session keys, not the certificate. Your server certificate is still signed with RSA or ECDSA, and so is every certificate above it, because publicly trusted certificate authorities do not yet issue ML-DSA certificates for the web. That is acceptable for the moment for the same reason short-lived JWTs are: a certificate signature has to be forged during the handshake, by someone who already has a quantum computer, and recording it achieves nothing. What you can do now is inventory where certificates are issued (public CAs, a private CA for mTLS, a service mesh) and confirm that each issuer has a plan for ML-DSA. For a private CA that you run yourself, ask whether its key storage and its clients can handle keys and signatures several kilobytes long, since that is where the migration will break first.

ML-KEM in node:crypto

For your own encryption to a public key, ML-KEM replaces RSA-OAEP and ECDH. Node.js 24.7.0 added [crypto.encapsulate()](https://nodejs.org/docs/latest-v26.x/api/crypto.html#cryptoencapsulatekey-callback) and crypto.decapsulate(), and generateKeyPair() gained 'ml-kem-512', 'ml-kem-768' and 'ml-kem-1024' in the same release. All of them require OpenSSL 3.5, which is the footnote on every ML-KEM entry in the docs.

A KEM does not encrypt your data. The sender runs encapsulate() on the recipient's public key and gets a random 32-byte shared key plus a ciphertext that carries it; the recipient runs decapsulate() on the ciphertext and gets the same key; the data is then encrypted with that key and AES-256-GCM.

mlkem.mjsJavaScript
import { decapsulate, encapsulate, generateKeyPairSync } from 'node:crypto';

const { publicKey, privateKey } = generateKeyPairSync('ml-kem-1024');

const { sharedKey, ciphertext } = encapsulate(publicKey);
const recovered = decapsulate(privateKey, ciphertext);

console.log(publicKey.asymmetricKeyType, ciphertext.length, sharedKey.length);
console.log(recovered.equals(sharedKey));
Text
ml-kem-1024 1568 32
true

encapsulate() returns an object with sharedKey and ciphertext, both Buffers, and decapsulate() returns the key as a Buffer. Both take an optional callback, and with one they run on libuv's threadpool instead of the main thread, which is what a server encrypting per request should use. ML-KEM-1024 is the CNSA 2.0 parameter set, with a 1,568-byte public key and ciphertext; ML-KEM-768, used by the TLS hybrid group, has a 1,184-byte public key and a 1,088-byte ciphertext.

The same encapsulate() also accepts 'x25519', 'ec' and 'rsa' keys, using DHKEM and RSA secret value encapsulation. That is convenient for writing one code path, and it is also how a classical KEM ends up in a "post-quantum" feature by mistake. Check asymmetricKeyType on keys that arrive from configuration.

Keys serialize the usual ways. Since Node.js 26.0.0, ML-KEM and ML-DSA private keys exported as 'pkcs8' use the seed-only form by default, and the 'raw-seed' format exports the 64-byte ML-KEM seed directly; the asymmetric key types table lists the formats each type supports, and 26.1.0 added JWK export for ML-KEM.

Hybrid KEMs in WebCrypto

Pairing ML-KEM with X25519 means an attacker has to break both, which is the hedge the CIRG recommends while lattice research is active. Writing that combiner yourself is where hybrid schemes go wrong, and since Node.js 26.10.0 and 24.22.0 you do not have to: WebCrypto supports 'MLKEM768-X25519', 'MLKEM768-P256' and 'MLKEM1024-P384', which the Modern Algorithms in the Web Cryptography API proposal defines from the IRTF's concrete hybrid KEM draft. The shared key is 256 bits for all three.

hybrid-kem.mjsJavaScript
const { subtle } = globalThis.crypto;
const kem = 'MLKEM768-X25519';
const aes = { name: 'AES-GCM', length: 256 };

const { publicKey, privateKey } = await subtle.generateKey(
  { name: kem }, false, ['encapsulateKey', 'decapsulateKey'],
);

// Sender: derive an AES key and the ciphertext that carries it
const { sharedKey, ciphertext } = await subtle.encapsulateKey(
  kem, publicKey, aes, false, ['encrypt'],
);
const iv = crypto.getRandomValues(new Uint8Array(12));
const sealed = await subtle.encrypt(
  { name: 'AES-GCM', iv }, sharedKey, new TextEncoder().encode('customer 1001 card token'),
);

// Recipient: recover the same AES key from the ciphertext
const key = await subtle.decapsulateKey(kem, privateKey, ciphertext, aes, false, ['decrypt']);
const opened = await subtle.decrypt({ name: 'AES-GCM', iv }, key, sealed);
console.log(new TextDecoder().decode(opened));
Text
customer 1001 card token

encapsulateKey() imports the shared secret straight into a non-extractable AES-GCM key, so the raw secret never appears in JavaScript. To store the result you keep three things: ciphertext, iv and sealed. Put an identifier for MLKEM768-X25519 in front of them, as the agility section below does, so that switching to MLKEM1024-P384 later is a new identifier and not a format migration. The WebCrypto KEM methods are marked Stability 1.1, active development, in the Node.js docs, so pin your Node.js minor version in CI for code that depends on them.

ML-DSA and SLH-DSA signatures

Node.js 24.6.0 added ML-DSA key pairs and signing to node:crypto, and 24.8.0 added SLH-DSA plus the context option for ML-DSA, Ed448 and SLH-DSA. As with Ed25519, [crypto.sign()](https://nodejs.org/docs/latest-v26.x/api/crypto.html#cryptosignalgorithm-data-key-callback) takes null as the algorithm, because the key type decides it.

mldsa.mjsJavaScript
import { generateKeyPairSync, sign, verify } from 'node:crypto';

const { publicKey, privateKey } = generateKeyPairSync('ml-dsa-87');
const message = Buffer.from('release 4.2.0 manifest');
const context = Buffer.from('release-manifest-v1');

const signature = sign(null, message, { key: privateKey, context });
console.log(signature.length);
console.log(verify(null, message, { key: publicKey, context }, signature));
console.log(verify(null, message, { key: publicKey, context: Buffer.from('other') }, signature));
Text
4627
true
false

The context string binds a signature to one purpose, so a signature made for release manifests does not verify as, say, a license file signed with the same key. A 4,627-byte ML-DSA-87 signature against Ed25519's 64 bytes is the main cost; ML-DSA-65 signatures are 3,309 bytes and ML-DSA-44 are 2,420. WebCrypto has the same algorithms as 'ML-DSA-44', 'ML-DSA-65' and 'ML-DSA-87', with ContextParams carrying the context.

SLH-DSA, the hash-based standard in FIPS 205, is available as twelve 'slh-dsa-*' key types. Its signatures are larger and slower to produce, and its security rests only on hash functions, which makes it a reasonable choice for rarely-made, long-lived signatures such as a release-signing root. CNSA 2.0 itself lists the stateful hash-based schemes LMS and XMSS for firmware, which Node.js does not implement; those belong in an HSM.

JWT and OAuth

RFC 9964, published in May 2026, defines ML-DSA for JOSE: the JWS algorithms ML-DSA-44, ML-DSA-65 and ML-DSA-87, and a new key type, AKP, whose private part is the 32-byte seed.

jose has supported those identifiers since 6.1.0, released in August 2025, and its per-runtime support tables list ML-DSA for Node.js, Deno and Bun. On Node.js it uses WebCrypto, so it needs 24.7.0 or later on an OpenSSL 3.5 build.

jwt-mldsa.mjsJavaScript
import { generateKeyPair, jwtVerify, SignJWT } from 'jose';

const { publicKey, privateKey } = await generateKeyPair('ML-DSA-65');

const jwt = await new SignJWT({ sub: 'user-42', scope: 'read' })
  .setProtectedHeader({ alg: 'ML-DSA-65' })
  .sign(privateKey);
console.log(jwt.length);

const { payload, protectedHeader } = await jwtVerify(jwt, publicKey, { algorithms: ['ML-DSA-65'] });
console.log(protectedHeader.alg, payload.sub);
Text
4483
ML-DSA-65 user-42

The length is fixed by the sizes: 26 base64url characters for the header, 43 for the claims, 4,412 for a 3,309-byte signature, and two dots. The same token signed with ES256 is 151 characters. A 4.4 KB token fits in an Authorization header and does not fit in a 4,096-byte cookie, and some proxies cap headers at 8 KB in total.

jsonwebtoken 9.0.3, still the most installed JWT package, has no ML-DSA. Its key validation in lib/validateAsymmetricKey.js allows only ec, rsa and rsa-pss key types for asymmetric algorithms, and its README's algorithm table stops at ES512 and none. Code on jsonwebtoken that needs ML-DSA has to move to jose, which is the move we would make anyway for any new service.

For most services, our advice is the same as for every stack: do not switch access tokens to ML-DSA yet. They live for minutes, a signature is not exposed to harvest now, decrypt later, and nobody can forge ES256 today. What to do now is make every verifier pick keys by kid from a JWKS with an explicit algorithm allow-list, which jose's createRemoteJWKSet() and jwtVerify() already do. Adding an AKP key with ML-DSA-65 is then a rotation, not a release.

SSH from Node.js

The ssh2 package, which most Node.js SSH tooling depends on, offers curve25519-sha256 and the elliptic-curve and Diffie-Hellman methods, and no post-quantum key exchange; the latest release is 1.17.0 from August 2025. OpenSSH made mlkem768x25519-sha256 its default in 10.0, per the OpenSSH release notes.

So for deploy scripts and automation, the practical path is to shell out to the system ssh client with child_process.spawn() on hosts that have OpenSSH 10, or to route ssh2 connections through a jump host whose OpenSSH negotiates the hybrid method on the long-haul leg. Neither is elegant. Recorded SSH sessions carry credentials and data the same way TLS does, so treat this as a known gap in the inventory rather than something to ignore.

Deno and Bun

Deno 2.8.2, released in June 2026, added ML-DSA and ML-KEM to its WebCrypto implementation, and 2.8.3 added ML-DSA JWK import and export and fixes for ML-KEM raw-seed and PKCS#8 keys. Deno's TLS stack is rustls, not OpenSSL, and we could not find a Deno release note or manual page that documents hybrid key exchange for its fetch() or Deno.connectTls(), so test it against your own server before you count on it.

Bun uses BoringSSL. Its node:crypto ML-DSA and ML-KEM support (oven-sh/bun#34549) and its WebCrypto ML-DSA and ML-KEM support (#34838) were merged in July 2026 and are in Bun 1.4.0 and later. In Bun 1.4.5's node:tls layer, ecdhCurve is checked against a fixed list that includes X25519MLKEM768 and MLKEM1024, in src/js/internal/tls.ts. That check splits on : and compares exact names, so the OpenSSL * and ? prefixes used above make Bun throw Failed to set ECDH curve. Write plain names, such as 'X25519MLKEM768:X25519:P-256', in code that has to run on both runtimes.

Crypto agility: make the next change a config change

The CIRG's advice to design for agility is the part most JavaScript code fails, because byte formats rarely carry a version and functions are named for what they do rather than how. The pattern that works is an algorithm identifier stored with every ciphertext and signature, a registry from identifier to implementation, and a policy that says which identifiers may be written and which may still be read.

agility.mjsJavaScript
import { generateKeyPairSync, sign, verify } from 'node:crypto';

const SCHEMES = new Map([
  [1, { name: 'ed25519' }],
  [2, { name: 'ml-dsa-65' }],
]);
const WRITE = 2;
const READ = new Set([1, 2]);

const keys = new Map(
  [...SCHEMES].map(([id, { name }]) => [id, generateKeyPairSync(name)]),
);

function signBlob(message) {
  const signature = sign(null, message, keys.get(WRITE).privateKey);
  return Buffer.concat([Buffer.from([WRITE]), signature]);
}

function verifyBlob(blob, message) {
  const id = blob[0];
  if (!READ.has(id)) throw new Error(`scheme ${id} is retired`);
  return verify(null, message, keys.get(id).publicKey, blob.subarray(1));
}

const blob = signBlob(Buffer.from('invoice 1001'));
console.log(blob.length, SCHEMES.get(blob[0]).name, verifyBlob(blob, Buffer.from('invoice 1001')));
Text
3310 ml-dsa-65 true

One extra byte per signature buys a clean retirement: once every stored Ed25519 signature has been re-signed, remove 1 from READ. Both key types take null as the algorithm in crypto.sign(), which is why one function can serve both. A real system adds a key identifier and keeps READ and WRITE in configuration.

Treat TLS the same way. Keep group lists in environment variables or config files (ecdhCurve from process.env, ssl_groups in postgresql.conf, ssl_ecdh_curve in nginx) so that moving to SecP384r1MLKEM1024, or dropping a group, is a deploy.

The migration plan, in order

The NSA's next steps are inventory, risk assessment, then triage and implementation. For a Node.js service, this is the order we would work in.

OrderWorkWhy here
1Run pq-inventory.mjs in every image and on every build agentEverything below depends on the OpenSSL line
2Move to official Node.js 26.14 or 24.23 binaries, off distro builds linked to OpenSSL 3.0Turns on hybrid outbound TLS with no code change
3Remove ecdhCurve and DEFAULT_ECDH_CURVE overrides that list only classical curvesThey disable the hybrid group silently
4Audit which outbound hosts negotiate X25519MLKEM768Shows which traffic is still exposed
5Turn on hybrid groups at the TLS terminator: nginx on OpenSSL 3.5, the load balancer policy, or ecdhCurveInbound traffic is the most recorded
6Set ssl_groups on PostgreSQL 18 and the equivalent on other data storesClients are ready; servers are not
7Replace RSA-OAEP and ECDH wrapping of stored keys with MLKEM768-X25519 or ML-KEM-1024 behind an identifierStored data has the longest exposure
8Move JWT code from jsonwebtoken to jose, with JWKS and algorithm allow-listsMakes the ML-DSA switch a key rotation
9Replace ssh2 key exchange paths with OpenSSH 10 where sessions carry secretsCloses the SSH gap
10Add ML-DSA or SLH-DSA beside existing signatures on releases and updates you signLong-lived roots take years to roll out

Steps 1 to 6 are upgrades and configuration that a team can finish in weeks. Step 7 is a data migration and should be planned like one. Steps 8 to 10 are the long tail, and the reason to start them now rather than in 2030.

Where this advice stops

If you run Node.js in FIPS mode with --enable-fips or a FIPS OpenSSL provider, the hybrid groups and ML-KEM may not be within the validated module you are required to use. The provider's security policy decides, not the OpenSSL default list, and a FIPS-only configuration can refuse them.

If you run on a serverless platform, the platform chooses the Node.js build. Run the inventory inside the function. A runtime that reports OpenSSL 3.0 cannot be fixed from your code; your options are a container-image deployment if the platform offers one, or a proxy you control.

Browser code is outside this guide. Whether a browser's WebCrypto offers ML-KEM depends on the browser and version, so feature-detect with SubtleCrypto.supports?.() and keep the classical path working; Node.js's own Modern Algorithms support is marked as active development for the same reason.

And if you build national security systems, CNSA 2.0 requires ML-KEM-1024, ML-DSA-87, validated products and acquisition language, and the NSA's documents are the authority on its transition dates, not any summary, this one included.

Also inNode.js
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.