mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
cleanup
This commit is contained in:
@@ -22,6 +22,18 @@
|
||||
|
||||
namespace esphome::sha256 {
|
||||
|
||||
/// SHA256 hash implementation.
|
||||
///
|
||||
/// CRITICAL for ESP32-S3 with IDF 5.5.x hardware SHA acceleration:
|
||||
/// 1. SHA256 objects MUST be declared with `alignas(32)` for proper DMA alignment
|
||||
/// 2. The object MUST stay in the same stack frame (no passing to other functions)
|
||||
/// 3. NO Variable Length Arrays (VLAs) in the same function
|
||||
///
|
||||
/// Example usage:
|
||||
/// alignas(32) sha256::SHA256 hasher;
|
||||
/// hasher.init();
|
||||
/// hasher.add(data, len);
|
||||
/// hasher.calculate();
|
||||
class SHA256 : public esphome::HashBase {
|
||||
public:
|
||||
SHA256() = default;
|
||||
@@ -39,10 +51,8 @@ class SHA256 : public esphome::HashBase {
|
||||
|
||||
protected:
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
// CRITICAL: The mbedtls context MUST be stack-allocated (not a pointer) for ESP32-S3 hardware SHA acceleration.
|
||||
// The ESP32-S3 DMA engine references this structure's memory addresses. If the context is passed to another
|
||||
// function (crossing stack frames) or if VLAs are present, the DMA operations will corrupt memory and produce
|
||||
// truncated/incorrect hash results.
|
||||
// The mbedtls context for ESP32-S3 hardware SHA requires proper alignment and stack frame constraints.
|
||||
// See class documentation above for critical requirements.
|
||||
mbedtls_sha256_context ctx_{};
|
||||
#elif defined(USE_ESP8266) || defined(USE_RP2040)
|
||||
br_sha256_context ctx_{};
|
||||
|
||||
Reference in New Issue
Block a user