Skip to content

Commit

Permalink
move eth address hashing to heap
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 4, 2023
1 parent f34fba7 commit a978a37
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crypto/bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ int hdnode_fill_public_key(HDNode *node) {
#if USE_ETHEREUM
int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash) {
uint8_t buf[65] = {0};
SHA3_CTX ctx = {0};
//SHA3_CTX ctx = {0};
SHA3_CTX *ctx = malloc(sizeof(SHA3_CTX));
memzero(ctx, sizeof(SHA3_CTX));

/* get uncompressed public key */
if (ecdsa_get_public_key65(node->curve->params, node->private_key, buf) !=
Expand All @@ -516,9 +518,12 @@ int hdnode_get_ethereum_pubkeyhash(const HDNode *node, uint8_t *pubkeyhash) {
}

/* compute sha3 of x and y coordinate without 04 prefix */
sha3_256_Init(&ctx);
sha3_Update(&ctx, buf + 1, 64);
keccak_Final(&ctx, buf);
sha3_256_Init(ctx);
sha3_Update(ctx, buf + 1, 64);
keccak_Final(ctx, buf);

memzero(ctx, sizeof(SHA3_CTX));
free(ctx);

/* result are the least significant 160 bits */
memcpy(pubkeyhash, buf + 12, 20);
Expand Down

0 comments on commit a978a37

Please sign in to comment.