Created
September 23, 2020 02:09
-
-
Save AndrejMitrovic/c374651809a3b746e18531c0a579a817 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/source/scpp/src/scp/BallotProtocol.cpp b/source/scpp/src/scp/BallotProtocol.cpp | |
index 6e086c931..9c2f97b92 100644 | |
--- a/source/scpp/src/scp/BallotProtocol.cpp | |
+++ b/source/scpp/src/scp/BallotProtocol.cpp | |
@@ -6,7 +6,7 @@ | |
#include "Slot.h" | |
#include "crypto/Hex.h" | |
-#include "crypto/SHA.h" | |
+#include "crypto/Hash.h" | |
#include "lib/json/json.h" | |
#include "scp/LocalNode.h" | |
#include "scp/QuorumSetUtils.h" | |
diff --git a/source/scpp/src/scp/LocalNode.cpp b/source/scpp/src/scp/LocalNode.cpp | |
index 0a5643452..1f2bcc529 100644 | |
--- a/source/scpp/src/scp/LocalNode.cpp | |
+++ b/source/scpp/src/scp/LocalNode.cpp | |
@@ -6,7 +6,7 @@ | |
#include "crypto/Hex.h" | |
#include "crypto/KeyUtils.h" | |
-#include "crypto/SHA.h" | |
+#include "crypto/Hash.h" | |
#include "lib/json/json.h" | |
#include "scp/QuorumSetUtils.h" | |
#include "util/Logging.h" | |
@@ -24,14 +24,14 @@ LocalNode::LocalNode(NodeID const& nodeID, bool isValidator, | |
: mNodeID(nodeID), mIsValidator(isValidator), mQSet(qSet), mSCP(scp) | |
{ | |
normalizeQSet(mQSet); | |
- mQSetHash = sha512(xdr::xdr_to_opaque(mQSet)); | |
+ mQSetHash = getHashOf(mQSet); | |
CLOG(INFO, "SCP") << "LocalNode::LocalNode" | |
<< "@" << KeyUtils::toShortString(mNodeID) | |
<< " qSet: " << hexAbbrev(mQSetHash); | |
mSingleQSet = std::make_shared<SCPQuorumSet>(buildSingletonQSet(mNodeID)); | |
- gSingleQSetHash = sha512(xdr::xdr_to_opaque(*mSingleQSet)); | |
+ gSingleQSetHash = getHashOf(*mSingleQSet); | |
} | |
SCPQuorumSet | |
@@ -46,7 +46,7 @@ LocalNode::buildSingletonQSet(NodeID const& nodeID) | |
void | |
LocalNode::updateQuorumSet(SCPQuorumSet const& qSet) | |
{ | |
- mQSetHash = sha512(xdr::xdr_to_opaque(qSet)); | |
+ mQSetHash = getHashOf(qSet); | |
mQSet = qSet; | |
} | |
diff --git a/source/scpp/src/scp/NominationProtocol.cpp b/source/scpp/src/scp/NominationProtocol.cpp | |
index cdf7e670b..c58a138a5 100644 | |
--- a/source/scpp/src/scp/NominationProtocol.cpp | |
+++ b/source/scpp/src/scp/NominationProtocol.cpp | |
@@ -6,7 +6,7 @@ | |
#include "Slot.h" | |
#include "crypto/Hex.h" | |
-#include "crypto/SHA.h" | |
+#include "crypto/Hash.h" | |
#include "lib/json/json.h" | |
#include "scp/LocalNode.h" | |
#include "scp/QuorumSetUtils.h" | |
diff --git a/source/scpp/src/scp/SCP.cpp b/source/scpp/src/scp/SCP.cpp | |
index 3926d20bd..6915bb42d 100644 | |
--- a/source/scpp/src/scp/SCP.cpp | |
+++ b/source/scpp/src/scp/SCP.cpp | |
@@ -4,7 +4,7 @@ | |
#include "scp/SCP.h" | |
#include "crypto/Hex.h" | |
-#include "crypto/SHA.h" | |
+#include "crypto/Hash.h" | |
#include "scp/LocalNode.h" | |
#include "scp/Slot.h" | |
#include "util/GlobalChecks.h" | |
diff --git a/source/scpp/src/scp/SCPDriver.cpp b/source/scpp/src/scp/SCPDriver.cpp | |
index 542968829..eedf8f7e9 100644 | |
--- a/source/scpp/src/scp/SCPDriver.cpp | |
+++ b/source/scpp/src/scp/SCPDriver.cpp | |
@@ -8,7 +8,7 @@ | |
#include "crypto/Hex.h" | |
#include "crypto/KeyUtils.h" | |
-#include "crypto/SHA.h" | |
+#include "crypto/Hash.h" | |
#include "crypto/SecretKey.h" | |
#include "xdrpp/marshal.h" | |
@@ -18,8 +18,7 @@ namespace stellar | |
std::string | |
SCPDriver::getValueString(Value const& v) const | |
{ | |
- uint512 valueHash = sha512(xdr::xdr_to_opaque(v)); | |
- | |
+ uint512 valueHash = getHashOf(v); | |
return hexAbbrev(valueHash); | |
} | |
@@ -41,18 +40,12 @@ static const uint32 hash_P = 2; | |
static const uint32 hash_K = 3; | |
static uint64 | |
-hashHelper(uint64 slotIndex, Value const& prev, | |
- std::function<void(SHA512*)> extra) | |
-{ | |
- auto h = SHA512::create(); | |
- h->add(xdr::xdr_to_opaque(slotIndex)); | |
- h->add(xdr::xdr_to_opaque(prev)); | |
- extra(h.get()); | |
- uint512 t = h->finish(); | |
+hashHelper(uint512 &hash) | |
+{ | |
uint64 res = 0; | |
for (size_t i = 0; i < sizeof(res); i++) | |
{ | |
- res = (res << 8) | t[i]; | |
+ res = (res << 8) | hash[i]; | |
} | |
return res; | |
} | |
@@ -61,22 +54,17 @@ uint64 | |
SCPDriver::computeHashNode(uint64 slotIndex, Value const& prev, bool isPriority, | |
int32_t roundNumber, NodeID const& nodeID) | |
{ | |
- return hashHelper(slotIndex, prev, [&](SHA512* h) { | |
- h->add(xdr::xdr_to_opaque(isPriority ? hash_P : hash_N)); | |
- h->add(xdr::xdr_to_opaque(roundNumber)); | |
- h->add(xdr::xdr_to_opaque(nodeID)); | |
- }); | |
+ uint512 hash = getHashOf(slotIndex, prev, isPriority ? hash_P : hash_N, | |
+ roundNumber, nodeID); | |
+ return hashHelper(hash); | |
} | |
uint64 | |
SCPDriver::computeValueHash(uint64 slotIndex, Value const& prev, | |
int32_t roundNumber, Value const& value) | |
{ | |
- return hashHelper(slotIndex, prev, [&](SHA512* h) { | |
- h->add(xdr::xdr_to_opaque(hash_K)); | |
- h->add(xdr::xdr_to_opaque(roundNumber)); | |
- h->add(xdr::xdr_to_opaque(value)); | |
- }); | |
+ uint512 hash = getHashOf(slotIndex, prev, hash_K, roundNumber, value); | |
+ return hashHelper(hash); | |
} | |
static const int MAX_TIMEOUT_SECONDS = (30 * 60); | |
diff --git a/source/scpp/src/scp/Slot.cpp b/source/scpp/src/scp/Slot.cpp | |
index 7c730d50a..4aba75a10 100644 | |
--- a/source/scpp/src/scp/Slot.cpp | |
+++ b/source/scpp/src/scp/Slot.cpp | |
@@ -5,7 +5,7 @@ | |
#include "Slot.h" | |
#include "crypto/Hex.h" | |
-#include "crypto/SHA.h" | |
+#include "crypto/Hash.h" | |
#include "lib/json/json.h" | |
#include "main/ErrorMessages.h" | |
#include "scp/LocalNode.h" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment