30a7b90034
Per PROTOCOL.md and the Wolf docs; interop with a real host is unverified. Strict, capped parsers throughout, shared helpers in util.rs. Where PROTOCOL.md says UNKNOWN the Wolf-documented behaviour is used. The audio receiver waits for the jitter budget before rebuilding a missing packet, so a late packet beats a rebuilt one.
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
//! The per-session stream key handed to the host in `launch` / `resume` (`docs/PROTOCOL.md` 1.4, 7).
|
|
|
|
use core::fmt;
|
|
|
|
use crate::{RandomSource, Result};
|
|
|
|
/// Length of `rikey` in bytes (AES-128).
|
|
pub const RIKEY_LEN: usize = 16;
|
|
|
|
/// The stream key pair of one session: `rikey` (AES-128 key for control, audio and video) and `rikeyid`
|
|
/// (feeds the audio IV).
|
|
///
|
|
/// A fresh pair is generated for every launch and resume, because the GCM nonce counters restart per session.
|
|
/// `Debug` never prints the key.
|
|
#[derive(Clone, PartialEq, Eq)]
|
|
pub struct SessionKeys {
|
|
/// AES-128 key, sent hex-encoded as the `rikey` launch parameter.
|
|
pub rikey: [u8; RIKEY_LEN],
|
|
/// Key id, sent as the decimal `rikeyid` launch parameter.
|
|
pub rikeyid: u32,
|
|
}
|
|
|
|
impl SessionKeys {
|
|
/// Draws a fresh key and key id from `rng`.
|
|
///
|
|
/// # Errors
|
|
/// None today; the `Result` leaves room for a fallible source.
|
|
pub fn generate(rng: &mut dyn RandomSource) -> Result<Self> {
|
|
let mut rikey = [0u8; RIKEY_LEN];
|
|
rng.fill(&mut rikey);
|
|
let mut id = [0u8; 4];
|
|
rng.fill(&mut id);
|
|
Ok(Self { rikey, rikeyid: u32::from_le_bytes(id) })
|
|
}
|
|
}
|
|
|
|
impl fmt::Debug for SessionKeys {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.debug_struct("SessionKeys").field("rikey", &"<redacted>").field("rikeyid", &self.rikeyid).finish()
|
|
}
|
|
}
|