Skip to content

Commit

Permalink
build: Prebuild and distribute ecmult_gen table
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
real-or-random committed Dec 9, 2021
1 parent ac49361 commit ad63bb4
Show file tree
Hide file tree
Showing 5 changed files with 9,776 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/ecmult_static_pre_g.h linguist-generated
src/ecmult_gen_static_prec_table.h linguist-generated
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ coverage.*.html

src/libsecp256k1-config.h
src/libsecp256k1-config.h.in
src/ecmult_static_context.h
build-aux/config.guess
build-aux/config.sub
build-aux/depcomp
Expand Down
49 changes: 27 additions & 22 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.PHONY: clean-precomp precomp

ACLOCAL_AMFLAGS = -I build-aux/m4

# AM_CFLAGS will be automatically prepended to CFLAGS by Automake when compiling some foo
Expand Down Expand Up @@ -52,6 +54,7 @@ noinst_HEADERS += src/hash_impl.h
noinst_HEADERS += src/field.h
noinst_HEADERS += src/field_impl.h
noinst_HEADERS += src/bench.h
noinst_HEADERS += src/basic-config.h
noinst_HEADERS += contrib/lax_der_parsing.h
noinst_HEADERS += contrib/lax_der_parsing.c
noinst_HEADERS += contrib/lax_der_privatekey_parsing.h
Expand Down Expand Up @@ -125,37 +128,39 @@ exhaustive_tests_LDFLAGS = -static
TESTS += exhaustive_tests
endif

EXTRA_PROGRAMS = gen_ecmult_static_pre_g
### Precomputed tables
EXTRA_PROGRAMS = gen_ecmult_static_pre_g gen_ecmult_gen_static_prec_table
CLEANFILES = $(EXTRA_PROGRAMS)
gen_ecmult_static_pre_g_SOURCES = src/gen_ecmult_static_pre_g.c
# See Automake manual, Section "Errors with distclean"
gen_ecmult_gen_static_prec_table_SOURCES = src/gen_ecmult_gen_static_prec_table.c

# See Automake manual, Section "Errors with distclean".
# We don't list any dependencies for the prebuilt files here because
# otherwise make's decision whether to rebuild them (even in the first
# build by a normal user) depends on mtimes, and thus is very fragile.
# This means that rebuilds of the prebuilt files always need to be
# forced by deleting them, e.g., by invoking `make clean-precomp`.
src/ecmult_static_pre_g.h:
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_static_pre_g$(EXEEXT)
./gen_ecmult_static_pre_g$(EXEEXT)
src/ecmult_gen_static_prec_table.h:
$(MAKE) $(AM_MAKEFLAGS) gen_ecmult_gen_static_prec_table$(EXEEXT)
./gen_ecmult_gen_static_prec_table$(EXEEXT)

if USE_ECMULT_STATIC_PRECOMPUTATION
CPPFLAGS_FOR_BUILD +=-I$(top_srcdir) -I$(builddir)/src

gen_ecmult_gen_static_prec_table_OBJECTS = gen_ecmult_gen_static_prec_table.o
gen_ecmult_gen_static_prec_table_BIN = gen_ecmult_gen_static_prec_table$(BUILD_EXEEXT)
$(gen_ecmult_gen_static_prec_table_OBJECTS): src/gen_ecmult_gen_static_prec_table.c src/libsecp256k1-config.h
$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -c $< -o $@
PRECOMP = src/ecmult_gen_static_prec_table.h src/ecmult_static_pre_g.h
noinst_HEADERS += $(PRECOMP)
precomp: $(PRECOMP)

$(gen_ecmult_gen_static_prec_table_BIN): $(gen_ecmult_gen_static_prec_table_OBJECTS)
$(CC_FOR_BUILD) $(SECP_CFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $^ -o $@
# Ensure the prebuilt files will be build first (only if they don't exist,
# e.g., after `make maintainer-clean`).
BUILT_SOURCES = $(PRECOMP)

$(libsecp256k1_la_OBJECTS): src/ecmult_gen_static_prec_table.h
$(tests_OBJECTS): src/ecmult_gen_static_prec_table.h
$(exhaustive_tests_OBJECTS): src/ecmult_gen_static_prec_table.h
$(bench_internal_OBJECTS): src/ecmult_gen_static_prec_table.h
$(bench_ecmult_OBJECTS): src/ecmult_gen_static_prec_table.h
maintainer-clean-local: clean-precomp

src/ecmult_gen_static_prec_table.h: $(gen_ecmult_gen_static_prec_table_BIN)
./$(gen_ecmult_gen_static_prec_table_BIN)

CLEANFILES = $(gen_ecmult_gen_static_prec_table_BIN) src/ecmult_gen_static_prec_table.h
endif
clean-precomp:
rm -f $(PRECOMP)

EXTRA_DIST = autogen.sh src/gen_ecmult_gen_static_prec_table.c src/ecmult_static_pre_g.h src/basic-config.h
EXTRA_DIST = autogen.sh SECURITY.md

if ENABLE_MODULE_ECDH
include src/modules/ecdh/Makefile.am.include
Expand Down
3 changes: 0 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ AC_ARG_ENABLE(exhaustive_tests,
[use_exhaustive_tests=$enableval],
[use_exhaustive_tests=yes])

# Force static precomputation. The code handling this will be removed in a later commit.
use_ecmult_static_precomputation=yes

AC_ARG_ENABLE(module_ecdh,
AS_HELP_STRING([--enable-module-ecdh],[enable ECDH shared secret computation]),
[enable_module_ecdh=$enableval],
Expand Down
Loading

0 comments on commit ad63bb4

Please sign in to comment.