What changed, and why it matters
This commit adds a new method called mcu_32_bytes to the random number generation abstraction layer in the BitBox02 firmware. It is a straightforward code addition that exposes an existing microcontroller random function through the Rust hardware abstraction layer, and adds corresponding test support. There is no indication this fixes or introduces a security vulnerability.
No security action required; review as normal code change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch extends the Random trait with mcu_32_bytes(&mut self, out: &mut [u8; 32]), implements it for the real BitBox02 HAL by calling bitbox02::random::mcu_32_bytes(out), and implements it for the testing HAL by reusing the same deterministic mock sequence used by random_32_bytes. It also refactors TestingRandom slightly to share the next_value() helper and adds a unit test verifying deterministic output. No cryptographic logic, entropy source, or memory safety behavior is changed.
Changed components
src/rust/bitbox02-rust/src/hal/bitbox02/random.rssrc/rust/bitbox02-rust/src/hal/random.rssrc/rust/bitbox02-rust/src/hal/testing/random.rsInspect captured patch +36 / −6
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs
index 58d91d3..e1663fd 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs
@@ -11,4 +11,9 @@ impl Random for BitBox02Random {
fn random_32_bytes(&mut self) -> Box<zeroize::Zeroizing<[u8; 32]>> {
bitbox02::random::random_32_bytes()
}
+
+ #[inline(always)]
+ fn mcu_32_bytes(&mut self, out: &mut [u8; 32]) {
+ bitbox02::random::mcu_32_bytes(out);
+ }
}
diff --git a/src/rust/bitbox02-rust/src/hal/random.rs b/src/rust/bitbox02-rust/src/hal/random.rs
index 84e534f..1536f76 100644
--- a/src/rust/bitbox02-rust/src/hal/random.rs
+++ b/src/rust/bitbox02-rust/src/hal/random.rs
@@ -4,4 +4,5 @@ use alloc::boxed::Box;
pub trait Random {
fn random_32_bytes(&mut self) -> Box<zeroize::Zeroizing<[u8; 32]>>;
+ fn mcu_32_bytes(&mut self, out: &mut [u8; 32]);
}
diff --git a/src/rust/bitbox02-rust/src/hal/testing/random.rs b/src/rust/bitbox02-rust/src/hal/testing/random.rs
index 2a3b5a1..d871412 100644
--- a/src/rust/bitbox02-rust/src/hal/testing/random.rs
+++ b/src/rust/bitbox02-rust/src/hal/testing/random.rs
@@ -21,18 +21,25 @@ impl TestingRandom {
pub fn mock_next(&mut self, value: [u8; 32]) {
self.mock_next_values.push_back(value)
}
-}
-impl crate::hal::Random for TestingRandom {
- fn random_32_bytes(&mut self) -> Box<zeroize::Zeroizing<[u8; 32]>> {
+ fn next_value(&mut self) -> [u8; 32] {
self.counter += 1;
- let value = if let Some(value) = self.mock_next_values.pop_front() {
+ if let Some(value) = self.mock_next_values.pop_front() {
value
} else {
let hash = sha256::Hash::hash(&self.counter.to_be_bytes());
hash.to_byte_array()
- };
- Box::new(zeroize::Zeroizing::new(value))
+ }
+ }
+}
+
+impl crate::hal::Random for TestingRandom {
+ fn random_32_bytes(&mut self) -> Box<zeroize::Zeroizing<[u8; 32]>> {
+ Box::new(zeroize::Zeroizing::new(self.next_value()))
+ }
+
+ fn mcu_32_bytes(&mut self, out: &mut [u8; 32]) {
+ *out = self.next_value();
}
}
@@ -56,4 +63,21 @@ mod tests {
&hex!("433ebf5bc03dffa38536673207a21281612cef5faa9bc7a4d5b9be2fdb12cf1a"),
);
}
+
+ #[test]
+ fn test_mcu_32_bytes() {
+ let mut random = TestingRandom::new();
+ let mut first = [0u8; 32];
+ let mut second = [0u8; 32];
+ random.mcu_32_bytes(&mut first);
+ random.mcu_32_bytes(&mut second);
+ assert_eq!(
+ first,
+ hex!("b40711a88c7039756fb8a73827eabe2c0fe5a0346ca7e0a104adc0fc764f528d"),
+ );
+ assert_eq!(
+ second,
+ hex!("433ebf5bc03dffa38536673207a21281612cef5faa9bc7a4d5b9be2fdb12cf1a"),
+ );
+ }
}
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.