Skip to main content

Handshake

Struct Handshake 

Source
pub struct Handshake { /* private fields */ }
Expand description

An in-progress Noise-IKpsk2 post-quantum hybrid handshake.

Implementations§

Source§

impl Handshake

Source

pub fn initiator( local_private: &[u8; 32], peer_public: &[u8; 32], ) -> Result<Handshake, CryptoError>

Begin as the initiator, which must already know the responder’s static public key.

Source

pub fn responder(local_private: &[u8; 32]) -> Result<Handshake, CryptoError>

Begin as the responder; learns the initiator’s static key during the handshake.

Source

pub fn write_message(&mut self, payload: &[u8]) -> Result<Vec<u8>, CryptoError>

Produce the next handshake message to send to the peer.

  • For Initiator (Msg 1): Encrypts [ek_A (800B) || payload] inside Noise Msg 1.
  • For Responder (Msg 2): Encrypts payload inside Noise Msg 2, framed as [ct (768B) || Noise Msg 2].
Source

pub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>, CryptoError>

Consume a handshake message received from the peer, returning the decrypted app payload.

  • For Responder (Msg 1): Decrypts Noise Msg 1, extracts ek_A, encapsulates (ct, ss), calls set_psk(2, &ss), and returns payload.
  • For Initiator (Msg 2): Slices ct from Msg 2 prefix, decapsulates ss, calls set_psk(2, &ss), decrypts Noise Msg 2, scrubs dk, and returns payload.
Source

pub fn is_finished(&self) -> bool

Whether the handshake has completed and a session can be derived.

Source

pub fn remote_static(&self) -> Option<[u8; 32]>

The peer’s authenticated static public key, if learned yet.

Source

pub fn channel_binding(&self) -> [u8; 32]

The Noise channel-binding hash (snow’s handshake hash), identical on both peers after the handshake completes. Use it to derive subkeys (e.g. the wire codec keys) bound to this session.

Source

pub fn raw_split_keys(&self) -> ([u8; 32], [u8; 32])

Extract the two raw 32-byte secret Noise transport keys (send key, recv key) derived from the handshake.

Source

pub fn into_session(self) -> Result<Session, CryptoError>

Convert a completed handshake into an AEAD Session.

Extracts the two secret Noise transport keys via snow’s raw split and builds ring AEAD keys from them directly; snow’s own transport state is not used for the data plane. Per snow’s split convention, element 0 of the pair is the initiator’s send key (= responder’s receive key) and element 1 is the responder’s send key (= initiator’s receive key), so the mapping below is role-dependent.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.