What changed, and why it matters
This commit is a simple internal cleanup: it takes two places in the firmware that were doing the same 'wait until the secure chip is no longer busy' loop and makes them share one copy of that loop. There is no change in behavior, no new feature, and no indication of a security fix.
No security action needed. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors the async Optiga wrapper in src/rust/bitbox-securechip/src/optiga/ops.rs. It extracts the busy-polling poll_fn block into a new helper wait_until_not_busy() and reuses it from both reclaim_detached_op() and wait(). The control flow and outcomes are preserved: wait() still returns Ok(()) only on OPTIGA_LIB_SUCCESS and Err(status) otherwise, and reclaim_detached_op() still discards the returned status. The diff is purely code deduplication with no functional change.
Changed components
src/rust/bitbox-securechip/src/optiga/ops.rsInspect captured patch +17 / −32
diff --git a/src/rust/bitbox-securechip/src/optiga/ops.rs b/src/rust/bitbox-securechip/src/optiga/ops.rs
index 2be864b..6c5fb7c 100644
--- a/src/rust/bitbox-securechip/src/optiga/ops.rs
+++ b/src/rust/bitbox-securechip/src/optiga/ops.rs
@@ -160,23 +160,7 @@ async fn reclaim_detached_op() {
}
let mut guard = AsyncOpGuard::new();
- poll_fn(|cx| {
- let status = unsafe { bitbox_securechip_sys::optiga_ops_get_status() };
- if status == bitbox_securechip_sys::OPTIGA_LIB_BUSY as _ {
- WAKER.register(cx.waker());
- let status = unsafe { bitbox_securechip_sys::optiga_ops_get_status() };
- if status == bitbox_securechip_sys::OPTIGA_LIB_BUSY as _ {
- Poll::Pending
- } else {
- WAKER.clear();
- Poll::Ready(())
- }
- } else {
- WAKER.clear();
- Poll::Ready(())
- }
- })
- .await;
+ let _ = wait_until_not_busy().await;
guard.disarm();
WAKER.clear();
STATE.write(AsyncOpState::Idle);
@@ -226,13 +210,7 @@ async fn run_async_op(
result
}
-async fn wait(
- initial_status: bitbox_securechip_sys::optiga_lib_status_t,
-) -> Result<(), bitbox_securechip_sys::optiga_lib_status_t> {
- if initial_status != bitbox_securechip_sys::OPTIGA_LIB_SUCCESS as _ {
- return Err(initial_status);
- }
-
+async fn wait_until_not_busy() -> bitbox_securechip_sys::optiga_lib_status_t {
poll_fn(|cx| {
let status = unsafe { bitbox_securechip_sys::optiga_ops_get_status() };
if status == bitbox_securechip_sys::OPTIGA_LIB_BUSY as _ {
@@ -242,24 +220,31 @@ async fn wait(
let status = unsafe { bitbox_securechip_sys::optiga_ops_get_status() };
if status == bitbox_securechip_sys::OPTIGA_LIB_BUSY as _ {
Poll::Pending
- } else if status == bitbox_securechip_sys::OPTIGA_LIB_SUCCESS as _ {
- WAKER.clear();
- Poll::Ready(Ok(()))
} else {
WAKER.clear();
- Poll::Ready(Err(status))
+ Poll::Ready(status)
}
- } else if status == bitbox_securechip_sys::OPTIGA_LIB_SUCCESS as _ {
- WAKER.clear();
- Poll::Ready(Ok(()))
} else {
WAKER.clear();
- Poll::Ready(Err(status))
+ Poll::Ready(status)
}
})
.await
}
+async fn wait(
+ initial_status: bitbox_securechip_sys::optiga_lib_status_t,
+) -> Result<(), bitbox_securechip_sys::optiga_lib_status_t> {
+ if initial_status != bitbox_securechip_sys::OPTIGA_LIB_SUCCESS as _ {
+ return Err(initial_status);
+ }
+
+ match wait_until_not_busy().await {
+ status if status == bitbox_securechip_sys::OPTIGA_LIB_SUCCESS as _ => Ok(()),
+ status => Err(status),
+ }
+}
+
pub(super) async fn util_read_data(oid: u16, offset: u16, out: &mut [u8]) -> Result<(), Error> {
// Static because the Optiga library keeps raw pointers to this buffer and length until the
// async callback completes, and the Rust future may be dropped before that happens.
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.