Skip to content

Commit c020cba

Browse files
committed
Squashed 'src/secp256k1/' changes from efad350..be8d9c2
be8d9c2 Merge bitcoin-core/secp256k1#965: gen_context: Don't use any ASM aeece44 gen_context: Don't use any ASM 7688a4f Merge bitcoin-core/secp256k1#963: "Schnorrsig API overhaul" fixups 90e8344 ci: Add C++ test f698caa Use unsigned char consistently for byte arrays b5b8e7b Don't declare constants twice 769528f Don't use string literals for char arrays without NUL termination 2cc3cfa Fix -Wmissing-braces warning in clang 0440945 Merge dashpay#844: schnorrsig API overhaul ec3aaa5 Merge dashpay#960: tests_exhaustive: check the result of secp256k1_ecdsa_sign a1ee83c tests_exhaustive: check the result of secp256k1_ecdsa_sign 253f90c Merge bitcoin-core/secp256k1#951: configure: replace AC_PATH_PROG to AC_CHECK_PROG 446d28d Merge bitcoin-core/secp256k1#944: Various improvements related to CFLAGS 0302138 ci: Make compiler warning into errors on CI b924e1e build: Ensure that configure's compile checks default to -O2 7939cd5 build: List *CPPFLAGS before *CFLAGS like on the compiler command line 595e8a3 build: Enable -Wcast-align=strict warning 0725626 build: Use own variable SECP_CFLAGS instead of touching user CFLAGS 4866178 Merge bitcoin-core/secp256k1#955: Add random field multiply/square tests 75ce488 Merge bitcoin-core/secp256k1#959: tests: really test the non-var scalar inverse 41ed139 tests: really test the non-var scalar inverse 5f6ceaf schnorrsig: allow setting MSGLEN != 32 in benchmark fdd06b7 schnorrsig: add tests for sign_custom and varlen msg verification d8d806a schnorrsig: add extra parameter struct for sign_custom a0c3fc1 schnorrsig: allow signing and verification of variable length msgs 5a8e499 Add secp256k1_tagged_sha256 as defined in BIP-340 b6c0b72 schnorrsig: remove noncefp args from sign; add sign_custom function bdf19f1 Add random field multiply/square tests 8ae56e3 Merge dashpay#879: Avoid passing out-of-bound pointers to 0-size memcpy a4642fa configure: replace AC_PATH_PROG to AC_CHECK_PROG 1758a92 Merge dashpay#950: ci: Add ppc64le build c58c4ea ci: Add ppc64le build 7973576 Merge dashpay#662: Add ecmult_gen, ecmult_const and ecmult to benchmark 8f879c2 Fix array size in bench_ecmult 2fe1b50 Add ecmult_gen, ecmult_const and ecmult to benchmark 593e6ba Clean up ecmult_bench to make space for more benchmarks 50f3367 Merge dashpay#947: ci: Run PRs on merge result even for i686 a35fdd3 ci: Run PRs on merge result even for i686 442cee5 schnorrsig: add algolen argument to nonce_function_hardened df3bfa1 schnorrsig: clarify result of calling nonce_function_bip340 without data 99e8614 README: mention schnorrsig module 3dc8c07 Merge dashpay#846: ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs 02dcea1 ci: Make test iterations configurable and tweak for sanitizer builds 489ff5c tests: Treat empty SECP2561_TEST_ITERS as if it was unset fcfcb97 ci: Simplify to use generic wrapper for QEMU, Valgrind, etc de4157f ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs 399722a Merge dashpay#941: Clean up git tree 09b3bb8 Clean up git tree bf0ac46 Merge dashpay#930: Add ARM32/ARM64 CI 202a030 Merge dashpay#850: add `secp256k1_ec_pubkey_cmp` method 1e78c18 Merge bitcoin-core/secp256k1#940: contrib: Explain explicit header guards 6939487 Merge dashpay#926: secp256k1.h: clarify that by default arguments must be != NULL 6eceec6 add `secp256k1_xonly_pubkey_cmp` method 0d9561a add `secp256k1_ec_pubkey_cmp` method 22a9ea1 contrib: Explain explicit header guards 6c52ae8 Merge dashpay#937: Have ge_set_gej_var, gej_double_var and ge_set_all_gej_var initialize all fields of their outputs. 185a6af Merge dashpay#925: changed include statements without prefix 'include/' 14c9739 tests: Improve secp256k1_ge_set_all_gej_var for some infinity inputs 4a19668 tests: Test secp256k1_ge_set_all_gej_var for all infinity inputs 3c90bdd change local lib headers to be relative for those pointing at "include/" dir 45b6468 Have secp256k1_ge_set_all_gej_var initialize all fields. Previous behaviour would not initialize r->y values in the case where infinity is passed in. Furthermore, the previous behaviour wouldn't initialize anything in the case where all inputs were infinity. 31c0f6d Have secp256k1_gej_double_var initialize all fields. Previous behaviour would not initialize r->x and r->y values in the case where infinity is passed in. dd6c3de Have secp256k1_ge_set_gej_var initialize all fields. Previous behaviour would not initialize r->x and r->y values in the case where infinity is passed in. d0bd269 Merge bitcoin-core/secp256k1#936: Fix gen_context/ASM build on ARM 8bbad7a Add asm build to ARM32 CI 7d65ed5 Add ARM32/ARM64 CI c848352 Makefile.am: Don't pass a variable twice 2161f31 Makefile.am: Honor config when building gen_context 99f47c2 gen_context: Don't use external ASM because it complicates the build 98e0358 Merge dashpay#933: Avoids a missing brace warning in schnorrsig/tests_impl.h on old compilers 99e2d5b Avoids a missing brace warning in schnorrsig/tests_impl.h on old compilers. 34388af Merge dashpay#922: Add mingw32-w64/wine CI build 7012a18 Merge dashpay#928: Define SECP256K1_BUILD in secp256k1.c directly. ed5a199 tests: fopen /dev/urandom in binary mode ae9e648 Define SECP256K1_BUILD in secp256k1.c directly. 4dc37bf Add mingw32-w64/wine CI build 0881633 secp256k1.h: clarify that by default arguments must be != NULL 9570f67 Avoid passing out-of-bound pointers to 0-size memcpy git-subtree-dir: src/secp256k1 git-subtree-split: be8d9c2
1 parent bdca9bc commit c020cba

Some content is hidden

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

42 files changed

+1222
-365
lines changed

.cirrus.yml

+173-29
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
env:
2-
WIDEMUL: auto
2+
### compiler options
3+
HOST:
4+
# Specific warnings can be disabled with -Wno-error=foo.
5+
# -pedantic-errors is not equivalent to -Werror=pedantic and thus not implied by -Werror according to the GCC manual.
6+
WERROR_CFLAGS: -Werror -pedantic-errors
7+
MAKEFLAGS: -j2
8+
BUILD: check
9+
### secp256k1 config
310
STATICPRECOMPUTATION: yes
411
ECMULTGENPRECISION: auto
512
ASM: no
6-
BUILD: check
13+
WIDEMUL: auto
714
WITH_VALGRIND: yes
8-
RUN_VALGRIND: no
915
EXTRAFLAGS:
10-
HOST:
16+
### secp256k1 modules
17+
EXPERIMENTAL: no
1118
ECDH: no
1219
RECOVERY: no
1320
SCHNORRSIG: no
14-
EXPERIMENTAL: no
15-
CTIMETEST: yes
21+
### test options
22+
TEST_ITERS:
1623
BENCH: yes
17-
ITERS: 2
18-
MAKEFLAGS: -j2
24+
BENCH_ITERS: 2
25+
CTIMETEST: yes
1926

2027
cat_logs_snippet: &CAT_LOGS
2128
always:
@@ -63,27 +70,8 @@ task:
6370
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
6471
- env: {CPPFLAGS: -DDETERMINISTIC}
6572
- env: {CFLAGS: -O0, CTIMETEST: no}
66-
- env:
67-
CFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
68-
LDFLAGS: "-fsanitize=undefined -fno-omit-frame-pointer"
69-
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
70-
ASM: x86_64
71-
ECDH: yes
72-
RECOVERY: yes
73-
EXPERIMENTAL: yes
74-
SCHNORRSIG: yes
75-
CTIMETEST: no
7673
- env: { ECMULTGENPRECISION: 2 }
7774
- env: { ECMULTGENPRECISION: 8 }
78-
- env:
79-
RUN_VALGRIND: yes
80-
ASM: x86_64
81-
ECDH: yes
82-
RECOVERY: yes
83-
EXPERIMENTAL: yes
84-
SCHNORRSIG: yes
85-
EXTRAFLAGS: "--disable-openssl-tests"
86-
BUILD:
8775
matrix:
8876
- env:
8977
CC: gcc
@@ -111,6 +99,7 @@ task:
11199
CC: i686-linux-gnu-gcc
112100
- env:
113101
CC: clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include
102+
<< : *MERGE_BASE
114103
test_script:
115104
- ./ci/cirrus.sh
116105
<< : *CAT_LOGS
@@ -181,9 +170,9 @@ task:
181170
cpu: 1
182171
memory: 1G
183172
env:
184-
QEMU_CMD: qemu-s390x
173+
WRAPPER_CMD: qemu-s390x
174+
TEST_ITERS: 16
185175
HOST: s390x-linux-gnu
186-
BUILD:
187176
WITH_VALGRIND: no
188177
ECDH: yes
189178
RECOVERY: yes
@@ -196,3 +185,158 @@ task:
196185
- rm /etc/ld.so.cache
197186
- ./ci/cirrus.sh
198187
<< : *CAT_LOGS
188+
189+
task:
190+
name: "ARM32: Linux (Debian stable, QEMU)"
191+
container:
192+
dockerfile: ci/linux-debian.Dockerfile
193+
cpu: 1
194+
memory: 1G
195+
env:
196+
WRAPPER_CMD: qemu-arm
197+
TEST_ITERS: 16
198+
HOST: arm-linux-gnueabihf
199+
WITH_VALGRIND: no
200+
ECDH: yes
201+
RECOVERY: yes
202+
EXPERIMENTAL: yes
203+
SCHNORRSIG: yes
204+
CTIMETEST: no
205+
matrix:
206+
- env: {}
207+
- env: {ASM: arm}
208+
<< : *MERGE_BASE
209+
test_script:
210+
- ./ci/cirrus.sh
211+
<< : *CAT_LOGS
212+
213+
task:
214+
name: "ARM64: Linux (Debian stable, QEMU)"
215+
container:
216+
dockerfile: ci/linux-debian.Dockerfile
217+
cpu: 1
218+
memory: 1G
219+
env:
220+
WRAPPER_CMD: qemu-aarch64
221+
TEST_ITERS: 16
222+
HOST: aarch64-linux-gnu
223+
WITH_VALGRIND: no
224+
ECDH: yes
225+
RECOVERY: yes
226+
EXPERIMENTAL: yes
227+
SCHNORRSIG: yes
228+
CTIMETEST: no
229+
<< : *MERGE_BASE
230+
test_script:
231+
- ./ci/cirrus.sh
232+
<< : *CAT_LOGS
233+
234+
task:
235+
name: "ppc64le: Linux (Debian stable, QEMU)"
236+
container:
237+
dockerfile: ci/linux-debian.Dockerfile
238+
cpu: 1
239+
memory: 1G
240+
env:
241+
WRAPPER_CMD: qemu-ppc64le
242+
TEST_ITERS: 16
243+
HOST: powerpc64le-linux-gnu
244+
WITH_VALGRIND: no
245+
ECDH: yes
246+
RECOVERY: yes
247+
EXPERIMENTAL: yes
248+
SCHNORRSIG: yes
249+
CTIMETEST: no
250+
<< : *MERGE_BASE
251+
test_script:
252+
- ./ci/cirrus.sh
253+
<< : *CAT_LOGS
254+
255+
task:
256+
name: "x86_64 (mingw32-w64): Windows (Debian stable, Wine)"
257+
container:
258+
dockerfile: ci/linux-debian.Dockerfile
259+
cpu: 1
260+
memory: 1G
261+
env:
262+
WRAPPER_CMD: wine64-stable
263+
TEST_ITERS: 16
264+
HOST: x86_64-w64-mingw32
265+
WITH_VALGRIND: no
266+
ECDH: yes
267+
RECOVERY: yes
268+
EXPERIMENTAL: yes
269+
SCHNORRSIG: yes
270+
CTIMETEST: no
271+
<< : *MERGE_BASE
272+
test_script:
273+
- ./ci/cirrus.sh
274+
<< : *CAT_LOGS
275+
276+
# Sanitizers
277+
task:
278+
container:
279+
dockerfile: ci/linux-debian.Dockerfile
280+
cpu: 1
281+
memory: 1G
282+
env:
283+
ECDH: yes
284+
RECOVERY: yes
285+
EXPERIMENTAL: yes
286+
SCHNORRSIG: yes
287+
CTIMETEST: no
288+
EXTRAFLAGS: "--disable-openssl-tests"
289+
matrix:
290+
- name: "Valgrind (memcheck)"
291+
env:
292+
# The `--error-exitcode` is required to make the test fail if valgrind found errors, otherwise it'll return 0 (https://www.valgrind.org/docs/manual/manual-core.html)
293+
WRAPPER_CMD: "valgrind --error-exitcode=42"
294+
TEST_ITERS: 16
295+
- name: "UBSan, ASan, LSan"
296+
env:
297+
CFLAGS: "-fsanitize=undefined,address"
298+
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
299+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
300+
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
301+
LSAN_OPTIONS: "use_unaligned=1"
302+
TEST_ITERS: 32
303+
# Try to cover many configurations with just a tiny matrix.
304+
matrix:
305+
- env:
306+
ASM: auto
307+
STATICPRECOMPUTATION: yes
308+
- env:
309+
ASM: no
310+
STATICPRECOMPUTATION: no
311+
ECMULTGENPRECISION: 2
312+
matrix:
313+
- env:
314+
CC: clang
315+
- env:
316+
HOST: i686-linux-gnu
317+
CC: i686-linux-gnu-gcc
318+
<< : *MERGE_BASE
319+
test_script:
320+
- ./ci/cirrus.sh
321+
<< : *CAT_LOGS
322+
323+
task:
324+
name: "C++ -fpermissive"
325+
container:
326+
dockerfile: ci/linux-debian.Dockerfile
327+
cpu: 1
328+
memory: 1G
329+
env:
330+
# ./configure correctly errors out when given CC=g++.
331+
# We hack around this by passing CC=g++ only to make.
332+
CC: gcc
333+
MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive
334+
WERROR_CFLAGS:
335+
EXPERIMENTAL: yes
336+
ECDH: yes
337+
RECOVERY: yes
338+
SCHNORRSIG: yes
339+
<< : *MERGE_BASE
340+
test_script:
341+
- ./ci/cirrus.sh
342+
<< : *CAT_LOGS

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ aclocal.m4
2323
autom4te.cache/
2424
config.log
2525
config.status
26+
conftest*
2627
*.tar.gz
2728
*.la
2829
libtool
@@ -33,6 +34,14 @@ libtool
3334
*~
3435
*.log
3536
*.trs
37+
38+
coverage/
39+
coverage.html
40+
coverage.*.html
41+
*.gcda
42+
*.gcno
43+
*.gcov
44+
3645
src/libsecp256k1-config.h
3746
src/libsecp256k1-config.h.in
3847
src/ecmult_static_context.h

Makefile.am

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
ACLOCAL_AMFLAGS = -I build-aux/m4
22

3+
# AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo
4+
# which does not have an explicit foo_CFLAGS variable set.
5+
AM_CFLAGS = $(SECP_CFLAGS)
6+
37
lib_LTLIBRARIES = libsecp256k1.la
48
include_HEADERS = include/secp256k1.h
59
include_HEADERS += include/secp256k1_preallocated.h
@@ -68,7 +72,7 @@ endif
6872
endif
6973

7074
libsecp256k1_la_SOURCES = src/secp256k1.c
71-
libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
75+
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
7276
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
7377

7478
if VALGRIND_ENABLED
@@ -81,27 +85,27 @@ noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8185
bench_verify_SOURCES = src/bench_verify.c
8286
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8387
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
84-
bench_verify_CPPFLAGS = -DSECP256K1_BUILD $(SECP_TEST_INCLUDES)
88+
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
8589
bench_sign_SOURCES = src/bench_sign.c
8690
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8791
bench_internal_SOURCES = src/bench_internal.c
8892
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
89-
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
93+
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
9094
bench_ecmult_SOURCES = src/bench_ecmult.c
9195
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
92-
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
96+
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
9397
endif
9498

9599
TESTS =
96100
if USE_TESTS
97101
noinst_PROGRAMS += tests
98102
tests_SOURCES = src/tests.c
99-
tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
103+
tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
100104
if VALGRIND_ENABLED
101105
tests_CPPFLAGS += -DVALGRIND
102106
noinst_PROGRAMS += valgrind_ctime_test
103107
valgrind_ctime_test_SOURCES = src/valgrind_ctime_test.c
104-
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_LIBS) $(COMMON_LIB)
108+
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB)
105109
endif
106110
if !ENABLE_COVERAGE
107111
tests_CPPFLAGS += -DVERIFY
@@ -114,7 +118,7 @@ endif
114118
if USE_EXHAUSTIVE_TESTS
115119
noinst_PROGRAMS += exhaustive_tests
116120
exhaustive_tests_SOURCES = src/tests_exhaustive.c
117-
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
121+
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
118122
if !ENABLE_COVERAGE
119123
exhaustive_tests_CPPFLAGS += -DVERIFY
120124
endif
@@ -129,10 +133,10 @@ CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
129133
gen_context_OBJECTS = gen_context.o
130134
gen_context_BIN = gen_context$(BUILD_EXEEXT)
131135
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
132-
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
136+
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
133137

134138
$(gen_context_BIN): $(gen_context_OBJECTS)
135-
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
139+
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
136140

137141
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
138142
$(tests_OBJECTS): src/ecmult_static_context.h

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Features:
1717
* Suitable for embedded systems.
1818
* Optional module for public key recovery.
1919
* Optional module for ECDH key exchange.
20+
* Optional module for Schnorr signatures according to [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki) (experimental).
2021

2122
Experimental features have not received enough scrutiny to satisfy the standard of quality of this library but are made available for testing and review by the community. The APIs of these features should not be considered stable.
2223

@@ -96,7 +97,8 @@ To create a report, `gcovr` is recommended, as it includes branch coverage repor
9697

9798
To create a HTML report with coloured and annotated source code:
9899

99-
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage.html
100+
$ mkdir -p coverage
101+
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html
100102

101103
Reporting a vulnerability
102104
------------

build-aux/m4/bitcoin_secp.m4

+16
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,19 @@ if test x"$has_valgrind" != x"yes"; then
8282
AC_CHECK_HEADER([valgrind/memcheck.h], [has_valgrind=yes; AC_DEFINE(HAVE_VALGRIND,1,[Define this symbol if valgrind is installed])])
8383
fi
8484
])
85+
86+
dnl SECP_TRY_APPEND_CFLAGS(flags, VAR)
87+
dnl Append flags to VAR if CC accepts them.
88+
AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [
89+
AC_MSG_CHECKING([if ${CC} supports $1])
90+
SECP_TRY_APPEND_CFLAGS_saved_CFLAGS="$CFLAGS"
91+
CFLAGS="$1 $CFLAGS"
92+
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], [flag_works=yes], [flag_works=no])
93+
AC_MSG_RESULT($flag_works)
94+
CFLAGS="$SECP_TRY_APPEND_CFLAGS_saved_CFLAGS"
95+
if test x"$flag_works" = x"yes"; then
96+
$2="$$2 $1"
97+
fi
98+
unset flag_works
99+
AC_SUBST($2)
100+
])

0 commit comments

Comments
 (0)