keystore: compile rust_secp256k1_get_private_key only for testing
What changed, and why it matters
This commit removes a function that can extract a private key from the compiled firmware build, leaving it available only for automated tests. The change reduces the amount of sensitive key-extraction code present in the final device firmware, which is a defensive hardening step rather than a fix for an active attack.
Verify that no production code paths or linker scripts still reference rust_secp256k1_get_private_key, and confirm that test-only builds still compile and pass. Consider auditing other #[cfg(feature = "firmware")] exports in the keystore for similar unused sensitive interfaces.
Security signals we found
private-key-extraction function removed from production build
conditional compilation narrowed from firmware to test-only
defensive reduction of attack surface in keystore module
Evidence from the diff
The diff changes the conditional compilation attribute on rust_secp256k1_get_private_key from #[cfg(feature = "firmware")] to #[cfg(feature = "c-unit-testing")]. The function exposes a C-callable interface that returns a secp256k1 private key for a given keypath. The commit message states it is ‘Not used in the firmware.’ This prevents the symbol from being compiled into production firmware while keeping it for test suites.
Changed components
src/rust/bitbox02-rust/src/keystore.rsrust_secp256k1_get_private_keyInspect captured patch +1 / −1
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 8792967..e6be355 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -187,7 +187,7 @@ pub fn secp256k1_schnorr_sign(
/// # Safety
///
/// keypath pointer has point to a buffer of length `keypath_len` uint32 elements.
-#[cfg(feature = "firmware")]
+#[cfg(feature = "c-unit-testing")]
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust_secp256k1_get_private_key(
keypath: *const u32,
Why this scored 24/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.