Browse Source

pubkey: rename PUBKEY_DER_LEN to PUBKEY_CMPR_LEN.

Pubkeys are not not actually DER encoding, but Pieter Wuille corrected
me: it's SEC 1 documented encoding.

Results from 5 runs, min-max(mean +/- stddev):
	store_load_msec,vsz_kb,store_rewrite_sec,listnodes_sec,listchannels_sec,routing_sec,peer_write_all_sec
	38922-39297(39180.6+/-1.3e+02),2880728,41.040000-41.160000(41.106+/-0.05),2.270000-2.530000(2.338+/-0.097),44.570000-53.980000(49.696+/-3),32.840000-33.080000(32.95+/-0.095),43.060000-44.950000(43.696+/-0.72)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pr-2587
Rusty Russell 6 years ago
committed by neil saitug
parent
commit
837a095d68
  1. 16
      bitcoin/pubkey.c
  2. 4
      bitcoin/pubkey.h
  3. 6
      bitcoin/script.c
  4. 4
      common/bolt11.c
  5. 4
      common/initial_commit_tx.c
  6. 44
      common/key_derive.c
  7. 8
      common/sphinx.c
  8. 4
      connectd/connectd.c
  9. 12
      connectd/handshake.c
  10. 4
      hsmd/hsmd.c
  11. 4
      lightningd/gossip_control.c
  12. 2
      lightningd/json.c
  13. 2
      lightningd/options.c
  14. 2
      lightningd/test/run-find_my_abspath.c
  15. 2
      onchaind/onchaind.c
  16. 16
      wallet/db.c
  17. 2
      wallet/txfilter.c
  18. 2
      wallet/txfilter.h
  19. 2
      wire/fromwire.c
  20. 2
      wire/test/run-peer-wire.c
  21. 2
      wire/towire.c

16
bitcoin/pubkey.c

@ -8,7 +8,7 @@
bool pubkey_from_der(const u8 *der, size_t len, struct pubkey *key)
{
if (len != PUBKEY_DER_LEN)
if (len != PUBKEY_CMPR_LEN)
return false;
if (!secp256k1_ec_pubkey_parse(secp256k1_ctx, &key->pubkey,
@ -18,14 +18,14 @@ bool pubkey_from_der(const u8 *der, size_t len, struct pubkey *key)
return true;
}
void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key)
void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN], const struct pubkey *key)
{
size_t outlen = PUBKEY_DER_LEN;
size_t outlen = PUBKEY_CMPR_LEN;
if (!secp256k1_ec_pubkey_serialize(secp256k1_ctx, der, &outlen,
&key->pubkey,
SECP256K1_EC_COMPRESSED))
abort();
assert(outlen == PUBKEY_DER_LEN);
assert(outlen == PUBKEY_CMPR_LEN);
}
bool pubkey_from_secret(const struct secret *secret, struct pubkey *key)
@ -45,7 +45,7 @@ bool pubkey_from_privkey(const struct privkey *privkey,
bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key)
{
size_t dlen;
unsigned char der[PUBKEY_DER_LEN];
unsigned char der[PUBKEY_CMPR_LEN];
dlen = hex_data_size(slen);
if (dlen != sizeof(der))
@ -59,7 +59,7 @@ bool pubkey_from_hexstr(const char *derstr, size_t slen, struct pubkey *key)
char *pubkey_to_hexstr(const tal_t *ctx, const struct pubkey *key)
{
unsigned char der[PUBKEY_DER_LEN];
unsigned char der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, key);
return tal_hexstr(ctx, der, sizeof(der));
@ -68,7 +68,7 @@ REGISTER_TYPE_TO_STRING(pubkey, pubkey_to_hexstr);
char *secp256k1_pubkey_to_hexstr(const tal_t *ctx, const secp256k1_pubkey *key)
{
unsigned char der[PUBKEY_DER_LEN];
unsigned char der[PUBKEY_CMPR_LEN];
size_t outlen = sizeof(der);
if (!secp256k1_ec_pubkey_serialize(secp256k1_ctx, der, &outlen, key,
SECP256K1_EC_COMPRESSED))
@ -88,7 +88,7 @@ int pubkey_cmp(const struct pubkey *a, const struct pubkey *b)
void pubkey_to_hash160(const struct pubkey *pk, struct ripemd160 *hash)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
struct sha256 h;
pubkey_to_der(der, pk);

4
bitcoin/pubkey.h

@ -11,7 +11,7 @@
struct privkey;
struct secret;
#define PUBKEY_DER_LEN 33
#define PUBKEY_CMPR_LEN 33
struct pubkey {
/* Unpacked pubkey (as used by libsecp256k1 internally) */
@ -40,7 +40,7 @@ bool pubkey_from_privkey(const struct privkey *privkey,
bool pubkey_from_der(const u8 *der, size_t len, struct pubkey *key);
/* Pubkey to DER encoding: must be valid pubkey. */
void pubkey_to_der(u8 der[PUBKEY_DER_LEN], const struct pubkey *key);
void pubkey_to_der(u8 der[PUBKEY_CMPR_LEN], const struct pubkey *key);
/* Compare the keys `a` and `b`. Return <0 if `a`<`b`, 0 if equal and >0 otherwise */
int pubkey_cmp(const struct pubkey *a, const struct pubkey *b);

6
bitcoin/script.c

@ -104,7 +104,7 @@ static void add_number(u8 **script, u32 num)
static void add_push_key(u8 **scriptp, const struct pubkey *key)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, key);
add_push_bytes(scriptp, der, sizeof(der));
@ -120,7 +120,7 @@ static void add_push_sig(u8 **scriptp, const struct bitcoin_signature *sig)
static u8 *stack_key(const tal_t *ctx, const struct pubkey *key)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, key);
return tal_dup_arr(ctx, u8, der, sizeof(der), 0);
@ -305,7 +305,7 @@ u8 *scriptpubkey_p2wpkh_derkey(const tal_t *ctx, const u8 der[33])
struct ripemd160 h;
add_op(&script, OP_0);
hash160(&h, der, PUBKEY_DER_LEN);
hash160(&h, der, PUBKEY_CMPR_LEN);
add_push_bytes(&script, &h, sizeof(h));
return script;
}

4
common/bolt11.c

@ -279,7 +279,7 @@ static char *decode_n(struct bolt11 *b11,
u5 **data, size_t *data_len,
size_t data_length, bool *have_n)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
if (*have_n)
return unknown_field(b11, hu5, data, data_len, 'n',
@ -787,7 +787,7 @@ static void encode_h(u5 **data, const struct sha256 *hash)
static void encode_n(u5 **data, const struct pubkey *id)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, id);
push_field(data, 'n', der, sizeof(der) * CHAR_BIT);

4
common/initial_commit_tx.c

@ -18,12 +18,12 @@
u64 commit_number_obscurer(const struct pubkey *opener_payment_basepoint,
const struct pubkey *accepter_payment_basepoint)
{
u8 ders[PUBKEY_DER_LEN * 2];
u8 ders[PUBKEY_CMPR_LEN * 2];
struct sha256 sha;
be64 obscurer = 0;
pubkey_to_der(ders, opener_payment_basepoint);
pubkey_to_der(ders + PUBKEY_DER_LEN, accepter_payment_basepoint);
pubkey_to_der(ders + PUBKEY_CMPR_LEN, accepter_payment_basepoint);
sha256(&sha, ders, sizeof(ders));
/* Lower 48 bits */

44
common/key_derive.c

@ -25,16 +25,16 @@ bool derive_simple_key(const struct pubkey *basepoint,
struct pubkey *key)
{
struct sha256 sha;
unsigned char der_keys[PUBKEY_DER_LEN * 2];
unsigned char der_keys[PUBKEY_CMPR_LEN * 2];
pubkey_to_der(der_keys, per_commitment_point);
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE
printf("# SHA256(per_commitment_point || basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
printf("# = 0x%s\n",
tal_hexstr(tmpctx, &sha, sizeof(sha)));
#endif
@ -66,16 +66,16 @@ bool derive_simple_privkey(const struct secret *base_secret,
struct privkey *key)
{
struct sha256 sha;
unsigned char der_keys[PUBKEY_DER_LEN * 2];
unsigned char der_keys[PUBKEY_CMPR_LEN * 2];
pubkey_to_der(der_keys, per_commitment_point);
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE
printf("# SHA256(per_commitment_point || basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
printf("# = 0x%s\n", tal_hexstr(tmpctx, &sha, sizeof(sha)));
#endif
@ -117,18 +117,18 @@ bool derive_revocation_key(const struct pubkey *basepoint,
struct pubkey *key)
{
struct sha256 sha;
unsigned char der_keys[PUBKEY_DER_LEN * 2];
unsigned char der_keys[PUBKEY_CMPR_LEN * 2];
secp256k1_pubkey add[2];
const secp256k1_pubkey *args[2];
pubkey_to_der(der_keys, basepoint);
pubkey_to_der(der_keys + PUBKEY_DER_LEN, per_commitment_point);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, per_commitment_point);
sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE
printf("# SHA256(revocation_basepoint || per_commitment_point)\n");
printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
printf("# = 0x%s\n", tal_hexstr(tmpctx, sha.u.u8, sizeof(sha.u.u8))),
#endif
@ -141,13 +141,13 @@ bool derive_revocation_key(const struct pubkey *basepoint,
#endif
pubkey_to_der(der_keys, per_commitment_point);
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE
printf("# SHA256(per_commitment_point || revocation_basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
printf("# = 0x%s\n", tal_hexstr(tmpctx, sha.u.u8, sizeof(sha.u.u8))),
#endif
@ -188,17 +188,17 @@ bool derive_revocation_privkey(const struct secret *base_secret,
struct privkey *key)
{
struct sha256 sha;
unsigned char der_keys[PUBKEY_DER_LEN * 2];
unsigned char der_keys[PUBKEY_CMPR_LEN * 2];
struct secret part2;
pubkey_to_der(der_keys, basepoint);
pubkey_to_der(der_keys + PUBKEY_DER_LEN, per_commitment_point);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, per_commitment_point);
sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE
printf("# SHA256(revocation_basepoint || per_commitment_point)\n");
printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
printf("# = 0x%s\n", tal_hexstr(tmpctx, sha.u.u8, sizeof(sha.u.u8))),
#endif
@ -214,13 +214,13 @@ bool derive_revocation_privkey(const struct secret *base_secret,
#endif
pubkey_to_der(der_keys, per_commitment_point);
pubkey_to_der(der_keys + PUBKEY_DER_LEN, basepoint);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint);
sha256(&sha, der_keys, sizeof(der_keys));
#ifdef SUPERVERBOSE
printf("# SHA256(per_commitment_point || revocation_basepoint)\n");
printf("# => SHA256(0x%s || 0x%s)\n",
tal_hexstr(tmpctx, der_keys, PUBKEY_DER_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_DER_LEN, PUBKEY_DER_LEN));
tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN),
tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN));
printf("# = 0x%s\n", tal_hexstr(tmpctx, sha.u.u8, sizeof(sha.u.u8))),
#endif

8
common/sphinx.c

@ -59,7 +59,7 @@ u8 *serialize_onionpacket(
{
u8 *dst = tal_arr(ctx, u8, TOTAL_PACKET_SIZE);
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
int p = 0;
pubkey_to_der(der, &m->ephemeralkey);
@ -77,7 +77,7 @@ struct onionpacket *parse_onionpacket(const tal_t *ctx,
{
struct onionpacket *m;
int p = 0;
u8 rawEphemeralkey[PUBKEY_DER_LEN];
u8 rawEphemeralkey[PUBKEY_CMPR_LEN];
assert(srclen == TOTAL_PACKET_SIZE);
@ -186,7 +186,7 @@ static void compute_blinding_factor(const struct pubkey *key,
u8 res[BLINDING_FACTOR_SIZE])
{
struct sha256_ctx ctx;
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
struct sha256 temp;
pubkey_to_der(der, key);
@ -289,7 +289,7 @@ static struct hop_params *generate_hop_params(
/* Now hash temp and store it. This requires us to
* DER-serialize first and then skip the sign byte.
*/
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, &temp);
struct sha256 h;
sha256(&h, der, sizeof(der));

4
connectd/connectd.c

@ -1191,11 +1191,11 @@ static struct io_plan *connect_activate(struct io_conn *conn,
static const char *seedname(const tal_t *ctx, const struct pubkey *id)
{
char bech32[100];
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
u5 *data = tal_arr(ctx, u5, 0);
pubkey_to_der(der, id);
bech32_push_bits(&data, der, PUBKEY_DER_LEN*8);
bech32_push_bits(&data, der, PUBKEY_CMPR_LEN*8);
bech32_encode(bech32, "ln", data, tal_count(data), sizeof(bech32));
return tal_fmt(ctx, "%s.lseed.bitcoinstats.com", bech32);
}

12
connectd/handshake.c

@ -39,7 +39,7 @@ enum bolt8_side {
*/
struct act_one {
u8 v;
u8 pubkey[PUBKEY_DER_LEN];
u8 pubkey[PUBKEY_CMPR_LEN];
u8 tag[crypto_aead_chacha20poly1305_ietf_ABYTES];
};
@ -68,7 +68,7 @@ static inline void check_act_one(const struct act_one *act1)
*/
struct act_two {
u8 v;
u8 pubkey[PUBKEY_DER_LEN];
u8 pubkey[PUBKEY_CMPR_LEN];
u8 tag[crypto_aead_chacha20poly1305_ietf_ABYTES];
};
@ -98,7 +98,7 @@ static inline void check_act_two(const struct act_two *act2)
*/
struct act_three {
u8 v;
u8 ciphertext[PUBKEY_DER_LEN + crypto_aead_chacha20poly1305_ietf_ABYTES];
u8 ciphertext[PUBKEY_CMPR_LEN + crypto_aead_chacha20poly1305_ietf_ABYTES];
u8 tag[crypto_aead_chacha20poly1305_ietf_ABYTES];
};
@ -211,7 +211,7 @@ static void sha_mix_in(struct sha256 *h, const void *data, size_t len)
/* h = SHA-256(h || pub.serializeCompressed()) */
static void sha_mix_in_key(struct sha256 *h, const struct pubkey *key)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
size_t len = sizeof(der);
secp256k1_ec_pubkey_serialize(secp256k1_ctx, der, &len, &key->pubkey,
@ -442,7 +442,7 @@ static struct handshake *new_handshake(const tal_t *ctx,
static struct io_plan *act_three_initiator(struct io_conn *conn,
struct handshake *h)
{
u8 spub[PUBKEY_DER_LEN];
u8 spub[PUBKEY_CMPR_LEN];
size_t len = sizeof(spub);
SUPERVERBOSE("Initiator: Act 3");
@ -689,7 +689,7 @@ static struct io_plan *act_one_initiator(struct io_conn *conn,
static struct io_plan *act_three_responder2(struct io_conn *conn,
struct handshake *h)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
SUPERVERBOSE("input: 0x%s", tal_hexstr(tmpctx, &h->act3, ACT_THREE_SIZE));

4
hsmd/hsmd.c

@ -327,7 +327,7 @@ static void get_channel_seed(const struct pubkey *peer_id, u64 dbid,
struct secret *channel_seed)
{
struct secret channel_base;
u8 input[PUBKEY_DER_LEN + sizeof(dbid)];
u8 input[PUBKEY_CMPR_LEN + sizeof(dbid)];
/*~ Again, "per-peer" should be "per-channel", but Hysterical Raisins */
const char *info = "per-peer seed";
@ -341,7 +341,7 @@ static void get_channel_seed(const struct pubkey *peer_id, u64 dbid,
/*~ For all that talk about platform-independence, note that this
* field is endian-dependent! But let's face it, little-endian won.
* In related news, we don't support EBCDIC or middle-endian. */
memcpy(input + PUBKEY_DER_LEN, &dbid, sizeof(dbid));
memcpy(input + PUBKEY_CMPR_LEN, &dbid, sizeof(dbid));
hkdf_sha256(channel_seed, sizeof(*channel_seed),
input, sizeof(input),

4
lightningd/gossip_control.c

@ -191,8 +191,8 @@ static void json_add_raw_pubkey(struct json_stream *response,
const u8 raw_pubkey[sizeof(struct pubkey)])
{
secp256k1_pubkey pubkey;
u8 der[PUBKEY_DER_LEN];
size_t outlen = PUBKEY_DER_LEN;
u8 der[PUBKEY_CMPR_LEN];
size_t outlen = PUBKEY_CMPR_LEN;
memcpy(&pubkey, raw_pubkey, sizeof(pubkey));
if (!secp256k1_ec_pubkey_serialize(secp256k1_ctx, der, &outlen,

2
lightningd/json.c

@ -54,7 +54,7 @@ void json_add_pubkey(struct json_stream *response,
const char *fieldname,
const struct pubkey *key)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, key);
json_add_hex(response, fieldname, der, sizeof(der));

2
lightningd/options.c

@ -845,7 +845,7 @@ static const char *codename_noun[]
void setup_color_and_alias(struct lightningd *ld)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, &ld->id);
if (!ld->rgb)

2
lightningd/test/run-find_my_abspath.c

@ -155,7 +155,7 @@ void timer_expired(tal_t *ctx UNNEEDED, struct timer *timer UNNEEDED)
{ fprintf(stderr, "timer_expired called!\n"); abort(); }
/* Generated stub for txfilter_add_derkey */
void txfilter_add_derkey(struct txfilter *filter UNNEEDED,
const u8 derkey[PUBKEY_DER_LEN])
const u8 derkey[PUBKEY_CMPR_LEN])
{ fprintf(stderr, "txfilter_add_derkey called!\n"); abort(); }
/* Generated stub for txfilter_new */
struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED)

2
onchaind/onchaind.c

@ -1872,7 +1872,7 @@ static void steal_htlc(struct tracked_output *out)
{
struct bitcoin_tx *tx;
enum tx_type tx_type = OUR_PENALTY_TX;
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
/* BOLT #3:
*

16
wallet/db.c

@ -939,13 +939,13 @@ bool sqlite3_column_signature(sqlite3_stmt *stmt, int col,
bool sqlite3_column_pubkey(sqlite3_stmt *stmt, int col, struct pubkey *dest)
{
assert(sqlite3_column_bytes(stmt, col) == PUBKEY_DER_LEN);
return pubkey_from_der(sqlite3_column_blob(stmt, col), PUBKEY_DER_LEN, dest);
assert(sqlite3_column_bytes(stmt, col) == PUBKEY_CMPR_LEN);
return pubkey_from_der(sqlite3_column_blob(stmt, col), PUBKEY_CMPR_LEN, dest);
}
bool sqlite3_bind_pubkey(sqlite3_stmt *stmt, int col, const struct pubkey *pk)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
pubkey_to_der(der, pk);
int err = sqlite3_bind_blob(stmt, col, der, sizeof(der), SQLITE_TRANSIENT);
return err == SQLITE_OK;
@ -964,10 +964,10 @@ bool sqlite3_bind_pubkey_array(sqlite3_stmt *stmt, int col,
}
n = tal_count(pks);
ders = tal_arr(NULL, u8, n * PUBKEY_DER_LEN);
ders = tal_arr(NULL, u8, n * PUBKEY_CMPR_LEN);
for (i = 0; i < n; ++i)
pubkey_to_der(&ders[i * PUBKEY_DER_LEN], &pks[i]);
pubkey_to_der(&ders[i * PUBKEY_CMPR_LEN], &pks[i]);
int err = sqlite3_bind_blob(stmt, col, ders, tal_count(ders), SQLITE_TRANSIENT);
tal_free(ders);
@ -984,13 +984,13 @@ struct pubkey *sqlite3_column_pubkey_array(const tal_t *ctx,
if (sqlite3_column_type(stmt, col) == SQLITE_NULL)
return NULL;
n = sqlite3_column_bytes(stmt, col) / PUBKEY_DER_LEN;
assert(n * PUBKEY_DER_LEN == (size_t)sqlite3_column_bytes(stmt, col));
n = sqlite3_column_bytes(stmt, col) / PUBKEY_CMPR_LEN;
assert(n * PUBKEY_CMPR_LEN == (size_t)sqlite3_column_bytes(stmt, col));
ret = tal_arr(ctx, struct pubkey, n);
ders = sqlite3_column_blob(stmt, col);
for (i = 0; i < n; ++i) {
if (!pubkey_from_der(&ders[i * PUBKEY_DER_LEN], PUBKEY_DER_LEN, &ret[i]))
if (!pubkey_from_der(&ders[i * PUBKEY_CMPR_LEN], PUBKEY_CMPR_LEN, &ret[i]))
return tal_free(ret);
}

2
wallet/txfilter.c

@ -59,7 +59,7 @@ void txfilter_add_scriptpubkey(struct txfilter *filter, const u8 *script TAKES)
}
void txfilter_add_derkey(struct txfilter *filter,
const u8 derkey[PUBKEY_DER_LEN])
const u8 derkey[PUBKEY_CMPR_LEN])
{
u8 *skp, *p2sh;

2
wallet/txfilter.h

@ -27,7 +27,7 @@ struct txfilter *txfilter_new(const tal_t *ctx);
* scriptpubkey for both raw p2wpkh and p2wpkh wrapped in p2sh.
*/
void txfilter_add_derkey(struct txfilter *filter,
const u8 derkey[PUBKEY_DER_LEN]);
const u8 derkey[PUBKEY_CMPR_LEN]);
/**
* txfilter_match -- Check whether the tx matches the filter

2
wire/fromwire.c

@ -119,7 +119,7 @@ u64 fromwire_var_int(const u8 **cursor, size_t *max)
void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
if (!fromwire(cursor, max, der, sizeof(der)))
return;

2
wire/test/run-peer-wire.c

@ -37,7 +37,7 @@ void fromwire_pad(const u8 **cursor, size_t *max, size_t num)
/* memsetting pubkeys doesn't work */
static void set_pubkey(struct pubkey *key)
{
u8 der[PUBKEY_DER_LEN];
u8 der[PUBKEY_CMPR_LEN];
memset(der, 2, sizeof(der));
assert(pubkey_from_der(der, sizeof(der), key));
}

2
wire/towire.c

@ -72,7 +72,7 @@ void towire_var_int(u8 **pptr, const u64 val)
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
{
u8 output[PUBKEY_DER_LEN];
u8 output[PUBKEY_CMPR_LEN];
size_t outputlen = sizeof(output);
secp256k1_ec_pubkey_serialize(secp256k1_ctx, output, &outputlen,

Loading…
Cancel
Save