From 73596a85a2ab9c885e58a7a2a8876355a6ae68e4 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Wed, 27 May 2020 00:38:46 +0300 Subject: [PATCH] Add ecdsa_sign_recoverable to the ctime tests --- src/valgrind_ctime_test.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/valgrind_ctime_test.c b/src/valgrind_ctime_test.c index 5d26244dba0a4..60a82d599e8f9 100644 --- a/src/valgrind_ctime_test.c +++ b/src/valgrind_ctime_test.c @@ -12,6 +12,10 @@ # include "include/secp256k1_ecdh.h" #endif +#if ENABLE_MODULE_RECOVERY +# include "include/secp256k1_recovery.h" +#endif + int main(void) { secp256k1_context* ctx; secp256k1_ecdsa_signature signature; @@ -24,6 +28,10 @@ int main(void) { unsigned char key[32]; unsigned char sig[74]; unsigned char spubkey[33]; +#if ENABLE_MODULE_RECOVERY + secp256k1_ecdsa_recoverable_signature recoverable_signature; + int recid; +#endif if (!RUNNING_ON_VALGRIND) { fprintf(stderr, "This test can only usefully be run inside valgrind.\n"); @@ -67,6 +75,17 @@ int main(void) { CHECK(ret == 1); #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); ret = secp256k1_ec_seckey_verify(ctx, key); VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret));