rtci-sframe
Sans-I/O SFrame (RFC 9605) end-to-end media encryption. 1 public module, 30 items at 0.5.0.
cargo add [email protected] · crates.io · docs.rs · README on GitHub· MSRV 1.89
README
SFrame (RFC 9605) for the Sans-I/O WebRTC stack: authenticated encryption of 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.
The crate does no I/O, reads no clock and runs no key exchange. The application brings the keys from its key management, and decides what a ciphertext covers (a whole encoded frame, or one packet's payload) and how it is packetized.
use rtci_sframe::{CipherSuite, SFrameContext};
let suite = CipherSuite::Aes128GcmSha256_128;
let base_key = [0x2a; 16]; // from the application's key management
let mut sender = SFrameContext::with_default_provider(suite)?;
sender.add_send_key(7, &base_key)?;
let mut receiver = SFrameContext::with_default_provider(suite)?;
receiver.add_recv_key(7, &base_key)?;
let ciphertext = sender.encrypt(7, b"metadata", b"an encoded frame")?;
assert_eq!(receiver.decrypt(b"metadata", &ciphertext)?, b"an encoded frame");
What is implemented
- The SFrame header (section 4.3), key derivation (4.4.2), encryption and decryption (4.4.3, 4.4.4).
- Every registered cipher suite:
AES_128_CTR_HMAC_SHA256_80/_64/_32,AES_128_GCM_SHA256_128,AES_256_GCM_SHA512_128(RFC 9605), andAES_256_CTR_HMAC_SHA512_80/_64/_32(RFC 10079, IANA values 0x0006 to 0x0008, listed by the W3C Encoded Transform API), checked against RFC 10079 Appendix A.2. - A key store in which a key encrypts or decrypts, never both. A sending key owns its counter: a (key, nonce) pair is never used twice, and a key that has used every counter stops.
- Anti-replay per receiving key (section 9.3), on by default.
- The sender-keys scheme (section 5.1): KID layout, ratchet, and a receiver that follows the sender's ratchet only once a ciphertext has authenticated under the new key.
- MLS-keyed contexts (section 5.2): KID layout, keys derived on demand from the epoch secret the application exports, old epochs removed when their low bits are reused. No MLS here.
- A bounded store for ciphertexts whose key has not arrived yet.
Every test vector of RFC 9605 Appendix C is checked byte for byte.
What stays with the application
That a base key has one sender and a (base key, KID) pair is installed for sending once; the key exchange and when keys change; what goes into the metadata; packetizing a ciphertext and reassembling it, unless it lets the engine do so: the SFrame RTP payload format (draft-ietf-avtcore-rtp-sframe-03) is in rtci-rtp (codec::sframe), and the root crate (rtci) negotiates it (a=sframe) and applies it to a transceiver's packets.
Scalable video: RFC 9605 section 6.1.3 makes the sender put each layer in its own ciphertext, so that a forwarder can drop layers. This crate encrypts what it is given; the root crate's rtp_transceiver::sframe_transform (RTCRtpSFrameEncryptor::set_scalability, transform_access_unit, transform_layer_frame, join_layer_frames) splits VP9 superframes and AV1 temporal units into their spatial layers, and its module documentation says how an application hands layer frames.
Specifications
RFC 9605 and the SFrame parts of draft-ietf-avtcore-rtp-sframe-03; clause-by-clause status in rfc9605 and draft-ietf-avtcore-rtp-sframe.
Cryptography
All of it goes through rtci-crypto's provider (crypto-ring by default, crypto-aws-lc-rs): AES-CTR, AES-GCM and HMAC from the provider, HKDF built on its HMAC. Tags are compared in constant time, and this crate's copies of base keys and derived key material are erased when dropped.
Licence
Licensed under either of the MIT licence or the Apache License, Version 2.0, at your option.
This crate is part of the rtci workspace, which descends from webrtc-rs/rtc and is developed independently; FORK.md lists what it carries over upstream. Upstream's licence and copyright notices are retained.
rtci_sframe
SFrame for the Sans-I/O WebRTC stack.
- struct
Headerfromheader::HeaderAn SFrame header (RFC 9605 section 4.3): the key id that selects the key and the counter the nonce is built from. - struct
MlsContextfrommls::MlsContextAn SFrame context keyed by MLS epochs. - struct
PendingCiphertextfrompending::PendingCiphertextA ciphertext waiting for its key, with the metadata it has to be decrypted with. - struct
PendingCiphertextsfrompending::PendingCiphertextsCiphertexts that failed withError::UnknownKeyId, kept to be decrypted once the key is there. - struct
SenderKeyRatchetfromsender_key::SenderKeyRatchetOne sender's key at a point of its ratchet: the key generation, the ratchet step and thebase_keythere. - struct
SenderKeyReceiverfromsender_key::SenderKeyReceiverThe receiving side of one sender in the sender-keys scheme. - struct
SFrameConfigfromcontext::SFrameConfigOptions of anSFrameContext. - struct
SFrameContextfromcontext::SFrameContextAn SFrame context (RFC 9605 Appendix A): one cipher suite, and the keys known for each KID. - struct
SFrameStatsfromcontext::SFrameStatsCounts 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). - struct
UnknownCipherSuitefromcipher_suite::UnknownCipherSuiteThe name is not that of a cipher suite this crate implements. - enum
CipherSuitefromcipher_suite::CipherSuiteAn SFrame cipher suite: the hash used for key derivation and the AEAD used for the frames. - enum
Errorfromerror::ErrorWhy an SFrame operation failed. - enum
ErrorKindfromerror::ErrorKindThe three kinds of decryption failure the W3C Encoded Transform API reports (SFrameTransformErrorEventType). - enum
KeyUsagefromcontext::KeyUsageWhat 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). - fn
derive_ssrc_keyfromkdf::derive_ssrc_keydraft-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): - fn
ratchet_base_keyfromkdf::ratchet_base_keyOne step of the sender-key ratchet of RFC 9605 section 5.1: the nextbase_key,Nhbytes. - type
Resultfromerror::ResultA specializedResultfor SFrame operations. - const
DEFAULT_MAX_MLS_KEYSfrommls::DEFAULT_MAX_MLS_KEYSThe number of derived keys anMlsContextholds unless told otherwise. - const
DEFAULT_MAX_RATCHET_STEPSfromsender_key::DEFAULT_MAX_RATCHET_STEPSHow many ratchet steps aSenderKeyReceiverfollows for one ciphertext unless told otherwise. - const
DEFAULT_REPLAY_WINDOWfromreplay::DEFAULT_REPLAY_WINDOWThe window a receiving key gets unless the configuration says otherwise, in counter values. - const
DEFAULT_RETAINED_OLD_KEYSfromsender_key::DEFAULT_RETAINED_OLD_KEYSHow many keys older than the current one aSenderKeyReceiverkeeps unless told otherwise. - const
MAX_HEADER_LENfromheader::MAX_HEADER_LENThe longest SFrame header: the config byte, an 8-byte KID and an 8-byte CTR. - const
MAX_REPLAY_WINDOWfromreplay::MAX_REPLAY_WINDOWThe largest window a key can be given, in counter values (8 KiB of state per key). - const
MLS_EXPORTER_LABELfrommls::MLS_EXPORTER_LABELThe label of the MLS exporter call that yields an epoch's SFramebase_key:base_key = MLS-Exporter("SFrame 1.0 Base Key", "", AEAD.Nk), withAEAD.NkbeingCipherSuite::key_len. - const
NONCE_LENfromcipher_suite::NONCE_LENThe size in bytes of every SFrame nonce (AEAD.Nn): 12 for all registered suites. - use
crypto - use
MlsKeyIdfromkey_id::MlsKeyId - use
MlsKeyIdLayoutfromkey_id::MlsKeyIdLayout - use
SenderKeyIdfromkey_id::SenderKeyId - use
SenderKeyIdLayoutfromkey_id::SenderKeyIdLayout
Generated from the sources of rtci-sframe 0.5.0 at its release tag. Items made by macros and methods are on docs.rs.