As network security becomes increasingly crucial, the advent of WireGuard has introduced a new paradigm in the VPN domain. This article provides an in-depth analysis of WireGuard, comparing it with traditional solutions like OpenVPN.

The primary objective of this initial article is to concentrate on the technical facets of WireGuard, while a subsequent article will explore its practical applications in a more pragmatic manner.

What is WireGuard?

WireGuard is a modern, high-performance VPN protocol that emphasizes simplicity, speed, and security. It's designed to provide a more streamlined and efficient approach to secure communications.

Key Characteristics

  • Minimal Codebase: At under 4000 lines, WireGuard's code is easier to audit and maintain.
  • Advanced Cryptography: Utilizes modern cryptographic primitives like Curve25519, ChaCha20-Poly1305, and SipHash.
  • Ease of Configuration: Simplifies setup processes, reducing potential for errors.
  • Transport Layer: WireGuard only supports UDP (User Datagram Protocol), making it impossible to use TCP (Transmission Control Protocol) port 443 and therefore harder to bypass censorship.
  • Connectionless: Supports roaming, survives connection interruptions, has transparent session renegotiation.
  • Minimizes attack surface:: Invisible in port scans, DoS (cf. SYN-Flooding) & Replay protection.
  • Kernel integration: WireGuard's integration into Linux kernel offers native support for Linux-based systems since 2020. The application runs in the kernel space, and is faster because it does not run in the user space like other VPNs typically do.

Transport Layer: TCP vs UDP

The decision to use either TCP or UDP for your VPN connection depends on your specific needs and requirements. Here are the advantages and disadvantages of both protocols:

Advantages of TCP

  1. Reliability: TCP provides reliable, error-checked data transmission. It ensures that all packets are received in the correct order, and retransmits any lost or corrupted packets.
  2. Connection-oriented: TCP establishes a connection between the client and server before transmitting data, ensuring a more secure and stable connection.
  3. Compatibility: TCP is widely supported by most networks and applications, making it suitable for scenarios where network conditions may not be optimal or stable.

Disadvantages of TCP

  1. Overhead: The additional reliability features of TCP result in higher overhead, increasing bandwidth usage and potentially slowing down the connection.
  2. Latency: Due to the connection-oriented nature, TCP can introduce latency as it waits for acknowledgment after sending each packet.
  3. Blocked by firewalls: Some firewalls may block certain TCP ports, limiting connectivity in some situations.

Advantages of UDP

  1. Speed: UDP is faster than TCP since it does not have the same level of error-checking and retransmission mechanisms.
  2. Lower overhead: UDP has lower overhead compared to TCP, resulting in less bandwidth usage.
  3. Streaming applications: UDP is commonly used for real-time streaming applications like video conferencing or online gaming because it prioritizes speed over reliability.

Disadvantages of UDP

  1. Unreliable delivery: UDP does not guarantee packet delivery or order; therefore, some packets may be lost or arrive out of order.
  2. Potential security risks: Without error-checking mechanisms, UDP can be vulnerable to certain types of attacks if not properly secured.

In summary, if you prioritize reliability over speed and require a secure connection with error-checking mechanisms, TCP is a better choice for your VPN connection. On the other hand, if speed and low latency are more important, and you are using applications that can handle packet loss or out-of-order delivery, UDP may be the preferred option.

WireGuard vs. Traditional VPN Solutions

Comparison with OpenVPN & IPSec

Feature WireGuard OpenVPN IPSec
Codebase Size ~4,000 lines ~100,000 lines >400,000 lines
Encryption ChaCha20 AES-256 AES-256/SHA1
Authentication Poly1305 RSA RSA/ECDSA
Handshake Noise Protocol Framework SSL/TLS IKEv2/IPSec
Configuration Simple Complex Complex
Performance High Moderate Moderate
Cross-Platform Support Extensive Extensive Varied

Source: YouTube – WireGuard vs. OpenVPN vs. IPSec

Performance

  • Speed: WireGuard often outperforms OpenVPN and IPSec in throughput and latency, thanks to its efficient cryptographic algorithms and lean code.
  • Resource Usage: WireGuard's minimalistic design translates to lower resource consumption, making it suitable for low-powered devices.

Technical Advantages of WireGuard

  1. Simplified Key Management: WireGuard simplifies key management with its use of public key cryptography. Each peer in a WireGuard network has a pair of public and private keys, streamlining the authentication process.
  2. IP Address Management: WireGuard assigns static internal IP addresses to peers, which makes network policies and routing simpler compared to dynamic IP allocations in OpenVPN.
  3. Roaming Support: WireGuard handles IP address changes seamlessly, making it ideal for mobile devices that switch between Wi-Fi and cellular networks.
  4. Network Performance: WireGuard's lean code and efficient cryptography result in better network performance, particularly in terms of throughput and latency.

Cryptography

  • Use of static and short-lived key pairs for Diffie-Hellman key exchange. WireGuard implements perfect forward secrecy (PFS), which means that even if an attacker gains access to a current key, they cannot use it to decrypt previous communications.
  • No direct transmission of static public keys. This way, WireGuard obscures the identities of the participating hosts for outsiders.
  • Optional symmetric pre-shared key mode. This is used to prevent quantum attacks (PDF) against asymmetric algorithms.

CryptoKey Routing

CryptoKey routing is a routing mechanism used in WireGuard, which allows for direct encrypted communication between peers in a network without the need for complex configurations or additional virtual interfaces.

In WireGuard, each peer has a public (PubKey or Session Key) and private key pair. These keys are used to establish secure connections and encrypt traffic between peers. CryptoKey routing leverages these keys to determine how packets should be routed within the network.

When a packet arrives at a WireGuard interface, it is decrypted using the appropriate private key. The decrypted packet includes an inner IP header that contains the original source and destination IP addresses. Based on this information, WireGuard determines which peer the packet should be sent to.

CryptoKey routing relies on the fact that each peer's public key is unique and acts as an identifier. This allows WireGuard to determine which peer should receive each packet by matching the destination IP address with the public key of the corresponding peer.

Thus, each peer maintains a table of peers:

PubKey/ID Allowed IPs Internet Endpoint
TrMv..X0= 10.0.0.2/32  
gN65…EA= 10.0.0.3/32 203.0.113.20

By using CryptoKey routing, WireGuard simplifies network configuration and eliminates the need for complex routing tables or virtual interfaces typically found in traditional VPN solutions. It offers improved performance and security while maintaining simplicity in setup and management.

HKDF and its purpose

WireGuard uses HKDF (HMAC-based Extract-and-Expand Key Derivation Function) as a part of its cryptographic protocol for generating secure keys. The way WireGuard utilizes HKDF can be broken down into several key steps:

Initial Key Exchange

WireGuard starts with a Diffie-Hellman key exchange, usually using Curve25519. This exchange produces a shared secret between the two communicating parties.

Extract Phase of HKDF

  • Input: The shared secret obtained from the Diffie-Hellman exchange is used as the Input Keying Material (IKM) for HKDF.
  • Salt: WireGuard uses specific salts for different purposes, ensuring that keys derived for different purposes (like encryption, authentication) are different even if the initial shared secret is the same.
  • Output: The result is a Pseudorandom Key (PRK) that is uniformly random and suitable for cryptographic use.

Expand Phase of HKDF

  • Purpose (Continued): WireGuard uses the Expand phase to derive specific keys needed for its operations. This includes keys for encrypting and authenticating data packets.
  • Input: The PRK from the Extract phase and context-specific info are used. The info parameter is different depending on the specific key being derived, ensuring uniqueness of each key.
  • Output: The Expand phase produces several different keys from the same PRK:
    • Encryption Keys: Separate keys for sending and receiving encrypted data.
    • Authentication Keys: Keys used to authenticate packets, ensuring they are from the legitimate sender and have not been tampered with.

Rekeying

WireGuard can periodically perform a new Diffie-Hellman exchange and use HKDF again to generate new keys. This is part of its forward secrecy feature, ensuring that even if current keys are compromised, past communications remain secure.

Practical Considerations

  1. Scalability: While WireGuard is highly scalable due to its simplicity, the static nature of configuration can be a limitation in large-scale deployments.
  2. Audit and Compliance: Given its relatively new entry into the market, WireGuard is still undergoing extensive reviews and audits, which is a crucial consideration for enterprise environments.
  3. Interoperability: Integration with existing network infrastructure and compatibility with legacy systems can be a challenge when transitioning to WireGuard from solutions like OpenVPN or IPSec.

Final thoughts

WireGuard represents the next step in VPN technology, offering significant improvements in terms of performance, security, and simplicity. For technicians looking to deploy modern, efficient VPN solutions, WireGuard stands as a compelling choice, albeit with considerations for scalability and interoperability in complex network environments.

Further articles