Add ecdsa_sign_recoverable to the ctime tests

This commit is contained in:
Elichai Turkel 2020-05-27 00:38:46 +03:00
parent 2876af4f8d
commit 73596a85a2
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
1 changed files with 19 additions and 0 deletions

View File

@ -12,6 +12,10 @@
# include "include/secp256k1_ecdh.h" # include "include/secp256k1_ecdh.h"
#endif #endif
#if ENABLE_MODULE_RECOVERY
# include "include/secp256k1_recovery.h"
#endif
int main(void) { int main(void) {
secp256k1_context* ctx; secp256k1_context* ctx;
secp256k1_ecdsa_signature signature; secp256k1_ecdsa_signature signature;
@ -24,6 +28,10 @@ int main(void) {
unsigned char key[32]; unsigned char key[32];
unsigned char sig[74]; unsigned char sig[74];
unsigned char spubkey[33]; unsigned char spubkey[33];
#if ENABLE_MODULE_RECOVERY
secp256k1_ecdsa_recoverable_signature recoverable_signature;
int recid;
#endif
if (!RUNNING_ON_VALGRIND) { if (!RUNNING_ON_VALGRIND) {
fprintf(stderr, "This test can only usefully be run inside valgrind.\n"); fprintf(stderr, "This test can only usefully be run inside valgrind.\n");
@ -67,6 +75,17 @@ int main(void) {
CHECK(ret == 1); CHECK(ret == 1);
#endif #endif
#if ENABLE_MODULE_RECOVERY
/* Test signing a recoverable signature. */
VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
ret = secp256k1_ecdsa_sign_recoverable(ctx, &recoverable_signature, msg, key, NULL, NULL);
VALGRIND_MAKE_MEM_DEFINED(&recoverable_signature, sizeof(recoverable_signature));
VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret));
CHECK(ret);
CHECK(secp256k1_ecdsa_recoverable_signature_serialize_compact(ctx, sig, &recid, &recoverable_signature));
CHECK(recid >= 0 && recid <= 3);
#endif
VALGRIND_MAKE_MEM_UNDEFINED(key, 32); VALGRIND_MAKE_MEM_UNDEFINED(key, 32);
ret = secp256k1_ec_seckey_verify(ctx, key); ret = secp256k1_ec_seckey_verify(ctx, key);
VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret));