From 7699fe9aa6dbf9f7b3273ae919c0ca6eafba953e Mon Sep 17 00:00:00 2001 From: DarkWindman Date: Thu, 26 Feb 2026 14:35:11 +0200 Subject: [PATCH] modules: Port bitcoin-core/secp256k1#1735 to zkp-specific code --- src/modules/ecdsa_s2c/main_impl.h | 2 +- src/modules/generator/pedersen_impl.h | 2 +- src/modules/rangeproof/borromean_impl.h | 2 +- src/modules/rangeproof/rangeproof_impl.h | 8 ++++---- src/modules/surjection/surjection_impl.h | 4 ++-- src/modules/whitelist/main_impl.h | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/modules/ecdsa_s2c/main_impl.h b/src/modules/ecdsa_s2c/main_impl.h index 471ae8fb..59a4cdfa 100644 --- a/src/modules/ecdsa_s2c/main_impl.h +++ b/src/modules/ecdsa_s2c/main_impl.h @@ -182,7 +182,7 @@ int secp256k1_ecdsa_anti_exfil_signer_commit(const secp256k1_context* ctx, secp2 secp256k1_ecmult_gen(&ctx->ecmult_gen_ctx, &rj, &k); secp256k1_ge_set_gej(&r, &rj); secp256k1_ecdsa_s2c_opening_save(opening, &r); - secp256k1_memclear(nonce32, 32); + secp256k1_memclear_explicit(nonce32, 32); secp256k1_scalar_clear(&k); return 1; } diff --git a/src/modules/generator/pedersen_impl.h b/src/modules/generator/pedersen_impl.h index f5526eb6..7d2a8a27 100644 --- a/src/modules/generator/pedersen_impl.h +++ b/src/modules/generator/pedersen_impl.h @@ -28,7 +28,7 @@ static void secp256k1_pedersen_scalar_set_u64(secp256k1_scalar *sec, uint64_t va value <<= 8; } secp256k1_scalar_set_b32(sec, data, NULL); - secp256k1_memclear(data, 32); + secp256k1_memclear_explicit(data, 32); } static void secp256k1_pedersen_ecmult_small(secp256k1_gej *r, uint64_t gn, const secp256k1_ge* genp) { diff --git a/src/modules/rangeproof/borromean_impl.h b/src/modules/rangeproof/borromean_impl.h index 3ca86108..4906ce85 100644 --- a/src/modules/rangeproof/borromean_impl.h +++ b/src/modules/rangeproof/borromean_impl.h @@ -192,7 +192,7 @@ int secp256k1_borromean_sign(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_scalar_clear(&ens); secp256k1_ge_clear(&rge); secp256k1_gej_clear(&rgej); - secp256k1_memclear(tmp, 33); + secp256k1_memclear_explicit(tmp, 33); return 1; } diff --git a/src/modules/rangeproof/rangeproof_impl.h b/src/modules/rangeproof/rangeproof_impl.h index fc12ad4f..476da5eb 100644 --- a/src/modules/rangeproof/rangeproof_impl.h +++ b/src/modules/rangeproof/rangeproof_impl.h @@ -107,7 +107,7 @@ SECP256K1_INLINE static int secp256k1_rangeproof_genrand(secp256k1_scalar *sec, secp256k1_rfc6979_hmac_sha256_finalize(&rng); secp256k1_rfc6979_hmac_sha256_clear(&rng); secp256k1_scalar_clear(&acc); - secp256k1_memclear(tmp, 32); + secp256k1_memclear_explicit(tmp, 32); return ret; } @@ -270,7 +270,7 @@ SECP256K1_INLINE static int secp256k1_rangeproof_sign_impl(const secp256k1_ecmul if (!secp256k1_rangeproof_genrand(sec, s, prep, rsizes, rings, nonce, commit, proof, len, genp)) { return 0; } - secp256k1_memclear(prep, 4096); + secp256k1_memclear_explicit(prep, 4096); for (i = 0; i < rings; i++) { /* Sign will overwrite the non-forged signature, move that random value into the nonce. */ k[i] = s[i * 4 + secidx[i]]; @@ -332,7 +332,7 @@ SECP256K1_INLINE static int secp256k1_rangeproof_sign_impl(const secp256k1_ecmul } VERIFY_CHECK(len <= *plen); *plen = len; - secp256k1_memclear(prep, 4096); + secp256k1_memclear_explicit(prep, 4096); return 1; } @@ -473,7 +473,7 @@ SECP256K1_INLINE static int secp256k1_rangeproof_rewind_inner(secp256k1_scalar * } } *mlen = offset; - secp256k1_memclear(prep, 4096); + secp256k1_memclear_explicit(prep, 4096); for (i = 0; i < 128; i++) { secp256k1_scalar_clear(&s_orig[i]); } diff --git a/src/modules/surjection/surjection_impl.h b/src/modules/surjection/surjection_impl.h index cc0ad300..0776e4c8 100644 --- a/src/modules/surjection/surjection_impl.h +++ b/src/modules/surjection/surjection_impl.h @@ -55,11 +55,11 @@ SECP256K1_INLINE static int secp256k1_surjection_genrand(secp256k1_scalar *s, si secp256k1_sha256_clear(&sha256_en); secp256k1_scalar_set_b32(&s[i], sec_input, &overflow); if (overflow == 1) { - secp256k1_memclear(sec_input, 32); + secp256k1_memclear_explicit(sec_input, 32); return 0; } } - secp256k1_memclear(sec_input, 32); + secp256k1_memclear_explicit(sec_input, 32); return 1; } diff --git a/src/modules/whitelist/main_impl.h b/src/modules/whitelist/main_impl.h index ce94d23a..301d2476 100644 --- a/src/modules/whitelist/main_impl.h +++ b/src/modules/whitelist/main_impl.h @@ -54,7 +54,7 @@ int secp256k1_whitelist_sign(const secp256k1_context* ctx, secp256k1_whitelist_s break; } secp256k1_scalar_set_b32(&non, nonce32, &overflow); - secp256k1_memclear(nonce32, 32); + secp256k1_memclear_explicit(nonce32, 32); if (overflow || secp256k1_scalar_is_zero(&non)) { count++; continue; @@ -80,7 +80,7 @@ int secp256k1_whitelist_sign(const secp256k1_context* ctx, secp256k1_whitelist_s break; } } - secp256k1_memclear(seckey32, 32); + secp256k1_memclear_explicit(seckey32, 32); } /* Actually sign */ if (ret) {