Commit Graph

116 Commits

Author SHA1 Message Date
Pieter Wuille bc08599e77 Remove OpenSSL testing support 2021-10-14 12:39:27 -04:00
Russell O'Connor 16a3cc07e8 Generate ecmult_static_pre_g.h
This header contains a static array that replaces the ecmult_context pre_g and pre_g_128 tables.
The gen_ecmult_static_pre_g program generates this header file.
2021-08-20 11:11:26 -04:00
Jonas Nick 253f90cdeb
Merge bitcoin-core/secp256k1#951: configure: replace AC_PATH_PROG to AC_CHECK_PROG
a4642fa15e configure: replace AC_PATH_PROG to AC_CHECK_PROG (UdjinM6)

Pull request description:

ACKs for top commit:
  real-or-random:
    ACK a4642fa15e
  jonasnick:
    utACK a4642fa15e

Tree-SHA512: 55a431633ca45ea78be3887cda2e94f6ec9e8a937bc60cf04f14d7e3be11acb7ee861bd356070e3b1f6ccdeff28c6f9ab7048a58f920681c09fe3a976621a187
2021-07-02 12:08:00 +00:00
Tim Ruffing 0302138f75 ci: Make compiler warning into errors on CI
This also tidies the list of environment variables in .cirrus.yml.
2021-07-01 20:37:40 +02:00
Tim Ruffing b924e1e605 build: Ensure that configure's compile checks default to -O2
Fixes #896.
2021-07-01 19:59:25 +02:00
Tim Ruffing 7939cd571c build: List *CPPFLAGS before *CFLAGS like on the compiler command line 2021-07-01 19:59:25 +02:00
Tim Ruffing 595e8a35d8 build: Enable -Wcast-align=strict warning 2021-07-01 19:59:23 +02:00
Tim Ruffing 07256267ff build: Use own variable SECP_CFLAGS instead of touching user CFLAGS
Fixes one of the items in #923, namely the warnings of the form
    '_putenv' redeclared without dllimport attribute:
    previous dllimport ignored [-Wattributes]

This also cleans up the way we add CFLAGS, in particular flags enabling
warnings. Now we perform some more fine-grained checking for flag
support, which is not strictly necessary but the changes also help to
document autoconf.ac.
2021-07-01 19:58:44 +02:00
UdjinM6 a4642fa15e
configure: replace AC_PATH_PROG to AC_CHECK_PROG
Bitcoin Core's `configure` script uses `AC_CHECK_PROG` to find brew in the `PATH` [1]. If found, this macro will set `BREW=brew`. When building with dependencies however the `BREW` variable is set to `no` on macOS via `depends/<host_prefix>/share/config.site` [2] and this overrides `AC_CHECK_PROG` results [3]. Ideally, secp256k1's `configure` script should follow the same logic but this is not what happens because secp256k1's `configure` uses `AC_PATH_PROG` instead which respects preset variable values (in this case for variable `BREW`) only if they are a valid path (i.e., they match `[\\/*] | ?:[\\/]*` [4]), and `no` is not a path.

This commit changes `AC_PATH_PROG` to `AC_CHECK_PROG` to be consistent with Core's `AC_CHECK_PROG`. Both of these macros are supposed to find executables in the `PATH` but the difference is that former is supposed to return the full path whereas the latter is supposed to find only the program. As a result, the latter will accept even non-paths `no` as an override. Not knowing the full path is not an issue for the `configure` script because it will only execute `BREW` immediately afterwards, which works fine without the full path. (In particular, `PATH` cannot have changed in between [5].)

[1] https://github.com/bitcoin/bitcoin/blob/master/configure.ac#L684
[2] https://github.com/bitcoin/bitcoin/blob/master/depends/config.site.in#L73-L76
[3] 6d38e9fa2b/lib/autoconf/programs.m4 (L47)
[4] 6d38e9fa2b/lib/autoconf/programs.m4 (L127)
[5] [3ab1178](3ab1178d54)
2021-06-15 19:33:57 +03:00
Jonas Nick 1e5d50fa93
Merge #889: fix uninitialized read in tests
99a1cfec17 print warnings for conditional-uninitialized (PiRK)
3d2cf6c5bd initialize variable in tests (PiRK)

Pull request description:

ACKs for top commit:
  real-or-random:
    ACK 99a1cfec17 code inspection
  jonasnick:
    ACK 99a1cfec17

Tree-SHA512: 72f92f51c44210ab54f166920f540525db0e3d1f19a2fa56e4a6d157a38a582f9dc649d919cf3278482c9fd723021b07759284a8fccbc574b62a22aac0facf51
2021-04-07 12:53:09 +00:00
Pieter Wuille 1f233b3fa0 Remove num/gmp support
The whole "num" API and its libgmp-based implementation are now unused. Remove them.
2021-03-15 13:01:52 -07:00
PiRK 99a1cfec17 print warnings for conditional-uninitialized
This compiler flag is available for clang but not gcc.

Test plan:

```
autogen.sh
./configure
make check
CC=clang ./configure
make check
```

If a variable is used uninitialized, the warning should look something
like:
```
  CC       src/tests-tests.o
src/tests.c:4336:15: warning: variable 'recid' may be uninitialized when used here [-Wconditional-uninitialized]
        CHECK(recid >= 0 && recid < 4);
              ^~~~~
./src/util.h:54:18: note: expanded from macro 'CHECK'
    if (EXPECT(!(cond), 0)) { \
                 ^~~~
./src/util.h:41:39: note: expanded from macro 'EXPECT'
                                      ^
src/tests.c:4327:14: note: initialize the variable 'recid' to silence this warning
    int recid;
             ^
              = 0
1 warning generated.
```
2021-02-04 09:52:54 +01:00
Tim Ruffing f329bba244 build: Add workaround for automake 1.13 and older
Fixes #890.
2021-02-01 22:54:09 +01:00
Tim Ruffing 3c15130709 Improve CC_FOR_BUILD detection
This commits simply uses CC as CC_FOR_BUILD and the same for
corresponding flags if we're not cross-compiling. This has a number of
benefits in this common case:
 - It avoids strange cases where very old compilers are used (#768).
 - Flags are consistently set for CC and CC_FOR_BUILD.
 - ./configure is faster.
 - You get compiler x consistently if you set CC=x; we got this wrong
   in CI in the past.

./configure warns if a _FOR_BUILD variable is set but ignored because
we're not cross-compiling.

The change exposed that //-style comments are used in gen_context.c,
which is also fixed by this commit.

This commit also reorganizes code in configure.ac to have a cleaner
separation of sections.
2021-01-08 16:09:04 +01:00
Tim Ruffing 47802a4762 Restructure and tidy configure.ac
No behavioral changes.
2021-01-08 15:29:40 +01:00
Tim Ruffing 252c19dfc6 Ask brew for valgrind include path
Valgrind is typically installed using brew on macOS. This commit
makes ./configure detect this case set the appropriate include
directory (in the same way as we already do for openssl and gmp).
2021-01-08 14:24:34 +01:00
Elichai Turkel 3734b68200
Configure echo if openssl tests are enabled 2020-10-27 16:11:27 +02:00
Jonas Nick 353dff156f Stop treating ECDH as experimental 2020-10-20 17:49:33 +00:00
Pieter Wuille 4232e5b7da Rip out non-endomorphism code 2020-10-13 11:31:13 -07:00
Jonas Nick d7838ba6a6
Merge #813: Enable configuring Valgrind support
412bf874d0 configure: Allow specifying --with[out]-valgrind explicitly (Luke Dashjr)

Pull request description:

ACKs for top commit:
  sipa:
    ACK 412bf874d0. Tested by running configure on a system with and without valgrind, and with no argument, with `--with-valgrind`, and with `--without-valgrind`.
  real-or-random:
    ACK 412bf874d0
  jonasnick:
    ACK 412bf874d0

Tree-SHA512: 92417609751e5af813faff1661055cd37f3d00dbcf109a8f14f8ba59d9f3d620c9c6b67d2b1629b6ab75e2afcd47d2b3898a0427931567fb505bc92fa5ee3532
2020-09-19 08:48:14 +00:00
Tim Ruffing e73ff30922 Enable -Wundef warning 2020-09-18 13:39:17 +02:00
Luke Dashjr 412bf874d0 configure: Allow specifying --with[out]-valgrind explicitly 2020-09-14 21:43:45 +00:00
Jonas Nick 7a703fd97d schnorrsig: Init empty experimental module 2020-09-06 19:00:03 +00:00
Jonas Nick 47e6618e11 extrakeys: Init empty experimental module
This is to prepare for xonly_pubkeys and keypairs.
2020-08-26 19:52:55 +00:00
Tim Ruffing 979961c506
Merge #787: Use preprocessor macros instead of autoconf to detect endianness
0dccf98a21 Use preprocessor macros instead of autoconf to detect endianness (Tim Ruffing)

Pull request description:

  This does not fix any particular issue but it's preferable to not
  rely on autoconf. This avoids endianness mess for users on BE hosts
  if they use their build without autoconf.

  The macros are carefully written to err on the side of the caution,
  e.g., we #error if the user manually configures a different endianness
  than what we detect.

  Supersedes #770 .

ACKs for top commit:
  sipa:
    ACK 0dccf98a21
  gmaxwell:
    ACK 0dccf98a21

Tree-SHA512: 6779458de5cb6eaef2ac37f9d4b8fa6c9b299f58f6e5b72f2b0d7e36c12ea06074e483acfb85085a147e0f4b51cd67d897f61a67250ec1cea284a0f7680eb2e8
2020-08-13 12:36:53 +02:00
Tim Ruffing 0dccf98a21 Use preprocessor macros instead of autoconf to detect endianness
This does not fix any particular issue but it's preferable to not
rely on autoconf. This avoids endianness mess for users on BE hosts
if they use their build without autoconf.

The macros are carefully written to err on the side of the caution,
e.g., we #error if the user manually configures a different endianness
than what we detect.
2020-08-11 11:25:39 +02:00
Pieter Wuille 79f1f7a4f1 Autodetect __int128 availability on the C side
Instead of supporting configuration of the field and scalar size independently,
both are now controlled by the availability of a 64x64->128 bit multiplication
(currently only through __int128). This is autodetected from the C code through
__SIZEOF_INT128__, but can be overridden using configure's
--with-test-override-wide-multiply, or by defining
USE_FORCE_WIDEMUL_{INT64,INT128} manually.
2020-08-10 14:56:39 -07:00
Tim Ruffing 5e8747ae2a autoconf: Use ":" instead of "dnl" as a noop
Fixes #424.
2020-05-18 12:30:01 +02:00
fanquake 84b5fc5bc3
build: fix OpenSSL EC detection on macOS 2020-04-09 17:14:06 +08:00
Tim Ruffing ed1b91171a
Merge #700: Allow overriding default flags
ca739cba23 Compile with optimization flag -O2 by default instead of -O3 (Jonas Nick)
83fb1bcef4 Remove -O2 from default CFLAGS because this would override the -O3 flag (see AC_PROG_CC in the Autoconf manual) (Jonas Nick)
ecba8138ec Append instead of Prepend user-CFLAGS to default CFLAGS allowing the user to override default variables (Jonas Nick)
613c34cd86 Remove test in configure.ac because it doesn't have an effect (Jonas Nick)

Pull request description:

  Right now, it's not easy to reduce the optimization level with `CFLAGS` because `configure` overwrites any optimization flag with `-O3`. The [automake documentation](https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html) states that:

   > The reason ‘$(CPPFLAGS)’ appears after ‘$(AM_CPPFLAGS)’ or ‘$(mumble_CPPFLAGS)’ in the compile command is that users should always have the last say.

  and also that it's incorrect to redefine CFLAGS in the first place

  > You should never redefine a user variable such as CPPFLAGS in Makefile.am. [...] You should not add options to these user variables within configure either, for the same reason

  With this PR `CFLAGS` is still redefined, but user-provided flags appear after the default `CFLAGS` which means that they override the default flags (at least in clang and gcc). Otherwise, the default configuration is not changed. This also means that if CFLAGS are defined by the user, then -g is not added (which does not seem to make much sense). In order to keep the `-O3` despite the reordering we need to explicitly tell autoconf to not append `-O2` by setting the default to `-g` with `: ${CFLAGS="-g"}` as per [the manual](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/autoconf.html#C-Compiler) (EDIT: link fix).

ACKs for top commit:
  real-or-random:
    ACK ca739cba23
  theuni:
    ACK ca739cba23.
  elichai:
    ACK ca739cba23

Tree-SHA512: be92589faa461d245203385d44b489c7d6917b0c68472b8d7576806c0250cf5ff61d5c99ce04eebb8ff5279b9987185d4e5d2da979683fb1c489fdf3e5b59630
2020-03-20 16:56:33 +01:00
Gregory Maxwell 3d2302257f Constant-time behaviour test using valgrind memtest.
Valgrind does bit-level tracking of the "uninitialized" status of memory,
 property tracks memory which is tainted by any uninitialized memory, and
 warns if any branch or array access depends on an uninitialized bit.

That is exactly the verification we need on secret data to test for
 constant-time behaviour. All we need to do is tell valgrind our
 secret key is actually uninitialized memory.

This adds a valgrind_ctime_test which is compiled if valgrind is installed:

Run it with libtool --mode=execute:
$ libtool --mode=execute valgrind ./valgrind_ctime_test
2020-02-24 18:59:30 +00:00
Gregory Maxwell 7b50483ad7 Adds a declassify operation to aid constant-time analysis.
ECDSA signing has a retry loop for the exceptionally unlikely case
 that S==0.  S is not a secret at this point and this case is so
 rare that it will never be observed but branching on it will trip
 up tools analysing if the code is constant time with respect to
 secrets.

Derandomized ECDSA can also loop on k being zero or overflowing,
 and while k is a secret these cases are too rare (1:2^255) to
 ever observe and are also of no concern.

This adds a function for marking memory as no-longer-secret and
 sets it up for use with the valgrind memcheck constant-time
 test.
2020-02-20 17:27:26 +00:00
Jonas Nick ca739cba23 Compile with optimization flag -O2 by default instead of -O3 2020-02-19 14:07:54 +00:00
Jonas Nick 642cd062bd Remove Java Native Interface 2020-01-08 09:13:09 +00:00
Jonas Nick 83fb1bcef4 Remove -O2 from default CFLAGS because this would override the -O3 flag (see AC_PROG_CC in the Autoconf manual) 2020-01-05 15:16:33 +00:00
Jonas Nick ecba8138ec Append instead of Prepend user-CFLAGS to default CFLAGS allowing the user to override default variables 2020-01-05 15:16:33 +00:00
Jonas Nick 613c34cd86 Remove test in configure.ac because it doesn't have an effect 2020-01-05 15:16:33 +00:00
djb dcb2e3b3ff
variable signing precompute table
make ECMULT_GEN_PREC_BITS configurable

ecmult_static_context.h: add compile time config assertion (#3) - Prevents accidentally using a file which was generated with a
different configuration.

README: mention valgrind issue

With --with-ecmult-gen-precision=8, valgrind needs a max stack size
adjustment to not run into a stack switching heuristic:

http://valgrind.org/docs/manual/manual-core.html

> -max-stackframe= [default: 2000000]
> The maximum size of a stack frame. If the stack pointer moves by more than this amount then Valgrind will assume that the program is switching to a different stack.
You may need to use this option if your program has large stack-allocated arrays.

basic-config: undef ECMULT_WINDOW_SIZE before (re-)defining it
2019-09-05 09:19:41 +02:00
Tim Ruffing a467047e11
Make ./configure string consistent
This was forgotten in some PR rebase.
2019-09-04 18:53:08 +02:00
Tim Ruffing 5db782e655 Allow usage of external default callbacks 2019-05-26 22:32:36 +02:00
Tim Ruffing a61a93ff50 Clean up ./configure help strings 2019-05-24 21:02:31 +02:00
Tim Ruffing 2842dc523e Make WINDOW_G configurable
This makes WINDOW_G a configurable value in the range of [2..24].
The upper limit of 24 is a defensive choice. The code is probably
correct for values up to 27 but those larger values yield in huge
tables (>= 256MiB), which are i) unlikely to be really beneficial
in practice and ii) increasingly difficult to test.
2019-05-24 21:02:31 +02:00
DesWurstes 310111e093
Keep LDFLAGS if `--coverage` 2019-02-25 11:34:52 +03:00
Gregory Maxwell 5545e13dea
Merge #584: configure: Use CFLAGS_FOR_BUILD when checking native compiler
a34bcaa Actually pass CFLAGS_FOR_BUILD and LDFLAGS_FOR_BUILD to linker (Tim Ruffing)
2d5f4ce configure: Use CFLAGS_FOR_BUILD when checking native compiler (Tim Ruffing)

Pull request description:

  This fixes a bug where configure would fail or disable static
  ecmult tables because it wrongly checks the native compiler using
  the target CFLAGS (instead of the native CFLAGS_FOR_BUILD).

  Moreover, this commit adds tests to figure out whether the native
  compiler supports the warning flags passed during the build, and it
  contains a few minor improvements to the code that checks the native
  compiler.

Tree-SHA512: 31a92a5516cf2f9801c918edfba0059aa4f8549b0c1de94fc166b5e92ad1868a480c48cdc5ff62679ba20e26f4a0e2948c71fd2b3e80766673d2bf7512da3875
2019-02-22 01:29:02 +00:00
Gregory Maxwell 6492bf88cc
Merge #518: Summarize build options after running configure
3965027 Summarize build options in configure script (Evan Klitzke)

Pull request description:

  This is a trivial build system change to summarize the build options after running configure.

  Example output:
  ```
  $ ./configure
  ....
  <many lines omitted>
  ...
  config.status: src/libsecp256k1-config.h is unchanged
  config.status: executing depfiles commands
  config.status: executing libtool commands

  Build Options:
    with endomorphism   = no
    with ecmult precomp = yes
    with jni            = no
    module ecdh         = no
    module recovery     = no

    asm                 = x86_64
    bignum              = gmp
    field               = 64bit
    scalar              = 64bit

    CC                  = gcc
    CFLAGS              = -g -O2 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden -O3
    CPPFLAGS            =
    LDFLAGS             =
  ```

  I tried to just include the configure options that looked interesting; let me know if there are any I didn't include that I should have.

Tree-SHA512: 428381654d772f76bc81210d39ba5c3f07a94dc6a6378a02ccc6f23ebce7f501896268bcd2e94e2b0d8aea54c9c70c44a9238a0f0960600f463b1e2847c7ed1f
2019-02-21 04:44:01 +00:00
Gregory Maxwell 58df8d03ad
Merge #511: Portability fix for the configure scripts generated
270f6c8 Portability fix for the configure scripts generated (Pierre Pronchery)

Pull request description:

  Found thanks to the developer checks from the pkgsrc software
  distribution (for NetBSD, SmartOS, Minix, MacOS X, Linux, and more).

Tree-SHA512: 2589545aa4d0620db66e79df1dc148a487384b5169ba7323937490d802973388859d30d45b35ee3e614be6d49cb694f37f585a16caa87ad1e500a0b7368dcc0a
2019-02-21 04:28:20 +00:00
Tim Ruffing 2d5f4cebdc configure: Use CFLAGS_FOR_BUILD when checking native compiler
This fixes a bug where configure would fail or disable static
ecmult tables because it wrongly checks the native compiler using
the target CFLAGS (instead of the native CFLAGS_FOR_BUILD), and
similar for CPPFLAGS and LDFLAGS.

Moreover, this commit adds tests to figure out whether the native
compiler supports the warning flags passed during the build, and it
contains a few minor improvements to the code that checks the native
compiler.
2019-02-10 11:56:36 +01:00
Tim Ruffing c663397f46 Use __GNUC_PREREQ for detecting __builtin_expect 2018-12-17 11:47:25 +01:00
Evan Klitzke 3965027c81
Summarize build options in configure script 2018-03-27 16:10:15 -07:00
Pierre Pronchery 270f6c80db Portability fix for the configure scripts generated
Found thanks to the developer checks from the pkgsrc software
distribution (for NetBSD, SmartOS, Minix, MacOS X, Linux, and more).
2018-02-26 02:22:11 +01:00