1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! SRTP and SRTCP for the Sans-I/O WebRTC stack.
//!
//! The Secure Real-time Transport Protocol ([RFC 3711]) as WebRTC keys it: protection
//! profiles negotiated through DTLS-SRTP ([RFC 5764]), with keying material exported from
//! the DTLS handshake rather than signalled.
//!
//! # Structure
//!
//! * [`context`] — [`Context`](context::Context), the encrypt/decrypt state for one
//! direction: `encrypt_rtp`/`decrypt_rtp` and the RTCP equivalents, plus the replay
//! protection and rollover-counter tracking the RFC requires.
//! * [`protection_profile`] — the negotiable profiles (AES-128-CM-SHA1-80,
//! AEAD-AES-128-GCM, and friends) and their key/salt lengths.
//! * [`config`], [`option`] — how a context is built, including replay-window sizing.
//! * [`keying`] — master keys over time: the key derivation rate, the MKI and the master-key
//! table, key lifetimes, and the events that tell the application to re-key.
//! * [`cryptex`] ([RFC 9335]) and [`header_extension`] ([RFC 6904]) — the two ways to encrypt
//! RTP header extensions.
//!
//! # Key material
//!
//! Every struct holding secret key material derives `Zeroize` and `ZeroizeOnDrop`, or holds
//! each secret in a type that does (`rtci_crypto::SecretVec`, `zeroize::Zeroizing`), and
//! key material is never built in a buffer that grows (a growing `Vec` frees its old allocation
//! as it is). What a provider's own objects keep is the provider's to erase: the ring provider
//! does not erase its AES-GCM keys, the AWS-LC
//! provider does. `docs/key-erasure.md` lists every secret, where it lives and which test
//! checks it.
//!
//! # Transforms
//!
//! AES-128 counter mode with HMAC-SHA1 (the default of [RFC 3711]), AES-192 and AES-256
//! counter mode ([RFC 6188]), the NULL cipher with HMAC-SHA1 (mandatory to implement in RFC
//! 3711, never used by WebRTC), and AEAD_AES_128_GCM / AEAD_AES_256_GCM ([RFC 7714]). AES-f8
//! (RFC 3711 section 4.1.2, optional) is not implemented.
//!
//! # Example
//!
//! A profile is negotiated through DTLS-SRTP, and it fixes the key, salt and tag sizes the
//! context will use:
//!
//! ```
//! use rtci_srtp::protection_profile::ProtectionProfile;
//!
//! let profile = ProtectionProfile::Aes128CmHmacSha1_80;
//! assert_eq!(profile.key_len(), 16); // AES-128
//! assert_eq!(profile.salt_len(), 14);
//! assert_eq!(profile.rtp_auth_tag_len(), 10); // 80-bit tag
//!
//! // The AEAD profiles authenticate inside the cipher, so they carry no HMAC key.
//! assert_eq!(ProtectionProfile::AeadAes128Gcm.auth_key_len(), 0);
//! ```
//!
//! Most applications do not depend on this crate directly — the
//! [`rtci`](https://docs.rs/rtci) crate creates the contexts from the DTLS handshake and
//! applies them to media as one layer of the peer-connection pipeline.
//! Applications constructing contexts directly can select cryptography explicitly with
//! [`context::Context::new`]; [`context::Context::new`] retains default-provider
//! compatibility.
//!
//! [RFC 3711]: https://datatracker.ietf.org/doc/html/rfc3711
//! [RFC 5764]: https://datatracker.ietf.org/doc/html/rfc5764
//! [RFC 6188]: https://datatracker.ietf.org/doc/html/rfc6188
//! [RFC 6904]: https://datatracker.ietf.org/doc/html/rfc6904
//! [RFC 7714]: https://datatracker.ietf.org/doc/html/rfc7714
//! [RFC 9335]: https://datatracker.ietf.org/doc/html/rfc9335
/// The crypto provider API.
///
/// Re-exported because this crate's public constructors take an
/// [`Arc<dyn RTCCryptoProvider>`](crypto::RTCCryptoProvider), which a caller must be able to name
/// without adding — and version-matching — a direct `rtci-crypto` dependency.
pub use crypto;
/// Session configuration: keys, protection profile, and replay-protection options.
/// The encrypt/decrypt state for one SRTP/SRTCP session.
/// Entry points for stateful fuzz targets. Gated behind `cfg(fuzzing)`; not part of the
/// supported API.
/// Per-context options, currently the replay-detector factory.
/// The DTLS-SRTP protection profiles and their key, salt and tag lengths.
/// Helpers shared by the unit tests.
pub