mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
refactor: add helper function to decrypt messages with blsKeyOperator
This commit is contained in:
parent
3eb931b596
commit
33702aca39
@ -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)) {
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user