This PR partly addresses issue #1621, handling invalid inputs consistently w.r.t. constant-time, by applying the suggested "functions are constant-time only for valid inputs" approach (number 2. in the issue), for the following modules and API functions:
- ecdh:
secp256k1_ecdh - ellswift:
secp256k1_ellswift_createandsecp256k1_ellswift_xdh - schnorrsig:
secp256k1_schnorrsig_sign{32,_custom}
As stated in #1621, this leads to more readable and maintainable code, getting rid of constructs like return (!!ret) & is_sec_valid; or intermediate ret &= ...; statements. Conditional assignments like secp256k1_scalar_cmov can be removed as well.
Tests are added for the newly introduced branches if there were none. There are still further instances to tackle (mostly the main module API functions in secp256k1.c, and potential cleanups like e.g. removing the dummy assignments in _keypair_load), happy to add these here or in another PR, mostly chasing Conecpt ACKs for now if this is we want to handle constant-time behavior for current and future modules.