14using psk_t = std::array<uint8_t, 32>;
24 for (uint8_t b : psk) {
38 const uint8_t *
psk_{
nullptr};
44#ifdef USE_NOISE_SPARE_EPHEMERAL
48static constexpr size_t SPARE_EPHEMERAL_KEY_SIZE = 32;
49static constexpr size_t SPARE_EPHEMERAL_SIZE = 2 * SPARE_EPHEMERAL_KEY_SIZE;
63static constexpr uint8_t FRAME_INDICATOR = 0x01;
64static constexpr size_t FRAME_HEADER_SIZE = 3;
65static constexpr size_t MAC_SIZE = 16;
66static constexpr size_t MAX_HANDSHAKE_SIZE = 128;
67static constexpr uint8_t HANDSHAKE_STATUS_OK = 0x00;
68static constexpr uint8_t HANDSHAKE_STATUS_REJECT = 0x01;
71 buf[0] = FRAME_INDICATOR;
72 buf[1] = (uint8_t) (payload_len >> 8);
73 buf[2] = (uint8_t) payload_len;
89static constexpr size_t MAC_FAILURE_PAYLOAD_SIZE =
sizeof(
"Handshake MAC failure");
void set_psk(const uint8_t *psk)
psk points at 32 bytes that outlive the context (PROGMEM or caller owned RAM); nullptr means no key.
static bool is_all_zeros(const psk_t &psk)
void load_psk(psk_t &out) const
Copy the key out (flash-aware on ESP8266); all zeros when none is set.
std::vector< uint8_t > & out
void write_frame_header(uint8_t *buf, uint16_t payload_len)
std::array< uint8_t, 32 > psk_t
uint8_t spare_ephemeral[SPARE_EPHEMERAL_SIZE]
const LogString * noise_err_to_logstr(int err)
Convert a noise error code to a readable error.
size_t format_reject_payload(uint8_t *buf, size_t capacity, const LogString *reason)
Fill buf with a handshake reject payload (status byte plus the reason text, PROGMEM aware); returns t...
int consume_spare_ephemeral(NoiseHandshakeState *state)
Move the key pair into a handshake that has not started and wipe the slot; 0 unless noise-c rejects i...
bool has_spare_ephemeral()
const LogString * reject_reason_for(int err)
Reject reason for a failed handshake read.
void prepare_spare_ephemeral()
Fill the slot; blocks for the base point multiply.
uint16_t uint16_t & capacity
struct NoiseHandshakeState_s NoiseHandshakeState