Skip to content

Commit c06cda3

Browse files
committed
Merge bitcoin/bitcoin#23383: Update libsecp256k1 subtree to current master
314195c Remove unnecessary cast in CKey::SignSchnorr (Pieter Wuille) a1f76cd Remove --disable-openssl-tests for libsecp256k1 configure (Pieter Wuille) 86dbc4d Squashed 'src/secp256k1/' changes from be8d9c262f..0559fc6e41 (Pieter Wuille) Pull request description: The motivation for this bump is getting rid of a cast in `CKey::SignSchnorr`; the `aux_rand` argument isn't modified by the `secp256k1_schnorrsig_sign` function, but was marked as non-`const` anyway. This is fixed now (bitcoin-core/secp256k1#966), and the cast is removed in this PR. There are a few other relevant changes: * (bitcoin-core/secp256k1#956): replaces a runtime-computed table with a precomputed one; this adds arouns 1 MiB to the binary size, but is a step towards significantly simplifying the API. If 1 MiB is too much, it can be reduced by 2 or 4 (or more) for a slight verification performance reduction. * (bitcoin-core/secp256k1#983): removes (test/bench only) OpenSSL support entirely, removing the need to pass `--disable-openssl-tests` (see #23314). * (bitcoin-core/secp256k1#810): mild performance increase for 64-bit non-x86 platforms. * (bitcoin-core/secp256k1#1002): Make aux_rnd32==NULL behave identical to 0x0000..00 (which impacts BIP341/BIP342 signing in Bitcoin Core, making it more strictly BIP340 compliant, though not in a manner that affects security). ACKs for top commit: fanquake: ACK 314195c - this includes a nice simplification to the lilbsecp build system (and thus our build system), and fixes issues like #22854. Did a Guix build on x86 (above), as well as a build on arm64 (except for the arm64 host): Tree-SHA512: 0e048390fc148fbbdf5b98d9cce8c71067564e7d69d97b68347808a9bc45a04f4fc653c392c880d79d5d8b9cf282195520955581ac4f1595f6a948080cf5949d
2 parents 97b2fc0 + 314195c commit c06cda3

Some content is hidden

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

66 files changed

+27893
-1841
lines changed

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ PKGCONFIG_LIBDIR_TEMP="$PKG_CONFIG_LIBDIR"
19001900
unset PKG_CONFIG_LIBDIR
19011901
PKG_CONFIG_LIBDIR="$PKGCONFIG_LIBDIR_TEMP"
19021902

1903-
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-schnorrsig --enable-experimental --disable-openssl-tests"
1903+
ac_configure_args="${ac_configure_args} --disable-shared --with-pic --enable-benchmark=no --enable-module-recovery --enable-module-schnorrsig --enable-experimental"
19041904
AC_CONFIG_SUBDIRS([src/secp256k1])
19051905

19061906
AC_OUTPUT

src/key.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ bool CKey::SignSchnorr(const uint256& hash, Span<unsigned char> sig, const uint2
288288
uint256 tweak = XOnlyPubKey(pubkey_bytes).ComputeTapTweakHash(merkle_root->IsNull() ? nullptr : merkle_root);
289289
if (!secp256k1_keypair_xonly_tweak_add(GetVerifyContext(), &keypair, tweak.data())) return false;
290290
}
291-
bool ret = secp256k1_schnorrsig_sign(secp256k1_context_sign, sig.data(), hash.data(), &keypair, (unsigned char*)aux.data());
291+
bool ret = secp256k1_schnorrsig_sign(secp256k1_context_sign, sig.data(), hash.data(), &keypair, aux.data());
292292
if (ret) {
293293
// Additional verification step to prevent using a potentially corrupted signature
294294
secp256k1_xonly_pubkey pubkey_verify;

src/secp256k1/.cirrus.yml

+12-14
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ env:
1919
RECOVERY: no
2020
SCHNORRSIG: no
2121
### test options
22-
TEST_ITERS:
22+
SECP256K1_TEST_ITERS:
2323
BENCH: yes
24-
BENCH_ITERS: 2
24+
SECP256K1_BENCH_ITERS: 2
2525
CTIMETEST: yes
2626

2727
cat_logs_snippet: &CAT_LOGS
@@ -171,7 +171,7 @@ task:
171171
memory: 1G
172172
env:
173173
WRAPPER_CMD: qemu-s390x
174-
TEST_ITERS: 16
174+
SECP256K1_TEST_ITERS: 16
175175
HOST: s390x-linux-gnu
176176
WITH_VALGRIND: no
177177
ECDH: yes
@@ -194,7 +194,7 @@ task:
194194
memory: 1G
195195
env:
196196
WRAPPER_CMD: qemu-arm
197-
TEST_ITERS: 16
197+
SECP256K1_TEST_ITERS: 16
198198
HOST: arm-linux-gnueabihf
199199
WITH_VALGRIND: no
200200
ECDH: yes
@@ -218,7 +218,7 @@ task:
218218
memory: 1G
219219
env:
220220
WRAPPER_CMD: qemu-aarch64
221-
TEST_ITERS: 16
221+
SECP256K1_TEST_ITERS: 16
222222
HOST: aarch64-linux-gnu
223223
WITH_VALGRIND: no
224224
ECDH: yes
@@ -239,7 +239,7 @@ task:
239239
memory: 1G
240240
env:
241241
WRAPPER_CMD: qemu-ppc64le
242-
TEST_ITERS: 16
242+
SECP256K1_TEST_ITERS: 16
243243
HOST: powerpc64le-linux-gnu
244244
WITH_VALGRIND: no
245245
ECDH: yes
@@ -260,7 +260,7 @@ task:
260260
memory: 1G
261261
env:
262262
WRAPPER_CMD: wine64-stable
263-
TEST_ITERS: 16
263+
SECP256K1_TEST_ITERS: 16
264264
HOST: x86_64-w64-mingw32
265265
WITH_VALGRIND: no
266266
ECDH: yes
@@ -278,28 +278,26 @@ 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:
292291
# 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)
293292
WRAPPER_CMD: "valgrind --error-exitcode=42"
294-
TEST_ITERS: 16
293+
SECP256K1_TEST_ITERS: 2
295294
- name: "UBSan, ASan, LSan"
296295
env:
297-
CFLAGS: "-fsanitize=undefined,address"
298-
CFLAGS_FOR_BUILD: "-fsanitize=undefined,address"
296+
CFLAGS: "-fsanitize=undefined,address -g"
299297
UBSAN_OPTIONS: "print_stacktrace=1:halt_on_error=1"
300298
ASAN_OPTIONS: "strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1"
301299
LSAN_OPTIONS: "use_unaligned=1"
302-
TEST_ITERS: 32
300+
SECP256K1_TEST_ITERS: 32
303301
# Try to cover many configurations with just a tiny matrix.
304302
matrix:
305303
- env:
@@ -330,7 +328,7 @@ task:
330328
# ./configure correctly errors out when given CC=g++.
331329
# We hack around this by passing CC=g++ only to make.
332330
CC: gcc
333-
MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive
331+
MAKEFLAGS: -j2 CC=g++ CFLAGS=-fpermissive\ -g
334332
WERROR_CFLAGS:
335333
EXPERIMENTAL: yes
336334
ECDH: yes

src/secp256k1/.gitattributes

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

src/secp256k1/.gitignore

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
bench_inv
2-
bench_ecdh
1+
bench
32
bench_ecmult
4-
bench_schnorrsig
5-
bench_sign
6-
bench_verify
7-
bench_recover
83
bench_internal
94
tests
105
exhaustive_tests
11-
gen_context
6+
gen_ecmult_gen_static_prec_table
7+
gen_ecmult_static_pre_g
128
valgrind_ctime_test
139
*.exe
1410
*.so
1511
*.a
12+
*.csv
1613
!.gitignore
1714

1815
Makefile
@@ -44,7 +41,6 @@ coverage.*.html
4441

4542
src/libsecp256k1-config.h
4643
src/libsecp256k1-config.h.in
47-
src/ecmult_static_context.h
4844
build-aux/config.guess
4945
build-aux/config.sub
5046
build-aux/depcomp

src/secp256k1/Makefile.am

+49-31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.PHONY: clean-precomp precomp
2+
13
ACLOCAL_AMFLAGS = -I build-aux/m4
24

35
# AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo
@@ -28,6 +30,8 @@ noinst_HEADERS += src/ecmult_const.h
2830
noinst_HEADERS += src/ecmult_const_impl.h
2931
noinst_HEADERS += src/ecmult_gen.h
3032
noinst_HEADERS += src/ecmult_gen_impl.h
33+
noinst_HEADERS += src/ecmult_gen_prec.h
34+
noinst_HEADERS += src/ecmult_gen_prec_impl.h
3135
noinst_HEADERS += src/field_10x26.h
3236
noinst_HEADERS += src/field_10x26_impl.h
3337
noinst_HEADERS += src/field_5x52.h
@@ -50,6 +54,7 @@ noinst_HEADERS += src/hash_impl.h
5054
noinst_HEADERS += src/field.h
5155
noinst_HEADERS += src/field_impl.h
5256
noinst_HEADERS += src/bench.h
57+
noinst_HEADERS += src/basic-config.h
5358
noinst_HEADERS += contrib/lax_der_parsing.h
5459
noinst_HEADERS += contrib/lax_der_parsing.c
5560
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
@@ -74,20 +79,17 @@ endif
7479
libsecp256k1_la_SOURCES = src/secp256k1.c
7580
libsecp256k1_la_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src $(SECP_INCLUDES)
7681
libsecp256k1_la_LIBADD = $(SECP_LIBS) $(COMMON_LIB)
82+
libsecp256k1_la_LDFLAGS = -no-undefined
7783

7884
if VALGRIND_ENABLED
7985
libsecp256k1_la_CPPFLAGS += -DVALGRIND
8086
endif
8187

8288
noinst_PROGRAMS =
8389
if USE_BENCHMARK
84-
noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
85-
bench_verify_SOURCES = src/bench_verify.c
86-
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)
89-
bench_sign_SOURCES = src/bench_sign.c
90-
bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
90+
noinst_PROGRAMS += bench bench_internal bench_ecmult
91+
bench_SOURCES = src/bench.c
92+
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
9193
bench_internal_SOURCES = src/bench_internal.c
9294
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
9395
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
@@ -118,7 +120,7 @@ endif
118120
if USE_EXHAUSTIVE_TESTS
119121
noinst_PROGRAMS += exhaustive_tests
120122
exhaustive_tests_SOURCES = src/tests_exhaustive.c
121-
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
123+
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES)
122124
if !ENABLE_COVERAGE
123125
exhaustive_tests_CPPFLAGS += -DVERIFY
124126
endif
@@ -127,29 +129,45 @@ exhaustive_tests_LDFLAGS = -static
127129
TESTS += exhaustive_tests
128130
endif
129131

130-
if USE_ECMULT_STATIC_PRECOMPUTATION
131-
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
132-
133-
gen_context_OBJECTS = gen_context.o
134-
gen_context_BIN = gen_context$(BUILD_EXEEXT)
135-
gen_%.o: src/gen_%.c src/libsecp256k1-config.h
136-
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
137-
138-
$(gen_context_BIN): $(gen_context_OBJECTS)
139-
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
140-
141-
$(libsecp256k1_la_OBJECTS): src/ecmult_static_context.h
142-
$(tests_OBJECTS): src/ecmult_static_context.h
143-
$(bench_internal_OBJECTS): src/ecmult_static_context.h
144-
$(bench_ecmult_OBJECTS): src/ecmult_static_context.h
145-
146-
src/ecmult_static_context.h: $(gen_context_BIN)
147-
./$(gen_context_BIN)
148-
149-
CLEANFILES = $(gen_context_BIN) src/ecmult_static_context.h
150-
endif
151-
152-
EXTRA_DIST = autogen.sh src/gen_context.c src/basic-config.h
132+
### Precomputed tables
133+
EXTRA_PROGRAMS = gen_ecmult_static_pre_g gen_ecmult_gen_static_prec_table
134+
CLEANFILES = $(EXTRA_PROGRAMS)
135+
136+
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
137+
gen_ecmult_static_pre_g_CPPFLAGS = $(SECP_INCLUDES)
138+
gen_ecmult_static_pre_g_LDADD = $(SECP_LIBS) $(COMMON_LIB)
139+
140+
gen_ecmult_gen_static_prec_table_SOURCES = src/gen_ecmult_gen_static_prec_table.c
141+
gen_ecmult_gen_static_prec_table_CPPFLAGS = $(SECP_INCLUDES)
142+
gen_ecmult_gen_static_prec_table_LDADD = $(SECP_LIBS) $(COMMON_LIB)
143+
144+
# See Automake manual, Section "Errors with distclean".
145+
# We don't list any dependencies for the prebuilt files here because
146+
# otherwise make's decision whether to rebuild them (even in the first
147+
# build by a normal user) depends on mtimes, and thus is very fragile.
148+
# This means that rebuilds of the prebuilt files always need to be
149+
# forced by deleting them, e.g., by invoking `make clean-precomp`.
150+
src/ecmult_static_pre_g.h:
151+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
152+
./gen_ecmult_static_pre_g$(EXEEXT)
153+
src/ecmult_gen_static_prec_table.h:
154+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_gen_static_prec_table$(EXEEXT)
155+
./gen_ecmult_gen_static_prec_table$(EXEEXT)
156+
157+
PRECOMP = src/ecmult_gen_static_prec_table.h src/ecmult_static_pre_g.h
158+
noinst_HEADERS += $(PRECOMP)
159+
precomp: $(PRECOMP)
160+
161+
# Ensure the prebuilt files will be build first (only if they don't exist,
162+
# e.g., after `make maintainer-clean`).
163+
BUILT_SOURCES = $(PRECOMP)
164+
165+
maintainer-clean-local: clean-precomp
166+
167+
clean-precomp:
168+
rm -f $(PRECOMP)
169+
170+
EXTRA_DIST = autogen.sh SECURITY.md
153171

154172
if ENABLE_MODULE_ECDH
155173
include src/modules/ecdh/Makefile.am.include

src/secp256k1/README.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,9 @@ libsecp256k1 is built using autotools:
6666
$ ./autogen.sh
6767
$ ./configure
6868
$ make
69-
$ make check
69+
$ make check # run the test suite
7070
$ sudo make install # optional
7171

72-
Exhaustive tests
73-
-----------
74-
75-
$ ./exhaustive_tests
76-
77-
With valgrind, you might need to increase the max stack size:
78-
79-
$ valgrind --max-stackframe=2500000 ./exhaustive_tests
80-
8172
Test coverage
8273
-----------
8374

@@ -100,6 +91,18 @@ To create a HTML report with coloured and annotated source code:
10091
$ mkdir -p coverage
10192
$ gcovr --exclude 'src/bench*' --html --html-details -o coverage/coverage.html
10293

94+
Benchmark
95+
------------
96+
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.
97+
98+
To print the benchmark result to the command line:
99+
100+
$ ./bench_name
101+
102+
To create a CSV file for the benchmark result :
103+
104+
$ ./bench_name | sed '2d;s/ \{1,\}//g' > bench_name.csv
105+
103106
Reporting a vulnerability
104107
------------
105108

src/secp256k1/SECURITY.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The following keys may be used to communicate sensitive information to developer
99
| Name | Fingerprint |
1010
|------|-------------|
1111
| Pieter Wuille | 133E AC17 9436 F14A 5CF1 B794 860F EB80 4E66 9320 |
12-
| Andrew Poelstra | 699A 63EF C17A D3A9 A34C FFC0 7AD0 A91C 40BD 0091 |
12+
| Jonas Nick | 36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366 |
1313
| Tim Ruffing | 09E0 3F87 1092 E40E 106E 902B 33BC 86AB 80FF 5516 |
1414

15-
You can import a key by running the following command with that individual’s fingerprint: `gpg --recv-keys "<fingerprint>"` Ensure that you put quotes around fingerprints containing spaces.
15+
You can import a key by running the following command with that individual’s fingerprint: `gpg --keyserver hkps://keys.openpgp.org --recv-keys "<fingerprint>"` Ensure that you put quotes around fingerprints containing spaces.

0 commit comments

Comments
 (0)