pub struct CryptoState {
pub session: CryptoSession,
pub session_key: [u8; 32],
}Expand description
Crypto state for session encryption.
On drop, session_key is zeroed. The wrapped CryptoSession holds AEAD
keys in ring’s opaque LessSafeKey (which cannot be zeroed directly — we
rely on the OS reclaiming memory and on the Arc<CryptoSessionInner> going
out of scope alongside this struct).
Fields§
§session: CryptoSessionBidirectional crypto session
session_key: [u8; 32]Shared session key (for additional derivations)
Implementations§
Source§impl CryptoState
impl CryptoState
Sourcepub fn new(shared_secret: &[u8; 32], peer_side: bool) -> Result<Self, CoreError>
pub fn new(shared_secret: &[u8; 32], peer_side: bool) -> Result<Self, CoreError>
Create new crypto state from shared secret
Sourcepub fn encrypt_with_nonce(
&self,
nonce: [u8; 12],
aad: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>, CoreError>
pub fn encrypt_with_nonce( &self, nonce: [u8; 12], aad: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>, CoreError>
Encrypt with a caller-supplied 12-byte nonce. Used by
Session::encrypt_packet, which constructs the nonce from the
authenticated (epoch, stream_id, sequence, path_id) of the packet
header — so the receiver survives failed decrypts without desyncing.
Sourcepub fn decrypt_with_nonce(
&self,
nonce: [u8; 12],
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>, CoreError>
pub fn decrypt_with_nonce( &self, nonce: [u8; 12], aad: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>, CoreError>
V2-path decrypt: caller supplies the 12-byte nonce explicitly.
Sourcepub fn nonce_prefix(&self) -> [u8; 4]
pub fn nonce_prefix(&self) -> [u8; 4]
Borrow the 4-byte nonce prefix derived at session establishment.
Sourcepub fn send_invocations(&self) -> u64
pub fn send_invocations(&self) -> u64
Per-direction send-side AEAD invocation count for this epoch. Resets to
0 on rekey (a fresh CryptoState is installed). Drives the C1
automatic-rekey trigger.