Skip to main content

HandshakeState

Struct HandshakeState 

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

Handshake state for Noise IK and XK patterns.

Implementations§

Source§

impl HandshakeState

Source

pub fn new_initiator(static_keypair: Keypair, remote_static: PublicKey) -> Self

Create a new IK handshake as initiator.

The initiator knows the responder’s static key and will send first. Used by FMP (link layer).

Source

pub fn new_responder(static_keypair: Keypair) -> Self

Create a new IK handshake as responder.

The responder does NOT know the initiator’s static key - it will be learned from message 1. Used by FMP (link layer).

Source

pub fn new_xk_initiator( static_keypair: Keypair, remote_static: PublicKey, ) -> Self

Create a new XK handshake as initiator.

The initiator knows the responder’s static key. XK defers the initiator’s static key reveal to msg3. Used by FSP (session layer).

Source

pub fn new_xk_responder(static_keypair: Keypair) -> Self

Create a new XK handshake as responder.

The responder does NOT know the initiator’s static key - it will be learned from message 3. Used by FSP (session layer).

Source

pub fn role(&self) -> HandshakeRole

Get our role.

Source

pub fn progress(&self) -> HandshakeProgress

Get current progress.

Source

pub fn is_complete(&self) -> bool

Check if handshake is complete.

Source

pub fn remote_static(&self) -> Option<&PublicKey>

Get the remote static key (available after message 1 for responder).

Source

pub fn set_local_epoch(&mut self, epoch: [u8; 8])

Set the local startup epoch for restart detection.

Source

pub fn remote_epoch(&self) -> Option<[u8; 8]>

Get the remote peer’s startup epoch (available after processing their message).

Source

pub fn write_message_1(&mut self) -> Result<Vec<u8>, NoiseError>

Write message 1 (initiator only).

Message 1 contains:

  • e: ephemeral public key (33 bytes)
  • encrypted s: our static public key encrypted (33 + 16 = 49 bytes)
  • encrypted epoch: startup epoch for restart detection (8 + 16 = 24 bytes)

Total: 106 bytes

Source

pub fn read_message_1(&mut self, message: &[u8]) -> Result<(), NoiseError>

Read message 1 (responder only).

Processes the initiator’s first message and learns their identity and epoch.

Source

pub fn write_message_2(&mut self) -> Result<Vec<u8>, NoiseError>

Write message 2 (responder only).

Message 2 contains:

  • e: ephemeral public key (33 bytes)
  • encrypted epoch: startup epoch for restart detection (8 + 16 = 24 bytes)

Total: 57 bytes

Source

pub fn read_message_2(&mut self, message: &[u8]) -> Result<(), NoiseError>

Read message 2 (initiator only).

Processes the responder’s message and completes the handshake.

Source

pub fn write_xk_message_1(&mut self) -> Result<Vec<u8>, NoiseError>

Write XK message 1 (initiator only).

XK msg1: -> e, es

  • e: ephemeral public key (33 bytes)
  • es: DH(e_priv, rs_pub), mix_key

Total: 33 bytes (ephemeral only — no static, no epoch)

Source

pub fn read_xk_message_1(&mut self, message: &[u8]) -> Result<(), NoiseError>

Read XK message 1 (responder only).

Processes the initiator’s first message. Does NOT learn initiator’s identity (that comes in msg3).

Source

pub fn write_xk_message_2(&mut self) -> Result<Vec<u8>, NoiseError>

Write XK message 2 (responder only).

XK msg2: <- e, ee + encrypted epoch

  • e: ephemeral public key (33 bytes)
  • ee: DH(e_priv, re_pub), mix_key
  • encrypted epoch (24 bytes)

Total: 57 bytes

Source

pub fn read_xk_message_2(&mut self, message: &[u8]) -> Result<(), NoiseError>

Read XK message 2 (initiator only).

Processes the responder’s message and extracts the responder’s epoch. Does NOT complete the handshake — msg3 still needed.

Source

pub fn write_xk_message_3(&mut self) -> Result<Vec<u8>, NoiseError>

Write XK message 3 (initiator only).

XK msg3: -> s, se + encrypted epoch

  • s: encrypt_and_hash(s_pub) — encrypted static (49 bytes)
  • se: DH(s_priv, re_pub), mix_key
  • encrypted epoch (24 bytes)

Total: 73 bytes

Source

pub fn read_xk_message_3(&mut self, message: &[u8]) -> Result<(), NoiseError>

Read XK message 3 (responder only).

Processes the initiator’s encrypted static key and epoch. After this, the responder learns the initiator’s identity.

Source

pub fn into_session(self) -> Result<NoiseSession, NoiseError>

Complete the handshake and return a NoiseSession.

Must be called after the handshake is complete.

Source

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

Get the handshake hash (for channel binding, available after complete).

Trait Implementations§

Source§

impl Debug for HandshakeState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more