From a978a3761dafd7a7d13067f85c2938ad01fc0c65 Mon Sep 17 00:00:00 2001 From: xtruan Date: Sat, 4 Mar 2023 10:00:02 -0800 Subject: [PATCH] move eth address hashing to heap --- crypto/bip32.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crypto/bip32.c b/crypto/bip32.c index 09723d9fd5e..b8a787e2378 100644 --- a/crypto/bip32.c +++ b/crypto/bip32.c @@ -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) != @@ -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);