1096 Commits

Author SHA1 Message Date
Tim Ruffing
f6bef03c0a
Merge bitcoin-core/secp256k1#1283: Get rid of secp256k1_fe_const_b
69e1ec033120497b83dd95d92166fa05c54b8a06 Get rid of secp256k1_fe_const_b (Pieter Wuille)

Pull request description:

  Replaces #1282.

  Its only remaining use is in a test introduced in #1118, and it is easily replaced by the new `secp256k1_fe_add_int` from #1217.

ACKs for top commit:
  real-or-random:
    utACK 69e1ec033120497b83dd95d92166fa05c54b8a06

Tree-SHA512: 6ada192e0643fc5326198b60f019a5081444f9ba0a5b8ba6236f2a526829d8e5e479556600a604d9bc96c7ba86e3aab813f93c66679287d2135e95a2b75f5d3e
2023-04-21 13:07:59 +02:00
Tim Ruffing
68b16a1662 bench: Make sys/time.h a system include 2023-04-21 11:18:36 +02:00
Pieter Wuille
69e1ec0331 Get rid of secp256k1_fe_const_b 2023-04-20 16:07:56 -04:00
Tim Ruffing
a6f4bcf6e1
Merge bitcoin-core/secp256k1#1231: Move SECP256K1_INLINE macro definition out from include/secp256k1.h
8e142ca4102ade1b90dcb06d6c78405ef3220599 Move `SECP256K1_INLINE` macro definition out from `include/secp256k1.h` (Hennadii Stepanov)
77445898a5852ecd38ab95cfb329333a82673115 Remove `SECP256K1_INLINE` usage from examples (Hennadii Stepanov)

Pull request description:

  From [IRC](https://gnusha.org/secp256k1/2023-01-31.log):
  > 06:29 \< hebasto\> What are reasons to define the `SECP256K1_INLINE` macro in user's `include/secp256k1.h` header, while it is used internally only?
  > 06:32 \< hebasto\> I mean, any other (or a new dedicated) header in `src` looks more appropriate, no?
  > 06:35 \< sipa\> I think it may just predate any "utility" internal headers.
  > 06:42 \< sipa\> I think it makes sense to move it to util.h

  Pros:
  - it is a step in direction to better organized headers (in context of #924, #1039)

  Cons:
  - code duplication for `SECP256K1_GNUC_PREREQ` macro

ACKs for top commit:
  sipa:
    utACK 8e142ca4102ade1b90dcb06d6c78405ef3220599
  real-or-random:
    utACK 8e142ca410

Tree-SHA512: 180e0ba7c2ef242b765f20698b67d06c492b7b70866c21db27c18d8b2e85c3e11f86c6cb99ffa88bbd23891ce3ee8a24bc528f2c91167ec2fddc167463f78eac
2023-04-20 18:18:11 +02:00
Hennadii Stepanov
8a8b6536ef
cmake: Use SameMinorVersion compatibility mode
Available in CMake 3.11+.
2023-04-20 17:00:03 +01:00
Anna “CyberTailor”
47ac3d63cd
cmake: Make installation optional
Useful for embedding secp256k1 in a subproject.
2023-04-20 19:20:33 +05:00
Tim Ruffing
04bf3f6778
Merge bitcoin-core/secp256k1#1230: Build: allow static or shared but not both
ef49a11d29601e09e94134975c968e92c0214102 build: allow static or shared but not both (Cory Fields)
36b0adf1b90139a41fdcb94390d0bb06e9224795 build: remove warning until it's reproducible (Cory Fields)

Pull request description:

  Continuing from here: https://github.com/bitcoin-core/secp256k1/issues/1224#issuecomment-1460438227

  Unfortunately it wasn't really possible to keep a clean diff here because of the nature of the change. I suggest reviewing the lib creation stuff in its entirety, sorry about that :\

  Rather than allowing for shared and static libs to be built at the same time like autotools, this PR switches to the CMake convention of allowing only 1.

  A new `BUILD_SHARED_LIBS` option is added to match CMake convention, as well as a `SECP256K1_DISABLE_SHARED` option which overrides it. That way even projects which have `BUILD_SHARED_LIBS=1` can opt-into a static libsecp in particular.

  Details:

  Two object libraries are created: `secp256k1_asm` and `secp256k1_precomputed_objs`. Some tests/benchmarks use the object libraries directly, some link against the real lib: `secp256k1`.

  Because the objs don't know what they're going to be linked into, they need to be told how to deal with PIC.

  The `DEFINE_SYMBOL` property sets the `DLL_EXPORT` define as necessary (when building a shared lib)

ACKs for top commit:
  hebasto:
    re-ACK ef49a11d29601e09e94134975c968e92c0214102, only [suggested](https://github.com/bitcoin-core/secp256k1/pull/1230#pullrequestreview-1388191165) changes since my recent [review](https://github.com/bitcoin-core/secp256k1/pull/1230#pullrequestreview-1352125381).
  real-or-random:
    ACK ef49a11d29601e09e94134975c968e92c0214102

Tree-SHA512: 8870de305176fdb677caff0fdfc6f8c59c0e906489cb72bc9980e551002812685e59e20d731f2a82e33628bdfbb7261eafd6f228038cad3ec83bd74335959600
2023-04-18 12:54:03 +02:00
Tim Ruffing
9ce9984f32
Merge bitcoin-core/secp256k1#1265: Remove bits argument from secp256k1_wnaf_const{_xonly}
a575339c0282ba49a4f46c9c660a4cc3b6bfc703 Remove bits argument from secp256k1_wnaf_const (always 256) (Pieter Wuille)

Pull request description:

  There is little reason for having the number of bits in the scalar as a parameter, as I don't think there are any (current) use cases for non-256-bit scalars.

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

Tree-SHA512: 994b1f19b4c513f6d070ed259a5d6f221a0c2450271ec824c5eba1cd0ecace276de391c170285bfeae96aaf8f1e0f7fe6260966ded0336c75c522ab6c56d182c
2023-04-18 12:25:09 +02:00
Cory Fields
ef49a11d29 build: allow static or shared but not both 2023-04-17 16:25:27 +00:00
Pieter Wuille
7b7503dac5
Merge bitcoin-core/secp256k1#1245: tests: Add Wycheproof ECDSA vectors
e5de45460953c8ae16521b1928ac14de218998a3 tests: Add Wycheproof ECDSA vectors (RandomLattice)

Pull request description:

  This PR adds a test using the Wycheproof vectors as outlined in #1106. We add all 463 ECDSA test vectors. These vectors cover:
  - edge cases in arithmetic operations
  - signatures with special values for (r,s) that should be rejected
  - special cases of public keys

  The vectors are pulled from the Wycheproof project using a python script to emit C code.

  All the new ECDSA Wycheproof vectors pass.

ACKs for top commit:
  sipa:
    ACK e5de45460953c8ae16521b1928ac14de218998a3
  real-or-random:
    ACK e5de45460953c8ae16521b1928ac14de218998a3

Tree-SHA512: e9684f14ff3f5225a4a4949b490e07527d559c28aa61ed03c03bc52ea64785f0b80b9e1b1628665eacf24006526271ea0fb108629c9c3c1d758e52d214a056f1
2023-04-10 09:29:02 -04:00
Pieter Wuille
a575339c02 Remove bits argument from secp256k1_wnaf_const (always 256) 2023-04-10 06:40:21 -04:00
RandomLattice
e5de454609 tests: Add Wycheproof ECDSA vectors
Adds a test using the Wycheproof vectors as outlined in #1106. The
vectors are taken from the Wycheproof repo. We use a python script
to convert the JSON-formatted vectors into C code.

Co-authored-by: Sean Andersen <6730974+andozw@users.noreply.github.com>
2023-04-09 06:17:16 +02:00
Pieter Wuille
0f8642079b Add exhaustive tests for ecmult_const_xonly 2023-04-08 15:25:41 -04:00
Pieter Wuille
4485926ace Add x-only ecmult_const version for x=n/d 2023-04-08 15:24:36 -04:00
Tim Ruffing
2d51a454fc
Merge bitcoin-core/secp256k1#1257: ct: Use volatile "trick" in all fe/scalar cmov implementations
4a496a36fb07d6cc8c99e591994f4ce0c3b1174c ct: Use volatile "trick" in all fe/scalar cmov implementations (Tim Ruffing)

Pull request description:

  Apparently clang 15 is able to compile our cmov code into a branch, at least for fe_cmov and fe_storage_cmov. This commit makes the condition volatile in all cmov implementations (except ge but that one only calls into the fe impls).

  This is just a quick fix. We should still look into other methods, e.g., asm and #457. We should also consider not caring about constant-time in scalar_low_impl.h

  We should also consider testing on very new compilers in nightly CI, see https://github.com/bitcoin-core/secp256k1/pull/864#issuecomment-769211867

ACKs for top commit:
  jonasnick:
    ACK 4a496a36fb07d6cc8c99e591994f4ce0c3b1174c

Tree-SHA512: a6010f9d752e45f01f88b804a9b27e77caf5ddf133ddcbc4235b94698bda41c9276bf588c93710e538250d1a96844bcec198ec5459e675f166ceaaa42da921d5
2023-04-06 03:59:30 +02:00
Tim Ruffing
4a496a36fb ct: Use volatile "trick" in all fe/scalar cmov implementations
Apparently clang 15 is able to compile our cmov code into a branch,
at least for fe_cmov and fe_storage_cmov. This commit makes the
condition volatile in all cmov implementations (except ge but that
one only calls into the fe impls).

This is just a quick fix. We should still look into other methods,
e.g., asm and #457. We should also consider not caring about
constant-time in scalar_low_impl.h

We should also consider testing on very new compilers in nightly CI,
see https://github.com/bitcoin-core/secp256k1/pull/864#issuecomment-769211867
2023-04-01 15:58:24 +09: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
3e43041be6
No need to subtract 1 before doing a right shift 2023-03-27 09:29:41 -04:00
Tim Ruffing
464a9115b4
Merge bitcoin-core/secp256k1#1242: Set ARM ASM symbol visibility to hidden
fd2a408647ba0f999b7b217977cc68773fa35257 Set ARM ASM symbol visibility to `hidden` (Hennadii Stepanov)

Pull request description:

  Solves one item in #1181.

  To test on arm-32bit hardware, run:
  ```
  $ ./autogen.sh && ./configure --enable-experimental --with-asm=arm && make
  ```

  On master branch (427bc3cdcfbc74778070494daab1ae5108c71368):
  ```
  $ nm -D .libs/libsecp256k1.so | grep secp256k1_fe
  0000e2bc T secp256k1_fe_mul_inner
  0000e8dc T secp256k1_fe_sqr_inner
  ```

  With this PR:
  ```
  $ nm -D .libs/libsecp256k1.so | grep secp256k1_fe | wc -l
  0
  ```

  For reference, see https://sourceware.org/binutils/docs/as/Hidden.html.

ACKs for top commit:
  theuni:
    ACK fd2a408647ba0f999b7b217977cc68773fa35257.
  sipa:
    ACK fd2a408647ba0f999b7b217977cc68773fa35257

Tree-SHA512: abf8ad332631672c036844f69c5599917c49e12c4402bf9066f93a692d3007b1914bd3eea8f83f0141c1b09d5c88ebc5e6c8bfbb5444b7b3471749f7b901ca59
2023-03-26 12:26:01 +09:00
Pieter Wuille
f16a709fd6
Merge bitcoin-core/secp256k1#1247: Apply Checks only in VERIFY mode.
4ebd82852d3ad00ab579b26173575a4f4642ea76 Apply Checks only in VERIFY mode. (roconnor-blockstream)

Pull request description:

  This is already done in `field_5x52_impl.h`.

ACKs for top commit:
  sipa:
    ACK 4ebd82852d3ad00ab579b26173575a4f4642ea76
  jonasnick:
    ACK 4ebd82852d3ad00ab579b26173575a4f4642ea76

Tree-SHA512: c24211e5219907e41e2c5792255734bd50ca5866a4863abbb3ec174ed92d1792dd10563a94c08e8fecd6cdf776a9c49ca87e8f9806a023d9081ecc0d55ae3e66
2023-03-24 09:35:04 -04:00
roconnor-blockstream
4ebd82852d
Apply Checks only in VERIFY mode. 2023-03-22 22:06:47 -04:00
roconnor-blockstream
d1e7ca192d
Typo 2023-03-22 22:01:01 -04:00
Cory Fields
36b0adf1b9 build: remove warning until it's reproducible
Also remove the interface it was attached to since it's no longer needed.
This removal simplifies the next commit.
2023-03-21 16:21:21 +00:00
Hennadii Stepanov
5bb03c2911
Replace SECP256K1_ECMULT_TABLE_VERIFY macro by a function 2023-03-21 15:29:22 +00:00
Hennadii Stepanov
fd2a408647
Set ARM ASM symbol visibility to hidden
Co-authored-by: Cory Fields <cory-nospam-@coryfields.com>
2023-03-15 09:08:41 +00:00
Hennadii Stepanov
4429a8c218
Suppress -Wunused-parameter when building for coverage analysis 2023-03-14 20:03:42 +00:00
roconnor-blockstream
647f0a5cb1
Update comment for secp256k1_modinv32_inv256 2023-03-10 08:53:33 -05:00
Hennadii Stepanov
8e142ca410
Move SECP256K1_INLINE macro definition out from include/secp256k1.h 2023-03-09 15:29:56 +00:00
Hennadii Stepanov
8be82d4362
cmake: Rename project to "libsecp256k1" 2023-03-08 21:22:24 +00:00
Pieter Wuille
df323b5c14
Merge bitcoin-core/secp256k1#1113: build: Add CMake-based build system
e1eb33724c2ca47855a8c1dada421cabdb717fe7 ci: Add "x86_64: Windows (VS 2022)" task (Hennadii Stepanov)
10602b0030e67c830596e08ffc775039ee0b2607 cmake: Export config files (Hennadii Stepanov)
5468d709644823b6302141ff93d0b946b70def4a build: Add CMake-based build system (Hennadii Stepanov)

Pull request description:

  This PR adds a [CMake](https://cmake.org/)-based build system.

  Added build instructions and examples to the [`README.md`](https://github.com/hebasto/secp256k1/blob/220628-cmake/README.md#building-with-cmake-experimental) file.

  Ways to integrate with downstream CMake-based projects:
  - if `secp256k1` is a subtree (including Bitcoin Core project) -- `add_subdirectory(secp256k1)`
  - if `secp256k1` has been installed -- `find_package(secp256k1 0.2.1 CONFIG)`, see https://github.com/hebasto/secp256k1-CMake-example

  Added a few toolchain files for easy cross compiling.

  Discussions on IRC:
  - https://gnusha.org/secp256k1/2022-06-23.log
  - https://gnusha.org/secp256k1/2022-06-24.log
  - https://gnusha.org/secp256k1/2022-06-27.log
  - https://gnusha.org/secp256k1/2023-01-30.log

  ---

  Related PRs:
  - #315
  - #549
  - #761

  ---

  **Implementation notes**

  Minimum required CMake version is 3.1. This was required to provide [`C_STANDARD`](https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html) property.

  In turn, this choice of CMake version implies it is not possible to build with default CMake on Debian 8, which has CMake v3.0.2 only.

  Also see:
  - [CMake Versions on Linux Distros](https://gitlab.kitware.com/cmake/community/-/wikis/CMake-Versions-on-Linux-Distros)
  - https://repology.org/project/cmake/versions

  ---

  # Autotools -- CMake Feature Parity Tables

  ## 1. Configuration options

  Autotool-based build system features being listed according to the `./configure --help` output.

  | Autotools | CMake |
  |---|---|
  | `--prefix` | `-DCMAKE_INSTALL_PREFIX`
  | `--enable-shared` | `-DSECP256K1_BUILD_SHARED` |
  | `--enable-static` | `-DSECP256K1_BUILD_STATIC` |
  | `--enable-dev-mode` _hidden_ | N/A, see https://github.com/bitcoin-core/secp256k1/pull/1113#discussion_r916979117 |
  | `--enable-benchmark` | `-DSECP256K1_BUILD_BENCHMARK` |
  | `--enable-coverage` | `-DCMAKE_BUILD_TYPE=Coverage` |
  | `--enable-tests` | `-DSECP256K1_BUILD_TESTS` |
  | `--enable-ctime-tests` | `-DSECP256K1_BUILD_CTIME_TESTS` |
  | `--enable-experimental` | `-DSECP256K1_EXPERIMENTAL` |
  | `--enable-exhaustive-tests` | `-DSECP256K1_BUILD_EXHAUSTIVE_TESTS` |
  | `--enable-examples` | `-DSECP256K1_BUILD_EXAMPLES` |
  | `--enable-module-ecdh` | `-DSECP256K1_ENABLE_MODULE_ECDH` |
  | `--enable-module-recovery` | `-DSECP256K1_ENABLE_MODULE_RECOVERY` |
  | `--enable-module-extrakeys` | `-DSECP256K1_ENABLE_MODULE_EXTRAKEYS` |
  | `--enable-module-schnorrsig` | `-DSECP256K1_ENABLE_MODULE_SCHNORRSIG` |
  | `--enable-external-default-callbacks` | `-DSECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS` |
  | `--with-test-override-wide-multiply` _hidden_ | `-DSECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY` |
  | `--with-asm` | `-DSECP256K1_ASM` |
  | `--with-ecmult-window` | `-DSECP256K1_ECMULT_WINDOW_SIZE` |
  | `--with-ecmult-gen-precision` | `-DSECP256K1_ECMULT_GEN_PREC_BITS` |
  | `--with-valgrind` | `-DSECP256K1_VALGRING` |

  A screenshot of grouped options from `cmake-gui`:
  ![image](https://user-images.githubusercontent.com/32963518/214821305-fc3ffe82-4d05-4dd7-b2c2-7ca2d5d12e86.png)

  ## 2. `make` targets

  | Autotools | CMake |
  |---|---|
  | `make` | `make` |
  | `make check` | `make check` |
  | `make install` | `make install` * |

  * Installation of `lib/pkgconfig/libsecp256k1.pc` not implemented.

ACKs for top commit:
  theuni:
    ACK e1eb33724c2ca47855a8c1dada421cabdb717fe7.
  sipa:
    ACK e1eb33724c2ca47855a8c1dada421cabdb717fe7
  real-or-random:
    ACK e1eb33724c2ca47855a8c1dada421cabdb717fe7

Tree-SHA512: ebe2772eeb1a430a0a7ae767fb1a9a82d52d5e9bf2306956cd08f7b442c862be2539774dd10d5555817353d37d1c6add78b8fe5a85bb71239304fb42c98ff337
2023-03-08 10:33:09 -05:00
Hennadii Stepanov
10602b0030
cmake: Export config files 2023-03-08 13:33:52 +00:00
Hennadii Stepanov
5468d70964
build: Add CMake-based build system
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-03-08 13:33:16 +00:00
Tim Ruffing
6048e6c03e
Merge bitcoin-core/secp256k1#1222: Remove redundant checks.
5d8f53e31293c582fb3fe02157bc67d2eeccea77 Remove redudent checks. (Russell O'Connor)

Pull request description:

  These abs checks are implied by the subsequent line, and with the subsequent line written as it is, no underflow is possible with signed integers.

  Follows up on https://github.com/bitcoin-core/secp256k1/pull/1218.

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

Tree-SHA512: ddd6758638fe634866fdaf900224372e2e51cb81ef4d024f169fbc39fff38ef1b29e90e0732877e8910158b82bc428ee9c3a4031882c2850b22ad87cc63ee305
2023-03-08 14:18:44 +01:00
Russell O'Connor
5d8f53e312 Remove redudent checks.
These abs checks are implied by the subsequent line, and with the subsequent line written as it is, no underflow is possible with signed integers.
2023-03-07 09:10:36 -05:00
Jonas Nick
9d1b458d5f
Merge bitcoin-core/secp256k1#1217: Add secp256k1_fe_add_int function
b081f7e4cbfd27edc36e823dcd93537a46f7d2a6 Add secp256k1_fe_add_int function (Pieter Wuille)

Pull request description:

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

Tree-SHA512: daf9956c81a328505faee7fb59d29ec0c5a326bce7c48159a8e0ed7590505b430785d750d0c34f152b9119ad130030063be999da0c2035747a27fe501e77560a
2023-03-07 14:08:05 +00:00
Russell O'Connor
2ef1c9b387 Update overflow check
One does not simply check for integer overlow.
2023-03-06 18:13:47 -05:00
Pieter Wuille
b081f7e4cb Add secp256k1_fe_add_int function 2023-03-02 17:09:25 -05:00
Pieter Wuille
6be01036c8 Add secp256k1_fe_is_square_var function
The implementation calls the secp256k1_modinvNN_jacobi_var code, falling back
to computing a square root in the (extremely rare) case it failed converge.
2023-02-28 15:57:32 -05:00
Pieter Wuille
1de2a01c2b Native jacobi symbol algorithm
This introduces variants of the divsteps-based GCD algorithm used for
modular inverses to compute Jacobi symbols. Changes compared to
the normal vartime divsteps:
* Only positive matrices are used, guaranteeing that f and g remain
  positive.
* An additional jac variable is updated to track sign changes during
  matrix computation.
* There is (so far) no proof that this algorithm terminates within
  reasonable amount of time for every input, but experimentally it
  appears to almost always need less than 900 iterations. To account
  for that, only a bounded number of iterations is performed (1500),
  after which failure is returned. In VERIFY mode a lower iteration
  count is used to make sure that callers exercise their fallback.
* The algorithm converges to f=g=gcd(f0,g0) rather than g=0. To keep
  this test simple, the end condition is f=1, which won't be reached
  if started with non-coprime or g=0 inputs. Because of that we only
  support coprime non-zero inputs.
2023-02-28 15:54:00 -05:00
Pieter Wuille
04c6c1b181 Make secp256k1_modinv64_det_check_pow2 support abs val 2023-02-27 15:38:05 -05:00
Pieter Wuille
5fffb2c7af Make secp256k1_i128_check_pow2 support -(2^n) 2023-02-27 15:38:05 -05:00
Pieter Wuille
1b21aa5175
Merge bitcoin-core/secp256k1#1078: group: Save a normalize_to_zero in gej_add_ge
e089eecc1e54551287b12539d2211da631a6ec5c group: Further simply gej_add_ge (Tim Ruffing)
ac71020ebe052901000e5efa7a59aad77ecfc1a0 group: Save a normalize_to_zero in gej_add_ge (Tim Ruffing)

Pull request description:

  As discovered  by sipa in #1033.

  See commit message for reasoning but note that the infinity handling will be replaced in the second commit again.

ACKs for top commit:
  sipa:
    ACK e089eecc1e54551287b12539d2211da631a6ec5c
  apoelstra:
    ACK e089eecc1e54551287b12539d2211da631a6ec5c

Tree-SHA512: fb1b5742e73dd8b2172b4d3e2852490cfd626e8673b72274d281fa34b04e9368a186895fb9cd232429c22b14011df136f4c09bdc7332beef2b3657f7f2798d66
2023-02-14 14:55:46 -05:00
Tim Ruffing
ca92a35d01 field: Simplify code in secp256k1_fe_set_b32 2023-02-01 12:29:34 +01:00
Tim Ruffing
d93f62e369 field: Verify field element even after secp256k1_fe_set_b32 fails 2023-02-01 12:29:03 +01:00
Jonas Nick
eb6bebaee3
scalar: restrict split_lambda args, improve doc and VERIFY_CHECKs
VERIFY_CHECK(r1 != r2) is added because otherwise the verify_scalar_split fails.
2023-01-19 21:14:38 +00:00
Jonas Nick
620ba3d74b
benchmarks: fix bench_scalar_split
scalar_split_lambda requires that the input pointer is different to both output
pointers. Without this fix, the internal benchmarks crash when compiled with
-DVERIFY.

This was introduced in commit 362bb25608dbcd724a07dd5170c4ebe081c3dd84 (which
requires configuring with --enable-endomorphism to exhibit the crash).
2023-01-19 18:12:31 +00:00
Pieter Wuille
5fbff5d348
Merge bitcoin-core/secp256k1#1170: contexts: Forbid destroying, cloning and randomizing the static context
e39d954f118a29db2c33e9a9a507053fff5573ed tests: Add CHECK_ILLEGAL(_VOID) macros and use in static ctx tests (Tim Ruffing)
61841fc9ee5aa1ffde3ccd512660207034125ebd contexts: Forbid randomizing secp256k1_context_static (Tim Ruffing)
4b6df5e33e197a50fd7d9bc4c14b8ba8526013b9 contexts: Forbid cloning/destroying secp256k1_context_static (Tim Ruffing)

Pull request description:

  As discussed in #1126.

  For randomization, this has a history. Initially, this threw the illegal callback but then we changed it to be a no-op on non-signing contexts: 6198375218 But this was with (non-static) none/verification contexts in mind, not with the static context. If we anyway forbid cloning the static context, you should never a way to randomize a copy of the static context. (You need a copy because the static context itself is not writable. But you cannot obtain a copy except when using memcpy etc.)

ACKs for top commit:
  sipa:
    utACK e39d954f118a29db2c33e9a9a507053fff5573ed
  apoelstra:
    ACK e39d954f118a29db2c33e9a9a507053fff5573ed

Tree-SHA512: dc804b15652d536b5d67db7297ac0e65eab3a64cbb35a9856329cb87e7ea0fe8ea733108104b3bba580077fe03d6ad6b161c797cf866a74722bab7849f0bb60c
2023-01-19 13:04:18 -05:00
Pieter Wuille
233822d849
Merge bitcoin-core/secp256k1#1195: ctime_tests: improve output when CHECKMEM_RUNNING is not defined
8f51229e0348a1524fed541f334cd4f1726d2685 ctime_tests: improve output when CHECKMEM_RUNNING is not defined (Jonas Nick)

Pull request description:

  When seeing the output
  ```
  Unless compiled under msan, this test can only usefully be run inside valgrind.
  ```
  I thought that I would have to go back to the `configure` output to manually check if it was compiled under memsan to determine whether this test can be usefully run outside valgrind. But when we go into this branch then it was definitely not compiled under msan, which means that we can make the output clearer.

ACKs for top commit:
  sipa:
    utACK 8f51229e0348a1524fed541f334cd4f1726d2685
  real-or-random:
    utACK 8f51229e03

Tree-SHA512: a4953a158b1375d8fc3a2ee29e7014c5399becf5f75ffd3765c0141861e092fbc120003e00dfd25ec54b92a466e133377b96d5a9f4017c100aaf64fb9a045df1
2023-01-19 11:00:16 -05:00
Tim Ruffing
e39d954f11 tests: Add CHECK_ILLEGAL(_VOID) macros and use in static ctx tests 2023-01-19 13:36:40 +01:00
Tim Ruffing
61841fc9ee contexts: Forbid randomizing secp256k1_context_static 2023-01-18 16:47:31 +01:00