This commit is contained in:
DarkWindman
2026-02-26 14:24:06 +02:00
36 changed files with 1138 additions and 574 deletions

View File

@@ -385,10 +385,10 @@ static void secp256k1_nonce_function_musig(secp256k1_scalar *k, const unsigned c
secp256k1_scalar_set_b32(&k[i], buf, NULL);
/* Attempt to erase secret data */
secp256k1_memclear(buf, sizeof(buf));
secp256k1_memclear_explicit(buf, sizeof(buf));
secp256k1_sha256_clear(&sha_tmp);
}
secp256k1_memclear(rand, sizeof(rand));
secp256k1_memclear_explicit(rand, sizeof(rand));
secp256k1_sha256_clear(&sha);
}
@@ -518,7 +518,7 @@ int secp256k1_musig_nonce_gen_counter(const secp256k1_context* ctx, secp256k1_mu
if (!secp256k1_musig_nonce_gen_internal(ctx, secnonce, pubnonce, buf, seckey, &pubkey, msg32, keyagg_cache, extra_input32)) {
return 0;
}
secp256k1_memclear(seckey, sizeof(seckey));
secp256k1_memclear_explicit(seckey, sizeof(seckey));
return 1;
}
@@ -691,7 +691,7 @@ int secp256k1_musig_partial_sign(const secp256k1_context* ctx, secp256k1_musig_p
ret = secp256k1_musig_secnonce_load(ctx, k, &pk, secnonce);
/* Set nonce to zero to avoid nonce reuse. This will cause subsequent calls
* of this function to fail */
memset(secnonce, 0, sizeof(*secnonce));
secp256k1_memzero_explicit(secnonce, sizeof(*secnonce));
if (!ret) {
secp256k1_musig_partial_sign_clear(&sk, k);
return 0;

View File

@@ -20,6 +20,7 @@
#include "../../group.h"
#include "../../hash.h"
#include "../../util.h"
#include "../../unit_test.h"
#include "vectors.h"
@@ -36,7 +37,7 @@ static int create_keypair_and_pk(secp256k1_keypair *keypair, secp256k1_pubkey *p
/* Just a simple (non-adaptor, non-tweaked) 2-of-2 MuSig aggregate, sign, verify
* test. */
static void musig_simple_test(void) {
static void musig_simple_test_internal(void) {
unsigned char sk[2][32];
secp256k1_keypair keypair[2];
secp256k1_musig_pubnonce pubnonce[2];
@@ -591,7 +592,7 @@ static void musig_nonce_test(void) {
}
}
static void scriptless_atomic_swap(void) {
static void scriptless_atomic_swap_internal(void) {
/* Throughout this test "a" and "b" refer to two hypothetical blockchains,
* while the indices 0 and 1 refer to the two signers. Here signer 0 is
* sending a-coins to signer 1, while signer 1 is sending b-coins to signer
@@ -777,7 +778,7 @@ static void musig_tweak_test_helper(const secp256k1_xonly_pubkey* agg_pk, const
/* Create aggregate public key P[0], tweak multiple times (using xonly and
* plain tweaking) and test signing. */
static void musig_tweak_test(void) {
static void musig_tweak_test_internal(void) {
unsigned char sk[2][32];
secp256k1_pubkey pk[2];
const secp256k1_pubkey *pk_ptr[2];
@@ -1262,29 +1263,26 @@ static void musig_test_static_nonce_gen_counter(void) {
CHECK(secp256k1_memcmp_var(pubnonce66, expected_pubnonce, sizeof(pubnonce66)) == 0);
}
static void run_musig_tests(void) {
int i;
/* --- Test registry --- */
REPEAT_TEST(musig_simple_test)
/* Run multiple times to ensure that pk and nonce have different y parities */
REPEAT_TEST(scriptless_atomic_swap)
REPEAT_TEST(musig_tweak_test)
for (i = 0; i < COUNT; i++) {
musig_simple_test();
}
musig_api_tests();
musig_nonce_test();
for (i = 0; i < COUNT; i++) {
/* Run multiple times to ensure that pk and nonce have different y
* parities */
scriptless_atomic_swap();
musig_tweak_test();
}
sha256_tag_test();
musig_test_vectors_keyagg();
musig_test_vectors_noncegen();
musig_test_vectors_nonceagg();
musig_test_vectors_signverify();
musig_test_vectors_tweak();
musig_test_vectors_sigagg();
musig_test_static_nonce_gen_counter();
}
static const struct tf_test_entry tests_musig[] = {
CASE1(musig_simple_test),
CASE1(musig_api_tests),
CASE1(musig_nonce_test),
CASE1(scriptless_atomic_swap),
CASE1(musig_tweak_test),
CASE1(sha256_tag_test),
CASE1(musig_test_vectors_keyagg),
CASE1(musig_test_vectors_noncegen),
CASE1(musig_test_vectors_nonceagg),
CASE1(musig_test_vectors_signverify),
CASE1(musig_test_vectors_tweak),
CASE1(musig_test_vectors_sigagg),
CASE1(musig_test_static_nonce_gen_counter),
};
#endif