Commit Graph

992 Commits

Author SHA1 Message Date
Russell O'Connor d6ff738d5b Ensure safety of ctz_debruijn implementation.
Adding U to the magic constants ensures that we are not mixing unsigned and signed value during multiplication, and ensures that the multiplication will not be subject to integer promotion.

The (uint32_t)/(uint64_t) casts ensure the values are properly truncated no matter the size of an int.

Prior to this commit, if secp256k1_ctz32_var_debruijn were some how managed to be built on a platform with 64-bit ints, (though this function is specifically only intended to be used on 32-bit platforms) it would perform an out-of-bounds array access.
2023-01-16 22:23:57 -05:00
Tim Ruffing a01a7d86dc
Merge bitcoin-core/secp256k1#1192: Switch to exhaustive groups with small B coefficient
ce60785b26 Introduce SECP256K1_B macro for curve b coefficient (Pieter Wuille)
4934aa7995 Switch to exhaustive groups with small B coefficient (Pieter Wuille)

Pull request description:

  This has the advantage that in the future, multiplication with B can be done using `secp256k1_fe_mul_int` rather than the slower `secp256k1_fe_mul`.

ACKs for top commit:
  real-or-random:
    ACK ce60785b26 also ran the exhaustive tests with the group of size 7
  apoelstra:
    ACK ce60785b26

Tree-SHA512: 006041189d18319ddb9c0ed54e479f393b83ab2a368d198bd24860d1d2574c0c1a311aea24fbef2e74bb7859a687dfc803b9e963e6dc5c61cb707e20f52b5a70
2023-01-16 22:36:15 +01:00
Tim Ruffing a7a7bfaf3d
Merge bitcoin-core/secp256k1#1190: Make all non-API functions (except main) static
e03ef86559 Make all non-API functions (except main) static (Pieter Wuille)

Pull request description:

ACKs for top commit:
  real-or-random:
    utACK e03ef86559
  hebasto:
    ACK e03ef86559.

Tree-SHA512: 36a35d9a8da05411c88644aec81e79883febce3e08c9eb6b0ec95cfc3705fd6abfd66f7ee10dfa081ca20786d26b0a060ead7f5c8109bf02a73dde7ef811144b
2023-01-16 18:46:37 +01:00
Pieter Wuille ce60785b26 Introduce SECP256K1_B macro for curve b coefficient 2023-01-13 17:05:39 -05:00
Pieter Wuille 4934aa7995 Switch to exhaustive groups with small B coefficient 2023-01-13 17:05:35 -05:00
Pieter Wuille 74b026f05d Add runtime checking for DECLASSIFY flag 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 6eed6c18de Update error messages to suggest msan as well 2023-01-11 16:07:37 -05:00
Pieter Wuille 8e11f89a68 Add support for msan integration to checkmem.h 2023-01-11 16:07:37 -05:00
Pieter Wuille 8dc64079eb Add compile-time error to valgrind_ctime_test 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
Tim Ruffing 9a93f48f50 refactor: Rename STTC to STATIC_CTX in tests 2023-01-10 18:43:09 +01:00
Tim Ruffing 3385a2648d refactor: Rename global variables to uppercase in tests 2023-01-10 18:43:09 +01:00
Pieter Wuille e03ef86559 Make all non-API functions (except main) static 2023-01-09 12:02:27 -05:00
Tim Ruffing 39e8f0e3d7 refactor: Separate run_context_tests into static vs proper contexts 2023-01-05 10:28:10 +01:00
Tim Ruffing a4a09379b1 tests: Clean up and improve run_context_tests() further 2023-01-05 10:28:10 +01:00
Tim Ruffing fc90bb5695 refactor: Tidy up main() 2023-01-05 10:28:10 +01:00
Tim Ruffing f32a36f620 tests: Don't use global context for context tests 2023-01-05 10:28:10 +01:00
Tim Ruffing ce4f936c4f tests: Tidy run_context_tests() by extracting functions 2023-01-05 10:28:04 +01:00
Tim Ruffing 18e0db30cb tests: Don't recreate global context in scratch space test 2023-01-04 16:52:36 +01:00
Tim Ruffing b19806122e tests: Use global copy of secp256k1_context_static instead of clone 2023-01-04 16:39:50 +01:00
Tim Ruffing 01b819a8c7
Merge bitcoin-core/secp256k1#1158: Add a secp256k1_i128_to_u64 function.
d216475205 test secp256k1_i128_to_i64 (Russell O'Connor)
4bc429019d Add a secp256k1_i128_to_u64 function. (Russell O'Connor)

Pull request description:

  I wanted to experiment with what would be required to split up `secp256k1_i128_to_i64` between those cases when a signed 64 bit value is being demoted, versus an unsigned 64 bit value is being extracted from the lower bits, and this is the result.

  I'm not sure this is a useful PR, so feel free to close it.  However, since it is already written, I figured it is worth at least discussing.

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

Tree-SHA512: 41dbb1d33b3078bee8e71a838cfad6f1859c0bba602ae061259add8e9e8ea5aa482daa41de79dbd7433ddbef4a0bc52757f3c45d63acc9c0eb05aa3ca891b922
2022-12-21 17:25:07 +01:00
Jonas Nick eacad90f69
Merge bitcoin-core/secp256k1#1171: Change ARG_CHECK_NO_RETURN to ARG_CHECK_VOID which returns (void)
a49e0940ad docs: Fix typo (Tim Ruffing)
2551cdac90 tests: Fix code formatting (Tim Ruffing)
c635c1bfd5 Change ARG_CHECK_NO_RETURN to ARG_CHECK_VOID which returns (void) (Tim Ruffing)
cf66f2357c refactor: Add helper function secp256k1_context_is_proper() (Tim Ruffing)

Pull request description:

ACKs for top commit:
  sipa:
    utACK a49e0940ad
  jonasnick:
    ACK a49e0940ad

Tree-SHA512: 0fd4ee88510f2de0de96378ae69ce6e610a446000bb78597026c5924803e1ce5a4f76303fc6446233a6129f9c42dce1b1549f93bef935131101e47b5a69cdf2f
2022-12-21 15:28:10 +00: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
Tim Ruffing 2551cdac90 tests: Fix code formatting 2022-12-08 16:30:26 +01:00
Tim Ruffing c635c1bfd5 Change ARG_CHECK_NO_RETURN to ARG_CHECK_VOID which returns (void) 2022-12-08 16:30:26 +01:00
Tim Ruffing cf66f2357c refactor: Add helper function secp256k1_context_is_proper() 2022-12-08 16:30:26 +01:00
Jonas Nick d6dc0f4ae3
tests: Switch to NONE contexts in module tests 2022-12-07 10:54:50 +00:00
Jonas Nick 0c8a5caddd
tests: Switch to NONE contexts in tests.c 2022-12-07 10:54:50 +00:00
Jonas Nick 86540e9e1f
tests: add test for deprecated flags and rm them from run_context 2022-12-07 10:54:50 +00:00
Jonas Nick caa0ad631e
group: add gej_eq_var 2022-12-07 10:54:50 +00:00
Jonas Nick 37ba744f5b
tests: Switch to NONE contexts in exhaustive and ctime tests 2022-12-07 10:54:50 +00:00
Jonas Nick 8d7a9a8eda
benchmarks: Switch to NONE contexts 2022-12-07 10:54:43 +00:00
Tim Ruffing e02d6862bd selftest: Expose in public API 2022-12-05 11:26:44 +01:00
Tim Ruffing e383fbfa66 selftest: Rename internal function to make name available for API 2022-12-05 11:26:44 +01:00
Tim Ruffing d2c6d48de3 tests: Use new name of static context 2022-12-05 11:26:44 +01:00
Tim Ruffing 53796d2b24 contexts: Rename static context 2022-12-05 11:26:44 +01:00
Russell O'Connor d216475205 test secp256k1_i128_to_i64 2022-11-21 11:16:56 -05:00
Russell O'Connor 4bc429019d Add a secp256k1_i128_to_u64 function. 2022-11-21 11:03:44 -05:00
Pieter Wuille 99bd335599 Make int128 overflow test use secp256k1_[ui]128_mul 2022-11-17 12:22:29 -05:00
Pieter Wuille 3afce0af7c Avoid signed overflow in MSVC AMR64 secp256k1_mul128 2022-11-17 09:44:10 -05:00
Pieter Wuille 9b5f589d30 Heuristically decide whether to use int128_struct 2022-11-17 09:28:30 -05:00
Tim Ruffing 63ff064d2f int128: Add test override for testing __(u)mulh on MSVC X64
Also add a corresponding CI job
2022-11-17 09:28:30 -05:00
Pieter Wuille f2b7e88768 Add int128 randomized tests 2022-11-17 09:28:30 -05:00
Tim Ruffing ddf2b2910e
Merge bitcoin-core/secp256k1#1000: Synthetic int128 type.
a340d9500a ci: add int128_struct tests (Jonas Nick)
dceaa1f579 int128: Tidy #includes of int128.h and int128_impl.h (Tim Ruffing)
2914bccbc0 Simulated int128 type. (Russell O'Connor)

Pull request description:

  Abstracts the int128 type and provides an native version, if available, or a implements it using a pair of int64_t's.

  This is activated by setting the configuration flag `--with-test-override-wide-multiply=int128_struct`.

  The primary purpose of this PR is to take advantage of MSVC's [umulh](https://docs.microsoft.com/en-us/cpp/intrinsics/umulh?view=msvc-170) intrinsic that we can use to simulate an int128 type which MSVC does not have (AFAIU). This PR lays out the groundwork for this level of MSVC support, but doesn't include the configuration logic to enable it yet.

  For completeness, and implementation of `umulh` and `mulh` are also provided for compilers that support neither the intrinsic nor the int128 type (such as CompCert?).  This also opens up the possibility of removing the 32-bit field and scalar implementations should that ever be desired.

ACKs for top commit:
  sipa:
    ACK a340d9500a
  jonasnick:
    ACK a340d9500a

Tree-SHA512: b4f2853fa3ab60ce9d77b4eaee1fd20c4b612850e19fcb3179d7e36986f420c6c4589ff72f0cf844f989584ace49a1cd23cca3f4e405dabefc8da647a0df679d
2022-11-16 14:37:01 -05:00
Jonas Nick a340d9500a ci: add int128_struct tests 2022-11-07 16:55:43 -05:00
Tim Ruffing dceaa1f579 int128: Tidy #includes of int128.h and int128_impl.h
After this commit, int128.h and int128_impl.h are included as follows:
 - .c files which use int128 include int128_impl.h (after util.h)
 - .h files which use int128 include int128.h (after util.h)

This list is exhaustive. util.h needs to included first because it sets
up necessary #defines.
2022-11-07 16:38:30 -05:00
Russell O'Connor 2914bccbc0 Simulated int128 type. 2022-11-07 16:37:24 -05:00
Tobin C. Harding 6a965b6b98 Remove usage of CHECK from non-test file
Currently CHECK is used only in test and bench mark files except for one
usage in `ecmult_impl.h`.

We would like to move the definition of CHECK out of `util.h` so that
`util.h` no longer has a hard dependency on `stdio.h`.

Done in preparation for moving the definition of `CHECK` as part of an
effort to allow secp256k1 to be compiled to WASM as part of
`rust-secp256k1`.
2022-11-08 07:29:52 +11:00
Jonas Nick 3efeb9da21
Merge bitcoin-core/secp256k1#1121: config: Set preprocessor defaults for ECMULT_* config values
c27ae45144 config: Remove basic-config.h (Tim Ruffing)
da6514a04a config: Introduce DEBUG_CONFIG macro for debug output of config (Tim Ruffing)
d0cf55e13a config: Set preprocessor defaults for ECMULT_* config values (Tim Ruffing)

Pull request description:

ACKs for top commit:
  sipa:
    ACK c27ae45144
  hebasto:
    ACK c27ae45144, I have reviewed the code and it looks correct.
  jonasnick:
    ACK c27ae45144

Tree-SHA512: 56b0f384bd9f42cf7c903bec08f4807db1415ddf9a06676dfe1e638e4d02431c522ef0422585e85429074e0dbb51da4f400cf53e8f883d6e07122731c57be1e3
2022-07-11 12:14:25 +00:00