Skip to content

Commit 86dbc4d

Browse files
committed
Squashed 'src/secp256k1/' changes from be8d9c2..0559fc6
0559fc6 Merge bitcoin-core/secp256k1#988: Make signing table fully static 7dfcece build: Remove #undef hack for ASM in the precomputation programs bb36fe9 ci: Test `make precomp` d94a37a build: Remove CC_FOR_BUILD stuff ad63bb4 build: Prebuild and distribute ecmult_gen table ac49361 prealloc: Get rid of manual memory management for prealloc contexts 6573c08 ecmult_gen: Tidy precomputed file and save space 5eba83f ecmult_gen: Precompute tables for all values of ECMULT_GEN_PREC_BITS 5d0dbef Merge bitcoin-core/secp256k1#942: Verify that secp256k1_ge_set_gej_zinv does not operate on infinity. 486205a Merge bitcoin-core/secp256k1#920: Test all ecmult functions with many j*2^i combinations fdb33dd refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table 5eb519e ci: reduce TEST_ITERS in memcheck run e2cf773 Test ecmult functions for all i*2^j for j=0..255 and odd i=1..255. 61ae37c Merge bitcoin-core/secp256k1#1022: build: Windows DLL additions 4f01840 Merge bitcoin-core/secp256k1#1027: build: Add a check that Valgrind actually supports a host platform 6ad908a Merge bitcoin-core/secp256k1#1008: bench.c: add `--help` option and ci: move env variables 592661c ci: move test environment variable declaration to .cirrus.yml dcbe84b bench: add --help option to bench. 099bad9 Comment and check a parameter for inf in secp256k1_ecmult_const. 6c0be85 Verify that secp256k1_ge_set_gej_zinv does not operate on infinity. a->x and a->y should not be used if the infinity flag is set. 4900227 Merge bitcoin-core/secp256k1#1025: build: replace backtick command substitution with $() 7c7ce87 build: Add a check that Valgrind actually supports a host platform a4875e3 refactor: Move default callbacks to util.h 4c94c55 doc: Remove obsolete hint for valgrind stack size 5106226 exhaustive_tests: Fix with ecmult_gen table with custom generator e1a7653 refactor: Make generator a parameter of ecmult_gen_create_prec_table 9ad09f6 refactor: Rename program that generates static ecmult_gen table 8ae18f1 refactor: Rename file that contains static ecmult_gen table 00d2fa1 ecmult_gen: Make code consistent with comment 3b0c218 ecmult_gen: Simplify ecmult_gen context after making table static 2b7c749 build: replace backtick command substitution with $() 49f608d Merge bitcoin-core/secp256k1#1004: ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS c0cd7de build: add -no-undefined to libtool LDFLAGS fe32a79 build: pass win32-dll to LT_INIT 60bf889 ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS fecf436 Merge bitcoin-core/secp256k1#1019: build: don't append valgrind CPPFLAGS if not installed (macOS) 2e5e4b6 Merge bitcoin-core/secp256k1#1020: doc: remove use of <0xa0> "no break space" 812ff5c doc: remove use of 0xa0 "no break space" 214042a build: don't append valgrind CPPFLAGS if not installed e43ba02 refactor: Decouple table generation and ecmult_gen context 22dc2c0 ecmult_gen: Move table creation to new file and force static prec 793ad90 Merge bitcoin-core/secp256k1#1010: doc: Minor fixes in safegcd_implementation.md dc9b685 doc: Minor fixes in safegcd_implementation.md ea5e8a9 Merge bitcoin-core/secp256k1#1012: Fix typos 2332975 Fix typos 7006f1b Merge bitcoin-core/secp256k1#1011: ci: Enable -g if we set CFLAGS manually 72de135 ci: Enable -g if we set CFLAGS manually 74c34e7 Merge bitcoin-core/secp256k1#1009: refactor: Use (int)&(int) in boolean context to avoid compiler warning 16d1322 refactor: Use (int)&(int) in boolean context to avoid compiler warning c74a7b7 Merge bitcoin-core/secp256k1#1007: doc: Replace apoelstra's GPG key by jonasnick's GPG key 3b157c4 doc: Suggest keys.openpgp.org as keyserver in SECURITY.md 73a7472 doc: Replace apoelstra's GPG key by jonasnick's GPG key 515a5db Merge bitcoin-core/secp256k1#991: Merge all "external" benchmarks into a single bench binary af6abcb Make bench support selecting which benchmarks to run 9f56bdf Merge bench_schnorrsig into bench 3208557 Merge bench_recover into bench 855e18d Merge bench_ecdh into bench 2a7be67 Combine bench_sign and bench_verify into single bench 8fa4120 Merge bitcoin-core/secp256k1#1002: Make aux_rnd32==NULL behave identical to 0x0000..00. 5324f89 Make aux_rnd32==NULL behave identical to 0x0000..00. 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: 0559fc6
1 parent c020cba commit 86dbc4d

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

+27891
-1839
lines changed

.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

.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

.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

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

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

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)