| 387 | return true; |
| 388 | } |
| 389 | bool 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 | |
| 442 | bool CCryptoKeyStore::DecryptHDChain(CHDChain& hdChainRet) const |
| 443 | { |
nothing calls this directly
no test coverage detected