Skip to content

net/srtp: Master Key Identifier (MKI) support - #446

Merged
haaspors merged 1 commit into
masterfrom
srtp-mki
Aug 3, 2026
Merged

net/srtp: Master Key Identifier (MKI) support#446
haaspors merged 1 commit into
masterfrom
srtp-mki

Conversation

@haaspors

@haaspors haaspors commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Implements RFC 3711 Master Key Identifier (MKI) support, closing #441.

What

A crypto context now holds a list of master keys, each tagged with an MKI, instead of a single key. On protect the active send key's MKI is written between the payload (RTP) / SRTCP index and the auth tag; on unprotect the trailing MKI selects the decrypting key. The MKI is left outside the authenticated portion per RFC 3711 §3.1/§3.4, so the existing auth ranges are untouched.

Session keys are derived lazily per stream and re-derived only when the selected key changes, so a key rollover preserves the replay window and packet index — the same crypto context continues (RFC 3711 §8.1). SRTCP unprotect drops replays before selecting the key, so a replayed packet cannot force key derivation.

KDF correctness for rollover

Re-derivation must be independent of the stream index or two peers (at different indices) would derive different keys and break interop with any correct implementation. With KDR 0 — the default — the generation counter r is always 0, so the packet index is no longer mixed into the KDF. Covered by a test that produces byte-identical ciphertext for the same key derived at two different stream indices.

API

  • r_srtp_add_crypto_context_for_ssrc_with_mki / ..._with_filter_with_mki — create an MKI context with its first key (dual recv/send keys, fixed mkisize).
  • r_srtp_add_master_key — stage a rollover key.
  • r_srtp_set_send_master_key — switch the sending key once both peers know it.
  • R_SRTP_MAX_MKI_SIZE.

Master-key material is cleared on teardown.

Testing

New tests cover MKI wire position (RTP + SRTCP), two-key rollover via set_send, index-independent rollover derivation, unknown-MKI rejection, and the invalid-argument matrix. Validated on the linux and ASan tiers (both warning-free); full suite 2334 passed / 0 failed.

🤖 Generated with Claude Code

A crypto context now holds a list of master keys, each tagged with an MKI,
rather than a single key. On protect the active send key's MKI is written
after the payload (RTP) or the SRTCP index, ahead of the auth tag; on
unprotect that MKI selects the decrypting key. The MKI is left outside the
authenticated portion (RFC 3711 3.1/3.4), so the existing auth ranges are
unchanged.

Session keys are derived lazily per stream and re-derived only when the
selected key changes, so a rollover keeps the replay window and packet index
-- the same crypto context continues (RFC 3711 8.1). For that re-derivation
to agree between peers it must not depend on the stream index: with KDR 0 the
generation counter is always 0, so the packet index no longer enters the KDF.
SRTCP unprotect drops replays before selecting the key, so a replayed packet
cannot force key derivation.

New API: r_srtp_add_crypto_context_{for_ssrc,with_filter}_with_mki create an
MKI context with its first key, r_srtp_add_master_key stages a rollover key,
and r_srtp_set_send_master_key switches the sending key.

Closes #441

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@haaspors
haaspors merged commit ba7e995 into master Aug 3, 2026
18 checks passed
@haaspors
haaspors deleted the srtp-mki branch August 3, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant