What changed, and why it matters
This is a routine code cleanup commit that reorganizes how two internal Rust software components connect to each other. It removes a circular dependency where a higher-level crate called 'bitbox02-rust' depended on a lower-level crate called 'bitbox02', and vice versa. The change moves a small piece of noise-cryptography-related code into the lower-level crate and adjusts build configuration files accordingly. There is no indication this fixes a security vulnerability or changes user-visible behavior.
No security action required. Treat as normal refactoring/dependency hygiene. Reviewers may optionally verify that the moved rust_noise_generate_static_private_key symbol is still exported with the same ABI and that cbindgen still emits the expected C header.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the Rust crate dependency graph in the BitBox02 firmware. Specifically, it breaks a cyclic dependency between ‘bitbox02’ and ‘bitbox02-rust’ by moving the BB02Random32 trait implementation and the rust_noise_generate_static_private_key C-exported function from bitbox02-rust/src/hww/noise.rs and bitbox02-rust/src/lib.rs into bitbox02/src/random.rs. It also adds bitbox02-noise as a direct dependency of bitbox02, removes bitbox02-rust as a dev-dependency of bitbox02, updates cbindgen configuration to include bitbox02, and refreshes Cargo.lock files. Functionally, the same randomness source and static private key generation logic remain in place; only their crate location changes.
Changed components
src/rust/bitbox02-rust/src/hww/noise.rssrc/rust/bitbox02-rust/src/lib.rssrc/rust/bitbox02/Cargo.tomlsrc/rust/bitbox02/src/lib.rssrc/rust/bitbox02/src/random.rssrc/rust/bitbox02-cbindgen.tomlsrc/rust/Cargo.locktest/simulator-graphical/Cargo.locktest/simulator-graphical-bb03/Cargo.lockInspect captured patch +37 / −34
diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock
index 3e3f25b..af2fbe5 100644
--- a/src/rust/Cargo.lock
+++ b/src/rust/Cargo.lock
@@ -149,7 +149,7 @@ dependencies = [
"bitbox-bytequeue",
"bitbox-framed-serial-link",
"bitbox-hal",
- "bitbox02-rust",
+ "bitbox02-noise",
"bitbox02-sys",
"futures-lite",
"grounded",
diff --git a/src/rust/bitbox02-cbindgen.toml b/src/rust/bitbox02-cbindgen.toml
index fce4ac6..2072e55 100644
--- a/src/rust/bitbox02-cbindgen.toml
+++ b/src/rust/bitbox02-cbindgen.toml
@@ -22,10 +22,10 @@ header = '''
parse_deps = true
# ... but only parse these crates.
-include = ["bitbox02-rust", "util", "bitbox-aes", "bitbox-framed-serial-link", "bitbox-bytequeue"]
+include = ["bitbox02", "bitbox02-rust", "util", "bitbox-aes", "bitbox-framed-serial-link", "bitbox-bytequeue"]
# also generate bindings from these crates.
-extra_bindings = ["bitbox02-rust", "util", "bitbox-aes", "bitbox-framed-serial-link", "bitbox-bytequeue"]
+extra_bindings = ["bitbox02", "bitbox02-rust", "util", "bitbox-aes", "bitbox-framed-serial-link", "bitbox-bytequeue"]
[export]
# malloc, free declared in bitbox02-rust-c/src/c_alloc.rs, but does not need to be exported, as it
diff --git a/src/rust/bitbox02-rust/src/hww/noise.rs b/src/rust/bitbox02-rust/src/hww/noise.rs
index 0f7eeda..8509155 100644
--- a/src/rust/bitbox02-rust/src/hww/noise.rs
+++ b/src/rust/bitbox02-rust/src/hww/noise.rs
@@ -11,17 +11,8 @@ const OP_I_CAN_HAS_PAIRIN_VERIFICASHUN: u8 = b'v';
const OP_HER_COMEZ_TEH_HANDSHAEK: u8 = b'H';
pub const OP_NOISE_MSG: u8 = b'n';
-/// Supplies the randomness source to the noise crate.
-pub enum BB02Random32 {}
-
-impl bitbox02_noise::Random32 for BB02Random32 {
- fn mcu_32_bytes(out: &mut [u8; 32]) {
- bitbox02::random::mcu_32_bytes(out);
- }
-}
-
/// A safer version of the noise state. RefCell so we cannot accidentally borrow illegally.
-struct SafeNoiseState(RefCell<bitbox02_noise::State<BB02Random32>>);
+struct SafeNoiseState(RefCell<bitbox02_noise::State<bitbox02::random::BB02Random32>>);
/// Safety: this implements Sync even though it is not thread safe. This is okay, as we run only in
/// a single thread in the BitBox02.
diff --git a/src/rust/bitbox02-rust/src/lib.rs b/src/rust/bitbox02-rust/src/lib.rs
index 9331d65..7301252 100644
--- a/src/rust/bitbox02-rust/src/lib.rs
+++ b/src/rust/bitbox02-rust/src/lib.rs
@@ -44,16 +44,3 @@ extern crate alloc;
#[cfg(test)]
extern crate bitbox_aes;
-
-//
-// C interface
-//
-
-/// `private_key_out` must be 32 bytes.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_noise_generate_static_private_key(
- mut private_key_out: util::bytes::BytesMut,
-) {
- let key = bitbox02_noise::generate_static_private_key::<hww::noise::BB02Random32>();
- private_key_out.as_mut().copy_from_slice(&key[..]);
-}
diff --git a/src/rust/bitbox02/Cargo.toml b/src/rust/bitbox02/Cargo.toml
index 121c6fd..f73ec49 100644
--- a/src/rust/bitbox02/Cargo.toml
+++ b/src/rust/bitbox02/Cargo.toml
@@ -10,6 +10,7 @@ license = "Apache-2.0"
[dependencies]
bitbox02-sys = {path="../bitbox02-sys"}
+bitbox02-noise = { path = "../bitbox02-noise" }
bitbox-hal = { path = "../bitbox-hal" }
bitbox-bytequeue = { path = "../bitbox-bytequeue" }
util = {path = "../util"}
@@ -21,7 +22,6 @@ grounded = { workspace = true }
[dev-dependencies]
bitbox-aes = { path = "../bitbox-aes" }
bitbox-framed-serial-link = { path = "../bitbox-framed-serial-link" }
-bitbox02-rust = { path = "../bitbox02-rust" }
hex_lit = { workspace = true }
[features]
diff --git a/src/rust/bitbox02/src/lib.rs b/src/rust/bitbox02/src/lib.rs
index e1660cc..f371cd5 100644
--- a/src/rust/bitbox02/src/lib.rs
+++ b/src/rust/bitbox02/src/lib.rs
@@ -19,9 +19,6 @@ extern crate alloc;
#[cfg(any(feature = "testing", feature = "simulator-graphical"))]
pub mod testing;
-#[cfg(test)]
-extern crate bitbox02_rust;
-
pub mod da14531;
pub mod da14531_handler;
pub mod da14531_protocol;
diff --git a/src/rust/bitbox02/src/random.rs b/src/rust/bitbox02/src/random.rs
index 3df33db..5b6c63e 100644
--- a/src/rust/bitbox02/src/random.rs
+++ b/src/rust/bitbox02/src/random.rs
@@ -1,5 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
+/// Supplies the randomness source to the noise crate.
+pub enum BB02Random32 {}
+
+impl bitbox02_noise::Random32 for BB02Random32 {
+ fn mcu_32_bytes(out: &mut [u8; 32]) {
+ mcu_32_bytes(out);
+ }
+}
+
#[cfg(not(feature = "testing"))]
pub fn mcu_32_bytes(out: &mut [u8; 32]) {
unsafe { bitbox02_sys::random_32_bytes_mcu(out.as_mut_ptr()) }
@@ -23,6 +32,15 @@ pub fn random_32_bytes() -> alloc::boxed::Box<zeroize::Zeroizing<[u8; 32]>> {
out
}
+/// `private_key_out` must be 32 bytes.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_noise_generate_static_private_key(
+ mut private_key_out: util::bytes::BytesMut,
+) {
+ let key = bitbox02_noise::generate_static_private_key::<BB02Random32>();
+ private_key_out.as_mut().copy_from_slice(&key[..]);
+}
+
#[cfg(feature = "testing")]
pub fn fake_reset() {
unsafe {
@@ -40,4 +58,12 @@ mod tests {
mcu_32_bytes(&mut result);
assert!([0; 32] != result);
}
+
+ #[test]
+ fn test_generate_static_private_key() {
+ let key = bitbox02_noise::generate_static_private_key::<BB02Random32>();
+ assert_eq!(key[0] & 0b111, 0);
+ assert_eq!(key[31] & 0b1000_0000, 0);
+ assert_eq!(key[31] & 0b0100_0000, 0b0100_0000);
+ }
}
diff --git a/test/simulator-graphical-bb03/Cargo.lock b/test/simulator-graphical-bb03/Cargo.lock
index 48e41c5..fe709d8 100644
--- a/test/simulator-graphical-bb03/Cargo.lock
+++ b/test/simulator-graphical-bb03/Cargo.lock
@@ -369,8 +369,9 @@ name = "bitbox02"
version = "0.1.0"
dependencies = [
"bip39",
- "bitbox-hal",
"bitbox-bytequeue",
+ "bitbox-hal",
+ "bitbox02-noise",
"bitbox02-sys",
"futures-lite",
"grounded",
@@ -395,9 +396,9 @@ dependencies = [
"bip32-ed25519",
"bip39",
"bitbox-aes",
+ "bitbox-bytequeue",
"bitbox-executor",
"bitbox-hal",
- "bitbox-bytequeue",
"bitbox-secp256k1",
"bitbox02",
"bitbox02-noise",
diff --git a/test/simulator-graphical/Cargo.lock b/test/simulator-graphical/Cargo.lock
index fb6aea9..5fdf6f9 100644
--- a/test/simulator-graphical/Cargo.lock
+++ b/test/simulator-graphical/Cargo.lock
@@ -331,8 +331,9 @@ name = "bitbox02"
version = "0.1.0"
dependencies = [
"bip39",
- "bitbox-hal",
"bitbox-bytequeue",
+ "bitbox-hal",
+ "bitbox02-noise",
"bitbox02-sys",
"futures-lite",
"grounded",
@@ -357,9 +358,9 @@ dependencies = [
"bip32-ed25519",
"bip39",
"bitbox-aes",
+ "bitbox-bytequeue",
"bitbox-executor",
"bitbox-hal",
- "bitbox-bytequeue",
"bitbox-secp256k1",
"bitbox02",
"bitbox02-noise",
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.