From f5ae09056c8e420ca7bc9a0de9015fda125f8ef5 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 6 Jan 2026 00:34:36 -1000 Subject: [PATCH] cleanup --- .../components/esphome/ota/ota_esphome.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/esphome/components/esphome/ota/ota_esphome.cpp b/esphome/components/esphome/ota/ota_esphome.cpp index 7669cffcd9..be0dc61607 100644 --- a/esphome/components/esphome/ota/ota_esphome.cpp +++ b/esphome/components/esphome/ota/ota_esphome.cpp @@ -559,11 +559,17 @@ bool ESPHomeOTAComponent::handle_auth_send_() { // [1+hex_size...1+2*hex_size-1]: cnonce (hex_size bytes) - client's nonce // [1+2*hex_size...1+3*hex_size-1]: response (hex_size bytes) - client's hash - // Allocate auth buffer before creating SHA256 hasher to avoid potential - // heap/DMA interactions on ESP32-S3 with hardware SHA acceleration - constexpr size_t hex_size = SHA256_HEX_SIZE; - constexpr size_t nonce_len = 8; // SHA256 digest size (32) / 4 - constexpr size_t auth_buf_size = 1 + 3 * hex_size; + // CRITICAL ESP32-S3 HARDWARE SHA ACCELERATION: Hash object must stay in same stack frame + // (no passing to other functions). All hash operations must happen in this function. + // NOTE: On ESP32-S3 with IDF 5.5.x, having only SHA256 on the stack causes crashes with + // hardware SHA acceleration. Adding an MD5 object provides the necessary stack alignment. + sha256::SHA256 hasher; + md5::MD5Digest md5_dummy; // Required for ESP32-S3 IDF 5.5.x stack alignment + (void) md5_dummy; // Suppress unused variable warning + + const size_t hex_size = hasher.get_size() * 2; + const size_t nonce_len = hasher.get_size() / 4; + const size_t auth_buf_size = 1 + 3 * hex_size; this->auth_buf_ = std::make_unique(auth_buf_size); this->auth_buf_pos_ = 0; @@ -574,13 +580,6 @@ bool ESPHomeOTAComponent::handle_auth_send_() { return false; } - // CRITICAL ESP32-S3 HARDWARE SHA ACCELERATION: Hash object must stay in same stack frame - // (no passing to other functions). All hash operations must happen in this function. - // NOTE: On ESP32-S3 with IDF 5.5.x, having only SHA256 on the stack causes crashes with - // hardware SHA acceleration. Adding an MD5 object provides the necessary stack alignment. - sha256::SHA256 hasher; - md5::MD5Digest md5_dummy; // Required for ESP32-S3 IDF 5.5.x stack alignment - (void) md5_dummy; // Suppress unused variable warning hasher.init(); hasher.add(buf, nonce_len); hasher.calculate();