1444 Commits

Author SHA1 Message Date
Sanket Kanjalkar
e2eb3fae40 Make *key_cache const in musig_pubkey_get 2024-01-07 07:44:11 -08:00
roconnor-blockstream
c33d2241cb Typo in shallue_van_de_woestijne description 2023-11-17 14:58:35 -05:00
Jon Griffiths
fcc0299fa5
surjectionproof: remove unused include
Following the merge of b627ba7050b608e869515a8ef622d71bf8c13b54 from
upstream, this include should have been deleted as well.
2023-10-31 16:53:26 +13:00
Jonas Nick
b41caaafd2
bppp: replace memcmp in tests with secp256k1_memcmp_var 2023-10-12 13:10:05 +00:00
Jonas Nick
6a3aae8f1d
group_parse: use secp256k1_memcmp_var instead of memcmp 2023-10-12 11:18:21 +00:00
Jonas Nick
775f5e242b
Merge commits '1b13415d 374e2b54 96294c00 8d2960c8 ce765a5b b2f6712d eedd7810 b327abfc 5d8fa825 3d05c86d bcffeb14 de657c20 060e32cb 0ba2b945 48b1d939 6b9507ad 5373693e 2e6cf9ba 6ee14550 26a98992 4d7fe609 ea26b71c 65c79fe2 727bec5b 0b4640ae 199d27ce cbf3053f 49be5be9 b10ddd2b 4fd00f4b ba9cb6f3 ee7aaf21 ' into temp-merge-1395
- Replace fe_equal_var with fe_equal
- Use CHECK_ILLEGAL instead of CHECK/ecount
- Turn on secp256k1-zkp specific modules in CI
2023-09-20 09:38:36 +00:00
Tim Ruffing
ee7aaf213e
Merge bitcoin-core/secp256k1#1395: tests: simplify random_fe_non_zero (remove loop limit and unneeded normalize)
c45b7c4fbbf41b011f138c465a58322a36664fd3 refactor: introduce testutil.h (deduplicate `random_fe_`, `ge_equals_` helpers) (Sebastian Falbesoner)
dc5514144fb9d412aa3845432b053ee06a27da37 tests: simplify `random_fe_non_zero` (remove loop limit and unneeded normalize) (Sebastian Falbesoner)

Pull request description:

  `random_fe_non_zero` contains a loop iteration limit that ensures that we abort if `random_fe` ever yielded zero more than ten times in a row. This construct was first introduced in PR #19 (commit 09ca4f32) for random non-square field elements and was later refactored into the non-zero helper in PR #25 (commit 6d6102fe). The copy-over to the exhaustive tests happened recently in PR #1118 (commit 0f864207).

  This case seems to be practically irrelevant and I'd argue for keeping things simple and removing it (which was already suggested in https://github.com/bitcoin-core/secp256k1/pull/1118#discussion_r1067259954); if there's really a worry that the test's random generator is heavily biased towards certain values or value ranges then there should consequently be checks at other places too (e.g. directly in `random_fe` for 256-bit values that repeatedly overflow, i.e. >= p).

  Also, the _fe_normalize call is not needed and can be removed, as the result of `random_fe` is already normalized.

ACKs for top commit:
  real-or-random:
    utACK c45b7c4fbbf41b011f138c465a58322a36664fd3
  siv2r:
    ACK `c45b7c4` (reviewed the changes and tests for both the commits passed locally).

Tree-SHA512: 4ffa66dd0b8392d7d0083a71e7b0682ad18f9261fd4ce8548c3059b497d3462db97e16114fded9787661ca447a877a27f5b996bd7d47e6f91c4454079d28a8ac
2023-09-14 15:06:41 +02:00
Hennadii Stepanov
9f005c60d6
cmake: Install libsecp256k1.pc file
This change allows downstream projects to use pkg-config to search for
the libsecp256k1 library that is built with CMake.
2023-09-07 20:47:57 +01:00
Jonas Nick
70303643cf
tests: add CHECK_ERROR_VOID and use it in scratch tests 2023-09-04 16:19:49 +00:00
Jonas Nick
f8d7ea68df
tests: Replace counting_illegal_callbacks with CHECK_ILLEGAL_VOID
This commit also explicitly initializes shortpubkey. For some reason, removing
surrounding, unrelated lines results in gcc warnings when configured with
--enable-ctime-tests=no --with-valgrind=no.
2023-09-04 16:19:40 +00:00
Jonas Nick
a1d52e3e12
tests: remove unnecessary test in run_ec_pubkey_parse_test
This test tested whether setting the callback works correctly which should be
tested in the context tests.
2023-09-04 12:52:19 +00:00
Jonas Nick
875b0ada25
tests: remove unnecessary set_illegal_callback 2023-09-04 12:50:32 +00:00
Tim Ruffing
0ba2b94551
Merge bitcoin-core/secp256k1#1373: Add invariant checking for scalars
d23da6d55714271c720fee58fbff5e5ef2fe193f use secp256k1_scalar_verify checks (stratospher)
c7d0454932b42a9728b55033c94e000b1dbbb6f2 add verification for scalars (stratospher)
ad152151b06a40aaf6cd90561356ff451996455d update max scalar in scalar_cmov_test and fix schnorrsig_verify exhaustive test (stratospher)

Pull request description:

  From #1360. This PR:
  1. adds `secp256k1_scalar_verify` to make sure scalars are reduced mod the group order in VERIFY mode
  2. uses `secp256k1_scalar_verify` in all the scalar functions except `secp256k1_scalar_clear`, `secp256k1_scalar_reduce_512`, `secp256k1_scalar_mul_512` and `secp256k1_scalar_*_var` functions in `scalar_low_impl.h`

ACKs for top commit:
  real-or-random:
    utACK d23da6d55714271c720fee58fbff5e5ef2fe193f
  theStack:
    Code-review ACK d23da6d55714271c720fee58fbff5e5ef2fe193f

Tree-SHA512: a371b319d948198c4038d35c9ea58f4b94de4dc312215e2b78a323c2acd4ae1355d97935c558b388774832d6d0058b97ff8ca50c3aab40b9ede5307760d0a505
2023-08-18 11:44:17 +02:00
Sebastian Falbesoner
c45b7c4fbb refactor: introduce testutil.h (deduplicate random_fe_, ge_equals_ helpers) 2023-08-17 19:44:00 +02:00
Sebastian Falbesoner
dc5514144f tests: simplify random_fe_non_zero (remove loop limit and unneeded normalize)
`random_fe_non_zero` contains a loop iteration limit that ensures that
we abort if `random_fe` ever yielded zero more than ten times in a row.
This construct was first introduced in PR #19 (commit 09ca4f32) for
random non-square field elements and was later refactored into the
non-zero helper in PR #25 (commit 6d6102fe). The copy-over to the
exhaustive tests happened recently in PR #1118 (commit 0f864207).

This case seems to be practically irrelevant and I'd argue for keeping
things simple and removing it; if there's really a worry that the test's
random generator is heavily biased towards certain values or value
ranges then there should consequently be checks at other places too
(e.g. directly in `random_fe` for 256-bit values that repeatedly
overflow, i.e. >= p).

Also, the _fe_normalize call is not needed and can be removed, as the
result of `random_fe` is already normalized.
2023-08-17 19:40:49 +02:00
Tim Ruffing
de657c2044
Merge bitcoin-core/secp256k1#1062: Removes _fe_equal_var, and unwanted _fe_normalize_weak calls (in tests)
54058d16feaa431520029335e2d56252859d3260 field: remove `secp256k1_fe_equal_var` (siv2r)
bb4efd6404960f9e8f93c15d7d001af068e5b5a4 tests: remove unwanted `secp256k1_fe_normalize_weak` call (siv2r)

Pull request description:

  Fixes #946 and #1061

  Changes:
  - removes unwanted `fe_normalize_weak` calls to the second argument of `fe_equal`
  - removes `fe_equal_var`

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

Tree-SHA512: 89bfd1c205f760d0736b995adebb96d15b0df0a42ece25885c57ae7f4318f6816eb009a7fe94b5987a4cbb8588f0fffbdc275234b406a2d1f80d7695b4bd89db
2023-08-17 18:25:22 +02:00
Tim Ruffing
5d8fa825e2
Merge bitcoin-core/secp256k1#1274: test: Silent noisy clang warnings about Valgrind code on macOS x86_64
747ada35877d4392c453b7c7249465fb382125ea test: Silent noisy clang warnings about Valgrind code on macOS x86_64 (Hennadii Stepanov)

Pull request description:

  Since #1206, on macOS x86_64 with Valgrind installed, clang emits a massive amount of `-Wreserved-identifier` and `-Wreserved-macro-identifier` warnings from the `valgrind/valgrind.h` and `valgrind/memcheck.h` headers.

  This PR prevents warnings emitted for the Valgrind code.

ACKs for top commit:
  real-or-random:
    utACK 747ada35877d4392c453b7c7249465fb382125ea

Tree-SHA512: dd1b2b9db2d471939fdc30f9d8fd106a12f21ec5008ca98d8ebe3087d7ea352d564e8bbd0cec59a004e084af3a84d4680cb81f2ef6fe13cf164b7691e33f437d
2023-08-16 19:04:31 +02:00
siv2r
54058d16fe field: remove secp256k1_fe_equal_var
`fe_equal_var` hits a fast path only when the inputs are unequal, which is
uncommon among its callers (public key parsing, ECDSA verify).
2023-08-16 17:39:25 +05:30
siv2r
bb4efd6404 tests: remove unwanted secp256k1_fe_normalize_weak call
It is not neccessary for the second argument in `secp256k1_fe_equal_var`
(or `secp256k1_fe_equal`) to have magnitude = 1.
Hence, removed the `secp256k1_fe_normalize_weak` call for those argument.
2023-08-16 17:38:04 +05:30
Tim Ruffing
eedd781085
Merge bitcoin-core/secp256k1#1348: tighten group magnitude limits, save normalize_weak calls in group add methods (revival of #1032)
b7c685e74adbd83937990e90f076600fabf8ccf0 Save _normalize_weak calls in group add methods (Peter Dettman)
c83afa66e0c324e42d13adff0e4f7db9b2868788 Tighten group magnitude limits (Peter Dettman)
173e8d061a8d1526f80d9ae79dd7f0371d38f7e0 Implement current magnitude assumptions (Peter Dettman)
49afd2f5d8c323d32a21f2fe182823b6d7704eb2 Take use of _fe_verify_magnitude in field_impl.h (Sebastian Falbesoner)
4e9661fc426c6068b2472f52a772c312bc26acc9 Add _fe_verify_magnitude (no-op unless VERIFY is enabled) (Peter Dettman)
690b0fc05abd76cb7f6bd87e88bf7b8b0fd1ab70 add missing group element invariant checks (Sebastian Falbesoner)

Pull request description:

  This PR picks up #1032 by peterdettman. It's essentially a rebase on master; the original first commit (09dbba561fdb9d57a2cc9842ce041d9ba29a6189) which introduced group verification methods has mostly been replaced by PR #1299 (commit f20266722ac93ca66d1beb0d2f2d2469b95aafea) and what remains now is only adding a few missing checks at some places. The remaining commits are unchanged, though some (easy-to-solve) conflicts appeared through cherry-picking. The last commit which actually removes the `normalize_weak` calls is obviously the critical one and needs the most attention for review.

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

Tree-SHA512: f15167eff7ef6ed971c726a4d738de9a15be95b0c947d7e38329e7b16656202b7113497d36625304e784866349f2293f6f1d8cb97df35393af9ea465a4156da3
2023-08-16 13:51:11 +02:00
Tim Ruffing
db32a24761 ctimetests: Use new SECP256K1_CHECKMEM macros also for ellswift 2023-08-15 19:13:09 +02:00
Jonas Nick
5bf57590bf
bppp: Fix test for invalid sign byte again
The first byte provided to secp256k1_bppp_parse_one_of_points is allowed to be
0, 1, 2, or 3 since it encodes the Y coordinate of two points. In a previous fix
we wrongly assumed it can only be 2 or 3.
2023-08-05 19:12:59 +00:00
Tim Ruffing
aa3edea119 scalar: Remove unused secp256k1_scalar_chacha20
Unused since a11250330b24b3dffdf11d2de5d496397b4e4410.
2023-08-01 10:50:10 +02:00
Tim Ruffing
167194bede rangeproof: Use util functions for writing big endian 2023-08-01 10:48:34 +02:00
Sebastian Falbesoner
a1bd4971d6 refactor: take use of secp256k1_scalar_{zero,one} constants (part 2) 2023-08-01 02:40:21 +02:00
Peter Dettman
b7c685e74a Save _normalize_weak calls in group add methods
Also update the operations count comments in each of the affected
functions accordingly and remove a redundant VERIFY_CHECK in
secp256k1_gej_add_ge (the infinity value range check [0,1] is already
covered by secp256k1_gej_verify above).

Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
2023-07-29 01:10:21 +02:00
Tim Ruffing
82777bba34 bppp: Fix test for invalid sign byte
The test is supposed to create an invalid sign byte. Before this PR,
the generated sign byte could in fact be valid due to an overflow.

Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
2023-07-28 14:20:44 +02:00
Tim Ruffing
54b37db953 build: Fix linkage of extra binaries in -zkp modules 2023-07-28 14:20:42 +02:00
Peter Dettman
c83afa66e0 Tighten group magnitude limits
- adjust test methods that randomize magnitudes

Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
Co-authored-by: Jonas Nick <jonasd.nick@gmail.com>
2023-07-28 13:05:04 +02:00
Tim Ruffing
9e96a2e9d8 hsort tests: Don't call secp256k1_testrand_int(0) 2023-07-28 10:52:25 +02:00
Jonas Nick
80187089ff
Merge commits '4494a369 3aef6ab8 0fa84f86 249c81ea 7966aee3 fb758fe8 3fc1de5c 0aacf643 9e6d1b0e 332af315 afd7eb4a c9ebca95 cc557575 0f7657d5 907a6721 b40e2d30 c545fdc3 2bd5f3e6 0e00fc7d c734c642 26392da2 ' into temp-merge-1386 2023-07-27 18:57:30 +00:00
Tim Ruffing
525b661f83
bppp/build: Fix linkage of benchmark 2023-07-27 16:31:40 +00:00
Tim Ruffing
4c70cc9bf5
Suppress wrong/buggy warning in MSVC <19.33
For background, see:
https://developercommunity.visualstudio.com/t/c-compiler-incorrect-propagation-of-const-qualifie/390711
2023-07-27 16:31:40 +00:00
Jonas Nick
579999b425
scalar: adjust muladd2 to new int128 interface 2023-07-27 16:31:40 +00:00
Jonas Nick
74d9073414
Merge commits '83186db3 e9e4526a 5f7903c7 d373a721 09df0bfb 20a5da5f 908e02d5 d75dc59b debf3e5c bf29f8d0 60556c9f cb1a5927 67214f5f 45c5ca76 30574f22 0702ecb0 705ce7ed 3c1a0fd3 10836832 926dd3e9 ac43613d fd491ea1 799f4eec ' into temp-merge-1356 2023-07-27 16:31:40 +00:00
stratospher
d23da6d557 use secp256k1_scalar_verify checks 2023-07-27 17:35:50 +05:30
stratospher
c7d0454932 add verification for scalars
secp256k1_scalar_verify checks that scalars are reduced mod the
group order
2023-07-27 14:03:59 +05:30
stratospher
ad152151b0 update max scalar in scalar_cmov_test and fix schnorrsig_verify exhaustive test
- `secp256k1_scalar_set_int` in scalar_low uses input mod EXHAUSTIVE_TEST_ORDER
- directly store s in sig64 without reducing it mod the group order for testing
2023-07-27 11:59:33 +05:30
Cory Fields
b097a466c1 util: remove unused checked_realloc
Usage was removed in 6fe50439 .
2023-07-25 20:37:46 +00:00
Jonas Nick
e593ed5685
musig: ensure point_load output is normalized
This is similar to the upstream commit "Normalize ge produced from
secp256k1_pubkey_load".
2023-07-25 07:28:33 +00:00
Jonas Nick
7a07f3d33f
Merge commits '3bab71cf 4258c54f 566faa17 9ce9984f 04bf3f67 5be353d6 2e035af2 5b0444a3 a6f4bcf6 5ec1333d f6bef03c 1f33bb2b 1c895367 6b7e5b71 596b336f 4b84f4bf 024a4094 222ecaf6 4b0f711d 3c818388 f30c7486 1cf15ebd 24c768ae 341cc197 c63ec88e 54d34b6c 073d98a0 9eb6934f ab5a9171 fb3a8063 006ddc1f 3353d3c7 b54a0672 7d4f86d2 e8295d07 3e3d125b acf5c55a ' into temp-merge-1312 2023-07-24 20:15:07 +00:00
Jonas Nick
a9a5c24de2
Merge commits '56582094 427bc3cd 0cf2fb91 9c8c4f44 70be3cad f16a709f 464a9115 1d8f3675 afd8b23b 2bca0a5c 2d51a454 4e682626 a0f4644f 145078c4 7b7503da ec98fced 346a053d ' into temp-merge-1269 2023-07-24 13:46:43 +00:00
Hennadii Stepanov
4f8c5bd761
refactor: Drop unused cast 2023-07-24 13:14:23 +01:00
Peter Dettman
173e8d061a Implement current magnitude assumptions
Remove also the explicit magnitude restriction `a->x.magnitude <= 31`
in `secp256k1_gej_eq_x_var` (introduced in commit
07c0e8b82e2cea87f85263512945fed7adffea18), as this is implied by the
new limits.

Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
2023-07-22 01:52:06 +02:00
Sebastian Falbesoner
49afd2f5d8 Take use of _fe_verify_magnitude in field_impl.h 2023-07-22 01:52:06 +02:00
Peter Dettman
4e9661fc42 Add _fe_verify_magnitude (no-op unless VERIFY is enabled)
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-07-22 01:52:06 +02:00
Sebastian Falbesoner
690b0fc05a add missing group element invariant checks
The group element checks `secp256k1_{ge,gej}_verify` have first been
implemented and added in commit f20266722ac93ca66d1beb0d2f2d2469b95aafea
(PR #1299). This commit adds additional verification calls in group
functions, to match the ones that were originally proposed in commit
09dbba561fdb9d57a2cc9842ce041d9ba29a6189 of WIP-PR #1032 (which is
obviously not rebased on #1299 yet).

Also, for easier review, all functions handling group elements are
structured in the following wasy for easier review (idea suggested by
Tim Ruffing):

- on entry, verify all input ge, gej (and fe)
- empty line
- actual function body
- empty line
- on exit, verify all output ge, gej

Co-authored-by: Peter Dettman <peter.dettman@gmail.com>
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-07-22 01:52:06 +02:00
Jonas Nick
dc733595b0
Merge commits 'df323b5c 3295aa14 ef4f8bd0 90b513aa bdf39000 ' into temp-merge-1223 2023-07-21 13:34:46 +00:00
Jonas Nick
0d540ec942
Merge commits '88e80722 ff8edf89 f29a3270 a7a7bfaf a01a7d86 b1579cf5 ad7433b1 233822d8 5fbff5d3 2b77240b 1bff2005 e1817a6f 5596ec5c 8ebe5c52 1cca7c17 1b21aa51 cbd25559 09b1d466 57573187 8962fc95 9d1b458d eb8749fc 6048e6c0 ' into temp-merge-1222 2023-07-20 16:29:40 +00:00
Jonas Nick
304fc88557
Merge commits '9a8d65f0 75d7b7f5 665ba77e 3f57b9f7 eacad90f 01b819a8 31ed5386 2a39ac16 0eb30004 cbe41ac1 cc3b8a4f ' into temp-merge-1187 2023-07-20 12:19:00 +00:00