Skip to main content

rtc_srtp/
lib.rs

1#![warn(rust_2018_idioms)]
2#![warn(missing_docs)]
3#![allow(dead_code)]
4
5//! SRTP and SRTCP for the Sans-I/O WebRTC stack.
6//!
7//! The Secure Real-time Transport Protocol ([RFC 3711]) as WebRTC keys it: protection
8//! profiles negotiated through DTLS-SRTP ([RFC 5764]), with keying material exported from
9//! the DTLS handshake rather than signalled.
10//!
11//! # Structure
12//!
13//! * [`context`] — [`Context`](context::Context), the encrypt/decrypt state for one
14//!   direction: `encrypt_rtp`/`decrypt_rtp` and the RTCP equivalents, plus the replay
15//!   protection and rollover-counter tracking the RFC requires.
16//! * [`protection_profile`] — the negotiable profiles (AES-128-CM-SHA1-80,
17//!   AEAD-AES-128-GCM, and friends) and their key/salt lengths.
18//! * [`config`], [`option`] — how a context is built, including replay-window sizing.
19//!
20//! # Example
21//!
22//! A profile is negotiated through DTLS-SRTP, and it fixes the key, salt and tag sizes the
23//! context will use:
24//!
25//! ```
26//! use rtc_srtp::protection_profile::ProtectionProfile;
27//!
28//! let profile = ProtectionProfile::Aes128CmHmacSha1_80;
29//! assert_eq!(profile.key_len(), 16); // AES-128
30//! assert_eq!(profile.salt_len(), 14);
31//! assert_eq!(profile.rtp_auth_tag_len(), 10); // 80-bit tag
32//!
33//! // The AEAD profiles authenticate inside the cipher, so they carry no HMAC key.
34//! assert_eq!(ProtectionProfile::AeadAes128Gcm.auth_key_len(), 0);
35//! ```
36//!
37//! Most applications do not depend on this crate directly — the
38//! [`rtc`](https://docs.rs/rtc) crate creates the contexts from the DTLS handshake and
39//! applies them to media as one layer of the peer-connection pipeline.
40//! Applications constructing contexts directly can select cryptography explicitly with
41//! [`context::Context::new`]; [`context::Context::new`] retains default-provider
42//! compatibility.
43//!
44//! [RFC 3711]: https://datatracker.ietf.org/doc/html/rfc3711
45//! [RFC 5764]: https://datatracker.ietf.org/doc/html/rfc5764
46
47mod cipher;
48
49/// The crypto provider API.
50///
51/// Re-exported because this crate's public constructors take an
52/// [`Arc<dyn RTCCryptoProvider>`](crypto::RTCCryptoProvider), which a caller must be able to name
53/// without adding — and version-matching — a direct `rtc-crypto` dependency.
54pub use crypto;
55
56/// Session configuration: keys, protection profile, and replay-protection options.
57pub mod config;
58/// The encrypt/decrypt state for one SRTP/SRTCP session.
59pub mod context;
60mod key_derivation;
61/// Per-context options, currently the replay-detector factory.
62pub mod option;
63/// The DTLS-SRTP protection profiles and their key, salt and tag lengths.
64pub mod protection_profile;