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 scalar multiplication, const-time or otherwise, by the same mechanism. The reason is that our 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.
Exhaustive tests added for the following internal functions:
secp256k1_ge_is_infinity,secp256k1_gej_is_infinitysecp256k1_gej_add_var,secp256k1_gej_add_ge,secp256k1_gej_add_ge_var,secp256k1_gej_add_zinv_varsecp256k1_gej_double_nonzero,secp256k1_gej_double_varsecp256k1_ge_neg,secp256k1_gej_negsecp256k1_ecmult,secp256k1_ecmult_const
And also (unfortunately with a bit of surgery; the original functions don't work with small group orders)
secp256k1_ecdsa_signsecp256k1_ecdsa_verify