@zerolabz/wire
v0.2.1
Published
Sub-microsecond C++20 Node-API transport engine implementing SPEC-LATTICE-WIRE-02 (ML-KEM-512, ChaCha20-Poly1305, 0-RTT/1-RTT anti-replay, and mlock secret handles)
Maintainers
Readme
@zerolabz/wire
High-assurance, zero-V8-residency post-quantum 0-RTT and 1-RTT transport engine for Node.js.
lattice-wire-native implements SPEC-LATTICE-WIRE-01 and SPEC-LATTICE-WIRE-02 as a C/C++20 Node-API (N-API) native addon. It pairs FIPS 203 ML-KEM-512 (vendored PQClean clean implementation), a domain-separated SHAKE-256 KDF, and RFC 8439 ChaCha20-Poly1305 AEAD (Monocypher 4.0.3) with a page-aligned mmap + mlock (MADV_DONTDUMP) secure allocator so Critical Security Parameters (CSPs) never reside on the V8 JavaScript heap.
Core Security Guarantees
- Zero V8 Heap Residency for CSPs (
{ secureHandle: true })- ML-KEM-512 secret keys (
1,632 bytes), KEM shared secrets (32 bytes), and derived 0-RTT/1-RTT ChaCha20-Poly1305 session keys (32 bytes) are generated, derived, and consumed directly inside page-aligned native memory wrapped by type-tagged Node-APIExternalhandles (SECURE_SECRET_TYPE_TAG). - Secrets are never staged in V8
Bufferobjects, protecting against V8 heap snapshots, garbage-collector copying/relocation, and accidental buffer serialization.
- ML-KEM-512 secret keys (
- Swap & Core-Dump Exclusion (
mlock+MADV_DONTDUMP)- Every secure handle allocation is page-aligned (
mmapwithMAP_PRIVATE | MAP_ANONYMOUSon POSIX,VirtualAllocon Windows), pinned in physical RAM viamlock(VirtualLockon Windows) to prevent swap-file leakage, and markedMADV_DONTDUMPon Linux so core dumps omit secret pages.
- Every secure handle allocation is page-aligned (
- Deterministic Zeroization (
destroySecret)- Calling
destroySecret(handle)(orsession.destroy()/manager.destroy()) immediately scrubs the underlying page via constant-timecrypto_wipebefore invokingmunlockandmunmap. Subsequent attempts to use a destroyed handle fail deterministically withERR_SECRET_DESTROYED.
- Calling
- Two-Phase Inspect-Then-Commit Replay Protection
- Both the 0-RTT datagram engine and the fused 1-RTT frame pipeline inspect the sliding replay window before running ChaCha20-Poly1305 verification and commit the sequence/nonce state only after the 16-byte Poly1305 MAC authenticates. Forged packets cannot advance or poison the replay window, and in-place decryption wipes the buffer if a concurrent replay commit fails.
- Bounded
RLIMIT_MEMLOCKFootprint (EpochKeyManager)EpochKeyManagermaintains at most two active ML-KEM-512 epoch key slots (#currentand#previous), retiring#previousprior to allocating a replacement epoch so locked memory never exceeds 2 OS pages (8 KBonx86_64), while protecting in-flight 0-RTT decapsulations viaacquireEpoch()reference leases.
Wire Format (SPEC-LATTICE-WIRE-01 / 02)
0-RTT Datagram Layout (812-Byte Header AAD + Variable Payload + 16-Byte Tag)
+-----------------------------------------------------------------------+
| 0..3 MagicU32 (4B) : 0x4C573031 ("LW01") |
| 4..7 KeyEpochId (4B) : Big-Endian uint32 Epoch ID |
| 8..15 StreamId (8B) : Big-Endian uint64 Stream ID |
| 16..31 ClientDstKeyId (16B) : 128-bit Routing / Destination ID |
| 32..43 Nonce96 (12B) : 96-bit Packet Nonce / Base IV |
| 44..811 KemCiphertext (768B) : FIPS 203 ML-KEM-512 Ciphertext |
+-----------------------------------------------------------------------+
| 812..N Ciphertext (Var) : ChaCha20 Encrypted Payload |
| N..N+16 Poly1305Tag (16B) : 128-bit Authentication Tag |
+-----------------------------------------------------------------------+