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

    Class MlKem512

    Represents the MlKem512 class.

    This class extends the MlKem512Base class and provides specific implementation for MlKem512.

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

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

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

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

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

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

    Hierarchy

    • MlKem512Base
      • MlKem512
    Index

    Constructors

    Properties

    _api: Crypto = undefined
    _compressedUSize: number = 0
    _compressedVSize: number = 0
    _du: number = 10
    _dv: number = 4
    _eta1: number = 3
    _eta2: number = 2
    _k: number = 2
    _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>]

    • Returns void

    • Parameters

      • sigma: Uint8Array
      • nonce: number

      Returns Uint8Array

    • Internal

      Samples a vector of polynomials from a seed.

      Parameters

      • sigma: Uint8Array

        The seed.

      • offset: number

        The offset.

      • size: number

        The size.

      Returns Int16Array<ArrayBufferLike>[]

      The sampled vector of polynomials.

    • 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