Skip to content

Commit

Permalink
bitcoin/pubkey: add pubkey_from_secret.
Browse files Browse the repository at this point in the history
Really, we should have a 'struct point' since we don't use all points
as pubkeys.  But this is the minimal fix to avoid type cast nastiness.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Jul 23, 2018
1 parent 9dd0415 commit 289e39a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 8 additions & 4 deletions bitcoin/pubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key)
assert(outlen == PUBKEY_DER_LEN);
}

/* Pubkey from privkey */
bool pubkey_from_privkey(const struct privkey *privkey,
struct pubkey *key)
bool pubkey_from_secret(const struct secret *secret, struct pubkey *key)
{
if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
&key->pubkey, privkey->secret.data))
&key->pubkey, secret->data))
return false;
return true;
}

bool pubkey_from_privkey(const struct privkey *privkey,
struct pubkey *key)
{
return pubkey_from_secret(&privkey->secret, key);
}

bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key)
{
size_t dlen;
Expand Down
4 changes: 4 additions & 0 deletions bitcoin/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <secp256k1.h>

struct privkey;
struct secret;

#define PUBKEY_DER_LEN 33

Expand All @@ -28,6 +29,9 @@ char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key);
/* Convenience wrapper for a raw secp256k1_pubkey */
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key);

/* Point from secret */
bool pubkey_from_secret(const struct secret *secret, struct pubkey *key);

/* Pubkey from privkey */
bool pubkey_from_privkey(const struct privkey *privkey,
struct pubkey *key);
Expand Down
8 changes: 0 additions & 8 deletions lightningd/test/run-commit_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ static struct secret secret_from_hex(const char *hex)
return s;
}

static bool pubkey_from_secret(const struct secret *secret,
struct pubkey *key)
{
return secp256k1_ec_pubkey_create(secp256k1_ctx,
&key->pubkey,
secret->data);
}

static void tx_must_be_eq(const struct bitcoin_tx *a,
const struct bitcoin_tx *b)
{
Expand Down

0 comments on commit 289e39a

Please sign in to comment.