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

    Class MlKem768

    Represents the MlKem768 class, which extends the MlKemBase class.

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

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

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

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

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

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

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

    Hierarchy

    • MlKemBase
      • MlKem768
    Index

    Constructors

    Properties

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

    Methods

    • Compresses the given array of coefficients into a Uint8Array.

      Parameters

      • r: Uint8Array

        The output Uint8Array.

      • u: Int16Array<ArrayBufferLike>[]

        The array of coefficients.

      Returns Uint8Array

      The compressed Uint8Array.

    • Compresses the given array of numbers into a Uint8Array.

      Parameters

      • r: Uint8Array

        The Uint8Array to store the compressed values.

      • v: Int16Array

        The array of numbers to compress.

      Returns Uint8Array

      The compressed Uint8Array.

    • Parameters

      • ct: Uint8Array
      • sk: Uint8Array

      Returns Uint8Array

    • Decompresses a Uint8Array into a two-dimensional array of numbers.

      Parameters

      • a: Uint8Array

        The Uint8Array to decompress.

      Returns Int16Array<ArrayBufferLike>[]

      The decompressed two-dimensional array.

    • Decompresses a Uint8Array into an array of numbers.

      Parameters

      • a: Uint8Array

        The Uint8Array to decompress.

      Returns Int16Array

      An array of numbers.

    • Parameters

      • seed: Uint8Array

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

    • Parameters

      • pk: Uint8Array
      • Optionalseed: Uint8Array

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

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

    • 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