Loading content...
The Authentication Header carries all the information necessary for a receiving system to validate a packet's integrity and origin. Unlike many complex protocol headers with numerous optional fields, AH is remarkably straightforward—a design that reflects its focused purpose and enables efficient processing.
Every bit in the AH header serves a specific function. Understanding this structure is essential for:
By the end of this page, you will: understand each field in the AH header and its byte-level layout; know how AH integrates with IPv4 and IPv6 packets; be able to calculate AH header sizes for different authentication algorithms; and interpret AH headers in packet captures.
The Authentication Header consists of a fixed portion (12 bytes) followed by a variable-length Integrity Check Value (ICV). The total header size must be a multiple of 32 bits (4 bytes) for IPv4 or 64 bits (8 bytes) for IPv6 to maintain proper alignment.
Complete AH Header Structure:
| Bits | Field Name | Size | RFC 4302 Reference |
|---|---|---|---|
| 0-7 | Next Header | 8 bits (1 byte) | Section 2.1 |
| 8-15 | Payload Length | 8 bits (1 byte) | Section 2.2 |
| 16-31 | Reserved | 16 bits (2 bytes) | Section 2.3 |
| 32-63 | Security Parameters Index (SPI) | 32 bits (4 bytes) | Section 2.4 |
| 64-95 | Sequence Number | 32 bits (4 bytes) | Section 2.5 |
| 96+ | Integrity Check Value (ICV) | Variable (multiple of 32 bits) | Section 2.6 |
Minimum Header Size:
Typical Header Sizes:
| Authentication Algorithm | ICV Size | Total AH Header |
|---|---|---|
| HMAC-MD5-96 | 12 bytes | 24 bytes |
| HMAC-SHA1-96 | 12 bytes | 24 bytes |
| HMAC-SHA-256-128 | 16 bytes | 28 bytes (+4 padding for IPv6) |
| HMAC-SHA-384-192 | 24 bytes | 36 bytes |
| HMAC-SHA-512-256 | 32 bytes | 44 bytes (+4 padding) |
The header size directly impacts network overhead. For small packets (e.g., 64-byte minimum Ethernet frames), AH can represent 30%+ additional data.
IPv4 requires AH header length to be a multiple of 32 bits; IPv6 requires 64 bits. Implementations must add padding after the ICV if necessary. The Payload Length field accounts for this padding. Misalignment causes packet processing failures.
The Next Header field (8 bits) identifies the type of header or protocol that immediately follows the Authentication Header. This field uses the same protocol number space as the IPv4 Protocol field and IPv6 Next Header field, maintained by IANA.
Common Values:
| Value (Decimal) | Protocol | Context |
|---|---|---|
| 4 | IPv4 (IP-in-IP) | Tunnel mode encapsulation |
| 6 | TCP | Transport mode protecting TCP traffic |
| 17 | UDP | Transport mode protecting UDP traffic |
| 41 | IPv6 | IPv6 tunnel encapsulation |
| 50 | ESP | AH protecting ESP (combined use) |
| 58 | ICMPv6 | Transport mode protecting ICMPv6 |
| 59 | No Next Header | IPv6 special case—no payload |
| 89 | OSPF | Protecting routing protocol traffic |
Operational Significance:
The Next Header field is critical for proper packet processing. After validating the AH ICV, the receiver uses this field to determine how to handle the rest of the packet:
IPv4 Integration:
In IPv4 packets, AH is identified by protocol number 51 in the IP header's Protocol field. The IP header's Protocol field points to AH, and AH's Next Header field points to the next layer.
IPv6 Integration:
In IPv6, AH is an extension header (protocol 51). It chains with other extension headers using the Next Header mechanism. IPv6's streamlined design makes AH integration particularly elegant—it fits naturally into the extension header chain.
When analyzing AH-protected packets in Wireshark or tcpdump, follow the Next Header chain to understand packet structure. Mismatched Next Header values are a common source of authentication failures—ensure both endpoints agree on the protected protocol stack.
The Payload Length field (8 bits) specifies the length of the AH header in 32-bit (4-byte) units, minus 2. This unusual encoding requires careful interpretation.
Formula:
Payload Length Value = (AH Header Length in bytes / 4) - 2
Why "Minus 2"?
The original IPSec specification used a length encoding that counts 32-bit words. Subtracting 2 accounts for the minimum data before the ICV (Next Header + Payload Length + Reserved = 4 bytes, plus SPI = 4 bytes = 8 bytes = 2 words).
Calculation Examples:
| AH Header Size (bytes) | Calculation | Payload Length Value |
|---|---|---|
| 24 (HMAC-MD5-96, HMAC-SHA1-96) | (24 / 4) - 2 = 6 - 2 | 4 |
| 28 (HMAC-SHA-256-128) | (28 / 4) - 2 = 7 - 2 | 5 |
| 32 | (32 / 4) - 2 = 8 - 2 | 6 |
| 36 (HMAC-SHA-384-192) | (36 / 4) - 2 = 9 - 2 | 7 |
| 44 | (44 / 4) - 2 = 11 - 2 | 9 |
Decoding the Field:
To calculate the actual AH header length from the Payload Length field:
AH Header Length (bytes) = (Payload Length + 2) × 4
Example Decode:
Practical Implications:
Implementation Consideration:
When implementing AH processing, always validate the Payload Length makes sense:
The 'minus 2' encoding is a legacy of early IPSec designs. While it can confuse newcomers, it remains standard. RFC 4302 explicitly defines this encoding to maintain backward compatibility with existing implementations.
The Reserved field is 16 bits (2 bytes) set aside for future use. Per RFC 4302:
Purpose:
Reserved fields allow protocol evolution without changing header structure. If future requirements emerge—such as new flags, quality-of-service indicators, or extended capabilities—this field provides space for expansion while maintaining backward compatibility with existing implementations.
Current Usage:
Despite being defined in 1998 (RFC 2402) and formalized in 2005 (RFC 4302), the Reserved field remains unused. No RFCs have allocated bits from this field for any purpose.
Implementation Requirements:
Why 16 Bits?
The Reserved field size maintains 32-bit alignment for the first row of the header (Next Header + Payload Length + Reserved = 32 bits). This alignment optimizes processing on most CPU architectures, where 32-bit aligned reads are most efficient.
Comparison with ESP:
Interestingly, ESP has no equivalent reserved field—its header is more tightly packed. AH's reserved field reflects the original design philosophy of allowing future enhancement without protocol revision.
Some researchers have proposed using reserved fields as covert channels for data exfiltration. Because receivers ignore these bits while they're authenticated, malicious software could encode information here. Security monitoring systems should be aware of this theoretical attack vector.
The Security Parameters Index (SPI) is a 32-bit field that, combined with the destination IP address and the security protocol (AH or ESP), uniquely identifies the Security Association for this packet.
Fundamental Concept:
The SPI is the key that unlocks SA lookup. When a packet arrives, the receiver uses:
(Destination IP Address + Protocol + SPI) → Security Association
This triplet maps to a unique SA in the receiver's Security Association Database (SAD), which contains all parameters needed to authenticate the packet.
SPI Value Ranges:
| Range | Description |
|---|---|
| 0x00000000 | Reserved—local implementation-specific use |
| 0x00000001 - 0x000000FF | Reserved for IANA—future allocation |
| 0x00000100 - 0xFFFFFFFF | Available for SA assignment |
SPI Assignment:
The SPI is selected by the receiving host during SA establishment. This is critical for understanding who "owns" an SPI:
IKE and SPI Negotiation:
During IKE negotiation:
Uniqueness Requirements:
SPIs must be unique for:
Different destination IPs can use the same SPI value. Different protocols (AH and ESP) for the same destination can use the same SPI value. This scoping minimizes the risk of SPI exhaustion in large-scale deployments.
Production implementations should generate SPIs cryptographically (random or pseudo-random) rather than sequentially. Sequential SPIs can leak information about SA establishment patterns and potentially enable prediction attacks during SA renegotiation.
The Sequence Number field is a 32-bit unsigned integer that provides anti-replay protection. Each packet transmitted using a particular SA has a unique, monotonically increasing sequence number.
Sender Behavior:
Receiver Behavior:
Counter Lifecycle:
| Packet Count | Sequence Number (Hex) | Status |
|---|---|---|
| SA Established | 0x00000000 (counter init) | Ready |
| 1st Packet | 0x00000001 | Counter incremented before use |
| 1000th Packet | 0x000003E8 | Normal operation |
| 4,294,967,294th Packet | 0xFFFFFFFE | Approaching limit |
| 4,294,967,295th Packet | 0xFFFFFFFF | MUST establish new SA before next packet |
Sequence Number Window:
Receivers maintain a sliding window (typically 32 or 64 packets wide) to accommodate out-of-order packet delivery:
Window of size W, right edge at R
Acceptable range: [R - W + 1, R]
Example (W=32, R=100):
Acceptable: 69-100
Packet 70 arriving after 71-100: Accepted (in window, not yet seen)
Packet 68: Rejected (below window)
Packet 73: Rejected (already seen—replay attempt)
Extended Sequence Numbers (ESN):
RFC 4302 supports 64-bit Extended Sequence Numbers for high-bandwidth connections. With ESN:
Why This Matters:
Without sequence numbers, an attacker could:
The sequence number ensures each packet is processed exactly once.
While anti-replay is technically optional per RFC 4302, it MUST be enabled for security-sensitive deployments. Disabling it removes a critical protection layer. The only valid reason to disable it is compatibility with legacy systems that don't support it—and such systems should be upgraded.
The Integrity Check Value (ICV) is the cryptographic heart of the Authentication Header. It's a variable-length field containing the output of the authentication algorithm applied to protected portions of the packet.
ICV Computation:
The ICV is computed over:
Algorithm Selection:
The authentication algorithm is specified in the SA. Common choices include:
| Algorithm | Hash | ICV Size | Security Status |
|---|---|---|---|
| HMAC-MD5-96 | MD5 | 96 bits (12 bytes) | Deprecated—MD5 weaknesses |
| HMAC-SHA1-96 | SHA-1 | 96 bits (12 bytes) | Legacy—SHA-1 deprecated for new deployments |
| HMAC-SHA-256-128 | SHA-256 | 128 bits (16 bytes) | Recommended—current standard |
| HMAC-SHA-384-192 | SHA-384 | 192 bits (24 bytes) | Strong—for high-security requirements |
| HMAC-SHA-512-256 | SHA-512 | 256 bits (32 bytes) | Very strong—highest security tier |
| AES-XCBC-MAC-96 | AES | 96 bits (12 bytes) | Alternative for AES-capable hardware |
| AES-GMAC | AES-GCM | 128 bits | Modern, efficient on hardware with AES-NI |
ICV Computation Process:
Handling Mutable Fields:
Certain IP header fields change as packets traverse the network. For ICV computation, these are handled specially:
| IPv4 Field | Handling |
|---|---|
| TOS/DSCP | Zeroed (may change at routers) |
| Flags | Zeroed for DF bit only |
| Fragment Offset | Zeroed |
| TTL | Zeroed (decrements at each hop) |
| Header Checksum | Zeroed (changes with TTL) |
| Options | May be mutable—handled per option type |
| IPv6 Field | Handling |
|---|---|
| Flow Label | Included (immutable once set) |
| Hop Limit | Zeroed (decrements at each hop) |
| Destination Address | Included unless routing header present |
Truncation:
Many algorithms specify truncated ICVs (e.g., "96" in HMAC-SHA1-96). Truncation:
IKE negotiates the authentication algorithm during SA establishment. Both parties must support and agree on the algorithm. Configure implementations to prefer stronger algorithms (SHA-256+) and disable deprecated options (MD5) where possible.
Let's examine how AH headers integrate with complete IP packets in both transport and tunnel modes.
Example 1: IPv4 Transport Mode (TCP Traffic)
Original packet: 192.168.1.10 → 192.168.1.20, TCP port 443 (HTTPS)
1234567891011121314151617181920212223242526272829303132333435363738394041
Original Packet:┌─────────────────────────────────────┐│ IPv4 Header (20 bytes) ││ - Version: 4 ││ - Protocol: 6 (TCP) ││ - Src: 192.168.1.10 ││ - Dst: 192.168.1.20 │├─────────────────────────────────────┤│ TCP Header (20 bytes) ││ - Src Port: 54321 ││ - Dst Port: 443 ││ - Flags: ACK, PSH │├─────────────────────────────────────┤│ Application Data (100 bytes) ││ - TLS encrypted payload │└─────────────────────────────────────┘Total: 140 bytes With AH Applied:┌─────────────────────────────────────┐│ IPv4 Header (20 bytes) ││ - Version: 4 ││ - Protocol: 51 (AH) ← Changed! ││ - Src: 192.168.1.10 ││ - Dst: 192.168.1.20 │├─────────────────────────────────────┤│ AH Header (24 bytes) ││ - Next Header: 6 (TCP) ││ - Payload Length: 4 ││ - Reserved: 0x0000 ││ - SPI: 0x12345678 ││ - Sequence: 0x00000001 ││ - ICV: 12 bytes (HMAC-SHA1-96) │├─────────────────────────────────────┤│ TCP Header (20 bytes) ││ [Unchanged from original] │├─────────────────────────────────────┤│ Application Data (100 bytes) ││ [Unchanged from original] │└─────────────────────────────────────┘Total: 164 bytes (+24 bytes overhead)Example 2: IPv4 Tunnel Mode (Site-to-Site)
Internal hosts (10.0.1.0/24) communicating through VPN gateways:
12345678910111213141516171819202122232425262728293031
Original Packet (from internal host):┌─────────────────────────────────────┐│ IPv4 Header (20 bytes) ││ - Src: 10.0.1.50 (internal) ││ - Dst: 10.0.2.100 (remote internal) ││ - Protocol: 6 (TCP) │├─────────────────────────────────────┤│ TCP + Application Data │└─────────────────────────────────────┘ At VPN Gateway (Tunnel Mode AH Applied):┌─────────────────────────────────────┐│ Outer IPv4 Header (20 bytes) ││ - Src: 203.0.113.1 (gateway 1) ││ - Dst: 198.51.100.1 (gateway 2) ││ - Protocol: 51 (AH) │├─────────────────────────────────────┤│ AH Header (24 bytes) ││ - Next Header: 4 (IPv4) ││ - SPI: 0xABCD1234 ││ - Sequence: 0x00001000 ││ - ICV: 12 bytes │├─────────────────────────────────────┤│ Inner IPv4 Header (20 bytes) ││ - Src: 10.0.1.50 ││ - Dst: 10.0.2.100 ││ - Protocol: 6 (TCP) │├─────────────────────────────────────┤│ TCP + Application Data │└─────────────────────────────────────┘Overhead: +44 bytes (outer IP + AH)Wireshark fully decodes AH headers. Filter with 'ah' to show only AH packets. Expand the 'Authentication Header' section to see all fields. The 'Sequence Number' helps identify packet order and potential replay attempts.
We've thoroughly examined every component of the Authentication Header. Let's consolidate the essential knowledge:
What's Next:
With a complete understanding of AH's format, we're ready to explore how it provides integrity protection. The next page examines the cryptographic mechanisms—how ICVs are computed, which fields are protected, and how receivers validate authenticity at the packet level.
You can now interpret AH headers in packet captures, calculate header sizes for different algorithms, understand how SPIs and sequence numbers enable SA lookup and anti-replay, and recognize how AH integrates with IPv4 and IPv6 packets.