Protected
_compressedUSizeProtected
_compressedVSizeProtected
_pkProtected
_skProtected
_compressUCompresses the given array of coefficients into a Uint8Array.
The output Uint8Array.
The array of coefficients.
The compressed Uint8Array.
Protected
_compressVCompresses the given array of numbers into a Uint8Array.
The Uint8Array to store the compressed values.
The array of numbers to compress.
The compressed Uint8Array.
Protected
_decompressUProtected
_decompressVProtected
_sampleInternal
Samples a vector of polynomials from a seed.
The seed.
The offset.
The size.
The sampled vector of polynomials.
Protected
_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: Uint8Array<ArrayBufferLike>An 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 MlKem512 class.
This class extends the MlKemBase class and provides specific implementation for MlKem512.
Remarks
MlKem512 is a specific implementation of the ML-KEM key encapsulation mechanism.
Example