4#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) || defined(USE_HOST)
11#if defined(USE_ESP32) || defined(USE_LIBRETINY)
16 mbedtls_md_init(&this->
ctx_);
17 const mbedtls_md_info_t *md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA256);
18 mbedtls_md_setup(&this->
ctx_, md_info, 1);
19 mbedtls_md_hmac_starts(&this->
ctx_, key,
len);
30 sprintf(output + (i * 2),
"%02x", this->
digest_[i]);
55 memset(ipad, 0,
sizeof(ipad));
63 memcpy(ipad, key,
len);
65 memcpy(opad, ipad,
sizeof(opad));
void get_hex(char *output)
Retrieve the hash as hex characters.
bool equals_hex(const char *expected)
Compare the hash against a provided hex-encoded hash.
bool equals_bytes(const uint8_t *expected)
Compare the hash against a provided byte-encoded hash.
void get_bytes(uint8_t *output)
Retrieve the hash as bytes.
bool equals_bytes(const uint8_t *expected)
Compare the digest against a provided byte-encoded digest (32 bytes).
mbedtls_md_context_t ctx_
uint8_t digest_[SHA256_DIGEST_SIZE]
static constexpr size_t SHA256_DIGEST_SIZE
bool equals_hex(const char *expected)
Compare the digest against a provided hex-encoded digest (64 bytes).
void add(const uint8_t *data, size_t len)
Add bytes of data for the digest.
void get_hex(char *output)
Retrieve the HMAC-SHA256 digest as hex characters.
void get_bytes(uint8_t *output)
Retrieve the HMAC-SHA256 digest as bytes.
void calculate()
Compute the digest, based on the provided data.
void init(const uint8_t *key, size_t len)
Initialize a new HMAC-SHA256 digest computation.
void calculate() override
void add(const uint8_t *data, size_t len) override
constexpr size_t SHA256_DIGEST_SIZE
constexpr size_t HMAC_BLOCK_SIZE