diff --git a/CHANGELOG.md b/CHANGELOG.md index d6a9fea8..e771d328 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,21 @@ # Change log +## [1.5.5] - 2023-12-10 +### Added +- Use CX_CHECK macro in compare_recovery_phrase() + +### Changed +- + +### Fixed +- + ## [1.5.4] - 2023-11-30 ### Added - Added mandatory Ledger embedded application manifest file ### Changed -- Combined BIP39 wordlist and SSKR wordlist unit tests +- Combined BIP39 wordlist and SSKR wordlist unit tests ### Fixed - diff --git a/Makefile b/Makefile index 8a393338..58673edb 100755 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ all: default APPNAME = "Seed Tool" APPVERSION_M = 1 APPVERSION_N = 5 -APPVERSION_P = 4 +APPVERSION_P = 5 APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)" APP_LOAD_PARAMS = --appFlags 0x10 $(COMMON_LOAD_PARAMS) --curve secp256k1 --path "" diff --git a/src/nano/nanos_enter_phrase.c b/src/nano/nanos_enter_phrase.c index 04bea5fb..522f508f 100644 --- a/src/nano/nanos_enter_phrase.c +++ b/src/nano/nanos_enter_phrase.c @@ -412,8 +412,11 @@ void compare_recovery_phrase(void) { G_bolos_ux_context.processing = PROCESSING_COMPLETE; io_seproxyhal_general_status(); - // convert mnemonic to hex-seed + cx_err_t error = CX_OK; // By default, until some error occurs uint8_t buffer[64] = {0}; + uint8_t buffer_device[64] = {0}; + + // convert mnemonic to hex-seed if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) { bolos_ux_bip39_mnemonic_to_seed((unsigned char*) G_bolos_ux_context.words_buffer, G_bolos_ux_context.words_buffer_length, @@ -432,32 +435,33 @@ void compare_recovery_phrase(void) { cx_hmac_sha512_t ctx; const char key[] = "Bitcoin seed"; - cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)); - cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64); + 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)); PRINTF("Root key from input:\n%.*H\n", 64, buffer); // get rootkey from device's seed - uint8_t buffer_device[64]; - // os_derive_bip32* do not accept NULL path, even with a size of 0, so we provide an empty path const unsigned int empty_path = 0; - if (os_derive_bip32_no_throw(CX_CURVE_256K1, - &empty_path, - 0, - buffer_device, - buffer_device + 32) != CX_OK) { - PRINTF("An error occurred while comparing the recovery phrase\n"); - return; - } + CX_CHECK(os_derive_bip32_no_throw(CX_CURVE_256K1, + &empty_path, + 0, + buffer_device, + buffer_device + 32)); PRINTF("Root key from device: \n%.*H\n", 64, buffer_device); - bool memcmp_ret = (os_secure_memcmp(buffer, buffer_device, 64) == 0) ? 0 : 1; + // compare both rootkey + CX_CHECK(os_secure_memcmp(buffer, buffer_device, 64)); + +end: memzero(buffer, 64); memzero(buffer_device, 64); - // compare both rootkey - if (memcmp_ret) { + 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) : ux_flow_init(0, ux_sskr_nomatch_flow, NULL); diff --git a/src/nano/nanox_enter_phrase.c b/src/nano/nanox_enter_phrase.c index f9d76446..d7c9f725 100644 --- a/src/nano/nanox_enter_phrase.c +++ b/src/nano/nanox_enter_phrase.c @@ -460,8 +460,11 @@ const bagl_element_t* screen_onboarding_restore_word_before_element_display_call } static uint8_t compare_recovery_phrase(void) { - // convert mnemonic to hex-seed + cx_err_t error = CX_OK; // By default, until some error occurs uint8_t buffer[64] = {0}; + uint8_t buffer_device[64] = {0}; + + // convert mnemonic to hex-seed if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) { bolos_ux_bip39_mnemonic_to_seed((unsigned char*) G_bolos_ux_context.words_buffer, G_bolos_ux_context.words_buffer_length, @@ -480,31 +483,37 @@ static uint8_t compare_recovery_phrase(void) { cx_hmac_sha512_t ctx; const char key[] = "Bitcoin seed"; - cx_hmac_sha512_init_no_throw(&ctx, (const uint8_t*) key, strlen(key)); - cx_hmac_no_throw((cx_hmac_t*) &ctx, CX_LAST, buffer, 64, buffer, 64); + 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)); PRINTF("Root key from BIP39 input:\n%.*H\n", 64, buffer); // get rootkey from device's seed - uint8_t buffer_device[64]; - // os_derive_bip32* do not accept NULL path, even with a size of 0, so we provide an empty path const unsigned int empty_path = 0; - if (os_derive_bip32_no_throw(CX_CURVE_256K1, - &empty_path, - 0, - buffer_device, - buffer_device + 32) != CX_OK) { - PRINTF("An error occurred while comparing the recovery phrase\n"); - return 0; - } + CX_CHECK(os_derive_bip32_no_throw(CX_CURVE_256K1, + &empty_path, + 0, + buffer_device, + buffer_device + 32)); PRINTF("Root key from device: \n%.*H\n", 64, buffer_device); // compare both rootkey - uint8_t ret = (os_secure_memcmp(buffer, buffer_device, 64) != 0) ? 0 : 1; + CX_CHECK(os_secure_memcmp(buffer, buffer_device, 64)); + +end: memzero(buffer, 64); memzero(buffer_device, 64); - return ret; + + if ((error == CX_INVALID_PARAMETER) || (error == CX_INTERNAL_ERROR)) { + PRINTF("ERROR: compare_recovery_phrase(): %d\n", error); + } + + if (error != CX_OK) { + return 0; + } else { + return 1; + } } void screen_onboarding_restore_word_validate(void) {