Skip to content

Commit ed3e5b0

Browse files
committed
Squashed 'src/secp256k1/' changes from efad3506a8..1758a92ffd
1758a92ffd Merge zcash#950: ci: Add ppc64le build c58c4ea470 ci: Add ppc64le build 7973576f6e Merge zcash#662: Add ecmult_gen, ecmult_const and ecmult to benchmark 8f879c2887 Fix array size in bench_ecmult 2fe1b50df1 Add ecmult_gen, ecmult_const and ecmult to benchmark 593e6bad9c Clean up ecmult_bench to make space for more benchmarks 50f3367712 Merge zcash#947: ci: Run PRs on merge result even for i686 a35fdd3478 ci: Run PRs on merge result even for i686 3dc8c072b6 Merge zcash#846: ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs 02dcea1ad9 ci: Make test iterations configurable and tweak for sanitizer builds 489ff5c20a tests: Treat empty SECP2561_TEST_ITERS as if it was unset fcfcb97e74 ci: Simplify to use generic wrapper for QEMU, Valgrind, etc de4157f13a ci: Run ASan/LSan and reorganize sanitizer and Valgrind jobs 399722a63a Merge zcash#941: Clean up git tree 09b3bb8648 Clean up git tree bf0ac46066 Merge zcash#930: Add ARM32/ARM64 CI 202a030f7d Merge zcash#850: add `secp256k1_ec_pubkey_cmp` method 1e78c18d5b Merge bitcoin-core/secp256k1#940: contrib: Explain explicit header guards 69394879b6 Merge zcash#926: secp256k1.h: clarify that by default arguments must be != NULL 6eceec6d56 add `secp256k1_xonly_pubkey_cmp` method 0d9561ae87 add `secp256k1_ec_pubkey_cmp` method 22a9ea154a contrib: Explain explicit header guards 6c52ae8724 Merge zcash#937: Have ge_set_gej_var, gej_double_var and ge_set_all_gej_var initialize all fields of their outputs. 185a6af227 Merge zcash#925: changed include statements without prefix 'include/' 14c9739a1f tests: Improve secp256k1_ge_set_all_gej_var for some infinity inputs 4a19668c37 tests: Test secp256k1_ge_set_all_gej_var for all infinity inputs 3c90bdda95 change local lib headers to be relative for those pointing at "include/" dir 45b6468d7e 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. 31c0f6de41 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. dd6c3de322 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. d0bd2693e3 Merge bitcoin-core/secp256k1#936: Fix gen_context/ASM build on ARM 8bbad7a18e Add asm build to ARM32 CI 7d65ed5214 Add ARM32/ARM64 CI c8483520c9 Makefile.am: Don't pass a variable twice 2161f31785 Makefile.am: Honor config when building gen_context 99f47c20ec gen_context: Don't use external ASM because it complicates the build 98e0358d29 Merge zcash#933: Avoids a missing brace warning in schnorrsig/tests_impl.h on old compilers 99e2d5be0d Avoids a missing brace warning in schnorrsig/tests_impl.h on old compilers. 34388af6b6 Merge zcash#922: Add mingw32-w64/wine CI build 7012a188e6 Merge zcash#928: Define SECP256K1_BUILD in secp256k1.c directly. ed5a199bed tests: fopen /dev/urandom in binary mode ae9e648526 Define SECP256K1_BUILD in secp256k1.c directly. 4dc37bf81b Add mingw32-w64/wine CI build 0881633dfd secp256k1.h: clarify that by default arguments must be != NULL git-subtree-dir: src/secp256k1 git-subtree-split: 1758a92ffd896af533b142707e9892ea6e15e5db
1 parent 678f3c9 commit ed3e5b0

36 files changed

+645
-151
lines changed

.cirrus.yml

+140-23
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ env:
55
ASM: no
66
BUILD: check
77
WITH_VALGRIND: yes
8-
RUN_VALGRIND: no
98
EXTRAFLAGS:
109
HOST:
1110
ECDH: no
@@ -14,7 +13,8 @@ env:
1413
EXPERIMENTAL: no
1514
CTIMETEST: yes
1615
BENCH: yes
17-
ITERS: 2
16+
TEST_ITERS:
17+
BENCH_ITERS: 2
1818
MAKEFLAGS: -j2
1919

2020
cat_logs_snippet: &CAT_LOGS
@@ -63,27 +63,8 @@ task:
6363
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
6464
- env: {CPPFLAGS: -DDETERMINISTIC}
6565
- 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
7666
- env: { ECMULTGENPRECISION: 2 }
7767
- 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:
8768
matrix:
8869
- env:
8970
CC: gcc
@@ -111,6 +92,7 @@ task:
11192
CC: i686-linux-gnu-gcc
11293
- env:
11394
CC: clang --target=i686-pc-linux-gnu -isystem /usr/i686-linux-gnu/include
95+
<< : *MERGE_BASE
11496
test_script:
11597
- ./ci/cirrus.sh
11698
<< : *CAT_LOGS
@@ -181,9 +163,9 @@ task:
181163
cpu: 1
182164
memory: 1G
183165
env:
184-
QEMU_CMD: qemu-s390x
166+
WRAPPER_CMD: qemu-s390x
167+
TEST_ITERS: 16
185168
HOST: s390x-linux-gnu
186-
BUILD:
187169
WITH_VALGRIND: no
188170
ECDH: yes
189171
RECOVERY: yes
@@ -196,3 +178,138 @@ task:
196178
- rm /etc/ld.so.cache
197179
- ./ci/cirrus.sh
198180
<< : *CAT_LOGS
181+
182+
task:
183+
name: "ARM32: Linux (Debian stable, QEMU)"
184+
container:
185+
dockerfile: ci/linux-debian.Dockerfile
186+
cpu: 1
187+
memory: 1G
188+
env:
189+
WRAPPER_CMD: qemu-arm
190+
TEST_ITERS: 16
191+
HOST: arm-linux-gnueabihf
192+
WITH_VALGRIND: no
193+
ECDH: yes
194+
RECOVERY: yes
195+
EXPERIMENTAL: yes
196+
SCHNORRSIG: yes
197+
CTIMETEST: no
198+
matrix:
199+
- env: {}
200+
- env: {ASM: arm}
201+
<< : *MERGE_BASE
202+
test_script:
203+
- ./ci/cirrus.sh
204+
<< : *CAT_LOGS
205+
206+
task:
207+
name: "ARM64: Linux (Debian stable, QEMU)"
208+
container:
209+
dockerfile: ci/linux-debian.Dockerfile
210+
cpu: 1
211+
memory: 1G
212+
env:
213+
WRAPPER_CMD: qemu-aarch64
214+
TEST_ITERS: 16
215+
HOST: aarch64-linux-gnu
216+
WITH_VALGRIND: no
217+
ECDH: yes
218+
RECOVERY: yes
219+
EXPERIMENTAL: yes
220+
SCHNORRSIG: yes
221+
CTIMETEST: no
222+
<< : *MERGE_BASE
223+
test_script:
224+
- ./ci/cirrus.sh
225+
<< : *CAT_LOGS
226+
227+
task:
228+
name: "ppc64le: Linux (Debian stable, QEMU)"
229+
container:
230+
dockerfile: ci/linux-debian.Dockerfile
231+
cpu: 1
232+
memory: 1G
233+
env:
234+
WRAPPER_CMD: qemu-ppc64le
235+
TEST_ITERS: 16
236+
HOST: powerpc64le-linux-gnu
237+
WITH_VALGRIND: no
238+
ECDH: yes
239+
RECOVERY: yes
240+
EXPERIMENTAL: yes
241+
SCHNORRSIG: yes
242+
CTIMETEST: no
243+
<< : *MERGE_BASE
244+
test_script:
245+
- ./ci/cirrus.sh
246+
<< : *CAT_LOGS
247+
248+
task:
249+
name: "x86_64 (mingw32-w64): Windows (Debian stable, Wine)"
250+
container:
251+
dockerfile: ci/linux-debian.Dockerfile
252+
cpu: 1
253+
memory: 1G
254+
env:
255+
WRAPPER_CMD: wine64-stable
256+
TEST_ITERS: 16
257+
HOST: x86_64-w64-mingw32
258+
WITH_VALGRIND: no
259+
ECDH: yes
260+
RECOVERY: yes
261+
EXPERIMENTAL: yes
262+
SCHNORRSIG: yes
263+
CTIMETEST: no
264+
<< : *MERGE_BASE
265+
test_script:
266+
- ./ci/cirrus.sh
267+
<< : *CAT_LOGS
268+
269+
# Sanitizers
270+
task:
271+
container:
272+
dockerfile: ci/linux-debian.Dockerfile
273+
cpu: 1
274+
memory: 1G
275+
env:
276+
ECDH: yes
277+
RECOVERY: yes
278+
EXPERIMENTAL: yes
279+
SCHNORRSIG: yes
280+
CTIMETEST: no
281+
EXTRAFLAGS: "--disable-openssl-tests"
282+
matrix:
283+
- name: "Valgrind (memcheck)"
284+
env:
285+
# 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)
286+
WRAPPER_CMD: "valgrind --error-exitcode=42"
287+
TEST_ITERS: 16
288+
- name: "UBSan, ASan, LSan"
289+
env:
290+
CFLAGS: "-fsanitize=undefined,address"
291+
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
292+
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
293+
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
294+
LSAN_OPTIONS: "use_unaligned=1"
295+
TEST_ITERS: 32
296+
# Try to cover many configurations with just a tiny matrix.
297+
matrix:
298+
- env:
299+
ASM: auto
300+
STATICPRECOMPUTATION: yes
301+
- env:
302+
ASM: no
303+
STATICPRECOMPUTATION: no
304+
ECMULTGENPRECISION: 2
305+
matrix:
306+
- env:
307+
CC: clang
308+
- env:
309+
HOST: i686-linux-gnu
310+
CC: i686-linux-gnu-gcc
311+
<< : *MERGE_BASE
312+
test_script:
313+
- ./ci/cirrus.sh
314+
<< : *CAT_LOGS
315+

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ libtool
3333
*~
3434
*.log
3535
*.trs
36+
37+
coverage/
38+
coverage.html
39+
coverage.*.html
40+
*.gcda
41+
*.gcno
42+
*.gcov
43+
3644
src/libsecp256k1-config.h
3745
src/libsecp256k1-config.h.in
3846
src/ecmult_static_context.h

Makefile.am

+8-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ endif
6868
endif
6969

7070
libsecp256k1_la_SOURCES = src/secp256k1.c
71-
libsecp256k1_la_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
71+
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
7272
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
7373

7474
if VALGRIND_ENABLED
@@ -81,27 +81,27 @@ noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
8181
bench_verify_SOURCES = src/bench_verify.c
8282
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8383
# SECP_TEST_INCLUDES are only used here for CRYPTO_CPPFLAGS
84-
bench_verify_CPPFLAGS = -DSECP256K1_BUILD $(SECP_TEST_INCLUDES)
84+
bench_verify_CPPFLAGS = $(SECP_TEST_INCLUDES)
8585
bench_sign_SOURCES = src/bench_sign.c
8686
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
8787
bench_internal_SOURCES = src/bench_internal.c
8888
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
89-
bench_internal_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
89+
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
9090
bench_ecmult_SOURCES = src/bench_ecmult.c
9191
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
92-
bench_ecmult_CPPFLAGS = -DSECP256K1_BUILD $(SECP_INCLUDES)
92+
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES)
9393
endif
9494

9595
TESTS =
9696
if USE_TESTS
9797
noinst_PROGRAMS += tests
9898
tests_SOURCES = src/tests.c
99-
tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
99+
tests_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include $(SECP_INCLUDES) $(SECP_TEST_INCLUDES)
100100
if VALGRIND_ENABLED
101101
tests_CPPFLAGS += -DVALGRIND
102102
noinst_PROGRAMS += valgrind_ctime_test
103103
valgrind_ctime_test_SOURCES = src/valgrind_ctime_test.c
104-
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_LIBS) $(COMMON_LIB)
104+
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB)
105105
endif
106106
if !ENABLE_COVERAGE
107107
tests_CPPFLAGS += -DVERIFY
@@ -114,7 +114,7 @@ endif
114114
if USE_EXHAUSTIVE_TESTS
115115
noinst_PROGRAMS += exhaustive_tests
116116
exhaustive_tests_SOURCES = src/tests_exhaustive.c
117-
exhaustive_tests_CPPFLAGS = -DSECP256K1_BUILD -I$(top_srcdir)/src $(SECP_INCLUDES)
117+
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
118118
if !ENABLE_COVERAGE
119119
exhaustive_tests_CPPFLAGS += -DVERIFY
120120
endif
@@ -129,7 +129,7 @@ CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
129129
gen_context_OBJECTS = gen_context.o
130130
gen_context_BIN = gen_context$(BUILD_EXEEXT)
131131
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
132-
$(CC_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
132+
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
133133

134134
$(gen_context_BIN): $(gen_context_OBJECTS)
135135
$(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ To create a report, `gcovr` is recommended, as it includes branch coverage repor
9696

9797
To create a HTML report with coloured and annotated source code:
9898

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

101102
Reporting a vulnerability
102103
------------

ci/cirrus.sh

+9-24
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,27 @@ valgrind --version || true
2525
make
2626

2727
# Print information about binaries so that we can see that the architecture is correct
28-
file *tests || true
28+
file *tests* || true
2929
file bench_* || true
3030
file .libs/* || true
3131

32-
if [ -n "$BUILD" ]
33-
then
34-
make "$BUILD"
35-
fi
32+
# This tells `make check` to wrap test invocations.
33+
export LOG_COMPILER="$WRAPPER_CMD"
3634

37-
if [ "$RUN_VALGRIND" = "yes" ]
38-
then
39-
# 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)
40-
valgrind --error-exitcode=42 ./tests 16
41-
valgrind --error-exitcode=42 ./exhaustive_tests
42-
fi
35+
# This limits the iterations in the tests and benchmarks.
36+
export SECP256K1_TEST_ITERS="$TEST_ITERS"
37+
export SECP256K1_BENCH_ITERS="$BENCH_ITERS"
4338

44-
if [ -n "$QEMU_CMD" ]
45-
then
46-
$QEMU_CMD ./tests 16
47-
$QEMU_CMD ./exhaustive_tests
48-
fi
39+
make "$BUILD"
4940

5041
if [ "$BENCH" = "yes" ]
5142
then
5243
# Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
5344
EXEC='./libtool --mode=execute'
54-
if [ -n "$QEMU_CMD" ]
55-
then
56-
EXEC="$EXEC $QEMU_CMD"
57-
fi
58-
if [ "$RUN_VALGRIND" = "yes" ]
45+
if [ -n "$WRAPPER_CMD" ]
5946
then
60-
EXEC="$EXEC valgrind --error-exitcode=42"
47+
EXEC="$EXEC $WRAPPER_CMD"
6148
fi
62-
# This limits the iterations in the benchmarks below to ITER iterations.
63-
export SECP256K1_BENCH_ITERS="$ITERS"
6449
{
6550
$EXEC ./bench_ecmult
6651
$EXEC ./bench_internal

ci/linux-debian.Dockerfile

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ FROM debian:stable
22

33
RUN dpkg --add-architecture i386
44
RUN dpkg --add-architecture s390x
5+
RUN dpkg --add-architecture armhf
6+
RUN dpkg --add-architecture arm64
7+
RUN dpkg --add-architecture ppc64el
58
RUN apt-get update
69

710
# dkpg-dev: to make pkg-config work in cross-builds
11+
# llvm: for llvm-symbolizer, which is used by clang's UBSan for symbolized stack traces
812
RUN apt-get install --no-install-recommends --no-upgrade -y \
913
git ca-certificates \
1014
make automake libtool pkg-config dpkg-dev valgrind qemu-user \
11-
gcc clang libc6-dbg \
12-
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 \
13-
gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x
15+
gcc clang llvm libc6-dbg \
16+
gcc-i686-linux-gnu libc6-dev-i386-cross libc6-dbg:i386 libubsan1:i386 libasan5:i386 \
17+
gcc-s390x-linux-gnu libc6-dev-s390x-cross libc6-dbg:s390x \
18+
gcc-arm-linux-gnueabihf libc6-dev-armhf-cross libc6-dbg:armhf \
19+
gcc-aarch64-linux-gnu libc6-dev-arm64-cross libc6-dbg:arm64 \
20+
gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross libc6-dbg:ppc64el \
21+
wine gcc-mingw-w64-x86-64
22+
23+
# Run a dummy command in wine to make it set up configuration
24+
RUN wine64-stable xcopy || true

contrib/lax_der_parsing.c

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
***********************************************************************/
66

77
#include <string.h>
8-
#include <secp256k1.h>
98

109
#include "lax_der_parsing.h"
1110

contrib/lax_der_parsing.h

+6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@
5151
#ifndef SECP256K1_CONTRIB_LAX_DER_PARSING_H
5252
#define SECP256K1_CONTRIB_LAX_DER_PARSING_H
5353

54+
/* #include secp256k1.h only when it hasn't been included yet.
55+
This enables this file to be #included directly in other project
56+
files (such as tests.c) without the need to set an explicit -I flag,
57+
which would be necessary to locate secp256k1.h. */
58+
#ifndef SECP256K1_H
5459
#include <secp256k1.h>
60+
#endif
5561

5662
#ifdef __cplusplus
5763
extern "C" {

contrib/lax_der_privatekey_parsing.c

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
***********************************************************************/
66

77
#include <string.h>
8-
#include <secp256k1.h>
98

109
#include "lax_der_privatekey_parsing.h"
1110

0 commit comments

Comments
 (0)