Protected
_compressedUSizeProtected
_compressedVSizeProtected
_pkProtected
_skProtected
_compressUProtected
_compressVProtected
_decompressUDeserializes and decompresses a vector of polynomials.
This is the approximate inverse of the _compressU
method.
Since compression is lossy, the decompressed data may not match the original vector of polynomials.
The compressed and serialized data as a Uint8Array.
The decompressed vector of polynomials.
Protected
_decompressVDecompresses a given polynomial, representing the approximate inverse of compress2, in Uint8Array into an array of numbers.
Note that compression is lossy, and thus decompression will not match the original input.
The Uint8Array to decompress.
An array of numbers obtained from the decompression process.
Protected
_sampleProtected
_sampleGenerates a 2-dimensional array of noise samples.
The noise parameter.
The offset value.
The size of the array.
The generated 2-dimensional array of noise samples.
Generates a ciphertext for the public key and a shared secret.
If an error occurred, throws MlKemError.
A ciphertext generated by encap.
A private key.
A shared secret.
// Using jsr:
import { MlKem768 } from "@dajiaji/mlkem";
// Using npm:
// import { MlKem768 } from "mlkem"; // or "crystals-kyber-js"
const kyber = new MlKem768();
const [pk, sk] = await kyber.generateKeyPair();
const [ct, ssS] = await kyber.encap(pk);
const ssR = await kyber.decap(ct, sk);
// ssS === ssR
Derives a keypair [publicKey, privateKey] deterministically from a 64-octet seed.
If an error occurred, throws MlKemError.
A 64-octet seed for the deterministic key generation.
A kaypair [publicKey, privateKey].
// Using jsr:
import { MlKem768 } from "@dajiaji/mlkem";
// Using npm:
// import { MlKem768 } from "mlkem"; // or "crystals-kyber-js"
const kyber = new MlKem768();
const seed = new Uint8Array(64);
globalThis.crypto.getRandomValues(seed);
const [pk, sk] = await kyber.deriveKeyPair(seed);
Generates a shared secret from the encapsulated ciphertext and the private key.
If an error occurred, throws MlKemError.
A public key.
Optional
seed: Uint8ArrayAn optional 32-octet seed for the deterministic shared secret generation.
A ciphertext (encapsulated public key) and a shared secret.
Generates a keypair [publicKey, privateKey].
If an error occurred, throws MlKemError.
A kaypair [publicKey, privateKey].
Represents the MlKem1024 class, which extends the MlKemBase class.
This class extends the MlKemBase class and provides specific implementation for MlKem1024.
Remarks
MlKem1024 is a specific implementation of the ML-KEM key encapsulation mechanism.
Example