bitcoin/base58: don't segv if key_to_base58 / key_from_base58 called first.

We need to initialize b58_sha256_impl here too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2017-02-07 12:14:21 +10:30
parent 4ed259c46c
commit e899c47260

View file

@ -118,6 +118,7 @@ char *key_to_base58(const tal_t *ctx, bool test_net, const struct privkey *key)
/* Mark this as a compressed key. */ /* Mark this as a compressed key. */
buf[32] = 1; buf[32] = 1;
b58_sha256_impl = my_sha256;
b58check_enc(out, &outlen, version, buf, sizeof(buf)); b58check_enc(out, &outlen, version, buf, sizeof(buf));
return tal_strdup(ctx, out); return tal_strdup(ctx, out);
} }
@ -129,6 +130,8 @@ bool key_from_base58(const char *base58, size_t base58_len,
u8 keybuf[1 + 32 + 1 + 4]; u8 keybuf[1 + 32 + 1 + 4];
size_t keybuflen = sizeof(keybuf); size_t keybuflen = sizeof(keybuf);
b58_sha256_impl = my_sha256;
b58tobin(keybuf, &keybuflen, base58, base58_len); b58tobin(keybuf, &keybuflen, base58, base58_len);
if (b58check(keybuf, sizeof(keybuf), base58, base58_len) < 0) if (b58check(keybuf, sizeof(keybuf), base58, base58_len) < 0)
return false; return false;