Skip to content

Commit

Permalink
Merge pull request #114 from LedgerHQ/xch/improve-cx-hash
Browse files Browse the repository at this point in the history
src: Use new SDK function cx_keccak_256_hash
  • Loading branch information
xchapron-ledger authored Feb 21, 2024
2 parents 7b8c85b + 2307134 commit 6061f31
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,14 @@

bool address_from_pubkey(const uint8_t public_key[static 65], uint8_t *out, size_t out_len) {
uint8_t address[32] = {0};
cx_sha3_t keccak256;

LEDGER_ASSERT(out != NULL, "NULL out");

if (out_len < ADDRESS_LEN) {
return false;
}

if (cx_keccak_init_no_throw(&keccak256, 256) != CX_OK) {
return false;
}

if (cx_hash_no_throw((cx_hash_t *) &keccak256,
CX_LAST,
public_key + 1,
64,
address,
sizeof(address)) != CX_OK) {
if (cx_keccak_256_hash(public_key + 1, 64, address) != CX_OK) {
return false;
}

Expand Down
15 changes: 3 additions & 12 deletions src/handler/sign_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,9 @@ int handler_sign_tx(buffer_t *cdata, uint8_t chunk, bool more) {

G_context.state = STATE_PARSED;

cx_sha3_t keccak256;

if (cx_keccak_init_no_throw(&keccak256, 256) != CX_OK) {
return io_send_sw(SW_TX_HASH_FAIL);
}

if (cx_hash_no_throw((cx_hash_t *) &keccak256,
CX_LAST,
G_context.tx_info.raw_tx,
G_context.tx_info.raw_tx_len,
G_context.tx_info.m_hash,
sizeof(G_context.tx_info.m_hash)) != CX_OK) {
if (cx_keccak_256_hash(G_context.tx_info.raw_tx,
G_context.tx_info.raw_tx_len,
G_context.tx_info.m_hash) != CX_OK) {
return io_send_sw(SW_TX_HASH_FAIL);
}

Expand Down

0 comments on commit 6061f31

Please sign in to comment.