mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-07-27 00:28:52 +02:00
key: validate BIP32 seed length in CExtKey::SetSeed
BIP32 specifies that seed must be between 128 and 512 bits (16 to 64 bytes). CExtKey::SetSeed currently accepts any length, including empty seeds, which could lead to weak master keys. Add an Assert at the start of SetSeed to enforce the valid seed length range. Fixes #35308
This commit is contained in:
@@ -367,6 +367,7 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
|
||||
|
||||
void CExtKey::SetSeed(std::span<const std::byte> seed)
|
||||
{
|
||||
Assert(16 <= seed.size() && seed.size() <= 64);
|
||||
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(UCharCast(seed.data()), seed.size()).Finalize(vout.data());
|
||||
|
||||
Reference in New Issue
Block a user