UNPKG

mlkem

Version:

An ML-KEM/CRYSTALS-KYBER implementation written in TypeScript for various JavaScript runtimes

74 lines (73 loc) 2.15 kB
/** * This implementation is based on https://github.com/antontutoveanu/crystals-kyber-javascript, * which was deveploped under the MIT licence below: * https://github.com/antontutoveanu/crystals-kyber-javascript/blob/main/LICENSE */ import { N } from "./consts.js"; import { MlKemBase } from "./mlKemBase.js"; /** * Represents the MlKem768 class, which extends the MlKemBase class. * * This class extends the MlKemBase class and provides specific implementation for MlKem768. * * @remarks * * MlKem768 is a specific implementation of the ML-KEM key encapsulation mechanism. * * @example * * ```ts * // Using jsr: * import { MlKem768 } from "@dajiaji/mlkem"; * // Using npm: * // import { MlKem768 } from "mlkem"; // or "crystals-kyber-js" * * const recipient = new MlKem768(); * const [pkR, skR] = await recipient.generateKeyPair(); * * const sender = new MlKem768(); * const [ct, ssS] = await sender.encap(pkR); * * const ssR = await recipient.decap(ct, skR); * // ssS === ssR * ``` */ export class MlKem768 extends MlKemBase { constructor() { super(); Object.defineProperty(this, "_k", { enumerable: true, configurable: true, writable: true, value: 3 }); Object.defineProperty(this, "_du", { enumerable: true, configurable: true, writable: true, value: 10 }); Object.defineProperty(this, "_dv", { enumerable: true, configurable: true, writable: true, value: 4 }); Object.defineProperty(this, "_eta1", { enumerable: true, configurable: true, writable: true, value: 2 }); Object.defineProperty(this, "_eta2", { enumerable: true, configurable: true, writable: true, value: 2 }); this._skSize = 12 * this._k * N / 8; this._pkSize = this._skSize + 32; this._compressedUSize = this._k * this._du * N / 8; this._compressedVSize = this._dv * N / 8; } }