mirror of
https://github.com/esphome/esphome.git
synced 2025-09-22 13:12:22 +01:00
try to make it work on 8266
This commit is contained in:
@@ -34,6 +34,35 @@ void SHA256::calculate() {
|
||||
mbedtls_sha256_finish(&this->ctx_->ctx, this->ctx_->hash);
|
||||
}
|
||||
|
||||
#elif defined(USE_ESP8266)
|
||||
|
||||
SHA256::~SHA256() = default;
|
||||
|
||||
void SHA256::init() {
|
||||
if (!this->ctx_) {
|
||||
this->ctx_ = std::make_unique<SHA256Context>();
|
||||
}
|
||||
br_sha256_init(&this->ctx_->ctx);
|
||||
this->ctx_->calculated = false;
|
||||
}
|
||||
|
||||
void SHA256::add(const uint8_t *data, size_t len) {
|
||||
if (!this->ctx_) {
|
||||
this->init();
|
||||
}
|
||||
br_sha256_update(&this->ctx_->ctx, data, len);
|
||||
}
|
||||
|
||||
void SHA256::calculate() {
|
||||
if (!this->ctx_) {
|
||||
this->init();
|
||||
}
|
||||
if (!this->ctx_->calculated) {
|
||||
br_sha256_out(&this->ctx_->ctx, this->ctx_->hash);
|
||||
this->ctx_->calculated = true;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(USE_ARDUINO)
|
||||
|
||||
SHA256::~SHA256() = default;
|
||||
|
@@ -7,6 +7,8 @@
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include "mbedtls/sha256.h"
|
||||
#elif defined(USE_ESP8266)
|
||||
#include <bearssl/bearssl_hash.h>
|
||||
#elif defined(USE_ARDUINO)
|
||||
#include <SHA256.h>
|
||||
#endif
|
||||
@@ -38,6 +40,12 @@ class SHA256 {
|
||||
mbedtls_sha256_context ctx;
|
||||
uint8_t hash[32];
|
||||
};
|
||||
#elif defined(USE_ESP8266)
|
||||
struct SHA256Context {
|
||||
br_sha256_context ctx;
|
||||
uint8_t hash[32];
|
||||
bool calculated{false};
|
||||
};
|
||||
#elif defined(USE_ARDUINO)
|
||||
struct SHA256Context {
|
||||
::SHA256 sha;
|
||||
|
Reference in New Issue
Block a user