Skip to content

Commit c4a1e09

Browse files
committed
Squashed 'src/secp256k1/' changes from be8d9c2..699c057e4f
699c057e4f build: Remove #undef hack for ASM in the precomputation programs b161047ad3 ci: Test `make precomp` 7758af3606 build: Remove CC_FOR_BUILD stuff 6e2bbd9667 build: Prebuild and distribute ecmult_gen table d874b87ca9 prealloc: Get rid of manual memory management for prealloc contexts 72f7621ca8 ecmult_gen: Tidy precomputed file and save space a844e377a6 ecmult_gen: Precompute tables for all values of ECMULT_GEN_PREC_BITS f9c0d1c732 refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table af8db36679 refactor: Move default callbacks to util.h e84f9d9867 doc: Remove obsolete hint for valgrind stack size 0997db140c exhaustive_tests: Fix with ecmult_gen table with custom generator 2e6770c27b refactor: Make generator a parameter of ecmult_gen_create_prec_table d44559ccbd refactor: Rename program that generates static ecmult_gen table 0396aa2078 refactor: Rename file that contains static ecmult_gen table 69c1e00ee0 ecmult_gen: Make code consistent with comment 6dc3acf95f ecmult_gen: Simplify ecmult_gen context after making table static 4c5ed7a731 refactor: Decouple table generation and ecmult_gen context ae1e76f648 ecmult_gen: Move table creation to new file and force static prec 49f608d Merge bitcoin-core/secp256k1#1004: ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS 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 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: 699c057e4f0f72296641971c43d94f06e7d80eaf
1 parent c020cba commit c4a1e09

Some content is hidden

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

61 files changed

+27603
-1721
lines changed

Diff for: .cirrus.yml

+3-5
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ 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:
@@ -294,8 +293,7 @@ task:
294293
TEST_ITERS: 16
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"
@@ -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

Diff for: .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

Diff for: .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

Diff for: Makefile.am

+48-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
@@ -81,13 +86,9 @@ endif
8186

8287
noinst_PROGRAMS =
8388
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)
89+
noinst_PROGRAMS += bench bench_internal bench_ecmult
90+
bench_SOURCES = src/bench.c
91+
bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
9192
bench_internal_SOURCES = src/bench_internal.c
9293
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
9394
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
@@ -118,7 +119,7 @@ endif
118119
if USE_EXHAUSTIVE_TESTS
119120
noinst_PROGRAMS += exhaustive_tests
120121
exhaustive_tests_SOURCES = src/tests_exhaustive.c
121-
exhaustive_tests_CPPFLAGS = -I$(top_srcdir)/src $(SECP_INCLUDES)
122+
exhaustive_tests_CPPFLAGS = $(SECP_INCLUDES)
122123
if !ENABLE_COVERAGE
123124
exhaustive_tests_CPPFLAGS += -DVERIFY
124125
endif
@@ -127,29 +128,45 @@ exhaustive_tests_LDFLAGS = -static
127128
TESTS += exhaustive_tests
128129
endif
129130

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

154171
if ENABLE_MODULE_ECDH
155172
include src/modules/ecdh/Makefile.am.include

Diff for: 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

Diff for: 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.

Diff for: build-aux/m4/ax_prog_cc_for_build.m4

-125
This file was deleted.

0 commit comments

Comments
 (0)