17 Commits

Author SHA1 Message Date
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
Pieter Wuille
18d36327fd secp256k1_gej_double_nonzero supports infinity 2020-07-28 18:12:30 -07:00
Gregory Maxwell
2241ae6d14 Remove secret-dependant non-constant time operation in ecmult_const.
ECMULT_CONST_TABLE_GET_GE was branching on its secret input.

Also makes secp256k1_gej_double_var implemented as a wrapper
 on secp256k1_gej_double_nonzero instead of the other way
 around.  This wasn't a constant time bug but it was fragile
 and could easily become one in the future if the double_var
 algorithm is changed.
2020-01-09 12:21:28 +00:00
Andrew Poelstra
c2b028a281 scratch space: thread error_callback into all scratch space functions
Use it when checking magic bytes
2019-05-25 22:59:50 +00:00
Andrew Poelstra
6fe50439ae scratch: add stack frame support 2018-04-05 22:49:29 +00:00
Andrew Poelstra
7c1b91ba4b parameterize ecmult_const over input size 2018-04-05 21:05:13 +00:00
Jonas Nick
355a38f113 Add pippenger_wnaf ecmult_multi 2017-12-07 20:13:04 +00:00
Andrew Poelstra
dba5471b69 Add ecmult_multi tests 2017-12-07 20:13:04 +00:00
Andrew Poelstra
2cee5fd4c9 exhaustive tests: add recovery module 2016-12-16 21:50:16 +00:00
Andrew Poelstra
678b0e5466 exhaustive tests: remove erroneous comment from ecdsa_sig_sign
Mathematically, we always overflow when using the exhaustive tests (because our
scalar order is 13 and our field order is on the order of 2^256), but the
`overflow` variable returned when parsing a b32 as a scalar is always set
to 0, to prevent infinite (or practically infinite) loops searching for
non-overflowing scalars.
2016-11-28 19:46:18 +00:00
Andrew Poelstra
b4ceedf14f Add exhaustive test for verification 2016-11-26 00:35:02 +00:00
Andrew Poelstra
83836a9547 Add exhaustive tests for group arithmetic, signing, and ecmult on a small group
If you compile without ./configure --enable-exhaustive-tests=no,
this will create a binary ./exhaustive_tests which will execute
every function possible on a group of small order obtained by
moving to a twist of our curve and locating a generator of small
order.

Currently defaults to order 13, though by changing some #ifdefs
you can get a couple other ones. (Currently 199, which will take
forever to run, and 14, which won't work because it's composite.)

TODO exhaustive tests for the various modules
2016-11-26 00:35:00 +00:00
Andrew Poelstra
20b8877be1 Add exhaustive test for group functions on a low-order subgroup
We observe that when changing the b-value in the elliptic curve formula
`y^2 = x^3 + ax + b`, the group law is unchanged. Therefore our functions
for secp256k1 will be correct if and only if they are correct when applied
to the curve defined by `y^2 = x^3 + 4` defined over the same field. This
curve has a point P of order 199.

This commit adds a test which computes the subgroup generated by P and
exhaustively checks that addition of every pair of points gives the correct
result.

Unfortunately we cannot test const-time scalar multiplication by the same
mechanism. The reason is that these ecmult functions both compute a wNAF
representation of the scalar, and this representation is tied to the order
of the group.

Testing with the incomplete version of gej_add_ge (found in 5de4c5dff^)
shows that this detects the incompleteness when adding P - 106P, which
is exactly what we expected since 106 is a cube root of 1 mod 199.
2016-11-25 20:45:29 +00:00