Get SHA256 of SPIFFS partition?
Posted: Mon Jun 29, 2020 6:44 pm
Im having some trouble getting the ESP to properly calculate the SHA hash of my SPIFFS partition.
Using IDF 3.3.1
This works fine for getting the SHA256 of the running firmware
But this returns all zero's for the SPIFFS SHA256
=================================================================================
(This is what Im doing to print the hash)
Using IDF 3.3.1
This works fine for getting the SHA256 of the running firmware
Code: Select all
uint8_t FWsha_256[HASH_LEN] = {0};
esp_partition_get_sha256(esp_ota_get_running_partition(), FWsha_256);
calc_sha256(FWsha_256);
ESP_LOGE(TAG, "spiffs hash: %s", hash_print);
Code: Select all
const esp_partition_t *_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
uint8_t SPIFFSsha_256[HASH_LEN] = {0};
esp_partition_get_sha256(&_partition, SPIFFSsha_256);
calc_sha256(SPIFFSsha_256);
ESP_LOGE(TAG, "spiffs hash: %s", hash_print);
(This is what Im doing to print the hash)
Code: Select all
char hash_print[HASH_LEN * 2 + 1];
#define HASH_LEN 32 /* SHA-256 digest length */
static void calc_sha256(const uint8_t *image_hash)
{
hash_print[HASH_LEN * 2] = 0;
for (int i = 0; i < HASH_LEN; ++i)
{
sprintf(&hash_print[i * 2], "%02x", image_hash[i]);
}
}