Skip to content

Commit 83a4b74

Browse files
build: Prebuild and distribute ecmult_gen table
- Improve Makefile.am for both prebuilt tables files - On the way, tidy EXTRA_DIST: Move the header files to noinst_HEADERS, where they conceptually belong, and add missing SECURITY.md to EXTRA_DIST
1 parent b83a2f3 commit 83a4b74

5 files changed

+12465
-27
lines changed

.gitattributes

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

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ coverage.*.html
4141

4242
src/libsecp256k1-config.h
4343
src/libsecp256k1-config.h.in
44-
src/ecmult_static_context.h
4544
build-aux/config.guess
4645
build-aux/config.sub
4746
build-aux/depcomp

Makefile.am

+26-23
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ noinst_HEADERS += src/ecmult_const.h
2828
noinst_HEADERS += src/ecmult_const_impl.h
2929
noinst_HEADERS += src/ecmult_gen.h
3030
noinst_HEADERS += src/ecmult_gen_impl.h
31+
noinst_HEADERS += src/ecmult_gen_build_table.h
32+
noinst_HEADERS += src/ecmult_gen_build_table_impl.h
3133
noinst_HEADERS += src/field_10x26.h
3234
noinst_HEADERS += src/field_10x26_impl.h
3335
noinst_HEADERS += src/field_5x52.h
@@ -50,6 +52,7 @@ noinst_HEADERS += src/hash_impl.h
5052
noinst_HEADERS += src/field.h
5153
noinst_HEADERS += src/field_impl.h
5254
noinst_HEADERS += src/bench.h
55+
noinst_HEADERS += src/basic-config.h
5356
noinst_HEADERS += contrib/lax_der_parsing.h
5457
noinst_HEADERS += contrib/lax_der_parsing.c
5558
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
@@ -123,37 +126,37 @@ exhaustive_tests_LDFLAGS = -static
123126
TESTS += exhaustive_tests
124127
endif
125128

126-
EXTRA_PROGRAMS = gen_ecmult_static_pre_g
129+
### Precomputed tables
130+
EXTRA_PROGRAMS = gen_ecmult_static_pre_g gen_ecmult_gen_static_prec_table
131+
CLEANFILES = $(EXTRA_PROGRAMS)
127132
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
128-
# See Automake manual, Section "Errors with distclean"
133+
gen_ecmult_gen_static_prec_table_SOURCES = src/gen_ecmult_gen_static_prec_table.c
134+
135+
# See Automake manual, Section "Errors with distclean".
136+
# We don't list any dependencies for the prebuilt files here because
137+
# otherwise make's decision whether to rebuild them (even in the first
138+
# build by a normal user) depends on mtimes, and thus is very fragile.
139+
# This means that rebuilds of the prebuilt files always need to be
140+
# forced by deleting them, e.g., by invoking `make clean-precomp`.
129141
src/ecmult_static_pre_g.h:
130142
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
131143
./gen_ecmult_static_pre_g$(EXEEXT)
144+
src/ecmult_gen_static_prec_table.h:
145+
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_gen_static_prec_table$(EXEEXT)
146+
./gen_ecmult_gen_static_prec_table$(EXEEXT)
132147

133-
if USE_ECMULT_STATIC_PRECOMPUTATION
134-
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src
148+
PRECOMP = src/ecmult_gen_static_prec_table.h src/ecmult_static_pre_g.h
149+
noinst_HEADERS += $(PRECOMP)
150+
precomp: $(PRECOMP)
135151

136-
gen_ecmult_gen_static_prec_table_OBJECTS = gen_ecmult_gen_static_prec_table.o
137-
gen_ecmult_gen_static_prec_table_BIN = gen_ecmult_gen_static_prec_table$(BUILD_EXEEXT)
138-
$(gen_ecmult_gen_static_prec_table_OBJECTS): src/gen_ecmult_gen_static_prec_table.c src/libsecp256k1-config.h
139-
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
152+
# One can use `make maintainerclean` instead of `make clean-precomp && make clean`.
153+
maintainerclean-local: clean-precomp
140154

141-
$(gen_ecmult_gen_static_prec_table_BIN): $(gen_ecmult_gen_static_prec_table_OBJECTS)
142-
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
155+
.PHONY: clean-precomp
156+
clean-precomp:
157+
rm -f $(PRECOMP)
143158

144-
$(libsecp256k1_la_OBJECTS): src/ecmult_gen_static_prec_table.h
145-
$(tests_OBJECTS): src/ecmult_gen_static_prec_table.h
146-
$(exhaustive_tests_OBJECTS): src/ecmult_gen_static_prec_table.h
147-
$(bench_internal_OBJECTS): src/ecmult_gen_static_prec_table.h
148-
$(bench_ecmult_OBJECTS): src/ecmult_gen_static_prec_table.h
149-
150-
src/ecmult_gen_static_prec_table.h: $(gen_ecmult_gen_static_prec_table_BIN)
151-
./$(gen_ecmult_gen_static_prec_table_BIN)
152-
153-
CLEANFILES = $(gen_ecmult_gen_static_prec_table_BIN) src/ecmult_gen_static_prec_table.h
154-
endif
155-
156-
EXTRA_DIST = autogen.sh src/gen_ecmult_gen_static_prec_table.c src/ecmult_static_pre_g.h src/basic-config.h
159+
EXTRA_DIST = autogen.sh SECURITY.md
157160

158161
if ENABLE_MODULE_ECDH
159162
include src/modules/ecdh/Makefile.am.include

configure.ac

-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ AC_ARG_ENABLE(exhaustive_tests,
125125
[use_exhaustive_tests=$enableval],
126126
[use_exhaustive_tests=yes])
127127

128-
# Force static precomputation. The code handling this will be removed in a later commit.
129-
use_ecmult_static_precomputation=yes
130-
131128
AC_ARG_ENABLE(module_ecdh,
132129
AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation]),
133130
[enable_module_ecdh=$enableval],

0 commit comments

Comments
 (0)