random: wipe hashers in MixExtract and Strengthen #36551

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:random-cleanse-hashers changing 1 files +2 −2
  1. fametrano commented at 6:19 AM on October 16, 2026: contributor

    RNGState::MixExtract() and Strengthen() call CSHA512::Reset() as a best-effort cleanup, but Reset() does not clear the hasher's 128-byte block buffer. After a GetRandBytes() call that buffer still holds the previous RNG state, and after Strengthen() it holds the chain value whose hash went into the outer hasher. Both are left on the stack.

    I replace the two Reset() calls with memory_cleanse() of the whole hasher, which leaves CSHA512 and its other users unchanged. A small program built from random.cpp finds the previous state in the hasher and the chain value on the stack before the change, and neither after. The unit tests pass.

  2. random: wipe hashers in MixExtract and Strengthen
    `CSHA512::Reset()` clears the state and the byte counter but not the
    128-byte block buffer. After `MixExtract()` that buffer can still hold
    the previous RNG state, as it does after every `GetRandBytes()` call.
    After `Strengthen()` the inner hasher's buffer holds the chain value
    whose hash was fed into the outer hasher.
    
    Wipe the whole hasher with `memory_cleanse()` instead of calling
    `Reset()` at the end of both functions. The hasher in `MixExtract()` is
    not used again by any caller.
    ab5d6f1163
  3. DrahtBot added the label Utils/log/libs on Oct 16, 2026
  4. DrahtBot commented at 6:19 AM on October 16, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. fametrano commented at 8:07 PM on October 16, 2026: contributor

    Closing in favour of #36550, which now cleanses CSHA512 in its destructor and so wipes these hashers when they go out of scope.

  6. fametrano closed this on Oct 16, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-18 11:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me