CryptoSession

Struct CryptoSession 

Source
pub struct CryptoSession { /* private fields */ }
Available on crate feature 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

Source

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 identifier
  • role - Our role (initiator or responder)
  • send_key - Initial send key
  • recv_key - Initial receive key
  • handshake_hash - Hash of the handshake transcript
  • rekey_auth_key - Key derived from static DH for PCS during rekey
Source

pub fn session_id(&self) -> &SessionId

Get the session ID.

Source

pub fn role(&self) -> Role

Get the current role.

Source

pub fn epoch(&self) -> u32

Get the current epoch.

Source

pub fn should_rekey(&self) -> bool

Check if we should initiate a rekey.

Source

pub fn keys_expired(&self) -> bool

Check if keys are expired (session must terminate).

Source

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).

Source

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.

Source

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

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V