Skip to content

Libertaria Wire Frame Protocol

LWF v3 — Encrypted by Default

The Libertaria Wire Frame (LWF) protocol is the wire format used by the Libertaria protocol stack – a separate project that converges with Nexus OS at the networking layer. LWF v3 encrypts all frames by default; cleartext is the exception, not the rule.

Overview

LWF provides a structured frame format for Libertaria's decentralized communication protocols. It operates alongside UTCP and TCP/IP on the same network:

EtherTypeProtocolPurpose
0x0800IPv4Legacy TCP/IP (LwIP)
0x86DDIPv6Dual-stack connectivity (LwIP)
0x88B5UTCPNexus sovereign transport
0x4C57LWFLibertaria protocol stack

LWF v3 Frame Format

LWF v3 (VERSION 0x03) introduces mandatory encryption and a full Ed25519 signature in the trailer. Total frame overhead is 156 bytes.

Header (88 bytes)

The header is transmitted in cleartext – routers can read routing hints but cannot tamper with the payload. The header serves as Additional Authenticated Data (AAD) for the encryption layer.

LWF v3 Header (88 bytes):

Offset  Field               Type      Size   Description
──────────────────────────────────────────────────────────────
0x00    version             u8        1      0x03 (LWF v3)
0x01    flags               u8        1      Frame flags (see below)
0x02    frame_type          u16       2      Protocol message type
0x04    src_cellid          [16]u8    16     Source CellID
0x14    dst_cellid          [16]u8    16     Destination CellID
0x24    src_hint            [8]u8     8      Source routing hint
0x2C    dst_hint            [8]u8     8      Destination routing hint
0x34    seq                 u32       4      Sequence number
0x38    payload_len         u32       4      Payload length (ciphertext)
0x3C    nonce               [24]u8    24     Encryption nonce
0x54    _reserved           [4]u8     4      Reserved (zero)
──────────────────────────────────────────────────────────────
        Total: 88 bytes

Payload (variable)

Encrypted by default. Raw bytes when CLEARTEXT flag is set.

Trailer (68 bytes)

LWF v3 Trailer (68 bytes):

Offset  Field               Type      Size   Description
──────────────────────────────────────────────────────────────
0x00    signature           [64]u8    64     Ed25519 signature over header + payload
0x40    crc32c              u32       4      CRC32-C of entire frame (header + payload + signature)
──────────────────────────────────────────────────────────────
        Total: 68 bytes

Total Overhead

Componentv2 Sizev3 Size
Header88 bytes88 bytes
Trailer36 bytes68 bytes
Total overhead124 bytes156 bytes

The 32-byte increase buys a full 64-byte Ed25519 signature (v2 used a truncated hash) and a CRC32-C integrity check. Non-negotiable for a protocol that encrypts by default.

Flag Semantics

BitFlagValueMeaning
0CLEARTEXT0x01Payload is NOT encrypted. The exception, not the rule.
1RELAY0x02Frame should be forwarded by intermediate nodes
2FRAGMENT0x04Frame is a fragment of a larger message
3PRIORITY0x08High-priority frame (scheduler hint)
4Reserved0x10Must be 0
5Reserved0x20Must be 0
6SESSION_CIPHER0x40Cipher mode select: 0 = Mode A (Noise XX), 1 = Mode B (XChaCha20-Poly1305)
7Reserved0x80Must be 0

Invalid Flag Combinations

CLEARTEXT + SESSION_CIPHER (0x01 | 0x40 = 0x41) is an invalid combination. If a frame arrives with both flags set, it must be rejected. Cleartext frames have no cipher to select. Receivers drop the frame and increment a counter; no NACK is sent (do not help an attacker probe flag logic).

Default State

When flags = 0x00: the frame is encrypted using Mode A (Noise XX). This is the default for all live session traffic. Cleartext must be explicitly opted into.

Dual Cipher Model

LWF v3 supports two encryption modes, selected by the SESSION_CIPHER flag.

Mode A — Noise XX (Default)

For live, interactive sessions between two nodes that have completed a Noise XX handshake.

Noise Protocol Name: Noise_XX_25519_ChaChaPoly_BLAKE2b

PropertyValue
ProtocolNoise_XX_25519_ChaChaPoly_BLAKE2b
DH FunctionX25519 (Curve25519 scalar multiplication)
CipherChaCha20-Poly1305 (AEAD)
Hash / KDFBLAKE2b (keyed BLAKE2b as HMAC-like KDF)
NonceSequential (8-byte LE counter, zero-padded to 12 bytes for AEAD)
Auth tag16 bytes (Poly1305, appended to ciphertext)
AADLWF header (88 bytes)
IdentityBLAKE3(remote_static) = peer key ID (QVL ecosystem standard)
LibraryMonocypher (freestanding C — no std, no heap)
Use caseLive sessions, real-time communication, UTCP tunneling

Crypto split: BLAKE2b is used for the Noise KDF (keyed hashing for key derivation during handshake). BLAKE3 is used for identity — QVL key IDs, content addressing, and trust binding. This split exists because Monocypher provides freestanding BLAKE2b with native keying (stronger than HMAC construction), while BLAKE3 is the Libertaria ecosystem standard hash for everything outside the Noise transport.

3-message handshake:

  1. -> e — Initiator sends ephemeral X25519 public key (32 bytes, cleartext)
  2. <- e, ee, s, es — Responder: ephemeral + 2 DH + encrypted static (32+48+payload bytes)
  3. -> s, se — Initiator: encrypted static + DH (48+payload bytes)

After message 3, both sides call split() to derive transport CipherStates (send + recv). The session is keyed by (session_id[16] + source_hint[8]) in the capsule's 8-slot session table with LRU eviction.

Mode A provides forward secrecy through the Noise XX handshake. Sequential nonces are efficient but require both peers to maintain state. If a peer restarts, the session must be re-established.

Mode B — XChaCha20-Poly1305

For store-and-forward, offline messages, and scenarios where the recipient may not be online.

PropertyValue
HandshakeNone – uses long-term keys or pre-shared keys
CipherXChaCha20-Poly1305
Nonce24-byte random (full nonce field in header)
Auth tag16 bytes (included in ciphertext)
Overhead40 bytes total (24-byte nonce + 16-byte tag)
AADLWF header (88 bytes)
Use caseStore-and-forward, mesh relay, offline messages

Mode B uses random nonces – no state required. A frame encrypted with Mode B can sit in a relay node's queue for hours or days and be decrypted when the recipient comes online. The 24-byte nonce provides a collision probability of ~2^-96 even at high message volumes.

Cipher Selection Logic

if flags & CLEARTEXT:
    # No encryption. Payload is raw.
    if flags & SESSION_CIPHER:
        REJECT  # Invalid combination
    # Signature still required in trailer.

elif flags & SESSION_CIPHER:
    # Mode B: XChaCha20-Poly1305
    # nonce = random 24 bytes (full header nonce field)
    # encrypt(key, nonce, plaintext, aad=header)

else:
    # Mode A: Noise XX / ChaCha20-Poly1305 (DEFAULT)
    # nonce = sequential counter (8 bytes, zero-padded in header)
    # encrypt(session_key, nonce, plaintext, aad=header)

Integration with Rumpk

LWF v3 integration follows the principle: crypto runs in the membrane; the kernel does routing only.

Kernel Layer (NetSwitch + LWF Adapter)

  • The NetSwitch routes frames with EtherType 0x4C57 to the LWF handler fiber
  • The LWF adapter parses the 88-byte header in-place (zero-copy)
  • Routing decisions use dst_cellid, dst_hint, and the RELAY flag
  • The kernel never decrypts payloads – it reads cleartext hints and forwards
  • RELAY_FORWARD frames are re-queued to the VirtIO TX ring with updated hop hints

Membrane Layer (Capsule NPL)

  • Decryption happens in the Capsule's address space (userland)
  • Noise XX session state is per-connection, managed by the Capsule
  • Ed25519 signature verification before decryption (reject tampered frames early)
  • CRC32-C check on receive (reject corrupted frames before any crypto)

Syscalls

SyscallNumberPurpose
SYS_LWF_RECV0x700Receive an LWF frame via ION copy
SYS_LWF_SEND0x701Send an LWF frame via ION copy

CSpace Capabilities

CapabilitySlotPermission
LWF_RX0x600READ
LWF_TX0x601WRITE

Pledge

LWF operations require the PLEDGE_INET bit. A process without PLEDGE_INET cannot send or receive LWF frames.

Capsule Integration

The Capsule NPL (the Libertaria stack's Nexus-native process) uses LWF for all its network communication:

  1. Capsule receives LWF frames via SYS_LWF_RECV
  2. Verifies CRC32-C, then Ed25519 signature
  3. Decrypts payload (Mode A or Mode B based on flags)
  4. Parses the LWF payload (protocol-specific messages)
  5. Sends responses via SYS_LWF_SEND (encrypts, signs, computes CRC)
  6. Runs an event loop with heartbeat: recv → verify → decrypt → parse → respond → yield

The Capsule has been verified stable for 30+ seconds of continuous operation with zero faults.

Implementation

The Libertaria stack is implemented in ~15,000 lines of Zig across 24 test suites. It is maintained as a separate project and converges with Nexus OS when the Capsule runs as an NPL payload inside Rumpk.