Skip to content

Commit

Permalink
Fix cx_hash_no_throw return value
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Nov 23, 2023
1 parent 3103ca2 commit 2427ecb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/xrp/xrp_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,16 @@ void xrp_public_key_hash160(xrp_pubkey_t *pubkey, uint8_t *out) {
cx_ripemd160_t riprip;
} u;
uint8_t buffer[32];
cx_err_t error = CX_INTERNAL_ERROR;

cx_sha256_init(&u.shasha);
cx_hash_no_throw(&u.shasha.header, CX_LAST, pubkey->buf, sizeof(pubkey->buf), buffer, 32);
error =
cx_hash_no_throw(&u.shasha.header, CX_LAST, pubkey->buf, sizeof(pubkey->buf), buffer, 32);
if (error != CX_OK) return;
cx_ripemd160_init(&u.riprip);
cx_hash_no_throw(&u.riprip.header, CX_LAST, buffer, 32, out, 20);
// Make scan-build happy
if (error != CX_OK) return;
}

size_t xrp_public_key_to_encoded_base58(xrp_pubkey_t *pubkey,
Expand All @@ -99,6 +104,7 @@ size_t xrp_public_key_to_encoded_base58(xrp_pubkey_t *pubkey,
unsigned char checksum_buffer[32];
cx_sha256_t hash;
unsigned char version_size = (version > 255 ? 2 : 1);
cx_err_t error = CX_INTERNAL_ERROR;

if (version > 255) {
tmp.buf[0] = (version >> 8u);
Expand All @@ -115,9 +121,12 @@ size_t xrp_public_key_to_encoded_base58(xrp_pubkey_t *pubkey,
}

cx_sha256_init(&hash);
cx_hash_no_throw(&hash.header, CX_LAST, tmp.buf, 20 + version_size, checksum_buffer, 32);
error =
cx_hash_no_throw(&hash.header, CX_LAST, tmp.buf, 20 + version_size, checksum_buffer, 32);
if (error != CX_OK) return 0;
cx_sha256_init(&hash);
cx_hash_no_throw(&hash.header, CX_LAST, checksum_buffer, 32, checksum_buffer, 32);
error = cx_hash_no_throw(&hash.header, CX_LAST, checksum_buffer, 32, checksum_buffer, 32);
if (error != CX_OK) return 0;

memmove(tmp.buf + 20 + version_size, checksum_buffer, 4);
tmp.length = 24 + version_size;
Expand Down

0 comments on commit 2427ecb

Please sign in to comment.