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: u32Count of successfully decrypted packets.
late: u32Running count of late (out-of-order but recovered) packets.
lost: u32Running count of lost packets inferred from IV gaps.
Implementations§
Source§impl CryptState
impl CryptState
Sourcepub fn new(
raw_key: &[u8; 16],
encrypt_iv: &[u8; 16],
decrypt_iv: &[u8; 16],
) -> Self
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.
Sourcepub fn encrypt_iv(&self) -> [u8; 16]
pub fn encrypt_iv(&self) -> [u8; 16]
Current encrypt IV (mainly for tests that force/inspect IV state).
Sourcepub fn decrypt_iv(&self) -> [u8; 16]
pub fn decrypt_iv(&self) -> [u8; 16]
Current decrypt IV.
Sourcepub fn set_encrypt_iv(&mut self, iv: &[u8; 16])
pub fn set_encrypt_iv(&mut self, iv: &[u8; 16])
Overwrite the encrypt IV.
Sourcepub fn set_decrypt_iv(&mut self, iv: &[u8; 16])
pub fn set_decrypt_iv(&mut self, iv: &[u8; 16])
Overwrite the decrypt IV.
Sourcepub fn encrypt(&mut self, plain: &[u8]) -> Option<Vec<u8>>
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.
Sourcepub fn decrypt(&mut self, source: &[u8]) -> Option<Vec<u8>>
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.