Skip to content

Commit be9a78f

Browse files
authored
Merge pull request #237 from p2pderivatives/add-bip340-schnorr
Add bip340 schnorr
2 parents 9083bab + 0c937d0 commit be9a78f

File tree

101 files changed

+9189
-5006
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+9189
-5006
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ external-symbols = ["secp256k1-sys/external-symbols"]
3434
fuzztarget = ["secp256k1-sys/fuzztarget"]
3535

3636
[dependencies]
37-
secp256k1-sys = { version = "0.3.0", default-features = false, path = "./secp256k1-sys" }
37+
secp256k1-sys = { version = "0.3.1", default-features = false, path = "./secp256k1-sys" }
3838
bitcoin_hashes = { version = "0.9", optional = true }
3939
rand = { version = "0.6", default-features = false, optional = true }
4040
serde = { version = "1.0", default-features = false, optional = true }

secp256k1-sys/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secp256k1-sys"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
55
"Andrew Poelstra <apoelstra@wpsoftware.net>",
66
"Steven Roose <steven@stevenroose.org>" ]
@@ -12,7 +12,7 @@ description = "FFI for Pieter Wuille's `libsecp256k1` library."
1212
keywords = [ "secp256k1", "libsecp256k1", "ffi" ]
1313
readme = "README.md"
1414
build = "build.rs"
15-
links = "rustsecp256k1_v0_2_0"
15+
links = "rustsecp256k1_v0_3_1"
1616

1717
# Should make docs.rs show all functions, even those behind non-default features
1818
[package.metadata.docs.rs]

secp256k1-sys/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ fn main() {
3939
.flag_if_supported("-Wno-unused-function") // some ecmult stuff is defined but not used upstream
4040
.define("SECP256K1_BUILD", Some("1"))
4141
.define("ENABLE_MODULE_ECDH", Some("1"))
42+
.define("ENABLE_MODULE_SCHNORRSIG", Some("1"))
43+
.define("ENABLE_MODULE_EXTRAKEYS", Some("1"))
4244
.define("ECMULT_GEN_PREC_BITS", Some("4"))
4345
// TODO these three should be changed to use libgmp, at least until secp PR 290 is merged
4446
.define("USE_NUM_NONE", Some("1"))

secp256k1-sys/depend/scratch_impl.h.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
13,37d12
22
< static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
3-
< const size_t base_alloc = ((sizeof(secp256k1_scratch) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;
3+
< const size_t base_alloc = ROUND_TO_ALIGN(sizeof(secp256k1_scratch));
44
< void *alloc = checked_malloc(error_callback, base_alloc + size);
55
< secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
66
< if (ret != NULL) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This file was automatically created by ./vendor-libsecp.sh
2-
670cdd3f8be25f81472b2d16dcd228b0d24a5c45
2+
63150ab4da1ef13ebfb4396064e1ff501dbd015e

secp256k1-sys/depend/secp256k1/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
bench_inv
22
bench_ecdh
33
bench_ecmult
4+
bench_schnorrsig
45
bench_sign
56
bench_verify
6-
bench_schnorr_verify
77
bench_recover
88
bench_internal
99
tests
@@ -31,6 +31,8 @@ libtool
3131
*.lo
3232
*.o
3333
*~
34+
*.log
35+
*.trs
3436
src/libsecp256k1-config.h
3537
src/libsecp256k1-config.h.in
3638
src/ecmult_static_context.h

secp256k1-sys/depend/secp256k1/.travis.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ compiler:
1717
- gcc
1818
env:
1919
global:
20-
- WIDEMUL=auto BIGNUM=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ECMULTGENPRECISION=auto ASM=no BUILD=check EXTRAFLAGS= HOST= ECDH=no RECOVERY=no EXPERIMENTAL=no CTIMETEST=yes BENCH=yes ITERS=2
20+
- WIDEMUL=auto BIGNUM=auto ENDOMORPHISM=no STATICPRECOMPUTATION=yes ECMULTGENPRECISION=auto ASM=no BUILD=check WITH_VALGRIND=yes RUN_VALGRIND=no EXTRAFLAGS= HOST= ECDH=no RECOVERY=no SCHNORRSIG=no EXPERIMENTAL=no CTIMETEST=yes BENCH=yes ITERS=2
2121
matrix:
2222
- WIDEMUL=int64 RECOVERY=yes
23-
- WIDEMUL=int64 ECDH=yes EXPERIMENTAL=yes
23+
- WIDEMUL=int64 ECDH=yes EXPERIMENTAL=yes SCHNORRSIG=yes
2424
- WIDEMUL=int64 ENDOMORPHISM=yes
2525
- WIDEMUL=int128
26-
- WIDEMUL=int128 RECOVERY=yes
26+
- WIDEMUL=int128 RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes
2727
- WIDEMUL=int128 ENDOMORPHISM=yes
28-
- WIDEMUL=int128 ENDOMORPHISM=yes ECDH=yes EXPERIMENTAL=yes
28+
- WIDEMUL=int128 ENDOMORPHISM=yes ECDH=yes EXPERIMENTAL=yes SCHNORRSIG=yes
2929
- WIDEMUL=int128 ASM=x86_64
3030
- WIDEMUL=int128 ENDOMORPHISM=yes ASM=x86_64
3131
- BIGNUM=no
32-
- BIGNUM=no ENDOMORPHISM=yes RECOVERY=yes EXPERIMENTAL=yes
32+
- BIGNUM=no ENDOMORPHISM=yes RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes
3333
- BIGNUM=no STATICPRECOMPUTATION=no
34-
- BUILD=distcheck CTIMETEST= BENCH=
34+
- BUILD=distcheck WITH_VALGRIND=no CTIMETEST=no BENCH=no
3535
- CPPFLAGS=-DDETERMINISTIC
36-
- CFLAGS=-O0 CTIMETEST=
36+
- CFLAGS=-O0 CTIMETEST=no
3737
- ECMULTGENPRECISION=2
3838
- ECMULTGENPRECISION=8
39-
- VALGRIND=yes ENDOMORPHISM=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" CPPFLAGS=-DVALGRIND BUILD=
40-
- VALGRIND=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" CPPFLAGS=-DVALGRIND BUILD=
39+
- RUN_VALGRIND=yes ENDOMORPHISM=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" BUILD=
40+
- RUN_VALGRIND=yes BIGNUM=no ASM=x86_64 EXPERIMENTAL=yes ECDH=yes RECOVERY=yes EXTRAFLAGS="--disable-openssl-tests" BUILD=
4141
matrix:
4242
fast_finish: true
4343
include:

secp256k1-sys/depend/secp256k1/Makefile.am

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I build-aux/m4
22

33
lib_LTLIBRARIES = libsecp256k1.la
44
include_HEADERS = include/secp256k1.h
5-
include_HEADERS += include/rustsecp256k1_v0_2_0_preallocated.h
5+
include_HEADERS += include/rustsecp256k1_v0_3_1_preallocated.h
66
noinst_HEADERS =
77
noinst_HEADERS += src/scalar.h
88
noinst_HEADERS += src/scalar_4x64.h
@@ -38,6 +38,7 @@ noinst_HEADERS += src/assumptions.h
3838
noinst_HEADERS += src/util.h
3939
noinst_HEADERS += src/scratch.h
4040
noinst_HEADERS += src/scratch_impl.h
41+
noinst_HEADERS += src/selftest.h
4142
noinst_HEADERS += src/testrand.h
4243
noinst_HEADERS += src/testrand_impl.h
4344
noinst_HEADERS += src/hash.h
@@ -51,7 +52,7 @@ noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
5152
noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
5253

5354
if USE_EXTERNAL_ASM
54-
COMMON_LIB = librustsecp256k1_v0_2_0_common.la
55+
COMMON_LIB = librustsecp256k1_v0_3_1_common.la
5556
noinst_LTLIBRARIES = $(COMMON_LIB)
5657
else
5758
COMMON_LIB =
@@ -62,16 +63,16 @@ pkgconfig_DATA = libsecp256k1.pc
6263

6364
if USE_EXTERNAL_ASM
6465
if USE_ASM_ARM
65-
librustsecp256k1_v0_2_0_common_la_SOURCES = src/asm/field_10x26_arm.s
66+
librustsecp256k1_v0_3_1_common_la_SOURCES = src/asm/field_10x26_arm.s
6667
endif
6768
endif
6869

69-
librustsecp256k1_v0_2_0_la_SOURCES = src/secp256k1.c
70-
librustsecp256k1_v0_2_0_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
71-
librustsecp256k1_v0_2_0_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
70+
librustsecp256k1_v0_3_1_la_SOURCES = src/secp256k1.c
71+
librustsecp256k1_v0_3_1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
72+
librustsecp256k1_v0_3_1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
7273

7374
if VALGRIND_ENABLED
74-
librustsecp256k1_v0_2_0_la_CPPFLAGS += -DVALGRIND
75+
librustsecp256k1_v0_3_1_la_CPPFLAGS += -DVALGRIND
7576
endif
7677

7778
noinst_PROGRAMS =
@@ -133,7 +134,7 @@ gen_%.o: src/gen_%.c src/libsecp256k1-config.h
133134
$(gen_context_BIN): $(gen_context_OBJECTS)
134135
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
135136

136-
$(librustsecp256k1_v0_2_0_la_OBJECTS): src/ecmult_static_context.h
137+
$(librustsecp256k1_v0_3_1_la_OBJECTS): src/ecmult_static_context.h
137138
$(tests_OBJECTS): src/ecmult_static_context.h
138139
$(bench_internal_OBJECTS): src/ecmult_static_context.h
139140
$(bench_ecmult_OBJECTS): src/ecmult_static_context.h
@@ -153,3 +154,11 @@ endif
153154
if ENABLE_MODULE_RECOVERY
154155
include src/modules/recovery/Makefile.am.include
155156
endif
157+
158+
if ENABLE_MODULE_EXTRAKEYS
159+
include src/modules/extrakeys/Makefile.am.include
160+
endif
161+
162+
if ENABLE_MODULE_SCHNORRSIG
163+
include src/modules/schnorrsig/Makefile.am.include
164+
endif

secp256k1-sys/depend/secp256k1/TODO

Lines changed: 0 additions & 3 deletions
This file was deleted.

secp256k1-sys/depend/secp256k1/configure.ac

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ esac
6767

6868
CFLAGS="-W $CFLAGS"
6969

70-
warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
70+
warn_CFLAGS="-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
7171
saved_CFLAGS="$CFLAGS"
7272
CFLAGS="$warn_CFLAGS $CFLAGS"
7373
AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
@@ -136,6 +136,16 @@ AC_ARG_ENABLE(module_recovery,
136136
[enable_module_recovery=$enableval],
137137
[enable_module_recovery=no])
138138

139+
AC_ARG_ENABLE(module_extrakeys,
140+
AS_HELP_STRING([--enable-module-extrakeys],[enable extrakeys module (experimental)]),
141+
[enable_module_extrakeys=$enableval],
142+
[enable_module_extrakeys=no])
143+
144+
AC_ARG_ENABLE(module_schnorrsig,
145+
AS_HELP_STRING([--enable-module-schnorrsig],[enable schnorrsig module (experimental)]),
146+
[enable_module_schnorrsig=$enableval],
147+
[enable_module_schnorrsig=no])
148+
139149
AC_ARG_ENABLE(external_default_callbacks,
140150
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]),
141151
[use_external_default_callbacks=$enableval],
@@ -168,7 +178,21 @@ AC_ARG_WITH([ecmult-gen-precision], [AS_HELP_STRING([--with-ecmult-gen-precision
168178
)],
169179
[req_ecmult_gen_precision=$withval], [req_ecmult_gen_precision=auto])
170180

171-
AC_CHECK_HEADER([valgrind/memcheck.h], [enable_valgrind=yes], [enable_valgrind=no], [])
181+
AC_ARG_WITH([valgrind], [AS_HELP_STRING([--with-valgrind=yes|no|auto],
182+
[Build with extra checks for running inside Valgrind [default=auto]]
183+
)],
184+
[req_valgrind=$withval], [req_valgrind=auto])
185+
186+
if test x"$req_valgrind" = x"no"; then
187+
enable_valgrind=no
188+
else
189+
AC_CHECK_HEADER([valgrind/memcheck.h], [enable_valgrind=yes], [
190+
if test x"$req_valgrind" = x"yes"; then
191+
AC_MSG_ERROR([Valgrind support explicitly requested but valgrind/memcheck.h header not available])
192+
fi
193+
enable_valgrind=no
194+
], [])
195+
fi
172196
AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
173197

174198
if test x"$enable_coverage" = x"yes"; then
@@ -421,6 +445,17 @@ if test x"$enable_module_recovery" = x"yes"; then
421445
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
422446
fi
423447

448+
if test x"$enable_module_schnorrsig" = x"yes"; then
449+
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
450+
enable_module_extrakeys=yes
451+
fi
452+
453+
# Test if extrakeys is set after the schnorrsig module to allow the schnorrsig
454+
# module to set enable_module_extrakeys=yes
455+
if test x"$enable_module_extrakeys" = x"yes"; then
456+
AC_DEFINE(ENABLE_MODULE_EXTRAKEYS, 1, [Define this symbol to enable the extrakeys module])
457+
fi
458+
424459
if test x"$use_external_asm" = x"yes"; then
425460
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
426461
fi
@@ -434,11 +469,19 @@ if test x"$enable_experimental" = x"yes"; then
434469
AC_MSG_NOTICE([WARNING: experimental build])
435470
AC_MSG_NOTICE([Experimental features do not have stable APIs or properties, and may not be safe for production use.])
436471
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
472+
AC_MSG_NOTICE([Building extrakeys module: $enable_module_extrakeys])
473+
AC_MSG_NOTICE([Building schnorrsig module: $enable_module_schnorrsig])
437474
AC_MSG_NOTICE([******])
438475
else
439476
if test x"$enable_module_ecdh" = x"yes"; then
440477
AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
441478
fi
479+
if test x"$enable_module_extrakeys" = x"yes"; then
480+
AC_MSG_ERROR([extrakeys module is experimental. Use --enable-experimental to allow.])
481+
fi
482+
if test x"$enable_module_schnorrsig" = x"yes"; then
483+
AC_MSG_ERROR([schnorrsig module is experimental. Use --enable-experimental to allow.])
484+
fi
442485
if test x"$set_asm" = x"arm"; then
443486
AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
444487
fi
@@ -457,6 +500,8 @@ AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
457500
AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
458501
AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
459502
AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
503+
AM_CONDITIONAL([ENABLE_MODULE_EXTRAKEYS], [test x"$enable_module_extrakeys" = x"yes"])
504+
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
460505
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
461506
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
462507

@@ -476,6 +521,8 @@ echo " with benchmarks = $use_benchmark"
476521
echo " with coverage = $enable_coverage"
477522
echo " module ecdh = $enable_module_ecdh"
478523
echo " module recovery = $enable_module_recovery"
524+
echo " module extrakeys = $enable_module_extrakeys"
525+
echo " module schnorrsig = $enable_module_schnorrsig"
479526
echo
480527
echo " asm = $set_asm"
481528
echo " bignum = $set_bignum"

0 commit comments

Comments
 (0)