bitcoin/signature.h: remove struct signature.
It's a wrapper around secp256k1_ecdsa_signature, so use that directly. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
e3d966c102
commit
1edce4878d
|
@ -15,7 +15,7 @@ struct abs_locktime;
|
||||||
|
|
||||||
/* A bitcoin signature includes one byte for the type. */
|
/* A bitcoin signature includes one byte for the type. */
|
||||||
struct bitcoin_signature {
|
struct bitcoin_signature {
|
||||||
struct signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
enum sighash_type stype;
|
enum sighash_type stype;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -75,12 +75,12 @@ static void dump_tx(const char *msg,
|
||||||
|
|
||||||
void sign_hash(const struct privkey *privkey,
|
void sign_hash(const struct privkey *privkey,
|
||||||
const struct sha256_double *h,
|
const struct sha256_double *h,
|
||||||
struct signature *s)
|
secp256k1_ecdsa_signature *s)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
ok = secp256k1_ecdsa_sign(secp256k1_ctx,
|
ok = secp256k1_ecdsa_sign(secp256k1_ctx,
|
||||||
&s->sig,
|
s,
|
||||||
h->sha.u.u8,
|
h->sha.u.u8,
|
||||||
privkey->secret, NULL, NULL);
|
privkey->secret, NULL, NULL);
|
||||||
assert(ok);
|
assert(ok);
|
||||||
|
@ -117,7 +117,7 @@ void sign_tx_input(struct bitcoin_tx *tx,
|
||||||
const u8 *subscript, size_t subscript_len,
|
const u8 *subscript, size_t subscript_len,
|
||||||
const u8 *witness_script,
|
const u8 *witness_script,
|
||||||
const struct privkey *privkey, const struct pubkey *key,
|
const struct privkey *privkey, const struct pubkey *key,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
struct sha256_double hash;
|
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,
|
bool check_signed_hash(const struct sha256_double *hash,
|
||||||
const struct signature *signature,
|
const secp256k1_ecdsa_signature *signature,
|
||||||
const struct pubkey *key)
|
const struct pubkey *key)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = secp256k1_ecdsa_verify(secp256k1_ctx,
|
ret = secp256k1_ecdsa_verify(secp256k1_ctx,
|
||||||
&signature->sig,
|
signature,
|
||||||
hash->sha.u.u8, &key->pubkey);
|
hash->sha.u.u8, &key->pubkey);
|
||||||
return ret == 1;
|
return ret == 1;
|
||||||
}
|
}
|
||||||
|
@ -236,31 +236,30 @@ static bool IsValidSignatureEncoding(const unsigned char sig[], size_t len)
|
||||||
return true;
|
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;
|
size_t len = 72;
|
||||||
|
|
||||||
secp256k1_ecdsa_signature_serialize_der(secp256k1_ctx,
|
secp256k1_ecdsa_signature_serialize_der(secp256k1_ctx,
|
||||||
der, &len, &sig->sig);
|
der, &len, sig);
|
||||||
|
|
||||||
/* IsValidSignatureEncoding() expect extra byte for sighash */
|
/* IsValidSignatureEncoding() expect extra byte for sighash */
|
||||||
assert(IsValidSignatureEncoding(der, len + 1));
|
assert(IsValidSignatureEncoding(der, len + 1));
|
||||||
return len;
|
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,
|
return secp256k1_ecdsa_signature_parse_der(secp256k1_ctx,
|
||||||
&sig->sig, der, len);
|
sig, der, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Signature must have low S value. */
|
/* 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;
|
secp256k1_ecdsa_signature tmp;
|
||||||
|
|
||||||
if (secp256k1_ecdsa_signature_normalize(secp256k1_ctx,
|
if (secp256k1_ecdsa_signature_normalize(secp256k1_ctx, &tmp, sig) == 0)
|
||||||
&tmp, &sig->sig) == 0)
|
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,6 @@ enum sighash_type {
|
||||||
SIGHASH_ANYONECANPAY = 0x80
|
SIGHASH_ANYONECANPAY = 0x80
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ECDSA of double SHA256. */
|
|
||||||
struct signature {
|
|
||||||
secp256k1_ecdsa_signature sig;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sha256_double;
|
struct sha256_double;
|
||||||
struct bitcoin_tx;
|
struct bitcoin_tx;
|
||||||
struct pubkey;
|
struct pubkey;
|
||||||
|
@ -26,10 +21,10 @@ struct bitcoin_signature;
|
||||||
|
|
||||||
void sign_hash(const struct privkey *p,
|
void sign_hash(const struct privkey *p,
|
||||||
const struct sha256_double *h,
|
const struct sha256_double *h,
|
||||||
struct signature *s);
|
secp256k1_ecdsa_signature *s);
|
||||||
|
|
||||||
bool check_signed_hash(const struct sha256_double *hash,
|
bool check_signed_hash(const struct sha256_double *hash,
|
||||||
const struct signature *signature,
|
const secp256k1_ecdsa_signature *signature,
|
||||||
const struct pubkey *key);
|
const struct pubkey *key);
|
||||||
|
|
||||||
/* All tx input scripts must be set to 0 len. */
|
/* 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 *subscript, size_t subscript_len,
|
||||||
const u8 *witness,
|
const u8 *witness,
|
||||||
const struct privkey *privkey, const struct pubkey *pubkey,
|
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. */
|
/* Does this sig sign the tx with this input for this pubkey. */
|
||||||
bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num,
|
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);
|
const struct bitcoin_signature *sig);
|
||||||
|
|
||||||
/* Signature must have low S value. */
|
/* 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). */
|
/* 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 */
|
/* 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 */
|
#endif /* LIGHTNING_BITCOIN_SIGNATURE_H */
|
||||||
|
|
|
@ -374,7 +374,7 @@ static bool check_proof(struct key_negotiate *neg, struct log *log,
|
||||||
struct pubkey *id)
|
struct pubkey *id)
|
||||||
{
|
{
|
||||||
struct sha256_double sha;
|
struct sha256_double sha;
|
||||||
struct signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
Authenticate *auth;
|
Authenticate *auth;
|
||||||
|
|
||||||
auth = pkt_unwrap(inpkt, log, PKT__PKT_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,
|
static Pkt *authenticate_pkt(const tal_t *ctx,
|
||||||
const struct pubkey *node_id,
|
const struct pubkey *node_id,
|
||||||
const struct signature *sig)
|
const secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
Authenticate *auth = tal(ctx, Authenticate);
|
Authenticate *auth = tal(ctx, Authenticate);
|
||||||
authenticate__init(auth);
|
authenticate__init(auth);
|
||||||
|
@ -494,7 +494,7 @@ static struct io_plan *keys_exchanged(struct io_conn *conn,
|
||||||
{
|
{
|
||||||
u8 shared_secret[32];
|
u8 shared_secret[32];
|
||||||
struct pubkey sessionkey;
|
struct pubkey sessionkey;
|
||||||
struct signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
Pkt *auth;
|
Pkt *auth;
|
||||||
size_t totlen;
|
size_t totlen;
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ static void sig_from_sql(sqlite3_stmt *stmt, int idx,
|
||||||
u8 compact[64];
|
u8 compact[64];
|
||||||
|
|
||||||
from_sql_blob(stmt, idx, compact, sizeof(compact));
|
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)
|
compact) != 1)
|
||||||
fatal("db:bad signature blob");
|
fatal("db:bad signature blob");
|
||||||
sig->stype = SIGHASH_ALL;
|
sig->stype = SIGHASH_ALL;
|
||||||
|
@ -181,7 +181,7 @@ static char *sig_to_sql(const tal_t *ctx,
|
||||||
|
|
||||||
assert(sig->stype == SIGHASH_ALL);
|
assert(sig->stype == SIGHASH_ALL);
|
||||||
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, compact,
|
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, compact,
|
||||||
&sig->sig.sig);
|
&sig->sig);
|
||||||
return sql_hex_or_null(ctx, compact, sizeof(compact));
|
return sql_hex_or_null(ctx, compact, sizeof(compact));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ static void sign_privmsg(struct ircstate *state, struct privmsg *msg)
|
||||||
{
|
{
|
||||||
int siglen;
|
int siglen;
|
||||||
u8 der[72];
|
u8 der[72];
|
||||||
struct signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
privkey_sign(state->dstate, msg->msg, strlen(msg->msg), &sig);
|
privkey_sign(state->dstate, msg->msg, strlen(msg->msg), &sig);
|
||||||
siglen = signature_to_der(der, &sig);
|
siglen = signature_to_der(der, &sig);
|
||||||
msg->msg = tal_fmt(msg, "%s %s", tal_hexstr(msg, der, siglen), msg->msg);
|
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 pubkey *pk,
|
||||||
const struct privmsg *msg)
|
const struct privmsg *msg)
|
||||||
{
|
{
|
||||||
struct signature sig;
|
secp256k1_ecdsa_signature sig;
|
||||||
struct sha256_double hash;
|
struct sha256_double hash;
|
||||||
const char *m = msg->msg + 1;
|
const char *m = msg->msg + 1;
|
||||||
int siglen = strchr(m, ' ') - m;
|
int siglen = strchr(m, ' ') - m;
|
||||||
|
|
|
@ -204,11 +204,11 @@ void handle_channel_announcement(
|
||||||
{
|
{
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
bool forward = false;
|
bool forward = false;
|
||||||
struct signature node_signature_1;
|
secp256k1_ecdsa_signature node_signature_1;
|
||||||
struct signature node_signature_2;
|
secp256k1_ecdsa_signature node_signature_2;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct signature bitcoin_signature_1;
|
secp256k1_ecdsa_signature bitcoin_signature_1;
|
||||||
struct signature bitcoin_signature_2;
|
secp256k1_ecdsa_signature bitcoin_signature_2;
|
||||||
struct pubkey node_id_1;
|
struct pubkey node_id_1;
|
||||||
struct pubkey node_id_2;
|
struct pubkey node_id_2;
|
||||||
struct pubkey bitcoin_key_1;
|
struct pubkey bitcoin_key_1;
|
||||||
|
@ -265,7 +265,7 @@ void handle_channel_update(struct peer *peer, const u8 *update, size_t len)
|
||||||
{
|
{
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
struct node_connection *c;
|
struct node_connection *c;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
u32 timestamp;
|
u32 timestamp;
|
||||||
u16 flags;
|
u16 flags;
|
||||||
|
@ -341,7 +341,7 @@ void handle_node_announcement(
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
struct sha256_double hash;
|
struct sha256_double hash;
|
||||||
struct node *node;
|
struct node *node;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
u32 timestamp;
|
u32 timestamp;
|
||||||
struct pubkey node_id;
|
struct pubkey node_id;
|
||||||
u8 rgb_color[3];
|
u8 rgb_color[3];
|
||||||
|
@ -409,7 +409,7 @@ static void broadcast_channel_update(struct lightningd_state *dstate, struct pee
|
||||||
{
|
{
|
||||||
struct txlocator *loc;
|
struct txlocator *loc;
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
u32 timestamp = time_now().ts.tv_sec;
|
u32 timestamp = time_now().ts.tv_sec;
|
||||||
const tal_t *tmpctx = tal_tmpctx(dstate);
|
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)
|
static void broadcast_node_announcement(struct lightningd_state *dstate)
|
||||||
{
|
{
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
static const u8 rgb_color[3];
|
static const u8 rgb_color[3];
|
||||||
static const u8 alias[32];
|
static const u8 alias[32];
|
||||||
u32 timestamp = time_now().ts.tv_sec;
|
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 txlocator *loc;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct signature node_signature[2];
|
secp256k1_ecdsa_signature node_signature[2];
|
||||||
struct signature bitcoin_signature[2];
|
secp256k1_ecdsa_signature bitcoin_signature[2];
|
||||||
const struct pubkey *node_id[2];
|
const struct pubkey *node_id[2];
|
||||||
const struct pubkey *bitcoin_key[2];
|
const struct pubkey *bitcoin_key[2];
|
||||||
struct signature *my_node_signature;
|
secp256k1_ecdsa_signature *my_node_signature;
|
||||||
struct signature *my_bitcoin_signature;
|
secp256k1_ecdsa_signature *my_bitcoin_signature;
|
||||||
u8 *serialized;
|
u8 *serialized;
|
||||||
const tal_t *tmpctx = tal_tmpctx(dstate);
|
const tal_t *tmpctx = tal_tmpctx(dstate);
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,7 @@ void queue_pkt_close_signature(struct peer *peer)
|
||||||
{
|
{
|
||||||
CloseSignature *c = tal(peer, CloseSignature);
|
CloseSignature *c = tal(peer, CloseSignature);
|
||||||
struct bitcoin_tx *close_tx;
|
struct bitcoin_tx *close_tx;
|
||||||
struct signature our_close_sig;
|
secp256k1_ecdsa_signature our_close_sig;
|
||||||
|
|
||||||
close_signature__init(c);
|
close_signature__init(c);
|
||||||
close_tx = peer_create_close_tx(c, peer, peer->closing.our_fee);
|
close_tx = peer_create_close_tx(c, peer, peer->closing.our_fee);
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct secret {
|
||||||
};
|
};
|
||||||
|
|
||||||
void privkey_sign(struct lightningd_state *dstate, const void *src, size_t len,
|
void privkey_sign(struct lightningd_state *dstate, const void *src, size_t len,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
struct sha256_double h;
|
struct sha256_double h;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ struct peer_secrets {
|
||||||
|
|
||||||
void peer_sign_theircommit(const struct peer *peer,
|
void peer_sign_theircommit(const struct peer *peer,
|
||||||
struct bitcoin_tx *commit,
|
struct bitcoin_tx *commit,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
/* Commit tx only has one input: that of the anchor. */
|
/* Commit tx only has one input: that of the anchor. */
|
||||||
sign_tx_input(commit, 0,
|
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,
|
void peer_sign_ourcommit(const struct peer *peer,
|
||||||
struct bitcoin_tx *commit,
|
struct bitcoin_tx *commit,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
/* Commit tx only has one input: that of the anchor. */
|
/* Commit tx only has one input: that of the anchor. */
|
||||||
sign_tx_input(commit, 0,
|
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,
|
void peer_sign_spend(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
const u8 *commit_witnessscript,
|
const u8 *commit_witnessscript,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
/* Spend tx only has one input: that of the commit tx. */
|
/* Spend tx only has one input: that of the commit tx. */
|
||||||
sign_tx_input(spend, 0,
|
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,
|
void peer_sign_htlc_refund(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
const u8 *htlc_witnessscript,
|
const u8 *htlc_witnessscript,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
/* Spend tx only has one input: that of the commit tx. */
|
/* Spend tx only has one input: that of the commit tx. */
|
||||||
sign_tx_input(spend, 0,
|
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,
|
void peer_sign_htlc_fulfill(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
const u8 *htlc_witnessscript,
|
const u8 *htlc_witnessscript,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
/* Spend tx only has one input: that of the commit tx. */
|
/* Spend tx only has one input: that of the commit tx. */
|
||||||
sign_tx_input(spend, 0,
|
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,
|
void peer_sign_mutual_close(const struct peer *peer,
|
||||||
struct bitcoin_tx *close,
|
struct bitcoin_tx *close,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
sign_tx_input(close, 0,
|
sign_tx_input(close, 0,
|
||||||
NULL, 0,
|
NULL, 0,
|
||||||
|
@ -126,7 +126,7 @@ void peer_sign_steal_input(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
size_t i,
|
size_t i,
|
||||||
const u8 *witnessscript,
|
const u8 *witnessscript,
|
||||||
struct signature *sig)
|
secp256k1_ecdsa_signature *sig)
|
||||||
{
|
{
|
||||||
/* Spend tx only has one input: that of the commit tx. */
|
/* Spend tx only has one input: that of the commit tx. */
|
||||||
sign_tx_input(spend, i,
|
sign_tx_input(spend, i,
|
||||||
|
|
|
@ -4,47 +4,47 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <ccan/tal/tal.h>
|
#include <ccan/tal/tal.h>
|
||||||
|
#include <secp256k1.h>
|
||||||
|
|
||||||
struct peer;
|
struct peer;
|
||||||
struct lightningd_state;
|
struct lightningd_state;
|
||||||
struct signature;
|
|
||||||
struct sha256;
|
struct sha256;
|
||||||
|
|
||||||
void privkey_sign(struct lightningd_state *dstate, const void *src, size_t len,
|
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,
|
void peer_sign_theircommit(const struct peer *peer,
|
||||||
struct bitcoin_tx *commit,
|
struct bitcoin_tx *commit,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
void peer_sign_ourcommit(const struct peer *peer,
|
void peer_sign_ourcommit(const struct peer *peer,
|
||||||
struct bitcoin_tx *commit,
|
struct bitcoin_tx *commit,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
void peer_sign_spend(const struct peer *peer,
|
void peer_sign_spend(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
const u8 *commit_witnessscript,
|
const u8 *commit_witnessscript,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
void peer_sign_htlc_refund(const struct peer *peer,
|
void peer_sign_htlc_refund(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
const u8 *htlc_witnessscript,
|
const u8 *htlc_witnessscript,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
void peer_sign_htlc_fulfill(const struct peer *peer,
|
void peer_sign_htlc_fulfill(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
const u8 *htlc_witnessscript,
|
const u8 *htlc_witnessscript,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
void peer_sign_mutual_close(const struct peer *peer,
|
void peer_sign_mutual_close(const struct peer *peer,
|
||||||
struct bitcoin_tx *close,
|
struct bitcoin_tx *close,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
void peer_sign_steal_input(const struct peer *peer,
|
void peer_sign_steal_input(const struct peer *peer,
|
||||||
struct bitcoin_tx *spend,
|
struct bitcoin_tx *spend,
|
||||||
size_t i,
|
size_t i,
|
||||||
const u8 *witnessscript,
|
const u8 *witnessscript,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
const char *peer_secrets_for_db(const tal_t *ctx, struct peer *peer);
|
const char *peer_secrets_for_db(const tal_t *ctx, struct peer *peer);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <ccan/crypto/sha256/sha256.h>
|
#include <ccan/crypto/sha256/sha256.h>
|
||||||
|
|
||||||
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];
|
u8 compact[64];
|
||||||
Signature *pb = tal(ctx, Signature);
|
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));
|
assert(sig_valid(sig));
|
||||||
|
|
||||||
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx,
|
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx,
|
||||||
compact, &sig->sig);
|
compact, sig);
|
||||||
|
|
||||||
/* Kill me now... */
|
/* Kill me now... */
|
||||||
memcpy(&pb->r1, compact, 8);
|
memcpy(&pb->r1, compact, 8);
|
||||||
|
@ -30,8 +30,7 @@ Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig)
|
||||||
return pb;
|
return pb;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool proto_to_signature(const Signature *pb,
|
bool proto_to_signature(const Signature *pb, secp256k1_ecdsa_signature *sig)
|
||||||
struct signature *sig)
|
|
||||||
{
|
{
|
||||||
u8 compact[64];
|
u8 compact[64];
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ bool proto_to_signature(const Signature *pb,
|
||||||
memcpy(compact + 56, &pb->s4, 8);
|
memcpy(compact + 56, &pb->s4, 8);
|
||||||
|
|
||||||
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx,
|
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx,
|
||||||
&sig->sig, compact)
|
sig, compact)
|
||||||
!= 1)
|
!= 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -7,11 +7,10 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* Convert to-from protobuf to internal representation. */
|
/* Convert to-from protobuf to internal representation. */
|
||||||
struct signature;
|
|
||||||
Signature *signature_to_proto(const tal_t *ctx,
|
Signature *signature_to_proto(const tal_t *ctx,
|
||||||
const struct signature *sig);
|
const secp256k1_ecdsa_signature *sig);
|
||||||
bool proto_to_signature(const Signature *pb,
|
bool proto_to_signature(const Signature *pb,
|
||||||
struct signature *sig);
|
secp256k1_ecdsa_signature *sig);
|
||||||
|
|
||||||
/* Convert to-from protobuf to internal representation. */
|
/* Convert to-from protobuf to internal representation. */
|
||||||
struct pubkey;
|
struct pubkey;
|
||||||
|
|
|
@ -25,7 +25,7 @@ class FieldType(object):
|
||||||
return 8
|
return 8
|
||||||
elif typename == 'struct ipv6':
|
elif typename == 'struct ipv6':
|
||||||
return 16
|
return 16
|
||||||
elif typename == 'struct signature':
|
elif typename == 'secp256k1_ecdsa_signature':
|
||||||
return 64
|
return 64
|
||||||
elif typename == 'struct pubkey':
|
elif typename == 'struct pubkey':
|
||||||
return 33
|
return 33
|
||||||
|
@ -120,7 +120,7 @@ class Field(object):
|
||||||
|
|
||||||
# We translate signatures and pubkeys.
|
# We translate signatures and pubkeys.
|
||||||
if 'signature' in fieldname:
|
if 'signature' in fieldname:
|
||||||
return FieldType('struct signature')
|
return FieldType('secp256k1_ecdsa_signature')
|
||||||
|
|
||||||
# We whitelist specific things here, otherwise we'd treat everything
|
# We whitelist specific things here, otherwise we'd treat everything
|
||||||
# as a u8 array.
|
# as a u8 array.
|
||||||
|
|
|
@ -100,15 +100,15 @@ void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey)
|
||||||
fail_pull(cursor, max);
|
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];
|
u8 compact[64];
|
||||||
|
|
||||||
if (!fromwire(cursor, max, compact, sizeof(compact)))
|
if (!fromwire(cursor, max, compact, sizeof(compact)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx,
|
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx, sig, compact)
|
||||||
&sig->sig, compact)
|
|
||||||
!= 1)
|
!= 1)
|
||||||
fail_pull(cursor, max);
|
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);
|
fromwire(cursor, max, NULL, num);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fromwire_signature_array(const u8 **cursor, size_t *max,
|
void fromwire_secp256k1_ecdsa_signature_array(const u8 **cursor, size_t *max,
|
||||||
struct signature *arr, size_t num)
|
secp256k1_ecdsa_signature *arr, size_t num)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < num; 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)
|
static char *fmt_channel_id(const tal_t *ctx, const struct channel_id *id)
|
||||||
|
|
|
@ -86,13 +86,13 @@ struct msg_error {
|
||||||
struct msg_closing_signed {
|
struct msg_closing_signed {
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
u64 fee_satoshis;
|
u64 fee_satoshis;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
};
|
};
|
||||||
struct msg_funding_created {
|
struct msg_funding_created {
|
||||||
struct channel_id temporary_channel_id;
|
struct channel_id temporary_channel_id;
|
||||||
struct sha256 txid;
|
struct sha256 txid;
|
||||||
u8 output_index;
|
u8 output_index;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
};
|
};
|
||||||
struct msg_accept_channel {
|
struct msg_accept_channel {
|
||||||
struct channel_id temporary_channel_id;
|
struct channel_id temporary_channel_id;
|
||||||
|
@ -120,17 +120,17 @@ struct msg_shutdown {
|
||||||
};
|
};
|
||||||
struct msg_funding_signed {
|
struct msg_funding_signed {
|
||||||
struct channel_id temporary_channel_id;
|
struct channel_id temporary_channel_id;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
};
|
};
|
||||||
struct msg_revoke_and_ack {
|
struct msg_revoke_and_ack {
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct sha256 per_commitment_secret;
|
struct sha256 per_commitment_secret;
|
||||||
struct pubkey next_per_commitment_point;
|
struct pubkey next_per_commitment_point;
|
||||||
u8 padding[1];
|
u8 padding[1];
|
||||||
struct signature *htlc_timeout_signature;
|
secp256k1_ecdsa_signature *htlc_timeout_signature;
|
||||||
};
|
};
|
||||||
struct msg_channel_update {
|
struct msg_channel_update {
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
u32 timestamp;
|
u32 timestamp;
|
||||||
u16 flags;
|
u16 flags;
|
||||||
|
@ -142,17 +142,17 @@ struct msg_channel_update {
|
||||||
struct msg_funding_locked {
|
struct msg_funding_locked {
|
||||||
struct channel_id temporary_channel_id;
|
struct channel_id temporary_channel_id;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct signature announcement_node_signature;
|
secp256k1_ecdsa_signature announcement_node_signature;
|
||||||
struct signature announcement_bitcoin_signature;
|
secp256k1_ecdsa_signature announcement_bitcoin_signature;
|
||||||
struct pubkey next_per_commitment_point;
|
struct pubkey next_per_commitment_point;
|
||||||
};
|
};
|
||||||
struct msg_commit_sig {
|
struct msg_commit_sig {
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
struct signature *htlc_signature;
|
secp256k1_ecdsa_signature *htlc_signature;
|
||||||
};
|
};
|
||||||
struct msg_node_announcement {
|
struct msg_node_announcement {
|
||||||
struct signature signature;
|
secp256k1_ecdsa_signature signature;
|
||||||
u32 timestamp;
|
u32 timestamp;
|
||||||
struct pubkey node_id;
|
struct pubkey node_id;
|
||||||
u8 rgb_color[3];
|
u8 rgb_color[3];
|
||||||
|
@ -183,11 +183,11 @@ struct msg_update_fail_htlc {
|
||||||
u8 *reason;
|
u8 *reason;
|
||||||
};
|
};
|
||||||
struct msg_channel_announcement {
|
struct msg_channel_announcement {
|
||||||
struct signature node_signature_1;
|
secp256k1_ecdsa_signature node_signature_1;
|
||||||
struct signature node_signature_2;
|
secp256k1_ecdsa_signature node_signature_2;
|
||||||
struct channel_id channel_id;
|
struct channel_id channel_id;
|
||||||
struct signature bitcoin_signature_1;
|
secp256k1_ecdsa_signature bitcoin_signature_1;
|
||||||
struct signature bitcoin_signature_2;
|
secp256k1_ecdsa_signature bitcoin_signature_2;
|
||||||
struct pubkey node_id_1;
|
struct pubkey node_id_1;
|
||||||
struct pubkey node_id_2;
|
struct pubkey node_id_2;
|
||||||
struct pubkey bitcoin_key_1;
|
struct pubkey bitcoin_key_1;
|
||||||
|
@ -871,8 +871,8 @@ int main(void)
|
||||||
test_corruption(&ufh, ufh2, update_fail_htlc);
|
test_corruption(&ufh, ufh2, update_fail_htlc);
|
||||||
|
|
||||||
memset(&cs, 2, sizeof(cs));
|
memset(&cs, 2, sizeof(cs));
|
||||||
cs.htlc_signature = tal_arr(ctx, struct signature, 2);
|
cs.htlc_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2);
|
||||||
memset(cs.htlc_signature, 2, sizeof(struct signature)*2);
|
memset(cs.htlc_signature, 2, sizeof(secp256k1_ecdsa_signature)*2);
|
||||||
|
|
||||||
msg = towire_struct_commit_sig(ctx, &cs);
|
msg = towire_struct_commit_sig(ctx, &cs);
|
||||||
len = tal_count(msg);
|
len = tal_count(msg);
|
||||||
|
@ -963,8 +963,8 @@ int main(void)
|
||||||
|
|
||||||
memset(&raa, 2, sizeof(raa));
|
memset(&raa, 2, sizeof(raa));
|
||||||
set_pubkey(&raa.next_per_commitment_point);
|
set_pubkey(&raa.next_per_commitment_point);
|
||||||
raa.htlc_timeout_signature = tal_arr(ctx, struct signature, 2);
|
raa.htlc_timeout_signature = tal_arr(ctx, secp256k1_ecdsa_signature, 2);
|
||||||
memset(raa.htlc_timeout_signature, 2, sizeof(struct signature) * 2);
|
memset(raa.htlc_timeout_signature, 2, sizeof(secp256k1_ecdsa_signature) * 2);
|
||||||
|
|
||||||
msg = towire_struct_revoke_and_ack(ctx, &raa);
|
msg = towire_struct_revoke_and_ack(ctx, &raa);
|
||||||
len = tal_count(msg);
|
len = tal_count(msg);
|
||||||
|
|
|
@ -52,12 +52,13 @@ void towire_pubkey(u8 **pptr, const struct pubkey *pubkey)
|
||||||
towire(pptr, output, outputlen);
|
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];
|
u8 compact[64];
|
||||||
|
|
||||||
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx,
|
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx,
|
||||||
compact, &sig->sig);
|
compact, sig);
|
||||||
towire(pptr, compact, sizeof(compact));
|
towire(pptr, compact, sizeof(compact));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,10 +96,11 @@ void towire_pad(u8 **pptr, size_t num)
|
||||||
memset(*pptr + oldsize, 0, 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;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < num; i++)
|
for (i = 0; i < num; i++)
|
||||||
towire_signature(pptr, arr+i);
|
towire_secp256k1_ecdsa_signature(pptr, arr+i);
|
||||||
}
|
}
|
||||||
|
|
14
wire/wire.h
14
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(u8 **pptr, const void *data, size_t len);
|
||||||
void towire_pubkey(u8 **pptr, const struct pubkey *pubkey);
|
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_channel_id(u8 **pptr, const struct channel_id *channel_id);
|
||||||
void towire_sha256(u8 **pptr, const struct sha256 *sha256);
|
void towire_sha256(u8 **pptr, const struct sha256 *sha256);
|
||||||
void towire_ipv6(u8 **pptr, const struct ipv6 *ipv6);
|
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_bool(u8 **pptr, bool v);
|
||||||
|
|
||||||
void towire_u8_array(u8 **pptr, const u8 *arr, size_t num);
|
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);
|
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);
|
u64 fromwire_u64(const u8 **cursor, size_t *max);
|
||||||
bool fromwire_bool(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_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey);
|
||||||
void fromwire_signature(const u8 **cursor, size_t *max,
|
void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max,
|
||||||
struct signature *signature);
|
secp256k1_ecdsa_signature *signature);
|
||||||
void fromwire_channel_id(const u8 **cursor, size_t *max,
|
void fromwire_channel_id(const u8 **cursor, size_t *max,
|
||||||
struct channel_id *channel_id);
|
struct channel_id *channel_id);
|
||||||
void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256);
|
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,
|
void fromwire_u8_array(const u8 **cursor, size_t *max,
|
||||||
u8 *arr, size_t num);
|
u8 *arr, size_t num);
|
||||||
void fromwire_signature_array(const u8 **cursor, size_t *max,
|
void fromwire_secp256k1_ecdsa_signature_array(const u8 **cursor, size_t *max,
|
||||||
struct signature *arr, size_t num);
|
secp256k1_ecdsa_signature *arr, size_t num);
|
||||||
|
|
||||||
#endif /* LIGHTNING_WIRE_WIRE_H */
|
#endif /* LIGHTNING_WIRE_WIRE_H */
|
||||||
|
|
Loading…
Reference in New Issue