mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
refactor: Use Span of std::byte in CExtKey::SetSeed
This commit is contained in:
parent
fae1006019
commit
facd1fb911
4 changed files with 8 additions and 7 deletions
|
@ -340,11 +340,11 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
|
|||
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
|
||||
}
|
||||
|
||||
void CExtKey::SetSeed(Span<const uint8_t> seed)
|
||||
void CExtKey::SetSeed(Span<const std::byte> 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.data(), seed.size()).Finalize(vout.data());
|
||||
CHMAC_SHA512{hashkey, sizeof(hashkey)}.Write(UCharCast(seed.data()), seed.size()).Finalize(vout.data());
|
||||
key.Set(vout.data(), vout.data() + 32, true);
|
||||
memcpy(chaincode.begin(), vout.data() + 32, 32);
|
||||
nDepth = 0;
|
||||
|
|
|
@ -85,7 +85,7 @@ public:
|
|||
|
||||
//! Simple read-only vector-like interface.
|
||||
unsigned int size() const { return (fValid ? keydata.size() : 0); }
|
||||
const unsigned char* data() const { return keydata.data(); }
|
||||
const std::byte* data() const { return reinterpret_cast<const std::byte*>(keydata.data()); }
|
||||
const unsigned char* begin() const { return keydata.data(); }
|
||||
const unsigned char* end() const { return keydata.data() + size(); }
|
||||
|
||||
|
@ -178,7 +178,7 @@ struct CExtKey {
|
|||
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
|
||||
bool Derive(CExtKey& out, unsigned int nChild) const;
|
||||
CExtPubKey Neuter() const;
|
||||
void SetSeed(Span<const uint8_t> seed);
|
||||
void SetSeed(Span<const std::byte> seed);
|
||||
};
|
||||
|
||||
/** Initialize the elliptic curve support. May not be called twice without calling ECC_Stop first. */
|
||||
|
|
|
@ -120,8 +120,9 @@ const std::vector<std::string> TEST5 = {
|
|||
"xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHL"
|
||||
};
|
||||
|
||||
void RunTest(const TestVector &test) {
|
||||
std::vector<unsigned char> seed = ParseHex(test.strHexMaster);
|
||||
void RunTest(const TestVector& test)
|
||||
{
|
||||
std::vector<std::byte> seed{ParseHex<std::byte>(test.strHexMaster)};
|
||||
CExtKey key;
|
||||
CExtPubKey pubkey;
|
||||
key.SetSeed(seed);
|
||||
|
|
|
@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse)
|
|||
continue;
|
||||
}
|
||||
std::string exp_base58string = test[0].get_str();
|
||||
std::vector<unsigned char> exp_payload = ParseHex(test[1].get_str());
|
||||
const std::vector<std::byte> exp_payload{ParseHex<std::byte>(test[1].get_str())};
|
||||
const UniValue &metadata = test[2].get_obj();
|
||||
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
|
||||
SelectParams(find_value(metadata, "chain").get_str());
|
||||
|
|
Loading…
Add table
Reference in a new issue