Merge remote-tracking branch 'agent/benma-agent/set-password-seed-test'
What changed, and why it matters
This commit only adds a new unit test to the BitBox02 firmware. It verifies that the set-password API correctly derives a wallet seed from host entropy, device randomness, a salt, and the user's password. No production code was changed, and no bug or security weakness is present in the diff.
No security action required. This is a test-only change. Routine code-review approval is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to src/rust/bitbox02-rust/src/hww/api/set_password.rs and adds a single test function, test_process_seed, plus an import of hex_lit::hex. The test mocks the hardware abstraction layer (UI, salt root, MCU random, secure-chip random) and checks that process() returns success and that keystore::copy_seed() matches a precomputed expected seed for both 16-byte and 32-byte host entropy lengths. The expected seed is documented with a Python script showing the XOR-and-SHA256 derivation. Existing tests remain untouched.
Changed components
src/rust/bitbox02-rust/src/hww/api/set_password.rsInspect captured patch +72 / −0
### src/rust/bitbox02-rust/src/hww/api/set_password.rs
@@ -44,6 +44,7 @@ mod tests {
use crate::hal::testing::TestingHal;
use alloc::boxed::Box;
+ use hex_lit::hex;
#[async_test::test]
async fn test_process() {
@@ -101,6 +102,77 @@ mod tests {
assert!(keystore::copy_seed(&mut mock_hal).await.unwrap().len() == 16);
}
+ #[async_test::test]
+ async fn test_process_seed() {
+ let host_entropy = hex!("25569b9a11f9db6560459e8e48b4727a4c935300143d978989ed55db1d1b9cbe");
+ let salt_root = hex!("3333333333333333444444444444444411111111111111112222222222222222");
+ let mcu_random = hex!("00112233445566778899aabbccddeefffedcba98765432100123456789abcdef");
+ let securechip_random =
+ hex!("102030405060708090a0b0c0d0e0f0000f1e2d3c4b5a69788796a5b4c3d2e1f0");
+ #[rustfmt::skip]
+ /* Reproduce expected_seed with Python:
+import hashlib
+
+mcu_random = bytes.fromhex(
+ "00112233445566778899aabbccddeefffedcba98765432100123456789abcdef"
+)
+securechip_random = bytes.fromhex(
+ "102030405060708090a0b0c0d0e0f0000f1e2d3c4b5a69788796a5b4c3d2e1f0"
+)
+factory_randomness = bytes.fromhex(
+ "f71df5932e61dbaab9b9eca90e59c4b45ec91fadf803db15578c260c608eb46b"
+)
+host_entropy = bytes.fromhex(
+ "25569b9a11f9db6560459e8e48b4727a4c935300143d978989ed55db1d1b9cbe"
+)
+salt_root = bytes.fromhex(
+ "3333333333333333444444444444444411111111111111112222222222222222"
+)
+purpose = b"keystore_seed_generation"
+password = b"test password"
+
+mixed_random = bytes(
+ mcu ^ securechip ^ factory
+ for mcu, securechip, factory in zip(mcu_random, securechip_random, factory_randomness)
+)
+device_random = hashlib.sha256(mixed_random).digest()
+password_salted_hashed = hashlib.sha256(salt_root + purpose + password).digest()
+expected_seed = bytes(
+ device ^ host ^ password_byte
+ for device, host, password_byte in zip(device_random, host_entropy, password_salted_hashed)
+)
+print(expected_seed.hex())
+ */
+ let expected_seed =
+ hex!("69c1a051c7cc3119603c2fb80e87a54b56d08b3536aea577c8f5819249fc6032");
+
+ for seed_len in [16, 32] {
+ keystore::lock();
+ let mut mock_hal = TestingHal::new();
+ mock_hal
+ .ui
+ .set_enter_string(Box::new(|_params| Ok("test password".into())));
+ mock_hal.memory.set_salt_root(&salt_root);
+ mock_hal.random.mock_next(mcu_random);
+ mock_hal.securechip.mock_random(securechip_random);
+
+ assert_eq!(
+ process(
+ &mut mock_hal,
+ &pb::SetPasswordRequest {
+ entropy: host_entropy[..seed_len].to_vec(),
+ }
+ )
+ .await,
+ Ok(Response::Success(pb::Success {}))
+ );
+ assert_eq!(
+ keystore::copy_seed(&mut mock_hal).await.unwrap().as_slice(),
+ &expected_seed[..seed_len]
+ );
+ }
+ }
+
/// Invalid host entropy size.
#[async_test::test]
async fn test_process_invalid_host_entropy() {Why this scored 14/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.