Skip to content

Commit

Permalink
Commit contains changes:-
Browse files Browse the repository at this point in the history
- Remove init() from DigestCreator class.
- Change update() and compute to updateDigest() and computeDigest() respectively.
- static property of a function removed from EVPHash class.
  • Loading branch information
Pankaj authored and arc-vmware committed Jun 13, 2022
1 parent 770e674 commit 5ec8e9c
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 37 deletions.
12 changes: 6 additions & 6 deletions bftengine/src/bcstatetransfer/BCStateTran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(&pageId), sizeof(pageId));
digestGenerator.update(reinterpret_cast<const char *>(&checkpointNumber), sizeof(checkpointNumber));
digestGenerator.updateDigest(reinterpret_cast<const char *>(&pageId), sizeof(pageId));
digestGenerator.updateDigest(reinterpret_cast<const char *>(&checkpointNumber), sizeof(checkpointNumber));
if (checkpointNumber > 0) {
digestGenerator.update(page, pageSize);
digestGenerator.updateDigest(page, pageSize);
}
digestGenerator.writeDigest(reinterpret_cast<char *>(&outDigest));
}

void BCStateTran::computeDigestOfPagesDescriptor(const DataStore::ResPagesDescriptor *pagesDesc, Digest &outDigest) {
DigestGenerator digestGenerator;
digestGenerator.update(reinterpret_cast<const char *>(pagesDesc), pagesDesc->size());
digestGenerator.updateDigest(reinterpret_cast<const char *>(pagesDesc), pagesDesc->size());
digestGenerator.writeDigest(reinterpret_cast<char *>(&outDigest));
}

Expand All @@ -3901,8 +3901,8 @@ void BCStateTran::computeDigestOfBlockImpl(const uint64_t blockNum,
ConcordAssertGT(blockNum, 0);
ConcordAssertGT(blockSize, 0);
DigestGenerator digestGenerator;
digestGenerator.update(reinterpret_cast<const char *>(&blockNum), sizeof(blockNum));
digestGenerator.update(block, blockSize);
digestGenerator.updateDigest(reinterpret_cast<const char *>(&blockNum), sizeof(blockNum));
digestGenerator.updateDigest(block, blockSize);
digestGenerator.writeDigest(outDigest);
}

Expand Down
4 changes: 2 additions & 2 deletions bftengine/src/bcstatetransfer/RVBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>(&block_id), sizeof(block_id));
digest_generator.update(block, block_size);
digest_generator.updateDigest(reinterpret_cast<const char*>(&block_id), sizeof(block_id));
digest_generator.updateDigest(block, block_size);
digest_generator.writeDigest(out_digest);
}

Expand Down
4 changes: 2 additions & 2 deletions bftengine/src/bcstatetransfer/RangeValidationTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ const shared_ptr<char[]> RVBNode::computeNodeInitialValue(NodeInfo& node_info, c
ConcordAssertGT(node_info.id(), 0);
DigestGenerator digest_generator;

digest_generator.update(reinterpret_cast<const char*>(&node_info.id_data_), sizeof(node_info.id_data_));
digest_generator.update(data, data_size);
digest_generator.updateDigest(reinterpret_cast<const char*>(&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<char[]> out_digest_buff(new char[NodeVal::kDigestContextOutputSize]);
digest_generator.writeDigest(out_digest_buff.get());
Expand Down
2 changes: 1 addition & 1 deletion bftengine/src/bftengine/NullStateTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions bftengine/src/bftengine/messages/PrePrepareMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"));
}
Expand Down
2 changes: 1 addition & 1 deletion bftengine/src/bftengine/messages/ViewChangeMsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions bftengine/tests/messages/PrePrepareMsg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool concord::kvbc::strategy::MangledPreProcessResultMsgStrategy::changeMessage(
} else {
Digest d;
DigestGenerator digestGenerator;
digestGenerator.compute(req.body(), req.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
digestGenerator.computeDigest(req.body(), req.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
sigOrDigestOfRequest[idx].append(d.content(), sizeof(Digest));
}
idx++;
Expand All @@ -71,7 +71,7 @@ bool concord::kvbc::strategy::MangledPreProcessResultMsgStrategy::changeMessage(

Digest d;
DigestGenerator digestGenerator;
digestGenerator.compute(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
digestGenerator.computeDigest(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
nmsg.digestOfRequests() = d;
LOG_INFO(logger_,
"Finally the PrePrepare Message with correlation id : "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool ShufflePrePrepareMsgStrategy::changeMessage(std::shared_ptr<MessageBase>& m
} else {
Digest d;
DigestGenerator digestGenerator;
digestGenerator.compute(req.body(), req.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
digestGenerator.computeDigest(req.body(), req.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
if (idx == swapIdx) {
sigOrDigestOfRequest[idx + 1].append(d.content(), sizeof(Digest));
} else if (idx == (swapIdx + 1)) {
Expand All @@ -98,7 +98,7 @@ bool ShufflePrePrepareMsgStrategy::changeMessage(std::shared_ptr<MessageBase>& m

Digest d;
DigestGenerator digestGenerator;
digestGenerator.compute(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
digestGenerator.computeDigest(sigOrDig.c_str(), sigOrDig.size(), reinterpret_cast<char*>(&d), sizeof(Digest));
nmsg.digestOfRequests() = d;
LOG_INFO(logger_,
"Finally the PrePrepare Message with correlation id : "
Expand Down
8 changes: 4 additions & 4 deletions util/include/cryptopp_digest_creator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
8 changes: 4 additions & 4 deletions util/include/digest_creator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions util/include/digest_holder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions util/include/openssl_digest_creator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions util/src/cryptopp_digest_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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_;
Expand Down

0 comments on commit 5ec8e9c

Please sign in to comment.