Skip to content

Commit

Permalink
src: Use CX_ASSERT to fix warn-unused-result
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier Chapron committed Jan 26, 2024
1 parent 8b89471 commit ac602c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/handlers/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int handleSign(uint8_t p1, uint8_t p2, uint8_t *workBuffer, uint16_t dataLength)
return io_send_sw(E_INCORRECT_P1_P2);
}
// hash data
cx_hash_no_throw((cx_hash_t *) &txContext.sha2, 0, workBuffer, dataLength, NULL, 32);
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &txContext.sha2, 0, workBuffer, dataLength, NULL, 32));

#ifdef HAVE_SWAP
if (G_called_from_swap) {
Expand Down Expand Up @@ -180,12 +180,12 @@ int handleSign(uint8_t p1, uint8_t p2, uint8_t *workBuffer, uint16_t dataLength)
}

// Last data hash
cx_hash_no_throw((cx_hash_t *) &txContext.sha2,
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &txContext.sha2,
CX_LAST,
workBuffer,
0,
transactionContext.hash,
32);
32));

if (txContent.permission_id > 0) {
PRINTF("Set permission_id...\n");
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/sign_personal_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ int handleSignPersonalMessage(uint8_t p1, uint8_t p2, uint8_t *workBuffer, uint1
dataLength -= 4;

// Initialize message header + length
cx_keccak_init_no_throw(&sha3, 256);
cx_hash_no_throw((cx_hash_t *) &sha3,
CX_ASSERT(cx_keccak_init_no_throw(&sha3, 256));
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &sha3,
0,
(const uint8_t *) SIGN_MAGIC,
sizeof(SIGN_MAGIC) - 1,
NULL,
0);
0));

char tmp[11];
snprintf((char *) tmp, 11, "%d", (uint32_t) txContent.dataBytes);
cx_hash_no_throw((cx_hash_t *) &sha3, 0, (const uint8_t *) tmp, strlen(tmp), NULL, 0);
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &sha3, 0, (const uint8_t *) tmp, strlen(tmp), NULL, 0));

} else if (p1 != P1_MORE) {
return io_send_sw(E_INCORRECT_P1_P2);
Expand All @@ -71,10 +71,10 @@ int handleSignPersonalMessage(uint8_t p1, uint8_t p2, uint8_t *workBuffer, uint1
return io_send_sw(E_INCORRECT_LENGTH);
}

cx_hash_no_throw((cx_hash_t *) &sha3, 0, workBuffer, dataLength, NULL, 0);
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &sha3, 0, workBuffer, dataLength, NULL, 0));
txContent.dataBytes -= dataLength;
if (txContent.dataBytes == 0) {
cx_hash_no_throw((cx_hash_t *) &sha3, CX_LAST, workBuffer, 0, transactionContext.hash, 32);
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &sha3, CX_LAST, workBuffer, 0, transactionContext.hash, 32));
#ifdef HAVE_BAGL
#define HASH_LENGTH 4
format_hex(transactionContext.hash, HASH_LENGTH / 2, fullContract, sizeof(fullContract));
Expand Down
14 changes: 7 additions & 7 deletions src/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ void getAddressFromPublicKey(const uint8_t *publicKey, uint8_t address[static AD
uint8_t hashAddress[HASH_SIZE];
cx_sha3_t sha3;

cx_keccak_init_no_throw(&sha3, 256);
cx_hash_no_throw((cx_hash_t *) &sha3,
CX_LAST,
publicKey + 1,
PUBLIC_KEY_SIZE - 1,
hashAddress,
HASH_SIZE);
CX_ASSERT(cx_keccak_init_no_throw(&sha3, 256));
CX_ASSERT(cx_hash_no_throw((cx_hash_t *) &sha3,
CX_LAST,
publicKey + 1,
PUBLIC_KEY_SIZE - 1,
hashAddress,
HASH_SIZE));

memmove(address, hashAddress + 11, ADDRESS_SIZE);
address[0] = ADD_PRE_FIX_BYTE_MAINNET;
Expand Down
16 changes: 8 additions & 8 deletions src/tokens.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,10 +1576,10 @@ int verifyTokenNameID(const char *tokenId,

cx_hash_sha256(buffer, strlen(tokenId) + strlen(tokenName) + 1, hash, 32);

cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
(uint8_t *) PIC(&token_public_key),
65,
&publicKey);
CX_ASSERT(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
(uint8_t *) PIC(&token_public_key),
65,
&publicKey));

int ret = cx_ecdsa_verify_no_throw(&publicKey, hash, 32, signature, signatureLength);

Expand All @@ -1595,10 +1595,10 @@ int verifyExchangeID(const unsigned char *exchangeValidation,

cx_hash_sha256(exchangeValidation, datLength, hash, 32);

cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
(uint8_t *) PIC(&token_public_key),
65,
&publicKey);
CX_ASSERT(cx_ecfp_init_public_key_no_throw(CX_CURVE_256K1,
(uint8_t *) PIC(&token_public_key),
65,
&publicKey));

int ret = cx_ecdsa_verify_no_throw(&publicKey, hash, 32, signature, signatureLength);

Expand Down

0 comments on commit ac602c0

Please sign in to comment.