pub struct MlsContext { /* private fields */ }Expand description
An SFrame context keyed by MLS epochs.
Every member derives its keys from the epoch’s exported secret and its own KIDs
(MlsKeyIdLayout): the KIDs with this member’s index encrypt, all the others decrypt.
Keys are derived on demand. A decryption key is kept only once a ciphertext has
authenticated with it, so forged KIDs do not fill the store.
A new epoch whose low E bits equal an older one’s replaces it, with every key derived
from the older one (RFC 9605 section 5.2). An epoch at or below one already introduced with
the same low bits is refused, so a removed epoch cannot come back with its counters at 0.
Implementations§
Source§impl MlsContext
impl MlsContext
Sourcepub fn new(
suite: CipherSuite,
provider: Arc<dyn RTCCryptoProvider>,
layout: MlsKeyIdLayout,
sender_index: u64,
) -> Result<Self>
pub fn new( suite: CipherSuite, provider: Arc<dyn RTCCryptoProvider>, layout: MlsKeyIdLayout, sender_index: u64, ) -> Result<Self>
A context for the member at sender_index of the MLS group, with no epoch yet.
Fails with Error::KeyIdLayout when the index does not fit the layout’s S bits.
Sourcepub fn with_config(
suite: CipherSuite,
provider: Arc<dyn RTCCryptoProvider>,
layout: MlsKeyIdLayout,
sender_index: u64,
config: SFrameConfig,
) -> Result<Self>
pub fn with_config( suite: CipherSuite, provider: Arc<dyn RTCCryptoProvider>, layout: MlsKeyIdLayout, sender_index: u64, config: SFrameConfig, ) -> Result<Self>
new with explicit options for the underlying SFrameContext.
Sourcepub fn set_max_keys(&mut self, max_keys: usize)
pub fn set_max_keys(&mut self, max_keys: usize)
Sets how many derived keys the context holds at most. Beyond it, a KID that needs a new
key fails with Error::TooManyKeys until an epoch is replaced or removed.
Sourcepub fn layout(&self) -> MlsKeyIdLayout
pub fn layout(&self) -> MlsKeyIdLayout
The KID layout.
Sourcepub fn sender_index(&self) -> u64
pub fn sender_index(&self) -> u64
This member’s index in the MLS group.
Sourcepub fn context(&self) -> &SFrameContext
pub fn context(&self) -> &SFrameContext
The underlying context: its cipher suite, statistics and stored keys.
Sourcepub fn has_epoch(&self, epoch: u64) -> bool
pub fn has_epoch(&self, epoch: u64) -> bool
Whether epoch has been introduced and not removed or replaced.
Sourcepub fn add_epoch(&mut self, epoch: u64, base_key: &[u8]) -> Result<()>
pub fn add_epoch(&mut self, epoch: u64, base_key: &[u8]) -> Result<()>
Introduces epoch with its exported secret (see MLS_EXPORTER_LABEL).
An older epoch with the same low E bits is removed, with all its keys. Introducing an
epoch again with the same secret changes nothing. Fails with Error::StaleEpoch when
epoch is older than the one its low bits already stand for, was removed, or comes with
another secret than before.
Sourcepub fn remove_epoch(&mut self, epoch: u64) -> bool
pub fn remove_epoch(&mut self, epoch: u64) -> bool
Removes epoch, its secret and every key derived from it. Returns whether it was
there. The epoch cannot be introduced again.
Sourcepub fn key_id(&self, epoch: u64, context: u64) -> Result<u64>
pub fn key_id(&self, epoch: u64, context: u64) -> Result<u64>
The KID this member sends with in epoch for its context value.
Sourcepub fn encrypt(
&mut self,
epoch: u64,
context: u64,
metadata: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt( &mut self, epoch: u64, context: u64, metadata: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>>
Encrypts plaintext as this member in epoch, under the KID of context, and returns
the SFrame ciphertext. Fails with Error::UnknownEpoch when the epoch is not held.
Sourcepub fn encrypt_into(
&mut self,
epoch: u64,
context: u64,
metadata: &[u8],
plaintext: &[u8],
out: &mut Vec<u8>,
) -> Result<Header>
pub fn encrypt_into( &mut self, epoch: u64, context: u64, metadata: &[u8], plaintext: &[u8], out: &mut Vec<u8>, ) -> Result<Header>
encrypt, appending the ciphertext to out.
Sourcepub fn decrypt(&mut self, metadata: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>>
pub fn decrypt(&mut self, metadata: &[u8], ciphertext: &[u8]) -> Result<Vec<u8>>
Decrypts an SFrame ciphertext from another member and returns the plaintext.
The key is found by the KID in the header: the epoch by its low E bits, the sender by
its index. A KID with this member’s own index is refused
(Error::KeyRoleConflict): its keys encrypt only.