From 82bf81cca612d0a057c6098c1d87ecd45c39ce56 Mon Sep 17 00:00:00 2001 From: TamtamHero <10632523+TamtamHero@users.noreply.github.com> Date: Thu, 6 May 2021 23:16:46 +0200 Subject: [PATCH] Remove dead code + expand allzeroes usage to bigger integers --- src/utils.c | 2 +- src_common/ethUtils.c | 56 ------------------------------------------- src_common/ethUtils.h | 2 ++ 3 files changed, 3 insertions(+), 57 deletions(-) diff --git a/src/utils.c b/src/utils.c index 79dbf7b..e952942 100644 --- a/src/utils.c +++ b/src/utils.c @@ -79,7 +79,7 @@ bool uint256_to_decimal(const uint8_t *value, char *out, size_t out_len) { n[i] = __builtin_bswap16(*p++); } int pos = out_len; - while (!allzeroes(n, sizeof(n))) { + while (!allzeroes((uint8_t *)n, sizeof(n))) { if (pos == 0) { return false; } diff --git a/src_common/ethUtils.c b/src_common/ethUtils.c index 8e19a15..07797c4 100644 --- a/src_common/ethUtils.c +++ b/src_common/ethUtils.c @@ -127,60 +127,6 @@ void getEthAddressFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3 memmove(out, hashAddress + 12, 20); } -#ifdef CHECKSUM_1 - -static const uint8_t const HEXDIGITS[] = "0123456789ABCDEF"; - -static const uint8_t const MASK[] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; - -char convertDigit(uint8_t *address, uint8_t index, uint8_t *hash) { - unsigned char digit = address[index / 2]; - if ((index % 2) == 0) { - digit = (digit >> 4) & 0x0f; - } else { - digit = digit & 0x0f; - } - if (digit < 10) { - return HEXDIGITS[digit]; - } else { - unsigned char data = hash[index / 8]; - if (((data & MASK[index % 8]) != 0) && (digit > 9)) { - return HEXDIGITS[digit] /*- 'a' + 'A'*/; - } else { - return HEXDIGITS[digit]; - } - } -} - -void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, - uint8_t *out, - cx_sha3_t *sha3Context, - chain_config_t *chain_config) { - uint8_t hashAddress[INT256_LENGTH]; - cx_keccak_init(sha3Context, 256); - cx_hash((cx_hash_t *) sha3Context, CX_LAST, publicKey->W + 1, 64, hashAddress, 32); - getEthAddressStringFromBinary(hashAddress + 12, out, sha3Context, chain_config); -} - -void getEthAddressStringFromBinary(uint8_t *address, - uint8_t *out, - cx_sha3_t *sha3Context, - chain_config_t *chain_config) { - UNUSED(chain_config); - uint8_t hashChecksum[INT256_LENGTH]; - uint8_t i; - cx_keccak_init(sha3Context, 256); - cx_hash((cx_hash_t *) sha3Context, CX_LAST, address, 20, hashChecksum, 32); - for (i = 0; i < 40; i++) { - out[i] = convertDigit(address, i, hashChecksum); - } - out[40] = '\0'; -} - -#else - -static const uint8_t const HEXDIGITS[] = "0123456789abcdef"; - void getEthAddressStringFromKey(cx_ecfp_public_key_t *publicKey, uint8_t *out, cx_sha3_t *sha3Context, @@ -250,8 +196,6 @@ void getEthAddressStringFromBinary(uint8_t *address, out[40] = '\0'; } -#endif - bool adjustDecimals(char *src, uint32_t srcLength, char *target, diff --git a/src_common/ethUtils.h b/src_common/ethUtils.h index a863add..511d7f1 100644 --- a/src_common/ethUtils.h +++ b/src_common/ethUtils.h @@ -77,4 +77,6 @@ __attribute__((no_instrument_function)) inline int ismaxint(uint8_t *buf, int n) return 1; } +static const uint8_t const HEXDIGITS[] = "0123456789abcdef"; + #endif /* _ETHUTILS_H_ */