How VPNs Work - Part 3: Encryption and Authentication
17,452 Total views across this article’s versions; includes the historical baseline where available.
This article is Part 3 in a series of three (3) articles about how Virtual Private Networks (VPNs) work. While I get into some technical details, the intent is to scratch the surface just enough to convey the most important security and privacy concepts about each subject.
Part 1 of this series, How VPNs Work outlines VPN functionality at a high level. Part 2 (Protocols) in this series examines VPN protocols and VPN server compatibility. And this article (Part 3) explores security and encryption risks in VPNs, such as encryption ciphers and Forward Secrecy.
Topics
- Terminology (security related)
- Encapsulated Tunnel Formation
- Key Negotiation
- Authentication
- Data Encryption
- Obfuscation
- Perfect Forward Secrecy (PFS)
- Privacy and Confidentiality through Cryptography
- Key Agreement and Authentication Protocols
- Payload Protection
- Common Cryptographic Algorithms
- Poor Habits of VPN Service Providers
Terminology
These terms describe different protections:
- Authentication establishes a peer’s identity or verifies that a message came from a party holding the appropriate key. Key agreement alone does not authenticate that party.
- Integrity detects unauthorized changes to protected data. Data-origin authentication normally includes integrity protection.
- Confidentiality prevents unauthorized parties from reading protected content, normally through encryption.
- Anonymity concerns whether activity can be linked to an identity. Encrypting a VPN connection does not by itself make its user anonymous.
- Privacy is broader than any one cryptographic property; addresses, timing, account records and endpoint behavior also matter.
- Hash means the output of a hash function. A cryptographic hash is designed for properties such as resistance to finding collisions and preimages. An ordinary unkeyed hash or checksum is not a message authentication code (MAC).
RFC 5116 distinguishes confidentiality, authentication and associated data; RFC 2104 describes keyed message authentication.
Encapsulated Tunnel Formation
The peers must support a compatible VPN protocol and configuration. Protocol selection may be configured in advance or negotiated by a particular implementation; there is no universal opening conversation that chooses among all VPN technologies.
A cryptographic handshake then negotiates permitted algorithms, establishes keying material and authenticates the peers as specified by that protocol. Some initial messages can be public. Security depends on authenticating the exchange and deriving keys correctly, not on hiding every negotiation message. Having a certificate or pre-shared key does not mean that all handshake bytes start out encrypted. See IKEv2 (RFC 7296) and TLS 1.3 (RFC 8446).
GRE: When Is a VPN Not a VPN?
Generic Routing Encapsulation (GRE) carries one protocol inside another. It is a tunneling mechanism, not a confidentiality or cryptographic authentication mechanism. Its optional checksum detects some transmission errors; neither that checksum nor the GRE Key field authenticates a sender.
GRE can carry different payload protocols, including Ethernet in appropriate encapsulations. Calling it simply a Layer 2 protocol, or ruling it out as a VPN building block, obscures that flexibility. GRE can be protected by IPsec ESP with encryption and integrity. Whether it is faster than another tunnel depends on the actual configuration and hardware. See RFC 2784 and RFC 2890, especially Section 3.
Key Negotiation
Key negotiation agrees algorithms and other parameters; key agreement or key transport establishes the secret material from which keys are derived. Well-designed protocols separate authentication keys, handshake keys and traffic keys as needed, often with different keys for each direction.
IKEv1 used Phase 1 and Phase 2 terminology. IKEv2 uses named exchanges: IKE_SA_INIT, IKE_AUTH and, when needed, CREATE_CHILD_SA. TLS and WireGuard have their own handshakes. Dividing every VPN into a single-phase or dual-phase model does not describe these protocols accurately. RFC 2409; RFC 7296.
Why Phase Count Does Not Establish Security
The number of phases does not determine whether a handshake provides forward secrecy or permits rekeying. A public Diffie–Hellman exchange can establish secret material, but its participants must also be authenticated to prevent a man-in-the-middle from substituting its own exchange.
Evaluate the protocol’s authentication, key derivation, algorithm choices, fresh secret generation and key deletion. A second negotiation inside an encrypted connection is not an automatic defense if the attacker can already recover or control that connection. RFC 7296, Sections 2.12–2.17.
Authentication
Peer authentication and packet authentication are related but distinct. A handshake may authenticate a peer with a certificate, signature, pre-shared key or another supported method. A protected data packet normally carries a keyed MAC or an AEAD authentication tag.
For HMAC, both peers use the shared secret key and the specified message bytes to calculate a tag. The receiver verifies the received tag and rejects a failed check. Knowing the message and the public algorithm does not supply the secret key needed to forge a valid tag. The tag is verified, not generally decrypted as a hidden hash. RFC 2104.
Data Encryption
Encryption provides confidentiality for the bytes it covers. It must be used with integrity protection in a secure VPN design, either through an authenticated-encryption construction or a suitable combination of encryption and authentication. Encryption alone does not establish peer identity. RFC 5116.
Obfuscation
Obfuscation means obscuring recognizable information; it is not a synonym for confidentiality or anonymity. An encrypted tunnel can hide an inner IP header from observers between its endpoints while leaving the outer source and destination visible for routing. Packet sizes and timing also remain observable unless additional measures address them.
For example, IPsec ESP in tunnel mode can encrypt the inner packet, including its addresses. AH provides no encryption in either mode. AH transport mode remains an IP-layer mechanism, and its header is inserted after the IP header rather than appended to the packet’s end. RFC 4302; RFC 4303.
Perfect Forward Secrecy (PFS)
Forward secrecy means that later compromise of long-term authentication secrets does not reveal past session keys, assuming the ephemeral secrets and session keys have been erased and the underlying cryptography remains secure.
Authenticated ephemeral Diffie–Hellman is a common way to obtain this property. It does not require a previously encrypted channel or a universal two-phase handshake. Merely creating a different traffic key is insufficient if that key can be reconstructed from a subsequently compromised long-term secret and a recorded transcript. RFC 7296, Section 2.12.
PFS Process Flow
A simplified authenticated ephemeral-DH exchange works as follows:
- Each peer creates a temporary private DH value and sends the corresponding public value.
- The protocol authenticates the exchange, binding the intended peers to the handshake.
- Each peer computes the same shared secret locally and derives the required traffic keys using the protocol’s key-derivation function.
- The peers protect traffic with those keys and erase temporary secrets when no longer needed.
The public values are not the private values or the resulting traffic keys. Exact message ordering and key separation depend on the protocol; this outline does not describe extra physical or logical tunnels that every VPN must create. RFC 7296; RFC 8446.
Rekeying, Timers and Forward Secrecy
Rekeying limits how much traffic is protected by a particular key and helps enforce algorithm-specific usage limits. It is related to, but distinct from, forward secrecy. New keys can often be installed while an existing connection remains usable; the protocol need not tear down the whole VPN on every timer expiration.
A short timer is not a race that forces an attacker to finish decryption before the key changes. An attacker can record ciphertext and attack it later. Fresh, independent secrets and secure deletion limit the consequences of some compromises; a timer cannot repair a weak DH group, a broken cipher or a compromised endpoint. There is no justified universal promise that every recorded transmission will eventually be decrypted, or that timely rekeying makes decryption impossible. RFC 7296, Sections 2.8 and 2.12.
Quantum Computing: A Real Threat to PFS
A sufficiently capable fault-tolerant quantum computer would threaten the factoring and discrete-logarithm assumptions behind RSA and conventional DH/ECDH. That could expose recorded sessions even when they used classical forward secrecy. Symmetric encryption faces a different kind of quantum speedup; it is not accurate to say every cipher would go from thousands of years to seconds.
A qubit is described by a quantum state whose measurement yields a classical outcome, not by three separately readable states called 0, 1 and both. Google’s 2019 random-circuit sampling experiment did not demonstrate cryptographic decryption. See Google’s 2019 Quantum Experiment and Cryptography for the experiment’s scope. NIST’s first finalized post-quantum standards appeared in 2024; post-quantum protection is an algorithm and protocol-design issue, not simply a shorter rekey timer. NIST’s 2024 standards announcement.
Privacy and Confidentiality through Cryptography
A VPN protocol combines several cryptographic tasks: authenticating peers, agreeing keys, protecting traffic and managing those keys over time. These tasks do not necessarily correspond to separate layers of encryption. Application encryption such as HTTPS can provide additional protection between the application endpoints, including beyond a consumer VPN exit.
Key Agreement and Authentication Protocols
IKE is the key-management protocol normally associated with IPsec. Other VPN families use other handshakes; IKE is not a universal key exchange for all VPNs.
IKE
Internet Key Exchange version 2 (IKEv2) authenticates peers and establishes and maintains IKE and IPsec Security Associations. Its base specification is RFC 7296. IKEv1 is a historical predecessor, deprecated by RFC 9395 (2023).
IKEv2 explicitly supports NAT detection and NAT traversal. Section 2.23 describes the exchange and use of UDP encapsulation; it is not neutral or silent on NAT-T. The IP header outside IKE’s protected payload is not covered as though it were an AH-protected header.
MOBIKE
MOBIKE is the IKEv2 Mobility and Multihoming extension. It allows address changes for an IKEv2 SA and associated tunnel-mode IPsec SAs, which is useful when a mobile client changes networks. Both endpoints must support and negotiate it. RFC 4555.
Payload Protection
The VPN’s traffic keys protect the selected traffic, not merely an empty outer tunnel. HTTPS inside a VPN protects application data separately. These protections have different endpoints: a VPN exit may see the destination and traffic metadata even when HTTPS keeps application content encrypted.
An encrypted inner IP header can conceal its addresses from observers along the tunnel, but this alone does not establish anonymity. Authentication tags protect the fields specified by the protocol; they do not automatically cover every surrounding network header.
IPsec Encapsulating Security Payload (ESP)
ESP supports confidentiality, integrity and data-origin authentication, with replay protection when used appropriately. ESP can also be configured for integrity without encryption; encryption is not inherent in every ESP packet.
With encryption enabled, transport mode protects the upper-layer payload and ESP trailer while leaving the outer IP header visible. Tunnel mode protects an entire inner IP packet and trailer. ESP integrity does not cover the outer IP header. See RFC 4303. The illustrations below omit details such as explicit IVs; they represent encrypted ESP configurations, not all possible ESP services.
Original illustrations — see correction above
The encryption and integrity ranges are schematic. The outer IP/UDP headers are outside ESP integrity coverage; the ESP integrity tag is not included in its own calculation.
IPsec Authentication Header (AH)
AH supplies integrity and data-origin authentication without confidentiality. It covers the payload and IP-header fields that are immutable or predictable in transit. Mutable fields are handled as specified in the protocol, and the AH integrity-check field is zeroed for calculation. Anti-replay uses sequence numbers and receiver state, not a returned acknowledgement bit. RFC 4302.
The original combined AH/ESP drawings below are retained for comparison. Their whole-packet arrows omit the mutable-field exceptions, and the tunnel drawing does not correctly represent an ESP-encrypted inner IP header. Use the corrected packet layouts in What Is IPsec?.
Original illustrations — see correction above
Historical illustrations: do not use their coverage arrows or tunnel-header placement as an implementation specification.
Common Cryptographic Algorithms
Encryption ciphers, hash functions, MACs and key-agreement algorithms perform different jobs. HMAC was specified in RFC 2104 (1997); AES was standardized in 2001, SHA-3 in 2015, and ChaCha20-Poly1305 has IETF specifications for TLS and IPsec. Age alone is not a useful measure of cryptographic strength. The construction, parameters, implementation and protocol context matter.
Authentication Only
A MAC authenticates message bytes using a secret key. It does not conceal the message. Which packet or frame fields are protected is determined by the protocol that uses it.
MAC, HMAC, and HMAC-SHA
MAC means Message Authentication Code. HMAC is a keyed-hash construction: it combines a secret key and a cryptographic hash function to authenticate a message. Its security does not depend on keeping the hash algorithm or plaintext secret.
SHA-1, SHA-2 and SHA-3 identify different hash standards or families. SHA-3’s fixed-output functions have 224-, 256-, 384- and 512-bit digests; SHAKE128 and SHAKE256 are separate extendable-output functions. A 1024-bit SHAKE output is not a fixed SHA3-1024 variant. SHA-3 is based on Keccak’s sponge construction, not on an improved MD5 algorithm. Hash output size, MAC tag length and encryption key size are different quantities. RFC 2104; FIPS 202.
Poly1305
Poly1305 is a message authenticator producing a 128-bit tag. Its one-time key must not be reused for different messages. In the IETF ChaCha20-Poly1305 construction, that key is derived for each nonce; the construction has specific nonce-uniqueness requirements. Poly1305 alone does not encrypt data. RFC 8439.
Encryption Only
Encryption primitives provide confidentiality when used in a suitable construction. They do not automatically authenticate ciphertext; a complete VPN must provide that protection too.
AES
AES is a block cipher with a fixed 128-bit block size and a choice of 128-, 192- or 256-bit keys. A key is not a block of the message. The AES primitive transforms blocks under a key; a mode of operation specifies how to protect longer messages. AES-GCM adds authentication, while AES-CBC or AES-CTR requires a suitable separate authentication construction. FIPS 197, updated 2023.
ChaCha20
ChaCha20 is a stream cipher based on a 20-round function. The IETF construction uses a 256-bit key and a 96-bit nonce. It derives a keystream that is combined with the message; ChaCha20 by itself does not authenticate the result. RFC 8439. Its combination with Poly1305 for IKE and IPsec is specified in RFC 7634 (2015).
Key Agreement Negotiation: Diffie-Hellman (DH)
Diffie–Hellman establishes a shared secret over a public channel. A key-derivation function then produces the keys the protocol needs. DH does not encrypt the application’s data and does not authenticate the participants by itself.
A finite-field DH group specifies mathematical parameters, including a prime modulus and generator; an elliptic-curve group specifies a different mathematical structure. Group identifiers do not denote bags of encryption algorithms, and there is no permanent limit of 24 groups. Parameter sizes across finite-field and elliptic-curve systems are not directly comparable. The 2015 Logjam research exposed weaknesses in deployed parameters and negotiation, not a previously universal belief that DH could never be broken. RFC 6989; the Logjam paper.
Curve25519
Curve25519 is an elliptic curve. X25519 is the Diffie–Hellman function using that curve, specified in RFC 7748. X25519 produces shared-secret material for key derivation. It is not a payload-encryption cipher and does not independently authenticate the peer.
AEAD Ciphers: Encryption + Authentication
Authenticated Encryption with Associated Data (AEAD) provides confidentiality and integrity for a plaintext while also authenticating selected associated data that remains unencrypted. The interface takes a key, nonce, plaintext and associated data and produces ciphertext with authentication information.
AEAD is not defined by completing both jobs in one computational round, or by always using a block cipher. The nonce and usage limits of the chosen construction still matter. RFC 5116.
ChaCha20 + Poly1305 Combo
ChaCha20-Poly1305 combines ChaCha20 encryption with a Poly1305 tag over the specified associated data, ciphertext and lengths. It is an AEAD construction with a defined way to derive the one-time Poly1305 key. It is not an arbitrary choice to run two unrelated algorithms in sequence. RFC 8439, Section 2.8.
Algorithm Modes of Operation
The suffix in a name such as AES-CBC or AES-GCM identifies a mode of operation:
- CBC: Cipher Block Chaining; confidentiality only unless combined with authentication.
- CTR: Counter mode; confidentiality only unless combined with authentication.
- GCM: Galois/Counter Mode; authenticated encryption with associated data.
Protocol specifications add details such as nonce format and tag length. RFC 3686 specifies AES-CTR for ESP and requires authentication. It does not make CTR an AEAD cipher.
Security Protocol Must’s, May’s, Should’s, and Do Nots
Standards distinguish algorithms an implementation must support from algorithms a deployment may negotiate. A required implementation capability is not a command to select that algorithm for every connection, and an optional capability does not imply equal suitability for every threat model.
RFC 8221 (2017) requires encryption to be authenticated. It describes ESP with AEAD, ESP with separate encryption and authentication, and ESP with AH supplying authentication. The last combination is explicitly not recommended because of overhead and security concerns with some configurations.
IPsec Algorithm Requirements: 2017 Snapshot
The following tables summarize selected 2017 RFC 8221 implementation requirements, not a complete current deployment policy. MUST- means required at publication with an anticipated future downgrade. Later guidance, including RFC 9395 (2023), must also be considered.
| ESP transform | 2017 status | Role / scope |
|---|---|---|
| ENCR_NULL | MUST | No encryption; requires integrity protection. |
| ENCR_AES_CBC | MUST | 128- and 256-bit keys; 192-bit keys MAY. Requires authentication. |
| ENCR_AES_GCM_16 | MUST | AEAD; 128- and 256-bit keys; 192-bit keys MAY. |
| ENCR_AES_CCM_8 | SHOULD | AEAD; IoT interoperability, 128-bit keys. This is CCM, not GCM_8. |
| ENCR_CHACHA20_POLY1305 | SHOULD | AEAD. |
| ENCR_3DES | SHOULD NOT | Non-AEAD, discouraged. |
| Integrity transform | 2017 status | Condition |
|---|---|---|
| AUTH_NONE | MUST / MUST NOT | Supported for AEAD; not a general permission to omit integrity. |
| AUTH_HMAC_SHA2_512_256 | SHOULD | SHA-512 HMAC with a 256-bit tag. |
| AUTH_HMAC_SHA2_256_128 | MUST | SHA-256 HMAC with a 128-bit tag. |
| AUTH_HMAC_SHA1_96 | MUST- | Historical compatibility requirement; anticipated downgrade. |
| AUTH_AES_XCBC_96 | SHOULD / MAY | SHOULD for IoT; MAY for broader VPN deployment. |
| AUTH_AES_256_GMAC | MAY | AH use; ESP has a separately specified GMAC transform. |
| AUTH_AES_128_GMAC | MAY | AH use; not encryption. |
This table summarizes some IPsec algorithm requirements from RFC 8221 (2017); it is not a complete list of what peers can negotiate. For example, the RFC says implementations SHOULD NOT use 3DES; that is different from an outright prohibition.
AES-CTR is not in the main ESP encryption table, but Section 8 explicitly lists it as optional (MAY), and Section 3 prohibits it with manual keying. RFC 3686 (2004) defines its use with IPsec ESP and requires a separate authentication method: AES-CTR is not an AEAD cipher. The IETF published RFC 8423 in July 2018 to reclassify ten specific NSA Suite B RFCs as Historic. RFC 3686 was outside that scope; its omission does not change its status. We’ll get into provider choices further below, in Poor Habits of VPN Service Providers.
IKEv2 Algorithm Requirements
IKEv2 protects its own exchanges separately from the Child SAs used for ESP or AH. Its algorithm implementation guidance is in RFC 8247 (2017) and later updates such as RFC 9395. IKE and ESP choices can differ; support for a cipher in one context does not automatically make it suitable in the other.
RFC 6071 is a document roadmap, not an instruction to copy whichever cipher list the surrounding framework uses. Local policy and both peers’ supported proposals determine the negotiated combination.
Poor Habits of VPN Service Providers
A provider’s protocol name or public-key publication does not establish whether its configuration is secure. Look for documented authentication, maintained software, suitable algorithms, protection of private material and an explanation of what traffic and metadata the service can observe.
Authentication without Encryption
If confidentiality is part of the promised service, authentication-only traffic protection does not meet that requirement. GRE alone provides neither encryption nor a cryptographic MAC. GRE protected by encrypted IPsec ESP is a different configuration and can provide both confidentiality and integrity.
An authentication-only construction can still provide strong integrity. With a secure keyed MAC, an observer who knows the plaintext and algorithm cannot simply recompute a valid tag without the key. That attack works against an unkeyed checksum, not against a correctly used HMAC. RFC 2104; RFC 2890.
Public Keys and Secret-Key Reuse
A server normally publishes its public key or certificate to many clients and can use the same long-term authentication key across multiple connections. Distribution through a website, email or configuration file is not itself a cryptographic weakness. The client must verify that the key belongs to the intended server through an appropriate trust mechanism.
Do not confuse the public authentication key with a shared private key, a shared password, or an ephemeral DH secret. Those have different confidentiality and lifetime requirements. RFC 5280; RFC 8446.
Which Key Practices Create Risk?
The relevant risks are compromise of the private key, acceptance of an attacker’s substituted key, weak algorithms or randomness, and inappropriate reuse of secret material. Giving unrelated customers the same private authentication credential can let them impersonate one another; giving them the server’s same public certificate does not.
If a long-term key is compromised, the consequences for recorded traffic depend on the handshake. Properly implemented ephemeral-DH forward secrecy can protect past sessions after their temporary secrets are erased. A protocol that lets the long-term key recover old session keys does not provide that protection. There is no general rule that a known server public key reveals half the traffic or makes the other direction easy to decrypt. RFC 7296, Section 2.12; RFC 8446.
Footnotes
The sources linked throughout this review distinguish protocol requirements from historical observations. The earlier footnote topics are retained here with corrected scope:
- How the NSA Monitors VPNs separates documented reports from inference.
- HMAC’s construction dates to RFC 2104 (1997); RFC 2404 specified its SHA-1 use with IPsec in 1998.
- AEAD research predates the 2008 interface RFC; its definition is not a release date for every construction.
- ChaCha20 derives from the Salsa20 family; see RFC 8439.
- RFC 7905 specified ChaCha20-Poly1305 for TLS in 2016.
- RFC 8439 updated the IETF ChaCha20/Poly1305 description in 2018.
- SHA-3 deployment and performance depend on implementation and workload; this is not evidence that its specification is invalid.
- FIPS 202 specifies SHA-3 and SHAKE, not an MD5 derivative.
- RFC 7539 (2015) is the predecessor of RFC 8439.
- RFC 7634 specifies ChaCha20-Poly1305 for IKE and IPsec.
- Logjam’s TLS export downgrade and the paper’s 1024-bit precomputation estimates are distinct findings.
- RFC 5116 (2008) defines an AEAD interface and selected algorithms.
- RFC 8221’s IoT row is AES-CCM-8, not AES-GCM-8.
- A separate integrity transform can be omitted when AEAD supplies authentication; that does not mean the packet is unauthenticated.
- GMAC is authentication without encryption. RFC 8221 distinguishes its AH and ESP uses.