Skip to main content

CryptoConfig

Struct CryptoConfig 

Source
#[non_exhaustive]
pub struct CryptoConfig { pub passphrase: Vec<u8>, pub salt: [u8; 16], pub sek: Vec<u8>, }
Available on crate feature crypto only.
Expand description

Opt-in §6 payload-encryption config for one side of a Caller-Listener handshake (draft-sharabayko-srt-01 §6.1.5, Key Material Exchange — curated at private/specs-verified/rules/srt-crypto.md). None on HandshakeConfig::crypto (the default) disables the encryption path entirely: no Key Material extension is sent, and a peer that sends one unexpectedly is rejected (RejectionReason::Unsecure).

This crate’s sans-IO core never reads OS randomness — the same design choice as cookie::derive_cookie’s caller-supplied time_bucket/secret inputs, or crate::io’s OS-random SYN Cookie key. Self::salt and, on the initiator, Self::sek must be freshly generated by the caller/driver (e.g. a tokio adapter with access to a real CSPRNG) for every new connection (§6.2.1: Salt = PRNG(128), SEK = PRNG(KLen)) and never reused across connections.

§Secret hygiene (issue #1142)

The passphrase and SEK never appear in core::fmt::Debug output (it prints only their lengths), PartialEq compares them in constant time, and dropping a CryptoConfig (or calling Zeroize::zeroize) wipes them.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§passphrase: Vec<u8>

The pre-shared secret (§6.1.4). Must be identical on both peers, or the responder’s KEK derivation recovers the wrong SEK and the RFC 3394 wrap’s integrity check fails (RejectionReason::BadSecret on the Listener side).

§salt: [u8; 16]

A fresh, cryptographically random 128-bit Salt for this connection (§6.2.1: Salt = PRNG(128)). See the struct doc for why this crate does not generate it internally.

§sek: Vec<u8>

This side’s plaintext Stream Encrypting Key. Only meaningful on the connection initiator (the Caller — §6.1.5: “sent by the connection initiator … to the responder”). Must be a fresh, cryptographically random 16/24/32-byte value (§6.2.1: SEK = PRNG(KLen)) matching HandshakeConfig::encryption_field’s advertised cipher. Ignored on the Listener/responder side (which instead recovers the SEK by unwrapping the initiator’s Key Material) — may be left empty there.

Implementations§

Source§

impl CryptoConfig

Source

pub fn new(passphrase: Vec<u8>, salt: [u8; 16], sek: Vec<u8>) -> Self

Build the crypto parameters for one connection’s handshake (encryption preamble §6.1). Every field is a secret or a per-connection nonce, so there is no Default; the caller supplies all three.

Trait Implementations§

Source§

impl Clone for CryptoConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CryptoConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for CryptoConfig

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl PartialEq for CryptoConfig

Source§

fn eq(&self, other: &Self) -> bool

Constant-time in the secret contents (the lengths are not secret).

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Zeroize for CryptoConfig

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl ZeroizeOnDrop for CryptoConfig

Auto Trait Implementations§

§

impl Forget for CryptoConfig

§

impl Freeze for CryptoConfig
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for CryptoConfig

§

impl RefUnwindSafe for CryptoConfig

§

impl Send for CryptoConfig
where RawVecInner: Send,

§

impl Sync for CryptoConfig
where RawVecInner: Sync,

§

impl Unpin for CryptoConfig
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for CryptoConfig

§

impl UnwindSafe for CryptoConfig
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more