IPSec: AH, ESP, IKEv2 and the two modes
What AH and ESP each authenticate and encrypt, the fields ESP adds to a packet, what IKEv2 negotiates and produces, and exactly what tunnel and transport mode each protect.
- State what AH authenticates and why it excludes certain header fields.
- List the fields ESP adds and what services ESP can provide beyond AH.
- State what IKEv2 negotiates and how many Security Associations it produces.
- Distinguish tunnel mode from transport mode by what each encapsulates and what each leaves exposed.
20 min read
Intuition
IPSec’s two protocols split the same overall job: AH authenticates, ESP encrypts and authenticates. They can be used separately or together, and IPSec runs each of them in one of two modes that decide exactly how much of the packet gets wrapped.
Mechanism
Authentication Header (AH) authenticates parts of the IP header and the payload. It cannot authenticate the whole header, because some fields legitimately change as the packet is forwarded, e.g. Time-to-Live. The fields AH does authenticate are the “normally immutable” ones: source and destination IP, version, length, and similar.
Mechanism
Encapsulating Security Payload (ESP) can provide confidentiality, data origin authentication, connectionless integrity, an anti-replay service, and limited traffic flow confidentiality. It can be used stand-alone or combined with AH. ESP adds another header, positioned after the IP header (and possibly after an AH header), and a trailer after the protected data. That header and trailer carry:
- SPI, identifying the Security Association.
- Sequence Number (32 bits), a monotonically increasing counter giving an anti-replay function.
- An initialization value (IV), or nonce, present if the encryption or authenticated-encryption algorithm needs one.
- Payload/Protected Data (variable), a transport-level segment in transport mode, or a full IP packet in tunnel mode.
- Pad Length (8 bits), the number of pad bytes immediately preceding this field.
- Next Header (8 bits), identifying the type of data in the payload, e.g. an IPv6 extension header or an upper-layer protocol such as TCP.
- Integrity Check Value (variable, an integral number of 32-bit words), computed over the ESP packet minus the authentication data field itself.
EXTRACTION DEFECT: the ESP header/trailer layout diagram (Figure 25) did not survive extraction, but the field list above, with sizes, is given directly in the lecture text and is reproduced in full.
EXTRACTION DEFECT: the ESP vs. AH comparison diagram (named on its own heading in both the slides and the notes, Figure 26) did not survive extraction. The
<Compare>block below states only what each protocol’s own description gives independently; it is not a reconstruction of that missing diagram.
Compare
EXTRACTION DEFECT: the diagram showing use of the Authentication Header (Figure 27) did not survive extraction.
Mechanism
IKEv2 provides mutual authentication and key establishment between two parties, negotiating cryptographic parameters such as ciphers and hash functions. It results in a total of four Security Associations, one per party and direction. These SAs are then used by AH and/or ESP, and are stored in the Security Association Database.
Mechanism
Tunnel mode is used when the gateways (routers) at each end are responsible for adding IPSec’s cryptographic protection to packets their hosts send, rather than the hosts doing it themselves. The entire original IP packet, once its AH or ESP fields are added, is treated as the payload of a new, outer IP packet with its own new outer IP header. The whole inner packet travels through a tunnel from one point of the network to another; no router along the way can examine the inner IP header, and since the original packet is fully encapsulated, the new outer packet can carry totally different source and destination addresses. This is why hosts behind a firewall can communicate securely without implementing IPSec themselves: their unprotected packets are tunneled through external networks by tunnel-mode SAs set up at the network boundary.
EXTRACTION DEFECT: the Tunnel Mode diagram (Figure 28) did not survive extraction.
Mechanism
Transport mode is used when the endpoint of the IP communication is the same principal that adds the protection, i.e. genuine end-to-end host-to-host communication. It protects the payload of an IP packet, e.g. a TCP or UDP segment or an ICMP packet, not the whole packet. ESP in transport mode encrypts and optionally authenticates the IP payload, but not the IP header. AH in transport mode authenticates the IP payload and selected portions of the IP header. Either way, transport mode authenticates and encrypts only the payload: the IP header is only authenticated, never encrypted. This gives confidentiality to any application using it, without needing every application to implement confidentiality itself, at the cost that traffic analysis is still possible on the transmitted packets, since the header remains visible.
EXTRACTION DEFECT: the Transport Mode diagram (Figure 30) and the side-by-side Transport/Tunnel Mode comparison diagram (Figure 29) did not survive extraction. The comparison above is built only from the two modes’ independently-given descriptions, not from that missing figure.
Exam detail
The exam-safe way to distinguish the two modes: tunnel mode wraps the entire original IP packet inside a new one, so no router en route can read the inner header at all; transport mode leaves the original IP header in place and protects only the payload, meaning the header is at most authenticated, never encrypted, in either AH or ESP transport-mode use.
Aside
The previous page states the total SA count for bidirectional AH+ESP traffic as “two per party and two per mode”, also arriving at four. IKEv2 here is described as producing “one SA per party and direction”, also four. Both are the lecture’s own wording, in two different places; they are presented here exactly as given rather than reconciled into a single derivation.
Recall
- AH authenticates header and payload, but never adds confidentiality; ESP can add confidentiality, and can run with or without AH.
- ESP’s header and trailer carry SPI, a 32-bit Sequence Number, an optional IV, the protected data, Pad Length (8 bits), Next Header (8 bits), and a variable-length Integrity Check Value.
- IKEv2 produces four SAs (one per party and direction), later used by AH and/or ESP.
- Tunnel mode encapsulates the whole original packet inside a new one; transport mode protects only the payload and never encrypts the IP header.
Source
Week 8 slides PDF