diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index bc3327cdb22a19..2fac9701f44bd2 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -810,7 +810,7 @@ bool LegacyScriptPubKeyMan::AddKeyPubKeyInner(const CKey& key, const CPubKey &pu std::vector vchCryptedSecret; CKeyingMaterial vchSecret(key.begin(), key.end()); - if (!EncryptSecret(m_storage.GetEncryptionKey(), vchSecret, pubkey.GetHash(), vchCryptedSecret)) { + if (!m_storage.EncryptSecret(vchSecret, pubkey.GetHash(), vchCryptedSecret)) { return false; } @@ -996,7 +996,7 @@ bool LegacyScriptPubKeyMan::GetKey(const CKeyID &address, CKey& keyOut) const { const CPubKey &vchPubKey = (*mi).second.first; const std::vector &vchCryptedSecret = (*mi).second.second; - return DecryptKey(m_storage.GetEncryptionKey(), vchCryptedSecret, vchPubKey, keyOut); + return m_storage.DecryptKey(vchCryptedSecret, vchPubKey, keyOut); } return false; } @@ -2126,7 +2126,7 @@ std::map DescriptorScriptPubKeyMan::GetKeys() const const CPubKey& pubkey = key_pair.second.first; const std::vector& crypted_secret = key_pair.second.second; CKey key; - DecryptKey(m_storage.GetEncryptionKey(), crypted_secret, pubkey, key); + m_storage.DecryptKey(crypted_secret, pubkey, key); keys[pubkey.GetID()] = key; } return keys; @@ -2252,7 +2252,7 @@ bool DescriptorScriptPubKeyMan::AddDescriptorKeyWithDB(WalletBatch& batch, const std::vector crypted_secret; CKeyingMaterial secret(key.begin(), key.end()); - if (!EncryptSecret(m_storage.GetEncryptionKey(), secret, pubkey.GetHash(), crypted_secret)) { + if (!m_storage.EncryptSecret(secret, pubkey.GetHash(), crypted_secret)) { return false; } diff --git a/src/wallet/scriptpubkeyman.h b/src/wallet/scriptpubkeyman.h index 7c0eca1475efe7..e8f70095a16871 100644 --- a/src/wallet/scriptpubkeyman.h +++ b/src/wallet/scriptpubkeyman.h @@ -46,7 +46,8 @@ class WalletStorage virtual void UnsetBlankWalletFlag(WalletBatch&) = 0; virtual bool CanSupportFeature(enum WalletFeature) const = 0; virtual void SetMinVersion(enum WalletFeature, WalletBatch* = nullptr) = 0; - virtual const CKeyingMaterial& GetEncryptionKey() const = 0; + virtual bool EncryptSecret(const CKeyingMaterial& plaintext, const uint256& iv, std::vector& ciphertext) const = 0; + virtual bool DecryptKey(const std::vector& crypted_secret, const CPubKey& pub_key, CKey& key) const = 0; virtual bool HasEncryptionKeys() const = 0; virtual bool IsLocked() const = 0; }; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 162d7f9ec70590..8dea411a210ad9 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3515,9 +3515,16 @@ void CWallet::SetupLegacyScriptPubKeyMan() AddScriptPubKeyMan(id, std::move(spk_manager)); } -const CKeyingMaterial& CWallet::GetEncryptionKey() const +bool CWallet::EncryptSecret(const CKeyingMaterial& plaintext, const uint256& iv, std::vector& ciphertext) const { - return vMasterKey; + LOCK(cs_wallet); + return ::wallet::EncryptSecret(vMasterKey, plaintext, iv, ciphertext); +} + +bool CWallet::DecryptKey(const std::vector& crypted_secret, const CPubKey& pub_key, CKey& key) const +{ + LOCK(cs_wallet); + return ::wallet::DecryptKey(vMasterKey, crypted_secret, pub_key, key); } bool CWallet::HasEncryptionKeys() const diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 9333493a6eebc3..50cf0cfaa07787 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -949,7 +949,10 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati //! Make a LegacyScriptPubKeyMan and set it for all types, internal, and external. void SetupLegacyScriptPubKeyMan(); - const CKeyingMaterial& GetEncryptionKey() const override; + bool EncryptSecret(const CKeyingMaterial& plaintext, const uint256& iv, std::vector& ciphertext) const override; + + bool DecryptKey(const std::vector& crypted_secret, const CPubKey& pub_key, CKey& key) const override; + bool HasEncryptionKeys() const override; /** Get last block processed height */