From 1edce4878dd738ec30c91ec82c4884c62a191ecb Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 25 Jan 2017 10:03:42 +1030 Subject: [PATCH] bitcoin/signature.h: remove struct signature. It's a wrapper around secp256k1_ecdsa_signature, so use that directly. Signed-off-by: Rusty Russell --- bitcoin/script.h | 2 +- bitcoin/signature.c | 23 +++++++++++------------ bitcoin/signature.h | 17 ++++++----------- daemon/cryptopkt.c | 6 +++--- daemon/db.c | 4 ++-- daemon/irc_announce.c | 4 ++-- daemon/p2p_announce.c | 24 ++++++++++++------------ daemon/packets.c | 2 +- daemon/secrets.c | 16 ++++++++-------- daemon/secrets.h | 18 +++++++++--------- protobuf_convert.c | 9 ++++----- protobuf_convert.h | 5 ++--- tools/generate-wire.py | 4 ++-- wire/fromwire.c | 12 ++++++------ wire/test/run-peer-wire.c | 36 ++++++++++++++++++------------------ wire/towire.c | 10 ++++++---- wire/wire.h | 14 ++++++++------ 17 files changed, 101 insertions(+), 105 deletions(-) diff --git a/bitcoin/script.h b/bitcoin/script.h index 4fd3883f1..7ac77f48f 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -15,7 +15,7 @@ struct abs_locktime; /* A bitcoin signature includes one byte for the type. */ struct bitcoin_signature { - struct signature sig; + secp256k1_ecdsa_signature sig; enum sighash_type stype; }; diff --git a/bitcoin/signature.c b/bitcoin/signature.c index 0cd12e440..a54128d9e 100644 --- a/bitcoin/signature.c +++ b/bitcoin/signature.c @@ -75,12 +75,12 @@ static void dump_tx(const char *msg, void sign_hash(const struct privkey *privkey, const struct sha256_double *h, - struct signature *s) + secp256k1_ecdsa_signature *s) { bool ok; ok = secp256k1_ecdsa_sign(secp256k1_ctx, - &s->sig, + s, h->sha.u.u8, privkey->secret, NULL, NULL); assert(ok); @@ -117,7 +117,7 @@ void sign_tx_input(struct bitcoin_tx *tx, const u8 *subscript, size_t subscript_len, const u8 *witness_script, const struct privkey *privkey, const struct pubkey *key, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { struct sha256_double hash; @@ -128,13 +128,13 @@ void sign_tx_input(struct bitcoin_tx *tx, } bool check_signed_hash(const struct sha256_double *hash, - const struct signature *signature, + const secp256k1_ecdsa_signature *signature, const struct pubkey *key) { int ret; ret = secp256k1_ecdsa_verify(secp256k1_ctx, - &signature->sig, + signature, hash->sha.u.u8, &key->pubkey); return ret == 1; } @@ -236,31 +236,30 @@ static bool IsValidSignatureEncoding(const unsigned char sig[], size_t len) return true; } -size_t signature_to_der(u8 der[72], const struct signature *sig) +size_t signature_to_der(u8 der[72], const secp256k1_ecdsa_signature *sig) { size_t len = 72; secp256k1_ecdsa_signature_serialize_der(secp256k1_ctx, - der, &len, &sig->sig); + der, &len, sig); /* IsValidSignatureEncoding() expect extra byte for sighash */ assert(IsValidSignatureEncoding(der, len + 1)); return len; } -bool signature_from_der(const u8 *der, size_t len, struct signature *sig) +bool signature_from_der(const u8 *der, size_t len, secp256k1_ecdsa_signature *sig) { return secp256k1_ecdsa_signature_parse_der(secp256k1_ctx, - &sig->sig, der, len); + sig, der, len); } /* Signature must have low S value. */ -bool sig_valid(const struct signature *sig) +bool sig_valid(const secp256k1_ecdsa_signature *sig) { secp256k1_ecdsa_signature tmp; - if (secp256k1_ecdsa_signature_normalize(secp256k1_ctx, - &tmp, &sig->sig) == 0) + if (secp256k1_ecdsa_signature_normalize(secp256k1_ctx, &tmp, sig) == 0) return true; return false; } diff --git a/bitcoin/signature.h b/bitcoin/signature.h index 7be8d2185..7f5329ea5 100644 --- a/bitcoin/signature.h +++ b/bitcoin/signature.h @@ -12,11 +12,6 @@ enum sighash_type { SIGHASH_ANYONECANPAY = 0x80 }; -/* ECDSA of double SHA256. */ -struct signature { - secp256k1_ecdsa_signature sig; -}; - struct sha256_double; struct bitcoin_tx; struct pubkey; @@ -26,10 +21,10 @@ struct bitcoin_signature; void sign_hash(const struct privkey *p, const struct sha256_double *h, - struct signature *s); + secp256k1_ecdsa_signature *s); bool check_signed_hash(const struct sha256_double *hash, - const struct signature *signature, + const secp256k1_ecdsa_signature *signature, const struct pubkey *key); /* All tx input scripts must be set to 0 len. */ @@ -38,7 +33,7 @@ void sign_tx_input(struct bitcoin_tx *tx, const u8 *subscript, size_t subscript_len, const u8 *witness, const struct privkey *privkey, const struct pubkey *pubkey, - struct signature *sig); + secp256k1_ecdsa_signature *sig); /* Does this sig sign the tx with this input for this pubkey. */ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num, @@ -48,12 +43,12 @@ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num, const struct bitcoin_signature *sig); /* Signature must have low S value. */ -bool sig_valid(const struct signature *sig); +bool sig_valid(const secp256k1_ecdsa_signature *sig); /* Give DER encoding of signature: returns length used (<= 72). */ -size_t signature_to_der(u8 der[72], const struct signature *s); +size_t signature_to_der(u8 der[72], const secp256k1_ecdsa_signature *s); /* Parse DER encoding into signature sig */ -bool signature_from_der(const u8 *der, size_t len, struct signature *sig); +bool signature_from_der(const u8 *der, size_t len, secp256k1_ecdsa_signature *sig); #endif /* LIGHTNING_BITCOIN_SIGNATURE_H */ diff --git a/daemon/cryptopkt.c b/daemon/cryptopkt.c index 8f04d5efe..d60f597f2 100644 --- a/daemon/cryptopkt.c +++ b/daemon/cryptopkt.c @@ -374,7 +374,7 @@ static bool check_proof(struct key_negotiate *neg, struct log *log, struct pubkey *id) { struct sha256_double sha; - struct signature sig; + secp256k1_ecdsa_signature sig; Authenticate *auth; auth = pkt_unwrap(inpkt, log, PKT__PKT_AUTH); @@ -480,7 +480,7 @@ static Pkt *pkt_wrap(const tal_t *ctx, void *w, Pkt__PktCase pkt_case) static Pkt *authenticate_pkt(const tal_t *ctx, const struct pubkey *node_id, - const struct signature *sig) + const secp256k1_ecdsa_signature *sig) { Authenticate *auth = tal(ctx, Authenticate); authenticate__init(auth); @@ -494,7 +494,7 @@ static struct io_plan *keys_exchanged(struct io_conn *conn, { u8 shared_secret[32]; struct pubkey sessionkey; - struct signature sig; + secp256k1_ecdsa_signature sig; Pkt *auth; size_t totlen; diff --git a/daemon/db.c b/daemon/db.c index d6d3705d4..edbfa812d 100644 --- a/daemon/db.c +++ b/daemon/db.c @@ -165,7 +165,7 @@ static void sig_from_sql(sqlite3_stmt *stmt, int idx, u8 compact[64]; from_sql_blob(stmt, idx, compact, sizeof(compact)); - if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, &sig->sig.sig, + if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, &sig->sig, compact) != 1) fatal("db:bad signature blob"); sig->stype = SIGHASH_ALL; @@ -181,7 +181,7 @@ static char *sig_to_sql(const tal_t *ctx, assert(sig->stype == SIGHASH_ALL); secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, compact, - &sig->sig.sig); + &sig->sig); return sql_hex_or_null(ctx, compact, sizeof(compact)); } diff --git a/daemon/irc_announce.c b/daemon/irc_announce.c index 936881023..abeb7680c 100644 --- a/daemon/irc_announce.c +++ b/daemon/irc_announce.c @@ -18,7 +18,7 @@ static void sign_privmsg(struct ircstate *state, struct privmsg *msg) { int siglen; u8 der[72]; - struct signature sig; + secp256k1_ecdsa_signature sig; privkey_sign(state->dstate, msg->msg, strlen(msg->msg), &sig); siglen = signature_to_der(der, &sig); msg->msg = tal_fmt(msg, "%s %s", tal_hexstr(msg, der, siglen), msg->msg); @@ -114,7 +114,7 @@ static bool verify_signed_privmsg( const struct pubkey *pk, const struct privmsg *msg) { - struct signature sig; + secp256k1_ecdsa_signature sig; struct sha256_double hash; const char *m = msg->msg + 1; int siglen = strchr(m, ' ') - m; diff --git a/daemon/p2p_announce.c b/daemon/p2p_announce.c index b9a9dfd97..f08e43cf6 100644 --- a/daemon/p2p_announce.c +++ b/daemon/p2p_announce.c @@ -204,11 +204,11 @@ void handle_channel_announcement( { u8 *serialized; bool forward = false; - struct signature node_signature_1; - struct signature node_signature_2; + secp256k1_ecdsa_signature node_signature_1; + secp256k1_ecdsa_signature node_signature_2; struct channel_id channel_id; - struct signature bitcoin_signature_1; - struct signature bitcoin_signature_2; + secp256k1_ecdsa_signature bitcoin_signature_1; + secp256k1_ecdsa_signature bitcoin_signature_2; struct pubkey node_id_1; struct pubkey node_id_2; struct pubkey bitcoin_key_1; @@ -265,7 +265,7 @@ void handle_channel_update(struct peer *peer, const u8 *update, size_t len) { u8 *serialized; struct node_connection *c; - struct signature signature; + secp256k1_ecdsa_signature signature; struct channel_id channel_id; u32 timestamp; u16 flags; @@ -341,7 +341,7 @@ void handle_node_announcement( u8 *serialized; struct sha256_double hash; struct node *node; - struct signature signature; + secp256k1_ecdsa_signature signature; u32 timestamp; struct pubkey node_id; u8 rgb_color[3]; @@ -409,7 +409,7 @@ static void broadcast_channel_update(struct lightningd_state *dstate, struct pee { struct txlocator *loc; u8 *serialized; - struct signature signature; + secp256k1_ecdsa_signature signature; struct channel_id channel_id; u32 timestamp = time_now().ts.tv_sec; const tal_t *tmpctx = tal_tmpctx(dstate); @@ -447,7 +447,7 @@ static void broadcast_channel_update(struct lightningd_state *dstate, struct pee static void broadcast_node_announcement(struct lightningd_state *dstate) { u8 *serialized; - struct signature signature; + secp256k1_ecdsa_signature signature; static const u8 rgb_color[3]; static const u8 alias[32]; u32 timestamp = time_now().ts.tv_sec; @@ -484,12 +484,12 @@ static void broadcast_channel_announcement(struct lightningd_state *dstate, stru { struct txlocator *loc; struct channel_id channel_id; - struct signature node_signature[2]; - struct signature bitcoin_signature[2]; + secp256k1_ecdsa_signature node_signature[2]; + secp256k1_ecdsa_signature bitcoin_signature[2]; const struct pubkey *node_id[2]; const struct pubkey *bitcoin_key[2]; - struct signature *my_node_signature; - struct signature *my_bitcoin_signature; + secp256k1_ecdsa_signature *my_node_signature; + secp256k1_ecdsa_signature *my_bitcoin_signature; u8 *serialized; const tal_t *tmpctx = tal_tmpctx(dstate); diff --git a/daemon/packets.c b/daemon/packets.c index 09ce77985..4f0d28dc7 100644 --- a/daemon/packets.c +++ b/daemon/packets.c @@ -277,7 +277,7 @@ void queue_pkt_close_signature(struct peer *peer) { CloseSignature *c = tal(peer, CloseSignature); struct bitcoin_tx *close_tx; - struct signature our_close_sig; + secp256k1_ecdsa_signature our_close_sig; close_signature__init(c); close_tx = peer_create_close_tx(c, peer, peer->closing.our_fee); diff --git a/daemon/secrets.c b/daemon/secrets.c index e3d7b1884..e4155b7a0 100644 --- a/daemon/secrets.c +++ b/daemon/secrets.c @@ -27,7 +27,7 @@ struct secret { }; void privkey_sign(struct lightningd_state *dstate, const void *src, size_t len, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { struct sha256_double h; @@ -44,7 +44,7 @@ struct peer_secrets { void peer_sign_theircommit(const struct peer *peer, struct bitcoin_tx *commit, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { /* Commit tx only has one input: that of the anchor. */ sign_tx_input(commit, 0, @@ -57,7 +57,7 @@ void peer_sign_theircommit(const struct peer *peer, void peer_sign_ourcommit(const struct peer *peer, struct bitcoin_tx *commit, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { /* Commit tx only has one input: that of the anchor. */ sign_tx_input(commit, 0, @@ -71,7 +71,7 @@ void peer_sign_ourcommit(const struct peer *peer, void peer_sign_spend(const struct peer *peer, struct bitcoin_tx *spend, const u8 *commit_witnessscript, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { /* Spend tx only has one input: that of the commit tx. */ sign_tx_input(spend, 0, @@ -85,7 +85,7 @@ void peer_sign_spend(const struct peer *peer, void peer_sign_htlc_refund(const struct peer *peer, struct bitcoin_tx *spend, const u8 *htlc_witnessscript, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { /* Spend tx only has one input: that of the commit tx. */ sign_tx_input(spend, 0, @@ -99,7 +99,7 @@ void peer_sign_htlc_refund(const struct peer *peer, void peer_sign_htlc_fulfill(const struct peer *peer, struct bitcoin_tx *spend, const u8 *htlc_witnessscript, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { /* Spend tx only has one input: that of the commit tx. */ sign_tx_input(spend, 0, @@ -112,7 +112,7 @@ void peer_sign_htlc_fulfill(const struct peer *peer, void peer_sign_mutual_close(const struct peer *peer, struct bitcoin_tx *close, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { sign_tx_input(close, 0, NULL, 0, @@ -126,7 +126,7 @@ void peer_sign_steal_input(const struct peer *peer, struct bitcoin_tx *spend, size_t i, const u8 *witnessscript, - struct signature *sig) + secp256k1_ecdsa_signature *sig) { /* Spend tx only has one input: that of the commit tx. */ sign_tx_input(spend, i, diff --git a/daemon/secrets.h b/daemon/secrets.h index f0397b51d..10abaf50b 100644 --- a/daemon/secrets.h +++ b/daemon/secrets.h @@ -4,47 +4,47 @@ #include "config.h" #include #include +#include struct peer; struct lightningd_state; -struct signature; struct sha256; void privkey_sign(struct lightningd_state *dstate, const void *src, size_t len, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_theircommit(const struct peer *peer, struct bitcoin_tx *commit, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_ourcommit(const struct peer *peer, struct bitcoin_tx *commit, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_spend(const struct peer *peer, struct bitcoin_tx *spend, const u8 *commit_witnessscript, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_htlc_refund(const struct peer *peer, struct bitcoin_tx *spend, const u8 *htlc_witnessscript, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_htlc_fulfill(const struct peer *peer, struct bitcoin_tx *spend, const u8 *htlc_witnessscript, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_mutual_close(const struct peer *peer, struct bitcoin_tx *close, - struct signature *sig); + secp256k1_ecdsa_signature *sig); void peer_sign_steal_input(const struct peer *peer, struct bitcoin_tx *spend, size_t i, const u8 *witnessscript, - struct signature *sig); + secp256k1_ecdsa_signature *sig); const char *peer_secrets_for_db(const tal_t *ctx, struct peer *peer); diff --git a/protobuf_convert.c b/protobuf_convert.c index 43997c4cd..58eb10873 100644 --- a/protobuf_convert.c +++ b/protobuf_convert.c @@ -6,7 +6,7 @@ #include "utils.h" #include -Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig) +Signature *signature_to_proto(const tal_t *ctx, const secp256k1_ecdsa_signature *sig) { u8 compact[64]; Signature *pb = tal(ctx, Signature); @@ -15,7 +15,7 @@ Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig) assert(sig_valid(sig)); secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, - compact, &sig->sig); + compact, sig); /* Kill me now... */ memcpy(&pb->r1, compact, 8); @@ -30,8 +30,7 @@ Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig) return pb; } -bool proto_to_signature(const Signature *pb, - struct signature *sig) +bool proto_to_signature(const Signature *pb, secp256k1_ecdsa_signature *sig) { u8 compact[64]; @@ -46,7 +45,7 @@ bool proto_to_signature(const Signature *pb, memcpy(compact + 56, &pb->s4, 8); if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, - &sig->sig, compact) + sig, compact) != 1) return false; diff --git a/protobuf_convert.h b/protobuf_convert.h index 26170507e..6eabb6051 100644 --- a/protobuf_convert.h +++ b/protobuf_convert.h @@ -7,11 +7,10 @@ #include /* Convert to-from protobuf to internal representation. */ -struct signature; Signature *signature_to_proto(const tal_t *ctx, - const struct signature *sig); + const secp256k1_ecdsa_signature *sig); bool proto_to_signature(const Signature *pb, - struct signature *sig); + secp256k1_ecdsa_signature *sig); /* Convert to-from protobuf to internal representation. */ struct pubkey; diff --git a/tools/generate-wire.py b/tools/generate-wire.py index ea0812168..b91517854 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -25,7 +25,7 @@ class FieldType(object): return 8 elif typename == 'struct ipv6': return 16 - elif typename == 'struct signature': + elif typename == 'secp256k1_ecdsa_signature': return 64 elif typename == 'struct pubkey': return 33 @@ -120,7 +120,7 @@ class Field(object): # We translate signatures and pubkeys. if 'signature' in fieldname: - return FieldType('struct signature') + return FieldType('secp256k1_ecdsa_signature') # We whitelist specific things here, otherwise we'd treat everything # as a u8 array. diff --git a/wire/fromwire.c b/wire/fromwire.c index 49440f530..6e89583d4 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -100,15 +100,15 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey) fail_pull(cursor, max); } -void fromwire_signature(const u8 **cursor, size_t *max, struct signature *sig) +void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, + size_t *max, secp256k1_ecdsa_signature *sig) { u8 compact[64]; if (!fromwire(cursor, max, compact, sizeof(compact))) return; - if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, - &sig->sig, compact) + if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact) != 1) fail_pull(cursor, max); } @@ -147,13 +147,13 @@ void fromwire_pad(const u8 **cursor, size_t *max, size_t num) fromwire(cursor, max, NULL, num); } -void fromwire_signature_array(const u8 **cursor, size_t *max, - struct signature *arr, size_t num) +void fromwire_secp256k1_ecdsa_signature_array(const u8 **cursor, size_t *max, + secp256k1_ecdsa_signature *arr, size_t num) { size_t i; for (i = 0; i < num; i++) - fromwire_signature(cursor, max, arr + i); + fromwire_secp256k1_ecdsa_signature(cursor, max, arr + i); } static char *fmt_channel_id(const tal_t *ctx, const struct channel_id *id) diff --git a/wire/test/run-peer-wire.c b/wire/test/run-peer-wire.c index 6a196ee97..97baee083 100644 --- a/wire/test/run-peer-wire.c +++ b/wire/test/run-peer-wire.c @@ -86,13 +86,13 @@ struct msg_error { struct msg_closing_signed { struct channel_id channel_id; u64 fee_satoshis; - struct signature signature; + secp256k1_ecdsa_signature signature; }; struct msg_funding_created { struct channel_id temporary_channel_id; struct sha256 txid; u8 output_index; - struct signature signature; + secp256k1_ecdsa_signature signature; }; struct msg_accept_channel { struct channel_id temporary_channel_id; @@ -120,17 +120,17 @@ struct msg_shutdown { }; struct msg_funding_signed { struct channel_id temporary_channel_id; - struct signature signature; + secp256k1_ecdsa_signature signature; }; struct msg_revoke_and_ack { struct channel_id channel_id; struct sha256 per_commitment_secret; struct pubkey next_per_commitment_point; u8 padding[1]; - struct signature *htlc_timeout_signature; + secp256k1_ecdsa_signature *htlc_timeout_signature; }; struct msg_channel_update { - struct signature signature; + secp256k1_ecdsa_signature signature; struct channel_id channel_id; u32 timestamp; u16 flags; @@ -142,17 +142,17 @@ struct msg_channel_update { struct msg_funding_locked { struct channel_id temporary_channel_id; struct channel_id channel_id; - struct signature announcement_node_signature; - struct signature announcement_bitcoin_signature; + secp256k1_ecdsa_signature announcement_node_signature; + secp256k1_ecdsa_signature announcement_bitcoin_signature; struct pubkey next_per_commitment_point; }; struct msg_commit_sig { struct channel_id channel_id; - struct signature signature; - struct signature *htlc_signature; + secp256k1_ecdsa_signature signature; + secp256k1_ecdsa_signature *htlc_signature; }; struct msg_node_announcement { - struct signature signature; + secp256k1_ecdsa_signature signature; u32 timestamp; struct pubkey node_id; u8 rgb_color[3]; @@ -183,11 +183,11 @@ struct msg_update_fail_htlc { u8 *reason; }; struct msg_channel_announcement { - struct signature node_signature_1; - struct signature node_signature_2; + secp256k1_ecdsa_signature node_signature_1; + secp256k1_ecdsa_signature node_signature_2; struct channel_id channel_id; - struct signature bitcoin_signature_1; - struct signature bitcoin_signature_2; + secp256k1_ecdsa_signature bitcoin_signature_1; + secp256k1_ecdsa_signature bitcoin_signature_2; struct pubkey node_id_1; struct pubkey node_id_2; struct pubkey bitcoin_key_1; @@ -871,8 +871,8 @@ int main(void) test_corruption(&ufh, ufh2, update_fail_htlc); memset(&cs, 2, sizeof(cs)); - cs.htlc_signature = tal_arr(ctx, struct signature, 2); - memset(cs.htlc_signature, 2, sizeof(struct signature)*2); + cs.htlc_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2); + memset(cs.htlc_signature, 2, sizeof(secp256k1_ecdsa_signature)*2); msg = towire_struct_commit_sig(ctx, &cs); len = tal_count(msg); @@ -963,8 +963,8 @@ int main(void) memset(&raa, 2, sizeof(raa)); set_pubkey(&raa.next_per_commitment_point); - raa.htlc_timeout_signature = tal_arr(ctx, struct signature, 2); - memset(raa.htlc_timeout_signature, 2, sizeof(struct signature) * 2); + raa.htlc_timeout_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2); + memset(raa.htlc_timeout_signature, 2, sizeof(secp256k1_ecdsa_signature) * 2); msg = towire_struct_revoke_and_ack(ctx, &raa); len = tal_count(msg); diff --git a/wire/towire.c b/wire/towire.c index 4330e5da3..7b42330ed 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -52,12 +52,13 @@ void towire_pubkey(u8 **pptr, const struct pubkey *pubkey) towire(pptr, output, outputlen); } -void towire_signature(u8 **pptr, const struct signature *sig) +void towire_secp256k1_ecdsa_signature(u8 **pptr, + const secp256k1_ecdsa_signature *sig) { u8 compact[64]; secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, - compact, &sig->sig); + compact, sig); towire(pptr, compact, sizeof(compact)); } @@ -95,10 +96,11 @@ void towire_pad(u8 **pptr, size_t num) memset(*pptr + oldsize, 0, num); } -void towire_signature_array(u8 **pptr, const struct signature *arr, size_t num) +void towire_secp256k1_ecdsa_signature_array(u8 **pptr, + const secp256k1_ecdsa_signature *arr, size_t num) { size_t i; for (i = 0; i < num; i++) - towire_signature(pptr, arr+i); + towire_secp256k1_ecdsa_signature(pptr, arr+i); } diff --git a/wire/wire.h b/wire/wire.h index 9e3c3bb21..a85c1ac0c 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -23,7 +23,8 @@ int fromwire_peektype(const u8 *cursor); void towire(u8 **pptr, const void *data, size_t len); void towire_pubkey(u8 **pptr, const struct pubkey *pubkey); -void towire_signature(u8 **pptr, const struct signature *signature); +void towire_secp256k1_ecdsa_signature(u8 **pptr, + const secp256k1_ecdsa_signature *signature); void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); void towire_sha256(u8 **pptr, const struct sha256 *sha256); void towire_ipv6(u8 **pptr, const struct ipv6 *ipv6); @@ -35,7 +36,8 @@ void towire_pad(u8 **pptr, size_t num); void towire_bool(u8 **pptr, bool v); void towire_u8_array(u8 **pptr, const u8 *arr, size_t num); -void towire_signature_array(u8 **pptr, const struct signature *arr, size_t num); +void towire_secp256k1_ecdsa_signature_array(u8 **pptr, + const secp256k1_ecdsa_signature *arr, size_t num); const u8 *fromwire(const u8 **cursor, size_t *max, void *copy, size_t n); @@ -45,8 +47,8 @@ u32 fromwire_u32(const u8 **cursor, size_t *max); u64 fromwire_u64(const u8 **cursor, size_t *max); bool fromwire_bool(const u8 **cursor, size_t *max); void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey); -void fromwire_signature(const u8 **cursor, size_t *max, - struct signature *signature); +void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max, + secp256k1_ecdsa_signature *signature); void fromwire_channel_id(const u8 **cursor, size_t *max, struct channel_id *channel_id); void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256); @@ -55,7 +57,7 @@ void fromwire_pad(const u8 **cursor, size_t *max, size_t num); void fromwire_u8_array(const u8 **cursor, size_t *max, u8 *arr, size_t num); -void fromwire_signature_array(const u8 **cursor, size_t *max, - struct signature *arr, size_t num); +void fromwire_secp256k1_ecdsa_signature_array(const u8 **cursor, size_t *max, + secp256k1_ecdsa_signature *arr, size_t num); #endif /* LIGHTNING_WIRE_WIRE_H */