Commit Graph
121 Commits
Author SHA1 Message Date
Tim Ruffing 47eb70959a ecmult: Use size_t for array indices in _odd_multiplies_table 2026-01-07 11:58:12 +01:00
Tim Ruffing bb1d199de5 ecmult: Use size_t for array indices into tables 2026-01-07 11:58:12 +01:00
merge-script 2d9137ce9d Merge bitcoin-core/secp256k1#1764: group: Avoid using infinity field directly in other modules
2f73e5281d group: Avoid using infinity field directly in other modules (Tim Ruffing)

Pull request description:

  Minor refactoring to make the abstraction cleaner

ACKs for top commit:
  hebasto:
    ACK 2f73e5281d, I have reviewed the code and it looks OK.
  theStack:
    ACK 2f73e5281d

Tree-SHA512: eae5ad1ce81f491adb48ab1cbf04211f8d43e41255abcacc958fa3dcb1de5021707d56ed1b009a6f3f6c45cd8f20c1f2677891690a3c0a467fc7e064af2512a8
2026-01-06 10:12:53 +01:00
Tim Ruffing 2f73e5281d group: Avoid using infinity field directly in other modules 2025-11-06 17:51:08 +01:00
Jonas Nick 26166c4f5f ecmult_multi: reduce strauss memory usage by 30% 2025-10-17 14:18:42 +00:00
Tim Ruffing 99cc9fd6d0 Don't rely on memset to set signed integers to 0 2024-10-25 18:44:48 +02:00
Tim Ruffing e7d384488e Don't clear secrets in pippenger implementation
This code is not supposed to handle secret data.
2024-10-22 18:24:57 +02:00
Pieter Wuille 5005abee60 Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t 2024-04-19 11:43:46 -04:00
Tim Ruffing aa00a6b892 Introduce CEIL_DIV macro and use it 2024-04-15 13:18:27 -04:00
Hennadii Stepanov a6ca76cdf2 Avoid -Wmaybe-uninitialized when compiling with gcc -O1 2023-06-28 07:45:57 +01:00
Sebastian Falbesoner 654246c635 refactor: take use of secp256k1_scalar_{zero,one} constants 2023-05-30 12:10:41 +02:00
Jonas Nick 073d98a076 Merge bitcoin-core/secp256k1#1292: refactor: Make 64-bit shift explicit
d1e48e5474 refactor: Make 64-bit shift explicit (Hennadii Stepanov)
b2e29e43d0 ci: Treat all compiler warnings as errors in "Windows (VS 2022)" task (Hennadii Stepanov)

Pull request description:

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

Tree-SHA512: fd07c8c136b1c947900d45b5a4ad4963e2c29884aca62a26be07713dfd1b0c5e7655f07a0b99217fc055bf3266e71cb5edabbd4d5c145a172b4be5d10f7ad51c
2023-05-11 15:06:47 +00:00
Pieter Wuille 97c63b9039 Avoid normalize conditional on VERIFY 2023-05-11 03:41:48 -04:00
Hennadii Stepanov d1e48e5474 refactor: Make 64-bit shift explicit
This change fixes MSVC level-3 warning C4334.
See: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4334

Required to enable level 3 warnings (/W3).
2023-05-02 13:35:15 +01:00
Jonas Nick afd8b23b27 Merge bitcoin-core/secp256k1#1244: Suppress -Wunused-parameter when building for coverage analysis
5bb03c2911 Replace `SECP256K1_ECMULT_TABLE_VERIFY` macro by a function (Hennadii Stepanov)
4429a8c218 Suppress `-Wunused-parameter` when building for coverage analysis (Hennadii Stepanov)

Pull request description:

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

Tree-SHA512: 19a395434ecefea201a03fc45b3f0b88f1520908926ac1207bbc6570034b1141b49c3c98e66819dcd9069dfdd28c7c6fbe957f13fb6bd178fd57ce65bfbb8fbd
2023-03-28 07:18:23 +00:00
roconnor-blockstream d1e7ca192d Typo 2023-03-22 22:01:01 -04:00
Hennadii Stepanov 5bb03c2911 Replace SECP256K1_ECMULT_TABLE_VERIFY macro by a function 2023-03-21 15:29:22 +00:00
Hennadii Stepanov 4429a8c218 Suppress -Wunused-parameter when building for coverage analysis 2023-03-14 20:03:42 +00: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
Russell O'Connor b797a500ec Create a SECP256K1_ECMULT_TABLE_VERIFY macro. 2022-01-19 11:51:43 -05:00
Russell O'Connor a731200cc3 Replace ECMULT_TABLE_GET_GE_STORAGE macro with a function. 2022-01-19 11:51:43 -05:00
Russell O'Connor fe34d9f341 Eliminate input_pos state field from ecmult_strauss_wnaf. 2022-01-19 11:51:43 -05:00
Russell O'Connor 0397d00ba0 Eliminate na_1 and na_lam state fields from ecmult_strauss_wnaf. 2022-01-19 11:51:43 -05:00
Russell O'Connor 7ba3ffcca0 Remove the unused pre_a_lam allocations. 2022-01-19 11:51:43 -05:00
Russell O'Connor b3b57ad6ee Eliminate the pre_a_lam array from ecmult_strauss_wnaf. 2022-01-19 11:51:43 -05:00
Russell O'Connor ae7ba0f922 Remove the unused prej allocations. 2022-01-19 11:51:43 -05:00
Russell O'Connor e5c18892db Eliminate the prej array from ecmult_strauss_wnaf. 2022-01-19 11:51:42 -05:00
siv2r 05e049b73c ecmult: move _ecmult_odd_multiples_table_globalz_windowa
Changes:
    - move `secp256k1_ecmult_odd_multiples_table_globalz_windowa` function from ecmult to ecmult_const
    - remove outdated comment
2021-12-24 16:22:49 +05:30
Pieter Wuille 19d96e15f9 Split off .c file from precomputed_ecmult.h 2021-12-18 16:12:34 -05:00
Pieter Wuille 075252c1b7 Rename ecmult_static_pre_g -> precomputed_ecmult 2021-12-17 11:29:17 -05:00
Tim Ruffing 49f608de47 Merge bitcoin-core/secp256k1#1004: ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS
60bf8890df ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS (Jonas Nick)

Pull request description:

  This bug was introduced in 7506e064d7 by adding
  an allocation but not updating the constant.

ACKs for top commit:
  robot-dreams:
    ACK 60bf8890df
  real-or-random:
    ACK 60bf8890df

Tree-SHA512: d7782fe9bf09fea8cf22304ab13679223a48f4d8b09081e662ea162a68c4e35f6b5820fbe4c6030fabad02a48dfdd02eb9eef22262c1dbbf02955bb92b75aef8
2021-12-02 21:26:49 +01:00
Jonas Nick 60bf8890df ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS
This bug was introduced in 7506e064d7 by adding
an allocation but not updating the constant.
2021-11-30 19:25:40 +00:00
Dimitris Apostolou 233297579d Fix typos 2021-11-13 02:12:47 +02:00
Russell O'Connor 6815761cf5 Remove ecmult_context.
These tables stored in this context are now statically available from the generated ecmult_static_pre_g.h file.
2021-08-20 11:11:26 -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
Dimitris Apostolou 07aa4c70ff Fix insecure links 2020-12-18 00:24:22 +02:00
Jonas Nick d0a83f7328 Merge #839: Prevent arithmetic on NULL pointer if the scratch space is too small
29a299e373 Run the undefined behaviour sanitizer on Travis (Fabien)
7506e064d7 Prevent arithmetic on NULL pointer if the scratch space is too small (Fabien)

Pull request description:

ACKs for top commit:
  sipa:
    ACK 29a299e373. Reviewed the code changes and verified that building with these sanitizer flags catches the existing error, as well as a signed integer overflow if introduced.
  real-or-random:
    ACK 29a299e373 code inspection
  jonasnick:
    utACK 29a299e373

Tree-SHA512: 4d788f12f3d7b48018e884910adb9b530a05d88f504de83dadeab8a22d75da83c05a1518f7317de5f536c4dd243ea7b347b1eaddb2ca1d804c663e41b85db69d
2020-11-04 14:53:04 +00:00
Fabien 7506e064d7 Prevent arithmetic on NULL pointer if the scratch space is too small
If the scratch space is too small when calling
`secp256k1_ecmult_strauss_batch()`, the `state.pre_a` allocation will
fail and the pointer will be `NULL`. This causes `state.pre_a_lam` to be
computed from the `NULL` pointer.

It is also possible that the first allocation to fail is for `state.ps`,
which will cause the failure to occur when in
`secp256k1_ecmult_strauss_wnaf()`.

The issue has been detected by UBSAN using Clang 10:
```
CC=clang \
CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \
LDFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" \
../configure

UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 make check
```
2020-10-27 08:41:14 +01:00
Tim Ruffing 8893f42438 Avoids a potentially shortening size_t to int cast in strauss_wnaf_
Fixes #834.
2020-10-27 02:17:23 +01:00
Pieter Wuille 2edc514c90 WNAF of lambda_split output has max size 129 2020-10-13 11:31:13 -07:00
Pieter Wuille 4232e5b7da Rip out non-endomorphism code 2020-10-13 11:31:13 -07:00
Jonas Nick b76142ff25 Remove note about heap allocation in secp256k1_ecmult_odd_multiples_table_storage_var which was removed in 47045270fa 2019-10-28 12:21:36 +00:00
Elichai Turkel 94ae7cbf83 Moved a dereference so the null check will be before the dereferencing 2019-07-03 09:41:41 -04:00
Andrew Poelstra 98836b11f0 scratch: replace frames with "checkpoint" system 2019-05-26 01:05:09 +00:00
Andrew Poelstra c2b028a281 scratch space: thread error_callback into all scratch space functions
Use it when checking magic bytes
2019-05-25 22:59:50 +00:00
Gregory Maxwell 40839e21b9 Merge #592: Use trivial algorithm in ecmult_multi if scratch space is small
9ab96f7 Use trivial algorithm in ecmult_multi if scratch space is small (Jonas Nick)

Pull request description:

  `ecmult_multi` already selects the trivial algorithm if the scratch space is NULL. With this PR the trivial algorithm is also selected if the scratch space is too small to use pippenger or strauss instead of returning 0. That makes it more easier to avoid consensus relevant inconsistencies just because scratch space construction was messed up.

ACKs for commit 9ab96f:
  real-or-random:
    utACK 9ab96f7

Tree-SHA512: aa451adf8880af15cf167a59cb07fc411edc43f26c8eb0873bdae2774382ba182e2a1c54487912f8f2999cb0402d554b9d293e2fb9483234471348a1f43c6653
2019-05-25 22:41:35 +00:00
Tim Ruffing c4fd5dab45 Switch to a single malloc call 2019-05-25 14:01:09 +02:00
Tim Ruffing ef020de16f Add size constants for preallocated memory 2019-05-25 13:58:09 +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
Pieter Wuille e6d01e9347 Use size_t shifts when computing a size_t 2019-03-30 16:09:17 -07:00