Belajar
← All lessons

How hybrid key exchange works

Two key exchanges, one key

Browser
shop.test

browser.js

const ecdh = await x25519.generateKey();const kem = ml_kem768.keygen();// 1,216 bytes: ML-KEM key, then X25519 keysend(concat(kem.publicKey, ecdh.publicKey)); const [ciphertext, serverKey] = split(reply, 1088);const pq = ml_kem768.decapsulate(ciphertext, kem.secretKey);const classic = await x25519.derive(ecdh.privateKey, serverKey);// 64 bytes: ML-KEM secret, then X25519 secretconst secret = concat(pq, classic);// TLS runs its key schedule here. HKDF stands inconst key = await hkdf(secret);

server.js

const [kemKey, clientKey] = split(share, 1184);const ecdh = await x25519.generateKey();const classic = await x25519.derive(ecdh.privateKey, clientKey);const kem = ml_kem768.encapsulate(kemKey);// 1,120 bytes: ML-KEM ciphertext, then X25519 keysend(concat(kem.cipherText, ecdh.publicKey));const key = await hkdf(concat(kem.sharedSecret, classic));

Break one half and the key still holds

Key exchangeX25519 aloneX25519MLKEM768
Message

Neither break is real here. Each switch hands the attacker one secret, to show what it unlocks

attacker.js

// everything the attacker copied off the wireconst { ciphertext } = recording;const classic = broken.x ? crackX25519(recording) : unknown;const pq = broken.pq ? crackMlKem(recording) : unknown;// the key needs every secret that went into itconst key = await hkdf(concat(pq, classic));read(await decrypt(key, ciphertext));

Topics

Next: How IP routing works

Open lesson