Commit Graph

118 Commits

Author SHA1 Message Date
Hennadii Stepanov 2cd4e3c0a9
Drop no longer used `SECP_{LIBS,INCLUDE}` variables
The last usage of the `SECP_INCLUDE` variable was removed
in https://github.com/bitcoin-core/secp256k1/pull/1169.
2023-01-19 09:43:28 +00:00
Hennadii Stepanov 613626f94c
Drop no longer used `SECP_TEST_{LIBS,INCLUDE}` variables
The last usage of the `SECP_TEST_{LIBS,INCLUDE}` variables was removed
in https://github.com/bitcoin-core/secp256k1/pull/983.
2023-01-19 09:27:33 +00:00
Tim Ruffing f29a327092
Merge bitcoin-core/secp256k1#1169: Add support for msan instead of valgrind (for memcheck and ctime test)
0f088ec112 Rename CTIMETEST -> CTIMETESTS (Pieter Wuille)
74b026f05d Add runtime checking for DECLASSIFY flag (Pieter Wuille)
5e2e6fcfc0 Run ctime test in Linux MSan CI job (Pieter Wuille)
18974061a3 Make ctime tests building configurable (Pieter Wuille)
5048be17e9 Rename valgrind_ctime_test -> ctime_tests (Pieter Wuille)
6eed6c18de Update error messages to suggest msan as well (Pieter Wuille)
8e11f89a68 Add support for msan integration to checkmem.h (Pieter Wuille)
8dc64079eb Add compile-time error to valgrind_ctime_test (Pieter Wuille)
0db05a770e Abstract interactions with valgrind behind new checkmem.h (Pieter Wuille)
4f1a54e41d Move valgrind CPPFLAGS into SECP_CONFIG_DEFINES (Pieter Wuille)

Pull request description:

  This introduces an abstraction layer `src/checkmem.h`, which defines macros for interacting with memory checking tools. Depending on the environment, they're mapped to MemorySanitizer builtins, Valgrind integration macros, or nothing at all.

  This means that msan builds immediately benefit from existing undefined memory checks in the tests. It also means those builds result in a `ctime_tests` (new name for `valgrind_ctime_test`) binary that can usefully test constant-timeness (not inside Valgrind, and with the downside that it's not running against a production library build, but it's faster and available on more platforms).

  Such an msan-ctime test is added to the Linux x86_64 msan CI job, as an example. More CI cases could be added (e.g. for MacOs or ARM Linux) later.

ACKs for top commit:
  real-or-random:
    ACK 0f088ec112
  hebasto:
    ACK 0f088ec112, I have reviewed the code and it looks OK. Able to build `ctime_tests` using MSan.

Tree-SHA512: f4ffcc0c2ea794894662d9797b3a349770a4b361996f967f33d7d14b332171de5d525f50bcebaeaf7d0624957083380962079c75e490d1b7d71f8f9eb6211590
2023-01-16 16:03:05 +01:00
Tim Ruffing 88e80722d2
Merge bitcoin-core/secp256k1#1160: Makefile: add `-I$(top_srcdir)/{include,src}` to `CPPFLAGS` for precomputed
e862c4af0c Makefile: add -I$(top_srcdir)/src to CPPFLAGS for precomputed (Matt Whitlock)

Pull request description:

  When performing an out-of-source-tree build, regenerating the source files for the precomputed ecmult tables places them outside the source tree. Then, when they are to be compiled, they cannot find the headers they need because the source tree is absent from their include search path. This appears to have been an oversight, as the relevant `-I` options are present in `libsecp256k1_la_CPPFLAGS` but were missing from `libsecp256k1_precomputed_la_CPPFLAGS`. This PR adds them.

ACKs for top commit:
  sipa:
    utACK e862c4af0c
  real-or-random:
    ACK e862c4af0c

Tree-SHA512: f58b8670b2798f2ca4bd6e9fd83218afcd14cf1b796cd18fb40e7b8a148dcdfabe5f0beae81bc6b82727c97a507431e6a7c72d756587e047daf1ea81242cccf9
2023-01-12 10:50:57 +01:00
Pieter Wuille 18974061a3 Make ctime tests building configurable 2023-01-11 16:07:37 -05:00
Pieter Wuille 5048be17e9 Rename valgrind_ctime_test -> ctime_tests 2023-01-11 16:07:37 -05:00
Pieter Wuille 0db05a770e Abstract interactions with valgrind behind new checkmem.h 2023-01-11 16:07:35 -05:00
Pieter Wuille 4f1a54e41d Move valgrind CPPFLAGS into SECP_CONFIG_DEFINES 2023-01-11 16:03:15 -05:00
Tim Ruffing 203760023c tests: Add noverify_tests which is like tests but without VERIFY 2023-01-07 23:13:06 +01:00
Matt Whitlock e862c4af0c Makefile: add -I$(top_srcdir)/src to CPPFLAGS for precomputed
When performing an out-of-source-tree build, regenerating the source
files for the precomputed ecmult tables places them outside the source
tree. Then, when they are to be compiled, they cannot find the headers
they need because the source tree is absent from their include search
path. This appears to have been an oversight, as the relevant -I options
are present in libsecp256k1_la_CPPFLAGS but were missing from
libsecp256k1_precomputed_la_CPPFLAGS. This commit adds them.
2023-01-06 18:20:05 -05:00
Hennadii Stepanov 2f9ca284e2
Drop `SECP_CONFIG_DEFINES` from examples
User applications shouldn't need or rely on `SECP_CONFIG_DEFINES`.
2023-01-03 17:33:32 +00:00
Pieter Wuille c0a555b2ae Bugfix: pass SECP_CONFIG_DEFINES to bench compilation 2022-12-29 15:31:55 -05:00
Hennadii Stepanov b627ba7050
Remove dependency on `src/libsecp256k1-config.h`
This change eases the use of alternate build systems by moving
the variables in `src/libsecp256k1-config.h` to compiler macros
for each invocation, preventing duplication of these variables
for each build system.

Co-authored-by: Ali Sherief <ali@notatether.com>
2022-12-15 10:56:16 +00:00
Jonas Nick 6d1784a2e2
build: add missing files to EXTRA_DIST 2022-12-12 21:26:32 +00:00
Russell O'Connor 2914bccbc0 Simulated int128 type. 2022-11-07 16:37:24 -05:00
Tim Ruffing c27ae45144 config: Remove basic-config.h
It's unused and thus potentially confusing.
2022-07-07 20:32:18 +02:00
Tim Ruffing 40a3473a9d build: Fix #include "..." paths to get rid of further -I arguments
This simplifies building without a build system.

This is in line with #925; the paths fixed here were either forgotten
there or only introduced later. This commit also makes the Makefile
stricter so that further "wrong" #include paths will lead to build
errors even in autotools builds.

This belongs to #929.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-07-01 15:03:35 +02:00
Elichai Turkel 517644eab1
Optionally compile the examples in autotools, compile+run in travis 2022-02-23 16:14:58 +02:00
Jonas Nick 0bd3e4243c build: set library version to 0.0.0 explicitly 2021-12-23 14:47:14 +00:00
Pieter Wuille 19d96e15f9 Split off .c file from precomputed_ecmult.h 2021-12-18 16:12:34 -05:00
Pieter Wuille 1a6691adae Split off .c file from precomputed_ecmult_gen.h 2021-12-18 16:12:34 -05:00
Pieter Wuille e458ec26d6 Move ecmult table computation code to separate file 2021-12-18 16:11:56 -05:00
Pieter Wuille 725370c3f2 Rename ecmult_gen_prec -> ecmult_gen_compute_table 2021-12-17 14:43:45 -05:00
Pieter Wuille 075252c1b7 Rename ecmult_static_pre_g -> precomputed_ecmult 2021-12-17 11:29:17 -05:00
Pieter Wuille 7cf47f72bc Rename ecmult_gen_static_prec_table -> precomputed_ecmult_gen 2021-12-17 11:24:18 -05:00
Pieter Wuille f95b8106d0 Rename gen_ecmult_static_pre_g -> precompute_ecmult 2021-12-17 11:19:45 -05:00
Pieter Wuille bae77685eb Rename gen_ecmult_gen_static_prec_table -> precompute_ecmult_gen 2021-12-17 11:15:37 -05:00
Tim Ruffing 0559fc6e41
Merge bitcoin-core/secp256k1#988: Make signing table fully static
7dfceceea6 build: Remove #undef hack for ASM in the precomputation programs (Tim Ruffing)
bb36fe9be0 ci: Test `make precomp` (Tim Ruffing)
d94a37a20c build: Remove CC_FOR_BUILD stuff (Tim Ruffing)
ad63bb4c29 build: Prebuild and distribute ecmult_gen table (Tim Ruffing)
ac49361ed0 prealloc: Get rid of manual memory management for prealloc contexts (Tim Ruffing)
6573c08f65 ecmult_gen: Tidy precomputed file and save space (Tim Ruffing)
5eba83f17c ecmult_gen: Precompute tables for all values of ECMULT_GEN_PREC_BITS (Tim Ruffing)
fdb33dd122 refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table (Tim Ruffing)
a4875e30a6 refactor: Move default callbacks to util.h (Tim Ruffing)
4c94c55bce doc: Remove obsolete hint for valgrind stack size (Tim Ruffing)
5106226991 exhaustive_tests: Fix with ecmult_gen table with custom generator (Tim Ruffing)
e1a76530db refactor: Make generator a parameter of ecmult_gen_create_prec_table (Tim Ruffing)
9ad09f6911 refactor: Rename program that generates static ecmult_gen table (Tim Ruffing)
8ae18f1ab3 refactor: Rename file that contains static ecmult_gen table (Tim Ruffing)
00d2fa116e ecmult_gen: Make code consistent with comment (Tim Ruffing)
3b0c2185ea ecmult_gen: Simplify ecmult_gen context after making table static (Tim Ruffing)
e43ba02cfc refactor: Decouple table generation and ecmult_gen context (Tim Ruffing)
22dc2c0a0d ecmult_gen: Move table creation to new file and force static prec (Tim Ruffing)

Pull request description:

  This resolves #893,  resolves #692 (and also resolves bitcoin/bitcoin#22854).

  - [x] Extract table generation to separate function in separate file (to be used by generation script and exhaustive tests)
  - [x] Tidy up
    - [x] Remove code that deals with non-static tables
    - [x] Make functions that need ecmult_gen not depend on signing context
    - [x] Rename stuff to make it fit the new structure and consistent with how we hande verification tables (#956)
  - [x] Fix exhaustive tests
    - [x] Make table generation function take generator as input
    - [x] Overwrite the static tables with a table with custom generator in exhaustive tests
  - [x] Overhaul script that generates table files
    - [x] Make table generation function take PREC_BITS as input (I have some code already, just not yet in this branch)
    - [x] Change generation script to generate three tables (for all three values of ECMULT_GEN_PREC_BITS)
  - [x] Ship pre-built tables
    - [x] Add pregenerated table file to repo
    - [x] Remove generation of table file from build process (like in #956)
    - [x] Remove left-over stuff (e.g., detecting a compiler running on the build machine) from build system
  - [x] Final cleanups (copyright headers, commit, messages, etc.)
  - [ ] (separate PR:) Make sure link-time optimization remove corresponding static tables (and code) when no signing/verifcation function is called
  - [ ] (separate PR:) Compile precomputation as a separate object file and link it (https://github.com/bitcoin-core/secp256k1/pull/988#issuecomment-977813538)
  - [ ] (separate PR:) Document the backwards-compatible API changes made in this PR and in #956.
    - [ ] Maybe deprecate the static context

ACKs for top commit:
  sipa:
    ACK 7dfceceea6
  robot-dreams:
    ACK 7dfceceea6 (based on range-diff between 56284c7d44c0ed46e636588bfbf6c403b7dfa6c1 and 7dfceceea6)

Tree-SHA512: 6efb3f36f05efe3b79bbd877881fe1409f71fd6488d24c811b2e77d9f053bed78670dd1dcbb42ad780458a51c4ffa36de9cd6567271b22041dc7a122ceb677c5
2021-12-15 11:06:47 +01:00
Tim Ruffing 7dfceceea6 build: Remove #undef hack for ASM in the precomputation programs
This was necessary because we used to cross-compile the library but
compile the precomputation programs for the build host. Now it's no
longer necessary and we can cleanly link even the external ASM
(which was the intent of #935).

On the way, remove an obsolete "-I" parameter.
2021-12-09 20:52:56 +01:00
Tim Ruffing ad63bb4c29 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
2021-12-09 20:52:28 +01:00
Tim Ruffing 9ad09f6911 refactor: Rename program that generates static ecmult_gen table 2021-12-03 11:23:33 +01:00
Tim Ruffing 8ae18f1ab3 refactor: Rename file that contains static ecmult_gen table 2021-12-03 11:23:33 +01:00
fanquake c0cd7de6d4
build: add -no-undefined to libtool LDFLAGS
Instruct libtool to not allow undefined symbols when linking a shared
library.

See:
https://autotools.io/libtool/windows.html
https://www.gnu.org/software/libtool/manual/libtool.html#LT_005fINIT
https://www.gnu.org/software/gnulib/manual/html_node/Libtool-and-Windows.html
2021-12-02 11:48:43 +08:00
Tim Ruffing 22dc2c0a0d ecmult_gen: Move table creation to new file and force static prec 2021-11-19 13:47:05 +01:00
Pieter Wuille 2a7be678a6 Combine bench_sign and bench_verify into single bench 2021-11-05 17:30:56 -04:00
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
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
Tim Ruffing c8483520c9 Makefile.am: Don't pass a variable twice 2021-05-03 15:07:04 +02:00
Tim Ruffing 2161f31785 Makefile.am: Honor config when building gen_context
This passes $(DEFS) (which should literally be "-DHAVE_CONFIG_H") to the
compiler when building gen_context.

This has currently no effect because gen_context.c does not check for
this macro but it's conceivable that it may do so in the future.
2021-05-03 15:05:38 +02:00
Gregory Maxwell ae9e648526 Define SECP256K1_BUILD in secp256k1.c directly.
This avoids building without it and makes it safer to use a custom
 building environment.  Test harnesses need to #include secp256k1.c
 first now.
2021-05-01 19:27:27 +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
Peter Dettman 8e415acba2 Add safegcd based modular inverse modules
Refactored by: Pieter Wuille <pieter@wuille.net>
2021-03-08 09:56:07 -08:00
Tim Ruffing 8ab24e8dad
Merge #558: Add schnorrsig module which implements BIP-340 compliant signatures
f431b3f28a valgrind_ctime_test: Add schnorrsig_sign (Jonas Nick)
16ffa9d97c schnorrsig: Add taproot test case (Jonas Nick)
8dfd53ee3f schnorrsig: Add benchmark for sign and verify (Jonas Nick)
4e43520026 schnorrsig: Add BIP-340 compatible signing and verification (Jonas Nick)
7332d2db6b schnorrsig: Add BIP-340 nonce function (Jonas Nick)
7a703fd97d schnorrsig: Init empty experimental module (Jonas Nick)
eabd9bc46a Allow initializing tagged sha256 (Jonas Nick)
6fcb5b845d extrakeys: Add keypair_xonly_tweak_add (Jonas Nick)
58254463f9 extrakeys: Add keypair struct with create, pub and pub_xonly (Jonas Nick)
f0010349b8 Separate helper functions for pubkey_create and seckey_tweak_add (Jonas Nick)
910d9c284c extrakeys: Add xonly_pubkey_tweak_add & xonly_pubkey_tweak_add_test (Jonas Nick)
176bfb1110 Separate helper function for ec_pubkey_tweak_add (Jonas Nick)
4cd2ee474d extrakeys: Add xonly_pubkey with serialize, parse and from_pubkey (Jonas Nick)
47e6618e11 extrakeys: Init empty experimental module (Jonas Nick)
3e08b02e2a Make the secp256k1_declassify argument constant (Jonas Nick)

Pull request description:

  This PR implements signing, verification and batch verification as described in [BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki) in an experimental module named `schnorrsig`. It includes the test vectors and a benchmarking tool.
  This PR also adds a module `extrakeys` that allows [BIP-341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)-style key tweaking.

  (Adding ChaCha20 as a CSPRNG and batch verification was moved to PR #760).

  In order to enable the module run `./configure` with `--enable-experimental --enable-module-schnorrsig`.

  Based on apoelstra's work.

ACKs for top commit:
  gmaxwell:
    ACK f431b3f28a  (exactly matches the previous post-fixup version which I have already reviewed and tested)
  sipa:
    ACK f431b3f28a
  real-or-random:
    ACK f431b3f28a careful code review

Tree-SHA512: e15e849c7bb65cdc5d7b1d6874678e275a71e4514de9d5432ec1700de3ba92aa9f381915813f4729057af152d90eea26aabb976ed297019c5767e59cf0bbc693
2020-09-11 21:25:34 +02:00
Tim Ruffing 54caf2e74f
Merge #799: Add fallback LE/BE for architectures with known endianness + SHA256 selftest
8bc6aeffa9 Add SHA256 selftest (Pieter Wuille)
5e5fb28b4a Use additional system macros to figure out endianness (Pieter Wuille)

Pull request description:

  These are all the architecture macros I could find with known endianness. Use those as a fallback when __BYTE_ORDER__ isn't available.

  See https://github.com/bitcoin-core/secp256k1/pull/787#issuecomment-673764652

  It also adds a SHA256 selftest, so that improperly overriding the endianness detection will be detected at runtime.

ACKs for top commit:
  real-or-random:
    ACK 8bc6aeffa9 I read the diff, and tested that the self-test passes/fails with/without the correct endianness setting
  gmaxwell:
    ACK 8bc6aeffa9  looks good and I also ran the tests on MIPS-BE and verified that forcing it to LE makes the runtime test  fail.

Tree-SHA512: aca4cebcd0715dcf5b58f5763cb4283af238987f43bd83a650e38e127f348131692b2eed7ae5b2ae96046d9b971fc77c6ab44467689399fe470a605c3458ecc5
2020-09-09 15:57:45 +02: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
Pieter Wuille 8bc6aeffa9 Add SHA256 selftest 2020-08-22 16:35:47 -07:00
Pieter Wuille 7c068998ba Compile-time check assumptions on integer types 2020-08-14 16:12:49 -07:00
Gregory Maxwell 57d3a3c64c Avoid linking libcrypto in the valgrind ct test.
Libcrypto isn't useful here and on some systems UB in OpenSSL's
 init causes failures.

Fixes #775.
2020-08-10 22:13:43 +00:00