debug(core): introduce adjustable wait time

onvej-sl/optiga-debug
Ondřej Vejpustek 2 weeks ago
parent 23f88dbb5f
commit 9c36e0314c

@ -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);

@ -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");
}
}

Loading…
Cancel
Save