Skip to content

Commit

Permalink
use oneshot hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Mar 4, 2024
1 parent 46e3e5b commit 714937a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 24 deletions.
1 change: 0 additions & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ $(error ICONNAME is not set)
endif

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
DEFINES += HAVE_HASH HAVE_BLAKE2 HAVE_SHA256 HAVE_SHA512
CFLAGS += -I$(MY_DIR)/../deps/tinycbor/src
APP_SOURCE_PATH += $(MY_DIR)/../deps/tinycbor-ledger
APP_SOURCE_PATH += $(MY_DIR)/../deps/jsmn/src
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=35
# This is the patch version of this release
APPVERSION_P=18
APPVERSION_P=19
25 changes: 3 additions & 22 deletions app/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ static zxerr_t crypto_hashBuffer(const uint8_t *input, const uint16_t inputLen,
}

case BECH32_ETH: {
cx_sha3_t sha3 = {0};
cx_err_t status = cx_keccak_init_no_throw(&sha3, 256);
if (status != CX_OK) {
return zxerr_ledger_api_error;
}
status = cx_hash_no_throw((cx_hash_t*) &sha3, CX_LAST, input, inputLen, output, outputLen);
if (status != CX_OK) {
return zxerr_ledger_api_error;
}
CHECK_CX_OK(cx_keccak_256_hash(input, inputLen, output));
break;
}

Expand Down Expand Up @@ -163,13 +155,6 @@ zxerr_t crypto_sign(uint8_t *output,
return error;
}

static zxerr_t ripemd160_32(uint8_t *out, uint8_t *in) {
cx_ripemd160_t rip160;
CHECK_CX_OK(cx_ripemd160_init_no_throw(&rip160));
CHECK_CX_OK(cx_hash_no_throw(&rip160.header, CX_LAST, in, CX_SHA256_SIZE, out, CX_RIPEMD160_SIZE));
return zxerr_ok;
}

zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrResponseLen) {
if (buffer_len < PK_LEN_SECP256K1 + 50) {
return zxerr_buffer_too_small;
Expand All @@ -188,17 +173,13 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR
// Hash it
cx_hash_sha256(buffer, PK_LEN_SECP256K1, hashed1_pk, CX_SHA256_SIZE);
uint8_t hashed2_pk[CX_RIPEMD160_SIZE] = {0};
CHECK_ZXERR(ripemd160_32(hashed2_pk, hashed1_pk));
CHECK_CX_OK(cx_ripemd160_hash(hashed1_pk, CX_SHA256_SIZE, hashed2_pk));
CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1, BECH32_ENCODING_BECH32));
break;
}

case BECH32_ETH: {
cx_sha3_t ctx;
if (cx_keccak_init_no_throw(&ctx, 256) != CX_OK) {
return zxerr_unknown;
}
CHECK_CX_OK(cx_hash_no_throw((cx_hash_t *)&ctx, CX_LAST, uncompressedPubkey+1, sizeof(uncompressedPubkey)-1, hashed1_pk, sizeof(hashed1_pk)));
CHECK_CX_OK(cx_keccak_256_hash(uncompressedPubkey+1, sizeof(uncompressedPubkey)-1, hashed1_pk));
CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed1_pk + 12, sizeof(hashed1_pk) - 12, 1, BECH32_ENCODING_BECH32));
break;
}
Expand Down

0 comments on commit 714937a

Please sign in to comment.