rust/memory: unit test encrypted_seed_and_hmac
What changed, and why it matters
This commit adds a new unit test for the BitBox02 firmware's Rust memory module. It verifies that storing and retrieving an encrypted seed with its authentication code works correctly, rejects inputs that are too large, and does not overwrite existing data when a too-large input is attempted. There is no change to production code or security behavior.
No security action needed. This is a routine test-only addition. Reviewers may optionally verify the test accurately reflects the intended size limit and error semantics of the underlying functions.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds test_encrypted_seed_and_hmac_roundtrip in src/rust/bitbox02/src/memory.rs. The test exercises set_encrypted_seed_and_hmac and get_encrypted_seed_and_hmac using a mocked memory backend. It checks a 96-byte roundtrip, asserts is_seeded() transitions from false to true, and confirms that a 97-byte input returns an error without corrupting the previously stored value. No implementation code is modified.
Changed components
src/rust/bitbox02/src/memory.rsInspect captured patch +17 / −0
diff --git a/src/rust/bitbox02/src/memory.rs b/src/rust/bitbox02/src/memory.rs
index 21074b7..a19d50a 100644
--- a/src/rust/bitbox02/src/memory.rs
+++ b/src/rust/bitbox02/src/memory.rs
@@ -517,6 +517,23 @@ mod tests {
assert_eq!(err, MemoryError::MEMORY_ERR_FULL);
}
+ #[test]
+ fn test_encrypted_seed_and_hmac_roundtrip() {
+ mock_memory();
+
+ assert!(!is_seeded());
+ let seed_data: Vec<u8> = (0..96).map(|i| i as u8).collect();
+ set_encrypted_seed_and_hmac(&seed_data).unwrap();
+ assert!(is_seeded());
+
+ let stored = get_encrypted_seed_and_hmac().unwrap();
+ assert_eq!(stored, seed_data);
+
+ let oversized = vec![0u8; 97];
+ assert!(set_encrypted_seed_and_hmac(&oversized).is_err());
+ assert_eq!(get_encrypted_seed_and_hmac().unwrap(), stored);
+ }
+
#[test]
fn test_memory_attestation() {
mock_memory();
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.