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

Method DecryptHDChain

src/crypter.cpp:442–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

440}
441
442bool CCryptoKeyStore::DecryptHDChain(CHDChain& hdChainRet) const
443{
444 if (!IsCrypted())
445 return true;
446
447 if (cryptedHDChain.IsNull())
448 return false;
449
450 if (!cryptedHDChain.IsCrypted())
451 return false;
452
453 SecureVector vchSecureSeed;
454 SecureVector vchSecureCryptedSeed = cryptedHDChain.GetSeed();
455 std::vector<unsigned char> vchCryptedSeed(vchSecureCryptedSeed.begin(), vchSecureCryptedSeed.end());
456 if (!DecryptSecret(vMasterKey, vchCryptedSeed, cryptedHDChain.GetID(), vchSecureSeed))
457 return false;
458
459 hdChainRet = cryptedHDChain;
460 if (!hdChainRet.SetSeed(vchSecureSeed, false))
461 return false;
462
463 // hash of decrypted seed must match chain id
464 if (hdChainRet.GetSeedHash() != cryptedHDChain.GetID())
465 return false;
466
467 SecureVector vchSecureCryptedMnemonic;
468 SecureVector vchSecureCryptedMnemonicPassphrase;
469
470 // it's ok to have no mnemonic if wallet was initialized via hdseed
471 if (cryptedHDChain.GetMnemonic(vchSecureCryptedMnemonic, vchSecureCryptedMnemonicPassphrase)) {
472 SecureVector vchSecureMnemonic;
473 SecureVector vchSecureMnemonicPassphrase;
474
475 std::vector<unsigned char> vchCryptedMnemonic(vchSecureCryptedMnemonic.begin(), vchSecureCryptedMnemonic.end());
476 std::vector<unsigned char> vchCryptedMnemonicPassphrase(vchSecureCryptedMnemonicPassphrase.begin(), vchSecureCryptedMnemonicPassphrase.end());
477
478 if (!vchCryptedMnemonic.empty() && !DecryptSecret(vMasterKey, vchCryptedMnemonic, cryptedHDChain.GetID(), vchSecureMnemonic))
479 return false;
480 if (!vchCryptedMnemonicPassphrase.empty() && !DecryptSecret(vMasterKey, vchCryptedMnemonicPassphrase, cryptedHDChain.GetID(), vchSecureMnemonicPassphrase))
481 return false;
482
483 if (!hdChainRet.SetMnemonic(vchSecureMnemonic, vchSecureMnemonicPassphrase, false))
484 return false;
485 }
486
487 hdChainRet.SetCrypted(false);
488 hdChainRet.Debug(__func__);
489
490 return true;
491}
492
493bool CCryptoKeyStore::SetHDChain(const CHDChain& chain)
494{

Callers

nothing calls this directly

Calls 14

DecryptSecretFunction · 0.85
SetSeedMethod · 0.80
GetSeedHashMethod · 0.80
GetMnemonicMethod · 0.80
SetMnemonicMethod · 0.80
IsNullMethod · 0.45
IsCryptedMethod · 0.45
GetSeedMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
GetIDMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected