diff --git a/src/apdu_setup.c b/src/apdu_setup.c index b36936c8..a2e6dabd 100644 --- a/src/apdu_setup.c +++ b/src/apdu_setup.c @@ -94,7 +94,7 @@ int handle_deauthorize(void) { UPDATE_NVRAM(ram, { memset(&ram->baking_key, 0, sizeof(ram->baking_key)); }); #ifdef HAVE_BAGL // Ignore calculation errors - calculate_baking_idle_screens_data(); + calculate_idle_screen_authorized_key(); refresh_screens(); #endif // HAVE_BAGL diff --git a/src/apdu_sign.c b/src/apdu_sign.c index 1169f8e4..ebc8b833 100644 --- a/src/apdu_sign.c +++ b/src/apdu_sign.c @@ -211,7 +211,7 @@ static int baking_sign_complete(bool const send_hash) { result = perform_signature(send_hash); #ifdef HAVE_BAGL // Ignore calculation errors - calculate_baking_idle_screens_data(); + calculate_idle_screen_hwm(); // The HWM screen is not updated to avoid slowing down the // application. Updating the HWM screen may slow down the // next signing. diff --git a/src/ui.h b/src/ui.h index d3b9ab97..2401b04f 100644 --- a/src/ui.h +++ b/src/ui.h @@ -42,12 +42,33 @@ void __attribute__((noreturn)) app_exit(void); #ifdef HAVE_BAGL +/** + * @brief Calculates the chain id for the idle screens + * + * @return tz_exc: exception, SW_OK if none + */ +tz_exc calculate_idle_screen_chain_id(void); + +/** + * @brief Calculates the authorized key for the idle screens + * + * @return tz_exc: exception, SW_OK if none + */ +tz_exc calculate_idle_screen_authorized_key(void); + +/** + * @brief Calculates the HWM for the idle screens + * + * @return tz_exc: exception, SW_OK if none + */ +tz_exc calculate_idle_screen_hwm(void); + /** * @brief Calculates baking values for the idle screens * - * @return bool: whether the values have been calculated successfully or not + * @return tz_exc: exception, SW_OK if none */ -bool calculate_baking_idle_screens_data(void); +tz_exc calculate_baking_idle_screens_data(void); /** * @brief Prepare confirmation screens callbacks diff --git a/src/ui_bagl.c b/src/ui_bagl.c index b2a43846..e9a814b5 100644 --- a/src/ui_bagl.c +++ b/src/ui_bagl.c @@ -78,16 +78,25 @@ UX_FLOW(ux_idle_flow, &ux_idle_quit_step, FLOW_LOOP); -bool calculate_baking_idle_screens_data(void) { +tz_exc calculate_idle_screen_chain_id(void) { tz_exc exc = SW_OK; - memset(&home_context, 0, sizeof(home_context)); + memset(&home_context.chain_id, 0, sizeof(home_context.chain_id)); TZ_ASSERT(chain_id_to_string_with_aliases(home_context.chain_id, sizeof(home_context.chain_id), &N_data.main_chain_id) >= 0, EXC_WRONG_LENGTH); +end: + return exc; +} + +tz_exc calculate_idle_screen_authorized_key(void) { + tz_exc exc = SW_OK; + + memset(&home_context.authorized_key, 0, sizeof(home_context.authorized_key)); + if (N_data.baking_key.bip32_path.length == 0u) { TZ_ASSERT(copy_string(home_context.authorized_key, sizeof(home_context.authorized_key), @@ -99,25 +108,50 @@ bool calculate_baking_idle_screens_data(void) { &N_data.baking_key)); } +end: + return exc; +} + +tz_exc calculate_idle_screen_hwm(void) { + tz_exc exc = SW_OK; + + memset(&home_context.hwm, 0, sizeof(home_context.hwm)); + TZ_ASSERT(hwm_to_string(home_context.hwm, sizeof(home_context.hwm), &N_data.hwm.main) >= 0, EXC_WRONG_LENGTH); - return true; +end: + return exc; +} + +tz_exc calculate_baking_idle_screens_data(void) { + tz_exc exc = SW_OK; + + TZ_CHECK(calculate_idle_screen_chain_id()); + + TZ_CHECK(calculate_idle_screen_authorized_key()); + + TZ_CHECK(calculate_idle_screen_hwm()); end: - TZ_EXC_PRINT(exc); - return false; + return exc; } void ui_initial_screen(void) { + tz_exc exc = SW_OK; + // reserve a display stack slot if none yet if (G_ux.stack_count == 0) { ux_stack_push(); } - if (calculate_baking_idle_screens_data()) { - ux_flow_init(0, ux_idle_flow, NULL); - } + TZ_CHECK(calculate_baking_idle_screens_data()); + + ux_flow_init(0, ux_idle_flow, NULL); + + return; +end: + TZ_EXC_PRINT(exc); } void ux_prepare_confirm_callbacks(ui_callback_t ok_c, ui_callback_t cxl_c) {