bootloader: Fixes bootloader_common_get_sha256_of_partition. Adds hash check.

Closes https://github.com/espressif/esp-idf/issues/8274
This commit is contained in:
KonstantinKondrashov
2022-01-25 02:05:40 +08:00
parent ce4a4be37f
commit 4eef5fd36f
2 changed files with 29 additions and 1 deletions

View File

@@ -158,6 +158,12 @@ esp_err_t bootloader_common_get_sha256_of_partition (uint32_t address, uint32_t
}
if (data.image.hash_appended) {
memcpy(out_sha_256, data.image_digest, ESP_PARTITION_HASH_LEN);
uint8_t calc_sha256[ESP_PARTITION_HASH_LEN];
// The hash is verified before returning, if app content is invalid then the function returns ESP_ERR_IMAGE_INVALID.
esp_err_t error = bootloader_sha256_flash_contents(address, data.image_len - ESP_PARTITION_HASH_LEN, calc_sha256);
if (error || memcmp(data.image_digest, calc_sha256, ESP_PARTITION_HASH_LEN) != 0) {
return ESP_ERR_IMAGE_INVALID;
}
return ESP_OK;
}
// If image doesn't have a appended hash then hash calculates for entire image.