What changed, and why it matters
This commit is a small cleanup following a code review. It updates comments, adds safety checks to a test-only mock function, increases a test mock queue size, and adds a missing standard header include. None of the changes affect the real device firmware's security behavior.
No security action required. Treat as routine review cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff consists of six minor edits: (1) a comment correction in get_merkle_preimage.h removing an outdated 254-byte preimage limit; (2) adding null and length assertions to the unit-test-only cx_hash_sha256 mock; (3) doubling MOCK_MAX_QUEUE_ELEMS in a unit-test header; (4)-(5) adding #include
Changed components
unit-tests/libs/cx_hash_mock.cunit-tests/libs/mock_dispatcher.hunit-tests/mock_includes/lcx_hash.hunit-tests/mock_includes/lcx_sha256.hunit-tests/test_get_merkle_leaf_hash.csrc/handler/lib/get_merkle_preimage.h (comment only)Inspect captured patch +7 / −4
diff --git a/src/handler/lib/get_merkle_preimage.h b/src/handler/lib/get_merkle_preimage.h
index 7b367a0..456d2c0 100644
--- a/src/handler/lib/get_merkle_preimage.h
+++ b/src/handler/lib/get_merkle_preimage.h
@@ -8,7 +8,7 @@
* The hash is still verified over the full preimage (including the prefix byte).
*
* In this flow, the HWW sends a CCMD_GET_PREIMAGE command with a SHA256 hash.
- * The client must respond with the preimage (at most 254 bytes), prefixed by its length.
+ * The client must respond with the preimage, prefixed by its length.
* The flow fails with SW_WRONG_DATA_LENGTH if the response is too short; it will fail with
* SW_INCORRECT_DATA if the computed hash does not match.
*
diff --git a/unit-tests/libs/cx_hash_mock.c b/unit-tests/libs/cx_hash_mock.c
index 8ef68a7..3a06782 100644
--- a/unit-tests/libs/cx_hash_mock.c
+++ b/unit-tests/libs/cx_hash_mock.c
@@ -71,7 +71,8 @@ int cx_hash_sha256(const unsigned char *in,
unsigned int in_len,
unsigned char *out,
unsigned int out_len) {
- (void) out_len;
+ assert(out != NULL);
+ assert(out_len >= CX_SHA256_SIZE);
calc_sha_256(out, in, in_len);
return CX_SHA256_SIZE;
}
diff --git a/unit-tests/libs/mock_dispatcher.h b/unit-tests/libs/mock_dispatcher.h
index f2b61b5..c4203b3 100644
--- a/unit-tests/libs/mock_dispatcher.h
+++ b/unit-tests/libs/mock_dispatcher.h
@@ -31,7 +31,7 @@
#define MOCK_MAX_TREES 16
#define MOCK_MAX_TREE_ELEMS 1024
#define MOCK_MAX_YIELDED 1024
-#define MOCK_MAX_QUEUE_ELEMS 1024
+#define MOCK_MAX_QUEUE_ELEMS 2048
#define MOCK_BUF_SIZE 2048
#define MOCK_MAX_YIELDED_LEN 1024
diff --git a/unit-tests/mock_includes/lcx_hash.h b/unit-tests/mock_includes/lcx_hash.h
index 56c50c9..e7f1645 100644
--- a/unit-tests/mock_includes/lcx_hash.h
+++ b/unit-tests/mock_includes/lcx_hash.h
@@ -1,3 +1,4 @@
+#include <stddef.h>
/*******************************************************************************
* Ledger Nano S - Secure firmware
diff --git a/unit-tests/mock_includes/lcx_sha256.h b/unit-tests/mock_includes/lcx_sha256.h
index d18dd97..3401f07 100644
--- a/unit-tests/mock_includes/lcx_sha256.h
+++ b/unit-tests/mock_includes/lcx_sha256.h
@@ -1,3 +1,4 @@
+#include <stddef.h>
/*******************************************************************************
* Ledger Nano S - Secure firmware
diff --git a/unit-tests/test_get_merkle_leaf_hash.c b/unit-tests/test_get_merkle_leaf_hash.c
index b2854b3..6597ef1 100644
--- a/unit-tests/test_get_merkle_leaf_hash.c
+++ b/unit-tests/test_get_merkle_leaf_hash.c
@@ -349,7 +349,7 @@ static int tamper_corrupt_proof_hash(uint8_t *response_buf,
if (cmd == CCMD_GET_MERKLE_LEAF_PROOF && *response_len > 35) {
/* Response: <leaf_hash:32> <proof_size:1> <n_proof_elements:1> <proof_hashes...>
- * Corrupt byte in first proof hash (offset 34) */
+ * Corrupt byte in first proof hash (starting at offset 34) */
response_buf[35] ^= 0xFF;
}
return 0;
Why this scored 12/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.