mock: Move wrap function to mocks from fakes
What changed, and why it matters
This commit only reorganizes test helper code. It moves a wrapper function from one test-only file to another and adds a small accessor function so the test fake can share its internal salt value. There is no change to the actual device firmware or to how real user data is handled, so it has no security relevance for end users.
No action required. Treat as routine test-code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors unit-test mocking infrastructure for the BitBox02 firmware. Previously, __wrap_memory_get_salt_root was defined in test/hardware-fakes/src/fake_memory.c. The commit removes it from there, exposes fake_memory_get_salt_root() to return the fake’s internal _salt_root buffer, and places the wrapping function __wrap_memory_get_salt_root in test/unit-test/framework/src/mock_memory.c instead. This is a test-code relocation with no functional change to production firmware, cryptographic handling, or memory semantics.
Changed components
test/hardware-fakes/include/fake_memory.htest/hardware-fakes/src/fake_memory.ctest/unit-test/framework/src/mock_memory.cInspect captured patch +11 / −3
diff --git a/test/hardware-fakes/include/fake_memory.h b/test/hardware-fakes/include/fake_memory.h
index 8cf45ad..e030214 100644
--- a/test/hardware-fakes/include/fake_memory.h
+++ b/test/hardware-fakes/include/fake_memory.h
@@ -28,6 +28,7 @@ void memory_read_chunk_fake(uint32_t chunk_num, uint8_t* chunk_out);
// Size: `FLASH_SHARED_DATA_LEN`.
void memory_read_shared_bootdata_fake(uint8_t* chunk_out);
void fake_memory_set_salt_root(const uint8_t* salt_root);
+const uint8_t* fake_memory_get_salt_root(void);
void memory_bootloader_hash_fake(uint8_t* hash_out);
void memory_set_bootloader_hash_fake(const uint8_t* fake_hash);
#endif
diff --git a/test/hardware-fakes/src/fake_memory.c b/test/hardware-fakes/src/fake_memory.c
index 50b350c..9b75c18 100644
--- a/test/hardware-fakes/src/fake_memory.c
+++ b/test/hardware-fakes/src/fake_memory.c
@@ -225,14 +225,14 @@ static uint8_t _salt_root[32] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
};
+
void fake_memory_set_salt_root(const uint8_t* salt_root)
{
memcpy(_salt_root, salt_root, 32);
}
-bool __wrap_memory_get_salt_root(uint8_t* salt_root_out)
+const uint8_t* fake_memory_get_salt_root(void)
{
- memcpy(salt_root_out, _salt_root, 32);
- return true;
+ return _salt_root;
}
// Arbitrary value.
diff --git a/test/unit-test/framework/src/mock_memory.c b/test/unit-test/framework/src/mock_memory.c
index f82a866..fc23ca2 100644
--- a/test/unit-test/framework/src/mock_memory.c
+++ b/test/unit-test/framework/src/mock_memory.c
@@ -18,6 +18,7 @@
#include <stddef.h>
#include <cmocka.h>
+#include <fake_memory.h>
#include <flags.h>
#include <memory/memory.h>
#include <stdio.h>
@@ -67,3 +68,9 @@ bool __wrap_memory_set_mnemonic_passphrase_enabled(bool enabled)
check_expected(enabled);
return mock();
}
+
+bool __wrap_memory_get_salt_root(uint8_t* salt_root_out)
+{
+ memcpy(salt_root_out, fake_memory_get_salt_root(), 32);
+ return true;
+}
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.