From aa1ccb8913eacf25ff02893ffb6204e117f0b0bb Mon Sep 17 00:00:00 2001 From: cepetr Date: Mon, 30 Sep 2024 08:39:38 +0200 Subject: [PATCH] refactor(core): remove hash_processor syscalls [no changelog] --- core/embed/lib/image_hash_conf.h | 2 +- core/embed/trezorhal/hash_processor.h | 4 +++ .../trezorhal/stm32f4/syscall_dispatch.c | 28 ------------------- .../embed/trezorhal/stm32f4/syscall_numbers.h | 5 ---- core/embed/trezorhal/stm32f4/syscall_stubs.c | 26 ----------------- 5 files changed, 5 insertions(+), 60 deletions(-) diff --git a/core/embed/lib/image_hash_conf.h b/core/embed/lib/image_hash_conf.h index 1fab5efabd9..11177cbc1e2 100644 --- a/core/embed/lib/image_hash_conf.h +++ b/core/embed/lib/image_hash_conf.h @@ -7,7 +7,7 @@ #ifdef IMAGE_HASH_SHA256 #include "sha2.h" #define IMAGE_HASH_DIGEST_LENGTH SHA256_DIGEST_LENGTH -#ifdef USE_HASH_PROCESSOR +#if defined(USE_HASH_PROCESSOR) && defined(KERNEL_MODE) #include "hash_processor.h" #define IMAGE_HASH_CTX hash_sha265_context_t #define IMAGE_HASH_INIT(ctx) hash_processor_sha256_init(ctx) diff --git a/core/embed/trezorhal/hash_processor.h b/core/embed/trezorhal/hash_processor.h index 66c85653b93..d72e8101d00 100644 --- a/core/embed/trezorhal/hash_processor.h +++ b/core/embed/trezorhal/hash_processor.h @@ -3,6 +3,8 @@ #include +#ifdef KERNEL_MODE + #define HASH_SHA256_BUFFER_SIZE 4 typedef struct { @@ -34,4 +36,6 @@ void hash_processor_sha256_update(hash_sha265_context_t *ctx, // Finalize the hash calculation, retrieve the digest void hash_processor_sha256_final(hash_sha265_context_t *ctx, uint8_t *output); +#endif // KERNEL_MODE + #endif diff --git a/core/embed/trezorhal/stm32f4/syscall_dispatch.c b/core/embed/trezorhal/stm32f4/syscall_dispatch.c index fbfc38aadfe..dfe2426e00d 100644 --- a/core/embed/trezorhal/stm32f4/syscall_dispatch.c +++ b/core/embed/trezorhal/stm32f4/syscall_dispatch.c @@ -29,7 +29,6 @@ #include "entropy.h" #include "fwutils.h" #include "haptic.h" -#include "hash_processor.h" #include "irq.h" #include "mpu.h" #include "optiga.h" @@ -130,33 +129,6 @@ __attribute((no_stack_protector)) void syscall_handler(uint32_t *args, reboot_and_upgrade(hash); } break; -#ifdef STM32U5 - case SYSCALL_SHA256_INIT: { - hash_sha265_context_t *ctx = (hash_sha265_context_t *)args[0]; - hash_processor_sha256_init(ctx); - } break; - - case SYSCALL_SHA256_UPDATE: { - hash_sha265_context_t *ctx = (hash_sha265_context_t *)args[0]; - const uint8_t *data = (const uint8_t *)args[1]; - uint32_t len = args[2]; - hash_processor_sha256_update(ctx, data, len); - } break; - - case SYSCALL_SHA256_FINAL: { - hash_sha265_context_t *ctx = (hash_sha265_context_t *)args[0]; - uint8_t *output = (uint8_t *)args[1]; - hash_processor_sha256_final(ctx, output); - } break; - - case SYSCALL_SHA256_CALC: { - const uint8_t *data = (const uint8_t *)args[0]; - uint32_t len = args[1]; - uint8_t *hash = (uint8_t *)args[2]; - hash_processor_sha256_calc(data, len, hash); - } break; -#endif // STM32U5 - case SYSCALL_DISPLAY_SET_BACKLIGHT: { int level = (int)args[0]; args[0] = display_set_backlight(level); diff --git a/core/embed/trezorhal/stm32f4/syscall_numbers.h b/core/embed/trezorhal/stm32f4/syscall_numbers.h index 2341d02ed7a..24631809271 100644 --- a/core/embed/trezorhal/stm32f4/syscall_numbers.h +++ b/core/embed/trezorhal/stm32f4/syscall_numbers.h @@ -37,11 +37,6 @@ typedef enum { SYSCALL_REBOOT_TO_BOOTLOADER, SYSCALL_REBOOT_AND_UPGRADE, - SYSCALL_SHA256_INIT, - SYSCALL_SHA256_UPDATE, - SYSCALL_SHA256_FINAL, - SYSCALL_SHA256_CALC, - SYSCALL_DISPLAY_SET_BACKLIGHT, SYSCALL_DISPLAY_GET_BACKLIGHT, SYSCALL_DISPLAY_SET_ORIENTATION, diff --git a/core/embed/trezorhal/stm32f4/syscall_stubs.c b/core/embed/trezorhal/stm32f4/syscall_stubs.c index 2f7a63ba827..045e0779a04 100644 --- a/core/embed/trezorhal/stm32f4/syscall_stubs.c +++ b/core/embed/trezorhal/stm32f4/syscall_stubs.c @@ -98,32 +98,6 @@ void reboot(void) { ; } -// ============================================================================= -// hash_processor.h -// ============================================================================= - -#include "hash_processor.h" - -void hash_processor_sha256_init(hash_sha265_context_t *ctx) { - syscall_invoke1((uint32_t)ctx, SYSCALL_SHA256_INIT); -} - -// Feed the hash next chunk of data -void hash_processor_sha256_update(hash_sha265_context_t *ctx, - const uint8_t *data, uint32_t len) { - syscall_invoke3((uint32_t)ctx, (uint32_t)data, len, SYSCALL_SHA256_UPDATE); -} - -// Finalize the hash calculation, retrieve the digest -void hash_processor_sha256_final(hash_sha265_context_t *ctx, uint8_t *output) { - syscall_invoke2((uint32_t)ctx, (uint32_t)output, SYSCALL_SHA256_FINAL); -} - -void hash_processor_sha256_calc(const uint8_t *data, uint32_t len, - uint8_t *hash) { - syscall_invoke3((uint32_t)data, len, (uint32_t)hash, SYSCALL_SHA256_CALC); -} - // ============================================================================= // xdisplay.h // =============================================================================