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.

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

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

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

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

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

    Hierarchy

    • MlKemBase
      • MlKem768
    Index

    Constructors

    Properties

    _compressedUSize: number = 0
    _compressedVSize: number = 0
    _du: number = 10
    _dv: number = 4
    _eta1: number = 2
    _eta2: number = 2
    _k: number = 3
    _pkSize: number = 0
    _skSize: number = 0

    Methods

    • Compresses the given array of coefficients into a Uint8Array.

      Parameters

      • r: Uint8Array

        The output Uint8Array.

      • u: number[][]

        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: number[]

        The array of numbers to compress.

      Returns Uint8Array

      The compressed Uint8Array.

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

      Parameters

      • a: Uint8Array

        The Uint8Array to decompress.

      Returns number[][]

      The decompressed two-dimensional array.

    • Decompresses a Uint8Array into an array of numbers.

      Parameters

      • a: Uint8Array

        The Uint8Array to decompress.

      Returns number[]

      An array of numbers.

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

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

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

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

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