Theme and language

VPN

WireGuard explained: keys, peers, allowed addresses and the handshake

A plain-language tour of WireGuard: interface, private and public keys, peers, allowed addresses and the short handshake that sets up encryption.

Panda Defender editorial team

Prepared with the help of AI from public sources and checked against them; the sources are listed at the end. How we write

In brief

  • A WireGuard interface has its own private key and knows the public keys of its peers.
  • Each peer is tied to a set of permitted tunnel addresses, and packets from other source addresses are not accepted.
  • A short handshake sets up symmetric keys that are rotated regularly, and an optional pre-shared key adds another layer.

WireGuard is a VPN tunnel protocol that is described as fast and modern. Its design is deliberately simple, which makes it a good protocol to learn from. This article explains the main building blocks in plain words.

The interface and the keys

WireGuard wraps IP packets and carries them over UDP. On each device you set up an interface. The interface has its own private key, which stays on that device, and it knows the public keys of the other devices it talks to.

Think of it like a lock and a key: the public key can be shared so others can recognise you, while the private key is never handed out. The protocol itself does not cover how public keys get from one side to the other. That is left to you or to the software you use.

Peers and allowed addresses

A peer is another device that your interface exchanges traffic with. Each peer is identified by its public key. The central idea is called Cryptokey Routing: every peer's public key is associated with a set of tunnel addresses that are permitted inside the tunnel.

This works in two directions:

  • When sending, the interface picks the matching peer, encrypts the packet with that peer's key and sends it to that peer's endpoint.
  • When receiving, the interface decrypts the packet and accepts it only if its source address is permitted for that peer.

So a peer cannot send traffic that claims to come from an address it was not assigned. Endpoints can also roam: the latest authenticated source address of a peer is remembered, so a device that changes networks can keep talking.

The handshake

Before data flows, the two sides run a short handshake based on the Noise_IK pattern from the Noise framework. It establishes symmetric keys, and these keys are rotated regularly. According to the protocol description, the key exchange provides perfect forward secrecy, which means that a later key compromise should not expose earlier sessions. It also provides identity hiding and avoids key-compromise impersonation and replay attacks.

An optional pre-shared key can be mixed in as an additional symmetric layer. The documentation gives post-quantum resistance as one example of why you might add it.

The cryptography in brief

The project uses a fixed set of primitives:

  • ChaCha20 with Poly1305 for authenticated encryption
  • Curve25519 for key agreement
  • BLAKE2s for hashing
  • SipHash24 for hashtable keys
  • HKDF for key derivation

The design aims to need very few lines of code, so it is easier to audit than large codebases such as IPsec implementations or OpenVPN with OpenSSL.

What to do

  • Keep each private key on the device where it was created and do not share it in chats or screenshots.
  • Share only public keys, and check that you add the right one for each peer.
  • Keep the permitted address set as narrow as your setup needs, since it decides what each peer may send.
  • Consider a pre-shared key if you want an extra symmetric layer.
  • Keep your WireGuard software up to date and check that the tunnel is active when you rely on it.

Sources

  1. WireGuard: fast, modern, secure VPN tunnelWireGuard
  2. Protocol & CryptographyWireGuard

Spotted an error? Write to us

Read also