| 78 | } |
| 79 | |
| 80 | static bool decryptKey(const std::string& hexInput, uint8_t key[ESP_NOW_KEY_LEN]) { |
| 81 | if (hexInput.size() != ESP_NOW_KEY_LEN * 2) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | uint8_t encrypted[ESP_NOW_KEY_LEN]; |
| 86 | if (!readHex(hexInput, encrypted, ESP_NOW_KEY_LEN)) { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | uint8_t iv[16]; |
| 91 | crypt::getIv(IV_SEED, std::strlen(IV_SEED), iv); |
| 92 | |
| 93 | if (crypt::decrypt(iv, encrypted, key, ESP_NOW_KEY_LEN) != 0) { |
| 94 | LOGGER.error("Failed to decrypt key"); |
| 95 | return false; |
| 96 | } |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | /** Generate a non-zero random sender ID using hardware RNG. */ |
| 101 | static uint32_t generateSenderId() { |
no test coverage detected