The sanstun API surface, showing explicit handling of handshakes, timeouts, and packet encapsulation.
*Firezone unveils sanstun, a Rust‑based WireGuard state machine stripped of side‑effects. The design promises tighter security, easier testing, and parallel‑friendly performance.*
Firezone announced today the release of sanstun, a new WireGuard state‑machine written in Rust that follows a strict sans‑IO model. The library promises to replace the patched boringtun codebase that Firezone relied on for over two years. By stripping I/O and side‑effects from the core logic, sanstun aims to deliver a more secure, testable, and parallel‑friendly implementation that can be integrated into any language ecosystem. The move reflects a broader shift toward deterministic cryptographic primitives in modern networking stacks.
Sans-IO forces a clean split between I/O (network, file, time, randomness) and the core state machine. By removing side‑effects, components become composable, testable, and align with Rust's ownership model. The approach avoids function coloring and works in any language, not just Rust. For WireGuard, sans-IO means the cryptographic state can be driven deterministically, while the caller supplies timestamps and random values. This deterministic control is crucial for accurate simulations and for preventing hidden bugs that only appear under real‑world timing conditions.
Firezone built its first product on boringtun, but over two years they accumulated more than 70 PRs to patch bugs and add APIs. Maintaining 100% upstream compatibility grew untenable as product needs evolved. Boringtun’s internal buffering auto‑created sessions and required a zero‑length decapsulate call to drain buffers, adding unintuitive steps and extra allocations. sanstun removes all internal buffering, eliminating the need for looped API contracts and simplifying the interface. The new design also drops the legacy _at time‑handling APIs, replacing them with a fully sans-IO model that gives callers explicit control over timestamps.
The core sans-IO API groups functions by purpose. Inbound packets are handled via Tunnel::handle_handshake_initiation, ::handle_handshake_response, ::handle_cookie_reply, and the two‑step ::begin_decapsulate / ::commit_decapsulate. Outbound traffic uses Tunnel::begin_encapsulate, letting the caller buffer packets until a session exists. Timer updates are explicit with ::handle_timeout and ::poll_timeout, while ::poll_event surfaces asynchronous events. Initiating a new handshake is a single call to ::initiate_handshake. By exposing these granular, typed methods, the compiler enforces correct usage, preventing bugs such as missed rate‑limiting or misrouted packets.
WireGuard’s protocol relies on a Diffie‑Hellman exchange and a cookie mechanism to thwart DoS attacks. sanstun’s sans-IO time handling lets callers simulate exact timing, ensuring the cookie rate‑limit applies uniformly across an interface. The absence of internal buffering reduces allocation churn and eliminates hidden latency, improving throughput in parallel workloads. Strong typing guarantees that rate‑limiting logic cannot be omitted at compile time, closing a class of production‑only bugs. Overall, the design tightens the attack surface while delivering smoother performance on multi‑core systems.
sanstun is a sans-IO Rust implementation of the WireGuard® state machine, optimized for ease of use, security, performance, and parallel-friendly operation.
Firezone accumulated over 70 PRs to patch boringtun, struggled to keep 100% API compatibility, and found internal buffering unintuitive and allocation‑heavy, prompting a rewrite as sanstun.
sanstun provides Tunnel::handle_handshake_initiation, ::handle_handshake_response, ::handle_cookie_reply, ::begin_decapsulate, ::commit_decapsulate for inbound, Tunnel::begin_encapsulate for outbound, ::handle_timeout, ::poll_timeout for timers, ::poll_event for events, and ::initiate_handshake to start a session.
With sanstun, Firezone signals that the era of ad‑hoc patches to upstream WireGuard forks is ending. The library’s clean separation of concerns, explicit timing control, and type‑enforced invariants set a new benchmark for userspace VPN implementations. As more projects adopt sans‑IO patterns, the industry may see a wave of more reliable, secure networking code that scales effortlessly across cores and platforms.
Sources: Hacker News – Sanstun: A sans-IO, parallel-friendly WireGuard implementation in Rust (https://www.firezone.dev/blog/introducing-sanstun)