Home IO Control
ESPHome add-on for IO-Homecontrol devices
Loading...
Searching...
No Matches
proto_crypto.cpp File Reference

Cryptographic helpers for the IO-Homecontrol protocol. More...

#include "proto_crypto.h"
#include "proto_constants.h"
#include <esp_random.h>
#include <cstring>
Include dependency graph for proto_crypto.cpp:

Go to the source code of this file.

Namespaces

namespace  esphome
namespace  esphome::home_io_control
namespace  esphome::home_io_control::crypto

Functions

void esphome::home_io_control::crypto::compute_checksum (uint8_t byte, uint8_t &c1, uint8_t &c2)
 Proprietary checksum algorithm used in IV construction.
static void esphome::home_io_control::crypto::construct_iv_prefix (const uint8_t *data, uint8_t len, uint8_t iv[IV_SIZE])
 Shared core of construct_iv() (2W) and construct_iv_1w_sequence() (1W): fills IV bytes 0-9 — up to 8 bytes of span data (0x55-padded if the span is shorter), then the two running checksum bytes (compute_checksum()) accumulated over the whole span.
void esphome::home_io_control::crypto::construct_iv (const uint8_t *data, uint8_t len, const uint8_t challenge[HMAC_SIZE], uint8_t iv[IV_SIZE])
 Construct the 16-byte initialization vector (IV) for AES encryption.
void esphome::home_io_control::crypto::construct_iv_1w_sequence (const uint8_t *data, uint8_t len, uint16_t sequence, uint8_t iv[IV_SIZE])
 Construct the 16-byte IV for the 1W sequence-keyed HMAC (create_1w_hmac()).
void esphome::home_io_control::crypto::construct_iv_1w_node (const uint8_t node[NODE_ID_SIZE], uint8_t iv[IV_SIZE])
 Construct the 16-byte IV for the 1W key-wrap primitive from a sender's node address alone.
bool esphome::home_io_control::crypto::aes128_encrypt (const uint8_t in[AES_BLOCK_SIZE], const uint8_t key[AES_KEY_SIZE], uint8_t out[AES_BLOCK_SIZE])
 AES-128 ECB encrypt a single 16-byte block.
bool esphome::home_io_control::crypto::aes128_decrypt (const uint8_t in[AES_BLOCK_SIZE], const uint8_t key[AES_KEY_SIZE], uint8_t out[AES_BLOCK_SIZE])
 AES‑128 ECB decrypt a single 16‑byte block.
bool esphome::home_io_control::crypto::create_hmac (const uint8_t *data, uint8_t len, const uint8_t challenge[HMAC_SIZE], const uint8_t key[AES_KEY_SIZE], uint8_t hmac[HMAC_SIZE])
 Create a 6-byte HMAC for authentication (proprietary IO-Homecontrol scheme).
bool esphome::home_io_control::crypto::create_1w_hmac (const uint8_t *data, uint8_t len, uint16_t sequence, const uint8_t controller_key[AES_KEY_SIZE], uint8_t hmac[HMAC_SIZE])
 Create the 6-byte authenticator for a 1W frame.
bool esphome::home_io_control::crypto::verify_hmac (const uint8_t *data, uint8_t len, const uint8_t hmac[HMAC_SIZE], const uint8_t challenge[HMAC_SIZE], const uint8_t key[AES_KEY_SIZE])
 Verify a received HMAC using constant-time comparison.
static bool esphome::home_io_control::crypto::xor_with_encrypted_iv (const uint8_t iv[IV_SIZE], const uint8_t in[AES_KEY_SIZE], uint8_t out[AES_KEY_SIZE])
 Shared core of crypt_key() (2W) and crypt_1w_key() (1W): AES-128-ECB-encrypt iv under the public TRANSFER_KEY, then XOR the result over in.
bool esphome::home_io_control::crypto::crypt_key (const uint8_t *data, uint8_t len, const uint8_t challenge[HMAC_SIZE], const uint8_t in[AES_KEY_SIZE], uint8_t out[AES_KEY_SIZE])
 Encrypt or decrypt a system key during pairing.
bool esphome::home_io_control::crypto::crypt_1w_key (const uint8_t node[NODE_ID_SIZE], const uint8_t in[AES_KEY_SIZE], uint8_t out[AES_KEY_SIZE])
 Encrypt or decrypt a 1W controller key during add-controller key adoption (CMD 0x30).
void esphome::home_io_control::crypto::generate_challenge (uint8_t out[HMAC_SIZE])
 Generate 6 random bytes for a challenge using the ESP32 hardware RNG.

Detailed Description

Cryptographic helpers for the IO-Homecontrol protocol.

Definition in file proto_crypto.cpp.