@openforge-sh/liboqs - v0.14.3
    Preparing search index...

    Class MLKEM512

    ML-KEM-512 wrapper class providing high-level KEM operations

    This class wraps the low-level WASM module to provide a user-friendly interface for ML-KEM-512 operations with automatic memory management and input validation.

    MLKEM512

    import LibOQS_ml_kem_512 from '@openforge-sh/liboqs/ml-kem-512';
    import { createMLKEM512 } from '@openforge-sh/liboqs/algorithms/ml-kem-512';

    const kem = await createMLKEM512(LibOQS_ml_kem_512);
    const { publicKey, secretKey } = kem.generateKeyPair();
    const { ciphertext, sharedSecret } = kem.encapsulate(publicKey);
    kem.destroy();
    Index

    Accessors

    • get info(): {
          name: "ML-KEM-512";
          identifier: "ML-KEM-512";
          type: "kem";
          securityLevel: 1;
          standardized: true;
          description: "NIST FIPS 203 ML-KEM-512 (128-bit quantum security)";
          keySize: {
              publicKey: 800;
              secretKey: 1632;
              ciphertext: 768;
              sharedSecret: 32;
          };
      }

      Get algorithm information and constants

      Returns {
          name: "ML-KEM-512";
          identifier: "ML-KEM-512";
          type: "kem";
          securityLevel: 1;
          standardized: true;
          description: "NIST FIPS 203 ML-KEM-512 (128-bit quantum security)";
          keySize: {
              publicKey: 800;
              secretKey: 1632;
              ciphertext: 768;
              sharedSecret: 32;
          };
      }

      Algorithm metadata

      const info = kem.info;
      console.log(info.keySize.publicKey); // 800

    Methods

    • Generate a new keypair for ML-KEM-512

      Generates a public/private keypair using the algorithm's internal random number generator. The secret key must be kept confidential.

      Returns { publicKey: Uint8Array; secretKey: Uint8Array }

      If keypair generation fails

      If instance has been destroyed

      const { publicKey, secretKey } = kem.generateKeyPair();
      // publicKey: 800 bytes
      // secretKey: 1632 bytes (keep confidential!)
    • Encapsulate a shared secret using a public key

      Generates a random shared secret and encapsulates it using the provided public key. The shared secret can be used for symmetric encryption.

      Parameters

      • publicKey: Uint8Array<ArrayBufferLike>

        Recipient's public key (800 bytes)

      Returns { ciphertext: Uint8Array; sharedSecret: Uint8Array }

      If public key is invalid

      If encapsulation fails

      If instance has been destroyed

      const { ciphertext, sharedSecret } = kem.encapsulate(recipientPublicKey);
      // ciphertext: 768 bytes (send to recipient)
      // sharedSecret: 32 bytes (use for symmetric encryption)
    • Decapsulate a shared secret using a secret key

      Recovers the shared secret from a ciphertext using the secret key. The recovered shared secret will match the one generated during encapsulation.

      Parameters

      • ciphertext: Uint8Array<ArrayBufferLike>

        Ciphertext received (768 bytes)

      • secretKey: Uint8Array<ArrayBufferLike>

        Recipient's secret key (1632 bytes)

      Returns Uint8Array<ArrayBufferLike>

      Recovered shared secret (32 bytes)

      If inputs are invalid

      If decapsulation fails

      If instance has been destroyed

      const sharedSecret = kem.decapsulate(ciphertext, mySecretKey);
      // sharedSecret: 32 bytes (matches sender's shared secret)
    • Clean up resources and free WASM memory

      This method should be called when you're done using the instance to free WASM memory. After calling destroy(), the instance cannot be used for further operations.

      Returns void

      const kem = await createMLKEM512(LibOQS_ml_kem_512);
      // ... use kem ...
      kem.destroy();