c-esp — Zero-Allocation IPsec ESP Data-Plane Engine
Abstract
Freestanding C11 IPsec ESP data-plane engine. Encrypts and authenticates packets in place with no OS, socket, or heap dependencies.
1. Packet Flow¶
TX: [16B headroom | Payload | 34B tail]
-> 5-tuple SPD policy lookup (RFC 4301)
-> In-place AEAD (ChaCha20-Poly1305 or AES-256-GCM)
-> Wire: SPI(4) | Seq(4) | IV(8) | Ciphertext | Pad | ICV(16)
RX: Wire frame
-> SA lookup in rx_sa_ring[4] (make-before-break rollover)
-> Phase 1: read-only 1024-bit anti-replay precheck
-> Phase 2: constant-time ICV verify & decrypt -> commit bitmap
2. Design Notes¶
-
Caller-owned memory: all state lives in a 1,944 B
esp_context_tand a 516 Besp_spd_t. Zero calls tomallocorfree. - Two-phase anti-replay: sequence numbers are checked against a 1024-bit RFC 6479 bitmap (with 64-bit ESN) before decryption; the window advances only after AEAD authentication succeeds.
- Constant-time crypto: both ChaCha20-Poly1305 and table-free AES-256-GCM avoid secret-dependent branches and table lookups, with branchless padding checks and hardened key zeroing.
3. Verification¶
- Throughput
- 6.81 cycles/byte at 1400 B MTU (ChaCha20-Poly1305)
- Vectors
- RFC 8439, RFC 7634 Appendix A, NIST AES-256-GCM
- Timing
- dudect |t| ≤ 1.95 (threshold 4.5); ctgrind 0 secret branches
- Reordering
- 0.04% drop at sigma = 128 jitter (vs 68.5% with 64-bit window)