keystore: call rust keystore_unlock from C
What changed, and why it matters
This commit fixes a small but meaningful inconsistency in how the BitBox02 hardware wallet locks its secure storage (keystore). Previously, two places in the C code called the older C locking function directly, even though the newer Rust code's lock function now performs extra cleanup. The change makes those C call sites use the Rust function instead, so the device consistently performs the full lock procedure. The commit message calls this a 'small fix' and does not describe any active security vulnerability or incident.
Treat as a hardening/correctness fix rather than an urgent security patch. Reviewers should verify what additional work Rust keystore::lock() performs compared with the C keystore_lock(), and confirm no other C call sites still invoke the C function directly. Users on prior firmware should update through normal channels if concerned, but no emergency action is indicated by the commit itself.
Security signals we found
Inconsistent lock path: C code bypassed Rust keystore lock logic
Potential skipped Rust-side cleanup/state update when locking from C
Fix is described by the vendor as a small correctness fix, not a disclosed vulnerability
Evidence from the diff
The patch adds a new C-exported Rust function rust_keystore_lock() that wraps keystore.rs::lock(), and replaces two direct C calls to keystore_lock() in keystore.c and reset.c with calls to rust_keystore_lock(). The Rust lock() function had already been enhanced beyond a simple pass-through to the C implementation, so calling the C function directly could skip Rust-side state or cleanup steps. The change ensures all lock paths go through the canonical Rust implementation.
Changed components
src/keystore.csrc/reset.csrc/rust/bitbox02-rust/src/keystore.rsInspect captured patch +8 / −2
diff --git a/src/keystore.c b/src/keystore.c
index 2ec5a6b..0cdedd2 100644
--- a/src/keystore.c
+++ b/src/keystore.c
@@ -336,7 +336,7 @@ keystore_error_t keystore_encrypt_and_store_seed(
if (memory_is_initialized()) {
return KEYSTORE_ERR_MEMORY;
}
- keystore_lock();
+ rust_keystore_lock();
if (!_validate_seed_length(seed_length)) {
return KEYSTORE_ERR_SEED_SIZE;
}
diff --git a/src/reset.c b/src/reset.c
index f860fd4..0184d5e 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -22,6 +22,7 @@
#include "memory/smarteeprom.h"
#include "system.h"
#include "uart.h"
+#include <rust/rust.h>
#include <screen.h>
#ifndef TESTING
@@ -64,7 +65,7 @@ void reset_ble(void)
void reset_reset(bool status)
{
- keystore_lock();
+ rust_keystore_lock();
#if !defined(TESTING)
bool sc_result_reset_keys = false;
for (int retries = 0; retries < 5; retries++) {
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 8bec507..0dd5c13 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -255,6 +255,11 @@ pub fn stretch_retained_seed_encryption_key(
Ok(zeroize::Zeroizing::new(stretched.to_vec()))
}
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_keystore_lock() {
+ lock()
+}
+
/// # Safety
///
/// `encryption_key` must refer to a 32-byte buffer and `out` must have space for 32 bytes.
Why this scored 41/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.