Skip to main content

Module replay_window

Module replay_window 

Source
Available on crate feature std only.
Expand description

Bitmap-based sliding-window replay detection (RFC 4303 § 3.4.3 / IPsec ESP).

Per-direction replay protection for the data plane (① — Phase 4). Tracks the highest accepted packet number plus a 1024-bit bitmap covering [high - 1024 + 1, high], rejecting duplicates and out-of-window-old packets.

§Why this exists if the AEAD already prevents replay

The AEAD nonce is nonce_prefix || header.packet_number — derived from the authenticated u64 packet number in the wire header, not an internal counter. A replayed packet therefore reuses a nonce + AAD that the receiver has already opened, but the AEAD open itself does not reject a duplicate (a faithfully-replayed ciphertext still verifies). This window is what makes replay an explicit, observable rejection:

  • Yields the CoreError::ReplayDetected error variant and bumps the replay_rejected_total counter (metrics / detection signal).
  • Enforces freshness on top of confidentiality + integrity: even an exact re-injection of an authentic packet is dropped once.
  • Tolerates legitimate reordering within the window (out-of-order delivery on the reliable transport) while still rejecting true duplicates.

Ordering (Invariant 4): in Session::decrypt_packet the window is consulted after a successful AEAD open, never before — so the window never keys off an attacker-controlled (un-authenticated) packet number, and a spoofed counter cannot drive a timing channel.

§Window semantics

  • WINDOW_BITS = 1024. Bit 0 represents high_watermark; bit i represents high_watermark - i.
  • Sequence numbers strictly greater than high_watermark advance the window (left-shift the bitmap, mark bit 0).
  • Sequence numbers within the window: check the bit; reject if set, accept and set the bit otherwise.
  • Sequence numbers below high_watermark - WINDOW_BITS + 1: too old, reject.

The struct is small (128-byte bitmap + a couple of small words) and intended to be held once per direction under a parking_lot::Mutex.

Structs§

ReplayWindow
Sliding-window replay tracker for one direction’s packet-number space.

Constants§

WINDOW_BITS
Width of the sliding window in bits. 1024 matches RFC 4303’s recommended upper bound and gives us comfortable headroom for severely reordered transports.