|
ESPHome 2026.9.0-dev
|
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 | |
| NoiseResponderHandshake & | operator= (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} |
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.
|
strong |
| Enumerator | |
|---|---|
| ACTION_READ | |
| ACTION_WRITE | |
| ACTION_SPLIT | |
| ACTION_FAILED | |
Definition at line 31 of file noise_handshake.h.
|
default |
| esphome::noise::NoiseResponderHandshake::~NoiseResponderHandshake | ( | ) |
Definition at line 16 of file noise_handshake.cpp.
|
delete |
|
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.
|
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.
|
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.
|
delete |
|
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.
|
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.
|
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.
|
protected |
Definition at line 59 of file noise_handshake.h.