What changed, and why it matters
This commit is a routine internal code cleanup in the BitBox02 firmware's Rust hardware-abstraction layer. It restructures how subsystems (screen UI, random number generator, SD card, secure chip, memory, system control) are accessed so that multiple subsystems can be borrowed at the same time. The stated reason is to let the user-interface code use the random generator for a mnemonic quiz feature. There is no security fix or vulnerability patch here.
No security action needed. Review as normal code-quality/refactor change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces a HalSubsystems struct that holds mutable references to all HAL subsystem traits, and makes subsystems() the single required method on the Hal trait. Concrete implementations (BitBox02Hal, TestingHal) now expose associated types and return all subsystems together, while keeping the old per-subsystem accessor methods as default implementations. Several pub(crate) structs are widened to pub so they can be named as associated types. This is purely an architectural refactor; no behavior, boundary checks, or cryptographic operations are modified.
Changed components
src/rust/bitbox02-rust/src/hal.rssrc/rust/bitbox02-rust/src/hal/bitbox02.rssrc/rust/bitbox02-rust/src/hal/bitbox02/memory.rssrc/rust/bitbox02-rust/src/hal/bitbox02/random.rssrc/rust/bitbox02-rust/src/hal/bitbox02/sd.rssrc/rust/bitbox02-rust/src/hal/bitbox02/securechip.rssrc/rust/bitbox02-rust/src/hal/bitbox02/system.rssrc/rust/bitbox02-rust/src/hal/bitbox02/ui.rssrc/rust/bitbox02-rust/src/hal/testing.rsInspect captured patch +118 / −57
diff --git a/src/rust/bitbox02-rust/src/hal.rs b/src/rust/bitbox02-rust/src/hal.rs
index 0e90657..764f4a6 100644
--- a/src/rust/bitbox02-rust/src/hal.rs
+++ b/src/rust/bitbox02-rust/src/hal.rs
@@ -19,12 +19,65 @@ pub use securechip::SecureChip;
pub use system::System;
pub use ui::Ui;
+pub struct HalSubsystems<
+ 'a,
+ Ui: ui::Ui,
+ Random: random::Random,
+ Sd: sd::Sd,
+ SecureChip: securechip::SecureChip,
+ Memory: memory::Memory,
+ System: system::System,
+> {
+ pub ui: &'a mut Ui,
+ pub random: &'a mut Random,
+ pub sd: &'a mut Sd,
+ pub securechip: &'a mut SecureChip,
+ pub memory: &'a mut Memory,
+ pub system: &'a mut System,
+}
+
/// Hardware abstraction layer for BitBox devices.
pub trait Hal {
- fn ui(&mut self) -> &mut impl Ui;
- fn sd(&mut self) -> &mut impl Sd;
- fn random(&mut self) -> &mut impl Random;
- fn securechip(&mut self) -> &mut impl SecureChip;
- fn memory(&mut self) -> &mut impl Memory;
- fn system(&mut self) -> &mut impl System;
+ type Ui: ui::Ui;
+ type Random: random::Random;
+ type Sd: sd::Sd;
+ type SecureChip: securechip::SecureChip;
+ type Memory: memory::Memory;
+ type System: system::System;
+
+ fn subsystems(
+ &mut self,
+ ) -> HalSubsystems<
+ '_,
+ Self::Ui,
+ Self::Random,
+ Self::Sd,
+ Self::SecureChip,
+ Self::Memory,
+ Self::System,
+ >;
+
+ fn ui(&mut self) -> &mut Self::Ui {
+ self.subsystems().ui
+ }
+
+ fn random(&mut self) -> &mut Self::Random {
+ self.subsystems().random
+ }
+
+ fn sd(&mut self) -> &mut Self::Sd {
+ self.subsystems().sd
+ }
+
+ fn securechip(&mut self) -> &mut Self::SecureChip {
+ self.subsystems().securechip
+ }
+
+ fn memory(&mut self) -> &mut Self::Memory {
+ self.subsystems().memory
+ }
+
+ fn system(&mut self) -> &mut Self::System {
+ self.subsystems().system
+ }
}
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02.rs b/src/rust/bitbox02-rust/src/hal/bitbox02.rs
index 7a9cb8c..e5f197c 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02.rs
@@ -7,7 +7,7 @@ pub mod securechip;
pub mod system;
pub mod ui;
-use crate::hal::{Hal, Memory, Random, Sd, SecureChip, System, Ui};
+use crate::hal::Hal;
pub struct BitBox02Hal {
ui: ui::BitBox02Ui,
@@ -32,27 +32,31 @@ impl BitBox02Hal {
}
impl Hal for BitBox02Hal {
- fn ui(&mut self) -> &mut impl Ui {
- &mut self.ui
- }
-
- fn sd(&mut self) -> &mut impl Sd {
- &mut self.sd
- }
-
- fn random(&mut self) -> &mut impl Random {
- &mut self.random
- }
-
- fn securechip(&mut self) -> &mut impl SecureChip {
- &mut self.securechip
- }
-
- fn memory(&mut self) -> &mut impl Memory {
- &mut self.memory
- }
-
- fn system(&mut self) -> &mut impl System {
- &mut self.system
+ type Ui = ui::BitBox02Ui;
+ type Random = random::BitBox02Random;
+ type Sd = sd::BitBox02Sd;
+ type SecureChip = securechip::BitBox02SecureChip;
+ type Memory = memory::BitBox02Memory;
+ type System = system::BitBox02System;
+
+ fn subsystems(
+ &mut self,
+ ) -> crate::hal::HalSubsystems<
+ '_,
+ Self::Ui,
+ Self::Random,
+ Self::Sd,
+ Self::SecureChip,
+ Self::Memory,
+ Self::System,
+ > {
+ crate::hal::HalSubsystems {
+ ui: &mut self.ui,
+ random: &mut self.random,
+ sd: &mut self.sd,
+ securechip: &mut self.securechip,
+ memory: &mut self.memory,
+ system: &mut self.system,
+ }
}
}
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs
index a128ff7..d450888 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs
@@ -5,7 +5,7 @@ use alloc::vec::Vec;
use crate::hal::Memory;
-pub(crate) struct BitBox02Memory;
+pub struct BitBox02Memory;
impl Memory for BitBox02Memory {
fn get_securechip_type(&mut self) -> Result<bitbox02::memory::SecurechipType, ()> {
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs
index 8aac125..58d91d3 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/random.rs
@@ -4,7 +4,7 @@ use alloc::boxed::Box;
use crate::hal::Random;
-pub(crate) struct BitBox02Random;
+pub struct BitBox02Random;
impl Random for BitBox02Random {
#[inline(always)]
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/sd.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/sd.rs
index 45e60f7..9bebd77 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/sd.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/sd.rs
@@ -7,7 +7,7 @@ use futures_lite::future::yield_now;
use crate::hal::Sd;
-pub(crate) struct BitBox02Sd;
+pub struct BitBox02Sd;
impl Sd for BitBox02Sd {
#[inline(always)]
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/securechip.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/securechip.rs
index 73eea74..333c999 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/securechip.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/securechip.rs
@@ -4,7 +4,7 @@ use alloc::vec::Vec;
use crate::hal::SecureChip;
-pub(crate) struct BitBox02SecureChip;
+pub struct BitBox02SecureChip;
impl SecureChip for BitBox02SecureChip {
fn init_new_password(
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/system.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/system.rs
index 6fd5f0d..62be659 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/system.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/system.rs
@@ -2,7 +2,7 @@
use crate::hal::System;
-pub(crate) struct BitBox02System;
+pub struct BitBox02System;
impl System for BitBox02System {
fn reboot_to_bootloader(&mut self) -> ! {
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs
index 7d0db89..3cd7fab 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/ui.rs
@@ -8,7 +8,7 @@ use crate::workflow::{
trinary_input_string,
};
-pub(crate) struct BitBox02Ui;
+pub struct BitBox02Ui;
impl Ui for BitBox02Ui {
#[inline(always)]
diff --git a/src/rust/bitbox02-rust/src/hal/testing.rs b/src/rust/bitbox02-rust/src/hal/testing.rs
index c5ac3db..6844f9a 100644
--- a/src/rust/bitbox02-rust/src/hal/testing.rs
+++ b/src/rust/bitbox02-rust/src/hal/testing.rs
@@ -36,28 +36,32 @@ impl TestingHal<'_> {
}
}
-impl crate::hal::Hal for TestingHal<'_> {
- fn ui(&mut self) -> &mut impl crate::hal::Ui {
- &mut self.ui
- }
-
- fn sd(&mut self) -> &mut impl crate::hal::Sd {
- &mut self.sd
- }
-
- fn random(&mut self) -> &mut impl crate::hal::Random {
- &mut self.random
- }
+impl<'a> crate::hal::Hal for TestingHal<'a> {
+ type Ui = TestingUi<'a>;
+ type Random = TestingRandom;
+ type Sd = TestingSd;
+ type SecureChip = TestingSecureChip;
+ type Memory = TestingMemory;
+ type System = TestingSystem;
- fn securechip(&mut self) -> &mut impl crate::hal::SecureChip {
- &mut self.securechip
- }
-
- fn memory(&mut self) -> &mut impl crate::hal::Memory {
- &mut self.memory
- }
-
- fn system(&mut self) -> &mut impl crate::hal::System {
- &mut self.system
+ fn subsystems(
+ &mut self,
+ ) -> crate::hal::HalSubsystems<
+ '_,
+ Self::Ui,
+ Self::Random,
+ Self::Sd,
+ Self::SecureChip,
+ Self::Memory,
+ Self::System,
+ > {
+ crate::hal::HalSubsystems {
+ ui: &mut self.ui,
+ random: &mut self.random,
+ sd: &mut self.sd,
+ securechip: &mut self.securechip,
+ memory: &mut self.memory,
+ system: &mut self.system,
+ }
}
}
Why this scored 13/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.