diff options
author | Jeremy Rubin <j@rubin.io> | 2020-02-05 11:57:32 -0800 |
---|---|---|
committer | Jeremy Rubin <j@rubin.io> | 2020-08-06 16:28:26 -0700 |
commit | 6510d0ff4173a7b01d6728051303c7c38eb34533 (patch) | |
tree | 43d18ecb40cf20a459a03553b946fc2fc5aaf40d /src | |
parent | b475d7d0fa000d5802caf3065b8b2abcea60719b (diff) | |
download | bitcoin-6510d0ff4173a7b01d6728051303c7c38eb34533.tar.xz |
Add SHA256Uint256 helper functions
Diffstat (limited to 'src')
-rw-r--r-- | src/hash.cpp | 7 | ||||
-rw-r--r-- | src/hash.h | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/hash.cpp b/src/hash.cpp index 4c09f5f646..83b90ae063 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -77,3 +77,10 @@ void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char he num[3] = (nChild >> 0) & 0xFF; CHMAC_SHA512(chainCode.begin(), chainCode.size()).Write(&header, 1).Write(data, 32).Write(num, 4).Finalize(output); } + +uint256 SHA256Uint256(const uint256& input) +{ + uint256 result; + CSHA256().Write(input.begin(), 32).Finalize(result.begin()); + return result; +} diff --git a/src/hash.h b/src/hash.h index 4f392fa0aa..c16bbb48ce 100644 --- a/src/hash.h +++ b/src/hash.h @@ -6,6 +6,7 @@ #ifndef BITCOIN_HASH_H #define BITCOIN_HASH_H +#include <attributes.h> #include <crypto/common.h> #include <crypto/ripemd160.h> #include <crypto/sha256.h> @@ -194,6 +195,9 @@ uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL return ss.GetHash(); } +/** Single-SHA256 a 32-byte input (represented as uint256). */ +NODISCARD uint256 SHA256Uint256(const uint256& input); + unsigned int MurmurHash3(unsigned int nHashSeed, Span<const unsigned char> vDataToHash); void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]); |