Hello Nordic team,
I'm currently looking into mbedtls on nRF5340, I'm using nRF NCS SDK 2.1.0
I wanted to calculate the HASH of the firmware image, I already developed one API that calculate and provide me a HASH of firmware image,
But I am unsure that API internally used the nRF5340 hardware acceleration feature or not? If not, then please provide me a sample code that used the hardware-acceleration internally?
Below is my API that provide me a HASH of firmware image.
void calculate_file_hash(unsigned char *hash_value, size_t hash_size)
{
uint8_t buffer[READ_FLASH_BYTES];
size_t bytes_read, address = QSPI_OTA_HEADER_START_ADDRESS;
int rc = 0u;
LOG_INF("calculate_file_hash");
mbedtls_sha256_context sha256_ctx;
mbedtls_sha256_init(&sha256_ctx);
mbedtls_sha256_starts(&sha256_ctx, /*is224=*/0);
for(bytes_read = 210539; bytes_read > 0; ) // For Net core
{
if(bytes_read >= READ_FLASH_BYTES)
{
rc = external_flash_sector_read(address, buffer, READ_FLASH_BYTES);
if(rc != 0U)
{
LOG_INF("Error in flash reading(%x)", rc);
}
mbedtls_sha256_update(&sha256_ctx, buffer, READ_FLASH_BYTES);
}
else
{
memset(buffer, 0xFF, READ_FLASH_BYTES);
rc = external_flash_sector_read(address, buffer, bytes_read);
if(rc != 0U)
{
LOG_INF("Error in flash reading(%x)", rc);
}
mbedtls_sha256_update(&sha256_ctx, buffer, bytes_read);
}
if(bytes_read >= READ_FLASH_BYTES)
{
bytes_read = bytes_read - READ_FLASH_BYTES;
}
else
{
bytes_read = 0;
}
address = address + READ_FLASH_BYTES;
// LOG_INF("address = %x, bytes_read = %d", address, bytes_read);
}
mbedtls_sha256_finish(&sha256_ctx, hash_value);
mbedtls_sha256_free(&sha256_ctx);
}
Thanks in advance,
Kaushik