aboutsummaryrefslogtreecommitdiff
path: root/src/hash.h
diff options
context:
space:
mode:
authorJeremy Rubin <j@rubin.io>2019-10-07 13:45:00 -0700
committerJeremy Rubin <j@rubin.io>2020-08-06 16:28:26 -0700
commitb475d7d0fa000d5802caf3065b8b2abcea60719b (patch)
treecbbd801ecf1918ea300f38f043d97f6684637ad4 /src/hash.h
parent82127d27c9001eee3eb28df67ce2e6eace620423 (diff)
downloadbitcoin-b475d7d0fa000d5802caf3065b8b2abcea60719b.tar.xz
Add single sha256 call to CHashWriter
Diffstat (limited to 'src/hash.h')
-rw-r--r--src/hash.h27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/hash.h b/src/hash.h
index 71806483ff..4f392fa0aa 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -98,7 +98,7 @@ inline uint160 Hash160(const T1& in1)
class CHashWriter
{
private:
- CHash256 ctx;
+ CSHA256 ctx;
const int nType;
const int nVersion;
@@ -110,13 +110,27 @@ public:
int GetVersion() const { return nVersion; }
void write(const char *pch, size_t size) {
- ctx.Write({(const unsigned char*)pch, size});
+ ctx.Write((const unsigned char*)pch, size);
}
- // invalidates the object
+ /** Compute the double-SHA256 hash of all data written to this object.
+ *
+ * Invalidates this object.
+ */
uint256 GetHash() {
uint256 result;
- ctx.Finalize(result);
+ ctx.Finalize(result.begin());
+ ctx.Reset().Write(result.begin(), CSHA256::OUTPUT_SIZE).Finalize(result.begin());
+ return result;
+ }
+
+ /** Compute the SHA256 hash of all data written to this object.
+ *
+ * Invalidates this object.
+ */
+ uint256 GetSHA256() {
+ uint256 result;
+ ctx.Finalize(result.begin());
return result;
}
@@ -124,9 +138,8 @@ public:
* Returns the first 64 bits from the resulting hash.
*/
inline uint64_t GetCheapHash() {
- unsigned char result[CHash256::OUTPUT_SIZE];
- ctx.Finalize(result);
- return ReadLE64(result);
+ uint256 result = GetHash();
+ return ReadLE64(result.begin());
}
template<typename T>