ESPHome 2026.9.0-dev
Loading...
Searching...
No Matches
esphome::noise::NoiseResponderHandshake Class Reference

Sans-IO responder side of a Noise_NNpsk0_25519_ChaChaPoly_SHA256 handshake. More...

#include <noise_handshake.h>

Public Types

enum class  Action : uint8_t { ACTION_READ , ACTION_WRITE , ACTION_SPLIT , ACTION_FAILED }
 

Public Member Functions

 NoiseResponderHandshake ()=default
 
 ~NoiseResponderHandshake ()
 
 NoiseResponderHandshake (const NoiseResponderHandshake &)=delete
 
NoiseResponderHandshakeoperator= (const NoiseResponderHandshake &)=delete
 
int init (const psk_t &psk, const uint8_t *prologue, size_t prologue_len)
 Create and start the handshake with the given PSK and prologue.
 
Action action () const
 ACTION_FAILED is the catch-all: returned before init(), after split() has released the state, and when noise-c reports a failed handshake.
 
int read_message (uint8_t *data, size_t len)
 Process one received handshake message.
 
int write_message (uint8_t *out, size_t capacity, size_t &out_len)
 Produce the next handshake message into out; out_len receives its size and is zero on error.
 
int split (NoiseCipherState *&send_cipher, NoiseCipherState *&recv_cipher)
 Hand out the transport ciphers and free the handshake state.
 

Protected Member Functions

int fail_init_ (int err)
 Release a half-initialized state so a failed init() leaves the object as if init() was never called.
 

Protected Attributes

NoiseHandshakeState * handshake_ {nullptr}
 

Detailed Description

Sans-IO responder side of a Noise_NNpsk0_25519_ChaChaPoly_SHA256 handshake.

Owns only the noise-c handshake state; the caller moves the raw handshake messages (no framing) over its own transport, driven by action(): read_message() while READ, write_message() while WRITE, then split() to take ownership of the transport ciphers. All methods return a noise-c error code, 0 on success. Called outside their action() step (before init(), after split()) the message methods return a noise-c error rather than crashing; the library checks its state argument.

Methods are deliberately small separate functions so callers on tight stacks (RP2040 core0 scratch bank) never pay for more than one branch; the curve25519 step alone needs ~2KB of stack.

Definition at line 27 of file noise_handshake.h.

Member Enumeration Documentation

◆ Action

Enumerator
ACTION_READ 
ACTION_WRITE 
ACTION_SPLIT 
ACTION_FAILED 

Definition at line 31 of file noise_handshake.h.

Constructor & Destructor Documentation

◆ NoiseResponderHandshake() [1/2]

esphome::noise::NoiseResponderHandshake::NoiseResponderHandshake ( )
default

◆ ~NoiseResponderHandshake()

esphome::noise::NoiseResponderHandshake::~NoiseResponderHandshake ( )

Definition at line 16 of file noise_handshake.cpp.

◆ NoiseResponderHandshake() [2/2]

esphome::noise::NoiseResponderHandshake::NoiseResponderHandshake ( const NoiseResponderHandshake & )
delete

Member Function Documentation

◆ action()

NoiseResponderHandshake::Action esphome::noise::NoiseResponderHandshake::action ( ) const
nodiscard

ACTION_FAILED is the catch-all: returned before init(), after split() has released the state, and when noise-c reports a failed handshake.

Definition at line 73 of file noise_handshake.cpp.

◆ fail_init_()

int esphome::noise::NoiseResponderHandshake::fail_init_ ( int err)
protected

Release a half-initialized state so a failed init() leaves the object as if init() was never called.

Definition at line 67 of file noise_handshake.cpp.

◆ init()

int esphome::noise::NoiseResponderHandshake::init ( const psk_t & psk,
const uint8_t * prologue,
size_t prologue_len )
nodiscard

Create and start the handshake with the given PSK and prologue.

A repeated call frees the previous handshake state and starts over.

Definition at line 23 of file noise_handshake.cpp.

◆ operator=()

NoiseResponderHandshake & esphome::noise::NoiseResponderHandshake::operator= ( const NoiseResponderHandshake & )
delete

◆ read_message()

int esphome::noise::NoiseResponderHandshake::read_message ( uint8_t * data,
size_t len )
nodiscard

Process one received handshake message.

The buffer is consumed in place: noise-c decrypts into it and zeroes it before returning.

Definition at line 94 of file noise_handshake.cpp.

◆ split()

int esphome::noise::NoiseResponderHandshake::split ( NoiseCipherState *& send_cipher,
NoiseCipherState *& recv_cipher )
nodiscard

Hand out the transport ciphers and free the handshake state.

The caller owns both cipher states and must free them with noise_cipherstate_free(); both are set to nullptr on error.

Definition at line 112 of file noise_handshake.cpp.

◆ write_message()

int esphome::noise::NoiseResponderHandshake::write_message ( uint8_t * out,
size_t capacity,
size_t & out_len )
nodiscard

Produce the next handshake message into out; out_len receives its size and is zero on error.

Definition at line 101 of file noise_handshake.cpp.

Field Documentation

◆ handshake_

NoiseHandshakeState* esphome::noise::NoiseResponderHandshake::handshake_ {nullptr}
protected

Definition at line 59 of file noise_handshake.h.


The documentation for this class was generated from the following files: