diff options
author | Pieter Wuille <pieter@wuille.net> | 2020-06-18 17:19:46 -0700 |
---|---|---|
committer | Pieter Wuille <pieter@wuille.net> | 2020-07-30 13:57:54 -0700 |
commit | 02c4cc5c5ddf61f98ee366a4bea8abc26de492bd (patch) | |
tree | 71a25d64248ffeac24259ddbe328481e9125020d /src/hash.h | |
parent | 0ef97b1b103231db54e04a64bbdb5dcc3f34f482 (diff) |
Make CHash256/CHash160 output to Span
Diffstat (limited to 'src/hash.h')
-rw-r--r-- | src/hash.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/hash.h b/src/hash.h index e93146f92c..409c84ba30 100644 --- a/src/hash.h +++ b/src/hash.h @@ -25,10 +25,11 @@ private: public: static const size_t OUTPUT_SIZE = CSHA256::OUTPUT_SIZE; - void Finalize(unsigned char hash[OUTPUT_SIZE]) { + void Finalize(Span<unsigned char> output) { + assert(output.size() == OUTPUT_SIZE); unsigned char buf[CSHA256::OUTPUT_SIZE]; sha.Finalize(buf); - sha.Reset().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(hash); + sha.Reset().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(output.data()); } CHash256& Write(Span<const unsigned char> input) { @@ -49,10 +50,11 @@ private: public: static const size_t OUTPUT_SIZE = CRIPEMD160::OUTPUT_SIZE; - void Finalize(unsigned char hash[OUTPUT_SIZE]) { + void Finalize(Span<unsigned char> output) { + assert(output.size() == OUTPUT_SIZE); unsigned char buf[CSHA256::OUTPUT_SIZE]; sha.Finalize(buf); - CRIPEMD160().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(hash); + CRIPEMD160().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(output.data()); } CHash160& Write(Span<const unsigned char> input) { @@ -73,7 +75,7 @@ inline uint256 Hash(const T1 pbegin, const T1 pend) static const unsigned char pblank[1] = {}; uint256 result; CHash256().Write({pbegin == pend ? pblank : (const unsigned char*)&pbegin[0], (pend - pbegin) * sizeof(pbegin[0])}) - .Finalize((unsigned char*)&result); + .Finalize(result); return result; } @@ -85,7 +87,7 @@ inline uint256 Hash(const T1 p1begin, const T1 p1end, uint256 result; CHash256().Write({p1begin == p1end ? pblank : (const unsigned char*)&p1begin[0], (p1end - p1begin) * sizeof(p1begin[0])}) .Write({p2begin == p2end ? pblank : (const unsigned char*)&p2begin[0], (p2end - p2begin) * sizeof(p2begin[0])}) - .Finalize((unsigned char*)&result); + .Finalize(result); return result; } @@ -96,7 +98,7 @@ inline uint160 Hash160(const T1 pbegin, const T1 pend) static unsigned char pblank[1] = {}; uint160 result; CHash160().Write({pbegin == pend ? pblank : (const unsigned char*)&pbegin[0], (pend - pbegin) * sizeof(pbegin[0])}) - .Finalize((unsigned char*)&result); + .Finalize(result); return result; } @@ -135,7 +137,7 @@ public: // invalidates the object uint256 GetHash() { uint256 result; - ctx.Finalize((unsigned char*)&result); + ctx.Finalize(result); return result; } |