API reference for crystals-kyber-js/main
    Preparing search index...

    Class MlKem1024

    Represents the MlKem1024 class, which extends the MlKem1024Base class.

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

    Use createMlKem1024 instead. This async class-based API will be removed in a future release.

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

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

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

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

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

    Hierarchy

    • MlKem1024Base
      • MlKem1024
    Index

    Constructors

    Properties

    _api: Crypto = undefined
    _compressedUSize: number = 0
    _compressedVSize: number = 0
    _du: number = 11
    _dv: number = 5
    _eta1: number = 2
    _eta2: number = 2
    _k: number = 4
    _noiseVecs: Int16Array<ArrayBufferLike>[]
    _pkSize: number = 0
    _skSize: number = 0

    Methods

    • Lossily compresses and serializes a vector of polynomials.

      Parameters

      • r: Uint8Array
      • u: Int16Array<ArrayBufferLike>[]

        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: Int16Array

        The polynomial to compress.

      Returns Uint8Array

      The compressed and serialized data as a Uint8Array.

    • Parameters

      • ct: Uint8Array
      • sk: Uint8Array

      Returns 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 Int16Array<ArrayBufferLike>[]

      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 Int16Array

      An array of numbers obtained from the decompression process.

    • Parameters

      • seed: Uint8Array

      Returns [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]

    • Parameters

      • pk: Uint8Array
      • Optionalseed: Uint8Array

      Returns [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]

    • Returns [Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]

    • Returns void

    • Parameters

      • sigma: Uint8Array
      • nonce: number

      Returns Uint8Array

    • 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 Int16Array<ArrayBufferLike>[]

      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 Int16Array<ArrayBufferLike>[]

      The generated 2-dimensional array of noise samples.

    • Sets up the MlKemBase instance by loading the necessary crypto library. If the crypto library is already loaded, this method does nothing.

      Returns Promise<void>

      A promise that resolves when the setup is complete.

    • 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<ArrayBufferLike>>

      A shared secret.

      MlKemError

    • 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<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]>

      A kaypair [publicKey, privateKey].

      MlKemError

    • 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<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]>

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

      MlKemError

    • Generates a keypair [publicKey, privateKey].

      If an error occurred, throws MlKemError.

      Returns Promise<[Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>]>

      A kaypair [publicKey, privateKey].

      MlKemError