Skip to main content

zaun_community_protocol/crypto/
voice.rs

1//! Voice media encryption (ADR-0018): an end-to-end layer over WebRTC whose keys come only from
2//! post-quantum or hybrid primitives, authenticated by the members' composite keys.
3//!
4//! ```text
5//! member key (ML-DSA-65 + Ed25519) ──signs──▶ KeyPackage { X-Wing public key, voice session }
6//!                                  ──signs──▶ SenderKeys { epoch, KID, H(wrapped) per recipient }
7//! sender base key (32 random bytes, one per epoch)
8//!     ──HPKE base mode (X-Wing, HKDF-SHA256, AES-256-GCM)──▶ WrappedKey, one per recipient
9//!     ──SFrame (RFC 9605, AES_256_GCM_SHA512_128)──────────▶ sealed frames
10//! ```
11//!
12//! Everything here is sans-IO. The host relays key packages, sender keys and wrapped keys as
13//! opaque bytes; it cannot read frames or substitute keys without breaking a member signature.
14//! The trust root is the roster's member public keys, which the host serves.
15
16mod error;
17mod group;
18mod identity;
19mod package;
20mod rng;
21mod sender;
22mod session;
23mod sframe;
24
25#[cfg(test)]
26mod kat;
27#[cfg(test)]
28mod tests;
29
30pub use error::VoiceError;
31pub use group::{GroupKeys, Rekey, RekeyTarget};
32pub use identity::{VoiceIdentity, VoicePublicKey};
33pub use package::{KeyPackage, PackageExpectation, SignedKeyPackage};
34pub use sender::{
35    RecipientEntry, SenderKey, SenderKeys, SenderKeysExpectation, SignedSenderKeys, WrapContext,
36    WrappedKey,
37};
38pub use session::VoiceSessionId;
39pub use sframe::{
40    FRAMES_PER_KEY, FrameOpener, FrameSealer, HEADER_MAX, Header, REPLAY_WINDOW,
41    SFRAME_CIPHER_SUITE, SFRAME_OVERHEAD_MAX, derive_key_salt, kid_for,
42};
43
44use crate::keys::SIGNATURE_LEN;
45
46/// The voice suite of protocol version 1: X-Wing KEM, HPKE (HKDF-SHA256, AES-256-GCM), SFrame
47/// `AES_256_GCM_SHA512_128`. Unknown suites are rejected (ADR-0011 agility rules).
48pub const SUITE_V1: u8 = 0x01;
49
50/// X-Wing encapsulation (public) key length.
51pub const KEM_PUBLIC_LEN: usize = 1216;
52/// X-Wing ciphertext (HPKE `enc`) length.
53pub const KEM_CIPHERTEXT_LEN: usize = 1120;
54/// An SFrame base key: 32 bytes.
55pub const BASE_KEY_LEN: usize = 32;
56/// AES-256-GCM tag length (HPKE and SFrame).
57pub const TAG_LEN: usize = 16;
58/// A wrapped sender key: `enc ‖ AES-256-GCM(base key) ‖ tag`, 1 168 bytes.
59pub const WRAPPED_KEY_LEN: usize = KEM_CIPHERTEXT_LEN + BASE_KEY_LEN + TAG_LEN;
60
61/// Canonical bytes of a key package (all fields are fixed width): 1 306 bytes.
62pub const KEY_PACKAGE_BYTES_LEN: usize = 1 + 1 + 32 + 16 + 16 + 16 + KEM_PUBLIC_LEN + 8;
63/// A key package on the wire: canonical bytes ‖ composite signature, 4 680 bytes.
64pub const KEY_PACKAGE_WIRE_LEN: usize = KEY_PACKAGE_BYTES_LEN + SIGNATURE_LEN;
65
66/// Most recipients one sender-keys message names (a mesh of 32 participants).
67pub const MAX_RECIPIENTS: usize = 31;
68/// One recipient entry: member id ‖ voice session ‖ SHA3-256 of the wrapped key.
69pub const RECIPIENT_ENTRY_LEN: usize = 16 + 16 + 32;
70/// Canonical bytes of a sender-keys message without its recipients.
71pub const SENDER_KEYS_FIXED_LEN: usize = 1 + 1 + 32 + 16 + 16 + 16 + 4 + 8 + 4 + 8;
72/// Largest canonical sender-keys message: 2 090 bytes.
73pub const SENDER_KEYS_BYTES_MAX: usize =
74    SENDER_KEYS_FIXED_LEN + MAX_RECIPIENTS * RECIPIENT_ENTRY_LEN;
75/// Largest sender-keys message on the wire: `u32` length ‖ bytes ‖ signature, 5 468 bytes.
76pub const SENDER_KEYS_WIRE_MAX: usize = 4 + SENDER_KEYS_BYTES_MAX + SIGNATURE_LEN;