From 8479eafa5720421d4b7f4b524a35e0a7edf291c7 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 28 Apr 2026 22:58:11 +0200 Subject: [PATCH] musig: always clear out secret key in `secp256k1_musig_nonce_gen_counter` Even though `secp256k1_musig_nonce_gen_internal` can currently only fail if the API is misused (invalid `keypair` or `keyagg_cache` parameters), clear out the buffer holding secret key data as well in this case to follow best practices. The issue was found and reported by l0rinc using GPT 5.5 (Thanks!). --- src/modules/musig/session_impl.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/musig/session_impl.h b/src/modules/musig/session_impl.h index 6a37bfdf..510ee89f 100644 --- a/src/modules/musig/session_impl.h +++ b/src/modules/musig/session_impl.h @@ -483,11 +483,9 @@ int secp256k1_musig_nonce_gen_counter(const secp256k1_context* ctx, secp256k1_mu (void) ret; #endif - if (!secp256k1_musig_nonce_gen_internal(ctx, secnonce, pubnonce, buf, seckey, &pubkey, msg32, keyagg_cache, extra_input32)) { - return 0; - } + ret = secp256k1_musig_nonce_gen_internal(ctx, secnonce, pubnonce, buf, seckey, &pubkey, msg32, keyagg_cache, extra_input32); secp256k1_memclear_explicit(seckey, sizeof(seckey)); - return 1; + return ret; } static int secp256k1_musig_sum_pubnonces(const secp256k1_context* ctx, secp256k1_gej *summed_pubnonces, const secp256k1_musig_pubnonce * const* pubnonces, size_t n_pubnonces) {