Browse Source

key_from_base58 / pubkey_from_privkey: don't support non-compressed keys.

It just clutters the API, and we don't support them on the wire anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
364c2cd2c0
  1. 14
      bitcoin/base58.c
  2. 3
      bitcoin/pubkey.c
  3. 3
      bitcoin/pubkey.h
  4. 6
      daemon/secrets.c
  5. 3
      daemon/wallet.c

14
bitcoin/base58.c

@ -313,7 +313,6 @@ bool key_from_base58(secp256k1_context *secpctx,
u8 keybuf[1 + 32 + 1 + 4];
u8 csum[4];
BIGNUM bn;
bool compressed;
size_t keylen;
BN_init(&bn);
@ -321,11 +320,7 @@ bool key_from_base58(secp256k1_context *secpctx,
return false;
keylen = BN_num_bytes(&bn);
if (keylen == 1 + 32 + 4)
compressed = false;
else if (keylen == 1 + 32 + 1 + 4)
compressed = true;
else
if (keylen != 1 + 32 + 1 + 4)
goto fail_free_bn;
BN_bn2bin(&bn, keybuf);
@ -334,7 +329,7 @@ bool key_from_base58(secp256k1_context *secpctx,
goto fail_free_bn;
/* Byte after key should be 1 to represent a compressed key. */
if (compressed && keybuf[1 + 32] != 1)
if (keybuf[1 + 32] != 1)
goto fail_free_bn;
if (keybuf[0] == 128)
@ -350,9 +345,8 @@ bool key_from_base58(secp256k1_context *secpctx,
if (!secp256k1_ec_seckey_verify(secpctx, priv->secret))
goto fail_free_bn;
/* Get public key, too, since we know if it's compressed. */
if (!pubkey_from_privkey(secpctx, priv, key,
compressed ? SECP256K1_EC_COMPRESSED : 0))
/* Get public key, too. */
if (!pubkey_from_privkey(secpctx, priv, key))
goto fail_free_bn;
BN_free(&bn);

3
bitcoin/pubkey.c

@ -34,8 +34,7 @@ void pubkey_to_der(secp256k1_context *secpctx, u8 der[PUBKEY_DER_LEN],
/* Pubkey from privkey */
bool pubkey_from_privkey(secp256k1_context *secpctx,
const struct privkey *privkey,
struct pubkey *key,
unsigned int compressed_flags)
struct pubkey *key)
{
if (!secp256k1_ec_pubkey_create(secpctx, &key->pubkey, privkey->secret))
return false;

3
bitcoin/pubkey.h

@ -25,8 +25,7 @@ char *pubkey_to_hexstr(const tal_t *ctx, secp256k1_context *secpctx,
/* Pubkey from privkey */
bool pubkey_from_privkey(secp256k1_context *secpctx,
const struct privkey *privkey,
struct pubkey *key,
unsigned int compressed_flags);
struct pubkey *key);
/* Pubkey from DER encoding. */
bool pubkey_from_der(secp256k1_context *secpctx,

6
daemon/secrets.c

@ -149,8 +149,7 @@ static void new_keypair(struct lightningd_state *dstate,
do {
if (RAND_bytes(privkey->secret, sizeof(privkey->secret)) != 1)
fatal("Could not get random bytes for privkey");
} while (!pubkey_from_privkey(dstate->secpctx,
privkey, pubkey, SECP256K1_EC_COMPRESSED));
} while (!pubkey_from_privkey(dstate->secpctx, privkey, pubkey));
}
void peer_secrets_init(struct peer *peer)
@ -220,8 +219,7 @@ void secrets_init(struct lightningd_state *dstate)
fatal("Failed to read privkey: %s", strerror(errno));
close(fd);
if (!pubkey_from_privkey(dstate->secpctx,
&dstate->secret->privkey, &dstate->id,
SECP256K1_EC_COMPRESSED))
&dstate->secret->privkey, &dstate->id))
fatal("Invalid privkey");
log_info_struct(dstate->base_log, "ID: %s", struct pubkey, &dstate->id);

3
daemon/wallet.c

@ -27,8 +27,7 @@ static void new_keypair(struct lightningd_state *dstate,
do {
if (RAND_bytes(privkey->secret, sizeof(privkey->secret)) != 1)
fatal("Could not get random bytes for privkey");
} while (!pubkey_from_privkey(dstate->secpctx,
privkey, pubkey, SECP256K1_EC_COMPRESSED));
} while (!pubkey_from_privkey(dstate->secpctx, privkey, pubkey));
}
void wallet_add_signed_input(struct lightningd_state *dstate,

Loading…
Cancel
Save