refactor: add helper function to decrypt messages with blsKeyOperator

This commit is contained in:
Kittywhiskers Van Gogh 2024-03-12 03:05:51 +00:00
parent 3eb931b596
commit 33702aca39
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
4 changed files with 19 additions and 5 deletions

View File

@ -316,7 +316,7 @@ void CDKGSession::ReceiveMessage(const CDKGContribution& qc, bool& retBan)
bool complain = false;
CBLSSecretKey skContribution;
if (!qc.contributions->Decrypt(*myIdx, WITH_LOCK(::activeMasternodeManager->cs, return *::activeMasternodeManager->m_info.blsKeyOperator), skContribution, PROTOCOL_VERSION)) {
if (!::activeMasternodeManager->Decrypt(*qc.contributions, *myIdx, skContribution, PROTOCOL_VERSION)) {
logger.Batch("contribution from %s could not be decrypted", member->dmn->proTxHash.ToString());
complain = true;
} else if (member->idx != myIdx && ShouldSimulateError(DKGError::type::COMPLAIN_LIE)) {

View File

@ -834,9 +834,8 @@ PeerMsgRet CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_t
std::vector<CBLSSecretKey> vecSecretKeys;
vecSecretKeys.resize(vecEncrypted.size());
auto secret = WITH_LOCK(::activeMasternodeManager->cs, return *::activeMasternodeManager->m_info.blsKeyOperator);
for (const auto i : irange::range(vecEncrypted.size())) {
if (!vecEncrypted[i].Decrypt(memberIdx, secret, vecSecretKeys[i], PROTOCOL_VERSION)) {
if (!::activeMasternodeManager->Decrypt(vecEncrypted[i], memberIdx, vecSecretKeys[i], PROTOCOL_VERSION)) {
return errorHandler("Failed to decrypt");
}
}

View File

@ -4,10 +4,10 @@
#include <masternode/node.h>
#include <evo/deterministicmns.h>
#include <bls/bls_ies.h>
#include <chainparams.h>
#include <deploymentstatus.h>
#include <evo/deterministicmns.h>
#include <net.h>
#include <netbase.h>
#include <protocol.h>
@ -252,6 +252,18 @@ bool CActiveMasternodeManager::IsValidNetAddr(const CService& addrIn)
(addrIn.IsIPv4() && IsReachable(addrIn) && addrIn.IsRoutable());
}
template <template <typename> class EncryptedObj, typename Obj>
[[nodiscard]] bool CActiveMasternodeManager::Decrypt(const EncryptedObj<Obj>& obj, size_t idx, Obj& ret_obj,
int version) const
{
AssertLockNotHeld(cs);
return WITH_LOCK(cs, return obj.Decrypt(idx, *Assert(m_info.blsKeyOperator), ret_obj, version));
}
template bool CActiveMasternodeManager::Decrypt(const CBLSIESEncryptedObject<CBLSSecretKey>& obj, size_t idx,
CBLSSecretKey& ret_obj, int version) const;
template bool CActiveMasternodeManager::Decrypt(const CBLSIESMultiRecipientObjects<CBLSSecretKey>& obj, size_t idx,
CBLSSecretKey& ret_obj, int version) const;
[[nodiscard]] CBLSSignature CActiveMasternodeManager::Sign(const uint256& hash) const
{
AssertLockNotHeld(cs);

View File

@ -64,6 +64,9 @@ public:
static bool IsValidNetAddr(const CService& addrIn);
template <template <typename> class EncryptedObj, typename Obj>
[[nodiscard]] bool Decrypt(const EncryptedObj<Obj>& obj, size_t idx, Obj& ret_obj, int version) const
LOCKS_EXCLUDED(cs);
[[nodiscard]] CBLSSignature Sign(const uint256& hash) const LOCKS_EXCLUDED(cs);
[[nodiscard]] CBLSSignature Sign(const uint256& hash, const bool is_legacy) const LOCKS_EXCLUDED(cs);