Commit Graph

2364 Commits

Author SHA1 Message Date
Hennadii Stepanov
a06805ee74 cmake: Remove "AUTO" value of SECP256K1_ECMULT_WINDOW_SIZE option
"AUTO" implies that a value is being chosen based on build system
introspection or host system capabilities. However, for the
`SECP256K1_ECMULT_WINDOW_SIZE` option, the value "AUTO" is hardcoded,
which might lead to confusion.

This change replaces "AUTO" with a more appropriate default value.
2024-05-27 13:28:48 +01:00
Hennadii Stepanov
26b94ee92a autotools: Remove "auto" value of --with-ecmult-gen-kb option
"auto" implies that a value is being chosen based on build system
introspection or host system capabilities. However, for the
`--with-ecmult-gen-kb` option, the value "auto" is hardcoded, which
might lead to confusion.

This change replaces "auto" with a more appropriate default value.
2024-05-27 10:57:30 +01:00
Hennadii Stepanov
122dbaeb37 autotools: Remove "auto" value of --with-ecmult-window option
"auto" implies that a value is being chosen based on build system
introspection or host system capabilities. However, for the
`--with-ecmult-window` option, the value "auto" is hardcoded, which
might lead to confusion.

This change replaces "auto" with a more appropriate default value.
2024-05-27 10:56:37 +01:00
Tim Ruffing
06bff6dec8 Merge bitcoin-core/secp256k1#1528: tests: call secp256k1_ecmult_multi_var with a non-NULL error callback
9554362b15 tests: call secp256k1_ecmult_multi_var with a non-NULL error callback (Nicolas Iooss)

Pull request description:

  Hello,
  This Pull Request fixes the issue reported in https://github.com/bitcoin-core/secp256k1/issues/1527. Function `secp256k1_ecmult_multi_var` expects to be called with a non-`NULL` `error_callback` parameter. Fix the invocation in `test_ecmult_accumulate` to do this. While at it, wrap the call in a `CHECK` macro to ensure it succeeds.

ACKs for top commit:
  real-or-random:
    utACK 9554362b15
  siv2r:
    ACK 9554362, I have also verified that other invocations of `ecmult_multi_var` (in tests) don’t use `NULL` for the error callback function argument.

Tree-SHA512: 6a9f6c10c575794da75f2254d6fbbc195de889c81a371ce35ab38e2e5483aa1e25ec0bcd5aa8d6a32a1493586f73430208a4bd0613e373571d2f04d63dbc4a1c
2024-05-13 16:06:55 +02:00
Tim Ruffing
4155e62fcc Merge bitcoin-core/secp256k1#1526: cmake: Fix check_arm32_assembly when using as subproject
9f4c8cd730 cmake: Fix `check_arm32_assembly` when using as subproject (Hennadii Stepanov)

Pull request description:

  When integrating libsecpk1 in a downstream project like this:
  ```cmake
  set(SECP256K1_ASM arm32 CACHE STRING "" FORCE)
  add_subdirectory(src/secp256k1)
  ```
  it fails to configure:
  ```
  CMake Error at /home/hebasto/git/bitcoin/build/check_arm32_assembly/CMakeFiles/CMakeTmp/CMakeLists.txt:21 (target_sources):
    Cannot find source file:

      /home/hebasto/git/bitcoin/cmake/source_arm32.s

  CMake Error at /home/hebasto/git/bitcoin/build/check_arm32_assembly/CMakeFiles/CMakeTmp/CMakeLists.txt:20 (add_executable):
    No SOURCES given to target: cmTC_d0f0b

  CMake Error at src/secp256k1/cmake/CheckArm32Assembly.cmake:2 (try_compile):
    Failed to generate test project build system.
  Call Stack (most recent call first):
    src/secp256k1/CMakeLists.txt:127 (check_arm32_assembly)

  ```

  This PR fixes this issue, which was overlooked in https://github.com/bitcoin-core/secp256k1/pull/1304.

ACKs for top commit:
  real-or-random:
    utACK 9f4c8cd730
  theuni:
    utACK 9f4c8cd730

Tree-SHA512: 47d97ad0fb2e3779523c2111ea75906671a0fb3f50646e29dee195f53106ace69af5e4abc92c765f0eee6973528ce9195b94377d0157209230c958894d4049fb
2024-05-09 09:51:58 +02:00
Nicolas Iooss
9554362b15 tests: call secp256k1_ecmult_multi_var with a non-NULL error callback
Function secp256k1_ecmult_multi_var expects to be called with a non-NULL
error_callback parameter. Fix the invocation in test_ecmult_accumulate
to do this.

While at it, wrap the call in a CHECK macro to ensure it succeeds.

Fixes: https://github.com/bitcoin-core/secp256k1/issues/1527
2024-05-08 19:13:35 +02:00
Hennadii Stepanov
9f4c8cd730 cmake: Fix check_arm32_assembly when using as subproject 2024-05-07 12:29:25 +01:00
Tim Ruffing
7712a53061 Merge bitcoin-core/secp256k1#1524: check-abi: explicitly provide public headers
dd695563e6 check-abi: explicitly provide public headers (Jonas Nick)

Pull request description:

  Without this commit, the check-abi shell script outputs false positives because it consider some headers public that are actually not public.

ACKs for top commit:
  real-or-random:
    ACK dd695563e6
  hebasto:
    ACK dd695563e6, tested on Ubuntu 24.04.

Tree-SHA512: b26e61639061f5fbbdd47569ba04f91c627feeefc43ec3d529a3ac4012ab6487aa1904bd38100ed190dcaebdffe60895a8c99346720d5dee84a0c457ec3b6f94
2024-05-07 10:35:52 +02:00
Tim Ruffing
7d0bc0870f Merge bitcoin-core/secp256k1#1525: changelog: Correct 0.5.0 release date
d45d9b74bb changelog: Correct 0.5.0 release date (Tim Ruffing)

Pull request description:

ACKs for top commit:
  sipa:
    ACK d45d9b74bb

Tree-SHA512: 45f59cd23f5ac25bd4d9cde42aea19600cdc86a4ee98ae829c1a9c8235479792c0e5bc56d470afcf6a54cf7d57d29501fb57349aa7606ae896ca10bfaf38790b
2024-05-06 19:29:57 +02:00
Tim Ruffing
d45d9b74bb changelog: Correct 0.5.0 release date 2024-05-06 19:22:16 +02:00
Jonas Nick
d7f6613dbb Merge bitcoin-core/secp256k1#1523: release cleanup: bump version after 0.5.0
2f05e2da4b release cleanup: bump version after 0.5.0 (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 2f05e2da4b

Tree-SHA512: 30e1e990b9f9b55b07895332ce46e3e12b92e5646120b504e04c8f5f88be6546c5d031ee11db8ef8226c8aacffcbaa83f96f415cc7137c4535f397a12c06bd0c
2024-05-06 17:13:29 +00:00
Tim Ruffing
2f05e2da4b release cleanup: bump version after 0.5.0 2024-05-06 19:02:57 +02:00
Jonas Nick
e3a885d42a Merge bitcoin-core/secp256k1#1522: release: prepare for 0.5.0
c0e4ec3fee release: prepare for 0.5.0 (Tim Ruffing)

Pull request description:

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

Tree-SHA512: f683d084e3f3edf13892df46a869ae9a62d4e165d08aad224b352b3f6f33bc30b1e596457bfad8c411900bf334d43d6f160889acf97dca88fea2b1d88688990a
v0.5.0
2024-05-06 16:56:12 +00:00
Jonas Nick
dd695563e6 check-abi: explicitly provide public headers
Without this commit, the check-abi shell script outputs false positives because
it consider some headers public that are actually not public.
2024-05-06 16:28:01 +00:00
Tim Ruffing
c0e4ec3fee release: prepare for 0.5.0 2024-05-06 17:59:34 +02:00
Pieter Wuille
bb528cfb08 Merge bitcoin-core/secp256k1#1518: Add secp256k1_pubkey_sort
7d2591ce12 Add secp256k1_pubkey_sort (Jonas Nick)

Pull request description:

  This PR adds a  `secp256k1_pubkey_sort` function the the public API which was originally part of the musig PR (#1479). However, I opened a separate PR because it adds internal functions that are also used by the WIP silent payments module.

ACKs for top commit:
  sipa:
    ACK 7d2591ce12
  josibake:
    ACK 7d2591ce12
  real-or-random:
    ACK 7d2591ce12

Tree-SHA512: d0e4464dc9cd4bdb35cc5d9bb4c37a7b71233328319165d49bc940d8d3394a2d74a43d2f73ee7bfe8f3f90a466ee8afcdca75cfbbf3969e218d76b89f4af55fb
2024-05-06 11:18:26 -04:00
Jonas Nick
7d2591ce12 Add secp256k1_pubkey_sort
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
Co-authored-by: Russell O'Connor <roconnor@blockstream.io>
2024-04-25 20:23:31 +00:00
Jonas Nick
da515074e3 Merge bitcoin-core/secp256k1#1058: Signed-digit multi-comb ecmult_gen algorithm
4c341f89ab Add changelog entry for SDMC (Pieter Wuille)
a043940253 Permit COMB_BITS < 256 for exhaustive tests (Pieter Wuille)
39b2f2a321 Add test case for ecmult_gen recoded = {-1,0,1} (Pieter Wuille)
644e86de9a Reintroduce projective blinding (Pieter Wuille)
07810d9abb Reduce side channels from single-bit reads (Peter Dettman)
a0d32b597d Optimization: use Nx32 representation for recoded bits (Peter Dettman)
e03dcc44b5 Make secp256k1_scalar_get_bits support 32-bit reads (Pieter Wuille)
5005abee60 Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t (Pieter Wuille)
6247f485b6 Optimization: avoid unnecessary doublings in precomputation (Peter Dettman)
15d0cca2a6 Optimization: first table lookup needs no point addition (Pieter Wuille)
7a33db35cd Optimization: move (2^COMB_BITS-1)/2 term into ctx->scalar_offset (Pieter Wuille)
ed2a056f3d Provide 3 configurations accessible through ./configure (Pieter Wuille)
5f7be9f6a5 Always generate tables for current (blocks,teeth) config (Pieter Wuille)
fde1dfcd8d Signed-digit multi-comb ecmult_gen algorithm (Peter Dettman)
486518b350 Make exhaustive tests's scalar_inverse(&x,&x) work (Pieter Wuille)
ab45c3e089 Initial gej blinding -> final ge blinding (Pieter Wuille)
aa00a6b892 Introduce CEIL_DIV macro and use it (Tim Ruffing)

Pull request description:

ACKs for top commit:
  real-or-random:
    reACK 4c341f89ab
  jonasnick:
    ACK 4c341f89ab
  stratospher:
    ACK 4c341f8. Did [these benchmarks](https://github.com/bitcoin-core/secp256k1/pull/1058#issuecomment-1002807283) and saw a 12.4% on gcc 13.2.0 and 11.5% on clang 15.0.0. Also summarised how the precomputed table generation works [here](https://github.com/stratospher/blogosphere/blob/main/sdmc.md) for future me :)

Tree-SHA512: 9a11138e4fb98b98e85c82cd46ed78b29fbe63d6efe61654ef519a64b1e175d63395a8a931c1646f9df8c7daacd796d5fe2384899d5a13a2c7ed2ded696ceed5
2024-04-22 15:17:33 +00:00
Pieter Wuille
4c341f89ab Add changelog entry for SDMC 2024-04-19 11:43:46 -04:00
Pieter Wuille
a043940253 Permit COMB_BITS < 256 for exhaustive tests 2024-04-19 11:43:46 -04:00
Pieter Wuille
39b2f2a321 Add test case for ecmult_gen recoded = {-1,0,1} 2024-04-19 11:43:46 -04:00
Pieter Wuille
644e86de9a Reintroduce projective blinding 2024-04-19 11:43:46 -04:00
Peter Dettman
07810d9abb Reduce side channels from single-bit reads
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2024-04-19 11:43:46 -04:00
Peter Dettman
a0d32b597d Optimization: use Nx32 representation for recoded bits
The existing code needs to deal with the edge case that bit_pos >= 256,
which would lead to an out-of-bounds read from secp256k1_scalar.

Instead, recode the scalar into an array of uint32_t with enough zero
padding at the end to alleviate the issue. This also simplifies the
code, and is necessary for a security improvement in a follow-up
commit.

Original code by Peter Dettman, with modifications by Pieter Wuille.
2024-04-19 11:43:46 -04:00
Pieter Wuille
e03dcc44b5 Make secp256k1_scalar_get_bits support 32-bit reads
The old code would trigger UB when count=32.
2024-04-19 11:43:46 -04:00
Pieter Wuille
5005abee60 Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t 2024-04-19 11:43:46 -04:00
Peter Dettman
6247f485b6 Optimization: avoid unnecessary doublings in precomputation 2024-04-19 11:43:46 -04:00
Pieter Wuille
15d0cca2a6 Optimization: first table lookup needs no point addition 2024-04-19 11:43:46 -04:00
Pieter Wuille
7a33db35cd Optimization: move (2^COMB_BITS-1)/2 term into ctx->scalar_offset
It is unnecessary to recompute this term needed by the SDMC algorithm
for every multiplication; move it into the context scalar_offset value
instead.
2024-04-19 11:43:45 -04:00
Pieter Wuille
ed2a056f3d Provide 3 configurations accessible through ./configure 2024-04-19 11:43:26 -04:00
Pieter Wuille
5f7be9f6a5 Always generate tables for current (blocks,teeth) config 2024-04-19 11:43:26 -04:00
Peter Dettman
fde1dfcd8d Signed-digit multi-comb ecmult_gen algorithm
This introduces the signed-digit multi-comb multiplication algorithm
for constant-time G multiplications (ecmult_gen). It is based on
section 3.3 of "Fast and compact elliptic-curve cryptography" by
Mike Hamburg (see https://eprint.iacr.org/2012/309).

Original implementation by Peter Dettman, with changes by Pieter Wuille
to use scalars for recoding, and additional comments.
2024-04-19 11:43:22 -04:00
Pieter Wuille
486518b350 Make exhaustive tests's scalar_inverse(&x,&x) work
The old code overwrote the input at the start of the function,
making a call like secp256k1_scalar_inverse(&x,&x) always fail.
2024-04-19 10:27:15 -04:00
Pieter Wuille
ab45c3e089 Initial gej blinding -> final ge blinding
Instead of having the starting point of the ecmult_gen computation be
offset, do it with the final point. This enables reasoning over the
set of points reachable in intermediary computations, which can be
leveraged by potential future optimization.

Because the final point is in affine coordinates, its projective
blinding is no longer possible. It will be reintroduced again in
a different way, in a later commit.

Also introduce some more comments and more descriptive names.
2024-04-19 10:27:12 -04:00
Tim Ruffing
aa00a6b892 Introduce CEIL_DIV macro and use it 2024-04-15 13:18:27 -04:00
Tim Ruffing
d8311688bd Merge bitcoin-core/secp256k1#1515: ci: Note affected clangs in comment on ASLR quirk
a85e2233e7 ci: Note affected clangs in comment on ASLR quirk (Tim Ruffing)

Pull request description:

  Resolves #1506.

ACKs for top commit:
  fanquake:
    ACK a85e2233e7

Tree-SHA512: a82d6f5e57175434c1f66c7b01c90eb2877db794d7f5213b3652ecb51ebb7c03ff13ab13424b3e6d41b9eaa504af330f16855e32e63d1805c1a475f462c6da66
2024-04-04 11:52:27 +02:00
Tim Ruffing
a85e2233e7 ci: Note affected clangs in comment on ASLR quirk
Resolves #1506.
2024-04-04 11:49:00 +02:00
Tim Ruffing
4b77fec67a Merge bitcoin-core/secp256k1#1512: msan: notate more variable assignments from assembly code
f7f0184ba1 msan: notate more variable assignments from assembly code (Cory Fields)
a61339149f change inconsistent array param to pointer (Cory Fields)

Pull request description:

  This was missed in 31ba404944 because older versions of clang did not complain about it. But clang-17, at least, does.

  The array-as-a-param makes this annoying because `sizeof(l)` is not helpful. I'd be happy to change the size calculation if there are any better suggestions or strong preferences.

ACKs for top commit:
  sipa:
    utACK f7f0184ba1
  real-or-random:
    ACK f7f0184ba1 tests work fine with clang 17 and `./configure CFLAGS="-fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -g -O1 -fno-optimize-sibling-calls" CC=clang`

Tree-SHA512: 8ab22209ef322a10f500b123c82ae5e7141ae1da0e7a890cbf90bd7d2eb11f397db4ccfe15a1666f2f49228585cccbf5bec741effebd1e2c6012cb7ea1689675
2024-04-03 19:06:22 +02:00
Cory Fields
f7f0184ba1 msan: notate more variable assignments from assembly code
This was missed in 31ba404944 because older
versions of clang did not complain about it. But clang-17, at least, does.
2024-04-03 16:03:19 +00:00
Cory Fields
a61339149f change inconsistent array param to pointer
The behavior is identical, but the former syntax suggests guarantees that
don't actually exist.
2024-04-03 16:03:19 +00:00
Tim Ruffing
05bfab69ae Merge bitcoin-core/secp256k1#1507: ci: Add workaround for ASLR bug in sanitizers
a5e8ab2484 ci: Add sanitizer env variables to debug output (Tim Ruffing)
84a93de4d2 ci: Add workaround for ASLR bug in sanitizers (Tim Ruffing)

Pull request description:

  Fixes #1506.

  This also adds the sanitizer env variables to our debug output as suggested in the same issue.

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

Tree-SHA512: 5162d14eeec01e088c600ed77e21c5ffd4dec23327b7e81b5ecac59b7c535cac97cd7b7b744c767766036dfc6d9152a9933eb326cf4065d56c46e2ee858da662
2024-03-20 13:25:32 +01:00
Tim Ruffing
a5e8ab2484 ci: Add sanitizer env variables to debug output 2024-03-19 23:52:15 +01:00
Tim Ruffing
84a93de4d2 ci: Add workaround for ASLR bug in sanitizers
Fixes #1506.
2024-03-19 23:52:15 +01:00
Jonas Nick
427e86b9ed Merge bitcoin-core/secp256k1#1490: tests: improve fe_sqr test (issue #1472)
2028069df2 doc: clarify input requirements for secp256k1_fe_mul (Sebastian Falbesoner)
11420a7a28 tests: improve fe_sqr test (Sebastian Falbesoner)

Pull request description:

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

Tree-SHA512: bb01bf6ceb34f0475a60b8dcb0cec000859a0c20f1009426bd8cab609f1941f44f84802f1565a719f7d2a55466076fb1591a353b1b75e6c0ceac44806d908176
2024-02-27 17:17:00 +00:00
Sebastian Falbesoner
2028069df2 doc: clarify input requirements for secp256k1_fe_mul
"... neither can be equal to b." could suggest that the values are not
allowed to be identical, but what is meant here is that the mentioned
inputs shouldn't point to the same object.
2024-02-27 16:32:49 +01:00
Sebastian Falbesoner
11420a7a28 tests: improve fe_sqr test
Currently the `run_sqr` test doesn't do anything with the
result of the `fe_sqr` call. Improve that by checking that
the equation `(x+y)*(x-y) = x^2 - y^2` holds for some random
values y, as suggested in issue #1471 by real-or-random.
The existing loop for generating the x values is kept as-is.
2024-02-27 16:32:45 +01:00
Jonas Nick
cdc9a6258e Merge bitcoin-core/secp256k1#1489: tests: add missing fe comparison checks for inverse field test cases
e7bdddd9c9 refactor: rename `check_fe_equal` -> `fe_equal` (Sebastian Falbesoner)
00111c9c56 tests: add missing fe comparison checks for inverse field test cases (Sebastian Falbesoner)

Pull request description:

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

Tree-SHA512: 1d14cb87bf3d190be6e11ae205ed25090758aae589f50793d9bcbdb3c04378ca08f6a3d41567fdf472786ea3234cf1f3b9c95ece8b605b4a7667a81a27b249e2
2024-02-27 15:18:20 +00:00
Tim Ruffing
d926510cf7 Merge bitcoin-core/secp256k1#1496: msan: notate variable assignments from assembly code
31ba404944 msan: notate variable assignments from assembly code (Cory Fields)
e7ea32e30a msan: Add SECP256K1_CHECKMEM_MSAN_DEFINE which applies to memory sanitizer and not valgrind (Cory Fields)

Pull request description:

  msan isn't smart enough to see that these are set without some help.

  This was pointed out here: https://github.com/bitcoin-core/secp256k1/pull/1169#issuecomment-1370003449

  With this commit, msan output is clean even with x86 asm turned on.

ACKs for top commit:
  real-or-random:
    utACK 31ba404944
  hebasto:
    re-ACK 31ba404944.

Tree-SHA512: c9c51fe542247e1e0a93f6d0063d119cf777ca8c1b7e9c8e45e168a2020dc503872eb2a78004725de81267a3ce78c923be1f8546fb92a3e95fc7ef034e5ba932
2024-02-27 14:47:18 +01:00
Cory Fields
31ba404944 msan: notate variable assignments from assembly code
msan isn't smart enough to see that these are set without some help.
2024-02-23 17:30:39 +00:00
Cory Fields
e7ea32e30a msan: Add SECP256K1_CHECKMEM_MSAN_DEFINE which applies to memory sanitizer and not valgrind 2024-02-23 17:30:39 +00:00