Meet Modi
Back to Blog
·11 min

WireGuard's post-quantum answer is a slot it always had

WireGuard is not post-quantum by default. A 32-byte preshared key fixes that today. I set one by hand, from ML-KEM and with Rosenpass. Each fails quietly.

By Meet Modi
WireGuardPost-quantum cryptographyNetworkingSecurity

The interesting part of Jason Donenfeld's mailing list post is not the WireGuard v2 bit everyone quoted. It is that his advice for today needs no new software. WireGuard has carried a 256-bit preshared key slot since the start, the wg man page says it is there "for post-quantum resistance", and a config without one quietly uses 32 zero bytes.

So, is WireGuard post-quantum? Not by default. Its handshake rests on Curve25519, which a large enough quantum computer breaks. Put a secret into the preshared key slot that an attacker cannot get, and the session keys also depend on that secret, so breaking Curve25519 alone is no longer enough. I tried the three ways to fill that slot on two Linux network namespaces: a plain wg genpsk key, an ML-KEM-768 exchange run through the tunnel, and Rosenpass. Each one has a way to fail quietly, and Ubuntu added one more.

What Donenfeld actually said about post-quantum WireGuard

The post went up on December 2 at 21:05 UTC, a few hours after the NSA press release telling national security system owners to speed up the move to post-quantum crypto. It reached 939 points on Hacker News. It makes three points, and the first two are things you can do this week.

  • Use the preshared key. In his words, if you can share one over a secure offline channel, "the security of the WireGuard protocol comes down to breaking that 256-bit ChaCha20 key, which isn't going to happen, rather than any asymmetric primitive."
  • If you can't share one offline, "run a variety of PQ key exchanges ... through an established WireGuard tunnel, and then pop the result into the pre-shared key slot." He adds that some VPN providers already do this.
  • WireGuard v2 is coming, built on WireGuard's "versioned crypto" idea. He is clear that it is not an invitation to design it on the list, and says ECC "was really in an ergonomic sweet spot, which we'll have to move on from."

What the post does not give: a date, a draft, or which post-quantum primitives v2 would use. Anyone telling you what v2 looks like right now is guessing.

Is WireGuard quantum safe? What the preshared key changes

WireGuard's protocol page says it plainly: "If an additional layer of symmetric-key crypto is required (for, say, post-quantum resistance), WireGuard also supports an optional pre-shared key that is mixed into the public key cryptography." When you don't set one, the protocol uses 32 zero bytes in its place. So every tunnel already runs the PSK code path. Most just feed it zeros.

The threat this addresses is the one the NSA release leads with: someone records your encrypted traffic today and decrypts it once they can break the key exchange. Without a PSK, a recording plus a working attack on Curve25519 gives them the session keys. With a secret PSK, they also need the PSK, and that is a symmetric 256-bit key. Grover's algorithm does not bring that within reach.

What the PSK does not do is authenticate peers in a post-quantum way. Identity still comes from the Curve25519 static keys. An attacker who can break the curve live, during the handshake, is a different problem from one who records now and decrypts later. The second is the one people mean by harvest now, decrypt later, and the one a PSK handles. It is the same split as in post-quantum SSH, where key exchange was fixed years before keys.

How to generate a WireGuard preshared key and set it

The test bench: Ubuntu 26.04.1, kernel 7.0, wireguard-tools v1.0.20250521, two network namespaces a and b joined by a veth pair, WireGuard on top as 10.9.0.1 and 10.9.0.2. First, the plain tunnel, then a PSK on one side only, then on both.

$ ip netns exec a ping -c2 10.9.0.2          # no PSK yet
2 packets transmitted, 2 received, 0% packet loss, time 1001ms

$ wg genpsk > psk && wc -c psk
45 psk                                         # 32 bytes, base64, plus newline

# PSK set on a only, then a fresh handshake forced
$ ip netns exec a wg set wg0 peer <b-pubkey> preshared-key psk
$ ip netns exec a ping -c3 -W1 10.9.0.2
3 packets transmitted, 0 received, 100% packet loss, time 2079ms

# same PSK set on b too
$ ip netns exec b wg set wg0 peer <a-pubkey> preshared-key psk
$ ip netns exec a ping -c3 -W1 10.9.0.2
3 packets transmitted, 3 received, 0% packet loss, time 2078ms
$ ip netns exec a wg show wg0
  peer: fESym0Nv...=
    preshared key: (hidden)
    latest handshake: 1 second ago

That middle block is what a typo in a PSK looks like in production. wg set exits 0. Nothing in dmesg. Pings just drop. And wg show wg0 latest-handshakes on both sides kept printing the timestamp from before the PSK went in, which reads like a healthy tunnel unless you compare it with the clock. If you roll a PSK out across a fleet, check that the handshake time moves, not that the command succeeded.

In a config file it is one line per peer, under [Peer]: PresharedKey = followed by the output of wg genpsk. The same key goes in the matching [Peer] block on the other side. It is per pair of peers, so a hub with 50 clients wants 50 different keys.

Ubuntu's AppArmor profile and WireGuard key files

My first attempt kept the keys in a scratch directory under /tmp. Running as root, with files owned by root, wg refused them:

$ sudo ip netns exec a wg set wg0 private-key /tmp/dsp/wg/a.key
fopen: Permission denied

$ sudo dmesg | grep 'profile="wg"'
apparmor="DENIED" operation="open" class="file" profile="wg"
  name="/tmp/dsp/wg/a.key" comm="wg" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

$ grep file /etc/apparmor.d/wg
  file rw @{etc_rw}/wireguard/{,**},

Ubuntu ships an AppArmor profile for /usr/bin/wg that allows key files under /etc/wireguard and nothing else. The apparmor package changelog lists it as added in February 2025, in the 25.04 cycle, among "new AppArmor profiles for more testing". It matters here because tools that write a PSK to a file for wg to pick up will hit it if the file lives somewhere else. Pipes are fine. Both of these worked:

$ wg genpsk | ip netns exec a wg set wg0 peer <b> preshared-key /dev/stdin
exit=0
$ ip netns exec a wg set wg0 peer <b> preshared-key <(wg genpsk)
exit=0
$ cp psk /tmp/x.psk; ip netns exec a wg set wg0 peer <b> preshared-key /tmp/x.psk
fopen: Permission denied
exit=1

Running ML-KEM through the tunnel into the PSK slot

Donenfeld's second option, done by hand, is shorter than I expected. OpenSSL 3.5 has ML-KEM built in, and an ML-KEM shared secret is 32 bytes, which is exactly the size of a WireGuard PSK. b makes a keypair, a encapsulates to b's public key, the ciphertext goes to b through the existing tunnel, both sides end up with the same 32 bytes. (ML-KEM is the lattice scheme the Anthropic cryptanalysis papers were about; at its standard sizes it is still considered sound.)

# on b
openssl genpkey -algorithm ML-KEM-768 -out b.mlkem.pem
openssl pkey -in b.mlkem.pem -pubout -out b.mlkem.pub      # copy this to a

# on a
openssl pkeyutl -encap -inkey b.mlkem.pub -pubin -out ct.bin -secret ss.bin
# send ct.bin to b over the tunnel (I used nc to 10.9.0.2:7000)
base64 -w0 ss.bin | wg set wg0 peer <b> preshared-key /dev/stdin

# on b
openssl pkeyutl -decap -inkey b.mlkem.pem -in ct.bin -secret ss.bin
base64 -w0 ss.bin | wg set wg0 peer <a> preshared-key /dev/stdin
tunnel up, no PSK
ciphertext bytes received by b: 1088, secret bytes: 32
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
  preshared key: (hidden)
  latest handshake: 2 seconds ago

It worked on the second try. The first try hung, because earlier tests had left the two sides with different PSKs, so the tunnel the ciphertext was meant to cross was already down. That is the general problem with this design: the PSK exchange depends on the tunnel, and the tunnel depends on the PSK. Clearing both PSKs first (preshared-key /dev/null) and forcing a handshake fixed it.

Why it is still worth doing: the ciphertext crosses a tunnel encrypted with today's keys. Someone recording it and breaking Curve25519 later gets the 1,088 byte ciphertext, which is useless without b's ML-KEM private key. That key never left b.

What is Rosenpass, and what it did here

Rosenpass is the maintained version of that script. It runs its own post-quantum handshake next to WireGuard and writes the result into the PSK slot. Its README states the trade directly: because it only feeds the PSK, "Rosenpass+WireGuard is cryptographically no less secure than using WireGuard on its own", and it "refreshes the symmetric key every two minutes". Per the whitepaper, it uses two KEMs: Classic McEliece 460896 for the long-term keys and Kyber-512 for the per-handshake ones.

I ran release 0.2.3 (August 3, 2026) as an ordinary user, with the outfile option that writes the key to a file instead of calling wg. I did not run its rp wrapper, which sets up the WireGuard interface and needs root. The first number that jumps out is the key size:

$ rp genkey a.sk && rp pubkey a.sk a.pk
$ du -b a.pk/*
524160  a.pk/pqpk      # Classic McEliece public key
45      a.pk/wgpk      # the WireGuard one

That is 512 KiB per peer that you have to get to the other side, against a 44 character WireGuard key you can paste into a chat. Not a problem for config management. A problem for anyone who sets peers up by hand.

With one side listening and the other given its endpoint, both outfiles held the same key within a second. Then I gave both sides an endpoint and started them at the same moment, the way two servers come up after a shared reboot:

run 1: differ
run 2: differ
run 3: differ

# 200 s run, keys compared once a second
    118 differ
     77 same
t=118s differ
t=119s same

Both sides started a handshake, both finished one, and each kept a different key. They agreed from the first rekey, at about two minutes. Plugged into WireGuard, that is two minutes of mismatched PSKs, which from the test above means two minutes of dropped packets with a healthy-looking wg show. This is a known bug, rosenpass issue #452, open since October 2024. The reporter saw "connection delays of boot time (~25s) plus a multiple of 120s". The maintainers' plan is to detect parallel handshakes and agree on one key, not to add a random delay.

Which option to use for post-quantum WireGuard

  • A few machines you control, and you can get a file to each one safely: wg genpsk per pair of peers, copied over SSH or your config management. It's the simplest of the three and the one Donenfeld leads with. Rotate it when you would rotate any other secret.
  • A commercial VPN: check whether it already does this. Mullvad's mullvad-upgrade-tunnel, for example, negotiates a PSK with the relay and defaults to Classic McEliece plus ML-KEM-1024.
  • Many peers, no safe way to pre-share: Rosenpass, started so that one side initiates, or with the issue #452 window accepted and monitored.
  • Learning how it fits together: the OpenSSL script above. Not as a service. It never rekeys, and nothing checks that the ML-KEM public key a received was really b's except the tunnel it travelled through.

The catch with each of them

  • Static PSK: no forward secrecy for the post-quantum part. Anyone who later steals the PSK file and has a recording, plus a way to break the curve, gets the traffic. It also has to be distributed safely, which is the problem public keys were invented to avoid.
  • Hand-rolled KEM: chicken and egg. The exchange runs inside the tunnel it is about to rekey, so a mismatch takes the tunnel down and the next exchange can't get through.
  • Rosenpass: 512 KiB public keys, the two-minute mismatch window above, and a release gap (0.2.2 in June 2024, 0.2.3 in August 2026) that says this is a small project. Its ephemeral KEM is Kyber-512, the smallest parameter set, though breaking that alone does not break it, since Classic McEliece also has to fall.
  • All three: peer authentication stays on Curve25519. A PSK protects recorded traffic. It does not protect against someone who can break the curve during the handshake. That part waits for v2.

What WireGuard v2 might change, and what not to expect

Donenfeld describes v2 as an update built on versioned crypto: when primitives need replacing, the version goes up and new software ships. He also warns that keeping WireGuard's properties with current post-quantum primitives is "certainly challenging". Post-quantum public keys and ciphertexts are hundreds or thousands of bytes, against 32 for Curve25519, and WireGuard's handshake was designed to fit in single small UDP packets. Something has to give. Nothing in the post says what, so I'd plan on the PSK slot being the post-quantum answer for a while.

Is WireGuard post quantum?

Not by default. WireGuard's handshake uses Curve25519, which a large quantum computer could break, and most configs leave the preshared key at its all-zero default. Setting a secret 256-bit preshared key on both peers makes the session keys depend on a symmetric secret as well, which protects recorded traffic from a future break of the curve. Peer authentication is still classical.

How do I generate a WireGuard preshared key?

Run wg genpsk, which prints 32 random bytes as 44 characters of base64. Put the same value in the PresharedKey line of the matching [Peer] section on both ends, or set it live with wg set wg0 peer PUBKEY preshared-key FILE. Use a different key for each pair of peers, and check that the latest handshake time moves afterwards.

What happens if the WireGuard preshared keys don't match?

The tunnel stops passing traffic and nothing tells you why. In my test, wg set exited 0, the kernel logged nothing, pings dropped 100%, and wg show kept printing the last handshake from before the change. The only clear sign is a latest-handshake time that stops advancing, so watch that when rolling out or rotating keys.

Does a preshared key slow WireGuard down?

Not in any way you would notice. The preshared key is mixed in once per handshake, which happens about every two minutes, and the data packets are encrypted the same way with or without it. WireGuard already runs the same code path with an all-zero key when you don't set one, so the work done is nearly identical.

What is Rosenpass?

Rosenpass is an open source tool that runs a post-quantum key exchange next to WireGuard and writes the result into WireGuard's preshared key slot every two minutes. It uses Classic McEliece for long-term keys and Kyber for per-handshake keys. Its public keys are about 512 KiB each, and an open bug can leave peers with different keys for two minutes.

Why does wg say fopen: Permission denied when I run it as root?

On recent Ubuntu, an AppArmor profile for /usr/bin/wg only allows key files under /etc/wireguard. A key in /tmp or a home directory is refused even for root, and dmesg shows an apparmor DENIED line with profile wg. Move the files under /etc/wireguard, or pass the key through a pipe with /dev/stdin or bash process substitution.

When is WireGuard v2 coming out?

There is no date. On December 2, 2026, Jason Donenfeld wrote that he has begun investigating a protocol update for WireGuard v2 and that it is not open for design on the mailing list. He gave no specification, schedule or choice of primitives, and recommended the preshared key in the meantime.

  1. Post Quantum WireGuard, WireGuard v2, ongoing AI discoveries, and so forth, Jason A. Donenfeld, WireGuard mailing list
  2. Protocol & Cryptography, WireGuard
  3. NSA Advises Immediate Transition to Post-Quantum Cryptography, NSA
  4. Rosenpass README and source, Rosenpass
  5. Rosenpass whitepaper, Rosenpass
  6. Rosenpass can produce diverging keys when two instances are started exactly in sync (issue #452), GitHub
  7. Quantum-resistant tunnels with WireGuard, Mullvad

More Posts