P11.46.1 The Replay Window

MediumImplementIcarus Verilog · serverReview the topic

An attacker records a good frame and sends it again. Its ICV still fits. Write the check that catches it, and the counts a network manager reads.

Hardware context: An Ethernet MAC and physical coding sublayer: frame builder and checker, reconciliation sublayer and block encoder. Build, check and pace Ethernet frames, and code them for the physical layer as IEEE 802.3 specifies.

A MACsec receiver keeps two numbers for each secure association: nextPN and the lowest acceptable PN.

Write that receiver for one SA: sa_start, sa_frame, sa_update and three functions that read its state.

sa_frame takes one frame that has reached the SA. It says if the frame is delivered and which count goes up.

The order of the checks is the standard's (10.6.2 to 10.6.5, Figure 10-4). The table below gives it, top to bottom.

The cipher is not part of this problem. The bench tells you in icv_ok whether the ICV fits.

This is a model: one call for each frame, and nothing waits between the checks.

Course choice: a PN field of 0 counts as 2^32 in every comparison. The text says so for InPktsDelayed only (10.6.5 b).

Figure 10-4 writes its first late test as PN(rx.pn), a conversion it does not define.

More course choices: the codes for validateFrames and for the counts, and the reading functions.

Counts of 32 bits that start at 0 with a new SA follow 10.7.13 and the per-SA counters of 13.6.

The tests never put the lowest acceptable PN above nextPN.

Signals in the Timeline

SignalWidthRole
test_number8input of each check
Full specification
Signatures (keep them)
function automatic void sa_start(input [1:0] validate_frames, input bit replay_protect, input [31:0] replay_window, input [32:0] next_pn, input [32:0] lowest_pn);
function automatic void sa_update(input [32:0] next_pn, input [32:0] lowest_pn);
function automatic [3:0] sa_frame(input [31:0] pn_field, input bit icv_ok, input bit cbit);
function automatic [32:0] sa_next_pn();
function automatic [32:0] sa_lowest_pn();
function automatic [31:0] sa_count(input int which);
ItemRule
sa_starta new SA with these settings and these two packet numbers. All six counts are 0
validate_frames0 Disabled, 1 Check, 2 Strict (10.7.8). Null is not used: such a frame never reaches an SA
replay_window0 to 2^32 − 1 (10.7.8)
next_pn, lowest_pn33 bits each: 1 to 2^32, and nextPN can reach 2^32 + 1
pn_fieldthe four PN octets of the SecTAG. The frame's PN is this value, and 2^32 if it is 0
icv_okwhat the cipher would answer: 1 if the ICV fits
Valida frame is valid if validateFrames is not Disabled and icv_ok is 1. With Disabled the cipher is not asked (10.6.3)
Check 1 (10.6.2, 10.6.4)replay_protect is 1 and PN < lowest acceptable PN: discarded, InPktsLate
Check 2 (10.6.5)else, not valid, and validateFrames is Strict or cbit is 1: discarded, InPktsNotValid
Check 3 (10.6.5 a)else, not valid, and validateFrames is Check: delivered, InPktsInvalid
Check 4 (10.6.5 b)else, PN < lowest acceptable PN: delivered, InPktsDelayed
Check 5 (10.6.5 c)else, not valid: delivered, InPktsUnchecked
Check 6 (10.6.5 d)else: delivered, InPktsOK
nextPN (10.6.5)a delivered frame that is valid and has PN ≥ nextPN sets nextPN to PN + 1. No other frame changes it
Lowest acceptable PN (10.6.5)when nextPN has been set: the greater of its old value and nextPN − replay_window. That difference can be below 0
sa_frame returns{delivered, count}: bit 3 is 1 if the frame is delivered, bits 2:0 name the count that went up
count1 InPktsOK, 2 InPktsUnchecked, 3 InPktsInvalid, 4 InPktsNotValid, 5 InPktsDelayed, 6 InPktsLate
sa_update (10.7.15)each of the two numbers becomes the greater of its old value and the value given
sa_count(which)the count with that number, 32 bits wide, since the last sa_start

Random tests compare every result, both packet numbers and all six counts with a private model after each call.

Examples

Example 1

A Frame That Comes Too Late
Input
window 0: PN 1, 2, 5, then 3
Output
delivered = 0, count = 6, next_pn = 6, lowest_pn = 6

PN 5 moved nextPN to 6, and the lowest acceptable PN with it. PN 3 is below it: discarded, InPktsLate (count 6).

Example 2

The Same Frames with a Window of 3
Input
window 3: PN 1, 2, 5, then 3
Output
delivered = 1, count = 1, next_pn = 6, lowest_pn = 3

Now the lowest acceptable PN is 6 − 3 = 3. PN 3 is not below it: delivered, InPktsOK (count 1). nextPN stays 6.

Example 3

A Frame Whose ICV Does Not Fit
Input
window 0: PN 1 and 2, then PN 9 with a wrong ICV
Output
delivered = 0, count = 4, next_pn = 3, lowest_pn = 3

Strict discards it: InPktsNotValid (count 4). It moves nothing: nextPN stays 3.

Constraints and Contract

  • Keep the six names and their arguments.
  • You may add helper functions and variables.
  • Declare your variables at the top of a function, not inside a loop, and do not return from inside a loop.
  • A full check calls sa_frame about 30,000 times. Compare and count with the operators of the language (<, >=, +).
  • A loop over the bits of a number in every call can take more than the 12 s limit on the server.
  • Do not call a variable cell, use, before, cross or small: they are reserved words (IEEE 1800 Annex B).
  • Off limits: the names ref_m, rng, tb, root, names that begin with fx_ and the modules of the bench.
  • The fixture's own names are off limits to keep an answer from reading the expected values.

Hints

Hint 1

Which is larger: a PN field of 32'hffff_ffff or nextPN after that frame? How many bits does nextPN need?

Hint 2

Work the six checks in the order of the table. The first one that holds decides.

Hint 3

nextPN is 3 and the window is 10. What is nextPN − replayWindow, and what does an unsigned subtraction make of it?

Hint 4

A frame fails the cipher's check but is delivered. May it move nextPN?

Hint 5

With Disabled, can any frame be valid?

Hint 6

After a wrong random row, read the two fields that name the kind of event and what was wrong first.

What the grader checks: A bench model of one receive SA: one call a frame, and nothing queued between the checks. The cipher's answer is given as one bit. The scripted calls take their expected values from a JavaScript model. Six more tests run random streams seeded by the judge: 2,880 calls. After each call they compare the result, both packet numbers and all six counts with a private model. Long runs take each count past 255 and past 4,095. A count that wraps at 65,536 or later is not caught: such a run would cost too much time. A PN field of 0 as 2^32 outside InPktsDelayed, the codes, the 32-bit counts and the cleared counts are course choices. Not graded: validateFrames Null, frames without a SecTAG or with a bad one, an unknown SC, an SA not in use. Also not graded: InPktsOverrun, the octet counts, extended packet numbering and the cipher.

71 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 1 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

A Frame That Comes Too Late

Input
window 0: PN 1, 2, 5, then 3
Expected output
delivered = 0, count = 6, next_pn = 6, lowest_pn = 6

PN 5 moved nextPN to 6, and the lowest acceptable PN with it. PN 3 is below it: discarded, InPktsLate (count 6).

Run samples executes all 3 public checks. Check all tests runs 71 checks on the server.

Icarus Verilog · server