Represents the MlKem1024 class, which extends the MlKemBase class.

This class extends the MlKemBase class and provides specific implementation for MlKem1024.

MlKem1024 is a specific implementation of the ML-KEM key encapsulation mechanism.

// Using jsr:
import { MlKem1024 } from "@dajiaji/mlkem";
// Using npm:
// import { MlKem1024 } from "mlkem"; // or "crystals-kyber-js"

const recipient = new MlKem1024();
const [pkR, skR] = await recipient.generateKeyPair();

const sender = new MlKem1024();
const [ct, ssS] = await sender.encap(pkR);

const ssR = await recipient.decap(ct, skR);
// ssS === ssR

Hierarchy

  • MlKemBase
    • MlKem1024

Constructors

Properties

_compressedUSize: number = 0
_compressedVSize: number = 0
_du: number = 11
_dv: number = 5
_eta1: number = 2
_eta2: number = 2
_k: number = 4
_pkSize: number = 0
_skSize: number = 0

Methods

  • Lossily compresses and serializes a vector of polynomials.

    Parameters

    • r: Uint8Array
    • u: number[][]

      The vector of polynomials to compress.

    Returns Uint8Array

    The compressed and serialized data as a Uint8Array.

  • Lossily compresses and serializes a polynomial.

    Parameters

    • r: Uint8Array

      The output buffer to store the compressed data.

    • v: number[]

      The polynomial to compress.

    Returns Uint8Array

    The compressed and serialized data as a Uint8Array.

  • Deserializes 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.

    Parameters

    • a: Uint8Array

      The compressed and serialized data as a Uint8Array.

    Returns number[][]

    The decompressed vector of polynomials.

  • Decompresses 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.

    Parameters

    • a: Uint8Array

      The Uint8Array to decompress.

    Returns number[]

    An array of numbers obtained from the decompression process.

  • Generates a 2D array of noise samples.

    Parameters

    • sigma: Uint8Array

      The noise parameter.

    • offset: number

      The offset value.

    • size: number

      The size of the array.

    Returns number[][]

    The generated 2D array of noise samples.

  • Generates a 2-dimensional array of noise samples.

    Parameters

    • sigma: Uint8Array

      The noise parameter.

    • offset: number

      The offset value.

    • size: number

      The size of the array.

    Returns number[][]

    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.

    Parameters

    • ct: Uint8Array

      A ciphertext generated by encap.

    • sk: Uint8Array

      A private key.

    Returns Promise<Uint8Array>

    A shared secret.

    MlKemError

    // 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.

    Parameters

    • seed: Uint8Array

      A 64-octet seed for the deterministic key generation.

    Returns Promise<[Uint8Array, Uint8Array]>

    A kaypair [publicKey, privateKey].

    MlKemError

    // 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.

    Parameters

    • pk: Uint8Array

      A public key.

    • Optionalseed: Uint8Array

      An optional 32-octet seed for the deterministic shared secret generation.

    Returns Promise<[Uint8Array, Uint8Array]>

    A ciphertext (encapsulated public key) and a shared secret.

    MlKemError

    // 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, ss] = await kyber.encap(pk);
  • Generates a keypair [publicKey, privateKey].

    If an error occurred, throws MlKemError.

    Returns Promise<[Uint8Array, Uint8Array]>

    A kaypair [publicKey, privateKey].

    MlKemError

    // 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();