Skip to content

Commit ce9efb0

Browse files
committed
Update libsecp256k1 upstream to 143dc6e
1 parent 0fbc0f9 commit ce9efb0

32 files changed

+1246
-455
lines changed

depend/secp256k1/.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: c
2-
sudo: false
2+
os: linux
33
addons:
44
apt:
55
packages: libgmp-dev
@@ -66,4 +66,3 @@ script:
6666
- if [ -n "$HOST" ]; then export USE_HOST="--host=$HOST"; fi
6767
- if [ "x$HOST" = "xi686-linux-gnu" ]; then export CC="$CC -m32"; fi
6868
- ./configure --enable-experimental=$EXPERIMENTAL --enable-endomorphism=$ENDOMORPHISM --with-field=$FIELD --with-bignum=$BIGNUM --with-scalar=$SCALAR --enable-ecmult-static-precomputation=$STATICPRECOMPUTATION --enable-module-ecdh=$ECDH --enable-module-recovery=$RECOVERY --enable-jni=$JNI $EXTRAFLAGS $USE_HOST && make -j2 $BUILD
69-
os: linux

depend/secp256k1/Makefile.am

+3-3
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
@@ -114,7 +115,7 @@ exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDE
114115
if !ENABLE_COVERAGE
115116
exhaustive_tests_CPPFLAGS += -DVERIFY
116117
endif
117-
exhaustive_tests_LDADD = $(SECP_LIBS)
118+
exhaustive_tests_LDADD = $(SECP_LIBS) $(COMMON_LIB)
118119
exhaustive_tests_LDFLAGS = -static
119120
TESTS += exhaustive_tests
120121
endif
@@ -151,15 +152,14 @@ endif
151152

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

156156
gen_context_OBJECTS = gen_context.o
157157
gen_context_BIN = gen_context$(BUILD_EXEEXT)
158158
gen_%.o: src/gen_%.c
159159
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
160160

161161
$(gen_context_BIN): $(gen_context_OBJECTS)
162-
$(CC_FOR_BUILD) $^ -o $@
162+
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
163163

164164
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
165165
$(tests_OBJECTS): src/ecmult_static_context.h

depend/secp256k1/configure.ac

+113-41
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

@@ -130,65 +130,100 @@ AC_ARG_ENABLE(module_ecdh,
130130
[enable_module_ecdh=no])
131131

132132
AC_ARG_ENABLE(module_recovery,
133-
AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module (default is no)]),
133+
AS_HELP_STRING([--enable-module-recovery],[enable ECDSA pubkey recovery module [default=no]]),
134134
[enable_module_recovery=$enableval],
135135
[enable_module_recovery=no])
136136

137+
AC_ARG_ENABLE(external_default_callbacks,
138+
AS_HELP_STRING([--enable-external-default-callbacks],[enable external default callback functions (default is no)]),
139+
[use_external_default_callbacks=$enableval],
140+
[use_external_default_callbacks=no])
141+
137142
AC_ARG_ENABLE(jni,
138-
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni (default is no)]),
143+
AS_HELP_STRING([--enable-jni],[enable libsecp256k1_jni [default=no]]),
139144
[use_jni=$enableval],
140145
[use_jni=no])
141146

142147
AC_ARG_WITH([field], [AS_HELP_STRING([--with-field=64bit|32bit|auto],
143-
[Specify Field Implementation. Default is auto])],[req_field=$withval], [req_field=auto])
148+
[finite field implementation to use [default=auto]])],[req_field=$withval], [req_field=auto])
144149

145150
AC_ARG_WITH([bignum], [AS_HELP_STRING([--with-bignum=gmp|no|auto],
146-
[Specify Bignum Implementation. Default is auto])],[req_bignum=$withval], [req_bignum=auto])
151+
[bignum implementation to use [default=auto]])],[req_bignum=$withval], [req_bignum=auto])
147152

148153
AC_ARG_WITH([scalar], [AS_HELP_STRING([--with-scalar=64bit|32bit|auto],
149-
[Specify scalar implementation. Default is auto])],[req_scalar=$withval], [req_scalar=auto])
154+
[scalar implementation to use [default=auto]])],[req_scalar=$withval], [req_scalar=auto])
150155

151-
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto]
152-
[Specify assembly optimizations to use. Default is auto (experimental: arm)])],[req_asm=$withval], [req_asm=auto])
156+
AC_ARG_WITH([asm], [AS_HELP_STRING([--with-asm=x86_64|arm|no|auto],
157+
[assembly optimizations to use (experimental: arm) [default=auto]])],[req_asm=$withval], [req_asm=auto])
153158

154-
AC_CHECK_TYPES([__int128])
159+
AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
160+
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
161+
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
162+
[The table will store 2^(SIZE-2) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
163+
[If the endomorphism optimization is enabled, two tables of this size are used instead of only one.]
164+
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
165+
)],
166+
[req_ecmult_window=$withval], [req_ecmult_window=auto])
155167

156-
AC_MSG_CHECKING([for __builtin_expect])
157-
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[void myfunc() {__builtin_expect(0,0);}]])],
158-
[ AC_MSG_RESULT([yes]);AC_DEFINE(HAVE_BUILTIN_EXPECT,1,[Define this symbol if __builtin_expect is available]) ],
159-
[ AC_MSG_RESULT([no])
160-
])
168+
AC_CHECK_TYPES([__int128])
161169

162170
if test x"$enable_coverage" = x"yes"; then
163171
AC_DEFINE(COVERAGE, 1, [Define this symbol to compile out all VERIFY code])
164172
CFLAGS="$CFLAGS -O0 --coverage"
165-
LDFLAGS="--coverage"
173+
LDFLAGS="$LDFLAGS --coverage"
166174
else
167175
CFLAGS="$CFLAGS -O3"
168176
fi
169177

170178
if test x"$use_ecmult_static_precomputation" != x"no"; then
179+
# Temporarily switch to an environment for the native compiler
171180
save_cross_compiling=$cross_compiling
172181
cross_compiling=no
173-
TEMP_CC="$CC"
182+
SAVE_CC="$CC"
174183
CC="$CC_FOR_BUILD"
175-
AC_MSG_CHECKING([native compiler: ${CC_FOR_BUILD}])
184+
SAVE_CFLAGS="$CFLAGS"
185+
CFLAGS="$CFLAGS_FOR_BUILD"
186+
SAVE_CPPFLAGS="$CPPFLAGS"
187+
CPPFLAGS="$CPPFLAGS_FOR_BUILD"
188+
SAVE_LDFLAGS="$LDFLAGS"
189+
LDFLAGS="$LDFLAGS_FOR_BUILD"
190+
191+
warn_CFLAGS_FOR_BUILD="-Wall -Wextra -Wno-unused-function"
192+
saved_CFLAGS="$CFLAGS"
193+
CFLAGS="$CFLAGS $warn_CFLAGS_FOR_BUILD"
194+
AC_MSG_CHECKING([if native ${CC_FOR_BUILD} supports ${warn_CFLAGS_FOR_BUILD}])
195+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
196+
[ AC_MSG_RESULT([yes]) ],
197+
[ AC_MSG_RESULT([no])
198+
CFLAGS="$saved_CFLAGS"
199+
])
200+
201+
AC_MSG_CHECKING([for working native compiler: ${CC_FOR_BUILD}])
176202
AC_RUN_IFELSE(
177-
[AC_LANG_PROGRAM([], [return 0])],
203+
[AC_LANG_PROGRAM([], [])],
178204
[working_native_cc=yes],
179205
[working_native_cc=no],[dnl])
180-
CC="$TEMP_CC"
206+
207+
CFLAGS_FOR_BUILD="$CFLAGS"
208+
209+
# Restore the environment
181210
cross_compiling=$save_cross_compiling
211+
CC="$SAVE_CC"
212+
CFLAGS="$SAVE_CFLAGS"
213+
CPPFLAGS="$SAVE_CPPFLAGS"
214+
LDFLAGS="$SAVE_LDFLAGS"
182215

183216
if test x"$working_native_cc" = x"no"; then
217+
AC_MSG_RESULT([no])
184218
set_precomp=no
219+
m4_define([please_set_for_build], [Please set CC_FOR_BUILD, CFLAGS_FOR_BUILD, CPPFLAGS_FOR_BUILD, and/or LDFLAGS_FOR_BUILD.])
185220
if test x"$use_ecmult_static_precomputation" = x"yes"; then
186-
AC_MSG_ERROR([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
221+
AC_MSG_ERROR([native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
187222
else
188-
AC_MSG_RESULT([${CC_FOR_BUILD} does not produce working binaries. Please set CC_FOR_BUILD])
223+
AC_MSG_WARN([Disabling statically generated ecmult table because the native compiler ${CC_FOR_BUILD} does not produce working binaries. please_set_for_build])
189224
fi
190225
else
191-
AC_MSG_RESULT([ok])
226+
AC_MSG_RESULT([yes])
192227
set_precomp=yes
193228
fi
194229
else
@@ -366,6 +401,28 @@ case $set_scalar in
366401
;;
367402
esac
368403

404+
#set ecmult window size
405+
if test x"$req_ecmult_window" = x"auto"; then
406+
set_ecmult_window=15
407+
else
408+
set_ecmult_window=$req_ecmult_window
409+
fi
410+
411+
error_window_size=['window size for ecmult precomputation not an integer in range [2..24] or "auto"']
412+
case $set_ecmult_window in
413+
''|*[[!0-9]]*)
414+
# no valid integer
415+
AC_MSG_ERROR($error_window_size)
416+
;;
417+
*)
418+
if test "$set_ecmult_window" -lt 2 -o "$set_ecmult_window" -gt 24 ; then
419+
# not in range
420+
AC_MSG_ERROR($error_window_size)
421+
fi
422+
AC_DEFINE_UNQUOTED(ECMULT_WINDOW_SIZE, $set_ecmult_window, [Set window size for ecmult precomputation])
423+
;;
424+
esac
425+
369426
if test x"$use_tests" = x"yes"; then
370427
SECP_OPENSSL_CHECK
371428
if test x"$has_openssl_ec" = x"yes"; then
@@ -441,17 +498,9 @@ if test x"$use_external_asm" = x"yes"; then
441498
AC_DEFINE(USE_EXTERNAL_ASM, 1, [Define this symbol if an external (non-inline) assembly implementation is used])
442499
fi
443500

444-
AC_MSG_NOTICE([Using static precomputation: $set_precomp])
445-
AC_MSG_NOTICE([Using assembly optimizations: $set_asm])
446-
AC_MSG_NOTICE([Using field implementation: $set_field])
447-
AC_MSG_NOTICE([Using bignum implementation: $set_bignum])
448-
AC_MSG_NOTICE([Using scalar implementation: $set_scalar])
449-
AC_MSG_NOTICE([Using endomorphism optimizations: $use_endomorphism])
450-
AC_MSG_NOTICE([Building benchmarks: $use_benchmark])
451-
AC_MSG_NOTICE([Building for coverage analysis: $enable_coverage])
452-
AC_MSG_NOTICE([Building ECDH module: $enable_module_ecdh])
453-
AC_MSG_NOTICE([Building ECDSA pubkey recovery module: $enable_module_recovery])
454-
AC_MSG_NOTICE([Using jni: $use_jni])
501+
if test x"$use_external_default_callbacks" = x"yes"; then
502+
AC_DEFINE(USE_EXTERNAL_DEFAULT_CALLBACKS, 1, [Define this symbol if an external implementation of the default callbacks is used])
503+
fi
455504

456505
if test x"$enable_experimental" = x"yes"; then
457506
AC_MSG_NOTICE([******])
@@ -482,7 +531,7 @@ AM_CONDITIONAL([USE_BENCHMARK], [test x"$use_benchmark" = x"yes"])
482531
AM_CONDITIONAL([USE_ECMULT_STATIC_PRECOMPUTATION], [test x"$set_precomp" = x"yes"])
483532
AM_CONDITIONAL([ENABLE_MODULE_ECDH], [test x"$enable_module_ecdh" = x"yes"])
484533
AM_CONDITIONAL([ENABLE_MODULE_RECOVERY], [test x"$enable_module_recovery" = x"yes"])
485-
AM_CONDITIONAL([USE_JNI], [test x"$use_jni" == x"yes"])
534+
AM_CONDITIONAL([USE_JNI], [test x"$use_jni" = x"yes"])
486535
AM_CONDITIONAL([USE_EXTERNAL_ASM], [test x"$use_external_asm" = x"yes"])
487536
AM_CONDITIONAL([USE_ASM_ARM], [test x"$set_asm" = x"arm"])
488537

@@ -492,3 +541,26 @@ unset PKG_CONFIG_PATH
492541
PKG_CONFIG_PATH="$PKGCONFIG_PATH_TEMP"
493542

494543
AC_OUTPUT
544+
545+
echo
546+
echo "Build Options:"
547+
echo " with endomorphism = $use_endomorphism"
548+
echo " with ecmult precomp = $set_precomp"
549+
echo " with external callbacks = $use_external_default_callbacks"
550+
echo " with jni = $use_jni"
551+
echo " with benchmarks = $use_benchmark"
552+
echo " with coverage = $enable_coverage"
553+
echo " module ecdh = $enable_module_ecdh"
554+
echo " module recovery = $enable_module_recovery"
555+
echo
556+
echo " asm = $set_asm"
557+
echo " bignum = $set_bignum"
558+
echo " field = $set_field"
559+
echo " scalar = $set_scalar"
560+
echo " ecmult window size = $set_ecmult_window"
561+
echo
562+
echo " CC = $CC"
563+
echo " CFLAGS = $CFLAGS"
564+
echo " CPPFLAGS = $CPPFLAGS"
565+
echo " LDFLAGS = $LDFLAGS"
566+
echo

0 commit comments

Comments
 (0)