What changed, and why it matters
This commit is a pure refactoring: it renames the test-only 'hardware-mocks' directory and all related function names to 'hardware-fakes' across build files, source code, and unit tests. No production firmware behavior changes, no security fixes, and no vulnerability is introduced or patched.
No security action needed; treat as routine maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a global identifier rename from ‘mock’ to ‘fake’ in the test infrastructure. It adds test/hardware-fakes/ with files functionally identical to the removed test/hardware-mocks/, updates CMake targets, include paths, linker wrap symbols, and Rust FFI names accordingly. The production code paths remain gated by #ifdef TESTING and are not affected. No functional logic was modified.
Changed components
test/hardware-mocks (renamed to test/hardware-fakes)test/unit-testtest/simulatorsrc/CMakeLists.txtsrc/rust/bitbox02-sys/build.rssrc/rust/bitbox02-sys/wrapper.hInspect captured patch +937 / −976
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 297c34e..b86bd89 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -389,7 +389,7 @@ if(CMAKE_CROSSCOMPILING)
add_dependencies(doc rust-docs)
else()
include(CTest)
- add_subdirectory(test/hardware-mocks)
+ add_subdirectory(test/hardware-fakes)
add_subdirectory(test/unit-test)
add_subdirectory(test/simulator)
if(COVERAGE)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 523babc..539130a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -277,7 +277,7 @@ add_custom_target(rust-cbindgen
# Test rust crates that contain business logic. Avoid testing crates that depend on hardware.
if(NOT CMAKE_CROSSCOMPILING)
- set(RUSTFLAGS_TESTS ${RUSTFLAGS} -L${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} -lbitbox_merged -lwallycore -lsecp256k1 -lfatfs -lhardware-mocks)
+ set(RUSTFLAGS_TESTS ${RUSTFLAGS} -L${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} -lbitbox_merged -lwallycore -lsecp256k1 -lfatfs -lhardware-fakes)
# Since we build with all features we need to use a separate build directory.
# Otherwise we invalidate the result from the normal compilation that uses a
diff --git a/src/cipher/cipher.c b/src/cipher/cipher.c
index 8e80f98..e2b6b73 100644
--- a/src/cipher/cipher.c
+++ b/src/cipher/cipher.c
@@ -18,7 +18,7 @@
#include <rust/rust.h>
#ifdef TESTING
-#include <mock_cipher.h>
+#include <fake_cipher.h>
#endif
bool cipher_aes_hmac_encrypt(
@@ -30,7 +30,7 @@ bool cipher_aes_hmac_encrypt(
{
uint8_t iv[32] = {0}; // only 16 bytes needed for IV.
#ifdef TESTING
- cipher_mock_iv(iv);
+ cipher_fake_iv(iv);
#else
random_32_bytes(iv);
#endif
diff --git a/src/memory/memory.c b/src/memory/memory.c
index d929d81..f5b5835 100644
--- a/src/memory/memory.c
+++ b/src/memory/memory.c
@@ -29,7 +29,7 @@
#ifndef TESTING
#include <hal_delay.h>
#else
-#include <mock_memory.h>
+#include <fake_memory.h>
#endif
#include <assert.h>
@@ -164,7 +164,7 @@ static void _clean_chunk(uint8_t** chunk_bytes)
static bool _write_to_address(uint32_t base, uint32_t offset, uint8_t* chunk)
{
#ifdef TESTING
- return memory_write_to_address_mock(base, offset, chunk);
+ return memory_write_to_address_fake(base, offset, chunk);
#else
uint32_t addr = base + offset;
if (addr < base) {
@@ -216,7 +216,7 @@ static bool _write_to_address(uint32_t base, uint32_t offset, uint8_t* chunk)
static bool _write_chunk(uint32_t chunk_num, uint8_t* chunk)
{
#ifdef TESTING
- return memory_write_chunk_mock(chunk_num, chunk);
+ return memory_write_chunk_fake(chunk_num, chunk);
#else
uint32_t offset = chunk_num * CHUNK_SIZE;
return _write_to_address(FLASH_APPDATA_START, offset, chunk);
@@ -228,7 +228,7 @@ static void _read_chunk(uint32_t chunk_num, uint8_t* chunk_out)
{
#ifdef TESTING
// empty, can be mocked in cmocka.
- memory_read_chunk_mock(chunk_num, chunk_out);
+ memory_read_chunk_fake(chunk_num, chunk_out);
#else
memcpy(chunk_out, (uint8_t*)(FLASH_APPDATA_START + chunk_num * CHUNK_SIZE), CHUNK_SIZE);
#endif
@@ -701,7 +701,7 @@ bool memory_get_attestation_pubkey_and_certificate(
void memory_bootloader_hash(uint8_t* hash_out)
{
#ifdef TESTING
- memory_bootloader_hash_mock(hash_out);
+ memory_bootloader_hash_fake(hash_out);
#else
uint8_t* bootloader = FLASH_BOOT_START;
size_t len = FLASH_BOOT_LEN - 32; // 32 bytes are random
diff --git a/src/memory/memory_shared.c b/src/memory/memory_shared.c
index c0ba2d2..dcf5745 100644
--- a/src/memory/memory_shared.c
+++ b/src/memory/memory_shared.c
@@ -28,7 +28,7 @@
#include "random.h"
#ifdef TESTING
-#include <mock_memory.h>
+#include <fake_memory.h>
#endif
static void _clean_chunk(uint8_t** chunk_bytes)
@@ -47,7 +47,7 @@ static void _clean_chunk(uint8_t** chunk_bytes)
static bool _write_to_address(uint32_t base, uint32_t offset, uint8_t* chunk)
{
#ifdef TESTING
- return memory_write_to_address_mock(base, offset, chunk);
+ return memory_write_to_address_fake(base, offset, chunk);
#else
uint32_t addr = base + offset;
if (addr < base) {
@@ -99,7 +99,7 @@ static bool _write_to_address(uint32_t base, uint32_t offset, uint8_t* chunk)
void memory_read_shared_bootdata(chunk_shared_t* chunk_out)
{
#ifdef TESTING
- memory_read_shared_bootdata_mock(chunk_out->bytes);
+ memory_read_shared_bootdata_fake(chunk_out->bytes);
#else
memcpy(chunk_out->bytes, (uint8_t*)(FLASH_SHARED_DATA_START), FLASH_SHARED_DATA_LEN);
#endif
diff --git a/src/random.c b/src/random.c
index ce06565..a5e143b 100644
--- a/src/random.c
+++ b/src/random.c
@@ -104,7 +104,7 @@ void random_32_bytes(uint8_t* buf)
}
#ifdef TESTING
-void random_mock_reset(void)
+void random_fake_reset(void)
{
srand(0);
}
diff --git a/src/random.h b/src/random.h
index 420b53c..3a3bf55 100644
--- a/src/random.h
+++ b/src/random.h
@@ -33,7 +33,7 @@ uint8_t random_byte_mcu(void);
#ifdef TESTING
// In testing, `rand()` is used for mocking. This function resets the seed using `srand(0)`, which
// allows individual unit tests to be independent of others.
-void random_mock_reset(void);
+void random_fake_reset(void);
#endif
#endif
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
index 1344532..a7cf908 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
@@ -2122,7 +2122,7 @@ mod tests {
}));
mock_unlocked();
- bitbox02::random::mock_reset();
+ bitbox02::random::fake_reset();
let mut init_request = transaction.borrow().init_request();
init_request.script_configs[0] = pb::BtcScriptConfigWithKeypath {
script_config: Some(pb::BtcScriptConfig {
@@ -2194,7 +2194,7 @@ mod tests {
mock_host_responder(transaction.clone());
mock_unlocked();
- bitbox02::random::mock_reset();
+ bitbox02::random::fake_reset();
let result = block_on(process(
&mut TestingHal::new(),
&transaction.borrow().init_request(),
@@ -3148,7 +3148,7 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- bitbox02::random::mock_reset();
+ bitbox02::random::fake_reset();
// For the policy registration below.
mock_memory();
@@ -3268,7 +3268,7 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- bitbox02::random::mock_reset();
+ bitbox02::random::fake_reset();
// For the policy registration below.
mock_memory();
@@ -3323,7 +3323,7 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- bitbox02::random::mock_reset();
+ bitbox02::random::fake_reset();
// For the policy registration below.
mock_memory();
@@ -3614,7 +3614,7 @@ mod tests {
mock_host_responder(transaction.clone());
mock_unlocked();
- bitbox02::random::mock_reset();
+ bitbox02::random::fake_reset();
let init_request = transaction.borrow().init_request();
let mut mock_hal = TestingHal::new();
diff --git a/src/rust/bitbox02-sys/build.rs b/src/rust/bitbox02-sys/build.rs
index 9032645..d416bec 100644
--- a/src/rust/bitbox02-sys/build.rs
+++ b/src/rust/bitbox02-sys/build.rs
@@ -118,14 +118,14 @@ const ALLOWLIST_FNS: &[&str] = &[
"memory_spi_get_active_ble_firmware_version",
"spi_mem_protected_area_write",
"menu_create",
- "mock_memory_factoryreset",
+ "fake_memory_factoryreset",
"spi_mem_full_erase",
"printf",
"progress_create",
"progress_set",
"random_32_bytes_mcu",
"random_32_bytes",
- "random_mock_reset",
+ "random_fake_reset",
"reboot_to_bootloader",
"reset_reset",
"reset_ble",
@@ -252,7 +252,7 @@ pub fn main() -> Result<(), &'static str> {
]);
} else {
// unit test framework includes
- includes.push("../../../test/hardware-mocks/include")
+ includes.push("../../../test/hardware-fakes/include")
}
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
diff --git a/src/rust/bitbox02-sys/wrapper.h b/src/rust/bitbox02-sys/wrapper.h
index ff7df24..4c41da3 100644
--- a/src/rust/bitbox02-sys/wrapper.h
+++ b/src/rust/bitbox02-sys/wrapper.h
@@ -55,7 +55,7 @@
#include <wally_crypto.h>
#if defined(TESTING)
-#include <mock_memory.h>
+#include <fake_memory.h>
#endif
#if !defined(TESTING)
diff --git a/src/rust/bitbox02/src/keystore.rs b/src/rust/bitbox02/src/keystore.rs
index cb1c289..89f54be 100644
--- a/src/rust/bitbox02/src/keystore.rs
+++ b/src/rust/bitbox02/src/keystore.rs
@@ -315,7 +315,7 @@ mod tests {
};
// Test without tweak
- crate::random::mock_reset();
+ crate::random::fake_reset();
let sig = secp256k1_schnorr_sign(&keypath, &msg, None).unwrap();
let secp = secp256k1::Secp256k1::new();
assert!(secp
@@ -327,7 +327,7 @@ mod tests {
.is_ok());
// Test with tweak
- crate::random::mock_reset();
+ crate::random::fake_reset();
let tweak = {
let tweak =
hex::decode("a39fb163dbd9b5e0840af3cc1ee41d5b31245c5dd8d6bdc3d026d09b8964997c")
@@ -623,7 +623,7 @@ mod tests {
// Hack to get the random bytes that will be used.
let seed_random = {
- crate::random::mock_reset();
+ crate::random::fake_reset();
crate::random::random_32_bytes()
};
@@ -642,7 +642,7 @@ mod tests {
for size in [16, 32] {
mock_memory();
- crate::random::mock_reset();
+ crate::random::fake_reset();
crate::memory::set_salt_root(mock_salt_root.as_slice().try_into().unwrap()).unwrap();
lock();
diff --git a/src/rust/bitbox02/src/random.rs b/src/rust/bitbox02/src/random.rs
index 2284d97..5c87b73 100644
--- a/src/rust/bitbox02/src/random.rs
+++ b/src/rust/bitbox02/src/random.rs
@@ -37,9 +37,9 @@ pub fn random_32_bytes() -> alloc::boxed::Box<zeroize::Zeroizing<[u8; 32]>> {
}
#[cfg(feature = "testing")]
-pub fn mock_reset() {
+pub fn fake_reset() {
unsafe {
- bitbox02_sys::random_mock_reset();
+ bitbox02_sys::random_fake_reset();
}
}
diff --git a/src/rust/bitbox02/src/testing.rs b/src/rust/bitbox02/src/testing.rs
index 0a5c372..7a7bc66 100644
--- a/src/rust/bitbox02/src/testing.rs
+++ b/src/rust/bitbox02/src/testing.rs
@@ -47,7 +47,7 @@ static MEMORY_IFS: bitbox02_sys::memory_interface_functions_t =
/// The memory is initialized to be like after factory setup, i.e. 0xFF everywhere followed by `memory_setup()`.
pub fn mock_memory() {
unsafe {
- bitbox02_sys::mock_memory_factoryreset();
+ bitbox02_sys::fake_memory_factoryreset();
assert!(bitbox02_sys::memory_setup(&MEMORY_IFS));
diff --git a/src/touch/gestures.c b/src/touch/gestures.c
index e2eb502..f23ca1e 100644
--- a/src/touch/gestures.c
+++ b/src/touch/gestures.c
@@ -22,7 +22,7 @@
#include "qtouch.h"
#include <driver_init.h>
#else
-#include "mock_qtouch.h"
+#include "fake_qtouch.h"
#endif
#include "gestures.h"
diff --git a/src/ui/components/orientation_arrows.c b/src/ui/components/orientation_arrows.c
index 76711f7..5689f32 100644
--- a/src/ui/components/orientation_arrows.c
+++ b/src/ui/components/orientation_arrows.c
@@ -26,7 +26,7 @@
#if !defined(TESTING)
#include <qtouch.h>
#else
-#include <mock_qtouch.h>
+#include <fake_qtouch.h>
#endif
#define SCALE 2 // Divide `count` by scale to slow down motion
diff --git a/test/hardware-fakes/CMakeLists.txt b/test/hardware-fakes/CMakeLists.txt
new file mode 100644
index 0000000..de44e2f
--- /dev/null
+++ b/test/hardware-fakes/CMakeLists.txt
@@ -0,0 +1,68 @@
+# Copyright 2024 Shift Cryptosecurity AG
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-bad-function-cast")
+
+set(HARDWARE-FAKES-SOURCES
+ src/fake_cipher.c
+ src/fake_diskio.c
+ src/fake_memory.c
+ src/fake_screen.c
+ src/fake_securechip.c
+ src/fake_smarteeprom.c
+ src/fake_spi_mem.c
+ src/fake_component.c
+ src/fake_delay.c
+ src/fake_qtouch.c
+)
+
+add_library(hardware-fakes
+ STATIC
+ ${HARDWARE-FAKES-SOURCES}
+)
+
+add_dependencies(hardware-fakes rust-cbindgen)
+
+target_compile_definitions(hardware-fakes PUBLIC
+ TESTING
+ _UNIT_TEST_
+ PRODUCT_BITBOX_MULTI=1
+ APP_BTC=1
+ APP_LTC=1
+ APP_U2F=1
+ APP_ETH=1
+)
+
+target_include_directories(
+ hardware-fakes
+ PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+)
+target_include_directories(
+ hardware-fakes
+ PRIVATE
+ ${INCLUDES}
+ ${CMAKE_BINARY_DIR}/src
+ $<TARGET_PROPERTY:fatfs,INTERFACE_INCLUDE_DIRECTORIES>
+ $<TARGET_PROPERTY:wallycore,INTERFACE_INCLUDE_DIRECTORIES>
+)
+
+target_link_libraries(hardware-fakes PUBLIC wallycore)
+
+if(SANITIZE_ADDRESS)
+ target_compile_options(hardware-fakes PUBLIC "-fsanitize=address")
+endif()
+if(SANTIZE_UNDEFINED)
+ target_compile_options(hardware-fakes PUBLIC "-fsanitize=undefined")
+endif()
diff --git a/test/hardware-fakes/README.md b/test/hardware-fakes/README.md
new file mode 100644
index 0000000..aa0a51a
--- /dev/null
+++ b/test/hardware-fakes/README.md
@@ -0,0 +1,4 @@
+# Hardware fakes
+
+All files in this directory fake hardware functionailty. Used in unit tests and
+simulators
diff --git a/test/hardware-fakes/include/fake_cipher.h b/test/hardware-fakes/include/fake_cipher.h
new file mode 100644
index 0000000..d9b49e0
--- /dev/null
+++ b/test/hardware-fakes/include/fake_cipher.h
@@ -0,0 +1,22 @@
+// Copyright 2023 Shift Crypto AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef _FAKE_CIPHER_H_
+#define _FAKE_CIPHER_H_
+
+#include <stdint.h>
+
+void cipher_fake_iv(uint8_t* iv_out);
+
+#endif
diff --git a/test/hardware-fakes/include/fake_component.h b/test/hardware-fakes/include/fake_component.h
new file mode 100644
index 0000000..656a7cf
--- /dev/null
+++ b/test/hardware-fakes/include/fake_component.h
@@ -0,0 +1,30 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef _FAKE_COMPONENT_H_
+#define _FAKE_COMPONENT_H_
+
+#include <ui/component.h>
+
+/********************************** Create Instance **********************************/
+
+/**
+ * Creates a label with the given font either upside down or normal.
+ * @param[in] text The text of the label.
+ * @param[in] upside_down Whether the text should be rotated 180 degree or not.
+ * @param[in] font The font of the label.
+ */
+component_t* fake_component_create(void);
+
+#endif
diff --git a/test/hardware-fakes/include/fake_memory.h b/test/hardware-fakes/include/fake_memory.h
new file mode 100644
index 0000000..5985240
--- /dev/null
+++ b/test/hardware-fakes/include/fake_memory.h
@@ -0,0 +1,32 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef _FAKE_MEMORY_H_
+#define _FAKE_MEMORY_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <flags.h>
+
+void fake_memory_factoryreset(void);
+bool memory_write_to_address_fake(uint32_t base, uint32_t addr, const uint8_t* chunk);
+bool memory_write_chunk_fake(uint32_t chunk_num, const uint8_t* chunk);
+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);
+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/include/fake_qtouch.h b/test/hardware-fakes/include/fake_qtouch.h
new file mode 100644
index 0000000..e012a2e
--- /dev/null
+++ b/test/hardware-fakes/include/fake_qtouch.h
@@ -0,0 +1,28 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef _QTOUCH_H_
+#define _QTOUCH_H_
+
+#include <stdint.h>
+
+void qtouch_process(void);
+
+uint8_t qtouch_is_scroller_active(uint16_t sensor_node);
+
+uint16_t qtouch_get_scroller_position(uint16_t sensor_node);
+
+void qtouch_force_calibrate(void);
+
+#endif
diff --git a/test/hardware-fakes/src/fake_cipher.c b/test/hardware-fakes/src/fake_cipher.c
new file mode 100644
index 0000000..ddb3fcd
--- /dev/null
+++ b/test/hardware-fakes/src/fake_cipher.c
@@ -0,0 +1,22 @@
+// Copyright 2023 Shift Crypto AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <string.h>
+
+#include <fake_cipher.h>
+
+void cipher_fake_iv(uint8_t* iv_out)
+{
+ memset(iv_out, 'a', 32);
+}
diff --git a/test/hardware-fakes/src/fake_component.c b/test/hardware-fakes/src/fake_component.c
new file mode 100644
index 0000000..faf4909
--- /dev/null
+++ b/test/hardware-fakes/src/fake_component.c
@@ -0,0 +1,53 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <string.h>
+
+#include <screen.h>
+#include <stdlib.h>
+#include <ui/ui_util.h>
+
+#include "fake_component.h"
+
+/********************************** Label Functions **********************************/
+
+/**
+ * Collects all component functions.
+ */
+static const component_functions_t FAKE_COMPONENT_FUNCTIONS = {
+ .cleanup = ui_util_component_cleanup,
+ .render = ui_util_component_render_subcomponents,
+ .on_event = ui_util_on_event_noop};
+
+/********************************** Create Instance **********************************/
+
+/**
+ * Creates a label with the given font either upside down or normal.
+ * @param[in] text The text of the label.
+ * @param[in] upside_down Whether the text should be rotated 180 degree or not.
+ * @param[in] font The font of the label.
+ */
+component_t* fake_component_create(void)
+{
+ component_t* fake = malloc(sizeof(component_t));
+ memset(fake, 0, sizeof(component_t));
+ fake->f = &FAKE_COMPONENT_FUNCTIONS;
+
+ fake->dimension.width = SCREEN_WIDTH;
+ fake->dimension.height = SCREEN_HEIGHT;
+ fake->position.left = 0;
+ fake->position.top = 0;
+
+ return fake;
+}
diff --git a/test/hardware-fakes/src/fake_delay.c b/test/hardware-fakes/src/fake_delay.c
new file mode 100644
index 0000000..e539f5b
--- /dev/null
+++ b/test/hardware-fakes/src/fake_delay.c
@@ -0,0 +1,26 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stdint.h>
+#include <unistd.h>
+
+void delay_ms(const uint16_t ms)
+{
+ usleep(1000 * ms);
+}
+
+void delay_us(const uint16_t us)
+{
+ usleep(us);
+}
diff --git a/test/hardware-fakes/src/fake_diskio.c b/test/hardware-fakes/src/fake_diskio.c
new file mode 100644
index 0000000..bb2fc7f
--- /dev/null
+++ b/test/hardware-fakes/src/fake_diskio.c
@@ -0,0 +1,82 @@
+// Copyright 2021 Shift Crypto AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stdint.h>
+#include <string.h>
+
+// Must be included before diskio.h, see http://elm-chan.org/fsw/ff/bd/?show=3626
+#include <ff.h>
+
+#include <diskio.h>
+
+// This file is the disk middleware for use in tests, replacing sdmmc_diskio.c used in the firmware
+// to write to microSD cards.
+//
+// It writes and reads from RAM instead of to a card or disk so that unit tests can exercise all
+// sd-card related functionality.
+
+// 100mb with 512 bytes per sector
+#define SECTOR_SIZE 512
+#define SECTOR_COUNT 204800
+static uint8_t _data[SECTOR_SIZE * SECTOR_COUNT] = {0};
+
+DSTATUS disk_initialize(uint8_t drv)
+{
+ (void)drv;
+ return 0;
+}
+
+DSTATUS disk_status(uint8_t drv)
+{
+ (void)drv;
+ return 0;
+}
+
+DRESULT disk_read(BYTE pdrv, BYTE* buff, LBA_t sector, UINT count)
+{
+ (void)pdrv;
+ for (UINT i = 0; i < count; i++) {
+ memcpy(&buff[SECTOR_SIZE * i], &_data[SECTOR_SIZE * sector + SECTOR_SIZE * i], SECTOR_SIZE);
+ }
+ return RES_OK;
+}
+
+DRESULT disk_write(BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count)
+{
+ for (UINT i = 0; i < count; i++) {
+ memcpy(&_data[SECTOR_SIZE * sector + SECTOR_SIZE * i], &buff[SECTOR_SIZE * i], SECTOR_SIZE);
+ }
+ return RES_OK;
+}
+
+DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff)
+{
+ (void)pdrv;
+ switch (cmd) {
+ case CTRL_SYNC:
+ // Already synced (RAM).
+ return RES_OK;
+ case GET_BLOCK_SIZE:
+ *(DWORD*)buff = 1;
+ return RES_OK;
+ case GET_SECTOR_SIZE:
+ *(LBA_t*)buff = SECTOR_SIZE;
+ return RES_OK;
+ case GET_SECTOR_COUNT:
+ *(LBA_t*)buff = SECTOR_COUNT;
+ return RES_OK;
+ default:
+ return RES_PARERR;
+ }
+}
diff --git a/test/hardware-fakes/src/fake_memory.c b/test/hardware-fakes/src/fake_memory.c
new file mode 100644
index 0000000..90e0ee9
--- /dev/null
+++ b/test/hardware-fakes/src/fake_memory.c
@@ -0,0 +1,99 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <flags.h>
+#include <memory/memory.h>
+#include <fake_memory.h>
+#include <stdio.h>
+#include <string.h>
+
+static uint8_t _memory_shared_data[FLASH_SHARED_DATA_LEN] = {0};
+static uint8_t _memory_app_data[FLASH_APPDATA_LEN] = {0};
+static uint8_t _memory_smarteeprom[SMARTEEPROM_RESERVED_FLASH_PAGES * FLASH_PAGE_SIZE] = {0};
+
+void fake_memory_factoryreset(void)
+{
+ memset(_memory_shared_data, 0xff, sizeof(_memory_shared_data));
+ memset(_memory_app_data, 0xff, sizeof(_memory_app_data));
+ memset(_memory_smarteeprom, 0xff, sizeof(_memory_smarteeprom));
+}
+
+static uint8_t* _get_memory(uint32_t base)
+{
+ switch (base) {
+ case FLASH_SHARED_DATA_START:
+ return _memory_shared_data;
+ case FLASH_APPDATA_START:
+ return _memory_app_data;
+ case FLASH_SMARTEEPROM_START:
+ return _memory_smarteeprom;
+ default:
+ return NULL;
+ }
+}
+
+bool memory_write_to_address_fake(uint32_t base, uint32_t addr, const uint8_t* chunk)
+{
+ if (chunk == NULL) {
+ memset(_get_memory(base) + addr, 0xff, (size_t)CHUNK_SIZE);
+ } else {
+ memcpy(_get_memory(base) + addr, chunk, (size_t)CHUNK_SIZE);
+ }
+ return true;
+}
+
+bool memory_write_chunk_fake(uint32_t chunk_num, const uint8_t* chunk)
+{
+ return memory_write_to_address_fake(FLASH_APPDATA_START, chunk_num * (size_t)CHUNK_SIZE, chunk);
+}
+
+void memory_read_chunk_fake(uint32_t chunk_num, uint8_t* chunk_out)
+{
+ memcpy(chunk_out, _memory_app_data + chunk_num * (size_t)CHUNK_SIZE, (size_t)CHUNK_SIZE);
+}
+
+void memory_read_shared_bootdata_fake(uint8_t* chunk_out)
+{
+ memcpy(chunk_out, _memory_shared_data, (size_t)FLASH_SHARED_DATA_LEN);
+}
+
+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)
+{
+ memcpy(salt_root_out, _salt_root, 32);
+ return true;
+}
+
+// Arbitrary value.
+static uint8_t _bootloader_hash[32] =
+ "\x71\x3d\xf0\xd5\x8c\x71\x7d\x40\x31\x78\x7c\xdc\x8f\xa3\x5b\x90\x25\x82\xbe\x6a\xb6\xa2\x2e"
+ "\x09\xde\x44\x77\xd3\x0e\x22\x30\xfc";
+
+void memory_bootloader_hash_fake(uint8_t* hash_out)
+{
+ memcpy(hash_out, _bootloader_hash, 32);
+}
+
+void memory_set_bootloader_hash_fake(const uint8_t* fake_hash)
+{
+ // NOLINTNEXTLINE(bugprone-not-null-terminated-result)
+ memcpy(_bootloader_hash, fake_hash, sizeof(_bootloader_hash));
+}
diff --git a/test/hardware-fakes/src/fake_qtouch.c b/test/hardware-fakes/src/fake_qtouch.c
new file mode 100644
index 0000000..d952306
--- /dev/null
+++ b/test/hardware-fakes/src/fake_qtouch.c
@@ -0,0 +1,24 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// The real qtouch.h depends on hardware specific headers and cannot be used
+#include <fake_qtouch.h>
+
+#include <stdbool.h>
+
+volatile bool measurement_done_touch = true;
+
+void qtouch_process(void) {}
+
+void qtouch_force_calibrate(void) {}
diff --git a/test/hardware-fakes/src/fake_screen.c b/test/hardware-fakes/src/fake_screen.c
new file mode 100644
index 0000000..45d81ca
--- /dev/null
+++ b/test/hardware-fakes/src/fake_screen.c
@@ -0,0 +1,46 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <screen.h>
+
+UG_COLOR screen_front_color = C_WHITE;
+UG_COLOR screen_back_color = C_BLACK;
+
+slider_location_t top_slider = 1;
+slider_location_t bottom_slider = 0;
+
+void screen_print_debug(const char* message, int duration)
+{
+ printf("%s\n", message);
+}
+
+void screen_splash(void)
+{
+ puts("screen splash\n");
+}
+
+void screen_rotate(void) {}
+
+bool screen_is_upside_down(void)
+{
+ return false;
+}
+
+void screen_clear(void) {}
diff --git a/test/hardware-fakes/src/fake_securechip.c b/test/hardware-fakes/src/fake_securechip.c
new file mode 100644
index 0000000..90ec17c
--- /dev/null
+++ b/test/hardware-fakes/src/fake_securechip.c
@@ -0,0 +1,81 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <rust/rust.h>
+#include <salt.h>
+#include <securechip/securechip.h>
+#include <stdio.h>
+#include <string.h>
+
+static uint32_t _u2f_counter;
+
+// Mocked contents of the secure chip rollkey slot.
+static const uint8_t _rollkey[32] =
+ "\x9d\xd1\x34\x1f\x6b\x4b\x26\xb1\x72\x89\xa1\xa3\x92\x71\x5c\xf0\xd0\x57\x8c\x84\xdb\x9a\x51"
+ "\xeb\xde\x14\x24\x06\x69\xd1\xd0\x5e";
+
+// Mocked contents of the securechip kdf slot.
+static const uint8_t _kdfkey[32] =
+ "\xd2\xe1\xe6\xb1\x8b\x6c\x6b\x08\x43\x3e\xdb\xc1\xd1\x68\xc1\xa0\x04\x37\x74\xa4\x22\x18\x77"
+ "\xe7\x9e\xd5\x66\x84\xbe\x5a\xc0\x1b";
+
+int securechip_kdf(const uint8_t* msg, size_t len, uint8_t* kdf_out)
+{
+ rust_hmac_sha256(_kdfkey, 32, msg, len, kdf_out);
+ return 0;
+}
+int securechip_kdf_rollkey(const uint8_t* msg, size_t len, uint8_t* kdf_out)
+{
+ rust_hmac_sha256(_rollkey, 32, msg, len, kdf_out);
+ return 0;
+}
+int securechip_init_new_password(const char* password)
+{
+ (void)password;
+ return 0;
+}
+int securechip_stretch_password(const char* password, uint8_t* stretched_out)
+{
+ uint8_t key[9] = "unit-test";
+ rust_hmac_sha256(key, sizeof(key), (const uint8_t*)password, strlen(password), stretched_out);
+ return 0;
+}
+bool securechip_u2f_counter_set(uint32_t counter)
+{
+ _u2f_counter = counter;
+ return true;
+}
+
+bool securechip_u2f_counter_inc(uint32_t* counter)
+{
+ *counter = _u2f_counter++;
+ return true;
+}
+
+bool securechip_attestation_sign(const uint8_t* msg, uint8_t* signature_out)
+{
+ return false;
+}
+
+bool securechip_monotonic_increments_remaining(uint32_t* remaining_out)
+{
+ *remaining_out = 1;
+ return true;
+}
+
+bool securechip_model(securechip_model_t* model_out)
+{
+ *model_out = ATECC_ATECC608B;
+ return true;
+}
diff --git a/test/hardware-fakes/src/fake_smarteeprom.c b/test/hardware-fakes/src/fake_smarteeprom.c
new file mode 100644
index 0000000..b5cf2ce
--- /dev/null
+++ b/test/hardware-fakes/src/fake_smarteeprom.c
@@ -0,0 +1,101 @@
+// Copyright 2019 Shift Cryptosecurity AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * Mock for the SmartEEPROM functions.
+ */
+#include <memory/smarteeprom.h>
+
+#include <assert.h>
+#include <string.h>
+
+static char* _mem_image = NULL;
+static size_t _allocated_space = 0;
+static size_t _enabled = 0;
+
+void smarteeprom_setup(void)
+{
+ /* Allocate an equivalent amount of raw memory */
+ size_t n_virtual_pages = SMARTEEPROM_ALLOCATED_BLOCKS * 8192 / SMARTEEPROM_PAGE_SIZE;
+ /*
+ * The maximum number of virtual pages is limited to 128.
+ * Ref. SAMD5x/E5x Family Data Sheet sec. 25.6.8.3
+ */
+ if (n_virtual_pages > 128) {
+ n_virtual_pages = 128;
+ }
+ _allocated_space = n_virtual_pages * SMARTEEPROM_PAGE_SIZE;
+ _mem_image = malloc(_allocated_space);
+ if (!_mem_image) {
+ abort();
+ }
+ memset(_mem_image, 0xFF, _allocated_space);
+ _enabled = 1;
+}
+
+/**
+ * Reads N contiguous bytes from the SmartEEPROM, starting at
+ * the specified address.
+ *
+ * @param[in] address Start address.
+ * @param[in] size Number of bytes to read.
+ * @param[out] out_buffer Buffer in which to read.
+ * Must be at least size bytes wide.
+ */
+void smarteeprom_read(size_t address, size_t bytes, uint8_t* out_buffer)
+{
+ assert(address + bytes < _allocated_space);
+ assert(_enabled);
+ memcpy(out_buffer, _mem_image + address, bytes);
+}
+
+/**
+ * Writes N contiguous bytes to the SmartEEPROM, starting at
+ * the specified address.
+ *
+ * Note that this will not affect the write endurance of the
+ * underlying memory, unless the content currently stored at
+ * the specified address has some bits that must be flipped from
+ * "0" to "1". Use this wisely!
+ *
+ * @param[in] address Start address.
+ * @param[in] size Number of bytes to write.
+ * @param[in] buffer Buffer from which to read the data.
+ * Must be at least size bytes wide.
+ */
+void smarteeprom_write(size_t address, size_t bytes, const uint8_t* buffer)
+{
+ assert(_allocated_space > bytes && address < _allocated_space - bytes);
+ assert(_enabled);
+ memcpy(_mem_image + address, buffer, bytes);
+}
+
+bool smarteeprom_is_enabled(void)
+{
+ return _enabled;
+}
+
+void smarteeprom_disable(void)
+{
+ _enabled = 0;
+ _allocated_space = 0;
+ free(_mem_image);
+}
+
+void smarteeprom_bb02_config(void)
+{
+ if (!_enabled) {
+ smarteeprom_setup();
+ }
+}
diff --git a/test/hardware-fakes/src/fake_spi_mem.c b/test/hardware-fakes/src/fake_spi_mem.c
new file mode 100644
index 0000000..17c5fde
--- /dev/null
+++ b/test/hardware-fakes/src/fake_spi_mem.c
@@ -0,0 +1,50 @@
+// Copyright 2025 Shift Crypto AG
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <memory/spi_mem.h>
+#include <stdlib.h>
+#include <string.h>
+
+__extension__ static uint8_t _memory[] = {[0 ... SPI_MEM_MEMORY_SIZE] = 0xFF};
+
+bool spi_mem_full_erase(void)
+{
+ memset(_memory, 0xFF, sizeof(_memory));
+ return true;
+}
+
+bool spi_mem_write(uint32_t address, const uint8_t* input, size_t size)
+{
+ memcpy(&_memory[address], input, size);
+ return true;
+}
+
+uint8_t* spi_mem_read(uint32_t address, size_t size)
+{
+ uint8_t* result = (uint8_t*)malloc(size);
+ if (!result) {
+ return NULL;
+ }
+ memcpy(result, &_memory[address], size);
+ return result;
+}
+
+void spi_mem_protected_area_lock(void) {}
+
+void spi_mem_protected_area_unlock(void) {}
+
+bool spi_mem_protected_area_write(uint32_t address, const uint8_t* input, size_t size)
+{
+ return spi_mem_write(address, input, size);
+}
diff --git a/test/hardware-mocks/CMakeLists.txt b/test/hardware-mocks/CMakeLists.txt
deleted file mode 100644
index e007dd8..0000000
--- a/test/hardware-mocks/CMakeLists.txt
+++ /dev/null
@@ -1,68 +0,0 @@
-# Copyright 2024 Shift Cryptosecurity AG
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-bad-function-cast")
-
-set(HARDWARE-MOCKS-SOURCES
- src/mock_cipher.c
- src/mock_diskio.c
- src/mock_memory.c
- src/mock_screen.c
- src/mock_securechip.c
- src/mock_smarteeprom.c
- src/mock_spi_mem.c
- src/mock_component.c
- src/mock_delay.c
- src/mock_qtouch.c
-)
-
-add_library(hardware-mocks
- STATIC
- ${HARDWARE-MOCKS-SOURCES}
-)
-
-add_dependencies(hardware-mocks rust-cbindgen)
-
-target_compile_definitions(hardware-mocks PUBLIC
- TESTING
- _UNIT_TEST_
- PRODUCT_BITBOX_MULTI=1
- APP_BTC=1
- APP_LTC=1
- APP_U2F=1
- APP_ETH=1
-)
-
-target_include_directories(
- hardware-mocks
- PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}/include
-)
-target_include_directories(
- hardware-mocks
- PRIVATE
- ${INCLUDES}
- ${CMAKE_BINARY_DIR}/src
- $<TARGET_PROPERTY:fatfs,INTERFACE_INCLUDE_DIRECTORIES>
- $<TARGET_PROPERTY:wallycore,INTERFACE_INCLUDE_DIRECTORIES>
-)
-
-target_link_libraries(hardware-mocks PUBLIC wallycore)
-
-if(SANITIZE_ADDRESS)
- target_compile_options(hardware-mocks PUBLIC "-fsanitize=address")
-endif()
-if(SANTIZE_UNDEFINED)
- target_compile_options(hardware-mocks PUBLIC "-fsanitize=undefined")
-endif()
diff --git a/test/hardware-mocks/README.md b/test/hardware-mocks/README.md
deleted file mode 100644
index aa0a51a..0000000
--- a/test/hardware-mocks/README.md
+++ /dev/null
@@ -1,4 +0,0 @@
-# Hardware fakes
-
-All files in this directory fake hardware functionailty. Used in unit tests and
-simulators
diff --git a/test/hardware-mocks/include/mock_cipher.h b/test/hardware-mocks/include/mock_cipher.h
deleted file mode 100644
index 8c73acd..0000000
--- a/test/hardware-mocks/include/mock_cipher.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2023 Shift Crypto AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef _MOCK_CIPHER_H_
-#define _MOCK_CIPHER_H_
-
-#include <stdint.h>
-
-void cipher_mock_iv(uint8_t* iv_out);
-
-#endif
diff --git a/test/hardware-mocks/include/mock_component.h b/test/hardware-mocks/include/mock_component.h
deleted file mode 100644
index db863fb..0000000
--- a/test/hardware-mocks/include/mock_component.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef _MOCK_COMPONENT_H_
-#define _MOCK_COMPONENT_H_
-
-#include <ui/component.h>
-
-/********************************** Create Instance **********************************/
-
-/**
- * Creates a label with the given font either upside down or normal.
- * @param[in] text The text of the label.
- * @param[in] upside_down Whether the text should be rotated 180 degree or not.
- * @param[in] font The font of the label.
- */
-component_t* mock_component_create(void);
-
-#endif
diff --git a/test/hardware-mocks/include/mock_memory.h b/test/hardware-mocks/include/mock_memory.h
deleted file mode 100644
index b050aad..0000000
--- a/test/hardware-mocks/include/mock_memory.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef _MOCK_MEMORY_H_
-#define _MOCK_MEMORY_H_
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <flags.h>
-
-void mock_memory_factoryreset(void);
-bool memory_write_to_address_mock(uint32_t base, uint32_t addr, const uint8_t* chunk);
-bool memory_write_chunk_mock(uint32_t chunk_num, const uint8_t* chunk);
-void memory_read_chunk_mock(uint32_t chunk_num, uint8_t* chunk_out);
-// Size: `FLASH_SHARED_DATA_LEN`.
-void memory_read_shared_bootdata_mock(uint8_t* chunk_out);
-void mock_memory_set_salt_root(const uint8_t* salt_root);
-void memory_bootloader_hash_mock(uint8_t* hash_out);
-void memory_set_bootloader_hash_mock(const uint8_t* mock_hash);
-#endif
diff --git a/test/hardware-mocks/include/mock_qtouch.h b/test/hardware-mocks/include/mock_qtouch.h
deleted file mode 100644
index eff3c10..0000000
--- a/test/hardware-mocks/include/mock_qtouch.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef _QTOUCH_H_
-#define _QTOUCH_H_
-
-#include <stdint.h>
-
-void __wrap_qtouch_process(void);
-
-uint8_t __wrap_qtouch_get_scroller_is_active(uint16_t sensor_node);
-
-uint16_t __wrap_qtouch_get_scroller_position(uint16_t sensor_node);
-
-void qtouch_process(void);
-
-uint8_t qtouch_is_scroller_active(uint16_t sensor_node);
-
-uint16_t qtouch_get_scroller_position(uint16_t sensor_node);
-
-void qtouch_force_calibrate(void);
-
-#endif
diff --git a/test/hardware-mocks/src/mock_cipher.c b/test/hardware-mocks/src/mock_cipher.c
deleted file mode 100644
index a18c3b3..0000000
--- a/test/hardware-mocks/src/mock_cipher.c
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2023 Shift Crypto AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <string.h>
-
-#include <mock_cipher.h>
-
-void cipher_mock_iv(uint8_t* iv_out)
-{
- memset(iv_out, 'a', 32);
-}
diff --git a/test/hardware-mocks/src/mock_component.c b/test/hardware-mocks/src/mock_component.c
deleted file mode 100644
index 09cfdc8..0000000
--- a/test/hardware-mocks/src/mock_component.c
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <string.h>
-
-#include <screen.h>
-#include <stdlib.h>
-#include <ui/ui_util.h>
-
-#include "mock_component.h"
-
-/********************************** Label Functions **********************************/
-
-/**
- * Collects all component functions.
- */
-static const component_functions_t MOCK_COMPONENT_FUNCTIONS = {
- .cleanup = ui_util_component_cleanup,
- .render = ui_util_component_render_subcomponents,
- .on_event = ui_util_on_event_noop};
-
-/********************************** Create Instance **********************************/
-
-/**
- * Creates a label with the given font either upside down or normal.
- * @param[in] text The text of the label.
- * @param[in] upside_down Whether the text should be rotated 180 degree or not.
- * @param[in] font The font of the label.
- */
-component_t* mock_component_create(void)
-{
- component_t* mock = malloc(sizeof(component_t));
- memset(mock, 0, sizeof(component_t));
- mock->f = &MOCK_COMPONENT_FUNCTIONS;
-
- mock->dimension.width = SCREEN_WIDTH;
- mock->dimension.height = SCREEN_HEIGHT;
- mock->position.left = 0;
- mock->position.top = 0;
-
- return mock;
-}
diff --git a/test/hardware-mocks/src/mock_delay.c b/test/hardware-mocks/src/mock_delay.c
deleted file mode 100644
index e539f5b..0000000
--- a/test/hardware-mocks/src/mock_delay.c
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdint.h>
-#include <unistd.h>
-
-void delay_ms(const uint16_t ms)
-{
- usleep(1000 * ms);
-}
-
-void delay_us(const uint16_t us)
-{
- usleep(us);
-}
diff --git a/test/hardware-mocks/src/mock_diskio.c b/test/hardware-mocks/src/mock_diskio.c
deleted file mode 100644
index bb2fc7f..0000000
--- a/test/hardware-mocks/src/mock_diskio.c
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2021 Shift Crypto AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdint.h>
-#include <string.h>
-
-// Must be included before diskio.h, see http://elm-chan.org/fsw/ff/bd/?show=3626
-#include <ff.h>
-
-#include <diskio.h>
-
-// This file is the disk middleware for use in tests, replacing sdmmc_diskio.c used in the firmware
-// to write to microSD cards.
-//
-// It writes and reads from RAM instead of to a card or disk so that unit tests can exercise all
-// sd-card related functionality.
-
-// 100mb with 512 bytes per sector
-#define SECTOR_SIZE 512
-#define SECTOR_COUNT 204800
-static uint8_t _data[SECTOR_SIZE * SECTOR_COUNT] = {0};
-
-DSTATUS disk_initialize(uint8_t drv)
-{
- (void)drv;
- return 0;
-}
-
-DSTATUS disk_status(uint8_t drv)
-{
- (void)drv;
- return 0;
-}
-
-DRESULT disk_read(BYTE pdrv, BYTE* buff, LBA_t sector, UINT count)
-{
- (void)pdrv;
- for (UINT i = 0; i < count; i++) {
- memcpy(&buff[SECTOR_SIZE * i], &_data[SECTOR_SIZE * sector + SECTOR_SIZE * i], SECTOR_SIZE);
- }
- return RES_OK;
-}
-
-DRESULT disk_write(BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count)
-{
- for (UINT i = 0; i < count; i++) {
- memcpy(&_data[SECTOR_SIZE * sector + SECTOR_SIZE * i], &buff[SECTOR_SIZE * i], SECTOR_SIZE);
- }
- return RES_OK;
-}
-
-DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff)
-{
- (void)pdrv;
- switch (cmd) {
- case CTRL_SYNC:
- // Already synced (RAM).
- return RES_OK;
- case GET_BLOCK_SIZE:
- *(DWORD*)buff = 1;
- return RES_OK;
- case GET_SECTOR_SIZE:
- *(LBA_t*)buff = SECTOR_SIZE;
- return RES_OK;
- case GET_SECTOR_COUNT:
- *(LBA_t*)buff = SECTOR_COUNT;
- return RES_OK;
- default:
- return RES_PARERR;
- }
-}
diff --git a/test/hardware-mocks/src/mock_memory.c b/test/hardware-mocks/src/mock_memory.c
deleted file mode 100644
index d3051b3..0000000
--- a/test/hardware-mocks/src/mock_memory.c
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <flags.h>
-#include <memory/memory.h>
-#include <mock_memory.h>
-#include <stdio.h>
-#include <string.h>
-
-static uint8_t _memory_shared_data[FLASH_SHARED_DATA_LEN] = {0};
-static uint8_t _memory_app_data[FLASH_APPDATA_LEN] = {0};
-static uint8_t _memory_smarteeprom[SMARTEEPROM_RESERVED_FLASH_PAGES * FLASH_PAGE_SIZE] = {0};
-
-void mock_memory_factoryreset(void)
-{
- memset(_memory_shared_data, 0xff, sizeof(_memory_shared_data));
- memset(_memory_app_data, 0xff, sizeof(_memory_app_data));
- memset(_memory_smarteeprom, 0xff, sizeof(_memory_smarteeprom));
-}
-
-static uint8_t* _get_memory(uint32_t base)
-{
- switch (base) {
- case FLASH_SHARED_DATA_START:
- return _memory_shared_data;
- case FLASH_APPDATA_START:
- return _memory_app_data;
- case FLASH_SMARTEEPROM_START:
- return _memory_smarteeprom;
- default:
- return NULL;
- }
-}
-
-bool memory_write_to_address_mock(uint32_t base, uint32_t addr, const uint8_t* chunk)
-{
- if (chunk == NULL) {
- memset(_get_memory(base) + addr, 0xff, (size_t)CHUNK_SIZE);
- } else {
- memcpy(_get_memory(base) + addr, chunk, (size_t)CHUNK_SIZE);
- }
- return true;
-}
-
-bool memory_write_chunk_mock(uint32_t chunk_num, const uint8_t* chunk)
-{
- return memory_write_to_address_mock(FLASH_APPDATA_START, chunk_num * (size_t)CHUNK_SIZE, chunk);
-}
-
-void memory_read_chunk_mock(uint32_t chunk_num, uint8_t* chunk_out)
-{
- memcpy(chunk_out, _memory_app_data + chunk_num * (size_t)CHUNK_SIZE, (size_t)CHUNK_SIZE);
-}
-
-void memory_read_shared_bootdata_mock(uint8_t* chunk_out)
-{
- memcpy(chunk_out, _memory_shared_data, (size_t)FLASH_SHARED_DATA_LEN);
-}
-
-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 mock_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)
-{
- memcpy(salt_root_out, _salt_root, 32);
- return true;
-}
-
-// Arbitrary value.
-static uint8_t _bootloader_hash[32] =
- "\x71\x3d\xf0\xd5\x8c\x71\x7d\x40\x31\x78\x7c\xdc\x8f\xa3\x5b\x90\x25\x82\xbe\x6a\xb6\xa2\x2e"
- "\x09\xde\x44\x77\xd3\x0e\x22\x30\xfc";
-
-void memory_bootloader_hash_mock(uint8_t* hash_out)
-{
- memcpy(hash_out, _bootloader_hash, 32);
-}
-
-void memory_set_bootloader_hash_mock(const uint8_t* mock_hash)
-{
- // NOLINTNEXTLINE(bugprone-not-null-terminated-result)
- memcpy(_bootloader_hash, mock_hash, sizeof(_bootloader_hash));
-}
diff --git a/test/hardware-mocks/src/mock_qtouch.c b/test/hardware-mocks/src/mock_qtouch.c
deleted file mode 100644
index e980b09..0000000
--- a/test/hardware-mocks/src/mock_qtouch.c
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// The real qtouch.h depends on hardware specific headers and cannot be used
-#include <mock_qtouch.h>
-
-#include <stdbool.h>
-
-volatile bool measurement_done_touch = true;
-
-void qtouch_process(void) {}
-
-void qtouch_force_calibrate(void) {}
diff --git a/test/hardware-mocks/src/mock_screen.c b/test/hardware-mocks/src/mock_screen.c
deleted file mode 100644
index 45d81ca..0000000
--- a/test/hardware-mocks/src/mock_screen.c
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include <screen.h>
-
-UG_COLOR screen_front_color = C_WHITE;
-UG_COLOR screen_back_color = C_BLACK;
-
-slider_location_t top_slider = 1;
-slider_location_t bottom_slider = 0;
-
-void screen_print_debug(const char* message, int duration)
-{
- printf("%s\n", message);
-}
-
-void screen_splash(void)
-{
- puts("screen splash\n");
-}
-
-void screen_rotate(void) {}
-
-bool screen_is_upside_down(void)
-{
- return false;
-}
-
-void screen_clear(void) {}
diff --git a/test/hardware-mocks/src/mock_securechip.c b/test/hardware-mocks/src/mock_securechip.c
deleted file mode 100644
index 90ec17c..0000000
--- a/test/hardware-mocks/src/mock_securechip.c
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <rust/rust.h>
-#include <salt.h>
-#include <securechip/securechip.h>
-#include <stdio.h>
-#include <string.h>
-
-static uint32_t _u2f_counter;
-
-// Mocked contents of the secure chip rollkey slot.
-static const uint8_t _rollkey[32] =
- "\x9d\xd1\x34\x1f\x6b\x4b\x26\xb1\x72\x89\xa1\xa3\x92\x71\x5c\xf0\xd0\x57\x8c\x84\xdb\x9a\x51"
- "\xeb\xde\x14\x24\x06\x69\xd1\xd0\x5e";
-
-// Mocked contents of the securechip kdf slot.
-static const uint8_t _kdfkey[32] =
- "\xd2\xe1\xe6\xb1\x8b\x6c\x6b\x08\x43\x3e\xdb\xc1\xd1\x68\xc1\xa0\x04\x37\x74\xa4\x22\x18\x77"
- "\xe7\x9e\xd5\x66\x84\xbe\x5a\xc0\x1b";
-
-int securechip_kdf(const uint8_t* msg, size_t len, uint8_t* kdf_out)
-{
- rust_hmac_sha256(_kdfkey, 32, msg, len, kdf_out);
- return 0;
-}
-int securechip_kdf_rollkey(const uint8_t* msg, size_t len, uint8_t* kdf_out)
-{
- rust_hmac_sha256(_rollkey, 32, msg, len, kdf_out);
- return 0;
-}
-int securechip_init_new_password(const char* password)
-{
- (void)password;
- return 0;
-}
-int securechip_stretch_password(const char* password, uint8_t* stretched_out)
-{
- uint8_t key[9] = "unit-test";
- rust_hmac_sha256(key, sizeof(key), (const uint8_t*)password, strlen(password), stretched_out);
- return 0;
-}
-bool securechip_u2f_counter_set(uint32_t counter)
-{
- _u2f_counter = counter;
- return true;
-}
-
-bool securechip_u2f_counter_inc(uint32_t* counter)
-{
- *counter = _u2f_counter++;
- return true;
-}
-
-bool securechip_attestation_sign(const uint8_t* msg, uint8_t* signature_out)
-{
- return false;
-}
-
-bool securechip_monotonic_increments_remaining(uint32_t* remaining_out)
-{
- *remaining_out = 1;
- return true;
-}
-
-bool securechip_model(securechip_model_t* model_out)
-{
- *model_out = ATECC_ATECC608B;
- return true;
-}
diff --git a/test/hardware-mocks/src/mock_smarteeprom.c b/test/hardware-mocks/src/mock_smarteeprom.c
deleted file mode 100644
index b5cf2ce..0000000
--- a/test/hardware-mocks/src/mock_smarteeprom.c
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-/**
- * Mock for the SmartEEPROM functions.
- */
-#include <memory/smarteeprom.h>
-
-#include <assert.h>
-#include <string.h>
-
-static char* _mem_image = NULL;
-static size_t _allocated_space = 0;
-static size_t _enabled = 0;
-
-void smarteeprom_setup(void)
-{
- /* Allocate an equivalent amount of raw memory */
- size_t n_virtual_pages = SMARTEEPROM_ALLOCATED_BLOCKS * 8192 / SMARTEEPROM_PAGE_SIZE;
- /*
- * The maximum number of virtual pages is limited to 128.
- * Ref. SAMD5x/E5x Family Data Sheet sec. 25.6.8.3
- */
- if (n_virtual_pages > 128) {
- n_virtual_pages = 128;
- }
- _allocated_space = n_virtual_pages * SMARTEEPROM_PAGE_SIZE;
- _mem_image = malloc(_allocated_space);
- if (!_mem_image) {
- abort();
- }
- memset(_mem_image, 0xFF, _allocated_space);
- _enabled = 1;
-}
-
-/**
- * Reads N contiguous bytes from the SmartEEPROM, starting at
- * the specified address.
- *
- * @param[in] address Start address.
- * @param[in] size Number of bytes to read.
- * @param[out] out_buffer Buffer in which to read.
- * Must be at least size bytes wide.
- */
-void smarteeprom_read(size_t address, size_t bytes, uint8_t* out_buffer)
-{
- assert(address + bytes < _allocated_space);
- assert(_enabled);
- memcpy(out_buffer, _mem_image + address, bytes);
-}
-
-/**
- * Writes N contiguous bytes to the SmartEEPROM, starting at
- * the specified address.
- *
- * Note that this will not affect the write endurance of the
- * underlying memory, unless the content currently stored at
- * the specified address has some bits that must be flipped from
- * "0" to "1". Use this wisely!
- *
- * @param[in] address Start address.
- * @param[in] size Number of bytes to write.
- * @param[in] buffer Buffer from which to read the data.
- * Must be at least size bytes wide.
- */
-void smarteeprom_write(size_t address, size_t bytes, const uint8_t* buffer)
-{
- assert(_allocated_space > bytes && address < _allocated_space - bytes);
- assert(_enabled);
- memcpy(_mem_image + address, buffer, bytes);
-}
-
-bool smarteeprom_is_enabled(void)
-{
- return _enabled;
-}
-
-void smarteeprom_disable(void)
-{
- _enabled = 0;
- _allocated_space = 0;
- free(_mem_image);
-}
-
-void smarteeprom_bb02_config(void)
-{
- if (!_enabled) {
- smarteeprom_setup();
- }
-}
diff --git a/test/hardware-mocks/src/mock_spi_mem.c b/test/hardware-mocks/src/mock_spi_mem.c
deleted file mode 100644
index 17c5fde..0000000
--- a/test/hardware-mocks/src/mock_spi_mem.c
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2025 Shift Crypto AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <memory/spi_mem.h>
-#include <stdlib.h>
-#include <string.h>
-
-__extension__ static uint8_t _memory[] = {[0 ... SPI_MEM_MEMORY_SIZE] = 0xFF};
-
-bool spi_mem_full_erase(void)
-{
- memset(_memory, 0xFF, sizeof(_memory));
- return true;
-}
-
-bool spi_mem_write(uint32_t address, const uint8_t* input, size_t size)
-{
- memcpy(&_memory[address], input, size);
- return true;
-}
-
-uint8_t* spi_mem_read(uint32_t address, size_t size)
-{
- uint8_t* result = (uint8_t*)malloc(size);
- if (!result) {
- return NULL;
- }
- memcpy(result, &_memory[address], size);
- return result;
-}
-
-void spi_mem_protected_area_lock(void) {}
-
-void spi_mem_protected_area_unlock(void) {}
-
-bool spi_mem_protected_area_write(uint32_t address, const uint8_t* input, size_t size)
-{
- return spi_mem_write(address, input, size);
-}
diff --git a/test/simulator/CMakeLists.txt b/test/simulator/CMakeLists.txt
index 761b084..5dbfa69 100644
--- a/test/simulator/CMakeLists.txt
+++ b/test/simulator/CMakeLists.txt
@@ -121,7 +121,7 @@ add_dependencies(bitbox_objects-simulator
secp256k1
fatfs
)
-target_link_libraries(bitbox_objects-simulator PUBLIC hardware-mocks)
+target_link_libraries(bitbox_objects-simulator PUBLIC hardware-fakes)
target_link_libraries(bitbox-simulator PRIVATE ${LIBBITBOX02_RUST} "-lm")
# _UNIT_TEST_ is used by ASF4 to not cross compile
@@ -163,7 +163,7 @@ target_link_libraries(simulator PRIVATE
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wl,--start-group>
c-unit-tests_rust_c
bitbox-simulator
- hardware-mocks
+ hardware-fakes
fatfs
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wl,--end-group>
""
diff --git a/test/simulator/simulator.c b/test/simulator/simulator.c
index 37fca76..13929be 100644
--- a/test/simulator/simulator.c
+++ b/test/simulator/simulator.c
@@ -16,9 +16,9 @@
#include "memory/bitbox02_smarteeprom.h"
#include "usb/usb_packet.h"
#include "usb/usb_processing.h"
+#include <fake_memory.h>
#include <fcntl.h>
#include <memory/memory.h>
-#include <mock_memory.h>
#include <queue.h>
#include <random.h>
#include <rust/rust.h>
@@ -117,7 +117,7 @@ int main(int argc, char* argv[])
return 1;
}
- mock_memory_factoryreset();
+ fake_memory_factoryreset();
memory_interface_functions_t ifs = {
.random_32_bytes = random_32_bytes_mcu,
};
diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt
index 3e0678a..43d0424 100644
--- a/test/unit-test/CMakeLists.txt
+++ b/test/unit-test/CMakeLists.txt
@@ -143,7 +143,7 @@ add_dependencies(bitbox_objects
secp256k1
fatfs
)
-target_link_libraries(bitbox_objects PUBLIC hardware-mocks)
+target_link_libraries(bitbox_objects PUBLIC hardware-fakes)
target_link_libraries(bitbox PRIVATE ${LIBBITBOX02_RUST} "-lm")
# _UNIT_TEST_ is used by ASF4 to not cross compile
@@ -224,13 +224,13 @@ set(TEST_LIST
ui_component_gestures
""
memory
- "-Wl,--wrap=memory_read_chunk_mock,--wrap=memory_write_chunk_mock,--wrap=rust_noise_generate_static_private_key,--wrap=memory_read_shared_bootdata_mock,--wrap=memory_write_to_address_mock,--wrap=random_32_bytes_mcu"
+ "-Wl,--wrap=memory_read_chunk_fake,--wrap=memory_write_chunk_fake,--wrap=rust_noise_generate_static_private_key,--wrap=memory_read_shared_bootdata_fake,--wrap=memory_write_to_address_fake,--wrap=random_32_bytes_mcu"
memory_functional
""
salt
"-Wl,--wrap=memory_get_salt_root"
cipher
- "-Wl,--wrap=cipher_mock_iv"
+ "-Wl,--wrap=cipher_fake_iv"
util
""
ugui
@@ -255,7 +255,7 @@ else()
-Wl,--start-group
c-unit-tests_rust_c
bitbox
- hardware-mocks
+ hardware-fakes
fatfs
-Wl,--end-group
${TEST_LINK_ARGS}
@@ -285,7 +285,7 @@ foreach(TEST_NAME ${U2F_TESTS})
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wl,--start-group>
c-unit-tests_rust_c
bitbox
- hardware-mocks
+ hardware-fakes
fatfs
$<$<NOT:$<PLATFORM_ID:Darwin>>:-Wl,--end-group>
u2f-util
diff --git a/test/unit-test/framework/include/mock_memory.h b/test/unit-test/framework/include/mock_memory.h
deleted file mode 100644
index b050aad..0000000
--- a/test/unit-test/framework/include/mock_memory.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2019 Shift Cryptosecurity AG
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#ifndef _MOCK_MEMORY_H_
-#define _MOCK_MEMORY_H_
-
-#include <stdbool.h>
-#include <stdint.h>
-
-#include <flags.h>
-
-void mock_memory_factoryreset(void);
-bool memory_write_to_address_mock(uint32_t base, uint32_t addr, const uint8_t* chunk);
-bool memory_write_chunk_mock(uint32_t chunk_num, const uint8_t* chunk);
-void memory_read_chunk_mock(uint32_t chunk_num, uint8_t* chunk_out);
-// Size: `FLASH_SHARED_DATA_LEN`.
-void memory_read_shared_bootdata_mock(uint8_t* chunk_out);
-void mock_memory_set_salt_root(const uint8_t* salt_root);
-void memory_bootloader_hash_mock(uint8_t* hash_out);
-void memory_set_bootloader_hash_mock(const uint8_t* mock_hash);
-#endif
diff --git a/test/unit-test/framework/src/mock_memory.c b/test/unit-test/framework/src/mock_memory.c
index 649dede..f82a866 100644
--- a/test/unit-test/framework/src/mock_memory.c
+++ b/test/unit-test/framework/src/mock_memory.c
@@ -20,7 +20,6 @@
#include <flags.h>
#include <memory/memory.h>
-#include <mock_memory.h>
#include <stdio.h>
#include <string.h>
diff --git a/test/unit-test/test_cipher.c b/test/unit-test/test_cipher.c
index 10c8276..1a1ba47 100644
--- a/test/unit-test/test_cipher.c
+++ b/test/unit-test/test_cipher.c
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <string.h>
-void __wrap_cipher_mock_iv(uint8_t* iv_out)
+void __wrap_cipher_fake_iv(uint8_t* iv_out)
{
memcpy(iv_out, (const uint8_t*)mock(), 32);
}
@@ -3839,7 +3839,7 @@ static void _test_cipher_aes_hmac_encrypt(void** state)
const test_t* test = &_tests[i];
uint8_t rand_mock[32] = {0};
memcpy(rand_mock, test->iv, 16);
- will_return(__wrap_cipher_mock_iv, rand_mock);
+ will_return(__wrap_cipher_fake_iv, rand_mock);
size_t cipher_len = test->msg_len + 64;
uint8_t cipher[cipher_len];
assert_true(
diff --git a/test/unit-test/test_gestures.c b/test/unit-test/test_gestures.c
index 763da4d..e979010 100644
--- a/test/unit-test/test_gestures.c
+++ b/test/unit-test/test_gestures.c
@@ -20,7 +20,7 @@
#include <touch/gestures.h>
-#include "mock_component.h"
+#include "fake_component.h"
#include "mock_gestures.h"
#include "mock_qtouch.h"
@@ -48,7 +48,7 @@ static void reset_state(void)
*/
static void test_gestures_slide_tap_slide_detected(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
mock_gestures_touch_init();
@@ -96,7 +96,7 @@ static void test_gestures_slide_tap_slide_detected(void** state)
*/
static void test_gestures_slide_and_tap_detected(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
// SLIDE:
mock_gestures_touch_init();
@@ -130,7 +130,7 @@ static void test_gestures_slide_and_tap_detected(void** state)
*/
static void test_gestures_slide_left_to_right_detected(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
mock_gestures_touch_init();
reset_state();
diff --git a/test/unit-test/test_memory.c b/test/unit-test/test_memory.c
index bc34c31..5db877d 100644
--- a/test/unit-test/test_memory.c
+++ b/test/unit-test/test_memory.c
@@ -64,25 +64,25 @@ __extension__ static uint8_t _salt_root[] = {[0 ... 32 - 1] = 0x84};
#define EMPTYCHUNK(var) __extension__ uint8_t var[] = {[0 ... CHUNK_SIZE - 1] = 0xFF};
-void __wrap_memory_read_chunk_mock(uint32_t chunk_num, uint8_t* chunk_out)
+void __wrap_memory_read_chunk_fake(uint32_t chunk_num, uint8_t* chunk_out)
{
check_expected(chunk_num);
memcpy(chunk_out, (uint8_t*)mock(), CHUNK_SIZE);
}
-void __wrap_memory_read_shared_bootdata_mock(uint8_t* chunk_out)
+void __wrap_memory_read_shared_bootdata_fake(uint8_t* chunk_out)
{
memcpy(chunk_out, (uint8_t*)mock(), CHUNK_SIZE);
}
-bool __wrap_memory_write_chunk_mock(uint32_t chunk_num, uint8_t* chunk)
+bool __wrap_memory_write_chunk_fake(uint32_t chunk_num, uint8_t* chunk)
{
check_expected(chunk_num);
check_expected(chunk);
return mock();
}
-bool __wrap_memory_write_to_address_mock(uint32_t base, uint32_t addr, uint8_t* chunk)
+bool __wrap_memory_write_to_address_fake(uint32_t base, uint32_t addr, uint8_t* chunk)
{
check_expected(base);
check_expected(addr);
@@ -120,22 +120,22 @@ static void _expect_reset(uint8_t* empty_chunk1, uint8_t* empty_chunk2)
// Reset all except first and last chunk.
for (uint32_t write_calls = 0; write_calls < FLASH_APP_DATA_LEN / CHUNK_SIZE - 2;
write_calls++) {
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, write_calls + 1);
- expect_value(__wrap_memory_write_chunk_mock, chunk, NULL);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, write_calls + 1);
+ expect_value(__wrap_memory_write_chunk_fake, chunk, NULL);
+ will_return(__wrap_memory_write_chunk_fake, true);
}
will_return(_mock_random_32_bytes, _salt_root);
// Initialize chunk 1
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk1);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk1);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
memcpy(&empty_chunk2[_addr_noise_static_private_key], _noise_static_private_key, 32);
memcpy(&empty_chunk2[_addr_salt_root], _salt_root, 32);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, empty_chunk2, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, empty_chunk2, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
}
#define EXPECT_RESET \
@@ -152,13 +152,13 @@ static void _expect_setup(uint8_t* expected_chunk, uint8_t* expected_shared_chun
memcpy(expected_chunk + _addr_enckey, _enc_key, 32);
memcpy(expected_shared_chunk + _addr_enckey_split, _enc_key_split, 32);
- expect_value(__wrap_memory_write_to_address_mock, base, FLASH_SHARED_DATA_START);
- expect_value(__wrap_memory_write_to_address_mock, addr, 0);
- expect_memory(__wrap_memory_write_to_address_mock, chunk, expected_shared_chunk, CHUNK_SIZE);
+ expect_value(__wrap_memory_write_to_address_fake, base, FLASH_SHARED_DATA_START);
+ expect_value(__wrap_memory_write_to_address_fake, addr, 0);
+ expect_memory(__wrap_memory_write_to_address_fake, chunk, expected_shared_chunk, CHUNK_SIZE);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 0);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 0);
expected_chunk[_addr_factory_setup_done] = _factory_setup_done;
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
}
static void _expect_keys(void)
@@ -174,44 +174,44 @@ static void _expect_keys(void)
static void _test_memory_setup(void** state)
{
// Success if setup not yet done.
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
EMPTYCHUNK(empty_chunk);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
EXPECT_RESET;
_expect_keys();
EMPTYCHUNK(empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
EMPTYCHUNK(setup_chunk);
EMPTYCHUNK(shared_chunk);
_expect_setup(setup_chunk, shared_chunk);
- will_return(__wrap_memory_write_chunk_mock, true);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_setup(&_ifs));
// Success if setup already done before.
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
EMPTYCHUNK(chunk0_setupdone);
chunk0_setupdone[_addr_factory_setup_done] = _factory_setup_done;
- will_return(__wrap_memory_read_chunk_mock, chunk0_setupdone);
+ will_return(__wrap_memory_read_chunk_fake, chunk0_setupdone);
assert_true(memory_setup(&_ifs));
}
static void _fail_reset(void)
{
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_value(__wrap_memory_write_chunk_mock, chunk, NULL);
- will_return(__wrap_memory_write_chunk_mock, false);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_value(__wrap_memory_write_chunk_fake, chunk, NULL);
+ will_return(__wrap_memory_write_chunk_fake, false);
}
static void _test_memory_setup_failreset(void** state)
{
// Fail because resetting failed.
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
EMPTYCHUNK(chunk0);
- will_return(__wrap_memory_read_chunk_mock, chunk0);
+ will_return(__wrap_memory_read_chunk_fake, chunk0);
_fail_reset();
assert_false(memory_setup(&_ifs));
}
@@ -219,30 +219,30 @@ static void _test_memory_setup_failreset(void** state)
static void _test_memory_setup_failpersist(void** state)
{
// Failing because perisisting the factory setup data fails.
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
EMPTYCHUNK(chunk0);
- will_return(__wrap_memory_read_chunk_mock, chunk0);
+ will_return(__wrap_memory_read_chunk_fake, chunk0);
EXPECT_RESET;
_expect_keys();
EMPTYCHUNK(empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
EMPTYCHUNK(setup_chunk);
EMPTYCHUNK(shared_chunk);
_expect_setup(setup_chunk, shared_chunk);
- will_return(__wrap_memory_write_chunk_mock, false);
+ will_return(__wrap_memory_write_chunk_fake, false);
assert_false(memory_setup(&_ifs));
}
static void _expect_bitmask(uint8_t* chunk, uint8_t bitmask)
{
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
chunk[_addr_bitmask] = bitmask;
- will_return(__wrap_memory_read_chunk_mock, chunk);
+ will_return(__wrap_memory_read_chunk_fake, chunk);
}
static void _test_memory_is_seeded(void** state)
@@ -278,9 +278,9 @@ static void _test_memory_set_initialized(void** state)
_expect_bitmask(chunk, i);
EMPTYCHUNK(expected_chunk);
expected_chunk[_addr_bitmask] = ~(~i | _bitmask_initialized);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_set_initialized());
}
}
@@ -290,8 +290,8 @@ static void _test_memory_get_failed_unlock_attempts(void** state)
for (uint8_t attempts = 0; attempts < 0xFF; attempts++) {
EMPTYCHUNK(empty_chunk);
empty_chunk[_addr_failed_unlock_attempts] = 0xFF - attempts;
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
assert_int_equal(attempts, memory_get_failed_unlock_attempts());
}
}
@@ -299,8 +299,8 @@ static void _test_memory_get_failed_unlock_attempts(void** state)
static void _expect_failed_unlock_attempts(uint8_t* chunk, uint8_t attempts)
{
chunk[_addr_failed_unlock_attempts] = 0xFF - attempts;
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, chunk);
}
static void _test_memory_increment_failed_unlock_attempts(void** state)
@@ -311,9 +311,9 @@ static void _test_memory_increment_failed_unlock_attempts(void** state)
EMPTYCHUNK(expected_chunk);
expected_chunk[_addr_failed_unlock_attempts] = 0xFF - (attempts + 1);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_increment_failed_unlock_attempts());
}
}
@@ -334,9 +334,9 @@ static void _test_memory_reset_failed_unlock_attempts(void** state)
if (attempts != 0) { // no write if already reset.
EMPTYCHUNK(expected_chunk);
expected_chunk[_addr_failed_unlock_attempts] = 0xFF;
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
}
assert_true(memory_reset_failed_unlock_attempts());
} while (attempts--);
@@ -368,9 +368,9 @@ static void _test_memory_set_mnemonic_passphrase_enabled(void** state)
// expect disabled
expected_chunk[_addr_bitmask] = ~(~i & ~_bitmask_mnemonic_passphrase_enabled);
}
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_set_mnemonic_passphrase_enabled(enable));
}
}
@@ -379,7 +379,7 @@ static void _test_memory_set_mnemonic_passphrase_enabled(void** state)
static void _test_memory_reset_hww(void** state)
{
EMPTYCHUNK(empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
EXPECT_RESET;
assert_true(memory_reset_hww());
@@ -391,11 +391,11 @@ static void _test_memory_get_device_name_default(void** state)
{
char name_out[MEMORY_DEVICE_NAME_MAX_LEN] = {0};
EMPTYCHUNK(empty_chunk);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
EMPTYCHUNK(empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
memory_get_device_name(name_out);
assert_string_equal(MEMORY_DEFAULT_DEVICE_NAME, name_out);
@@ -410,14 +410,14 @@ static void _test_memory_get_device_name_default_bluetooth(void** state)
char name_out[MEMORY_DEVICE_NAME_MAX_LEN] = {0};
EMPTYCHUNK(empty_chunk);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
EMPTYCHUNK(empty_shared_chunk);
chunk_shared_t shared_chunk = {0};
memcpy(shared_chunk.bytes, empty_shared_chunk, CHUNK_SIZE);
shared_chunk.fields.platform = MEMORY_PLATFORM_BITBOX02_PLUS;
- will_return(__wrap_memory_read_shared_bootdata_mock, shared_chunk.bytes);
+ will_return(__wrap_memory_read_shared_bootdata_fake, shared_chunk.bytes);
will_return(__wrap_random_32_bytes_mcu, entropy);
@@ -425,9 +425,9 @@ static void _test_memory_get_device_name_default_bluetooth(void** state)
assert_string_equal("BitBox AZUV", name_out);
// Calling it again does not re-generate a new random name but reuses the already generated one.
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, shared_chunk.bytes);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, shared_chunk.bytes);
memory_get_device_name(name_out);
assert_string_equal("BitBox AZUV", name_out);
}
@@ -441,10 +441,10 @@ static void _test_memory_get_device_name_invalid(void** state)
snprintf((char*)chunk + _addr_device_name, MEMORY_DEVICE_NAME_MAX_LEN, "%s", device_name);
EMPTYCHUNK(empty_shared_chunk);
- will_return(__wrap_memory_read_shared_bootdata_mock, empty_shared_chunk);
+ will_return(__wrap_memory_read_shared_bootdata_fake, empty_shared_chunk);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, chunk);
memory_get_device_name(name_out);
assert_string_equal(MEMORY_DEFAULT_DEVICE_NAME, name_out);
}
@@ -457,8 +457,8 @@ static void _test_memory_get_device_name(void** state)
const char* device_name = "foo bar";
snprintf((char*)chunk + _addr_device_name, MEMORY_DEVICE_NAME_MAX_LEN, "%s", device_name);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, chunk);
memory_get_device_name(name_out);
assert_string_equal(device_name, name_out);
}
@@ -466,16 +466,16 @@ static void _test_memory_get_device_name(void** state)
static void _set_device_name(const char* device_name)
{
EMPTYCHUNK(empty_chunk);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
EMPTYCHUNK(expected_chunk);
memset(expected_chunk + _addr_device_name, 0, MEMORY_DEVICE_NAME_MAX_LEN);
snprintf(
(char*)expected_chunk + _addr_device_name, MEMORY_DEVICE_NAME_MAX_LEN, "%s", device_name);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_set_device_name(device_name));
}
@@ -493,23 +493,23 @@ static void _test_memory_device_name(void** state)
static void _test_memory_set_seed_birthdate(void** state)
{
EMPTYCHUNK(empty_chunk);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 1);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 1);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
EMPTYCHUNK(expected_chunk);
uint32_t* timestamp = (uint32_t*)&expected_chunk[_addr_seed_birthdate];
*timestamp = 0xabcdef11;
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 1);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 1);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_set_seed_birthdate(*timestamp));
}
static void _test_memory_set_attestation_device_pubkey(void** state)
{
EMPTYCHUNK(empty_chunk);
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
- will_return(__wrap_memory_read_chunk_mock, empty_chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
+ will_return(__wrap_memory_read_chunk_fake, empty_chunk);
const uint8_t pubkey[64] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x11,
@@ -520,9 +520,9 @@ static void _test_memory_set_attestation_device_pubkey(void** state)
};
EMPTYCHUNK(expected_chunk);
memcpy(&expected_chunk[_addr_attestation_pubkey], pubkey, 64);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 0);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 0);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_set_attestation_device_pubkey(pubkey));
}
@@ -547,8 +547,8 @@ static void _test_memory_set_attestation_certificate(void** state)
uint8_t root_pubkey_identifier[32];
memset(root_pubkey_identifier, 0x67, sizeof(root_pubkey_identifier));
{ // fail if the pubkey does not match
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
- will_return(__wrap_memory_read_chunk_mock, chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
+ will_return(__wrap_memory_read_chunk_fake, chunk);
assert_false(
memory_set_attestation_certificate(pubkey, certificate, root_pubkey_identifier));
@@ -556,16 +556,16 @@ static void _test_memory_set_attestation_certificate(void** state)
memcpy(&chunk[_addr_attestation_pubkey], pubkey, 64);
// 1st call to check if setup is done, 2nd for read/write.
- expect_value(__wrap_memory_read_chunk_mock, chunk_num, 0);
- will_return(__wrap_memory_read_chunk_mock, chunk);
+ expect_value(__wrap_memory_read_chunk_fake, chunk_num, 0);
+ will_return(__wrap_memory_read_chunk_fake, chunk);
EMPTYCHUNK(expected_chunk);
memcpy(&expected_chunk[_addr_attestation_pubkey], pubkey, 64);
memcpy(&expected_chunk[_addr_attestation_certificate], certificate, 64);
memcpy(&expected_chunk[_addr_attestation_root_pubkey_identifier], root_pubkey_identifier, 32);
- expect_value(__wrap_memory_write_chunk_mock, chunk_num, 0);
- expect_memory(__wrap_memory_write_chunk_mock, chunk, expected_chunk, CHUNK_SIZE);
- will_return(__wrap_memory_write_chunk_mock, true);
+ expect_value(__wrap_memory_write_chunk_fake, chunk_num, 0);
+ expect_memory(__wrap_memory_write_chunk_fake, chunk, expected_chunk, CHUNK_SIZE);
+ will_return(__wrap_memory_write_chunk_fake, true);
assert_true(memory_set_attestation_certificate(pubkey, certificate, root_pubkey_identifier));
}
diff --git a/test/unit-test/test_memory_functional.c b/test/unit-test/test_memory_functional.c
index 65262dd..ffe4919 100644
--- a/test/unit-test/test_memory_functional.c
+++ b/test/unit-test/test_memory_functional.c
@@ -17,13 +17,13 @@
#include <stddef.h>
#include <cmocka.h>
+#include <fake_memory.h>
#include <memory/memory.h>
-#include <mock_memory.h>
#include <random.h>
static void _test_memory_multisig(void** state)
{
- mock_memory_factoryreset();
+ fake_memory_factoryreset();
const uint8_t hashes[][32] = {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@@ -84,7 +84,7 @@ static void _test_memory_multisig_invalid(void** state)
static void _test_memory_multisig_full(void** state)
{
- mock_memory_factoryreset();
+ fake_memory_factoryreset();
// Only 25 slots available.
const size_t limit = 25;
uint8_t hashes[limit + 1][32];
@@ -102,7 +102,7 @@ static void _test_memory_multisig_full(void** state)
static void _test_memory_attestation(void** state)
{
- mock_memory_factoryreset();
+ fake_memory_factoryreset();
uint8_t expected_pubkey[64];
memset(expected_pubkey, 0x55, sizeof(expected_pubkey));
@@ -175,7 +175,7 @@ void _memory_setup_rand_mock_test_functional(uint8_t* buf_out)
// Test a series of write/read operations
static void _test_functional(void** state)
{
- mock_memory_factoryreset();
+ fake_memory_factoryreset();
memory_interface_functions_t ifs = {
.random_32_bytes = _memory_setup_rand_mock_test_functional,
@@ -217,7 +217,7 @@ static void _test_functional(void** state)
static void _test_attestation_bootloader_hash(void** state)
{
- mock_memory_factoryreset();
+ fake_memory_factoryreset();
memory_interface_functions_t ifs = {
.random_32_bytes = random_32_bytes_mcu,
@@ -227,7 +227,7 @@ static void _test_attestation_bootloader_hash(void** state)
const uint8_t mock1[32] =
"\x03\x22\xb3\x19\x1a\xab\x5b\xc4\x15\xc5\xba\xfa\xc5\x33\x34\x45\x17\x5b\xe2\xfa\xa8\x33"
"\x3a\xc3\xab\xee\x4c\xd1\x7e\x49\x08\x2a";
- memory_set_bootloader_hash_mock(mock1);
+ memory_set_bootloader_hash_fake(mock1);
uint8_t hash[32];
memory_bootloader_hash(hash);
memory_get_attestation_bootloader_hash(hash);
@@ -241,7 +241,7 @@ static void _test_attestation_bootloader_hash(void** state)
const uint8_t mock2[32] =
"\x6c\xad\x6a\xbc\x3f\xd4\x47\xa5\x8d\x7a\x26\x2d\x76\x06\xa0\x40\xe4\x9e\x82\xb0\x06\x48"
"\x62\x36\x25\x88\x3e\x9f\xc0\xfa\xa8\xad";
- memory_set_bootloader_hash_mock(mock2);
+ memory_set_bootloader_hash_fake(mock2);
memset(hash, 0x00, sizeof(hash));
memory_bootloader_hash(hash);
diff --git a/test/unit-test/test_ui_component_gestures.c b/test/unit-test/test_ui_component_gestures.c
index dd95e80..c919365 100644
--- a/test/unit-test/test_ui_component_gestures.c
+++ b/test/unit-test/test_ui_component_gestures.c
@@ -25,7 +25,7 @@
#include <ui/screen_stack.h>
#include <ui/ui_util.h>
-#include "mock_component.h"
+#include "fake_component.h"
#include "mock_gestures.h"
#include "mock_qtouch.h"
@@ -46,7 +46,7 @@ static void test_ui_right_arrow_tap(void** state)
.render = ui_util_component_render_subcomponents,
.on_event = test_on_event};
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
mock_component->f = &modified_functions;
ui_screen_stack_push(mock_component);
@@ -75,7 +75,7 @@ static void test_ui_left_arrow_tap(void** state)
.render = ui_util_component_render_subcomponents,
.on_event = test_on_event};
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
mock_component->f = &modified_functions;
ui_screen_stack_push(mock_component);
diff --git a/test/unit-test/test_ui_components.c b/test/unit-test/test_ui_components.c
index 5097d4c..17693cf 100644
--- a/test/unit-test/test_ui_components.c
+++ b/test/unit-test/test_ui_components.c
@@ -30,7 +30,7 @@
#include <ui/fonts/monogram_5X9.h>
#include <ui/ui_util.h>
-#include "mock_component.h"
+#include "fake_component.h"
#include "mock_qtouch.h"
static void assert_ui_component_functions(component_t* component)
@@ -41,7 +41,7 @@ static void assert_ui_component_functions(component_t* component)
static void test_ui_components_label(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
component_t* label = label_create("Test", NULL, CENTER, mock_component);
assert_non_null(label);
@@ -53,7 +53,7 @@ static void test_ui_components_label(void** state)
static void test_ui_components_right_arrow(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
component_t* right_arrow = right_arrow_create(top_slider, mock_component);
assert_non_null(right_arrow);
@@ -65,7 +65,7 @@ static void test_ui_components_right_arrow(void** state)
static void test_ui_components_left_arrow(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
component_t* left_arrow = left_arrow_create(top_slider, mock_component);
assert_non_null(left_arrow);
@@ -88,7 +88,7 @@ static void test_ui_components_image(void** state)
0x01, 0xff, 0x00, 0x06, 0x00, 0x00, 0xff, 0x80, 0x03, 0x00, 0x00, 0x1f, 0x00, 0x01, 0xff,
0xfc, 0x03, 0x00, 0x00, 0xff, 0xfe, 0x01, 0x80, 0x00};
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
component_t* image =
image_create(logo_bytes, sizeof(logo_bytes), 41, 25, CENTER, mock_component);
@@ -128,7 +128,7 @@ static void test_ui_components_info_centered(void** state)
static void test_ui_components_keyboard_switch(void** state)
{
- component_t* mock_component = mock_component_create();
+ component_t* mock_component = fake_component_create();
component_t* keyboard_switch = keyboard_switch_create(top_slider, true, false, mock_component);
assert_non_null(keyboard_switch);
diff --git a/test/unit-test/test_ui_util.c b/test/unit-test/test_ui_util.c
index 233644f..f72d006 100644
--- a/test/unit-test/test_ui_util.c
+++ b/test/unit-test/test_ui_util.c
@@ -20,11 +20,11 @@
#include <ui/ui_util.h>
-#include "mock_component.h"
+#include "fake_component.h"
static void test_ui_util_position_center(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -32,7 +32,7 @@ static void test_ui_util_position_center(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 0;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
@@ -48,7 +48,7 @@ static void test_ui_util_position_center(void** state)
static void test_ui_util_position_center_top(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -56,7 +56,7 @@ static void test_ui_util_position_center_top(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 50;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
@@ -72,7 +72,7 @@ static void test_ui_util_position_center_top(void** state)
static void test_ui_util_position_center_bottom(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -80,7 +80,7 @@ static void test_ui_util_position_center_bottom(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 0;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
@@ -96,7 +96,7 @@ static void test_ui_util_position_center_bottom(void** state)
static void test_ui_util_position_left_bottom(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -104,7 +104,7 @@ static void test_ui_util_position_left_bottom(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 0;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
@@ -120,7 +120,7 @@ static void test_ui_util_position_left_bottom(void** state)
static void test_ui_util_position_left_top(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -128,7 +128,7 @@ static void test_ui_util_position_left_top(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 0;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
@@ -144,7 +144,7 @@ static void test_ui_util_position_left_top(void** state)
static void test_ui_util_position_right_bottom(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -152,7 +152,7 @@ static void test_ui_util_position_right_bottom(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 0;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
@@ -168,7 +168,7 @@ static void test_ui_util_position_right_bottom(void** state)
static void test_ui_util_position_right_top(void** state)
{
- component_t* mock_component_1 = mock_component_create();
+ component_t* mock_component_1 = fake_component_create();
mock_component_1->dimension.width = 100;
mock_component_1->dimension.height = 100;
@@ -176,7 +176,7 @@ static void test_ui_util_position_right_top(void** state)
mock_component_1->position.left = 0;
mock_component_1->position.top = 0;
- component_t* mock_component_2 = mock_component_create();
+ component_t* mock_component_2 = fake_component_create();
mock_component_2->dimension.width = 10;
mock_component_2->dimension.height = 10;
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.