From 9c36e0314c0aceca75039186d7f2f8f9eeaa2554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Fri, 19 Apr 2024 15:37:15 +0200 Subject: [PATCH] debug(core): introduce adjustable wait time --- core/embed/prodtest/main.c | 12 ++++++++++++ core/embed/trezorhal/stm32f4/random_delays.c | 16 ++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/embed/prodtest/main.c b/core/embed/prodtest/main.c index 71a822c99..c9b035c89 100644 --- a/core/embed/prodtest/main.c +++ b/core/embed/prodtest/main.c @@ -208,6 +208,14 @@ static void test_display(const char *colors) { vcp_println("OK"); } +extern int random_delays_wait_time; + +static void set_wait_time(const char *wait_time_string) { + int wait_time = atoi(wait_time_string); + random_delays_wait_time = wait_time; + vcp_println("OK"); +} + #ifdef USE_BUTTON static secbool test_btn_press(uint32_t deadline, uint32_t btn) { @@ -678,6 +686,10 @@ int main(void) { } else if (startswith(line, "DISP ")) { test_display(line + 5); + + } else if (startswith(line, "SET WAIT TIME ")) { + set_wait_time(line + 14); + #ifdef USE_BUTTON } else if (startswith(line, "BUTTON ")) { test_button(line + 7); diff --git a/core/embed/trezorhal/stm32f4/random_delays.c b/core/embed/trezorhal/stm32f4/random_delays.c index a2f11bd31..b4e1c182f 100644 --- a/core/embed/trezorhal/stm32f4/random_delays.c +++ b/core/embed/trezorhal/stm32f4/random_delays.c @@ -54,6 +54,8 @@ _Static_assert(CHACHA_DRBG_OPTIMAL_RESEED_LENGTH(1) == DRBG_TRNG_ENTROPY_LENGTH, ""); #define BUFFER_LENGTH 64 +int random_delays_wait_time = 0; + static CHACHA_DRBG_CTX drbg_ctx; static secbool drbg_initialized = secfalse; static uint8_t session_delay; @@ -193,18 +195,8 @@ void rdi_handler(uint32_t uw_tick) { * against fault injection. */ void wait_random(void) { - int wait = drbg_random8(); volatile int i = 0; - volatile int j = wait; - while (i < wait) { - if (i + j != wait) { - shutdown_privileged(); - } - ++i; - --j; - } - // Double-check loop completion. - if (i != wait || j != 0) { - shutdown_privileged(); + for (i = 0; i < random_delays_wait_time; i++) { + __asm__("nop"); } }