Sitemap
Press enter or click to view image in full size

Member-only story

Post Quantum Cryptography in a Browser

4 min readNov 4, 2024

--

Like it or not, we need to move away from ECDH (Elliptic Curve Diffie Hellman) for key exchange and move towards using ML-KEM (aka Kyber) for a key encapsulation method (KEM).

Alice will generate a key pair (pkAlice and skAlice) and sends Bob her public key (pkAlice). Bob will then generate a new key (bobKey). He will then encrypt the new key (bobKey) with Alice’s public key (pkAlice), and sends the resultant ciphertext (cipherText) to Alice. Alice then decrypts the ciphertext (cipherText) with her private key (skAlice). She then gets aliceKey, and which will be the same as bobKey (Figure 1):

const [pkAlice, skAlice] = await recipient.generateKeyPair();
const sender = new MlKem512();
const [cipherText, bobKey] = await sender.encap(pkAlice);
const aliceKey = await recipient.decap(cipherText, skAlice);
Press enter or click to view image in full size
Figure 1

The HTML is [here]:

<html>
<body>
<script type="module">
const toHexString = (bytes) => {
return Array.from(bytes, (byte) => {
return ('0' + (byte & 0xff).toString(16)).slice(-2);
}).join('');
};
import { MlKem512, MlKem768, MlKem1024 } from "https://esm.sh/mlkem"…

--

--

Prof Bill Buchanan OBE FRSE
Prof Bill Buchanan OBE FRSE

Written by Prof Bill Buchanan OBE FRSE

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.