Technical Note: c-esp G. Corpas <- Portfolio github.com/gcpino/c-esp

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

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)