Skip to content

Commit

Permalink
refactor(core): remove hash_processor syscalls
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
cepetr committed Sep 30, 2024
1 parent abc7fdc commit aa1ccb8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 60 deletions.
2 changes: 1 addition & 1 deletion core/embed/lib/image_hash_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions core/embed/trezorhal/hash_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stdint.h>

#ifdef KERNEL_MODE

#define HASH_SHA256_BUFFER_SIZE 4

typedef struct {
Expand Down Expand Up @@ -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
28 changes: 0 additions & 28 deletions core/embed/trezorhal/stm32f4/syscall_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions core/embed/trezorhal/stm32f4/syscall_numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 0 additions & 26 deletions core/embed/trezorhal/stm32f4/syscall_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =============================================================================
Expand Down

0 comments on commit aa1ccb8

Please sign in to comment.