NodeCrypto Help

ML-KEM Encapsulate

Category: Post-Quantum Cryptography ยท Node Type ID: pqc-mlkem-encaps

Encapsulates a shared key against recipient public key

Overview

Generates a fresh 32-byte (256-bit) post-quantum shared secret and encapsulates it against the recipient's ML-KEM public key (NIST FIPS 203), outputting both the 32-byte Shared Key (for the sender) and the encapsulated Ciphertext (to transmit to the recipient for decapsulation).

Ciphertext sizes are 768 bytes for ML-KEM-512, 1,088 bytes for ML-KEM-768, and 1,568 bytes for ML-KEM-1024.

When to Use

Parameter Configuration

Parameter (ID)Type & DefaultVisibility ConditionDescription & Options
Variant
variant
select
Default: 768
Always visible Must match the ML-KEM security level of the connected Recipient Public Key (512, 768, or 1024).
  • 512: ML-KEM-512
  • 768: ML-KEM-768
  • 1024: ML-KEM-1024

Port I/O Specification

See Ports & Connections for general wiring rules, data type colors, and dynamic port creation.

Input Ports

Port Nature: Fixed Input Ports (1 total).

Port NamePort IDData TypeRequiredVisibility ConditionDescription
Recipient Public Key publicKey Bytes Required Always visible Recipient's ML-KEM encapsulation public key (800B, 1184B, or 1568B depending on variant).

Output Ports

Port Nature: Fixed Output Ports (2 total).

Port NamePort IDData TypeVisibility ConditionDescription
Shared Key sharedSecret Bytes (32B) Always visible Generated 32-byte shared secret key (ready for use with AES-256, ChaCha20-Poly1305, or HKDF).
Ciphertext ciphertext Bytes Always visible Encapsulated KEM ciphertext (768B, 1088B, or 1568B) to send to ML-KEM Decapsulate.

Error Cases

When any of the following conditions occurs at runtime, this node transitions to an ERROR state and downstream nodes connected to its outputs do not execute.

Error CodeDefault Engine MessageTrigger Condition
INVALID_KEY_MATERIAL Invalid key length or format Raised when Recipient Public Key length does not match the selected ML-KEM variant or fails FIPS 203 modulus check.

Examples

Encapsulating a 32-Byte Key with ML-KEM-768

Encapsulate a shared key and encrypt a message with AES-256-GCM.

  1. Connect Public Key from ML-KEM KeyGen to Recipient Public Key.
  2. Connect Shared Key to the Key port of AES Encrypt, and send Ciphertext to ML-KEM Decapsulate.