Skip to main content

Crate rtci_sframe

Crate rtci_sframe 

Source
Expand description

SFrame for the Sans-I/O WebRTC stack.

Secure Frame (RFC 9605) is authenticated encryption for media that stays end-to-end when the transport is not: a selective forwarding unit terminates SRTP and still cannot read or alter what SFrame protects. An SFrame ciphertext is a short header (a key id and a counter), the encrypted data and an authentication tag; it is produced from a whole encoded frame or from one packet’s payload, and travels as the payload of whatever carries the media.

The crate does no I/O, reads no clock and runs no key exchange. The application brings the keys (base_key values labelled with a KID) from its key management, and decides what a ciphertext covers and how it is packetized.

§Structure

§Example

use rtci_sframe::{CipherSuite, Error, SFrameContext};

let suite = CipherSuite::Aes128CtrHmacSha256_80;
let base_key = b"sixteen byte key"; // from the application's key management

let mut alice = SFrameContext::with_default_provider(suite)?;
alice.add_send_key(1, base_key)?;
let mut bob = SFrameContext::with_default_provider(suite)?;
bob.add_recv_key(1, base_key)?;

// The metadata is authenticated but not sent in the ciphertext.
let ciphertext = alice.encrypt(1, b"metadata", b"an encoded frame")?;
assert_eq!(ciphertext.len(), 1 + b"an encoded frame".len() + suite.tag_len());
assert_eq!(bob.decrypt(b"metadata", &ciphertext)?, b"an encoded frame");

// A ciphertext is accepted once.
assert!(matches!(
    bob.decrypt(b"metadata", &ciphertext),
    Err(Error::Replayed { kid: 1, ctr: 0 })
));

§What stays with the application

RFC 9605 leaves these to the application, and so does this crate: that a base_key has one sender, and that a (base_key, KID) pair is never installed for sending twice (section 9.1); the key exchange and when keys change (sections 5, 7.3 and 9.2); what goes into the metadata, and that nothing uses it before decryption has authenticated it (section 9.4); and reassembling a ciphertext that was sent in several packets (section 4.4.4).

Re-exports§

pub use crypto;

Structs§

Header
An SFrame header (RFC 9605 section 4.3): the key id that selects the key and the counter the nonce is built from.
MlsContext
An SFrame context keyed by MLS epochs.
MlsKeyId
The parts of an MLS KID.
MlsKeyIdLayout
The KID layout of an MLS-keyed session (RFC 9605 section 5.2, Figure 8).
PendingCiphertext
A ciphertext waiting for its key, with the metadata it has to be decrypted with.
PendingCiphertexts
Ciphertexts that failed with Error::UnknownKeyId, kept to be decrypted once the key is there.
SFrameConfig
Options of an SFrameContext.
SFrameContext
An SFrame context (RFC 9605 Appendix A): one cipher suite, and the keys known for each KID.
SFrameStats
Counts of what a context has done, for an application that watches for the brute-force signal of RFC 9605 section 7.5 (an elevated rate of failures against a short tag).
SenderKeyId
The parts of a sender-keys KID.
SenderKeyIdLayout
The KID layout of the sender-keys scheme (RFC 9605 section 5.1, Figure 7).
SenderKeyRatchet
One sender’s key at a point of its ratchet: the key generation, the ratchet step and the base_key there.
SenderKeyReceiver
The receiving side of one sender in the sender-keys scheme.
UnknownCipherSuite
The name is not that of a cipher suite this crate implements.

Enums§

CipherSuite
An SFrame cipher suite: the hash used for key derivation and the AEAD used for the frames.
Error
Why an SFrame operation failed.
ErrorKind
The three kinds of decryption failure the W3C Encoded Transform API reports (SFrameTransformErrorEventType).
KeyUsage
What a stored key may be used for. A key has one role for as long as it is stored (RFC 9605 section 4.4.1).

Constants§

DEFAULT_MAX_MLS_KEYS
The number of derived keys an MlsContext holds unless told otherwise.
DEFAULT_MAX_RATCHET_STEPS
How many ratchet steps a SenderKeyReceiver follows for one ciphertext unless told otherwise.
DEFAULT_REPLAY_WINDOW
The window a receiving key gets unless the configuration says otherwise, in counter values.
DEFAULT_RETAINED_OLD_KEYS
How many keys older than the current one a SenderKeyReceiver keeps unless told otherwise.
MAX_HEADER_LEN
The longest SFrame header: the config byte, an 8-byte KID and an 8-byte CTR.
MAX_REPLAY_WINDOW
The largest window a key can be given, in counter values (8 KiB of state per key).
MLS_EXPORTER_LABEL
The label of the MLS exporter call that yields an epoch’s SFrame base_key: base_key = MLS-Exporter("SFrame 1.0 Base Key", "", AEAD.Nk), with AEAD.Nk being CipherSuite::key_len.
NONCE_LEN
The size in bytes of every SFrame nonce (AEAD.Nn): 12 for all registered suites.

Functions§

derive_ssrc_key
draft-ietf-avtcore-rtp-sframe-03 section 7, the per-SSRC key of an RTP stream (Nh bytes), the initial base_key of that SSRC’s SFrame keys (and of its ratchet, section 8):
ratchet_base_key
One step of the sender-key ratchet of RFC 9605 section 5.1: the next base_key, Nh bytes.

Type Aliases§

Result
A specialized Result for SFrame operations.