~/ learn/ comp-400/ cards/ IPsec: security associations and the ESP packet
1 of 9

Compute ESP overhead: given a protected payload length and a 16-byte cipher block, print the padding needed, the trailer size, and the total added bytes in transport mode versus tunnel mode (tunnel adds a 20-byte outer IPv4 header).

Compute ESP overhead: given a protected payload length and a 16-byte cipher block, print the padding needed, the trailer size, and the total added bytes in transport mode versus tunnel mode (tunnel adds a 20-byte outer IPv4 header).

Answer

ESP_HEADER = 8 ICV = 12 OUTER_IPV4 = 20 def esp_overhead(payload, block=16, mode='transport'): trailer_fixed = 2 pad = (-(payload + trailer_fixed)) % block trailer = pad + trailer_fixed outer = OUTER_IPV4 if mode == 'tunnel' else 0 return pad, trailer, ESP_HEADER + trailer + ICV + outer for mode in ('transport', 'tunnel'): for payload in (100, 1000): pad, trailer, total = esp_overhead(payload, mode=mode) print(mode, payload, 'pad', pad, 'trailer', trailer, 'overhead', total)

Stallings & Brown 5e ch22 §22.5; RFC 4301; RFC 4303

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/74532c35-90eb-43eb-b60f-1e7f5add8075/flashcard utf-8 LF