From a02ca46b03870b0a3f1f8ea7452d1b538917cc37 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 26 Oct 2017 13:31:19 +1030 Subject: [PATCH] secp256k1_ecdsa_recoverable_signature: add support. Signed-off-by: Rusty Russell --- external/Makefile | 2 +- wire/fromwire.c | 16 ++++++++++++++++ wire/towire.c | 14 ++++++++++++++ wire/wire.h | 6 ++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/external/Makefile b/external/Makefile index 0f4a03b24..c0e6035ef 100644 --- a/external/Makefile +++ b/external/Makefile @@ -37,7 +37,7 @@ external/libsecp256k1.% external/libwallycore.%: external/libwally-core/src/secp $(MAKE) -C external/libwally-core install-exec external/libwally-core/src/libwallycore.% external/libwally-core/src/secp256k1/libsecp256k1.%: $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS) - cd external/libwally-core && ./tools/autogen.sh && ./configure CC="$(CC)" --enable-static=yes --enable-shared=no --libdir=`pwd`/.. && $(MAKE) + cd external/libwally-core && ./tools/autogen.sh && ./configure CC="$(CC)" --enable-static=yes --enable-module-recovery --enable-shared=no --libdir=`pwd`/.. && $(MAKE) # Git submodules are seriously broken. external/jsmn/jsmn.h: diff --git a/wire/fromwire.c b/wire/fromwire.c index 0925eb6bd..4d4badd77 100644 --- a/wire/fromwire.c +++ b/wire/fromwire.c @@ -129,6 +129,22 @@ void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, fromwire_fail(cursor, max); } +void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor, + size_t *max, + secp256k1_ecdsa_recoverable_signature *rsig) +{ + u8 compact[64]; + int recid; + + fromwire(cursor, max, compact, sizeof(compact)); + recid = fromwire_u8(cursor, max); + + if (secp256k1_ecdsa_recoverable_signature_parse_compact(secp256k1_ctx, + rsig, compact, + recid) != 1) + fromwire_fail(cursor, max); +} + void fromwire_channel_id(const u8 **cursor, size_t *max, struct channel_id *channel_id) { diff --git a/wire/towire.c b/wire/towire.c index 872721698..4ca3fd7e7 100644 --- a/wire/towire.c +++ b/wire/towire.c @@ -79,6 +79,20 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr, towire(pptr, compact, sizeof(compact)); } +void towire_secp256k1_ecdsa_recoverable_signature(u8 **pptr, + const secp256k1_ecdsa_recoverable_signature *rsig) +{ + u8 compact[64]; + int recid; + + secp256k1_ecdsa_recoverable_signature_serialize_compact(secp256k1_ctx, + compact, + &recid, + rsig); + towire(pptr, compact, sizeof(compact)); + towire_u8(pptr, recid); +} + void towire_channel_id(u8 **pptr, const struct channel_id *channel_id) { towire(pptr, channel_id, sizeof(*channel_id)); diff --git a/wire/wire.h b/wire/wire.h index 7d2c49f20..f89abe6e5 100644 --- a/wire/wire.h +++ b/wire/wire.h @@ -8,6 +8,7 @@ #include #include #include +#include #include struct channel_id { @@ -30,6 +31,8 @@ void towire_privkey(u8 **pptr, const struct privkey *privkey); void towire_secret(u8 **pptr, const struct secret *secret); void towire_secp256k1_ecdsa_signature(u8 **pptr, const secp256k1_ecdsa_signature *signature); +void towire_secp256k1_ecdsa_recoverable_signature(u8 **pptr, + const secp256k1_ecdsa_recoverable_signature *rsig); void towire_channel_id(u8 **pptr, const struct channel_id *channel_id); void towire_short_channel_id(u8 **pptr, const struct short_channel_id *short_channel_id); @@ -57,6 +60,9 @@ void fromwire_privkey(const u8 **cursor, size_t *max, struct privkey *privkey); void fromwire_pubkey(const u8 **cursor, size_t *max, struct pubkey *pubkey); void fromwire_secp256k1_ecdsa_signature(const u8 **cursor, size_t *max, secp256k1_ecdsa_signature *signature); +void fromwire_secp256k1_ecdsa_recoverable_signature(const u8 **cursor, + size_t *max, + secp256k1_ecdsa_recoverable_signature *rsig); void fromwire_channel_id(const u8 **cursor, size_t *max, struct channel_id *channel_id); void fromwire_short_channel_id(const u8 **cursor, size_t *max,