mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
optimization: migrate SipHashUint256 to PresaltedSipHasher
Replaces standalone `SipHashUint256` with an `operator()` overload in `PresaltedSipHasher`. Updates all hasher classes (`SaltedUint256Hasher`, `SaltedTxidHasher`, `SaltedWtxidHasher`) to use `PresaltedSipHasher` internally, enabling the same constant-state caching optimization while keeping behavior unchanged. Benchmark was also adjusted to cache the salting part.
This commit is contained in:
@@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(siphash)
|
||||
hasher.Write(0x2F2E2D2C2B2A2928ULL);
|
||||
BOOST_CHECK_EQUAL(hasher.Finalize(), 0xe612a3cb9ecba951ull);
|
||||
|
||||
BOOST_CHECK_EQUAL(SipHashUint256(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL, uint256{"1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"}), 0x7127512f72f27cceull);
|
||||
BOOST_CHECK_EQUAL(PresaltedSipHasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL)(uint256{"1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100"}), 0x7127512f72f27cceull);
|
||||
|
||||
// Check test vectors from spec, one byte at a time
|
||||
CSipHasher hasher2(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL);
|
||||
@@ -128,9 +128,9 @@ BOOST_AUTO_TEST_CASE(siphash)
|
||||
// and the test would be affected by default tx version bumps if not fixed.
|
||||
tx.version = 1;
|
||||
ss << TX_WITH_WITNESS(tx);
|
||||
BOOST_CHECK_EQUAL(SipHashUint256(1, 2, ss.GetHash()), 0x79751e980c2a0a35ULL);
|
||||
BOOST_CHECK_EQUAL(PresaltedSipHasher(1, 2)(ss.GetHash()), 0x79751e980c2a0a35ULL);
|
||||
|
||||
// Check consistency between CSipHasher and SipHashUint256 and PresaltedSipHasher.
|
||||
// Check consistency between CSipHasher and PresaltedSipHasher.
|
||||
FastRandomContext ctx;
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
uint64_t k0 = ctx.rand64();
|
||||
@@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(siphash)
|
||||
|
||||
CSipHasher sip256(k0, k1);
|
||||
sip256.Write(x);
|
||||
BOOST_CHECK_EQUAL(SipHashUint256(k0, k1, x), sip256.Finalize()); // TODO modified in follow-up commit
|
||||
BOOST_CHECK_EQUAL(PresaltedSipHasher(k0, k1)(x), sip256.Finalize());
|
||||
|
||||
CSipHasher sip288 = sip256;
|
||||
uint32_t n = ctx.rand32();
|
||||
|
||||
Reference in New Issue
Block a user