refactor: Take Span in SetSeed

This makes calling code less verbose and less fragile. Also, by adding
the CKey::data() member function, it is now possible to call HexStr()
with a CKey object.
This commit is contained in:
MarcoFalke
2021-11-01 13:59:15 +01:00
parent 5574881ce3
commit fa93ef5a8a
7 changed files with 11 additions and 9 deletions

View File

@@ -319,10 +319,11 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
}
void CExtKey::SetSeed(const unsigned char *seed, unsigned int nSeedLen) {
void CExtKey::SetSeed(Span<const uint8_t> seed)
{
static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
CHMAC_SHA512(hashkey, sizeof(hashkey)).Write(seed, nSeedLen).Finalize(vout.data());
CHMAC_SHA512{hashkey, sizeof(hashkey)}.Write(seed.data(), seed.size()).Finalize(vout.data());
key.Set(vout.data(), vout.data() + 32, true);
memcpy(chaincode.begin(), vout.data() + 32, 32);
nDepth = 0;