diff --git a/bftengine/src/bcstatetransfer/BCStateTran.cpp b/bftengine/src/bcstatetransfer/BCStateTran.cpp index da4008f979..51b2e821fe 100644 --- a/bftengine/src/bcstatetransfer/BCStateTran.cpp +++ b/bftengine/src/bcstatetransfer/BCStateTran.cpp @@ -3880,17 +3880,17 @@ void BCStateTran::checkStoredCheckpoints(uint64_t firstStoredCheckpoint, uint64_ void BCStateTran::computeDigestOfPage( const uint32_t pageId, const uint64_t checkpointNumber, const char *page, uint32_t pageSize, Digest &outDigest) { DigestGenerator digestGenerator; - digestGenerator.update(reinterpret_cast(&pageId), sizeof(pageId)); - digestGenerator.update(reinterpret_cast(&checkpointNumber), sizeof(checkpointNumber)); + digestGenerator.updateDigest(reinterpret_cast(&pageId), sizeof(pageId)); + digestGenerator.updateDigest(reinterpret_cast(&checkpointNumber), sizeof(checkpointNumber)); if (checkpointNumber > 0) { - digestGenerator.update(page, pageSize); + digestGenerator.updateDigest(page, pageSize); } digestGenerator.writeDigest(reinterpret_cast(&outDigest)); } void BCStateTran::computeDigestOfPagesDescriptor(const DataStore::ResPagesDescriptor *pagesDesc, Digest &outDigest) { DigestGenerator digestGenerator; - digestGenerator.update(reinterpret_cast(pagesDesc), pagesDesc->size()); + digestGenerator.updateDigest(reinterpret_cast(pagesDesc), pagesDesc->size()); digestGenerator.writeDigest(reinterpret_cast(&outDigest)); } @@ -3901,8 +3901,8 @@ void BCStateTran::computeDigestOfBlockImpl(const uint64_t blockNum, ConcordAssertGT(blockNum, 0); ConcordAssertGT(blockSize, 0); DigestGenerator digestGenerator; - digestGenerator.update(reinterpret_cast(&blockNum), sizeof(blockNum)); - digestGenerator.update(block, blockSize); + digestGenerator.updateDigest(reinterpret_cast(&blockNum), sizeof(blockNum)); + digestGenerator.updateDigest(block, blockSize); digestGenerator.writeDigest(outDigest); } diff --git a/bftengine/src/bcstatetransfer/RVBManager.cpp b/bftengine/src/bcstatetransfer/RVBManager.cpp index 332a0486bc..bd79b9538a 100644 --- a/bftengine/src/bcstatetransfer/RVBManager.cpp +++ b/bftengine/src/bcstatetransfer/RVBManager.cpp @@ -630,8 +630,8 @@ void RVBManager::computeDigestOfBlock(const uint64_t block_id, ConcordAssertGT(block_id, 0); ConcordAssertGT(block_size, 0); DigestGenerator digest_generator; - digest_generator.update(reinterpret_cast(&block_id), sizeof(block_id)); - digest_generator.update(block, block_size); + digest_generator.updateDigest(reinterpret_cast(&block_id), sizeof(block_id)); + digest_generator.updateDigest(block, block_size); digest_generator.writeDigest(out_digest); } diff --git a/bftengine/src/bcstatetransfer/RangeValidationTree.cpp b/bftengine/src/bcstatetransfer/RangeValidationTree.cpp index 6ada47d8b7..695a7e6af6 100644 --- a/bftengine/src/bcstatetransfer/RangeValidationTree.cpp +++ b/bftengine/src/bcstatetransfer/RangeValidationTree.cpp @@ -152,8 +152,8 @@ const shared_ptr RVBNode::computeNodeInitialValue(NodeInfo& node_info, c ConcordAssertGT(node_info.id(), 0); DigestGenerator digest_generator; - digest_generator.update(reinterpret_cast(&node_info.id_data_), sizeof(node_info.id_data_)); - digest_generator.update(data, data_size); + digest_generator.updateDigest(reinterpret_cast(&node_info.id_data_), sizeof(node_info.id_data_)); + digest_generator.updateDigest(data, data_size); // TODO - Use default_delete in case memleak is reported by ASAN static std::shared_ptr out_digest_buff(new char[NodeVal::kDigestContextOutputSize]); digest_generator.writeDigest(out_digest_buff.get()); diff --git a/bftengine/src/bftengine/NullStateTransfer.cpp b/bftengine/src/bftengine/NullStateTransfer.cpp index 19c23184b5..c93b0226ad 100644 --- a/bftengine/src/bftengine/NullStateTransfer.cpp +++ b/bftengine/src/bftengine/NullStateTransfer.cpp @@ -64,7 +64,7 @@ void NullStateTransfer::getDigestOfCheckpoint(uint64_t checkpointNumber, Digest d; DigestGenerator digestGenerator; - digestGenerator.compute((char*)&checkpointNumber, sizeof(checkpointNumber), (char*)&d, sizeof(d)); + digestGenerator.computeDigest((char*)&checkpointNumber, sizeof(checkpointNumber), (char*)&d, sizeof(d)); memset(outStateDigest, 0, sizeOfDigestBuffer); memset(outResPagesDigest, 0, sizeOfDigestBuffer); diff --git a/bftengine/src/bftengine/messages/PrePrepareMsg.cpp b/bftengine/src/bftengine/messages/PrePrepareMsg.cpp index f7ac8a07fe..a93a6dd446 100644 --- a/bftengine/src/bftengine/messages/PrePrepareMsg.cpp +++ b/bftengine/src/bftengine/messages/PrePrepareMsg.cpp @@ -59,7 +59,7 @@ void PrePrepareMsg::calculateDigestOfRequests(Digest& digest) const { tasks.push_back(threadPool.async( [&sigOrDigestOfRequest, &digestBuffer, local_id](auto* request, auto requestLength) { DigestGenerator digestGenerator; - digestGenerator.compute( + digestGenerator.computeDigest( request, requestLength, digestBuffer.get() + local_id * sizeof(Digest), sizeof(Digest)); sigOrDigestOfRequest[local_id].first = digestBuffer.get() + local_id * sizeof(Digest); sigOrDigestOfRequest[local_id].second = sizeof(Digest); @@ -80,7 +80,7 @@ void PrePrepareMsg::calculateDigestOfRequests(Digest& digest) const { // compute and set digest DigestGenerator digestGenerator; - digestGenerator.compute(sigOrDig.c_str(), sigOrDig.size(), (char*)&digest, sizeof(Digest)); + digestGenerator.computeDigest(sigOrDig.c_str(), sigOrDig.size(), (char*)&digest, sizeof(Digest)); } catch (std::out_of_range& ex) { throw std::runtime_error(__PRETTY_FUNCTION__ + std::string(": digest threadpool")); } diff --git a/bftengine/src/bftengine/messages/ViewChangeMsg.cpp b/bftengine/src/bftengine/messages/ViewChangeMsg.cpp index 40de987b2e..e044a41446 100644 --- a/bftengine/src/bftengine/messages/ViewChangeMsg.cpp +++ b/bftengine/src/bftengine/messages/ViewChangeMsg.cpp @@ -52,7 +52,7 @@ void ViewChangeMsg::getMsgDigest(Digest& outDigest) const { auto bodySize = getBodySize(); bodySize += b()->sizeOfAllComplaints; DigestGenerator digestGenerator; - digestGenerator.compute(body(), bodySize, (char*)outDigest.content(), sizeof(Digest)); + digestGenerator.computeDigest(body(), bodySize, (char*)outDigest.content(), sizeof(Digest)); } uint32_t ViewChangeMsg::getBodySize() const { diff --git a/bftengine/tests/messages/PrePrepareMsg_test.cpp b/bftengine/tests/messages/PrePrepareMsg_test.cpp index df671aeb04..8b890963f6 100644 --- a/bftengine/tests/messages/PrePrepareMsg_test.cpp +++ b/bftengine/tests/messages/PrePrepareMsg_test.cpp @@ -139,7 +139,7 @@ TEST_F(PrePrepareMsgTestFixture, finalize_and_validate) { msg.addRequest(crm->body(), crm->size()); Digest d; DigestGenerator digestGenerator; - digestGenerator.compute(crm->body(), crm->size(), (char*)&d, sizeof(Digest)); + digestGenerator.computeDigest(crm->body(), crm->size(), (char*)&d, sizeof(Digest)); dv.push_back({d.content(), sizeof(Digest)}); } EXPECT_NO_THROW(msg.finishAddingRequests()); // create the digest @@ -151,7 +151,7 @@ TEST_F(PrePrepareMsgTestFixture, finalize_and_validate) { } Digest d; DigestGenerator digestGenerator; - digestGenerator.compute(dod.c_str(), dod.size(), (char*)&d, sizeof(Digest)); + digestGenerator.computeDigest(dod.c_str(), dod.size(), (char*)&d, sizeof(Digest)); EXPECT_EQ(d, msg.digestOfRequests()); EXPECT_NO_THROW(msg.validate(replicaInfo)); // validate the same digest } diff --git a/tests/simpleKVBC/TesterReplica/strategy/MangledPreProcessResultMsgStrategy.cpp b/tests/simpleKVBC/TesterReplica/strategy/MangledPreProcessResultMsgStrategy.cpp index 1021043607..7828386c2f 100644 --- a/tests/simpleKVBC/TesterReplica/strategy/MangledPreProcessResultMsgStrategy.cpp +++ b/tests/simpleKVBC/TesterReplica/strategy/MangledPreProcessResultMsgStrategy.cpp @@ -57,7 +57,7 @@ bool concord::kvbc::strategy::MangledPreProcessResultMsgStrategy::changeMessage( } else { Digest d; DigestGenerator digestGenerator; - digestGenerator.compute(req.body(), req.size(), reinterpret_cast(&d), sizeof(Digest)); + digestGenerator.computeDigest(req.body(), req.size(), reinterpret_cast(&d), sizeof(Digest)); sigOrDigestOfRequest[idx].append(d.content(), sizeof(Digest)); } idx++; @@ -71,7 +71,7 @@ bool concord::kvbc::strategy::MangledPreProcessResultMsgStrategy::changeMessage( Digest d; DigestGenerator digestGenerator; - digestGenerator.compute(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast(&d), sizeof(Digest)); + digestGenerator.computeDigest(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast(&d), sizeof(Digest)); nmsg.digestOfRequests() = d; LOG_INFO(logger_, "Finally the PrePrepare Message with correlation id : " diff --git a/tests/simpleKVBC/TesterReplica/strategy/ShufflePrePrepareMsgStrategy.cpp b/tests/simpleKVBC/TesterReplica/strategy/ShufflePrePrepareMsgStrategy.cpp index 2277184d6b..5c30ae8c20 100644 --- a/tests/simpleKVBC/TesterReplica/strategy/ShufflePrePrepareMsgStrategy.cpp +++ b/tests/simpleKVBC/TesterReplica/strategy/ShufflePrePrepareMsgStrategy.cpp @@ -73,7 +73,7 @@ bool ShufflePrePrepareMsgStrategy::changeMessage(std::shared_ptr& m } else { Digest d; DigestGenerator digestGenerator; - digestGenerator.compute(req.body(), req.size(), reinterpret_cast(&d), sizeof(Digest)); + digestGenerator.computeDigest(req.body(), req.size(), reinterpret_cast(&d), sizeof(Digest)); if (idx == swapIdx) { sigOrDigestOfRequest[idx + 1].append(d.content(), sizeof(Digest)); } else if (idx == (swapIdx + 1)) { @@ -98,7 +98,7 @@ bool ShufflePrePrepareMsgStrategy::changeMessage(std::shared_ptr& m Digest d; DigestGenerator digestGenerator; - digestGenerator.compute(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast(&d), sizeof(Digest)); + digestGenerator.computeDigest(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast(&d), sizeof(Digest)); nmsg.digestOfRequests() = d; LOG_INFO(logger_, "Finally the PrePrepare Message with correlation id : " diff --git a/util/include/cryptopp_digest_creator.hpp b/util/include/cryptopp_digest_creator.hpp index c4b78e85be..364062b056 100644 --- a/util/include/cryptopp_digest_creator.hpp +++ b/util/include/cryptopp_digest_creator.hpp @@ -38,10 +38,10 @@ class CryptoppDigestCreator : public DigestCreator { void update(const char* data, size_t len) override; void writeDigest(char* outDigest) override; size_t digestLength() const override; - bool compute(const char* input, - size_t inputLength, - char* outBufferForDigest, - size_t lengthOfBufferForDigest) override; + bool computeDigest(const char* input, + const size_t inputLength, + char* outBufferForDigest, + const size_t lengthOfBufferForDigest) override; private: void* internalState_; diff --git a/util/include/digest_creator.hpp b/util/include/digest_creator.hpp index bfff275e21..578a3123e7 100644 --- a/util/include/digest_creator.hpp +++ b/util/include/digest_creator.hpp @@ -24,9 +24,9 @@ class DigestCreator { virtual void update(const char* data, size_t len) = 0; virtual void writeDigest(char* outDigest) = 0; virtual size_t digestLength() const = 0; - virtual bool compute(const char* input, - size_t inputLength, - char* outBufferForDigest, - size_t lengthOfBufferForDigest) = 0; + virtual bool computeDigest(const char* input, + const size_t inputLength, + char* outBufferForDigest, + const size_t lengthOfBufferForDigest) = 0; }; } // namespace concord::util::digest diff --git a/util/include/digest_holder.hpp b/util/include/digest_holder.hpp index e2e74ed1d1..4cf5c25231 100644 --- a/util/include/digest_holder.hpp +++ b/util/include/digest_holder.hpp @@ -29,7 +29,7 @@ class DigestHolder { DigestHolder(const char* other) { std::memcpy(d, other, DIGEST_SIZE); } DigestHolder(char* buf, size_t len) { CREATOR digestCreator; - digestCreator.compute(buf, len, (char*)d, DIGEST_SIZE); + digestCreator.computeDigest(buf, len, (char*)d, DIGEST_SIZE); } DigestHolder(const DigestHolder& other) { std::memcpy(d, other.d, DIGEST_SIZE); } @@ -73,7 +73,7 @@ class DigestHolder { void digestOfDigest(const DigestHolder& inDigest, DigestHolder& outDigest) { CREATOR digestCreator; - digestCreator.compute(inDigest.d, sizeof(DigestHolder), outDigest.d, sizeof(DigestHolder)); + digestCreator.computeDigest(inDigest.d, sizeof(DigestHolder), outDigest.d, sizeof(DigestHolder)); } void calcCombination(const DigestHolder& inDigest, int64_t inDataA, int64_t inDataB, DigestHolder& outDigest) { diff --git a/util/include/openssl_digest_creator.ipp b/util/include/openssl_digest_creator.ipp index bc1ff35e7d..01128848d8 100644 --- a/util/include/openssl_digest_creator.ipp +++ b/util/include/openssl_digest_creator.ipp @@ -39,7 +39,7 @@ class OpenSSLDigestCreator : public DigestCreator { } } - void update(const char* data, size_t len) { + void updateDigest(const char* data, const size_t len) { ConcordAssert(nullptr != data); init(); @@ -56,7 +56,10 @@ class OpenSSLDigestCreator : public DigestCreator { size_t digestLength() const { return hash_ctx_.SIZE_IN_BYTES; } - bool compute(const char* input, size_t inputLength, char* outBufferForDigest, size_t lengthOfBufferForDigest) { + bool computeDigest(const char* input, + const size_t inputLength, + char* outBufferForDigest, + const size_t lengthOfBufferForDigest) { ConcordAssert(nullptr != input); ConcordAssert(nullptr != outBufferForDigest); diff --git a/util/src/cryptopp_digest_creator.cpp b/util/src/cryptopp_digest_creator.cpp index 7d9dc88b00..4aba292623 100644 --- a/util/src/cryptopp_digest_creator.cpp +++ b/util/src/cryptopp_digest_creator.cpp @@ -35,10 +35,10 @@ CryptoppDigestCreator::CryptoppDigestCreator() { size_t CryptoppDigestCreator::digestLength() const { return DigestType::DIGESTSIZE; } -bool CryptoppDigestCreator::compute(const char* input, - size_t inputLength, - char* outBufferForDigest, - size_t lengthOfBufferForDigest) { +bool CryptoppDigestCreator::computeDigest(const char* input, + const size_t inputLength, + char* outBufferForDigest, + const size_t lengthOfBufferForDigest) { DigestType dig; const size_t size = dig.DigestSize(); @@ -57,7 +57,7 @@ bool CryptoppDigestCreator::compute(const char* input, return true; } -void CryptoppDigestCreator::update(const char* data, size_t len) { +void CryptoppDigestCreator::updateDigest(const char* data, const size_t len) { ConcordAssert(nullptr != internalState_); DigestType* p = (DigestType*)internalState_;