Skip to content

feat(internet)!: support ESP Extended Sequence Numbers (#2963) - #3208

Open
JarryShaw wants to merge 1 commit into
developfrom
feat/2963-esp-esn
Open

JarryShaw wants to merge 1 commit into
developfrom
feat/2963-esp-esn

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Please follow the guide below

  • Put an x into every box [ ] that applies to your pull request (like this: [x])

  • Use the Preview tab to see how your pull request will look

  • Searched for similar pull requests

  • Followed the coding style (make pylint, make mypy, make isort)

  • make test passes, and a test case covers the change

  • Described the user-visible change below and left its changelog entry to the maintainer, keeping docs/source/changelog/ and CHANGELOG.md out of the diff, if the change is user-visible: N/A — centralised

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect

  • feat — adds a feature

  • perf — changes performance, not behaviour

  • refactor — changes neither behaviour nor performance

  • test — tests only

  • docs — documentation only

  • ci — workflows or build tooling

  • release — bumps the version or rolls up a distribution

  • chore — anything else

  • Also tick if it regenerates constant or registry tables, members keeping their numeric values (the const label)


Description of your pull request and other information

Closes #2963.

Design. The issue names no preference, so this takes the mechanism RFC 4303 specifies: the receiver "must deduce and track" the high-order bits (§3.4.3, Appendix A2.2); a caller-supplied high word appears nowhere in it and breaks at the first wrap. SecurityAssociation(esn=True, seq=T, window=W) holds Appendix A2's T and W; extend() picks Seqh by A2.2 (mod 2**32, as A2.3 computes it) and advance() moves T (A2.1) on every authentic packet. The high bits follow the trailer in the ICV (§3.3.2.1) and lead the AEAD associated data (RFC 4106 §5, RFC 4309 §5, RFC 4543 §3.3, RFC 7634 §2.1).

RFC 8750's ENCR_AES_CCM_8_IIV, ENCR_AES_GCM_16_IIV and ENCR_CHACHA20_POLY1305_IIV join CIPHER_SUITES through CipherSuite.implicit_iv: no IV on the wire, the nonce is the salt and the 64-bit sequence number (Figures 1 and 2). ESP.info.esn records the number a packet was processed under, and make(esn=) takes it, so a construction and from_data reuse it rather than inferring; seq stays the 32-bit field, so a keyless rebuild, as an outer layer's payload rebuild is, still writes the same octets. Appendix A3's re-synchronisation (a SHOULD whose trigger and retry limit are local) is left out and listed under Known Limitations; an SA joining a capture late is seeded through seq.

Tests. test_esp_esn_2963_unit.py: both A2.2 cases at their edges, an HMAC ICV recomputed with hmac across a 2**32 wrap in one extraction, every ESN packet of draft-mcgrew-gcm-test-01, and CCM, ChaCha20-Poly1305, GMAC, CMAC and implicit-IV packets recomputed with cryptography from each RFC's layout. Every test fails on an untouched origin/develop export. Branch coverage of esp/protocol.py under the ESP tests goes from 98.24% to 98.73%, and corekit/context.py stays at 96.15%. Moved pins: test_esp_unit's suite set, #2958's refused list, test_tier_guard's HAS_CRYPTO set and PYPY_EXCLUSIONS['cryptography'].

Breaking. Building a CipherSuite needs implicit_iv=, and the ESP data model, so to_dict() and every dump, gains esn. make() raises ProtocolError on a seq that does not fit in 32 bits where it wrote it modulo 2**32, and compute_icv/decrypt/encrypt raise it on a seq too wide for the SA, where they raised OverflowError or, under ENCR_NULL, ignored it.

@JarryShaw JarryShaw added feat Pull requests that add a new capability (feat: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 29, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 29, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.10 milestone Nov 29, 2026
@read-the-docs-community

read-the-docs-community Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

@JarryShaw

Copy link
Copy Markdown
Owner Author

Needs changes at 7af80dff3, from a Sonnet cross-review. The code checks out; two fixes and the breaking mark remain.

  • Verified: extend() matched an independent RFC 4303 A2.2 implementation in 20,000 random cases. The ICV and AEAD placement of the high bits matches RFC 4303 §3.3.2.1, RFC 4106, 4309, 4543 and 7634. GCM-IIV, CCM-ESN and HMAC vectors were recomputed independently.
  • Breaking: all four changes are caller-visible under process.rst: CipherSuite(implicit_iv=), the esn field, make(seq=) raising, and OverflowError → ProtocolError. The esn field and the exception change can't be avoided, so the subject gets ! and the PR gets breaking, as feat(internet)!: decrypt and verify the remaining registered ESP transforms (#2958) #3196 did.
  • Fix: with no ESN, make(seq=) still wraps a value from 232 to 264−1 to 32 bits without saying so. It should refuse any seq that cannot read back.
  • Docs: add one line to esp.rst Known Limitations: re-parsing with the same context re-advances the shared SA's T, so a second pass can infer different high bits.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment breaking Breaks public-facing behaviour or API (apply alongside the type label) and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 29, 2026
@JarryShaw JarryShaw changed the title feat(internet): support ESP Extended Sequence Numbers (#2963) feat(internet)!: support ESP Extended Sequence Numbers (#2963) Nov 29, 2026
- SecurityAssociation takes esn, seq and window: extend() infers the
  high-order bits by RFC 4303 Appendix A2.2 from the highest authenticated
  sequence number, which advance() moves on every authentic packet (A2.1)
- the ICV covers the high-order bits after the trailer (s3.3.2.1), and every
  AEAD's associated data leads with them
- RFC 8750's implicit IV suites join CIPHER_SUITES, with
  CipherSuite.implicit_iv; the nonce takes the 64-bit sequence number
- the ESP data model gains esn, and make() takes it as esn, so a
  construction and from_data process under it rather than inferring;
  make() refuses a seq that does not fit in 32 bits instead of wrapping it
- tests: new test_esp_esn_2963_unit; the suite-set, gate and PyPy pins move
@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Nov 29, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Good to go at d7187523f. A Sonnet delta review checked the fold against the full review at 7af80dff3.

  • seq is now strictly the 32-bit field, and the new keyword-only make(esn=) carries the 64-bit number, mirroring the data model.
    • A probe over every combination of context × encrypt × out-of-range and in-range seq/esn found no silent wrap. Every accepted call writes exactly seq, and the rest raise ProtocolError.
  • esn= with no SA is tolerated on purpose. _make_payload rebuilds inner layers without a context, so refusing it would break the keyless IPv4.from_data round trip. The new test pins that round trip byte for byte.
  • The subject carries !, and esp.rst documents re-parsing against a shared SA. The body's Breaking line matches the new seq/esn= contract.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 94.94% (unit tier, Python 3.15, d7187523f, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 116 4 20 2 95.59%
pcapkit/const 22308 224 3168 191 98.27%
pcapkit/corekit 3160 83 1058 40 96.85%
pcapkit/dumpkit 423 3 148 5 98.60%
pcapkit/foundation 4341 24 1362 26 99.12%
pcapkit/interface 112 4 40 3 95.39%
pcapkit/protocols 28684 152 7588 127 99.22%
pcapkit/toolkit 1136 35 406 9 96.24%
pcapkit/utilities 638 7 176 5 98.53%
pcapkit/vendor 6514 2394 1464 256 59.91%

Per-file detail: the coverage-html artifact of this run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks public-facing behaviour or API (apply alongside the type label) feat Pull requests that add a new capability (feat: subject prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

1 participant