diff --git a/src/valgrind_ctime_test.c b/src/valgrind_ctime_test.c index b153f2f13..38c23d5b7 100644 --- a/src/valgrind_ctime_test.c +++ b/src/valgrind_ctime_test.c @@ -6,6 +6,7 @@ #include #include +#include #include "include/secp256k1.h" #include "assumptions.h" @@ -35,6 +36,10 @@ #include "include/secp256k1_ecdsa_adaptor.h" #endif +#ifdef ENABLE_MODULE_MUSIG +#include "include/secp256k1_musig.h" +#endif + void run_tests(secp256k1_context *ctx, unsigned char *key); int main(void) { @@ -241,4 +246,47 @@ void run_tests(secp256k1_context *ctx, unsigned char *key) { CHECK(ret == 0); } #endif + +#ifdef ENABLE_MODULE_MUSIG + { + secp256k1_xonly_pubkey pk; + const secp256k1_xonly_pubkey *pk_ptr[1]; + secp256k1_xonly_pubkey combined_pk; + unsigned char session_id[32]; + secp256k1_musig_secnonce secnonce; + unsigned char pubnonce[66]; + const unsigned char *pubnonce_ptr[1]; + secp256k1_musig_pre_session pre_session; + secp256k1_musig_session_cache session_cache; + secp256k1_musig_template sig_template; + secp256k1_musig_partial_signature partial_sig; + unsigned char extra_input[32]; + + pk_ptr[0] = &pk; + pubnonce_ptr[0] = pubnonce; + VALGRIND_MAKE_MEM_DEFINED(key, 32); + memcpy(session_id, key, sizeof(session_id)); + session_id[0] = key[0] + 1; + memcpy(extra_input, session_id, sizeof(extra_input)); + extra_input[0] = session_id[0] + 1; + + CHECK(secp256k1_keypair_create(ctx, &keypair, key)); + CHECK(secp256k1_keypair_xonly_pub(ctx, &pk, NULL, &keypair)); + CHECK(secp256k1_musig_pubkey_combine(ctx, NULL, &combined_pk, &pre_session, pk_ptr, 1) == 1); + VALGRIND_MAKE_MEM_UNDEFINED(key, 32); + VALGRIND_MAKE_MEM_UNDEFINED(session_id, 32); + VALGRIND_MAKE_MEM_UNDEFINED(extra_input, 32); + ret = secp256k1_musig_session_init(ctx, &secnonce, pubnonce, session_id, key, msg, &combined_pk, extra_input); + VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); + CHECK(ret == 1); + CHECK(secp256k1_musig_process_nonces(ctx, &session_cache, &sig_template, NULL, pubnonce_ptr, 1, msg, &combined_pk, &pre_session, NULL) == 1); + + ret = secp256k1_keypair_create(ctx, &keypair, key); + VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); + CHECK(ret == 1); + ret = secp256k1_musig_partial_sign(ctx, &partial_sig, &secnonce, &keypair, &pre_session, &session_cache); + VALGRIND_MAKE_MEM_DEFINED(&ret, sizeof(ret)); + CHECK(ret == 1); + } +#endif }