Skip to content

Commit 773ff90

Browse files
author
Lawrence Nahum
committed
update secp-zkp 1c830b4c9ac30aa32e246ea3ab8ef9ef99acf664
1 parent eeb53a5 commit 773ff90

35 files changed

+4581
-206
lines changed

src/secp256k1/.gitignore

Lines changed: 1 addition & 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

src/secp256k1/Makefile.am

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ else
88
JNI_LIB =
99
endif
1010
include_HEADERS = include/secp256k1.h
11+
include_HEADERS += include/secp256k1_preallocated.h
1112
noinst_HEADERS =
1213
noinst_HEADERS += src/scalar.h
1314
noinst_HEADERS += src/scalar_4x64.h
@@ -151,6 +152,7 @@ endif
151152

152153
if USE_ECMULT_STATIC_PRECOMPUTATION
153154
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir)
155+
CFLAGS_FOR_BUILD += -Wall -Wextra -Wno-unused-function
154156

155157
gen_context_OBJECTS = gen_context.o
156158
gen_context_BIN = gen_context$(BUILD_EXEEXT)
@@ -177,6 +179,14 @@ if ENABLE_MODULE_ECDH
177179
include src/modules/ecdh/Makefile.am.include
178180
endif
179181

182+
if ENABLE_MODULE_SCHNORRSIG
183+
include src/modules/schnorrsig/Makefile.am.include
184+
endif
185+
186+
if ENABLE_MODULE_MUSIG
187+
include src/modules/musig/Makefile.am.include
188+
endif
189+
180190
if ENABLE_MODULE_RECOVERY
181191
include src/modules/recovery/Makefile.am.include
182192
endif

src/secp256k1/build-aux/m4/ax_jni_include_dir.m4

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ else
6565
_JTOPDIR=`echo "$_ACJNI_FOLLOWED" | sed -e 's://*:/:g' -e 's:/[[^/]]*$::'`
6666
fi
6767
68-
if test x$cross_compiling != xyes; then
6968
case "$host_os" in
7069
darwin*) # Apple Java headers are inside the Xcode bundle.
7170
macos_version=$(sw_vers -productVersion | sed -n -e 's/^@<:@0-9@:>@*.\(@<:@0-9@:>@*\).@<:@0-9@:>@*/\1/p')
@@ -79,7 +78,6 @@ case "$host_os" in
7978
;;
8079
*) _JINC="$_JTOPDIR/include";;
8180
esac
82-
fi
8381
_AS_ECHO_LOG([_JTOPDIR=$_JTOPDIR])
8482
_AS_ECHO_LOG([_JINC=$_JINC])
8583

src/secp256k1/configure.ac

Lines changed: 127 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -85,42 +85,42 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
8585
])
8686

8787
AC_ARG_ENABLE(benchmark,
88-
AS_HELP_STRING([--enable-benchmark],[compile benchmark (default is yes)]),
88+
AS_HELP_STRING([--enable-benchmark],[compile benchmark [default=yes]]),
8989
[use_benchmark=$enableval],
9090
[use_benchmark=yes])
9191

9292
AC_ARG_ENABLE(coverage,
93-
AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis]),
93+
AS_HELP_STRING([--enable-coverage],[enable compiler flags to support kcov coverage analysis [default=no]]),
9494
[enable_coverage=$enableval],
9595
[enable_coverage=no])
9696

9797
AC_ARG_ENABLE(tests,
98-
AS_HELP_STRING([--enable-tests],[compile tests (default is yes)]),
98+
AS_HELP_STRING([--enable-tests],[compile tests [default=yes]]),
9999
[use_tests=$enableval],
100100
[use_tests=yes])
101101

102102
AC_ARG_ENABLE(openssl_tests,
103-
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests, if OpenSSL is available (default is auto)]),
103+
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests [default=auto]]),
104104
[enable_openssl_tests=$enableval],
105105
[enable_openssl_tests=auto])
106106

107107
AC_ARG_ENABLE(experimental,
108-
AS_HELP_STRING([--enable-experimental],[allow experimental configure options (default is no)]),
108+
AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]),
109109
[use_experimental=$enableval],
110110
[use_experimental=no])
111111

112112
AC_ARG_ENABLE(exhaustive_tests,
113-
AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests (default is yes)]),
113+
AS_HELP_STRING([--enable-exhaustive-tests],[compile exhaustive tests [default=yes]]),
114114
[use_exhaustive_tests=$enableval],
115115
[use_exhaustive_tests=yes])
116116

117117
AC_ARG_ENABLE(endomorphism,
118-
AS_HELP_STRING([--enable-endomorphism],[enable endomorphism (default is no)]),
118+
AS_HELP_STRING([--enable-endomorphism],[enable endomorphism [default=no]]),
119119
[use_endomorphism=$enableval],
120120
[use_endomorphism=no])
121121

122122
AC_ARG_ENABLE(ecmult_static_precomputation,
123-
AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing (default is yes)]),
123+
AS_HELP_STRING([--enable-ecmult-static-precomputation],[enable precomputed ecmult table for signing [default=auto]]),
124124
[use_ecmult_static_precomputation=$enableval],
125125
[use_ecmult_static_precomputation=auto])
126126

@@ -129,47 +129,72 @@ AC_ARG_ENABLE(module_ecdh,
129129
[enable_module_ecdh=$enableval],
130130
[enable_module_ecdh=no])
131131

132+
AC_ARG_ENABLE(module_schnorrsig,
133+
AS_HELP_STRING([--enable-module-schnorrsig],[enable schnorrsig module (experimental)]),
134+
[enable_module_schnorrsig=$enableval],
135+
[enable_module_schnorrsig=no])
136+
137+
AC_ARG_ENABLE(module_musig,
138+
AS_HELP_STRING([--enable-module-musig],[enable MuSig module (experimental)]),
139+
[enable_module_musig=$enableval],
140+
[enable_module_musig=no])
141+
132142
AC_ARG_ENABLE(module_recovery,
133-
AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module (default is no)]),
143+
AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module [default=no]]),
134144
[enable_module_recovery=$enableval],
135145
[enable_module_recovery=no])
136146

137147
AC_ARG_ENABLE(module_generator,
138-
AS_HELP_STRING([--enable-module-generator],[enable NUMS generator module (default is no)]),
148+
AS_HELP_STRING([--enable-module-generator],[enable NUMS generator module [default=no]]),
139149
[enable_module_generator=$enableval],
140150
[enable_module_generator=no])
141151

142152
AC_ARG_ENABLE(module_rangeproof,
143-
AS_HELP_STRING([--enable-module-rangeproof],[enable Pedersen / zero-knowledge range proofs module (default is no)]),
153+
AS_HELP_STRING([--enable-module-rangeproof],[enable Pedersen / zero-knowledge range proofs module [default=no]]),
144154
[enable_module_rangeproof=$enableval],
145155
[enable_module_rangeproof=no])
146156

147157
AC_ARG_ENABLE(module_whitelist,
148-
AS_HELP_STRING([--enable-module-whitelist],[enable key whitelisting module (default is no)]),
158+
AS_HELP_STRING([--enable-module-whitelist],[enable key whitelisting module [default=no]]),
149159
[enable_module_whitelist=$enableval],
150160
[enable_module_whitelist=no])
151161

162+
AC_ARG_ENABLE(external_default_callbacks,
163+
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions [default=no]]),
164+
[use_external_default_callbacks=$enableval],
165+
[use_external_default_callbacks=no])
166+
152167
AC_ARG_ENABLE(jni,
153-
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is no)]),
168+
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni [default=no]]),
154169
[use_jni=$enableval],
155170
[use_jni=no])
156171

157172
AC_ARG_ENABLE(module_surjectionproof,
158-
AS_HELP_STRING([--enable-module-surjectionproof],[enable surjection proof module (default is no)]),
173+
AS_HELP_STRING([--enable-module-surjectionproof],[enable surjection proof module [default=no]]),
159174
[enable_module_surjectionproof=$enableval],
160175
[enable_module_surjectionproof=no])
161176

162177
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
163-
[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
178+
[finite field implementation to use [default=auto]])],[req_field=$withval], [req_field=auto])
164179

165180
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
166-
[Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
181+
[bignum implementation to use [default=auto]])],[req_bignum=$withval], [req_bignum=auto])
167182

168183
AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
169-
[Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
184+
[scalar implementation to use [default=auto]])],[req_scalar=$withval], [req_scalar=auto])
185+
186+
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
187+
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
170188

171-
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
172-
[Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
189+
# Default is window size 16 (or window size 15 with endomorphism) which needs 1.375 MiB. */
190+
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
191+
[window size for ecmult precomputation for verification, specified as integer in range [3..24].]
192+
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
193+
[The table will store 2^(SIZE-2) * 64 bytes of data but can be larger in memory due]
194+
[to platform-specific padding and alignment. "auto" is a reasonable setting for desktop machines]
195+
[(currently 15 if the endomorphism optimization is disabled and 16 if it is enabled). [default=auto]]
196+
)],
197+
[req_ecmult_window=$withval], [req_ecmult_window=auto])
173198

174199
AC_CHECK_TYPES([__int128])
175200

@@ -196,48 +221,25 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_popcount(0);}]])],
196221
if test x"$use_ecmult_static_precomputation" != x"no"; then
197222
save_cross_compiling=$cross_compiling
198223
cross_compiling=no
199-
SAVE_CC="$CC"
224+
TEMP_CC="$CC"
200225
CC="$CC_FOR_BUILD"
201-
SAVE_CFLAGS="$CFLAGS"
202-
CFLAGS="$CFLAGS_FOR_BUILD"
203-
SAVE_CPPFLAGS="$CPPFLAGS"
204-
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
205-
SAVE_LDFLAGS="$LDFLAGS"
206-
LDFLAGS="$LDFLAGS_FOR_BUILD"
207-
208-
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
209-
saved_CFLAGS="$CFLAGS"
210-
CFLAGS="$CFLAGS $warn_CFLAGS_FOR_BUILD"
211-
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
212-
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
213-
[ AC_MSG_RESULT([yes]) ],
214-
[ AC_MSG_RESULT([no])
215-
CFLAGS="$saved_CFLAGS"
216-
])
217-
218-
AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
226+
AC_MSG_CHECKING([native compiler: ${CC_FOR_BUILD}])
219227
AC_RUN_IFELSE(
220228
[AC_LANG_PROGRAM([], [return 0])],
221229
[working_native_cc=yes],
222230
[working_native_cc=no],[dnl])
223-
224-
CFLAGS_FOR_BUILD="$CFLAGS"
225-
CPPFLAGS="$SAVE_CPPFLAGS"
226-
CFLAGS="$SAVE_CFLAGS"
227-
LDFLAGS="$SAVE_LDFLAGS"
228-
CC="$SAVE_CC"
231+
CC="$TEMP_CC"
229232
cross_compiling=$save_cross_compiling
230233

231234
if test x"$working_native_cc" = x"no"; then
232-
AC_MSG_RESULT([no])
233235
set_precomp=no
234236
if test x"$use_ecmult_static_precomputation" = x"yes"; then
235-
AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD and/or CFLAGS_FOR_BUILD.])
237+
AC_MSG_ERROR([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
236238
else
237-
AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD and/or CFLAGS_FOR_BUILD.])
239+
AC_MSG_RESULT([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
238240
fi
239241
else
240-
AC_MSG_RESULT([yes])
242+
AC_MSG_RESULT([ok])
241243
set_precomp=yes
242244
fi
243245
else
@@ -421,6 +423,32 @@ case $set_scalar in
421423
;;
422424
esac
423425

426+
#set ecmult window size
427+
if test x"$req_ecmult_window" = x"auto"; then
428+
if test x"$use_endomorphism" = x"yes"; then
429+
set_ecmult_window=16
430+
else
431+
set_ecmult_window=15
432+
fi
433+
else
434+
set_ecmult_window=$req_ecmult_window
435+
fi
436+
437+
error_window_size=['window size for ecmult precomputation not an integer in range [3..24] or "auto"']
438+
case $set_ecmult_window in
439+
''|*[[!0-9]]*)
440+
# no valid integer
441+
AC_MSG_ERROR($error_window_size)
442+
;;
443+
*)
444+
if test "$set_ecmult_window" -lt 3 -o "$set_ecmult_window" -gt 24 ; then
445+
# not in range
446+
AC_MSG_ERROR($error_window_size)
447+
fi
448+
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
449+
;;
450+
esac
451+
424452
if test x"$use_tests" = x"yes"; then
425453
SECP_OPENSSL_CHECK
426454
if test x"$has_openssl_ec" = x"yes"; then
@@ -455,9 +483,6 @@ if test x"$use_jni" != x"no"; then
455483
if test "x$JNI_INCLUDE_DIRS" = "x"; then
456484
have_jni_dependencies=no
457485
fi
458-
if test "x$have_jni_dependencies" = "xno"; then
459-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <jni.h>]])], [have_jni_dependencies=yes])
460-
fi
461486
if test "x$have_jni_dependencies" = "xno"; then
462487
if test x"$use_jni" = x"yes"; then
463488
AC_MSG_ERROR([jni support explicitly requested but headers/dependencies were not found. Enable ECDH and try again.])
@@ -489,6 +514,14 @@ if test x"$enable_module_ecdh" = x"yes"; then
489514
AC_DEFINE(ENABLE_MODULE_ECDH, 1, [Define this symbol to enable the ECDH module])
490515
fi
491516

517+
if test x"$enable_module_schnorrsig" = x"yes"; then
518+
AC_DEFINE(ENABLE_MODULE_SCHNORRSIG, 1, [Define this symbol to enable the schnorrsig module])
519+
fi
520+
521+
if test x"$enable_module_musig" = x"yes"; then
522+
AC_DEFINE(ENABLE_MODULE_MUSIG, 1, [Define this symbol to enable the MuSig module])
523+
fi
524+
492525
if test x"$enable_module_recovery" = x"yes"; then
493526
AC_DEFINE(ENABLE_MODULE_RECOVERY, 1, [Define this symbol to enable the ECDSA pubkey recovery module])
494527
fi
@@ -515,17 +548,9 @@ if test x"$use_external_asm" = x"yes"; then
515548
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
516549
fi
517550

518-
AC_MSG_NOTICE([Using static precomputation: $set_precomp])
519-
AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
520-
AC_MSG_NOTICE([Using field implementation: $set_field])
521-
AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
522-
AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
523-
AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
524-
AC_MSG_NOTICE([Building benchmarks: $use_benchmark])
525-
AC_MSG_NOTICE([Building for coverage analysis: $enable_coverage])
526-
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
527-
AC_MSG_NOTICE([Building ECDSA pubkey recovery module: $enable_module_recovery])
528-
AC_MSG_NOTICE([Using jni: $use_jni])
551+
if test x"$use_external_default_callbacks" = x"yes"; then
552+
AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used])
553+
fi
529554

530555
if test x"$enable_experimental" = x"yes"; then
531556
AC_MSG_NOTICE([******])
@@ -536,8 +561,17 @@ if test x"$enable_experimental" = x"yes"; then
536561
AC_MSG_NOTICE([Building range proof module: $enable_module_rangeproof])
537562
AC_MSG_NOTICE([Building key whitelisting module: $enable_module_whitelist])
538563
AC_MSG_NOTICE([Building surjection proof module: $enable_module_surjectionproof])
564+
AC_MSG_NOTICE([Building schnorrsig module: $enable_module_schnorrsig])
565+
AC_MSG_NOTICE([Building MuSig module: $enable_module_musig])
539566
AC_MSG_NOTICE([******])
540567

568+
569+
if test x"$enable_module_schnorrsig" != x"yes"; then
570+
if test x"$enable_module_musig" = x"yes"; then
571+
AC_MSG_ERROR([MuSig module requires the schnorrsig module. Use --enable-module-schnorrsig to allow.])
572+
fi
573+
fi
574+
541575
if test x"$enable_module_generator" != x"yes"; then
542576
if test x"$enable_module_rangeproof" = x"yes"; then
543577
AC_MSG_ERROR([Rangeproof module requires the generator module. Use --enable-module-generator to allow.])
@@ -556,6 +590,12 @@ else
556590
if test x"$enable_module_ecdh" = x"yes"; then
557591
AC_MSG_ERROR([ECDH module is experimental. Use --enable-experimental to allow.])
558592
fi
593+
if test x"$enable_module_schnorrsig" = x"yes"; then
594+
AC_MSG_ERROR([schnorrsig module is experimental. Use --enable-experimental to allow.])
595+
fi
596+
if test x"$enable_module_musig" = x"yes"; then
597+
AC_MSG_ERROR([MuSig module is experimental. Use --enable-experimental to allow.])
598+
fi
559599
if test x"$set_asm" = x"arm"; then
560600
AC_MSG_ERROR([ARM assembly optimization is experimental. Use --enable-experimental to allow.])
561601
fi
@@ -586,6 +626,8 @@ AM_CONDITIONAL([USE_EXHAUSTIVE_TESTS], [test x"$use_exhaustive_tests" != x"no"])
586626
AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
587627
AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
588628
AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
629+
AM_CONDITIONAL([ENABLE_MODULE_SCHNORRSIG], [test x"$enable_module_schnorrsig" = x"yes"])
630+
AM_CONDITIONAL([ENABLE_MODULE_MUSIG], [test x"$enable_module_musig" = x"yes"])
589631
AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
590632
AM_CONDITIONAL([ENABLE_MODULE_GENERATOR], [test x"$enable_module_generator" = x"yes"])
591633
AM_CONDITIONAL([ENABLE_MODULE_RANGEPROOF], [test x"$enable_module_rangeproof" = x"yes"])
@@ -601,3 +643,26 @@ unset PKG_CONFIG_PATH
601643
PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
602644

603645
AC_OUTPUT
646+
647+
echo
648+
echo "Build Options:"
649+
echo " with endomorphism = $use_endomorphism"
650+
echo " with ecmult precomp = $set_precomp"
651+
echo " with external callbacks = $use_external_default_callbacks"
652+
echo " with jni = $use_jni"
653+
echo " with benchmarks = $use_benchmark"
654+
echo " with coverage = $enable_coverage"
655+
echo " module ecdh = $enable_module_ecdh"
656+
echo " module recovery = $enable_module_recovery"
657+
echo
658+
echo " asm = $set_asm"
659+
echo " bignum = $set_bignum"
660+
echo " field = $set_field"
661+
echo " scalar = $set_scalar"
662+
echo " ecmult window size = $set_ecmult_window"
663+
echo
664+
echo " CC = $CC"
665+
echo " CFLAGS = $CFLAGS"
666+
echo " CPPFLAGS = $CPPFLAGS"
667+
echo " LDFLAGS = $LDFLAGS"
668+
echo

0 commit comments

Comments
 (0)