ESPHome 2026.9.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
41 [[nodiscard]] int init(const psk_t &psk, const uint8_t *prologue, size_t prologue_len);
44 [[nodiscard]] Action action() const;
47 [[nodiscard]] int read_message(uint8_t *data, size_t len);
50 [[nodiscard]] int write_message(uint8_t *out, size_t capacity, size_t &out_len);
54 [[nodiscard]] int split(NoiseCipherState *&send_cipher, NoiseCipherState *&recv_cipher);
55
56 protected:
57 int fail_init_(int err);
58
59 NoiseHandshakeState *handshake_{nullptr};
60};
61
62} // namespace esphome::noise
63#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,...
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.
NoiseResponderHandshake & operator=(const NoiseResponderHandshake &)=delete
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::array< uint8_t, 32 > psk_t
Definition noise.h:11
const void size_t len
Definition hal.h:64
uint16_t uint16_t & capacity
Definition helpers.cpp:25