UNPKG

noble-xwing

Version:

Typescript implementation of the X-Wing hybrid Post Quantum KEM using the noble library, as outlined in https://eprint.iacr.org/2024/039.

37 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hkdfSha256KemForDH = hkdfSha256KemForDH; const hkdf_1 = require("@noble/hashes/hkdf"); const sha256_1 = require("@noble/hashes/sha256"); function id(a) { return a; } function hkdfSha256KemForDH(dh) { return { keygen: () => { const sk = dh.genSecretKey(); return { sk, pk: dh.publicKey(sk) }; }, encapsulate: (pk) => { const esk = dh.genSecretKey(); const encappedKey = dh.publicKey(esk); const ssEph = dh.exchange(esk, pk); const kemContext = new Uint8Array([...encappedKey, ...pk]); return { ss: (0, hkdf_1.hkdf)(sha256_1.sha256, ssEph, undefined, kemContext, 32), ct: encappedKey, }; }, decapsulate: (ct, sk) => { const ssEph = dh.exchange(sk, ct); const pkRecip = dh.publicKey(sk); const kemContext = new Uint8Array([...ct, ...pkRecip]); return (0, hkdf_1.hkdf)(sha256_1.sha256, ssEph, undefined, kemContext, 32); }, encodeSS: id, encodeCT: id, encodePK: id, encodeSK: id, }; } //# sourceMappingURL=dhKemHkdfSha256.js.map