pub struct CryptoSession { /* private fields */ }crypto only.Expand description
A complete crypto session for secure communication.
Combines key management, nonce construction, AEAD, and anti-replay into a single interface.
Implementations§
Source§impl CryptoSession
impl CryptoSession
Sourcepub fn new(
session_id: SessionId,
role: Role,
send_key: SessionKey,
recv_key: SessionKey,
handshake_hash: [u8; 32],
rekey_auth_key: [u8; 32],
) -> Self
pub fn new( session_id: SessionId, role: Role, send_key: SessionKey, recv_key: SessionKey, handshake_hash: [u8; 32], rekey_auth_key: [u8; 32], ) -> Self
Create a new crypto session after handshake completion.
§Arguments
session_id- Unique session identifierrole- Our role (initiator or responder)send_key- Initial send keyrecv_key- Initial receive keyhandshake_hash- Hash of the handshake transcriptrekey_auth_key- Key derived from static DH for PCS during rekey
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Get the session ID.
Sourcepub fn should_rekey(&self) -> bool
pub fn should_rekey(&self) -> bool
Check if we should initiate a rekey.
Sourcepub fn keys_expired(&self) -> bool
pub fn keys_expired(&self) -> bool
Check if keys are expired (session must terminate).
Sourcepub fn encrypt_frame(
&mut self,
frame_type: u8,
flags: u8,
plaintext: &[u8],
) -> Result<(u64, Vec<u8>), CryptoError>
pub fn encrypt_frame( &mut self, frame_type: u8, flags: u8, plaintext: &[u8], ) -> Result<(u64, Vec<u8>), CryptoError>
Encrypt a frame for sending.
Returns (nonce_counter, ciphertext).
Sourcepub fn decrypt_frame(
&mut self,
frame_type: u8,
flags: u8,
nonce_counter: u64,
ciphertext: &[u8],
) -> Result<Vec<u8>, CryptoError>
pub fn decrypt_frame( &mut self, frame_type: u8, flags: u8, nonce_counter: u64, ciphertext: &[u8], ) -> Result<Vec<u8>, CryptoError>
Decrypt a received frame.
Performs replay check BEFORE decryption per spec.
Sourcepub fn rekey(&mut self, ephemeral_dh: &[u8; 32]) -> Result<(), CryptoError>
pub fn rekey(&mut self, ephemeral_dh: &[u8; 32]) -> Result<(), CryptoError>
Perform a rekey operation with the given ephemeral DH result.
Advances the epoch and derives new keys using PCS-secure derivation. The caller is responsible for performing the ephemeral key exchange and computing the DH shared secret.
§Arguments
ephemeral_dh- The result of DH(my_ephemeral, their_ephemeral_public)
§Security
The rekey_auth_key (derived from static DH during handshake) is mixed into the KDF along with ephemeral_dh. This ensures:
- Forward secrecy from the fresh ephemeral exchange
- Post-compromise security from the static DH-derived auth key