modules: Port bitcoin-core/secp256k1#1735 to zkp-specific code

This commit is contained in:
DarkWindman
2026-02-26 14:35:11 +02:00
parent f1e52fac20
commit 7699fe9aa6
6 changed files with 11 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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]);
}

View File

@@ -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;
}

View File

@@ -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) {