1444 Commits

Author SHA1 Message Date
Pieter Wuille
19a2bfeeea Abstract out verify logic for fe_set_int 2023-05-11 06:18:40 -04:00
Pieter Wuille
864f9db491 Abstract out verify logic for fe_normalizes_to_zero{,_var} 2023-05-11 06:18:40 -04:00
Pieter Wuille
6c31371120 Abstract out verify logic for fe_normalize_var 2023-05-11 06:18:40 -04:00
Pieter Wuille
e28b51f522 Abstract out verify logic for fe_normalize_weak 2023-05-11 06:18:40 -04:00
Pieter Wuille
b6b6f9cb97 Abstract out verify logic for fe_normalize 2023-05-11 06:18:40 -04:00
Pieter Wuille
7fa5195559 Bugfix: correct SECP256K1_FE_CONST mag/norm fields 2023-05-11 06:18:37 -04:00
Hennadii Stepanov
e5cf4bf3ff
build: Rename arm to arm32 2023-05-11 10:03:23 +01:00
Pieter Wuille
b29566c51b Merge magnitude/normalized fields, move/improve comments
Also split secp256k1_fe_verify into a generic and an implementation
specific part.
2023-05-11 04:25:19 -04:00
Pieter Wuille
97c63b9039 Avoid normalize conditional on VERIFY 2023-05-11 03:41:48 -04:00
Pieter Wuille
6ec3731e8c Simplify test PRNG implementation 2023-05-10 10:40:08 -04:00
Pieter Wuille
bbc834467c Avoid secp256k1_ge_set_gej_zinv with uninitialized z 2023-05-10 09:25:09 -04:00
Pieter Wuille
0a2e0b2ae4 Make secp256k1_{fe,ge,gej}_verify work as no-op if non-VERIFY 2023-05-10 09:25:09 -04:00
Pieter Wuille
f20266722a Add invariant checking to group elements 2023-05-10 09:25:09 -04:00
Pieter Wuille
a18821d5b1 Always initialize output coordinates in secp256k1_ge_set_gej 2023-05-10 09:25:06 -04:00
Pieter Wuille
3086cb90ac Expose secp256k1_fe_verify to other modules 2023-05-10 09:06:02 -04:00
Gregory Maxwell
a0e696fd4d Make secp256k1_ecmult_const handle infinity
Infinity isn't currently needed here, but correctly handling it is a
little more safe against future changes.

Update docs for it to make it clear that it is not constant time in A
(the input point). It never was constant time in Q (and would be a little
complicated to make constant time in A).

If it was later made constant time in A, infinity support would be easy
to preserve, e.g. by running it on a dummy value and cmoving infinity into
the output.
2023-05-10 09:06:02 -04:00
Pieter Wuille
2e65f1fdbc Avoid using bench_verify_data as bench_sign_data; merge them 2023-05-09 14:00:43 -04:00
Tim Ruffing
fb5bfa4eed Add static test vector for Xoshiro256++ 2023-05-09 18:11:29 +02:00
Jonas Nick
4eab2c2fd8
Merge elementsproject/secp256k1-zkp#230: norm arg: add prove test vectors
f3126fdfec7c4dbfab3acf01714325b027110aff norm arg: remove prove edge tests which are now covered by vectors (Jonas Nick)
847ed9ecb2233f1e233fae1791b5adcdeb3be52b norm arg: add verification to prove vectors (Jonas Nick)
cf797ed2a4ccc7422de2f4081a6d6bcf536d72c8 norm arg: add prove test vectors (Jonas Nick)
095c1e749c106285e8252d6490073974dd4d8fcc norm arg: add prove_const to tests (Jonas Nick)
bf7bf8a64fa7a7256ad64f75ae0bcb9fccbd0ea4 norm arg: split norm_arg_zero into prove_edge and verify_zero_len (Jonas Nick)
a70c4d4a8a6970f8e299de541cc75f2fc2e39e76 norm arg: add test vector for |n| = 0 (Jonas Nick)
f5e4b16f0f96ae871d221900673f426e9c9ce85e norm arg: add test vector for sign bit malleability (Jonas Nick)
c0de361fc53dbfb0b058895f4824eba4d423e191 norm arg: allow X and R to be the point at infinity (Jonas Nick)
f22834f20252f9ca3e17f36093940e2aa2735790 norm arg: add verify vector for n = [0], l = [0] (Jonas Nick)
d8e7f3763bac9e52d07643a01c8352cadded64d2 musig: move ge_{serialize,parse}_ext to module-independent file (Jonas Nick)

Pull request description:

ACKs for top commit:
  Liam-Eagen:
    ACK f3126fd

Tree-SHA512: 1aad86521fce74435beabe7690c7fcc38ad9ae7a884ddcab69ef825b573433f700723a7672d29df1b4465bc33d5957b6a46f657f988cfd2cc73fa94a3472357d
2023-05-09 10:42:07 +00:00
Pieter Wuille
723e8ca8f7 Remove randomness tests
Our RNG has been replaced with Xoshiro256++, a well-analyzed RNG. Our
unit tests should not be resposible for verifying its statistical
qualities.
2023-05-08 12:17:33 -04:00
Tim Ruffing
f30c74866b
Merge bitcoin-core/secp256k1#1270: cmake: Fix library ABI versioning
bef448f9af248dba016883401de07b431f3e686e cmake: Fix library ABI versioning (Hennadii Stepanov)

Pull request description:

  This change emulates Libtool to make sure Libtool and CMake agree on the ABI version.

  To test, one needs to simulate a release with backward-compatible API changes, which means the following changes in `configure.ac` and `CMakeLists.txt`:
  - incrementing of `*_LIB_VERSION_CURRENT`
  - setting `*_LIB_VERSION_REVISION` to zero
  - incrementing of `*_LIB_VERSION_AGE`

ACKs for top commit:
  real-or-random:
    ACK bef448f9af248dba016883401de07b431f3e686e  diff looks good and I tested on Linux

Tree-SHA512: f7551fc7377ea50c8bc32d14108a034a1f91ebbb63d5fec562e5cc28416637834b9a4dcba3692df1780adcd1212ad4f238dc0219ab5add68bd88a5a458572ee5
2023-05-03 15:58:55 +02: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
Hennadii Stepanov
755629bc03
cmake: Use full signature of add_test() command
An executable target in the `COMMAND` option will automatically be
replaced by the location of the executable created at build time.

This change fixes tests for Windows binaries using Wine.
2023-04-29 09:49:25 +01:00
Hennadii Stepanov
bef448f9af
cmake: Fix library ABI versioning
This change emulates Libtool to make sure Libtool and CMake agree on the
ABI version.
2023-04-28 20:59:53 +01:00
Tim Ruffing
222ecaf661
Merge bitcoin-core/secp256k1#1284: cmake: Some improvements using PROJECT_IS_TOP_LEVEL variable
71f746c057a66d5ae0dfdb5d439bc49592c0d16e cmake: Include `include` directory for subtree builds (Hennadii Stepanov)
5431b9decdbbdf30c5c5f2aed4b59662f5c681a2 cmake: Make `SECP256K1_INSTALL` default depend on `PROJECT_IS_TOP_LEVEL` (Hennadii Stepanov)
162608cc982538906e775d0c549aff2de5dee413 cmake: Emulate `PROJECT_IS_TOP_LEVEL` for CMake<3.21 (Hennadii Stepanov)

Pull request description:

  This PR:
  1. Emulates [`PROJECT_IS_TOP_LEVEL`](https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html) variable for CMake versions where it is not available.
  2. Makes the `SECP256K1_INSTALL` option dependent on `PROJECT_IS_TOP_LEVEL` (a [follow up](https://github.com/bitcoin-core/secp256k1/pull/1263#issuecomment-1516564300) of https://github.com/bitcoin-core/secp256k1/pull/1263).
  3. Makes integration of this project as a subtree easier. A top project can `#include <secp256k1.h>` with no additional `target_include_directories()` commands. For example, see https://github.com/hebasto/secp256k1-CMake-example/tree/subtree.

ACKs for top commit:
  theuni:
    utACK 71f746c057a66d5ae0dfdb5d439bc49592c0d16e.

Tree-SHA512: 8ccdbcc94b26f36e772611ebaab0f2846debd6ad20f9e361be31a8d2128a14273acb692b0631026e12cc6cdef6d445dce0fd3beb4f71af47b46dfcf840a18879
2023-04-27 15:17:38 +01:00
Hennadii Stepanov
71f746c057
cmake: Include include directory for subtree builds 2023-04-27 15:13:10 +01:00
Tim Ruffing
4b84f4bf0f
Merge bitcoin-core/secp256k1#1239: cmake: Bugfix and other improvements after bumping CMake up to 3.13
a273d74b2ea1ef115a7e40fe89a64a6c744018c6 cmake: Improve version comparison (Hennadii Stepanov)
6a58b483efb96de32134611963c16f6bf7e94d51 cmake: Use `if(... IN_LIST ...)` command (Hennadii Stepanov)
2445808c0203215e7182355762944ab909d423d2 cmake: Use dedicated `GENERATOR_IS_MULTI_CONFIG` property (Hennadii Stepanov)
9f8703ef17db0144b320714cd56c1fe0317a5786 cmake: Use dedicated `CMAKE_HOST_APPLE` variable (Hennadii Stepanov)
8c2017035a9c0722aeb7f24162d57d795443fd4c cmake: Use recommended `add_compile_definitions` command (Hennadii Stepanov)
04d4cc071a7aa92ad5edcf970a6cc2a8f415d36c cmake: Add `DESCRIPTION` and `HOMEPAGE_URL` options to `project` command (Hennadii Stepanov)
8a8b6536ef52fbbd9690f859d2f02d7f4b3789f6 cmake: Use `SameMinorVersion` compatibility mode (Hennadii Stepanov)

Pull request description:

  This PR:
  - resolves two items from #1235, including a bugfix with package version compatibility
  - includes other improvements which have become available for CMake 3.13+.

  To test the `GENERATOR_IS_MULTI_CONFIG` property on Linux, one can use the "[Ninja Multi-Config](https://cmake.org/cmake/help/latest/generator/Ninja%20Multi-Config.html)" generator:
  ```sh
  cmake -S . -B build -G "Ninja Multi-Config"
  ```

ACKs for top commit:
  real-or-random:
    ACK a273d74b2ea1ef115a7e40fe89a64a6c744018c6
  theuni:
    ACK a273d74b2ea1ef115a7e40fe89a64a6c744018c6

Tree-SHA512: f31c4f0f30bf368303e70ab8952cde5cc8c70a5e79a04f879abcbee3d0a8d8c598379fb38f5142cb1f8ff5f9dcfc8b8eb4c13c975a1d05fdcc92d9c805a59d9a
2023-04-27 11:23:55 +01:00
Jonas Nick
c4062d6b5d
debug: move helper for printing buffers into util.h 2023-04-25 16:07:10 +00:00
Jonas Nick
f3126fdfec
norm arg: remove prove edge tests which are now covered by vectors 2023-04-25 15:06:57 +00:00
Jonas Nick
847ed9ecb2
norm arg: add verification to prove vectors 2023-04-25 15:06:40 +00:00
Jonas Nick
cf797ed2a4
norm arg: add prove test vectors 2023-04-25 14:56:42 +00:00
Jonas Nick
095c1e749c
norm arg: add prove_const to tests 2023-04-25 14:54:30 +00:00
Jonas Nick
ce18267b66
Merge elementsproject/secp256k1-zkp#229: musig: Fix nits left open in #211
a0b51afc01dfc8dbdc43e4c36825fadf760daa3c musig: VERIFY_CHECK preconditions of _musig_keyaggcoef_internal() (Tim Ruffing)
da7702844e212f0cc165d1560a4dc09a05811dae extrakeys: Clarify comparison order of compare/sort functions (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK a0b51afc01dfc8dbdc43e4c36825fadf760daa3c

Tree-SHA512: ad509d7a55c6f832a25b896b0fe38e259b79864b2a8d1fb337b9d9b4a5e1950a9d579040285465c89d815becc6e49af4129ab2d904d32ac98cef74357a440c89
2023-04-23 08:06:33 +00:00
Jonas Nick
3858bad2c6
tests: remove extra semicolon in macro 2023-04-21 20:21:28 +00:00
Jonas Nick
1f33bb2b1c
Merge bitcoin-core/secp256k1#1205: field: Improve docs +tests of secp256k1_fe_set_b32
162da73e9a48875aab1ee6ca1c14f86ca4646946 tests: Add debug helper for printing buffers (Tim Ruffing)
e9fd3dff76e30fcd83d060ad9195cadae9cdc9a2 field: Improve docs and tests of secp256k1_fe_set_b32 (Tim Ruffing)
ca92a35d019730aec9d3ec8097dcbb9633a69874 field: Simplify code in secp256k1_fe_set_b32 (Tim Ruffing)
d93f62e3693d6763891edcad11472f9d475177e5 field: Verify field element even after secp256k1_fe_set_b32 fails (Tim Ruffing)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 162da73e9a48875aab1ee6ca1c14f86ca4646946

Tree-SHA512: b3ed8e45c969d0420275ff154462f3820b72b57832ccba1f6f427e0cfd9cff3e27440c20994f69ea33a576b1903eb7f04a989f0dbd574bbd96ee56c6dd4500f7
2023-04-21 16:23:59 +00:00
Tim Ruffing
162da73e9a tests: Add debug helper for printing buffers 2023-04-21 17:20:37 +02:00
Tim Ruffing
e9fd3dff76 field: Improve docs and tests of secp256k1_fe_set_b32 2023-04-21 17:20:37 +02:00
Tim Ruffing
a0b51afc01 musig: VERIFY_CHECK preconditions of _musig_keyaggcoef_internal() 2023-04-21 16:18:19 +02:00
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
e444d24bca Fix include guards: No _ prefix/suffix but _H suffix (as in upstream) 2023-04-21 12:02:28 +02:00
Tim Ruffing
0eea7d97ab Use relative #include paths in tests (as in upstream) 2023-04-21 11:51:04 +02:00
Tim Ruffing
c690d6df70 Use relative #include paths in benchmarks (as in upstream) 2023-04-21 11:50:46 +02:00
Tim Ruffing
c565827c1a Use relative #include paths in ctime_test (as in upstream) 2023-04-21 11:50:34 +02:00
Tim Ruffing
4eca406f4c Use relative #include paths in library (as in upstream) 2023-04-21 11:50:24 +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
Jonas Nick
bf7bf8a64f
norm arg: split norm_arg_zero into prove_edge and verify_zero_len
One function tests prover edge cases, the other tests verifier edge cases.
2023-04-20 19:05:22 +00:00
Jonas Nick
a70c4d4a8a
norm arg: add test vector for |n| = 0 2023-04-20 19:03:27 +00:00
Jonas Nick
f5e4b16f0f
norm arg: add test vector for sign bit malleability
R is point at infinity but sign is != 0
2023-04-20 19:02:51 +00:00
Jonas Nick
c0de361fc5
norm arg: allow X and R to be the point at infinity
Add test vector
2023-04-20 19:02:41 +00:00