Commit Graph

1749 Commits

Author SHA1 Message Date
Peter Dettman d64bb5d4f3 Add fe_half tests for worst-case inputs
- Add field method _fe_get_bounds
2022-02-01 17:51:05 +07:00
Tim Ruffing b54d843eac sage: Fix printing of errors
Python 3 often returns iterable map objects where Python 2 returned
list. We can just them down to lists explicitly.

Overlooked in 13c88efed0.
2022-01-31 15:17:46 +01:00
Peter Dettman 4eb8b932ff Further improve doubling formula using fe_half 2022-01-31 19:41:07 +07:00
Pieter Wuille 557b31fac3 Doubling formula using fe_half 2022-01-31 19:41:07 +07:00
Pieter Wuille 2cbb4b1a42 Run more iterations of run_field_misc
At count=64, this makes the test take around 1% of the total time.
2022-01-31 19:41:07 +07:00
Pieter Wuille 9cc5c257ed Add test for secp256k1_fe_half 2022-01-31 19:41:07 +07:00
Peter Dettman 925f78d55e Add _fe_half and use in _gej_add_ge
- Trades 1 _half for 3 _mul_int and 2 _normalize_weak
- Updated formula and comments in _gej_add_ge
- Added internal benchmark for _fe_half
2022-01-31 19:41:01 +07:00
Tim Ruffing e108d0039c sage: Fix incompatibility with sage 9.4
`allexprs` is already the product all numerators. Don't take it's
numerator again.

Fixes #1067.
2022-01-31 12:15:16 +01:00
Jonas Nick d8a2463246
Merge bitcoin-core/secp256k1#899: Reduce stratch space needed by ecmult_strauss_wnaf.
b797a500ec Create a SECP256K1_ECMULT_TABLE_VERIFY macro. (Russell O'Connor)
a731200cc3 Replace ECMULT_TABLE_GET_GE_STORAGE macro with a function. (Russell O'Connor)
fe34d9f341 Eliminate input_pos state field from ecmult_strauss_wnaf. (Russell O'Connor)
0397d00ba0 Eliminate na_1 and na_lam state fields from ecmult_strauss_wnaf. (Russell O'Connor)
7ba3ffcca0 Remove the unused pre_a_lam allocations. (Russell O'Connor)
b3b57ad6ee Eliminate the pre_a_lam array from ecmult_strauss_wnaf. (Russell O'Connor)
ae7ba0f922 Remove the unused prej allocations. (Russell O'Connor)
e5c18892db Eliminate the prej array from ecmult_strauss_wnaf. (Russell O'Connor)
c9da1baad1 Move secp256k1_fe_one to field.h (Russell O'Connor)

Pull request description:

ACKs for top commit:
  sipa:
    ACK b797a500ec
  jonasnick:
    ACK b797a500ec

Tree-SHA512: 6742469979c306104a0861be76c2be86bf8ab14116b00afbd24f91b9e3ea843bf9b9a74552b367bd06ee617090019ad4df6be037d58937c8c869f8b37ddaa6cc
2022-01-26 14:49:40 +00:00
Tim Ruffing 0a40a4861a
Merge bitcoin-core/secp256k1#1049: Faster fixed-input ecmult tests
070e772211 Faster fixed-input ecmult tests (Pieter Wuille)

Pull request description:

  Given how much #920 slowed down the tests with low iteration count, replace it with 3 different similar test:
  * count >= 1: a test with 1024 multiplies that tests any pattern of 6 bits in windows not more than 20 bits wide
  * count >= 3: a test with 2048 multiplies that tests any pattern of 8 consecutive bits
  * count >= 35: the old test (which effectively tests all 2-bit patterns)

ACKs for top commit:
  robot-dreams:
    ACK 070e772211, the addition of the `CONDITIONAL_TEST` macro is nice.
  real-or-random:
    ACK 070e772211

Tree-SHA512: b4ccca42c71fcd1baa7143f73d1c3ac9d012c296485164a03341dbeee02e4ba9f7c7ad6b441923a5fe0286c97eff60815033adb4e1d30b3ef08bcb79590327ff
2022-01-24 22:01:54 +01:00
Pieter Wuille 070e772211 Faster fixed-input ecmult tests 2022-01-22 18:44:32 -05:00
Pieter Wuille c8aa516b57
Merge bitcoin-core/secp256k1#1064: Modulo-reduce msg32 inside RFC6979 nonce fn to match spec. Fixes #1063
45f37b6506 Modulo-reduce msg32 inside RFC6979 nonce fn to match spec. Fixes #1063. (Paul Miller)

Pull request description:

ACKs for top commit:
  siv2r:
    ACK 45f37b6. The diff looks good. It reduces `msg32` to modulo curve order for rfc6979 nonce generation. All tests passed on my machine with `make check`.
  sipa:
    utACK 45f37b6506
  real-or-random:
    ACK 45f37b6506

Tree-SHA512: 4c36784b2d6f2983bc0c3f380ff59cd9f2bd1822b98116d70964cd15183742fcc1f2ccde225a76dd30d946b3678b2cf29caff018efc07f40a200ee85843b39dd
2022-01-22 18:38:27 -05: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
Russell O'Connor c9da1baad1 Move secp256k1_fe_one to field.h
This makes secp256k1_fe_one part of field.h's interface, and allows other modules to appropriately access the constant.
2022-01-19 09:53:02 -05:00
Paul Miller 45f37b6506
Modulo-reduce msg32 inside RFC6979 nonce fn to match spec. Fixes #1063. 2022-01-17 04:07:16 +02:00
Pieter Wuille a1102b1219
Merge bitcoin-core/secp256k1#1029: Simpler and faster ecdh skew fixup
e82144edfb Fixup skew before global Z fixup (Peter Dettman)
40b624c90b Add tests for _gej_cmov (Peter Dettman)
8c13a9bfe1 ECDH skews by 0 or 1 (Peter Dettman)
1515099433 Simpler and faster ecdh skew fixup (Peter Dettman)

Pull request description:

  This PR adds a `_gej_cmov` method, with accompanying tests, and uses it to simplify the skew fixup at the end of `_ecmult_const`.

  In the existing code, `_wnaf_const` chooses a skew of either 1 or 2, and `_ecmult_const` needs a call to `_ge_set_gej` (which does an expensive field inversion internally) and some overly-complicated conversions to/from `_ge_storage` so that `_ge_storage_cmov` can be used to select what value to add for the fixup.

  This PR uses a simpler scheme where `_wnaf_const` chooses a skew of 0 or 1 and no longer needs special handling for scalars with value negative one. A new `_gej_cmov` method is used at the end of `_ecmult_const` for const-time optional addition to adjust the final result for the skew. Finally, the skew fixup is moved to before the global-Z adjustment, and the precomputed table entries (for 1P, λ(1P)) are used for the skew fixup, saving a field multiply and ensuring the fixup is done on the same isomorphism as the ladder.

  The resulting `_wnaf_const` and `_ecmult_const` are shorter and simpler, and the ECDH benchmark is around 5% faster (64bit, i7).

  Edit: Updated description once the final scope was clear.

ACKs for top commit:
  apoelstra:
    ACK e82144ed
  sipa:
    ACK e82144edfb
  real-or-random:
    ACK e82144edfb

Tree-SHA512: 10d6770f4ef4f8d0c78abbf58d643f25f5daef68896643af0a3f7f877414e23356724b6f20af2027316a4353a35b8cb0a7851e057a3f6483897df02bf033a8a2
2021-12-31 14:44:59 -05:00
Peter Dettman e82144edfb Fixup skew before global Z fixup 2021-12-26 14:56:51 +07:00
Peter Dettman 40b624c90b Add tests for _gej_cmov 2021-12-26 14:56:51 +07:00
Peter Dettman 8c13a9bfe1 ECDH skews by 0 or 1 2021-12-26 14:56:51 +07:00
Peter Dettman 1515099433 Simpler and faster ecdh skew fixup 2021-12-26 14:56:51 +07:00
Tim Ruffing 39a36db94a
Merge bitcoin-core/secp256k1#1054: tests: Fix test whose result is implementation-defined
3d7cbafb5f tests: Fix test whose result is implementation-defined (Tim Ruffing)

Pull request description:

  A compiler may add struct padding and fe_cmov is not guaranteed to
  preserve it.

  On the way, we restore the name of the function. It was mistakenly
  renamed in 6173839c90 using
  "search and replace".

ACKs for top commit:
  robot-dreams:
    ACK 3d7cbafb5f
  sipa:
    utACK 3d7cbafb5f

Tree-SHA512: f8bb643d4915e9ce9c4fe45b48a2878f6cf1f29e654be1c150cdf65c6959cf65f8491928cf098da5a01f1d488ba475914905ca96b232abed499eb6ed65e53fb8
2021-12-25 21:41:17 +01:00
Tim Ruffing a310e79ee5
Merge bitcoin-core/secp256k1#1052: Use xoshiro256++ instead of RFC6979 for tests
77a19750b4 Use xoshiro256++ PRNG instead of RFC6979 in tests (Pieter Wuille)
5f2efe684e secp256k1_testrand_int(2**N) -> secp256k1_testrand_bits(N) (Pieter Wuille)

Pull request description:

  Just some easy low-hanging fruit. It's complete overkill to use the RFC6979 RNG for our test randomness. Replace it with a modern non-cryptographic RNG with good properties. It's a few % speedup for me.

  Given the internal naming of all these functions to be "testrand", I'm not concerned about the risk of someone using this for something that needs actual cryptographic randomness.

ACKs for top commit:
  robot-dreams:
    ACK 77a19750b4
  real-or-random:
    utACK 77a19750b4

Tree-SHA512: 2706f37689e037e84b5df25c98af924c0756e6d59f5f822b23aec5ba381b2d536e0848f134026e2568396427218f1c770f1bb07613d702efb23a84015dc9271d
2021-12-25 19:21:21 +01:00
Tim Ruffing 423b6d19d3
Merge bitcoin-core/secp256k1#964: Add release-process.md
3ed0d02bf7 doc: add CHANGELOG template (Jonas Nick)
6f42dc16c8 doc: add release_process.md (Jonas Nick)
0bd3e4243c build: set library version to 0.0.0 explicitly (Jonas Nick)
b4b02fd8c4 build: change libsecp version from 0.1 to 0.1.0-pre (Jonas Nick)

Pull request description:

  This is an attempt at a simple release process. Fixes #856. To keep it simple, there is no concept of release candidates for now.

  The release version is determined by semantic versioning of the API. Since it does not seem to be a lot of work, it is proper to also version the ABI with the libtool versioning system. This versioning scheme (semver API, libtool versioning ABI) follows the suggestion in the [autotools mythbusters](https://autotools.io/libtool/version.html).

  Experimental modules are a bit of a headache, as expected. This release process suggests to treat any change in experimental modules as backwards compatible. That way, users of stable modules are not bothered by frequent non-backwards compatible releases. But a downside is that one must not use experimental modules in shared libraries (which should be mentioned in the README?). It would be nice if we could make the schnorrsig module stable in the not too distant future (see also #817).

ACKs for top commit:
  apoelstra:
    utACK 3ed0d02bf7
  elichai:
    ACK 3ed0d02bf7
  sipa:
    ACK 3ed0d02bf7
  real-or-random:
    ACK 3ed0d02bf7

Tree-SHA512: 25a04335a9579e16de48d378b93a9c6a248529f67f7c436680fa2d495192132743ce016c547aa9718cdcc7fe932de31dd7594f49052e8bd85572a84264f2dbee
2021-12-25 01:03:03 +01:00
Tim Ruffing 9281c9f4e1
Merge bitcoin-core/secp256k1#1053: ecmult: move `_ecmult_odd_multiples_table_globalz_windowa`
05e049b73c ecmult: move `_ecmult_odd_multiples_table_globalz_windowa` (siv2r)

Pull request description:

  Fixes #1035

  **Changes:**
      - move `secp256k1_ecmult_odd_multiples_table_globalz_windowa` function from ecmult to ecmult_const
      - remove outdated comment

ACKs for top commit:
  robot-dreams:
    utACK 05e049b73c (`diff` between removed and added lines is exactly as expected)
  real-or-random:
    utACK 05e049b73c

Tree-SHA512: 3fad4e93c641b642e84f4bbafcb8083d3e63b0523009fe0edcb2c1ebe1571d822320451289c651403ed1dc033ec6a7a3e8c3c56ad93d81bb1590cf9ff15a3b34
2021-12-25 00:11:19 +01:00
Pieter Wuille 77a19750b4 Use xoshiro256++ PRNG instead of RFC6979 in tests 2021-12-24 11:19:29 -05:00
Pieter Wuille 5f2efe684e secp256k1_testrand_int(2**N) -> secp256k1_testrand_bits(N) 2021-12-24 10:56:16 -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
Tim Ruffing 3d7cbafb5f tests: Fix test whose result is implementation-defined
A compiler may add struct padding and fe_cmov is not guaranteed to
preserve it.

On the way, we improve the identity check such that it covers the
VERIFY struct members.
2021-12-23 20:18:36 +01:00
Jonas Nick 3ed0d02bf7 doc: add CHANGELOG template 2021-12-23 14:47:15 +00:00
Jonas Nick 6f42dc16c8 doc: add release_process.md 2021-12-23 14:47:15 +00:00
Jonas Nick 0bd3e4243c build: set library version to 0.0.0 explicitly 2021-12-23 14:47:14 +00:00
Jonas Nick b4b02fd8c4 build: change libsecp version from 0.1 to 0.1.0-pre 2021-12-23 14:46:19 +00:00
Jonas Nick 09971a3ffd
Merge bitcoin-core/secp256k1#1047: ci: Various improvements
b4ac1a1d5f ci: Run valgrind/memcheck tasks with 2 CPUs (Tim Ruffing)
e70acab601 ci: Use Cirrus "greedy" flag to use idle CPU time when available (Tim Ruffing)
d07e30176e ci: Update brew on macOS (Tim Ruffing)
22382f0ea0 ci: Test different ecmult window sizes (Tim Ruffing)
26a022a3a0 ci: Remove STATICPRECOMPUTATION (Tim Ruffing)
10461d8bd3 precompute_ecmult: Always compute all tables up to default WINDOW_G (Tim Ruffing)

Pull request description:

ACKs for top commit:
  elichai:
    utACK b4ac1a1d5f
  jonasnick:
    ACK b4ac1a1d5f

Tree-SHA512: b283d7b1c72cf87484de1fe98318298698fe9982dc33389eaca62e92318ab0074c183b9799add274f46358032491fee875e5ffb2a76a47f3b07520b850f4c85e
2021-12-22 18:15:42 +00:00
Tim Ruffing 0b83b203e1
Merge bitcoin-core/secp256k1#1030: doc: Fix upper bounds + cleanup in field_5x52_impl.h comment
1287786c7a doc: Add comment to top of field_10x26_impl.h (Elliott Jin)
58da5bd589 doc: Fix upper bounds + cleanup in field_5x52_impl.h comment (Elliott Jin)

Pull request description:

  When reviewing #816 I noticed the upper bounds in the comment at the top of `field_5x52_impl.h` were off by 1 (see `fe_verify`). This PR fixes the upper bounds and also cleans up the comment along the way.

ACKs for top commit:
  real-or-random:
    ACK 1287786c7a

Tree-SHA512: 4b7dadc92451ab1ceb5a547a3101ff37f3ffd0645490563f1f3442ea8d6219f100ed914289d22435c4172d190fa1ff52e37e4464132bb3f9bbcc338488227f7b
2021-12-22 18:53:26 +01:00
Elliott Jin 1287786c7a doc: Add comment to top of field_10x26_impl.h 2021-12-22 07:32:41 -08:00
Elliott Jin 58da5bd589 doc: Fix upper bounds + cleanup in field_5x52_impl.h comment 2021-12-22 07:32:41 -08:00
Jonas Nick b39d431aed
Merge bitcoin-core/secp256k1#1044: Add another ecmult_multi test
22d25c8e0a Add another ecmult_multi test (Pieter Wuille)

Pull request description:

ACKs for top commit:
  jonasnick:
    ACK 22d25c8e0a

Tree-SHA512: e1394fa1708e65a66d4b324cca60dd49c67e37b23b7da2a3ff0db7a2a25c23976cb03b96a8c8584ee81aaec559feb84fb113dff2e2ebf89110ed466a4a6b158b
2021-12-22 14:18:55 +00:00
Tim Ruffing b4ac1a1d5f ci: Run valgrind/memcheck tasks with 2 CPUs
... and increase the memory only for UBSan, ASan, LSan builds. Those are
the ones who need more memory.
2021-12-22 14:57:16 +01:00
Tim Ruffing e70acab601 ci: Use Cirrus "greedy" flag to use idle CPU time when available 2021-12-22 14:57:16 +01:00
Tim Ruffing d07e30176e ci: Update brew on macOS
The preinstalled brew is very old and tries to download prebuilt bottles
from a server which is no longer available. Because that will fail, brew
falls back to building our dependencies (e.g., autotools) from source,
which takes very long.

This commit makes sure that brew is updated before we start the build.

We also need to remove the `--shallow` argument from `brew tap`. It
doesn't exist in recent brew versions.
2021-12-22 14:56:49 +01:00
Tim Ruffing 22382f0ea0 ci: Test different ecmult window sizes 2021-12-22 14:56:27 +01:00
Tim Ruffing a69df3ad24
Merge bitcoin-core/secp256k1#816: Improve checks at top of _fe_negate methods
515e7953ca Improve checks at top of _fe_negate methods (Peter Dettman)

Pull request description:

  In theory we could have a single static assertion that would ensure all of these are always true (for any magnitude up to the limit), but I think this small redundancy is clearer.

ACKs for top commit:
  sipa:
    utACK 515e7953ca
  real-or-random:
    ACK 515e7953ca bounds hold by inspection and by robot-dreams's script

Tree-SHA512: c33e47e186b37ca0b4e8d23712f8e5ab0c113024a0229fc6ce63b8cbad21bddbecc0c50029721a1fb3376b2d1da678c1ddb69c5ae971d84ddb7993c755867da4
2021-12-22 11:44:24 +01:00
Pieter Wuille 22d25c8e0a Add another ecmult_multi test 2021-12-21 16:42:08 -05:00