Browse Source

signature: expose check_signed_hash()

This is wanted for crypto communications to check signature.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 9 years ago
parent
commit
93b5db89a8
  1. 8
      bitcoin/signature.c
  2. 10
      bitcoin/signature.h
  3. 2
      test-cli/close-channel.c
  4. 2
      test-cli/create-anchor-tx.c
  5. 2
      test-cli/create-commit-spend-tx.c
  6. 2
      test-cli/create-commit-tx.c
  7. 2
      test-cli/create-htlc-spend-tx.c
  8. 2
      test-cli/create-steal-tx.c
  9. 2
      test-cli/open-anchor.c
  10. 2
      test-cli/open-commit-sig.c
  11. 2
      test-cli/update-channel-accept.c
  12. 2
      test-cli/update-channel-signature.c

8
bitcoin/signature.c

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

10
bitcoin/signature.h

@ -3,7 +3,7 @@
#include "config.h" #include "config.h"
#include "secp256k1.h" #include "secp256k1.h"
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <stdbool.h>
enum sighash_type { enum sighash_type {
SIGHASH_ALL = 1, SIGHASH_ALL = 1,
@ -28,12 +28,16 @@ struct privkey;
struct bitcoin_tx_output; struct bitcoin_tx_output;
struct bitcoin_signature; 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, const struct sha256_double *h,
struct signature *s); 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. */ /* 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, unsigned int in,
const u8 *subscript, size_t subscript_len, const u8 *subscript, size_t subscript_len,
const struct privkey *privkey, const struct pubkey *pubkey, const struct privkey *privkey, const struct pubkey *pubkey,

2
test-cli/close-channel.c

@ -92,7 +92,7 @@ int main(int argc, char *argv[])
cstate->b.pay_msat / 1000); cstate->b.pay_msat / 1000);
/* Sign it for them. */ /* 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); &privkey, &pubkey1, &sig);
if (close_file) if (close_file)

2
test-cli/create-anchor-tx.c

@ -163,7 +163,7 @@ int main(int argc, char *argv[])
/* Now, sign each input. */ /* Now, sign each input. */
for (i = 0; i < tal_count(in); i++) { for (i = 0; i < tal_count(in); i++) {
in[i].sig.stype = SIGHASH_ALL; 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].in.script_length,
&in[i].privkey, &in[i].pubkey, &in[i].privkey, &in[i].pubkey,
&in[i].sig.sig)) &in[i].sig.sig))

2
test-cli/create-commit-spend-tx.c

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

2
test-cli/create-commit-tx.c

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
/* We generate our signature. */ /* We generate our signature. */
sig1.stype = SIGHASH_ALL; 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); &privkey, &pubkey1, &sig1.sig);
/* Check it works with theirs... */ /* Check it works with theirs... */

2
test-cli/create-htlc-spend-tx.c

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

2
test-cli/create-steal-tx.c

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

2
test-cli/open-anchor.c

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
invert_cstate(cstate); invert_cstate(cstate);
commit = create_commit_tx(ctx, o2, o1, &oa, &rhash, 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); &privkey, &pubkey1, &sig);
oa.commit_sig = signature_to_proto(ctx, &sig); oa.commit_sig = signature_to_proto(ctx, &sig);

2
test-cli/open-commit-sig.c

@ -75,7 +75,7 @@ int main(int argc, char *argv[])
/* Sign it for them. */ /* Sign it for them. */
subscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); 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); &privkey, &pubkey1, &sig);
pkt = open_commit_sig_pkt(ctx, &sig); pkt = open_commit_sig_pkt(ctx, &sig);

2
test-cli/update-channel-accept.c

@ -91,7 +91,7 @@ int main(int argc, char *argv[])
errx(1, "Delta too large"); errx(1, "Delta too large");
/* Sign it for them. */ /* 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); &privkey, &pubkey1, &sig.sig);
pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash); pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash);

2
test-cli/update-channel-signature.c

@ -106,7 +106,7 @@ int main(int argc, char *argv[])
errx(1, "Invalid public open-channel-file2"); errx(1, "Invalid public open-channel-file2");
/* Sign it for them. */ /* 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); &privkey, &pubkey1, &sig.sig);
pkt = update_signature_pkt(ctx, &sig.sig, &preimage); pkt = update_signature_pkt(ctx, &sig.sig, &preimage);

Loading…
Cancel
Save