957 Commits

Author SHA1 Message Date
Tim Ruffing
6573c08f65 ecmult_gen: Tidy precomputed file and save space 2021-12-09 20:52:26 +01:00
Tim Ruffing
5eba83f17c ecmult_gen: Precompute tables for all values of ECMULT_GEN_PREC_BITS 2021-12-09 20:51:59 +01:00
Tim Ruffing
5d0dbef018
Merge bitcoin-core/secp256k1#942: Verify that secp256k1_ge_set_gej_zinv does not operate on infinity.
099bad945e9a7c5237cdd764eca420285a9de279 Comment and check a parameter for inf in secp256k1_ecmult_const. (Russell O'Connor)
6c0be857f8fee7807a2a704465d2e0f6b1f021e3 Verify that secp256k1_ge_set_gej_zinv does not operate on infinity. a->x and a->y should not be used if the infinity flag is set. (Russell O'Connor)

Pull request description:

  a->x and a->y should not be used if the infinity flag is set.

ACKs for top commit:
  robot-dreams:
    ACK 099bad945e9a7c5237cdd764eca420285a9de279
  real-or-random:
    ACK 099bad945e9a7c5237cdd764eca420285a9de279 I inspected all call sites, they all ensure that a is not infinity

Tree-SHA512: 495fcfe4ec4cacb3fc64bd5d04ecc67ab34f6b63666c6169d473abfd63c2041bc501a9a60d817566517435b986406ea2b7db3f5806043cecf30e214eba9892e9
2021-12-07 11:26:10 +01:00
Tim Ruffing
fdb33dd122 refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table 2021-12-05 17:58:26 +01:00
Pieter Wuille
e2cf77328a Test ecmult functions for all i*2^j for j=0..255 and odd i=1..255. 2021-12-05 11:53:47 -05:00
Tim Ruffing
6ad908aa00
Merge bitcoin-core/secp256k1#1008: bench.c: add --help option and ci: move env variables
592661c22f56736099f83700be8cf280f8a963ff ci: move test environment variable declaration to .cirrus.yml (siv2r)
dcbe84b84182bb077bc8639536a778a3129b1b3e bench: add --help option to bench. (siv2r)

Pull request description:

  Fixes #1005

  **Changes:**
  - added `--help` option to `bench.c`
      - `help()` function prints the help to command-line
      - `have_invalid_args()` checks if the user has entered an invalid argument
  - moved `secp256k1_bench_iters` and `secp256k1_test_iters` environment variables declaration to `.cirrus.yml`

ACKs for top commit:
  sipa:
    utACK 592661c22f56736099f83700be8cf280f8a963ff
  real-or-random:
    ACK 592661c22f56736099f83700be8cf280f8a963ff

Tree-SHA512: ebc6a2e6e47b529212efa1c9b75cc79649fca7f42aa75ce46502db24ac94f46b6cef59c828d13265d1fa69187a81c140d1951e7daeb7c8e008a6c1ad75259741
2021-12-05 11:24:00 +01:00
siv2r
dcbe84b841 bench: add --help option to bench.
The following functions were created:
    1. bench.c: help()
        - prints the help to the command-line
    2. bench.h: have_invalid_args()
        - takes a list of arguments that the user is allowed to enter on the command-line
        - returns 1 if the user entered an invalid argument
        - returns 0 if all the user entered arguments are valid
2021-12-04 22:47:30 +05:30
Russell O'Connor
099bad945e Comment and check a parameter for inf in secp256k1_ecmult_const. 2021-12-03 13:57:38 -05:00
Russell O'Connor
6c0be857f8 Verify that secp256k1_ge_set_gej_zinv does not operate on infinity.
a->x and a->y should not be used if the infinity flag is set.
2021-12-03 12:01:41 -05:00
Tim Ruffing
a4875e30a6 refactor: Move default callbacks to util.h 2021-12-03 11:23:33 +01:00
Tim Ruffing
5106226991 exhaustive_tests: Fix with ecmult_gen table with custom generator 2021-12-03 11:23:33 +01:00
Tim Ruffing
e1a76530db refactor: Make generator a parameter of ecmult_gen_create_prec_table 2021-12-03 11:23:33 +01:00
Tim Ruffing
9ad09f6911 refactor: Rename program that generates static ecmult_gen table 2021-12-03 11:23:33 +01:00
Tim Ruffing
8ae18f1ab3 refactor: Rename file that contains static ecmult_gen table 2021-12-03 11:23:33 +01:00
Tim Ruffing
00d2fa116e ecmult_gen: Make code consistent with comment
This also fixes a typo in the comment.
2021-12-03 11:23:33 +01:00
Tim Ruffing
3b0c2185ea ecmult_gen: Simplify ecmult_gen context after making table static
This is a backwards-compatible API change: Before this commit, a context
initialized for signing was required to call functions that rely on
ecmult_gen. After this commit, this is no longer necessary because the
static ecmult_gen table is always present. In practice this means that
the corresponding functions will just work instead of calling the
illegal callback when given a context which is not (officially)
initialized for signing.

This is in line with 6815761, which made the analogous change with
respect to ecmult and contexts initialized for signing. But as opposed
to 681571, which removed the ecmult context entirely, we cannot remove
the ecmult_gen context entirely because it is still used for random
blinding. Moreover, since the secp256k1_context_no_precomp context is
const and cannot meaningfully support random blinding, we refrain (for
now) from changing its API, i.e., the illegal callback will still be
called when trying to use ecmult_gen operations with the static
secp256k1_context_no_precomp context.
2021-12-03 11:23:33 +01: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
Tim Ruffing
e43ba02cfc refactor: Decouple table generation and ecmult_gen context 2021-11-19 14:03:44 +01:00
Tim Ruffing
22dc2c0a0d ecmult_gen: Move table creation to new file and force static prec 2021-11-19 13:47:05 +01:00
Dimitris Apostolou
233297579d
Fix typos 2021-11-13 02:12:47 +02:00
MarcoFalke
16d132215c refactor: Use (int)&(int) in boolean context to avoid compiler warning
This fixes a compiler warning:

./src/ecdsa_impl.h:312:12: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical]
    return !secp256k1_scalar_is_zero(sigr) & !secp256k1_scalar_is_zero(sigs);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-11-09 11:34:48 +01:00
Pieter Wuille
af6abcb3d0 Make bench support selecting which benchmarks to run 2021-11-05 17:48:18 -04:00
Pieter Wuille
9f56bdf5b9 Merge bench_schnorrsig into bench 2021-11-05 17:35:11 -04:00
Pieter Wuille
3208557ae1 Merge bench_recover into bench 2021-11-05 17:34:46 -04:00
Pieter Wuille
855e18d8a8 Merge bench_ecdh into bench 2021-11-05 17:34:25 -04:00
Pieter Wuille
2a7be678a6 Combine bench_sign and bench_verify into single bench 2021-11-05 17:30:56 -04:00
Pieter Wuille
5324f8942d Make aux_rnd32==NULL behave identical to 0x0000..00.
BIP340's default signing algorithm always requires an aux_rnd argument,
but permits using an all-zero one when no randomness is available.

Make secp256k1_schnorrsig_sign follow this even when aux_rnd32==NULL,
by treating the same as if an all-zero byte array was provided as
input.
2021-10-30 13:03:55 -04:00
Tim Ruffing
21c188b3c5
Merge bitcoin-core/secp256k1#943: VERIFY_CHECK precondition for secp256k1_fe_set_int.
2888640132eb64ed30a8a208931f27447c3e0366 VERIFY_CHECK precondition for secp256k1_fe_set_int. (Russell O'Connor)
d49011f54c2b31807158bdf06364f331558cccc7 Make _set_fe_int( . , 0 ) set magnitude to 0 (Tim Ruffing)

Pull request description:

  Also set the magnitude to 0 when setting the value to 0.

ACKs for top commit:
  real-or-random:
    ACK 2888640132eb64ed30a8a208931f27447c3e0366
  jonasnick:
    ACK 2888640132eb64ed30a8a208931f27447c3e0366

Tree-SHA512: 6ec9b3485380503b11c00f30bfa79f92ba3facb93ee4f3df582b881c4e19fb8ae8b5acd5aeb6326497c290cd0904230d0356f33bd136ca577d2f25616279e090
2021-10-28 17:19:40 +02:00
Jonas Nick
23e2f66726 bench: don't return 1 in have_flag() if argc = 1
This makes the semantic of have_flag more clear and fixes a bug
that was introduced in

2fe1b50df16c9f41ea77b151634d734b930eeddd
Add ecmult_gen, ecmult_const and ecmult to benchmark

where the behavior introduced by this commit was already assumed. If
bench_ecmult was called without arguments, have_flag("simple") returned 1 and no
scratch space was allocated which led to very wrong output.
2021-10-24 19:43:20 +00:00
Jonas Nick
96b1ad2ea9 bench_ecmult: improve clarity of output
Previously "ecmult{,_multi} xg" meant multiplication with (x - 1) random points
and base point G. Now
- ecmult_{,multi_}xp means multiplication with x random points and
- ecmult_{,multi_}xp_g means multiplication with x random points and G
2021-10-24 18:47:24 +00:00
Jonas Nick
20d791edfb
Merge bitcoin-core/secp256k1#989: Shared benchmark format for command line and CSV outputs
b4b130678db31a7cabc2cde091bc4acbca92b7a3 create csv file from the benchmark output (siv2r)
26a255beb673217c839dcc51790d9a484f9a292d Shared benchmark format for command line and CSV outputs (siv2r)

Pull request description:

ACKs for top commit:
  real-or-random:
    ACK b4b130678db31a7cabc2cde091bc4acbca92b7a3
  jonasnick:
    ACK b4b130678db31a7cabc2cde091bc4acbca92b7a3

Tree-SHA512: 1eebbdd7701ad21d9647434ff05f23827be217d47870bb05a2fdb12447abc365fc6e56306f344e05d8d2ec1ff5532562131b3876261733e4412117357c5c65f8
2021-10-22 12:30:36 +00:00
siv2r
26a255beb6 Shared benchmark format for command line and CSV outputs
1. add `print_output_table_header_row` func to print the table header for benchmark output
2. modify the following benchmarks to include the table header
    - bench_ecdh.c
    - bench_ecmult.c
    - bench_internal.c
    - bench_recover.c
    - bench_schnorrsig.c
    - bench_sign.c
    - bench_verify.c
2021-10-19 21:25:37 +05:30
Tim Ruffing
9526874d14
Merge bitcoin-core/secp256k1#810: Avoid overly-wide multiplications in 5x52 field mul/sqr
b53e0cd61fce0bcef178f317537c91efc9afd04d Avoid overly-wide multiplications (Peter Dettman)

Pull request description:

  Speeds up bench_ecdh, bench_sign, bench_verify relative to master by 5+% at -O3, haswell.

ACKs for top commit:
  sipa:
    ACK b53e0cd61fce0bcef178f317537c91efc9afd04d
  real-or-random:
    ACK b53e0cd61fce0bcef178f317537c91efc9afd04d I've inspected the diff and run the tests without asm for a CPU day

Tree-SHA512: 4f79c98371a3dc9da013632210c8db979f910b222291999dfaa0c31849a77eb427361e4ab9206cbfee73c30a8933178784d6cb8e747e8dca6b227eb77fbea2a2
2021-10-17 18:44:54 +02:00
Tim Ruffing
920a0e5fa6
Merge bitcoin-core/secp256k1#952: Avoid computing out-of-bounds pointer.
9be7b0f08340a063d961547b5d2663405f3fc162 Avoid computing out-of-bounds pointer. (Tim Ruffing)

Pull request description:

  This is a pedantic case of UB.

  Spotted in #879.

ACKs for top commit:
  elichai:
    ACK 9be7b0f08340a063d961547b5d2663405f3fc162
  practicalswift:
    cr ACK 9be7b0f08340a063d961547b5d2663405f3fc162
  sipa:
    ACK 9be7b0f08340a063d961547b5d2663405f3fc162

Tree-SHA512: a9d028c4cdb37ad0d5fcf0d2f678eef732a653d37155a69a20272c6b283c28e083172485d7a37dc4a7c6100b22a6f5b6a92e729239031be228cc511842ee35e8
2021-10-17 11:55:31 +02:00
Tim Ruffing
f34b5cae03
Merge bitcoin-core/secp256k1#983: [RFC] Remove OpenSSL testing support
bc08599e776aff33c834ef829843ec5f629d1f39 Remove OpenSSL testing support (Pieter Wuille)

Pull request description:

  This removes the ability to test against OpenSSL, as well as the OpenSSL verification benchmark.

  The motivation is that OpenSSL 3 is deprecating part of the API used here (see #869), and I'm not sure it's worth maintaining. We do lose the fact that this is the only test that verifies randomly-generated cases against an independent implementation. On the other hand, there are tons of existing fixed tests now that test all kinds of edge cases already.

ACKs for top commit:
  elichai:
    tACK bc08599
  real-or-random:
    ACK bc08599e776aff33c834ef829843ec5f629d1f39
  jonasnick:
    ACK bc08599e776aff33c834ef829843ec5f629d1f39

Tree-SHA512: 632e6d3cf7bbc5828f5ca1f0f2a92c80bcb681bbcd4320c352b4a86fd521e410c852ccebcfc30fadc8fbf86649267a9e521f53e0f78072a8cd74d8726da28973
2021-10-17 00:36:32 +02:00
Jonas Nick
297ce82091
Merge bitcoin-core/secp256k1#966: Make aux_rand32 arg to secp256k1_schnorrsig_sign const
db4667d5e0e13d1359991379df3400f64918b4e8 Make aux_rand32 arg to secp256k1_schnorrsig_sign const (Pieter Wuille)

Pull request description:

ACKs for top commit:
  real-or-random:
    ACK db4667d5e0e13d1359991379df3400f64918b4e8 diff looks good
  jonasnick:
    ACK db4667d5e0e13d1359991379df3400f64918b4e8

Tree-SHA512: 6f003c856b0e11f3f41f6d8007470129f02f9075416c6a5d3904f8efb5fa461f38e600a6b31d326314b2961946c8c6b3bca1a8e9b333b52e099a6f023a04c698
2021-10-15 15:57:23 +00:00
Russell O'Connor
2888640132 VERIFY_CHECK precondition for secp256k1_fe_set_int. 2021-10-15 11:27:24 -04:00
Tim Ruffing
d49011f54c Make _set_fe_int( . , 0 ) set magnitude to 0 2021-10-15 11:20:27 -04:00
Pieter Wuille
bc08599e77 Remove OpenSSL testing support 2021-10-14 12:39:27 -04:00
Jonas Nick
189f6bcfef Fix unused parameter warnings when building without VERIFY 2021-10-04 19:06:41 +00:00
siv2r
d43993724d tests: remove secp256k1_fe_verify from tests.c and modify secp256k1_fe_from_storage to call secp256k1_fe_verify
1. secp256k1_fe_verify is removed from tests since, it throws an error if VERIFY is not defined during compilation.
   (Ex: ./configure --enable-coverage)
2. `secp256k1_fe_from_storage` calls `secp256k1_fe_verify` in the VERIFY build to check for invalid field element.
2021-10-02 15:52:05 +05:30
Tim Ruffing
2a3a97c665
Merge bitcoin-core/secp256k1#976: secp256k1_schnorrsig_sign_internal should be static
72713872a8597884918bcf1edbc12f5c969ca680 Add missing static to secp256k1_schnorrsig_sign_internal (Elichai Turkel)

Pull request description:

  This function isn't used outside of this module so it should be declared static

ACKs for top commit:
  real-or-random:
    ACK 72713872a8597884918bcf1edbc12f5c969ca680
  jonasnick:
    ACK 72713872a8597884918bcf1edbc12f5c969ca680

Tree-SHA512: 6107a2c84c3e11ffd68de22a5288d989a3c71c2ec1ee4827c88f6165fc27ef8339d0f6740928540e8ccd03aff49a2a96149bf698ccebe6d6d8ad6e23e38e8838
2021-09-15 16:55:50 +02:00
Tim Ruffing
aa5d34a8fe
Merge bitcoin-core/secp256k1#783: Make the public API docs more consistent and explicit
adec5a16383f1704d80d7c767b2a65d9221cee08 Add missing null check for ctx and input keys in the public API (Elichai Turkel)
f4edfc758142d6e100ca5d086126bf532b8a7020 Improve consistency for NULL arguments in the public interface (Elichai Turkel)

Pull request description:

  I went over the public API and added missing explanations on when a pointer can be null and when it cannot,
  and added some missing checks for null ctx and null pubkey pointers.

  Open questions IMHO:
  1. Can `secp256k1_context_create` return NULL? right now it could return null if you replaced the callbacks at compile time to ones that do return(unlike the default ones which never return).
  2. Related to the first, should we document that the callbacks should never return? (in the tests we use returning callbacks but we can violate our own API) right now we say the following:

  > After this callback returns, anything may happen, including crashing.

  Is this enough to document answer `no` for the first question and just saying that if the callback returned then you violated the API so `secp256k1_context_create` can return NULL even though it is promised not to?
  Right now we AFAICT we never check if it returns null

  Another nit I'm not sure about is wording `(does nothing if NULL)`/`(ignored if NULL)`/`(can be NULL)`

  More missing docs:
  1. Documenting the `data` argument to the default nonce functions

ACKs for top commit:
  ariard:
    ACK adec5a16
  jonasnick:
    ACK adec5a16383f1704d80d7c767b2a65d9221cee08

Tree-SHA512: 6fe785776b7e451e9e8cae944987f927b1eb2e2d404dfcb1b0ceb0a30bda4ce16469708920269417e5ada09739723a430e270dea1868fe7d12ccd5699dde5976
2021-09-15 16:36:11 +02:00
Elichai Turkel
72713872a8
Add missing static to secp256k1_schnorrsig_sign_internal 2021-09-15 12:46:13 +03:00
Pieter Wuille
db4667d5e0 Make aux_rand32 arg to secp256k1_schnorrsig_sign const 2021-09-11 10:05:14 -04:00
Russell O'Connor
20abd52c2e Add tests for pre_g tables.
We check that the static table entries are all correct.
2021-08-20 11:11:26 -04: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
f20dcbbad1 Correct typo. 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