From f58ec316eb33a109875d16672c6f46477a385315 Mon Sep 17 00:00:00 2001 From: Sarah GLINER Date: Tue, 5 Dec 2023 10:26:38 +0100 Subject: [PATCH] clean: add LEDGER_ASSERT to handle errors --- src/btchip_apdu_hash_sign.c | 7 ++++--- src/btchip_helpers.c | 3 ++- src/btchip_transaction.c | 11 ++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/btchip_apdu_hash_sign.c b/src/btchip_apdu_hash_sign.c index 8e006af9..286fd1b7 100644 --- a/src/btchip_apdu_hash_sign.c +++ b/src/btchip_apdu_hash_sign.c @@ -20,6 +20,7 @@ #include "btchip_bagl_extensions.h" #include "btchip_display_variables.h" #include "ui.h" +#include "ledger_assert.h" #define SIGHASH_ALL 0x01 @@ -169,11 +170,11 @@ void btchip_bagl_user_action_signtx(unsigned char confirming, unsigned char dire if (confirming) { unsigned char hash[32]; if (btchip_context_D.usingOverwinter) { - cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, CX_LAST, hash, 0, hash, 32); + LEDGER_ASSERT(cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, CX_LAST, hash, 0, hash, 32) == CX_OK, "Hash Failed"); } else { - cx_hash_no_throw(&btchip_context_D.transactionHashFull.sha256.header, CX_LAST, - hash, 0, hash, 32); + LEDGER_ASSERT(cx_hash_no_throw(&btchip_context_D.transactionHashFull.sha256.header, CX_LAST, + hash, 0, hash, 32) == CX_OK, "Hash Failed"); PRINTF("Hash1\n%.*H\n", sizeof(hash), hash); // Rehash diff --git a/src/btchip_helpers.c b/src/btchip_helpers.c index 343ce74d..bbc020c8 100644 --- a/src/btchip_helpers.c +++ b/src/btchip_helpers.c @@ -19,6 +19,7 @@ #include "btchip_apdu_constants.h" #include "lib_standard_app/crypto_helpers.h" #include "bip32_path.h" +#include "ledger_assert.h" const unsigned char TRANSACTION_OUTPUT_SCRIPT_PRE[] = { 0x19, 0x76, 0xA9, @@ -215,7 +216,7 @@ void btchip_public_key_hash160(unsigned char *in, unsigned short inlen, unsigned char buffer[32]; cx_hash_sha256(in, inlen, buffer, 32); cx_ripemd160_init(&riprip); - cx_hash_no_throw(&riprip.header, CX_LAST, buffer, 32, out, 20); + LEDGER_ASSERT(cx_hash_no_throw(&riprip.header, CX_LAST, buffer, 32, out, 20) == CX_OK, "hash160"); } void btchip_compute_checksum(unsigned char* in, unsigned short inlen, unsigned char * output) { diff --git a/src/btchip_transaction.c b/src/btchip_transaction.c index 9cd29e61..f15fe553 100644 --- a/src/btchip_transaction.c +++ b/src/btchip_transaction.c @@ -18,6 +18,7 @@ #include "btchip_internal.h" #include "btchip_apdu_constants.h" #include "btchip_display_variables.h" +#include "ledger_assert.h" #define CONSENSUS_BRANCH_ID_OVERWINTER 0x5ba81b19 #define CONSENSUS_BRANCH_ID_SAPLING 0x76b809bb @@ -87,18 +88,18 @@ void transaction_offset(unsigned char value) { if ((btchip_context_D.transactionHashOption & TRANSACTION_HASH_FULL) != 0) { PRINTF("--- ADD TO HASH FULL:\n%.*H\n", value, btchip_context_D.transactionBufferPointer); if (btchip_context_D.usingOverwinter) { - cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, 0, btchip_context_D.transactionBufferPointer, value, NULL, 0); + LEDGER_ASSERT(cx_hash_no_throw(&btchip_context_D.transactionHashFull.blake2b.header, 0, btchip_context_D.transactionBufferPointer, value, NULL, 0) == CX_OK, "Hash Failed"); } else { - cx_hash_no_throw(&btchip_context_D.transactionHashFull.sha256.header, 0, - btchip_context_D.transactionBufferPointer, value, NULL, 0); + LEDGER_ASSERT(cx_hash_no_throw(&btchip_context_D.transactionHashFull.sha256.header, 0, + btchip_context_D.transactionBufferPointer, value, NULL, 0) == CX_OK, "Hash Failed"); } } if ((btchip_context_D.transactionHashOption & TRANSACTION_HASH_AUTHORIZATION) != 0) { PRINTF("--- ADD TO HASH AUTH:\n%.*H\n", value, btchip_context_D.transactionBufferPointer); - cx_hash_no_throw(&btchip_context_D.transactionHashAuthorization.header, 0, - btchip_context_D.transactionBufferPointer, value, NULL, 0); + LEDGER_ASSERT(cx_hash_no_throw(&btchip_context_D.transactionHashAuthorization.header, 0, + btchip_context_D.transactionBufferPointer, value, NULL, 0) == CX_OK, "Hash Failed"); } }