core-lightning/bitcoin/signature.h
Rusty Russell 32fe988fe8 bitcoin: signature fixes.
The libsecp change broke signature checking.  Disable it for now,
with a big FIXME.  The next version should have a method for S value
checking, and also compact serialization.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2015-10-12 10:45:02 +10:30

62 lines
1.7 KiB
C

#ifndef LIGHTNING_BITCOIN_SIGNATURE_H
#define LIGHTNING_BITCOIN_SIGNATURE_H
#include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
#include "secp256k1.h"
enum sighash_type {
SIGHASH_ALL = 1,
SIGHASH_NONE = 2,
SIGHASH_SINGLE = 3,
SIGHASH_ANYONECANPAY = 0x80
};
/* ECDSA of double SHA256. */
struct signature {
#ifdef USE_SCHNORR
u8 schnorr[64];
#else
secp256k1_ecdsa_signature sig;
#endif
};
struct sha256_double;
struct bitcoin_tx;
struct pubkey;
struct privkey;
struct bitcoin_tx_output;
struct bitcoin_signature;
bool sign_hash(const tal_t *ctx, const struct privkey *p,
const struct sha256_double *h,
struct signature *s);
/* All tx input scripts must be set to 0 len. */
bool sign_tx_input(const tal_t *ctx, struct bitcoin_tx *tx,
unsigned int in,
const u8 *subscript, size_t subscript_len,
const struct privkey *privkey, const struct pubkey *pubkey,
struct 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,
const u8 *redeemscript, size_t redeemscript_len,
const struct pubkey *key,
const struct bitcoin_signature *sig);
bool check_2of2_sig(struct bitcoin_tx *tx, size_t input_num,
const u8 *redeemscript, size_t redeemscript_len,
const struct pubkey *key1, const struct pubkey *key2,
const struct bitcoin_signature *sig1,
const struct bitcoin_signature *sig2);
/* Signature must have low S value. */
bool sig_valid(const struct signature *s);
#ifndef USE_SCHNORR
/* Give DER encoding of signature: returns length used (<= 72). */
size_t signature_to_der(u8 der[72], const struct signature *s);
#endif
#endif /* LIGHTNING_BITCOIN_SIGNATURE_H */