Merge bitcoin-core/secp256k1#1729: hash: Use size_t instead of int for RFC6979 outlen copy

960ba5f9c6 Use size_t instead of int for RFC6979 outlen copy (John Moffett)

Pull request description:

  If `outlen > INT_MAX` it results in segfault or hang (when `outlen` is a multiple of 2^32) on most implementations due to conversion in: `int now = outlen` producing negative values or zero. Unreachable in current code and highly improbable in future practice, but fits contract better and fixes a couple of compiler warnings.

ACKs for top commit:
  real-or-random:
    utACK 960ba5f9c6
  theStack:
    Code-review ACK 960ba5f9c6

Tree-SHA512: b91ee2fd3e962000f1b98a42e6f3c70cb3738c639fef8c2ce0cf53f49fe55da3e5d332eabbd8cbe9cdccb4e9c0ae70d3390a41f9468fd23ded3318596548c68f
This commit is contained in:
merge-script
2025-09-02 22:38:17 +02:00

View File

@@ -265,7 +265,7 @@ static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256
while (outlen > 0) { while (outlen > 0) {
secp256k1_hmac_sha256 hmac; secp256k1_hmac_sha256 hmac;
int now = outlen; size_t now = outlen;
secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32); secp256k1_hmac_sha256_initialize(&hmac, rng->k, 32);
secp256k1_hmac_sha256_write(&hmac, rng->v, 32); secp256k1_hmac_sha256_write(&hmac, rng->v, 32);
secp256k1_hmac_sha256_finalize(&hmac, rng->v); secp256k1_hmac_sha256_finalize(&hmac, rng->v);