esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
esphome::api::noise Namespace Reference

Classes

class  CipherState
 Wraps a symmetric key plus a monotonically increasing nonce, per the Noise CipherState object. More...
 
class  NoiseHandshake
 Drives the two-message NNpsk0 handshake. More...
 
class  SymmetricState
 Implements the Noise SymmetricState object: it accumulates the handshake transcript hash h, derives keys through the chaining key ck, and owns the handshake CipherState. More...
 

Typedefs

using Hash = std::array< std::uint8_t, hash_len >
 
using SymmetricKey = std::array< std::uint8_t, key_len >
 
using PublicKey = std::array< std::uint8_t, key_len >
 
using PrivateKey = std::array< std::uint8_t, key_len >
 

Functions

Hash sha256 (ByteView data)
 SHA-256 of data.
 
Hash hmac_sha256 (ByteView key, ByteView data)
 HMAC-SHA-256 with key over data.
 
void hkdf (const Hash &chaining_key, ByteView input_key_material, int num_outputs, Hash &o1, Hash &o2, Hash &o3)
 Noise HKDF: derive num_outputs (1..3) 32-byte values from chaining_key and input_key_material.
 
PublicKey x25519_base (const PrivateKey &private_key)
 X25519 public key for a private scalar.
 
SymmetricKey x25519 (const PrivateKey &private_key, const PublicKey &peer_public)
 X25519 shared secret. Throws EncryptionError on an all-zero (degenerate) result.
 
void generate_keypair (PrivateKey &private_key, PublicKey &public_key)
 Generate a fresh X25519 keypair from the system CSPRNG.
 
ByteBuffer aead_encrypt (const SymmetricKey &key, std::uint64_t nonce, ByteView ad, ByteView plaintext)
 AEAD ChaCha20-Poly1305 (IETF) encryption.
 
bool aead_decrypt (const SymmetricKey &key, std::uint64_t nonce, ByteView ad, ByteView ciphertext, ByteBuffer &out_plaintext)
 AEAD ChaCha20-Poly1305 (IETF) decryption. Returns false on auth failure.
 
bool base64_decode (const std::string &text, ByteBuffer &out)
 Decode standard base64. Returns false on malformed input.
 

Variables

constexpr auto protocol_name = "Noise_NNpsk0_25519_ChaChaPoly_SHA256"
 Noise protocol name for the ESPHome native API.
 
constexpr std::size_t hash_len = 32
 SHA-256 digest / key size.
 
constexpr std::size_t key_len = 32
 Symmetric / DH key size.
 

Typedef Documentation

◆ Hash

using esphome::api::noise::Hash = typedef std::array<std::uint8_t, hash_len>

◆ PrivateKey

using esphome::api::noise::PrivateKey = typedef std::array<std::uint8_t, key_len>

◆ PublicKey

using esphome::api::noise::PublicKey = typedef std::array<std::uint8_t, key_len>

◆ SymmetricKey

using esphome::api::noise::SymmetricKey = typedef std::array<std::uint8_t, key_len>

Function Documentation

◆ aead_decrypt()

bool esphome::api::noise::aead_decrypt ( const SymmetricKey key,
std::uint64_t  nonce,
ByteView  ad,
ByteView  ciphertext,
ByteBuffer out_plaintext 
)

AEAD ChaCha20-Poly1305 (IETF) decryption. Returns false on auth failure.

◆ aead_encrypt()

ByteBuffer esphome::api::noise::aead_encrypt ( const SymmetricKey key,
std::uint64_t  nonce,
ByteView  ad,
ByteView  plaintext 
)

AEAD ChaCha20-Poly1305 (IETF) encryption.

nonce is the Noise message counter (encoded as 4 zero bytes + 8-byte little-endian). Returns ciphertext||tag.

◆ base64_decode()

bool esphome::api::noise::base64_decode ( const std::string &  text,
ByteBuffer out 
)

Decode standard base64. Returns false on malformed input.

◆ generate_keypair()

void esphome::api::noise::generate_keypair ( PrivateKey private_key,
PublicKey public_key 
)

Generate a fresh X25519 keypair from the system CSPRNG.

◆ hkdf()

void esphome::api::noise::hkdf ( const Hash chaining_key,
ByteView  input_key_material,
int  num_outputs,
Hash o1,
Hash o2,
Hash o3 
)

Noise HKDF: derive num_outputs (1..3) 32-byte values from chaining_key and input_key_material.

Only the first num_outputs of o1/o2/o3 are valid.

◆ hmac_sha256()

Hash esphome::api::noise::hmac_sha256 ( ByteView  key,
ByteView  data 
)

HMAC-SHA-256 with key over data.

◆ sha256()

Hash esphome::api::noise::sha256 ( ByteView  data)

SHA-256 of data.

◆ x25519()

SymmetricKey esphome::api::noise::x25519 ( const PrivateKey private_key,
const PublicKey peer_public 
)

X25519 shared secret. Throws EncryptionError on an all-zero (degenerate) result.

◆ x25519_base()

PublicKey esphome::api::noise::x25519_base ( const PrivateKey private_key)

X25519 public key for a private scalar.

Variable Documentation

◆ hash_len

constexpr std::size_t esphome::api::noise::hash_len = 32
inlineconstexpr

SHA-256 digest / key size.

◆ key_len

constexpr std::size_t esphome::api::noise::key_len = 32
inlineconstexpr

Symmetric / DH key size.

◆ protocol_name

constexpr auto esphome::api::noise::protocol_name = "Noise_NNpsk0_25519_ChaChaPoly_SHA256"
inlineconstexpr

Noise protocol name for the ESPHome native API.