wireguard, one handshake per page
Twenty-eight lessons on what WireGuard is: a free and open-source protocol implementing encrypted VPNs over UDP, lighter than IPsec, better performing than OpenVPN; the law of one handshake per page; the overlay across a public net; long-term Curve25519 keys, ephemeral values, RFC 1918 addresses; the Noise IK pattern, the two-message ladder, the optional pre-shared key against quantum, the ChaCha20 session key with Poly1305; AEAD, the nonce, the byte toll, the MTU ladder of 1280, 1420 and 1440; UDP only and the TCP meltdown, port 51820, v4-in-v6, the roaming phone; the machine-checked proof, the IPsec and OpenVPN neighbors, the fixed menu; Donenfeld 2015, Linux 5.6 2020, one honest hour.
One handshake, one page, one honest run. That is the shape of this book.
wireguard, one handshake per page
Twenty-eight lessons on what WireGuard is: a free and open-source protocol implementing encrypted VPNs over UDP, lighter than IPsec, better performing than OpenVPN; the law of one handshake per page; the overlay across a public net; long-term Curve25519 keys, ephemeral values, RFC 1918 addresses; the Noise IK pattern, the two-message ladder, the optional pre-shared key against quantum, the ChaCha20 session key with Poly1305; AEAD, the nonce, the byte toll, the MTU ladder of 1280, 1420 and 1440; UDP only and the TCP meltdown, port 51820, v4-in-v6, the roaming phone; the machine-checked proof, the IPsec and OpenVPN neighbors, the fixed menu; Donenfeld 2015, Linux 5.6 2020, one honest hour.
Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).
An honest book about its demos: wg (wireguard-tools v1.0.20210914) ran on the machine that built this book for key generation ONLY, under umask 077: one wg genkey piped straight into wg pubkey (the private key went to the pipe and was never printed) and one wg genpsk; no interface was ever brought up by this machine and no networking was touched. Every quoted output line in these pages (the version banner and both key strings) was captured from those real runs, quoted verbatim from the captured run log. No wg output was invented. Every other fact is as the primary source states it, read during this build: the Wikipedia articles WireGuard, Virtual private network, Curve25519, ChaCha20-Poly1305, IPsec and OpenVPN, cached verbatim beside this book. No facts come from Reddit, Stack Overflow, vendor blogs or commercial sites. Every lesson that describes a practice exercise carries the label 'this book's plan', never posing as a captured fact. Independent, not affiliated with Jason A. Donenfeld, the WireGuard project or the Wikimedia Foundation.
Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.
© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.
Edition 1.0 · stevehodgkiss.net
Contents
Per a real local run captured at dispatch, wg --version printed wireguard-tools v1.0.20210914, and under umask 077 a wg genkey piped straight into wg pubkey printed the public key IecgtV/eRXjsn321JYto/QYafqlwsPw0fZvrzeNWOzY=; the private key went to the pipe and was never printed. Scope: key material generation only; no interface was created, no networking touched.
The first keys
Before anything else, the law: wireguard-tools v1.0.20210914 ran on this machine for key generation only, and no wg output was invented.
Two real lines from the run: umask 077 ; wg genkey | wg pubkey, which printed the public key IecgtV/eRXjsn321JYto/QYafqlwsPw0fZvrzeNWOzY=. The private half went to the pipe and was never printed. No interface was ever brought up.
A key pair in two commands: one secret kept, one public given away.
Why does umask 077 matter on the command that births a private key?
Per the Wikipedia Curve25519 article, the curve used is y2 = x3 + 486662*x2 + x, a Montgomery curve over the prime field defined by 2^255 - 19 (hence the numeric 25519 in the name), using the base point with x = 9; Bernstein has since proposed that the name Curve25519 be used for the underlying curve, and the name X25519 for the DH function; Curve25519 is constructed such that it avoids many potential implementation pitfalls.
The curve's math
The name is the prime: the curve is a Montgomery curve over the field defined by 2 to the power 255 minus 19, and its base point sits at x = 9. Per the article, Bernstein has since proposed the name Curve25519 be used for the underlying curve, and the name X25519 for the DH function.
The design aim: Curve25519 is constructed such that it avoids many potential implementation pitfalls.
Math chosen so ordinary implementations trip less often.
Why does a curve carry its own prime field in its name?
Per the Wikipedia WireGuard article, once the keys have been confirmed by both peers, the Noise Protocol is used to generate a shared ChaCha20 session key for symmetric encryption authenticated with Poly1305; SipHash24 is used for hashtable keys, while BLAKE2s is used as a cryptographic hash function.
The session key
Per the article, Once the keys have been confirmed by both peers, the Noise Protocol is used to generate a shared ChaCha20 session key for symmetric encryption authenticated with Poly1305.
Around it sit the helpers: SipHash24 is used for hashtable keys, while BLAKE2s is used as a cryptographic hash function.
The handshake's whole yield: one shared key, one hash, one fast table. Then the talking starts.
Why does the tunnel re-run the handshake instead of using one key forever?
Per the Wikipedia WireGuard article, assuming the underlay maintains a 1500 byte MTU, configuring the WireGuard interface to 1420 bytes MTU for all involved peers is ideal for being transported over IPv6 + IPv4; when exclusively utilizing legacy IPv4 transport, a higher MTU of 1440 bytes for the WireGuard interface suffices; for mobile clients with varying connectivity, an MTU of 1280 can be beneficial allowing for IPv6 transport inside the tunnel as that is its minimum allowed MTU.
The MTU ladder
Per the article, configuring the WireGuard interface to 1420 bytes MTU for all involved peers is ideal for being transported over IPv6 + IPv4, while a higher MTU of 1440 bytes for the WireGuard interface suffices on IPv4 only.
For phones that wander, an MTU of 1280 can be beneficial allowing for IPv6 transport inside the tunnel as that is its minimum allowed MTU.
1500 outside, minus the toll, sets the ceiling inside; the ladder has three honest rungs.
Why is 1280 the safe rung for a phone that changes networks all day?
Per the Wikipedia Virtual private network article, mobile virtual private networks are used in settings where an endpoint of the VPN is not fixed to a single IP address, but instead roams across various networks such as data networks from cellular carriers or between multiple Wi-Fi access points without dropping the secure VPN session; with IKE version 2 the tunnel can be seamlessly restored when the IP address of the associated host is changing, which is typical of a roaming mobile device; per the Wikipedia WireGuard article, WireGuard uses only UDP.
Roaming
Per the article, a mobile endpoint instead roams across various networks such as data networks from cellular carriers or between multiple Wi-Fi access points without dropping the secure VPN session.
With IKEv2, the tunnel can be seamlessly restored when the IP address of the associated host is changing, which is typical of a roaming mobile device.
Per this book's plan, the lesson is the carrier: a UDP walk needs no circuit to tear down.
What does a phone switch behind the scenes while its tunnel stays up?
Per the Wikipedia OpenVPN article, OpenVPN is a virtual private network system that implements techniques to create secure point-to-point or site-to-site connections in routed or bridged configurations; it uses the OpenSSL encryption library extensively, as well as the Transport Layer Security (TLS) protocol; it runs in userspace instead of requiring IP stack operation, and also supports Perfect Forward Secrecy (PFS).
The OpenVPN neighbor
Per the article, OpenVPN builds secure point-to-point or site-to-site connections in routed or bridged configurations and uses the OpenSSL encryption library extensively, as well as the TLS protocol.
It runs in userspace instead of requiring IP stack (therefore kernel) operation, and OpenVPN also supports Perfect Forward Secrecy (PFS).
A TLS veteran with a big cipher drawer, living outside the kernel.
What does living in userspace cost a tunnel the kernel could carry?
Per this book's plan, one honest hour of practice is: check wg --version, generate a key pair under umask 077 with wg genkey piped into wg pubkey and print nothing you would not share, run wg genpsk once, sketch both peers' public keys and tunnel addresses, name the five parts of the construction string, and set an MTU for a phone that roams.
One honest hour
Per this book's plan, one honest hour: check the banner with wg --version, then umask 077 ; wg genkey | wg pubkey and keep the private half off screen.
Run wg genpsk once, sketch two peers with public keys and tunnel addresses, name the five parts of the construction string, and pick an MTU for a roaming phone.
Six moves, one hour, every line traceable to a run you watched yourself.
Book the hour this week; which of the six moves will surprise you most?