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
SFrameContext: the key store and the two operations,encryptanddecrypt. A key is added for sending or for receiving and keeps that role; a sending key owns its counter, so a (key, nonce) pair is never used twice; a receiving key has an anti-replay window.CipherSuite: the five suites of RFC 9605 and the three AES-256-CTR suites of the IANA registry.Header: the SFrame header codec.SenderKeyIdLayout,SenderKeyRatchet,SenderKeyReceiver,ratchet_base_key: the sender-keys scheme of section 5.1.MlsKeyIdLayout,MlsContext: SFrame keyed from MLS epochs, section 5.2. The application runs MLS and supplies each epoch’s exported secret.PendingCiphertexts: a bounded store for ciphertexts whose key has not arrived yet.
§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.
- MlsKey
Id - The parts of an MLS KID.
- MlsKey
IdLayout - The KID layout of an MLS-keyed session (RFC 9605 section 5.2, Figure 8).
- Pending
Ciphertext - A ciphertext waiting for its key, with the metadata it has to be decrypted with.
- Pending
Ciphertexts - Ciphertexts that failed with
Error::UnknownKeyId, kept to be decrypted once the key is there. - SFrame
Config - Options of an
SFrameContext. - SFrame
Context - An SFrame context (RFC 9605 Appendix A): one cipher suite, and the keys known for each KID.
- SFrame
Stats - 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).
- Sender
KeyId - The parts of a sender-keys KID.
- Sender
KeyId Layout - The KID layout of the sender-keys scheme (RFC 9605 section 5.1, Figure 7).
- Sender
KeyRatchet - One sender’s key at a point of its ratchet: the key generation, the ratchet step and the
base_keythere. - Sender
KeyReceiver - The receiving side of one sender in the sender-keys scheme.
- Unknown
Cipher Suite - The name is not that of a cipher suite this crate implements.
Enums§
- Cipher
Suite - An SFrame cipher suite: the hash used for key derivation and the AEAD used for the frames.
- Error
- Why an SFrame operation failed.
- Error
Kind - 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
MlsContextholds unless told otherwise. - DEFAULT_
MAX_ RATCHET_ STEPS - How many ratchet steps a
SenderKeyReceiverfollows 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
SenderKeyReceiverkeeps 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), withAEAD.NkbeingCipherSuite::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 (
Nhbytes), the initialbase_keyof 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,Nhbytes.
Type Aliases§
- Result
- A specialized
Resultfor SFrame operations.