112 Commits

Author SHA1 Message Date
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
d1e48e5474a2be29e17a477874a4963f8f612a5a refactor: Make 64-bit shift explicit (Hennadii Stepanov)
b2e29e43d0e5e65c1e1199f86f59689a1e736109 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 d1e48e5474a2be29e17a477874a4963f8f612a5a
  jonasnick:
    ACK d1e48e5474a2be29e17a477874a4963f8f612a5a

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
5bb03c29116409ace8855e64bf2e2b2d45871469 Replace `SECP256K1_ECMULT_TABLE_VERIFY` macro by a function (Hennadii Stepanov)
4429a8c218d7bf7bc6de1de88bc31c834f771385 Suppress `-Wunused-parameter` when building for coverage analysis (Hennadii Stepanov)

Pull request description:

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

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
60bf8890df5360148df921f26d8dc4d667dd5926 ecmult: fix definition of STRAUSS_SCRATCH_OBJECTS (Jonas Nick)

Pull request description:

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

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

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 7506e064d791e529d2e57bb52c156deb33b897ef 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
29a299e373d5f0e326be74c514c7c70ddf50cce1 Run the undefined behaviour sanitizer on Travis (Fabien)
7506e064d791e529d2e57bb52c156deb33b897ef Prevent arithmetic on NULL pointer if the scratch space is too small (Fabien)

Pull request description:

ACKs for top commit:
  sipa:
    ACK 29a299e373d5f0e326be74c514c7c70ddf50cce1. 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 29a299e373d5f0e326be74c514c7c70ddf50cce1 code inspection
  jonasnick:
    utACK 29a299e373d5f0e326be74c514c7c70ddf50cce1

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 47045270fa90f81205d989f7107769bce1e71c4d 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
Jonas Nick
9ab96f7b12 Use trivial algorithm in ecmult_multi if scratch space is small 2019-03-18 15:15:35 +00:00
Jonas Nick
2277af5ff0 Fix integer overflow in ecmult_multi_var when n is large 2019-02-25 16:13:17 +00:00
Jonas Nick
bade617417 Add trivial ecmult_multi algorithm. It is selected when no scratch space is given and just multiplies and adds the points. 2019-02-23 20:24:28 +00:00
Gregory Maxwell
949e85b009
Merge #550: Optimize secp256k1_fe_normalize_weak calls.
9bd89c8 Optimize secp256k1_fe_normalize_weak calls. Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead. (Russell O'Connor)

Pull request description:

  Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead.

Tree-SHA512: 7bbb1aca8e37a268a26d7061bd1f390db129e697792f1d5ddd10ea34927616edc26ef118b500c3e5e14d1d463196033ef64e4d34b765380325c24835458b7a9b
2019-02-21 04:14:40 +00:00
Andrew Poelstra
b3bf5f99a3 ecmult_impl: expand comment to explain how effective affine interacts with everything 2018-11-10 14:01:13 +00:00
Peter Dettman
efa783f8f0 Store z-ratios in the 'x' coord they'll recover 2018-11-10 13:14:43 +00:00
Andrew Poelstra
84740acd2a ecmult_impl: save one fe_inv_var 2018-11-09 00:20:53 +00:00
Andrew Poelstra
47045270fa ecmult_impl: eliminate scratch memory used when generating context 2018-11-09 00:20:51 +00:00
Russell O'Connor
9bd89c836b Optimize secp256k1_fe_normalize_weak calls.
Move secp256k1_fe_normalize_weak calls out of ECMULT_TABLE_GET_GE and ECMULT_TABLE_GET_GE_STORAGE and into secp256k1_ge_globalz_set_table_gej instead.
2018-08-12 23:47:38 -04:00