mirror of
https://github.com/jmcorgan/fips.git
synced 2026-08-09 08:14:42 +00:00
BloomFilter derived all k hash functions from one SHA-256 digest but recomputed that digest inside the per-function loop, so every insert and contains ran SHA-256 hash_count times (5x at the default) over the same bytes. Hoist the digest out of the loop: base_hashes() computes it once and returns (h1, h2), and bit_index() derives each of the k indices with the same (h1 + k*h2) mod m arithmetic. Bit-for-bit identical output; this is the hottest path in packet forwarding and mesh-size estimation. Adds a test pinning the bit indices against the double-hashing formula recomputed independently, proving the refactor is behavior-neutral.