Skip to content

Commit 0d540ec

Browse files
committed
2 parents 7aa9887 + 6048e6c commit 0d540ec

Some content is hidden

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

64 files changed

+1695
-825
lines changed

.cirrus.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
env:
2+
### cirrus config
3+
CIRRUS_CLONE_DEPTH: 1
24
### compiler options
35
HOST:
46
WRAPPER_CMD:
@@ -29,7 +31,7 @@ env:
2931
SECP256K1_TEST_ITERS:
3032
BENCH: yes
3133
SECP256K1_BENCH_ITERS: 2
32-
CTIMETEST: yes
34+
CTIMETESTS: yes
3335
# Compile and run the tests
3436
EXAMPLES: yes
3537

@@ -46,8 +48,8 @@ cat_logs_snippet: &CAT_LOGS
4648
- cat noverify_tests.log || true
4749
cat_exhaustive_tests_log_script:
4850
- cat exhaustive_tests.log || true
49-
cat_valgrind_ctime_test_log_script:
50-
- cat valgrind_ctime_test.log || true
51+
cat_ctime_tests_log_script:
52+
- cat ctime_tests.log || true
5153
cat_bench_log_script:
5254
- cat bench.log || true
5355
cat_config_log_script:
@@ -60,10 +62,8 @@ cat_logs_snippet: &CAT_LOGS
6062
merge_base_script_snippet: &MERGE_BASE
6163
merge_base_script:
6264
- if [ "$CIRRUS_PR" = "" ]; then exit 0; fi
63-
- git fetch $CIRRUS_REPO_CLONE_URL $CIRRUS_BASE_BRANCH
64-
- git config --global user.email "[email protected]"
65-
- git config --global user.name "ci"
66-
- git merge FETCH_HEAD # Merge base to detect silent merge conflicts
65+
- git fetch --depth=1 $CIRRUS_REPO_CLONE_URL "pull/${CIRRUS_PR}/merge"
66+
- git checkout FETCH_HEAD # Use merged changes to detect silent merge conflicts
6767

6868
linux_container_snippet: &LINUX_CONTAINER
6969
container:
@@ -87,9 +87,10 @@ task:
8787
- env: {WIDEMUL: int128, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
8888
- env: {WIDEMUL: int128, ASM: x86_64}
8989
- env: { RECOVERY: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes}
90-
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETEST: no, BENCH: no}
90+
- env: {CTIMETESTS: no, RECOVERY: yes, ECDH: yes, SCHNORRSIG: yes, EXPERIMENTAL: yes, ECDSA_S2C: yes, RANGEPROOF: yes, WHITELIST: yes, GENERATOR: yes, MUSIG: yes, ECDSAADAPTOR: yes, BPPP: yes, CPPFLAGS: -DVERIFY}
91+
- env: {BUILD: distcheck, WITH_VALGRIND: no, CTIMETESTS: no, BENCH: no}
9192
- env: {CPPFLAGS: -DDETERMINISTIC}
92-
- env: {CFLAGS: -O0, CTIMETEST: no}
93+
- env: {CFLAGS: -O0, CTIMETESTS: no}
9394
- env: { ECMULTGENPRECISION: 2, ECMULTWINDOW: 2 }
9495
- env: { ECMULTGENPRECISION: 8, ECMULTWINDOW: 4 }
9596
matrix:
@@ -144,7 +145,7 @@ task:
144145
env:
145146
ASM: no
146147
WITH_VALGRIND: no
147-
CTIMETEST: no
148+
CTIMETESTS: no
148149
matrix:
149150
- env:
150151
CC: gcc
@@ -177,7 +178,7 @@ task:
177178
MUSIG: yes
178179
ECDSAADAPTOR: yes
179180
BPPP: yes
180-
CTIMETEST: no
181+
CTIMETESTS: no
181182
<< : *MERGE_BASE
182183
test_script:
183184
# https://sourceware.org/bugzilla/show_bug.cgi?id=27008
@@ -196,7 +197,7 @@ task:
196197
ECDH: yes
197198
RECOVERY: yes
198199
SCHNORRSIG: yes
199-
CTIMETEST: no
200+
CTIMETESTS: no
200201
matrix:
201202
- env: {}
202203
- env: {EXPERIMENTAL: yes, ASM: arm}
@@ -216,7 +217,7 @@ task:
216217
ECDH: yes
217218
RECOVERY: yes
218219
SCHNORRSIG: yes
219-
CTIMETEST: no
220+
CTIMETESTS: no
220221
<< : *MERGE_BASE
221222
test_script:
222223
- ./ci/cirrus.sh
@@ -233,7 +234,7 @@ task:
233234
ECDH: yes
234235
RECOVERY: yes
235236
SCHNORRSIG: yes
236-
CTIMETEST: no
237+
CTIMETESTS: no
237238
<< : *MERGE_BASE
238239
test_script:
239240
- ./ci/cirrus.sh
@@ -247,7 +248,7 @@ task:
247248
ECDH: yes
248249
RECOVERY: yes
249250
SCHNORRSIG: yes
250-
CTIMETEST: no
251+
CTIMETESTS: no
251252
matrix:
252253
- name: "x86_64 (mingw32-w64): Windows (Debian stable, Wine)"
253254
env:
@@ -277,7 +278,7 @@ task:
277278
MUSIG: yes
278279
ECDSAADAPTOR: yes
279280
BPPP: yes
280-
CTIMETEST: no
281+
CTIMETESTS: no
281282
# Use a MinGW-w64 host to tell ./configure we're building for Windows.
282283
# This will detect some MinGW-w64 tools but then make will need only
283284
# the MSVC tools CC, AR and NM as specified below.
@@ -288,7 +289,7 @@ task:
288289
# Set non-essential options that affect the CLI messages here.
289290
# (They depend on the user's taste, so we don't want to set them automatically in configure.ac.)
290291
CFLAGS: -nologo -diagnostics:caret
291-
LDFLAGS: -XCClinker -nologo -XCClinker -diagnostics:caret
292+
LDFLAGS: -Xlinker -Xlinker -Xlinker -nologo
292293
matrix:
293294
- name: "x86_64 (MSVC): Windows (Debian stable, Wine)"
294295
- name: "x86_64 (MSVC): Windows (Debian stable, Wine, int128_struct)"
@@ -325,7 +326,7 @@ task:
325326
MUSIG: yes
326327
ECDSAADAPTOR: yes
327328
BPPP: yes
328-
CTIMETEST: no
329+
CTIMETESTS: no
329330
matrix:
330331
- name: "Valgrind (memcheck)"
331332
container:
@@ -378,10 +379,11 @@ task:
378379
MUSIG: yes
379380
ECDSAADAPTOR: yes
380381
BPPP: yes
381-
CTIMETEST: no
382+
CTIMETESTS: yes
382383
CC: clang
383384
SECP256K1_TEST_ITERS: 32
384385
ASM: no
386+
WITH_VALGRIND: no
385387
container:
386388
memory: 2G
387389
matrix:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ bench_generator
55
bench_rangeproof
66
bench_internal
77
bench_whitelist
8+
noverify_tests
89
tests
910
example_musig
1011
exhaustive_tests
1112
precompute_ecmult_gen
1213
precompute_ecmult
13-
valgrind_ctime_test
14+
ctime_tests
1415
ecdh_example
1516
ecdsa_example
1617
schnorr_example

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
## [Unreleased]
1212

13+
#### Added
14+
- Usage examples: Added a recommended method for securely clearing sensitive data, e.g., secret keys, from memory.
15+
- Tests: Added a new test binary `noverify_tests`. This binary runs the tests without some additional checks present in the ordinary `tests` binary and is thereby closer to production binaries. The `noverify_tests` binary is automatically run as part of the `make check` target.
16+
17+
#### Fixed
18+
- Fixed declarations of API variables for MSVC (`__declspec(dllimport)`). This fixes MSVC builds of programs which link against a libsecp256k1 DLL dynamically and use API variables (and not only API functions). Unfortunately, the MSVC linker now will emit warning `LNK4217` when trying to link against libsecp256k1 statically. Pass `/ignore:4217` to the linker to suppress this warning.
19+
20+
#### Changed
21+
- Forbade cloning or destroying `secp256k1_context_static`. Create a new context instead of cloning the static context. (If this change breaks your code, your code is probably wrong.)
22+
- Forbade randomizing (copies of) `secp256k1_context_static`. Randomizing a copy of `secp256k1_context_static` did not have any effect and did not provide defense-in-depth protection against side-channel attacks. Create a new context if you want to benefit from randomization.
23+
24+
#### Removed
25+
- Removed the configuration header `src/libsecp256k1-config.h`. We recommend passing flags to `./configure` to set configuration options (see `./configure --help`). If you cannot or do not want to use `./configure`, pass configuration flags such as `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG` manually to the compiler (see the file `configure.ac` for supported flags).
26+
1327
## [0.2.0] - 2022-12-12
1428

1529
#### Added

Makefile.am

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ noinst_HEADERS += src/modinv64_impl.h
4949
noinst_HEADERS += src/precomputed_ecmult.h
5050
noinst_HEADERS += src/precomputed_ecmult_gen.h
5151
noinst_HEADERS += src/assumptions.h
52+
noinst_HEADERS += src/checkmem.h
5253
noinst_HEADERS += src/util.h
5354
noinst_HEADERS += src/int128.h
5455
noinst_HEADERS += src/int128_impl.h
@@ -70,12 +71,14 @@ noinst_HEADERS += contrib/lax_der_parsing.h
7071
noinst_HEADERS += contrib/lax_der_parsing.c
7172
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
7273
noinst_HEADERS += contrib/lax_der_privatekey_parsing.c
73-
noinst_HEADERS += examples/random.h
74+
noinst_HEADERS += examples/examples_util.h
7475

7576
PRECOMPUTED_LIB = libsecp256k1_precomputed.la
7677
noinst_LTLIBRARIES = $(PRECOMPUTED_LIB)
7778
libsecp256k1_precomputed_la_SOURCES = src/precomputed_ecmult.c src/precomputed_ecmult_gen.c
78-
libsecp256k1_precomputed_la_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
79+
# We need `-I$(top_srcdir)/src` in VPATH builds if libsecp256k1_precomputed_la_SOURCES have been recreated in the build tree.
80+
# This helps users and packagers who insist on recreating the precomputed files (e.g., Gentoo).
81+
libsecp256k1_precomputed_la_CPPFLAGS = -I$(top_srcdir)/src $(SECP_CONFIG_DEFINES)
7982

8083
if USE_EXTERNAL_ASM
8184
COMMON_LIB = libsecp256k1_common.la
@@ -94,42 +97,32 @@ endif
9497
endif
9598

9699
libsecp256k1_la_SOURCES = src/secp256k1.c
97-
libsecp256k1_la_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
98-
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
100+
libsecp256k1_la_CPPFLAGS = $(SECP_CONFIG_DEFINES)
101+
libsecp256k1_la_LIBADD = $(COMMON_LIB) $(PRECOMPUTED_LIB)
99102
libsecp256k1_la_LDFLAGS = -no-undefined -version-info $(LIB_VERSION_CURRENT):$(LIB_VERSION_REVISION):$(LIB_VERSION_AGE)
100103

101-
if VALGRIND_ENABLED
102-
libsecp256k1_la_CPPFLAGS += -DVALGRIND
103-
endif
104-
105104
noinst_PROGRAMS =
106105
if USE_BENCHMARK
107106
noinst_PROGRAMS += bench bench_internal bench_ecmult
108107
bench_SOURCES = src/bench.c
109-
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
108+
bench_LDADD = libsecp256k1.la
110109
bench_CPPFLAGS = $(SECP_CONFIG_DEFINES)
111110
bench_internal_SOURCES = src/bench_internal.c
112-
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
113-
bench_internal_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
111+
bench_internal_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB)
112+
bench_internal_CPPFLAGS = $(SECP_CONFIG_DEFINES)
114113
bench_ecmult_SOURCES = src/bench_ecmult.c
115-
bench_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
116-
bench_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
114+
bench_ecmult_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB)
115+
bench_ecmult_CPPFLAGS = $(SECP_CONFIG_DEFINES)
117116
endif
118117

119118
TESTS =
120119
if USE_TESTS
121120
TESTS += noverify_tests
122121
noinst_PROGRAMS += noverify_tests
123122
noverify_tests_SOURCES = src/tests.c
124-
noverify_tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_TEST_INCLUDES) $(SECP_CONFIG_DEFINES)
125-
noverify_tests_LDADD = $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB) $(PRECOMPUTED_LIB)
123+
noverify_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES)
124+
noverify_tests_LDADD = $(COMMON_LIB) $(PRECOMPUTED_LIB)
126125
noverify_tests_LDFLAGS = -static
127-
if VALGRIND_ENABLED
128-
noverify_tests_CPPFLAGS += -DVALGRIND
129-
noinst_PROGRAMS += valgrind_ctime_test
130-
valgrind_ctime_test_SOURCES = src/valgrind_ctime_test.c
131-
valgrind_ctime_test_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB)
132-
endif
133126
if !ENABLE_COVERAGE
134127
TESTS += tests
135128
noinst_PROGRAMS += tests
@@ -140,15 +133,22 @@ tests_LDFLAGS = $(noverify_tests_LDFLAGS)
140133
endif
141134
endif
142135

136+
if USE_CTIME_TESTS
137+
noinst_PROGRAMS += ctime_tests
138+
ctime_tests_SOURCES = src/ctime_tests.c
139+
ctime_tests_LDADD = libsecp256k1.la
140+
ctime_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES)
141+
endif
142+
143143
if USE_EXHAUSTIVE_TESTS
144144
noinst_PROGRAMS += exhaustive_tests
145145
exhaustive_tests_SOURCES = src/tests_exhaustive.c
146-
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
146+
exhaustive_tests_CPPFLAGS = $(SECP_CONFIG_DEFINES)
147147
if !ENABLE_COVERAGE
148148
exhaustive_tests_CPPFLAGS += -DVERIFY
149149
endif
150150
# Note: do not include $(PRECOMPUTED_LIB) in exhaustive_tests (it uses runtime-generated tables).
151-
exhaustive_tests_LDADD = $(SECP_LIBS) $(COMMON_LIB)
151+
exhaustive_tests_LDADD = $(COMMON_LIB)
152152
exhaustive_tests_LDFLAGS = -static
153153
TESTS += exhaustive_tests
154154
endif
@@ -203,12 +203,12 @@ EXTRA_PROGRAMS = precompute_ecmult precompute_ecmult_gen
203203
CLEANFILES = $(EXTRA_PROGRAMS)
204204

205205
precompute_ecmult_SOURCES = src/precompute_ecmult.c
206-
precompute_ecmult_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
207-
precompute_ecmult_LDADD = $(SECP_LIBS) $(COMMON_LIB)
206+
precompute_ecmult_CPPFLAGS = $(SECP_CONFIG_DEFINES)
207+
precompute_ecmult_LDADD = $(COMMON_LIB)
208208

209209
precompute_ecmult_gen_SOURCES = src/precompute_ecmult_gen.c
210-
precompute_ecmult_gen_CPPFLAGS = $(SECP_INCLUDES) $(SECP_CONFIG_DEFINES)
211-
precompute_ecmult_gen_LDADD = $(SECP_LIBS) $(COMMON_LIB)
210+
precompute_ecmult_gen_CPPFLAGS = $(SECP_CONFIG_DEFINES)
211+
precompute_ecmult_gen_LDADD = $(COMMON_LIB)
212212

213213
# See Automake manual, Section "Errors with distclean".
214214
# We don't list any dependencies for the prebuilt files here because

ci/cirrus.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ print_environment() {
1414
ECMULTWINDOW ECMULTGENPRECISION ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
1515
EXPERIMENTAL ECDH RECOVERY SCHNORRSIG \
1616
ECDSA_S2C GENERATOR RANGEPROOF WHITELIST MUSIG ECDSAADAPTOR BPPP \
17-
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETEST\
17+
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS\
1818
EXAMPLES \
1919
HOST WRAPPER_CMD \
2020
CC CFLAGS CPPFLAGS AR NM
@@ -35,6 +35,8 @@ print_environment
3535
# This speeds up jobs with many invocations of wine (e.g., ./configure with MSVC) tremendously.
3636
case "$WRAPPER_CMD" in
3737
*wine*)
38+
# Make sure to shutdown wineserver whenever we exit.
39+
trap "wineserver -k || true" EXIT INT HUP
3840
# This is apparently only reliable when we run a dummy command such as "hh.exe" afterwards.
3941
wineserver -p && wine hh.exe
4042
;;
@@ -67,6 +69,7 @@ fi
6769
--enable-module-schnorrsig="$SCHNORRSIG" --enable-module-musig="$MUSIG" --enable-module-ecdsa-adaptor="$ECDSAADAPTOR" \
6870
--enable-module-schnorrsig="$SCHNORRSIG" \
6971
--enable-examples="$EXAMPLES" \
72+
--enable-ctime-tests="$CTIMETESTS" \
7073
--with-valgrind="$WITH_VALGRIND" \
7174
--host="$HOST" $EXTRAFLAGS
7275

@@ -83,14 +86,15 @@ export LOG_COMPILER="$WRAPPER_CMD"
8386

8487
make "$BUILD"
8588

89+
# Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
90+
EXEC='./libtool --mode=execute'
91+
if [ -n "$WRAPPER_CMD" ]
92+
then
93+
EXEC="$EXEC $WRAPPER_CMD"
94+
fi
95+
8696
if [ "$BENCH" = "yes" ]
8797
then
88-
# Using the local `libtool` because on macOS the system's libtool has nothing to do with GNU libtool
89-
EXEC='./libtool --mode=execute'
90-
if [ -n "$WRAPPER_CMD" ]
91-
then
92-
EXEC="$EXEC $WRAPPER_CMD"
93-
fi
9498
{
9599
$EXEC ./bench_ecmult
96100
$EXEC ./bench_internal
@@ -102,9 +106,13 @@ then
102106
} >> bench.log 2>&1
103107
fi
104108

105-
if [ "$CTIMETEST" = "yes" ]
109+
if [ "$CTIMETESTS" = "yes" ]
106110
then
107-
./libtool --mode=execute valgrind --error-exitcode=42 ./valgrind_ctime_test > valgrind_ctime_test.log 2>&1
111+
if [ "$WITH_VALGRIND" = "yes" ]; then
112+
./libtool --mode=execute valgrind --error-exitcode=42 ./ctime_tests > ctime_tests.log 2>&1
113+
else
114+
$EXEC ./ctime_tests > ctime_tests.log 2>&1
115+
fi
108116
fi
109117

110118
# Rebuild precomputed files (if not cross-compiling).
@@ -114,9 +122,6 @@ then
114122
make precomp
115123
fi
116124

117-
# Shutdown wineserver again
118-
wineserver -k || true
119-
120125
# Check that no repo files have been modified by the build.
121126
# (This fails for example if the precomp files need to be updated in the repo.)
122127
git diff --exit-code

0 commit comments

Comments
 (0)