add monotonic_increments_remaining to securechip HAL
What changed, and why it matters
This commit is a small internal refactoring: it adds a way to read the secure chip's remaining monotonic counter through the hardware abstraction layer (HAL), and updates the Device Info API to use that new HAL method instead of calling the secure chip directly. There is no obvious security bug introduced or fixed here; it is mostly a code-organization change.
No immediate action required. Review as normal code-quality/HAL-cleanup change. If this is part of a larger series, evaluate the series as a whole for security relevance.
Security signals we found
No new input parsing or trust boundary introduced
No change to access-control checks on DeviceInfo request
No change to the semantics of monotonic counter reporting
Refactoring only: moves an existing secure-chip call behind the HAL trait
Evidence from the diff
The patch extends the SecureChip trait with monotonic_increments_remaining() and provides implementations for the real BitBox02 secure chip and the testing mock. It then threads the HAL into device_info::process() and replaces a direct call to securechip::monotonic_increments_remaining() with hal.securechip().monotonic_increments_remaining(). The functionality exposed to callers is unchanged.
Changed components
src/rust/bitbox02-rust/src/hal.rssrc/rust/bitbox02-rust/src/hww/api.rssrc/rust/bitbox02-rust/src/hww/api/device_info.rsInspect captured patch +13 / −3
diff --git a/src/rust/bitbox02-rust/src/hal.rs b/src/rust/bitbox02-rust/src/hal.rs
index b7b6ce4..4cd3550 100644
--- a/src/rust/bitbox02-rust/src/hal.rs
+++ b/src/rust/bitbox02-rust/src/hal.rs
@@ -53,6 +53,7 @@ pub trait SecureChip {
challenge: &[u8; 32],
signature: &mut [u8; 64],
) -> Result<(), ()>;
+ fn monotonic_increments_remaining(&mut self) -> Result<u32, ()>;
}
/// Hardware abstraction layer for BitBox devices.
@@ -143,6 +144,10 @@ impl SecureChip for BitBox02SecureChip {
) -> Result<(), ()> {
bitbox02::securechip::attestation_sign(challenge, signature)
}
+
+ fn monotonic_increments_remaining(&mut self) -> Result<u32, ()> {
+ bitbox02::securechip::monotonic_increments_remaining()
+ }
}
pub struct BitBox02Hal {
@@ -353,6 +358,10 @@ pub mod testing {
self.event_counter += 1;
todo!()
}
+
+ fn monotonic_increments_remaining(&mut self) -> Result<u32, ()> {
+ Ok(1)
+ }
}
pub struct TestingHal<'a> {
diff --git a/src/rust/bitbox02-rust/src/hww/api.rs b/src/rust/bitbox02-rust/src/hww/api.rs
index 3ade481..4ae4ca3 100644
--- a/src/rust/bitbox02-rust/src/hww/api.rs
+++ b/src/rust/bitbox02-rust/src/hww/api.rs
@@ -166,7 +166,7 @@ fn can_call(request: &Request) -> bool {
async fn process_api(hal: &mut impl crate::hal::Hal, request: &Request) -> Result<Response, Error> {
match request {
Request::Reboot(request) => system::reboot_to_bootloader(hal, request).await,
- Request::DeviceInfo(_) => device_info::process(),
+ Request::DeviceInfo(_) => device_info::process(hal),
Request::DeviceName(request) => set_device_name::process(hal, request).await,
Request::SetPassword(request) => set_password::process(hal, request).await,
Request::ChangePassword(_) => change_password::process(hal).await,
diff --git a/src/rust/bitbox02-rust/src/hww/api/device_info.rs b/src/rust/bitbox02-rust/src/hww/api/device_info.rs
index a8c1009..b7f5308 100644
--- a/src/rust/bitbox02-rust/src/hww/api/device_info.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/device_info.rs
@@ -13,13 +13,14 @@
// limitations under the License.
use super::Error;
+use crate::hal::SecureChip;
use crate::pb;
use pb::response::Response;
use bitbox02::{memory, securechip, spi_mem};
-pub fn process() -> Result<Response, Error> {
+pub fn process(hal: &mut impl crate::hal::Hal) -> Result<Response, Error> {
let bluetooth = match memory::get_platform().map_err(|_| Error::Memory)? {
memory::Platform::BitBox02Plus => {
let ble_metadata = memory::get_ble_metadata();
@@ -37,7 +38,7 @@ pub fn process() -> Result<Response, Error> {
initialized: memory::is_initialized(),
version: crate::version::FIRMWARE_VERSION_SHORT.into(),
mnemonic_passphrase_enabled: memory::is_mnemonic_passphrase_enabled(),
- monotonic_increments_remaining: securechip::monotonic_increments_remaining()?,
+ monotonic_increments_remaining: hal.securechip().monotonic_increments_remaining()?,
securechip_model: match securechip::model()? {
securechip::Model::ATECC_ATECC608A => "ATECC608A".into(),
securechip::Model::ATECC_ATECC608B => "ATECC608B".into(),
Why this scored 16/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.