deduplicate MAX_UNLOCK_ATTEMPTS define
What changed, and why it matters
This is a small code cleanup change. It removes a duplicated definition of the maximum number of failed device-unlock attempts (set to 10) and makes the Rust code the single source of truth. The C code now imports that same value from Rust. The numeric value and behavior do not change.
No security action needed. Treat as a normal refactoring review; verify build still succeeds and that rust.h correctly exports MAX_UNLOCK_ATTEMPTS.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit deduplicates MAX_UNLOCK_ATTEMPTS. Previously it was defined separately in bitbox02_smarteeprom.h (C) and keystore.rs (Rust), with comments requiring them to stay in sync. The patch removes the C #define, exposes the Rust const as pub, and includes rust.h in the two C files that need it. SMALL_MONOTONIC_COUNTER_MAX_USE in optiga.c is still referenced in the comment but not modified. No functional change; value remains 10.
Changed components
src/memory/bitbox02_smarteeprom.csrc/memory/bitbox02_smarteeprom.hsrc/optiga/optiga.hsrc/rust/bitbox02-rust/src/keystore.rsInspect captured patch +6 / −12
diff --git a/src/memory/bitbox02_smarteeprom.c b/src/memory/bitbox02_smarteeprom.c
index 1a4c322..d9271c3 100644
--- a/src/memory/bitbox02_smarteeprom.c
+++ b/src/memory/bitbox02_smarteeprom.c
@@ -17,6 +17,8 @@
#include "hardfault.h"
#include "memory/smarteeprom.h"
+#include <rust/rust.h> // for MAX_UNLOCK_ATTEMPTS
+
#include <stddef.h>
#include <stdio.h>
#include <string.h>
diff --git a/src/memory/bitbox02_smarteeprom.h b/src/memory/bitbox02_smarteeprom.h
index 9c23fde..5b4d755 100644
--- a/src/memory/bitbox02_smarteeprom.h
+++ b/src/memory/bitbox02_smarteeprom.h
@@ -17,15 +17,6 @@
#include <stdint.h>
-/**
- * After this many failed unlock attempts, the keystore becomes locked until a
- * device reset.
- *
- * Must match MAX_UNLOCK_ATTEMPTS in rust keystore.rs and
- * SMALL_MONOTONIC_COUNTER_MAX_USE in optiga.c.
- */
-#define MAX_UNLOCK_ATTEMPTS (10)
-
/**
* Reads and validates the last recorded number of unlock attempts.
*/
diff --git a/src/optiga/optiga.h b/src/optiga/optiga.h
index b446e8a..0febb67 100644
--- a/src/optiga/optiga.h
+++ b/src/optiga/optiga.h
@@ -26,6 +26,8 @@
#include <stddef.h>
#include <stdint.h>
+#include <rust/rust.h> // for MAX_UNLOCK_ATTEMPTS
+
// The Data Object IDs we use.
// Stores a shared secret used for a shielded connection. Is is used to encrypt
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 725f09a..eac9a22 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -40,9 +40,8 @@ const ENCRYPTION_OVERHEAD: usize = 64;
// to roughly seven seconds so we don't assume communication was lost mid-unlock.
const LONG_TIMEOUT: i16 = -70;
-// Must match MAX_UNLOCK_ATTEMPTS in bitbox02_smarteeprom.h and
-// SMALL_MONOTONIC_COUNTER_MAX_USE in optiga.c.
-const MAX_UNLOCK_ATTEMPTS: u8 = 10;
+// After this many failed unlock attempts, the keystore becomes locked until a device reset.
+pub const MAX_UNLOCK_ATTEMPTS: u8 = 10;
#[derive(Debug)]
pub enum Error {
Why this scored 15/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.