Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
const algorithm = { name: "ML-KEM-512" };
const { publicKey } = await crypto.subtle.generateKey(algorithm, true, ["encapsulateBits", "decapsulateBits"]);
const valid = new Uint8Array(await crypto.subtle.exportKey("raw-public", publicKey));
const spki = new Uint8Array(await crypto.subtle.exportKey("spki", publicKey));
const keys = [
["a valid key", "raw-public", valid],
["800 bytes of 0xff", "raw-public", new Uint8Array(800).fill(0xff)],
["799 bytes", "raw-public", valid.slice(0, 799)],
["a valid key in SPKI", "spki", spki],
["800 bytes of 0xff in SPKI", "spki", spki.slice().fill(0xff, spki.length - 800)],
];
for (const [name, format, data] of keys) {
let key;
try {
key = await crypto.subtle.importKey(format, data, algorithm, true, ["encapsulateBits"]);
} catch (error) {
println(`${name}: import ${error.name}`);
continue;
}
try {
await crypto.subtle.encapsulateBits(algorithm, key);
println(`${name}: imported, encapsulated`);
} catch (error) {
println(`${name}: imported, encapsulate ${error.name}`);
}
}
});
</script>