Commit Graph
62 Commits
Author SHA1 Message Date
kallal79 a77dacad9a test: enable -Wunused-function in test suite (Fix #1831) 2026-06-12 19:10:33 +05:30
Sebastian Falbesoner ca68daf8e1 test: refactor: simplify tests by using _ecmult_gen_ge helper
If the generator point multiplication result in Jacobian coordinates is
immediately converted to affine coordinates after and is not needed for
anything else, we can deduplicate by using the helper introduced in #1861.

Note that in a very strict sense this is not a refactor, as the Jacobian
object is now cleared out which was not done on master, but for the logic
in the tests this shouldn't matter at all.
2026-06-08 18:44:58 +02:00
Sebastian Falbesoner 9e017e5062 refactor: rename _ecmult_gen -> _ecmult_gen_gej for consistency
Now that we have a function `_ecmult_gen_ge`, it makes sense to rename
the existing function `_ecmult_gen` to `_ecmult_gen_gej` for
consistency, to signal that the result is a Jacobian group element.

This diff was created by applying
```
$ sed -i s/secp256k1_ecmult_gen\(/secp256k1_ecmult_gen_gej\(/g $(git ls-files)
```
2026-06-07 20:21:18 +02:00
Sebastian Falbesoner 5698e66c64 Add exhaustive test for ECDH module 2026-06-02 14:25:34 +02:00
Tim Ruffing 8d0eda07e9 testrand: Remove testrand_finish
This removes printing of the "random run = " at the end of the tests. I
haven't seen a single case where this proved to be useful. And as of
48789dafc2, this is anyway printed only at
the end of the exhaustive tests and not the normal tests, so the
probability that this will be useful in the future is very low.
2026-03-02 15:06:39 +01:00
Tim Ruffing 2f73e5281d group: Avoid using infinity field directly in other modules 2025-11-06 17:51:08 +01:00
Sebastian Falbesoner c855581728 test, bench, precompute_ecmult: use EXIT_... constants for main return values 2025-02-14 18:03:36 +01:00
Sebastian Falbesoner e73f6f8fd9 tests: refactor: drop secp256k1_ prefix from testrand.h functions
The rename was done with the following command:

$ sed -i 's/secp256k1_testrand/testrand/g' $(git grep -l secp256k1_testrand)
2024-05-27 03:29:36 +02:00
Sebastian Falbesoner 0ee7453a99 tests: refactor: add testutil_ prefix to testutil.h functions 2024-05-27 03:29:32 +02:00
Pieter Wuille a043940253 Permit COMB_BITS < 256 for exhaustive tests 2024-04-19 11:43:46 -04:00
Peter Dettman fde1dfcd8d Signed-digit multi-comb ecmult_gen algorithm
This introduces the signed-digit multi-comb multiplication algorithm
for constant-time G multiplications (ecmult_gen). It is based on
section 3.3 of "Fast and compact elliptic-curve cryptography" by
Mike Hamburg (see https://eprint.iacr.org/2012/309).

Original implementation by Peter Dettman, with changes by Pieter Wuille
to use scalars for recoding, and additional comments.
2024-04-19 11:43:22 -04:00
Pieter Wuille 04af0ba162 Replace ge_equals_ge[,j] calls with group.h equality calls 2023-12-01 16:10:20 -05: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
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
2792119278 Add exhaustive test for ellswift (create+decode roundtrip)
Co-authored-by: Pieter Wuille <pieter@wuille.net>
Co-authored-by: Tim Ruffing <crypto@timruffing.de>
2023-07-05 18:24:37 +02:00
Pieter Wuille 5b32602295 Split fe_set_b32 into reducing and normalizing variants 2023-05-11 13:49:33 -04:00
Tim Ruffing 1907f0f166 build: Make tests work with external default callbacks 2023-05-11 19:08:35 +02: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
Tim Ruffing a6f4bcf6e1 Merge bitcoin-core/secp256k1#1231: Move SECP256K1_INLINE macro definition out from include/secp256k1.h
8e142ca410 Move `SECP256K1_INLINE` macro definition out from `include/secp256k1.h` (Hennadii Stepanov)
77445898a5 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 8e142ca410
  real-or-random:
    utACK https://github.com/bitcoin-core/secp256k1/pull/1231/commits/8e142ca4102ade1b90dcb06d6c78405ef3220599

Tree-SHA512: 180e0ba7c2ef242b765f20698b67d06c492b7b70866c21db27c18d8b2e85c3e11f86c6cb99ffa88bbd23891ce3ee8a24bc528f2c91167ec2fddc167463f78eac
2023-04-20 18:18:11 +02:00
Pieter Wuille a575339c02 Remove bits argument from secp256k1_wnaf_const (always 256) 2023-04-10 06:40:21 -04:00
Pieter Wuille 0f8642079b Add exhaustive tests for ecmult_const_xonly 2023-04-08 15:25:41 -04:00
Hennadii Stepanov 8e142ca410 Move SECP256K1_INLINE macro definition out from include/secp256k1.h 2023-03-09 15:29:56 +00:00
Pieter Wuille e03ef86559 Make all non-API functions (except main) static 2023-01-09 12:02:27 -05:00
Hennadii StepanovandAli Sherief b627ba7050 Remove dependency on src/libsecp256k1-config.h
This change eases the use of alternate build systems by moving
the variables in `src/libsecp256k1-config.h` to compiler macros
for each invocation, preventing duplication of these variables
for each build system.

Co-authored-by: Ali Sherief <ali@notatether.com>
2022-12-15 10:56:16 +00:00
Jonas Nick 37ba744f5b tests: Switch to NONE contexts in exhaustive and ctime tests 2022-12-07 10:54:50 +00:00
Tim RuffingandHennadii Stepanov 40a3473a9d build: Fix #include "..." paths to get rid of further -I arguments
This simplifies building without a build system.

This is in line with #925; the paths fixed here were either forgotten
there or only introduced later. This commit also makes the Makefile
stricter so that further "wrong" #include paths will lead to build
errors even in autotools builds.

This belongs to #929.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-07-01 15:03:35 +02:00
Pieter Wuille 38cd84a0cb Compute ecmult tables at runtime for tests_exhaustive 2021-12-18 16:12:33 -05:00
Pieter Wuille 31feab053b Rename function secp256k1_ecmult_gen_{create_prec -> compute}_table 2021-12-18 16:11:52 -05:00
Pieter Wuille 725370c3f2 Rename ecmult_gen_prec -> ecmult_gen_compute_table 2021-12-17 14:43:45 -05:00
Tim Ruffing fdb33dd122 refactor: Make PREC_BITS a parameter of ecmult_gen_build_prec_table 2021-12-05 17:58:26 +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 22dc2c0a0d ecmult_gen: Move table creation to new file and force static prec 2021-11-19 13:47:05 +01: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
Nicolas Iooss a1ee83c654 tests_exhaustive: check the result of secp256k1_ecdsa_sign
If `secp256k1_ecdsa_sign` fails, the signature which is then loaded by
`secp256k1_ecdsa_signature_load` is garbage. Exit early with an error
when this occurs.
2021-07-02 16:22:43 +02:00
William Bright 3c90bdda95 change local lib headers to be relative for those pointing at "include/" dir
added relative paths to header files imported from src directory

added include guards for contrib/ files when referring to secp256k1.h
2021-05-05 09:24:05 -04:00
Gregory Maxwell ae9e648526 Define SECP256K1_BUILD in secp256k1.c directly.
This avoids building without it and makes it safer to use a custom
 building environment.  Test harnesses need to #include secp256k1.c
 first now.
2021-05-01 19:27:27 +00:00
Dimitris Apostolou 07aa4c70ff Fix insecure links 2020-12-18 00:24:22 +02:00
Pieter Wuille 4232e5b7da Rip out non-endomorphism code 2020-10-13 11:31:13 -07:00
Pieter Wuille a45c1fa63c Rename testrand functions to have test in name 2020-09-25 20:50:43 -07:00
Pieter Wuille 8b7dcdd955 Add exhaustive test for extrakeys and schnorrsig 2020-09-18 14:11:38 -07:00
Pieter Wuille 63e1b2aa7d Disable output buffering in tests_exhaustive.c 2020-09-18 14:11:37 -07:00
Pieter Wuille 39f67dd072 Support splitting exhaustive tests across cores 2020-09-18 14:11:02 -07:00
Pieter Wuille e99b26fcd5 Give exhaustive_tests count and seed cmdline inputs 2020-09-18 14:10:59 -07:00
Pieter Wuille b110c106fa Change exhaustive test groups so they have a point with X=1
This enables testing overflow is correctly encoded in the recid, and
likely triggers more edge cases.

Also introduce a Sage script to generate the parameters.
2020-09-18 14:01:15 -07:00
Pieter Wuille cec7b18a34 Select exhaustive lambda in function of order 2020-09-18 14:01:15 -07:00
Pieter Wuille c498366e5b Move exhaustive tests for recovery to module 2020-09-18 14:01:15 -07:00
Pieter Wuille be31791543 Make group order purely compile-time in exhaustive tests 2020-09-18 14:01:15 -07:00
Pieter Wuille 7c068998ba Compile-time check assumptions on integer types 2020-08-14 16:12:49 -07:00