From 62a002c8604df64c7683570daa27ac5d5f245f2c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 30 Jun 2015 15:31:33 +0930 Subject: [PATCH] script: make DER for signature encoding optional. Alpha does the sane thing, places signatures raw. Signed-off-by: Rusty Russell --- Makefile | 2 ++ bitcoin/script.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c0381553c..9992db1aa 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ PROTOCC:=protoc-c # Alpha has checksequenceverify, segregated witness+input-amount-in-sig+confidentual-transactions, schnorr #FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1 +# Bitcoin uses DER for signatures +FEATURES := -DSCRIPTS_USE_DER PROGRAMS := test-cli/open-channel test-cli/open-anchor-scriptsigs test-cli/leak-anchor-sigs test-cli/open-commit-sig test-cli/check-commit-sig test-cli/check-anchor-scriptsigs test-cli/get-anchor-depth test-cli/create-steal-tx test-cli/create-commit-spend-tx test-cli/close-channel test-cli/create-close-tx test-cli/update-channel test-cli/update-channel-accept test-cli/update-channel-signature test-cli/update-channel-complete test-cli/create-commit-tx diff --git a/bitcoin/script.c b/bitcoin/script.c index 37cb1c8f1..3b907bf09 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -85,15 +85,22 @@ static void add_push_key(u8 **scriptp, const struct pubkey *key) add_push_bytes(scriptp, key->key, pubkey_len(key)); } -/* Bitcoin wants DER encoding. */ static void add_push_sig(u8 **scriptp, const struct bitcoin_signature *sig) { +/* Bitcoin wants DER encoding. */ +#ifdef SCRIPTS_USE_DER u8 der[73]; size_t len = signature_to_der(der, &sig->sig); /* Append sighash type */ der[len++] = sig->stype; add_push_bytes(scriptp, der, len); +#else /* Alpha uses raw encoding */ + u8 with_sighash[sizeof(sig->sig) + 1]; + memcpy(with_sighash, &sig->sig, sizeof(sig->sig)); + with_sighash[sizeof(sig->sig)] = sig->stype; + add_push_bytes(scriptp, with_sighash, sizeof(with_sighash)); +#endif } /* FIXME: permute? */