From 47743a287c34f70f40402ec982eb91d5e19877de Mon Sep 17 00:00:00 2001 From: Jon Griffiths Date: Wed, 31 Oct 2018 08:44:48 +1300 Subject: [PATCH] Avoid a sha256/ripemd160 call for each pubkey we derive We only take the pubkey and ignore all other fields, so we might as well save the cycles used computing the hash for something else. Signed-off-by: Jon Griffiths --- common/key_derive.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/key_derive.c b/common/key_derive.c index 614a22869..df30ffa29 100644 --- a/common/key_derive.c +++ b/common/key_derive.c @@ -248,13 +248,13 @@ bool derive_revocation_privkey(const struct secret *base_secret, bool bip32_pubkey(const struct ext_key *bip32_base, struct pubkey *pubkey, u32 index) { + const uint32_t flags = BIP32_FLAG_KEY_PUBLIC | BIP32_FLAG_SKIP_HASH; struct ext_key ext; if (index >= BIP32_INITIAL_HARDENED_CHILD) return false; - if (bip32_key_from_parent(bip32_base, index, - BIP32_FLAG_KEY_PUBLIC, &ext) != WALLY_OK) + if (bip32_key_from_parent(bip32_base, index, flags, &ext) != WALLY_OK) return false; if (!secp256k1_ec_pubkey_parse(secp256k1_ctx, &pubkey->pubkey,