{"article":{"slug":"introducing-sanstun-a-sans-io-parallel-friendly-userspace-wireguard-implementation-in-rust","title":"Introducing sanstun: A sans-IO, parallel-friendly, userspace WireGuard implementation in Rust","subtitle":null,"summary":"Firezone's Thomas Eizinger announces sanstun, an open-source Rust implementation of the WireGuard state machine that separates IO from protocol logic, and explains its sans-IO design, how its API lets encryption and decryption run in parallel while the interface stays single-threaded, and why it replaces Firezone's boringtun fork.","content_type":"announcement","language":"en","canonical_url":"https://www.firezone.dev/blog/introducing-sanstun","author":{"name":"Thomas Eizinger","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Firezone","url":"https://www.firezone.dev/","listing_slug":"firezone","listing":{"slug":"firezone","name":"Firezone","listing_type":"company","url":"https://listedstartups.com/companies/firezone"}},"topics":[{"name":"rust","slug":"rust","url":"https://listedarticles.com/topics/rust"},{"name":"networking","slug":"networking","url":"https://listedarticles.com/topics/networking"},{"name":"open-source","slug":"open-source","url":"https://listedarticles.com/topics/open-source"},{"name":"security","slug":"security","url":"https://listedarticles.com/topics/security"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":1848,"reading_minutes":8,"published_at":"2026-10-31T00:00:00.000Z","added_at":"2026-10-30T23:14:53.261Z","updated_at":"2026-10-30T23:14:53.261Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/introducing-sanstun-a-sans-io-parallel-friendly-userspace-wireguard-implementation-in-rust","markdown_url":"https://listedarticles.com/articles/introducing-sanstun-a-sans-io-parallel-friendly-userspace-wireguard-implementation-in-rust.md","example":false,"citation":"Thomas Eizinger, Firezone. \"Introducing sanstun: A sans-IO, parallel-friendly, userspace WireGuard implementation in Rust.\" 31 Oct 2026. https://www.firezone.dev/blog/introducing-sanstun (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://www.firezone.dev/blog/introducing-sanstun"},"body_markdown":"Today, we are announcing [`sanstun`](https://github.com/firezone/sanstun): a sans-IO Rust implementation of the WireGuard® state machine, optimized for ease of use, security and performance through a parallel-friendly and idiomatic API.\n\n## [What is sans-IO?](#what-is-sans-io)\n\nsans-IO is the idea that you design your system such that IO and side-effects are cleanly separated from the state and \"business logic\".\nThe IO in sans-IO doesn't just mean file or network IO.\nIt also includes things like time and randomness!\n\nDue to their lack of side-effects, sans-IO components compose very well and are relatively easy to test.\nThe design also avoids problems like function coloring and plays well with Rust's ownership rules.\n\nThe code examples and references in this post are in Rust but sans-IO isn't Rust-specific at all.\nIts patterns and ideas can be applied in any language.\nFor a more in-depth explanation, our [sans-IO post](https://www.firezone.dev/blog/sans-io) is a good place to start.\n\n## [History](#history)\n\nWhen we first built Firezone, we reached for [`boringtun`](https://github.com/cloudflare/boringtun) as our WireGuard implementation.\n`boringtun` more or less did what we wanted, but over time, we found ourselves patching our fork over and over with bug fixes as well as API additions.\nThe goal was to allow these patches to still be upstreamed, so we always kept the existing API working the way it was.\n\nWhat we found was that retaining 100% API compatibility with upstream was increasingly difficult as our product requirements evolved.\nOne of the first big changes we made to `boringtun` was to make it fully sans-IO with regard to time handling ([firezone/boringtun#5](https://github.com/firezone/boringtun/pull/5)).\nThis meant adding new APIs for everything with a `_at` suffix that would take an `Instant`.\nsans-IO time handling is very important if you want to accurately simulate an entire system.\nSee [this blog post](https://www.firezone.dev/blog/finding-bugs-you-didnt-think-to-test-for) to learn more about how we do that.\n\nAnother thing we feature-flagged was internal buffering.\nAt first, it seems convenient that `boringtun` establishes a session automatically if you don't have one yet (or anymore) and you are trying to send a packet.\nInternal buffering, however, comes with several problems:\n\n1. At some point, the buffer needs to be drained.\n   `boringtun` solves this by requiring you to call `decapsulate` with a zero-length datagram.\n   Rather unintuitive.\n2. It incurs additional allocations (at least in the way it was implemented in `boringtun`).\n3. Buffer sizes should be configurable / tunable.\n\nAll of these problems point at the same solution: Just don't buffer in the library.\nIt simplifies the interface and the implementation on both sides.\n\nThe [full list](https://github.com/cloudflare/boringtun/compare/master...firezone:boringtun:master) of patches and fixes is pretty long.\nEven excluding dependency bumps, that is more than 70 PRs.\nSeveral of them are fixes for edge-cases we discovered.\nOthers add new APIs or make certain aspects configurable.\n\nAfter more than 2 years of using and patching `boringtun`, we had a pretty good idea of what the overall API of a userspace WireGuard implementation should be.\nNow it exists as `sanstun`.\n\n## [A better sans-IO API](#a-better-sans-io-api)\n\nThe core building blocks of the sans-IO API are now:\n\n- Handling inbound packets:\n  - `Tunnel::handle_handshake_initiation`\n  - `Tunnel::handle_handshake_response`\n  - `Tunnel::handle_cookie_reply`\n  - `Tunnel::begin_decapsulate` & `Tunnel::commit_decapsulate`\n- Handling outbound packets: `Tunnel::begin_encapsulate`\n- Handling timer updates: `Tunnel::handle_timeout` & `Tunnel::poll_timeout`\n- Handling events: `Tunnel::poll_event`\n\nWithout internal buffering, there is no API contract that requires you to call certain APIs in a loop, which fits much better into the overall sans-IO model.\nTo send a packet, you call `Tunnel::begin_encapsulate`.\nIt is up to you to buffer the packet if you don't have a session yet.\nCreating a new session means sending a handshake.\nYou can initiate a new handshake at any point with `Tunnel::initiate_handshake`.\n\nThe design of these APIs is very deliberate and will make more sense if we quickly recap the WireGuard protocol.\n\n## [WireGuard protocol](#wireguard-protocol)\n\nWireGuard's message format supports 4 types of messages: handshake init, handshake response, cookie reply and encrypted data.\n\nEvery WireGuard session starts with a Diffie-Hellman key exchange which is a moderately expensive operation.\nWireGuard's design ensures that exposing an endpoint doesn't open up a DoS opportunity.\n\nAnyone who knows the endpoint's public key can easily create bogus handshake initiations and forge the source IP of the incoming UDP packet.\nThe receiving WireGuard implementation has to run its half of the DH operations before it can tell that the supplied handshake data is bogus.\nBut at that point, the CPU resources have already been spent.\nSend enough handshake initiations and the receiving end will spend all its CPU cycles on handling irrelevant handshakes.\n\nTo prevent this, WireGuard specifies a cookie mechanism that forces the remote to prove ownership of its claimed source IP, which in turn allows rate-limiting handshakes per source IP.\n\nThese rate limits apply to an entire WireGuard interface and not just to a single tunnel.\n\nOnce a handshake has been completed, both peers can exchange encrypted data packets with a symmetric cipher.\nAs part of the handshake, the peers also exchange their locally-chosen session indices.\nThese indices enable de-multiplexing of tunnels as well as multiple sessions within a tunnel.\n\n## [Mapping protocol invariants to API design](#mapping-protocol-invariants-to-api-design)\n\nIf you are working in a language like Rust, chances are you enjoy using types.\nAnd using types well means enforcing invariants at compile-time such that you can't even ship a certain bug in the first place.\nFor example, forgetting to apply the rate limiter to a message would be pretty bad because it doesn't show up under normal operation.\nSimilarly, routing an incoming packet to the wrong tunnel is something that will only show up in production.\n\nA good API design makes it impossible to build things that are broken and also guides you along in understanding how the protocol works.\n\n## [One interface, many tunnels](#one-interface-many-tunnels)\n\nA WireGuard interface is identified by a single key and a tunnel is a connection between two interfaces.\nAny time we want to send a packet, we therefore need to specify which tunnel it should be sent on and when we receive a packet, we need to figure out which tunnel it belongs to.\n\nIn `sanstun`, these concepts directly map to the `Interface` and `Tunnel` types.\nAll inbound packets go through `Interface::receive`.\nThat is the only public API that parses a raw datagram.\nIt parses the packet, applies rate limits and hands you back a `ReceivedMessage` with one enum variant per WireGuard message type, or a cookie reply to send back if the interface is under load.\nThese then map directly to the corresponding functions on a `Tunnel`: `Tunnel::handle_handshake_initiation`, etc.\nHandshake initiations are routed by the initiator's static public key.\nAll other messages expose *which* `Tunnel` they should be dispatched to, identified by a `TunnelId`.\n\nEvery inbound datagram has to go through `Interface::receive`.\n\nUnder the hood, `sanstun` does a lot of things for you here.\nIt parses the tunnel index and extracts the upper 24 bits, it applies rate limits, generates cookie replies and validates handshake messages.\n\nCrucially, the constructors for types like `HandshakeInitiation` are all crate-private.\nEven though `Tunnel` exposes a public `handle_handshake_initiation` function, the only way to call that is by going through `Interface::receive` first to obtain such a type.\nAnd `Interface::receive` protects your application by applying the rate limiter, all without you having to think about it.\n\n## [Parallel crypto](#parallel-crypto)\n\nOne of the best features of `sanstun` is its parallel-friendly API for encrypting and decrypting packets.\n\nOn a protocol level, WireGuard doesn't share any state between tunnels.\nTherefore, parallelizing a WireGuard implementation across peers is very easy.\n\nBut what about parallelizing work within a single tunnel?\nWireGuard operates on layer 3, and thus a single session with another peer carries the traffic of many individual network flows.\nEven if we handle tunnels to different peers on different threads, all network flows (i.e., unique 5-tuples) toward the same host or subnet will be processed sequentially, effectively bounded by how fast the CPU is at ChaCha20-Poly1305, WireGuard's cipher for data packets.\nTo protect against replay by malicious on-path observers, WireGuard data packets have a monotonically increasing packet counter.\nThis counter is scoped to a single session and therefore would require synchronization if we were to access this state from multiple threads simultaneously.\n\nTo avoid this, `sanstun` separates the bookkeeping from the actual encryption and decryption.\nCalling `Tunnel::begin_encapsulate` doesn't in fact encrypt anything.\nIt checks for the current session, reserves a packet counter, advances timer state and then hands you a `PendingEncapsulate`:\n\n```\nimpl PendingEncapsulate {\n    pub fn encrypt<'a>(self, plaintext: &[u8], dst: &'a mut [u8]) -> Result<DataMessage<'a>, Error> {\n        // ...\n    }\n}\n```\n\n`PendingEncapsulate` implements `Send` and can thus be transferred to another thread to perform the bulk of the work.\nRunning `cargo bench data_path` in the `sanstun` repository showcases the effect of this split:\n\n```\ndata_path/64B/begin_encapsulate\n                        time:   [20.785 ns 20.828 ns 20.869 ns]\ndata_path/64B/encrypt   time:   [226.15 ns 226.22 ns 226.29 ns]\ndata_path/64B/begin_decapsulate\n                        time:   [37.600 ns 37.675 ns 37.744 ns]\ndata_path/64B/decrypt   time:   [205.78 ns 205.83 ns 205.87 ns]\ndata_path/64B/commit_decapsulate\n                        time:   [17.486 ns 17.529 ns 17.575 ns]\n\ndata_path/1280B/begin_encapsulate\n                        time:   [20.785 ns 20.828 ns 20.869 ns]\ndata_path/1280B/encrypt time:   [933.49 ns 933.54 ns 933.59 ns]\ndata_path/1280B/begin_decapsulate\n                        time:   [37.606 ns 37.681 ns 37.751 ns]\ndata_path/1280B/decrypt time:   [914.81 ns 914.89 ns 914.97 ns]\ndata_path/1280B/commit_decapsulate\n                        time:   [17.657 ns 17.707 ns 17.764 ns]\n```\n\nAs expected, the bookkeeping parts (`begin_encapsulate`, `begin_decapsulate` and `commit_decapsulate`) do not scale with packet size.\nWhat does scale with packet size are the `encrypt` and `decrypt` functions.\nAt a packet size of 1280 bytes, the bookkeeping part of encrypting a new packet is only 2%.\nIf we move the actual encryption to another thread, this hints at a potential speedup of more than 45x!\n\nAn effective speedup of 45x is hard to achieve in practice because it ignores the cost of passing `PendingEncapsulate` to another thread and assumes no other overhead is introduced.\nNevertheless, being able to offload the crypto to worker threads allows for some great throughput improvements.\n\nThe owner thread only does the bookkeeping, while encryption and decryption run on worker threads.\n\nBeing a sans-IO library, `sanstun` doesn't concern itself with how exactly you want to parallelize your crypto.\nIf you want to keep it simple, you can also just call `encrypt` and `decrypt` inline and not bother with parallelization at all.\n\nThe key thing we wanted to achieve with `sanstun`'s API design was to enable parallel crypto while keeping everything around `Interface` single-threaded.\nThis lets the internal rate limiter work without locks or atomic counters and take advantage of Rust's borrow checker, all while combining state from multiple tunnels.\n\n## [Closing](#closing)\n\nWith `sanstun`, our fork at [`firezone/boringtun`](https://github.com/firezone/boringtun) is now deprecated.\nIf you are building on top of WireGuard, whether that's a VPN, a mesh network or something else entirely, we hope `sanstun` makes your life a little easier.\nIt is available on [crates.io](https://crates.io/crates/sanstun).\n\n`sanstun` is open source under the Apache 2.0 license.\nCheck it out on [GitHub](https://github.com/firezone/sanstun); issues and pull requests are welcome!\n","body_html":"<p>Today, we are announcing <a href=\"https://github.com/firezone/sanstun\" rel=\"nofollow ugc noopener\"><code>sanstun</code></a>: a sans-IO Rust implementation of the WireGuard® state machine, optimized for ease of use, security and performance through a parallel-friendly and idiomatic API.</p>\n<h2 id=\"what-is-sans-io\"><a href=\"#what-is-sans-io\">What is sans-IO?</a></h2>\n<p>sans-IO is the idea that you design your system such that IO and side-effects are cleanly separated from the state and &quot;business logic&quot;.\nThe IO in sans-IO doesn&#39;t just mean file or network IO.\nIt also includes things like time and randomness!</p>\n<p>Due to their lack of side-effects, sans-IO components compose very well and are relatively easy to test.\nThe design also avoids problems like function coloring and plays well with Rust&#39;s ownership rules.</p>\n<p>The code examples and references in this post are in Rust but sans-IO isn&#39;t Rust-specific at all.\nIts patterns and ideas can be applied in any language.\nFor a more in-depth explanation, our <a href=\"https://www.firezone.dev/blog/sans-io\" rel=\"nofollow ugc noopener\">sans-IO post</a> is a good place to start.</p>\n<h2 id=\"history\"><a href=\"#history\">History</a></h2>\n<p>When we first built Firezone, we reached for <a href=\"https://github.com/cloudflare/boringtun\" rel=\"nofollow ugc noopener\"><code>boringtun</code></a> as our WireGuard implementation.\n<code>boringtun</code> more or less did what we wanted, but over time, we found ourselves patching our fork over and over with bug fixes as well as API additions.\nThe goal was to allow these patches to still be upstreamed, so we always kept the existing API working the way it was.</p>\n<p>What we found was that retaining 100% API compatibility with upstream was increasingly difficult as our product requirements evolved.\nOne of the first big changes we made to <code>boringtun</code> was to make it fully sans-IO with regard to time handling (<a href=\"https://github.com/firezone/boringtun/pull/5\" rel=\"nofollow ugc noopener\">firezone/boringtun#5</a>).\nThis meant adding new APIs for everything with a <code>_at</code> suffix that would take an <code>Instant</code>.\nsans-IO time handling is very important if you want to accurately simulate an entire system.\nSee <a href=\"https://www.firezone.dev/blog/finding-bugs-you-didnt-think-to-test-for\" rel=\"nofollow ugc noopener\">this blog post</a> to learn more about how we do that.</p>\n<p>Another thing we feature-flagged was internal buffering.\nAt first, it seems convenient that <code>boringtun</code> establishes a session automatically if you don&#39;t have one yet (or anymore) and you are trying to send a packet.\nInternal buffering, however, comes with several problems:</p>\n<ol><li><p>At some point, the buffer needs to be drained.</p><p> <code>boringtun</code> solves this by requiring you to call <code>decapsulate</code> with a zero-length datagram.\n Rather unintuitive.</p></li><li>It incurs additional allocations (at least in the way it was implemented in <code>boringtun</code>).</li><li>Buffer sizes should be configurable / tunable.</li></ol>\n<p>All of these problems point at the same solution: Just don&#39;t buffer in the library.\nIt simplifies the interface and the implementation on both sides.</p>\n<p>The <a href=\"https://github.com/cloudflare/boringtun/compare/master...firezone:boringtun:master\" rel=\"nofollow ugc noopener\">full list</a> of patches and fixes is pretty long.\nEven excluding dependency bumps, that is more than 70 PRs.\nSeveral of them are fixes for edge-cases we discovered.\nOthers add new APIs or make certain aspects configurable.</p>\n<p>After more than 2 years of using and patching <code>boringtun</code>, we had a pretty good idea of what the overall API of a userspace WireGuard implementation should be.\nNow it exists as <code>sanstun</code>.</p>\n<h2 id=\"a-better-sans-io-api\"><a href=\"#a-better-sans-io-api\">A better sans-IO API</a></h2>\n<p>The core building blocks of the sans-IO API are now:</p>\n<ul><li>Handling inbound packets:<ul><li><code>Tunnel::handle_handshake_initiation</code></li><li><code>Tunnel::handle_handshake_response</code></li><li><code>Tunnel::handle_cookie_reply</code></li><li><code>Tunnel::begin_decapsulate</code> &amp; <code>Tunnel::commit_decapsulate</code></li></ul></li><li>Handling outbound packets: <code>Tunnel::begin_encapsulate</code></li><li>Handling timer updates: <code>Tunnel::handle_timeout</code> &amp; <code>Tunnel::poll_timeout</code></li><li>Handling events: <code>Tunnel::poll_event</code></li></ul>\n<p>Without internal buffering, there is no API contract that requires you to call certain APIs in a loop, which fits much better into the overall sans-IO model.\nTo send a packet, you call <code>Tunnel::begin_encapsulate</code>.\nIt is up to you to buffer the packet if you don&#39;t have a session yet.\nCreating a new session means sending a handshake.\nYou can initiate a new handshake at any point with <code>Tunnel::initiate_handshake</code>.</p>\n<p>The design of these APIs is very deliberate and will make more sense if we quickly recap the WireGuard protocol.</p>\n<h2 id=\"wireguard-protocol\"><a href=\"#wireguard-protocol\">WireGuard protocol</a></h2>\n<p>WireGuard&#39;s message format supports 4 types of messages: handshake init, handshake response, cookie reply and encrypted data.</p>\n<p>Every WireGuard session starts with a Diffie-Hellman key exchange which is a moderately expensive operation.\nWireGuard&#39;s design ensures that exposing an endpoint doesn&#39;t open up a DoS opportunity.</p>\n<p>Anyone who knows the endpoint&#39;s public key can easily create bogus handshake initiations and forge the source IP of the incoming UDP packet.\nThe receiving WireGuard implementation has to run its half of the DH operations before it can tell that the supplied handshake data is bogus.\nBut at that point, the CPU resources have already been spent.\nSend enough handshake initiations and the receiving end will spend all its CPU cycles on handling irrelevant handshakes.</p>\n<p>To prevent this, WireGuard specifies a cookie mechanism that forces the remote to prove ownership of its claimed source IP, which in turn allows rate-limiting handshakes per source IP.</p>\n<p>These rate limits apply to an entire WireGuard interface and not just to a single tunnel.</p>\n<p>Once a handshake has been completed, both peers can exchange encrypted data packets with a symmetric cipher.\nAs part of the handshake, the peers also exchange their locally-chosen session indices.\nThese indices enable de-multiplexing of tunnels as well as multiple sessions within a tunnel.</p>\n<h2 id=\"mapping-protocol-invariants-to-api-design\"><a href=\"#mapping-protocol-invariants-to-api-design\">Mapping protocol invariants to API design</a></h2>\n<p>If you are working in a language like Rust, chances are you enjoy using types.\nAnd using types well means enforcing invariants at compile-time such that you can&#39;t even ship a certain bug in the first place.\nFor example, forgetting to apply the rate limiter to a message would be pretty bad because it doesn&#39;t show up under normal operation.\nSimilarly, routing an incoming packet to the wrong tunnel is something that will only show up in production.</p>\n<p>A good API design makes it impossible to build things that are broken and also guides you along in understanding how the protocol works.</p>\n<h2 id=\"one-interface-many-tunnels\"><a href=\"#one-interface-many-tunnels\">One interface, many tunnels</a></h2>\n<p>A WireGuard interface is identified by a single key and a tunnel is a connection between two interfaces.\nAny time we want to send a packet, we therefore need to specify which tunnel it should be sent on and when we receive a packet, we need to figure out which tunnel it belongs to.</p>\n<p>In <code>sanstun</code>, these concepts directly map to the <code>Interface</code> and <code>Tunnel</code> types.\nAll inbound packets go through <code>Interface::receive</code>.\nThat is the only public API that parses a raw datagram.\nIt parses the packet, applies rate limits and hands you back a <code>ReceivedMessage</code> with one enum variant per WireGuard message type, or a cookie reply to send back if the interface is under load.\nThese then map directly to the corresponding functions on a <code>Tunnel</code>: <code>Tunnel::handle_handshake_initiation</code>, etc.\nHandshake initiations are routed by the initiator&#39;s static public key.\nAll other messages expose <em>which</em> <code>Tunnel</code> they should be dispatched to, identified by a <code>TunnelId</code>.</p>\n<p>Every inbound datagram has to go through <code>Interface::receive</code>.</p>\n<p>Under the hood, <code>sanstun</code> does a lot of things for you here.\nIt parses the tunnel index and extracts the upper 24 bits, it applies rate limits, generates cookie replies and validates handshake messages.</p>\n<p>Crucially, the constructors for types like <code>HandshakeInitiation</code> are all crate-private.\nEven though <code>Tunnel</code> exposes a public <code>handle_handshake_initiation</code> function, the only way to call that is by going through <code>Interface::receive</code> first to obtain such a type.\nAnd <code>Interface::receive</code> protects your application by applying the rate limiter, all without you having to think about it.</p>\n<h2 id=\"parallel-crypto\"><a href=\"#parallel-crypto\">Parallel crypto</a></h2>\n<p>One of the best features of <code>sanstun</code> is its parallel-friendly API for encrypting and decrypting packets.</p>\n<p>On a protocol level, WireGuard doesn&#39;t share any state between tunnels.\nTherefore, parallelizing a WireGuard implementation across peers is very easy.</p>\n<p>But what about parallelizing work within a single tunnel?\nWireGuard operates on layer 3, and thus a single session with another peer carries the traffic of many individual network flows.\nEven if we handle tunnels to different peers on different threads, all network flows (i.e., unique 5-tuples) toward the same host or subnet will be processed sequentially, effectively bounded by how fast the CPU is at ChaCha20-Poly1305, WireGuard&#39;s cipher for data packets.\nTo protect against replay by malicious on-path observers, WireGuard data packets have a monotonically increasing packet counter.\nThis counter is scoped to a single session and therefore would require synchronization if we were to access this state from multiple threads simultaneously.</p>\n<p>To avoid this, <code>sanstun</code> separates the bookkeeping from the actual encryption and decryption.\nCalling <code>Tunnel::begin_encapsulate</code> doesn&#39;t in fact encrypt anything.\nIt checks for the current session, reserves a packet counter, advances timer state and then hands you a <code>PendingEncapsulate</code>:</p>\n<pre><code>impl PendingEncapsulate {\n    pub fn encrypt&lt;&#39;a&gt;(self, plaintext: &amp;[u8], dst: &amp;&#39;a mut [u8]) -&gt; Result&lt;DataMessage&lt;&#39;a&gt;, Error&gt; {\n        // ...\n    }\n}</code></pre>\n<p><code>PendingEncapsulate</code> implements <code>Send</code> and can thus be transferred to another thread to perform the bulk of the work.\nRunning <code>cargo bench data_path</code> in the <code>sanstun</code> repository showcases the effect of this split:</p>\n<pre><code>data_path/64B/begin_encapsulate\n                        time:   [20.785 ns 20.828 ns 20.869 ns]\ndata_path/64B/encrypt   time:   [226.15 ns 226.22 ns 226.29 ns]\ndata_path/64B/begin_decapsulate\n                        time:   [37.600 ns 37.675 ns 37.744 ns]\ndata_path/64B/decrypt   time:   [205.78 ns 205.83 ns 205.87 ns]\ndata_path/64B/commit_decapsulate\n                        time:   [17.486 ns 17.529 ns 17.575 ns]\n\ndata_path/1280B/begin_encapsulate\n                        time:   [20.785 ns 20.828 ns 20.869 ns]\ndata_path/1280B/encrypt time:   [933.49 ns 933.54 ns 933.59 ns]\ndata_path/1280B/begin_decapsulate\n                        time:   [37.606 ns 37.681 ns 37.751 ns]\ndata_path/1280B/decrypt time:   [914.81 ns 914.89 ns 914.97 ns]\ndata_path/1280B/commit_decapsulate\n                        time:   [17.657 ns 17.707 ns 17.764 ns]</code></pre>\n<p>As expected, the bookkeeping parts (<code>begin_encapsulate</code>, <code>begin_decapsulate</code> and <code>commit_decapsulate</code>) do not scale with packet size.\nWhat does scale with packet size are the <code>encrypt</code> and <code>decrypt</code> functions.\nAt a packet size of 1280 bytes, the bookkeeping part of encrypting a new packet is only 2%.\nIf we move the actual encryption to another thread, this hints at a potential speedup of more than 45x!</p>\n<p>An effective speedup of 45x is hard to achieve in practice because it ignores the cost of passing <code>PendingEncapsulate</code> to another thread and assumes no other overhead is introduced.\nNevertheless, being able to offload the crypto to worker threads allows for some great throughput improvements.</p>\n<p>The owner thread only does the bookkeeping, while encryption and decryption run on worker threads.</p>\n<p>Being a sans-IO library, <code>sanstun</code> doesn&#39;t concern itself with how exactly you want to parallelize your crypto.\nIf you want to keep it simple, you can also just call <code>encrypt</code> and <code>decrypt</code> inline and not bother with parallelization at all.</p>\n<p>The key thing we wanted to achieve with <code>sanstun</code>&#39;s API design was to enable parallel crypto while keeping everything around <code>Interface</code> single-threaded.\nThis lets the internal rate limiter work without locks or atomic counters and take advantage of Rust&#39;s borrow checker, all while combining state from multiple tunnels.</p>\n<h2 id=\"closing\"><a href=\"#closing\">Closing</a></h2>\n<p>With <code>sanstun</code>, our fork at <a href=\"https://github.com/firezone/boringtun\" rel=\"nofollow ugc noopener\"><code>firezone/boringtun</code></a> is now deprecated.\nIf you are building on top of WireGuard, whether that&#39;s a VPN, a mesh network or something else entirely, we hope <code>sanstun</code> makes your life a little easier.\nIt is available on <a href=\"https://crates.io/crates/sanstun\" rel=\"nofollow ugc noopener\">crates.io</a>.</p>\n<p><code>sanstun</code> is open source under the Apache 2.0 license.\nCheck it out on <a href=\"https://github.com/firezone/sanstun\" rel=\"nofollow ugc noopener\">GitHub</a>; issues and pull requests are welcome!</p>","headings":[{"level":2,"text":"What is sans-IO?","id":"what-is-sans-io"},{"level":2,"text":"History","id":"history"},{"level":2,"text":"A better sans-IO API","id":"a-better-sans-io-api"},{"level":2,"text":"WireGuard protocol","id":"wireguard-protocol"},{"level":2,"text":"Mapping protocol invariants to API design","id":"mapping-protocol-invariants-to-api-design"},{"level":2,"text":"One interface, many tunnels","id":"one-interface-many-tunnels"},{"level":2,"text":"Parallel crypto","id":"parallel-crypto"},{"level":2,"text":"Closing","id":"closing"}]}}