From 457e5956c85e3a2f5ec7c8ce0e478a155a1d854e Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Tue, 16 Apr 2024 14:26:15 +0200 Subject: [PATCH] fix(core): fix sha256 calculation with hash processor [no changelog] --- core/embed/trezorhal/stm32u5/hash_processor.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/core/embed/trezorhal/stm32u5/hash_processor.c b/core/embed/trezorhal/stm32u5/hash_processor.c index 390b2426b..57993663a 100644 --- a/core/embed/trezorhal/stm32u5/hash_processor.c +++ b/core/embed/trezorhal/stm32u5/hash_processor.c @@ -117,16 +117,11 @@ void hash_processor_sha256_update(hash_sha265_context_t *ctx, void hash_processor_sha256_final(hash_sha265_context_t *ctx, uint8_t *output) { uint32_t tmp_out[SHA256_DIGEST_LENGTH / sizeof(uint32_t)] = {0}; - - if (ctx->length > 0) { - memzero(ctx->buffer + ctx->length, HASH_SHA256_BUFFER_SIZE - ctx->length); - HAL_HASHEx_SHA256_Accmlt_End(&hhash, (uint8_t *)ctx->buffer, ctx->length, - (uint8_t *)tmp_out, 1000); - ctx->length = 0; - memzero(ctx->buffer, HASH_SHA256_BUFFER_SIZE); - } else { - HASH->STR |= HASH_STR_DCAL; - HAL_HASHEx_SHA256_Finish(&hhash, (uint8_t *)tmp_out, 1000); - } + memzero(ctx->buffer + ctx->length, HASH_SHA256_BUFFER_SIZE - ctx->length); + HAL_HASHEx_SHA256_Accmlt_End(&hhash, (uint8_t *)ctx->buffer, ctx->length, + (uint8_t *)tmp_out, 1000); + ctx->length = 0; + memzero(ctx->buffer, HASH_SHA256_BUFFER_SIZE); memcpy(output, tmp_out, SHA256_DIGEST_LENGTH); + memzero(tmp_out, sizeof(tmp_out)); }