Octet

What is the difference between AH and ESP?

Show the answer

Say this first

Both protect IP packets. AH (IP protocol 51) gives integrity and origin authentication over the whole packet, including the fields of the outer IP header that do not change in transit, but it does not encrypt. ESP (IP protocol 50) encrypts and authenticates, but its integrity check does not cover the outer IP header. Because AH signs the addresses, any NAT breaks it. Practically every deployment uses ESP.

Go deeper

ESP packet layout

FieldSize
SPI4 bytes
Sequence number4 bytes
IV16 bytes for AES-CBC, 8 for AES-GCM
Payloadthe protected packet or segment
Padding0 to 255 bytes, to fill the cipher block
Pad length and next header2 bytes
ICV (integrity check)12 bytes for HMAC-SHA1-96, 16 for HMAC-SHA-256-128 and GCM

Everything from the payload through the next header field is encrypted. The SPI and sequence number are in clear because the receiver needs them to find the SA.

Why AH is rare

  • No confidentiality.
  • NAT rewrites the source address, so the AH check fails.
  • If you ever need integrity without encryption, ESP with a null cipher does that and survives NAT traversal.

Traps

  • Saying AH and ESP use port 51 and port 50. They are IP protocol numbers. Only with NAT-T is ESP put inside UDP 4500.
  • Saying ESP authenticates the entire packet. In tunnel mode it covers the original packet, not the new outer header.
How did you do?Book 8.5 Example Systems