mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Add single sha256 call to CHashWriter
This commit is contained in:
parent
82127d27c9
commit
b475d7d0fa
1 changed files with 20 additions and 7 deletions
27
src/hash.h
27
src/hash.h
|
@ -98,7 +98,7 @@ inline uint160 Hash160(const T1& in1)
|
||||||
class CHashWriter
|
class CHashWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CHash256 ctx;
|
CSHA256 ctx;
|
||||||
|
|
||||||
const int nType;
|
const int nType;
|
||||||
const int nVersion;
|
const int nVersion;
|
||||||
|
@ -110,13 +110,27 @@ public:
|
||||||
int GetVersion() const { return nVersion; }
|
int GetVersion() const { return nVersion; }
|
||||||
|
|
||||||
void write(const char *pch, size_t size) {
|
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 GetHash() {
|
||||||
uint256 result;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,9 +138,8 @@ public:
|
||||||
* Returns the first 64 bits from the resulting hash.
|
* Returns the first 64 bits from the resulting hash.
|
||||||
*/
|
*/
|
||||||
inline uint64_t GetCheapHash() {
|
inline uint64_t GetCheapHash() {
|
||||||
unsigned char result[CHash256::OUTPUT_SIZE];
|
uint256 result = GetHash();
|
||||||
ctx.Finalize(result);
|
return ReadLE64(result.begin());
|
||||||
return ReadLE64(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
Loading…
Add table
Reference in a new issue