1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-20 05:18:08 +00:00

fix(core): fix sha256 calculation with hash processor

[no changelog]
This commit is contained in:
tychovrahe 2024-04-16 14:26:15 +02:00 committed by matejcik
parent e9f6eb0b2b
commit 457e5956c8

View File

@ -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) { void hash_processor_sha256_final(hash_sha265_context_t *ctx, uint8_t *output) {
uint32_t tmp_out[SHA256_DIGEST_LENGTH / sizeof(uint32_t)] = {0}; uint32_t tmp_out[SHA256_DIGEST_LENGTH / sizeof(uint32_t)] = {0};
memzero(ctx->buffer + ctx->length, HASH_SHA256_BUFFER_SIZE - ctx->length);
if (ctx->length > 0) { HAL_HASHEx_SHA256_Accmlt_End(&hhash, (uint8_t *)ctx->buffer, ctx->length,
memzero(ctx->buffer + ctx->length, HASH_SHA256_BUFFER_SIZE - ctx->length); (uint8_t *)tmp_out, 1000);
HAL_HASHEx_SHA256_Accmlt_End(&hhash, (uint8_t *)ctx->buffer, ctx->length, ctx->length = 0;
(uint8_t *)tmp_out, 1000); memzero(ctx->buffer, HASH_SHA256_BUFFER_SIZE);
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);
}
memcpy(output, tmp_out, SHA256_DIGEST_LENGTH); memcpy(output, tmp_out, SHA256_DIGEST_LENGTH);
memzero(tmp_out, sizeof(tmp_out));
} }