From 156cf782a244b923bceba0d35a330e818c9371dc Mon Sep 17 00:00:00 2001 From: Aido Date: Sat, 27 Jan 2024 01:56:19 +0000 Subject: [PATCH] Assert HMAC return valuess --- CHANGELOG.md | 3 ++- src/nano/nanos_enter_phrase.c | 8 ++------ src/nano/nanox_enter_phrase.c | 8 ++------ src/ux_common/onboarding_seed_sskr.c | 10 +++++----- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 989b1e1d..67f7098f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ # Change log -## [1.6.1] - 2024-01-19 +## [1.6.1] - 2024-01-27 ### Added - Added a Release Policy document ### Changed - Updated version of cmocka used for unit tests - Updated version of github actions used +- Assert HMAC return values ### Fixed - Fixed failing Ledger rule enforcer check diff --git a/src/nano/nanos_enter_phrase.c b/src/nano/nanos_enter_phrase.c index 522f508f..1d3c3ba1 100644 --- a/src/nano/nanos_enter_phrase.c +++ b/src/nano/nanos_enter_phrase.c @@ -435,8 +435,8 @@ void compare_recovery_phrase(void) { cx_hmac_sha512_t ctx; const char key[] = "Bitcoin seed"; - CX_CHECK(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key))); - CX_CHECK(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64)); + CX_ASSERT(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key))); + CX_ASSERT(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64)); PRINTF("Root key from input:\n%.*H\n", 64, buffer); // get rootkey from device's seed @@ -457,10 +457,6 @@ void compare_recovery_phrase(void) { memzero(buffer, 64); memzero(buffer_device, 64); - if ((error == CX_INVALID_PARAMETER) || (error == CX_INTERNAL_ERROR)) { - PRINTF("ERROR: compare_recovery_phrase(): %d\n", error); - } - if (error != CX_OK) { (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) ? ux_flow_init(0, ux_bip39_nomatch_flow, NULL) diff --git a/src/nano/nanox_enter_phrase.c b/src/nano/nanox_enter_phrase.c index d7c9f725..987e0ebf 100644 --- a/src/nano/nanox_enter_phrase.c +++ b/src/nano/nanox_enter_phrase.c @@ -483,8 +483,8 @@ static uint8_t compare_recovery_phrase(void) { cx_hmac_sha512_t ctx; const char key[] = "Bitcoin seed"; - CX_CHECK(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key))); - CX_CHECK(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64)); + CX_ASSERT(cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key))); + CX_ASSERT(cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64)); PRINTF("Root key from BIP39 input:\n%.*H\n", 64, buffer); // get rootkey from device's seed @@ -505,10 +505,6 @@ static uint8_t compare_recovery_phrase(void) { memzero(buffer, 64); memzero(buffer_device, 64); - if ((error == CX_INVALID_PARAMETER) || (error == CX_INTERNAL_ERROR)) { - PRINTF("ERROR: compare_recovery_phrase(): %d\n", error); - } - if (error != CX_OK) { return 0; } else { diff --git a/src/ux_common/onboarding_seed_sskr.c b/src/ux_common/onboarding_seed_sskr.c index 436dbc42..acb661cb 100644 --- a/src/ux_common/onboarding_seed_sskr.c +++ b/src/ux_common/onboarding_seed_sskr.c @@ -10,9 +10,9 @@ // Return the CRC-32 checksum of the input buffer in network byte order (big endian). #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define cx_crc32_nbo(...) cx_crc32(__VA_ARGS__) +#define crc32_nbo(...) crc32(__VA_ARGS__) #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define cx_crc32_nbo(...) os_swap_u32(cx_crc32(__VA_ARGS__)) +#define crc32_nbo(...) os_swap_u32(crc32(__VA_ARGS__)) #else #error "What kind of system is this?" #endif @@ -23,7 +23,7 @@ // The following function is a temporary workaround that can be removed once cx_crc32_hw() // works on all Ledger devices -uint32_t cx_crc32(const uint8_t *data, size_t len) { +uint32_t crc32(const uint8_t *data, size_t len) { uint32_t crc = ~0; const uint8_t *end = data + len; @@ -245,7 +245,7 @@ unsigned int bolos_ux_bip39_to_sskr_convert(unsigned char *bip39_words_buffer, memcpy(cbor_share_crc_buffer + cbor_len, share_buffer + share_len * share, share_len); - checksum = cx_crc32_nbo(cbor_share_crc_buffer, cbor_len + share_len); + checksum = crc32_nbo(cbor_share_crc_buffer, cbor_len + share_len); memcpy(cbor_share_crc_buffer + cbor_len + share_len, &checksum, checksum_len); if (bolos_ux_sskr_mnemonic_encode( @@ -279,7 +279,7 @@ unsigned int bolos_ux_sskr_hex_check(unsigned char *mnemonic_hex, uint8_t checksum_len = sizeof(checksum); for (unsigned int i = 0; i < sskr_shares_count; i++) { - checksum = cx_crc32_nbo(mnemonic_hex + i * (mnemonic_length / sskr_shares_count), + checksum = crc32_nbo(mnemonic_hex + i * (mnemonic_length / sskr_shares_count), (mnemonic_length / sskr_shares_count) - checksum_len); // First 8 bytes of all shares in group should be same // Test checksum