pub struct Handshake { /* private fields */ }Expand description
An in-progress Noise-IKpsk2 post-quantum hybrid handshake.
Implementations§
Source§impl Handshake
impl Handshake
Sourcepub fn initiator(
local_private: &[u8; 32],
peer_public: &[u8; 32],
) -> Result<Handshake, CryptoError>
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.
Sourcepub fn responder(local_private: &[u8; 32]) -> Result<Handshake, CryptoError>
pub fn responder(local_private: &[u8; 32]) -> Result<Handshake, CryptoError>
Begin as the responder; learns the initiator’s static key during the handshake.
Sourcepub fn write_message(&mut self, payload: &[u8]) -> Result<Vec<u8>, CryptoError>
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
payloadinside Noise Msg 2, framed as[ct (768B) || Noise Msg 2].
Sourcepub fn read_message(&mut self, msg: &[u8]) -> Result<Vec<u8>, CryptoError>
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), callsset_psk(2, &ss), and returnspayload. - For Initiator (Msg 2): Slices
ctfrom Msg 2 prefix, decapsulatesss, callsset_psk(2, &ss), decrypts Noise Msg 2, scrubsdk, and returnspayload.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the handshake has completed and a session can be derived.
Sourcepub fn remote_static(&self) -> Option<[u8; 32]>
pub fn remote_static(&self) -> Option<[u8; 32]>
The peer’s authenticated static public key, if learned yet.
Sourcepub fn channel_binding(&self) -> [u8; 32]
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.
Sourcepub fn raw_split_keys(&self) -> ([u8; 32], [u8; 32])
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.
Sourcepub fn into_session(self) -> Result<Session, CryptoError>
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.