Skip to content

Commit f727914

Browse files
committed
Squashed 'src/secp256k1/' changes from be8d9c2..21c188b
21c188b Merge bitcoin-core/secp256k1#943: VERIFY_CHECK precondition for secp256k1_fe_set_int. 3e7b2ea Merge bitcoin-core/secp256k1#999: bench_ecmult: improve clarity of output 23e2f66 bench: don't return 1 in have_flag() if argc = 1 96b1ad2 bench_ecmult: improve clarity of output 20d791e Merge bitcoin-core/secp256k1#989: Shared benchmark format for command line and CSV outputs aa1b889 Merge bitcoin-core/secp256k1#996: Fix G.y parity in sage code 044d956 Fix G.y parity in sage code b4b1306 create csv file from the benchmark output 26a255b Shared benchmark format for command line and CSV outputs 9526874 Merge bitcoin-core/secp256k1#810: Avoid overly-wide multiplications in 5x52 field mul/sqr 920a0e5 Merge bitcoin-core/secp256k1#952: Avoid computing out-of-bounds pointer. f34b5ca Merge bitcoin-core/secp256k1#983: [RFC] Remove OpenSSL testing support 297ce82 Merge bitcoin-core/secp256k1#966: Make aux_rand32 arg to secp256k1_schnorrsig_sign const 2888640 VERIFY_CHECK precondition for secp256k1_fe_set_int. d49011f Make _set_fe_int( . , 0 ) set magnitude to 0 bc08599 Remove OpenSSL testing support 10f9bd8 Merge bitcoin-core/secp256k1#987: Fix unused parameter warnings when building without VERIFY 189f6bc Fix unused parameter warnings when building without VERIFY da0092b Merge bitcoin-core/secp256k1#986: tests: remove `secp256k1_fe_verify` from tests.c and modify `_fe_from_storage` to call `_fe_verify` d439937 tests: remove `secp256k1_fe_verify` from tests.c and modify `secp256k1_fe_from_storage` to call `secp256k1_fe_verify` 2a3a97c Merge bitcoin-core/secp256k1#976: `secp256k1_schnorrsig_sign_internal` should be static aa5d34a Merge bitcoin-core/secp256k1#783: Make the public API docs more consistent and explicit 7271387 Add missing static to secp256k1_schnorrsig_sign_internal db4667d Make aux_rand32 arg to secp256k1_schnorrsig_sign const 9a5a87e Merge bitcoin-core/secp256k1#956: Replace ecmult_context with a generated static array. 20abd52 Add tests for pre_g tables. 6815761 Remove ecmult_context. f20dcbb Correct typo. 16a3cc0 Generate ecmult_static_pre_g.h 8de2d86 Bump memory limits in advance of making the ecmult context static. d7ec49a Merge bitcoin-core/secp256k1#969: ci: Fixes after Debian release 5d5c74a tests: Rewrite code to circument potential bug in clang 3d2f492 ci: Install libasan6 (instead of 5) after Debian upgrade adec5a1 Add missing null check for ctx and input keys in the public API f4edfc7 Improve consistency for NULL arguments in the public interface 9be7b0f Avoid computing out-of-bounds pointer. b53e0cd Avoid overly-wide multiplications git-subtree-dir: src/secp256k1 git-subtree-split: 21c188b
1 parent c020cba commit f727914

Some content is hidden

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

46 files changed

+17328
-962
lines changed

.cirrus.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ task:
278278
container:
279279
dockerfile: ci/linux-debian.Dockerfile
280280
cpu: 1
281-
memory: 1G
281+
memory: 2G
282282
env:
283283
ECDH: yes
284284
RECOVERY: yes
285285
EXPERIMENTAL: yes
286286
SCHNORRSIG: yes
287287
CTIMETEST: no
288-
EXTRAFLAGS: "--disable-openssl-tests"
289288
matrix:
290289
- name: "Valgrind (memcheck)"
291290
env:

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/ecmult_static_pre_g.h linguist-generated

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ bench_internal
99
tests
1010
exhaustive_tests
1111
gen_context
12+
gen_ecmult_static_pre_g
1213
valgrind_ctime_test
1314
*.exe
1415
*.so
1516
*.a
17+
*.csv
1618
!.gitignore
1719

1820
Makefile

Makefile.am

+9-4
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ if USE_BENCHMARK
8484
noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8585
bench_verify_SOURCES = src/bench_verify.c
8686
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
87-
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
88-
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
8987
bench_sign_SOURCES = src/bench_sign.c
9088
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
9189
bench_internal_SOURCES = src/bench_internal.c
@@ -127,12 +125,19 @@ exhaustive_tests_LDFLAGS = -static
127125
TESTS += exhaustive_tests
128126
endif
129127

128+
EXTRA_PROGRAMS = gen_ecmult_static_pre_g
129+
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
130+
# See Automake manual, Section "Errors with distclean"
131+
src/ecmult_static_pre_g.h:
132+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
133+
./gen_ecmult_static_pre_g$(EXEEXT)
134+
130135
if USE_ECMULT_STATIC_PRECOMPUTATION
131136
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
132137

133138
gen_context_OBJECTS = gen_context.o
134139
gen_context_BIN = gen_context$(BUILD_EXEEXT)
135-
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
140+
$(gen_context_OBJECTS): src/gen_context.c src/libsecp256k1-config.h
136141
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
137142

138143
$(gen_context_BIN): $(gen_context_OBJECTS)
@@ -149,7 +154,7 @@ src/ecmult_static_context.h: $(gen_context_BIN)
149154
CLEANFILES = $(gen_context_BIN) src/ecmult_static_context.h
150155
endif
151156

152-
EXTRA_DIST = autogen.sh src/gen_context.c src/basic-config.h
157+
EXTRA_DIST = autogen.sh src/gen_context.c src/ecmult_static_pre_g.h src/basic-config.h
153158

154159
if ENABLE_MODULE_ECDH
155160
include src/modules/ecdh/Makefile.am.include

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ To create a HTML report with coloured and annotated source code:
100100
$ mkdir -p coverage
101101
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html
102102

103+
Benchmark
104+
------------
105+
If configured with `--enable-benchmark` (which is the default), binaries for benchmarking the libsecp256k1 functions will be present in the root directory after the build.
106+
107+
To print the benchmark result to the command line:
108+
109+
$ ./bench_name
110+
111+
To create a CSV file for the benchmark result :
112+
113+
$ ./bench_name | sed '2d;s/ \{1,\}//g' > bench_name.csv
114+
103115
Reporting a vulnerability
104116
------------
105117

build-aux/m4/bitcoin_secp.m4

-66
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,6 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
99
AC_MSG_RESULT([$has_64bit_asm])
1010
])
1111

12-
dnl
13-
AC_DEFUN([SECP_OPENSSL_CHECK],[
14-
has_libcrypto=no
15-
m4_ifdef([PKG_CHECK_MODULES],[
16-
PKG_CHECK_MODULES([CRYPTO], [libcrypto], [has_libcrypto=yes],[has_libcrypto=no])
17-
if test x"$has_libcrypto" = x"yes"; then
18-
TEMP_LIBS="$LIBS"
19-
LIBS="$LIBS $CRYPTO_LIBS"
20-
AC_CHECK_LIB(crypto, main,[AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])],[has_libcrypto=no])
21-
LIBS="$TEMP_LIBS"
22-
fi
23-
])
24-
if test x$has_libcrypto = xno; then
25-
AC_CHECK_HEADER(openssl/crypto.h,[
26-
AC_CHECK_LIB(crypto, main,[
27-
has_libcrypto=yes
28-
CRYPTO_LIBS=-lcrypto
29-
AC_DEFINE(HAVE_LIBCRYPTO,1,[Define this symbol if libcrypto is installed])
30-
])
31-
])
32-
LIBS=
33-
fi
34-
if test x"$has_libcrypto" = x"yes" && test x"$has_openssl_ec" = x; then
35-
AC_MSG_CHECKING(for EC functions in libcrypto)
36-
CPPFLAGS_TEMP="$CPPFLAGS"
37-
CPPFLAGS="$CRYPTO_CPPFLAGS $CPPFLAGS"
38-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
39-
#include <openssl/bn.h>
40-
#include <openssl/ec.h>
41-
#include <openssl/ecdsa.h>
42-
#include <openssl/obj_mac.h>]],[[
43-
# if OPENSSL_VERSION_NUMBER < 0x10100000L
44-
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) {(void)sig->r; (void)sig->s;}
45-
# endif
46-
47-
unsigned int zero = 0;
48-
const unsigned char *zero_ptr = (unsigned char*)&zero;
49-
EC_KEY_free(EC_KEY_new_by_curve_name(NID_secp256k1));
50-
EC_KEY *eckey = EC_KEY_new();
51-
EC_GROUP *group = EC_GROUP_new_by_curve_name(NID_secp256k1);
52-
EC_KEY_set_group(eckey, group);
53-
ECDSA_sign(0, NULL, 0, NULL, &zero, eckey);
54-
ECDSA_verify(0, NULL, 0, NULL, 0, eckey);
55-
o2i_ECPublicKey(&eckey, &zero_ptr, 0);
56-
d2i_ECPrivateKey(&eckey, &zero_ptr, 0);
57-
EC_KEY_check_key(eckey);
58-
EC_KEY_free(eckey);
59-
EC_GROUP_free(group);
60-
ECDSA_SIG *sig_openssl;
61-
sig_openssl = ECDSA_SIG_new();
62-
d2i_ECDSA_SIG(&sig_openssl, &zero_ptr, 0);
63-
i2d_ECDSA_SIG(sig_openssl, NULL);
64-
ECDSA_SIG_get0(sig_openssl, NULL, NULL);
65-
ECDSA_SIG_free(sig_openssl);
66-
const BIGNUM *bignum = BN_value_one();
67-
BN_is_negative(bignum);
68-
BN_num_bits(bignum);
69-
if (sizeof(zero) >= BN_num_bytes(bignum)) {
70-
BN_bn2bin(bignum, (unsigned char*)&zero);
71-
}
72-
]])],[has_openssl_ec=yes],[has_openssl_ec=no])
73-
AC_MSG_RESULT([$has_openssl_ec])
74-
CPPFLAGS="$CPPFLAGS_TEMP"
75-
fi
76-
])
77-
7812
AC_DEFUN([SECP_VALGRIND_CHECK],[
7913
if test x"$has_valgrind" != x"yes"; then
8014
CPPFLAGS_TEMP="$CPPFLAGS"

ci/linux-debian.Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN apt-get install --no-install-recommends --no-upgrade -y \
1414
make automake libtool pkg-config dpkg-dev valgrind qemu-user \
1515
gcc clang llvm libc6-dbg \
1616
g++ \
17-
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan5:i386 \
17+
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan6:i386 \
1818
gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
1919
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \
2020
gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \

configure.ac

+2-38
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ case $host_os in
4343
# These Homebrew packages may be keg-only, meaning that they won't be found
4444
# in expected paths because they may conflict with system files. Ask
4545
# Homebrew where each one is located, then adjust paths accordingly.
46-
openssl_prefix=`$BREW --prefix openssl 2>/dev/null`
4746
valgrind_prefix=`$BREW --prefix valgrind 2>/dev/null`
48-
if test x$openssl_prefix != x; then
49-
PKG_CONFIG_PATH="$openssl_prefix/lib/pkgconfig:$PKG_CONFIG_PATH"
50-
export PKG_CONFIG_PATH
51-
CRYPTO_CPPFLAGS="-I$openssl_prefix/include"
52-
fi
5347
if test x$valgrind_prefix != x; then
5448
VALGRIND_CPPFLAGS="-I$valgrind_prefix/include"
5549
fi
@@ -121,11 +115,6 @@ AC_ARG_ENABLE(tests,
121115
[use_tests=$enableval],
122116
[use_tests=yes])
123117

124-
AC_ARG_ENABLE(openssl_tests,
125-
AS_HELP_STRING([--enable-openssl-tests],[enable OpenSSL tests [default=auto]]),
126-
[enable_openssl_tests=$enableval],
127-
[enable_openssl_tests=auto])
128-
129118
AC_ARG_ENABLE(experimental,
130119
AS_HELP_STRING([--enable-experimental],[allow experimental configure options [default=no]]),
131120
[use_experimental=$enableval],
@@ -177,6 +166,8 @@ AC_ARG_WITH([ecmult-window], [AS_HELP_STRING([--with-ecmult-window=SIZE|auto],
177166
[window size for ecmult precomputation for verification, specified as integer in range [2..24].]
178167
[Larger values result in possibly better performance at the cost of an exponentially larger precomputed table.]
179168
[The table will store 2^(SIZE-1) * 64 bytes of data but can be larger in memory due to platform-specific padding and alignment.]
169+
[A window size larger than 15 will require you delete the prebuilt ecmult_static_pre_g.h file so that it can be rebuilt.]
170+
[For very large window sizes, use "make -j 1" to reduce memory use during compilation.]
180171
["auto" is a reasonable setting for desktop machines (currently 15). [default=auto]]
181172
)],
182173
[req_ecmult_window=$withval], [req_ecmult_window=auto])
@@ -327,32 +318,6 @@ case $set_ecmult_gen_precision in
327318
;;
328319
esac
329320

330-
if test x"$use_tests" = x"yes"; then
331-
SECP_OPENSSL_CHECK
332-
if test x"$enable_openssl_tests" != x"no" && test x"$has_openssl_ec" = x"yes"; then
333-
enable_openssl_tests=yes
334-
AC_DEFINE(ENABLE_OPENSSL_TESTS, 1, [Define this symbol if OpenSSL EC functions are available])
335-
SECP_TEST_INCLUDES="$SSL_CFLAGS $CRYPTO_CFLAGS $CRYPTO_CPPFLAGS"
336-
SECP_TEST_LIBS="$CRYPTO_LIBS"
337-
338-
case $host in
339-
*mingw*)
340-
SECP_TEST_LIBS="$SECP_TEST_LIBS -lgdi32"
341-
;;
342-
esac
343-
else
344-
if test x"$enable_openssl_tests" = x"yes"; then
345-
AC_MSG_ERROR([OpenSSL tests requested but OpenSSL with EC support is not available])
346-
fi
347-
enable_openssl_tests=no
348-
fi
349-
else
350-
if test x"$enable_openssl_tests" = x"yes"; then
351-
AC_MSG_ERROR([OpenSSL tests requested but tests are not enabled])
352-
fi
353-
enable_openssl_tests=no
354-
fi
355-
356321
if test x"$enable_valgrind" = x"yes"; then
357322
SECP_INCLUDES="$SECP_INCLUDES $VALGRIND_CPPFLAGS"
358323
fi
@@ -517,7 +482,6 @@ echo " with ecmult precomp = $set_precomp"
517482
echo " with external callbacks = $use_external_default_callbacks"
518483
echo " with benchmarks = $use_benchmark"
519484
echo " with tests = $use_tests"
520-
echo " with openssl tests = $enable_openssl_tests"
521485
echo " with coverage = $enable_coverage"
522486
echo " module ecdh = $enable_module_ecdh"
523487
echo " module recovery = $enable_module_recovery"

0 commit comments

Comments
 (0)