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
121
122
123
//! 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, [`encrypt`](SFrameContext::encrypt)
//! and [`decrypt`](SFrameContext::decrypt). 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};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! 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 })
//! ));
//! # Ok(())
//! # }
//! ```
//!
//! # 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).
//!
//! [RFC 9605]: https://www.rfc-editor.org/rfc/rfc9605
/// Entry points for the fuzz targets. Gated behind `cfg(fuzzing)`; not part of the supported
/// API.
/// 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;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;