MCPcopy Create free account
hub / github.com/LUX-Core/lux / EncryptHDChain

Method EncryptHDChain

src/crypter.cpp:389–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

387 return true;
388}
389bool CCryptoKeyStore::EncryptHDChain(const CKeyingMaterial& vMasterKeyIn)
390{
391 // should call EncryptKeys first
392 if (!IsCrypted())
393 return false;
394
395 if (!cryptedHDChain.IsNull())
396 return true;
397
398 if (cryptedHDChain.IsCrypted())
399 return true;
400
401 // make sure seed matches this chain
402 if (hdChain.GetID() != hdChain.GetSeedHash())
403 return false;
404
405 std::vector<unsigned char> vchCryptedSeed;
406 if (!EncryptSecret(vMasterKeyIn, hdChain.GetSeed(), hdChain.GetID(), vchCryptedSeed))
407 return false;
408
409 hdChain.Debug(__func__);
410 cryptedHDChain = hdChain;
411 cryptedHDChain.SetCrypted(true);
412
413 SecureVector vchSecureCryptedSeed(vchCryptedSeed.begin(), vchCryptedSeed.end());
414 if (!cryptedHDChain.SetSeed(vchSecureCryptedSeed, false))
415 return false;
416
417 SecureVector vchMnemonic;
418 SecureVector vchMnemonicPassphrase;
419
420 // it's ok to have no mnemonic if wallet was initialized via hdseed
421 if (hdChain.GetMnemonic(vchMnemonic, vchMnemonicPassphrase)) {
422 std::vector<unsigned char> vchCryptedMnemonic;
423 std::vector<unsigned char> vchCryptedMnemonicPassphrase;
424
425 if (!vchMnemonic.empty() && !EncryptSecret(vMasterKeyIn, vchMnemonic, hdChain.GetID(), vchCryptedMnemonic))
426 return false;
427 if (!vchMnemonicPassphrase.empty() && !EncryptSecret(vMasterKeyIn, vchMnemonicPassphrase, hdChain.GetID(), vchCryptedMnemonicPassphrase))
428 return false;
429
430 SecureVector vchSecureCryptedMnemonic(vchCryptedMnemonic.begin(), vchCryptedMnemonic.end());
431 SecureVector vchSecureCryptedMnemonicPassphrase(vchCryptedMnemonicPassphrase.begin(), vchCryptedMnemonicPassphrase.end());
432 if (!cryptedHDChain.SetMnemonic(vchSecureCryptedMnemonic, vchSecureCryptedMnemonicPassphrase, false))
433 return false;
434 }
435
436 if (!hdChain.SetNull())
437 return false;
438
439 return true;
440}
441
442bool CCryptoKeyStore::DecryptHDChain(CHDChain& hdChainRet) const
443{

Callers

nothing calls this directly

Calls 15

EncryptSecretFunction · 0.85
GetSeedHashMethod · 0.80
SetSeedMethod · 0.80
GetMnemonicMethod · 0.80
SetMnemonicMethod · 0.80
IsNullMethod · 0.45
IsCryptedMethod · 0.45
GetIDMethod · 0.45
GetSeedMethod · 0.45
DebugMethod · 0.45
SetCryptedMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected