X-Wing (X25519 + ML-KEM-768)
A general-purpose hybrid KEM that combines X25519 and ML-KEM-768 with a SHA3-256 combiner, designed for HPKE and application protocols.
Why it's safe
X-Wing stays secure if either X25519 or ML-KEM-768 holds, and its fixed combiner avoids the subtle mistakes of hand-rolled hybrids. It is still an Internet-Draft, so pin the exact draft version you implement for interoperability.
- Used for
- Key exchange
- Family
- Hybrid (elliptic curve + lattice)
- Classical security
- 128 bits
- Against a quantum computer
- ~192 bits
- Standards
- draft-connolly-cfrg-xwing-kem (IETF CFRG, draft), FIPS 203, RFC 7748
Migration guides
How to adopt X-Wing (X25519 + ML-KEM-768). Pick your stack.
@noble/post-quantum · typescriptJavaScript/TypeScript (any runtime): hybrid X25519 + ML-KEM-768 with @noble/post-quantumExperimental
Why
@noble/post-quantum is a small pure-JavaScript implementation of ML-KEM (FIPS 203), ML-DSA (FIPS 204) and SLH-DSA (FIPS 205). It runs anywhere JavaScript runs: Node 20/22, Deno, Bun, browsers and edge workers, which makes it the easiest option when you cannot rely on Node 24's native node:crypto support.
During the transition the recommended pattern is hybrid: combine a classical X25519 exchange with ML-KEM-768 so the result is secure if either holds. You can use the library's ready-made X-Wing construction, or build the combiner yourself with HKDF.
Maturity: the library is widely used and carefully written, but its README states it has not been independently audited. Prefer an OpenSSL/AWS-LC-backed API (Node 24.7+ node:crypto, WebCrypto where available) for high-assurance server code.
Steps
npm install @noble/post-quantum @noble/curves @noble/hashes- Decide between X-Wing (option A, a fixed, specified combiner; recommended) and a custom HKDF combiner (option B, if you must interoperate with an existing protocol).
- Store the recipient's private key as securely as any other private key; publish its public key.
- Use the 32-byte shared secret only as input to a KDF, then encrypt with AES-256-GCM or ChaCha20-Poly1305.
Before (X25519 / ECIES-style)
import { x25519 } from '@noble/curves/ed25519.js';
const recipient = x25519.keygen();
const eph = x25519.keygen();
const shared = x25519.getSharedSecret(eph.secretKey, recipient.publicKey); // quantum-vulnerableAfter, option A: X-Wing (X25519 + ML-KEM-768)
import { XWing } from '@noble/post-quantum/hybrid.js';
const recipient = XWing.keygen(); // publicKey: 1216 bytes
const { cipherText, sharedSecret } = XWing.encapsulate(recipient.publicKey); // cipherText: 1120 bytes
const recovered = XWing.decapsulate(cipherText, recipient.secretKey);
// sharedSecret and recovered are equal 32-byte keysX-Wing is specified in the IETF CFRG draft draft-connolly-cfrg-xwing-kem. Record the draft/library version you deployed so the other side can match it.
After, option B: explicit HKDF combiner
import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';
import { x25519 } from '@noble/curves/ed25519.js';
import { hkdf } from '@noble/hashes/hkdf.js';
import { sha256 } from '@noble/hashes/sha2.js';
import { concatBytes, utf8ToBytes } from '@noble/hashes/utils.js';
// Recipient long-term keys
const pq = ml_kem768.keygen(); // publicKey 1184 B, secretKey 2400 B
const ec = x25519.keygen();
// Sender
const { cipherText, sharedSecret: ssPq } = ml_kem768.encapsulate(pq.publicKey);
const eph = x25519.keygen();
const ssEc = x25519.getSharedSecret(eph.secretKey, ec.publicKey);
// Bind every public value into the derivation (domain separation + transcript)
const info = concatBytes(utf8ToBytes('myapp/hybrid-kem/v1'), eph.publicKey, ec.publicKey, cipherText, pq.publicKey);
const key = hkdf(sha256, concatBytes(ssPq, ssEc), undefined, info, 32);
// send: eph.publicKey (32 B) + cipherText (1088 B)
// Recipient
const ssPq2 = ml_kem768.decapsulate(cipherText, pq.secretKey);
const ssEc2 = x25519.getSharedSecret(ec.secretKey, eph.publicKey);
const key2 = hkdf(sha256, concatBytes(ssPq2, ssEc2), undefined, info, 32);Gotchas
- API versions. Code above is for
@noble/post-quantum0.5.x and@noble/curves/@noble/hashes2.x (note the.jssubpath imports). Argument orders and names have changed between major releases; check the README of the version you install. - Do not just XOR or concatenate secrets without a KDF, and include the ciphertext and public keys in the KDF input. Hand-made combiners are a classic source of subtle bugs, which is why option A exists.
- Implicit rejection.
decapsulatereturns a pseudo-random secret instead of throwing on a bad ciphertext; you detect tampering when the AEAD fails. - Sizes. Hybrid ciphertext ≈ 1.1 KB and public key ≈ 1.2 KB, versus 32 bytes for X25519 alone.
- Constant time. JavaScript engines give weaker side-channel guarantees than native code. That is fine for most client-side and server-side uses, but HSM-grade requirements need a native or hardware implementation.
- Pre-standard Kyber is not ML-KEM. Libraries or data created with "Kyber768" round-3 code are not interoperable with FIPS 203 ML-KEM.
Verify
console.assert(Buffer.from(key).equals(Buffer.from(key2)));
console.assert(cipherText.length === 1088 && pq.publicKey.length === 1184);