ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
noise_handshake.h
Go to the documentation of this file.
1#pragma once
3#ifdef USE_NOISE
4#include <cstddef>
5#include <cstdint>
6
7#include <noise/protocol.h>
8
9#include "noise.h"
10
11namespace esphome::noise {
12
28 public:
29 // The ACTION_ prefix is macro-collision safety: SDK headers #define bare
30 // names like READ/WRITE, and macros expand even inside an enum class.
32
35 // Owns a raw noise-c handshake state; copying would double free it
38
42 [[nodiscard]] int init(const NoiseContext &ctx, const uint8_t *prologue, size_t prologue_len);
45 [[nodiscard]] Action action() const;
48 [[nodiscard]] int read_message(uint8_t *data, size_t len);
51 [[nodiscard]] int write_message(uint8_t *out, size_t capacity, size_t &out_len);
55 [[nodiscard]] int split(NoiseCipherState *&send_cipher, NoiseCipherState *&recv_cipher);
56
57 protected:
58 int fail_init_(int err);
59
61};
62
63} // namespace esphome::noise
64#endif // USE_NOISE
Sans-IO responder side of a Noise_NNpsk0_25519_ChaChaPoly_SHA256 handshake.
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.
Action action() const
ACTION_FAILED is the catch-all: returned before init(), after split() has released the state,...
NoiseResponderHandshake & operator=(const NoiseResponderHandshake &)=delete
int init(const NoiseContext &ctx, const uint8_t *prologue, size_t prologue_len)
Create and start the handshake with the context's PSK and the prologue.
int fail_init_(int err)
Release a half-initialized state so a failed init() leaves the object as if init() was never called.
int read_message(uint8_t *data, size_t len)
Process one received handshake message.
int split(NoiseCipherState *&send_cipher, NoiseCipherState *&recv_cipher)
Hand out the transport ciphers and free the handshake state.
NoiseResponderHandshake(const NoiseResponderHandshake &)=delete
std::vector< uint8_t > & out
Definition gif.cpp:49
const void size_t len
Definition hal.h:68
uint16_t uint16_t & capacity
Definition helpers.cpp:34
struct NoiseHandshakeState_s NoiseHandshakeState
Definition noise.h:10