Skip to content

Commit 6510d0f

Browse files
committed
Add SHA256Uint256 helper functions
1 parent b475d7d commit 6510d0f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/hash.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,10 @@ void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char he
7777
num[3] = (nChild >> 0) & 0xFF;
7878
CHMAC_SHA512(chainCode.begin(), chainCode.size()).Write(&header, 1).Write(data, 32).Write(num, 4).Finalize(output);
7979
}
80+
81+
uint256 SHA256Uint256(const uint256& input)
82+
{
83+
uint256 result;
84+
CSHA256().Write(input.begin(), 32).Finalize(result.begin());
85+
return result;
86+
}

src/hash.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BITCOIN_HASH_H
77
#define BITCOIN_HASH_H
88

9+
#include <attributes.h>
910
#include <crypto/common.h>
1011
#include <crypto/ripemd160.h>
1112
#include <crypto/sha256.h>
@@ -194,6 +195,9 @@ uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL
194195
return ss.GetHash();
195196
}
196197

198+
/** Single-SHA256 a 32-byte input (represented as uint256). */
199+
NODISCARD uint256 SHA256Uint256(const uint256& input);
200+
197201
unsigned int MurmurHash3(unsigned int nHashSeed, Span<const unsigned char> vDataToHash);
198202

199203
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]);

0 commit comments

Comments
 (0)