Delete mock_include, rely on the speculos_bridge for all tests
What changed, and why it matters
This commit is a test-only refactoring: it removes a set of local mock SDK headers and a software SHA-256 implementation used by unit tests, and instead makes those tests run against the real Ledger SDK headers through the existing Speculos emulator bridge. No production application code is changed, and there is no indication this fixes or introduces a security vulnerability.
No security action required. Treat as normal maintenance; verify CI still passes with Speculos enabled.
Security signals we found
No production code changes
Test infrastructure refactoring only
Removal of local cryptographic mock in favor of real SDK/speculos bridge
No bug fixes, bounds checks, or input validation changes visible
Evidence from the diff
The change deletes the unit-tests/mock_includes/ directory (local stubs for cx.h, lcx_*.h, os.h, ledger_assert.h) and the unit-tests/libs/sha-256.c reference implementation plus cx_hash_mock.c wrapper. It updates CMakeLists.txt so the previously ‘non-speculos’ merkle/handler tests are now built only when Speculos is available, linking them against app_crypto (real app code compiled with real BOLOS SDK headers) and the speculos_bridge. Helper files mock_dispatcher.c and xpub.c are switched from the deleted sha-256.c to the real cx_hash_sha256. The diff is entirely within the unit-tests/ tree; no ../src/ production logic is modified.
Changed components
unit-tests/CMakeLists.txtunit-tests/libs/mock_dispatcher.cunit-tests/libs/xpub.cunit-tests/mock_includes/*unit-tests/libs/cx_hash_mock.cunit-tests/libs/sha-256.cInspect captured patch +79 / −3525
diff --git a/unit-tests/CMakeLists.txt b/unit-tests/CMakeLists.txt
index 0627846..107db93 100644
--- a/unit-tests/CMakeLists.txt
+++ b/unit-tests/CMakeLists.txt
@@ -76,7 +76,6 @@ add_compile_definitions(TEST DEBUG=0 PRINTF=printf COIN_NATIVE_SEGWIT_PREFIX=\"t
include_directories(../src)
include_directories(../src/debug-helpers)
include_directories(../src/boilerplate)
-include_directories(mock_includes)
include_directories(libs)
include_directories($ENV{BOLOS_SDK})
include_directories($ENV{BOLOS_SDK}/include)
@@ -86,18 +85,9 @@ include_directories($ENV{BOLOS_SDK}/lib_standard_app)
set(HANDLER_INCLUDES ../src/handler ../src/handler/lib ../src/common)
# ---------------------------------------------------------------------------
-# Mock libraries
+# Mock libraries (no-crypto, available to all tests)
# ---------------------------------------------------------------------------
-add_library(sha256 SHARED libs/sha-256.c)
-add_library(cx_hash_mock SHARED libs/cx_hash_mock.c)
-add_library(mock_dispatcher SHARED libs/mock_dispatcher.c)
-add_library(psbt_parse SHARED libs/psbt_parse.c)
-add_library(xpub SHARED libs/xpub.c)
-
-target_include_directories(mock_dispatcher PRIVATE ${HANDLER_INCLUDES})
-
-target_link_libraries(cx_hash_mock PUBLIC sha256)
-target_link_libraries(mock_dispatcher PUBLIC psbt_parse)
+add_library(psbt_parse SHARED libs/psbt_parse.c)
# Vendored TOML parser (cktan/tomlc17, MIT). Used by the data-driven
# unit tests that load test vectors from a .toml file.
@@ -110,64 +100,23 @@ target_compile_options(tomlc17 PRIVATE -w)
# ---------------------------------------------------------------------------
# App libraries (built standalone for the non-speculos tests)
# ---------------------------------------------------------------------------
-add_library(base58 SHARED $ENV{BOLOS_SDK}/lib_standard_app/base58.c)
-add_library(bip32 SHARED $ENV{BOLOS_SDK}/lib_standard_app/bip32.c)
-add_library(buffer SHARED $ENV{BOLOS_SDK}/lib_standard_app/buffer.c)
-add_library(read SHARED $ENV{BOLOS_SDK}/lib_standard_app/read.c)
-add_library(varint SHARED $ENV{BOLOS_SDK}/lib_standard_app/varint.c)
-add_library(write SHARED $ENV{BOLOS_SDK}/lib_standard_app/write.c)
-add_library(buffer_ext SHARED ../src/common/buffer_ext.c)
-add_library(merkle SHARED ../src/common/merkle.c)
-add_library(parser SHARED ../src/common/parser_ext.c)
-add_library(display_utils SHARED ../src/ui/display_utils.c)
-add_library(extract_bip32_derivation SHARED ../src/handler/sign_psbt/extract_bip32_derivation.c)
-add_library(check_merkle_tree_sorted SHARED ../src/handler/lib/check_merkle_tree_sorted.c)
-add_library(get_merkle_leaf_element SHARED ../src/handler/lib/get_merkle_leaf_element.c)
-add_library(get_merkle_leaf_hash SHARED ../src/handler/lib/get_merkle_leaf_hash.c)
-add_library(get_merkle_leaf_index SHARED ../src/handler/lib/get_merkle_leaf_index.c)
-add_library(get_merkle_preimage SHARED ../src/handler/lib/get_merkle_preimage.c)
-add_library(get_merkleized_map SHARED ../src/handler/lib/get_merkleized_map.c)
-add_library(get_merkleized_map_value SHARED ../src/handler/lib/get_merkleized_map_value.c)
-add_library(get_preimage SHARED ../src/handler/lib/get_preimage.c)
-add_library(stream_merkle_leaf_element SHARED ../src/handler/lib/stream_merkle_leaf_element.c)
-add_library(stream_merkleized_map_value SHARED ../src/handler/lib/stream_merkleized_map_value.c)
-add_library(stream_preimage SHARED ../src/handler/lib/stream_preimage.c)
-
-target_include_directories(check_merkle_tree_sorted PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(extract_bip32_derivation PRIVATE ${HANDLER_INCLUDES} ../src/handler/sign_psbt)
-target_include_directories(get_merkle_leaf_element PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(get_merkle_leaf_hash PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(get_merkle_leaf_index PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(get_merkle_preimage PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(get_merkleized_map PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(get_merkleized_map_value PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(get_preimage PRIVATE ../src/handler ../src/handler/lib)
-target_include_directories(stream_merkle_leaf_element PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(stream_merkleized_map_value PRIVATE ${HANDLER_INCLUDES})
-target_include_directories(stream_preimage PRIVATE ../src/handler ../src/handler/lib)
-
-target_link_libraries(get_merkle_leaf_index PUBLIC get_merkle_leaf_hash)
-target_link_libraries(xpub PUBLIC base58 sha256)
+add_library(base58 SHARED $ENV{BOLOS_SDK}/lib_standard_app/base58.c)
+add_library(bip32 SHARED $ENV{BOLOS_SDK}/lib_standard_app/bip32.c)
+add_library(buffer SHARED $ENV{BOLOS_SDK}/lib_standard_app/buffer.c)
+add_library(read SHARED $ENV{BOLOS_SDK}/lib_standard_app/read.c)
+add_library(varint SHARED $ENV{BOLOS_SDK}/lib_standard_app/varint.c)
+add_library(write SHARED $ENV{BOLOS_SDK}/lib_standard_app/write.c)
+add_library(buffer_ext SHARED ../src/common/buffer_ext.c)
+add_library(parser SHARED ../src/common/parser_ext.c)
+add_library(display_utils SHARED ../src/ui/display_utils.c)
# ---------------------------------------------------------------------------
# Test executables (non-speculos)
# ---------------------------------------------------------------------------
-# Common dependency bundles, exposed as INTERFACE libraries so each test
-# only has to list its own extras.
-
# Bare minimum every cmocka-based test needs.
add_library(test_common INTERFACE)
target_link_libraries(test_common INTERFACE cmocka)
-# Adds the mock dispatcher + SDK helpers needed by every handler/merkle
-# test. mock_dispatcher transitively pulls in psbt_parse.
-add_library(test_merkle_common INTERFACE)
-target_link_libraries(test_merkle_common INTERFACE
- test_common
- mock_dispatcher cx_hash_mock sha256
- buffer buffer_ext varint read write bip32 merkle)
-target_include_directories(test_merkle_common INTERFACE ${HANDLER_INCLUDES})
-
function(add_unit_test name)
cmake_parse_arguments(T "" "" "LIBS;INCLUDES" ${ARGN})
add_executable(${name} ${name}.c)
@@ -184,33 +133,6 @@ add_unit_test(test_display_utils LIBS test_common display_utils)
add_unit_test(test_parser LIBS test_common parser buffer buffer_ext varint read write bip32)
add_unit_test(test_psbt_parse LIBS test_common psbt_parse)
-add_unit_test(test_get_preimage
- LIBS test_merkle_common get_preimage
- INCLUDES ../src/handler ../src/handler/lib)
-add_unit_test(test_get_merkle_preimage
- LIBS test_merkle_common get_merkle_preimage)
-add_unit_test(test_extract_bip32_derivation
- LIBS test_merkle_common extract_bip32_derivation stream_merkle_leaf_element get_merkle_leaf_hash stream_preimage
- INCLUDES ${HANDLER_INCLUDES} ../src/handler/sign_psbt)
-add_unit_test(test_check_merkle_tree_sorted
- LIBS test_merkle_common check_merkle_tree_sorted get_merkle_leaf_element get_merkle_leaf_hash get_merkle_preimage stream_preimage)
-add_unit_test(test_get_merkle_leaf_element
- LIBS test_merkle_common get_merkle_leaf_element get_merkle_leaf_hash get_merkle_preimage stream_preimage)
-add_unit_test(test_get_merkle_leaf_hash
- LIBS test_merkle_common get_merkle_leaf_hash stream_preimage)
-add_unit_test(test_get_merkle_leaf_index
- LIBS test_merkle_common get_merkle_leaf_hash get_merkle_leaf_index stream_preimage)
-add_unit_test(test_stream_preimage
- LIBS test_merkle_common stream_preimage)
-add_unit_test(test_stream_merkle_leaf_element
- LIBS test_merkle_common stream_merkle_leaf_element get_merkle_leaf_hash stream_preimage)
-add_unit_test(test_stream_merkleized_map_value
- LIBS test_merkle_common stream_merkleized_map_value stream_merkle_leaf_element get_merkle_leaf_hash get_merkle_leaf_index stream_preimage)
-add_unit_test(test_get_merkleized_map
- LIBS test_merkle_common get_merkleized_map check_merkle_tree_sorted get_merkle_leaf_element get_merkle_leaf_hash get_merkle_preimage stream_preimage)
-add_unit_test(test_get_merkleized_map_value
- LIBS test_merkle_common get_merkleized_map_value get_merkle_leaf_element get_merkle_leaf_hash get_merkle_leaf_index get_merkle_preimage stream_preimage)
-
# ---------------------------------------------------------------------------
# Speculos-backed crypto tests
# ---------------------------------------------------------------------------
@@ -283,16 +205,10 @@ if(SPECULOS AND SPECULOS_SRC)
)
target_link_libraries(speculos_bridge PUBLIC speculos_bolos OpenSSL::Crypto)
- # Build the application code against the real SDK headers (not the
- # per-test mock_includes) so it sees the same syscall signatures the
- # speculos bridge implements. crypto.c can now be compiled this way,
- # which removes the need to mock it for tests that depend on it.
- # Compile flags shared between app_crypto and any test that needs to
- # see the real SDK declarations (so e.g. sizeof(cx_sha256_t) matches
- # the size app_crypto was built against, not the mock_includes one).
- #
- # The include paths are added with BEFORE PRIVATE so they take
- # precedence over the mock_includes added at global scope above.
+ # Build the application code against the real SDK headers so it sees the
+ # same syscall signatures the speculos bridge implements. The include
+ # paths are added with BEFORE PRIVATE so they take precedence over the
+ # global paths set above.
function(app_apply_real_sdk_config target)
target_compile_definitions(${target} PRIVATE
HAVE_HASH HAVE_RIPEMD160 HAVE_SHA256 HAVE_SHA512 HAVE_HMAC HAVE_MATH
@@ -331,11 +247,18 @@ if(SPECULOS AND SPECULOS_SRC)
../src/common/segwit_addr.c
../src/common/merkle.c
../src/handler/lib/policy.c
+ ../src/handler/lib/check_merkle_tree_sorted.c
../src/handler/lib/get_merkle_leaf_element.c
../src/handler/lib/get_merkle_leaf_hash.c
+ ../src/handler/lib/get_merkle_leaf_index.c
../src/handler/lib/get_merkle_preimage.c
- ../src/handler/lib/stream_preimage.c
+ ../src/handler/lib/get_merkleized_map.c
+ ../src/handler/lib/get_merkleized_map_value.c
../src/handler/lib/get_preimage.c
+ ../src/handler/lib/stream_merkle_leaf_element.c
+ ../src/handler/lib/stream_merkleized_map_value.c
+ ../src/handler/lib/stream_preimage.c
+ ../src/handler/sign_psbt/extract_bip32_derivation.c
../src/handler/sign_psbt/sign_psbt_cache.c
../src/musig/musig.c
$ENV{BOLOS_SDK}/lib_standard_app/crypto_helpers.c
@@ -349,6 +272,47 @@ if(SPECULOS AND SPECULOS_SRC)
base58 bip32 read write varint
)
+ # mock_dispatcher and xpub need real SDK headers (cx_hash_sha256, crypto.h)
+ # and are only used in the speculos-backed tests.
+ add_library(mock_dispatcher STATIC libs/mock_dispatcher.c)
+ app_apply_real_sdk_config(mock_dispatcher)
+ target_link_libraries(mock_dispatcher PUBLIC psbt_parse)
+
+ add_library(xpub STATIC libs/xpub.c)
+ app_apply_real_sdk_config(xpub)
+ target_link_libraries(xpub PUBLIC base58)
+
+ # Shared dependency bundle for all speculos-backed merkle/handler tests.
+ # mock_dispatcher must come before app_crypto so its unresolved refs to
+ # merkle_combine_hashes etc. are resolved from app_crypto.a by the linker.
+ add_library(test_merkle_common INTERFACE)
+ target_link_libraries(test_merkle_common INTERFACE
+ cmocka
+ mock_dispatcher app_crypto
+ buffer buffer_ext varint read write bip32)
+
+ add_unit_test(test_get_preimage LIBS test_merkle_common)
+ add_unit_test(test_get_merkle_preimage LIBS test_merkle_common)
+ add_unit_test(test_extract_bip32_derivation LIBS test_merkle_common)
+ add_unit_test(test_check_merkle_tree_sorted LIBS test_merkle_common)
+ add_unit_test(test_get_merkle_leaf_element LIBS test_merkle_common)
+ add_unit_test(test_get_merkle_leaf_hash LIBS test_merkle_common)
+ add_unit_test(test_get_merkle_leaf_index LIBS test_merkle_common)
+ add_unit_test(test_stream_preimage LIBS test_merkle_common)
+ add_unit_test(test_stream_merkle_leaf_element LIBS test_merkle_common)
+ add_unit_test(test_stream_merkleized_map_value LIBS test_merkle_common)
+ add_unit_test(test_get_merkleized_map LIBS test_merkle_common)
+ add_unit_test(test_get_merkleized_map_value LIBS test_merkle_common)
+
+ foreach(t
+ test_get_preimage test_get_merkle_preimage test_extract_bip32_derivation
+ test_check_merkle_tree_sorted test_get_merkle_leaf_element
+ test_get_merkle_leaf_hash test_get_merkle_leaf_index test_stream_preimage
+ test_stream_merkle_leaf_element test_stream_merkleized_map_value
+ test_get_merkleized_map test_get_merkleized_map_value)
+ app_apply_real_sdk_config(${t})
+ endforeach()
+
add_executable(test_crypto test_crypto.c)
# Compile the test against the real SDK headers too, so that types
# exposed by crypto.h (e.g. cx_sha256_t) have the same layout the
@@ -358,10 +322,12 @@ if(SPECULOS AND SPECULOS_SRC)
add_test(test_crypto test_crypto)
add_executable(test_script test_script.c)
+ app_apply_real_sdk_config(test_script)
target_link_libraries(test_script PRIVATE cmocka app_crypto)
add_test(test_script test_script)
add_executable(test_wallet test_wallet.c)
+ app_apply_real_sdk_config(test_wallet)
target_link_libraries(test_wallet PRIVATE cmocka app_crypto buffer buffer_ext)
add_test(test_wallet test_wallet)
@@ -369,14 +335,12 @@ if(SPECULOS AND SPECULOS_SRC)
# end-to-end against a mock dispatcher; vectors come from a separate
# TOML file (see test_get_wallet_address_vectors.toml).
add_executable(test_get_wallet_address test_get_wallet_address.c)
- target_include_directories(test_get_wallet_address PRIVATE
- ../src/common ../src/handler ../src/handler/lib ../src/handler/sign_psbt
- )
+ app_apply_real_sdk_config(test_get_wallet_address)
target_compile_definitions(test_get_wallet_address PRIVATE
TEST_VECTORS_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/test_get_wallet_address_vectors.toml\"
)
target_link_libraries(test_get_wallet_address PRIVATE
- cmocka app_crypto mock_dispatcher buffer buffer_ext sha256 tomlc17
+ cmocka mock_dispatcher app_crypto buffer buffer_ext tomlc17
)
add_test(test_get_wallet_address test_get_wallet_address)
endif()
diff --git a/unit-tests/libs/cx_hash_mock.c b/unit-tests/libs/cx_hash_mock.c
deleted file mode 100644
index 3a06782..0000000
--- a/unit-tests/libs/cx_hash_mock.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * Mock implementation of Ledger SDK cx_hash / cx_sha256 functions,
- * wrapping the reference SHA-256 library (sha-256.c).
- *
- * Since `struct Sha_256` does not fit inside `cx_sha256_t`, we use a
- * static pool of contexts and store the pool index in `cx_sha256_t.blen`.
- */
-
-#include <string.h>
-#include <assert.h>
-
-#include "cx_hash_mock.h"
-#include "sha-256.h"
-
-/* Pool of streaming SHA-256 contexts for the mock */
-#define MAX_HASH_CONTEXTS 32
-static struct Sha_256 g_sha256_pool[MAX_HASH_CONTEXTS];
-static uint8_t g_sha256_hash_out[MAX_HASH_CONTEXTS][32];
-int g_sha256_pool_next = 0;
-
-/**
- * Map a cx_sha256_t to its pool index. We store the index in `blen`.
- */
-static struct Sha_256 *get_sha256_ctx(cx_sha256_t *hash) {
- unsigned int idx = hash->blen;
- assert(idx < MAX_HASH_CONTEXTS);
- return &g_sha256_pool[idx];
-}
-
-int cx_sha256_init(cx_sha256_t *hash) {
- memset(hash, 0, sizeof(cx_sha256_t));
- hash->header.algo = CX_SHA256;
- hash->header.counter = 0;
-
- /* Allocate a pool slot */
- assert(g_sha256_pool_next < MAX_HASH_CONTEXTS);
- int idx = g_sha256_pool_next++;
- hash->blen = (unsigned int) idx;
-
- sha_256_init(&g_sha256_pool[idx], g_sha256_hash_out[idx]);
- return CX_SHA256;
-}
-
-int cx_hash_no_throw(cx_hash_t *hash,
- int mode,
- const unsigned char *in,
- unsigned int in_len,
- unsigned char *out,
- unsigned int out_len) {
- /* We only support SHA-256 in this mock */
- assert(hash->algo == CX_SHA256);
-
- cx_sha256_t *sha = (cx_sha256_t *) hash;
- struct Sha_256 *ctx = get_sha256_ctx(sha);
-
- if (in != NULL && in_len > 0) {
- sha_256_write(ctx, in, in_len);
- }
-
- if (mode & CX_LAST) {
- uint8_t *result = sha_256_close(ctx);
- if (out != NULL && out_len >= 32) {
- memcpy(out, result, 32);
- }
- }
-
- return 0;
-}
-
-int cx_hash_sha256(const unsigned char *in,
- unsigned int in_len,
- unsigned char *out,
- unsigned int out_len) {
- assert(out != NULL);
- assert(out_len >= CX_SHA256_SIZE);
- calc_sha_256(out, in, in_len);
- return CX_SHA256_SIZE;
-}
-
-int cx_sha256_hash_iovec(const cx_iovec_t *iovec, size_t iovec_count, uint8_t out[32]) {
- /* Use a temporary streaming context */
- struct Sha_256 ctx;
- uint8_t hash_buf[32];
- sha_256_init(&ctx, hash_buf);
-
- for (size_t i = 0; i < iovec_count; i++) {
- if (iovec[i].iov_base != NULL && iovec[i].iov_len > 0) {
- sha_256_write(&ctx, iovec[i].iov_base, iovec[i].iov_len);
- }
- }
-
- sha_256_close(&ctx);
- memcpy(out, hash_buf, 32);
- return 0;
-}
diff --git a/unit-tests/libs/cx_hash_mock.h b/unit-tests/libs/cx_hash_mock.h
deleted file mode 100644
index 07dea73..0000000
--- a/unit-tests/libs/cx_hash_mock.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#pragma once
-
-/**
- * Mock implementation of the Ledger SDK cx_hash / cx_sha256 functions,
- * backed by the reference SHA-256 library (sha-256.c from amosnier/sha-2).
- *
- * Provides:
- * - cx_sha256_init
- * - cx_hash_no_throw (update / finalize)
- * - cx_hash_sha256 (one-shot)
- * - cx_sha256_hash_iovec
- *
- * The function prototypes are already declared in the mock SDK headers
- * (lcx_hash.h / lcx_sha256.h). This header just needs to be included
- * in the mock .c file; test files should include the SDK headers via
- * cx.h or directly.
- */
-
-#include <stdint.h>
-#include <stddef.h>
-
-#include "os.h"
-#include "cx.h"
diff --git a/unit-tests/libs/mock_dispatcher.c b/unit-tests/libs/mock_dispatcher.c
index c345a28..ccb0c75 100644
--- a/unit-tests/libs/mock_dispatcher.c
+++ b/unit-tests/libs/mock_dispatcher.c
@@ -11,8 +11,7 @@
#include <stdio.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
+#include "cx.h"
#include "buffer.h"
#include "varint.h"
@@ -22,12 +21,9 @@
/* ---- Global pointer to active mock (needed for function-pointer callbacks) ---- */
static mock_dispatcher_t *g_active_mock = NULL;
-/* ---- External: reset the cx_hash_mock pool ---- */
-extern int g_sha256_pool_next;
-
/* ---- Helper: compute SHA-256 of a buffer ---- */
static void mock_sha256(const uint8_t *data, size_t len, uint8_t out[32]) {
- calc_sha_256(out, data, len);
+ cx_hash_sha256(data, len, out, 32);
}
/* ===========================================================================
@@ -433,9 +429,6 @@ void mock_dispatcher_init(mock_dispatcher_t *mock) {
/* Set global pointer so callbacks can find us */
g_active_mock = mock;
-
- /* Reset the cx_hash_mock pool so each test starts from a clean slate. */
- g_sha256_pool_next = 0;
}
int mock_dispatcher_setup(void **state) {
diff --git a/unit-tests/libs/mock_dispatcher.h b/unit-tests/libs/mock_dispatcher.h
index 502bd5b..ce39429 100644
--- a/unit-tests/libs/mock_dispatcher.h
+++ b/unit-tests/libs/mock_dispatcher.h
@@ -135,9 +135,8 @@ typedef struct {
/* ---- Public API ---- */
/**
- * Initialize a mock dispatcher. Zero-initializes all state, wires up
- * the function pointers in mock->dc, and resets the cx_hash_mock pool so
- * tests start from a clean slate.
+ * Initialize a mock dispatcher. Zero-initializes all state and wires up
+ * the function pointers in mock->dc.
*/
void mock_dispatcher_init(mock_dispatcher_t *mock);
diff --git a/unit-tests/libs/sha-256.c b/unit-tests/libs/sha-256.c
deleted file mode 100644
index 3ae891b..0000000
--- a/unit-tests/libs/sha-256.c
+++ /dev/null
@@ -1,224 +0,0 @@
-// from https://github.com/amosnier/sha-2/blob/0be5e1601b487b2aa6869e2fe12bd30ac2ca543c/sha-256.c
-
-#include "sha-256.h"
-
-#define TOTAL_LEN_LEN 8
-
-/*
- * Comments from pseudo-code at https://en.wikipedia.org/wiki/SHA-2 are reproduced here.
- * When useful for clarification, portions of the pseudo-code are reproduced here too.
- */
-
-/*
- * @brief Rotate a 32-bit value by a number of bits to the right.
- * @param value The value to be rotated.
- * @param count The number of bits to rotate by.
- * @return The rotated value.
- */
-static inline uint32_t right_rot(uint32_t value, unsigned int count)
-{
- /*
- * Defined behaviour in standard C for all count where 0 < count < 32, which is what we need here.
- */
- return value >> count | value << (32 - count);
-}
-
-/*
- * @brief Update a hash value under calculation with a new chunk of data.
- * @param h Pointer to the first hash item, of a total of eight.
- * @param p Pointer to the chunk data, which has a standard length.
- *
- * @note This is the SHA-256 work horse.
- */
-static inline void consume_chunk(uint32_t *h, const uint8_t *p)
-{
- unsigned i, j;
- uint32_t ah[8];
-
- /* Initialize working variables to current hash value: */
- for (i = 0; i < 8; i++)
- ah[i] = h[i];
-
- /*
- * The w-array is really w[64], but since we only need 16 of them at a time, we save stack by
- * calculating 16 at a time.
- *
- * This optimization was not there initially and the rest of the comments about w[64] are kept in their
- * initial state.
- */
-
- /*
- * create a 64-entry message schedule array w[0..63] of 32-bit words (The initial values in w[0..63]
- * don't matter, so many implementations zero them here) copy chunk into first 16 words w[0..15] of the
- * message schedule array
- */
- uint32_t w[16];
-
- /* Compression function main loop: */
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 16; j++) {
- if (i == 0) {
- w[j] =
- (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | (uint32_t)p[3];
- p += 4;
- } else {
- /* Extend the first 16 words into the remaining 48 words w[16..63] of the
- * message schedule array: */
- const uint32_t s0 = right_rot(w[(j + 1) & 0xf], 7) ^ right_rot(w[(j + 1) & 0xf], 18) ^
- (w[(j + 1) & 0xf] >> 3);
- const uint32_t s1 = right_rot(w[(j + 14) & 0xf], 17) ^
- right_rot(w[(j + 14) & 0xf], 19) ^ (w[(j + 14) & 0xf] >> 10);
- w[j] = w[j] + s0 + w[(j + 9) & 0xf] + s1;
- }
- const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25);
- const uint32_t ch = (ah[4] & ah[5]) ^ (~ah[4] & ah[6]);
-
- /*
- * Initialize array of round constants:
- * (first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311):
- */
- static const uint32_t k[] = {
- 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4,
- 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe,
- 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f,
- 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
- 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc,
- 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
- 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116,
- 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
- 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7,
- 0xc67178f2};
-
- const uint32_t temp1 = ah[7] + s1 + ch + k[i << 4 | j] + w[j];
- const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22);
- const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]);
- const uint32_t temp2 = s0 + maj;
-
- ah[7] = ah[6];
- ah[6] = ah[5];
- ah[5] = ah[4];
- ah[4] = ah[3] + temp1;
- ah[3] = ah[2];
- ah[2] = ah[1];
- ah[1] = ah[0];
- ah[0] = temp1 + temp2;
- }
- }
-
- /* Add the compressed chunk to the current hash value: */
- for (i = 0; i < 8; i++)
- h[i] += ah[i];
-}
-
-/*
- * Public functions. See header file for documentation.
- */
-
-void sha_256_init(struct Sha_256 *sha_256, uint8_t hash[SIZE_OF_SHA_256_HASH])
-{
- sha_256->hash = hash;
- sha_256->chunk_pos = sha_256->chunk;
- sha_256->space_left = SIZE_OF_SHA_256_CHUNK;
- sha_256->total_len = 0;
- /*
- * Initialize hash values (first 32 bits of the fractional parts of the square roots of the first 8 primes
- * 2..19):
- */
- sha_256->h[0] = 0x6a09e667;
- sha_256->h[1] = 0xbb67ae85;
- sha_256->h[2] = 0x3c6ef372;
- sha_256->h[3] = 0xa54ff53a;
- sha_256->h[4] = 0x510e527f;
- sha_256->h[5] = 0x9b05688c;
- sha_256->h[6] = 0x1f83d9ab;
- sha_256->h[7] = 0x5be0cd19;
-}
-
-void sha_256_write(struct Sha_256 *sha_256, const void *data, size_t len)
-{
- sha_256->total_len += len;
-
- const uint8_t *p = data;
-
- while (len > 0) {
- /*
- * If the input chunks have sizes that are multiples of the calculation chunk size, no copies are
- * necessary. We operate directly on the input data instead.
- */
- if (sha_256->space_left == SIZE_OF_SHA_256_CHUNK && len >= SIZE_OF_SHA_256_CHUNK) {
- consume_chunk(sha_256->h, p);
- len -= SIZE_OF_SHA_256_CHUNK;
- p += SIZE_OF_SHA_256_CHUNK;
- continue;
- }
- /* General case, no particular optimization. */
- const size_t consumed_len = len < sha_256->space_left ? len : sha_256->space_left;
- memcpy(sha_256->chunk_pos, p, consumed_len);
- sha_256->space_left -= consumed_len;
- len -= consumed_len;
- p += consumed_len;
- if (sha_256->space_left == 0) {
- consume_chunk(sha_256->h, sha_256->chunk);
- sha_256->chunk_pos = sha_256->chunk;
- sha_256->space_left = SIZE_OF_SHA_256_CHUNK;
- } else {
- sha_256->chunk_pos += consumed_len;
- }
- }
-}
-
-uint8_t *sha_256_close(struct Sha_256 *sha_256)
-{
- uint8_t *pos = sha_256->chunk_pos;
- size_t space_left = sha_256->space_left;
- uint32_t *const h = sha_256->h;
-
- /*
- * The current chunk cannot be full. Otherwise, it would already have been consumed. I.e. there is space left for
- * at least one byte. The next step in the calculation is to add a single one-bit to the data.
- */
- *pos++ = 0x80;
- --space_left;
-
- /*
- * Now, the last step is to add the total data length at the end of the last chunk, and zero padding before
- * that. But we do not necessarily have enough space left. If not, we pad the current chunk with zeroes, and add
- * an extra chunk at the end.
- */
- if (space_left < TOTAL_LEN_LEN) {
- memset(pos, 0x00, space_left);
- consume_chunk(h, sha_256->chunk);
- pos = sha_256->chunk;
- space_left = SIZE_OF_SHA_256_CHUNK;
- }
- const size_t left = space_left - TOTAL_LEN_LEN;
- memset(pos, 0x00, left);
- pos += left;
- size_t len = sha_256->total_len;
- pos[7] = (uint8_t)(len << 3);
- len >>= 5;
- int i;
- for (i = 6; i >= 0; --i) {
- pos[i] = (uint8_t)len;
- len >>= 8;
- }
- consume_chunk(h, sha_256->chunk);
- /* Produce the final hash value (big-endian): */
- int j;
- uint8_t *const hash = sha_256->hash;
- for (i = 0, j = 0; i < 8; i++) {
- hash[j++] = (uint8_t)(h[i] >> 24);
- hash[j++] = (uint8_t)(h[i] >> 16);
- hash[j++] = (uint8_t)(h[i] >> 8);
- hash[j++] = (uint8_t)h[i];
- }
- return sha_256->hash;
-}
-
-void calc_sha_256(uint8_t hash[SIZE_OF_SHA_256_HASH], const void *input, size_t len)
-{
- struct Sha_256 sha_256;
- sha_256_init(&sha_256, hash);
- sha_256_write(&sha_256, input, len);
- (void)sha_256_close(&sha_256);
-}
\ No newline at end of file
diff --git a/unit-tests/libs/sha-256.h b/unit-tests/libs/sha-256.h
deleted file mode 100644
index 2c1c804..0000000
--- a/unit-tests/libs/sha-256.h
+++ /dev/null
@@ -1,105 +0,0 @@
-// from https://github.com/amosnier/sha-2/blob/0be5e1601b487b2aa6869e2fe12bd30ac2ca543c/sha-256.h
-
-#ifndef SHA_256_H
-#define SHA_256_H
-
-#include <stdint.h>
-#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * @brief Size of the SHA-256 sum. This times eight is 256 bits.
- */
-#define SIZE_OF_SHA_256_HASH 32
-
-/*
- * @brief Size of the chunks used for the calculations.
- *
- * @note This should mostly be ignored by the user, although when using the streaming API, it has an impact for
- * performance. Add chunks whose size is a multiple of this, and you will avoid a lot of superfluous copying in RAM!
- */
-#define SIZE_OF_SHA_256_CHUNK 64
-
-/*
- * @brief The opaque SHA-256 type, that should be instantiated when using the streaming API.
- *
- * @note Although the details are exposed here, in order to make instantiation easy, you should refrain from directly
- * accessing the fields, as they may change in the future.
- */
-struct Sha_256 {
- uint8_t *hash;
- uint8_t chunk[SIZE_OF_SHA_256_CHUNK];
- uint8_t *chunk_pos;
- size_t space_left;
- size_t total_len;
- uint32_t h[8];
-};
-
-/*
- * @brief The simple SHA-256 calculation function.
- * @param hash Hash array, where the result is delivered.
- * @param input Pointer to the data the hash shall be calculated on.
- * @param len Length of the input data, in byte.
- *
- * @note If all of the data you are calculating the hash value on is available in a contiguous buffer in memory, this is
- * the function you should use.
- *
- * @note If either of the passed pointers is NULL, the results are unpredictable.
- */
-void calc_sha_256(uint8_t hash[SIZE_OF_SHA_256_HASH], const void *input, size_t len);
-
-/*
- * @brief Initialize a SHA-256 streaming calculation.
- * @param sha_256 A pointer to a SHA-256 structure.
- * @param hash Hash array, where the result will be delivered.
- *
- * @note If all of the data you are calculating the hash value on is not available in a contiguous buffer in memory, this is
- * where you should start. Instantiate a SHA-256 structure, for instance by simply declaring it locally, make your hash
- * buffer available, and invoke this function. Once a SHA-256 hash has been calculated (see further below) a SHA-256
- * structure can be initialized again for the next calculation.
- *
- * @note If either of the passed pointers is NULL, the results are unpredictable.
- */
-void sha_256_init(struct Sha_256 *sha_256, uint8_t hash[SIZE_OF_SHA_256_HASH]);
-
-/*
- * @brief Stream more input data for an on-going SHA-256 calculation.
- * @param sha_256 A pointer to a previously initialized SHA-256 structure.
- * @param data Pointer to the data to be added to the calculation.
- * @param len Length of the data to add, in byte.
- *
- * @note This function may be invoked an arbitrary number of times between initialization and closing, but the maximum
- * data length is limited by the SHA-256 algorithm: the total number of bits (i.e. the total number of bytes times
- * eight) must be representable by a 64-bit unsigned integer. While that is not a practical limitation, the results are
- * unpredictable if that limit is exceeded.
- *
- * @note This function may be invoked on empty data (zero length), although that obviously will not add any data.
- *
- * @note If either of the passed pointers is NULL, the results are unpredictable.
- */
-void sha_256_write(struct Sha_256 *sha_256, const void *data, size_t len);
-
-/*
- * @brief Conclude a SHA-256 streaming calculation, making the hash value available.
- * @param sha_256 A pointer to a previously initialized SHA-256 structure.
- * @return Pointer to the hash array, where the result is delivered.
- *
- * @note After this function has been invoked, the result is available in the hash buffer that initially was provided. A
- * pointer to the hash value is returned for convenience, but you should feel free to ignore it: it is simply a pointer
- * to the first byte of your initially provided hash array.
- *
- * @note If the passed pointer is NULL, the results are unpredictable.
- *
- * @note Invoking this function for a calculation with no data (the writing function has never been invoked, or it only
- * has been invoked with empty data) is legal. It will calculate the SHA-256 value of the empty string.
- */
-uint8_t *sha_256_close(struct Sha_256 *sha_256);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
\ No newline at end of file
diff --git a/unit-tests/libs/xpub.c b/unit-tests/libs/xpub.c
index 5a15e53..a280774 100644
--- a/unit-tests/libs/xpub.c
+++ b/unit-tests/libs/xpub.c
@@ -2,14 +2,13 @@
#include "xpub.h"
#include "base58.h"
-#include "sha-256.h"
#define XPUB_BIN_LEN 78
#define XPUB_FULL_LEN 82 /* 78 payload bytes + 4 checksum bytes */
static void double_sha256(const uint8_t *in, size_t len, uint8_t out[32]) {
- calc_sha_256(out, in, len);
- calc_sha_256(out, out, 32);
+ cx_hash_sha256(in, len, out, 32);
+ cx_hash_sha256(out, 32, out, 32);
}
bool xpub_from_base58(const char *str, serialized_extended_pubkey_t *out) {
diff --git a/unit-tests/mock_includes/cx.h b/unit-tests/mock_includes/cx.h
deleted file mode 100644
index 1b88201..0000000
--- a/unit-tests/mock_includes/cx.h
+++ /dev/null
@@ -1,128 +0,0 @@
-#pragma once
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 CX_H
-#define CX_H
-
-#define CXCALL SYSCALL
-
-#include <stdint.h>
-
-/* ======================================================================= */
-/* CHIP/LIB3rd */
-/* ======================================================================= */
-
-/* ------------------------------ ST NEScrypt ----------------------------- */
-
-/* ======================================================================= */
-/* COMMON */
-
-#include "lcx_common.h"
-
-/* ======================================================================= */
-/* RAND */
-/* ======================================================================= */
-
-// #include "lcx_rng.h"
-
-/* ======================================================================= */
-/* HASH */
-/* ======================================================================= */
-
-#include "lcx_hash.h"
-
-#include "lcx_ripemd160.h"
-
-#include "lcx_sha256.h"
-// #include "lcx_sha3.h"
-// #include "lcx_sha512.h"
-
-// #include "lcx_blake2.h"
-
-// #include "lcx_groestl.h"
-
-/* ======================================================================= */
-/* HASH MAC */
-/* ======================================================================= */
-
-// #include "lcx_hmac.h"
-
-/* ======================================================================= */
-/* PKDF2 */
-/* ======================================================================= */
-
-// #include "lcx_pbkdf2.h"
-
-/* ======================================================================= */
-/* DES */
-/* ======================================================================= */
-
-// #include "lcx_des.h"
-
-/* ====================================================================== */
-/* AES */
-/* ======================================================================= */
-
-// #include "lcx_aes.h"
-
-/* ======================================================================= */
-/* RSA */
-/* ======================================================================= */
-
-// #include "lcx_rsa.h"
-
-/* ======================================================================= */
-/* ECC */
-/* ======================================================================= */
-
-#include "lcx_ecfp.h"
-
-// #include "lcx_ecdsa.h"
-// #include "lcx_ecschnorr.h"
-// #include "lcx_eddsa.h"
-
-/* ======================================================================= */
-/* ECC-KA */
-/* ======================================================================= */
-
-// #include "lcx_ecdh.h"
-
-/* ======================================================================= */
-/* CRC */
-/* ======================================================================= */
-
-// #include "lcx_crc.h"
-
-/* ======================================================================= */
-/* MATH */
-/* ======================================================================= */
-
-// #include "lcx_math.h"
-
-/* ======================================================================= */
-/* DEBUG */
-/* ======================================================================= */
-
-/** @internal
- * @private
- */
-int cx_selftest(void);
-
-#endif // CX_H
-// #include "cx_compliance_141.h"
diff --git a/unit-tests/mock_includes/lcx_common.h b/unit-tests/mock_includes/lcx_common.h
deleted file mode 100644
index 1914a26..0000000
--- a/unit-tests/mock_includes/lcx_common.h
+++ /dev/null
@@ -1,165 +0,0 @@
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 LCX_COMMON_H
-#define LCX_COMMON_H
-
-#include <stdint.h>
-
-#ifndef NATIVE_64BITS // NO 64BITS
-/** 64bits types, native or by-hands, depending on target and/or compiler
- * support.
- * This type is defined here only because sha-3 struct used it INTENALLY.
- * It should never be directly used by other modules.
- */
-struct uint64_s {
-#ifdef OS_LITTLE_ENDIAN
- unsigned long int l;
- unsigned long int h;
-#else
- unsigned long int h;
- unsigned long int l;
-#endif
-};
-typedef struct uint64_s uint64bits_t;
-#else
-typedef uint64_t uint64bits_t;
-#endif
-
-/** Type of error code */
-typedef uint32_t cx_err_t;
-
-/**
- * Some function take logical or of various flags. The follwing flags are
- * globally defined:
- * @rststar
- *
- * +------------+----------------------------+------------------------------------------------------------------+
- * | bit pos | H constant | meanings |
- * +============+============================+==================================================================+
- * | 0 | - CX_LAST | last block |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 2:1 | - CX_ENCRYPT | | | | - CX_DECRYPT |
- * | | | - CX_SIGN | | | | - CX_VERIFY |
- * |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 5:3 | - CX_PAD_NONE | | | | -
- * CX_PAD_ISO9797M1 | | | | - CX_PAD_ISO9797M2 | | |
- * | - CX_PAD_PKCS1_1o5 | | | | - CX_PAD_PKCS1_PSS |
- * | | | - CX_PAD_PKCS1_OAEP | |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 8:6 | - CX_CHAIN_ECB | | | | - CX_CHAIN_CBC
- * | | | -DES
- * | - CX_CHAIN_CTR | | | -AES | - CX_CHAIN_CFB |
- * | | | - CX_CHAIN_OFB | |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 8:6 | - CX_NO_CANONICAL | do not perform canonical sig |
- * | | | | | -ECDSA | | | | -EDDSA |
- * | | |
- * -ECSCHNORR | | |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 11:9 | - CX_RND_TRNG | | | | - CX_RND_PRNG
- * | | | | -
- * CX_RND_RFC6979 | | | | - CX_RND_PROVIDED | |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 14:12 | - CX_ECDH_POINT | share full point | | | -
- * CX_ECDH_X | share only x coordinate | | | -
- * CX_ECSCHNORR_BSI03111 | | | | - CX_ECSCHNORR_ISO14888_XY | | |
- * | - CX_ECSCHNORR_ISO14888_X | | | | -CX_ECSCHNORR_LIBSECP |
- * | | | -CX_ECSCHNORR_Zfrai de port | Zilliqa scheme |
- * +------------+----------------------------+------------------------------------------------------------------+
- * | 15 | CX_NO_REINIT | do not reinitialize context on
- * CX_LAST when supported |
- * +------------+----------------------------+------------------------------------------------------------------+
- *
- * @endrststar
- */
-#define CX_FLAG
-
-/*
- * Bit 0
- */
-#define CX_LAST (1 << 0)
-
-/*
- * Bit 1
- */
-#define CX_SIG_MODE (1 << 1)
-
-/*
- * Bit 2:1
- */
-#define CX_MASK_SIGCRYPT (3 << 1)
-#define CX_ENCRYPT (2 << 1)
-#define CX_DECRYPT (0 << 1)
-#define CX_SIGN (CX_SIG_MODE | CX_ENCRYPT)
-#define CX_VERIFY (CX_SIG_MODE | CX_DECRYPT)
-
-/*
- * Bit 5:3: padding
- */
-#define CX_MASK_PAD (7 << 3)
-#define CX_PAD_NONE (0 << 3)
-#define CX_PAD_ISO9797M1 (1 << 3)
-#define CX_PAD_ISO9797M2 (2 << 3)
-#define CX_PAD_PKCS1_1o5 (3 << 3)
-#define CX_PAD_PKCS1_PSS (4 << 3)
-#define CX_PAD_PKCS1_OAEP (5 << 3)
-
-/*
- * Bit 8:6 DES/AES chaining
- */
-#define CX_MASK_CHAIN (7 << 6)
-#define CX_CHAIN_ECB (0 << 6)
-#define CX_CHAIN_CBC (1 << 6)
-#define CX_CHAIN_CTR (2 << 6)
-#define CX_CHAIN_CFB (3 << 6)
-#define CX_CHAIN_OFB (4 << 6)
-
-/*
- * Bit 8:6 ECC variant
- */
-#define CX_MASK_ECC_VARIANT (7 << 6)
-#define CX_NO_CANONICAL (1 << 6)
-
-/*
- * Bit 11:9
- */
-#define CX_MASK_RND (7 << 9)
-#define CX_RND_PRNG (1 << 9)
-#define CX_RND_TRNG (2 << 9)
-#define CX_RND_RFC6979 (3 << 9)
-#define CX_RND_PROVIDED (4 << 9)
-
-/*
- * Bit 14:12
- */
-#define CX_MASK_EC (7 << 12)
-#define CX_ECDH_POINT (1 << 12)
-#define CX_ECDH_X (2 << 12)
-#define CX_ECSCHNORR_ISO14888_XY (3 << 12)
-#define CX_ECSCHNORR_ISO14888_X (4 << 12)
-#define CX_ECSCHNORR_BSI03111 (5 << 12)
-#define CX_ECSCHNORR_LIBSECP (6 << 12)
-#define CX_ECSCHNORR_Z (7 << 12)
-/*
- * Bit 15
- */
-#define CX_NO_REINIT (1 << 15)
-
-#endif
diff --git a/unit-tests/mock_includes/lcx_ecfp.h b/unit-tests/mock_includes/lcx_ecfp.h
deleted file mode 100644
index c8131c8..0000000
--- a/unit-tests/mock_includes/lcx_ecfp.h
+++ /dev/null
@@ -1,595 +0,0 @@
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 LCX_ECFP_H
-#define LCX_ECFP_H
-
-/**
- *
- */
-#define CX_ECCINFO_PARITY_ODD 1
-#define CX_ECCINFO_xGTn 2
-
-/** List of supported elliptic curves */
-enum cx_curve_e {
- CX_CURVE_NONE,
- /* ------------------------ */
- /* --- Type Weierstrass --- */
- /* ------------------------ */
- /** Low limit (not included) of Weierstrass curve ID */
- CX_CURVE_WEIERSTRASS_START = 0x20,
-
- /** Secp.org */
- CX_CURVE_SECP256K1,
- CX_CURVE_SECP256R1,
-#define CX_CURVE_256K1 CX_CURVE_SECP256K1
-#define CX_CURVE_256R1 CX_CURVE_SECP256R1
- CX_CURVE_SECP384R1,
- CX_CURVE_SECP521R1,
-
- /** BrainPool */
- CX_CURVE_BrainPoolP256T1,
- CX_CURVE_BrainPoolP256R1,
- CX_CURVE_BrainPoolP320T1,
- CX_CURVE_BrainPoolP320R1,
- CX_CURVE_BrainPoolP384T1,
- CX_CURVE_BrainPoolP384R1,
- CX_CURVE_BrainPoolP512T1,
- CX_CURVE_BrainPoolP512R1,
-
-/* NIST P256 curve*/
-#define CX_CURVE_NISTP256 CX_CURVE_SECP256R1
-#define CX_CURVE_NISTP384 CX_CURVE_SECP384R1
-#define CX_CURVE_NISTP521 CX_CURVE_SECP521R1
-
- /* ANSSI P256 */
- CX_CURVE_FRP256V1,
-
- /* STARK */
- CX_CURVE_Stark256,
-
- /* BLS */
- CX_CURVE_BLS12_381_G1,
-
- /** High limit (not included) of Weierstrass curve ID */
- CX_CURVE_WEIERSTRASS_END,
-
- /* --------------------------- */
- /* --- Type Twister Edward --- */
- /* --------------------------- */
- /** Low limit (not included) of Twister Edward curve ID */
- CX_CURVE_TWISTED_EDWARD_START = 0x40,
-
- /** Ed25519 curve */
- CX_CURVE_Ed25519,
- CX_CURVE_Ed448,
-
- CX_CURVE_TWISTED_EDWARD_END,
- /** High limit (not included) of Twister Edward curve ID */
-
- /* ----------------------- */
- /* --- Type Montgomery --- */
- /* ----------------------- */
- /** Low limit (not included) of Montgomery curve ID */
- CX_CURVE_MONTGOMERY_START = 0x60,
-
- /** Curve25519 curve */
- CX_CURVE_Curve25519,
- CX_CURVE_Curve448,
-
- CX_CURVE_MONTGOMERY_END
- /** High limit (not included) of Montgomery curve ID */
-};
-/** Convenience type. See #cx_curve_e. */
-typedef enum cx_curve_e cx_curve_t;
-
-/** Return true if curve type is short weierstrass curve */
-#define CX_CURVE_IS_WEIRSTRASS(c) \
- (((c) > CX_CURVE_WEIERSTRASS_START) && ((c) < CX_CURVE_WEIERSTRASS_END))
-
-/** Return true if curve type is short weierstrass curve */
-#define CX_CURVE_IS_TWISTED_EDWARD(c) \
- (((c) > CX_CURVE_TWISTED_EDWARD_START) && ((c) < CX_CURVE_TWISTED_EDWARD_END))
-
-/** Return true if curve type is short weierstrass curve */
-#define CX_CURVE_IS_MONTGOMERY(c) \
- (((c) > CX_CURVE_MONTGOMERY_START) && ((c) < CX_CURVE_MONTGOMERY_END))
-
-#define CX_CURVE_HEADER \
- /** Curve Identifier. See #cx_curve_e */ \
- cx_curve_t curve; \
- /** Curve size in bits */ \
- unsigned int bit_size; \
- /** component lenth in bytes */ \
- unsigned int length; \
- /** Curve field */ \
- unsigned char WIDE *p; \
- /** @internal 2nd Mongtomery constant for Field */ \
- unsigned char WIDE *Hp; \
- /** Point Generator x coordinate*/ \
- unsigned char WIDE *Gx; \
- /** Point Generator y coordinate*/ \
- unsigned char WIDE *Gy; \
- /** Curve order*/ \
- unsigned char WIDE *n; \
- /** @internal 2nd Mongtomery constant for Curve order*/ \
- unsigned char WIDE *Hn; \
- /** cofactor */ \
- int h
-
-/**
- * Weirstrass curve : y^3=x^2+a*x+b over F(p)
- *
- */
-struct cx_curve_weierstrass_s {
- CX_CURVE_HEADER;
- /** a coef */
- unsigned char WIDE *a;
- /** b coef */
- unsigned char WIDE *b;
-};
-/** Convenience type. See #cx_curve_weierstrass_s. */
-typedef struct cx_curve_weierstrass_s cx_curve_weierstrass_t;
-
-/*
- * Twisted Edward curve : a*x^2+y^2=1+d*x2*y2 over F(q)
- */
-struct cx_curve_twisted_edward_s {
- CX_CURVE_HEADER;
- /** a coef */
- unsigned char WIDE *a;
- /** d coef */
- unsigned char WIDE *d;
- /** @internal Square root of -1 or zero */
- unsigned char WIDE *I;
- /** @internal (q+3)/8 or (q+1)/4*/
- unsigned char WIDE *Qq;
-};
-/** Convenience type. See #cx_curve_twisted_edward_s. */
-typedef struct cx_curve_twisted_edward_s cx_curve_twisted_edward_t;
-
-/*
- * Twisted Edward curve : a*x??+y??=1+d*x??*y?? over F(q)
- */
-struct cx_curve_montgomery_s {
- CX_CURVE_HEADER;
- /** a coef */
- unsigned char WIDE *a;
- /** b coef */
- unsigned char WIDE *b;
- /** @internal (a + 2) / 4*/
- unsigned char WIDE *A24;
- /** @internal (p-1)/2 */
- unsigned char WIDE *P1;
-};
-/** Convenience type. See #cx_curve_montgomery_s. */
-typedef struct cx_curve_montgomery_s cx_curve_montgomery_t;
-
-/** Abstract type for elliptic curve domain */
-struct cx_curve_domain_s {
- CX_CURVE_HEADER;
-};
-/** Convenience type. See #cx_curve_domain_s. */
-typedef struct cx_curve_domain_s cx_curve_domain_t;
-
-/** Retrieve domain parameters
- *
- * @param curve curve ID #cx_curve_e
- *
- * @return curve parameters
- */
-const cx_curve_domain_t WIDE *cx_ecfp_get_domain(cx_curve_t curve);
-
-/** Public Elliptic Curve key */
-struct cx_ecfp_public_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int W_len;
- /** Public key value starting at offset 0 */
- unsigned char W[1];
-};
-/** Private Elliptic Curve key */
-struct cx_ecfp_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[1];
-};
-// temporary typedef for scc check
-typedef struct cx_ecfp_private_key_s __cx_ecfp_private_key_t;
-typedef struct cx_ecfp_public_key_s __cx_ecfp_public_key_t;
-
-/** Up to 256 bits Public Elliptic Curve key */
-struct cx_ecfp_256_public_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int W_len;
- /** Public key value starting at offset 0 */
- unsigned char W[65];
-};
-/** Up to 256 bits Private Elliptic Curve key */
-struct cx_ecfp_256_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[32];
-};
-/** Up to 256 bits Extended Private Elliptic Curve key */
-struct cx_ecfp_256_extended_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[64];
-};
-/** Convenience type. See #cx_ecfp_256_public_key_s. */
-typedef struct cx_ecfp_256_public_key_s cx_ecfp_256_public_key_t;
-/** temporary def type. See #cx_ecfp_256_private_key_s. */
-typedef struct cx_ecfp_256_private_key_s cx_ecfp_256_private_key_t;
-/** Convenience type. See #cx_ecfp_256_extended_private_key_s. */
-typedef struct cx_ecfp_256_extended_private_key_s
- cx_ecfp_256_extended_private_key_t;
-
-/* Do not use those types anymore for declaration, they will become abstract */
-typedef struct cx_ecfp_256_public_key_s cx_ecfp_public_key_t;
-typedef struct cx_ecfp_256_private_key_s cx_ecfp_private_key_t;
-
-/** Up to 384 bits Public Elliptic Curve key */
-struct cx_ecfp_384_public_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int W_len;
- /** Public key value starting at offset 0 */
- unsigned char W[97];
-};
-/** Up to 384 bits Private Elliptic Curve key */
-struct cx_ecfp_384_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[48];
-};
-/** Convenience type. See #cx_ecfp_384_public_key_s. */
-typedef struct cx_ecfp_384_private_key_s cx_ecfp_384_private_key_t;
-/** Convenience type. See #cx_ecfp_384_private_key_s. */
-typedef struct cx_ecfp_384_public_key_s cx_ecfp_384_public_key_t;
-
-/** Up to 512 bits Public Elliptic Curve key */
-struct cx_ecfp_512_public_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int W_len;
- /** Public key value starting at offset 0 */
- unsigned char W[129];
-};
-/** Up to 512 bits Private Elliptic Curve key */
-struct cx_ecfp_512_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[64];
-};
-/** Up to 512 bits Extended Private Elliptic Curve key */
-struct cx_ecfp_512_extented_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[128];
-};
-/** Convenience type. See #cx_ecfp_512_public_key_s. */
-typedef struct cx_ecfp_512_public_key_s cx_ecfp_512_public_key_t;
-/** Convenience type. See #cx_ecfp_512_private_key_s. */
-typedef struct cx_ecfp_512_private_key_s cx_ecfp_512_private_key_t;
-/** Convenience type. See #cx_ecfp_512_extented_private_key_s. */
-typedef struct cx_ecfp_512_extented_private_key_s
- cx_ecfp_512_extented_private_key_t;
-
-/** Up to 640 bits Public Elliptic Curve key */
-struct cx_ecfp_640_public_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int W_len;
- /** Public key value starting at offset 0 */
- unsigned char W[161];
-};
-/** Up to 640 bits Private Elliptic Curve key */
-struct cx_ecfp_640_private_key_s {
- /** curve ID #cx_curve_e */
- cx_curve_t curve;
- /** Public key length in bytes */
- unsigned int d_len;
- /** Public key value starting at offset 0 */
- unsigned char d[80];
-};
-/** Convenience type. See #cx_ecfp_640_public_key_s. */
-typedef struct cx_ecfp_640_public_key_s cx_ecfp_640_public_key_t;
-/** Convenience type. See #cx_ecfp_640_private_key_s. */
-typedef struct cx_ecfp_640_private_key_s cx_ecfp_640_private_key_t;
-
-/**
- * Verify that a given point is really on the specified curve.
- *
- * @param [in] domain
- * The curve domain parameters to work with.
- *
- * @param [in] P
- * The point to test encoded as: 04 x y
- *
- * @return
- * 1 if point is on the curve
- * 0 if point is not on the curve
- * -1 if undefined (function not impl)
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int cx_ecfp_is_valid_point(cx_curve_t curve,
- const unsigned char WIDE *P PLENGTH(P_len),
- unsigned int P_len);
-
-/**
- * Verify that a given point is really on the specified curve and its order
- * is the curve order
- *
- * @param [in] domain
- * The curve domain parameters to work with.
- *
- * @param [in] public_point
- * The point to test encoded as: 04 x y
- *
- * @return
- * 1 if point is on the curve
- * 0 if point is not on the curve
- * -1 if undefined (function not impl)
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int
-cx_ecfp_is_cryptographic_point(cx_curve_t curve,
- const unsigned char WIDE *P PLENGTH(P_len),
- unsigned int P_len);
-
-/**
- * Add two affine point
- *
- * This routine only support Weierstrass and Twisted edward curve.
- *
- * @param [in] domain
- * The curve domain parameters to work with.
- *
- * @param [out] R
- * P+Q encoded as: 04 x y, where x and y are
- * encoded as big endian raw value and have bits length equals to
- * the curve size.
- *
- * @param [in] P
- * First point to add *
- * The value shall be a point encoded as: 04 x y, where x and y are
- * encoded as big endian raw value and have bits length equals to
- * the curve size.
- *
- * @param [in] Q
- * Second point to add
- *
- * @param [in] public_point
- * The point to test encoded as: 04 x y
- *
- * @return
- * R encoding length, if add success
- * 0 if result is infinity
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int cx_ecfp_add_point(cx_curve_t curve, unsigned char *R PLENGTH(X_len),
- const unsigned char WIDE *P PLENGTH(X_len),
- const unsigned char WIDE *Q PLENGTH(X_len),
- unsigned int X_len);
-
-/**
- * Multiply an affine point
- *
- * @param [in] domain
- * The curve domain parameters to work with.
- *
- * @param [out] R
- * R = k.P encoded as: 04 x y, where x and y are
- * encoded as big endian raw value and have bits length equals to
- * the curve size.
- *
- * @param [in] P
- * Point to multiply *
- * The value shall be a point encoded as: 04 x y, where x and y are
- * encoded as big endian raw value and have bits length equals to
- * the curve size.
- *
- * @param [in] k
- * scalar to multiply, encoded as big endian integer
- *
- * @param [in] k_len
- * byte length of scalar to multiply
- *
- * @return
- * R encoding length, if mult success
- * 0 if result is infinity
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int cx_ecfp_scalar_mult(cx_curve_t curve,
- unsigned char *P PLENGTH(P_len),
- unsigned int P_len,
- const unsigned char WIDE *k PLENGTH(k_len),
- unsigned int k_len);
-
-/**
- * Initialize a public ECFP Key.
- * Once initialized, the key may be stored in non-volatile memory
- * an reused 'as-is' for any ECDSA/25519 processing
- * Passing NULL as raw key initializes the key without value. The key may be
- used
- * as parameter for cx_ecfp_generate_pair.
-
- * @param [in] curve
- * The curve domain parameters to work with.
- *
- * @param [in] rawkey
- * Raw key value or NULL.
- * The value shall be the public point encoded as:
- * - '04 x y' for Weiertrass curve
- * - '04 x y' or '02 y' (plus sign) for twisted Edward curves
- * - '04 x y' or '02 x' for Montgomery curves
- * where x and y are encoded as big endian raw value and have bits length
- * equals to the curve size. Any specific integer decoding from binary,
- * such as specified in RFC7748 and RFC eddsa-draft, is up to caller.
- *
- * @param [in] key_len
- * Key bytes lenght
- *
- * @param [out] key
- * Public ecfp key to init.
- *
- * @param key
- * Ready to use key to init
- *
- * @return something
- *
- * @throws INVALID_PARAMETER
- */
-
-CXCALL int cx_ecfp_init_public_key(
- cx_curve_t curve, const unsigned char WIDE *rawkey PLENGTH(key_len),
- unsigned int key_len,
- cx_ecfp_public_key_t *key
- PLENGTH(scc__cx_scc_struct_size_ecfp_pubkey_from_curve__curve));
-
-/**
- * Initialize a private ECFP Key.
- * Once initialized, the key may be stored in non-volatile memory
- * and reused 'as-is' for any ECDSA/EC25519 processing
- * Passing NULL as raw key initializes the key without value. The key may be
- * used as parameter for cx_ecfp_generate_pair.
- *
- * @param [in] curve
- * The curve domain parameters to work with.
- *
- * @param [in] rawkey
- * Raw key value or NULL.
- * The value shall be the private key big endian raw value.
- *
- * @param [in] key_len
- * Key bytes lenght
- *
- * @param [out] pvkey
- * Private ecfp key to init.
- *
- * @param key
- * Ready to use key to init
- *
- * @return something
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int cx_ecfp_init_private_key(
- cx_curve_t curve, const unsigned char WIDE *rawkey PLENGTH(key_len),
- unsigned int key_len,
- cx_ecfp_private_key_t *pvkey
- PLENGTH(scc__cx_scc_struct_size_ecfp_privkey_from_curve__curve));
-
-/**
- * Generate a ecfp key pair.
- * This function call cx_ecfp_generate_pair2 with hashID equals to CX_SHA512.
- *
- * @param [in] curve
- * The curve domain parameters to work with.
- *
- * @param [out] pubkey
- * A public ecfp public key to generate.
- *
- * @param [in,out] privkey
- * A private ecfp private key to generate.
- * Either:
- * - if the private ecfp key is fully inited, i.e parameter 'rawkey' of
- * 'cx_ecfp_init_private_key' is NOT null, the private key value is kept
- * if the 'keep_private' parameter is non zero
- * - else a new private key is generated.
- *
- * @param [in] keepprivate if set to non zero, keep the private key value if
- * set. Else generate a new random one
- *
- * @return zero
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int cx_ecfp_generate_pair(
- cx_curve_t curve,
- cx_ecfp_public_key_t *pubkey
- PLENGTH(scc__cx_scc_struct_size_ecfp_pubkey_from_curve__curve),
- cx_ecfp_private_key_t *privkey
- PLENGTH(scc__cx_scc_struct_size_ecfp_privkey_from_curve__curve),
- int keepprivate);
-
-/**
- * Generate a ecfp key pair
- *
- * @param [in] curve
- * The curve domain parameters to work with.
- *
- * @param [out] pubkey
- * A public ecfp public key to generate.
- *
- * @param [in,out] privkey
- * A private ecfp private key to generate.
- * Either:
- * - if the private ecfp key is fully inited, i.e parameter 'rawkey' of
- * 'cx_ecfp_init_private_key' is NOT null, the private key value is kept
- * if the 'keep_private' parameter is non zero
- * - else a new private key is generated.
- *
- * @param [in] keepprivate if set to non zero, keep the private key value if
- * set. Else generate a new random one
- *
- * @param [in] hashID Hash to use for eddsa (SHA512, SHA3 and Keccak are
- * supported)
- *
- * @return zero
- *
- * @throws INVALID_PARAMETER
- */
-CXCALL int cx_ecfp_generate_pair2(
- cx_curve_t curve,
- cx_ecfp_public_key_t *pubkey
- PLENGTH(scc__cx_scc_struct_size_ecfp_pubkey_from_curve__curve),
- cx_ecfp_private_key_t *privkey
- PLENGTH(scc__cx_scc_struct_size_ecfp_privkey_from_curve__curve),
- int keepprivate, cx_md_t hashID);
-
-#endif
diff --git a/unit-tests/mock_includes/lcx_hash.h b/unit-tests/mock_includes/lcx_hash.h
deleted file mode 100644
index e7f1645..0000000
--- a/unit-tests/mock_includes/lcx_hash.h
+++ /dev/null
@@ -1,145 +0,0 @@
-#include <stddef.h>
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 LCX_HASH_H
-#define LCX_HASH_H
-
-#include <stdint.h>
-
-/* Defines from os.h */
-#ifndef SYSCALL
-#define SYSCALL
-#endif
-
-#ifndef PLENGTH
-#define PLENGTH(...)
-#endif
-
-#define WIDE // const // don't !!
-
-/** Message Digest algorithm identifiers. */
-enum cx_md_e {
- /** NONE Digest */
- CX_NONE,
- /** RIPEMD160 Digest */
- CX_RIPEMD160, // 20 bytes
- /** SHA224 Digest */
- CX_SHA224, // 28 bytes
- /** SHA256 Digest */
- CX_SHA256, // 32 bytes
- /** SHA384 Digest */
- CX_SHA384, // 48 bytes
- /** SHA512 Digest */
- CX_SHA512, // 64 bytes
- /** Keccak (pre-SHA3) Digest */
- CX_KECCAK, // 28,32,48,64 bytes
- /** SHA3 Digest */
- CX_SHA3, // 28,32,48,64 bytes
- /** Groestl Digest */
- CX_GROESTL,
- /** Blake Digest */
- CX_BLAKE2B,
- /** SHAKE-128 Digest */
- CX_SHAKE128, // any bytes
- /** SHAKE-128 Digest */
- CX_SHAKE256, // any bytes
-};
-/** Convenience type. See #cx_md_e. */
-typedef enum cx_md_e cx_md_t;
-
-/**
- * @internal
- * Maximum size of message for any digest. The size is given in block,
- */
-#define CX_HASH_MAX_BLOCK_COUNT 65535
-
-/**
- * Common Message Digest context, used as abstract type.
- */
-struct cx_hash_header_s {
- /** Message digest identifier, See cx_md_e. */
- cx_md_t algo;
- /** Number of block already processed */
- unsigned int counter;
-};
-/** Convenience type. See #cx_hash_header_s. */
-typedef struct cx_hash_header_s cx_hash_t;
-
-/**
- * Add more data to hash.
- *
- * @param [in/out] hash
- * Univers Continuation Blob.
- * The hash context pointer shall point to a well-defined hash struct
- * cx_ripemd160_t, cx_sha256_t, .... The hash context shall be inited with
- * 'cx_xxx_init' The hash context shall be in RAM The function should be called
- * with a nice cast.
- *
- * @param [in] mode
- * Supported flags: CX_LAST
- * If CX_LAST is set,
- * - The struct is left not modified after finishing
- * - if out is provided, hash is copied in out
- * - context is NOT automatically re-inited.
- *
- * @param [in] in
- * Input data to add to current hash
- *
- * @param [in] len
- * Length of input to data.
- *
- * @param [out] out
- * Either:
- * - NULL (ignored) if CX_LAST is NOT set
- * - produced hash if CX_LAST is set
- *
- * @param [out] out_len
- * Either:
- * - O, if out is NULL
- * - out buffer size, if buffer is too small to store the hash a exception
- * is thrown
- *
- */
-CXCALL int cx_hash(cx_hash_t *hash PLENGTH(scc__cx_scc_struct_size_hash__hash),
- int mode,
- const unsigned char WIDE *in PLENGTH(len),
- unsigned int len,
- unsigned char *out PLENGTH(out_len),
- unsigned int out_len);
-
-/**
- * cx_hash_no_throw - same as cx_hash but returns error code instead of throwing.
- * In unit tests we use this as the primary implementation.
- */
-int cx_hash_no_throw(cx_hash_t *hash,
- int mode,
- const unsigned char *in,
- unsigned int in_len,
- unsigned char *out,
- unsigned int out_len);
-
-/**
- * I/O vector for cx_sha256_hash_iovec.
- */
-typedef struct {
- const uint8_t *iov_base;
- size_t iov_len;
-} cx_iovec_t;
-
-#endif
diff --git a/unit-tests/mock_includes/lcx_ripemd160.h b/unit-tests/mock_includes/lcx_ripemd160.h
deleted file mode 100644
index 28ada53..0000000
--- a/unit-tests/mock_includes/lcx_ripemd160.h
+++ /dev/null
@@ -1,59 +0,0 @@
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 LCX_RIPEMD160_H
-#define LCX_RIPEMD160_H
-
-/** RIPEMD160 message digest size */
-#define CX_RIPEMD160_SIZE 20
-
-/**
- * RIPEMD-160 context
- */
-struct cx_ripemd160_s {
- /** See #cx_hash_header_s */
- struct cx_hash_header_s header;
- /** @internal
- * pending partial block length
- */
- unsigned int blen;
- /** @internal
- * pending partial block
- */
- unsigned char block[64];
- /** Current digest state.
- * After finishing the digest, contains the digest if correct parameters are
- * passed.
- */
- unsigned char acc[5 * 4];
-};
-/** Convenience type. See #cx_ripemd160_s. */
-typedef struct cx_ripemd160_s cx_ripemd160_t;
-
-/**
- * Initialize a RIPEMD-160 context.
- *
- * @param [out] hash the context to init.
- * The context shall be in RAM
- *
- * @return algorithm identifier
- */
-CXCALL int
-cx_ripemd160_init(cx_ripemd160_t *hash PLENGTH(sizeof(cx_ripemd160_t)));
-
-#endif
diff --git a/unit-tests/mock_includes/lcx_sha256.h b/unit-tests/mock_includes/lcx_sha256.h
deleted file mode 100644
index 3401f07..0000000
--- a/unit-tests/mock_includes/lcx_sha256.h
+++ /dev/null
@@ -1,87 +0,0 @@
-#include <stddef.h>
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 LCX_SHA256_H
-#define LCX_SHA256_H
-
-/** SHA224 message digest size */
-#define CX_SHA224_SIZE 28
-/** SHA256 message digest size */
-#define CX_SHA256_SIZE 32
-
-/**
- * SHA-224 and SHA-256 context
- */
-struct cx_sha256_s {
- /** @copydoc cx_ripemd160_s::header */
- struct cx_hash_header_s header;
- /** @internal @copydoc cx_ripemd160_s::blen */
- unsigned int blen;
- /** @internal @copydoc cx_ripemd160_s::block */
- unsigned char block[64];
- /** @copydoc cx_ripemd160_s::acc */
- unsigned char acc[8 * 4];
-};
-/** Convenience type. See #cx_sha256_s. */
-typedef struct cx_sha256_s cx_sha256_t;
-
-/**
- * Initialize a SHA-224 context.
- *
- * @param [out] hash the context to init.
- * The context shall be in RAM
- *
- * @return algorithm identifier
- */
-CXCALL int cx_sha224_init(cx_sha256_t *hash PLENGTH(sizeof(cx_sha256_t)));
-
-/**
- * Initialize a SHA-256 context.
- *
- * @param [out] hash the context to init.
- * The context shall be in RAM
- *
- * @return algorithm identifier
- */
-CXCALL int cx_sha256_init(cx_sha256_t *hash PLENGTH(sizeof(cx_sha256_t)));
-
-/**
- * One shot SHA-256 digest
- *
- * @param [in] in
- * Input data to compute the hash
- *
- * @param [in] len
- * Length of input data.
- *
- * @param [out] out
- * 'out' length is implicit
- *
- */
-CXCALL int cx_hash_sha256(const unsigned char WIDE *in PLENGTH(len),
- unsigned int len,
- unsigned char *out PLENGTH(out_len),
- unsigned int out_len);
-
-/**
- * Compute SHA-256 over an I/O vector.
- */
-int cx_sha256_hash_iovec(const cx_iovec_t *iovec, size_t iovec_count, uint8_t out[32]);
-
-#endif
diff --git a/unit-tests/mock_includes/ledger_assert.h b/unit-tests/mock_includes/ledger_assert.h
deleted file mode 100644
index f009955..0000000
--- a/unit-tests/mock_includes/ledger_assert.h
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma once
-
-#include <assert.h>
-
-#define LEDGER_ASSERT(test, message) assert(test)
diff --git a/unit-tests/mock_includes/os.h b/unit-tests/mock_includes/os.h
deleted file mode 100644
index fb8d79e..0000000
--- a/unit-tests/mock_includes/os.h
+++ /dev/null
@@ -1,1747 +0,0 @@
-#pragma once
-
-
-/*******************************************************************************
-* Ledger Nano S - Secure firmware
-* (c) 2019 Ledger
-*
-* 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 OS_H
-#define OS_H
-
-#define TARGET_NANOSP
-#define USB_SEGMENT_SIZE 64
-
-// #include "os_hal.h"
-
-// -----------------------------------------------------------------------
-// - BASIC MATHS
-// -----------------------------------------------------------------------
-#define U2(hi, lo) ((((hi)&0xFFu) << 8) | ((lo)&0xFFu))
-#define U4(hi3, hi2, lo1, lo0) \
- ((((hi3)&0xFFu) << 24) | (((hi2)&0xFFu) << 16) | (((lo1)&0xFFu) << 8) | \
- ((lo0)&0xFFu))
-#define U2BE(buf, off) ((((buf)[off] & 0xFFu) << 8) | ((buf)[off + 1] & 0xFFu))
-#define U2LE(buf, off) ((((buf)[off + 1] & 0xFFu) << 8) | ((buf)[off] & 0xFFu))
-#define U4BE(buf, off) ((U2BE(buf, off) << 16) | (U2BE(buf, off + 2) & 0xFFFFu))
-#define U4LE(buf, off) ((U2LE(buf, off + 2) << 16) | (U2LE(buf, off) & 0xFFFFu))
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#define MAX(x, y) ((x) > (y) ? (x) : (y))
-#define IS_POW2(x) (((x) & ((x)-1)) == 0)
-#define UPPER_ALIGN(adr, align, type) \
- (type)((type)((type)(adr) + \
- (type)((type)((type)MAX((type)(align), (type)1UL)) - \
- (type)1UL)) & \
- (type)(~(type)((type)((type)MAX(((type)align), (type)1UL)) - \
- (type)1UL)))
-#define LOWER_ALIGN(adr, align, type) \
- ((type)(adr) & \
- (type)((type) ~(type)(((type)MAX((type)(align), (type)1UL)) - (type)1UL)))
-#define U4BE_ENCODE(buf, off, value) \
- { \
- (buf)[(off) + 0] = ((value) >> 24) & 0xFF; \
- (buf)[(off) + 1] = ((value) >> 16) & 0xFF; \
- (buf)[(off) + 2] = ((value) >> 8) & 0xFF; \
- (buf)[(off) + 3] = ((value)) & 0xFF; \
- }
-#define U4LE_ENCODE(buf, off, value) \
- { \
- (buf)[(off) + 3] = ((value) >> 24) & 0xFF; \
- (buf)[(off) + 2] = ((value) >> 16) & 0xFF; \
- (buf)[(off) + 1] = ((value) >> 8) & 0xFF; \
- (buf)[(off) + 0] = ((value)) & 0xFF; \
- }
-#define U2BE_ENCODE(buf, off, value) \
- { \
- (buf)[(off) + 0] = ((value) >> 8) & 0xFF; \
- (buf)[(off) + 1] = ((value)) & 0xFF; \
- }
-#define U2LE_ENCODE(buf, off, value) \
- { \
- (buf)[(off) + 1] = ((value) >> 8) & 0xFF; \
- (buf)[(off) + 0] = ((value)) & 0xFF; \
- }
-
-/**
- * Helper to perform compilation time assertions
- */
-#if !defined(SYSCALL_GENERATE) && \
- (defined(__clang__) || \
- (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 6))))
-#define CCASSERT(id, predicate) _Static_assert(predicate, #id)
-#else
-#define CCASSERT(id, predicate) __x_CCASSERT_LINE(predicate, id, __LINE__)
-#define __x_CCASSERT_LINE(predicate, file, line) \
- __xx_CCASSERT_LINE(predicate, file, line)
-#define __xx_CCASSERT_LINE(predicate, file, line) \
- typedef char CCASSERT_##file##_line_##line[((predicate) ? 1 : -1)]
-#endif
-
-#ifdef macro_offsetof
-#define offsetof(type, field) ((unsigned int)&(((type *)NULL)->field))
-#endif
-
-/**
- * Quality development guidelines:
- * - NO header defined per arch and included in common if needed per arch,
- * define below
- * - exception model
- * - G_ prefix for RAM vars
- * - N_ prefix for NVRAM vars (mandatory for x86 link script to operate
- * correctly)
- * - C_ prefix for ROM constants (mandatory for x86 link script to operate
- * correctly)
- * - extensive use of * and arch specific C modifier
- */
-
-// error type definition
-typedef unsigned short exception_t;
-
-
-//#define macro_offsetof // already defined in stddef.h
-#define OS_LITTLE_ENDIAN
-#define NATIVE_64BITS
-#define NVM_ERASED_WORD_VALUE 0xFFFFFFFFUL
-
-#define WIDE // const // don't !!
-#define WIDE_AS_INT unsigned long int
-#define REENTRANT(x) x //
-
-#include <setjmp.h>
-// GCC/LLVM declare way too big jmp context, reduce them to what is used on CM0+
-typedef struct try_context_s try_context_t;
-
-struct try_context_s {
- // jmp context to backup (in increasing order address: r4, r5, r6, r7, r8, r9,
- // r10, r11, SP, setjmpcallPC)
- jmp_buf jmp_buf;
-
- // link to the previous jmp_buf context
- try_context_t *previous;
-
- // current exception
- exception_t ex;
-};
-
-// borrowed from setjmp.h
-
-#ifdef __GNUC__
-void longjmp(jmp_buf __jmpb, int __retval) __attribute__((__noreturn__));
-#else
-void longjmp(jmp_buf __jmpb, int __retval);
-#endif
-int setjmp(jmp_buf __jmpb);
-
-#include "stddef.h"
-#include "stdint.h"
-// #include <core_sc000.h>
-
-#define UNUSED(x) (void)x
-
-#endif
-#if defined(ST33)
-
-#define NVM_ERASED_WORD_VALUE 0xFFFFFFFF
-
-//#define macro_offsetof // already defined in stddef.h
-#define OS_LITTLE_ENDIAN
-#define NATIVE_64BITS
-#define WIDE // const // don't !!
-#define WIDE_AS_INT unsigned long int
-#define REENTRANT(x) x //
-
-//#include <setjmp.h>
-// GCC/LLVM declare way too big jmp context, reduce them to what is used on CM0+
-typedef struct try_context_s try_context_t;
-typedef unsigned int jmp_buf[10];
-struct try_context_s {
- // jmp context to backup (in increasing order address: r4, r5, r6, r7, r8, r9,
- // r10, r11, SP, setjmpcallPC)
- jmp_buf jmp_buf;
-
- // link to the previous jmp_buf context
- try_context_t *previous;
- // current exception
- exception_t ex;
-};
-
-// borrowed from setjmp.hm0
-
-#ifdef __GNUC__
-void longjmp(jmp_buf __jmpb, int __retval) __attribute__((__noreturn__));
-#else
-void longjmp(jmp_buf __jmpb, int __retval);
-#endif
-int setjmp(jmp_buf __jmpb);
-
-#include "stddef.h"
-#include "stdint.h"
-#include <core_sc300.h>
-
-#define UNUSED(x) (void)x
-
-#endif
-
-// #include "os_apilevel.h"
-
-#ifndef NULL
-#define NULL ((void *)0)
-#endif
-
-#ifndef WIDE_NULL
-#define WIDE_NULL ((void WIDE *)0)
-#endif
-
-// Position-independent code reference
-// Function that align the dereferenced value in a rom struct to use it
-// depending on the execution address. Can be used even if code is executing at
-// the same place where it had been linked.
-#ifndef PIC
-#define PIC(x) pic((unsigned int) x)
-static inline __attribute__((always_inline)) unsigned int pic(unsigned int linked_address) {
- return linked_address;
-}
-#endif
-
-#ifndef SYSCALL
-// #define SYSCALL syscall
-#define SYSCALL
-#endif
-
-#ifndef TASKSWITCH
-// #define TASKSWITCH taskswitch
-#define TASKSWITCH
-#endif
-
-#ifndef SUDOCALL
-// #define SUDOCALL sudocall
-#define SUDOCALL
-#endif
-
-#ifndef LIBCALL
-// #define LIBCALL libcall
-#define LIBCALL
-#endif
-
-#ifndef SHARED
-// #define SHARED shared
-#define SHARED
-#endif
-
-#ifndef PERMISSION
-#define PERMISSION(...)
-#endif
-
-#ifndef PLENGTH
-#define PLENGTH(...)
-#endif
-
-#ifndef CXPORT
-#define CXPORT(...)
-#endif
-
-#ifndef TASKLEVEL
-#define TASKLEVEL(...)
-#endif
-
-/* ----------------------------------------------------------------------- */
-/* - APPLICATION PRIVILEGES - */
-/* ----------------------------------------------------------------------- */
-
-/**
- * No rights concealed to the call
- */
-#define APPLICATION_FLAG_NONE 0x0
-
-/**
- * Base flag added to loaded application, to allow them to call all syscalls by
- * default (the one requiring no extra permission)
- */
-#define APPLICATION_FLAG_MAIN 0x1
-
-/**
- * Flag which combined with ::APPLICATION_FLAG_ISSUER.
- * The application is given full nvram access after the global seed has been
- * destroyed.
- */
-#define APPLICATION_FLAG_BOLOS_UPGRADE 0x2
-
-// this flag is set when a valid signature of the loaded application is
-// presented at the end of the bolos application load.
-#define APPLICATION_FLAG_SIGNED 0x4
-
-// must be set on one application in the registry which is used
-#define APPLICATION_FLAG_BOLOS_UX 0x8
-
-// application is allowed to use the raw master seed, if not set, at least a
-// level of derivation is required.
-#define APPLICATION_FLAG_DERIVE_MASTER 0x10
-
-#define APPLICATION_FLAG_SHARED_NVRAM 0x20
-#define APPLICATION_FLAG_GLOBAL_PIN 0x40
-
-// This flag means the application is meant to be debugged and allows for dump
-// or core ARM register in case of a fault detection
-#define APPLICATION_FLAG_DEBUG 0x80
-
-/**
- * Mark this application as defaultly booting along with the bootloader (no
- * application menu displayed) Only one application can have this at a time. It
- * is managed by the bootloader interface.
- */
-#define APPLICATION_FLAG_AUTOBOOT 0x100
-
-/**
- * Application is allowed to change the settings
- */
-#define APPLICATION_FLAG_BOLOS_SETTINGS 0x200
-
-#define APPLICATION_FLAG_CUSTOM_CA 0x400
-
-/**
- * The application main can be called in two ways:
- * - with first arg (stored in r0) set to 0: The application is called from the
- * dashboard
- * - with first arg (stored in r0) set to != 0 (ram address likely): The
- * application is used as a library from another app.
- */
-#define APPLICATION_FLAG_LIBRARY 0x800
-
-/**
- * The application won't be shown on the dashboard (somewhat reasonable for pure
- * library)
- */
-#define APPLICATION_FLAG_NO_RUN 0x1000
-
-/**
- * The application is considered an IO task by the system. It only gives
- * privileges to BOLOS' internal IO task
- */
-#define APPLICATION_FLAG_IO 0x2000
-
-/**
- * Application has been loaded using a secure channel opened using the
- * bootloader's issuer public key. This application is ledger legit.
- */
-#define APPLICATION_FLAG_ISSUER 0x4000
-
-/**
- * Application is enabled (when not being updated or removed)
- */
-#define APPLICATION_FLAG_ENABLED 0x8000
-
-#define APPLICATION_FLAG_NEG_MASK 0xFFFF0000UL
-
-/* ----------------------------------------------------------------------- */
-/* - SYSCALL CRYPTO EXPORT - */
-/* ----------------------------------------------------------------------- */
-
-#define CXPORT_ED_DES 0x0001UL
-#define CXPORT_ED_AES 0x0002UL
-#define CXPORT_ED_RSA 0x0004UL
-
-/* ----------------------------------------------------------------------- */
-/* - TYPES - */
-/* ----------------------------------------------------------------------- */
-
-/* ----------------------------------------------------------------------- */
-/* - GLOBALS - */
-/* ----------------------------------------------------------------------- */
-
-// the global apdu buffer
-#ifdef HAVE_IO_U2F
-#define IMPL_IO_APDU_BUFFER_SIZE (3 + 32 + 32 + 15 + 255)
-#else
-#define IMPL_IO_APDU_BUFFER_SIZE (5 + 255)
-#endif
-
-#ifdef CUSTOM_IO_APDU_BUFFER_SIZE
-#define IO_APDU_BUFFER_SIZE \
- MAX(IMPL_IO_APDU_BUFFER_SIZE, CUSTOM_IO_APDU_BUFFER_SIZE)
-#else
-#define IO_APDU_BUFFER_SIZE IMPL_IO_APDU_BUFFER_SIZE
-#endif
-extern unsigned char G_io_apdu_buffer[IO_APDU_BUFFER_SIZE];
-
-#define CUSTOMCA_MAXLEN 64
-
-/* ----------------------------------------------------------------------- */
-/* - ENTRY POINT - */
-/* ----------------------------------------------------------------------- */
-
-// os entry point
-void app_main(void);
-
-// os initialization function to be called by application entry point
-void os_boot();
-
-/* ----------------------------------------------------------------------- */
-/* - OS FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-#define os_swap_u16(u16) \
- ((((unsigned short)(u16) << 8) & 0xFF00U) | \
- (((unsigned short)(u16) >> 8) & 0x00FFU))
-
-#define os_swap_u32(u32) \
- (((unsigned long int)(u32) >> 24) | \
- (((unsigned long int)(u32) << 8) & 0x00FF0000UL) | \
- (((unsigned long int)(u32) >> 8) & 0x0000FF00UL) | \
- ((unsigned long int)(u32) << 24))
-
-REENTRANT(void os_memmove(void *dst, const void WIDE *src,
- unsigned int length));
-#define os_memcpy os_memmove
-
-void os_memset(void *dst, unsigned char c, unsigned int length);
-
-void os_memset4(void *dst, unsigned int initval, unsigned int nbintval);
-
-char os_memcmp(const void WIDE *buf1, const void WIDE *buf2,
- unsigned int length);
-
-void os_xor(void *dst, void WIDE *src1, void WIDE *src2, unsigned int length);
-
-// Secure memory comparison
-char os_secure_memcmp(void WIDE *src1, void WIDE *src2, unsigned int length);
-
-// patch point, address used to dispatch, no index
-REENTRANT(void patch(void));
-
-// check API level
-SYSCALL void check_api_level(unsigned int apiLevel);
-
-// halt the chip, waiting for a physical user interaction
-SYSCALL REENTRANT(void halt(void));
-
-// deprecated
-#define reset halt
-
-// send tx_len bytes (atr or rapdu) and retrieve the length of the next command
-// apdu (over the requested channel)
-#define CHANNEL_APDU 0
-#define CHANNEL_KEYBOARD 1
-#define CHANNEL_SPI 2
-#define IO_RESET_AFTER_REPLIED 0x80
-#define IO_RECEIVE_DATA 0x40
-#define IO_RETURN_AFTER_TX 0x20
-#define IO_ASYNCH_REPLY \
- 0x10 // avoid apdu state reset if tx_len == 0 when we're expected to reply
-#define IO_FINISHED 0x08 // inter task communication value
-#define IO_FLAGS 0xF8
-unsigned short io_exchange(unsigned char channel_and_flags,
- unsigned short tx_len);
-
-typedef enum {
- IO_APDU_MEDIA_NONE = 0, // not correctly in an apdu exchange
- IO_APDU_MEDIA_USB_HID = 1,
- IO_APDU_MEDIA_BLE,
- IO_APDU_MEDIA_NFC,
- IO_APDU_MEDIA_USB_CCID,
- IO_APDU_MEDIA_USB_WEBUSB,
- IO_APDU_MEDIA_RAW,
- IO_APDU_MEDIA_U2F,
-} io_apdu_media_t;
-
-#ifndef USB_SEGMENT_SIZE
-#ifdef IO_HID_EP_LENGTH
-#define USB_SEGMENT_SIZE IO_HID_EP_LENGTH
-#else
-#error IO_HID_EP_LENGTH and USB_SEGMENT_SIZE not defined
-#endif
-#endif
-#ifndef BLE_SEGMENT_SIZE
-#define BLE_SEGMENT_SIZE USB_SEGMENT_SIZE
-#endif
-
-// common usb endpoint buffer
-extern unsigned char
- G_io_usb_ep_buffer[MAX(USB_SEGMENT_SIZE, BLE_SEGMENT_SIZE)];
-
-/**
- * Return 1 when the event has been processed, 0 else
- */
-// io callback in the application called when an interrupt based channel has
-// received data to be processed
-unsigned char io_event(unsigned char channel);
-
-/**
- * Function takes 0 for first call. Returns 0 when timeout has occured. Returned
- * value is passed as argument for next call, acting as a timeout context.
- */
-unsigned short io_timeout(unsigned short last_timeout);
-// write in persistent memory, to make things easy keep a layout of the memory
-// in a structure and update fields upon needs The function throws exception
-// when the requesting application buffer being written in its declared data
-// segment. The later is declared during the application slot allocation (using
-// --dataSize parameter in the python scripts) NOTE: accept copy from far memory
-// to another far memory.
-// @param src_adr NULL to fill with 00's
-SYSCALL void nvm_write(void WIDE *dst_adr PLENGTH(src_len),
- void WIDE *src_adr PLENGTH(src_len),
- unsigned int src_len);
-// the priviledged version of nvm_write, called by bolos itself
-void nvm_write_os(void WIDE *dst_adr PLENGTH(src_len),
- void WIDE *src_adr PLENGTH(src_len), unsigned int src_len);
-
-// program a page with the content of the nvm_page_buffer
-// HAL for the high level NVM management functions
-SUDOCALL PERMISSION(APPLICATION_FLAG_ISSUER) void nvm_write_page(
- unsigned char WIDE *page_adr);
-void svc_nvm_write_page(unsigned char WIDE *page_adr);
-
-/* ----------------------------------------------------------------------- */
-/* - EXCEPTIONS - */
-/* ----------------------------------------------------------------------- */
-
-// workaround to make sure defines are replaced by their value for example
-#define CPP_CONCAT(x, y) CPP_CONCAT_x(x, y)
-#define CPP_CONCAT_x(x, y) x##y
-
-SUDOCALL PERMISSION(APPLICATION_FLAG_NONE) try_context_t *try_context_get(void);
-try_context_t *svc_try_context_get(void);
-// set the new try context and retrieve the previous one
-// SECURITY NOTE: no PLENGTH(sizeof(try_context_t)) set because the value is
-// never dereferenced within the SUDOCALL.
-// and is checked before being used in all SYSCALL that would use
-// it.
-SUDOCALL PERMISSION(APPLICATION_FLAG_NONE)
- try_context_t *try_context_set(try_context_t *context);
-try_context_t *svc_try_context_set(try_context_t *tryctx);
-
-// -----------------------------------------------------------------------
-// - BEGIN TRY
-// -----------------------------------------------------------------------
-
-#define BEGIN_TRY_L(L) \
- { \
- try_context_t __try##L;
-
-// -----------------------------------------------------------------------
-// - TRY
-// -----------------------------------------------------------------------
-#define TRY_L(L) \
- /* previous exception context chain is saved within the setjmp r9 save */ \
- __try \
- ##L.ex = setjmp(__try##L.jmp_buf); \
- if (__try##L.ex == 0) { \
- __try \
- ##L.previous = try_context_set(&__try##L);
-
-// -----------------------------------------------------------------------
-// - EXCEPTION CATCH
-// -----------------------------------------------------------------------
-#define CATCH_L(L, x) \
- goto CPP_CONCAT(__FINALLY, L); \
- } \
- else if (__try##L.ex == x) { \
- __try \
- ##L.ex = 0; \
- CLOSE_TRY_L(L);
-
-// -----------------------------------------------------------------------
-// - EXCEPTION CATCH OTHER
-// -----------------------------------------------------------------------
-#define CATCH_OTHER_L(L, e) \
- goto CPP_CONCAT(__FINALLY, L); \
- } \
- else { \
- exception_t e; \
- e = __try##L.ex; \
- __try \
- ##L.ex = 0; \
- CLOSE_TRY_L(L);
-
-// -----------------------------------------------------------------------
-// - EXCEPTION CATCH ALL
-// -----------------------------------------------------------------------
-#define CATCH_ALL_L(L) \
- goto CPP_CONCAT(__FINALLY, L); \
- } \
- else { \
- __try \
- ##L.ex = 0; \
- CLOSE_TRY_L(L);
-
-// -----------------------------------------------------------------------
-// - FINALLY
-// -----------------------------------------------------------------------
-#define FINALLY_L(L) \
- goto CPP_CONCAT(__FINALLY, L); \
- } \
- CPP_CONCAT(__FINALLY, L) \
- : /* has TRY clause ended without nested throw ? */ \
- if (try_context_get() == &__try##L) { \
- /* restore previous context manually (as a throw would have when caught) \
- */ \
- CLOSE_TRY_L(L); \
- }
-// -----------------------------------------------------------------------
-// - CLOSE TRY
-// -----------------------------------------------------------------------
-/**
- * Forced finally like clause.
- */
-#define CLOSE_TRY_L(L) try_context_set(__try##L.previous)
-
-// -----------------------------------------------------------------------
-// - END TRY
-// -----------------------------------------------------------------------
-#define END_TRY_L(L) \
- /* nested throw not consumed ? (by CATCH* clause) */ \
- if (__try##L.ex != 0) { \
- /* rethrow */ \
- THROW_L(L, __try##L.ex); \
- } \
- }
-
-// -----------------------------------------------------------------------
-// - EXCEPTION THROW
-// -----------------------------------------------------------------------
-
-/**
- Remember that using break/return/goto/continue keywords that disrupt the
- execution flow may introduce silent errors which can pop afterwards in a
- very sneaky and hard to debug way. Those keywords are malicious ONLY when
- jumping out of the current block (TRY/CATCH/CATCH_OTHER/CATCH_ALL) else
- they are perfectly fine.
- When those keywords use are unavoidable, then remember to CLOSE_TRY your
- opened BEGIN/END block.
- To detect those potential problems, here is a basic sed based script to
- narrow down the search to poentially suspicious cases.
- for i in `find . -name "*.c"`; do echo $i ; sed -n '/BEGIN_TRY/,/END_TRY/{
- /goto/{=;H;g;p} ;/return/{=;H;g;p} ; /continue/{=;H;g;p} ; /break/{=;H;g;p} ; h
- }' $i ; done Run it on your source code if unsure. The rule of thumb to respect
- to decide whether or not to use the CLOSE_TRY statement is the following:
- Jumping out of a TRY/CATCH/CATCH_ALL/CATCH_OTHER clause is not closing the
- BEGIN/TRY block if the FINALLY is not executed wholy (jumping to a label
- at the beginning of the FINALLY is not solving the above stated problem).
-
- Faulty example:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- }
- CATCH {
- ...
- goto noway;
- }
- FINALLY {
-
- }
- }
- END_TRY;
- noway:
- return;
-
- Faulty example 2:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- goto noway;
- }
- CATCH {
- ...
- }
- FINALLY {
-
- }
- }
- END_TRY;
- noway:
- return;
-
- Faulty example 3:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- }
- CATCH {
- ...
- goto end;
- ...
- }
- FINALLY {
- end:
- }
- }
- END_TRY;
- noway:
- return;
-
- Faulty example 4:
- ===============
- for(;;) {
- BEGIN_TRY {
- TRY {
- ...
- continue;
- ...
- }
- CATCH {
- ...
- }
- FINALLY {
-
- }
- }
- END_TRY;
- }
-
- Ok example (but very suspicious algorithmly speaking):
- ===============
- BEGIN_TRY {
- TRY {
- ...
- yo:
- ...
- }
- CATCH {
- ...
- goto yo;
- }
- FINALLY {
-
- }
- }
- END_TRY;
- noway:
- return;
-
- Ok example 2:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- CLOSE_TRY;
- goto noway;
- ...
- }
- CATCH {
- ...
- }
- FINALLY {
-
- }
- }
- END_TRY;
- noway:
- return;
-
- Ok example 3:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- goto baz;
- ...
- baz:
- }
- CATCH {
- ...
- }
- FINALLY {
-
- }
- }
- END_TRY;
-
- Faulty example 5:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- }
- CATCH {
- return val;
- }
- FINALLY {
- ...
- }
- }
- END_TRY;
-
- Faulty example 6:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- return val;
- }
- CATCH {
- ...
- }
- FINALLY {
- ...
- }
- }
- END_TRY;
-
- Ok example 4:
- ===============
- BEGIN_TRY {
- TRY {
- ...
- }
- CATCH {
- ...
- }
- FINALLY {
- return val;
- }
- }
- END_TRY;
- */
-
-// longjmp is marked as no return to avoid too much generated code
-#ifdef __clang_analyzer__
-void os_longjmp(unsigned int exception) __attribute__((analyzer_noreturn));
-#else
-void os_longjmp(unsigned int exception) __attribute__((noreturn));
-#endif
-#define THROW_L(L, x) os_longjmp(x)
-
-// Default macros when nesting is not used.
-#define THROW(x) THROW_L(EX, x)
-#define BEGIN_TRY BEGIN_TRY_L(EX)
-#define TRY TRY_L(EX)
-#define CATCH(x) CATCH_L(EX, x)
-#define CATCH_OTHER(e) CATCH_OTHER_L(EX, e)
-#define CATCH_ALL CATCH_ALL_L(EX)
-#define FINALLY FINALLY_L(EX)
-#define CLOSE_TRY CLOSE_TRY_L(EX)
-#define END_TRY END_TRY_L(EX)
-
-#define EXCEPTION 1
-#define INVALID_PARAMETER 2
-#define EXCEPTION_OVERFLOW 3
-#define EXCEPTION_SECURITY 4
-#define INVALID_CRC 5
-#define INVALID_CHECKSUM 6
-#define INVALID_COUNTER 7
-#define NOT_SUPPORTED 8
-#define INVALID_STATE 9
-#define TIMEOUT 10
-#define EXCEPTION_PIC 11
-#define EXCEPTION_APPEXIT 12
-#define EXCEPTION_IO_OVERFLOW 13
-#define EXCEPTION_IO_HEADER 14
-#define EXCEPTION_IO_STATE 15
-#define EXCEPTION_IO_RESET 16
-#define EXCEPTION_CXPORT 17
-#define EXCEPTION_SYSTEM 18
-#define NOT_ENOUGH_SPACE 19
-
-/* ----------------------------------------------------------------------- */
-/* - CRYPTO FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-#include "cx.h"
-
-/**
- BOLOS RAM LAYOUT
- msp psp psp
- | bolos ram <-os stack-| bolos ux ram <-ux_stack-| app ram <-app stack-|
-
- ux and app are seen as applications.
- os is not an application (it calls ux upon user inputs)
-**/
-
-/* ----------------------------------------------------------------------- */
-/* - BOLOS UX DEFINITIONS - */
-/* ----------------------------------------------------------------------- */
-typedef enum bolos_ux_e {
- BOLOS_UX_INITIALIZE = 0, // tag to be processed by the UX from the serial line
-
- BOLOS_UX_EVENT, // tag to be processed by the UX from the serial line
- BOLOS_UX_KEYBOARD,
- BOLOS_UX_WAKE_UP, // the application/os asks for the screen to be waked up
- // (asking pin if the lock period has been exceeded)
- BOLOS_UX_STATUS_BAR,
-
- BOLOS_UX_BOOT, // will never be presented to loaded UX app, this is for
- // failsafe UX only
- BOLOS_UX_BOOT_NOT_PERSONALIZED,
- BOLOS_UX_BOOT_ONBOARDING,
- BOLOS_UX_BOOT_UNSAFE_WIPE,
- BOLOS_UX_BOOT_UX_NOT_SIGNED,
- BOLOS_UX_BOLOS_START = 10, // called in before dashboard displays
- BOLOS_UX_DASHBOARD,
- BOLOS_UX_PROCESSING,
-
- BOLOS_UX_LOADER, // display loader screen or advance it
-
- BOLOS_UX_VALIDATE_PIN,
- BOLOS_UX_CONSENT_UPGRADE,
- BOLOS_UX_CONSENT_APP_ADD,
- BOLOS_UX_CONSENT_APP_DEL,
- BOLOS_UX_CONSENT_APP_UPG,
- BOLOS_UX_CONSENT_ISSUER_KEY,
- BOLOS_UX_CONSENT_CUSTOMCA_KEY = 20,
- BOLOS_UX_CONSENT_FOREIGN_KEY,
- BOLOS_UX_CONSENT_GET_DEVICE_NAME,
- BOLOS_UX_CONSENT_SET_DEVICE_NAME,
- BOLOS_UX_CONSENT_RESET_CUSTOMCA_KEY,
- BOLOS_UX_CONSENT_SETUP_CUSTOMCA_KEY,
- BOLOS_UX_APP_ACTIVITY, // special code when application is processing data but
- // not displaying UI. It prevent going poweroff, while
- // not avoiding screen locking
- BOLOS_UX_CONSENT_NOT_INTERACTIVE_ONBOARD,
- BOLOS_UX_PREPARE_RUN_APP, // called before the os runs an application, the os
- // ux must be cleared and not display anything on
- // upcoming display processed events
-
- BOLOS_UX_MCU_UPGRADE_REQUIRED,
- BOLOS_UX_CONSENT_RUN_APP = 30,
- BOLOS_UX_SECURITY_BOOT_DELAY,
- DEPRECATED_BOLOS_UX_CONSENT_GENUINENESS,
- BOLOS_UX_BOOT_MENU,
- BOLOS_UX_CONTROL_CENTER,
- BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST, // ask the ux to display a modal to
- // accept/reject the current pairing
- // request
- BOLOS_UX_ASYNCHMODAL_PAIRING_CANCEL, //
-
- BOLOS_UX_CONSENT_LISTAPPS,
-
- BOLOS_UX_LAST_ID, // keep that one at the end
-} bolos_ux_t;
-
-typedef char bolos_bool_t;
-#define BOLOS_TRUE BOLOS_UX_OK
-#define BOLOS_FALSE BOLOS_UX_CANCEL
-
-typedef unsigned char bolos_task_status_t;
-
-#define BOLOS_UX_OK 0xAA
-#define BOLOS_UX_CANCEL 0x55
-#define BOLOS_UX_ERROR 0xD6
-
-/* Value returned by os_ux to notify the application that the processed event
- * must be discarded and not processed by the application. Generally due to
- * handling of power management/dim/locking */
-#define BOLOS_UX_IGNORE 0x97
-// a modal has destroyed the display, app needs to redraw its screen
-#define BOLOS_UX_REDRAW 0x69
-// ux has not finished processing yet (not a final status)
-#define BOLOS_UX_CONTINUE 0
-
-/* ----------------------------------------------------------------------- */
-/* - APPLICATION FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-
-typedef void (*appmain_t)(void);
-
-#define BOLOS_TAG_APPNAME 0x01
-#define BOLOS_TAG_APPVERSION 0x02
-#define BOLOS_TAG_ICON 0x03
-#define BOLOS_TAG_DERIVEPATH 0x04
-#define BOLOS_TAG_DATA_SIZE \
- 0x05 // meta tag to retrieve the size of the data section for the application
-// Library Dependencies are a tuple of 2 LV, the lib appname and the lib version
-// (only exact for now). When lib version is not specified, it is not check,
-// only name is asserted The DEPENDENCY tag may have several occurences, one for
-// each dependency (by name). Malformed (multiple dep to the same lib with
-// different version is is not ORed but ANDed, and then considered bogus)
-#define BOLOS_TAG_DEPENDENCY 0x06
-// first autorised tag value for user data
-#define BOLOS_TAG_USER_TAG 0x20
-
-// application slot description
-typedef struct application_s {
- // nvram start address for this application (to check overlap when loading,
- // and mpu lock)
- unsigned char *nvram_begin;
- // nvram stop address (exclusive) for this application (to check overlap when
- // loading, and mpu lock)
- unsigned char *nvram_end;
-
- // address of the main address, must be set according to BLX spec ( ORed with
- // 1 when jumping into Thumb code
- appmain_t main;
-
- // special flags for this application
- unsigned int flags;
-
- // Memory organization: [ code (RX) |alignpage| data (RW) |alignpage| install
- // params (R) ]
-
- // length of the code section of the application (RX)
- unsigned int code_length;
-
- // NOTE: code_length+params_length must be a multiple of PAGE_SIZE
- // Length of the DATA section of the application. (RW)
- unsigned int data_length;
-
- // NOTE: code_length+params_length must be a multiple of PAGE_SIZE
- // length of the parameters sections of the application (R)
- unsigned int params_length;
-
- // Intermediate hash of the application's loaded code and data segments
- unsigned char sha256_code_data[32];
- // Hash of the application's loaded code, data and instantiation parameters
- unsigned char sha256_full[32];
-
-} application_t;
-
-// Structure that defines the parameters to exchange with the BOLOS UX
-// application
-typedef struct bolos_ux_params_s {
- bolos_ux_t ux_id;
- // length of parameters in the u union to be copied during the syscall
- unsigned int len;
-
- // structure to overlay parameters for each BOLOS_UX
- union {
- struct {
- unsigned int currently_onboarded;
- unsigned char hash[32];
- } boot_unsafe;
-
- struct {
- unsigned int app_idx;
- } appexitb;
-
- struct {
- unsigned int app_idx;
- application_t appentry;
- } appdel;
-
- struct {
- unsigned int app_idx;
- application_t appentry;
- } appadd;
-
- // pass the whole load application to that the os version and hash are
- // available
- struct {
- unsigned int app_idx;
- application_t upgrade;
- } upgrade;
-
- struct {
- application_t ux_app;
- } ux_not_signed;
-
- struct {
- unsigned int app_idx;
- application_t app;
- } run_app;
-
- struct {
- char name[CUSTOMCA_MAXLEN + 1];
- cx_ecfp_public_key_t public;
- } customca_key;
-
- struct {
- cx_ecfp_public_key_t host_pubkey;
- } foreign_key;
-
- struct {
- char name[CUSTOMCA_MAXLEN + 1];
- cx_ecfp_public_key_t public;
- } reset_customca;
-
- struct {
- char name[CUSTOMCA_MAXLEN + 1];
- cx_ecfp_public_key_t public;
- } setup_customca;
-
- struct {
- unsigned int keycode;
-#define BOLOS_UX_MODE_UPPERCASE 0
-#define BOLOS_UX_MODE_LOWERCASE 1
-#define BOLOS_UX_MODE_SYMBOLS 2
-#define BOLOS_UX_MODE_COUNT 3 // number of keyboard modes
- unsigned int mode;
- // + 1 EOS (0)
-#define BOLOS_UX_KEYBOARD_TEXT_BUFFER_SIZE 32
- char entered_text[BOLOS_UX_KEYBOARD_TEXT_BUFFER_SIZE + 1];
- } keyboard;
-
- struct {
- unsigned int cancellable;
- } validate_pin;
-
- struct {
- unsigned int keycode;
- } pin_keyboard;
-
- struct {
- unsigned int fgcolor;
- unsigned int bgcolor;
- } status_bar;
-
- struct {
- unsigned int x;
- unsigned int y;
- unsigned int width;
- unsigned int height;
- } loader;
-
- struct {
- unsigned int id;
- } onboard;
-
- struct {
- unsigned int percent;
- } boot_delay;
-
- struct {
- enum {
- BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST_PASSKEY,
- BOLOS_UX_ASYNCHMODAL_PAIRING_REQUEST_NUMCOMP,
- } type;
- unsigned int pairing_info_len;
- char pairing_info[16];
- } pairing_request;
-
- } u;
-
-} bolos_ux_params_t;
-
-// any application can wipe the global pin, global seed, user's keys
-// disabled for security reasons // SYSCALL void os_perso_wipe(void);
-// erase seed, settings AND applications
-SYSCALL void os_perso_erase_all(void);
-
-/* set_pin can update the pin if the perso is onboarded (tearing leads to perso
- * wipe though) */
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_perso_set_pin(
- unsigned int identity, unsigned char *pin PLENGTH(length),
- unsigned int length);
-// set the currently unlocked identity pin. (change pin feature)
-SYSCALL
- PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_perso_set_current_identity_pin(
- unsigned char *pin PLENGTH(length), unsigned int length);
-
-#define BOLOS_UX_ONBOARDING_ALGORITHM_BIP39 1
-#define BOLOS_UX_ONBOARDING_ALGORITHM_ELECTRUM 2
-
-/**
- * Set the persisted seed if none yet, else override the volatile seed (in RAM)
- */
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_perso_set_seed(
- unsigned int identity, unsigned int algorithm,
- unsigned char *seed PLENGTH(length), unsigned int length);
-
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_perso_derive_and_set_seed(
- unsigned char identity, const char *prefix PLENGTH(prefix_length),
- unsigned int prefix_length,
- const char *passphrase PLENGTH(passphrase_length),
- unsigned int passphrase_length, const char *words PLENGTH(words_length),
- unsigned int words_length);
-
-// SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void
-// os_perso_set_alternate_pin(unsigned char* pin PLENGTH(pinLength), unsigned int
-// pinLength); SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void
-// os_perso_set_alternate_seed(unsigned char* seed PLENGTH(seedLength), unsigned
-// int seedLength);
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_perso_set_words(
- const unsigned char *words PLENGTH(length), unsigned int length);
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_perso_finalize(void);
-
-// checked in the ux flow to avoid asking the pin for example
-// NBA : could also be checked by applications running in unsecure mode - thus
-// unprivilegied
-// @return BOLOS_UX_OK when perso is onboarded.
-SYSCALL bolos_bool_t os_perso_isonboarded(void);
-
-// derive the seed for the requested BIP32 path
-SYSCALL void os_perso_derive_node_bip32(
- cx_curve_t curve,
- const unsigned int *path PLENGTH(4 * (pathLength & 0x0FFFFFFFu)),
- unsigned int pathLength, unsigned char *privateKey PLENGTH(64),
- unsigned char *chain PLENGTH(32));
-
-#define HDW_NORMAL 0
-#define HDW_ED25519_SLIP10 1
-// symmetric key derivation according to SLIP-0021
-// this only supports derivation of the master node (level 1)
-// the beginning of the authorized path is to be provided in the authorized
-// derivation tag of the registry starting with a \x00 Note: for SLIP21, the
-// path is a string and the pathLength is the number of chars including the
-// starting \0 byte. However, firewall checks are processing a number of
-// integers, therefore, take care not to locate the buffer too far in memory to
-// pass the firewall check.
-#define HDW_SLIP21 2
-// derive the seed for the requested BIP32 path, with the custom provided
-// seed_key for the sha512 hmac ("Bitcoin Seed", "Nist256p1 Seed", "ed25519
-// seed", ...)
-SYSCALL void os_perso_derive_node_with_seed_key(
- unsigned int mode, cx_curve_t curve,
- const unsigned int *path PLENGTH(4 * (pathLength & 0x0FFFFFFFu)),
- unsigned int pathLength, unsigned char *privateKey PLENGTH(64),
- unsigned char *chain PLENGTH(32),
- unsigned char *seed_key PLENGTH(seed_key_length),
- unsigned int seed_key_length);
-#define os_perso_derive_node_bip32_seed_key(mode, curve, path, pathLength, \
- privateKey, chain, seed_key, \
- seed_key_length) \
- os_perso_derive_node_with_seed_key(mode, curve, path, pathLength, \
- privateKey, chain, seed_key, \
- seed_key_length)
-
-/**
- * Generate a seed based cookie
- * seed => derivation (path 0xda7aba5e/0xc1a551c5) => priv key =SECP256K1=>
- * pubkey => sha512 => cookie
- */
-SYSCALL unsigned int
-os_perso_seed_cookie(unsigned char *seed_cookie PLENGTH(seed_cookie_length),
- unsigned int seed_cookie_length);
-
-// endorsement APIs
-SYSCALL unsigned int
-os_endorsement_get_code_hash(unsigned char *buffer PLENGTH(32));
-SYSCALL unsigned int
-os_endorsement_get_public_key(unsigned char index,
- unsigned char *buffer PLENGTH(65));
-SYSCALL unsigned int os_endorsement_get_public_key_certificate(
- unsigned char index,
- unsigned char *buffer PLENGTH(1 + 1 + 2 * (1 + 1 + 33)));
-SYSCALL unsigned int
-os_endorsement_key1_get_app_secret(unsigned char *buffer PLENGTH(64));
-SYSCALL unsigned int os_endorsement_key1_sign_data(
- unsigned char *src PLENGTH(srcLength), unsigned int srcLength,
- unsigned char *signature PLENGTH(1 + 1 + 2 * (1 + 1 + 33)));
-SYSCALL unsigned int os_endorsement_key2_derive_sign_data(
- unsigned char *src PLENGTH(srcLength), unsigned int srcLength,
- unsigned char *signature PLENGTH(1 + 1 + 2 * (1 + 1 + 33)));
-
-// nvram shared zone access right => MPU opening at application switch, using a
-// flags in the registry
-
-// Global PIN
-#define DEFAULT_PIN_RETRIES 3
-/*
- * @return BOLOS_UX_OK if pin validated
- */
-SYSCALL bolos_bool_t os_global_pin_is_validated(void);
-/**
- * Validating the pin also setup the identity linked with this pin (normal or
- * alternate)
- * @return BOLOS_UX_OK if pin validated
- */
-SYSCALL PERMISSION(APPLICATION_FLAG_GLOBAL_PIN) bolos_bool_t
- os_global_pin_check(unsigned char *pin_buffer PLENGTH(pin_length),
- unsigned char pin_length);
-SYSCALL
- PERMISSION(APPLICATION_FLAG_GLOBAL_PIN) void os_global_pin_invalidate(void);
-SYSCALL PERMISSION(
- APPLICATION_FLAG_GLOBAL_PIN) unsigned int os_global_pin_retries(void);
-
-SYSCALL
- PERMISSION(APPLICATION_FLAG_BOLOS_UX) unsigned int os_registry_count(void);
-// return any entry, activated or not, enabled or not, empty or not. to enable
-// full control
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_registry_get(
- unsigned int index,
- application_t *out_application_entry PLENGTH(sizeof(application_t)));
-
-// return !0 when ux scenario has ended, else 0
-// while not ended, all display/touch/ticker and other events are to be
-// processed by the ux. only io is not processed. when returning !0 the
-// application must send a general status (or continue its command flow)
-SYSCALL TASKSWITCH unsigned int
-os_ux(bolos_ux_params_t *params PLENGTH(sizeof(bolos_ux_params_t)));
-// read parameters back from the UX app. useful to read keyboard type or such
-SYSCALL void
-os_ux_result(bolos_ux_params_t *params PLENGTH(sizeof(bolos_ux_params_t)));
-// Read the last os_ux call parameters from within the UX app. to make easier
-// the firewalling between tasks.
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_ux_read_parameters(
- bolos_ux_params_t *params PLENGTH(sizeof(bolos_ux_params_t)));
-
-// process all possible messages while waiting for a ux to finish,
-// unprocessed messages are replied with a generic general status
-// when returning the application must send a general status (or continue its
-// command flow)
-unsigned int os_ux_blocking(bolos_ux_params_t *params);
-
-/* ----------------------------------------------------------------------- */
-/* - LIB FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-/**
- * Library call function.
- * call_parameters[0] = library name string pointer (const)
- * call_parameters[1] = library call identifier (0 = init, ...)
- * call_parameters[2+] = called function parameters
- */
-SYSCALL void
-os_lib_call(unsigned int *call_parameters PLENGTH(3 * sizeof(unsigned int)));
-SYSCALL void os_lib_end(void);
-SYSCALL void os_lib_throw(unsigned int exception);
-
-/* ----------------------------------------------------------------------- */
-/* - ID FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-#define OS_FLAG_RECOVERY 1
-#define OS_FLAG_SIGNED_MCU_CODE 2
-#define OS_FLAG_ONBOARDED 4
-#define OS_FLAG_PIN_VALIDATED 128
-//#define OS_FLAG_CUSTOM_UX 4
-/* Enable application to retrieve OS current running options */
-SYSCALL PERMISSION(APPLICATION_FLAG_NONE) unsigned int os_flags(void);
-SYSCALL unsigned int os_version(unsigned char *version PLENGTH(maxlength),
- unsigned int maxlength);
-/* Grab the SE serial number */
-SYSCALL unsigned int os_serial(unsigned char *serial PLENGTH(maxlength),
- unsigned int maxlength);
-#ifdef TARGET_NANOX
-/* Grab the SEPROXYHAL's MCU serial number */
-SYSCALL unsigned int os_seph_serial(unsigned char *serial PLENGTH(maxlength),
- unsigned int maxlength);
-#endif // TARGET_NANOX
-/* Grab the SEPROXYHAL's feature set */
-SYSCALL unsigned int os_seph_features(void);
-/* Grab the SEPROXYHAL's version */
-SYSCALL unsigned int os_seph_version(unsigned char *version PLENGTH(maxlength),
- unsigned int maxlength);
-SYSCALL unsigned int
-os_bootloader_version(unsigned char *version PLENGTH(maxlength),
- unsigned int maxlength);
-
-/*
- * Copy the serial number in the given buffer and return its length
- */
-unsigned int os_get_sn(unsigned char *buffer);
-
-/* ----------------------------------------------------------------------- */
-/* - SETTINGS FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-typedef enum os_setting_e {
- OS_SETTING_BRIGHTNESS,
- OS_SETTING_INVERT,
- OS_SETTING_ROTATION,
-#ifdef HAVE_BOLOS_NOT_SHUFFLED_PIN
- OS_SETTING_NOSHUFFLE_PIN,
-#endif // HAVE_BOLOS_NOT_SHUFFLED_PIN
- OS_SETTING_AUTO_LOCK_DELAY,
- OS_SETTING_POWER_OFF_DELAY,
-
- OS_SETTING_PLANEMODE,
-
- // default off
- OS_SETTING_PRIVACY_MODE,
-
- // before that value, all settings are only making use of the length value
- // with a null buffer to be set, and are returned through the return value
- // with a maxlength = 0 in the get.
- OS_SETTING_LAST_INT,
-
- // screen saver string to display
- OS_SETTING_SAVER_STRING = OS_SETTING_LAST_INT,
- OS_SETTING_DEVICENAME,
- OS_SETTING_BLEMACADR,
-
- OS_SETTING_LAST,
-} os_setting_t;
-
-/**
- * Retrieve the value of a setting in a user specified buffer, with a max
- * length, and return the effective returned length.
- */
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_SETTINGS) unsigned int os_setting_get(
- unsigned int setting_id, unsigned char *value PLENGTH(maxlen),
- unsigned int maxlen);
-
-/**
- * Define a setting's value from a user buffer and its length. In case of error,
- * a throw is executed.
- */
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_SETTINGS) void os_setting_set(
- unsigned int setting_id, unsigned char *value PLENGTH(length),
- unsigned int length);
-
-/* ----------------------------------------------------------------------- */
-/* - DEBUG FUNCTIONS - */
-/* ----------------------------------------------------------------------- */
-void screen_printf(const char *format, ...);
-
-// emit a single byte
-void screen_printc(unsigned char const c);
-
-// redefined if string.h not included
-int snprintf(char *str, size_t str_size, const char *format, ...);
-
-#ifndef PRINTF
-#define PRINTF(...)
-#endif
-
-// syscall test
-// SYSCALL void dummy_1(unsigned int* p PLENGTH(2+len+15+ len + 16 +
-// sizeof(io_send_t) + 1 ), unsigned int len);
-
-typedef struct meminfo_s {
- unsigned int free_nvram_size;
- unsigned int appMemory;
- unsigned int systemSize;
- unsigned int slots;
-} meminfo_t;
-
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_get_memory_info(
- meminfo_t *meminfo PLENGTH(sizeof(meminfo_t)));
-
-// arbitraty max size for application names.
-#define BOLOS_APPNAME_MAX_SIZE_B 32
-
-// read from the application's install parameter TLV (if present), else 0 is
-// returned (no exception thrown). takes into account the currently loaded
-// application
-#define OS_REGISTRY_GET_TAG_OFFSET_COMPARE_WITH_BUFFER (0x80000000UL)
-#define OS_REGISTRY_GET_TAG_OFFSET_GET_LENGTH (0x40000000UL)
-
-/**
- * @param appidx The application entry index in the registry (raw, not filtering
- * ux or whatever). If the entry index correspond to the application being
- * installed then RAM structure content is used instead of the NVRAM registry.
- * @param tlvoffset The offset within the install parameters memory area, in
- * bytes. Useful if tag is present multiple times. Can be null. The tlv offset
- * is the offset of the tag in the install parameters area when a tag is
- * matched. This way long tag can be read in multiple time without the need to
- * play with the tlvoffset. Add +1 to skip to the next one when seraching for
- * multiple tag occurences.
- * @param tag The tag to be searched for
- * @param value_offset The offset within the value for this occurence of the
- * tag. The OS_REGISTRY_GET_TAG_OFFSET_COMPARE_WITH_BUFFER or
- * OS_REGISTRY_GET_TAG_OFFSET_GET_LENGTH can be ORed to perform meta operation
- * on the TLV occurence.
- * @param buffer The user buffer for comparison or to retrieve the value of the
- * tag at the given offset.
- * @param maxlength Size of the buffer to be compared OR to be retrieved
- * (trimmed depending the TLV effective length).
- */
-SYSCALL PERMISSION(APPLICATION_FLAG_BOLOS_UX) unsigned int os_registry_get_tag(
- unsigned int appidx, unsigned int *tlvoffset, unsigned int tag,
- unsigned int value_offset, void *buffer PLENGTH(maxlength),
- unsigned int maxlength);
-
-// Copy the currently running application tag from its install parameters to the
-// given user buffer. Only APPNAME/APPVERSION/DERIVEPATH/ICON tags are
-// retrievable to avoid install parameters private information. Warning: this
-// function returns tag content of the application lastly scheduled to run, not
-// the tag content of the currently executed piece of code (libraries subcalls)
-SYSCALL unsigned int
-os_registry_get_current_app_tag(unsigned int tag,
- unsigned char *buffer PLENGTH(maxlen),
- unsigned int maxlen);
-
-#ifndef HAVE_BOLOS_NO_CUSTOMCA
-/* ----------------------------------------------------------------------- */
-/* - CUSTOM CERTIFICATE AUTHORITY - */
-/* ----------------------------------------------------------------------- */
-
-// Verify the signature is issued from the custom certificate authority
-SYSCALL unsigned int
-os_customca_verify(unsigned char *hash PLENGTH(32),
- unsigned char *sign PLENGTH(sign_length),
- unsigned int sign_length);
-#endif // HAVE_BOLOS_NO_CUSTOMCA
-
-/* ----------------------------------------------------------------------- */
-/* - PRECISE WATCHDOG - */
-/* ----------------------------------------------------------------------- */
-
-#ifndef BOLOS_SECURITY_BOOT_DELAY_H
-#ifdef BOLOS_RELEASE
-// Boot delay before wiping the fault detection counter
-#define BOLOS_SECURITY_BOOT_DELAY_H 5
-#else // BOLOS_RELEASE
-#define BOLOS_SECURITY_BOOT_DELAY_H 1 - (60 * 60 * 100) + 15 * 100
-#endif // BOLOS_RELEASE
-#endif // BOLOS_SECURITY_BOOT_DELAY_H
-#ifndef BOLOS_SECURITY_ONBOARD_DELAY_S
-#ifdef BOLOS_RELEASE
-// Minimal time for an onboard
-#define BOLOS_SECURITY_ONBOARD_DELAY_S (2 * 60)
-#else // BOLOS_RELEASE
-// small overhead in dev
-#define BOLOS_SECURITY_ONBOARD_DELAY_S 5
-#endif // BOLOS_RELEASE
-#endif // BOLOS_SECURITY_ONBOARD_DELAY_S
-
-#ifndef BOLOS_SECURITY_ATTESTATION_DELAY_S
-// Minimal time interval in between two use of the device's private key (SCP
-// opening and endorsement)
-#define BOLOS_SECURITY_ATTESTATION_DELAY_S 5
-#endif // BOLOS_SECURITY_ATTESTATION_DELAY_S
-
-void safe_desynch();
-#define SAFE_DESYNCH() safe_desynch()
-
-typedef enum {
- /* Watchdog consumption lead to no action being taken, overflowed value is
- accounted and can be retrieved by the application */
- OS_WATCHDOG_NOACTION = 0,
- /* Request a platform reset when the watchdog set value is completely consumed
- */
- OS_WATCHDOG_RESET = 1,
- /* Request a wipe of the user data when the watchdog times out */
- OS_WATCHDOG_WIPE = 2,
-} os_watchdog_behavior_t;
-
-/**
- * This function arm a low level watchdog, when the value is consumed, and
- * depending on the requested behavior, an action can be taken.
- * @throw INVALID_PARAMETER when the useconds value overflows the possible
- * value.
- */
-void os_watchdog_arm(unsigned int useconds, os_watchdog_behavior_t behavior);
-
-/**
- * This function returns the number of useconds to be still consumed by the
- * watchdog (when > 0), or the overflowed useconds after the watchdog has timed
- * out (when < 0)
- */
-int os_watchdog_value(void);
-
-enum task_unsecure_id_e {
- TASK_BOLOS = 0, // can call os
- TASK_SYSCALL, // can call os
- TASK_USERTASKS_START,
- // disabled for now // TASK_USER_UX, // must call syscalls to reach os, locked
- // in ux ram
- TASK_USER =
- TASK_USERTASKS_START, // must call syscalls to reach os, locked in app ram
- TASK_SUBTASKS_START,
- TASK_SUBTASK_0 = TASK_SUBTASKS_START,
-#ifdef TARGET_NANOX
- TASK_SUBTASK_1,
- TASK_SUBTASK_2,
- TASK_SUBTASK_3,
-#endif // TARGET_NANOX
- TASK_BOLOS_UX,
- TASK_MAXCOUNT, // must be last in the structure
-};
-
-// execute the given application index in the registry, this function kills the
-// current app task
-SYSCALL TASKSWITCH PERMISSION(APPLICATION_FLAG_BOLOS_UX) void os_sched_exec(
- unsigned int application_index);
-// exit the current task
-SYSCALL PERMISSION(APPLICATION_FLAG_NONE) void os_sched_exit(
- bolos_task_status_t exit_code);
-
-// returns true when the given task is running, false else.
-SYSCALL bolos_bool_t os_sched_is_running(unsigned int task_idx);
-
-/**
- * Retrieve the last status issued by a task using either yield or exit.
- */
-SUDOCALL PERMISSION(APPLICATION_FLAG_NONE) bolos_task_status_t
- os_sched_last_status(unsigned int task_idx);
-bolos_task_status_t svc_os_sched_last_status(unsigned int task_idx);
-
-/**
- * Current task is yielding the process to another task.
- * Meta call for task_switch with 'the enxt' task idx.
- * @param status is the current task status
- */
-SUDOCALL TASKSWITCH PERMISSION(APPLICATION_FLAG_NONE) void os_sched_yield(
- bolos_task_status_t status);
-void svc_os_sched_yield(bolos_task_status_t status);
-
-/**
- * Perform task switching
- * @param registry_app_idx is the application registry index to switch into
- * @param status of the currently executed task
- * @return the status of the previously running task
- */
-SUDOCALL TASKSWITCH PERMISSION(APPLICATION_FLAG_NONE) void os_sched_switch(
- unsigned int task_idx, bolos_task_status_t status);
-void svc_os_sched_switch(unsigned int task_idx, bolos_task_status_t status);
-
-/**
- * Function that returns the currently running task identifier.
- */
-SUDOCALL
- PERMISSION(APPLICATION_FLAG_NONE) unsigned int os_sched_current_task(void);
-unsigned int svc_os_sched_current_task(void);
-
-/**
- * Create a new task with the given parameters and return its task identifier.
- * The newly created task is chrooted in the given nvram/ram1/ram2 segments
- * and its task pointer is set at the end of ram1 segment.
- * The task is bound to the currently running application.
- * The task identifiers are not garanteed to be the same after a power cycle.
- * At least valid main, nvram segment, ram0 segment and stack segment must be
- * provided with.
- * @param permissions to give to the task, permissions is a AND mask with the
- * application's installation flags (can only reduce scope, never grant more).
- * @param main The main function address to start the task with.
- * @param nvram The nvram segment address start
- * @param nvram_length The nvram segment length
- * @param ram0 /ram0_length the first RAM segment description
- * @param ram1 /ram1_length the second RAM segment description
- * @param stack /stack_length the task's stack RAM segment description
- */
-SYSCALL unsigned int
-os_sched_create(unsigned int permissions, void *main,
- void *nvram PLENGTH(nvram_length), unsigned int nvram_length,
- void *ram0 PLENGTH(ram0_length), unsigned int ram0_length,
- void *ram1 PLENGTH(ram1_length), unsigned int ram1_length,
- void *stack PLENGTH(stack_length), unsigned int stack_length);
-
-// kill a task
-SYSCALL void os_sched_kill(unsigned int taskidx);
-
-#ifdef HAVE_BAGL
-#ifdef TARGET_NANOX
-// SYSCALL void screen_write_frame(unsigned char* framebuffer
-// PLENGTH(BAGL_WIDTH*BAGL_HEIGHT/8));
-/**
- * Initialize the screen driver and blank the screen.
- */
-void screen_init(void);
-/**
- * Blank the screen buffer but don't update the screen driver just yet.
- */
-SYSCALL void screen_clear(void);
-/**
- * Require the screen buffer to be pushed into the screen driver.
- */
-SYSCALL void screen_update(void);
-/**
- * Require a specific zone not to be cleared/drawn by any graphic HAL to
- * implement screen overlay
- */
-SYSCALL void screen_set_keepout(unsigned int x, unsigned int y,
- unsigned int width, unsigned int height);
-/**
- * Draw the given bitmap, with the given colors and position into the screen
- * buffer. Don't update the screen driver.
- */
-SYSCALL void bagl_hal_draw_bitmap_within_rect(
- int x, int y, unsigned int width, unsigned int height,
- unsigned int color_count,
- const unsigned int *colors PLENGTH(color_count * 4),
- unsigned int bit_per_pixel,
- const unsigned char *bitmap PLENGTH(1 + bitmap_length_bits / 8),
- unsigned int bitmap_length_bits);
-/**
- * Fill a rectangle with a given color in the screen buffer, but don't update
- * the screen driver.
- */
-SYSCALL void bagl_hal_draw_rect(unsigned int color, int x, int y,
- unsigned int width, unsigned int height);
-#endif // TARGET_NANOX
-#endif // HAVE_BAGL
-
-#ifdef HAVE_TINY_COROUTINE
-
-/* ----------------------------------------------------------------------- */
-/* - CO ROUTINES - */
-/* ----------------------------------------------------------------------- */
-
-/**
- * Coroutine entry function. Called when the task is run first
- */
-typedef void (*tcr_entry_function_t)(void);
-
-void tcr_init(void);
-
-#define TCR_FLAG_PRIORITY_MAX 0x0
-#define TCR_FLAG_PRIORITY_MIN 0xF
-void tcr_add(unsigned int priority, unsigned int stack_ptr,
- unsigned int stack_size, tcr_entry_function_t coroutine_entry);
-void tcr_harakiri(void);
-void tcr_yield(void);
-void tcr_start(void);
-
-#endif // HAVE_TINY_COROUTINE
-
-/* ----------------------------------------------------------------------- */
-/* - HELPERS - */
-/* ----------------------------------------------------------------------- */
-
-#define OS_PARSE_BERTLV_OFFSET_COMPARE_WITH_BUFFER 0x80000000UL
-#define OS_PARSE_BERTLV_OFFSET_GET_LENGTH 0x40000000UL
-
-unsigned int os_parse_bertlv(unsigned char *mem, unsigned int mem_len,
- unsigned int *tlv_instance_offset,
- unsigned int tag, unsigned int offset,
- void **buffer, unsigned int maxlength);
-
-#ifdef BOLOS_DEBUG
-#ifdef TARGET_NANOX
-SYSCALL void trigger_gpio3(unsigned int val);
-SUDOCALL void l(char *fmt, unsigned int i);
-#endif // TARGET_NANOX
-#endif // BOLOS_DEBUG
-
-/* ----------------------------------------------------------------------- */
-/* - I/O I2C - */
-/* ----------------------------------------------------------------------- */
-
-#ifdef HAVE_IO_I2C
-
-#define IO_I2C_SPEED_STD 0
-#define IO_I2C_SPEED_FAST 1
-#define IO_I2C_SPEED_FASTPLUS 2
-#define IO_I2C_SPEED_HS 3
-#define IO_I2C_MASTER 0x80
-/**
- * Configure the I2C peripheral.
- * @param speed_and_master enables to set the bus speed. And to select if the
- * peripheral will act as master (issuing Start and Stop condition upon need) or
- * slave mode.
- * @param address In master mode, this parameter sets the target I2C device's
- * address. In slave mode, the address is the desired I2C bus address for the
- * interface. The address is always a 7bit address (excluding the transfer
- * direction bit).
- */
-SYSCALL void io_i2c_setmode(unsigned int speed_and_master,
- unsigned int address);
-
-/**
- * Setup the I2C peripheral for:
- * - In slave mode, receiving a WRITE transaction of maxlength bytes at most.
- * Upon WRITE transaction end, an SEPROXYHAL_TAG_I2C_EVENT is issued with the
- * received data. It has to be received through ::io_seph_recv.
- * - In master mode, this call is nop.
- */
-SYSCALL void io_i2c_prepare(unsigned int maxlength);
-
-#define IO_I2C_FLAGS_READ 0
-#define IO_I2C_FLAGS_WRITE 1
-#define IO_I2C_FLAGS_START 2
-#define IO_I2C_FLAGS_STOP 4
-/**
- * Request to execute a transfer:
- * - In slave mode, this call is non-blocking. It only enables to reply to a
- * READ transaction of at most length bytes. After the Stop condition is issued
- * from the master, a SEPROXYHAL_TAG_I2C_EVENT event containing the effectively
- * transferred length is issued and can be retrieved through ::io_seph_recv. To
- * restart or continue the transfer requires another call to ::io_i2c_xfer.
- * - In master mode, this call is blocking and triggers the transaction as
- * requested through the flags parameter. The READ or WRITE transaction will
- * place or transmit data from the given buffer and length. Depending on the
- * passed start/stop flags, corresponding bus condition are executed.
- */
-SYSCALL void io_i2c_xfer(void *buffer PLENGTH(length), unsigned int length,
- unsigned int flags);
-
-#ifndef BOLOS_RELEASE
-SYSCALL void io_i2c_dumpstate(void);
-#endif // BOLOS_RELEASE
-
-
-#ifndef SYSCALL_GENERATE
-// #include "syscalls.h"
-#endif // SYSCALL_GENERATE
-
-#endif // OS_H
diff --git a/unit-tests/test_check_merkle_tree_sorted.c b/unit-tests/test_check_merkle_tree_sorted.c
index 9b32227..af014c2 100644
--- a/unit-tests/test_check_merkle_tree_sorted.c
+++ b/unit-tests/test_check_merkle_tree_sorted.c
@@ -19,8 +19,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "handler/lib/check_merkle_tree_sorted.h"
diff --git a/unit-tests/test_extract_bip32_derivation.c b/unit-tests/test_extract_bip32_derivation.c
index 9bc0fc6..8ebdf2a 100644
--- a/unit-tests/test_extract_bip32_derivation.c
+++ b/unit-tests/test_extract_bip32_derivation.c
@@ -19,7 +19,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
#include "psbt_parse.h"
#include "client_commands.h"
diff --git a/unit-tests/test_get_merkle_leaf_element.c b/unit-tests/test_get_merkle_leaf_element.c
index f645925..37f0670 100644
--- a/unit-tests/test_get_merkle_leaf_element.c
+++ b/unit-tests/test_get_merkle_leaf_element.c
@@ -17,8 +17,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "handler/lib/get_merkle_leaf_element.h"
diff --git a/unit-tests/test_get_merkle_leaf_hash.c b/unit-tests/test_get_merkle_leaf_hash.c
index 0bed261..0127680 100644
--- a/unit-tests/test_get_merkle_leaf_hash.c
+++ b/unit-tests/test_get_merkle_leaf_hash.c
@@ -16,8 +16,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "handler/lib/get_merkle_leaf_hash.h"
@@ -25,7 +23,7 @@
/* ---------- Helpers ---------- */
static void compute_sha256(const uint8_t *data, size_t len, uint8_t out[32]) {
- calc_sha_256(out, data, len);
+ cx_hash_sha256(data, len, out, 32);
}
/**
diff --git a/unit-tests/test_get_merkle_leaf_index.c b/unit-tests/test_get_merkle_leaf_index.c
index 9836aa2..b985640 100644
--- a/unit-tests/test_get_merkle_leaf_index.c
+++ b/unit-tests/test_get_merkle_leaf_index.c
@@ -17,8 +17,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "handler/lib/get_merkle_leaf_index.h"
@@ -26,7 +24,7 @@
/* ---------- Helpers ---------- */
static void compute_sha256(const uint8_t *data, size_t len, uint8_t out[32]) {
- calc_sha_256(out, data, len);
+ cx_hash_sha256(data, len, out, 32);
}
/**
diff --git a/unit-tests/test_get_merkle_preimage.c b/unit-tests/test_get_merkle_preimage.c
index ed9111d..8af8580 100644
--- a/unit-tests/test_get_merkle_preimage.c
+++ b/unit-tests/test_get_merkle_preimage.c
@@ -17,8 +17,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "handler/lib/get_merkle_preimage.h"
@@ -26,7 +24,7 @@
/* ---------- Helpers ---------- */
static void compute_sha256(const uint8_t *data, size_t len, uint8_t out[32]) {
- calc_sha_256(out, data, len);
+ cx_hash_sha256(data, len, out, 32);
}
/**
diff --git a/unit-tests/test_get_merkleized_map.c b/unit-tests/test_get_merkleized_map.c
index f962549..b29fc78 100644
--- a/unit-tests/test_get_merkleized_map.c
+++ b/unit-tests/test_get_merkleized_map.c
@@ -22,8 +22,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "buffer.h"
#include "varint.h"
diff --git a/unit-tests/test_get_merkleized_map_value.c b/unit-tests/test_get_merkleized_map_value.c
index d837874..d0f918f 100644
--- a/unit-tests/test_get_merkleized_map_value.c
+++ b/unit-tests/test_get_merkleized_map_value.c
@@ -19,8 +19,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "common/merkle.h"
diff --git a/unit-tests/test_get_preimage.c b/unit-tests/test_get_preimage.c
index 26004c0..841dacb 100644
--- a/unit-tests/test_get_preimage.c
+++ b/unit-tests/test_get_preimage.c
@@ -17,8 +17,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "handler/lib/get_preimage.h"
@@ -26,7 +24,7 @@
/* ---------- Helpers ---------- */
static void compute_sha256(const uint8_t *data, size_t len, uint8_t out[32]) {
- calc_sha_256(out, data, len);
+ cx_hash_sha256(data, len, out, 32);
}
/* ---------- Test cases ---------- */
diff --git a/unit-tests/test_stream_merkle_leaf_element.c b/unit-tests/test_stream_merkle_leaf_element.c
index bd45859..de6e4f1 100644
--- a/unit-tests/test_stream_merkle_leaf_element.c
+++ b/unit-tests/test_stream_merkle_leaf_element.c
@@ -17,8 +17,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "handler/lib/stream_merkle_leaf_element.h"
diff --git a/unit-tests/test_stream_merkleized_map_value.c b/unit-tests/test_stream_merkleized_map_value.c
index ad5257c..a5be735 100644
--- a/unit-tests/test_stream_merkleized_map_value.c
+++ b/unit-tests/test_stream_merkleized_map_value.c
@@ -17,8 +17,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "handler/lib/stream_merkleized_map_value.h"
diff --git a/unit-tests/test_stream_preimage.c b/unit-tests/test_stream_preimage.c
index 2699103..1a78c06 100644
--- a/unit-tests/test_stream_preimage.c
+++ b/unit-tests/test_stream_preimage.c
@@ -18,8 +18,6 @@
#include <cmocka.h>
#include "mock_dispatcher.h"
-#include "cx_hash_mock.h"
-#include "sha-256.h"
#include "client_commands.h"
#include "handler/lib/stream_preimage.h"
@@ -27,7 +25,7 @@
/* ---------- Helpers ---------- */
static void compute_sha256(const uint8_t *data, size_t len, uint8_t out[32]) {
- calc_sha_256(out, data, len);
+ cx_hash_sha256(data, len, out, 32);
}
/**
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.