pub struct CryptoState {
pub session: CryptoSession,
pub session_key: [u8; 32],
}std only.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 as
nonce_prefix(4) ‖ packet_number(8) (① — Phase 4; see
Session::build_packet_nonce) from the authenticated header — the
per-direction u64 packet number is used once, so the nonce never repeats
and 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>
Decrypt with a caller-supplied 12-byte nonce (the recv counterpart of
encrypt_with_nonce).
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.