aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-01-31 19:34:35 +0100
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2023-01-31 19:34:35 +0100
commit87f11ef47fea31d51bcc3f5df68f78fb28e3d8dd (patch)
tree49ce74175b7a0721a246f93ff2b091c390b0ae73
parentb5868f4b1f884e8d6612f34ca4005fe3a992053d (diff)
downloadbitcoin-87f11ef47fea31d51bcc3f5df68f78fb28e3d8dd.tar.xz
refactor: use `Hash` helper for double-SHA256 calculations
-rw-r--r--src/blockfilter.cpp15
-rw-r--r--src/index/blockfilterindex.cpp4
-rw-r--r--src/key.cpp3
-rw-r--r--src/test/key_tests.cpp3
-rw-r--r--src/test/merkle_tests.cpp6
5 files changed, 8 insertions, 23 deletions
diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp
index fc6dde20f9..88c7526b9e 100644
--- a/src/blockfilter.cpp
+++ b/src/blockfilter.cpp
@@ -247,21 +247,10 @@ bool BlockFilter::BuildParams(GCSFilter::Params& params) const
uint256 BlockFilter::GetHash() const
{
- const std::vector<unsigned char>& data = GetEncodedFilter();
-
- uint256 result;
- CHash256().Write(data).Finalize(result);
- return result;
+ return Hash(GetEncodedFilter());
}
uint256 BlockFilter::ComputeHeader(const uint256& prev_header) const
{
- const uint256& filter_hash = GetHash();
-
- uint256 result;
- CHash256()
- .Write(filter_hash)
- .Write(prev_header)
- .Finalize(result);
- return result;
+ return Hash(GetHash(), prev_header);
}
diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
index 07b4cdc06b..59bf6d34cf 100644
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -157,9 +157,7 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256&
std::vector<uint8_t> encoded_filter;
try {
filein >> block_hash >> encoded_filter;
- uint256 result;
- CHash256().Write(encoded_filter).Finalize(result);
- if (result != hash) return error("Checksum mismatch in filter decode.");
+ if (Hash(encoded_filter) != hash) return error("Checksum mismatch in filter decode.");
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
}
catch (const std::exception& e) {
diff --git a/src/key.cpp b/src/key.cpp
index 33913ed461..3a3f0b2bc2 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -245,8 +245,7 @@ bool CKey::VerifyPubKey(const CPubKey& pubkey) const {
unsigned char rnd[8];
std::string str = "Bitcoin key verification\n";
GetRandBytes(rnd);
- uint256 hash;
- CHash256().Write(MakeUCharSpan(str)).Write(rnd).Finalize(hash);
+ uint256 hash{Hash(str, rnd)};
std::vector<unsigned char> vchSig;
Sign(hash, vchSig);
return pubkey.Verify(hash, vchSig);
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp
index d14fda7351..edf28cfbfc 100644
--- a/src/test/key_tests.cpp
+++ b/src/test/key_tests.cpp
@@ -205,8 +205,7 @@ BOOST_AUTO_TEST_CASE(key_key_negation)
unsigned char rnd[8];
std::string str = "Bitcoin key verification\n";
GetRandBytes(rnd);
- uint256 hash;
- CHash256().Write(MakeUCharSpan(str)).Write(rnd).Finalize(hash);
+ uint256 hash{Hash(str, rnd)};
// import the static test key
CKey key = DecodeSecret(strSecret1C);
diff --git a/src/test/merkle_tests.cpp b/src/test/merkle_tests.cpp
index bba103d1b0..74e01fc2a5 100644
--- a/src/test/merkle_tests.cpp
+++ b/src/test/merkle_tests.cpp
@@ -60,7 +60,7 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
}
}
mutated |= (inner[level] == h);
- CHash256().Write(inner[level]).Write(h).Finalize(h);
+ h = Hash(inner[level], h);
}
// Store the resulting hash at inner position level.
inner[level] = h;
@@ -86,7 +86,7 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
if (pbranch && matchh) {
pbranch->push_back(h);
}
- CHash256().Write(h).Write(h).Finalize(h);
+ h = Hash(h, h);
// Increment count to the value it would have if two entries at this
// level had existed.
count += ((uint32_t{1}) << level);
@@ -101,7 +101,7 @@ static void MerkleComputation(const std::vector<uint256>& leaves, uint256* proot
matchh = true;
}
}
- CHash256().Write(inner[level]).Write(h).Finalize(h);
+ h = Hash(inner[level], h);
level++;
}
}