CryptState

Struct CryptState 

Source
pub struct CryptState {
    pub good: u32,
    pub late: u32,
    pub lost: u32,
    /* private fields */
}
Expand description

A full OCB2 crypt state for one direction pair: the AES key, both IVs, the replay history and the good/late/lost counters. Mirrors Mumble’s CryptStateOCB2 object (minus key generation, which belongs to session setup).

REF: CryptStateOCB2.cpp : CryptStateOCB2, encrypt, decrypt.

Fields§

§good: u32

Count of successfully decrypted packets.

§late: u32

Running count of late (out-of-order but recovered) packets.

§lost: u32

Running count of lost packets inferred from IV gaps.

Implementations§

Source§

impl CryptState

Source

pub fn new( raw_key: &[u8; 16], encrypt_iv: &[u8; 16], decrypt_iv: &[u8; 16], ) -> Self

Build a state from a raw key and the two initial IVs.

Source

pub fn encrypt_iv(&self) -> [u8; 16]

Current encrypt IV (mainly for tests that force/inspect IV state).

Source

pub fn decrypt_iv(&self) -> [u8; 16]

Current decrypt IV.

Source

pub fn set_encrypt_iv(&mut self, iv: &[u8; 16])

Overwrite the encrypt IV.

Source

pub fn set_decrypt_iv(&mut self, iv: &[u8; 16])

Overwrite the decrypt IV.

Source

pub fn encrypt(&mut self, plain: &[u8]) -> Option<Vec<u8>>

Encrypt a packet: advance the IV, OCB2-encrypt, and prepend the 4-byte header (IV low byte plus three tag bytes). Returns None only if encryption reports inauthenticity, which cannot happen here because the XEX* mitigation is enabled.

REF: CryptStateOCB2.cpp : CryptStateOCB2::encrypt.

Source

pub fn decrypt(&mut self, source: &[u8]) -> Option<Vec<u8>>

Decrypt a packet, performing IV recovery for out-of-order/lost packets and rejecting replays. Returns the plaintext, or None if the packet is a replay, fails IV recovery, or fails tag verification (fail closed, R6).

REF: CryptStateOCB2.cpp : CryptStateOCB2::decrypt.

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.