Wire Format Reference
Wire Format Reference
Detailed 48-byte header offsets
KSP packets utilize a strict binary representation. The 48-byte header is structured as follows, followed immediately by the encrypted payload (if any) and a 16-byte authentication tag:
Offset Size (B) Field Name Description ------------------------------------------------------------------ 0 4 Magic Number Magic bytes "KSP1" (0x4B535031) 4 1 Packet Type Routing flag (0x01 - 0xFF) 5 2 Flags Flags bitfield (COMPRESSED, etc.) 7 4 Payload Length Size of encrypted payload 11 16 Session ID Unique UUID v4 session token 27 4 Stream ID Logical channel number (0 - 256) 31 8 Sequence Number Monotonically increasing sequence 39 12 Nonce / IV XORed initialization vector
Field Details
- Magic Number: All KSP readers discard frames immediately if the first 4 bytes do not match
0x4B535031. - Sequence Number: Must begin at 1 for both endpoints and increment by 1 for every packet. It prevents replay attacks and provides the basis for nonce generation.
- Flags Bitfield: Bit 0 indicates Zstd compression. Bit 1 indicates AEAD encryption is active. Bit 2 signals stream teardown.