refactor(core/embed): introduce `optiga_reset_counter()`
What changed, and why it matters
This commit is a straightforward code cleanup: it replaces several places that manually built an 8-byte zero-padded counter value with a single helper function called optiga_reset_counter(). The behavior is unchanged, and there is no indication of a security bug being fixed.
No security action required; treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The refactor introduces optiga_reset_counter(uint16_t oid, uint8_t limit), which constructs the same 8-byte {0,0,0,0,0,0,0,limit} payload previously created inline and passes it to optiga_set_data_object(). All call sites in optiga.c that previously used COUNTER_RESET or COUNTER_RESET_EXTRA arrays now use the helper. The functional behavior is identical; no security boundary or logic is altered.
Changed components
core/embed/sec/optiga/optiga.ccore/embed/sec/optiga/optiga_commands.ccore/embed/sec/optiga/inc/sec/optiga_commands.hInspect captured patch +12 / −15
diff --git a/core/embed/sec/optiga/inc/sec/optiga_commands.h b/core/embed/sec/optiga/inc/sec/optiga_commands.h
index 7ffc9fece..c562bd175 100644
--- a/core/embed/sec/optiga/inc/sec/optiga_commands.h
+++ b/core/embed/sec/optiga/inc/sec/optiga_commands.h
@@ -240,6 +240,7 @@ optiga_result optiga_derive_key(optiga_key_derivation deriv, uint16_t oid,
optiga_result optiga_set_trust_anchor(void);
optiga_result optiga_set_priv_key(uint16_t oid, const uint8_t priv_key[32]);
optiga_result optiga_clear_all_auto_states(void);
+optiga_result optiga_reset_counter(uint16_t oid, uint8_t limit);
#if !PRODUCTION
void optiga_command_set_log_hex(optiga_log_hex_t f);
diff --git a/core/embed/sec/optiga/optiga.c b/core/embed/sec/optiga/optiga.c
index 2105bfbf0..7cda0c021 100644
--- a/core/embed/sec/optiga/optiga.c
+++ b/core/embed/sec/optiga/optiga.c
@@ -69,13 +69,6 @@
// The throttling delay when the security event counter is at its maximum.
#define OPTIGA_T_MAX_MS 5000
-// Value of the PIN counter when it is reset.
-static const uint8_t COUNTER_RESET[] = {0, 0, 0, 0, 0, 0, 0, PIN_MAX_TRIES};
-
-// Value of the PIN counter with one extra attempt needed in optiga_pin_set().
-static const uint8_t COUNTER_RESET_EXTRA[] = {0, 0, 0, 0,
- 0, 0, 0, PIN_MAX_TRIES + 1};
-
// Initial value of the counter which limits the total number of PIN stretching
// operations. The limit is 600000 stretching operations, which equates to
// 300000 / PIN_STRETCH_ITERATIONS unlock operations over the lifetime of the
@@ -683,8 +676,8 @@ bool optiga_pin_set(optiga_ui_progress_t ui_progress,
// Initialize the counter which limits the guesses at OID_STRETCHED_PIN with
// one extra attempt that we will use up in the next step.
- if (optiga_set_data_object(OID_STRETCHED_PIN_CTR, false, COUNTER_RESET_EXTRA,
- sizeof(COUNTER_RESET_EXTRA)) != OPTIGA_SUCCESS) {
+ if (optiga_reset_counter(OID_STRETCHED_PIN_CTR, PIN_MAX_TRIES + 1) !=
+ OPTIGA_SUCCESS) {
ret = false;
goto end;
}
@@ -707,8 +700,7 @@ bool optiga_pin_set(optiga_ui_progress_t ui_progress,
}
// Initialize the PIN counter which limits the use of OID_PIN_HMAC.
- if (optiga_set_data_object(OID_PIN_HMAC_CTR, false, COUNTER_RESET,
- sizeof(COUNTER_RESET)) != OPTIGA_SUCCESS) {
+ if (optiga_reset_counter(OID_PIN_HMAC_CTR, PIN_MAX_TRIES) != OPTIGA_SUCCESS) {
ret = false;
goto end;
}
@@ -907,8 +899,7 @@ optiga_pin_result optiga_pin_verify(
ui_progress();
// Reset the counter which limits the use of OID_PIN_HMAC.
- if (optiga_set_data_object(OID_PIN_HMAC_CTR, false, COUNTER_RESET,
- sizeof(COUNTER_RESET)) != OPTIGA_SUCCESS) {
+ if (optiga_reset_counter(OID_PIN_HMAC_CTR, PIN_MAX_TRIES) != OPTIGA_SUCCESS) {
ret = OPTIGA_PIN_ERROR;
goto end;
}
@@ -934,8 +925,8 @@ optiga_pin_result optiga_pin_verify(
}
// Reset the counter which limits the guesses at OID_STRETCHED_PIN.
- if (optiga_set_data_object(OID_STRETCHED_PIN_CTR, false, COUNTER_RESET,
- sizeof(COUNTER_RESET)) != OPTIGA_SUCCESS) {
+ if (optiga_reset_counter(OID_STRETCHED_PIN_CTR, PIN_MAX_TRIES) !=
+ OPTIGA_SUCCESS) {
ret = OPTIGA_PIN_ERROR;
goto end;
}
diff --git a/core/embed/sec/optiga/optiga_commands.c b/core/embed/sec/optiga/optiga_commands.c
index a314c1787..e44521149 100644
--- a/core/embed/sec/optiga/optiga_commands.c
+++ b/core/embed/sec/optiga/optiga_commands.c
@@ -999,4 +999,9 @@ optiga_result optiga_clear_all_auto_states(void) {
return OPTIGA_SUCCESS;
}
+optiga_result optiga_reset_counter(uint16_t oid, uint8_t limit) {
+ uint8_t value_array[8] = {0, 0, 0, 0, 0, 0, 0, limit};
+ return optiga_set_data_object(oid, false, value_array, sizeof(value_array));
+}
+
#endif // SECURE_MODE
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.