IPsec encapsulates or decapsulates IP packets using Authentication Header (AH) and Encapsulating Security Payload (ESP).
AH is mainly used to authenticate data source, verify data integrity, and prevent packet replay. It does not support encryption.
ESP is mainly used to encrypt data, authenticate data origin, verify data integrity, and prevent packet replay.
Although both the AH and ESP protocols provide data origin authentication and data integrity verification, ESP cannot replace AH. The difference between the two protocols lies in the check range. For details, see Encapsulation Mode.
Table 1 shows the comparison between AH and ESP.
Security Feature |
AH |
ESP |
---|---|---|
IP protocol ID |
51 |
50 |
Data integrity verification |
Supported (checking the whole IP packet) |
Supported (transport mode: not checking the IP header; tunnel mode: verifying the entire IP packet in the new IP header, including the old IP header) |
Data origin authentication |
Supported |
Supported |
Data encryption |
Not supported |
Supported |
Anti-replay |
Supported |
Supported |
IPsec NAT traversal |
Not supported |
Supported |
Both protocols have advantages and disadvantages. AH does not provide the data encryption function. The verification scope of ESP does not include IP headers, unless the IP header is encapsulated within the ESP header (old IP header when the tunnel mode is used for encapsulation). The security of ESP is lower than that of AH. Therefore, in scenarios with high security requirements, AH and ESP can be used together. When AH and ESP are used together, ESP is used prior to AH because of the following reason: AH authenticates the entire IP packet. The ESP header and tail change the length of the IP packet, and the filling fields of ESP also change the length of the IP packet. If AH is used prior to ESP, AH authentication fails.