Commit Graph

97 Commits

Author SHA1 Message Date
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
Gregory Maxwell b549d3d5f7
Merge #472: [build] Set --enable-jni to no by default instead of auto.
57752d2 [build] Set --enable-jni to no by default instead of auto. (Karl-Johan Alm)

Pull request description:

  Having `--enable-jni` be `auto` doesn't make a lot of sense, and results in things like https://github.com/bitcoin/bitcoin/pull/11056.

Tree-SHA512: 27d6ea041f5d6e249857869ab87b8f7b1f6d18ec5ec82d2c46e692cd690b9f5c5857886725901a29d3539d427d8b6154d0c7909cfa2ce30bb3d4460c05708386
2018-02-06 22:54:03 +00:00
Pieter Wuille 7a78f60598 Print whether we're building benchmarks 2017-09-27 17:25:12 -07:00
Pieter Wuille 4afec9f1ae Build benchmarks by default 2017-09-27 17:25:12 -07:00
Karl-Johan Alm 57752d28b3
[build] Set --enable-jni to no by default instead of auto. 2017-08-17 17:10:57 +09:00
Andrew Poelstra a724d7296d configure: add --enable-coverage to set options for coverage analysis 2016-11-28 03:29:01 +00:00
Andrew Poelstra 20b8877be1 Add exhaustive test for group functions on a low-order subgroup
We observe that when changing the b-value in the elliptic curve formula
`y^2 = x^3 + ax + b`, the group law is unchanged. Therefore our functions
for secp256k1 will be correct if and only if they are correct when applied
to the curve defined by `y^2 = x^3 + 4` defined over the same field. This
curve has a point P of order 199.

This commit adds a test which computes the subgroup generated by P and
exhaustively checks that addition of every pair of points gives the correct
result.

Unfortunately we cannot test const-time scalar multiplication by the same
mechanism. The reason is that these ecmult functions both compute a wNAF
representation of the scalar, and this representation is tied to the order
of the group.

Testing with the incomplete version of gej_add_ge (found in 5de4c5dff^)
shows that this detects the incompleteness when adding P - 106P, which
is exactly what we expected since 106 is a cube root of 1 mod 199.
2016-11-25 20:45:29 +00:00
Pieter Wuille e06e878fd7 Remove Schnorr experiment 2016-11-17 18:55:06 -08:00
Cory Fields 00c5d2e142 fix auto-enabled static precompuatation
This was broken in aa0b1fd149
2016-09-07 12:16:15 -04:00
Pieter Wuille 65285a63ee
Merge #403: configure: add flag to disable OpenSSL tests
a9b2a5d configure: add flag to disable OpenSSL tests (Andrew Poelstra)
2016-07-06 12:08:16 +02:00
Andrew Poelstra a9b2a5d850 configure: add flag to disable OpenSSL tests
OpenSSL messes up valgrind.
2016-07-06 08:25:33 +00:00
Pieter Wuille 24ad20f75b
Merge #399: build: verify that the native compiler works for static precomp
aa0b1fd build: verify that the native compiler works for static precomp (Cory Fields)
2016-06-29 11:11:46 +02:00
Cory Fields aa0b1fd149 build: verify that the native compiler works for static precomp 2016-05-27 15:45:14 -04:00
Pieter Wuille eee808d809 Test whether ECDH and Schnorr are enabled for JNI 2016-05-25 19:15:42 +02:00
Wladimir J. van der Laan 001f1763c7 ARM assembly implementation of field_10x26 inner
Rebased-by: Pieter Wuille <pieter.wuille@gmail.com>
2016-05-25 18:27:47 +02:00
GreenAddress 3093576aa4 JNI library
Squashed and rebased. Thanks to @theuni and @faizkhan00 for doing
the majority of work here! Also thanks to @btchip for help with debugging
and review.
2016-02-01 14:07:18 +01:00
Pieter Wuille 83221ecb00 Add experimental features to configure 2015-11-27 00:20:28 +01:00
Gregory Maxwell 118cd8210f Use explicit symbol visibility.
The use of static makes this somewhat redundant currently, though if
 we later have multiple compilation units it will be needed.

This also sets the dllexport needed for shared libraries on win32.
2015-09-25 05:42:20 +00:00
Pieter Wuille 85e3a2cc08
Merge pull request #112
2b4cf41 Use pkg-config always when possible, with failover to manual checks for libcrypto (Luke Dashjr)
2015-09-04 20:24:42 +02:00
Pieter Wuille 9f443be086 Move pubkey recovery code to separate module 2015-08-28 01:51:52 +02:00