Skip to content

Commit b475d7d

Browse files
committed
Add single sha256 call to CHashWriter
1 parent 82127d2 commit b475d7d

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/hash.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ inline uint160 Hash160(const T1& in1)
9898
class CHashWriter
9999
{
100100
private:
101-
CHash256 ctx;
101+
CSHA256 ctx;
102102

103103
const int nType;
104104
const int nVersion;
@@ -110,23 +110,36 @@ class CHashWriter
110110
int GetVersion() const { return nVersion; }
111111

112112
void write(const char *pch, size_t size) {
113-
ctx.Write({(const unsigned char*)pch, size});
113+
ctx.Write((const unsigned char*)pch, size);
114114
}
115115

116-
// invalidates the object
116+
/** Compute the double-SHA256 hash of all data written to this object.
117+
*
118+
* Invalidates this object.
119+
*/
117120
uint256 GetHash() {
118121
uint256 result;
119-
ctx.Finalize(result);
122+
ctx.Finalize(result.begin());
123+
ctx.Reset().Write(result.begin(), CSHA256::OUTPUT_SIZE).Finalize(result.begin());
124+
return result;
125+
}
126+
127+
/** Compute the SHA256 hash of all data written to this object.
128+
*
129+
* Invalidates this object.
130+
*/
131+
uint256 GetSHA256() {
132+
uint256 result;
133+
ctx.Finalize(result.begin());
120134
return result;
121135
}
122136

123137
/**
124138
* Returns the first 64 bits from the resulting hash.
125139
*/
126140
inline uint64_t GetCheapHash() {
127-
unsigned char result[CHash256::OUTPUT_SIZE];
128-
ctx.Finalize(result);
129-
return ReadLE64(result);
141+
uint256 result = GetHash();
142+
return ReadLE64(result.begin());
130143
}
131144

132145
template<typename T>

0 commit comments

Comments
 (0)