signature: expose check_signed_hash()

This is wanted for crypto communications to check signature.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2016-01-22 06:41:45 +10:30
parent 888389e625
commit 93b5db89a8
12 changed files with 23 additions and 19 deletions

View File

@ -76,7 +76,7 @@ static void dump_tx(const char *msg,
}
#endif
bool sign_hash(const tal_t *ctx, const struct privkey *privkey,
bool sign_hash(const struct privkey *privkey,
const struct sha256_double *h,
struct signature *s)
{
@ -133,7 +133,7 @@ static void sha256_tx_one_input(struct bitcoin_tx *tx,
}
/* Only does SIGHASH_ALL */
bool sign_tx_input(const tal_t *ctx, struct bitcoin_tx *tx,
bool sign_tx_input(struct bitcoin_tx *tx,
unsigned int in,
const u8 *subscript, size_t subscript_len,
const struct privkey *privkey, const struct pubkey *key,
@ -143,12 +143,12 @@ bool sign_tx_input(const tal_t *ctx, struct bitcoin_tx *tx,
sha256_tx_one_input(tx, in, subscript, subscript_len, &hash);
dump_tx("Signing", tx, in, subscript, subscript_len, key, &hash);
return sign_hash(ctx, privkey, &hash, sig);
return sign_hash(privkey, &hash, sig);
}
static bool check_signed_hash(const struct sha256_double *hash,
const struct signature *signature,
const struct pubkey *key)
bool check_signed_hash(const struct sha256_double *hash,
const struct signature *signature,
const struct pubkey *key)
{
int ret;
secp256k1_context *secpctx;

View File

@ -3,7 +3,7 @@
#include "config.h"
#include "secp256k1.h"
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include <stdbool.h>
enum sighash_type {
SIGHASH_ALL = 1,
@ -28,12 +28,16 @@ struct privkey;
struct bitcoin_tx_output;
struct bitcoin_signature;
bool sign_hash(const tal_t *ctx, const struct privkey *p,
bool sign_hash(const struct privkey *p,
const struct sha256_double *h,
struct signature *s);
bool check_signed_hash(const struct sha256_double *hash,
const struct signature *signature,
const struct pubkey *key);
/* All tx input scripts must be set to 0 len. */
bool sign_tx_input(const tal_t *ctx, struct bitcoin_tx *tx,
bool sign_tx_input(struct bitcoin_tx *tx,
unsigned int in,
const u8 *subscript, size_t subscript_len,
const struct privkey *privkey, const struct pubkey *pubkey,

View File

@ -92,7 +92,7 @@ int main(int argc, char *argv[])
cstate->b.pay_msat / 1000);
/* Sign it for them. */
sign_tx_input(ctx, close_tx, 0, redeemscript, tal_count(redeemscript),
sign_tx_input(close_tx, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig);
if (close_file)

View File

@ -163,7 +163,7 @@ int main(int argc, char *argv[])
/* Now, sign each input. */
for (i = 0; i < tal_count(in); i++) {
in[i].sig.stype = SIGHASH_ALL;
if (!sign_tx_input(ctx, anchor, i, in[i].in.script,
if (!sign_tx_input(anchor, i, in[i].in.script,
in[i].in.script_length,
&in[i].privkey, &in[i].pubkey,
&in[i].sig.sig))

View File

@ -111,7 +111,7 @@ int main(int argc, char *argv[])
tx->output[0].script_length = tal_count(tx->output[0].script);
/* Now get signature, to set up input script. */
if (!sign_tx_input(tx, tx, 0, redeemscript, tal_count(redeemscript),
if (!sign_tx_input(tx, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig.sig))
errx(1, "Could not sign tx");
sig.stype = SIGHASH_ALL;

View File

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
/* We generate our signature. */
sig1.stype = SIGHASH_ALL;
sign_tx_input(ctx, commit, 0, redeemscript, tal_count(redeemscript),
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig1.sig);
/* Check it works with theirs... */

View File

@ -185,7 +185,7 @@ int main(int argc, char *argv[])
tx->output[0].script_length = tal_count(tx->output[0].script);
/* Now get signature, to set up input script. */
if (!sign_tx_input(tx, tx, 0, redeemscript, tal_count(redeemscript),
if (!sign_tx_input(tx, 0, redeemscript, tal_count(redeemscript),
&privkey, &key, &sig.sig))
errx(1, "Could not sign tx");

View File

@ -112,7 +112,7 @@ int main(int argc, char *argv[])
tx->output[0].script_length = tal_count(tx->output[0].script);
/* Now get signature, to set up input script. */
if (!sign_tx_input(tx, tx, 0, redeemscript, tal_count(redeemscript),
if (!sign_tx_input(tx, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig.sig))
errx(1, "Could not sign tx");
sig.stype = SIGHASH_ALL;

View File

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
invert_cstate(cstate);
commit = create_commit_tx(ctx, o2, o1, &oa, &rhash, cstate);
sign_tx_input(ctx, commit, 0, redeemscript, tal_count(redeemscript),
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig);
oa.commit_sig = signature_to_proto(ctx, &sig);

View File

@ -75,7 +75,7 @@ int main(int argc, char *argv[])
/* Sign it for them. */
subscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
sign_tx_input(ctx, commit, 0, subscript, tal_count(subscript),
sign_tx_input(commit, 0, subscript, tal_count(subscript),
&privkey, &pubkey1, &sig);
pkt = open_commit_sig_pkt(ctx, &sig);

View File

@ -91,7 +91,7 @@ int main(int argc, char *argv[])
errx(1, "Delta too large");
/* Sign it for them. */
sign_tx_input(ctx, commit, 0, redeemscript, tal_count(redeemscript),
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig.sig);
pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash);

View File

@ -106,7 +106,7 @@ int main(int argc, char *argv[])
errx(1, "Invalid public open-channel-file2");
/* Sign it for them. */
sign_tx_input(ctx, commit, 0, redeemscript, tal_count(redeemscript),
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
&privkey, &pubkey1, &sig.sig);
pkt = update_signature_pkt(ctx, &sig.sig, &preimage);