What changed, and why it matters
This commit is a tiny internal code cleanup in the BitBox02 firmware. It replaces one Rust standard-library call with a newer, equivalent one that avoids creating a temporary sub-slice. The behavior is unchanged: it still takes the first 16 bytes from 32 random bytes and uses them as an encryption IV. There is no security issue visible in the diff.
No security action required. This is a benign refactor. Routine code review/merge is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change replaces random_32_bytes()[..16].try_into().unwrap() with random_32_bytes().first_chunk::<16>().unwrap(). Both expressions produce a 16-byte IV from the first 16 bytes of a 32-byte random buffer. first_chunk returns a reference to a fixed-size array (&[u8; 16]), so the subsequent encrypt_with_hmac call now receives iv directly instead of &iv. The functional behavior, panic conditions, and data flow are identical; only an intermediate sub-slice allocation/creation is removed.
Changed components
src/rust/bitbox02-rust/src/keystore.rsInspect captured patch +6 / −5
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 230e9c2..8533b6e 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -86,8 +86,9 @@ impl RetainedEncryptedBuffer {
&format!("{}_in", purpose),
&format!("{}_out", purpose),
)?;
- let iv: [u8; 16] = random.random_32_bytes()[..16].try_into().unwrap();
- let encrypted = bitbox_aes::encrypt_with_hmac(&iv, &encryption_key, data);
+ let iv_rand = random.random_32_bytes();
+ let iv: &[u8; 16] = iv_rand.first_chunk::<16>().unwrap();
+ let encrypted = bitbox_aes::encrypt_with_hmac(iv, &encryption_key, data);
Ok(RetainedEncryptedBuffer {
unstretched_encryption_key: rand,
encrypted_seed: ReadOnlyBuffer::from_slice(&encrypted),
@@ -201,9 +202,9 @@ pub fn encrypt_and_store_seed(
securechip::init_new_password(password)?;
let secret = securechip::stretch_password(password)?;
-
- let iv: [u8; 16] = hal.random().random_32_bytes()[..16].try_into().unwrap();
- let encrypted = bitbox_aes::encrypt_with_hmac(&iv, &secret, seed);
+ let iv_rand = hal.random().random_32_bytes();
+ let iv: &[u8; 16] = iv_rand.first_chunk::<16>().unwrap();
+ let encrypted = bitbox_aes::encrypt_with_hmac(iv, &secret, seed);
if encrypted.len() > u8::MAX as usize {
panic!("encrypted seed length overflow");
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.