diff options
author | Luca Muscariello <muscariello@ieee.org> | 2022-04-22 17:55:01 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2022-04-26 15:30:21 +0200 |
commit | a1ac96f497719b897793ac14b287cb8d840651c1 (patch) | |
tree | 12c608fe352c21d944b0340ce8d3f0be0fb23b11 /libtransport/src/auth/crypto_hash.cc | |
parent | 1ac07d842a3a6ce0fb7fa4039241c8ec1a71419b (diff) |
HICN-722: Updates on transport, RTC, manifest usage for RTC, infra.
Co-authored-by: Mauro Sardara <msardara@cisco.com>
Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Co-authored-by: Michele Papalini <micpapal@cisco.com>
Co-authored-by: Angelo Mantellini <manangel@cisco.com>
Co-authored-by: Jacques Samain <jsamain@cisco.com>
Co-authored-by: Olivier Roques <oroques+fdio@cisco.com>
Co-authored-by: Enrico Loparco <eloparco@cisco.com>
Co-authored-by: Giulio Grassi <gigrassi@cisco.com>
manifest: optimize manifest processing
manifest: add FEC parameters to manifests
manifest: refactor verification process
manifest: report auth alerts in hiperf instead of aborting
manifest: remove FEC buffer callback in consumer
manifest: refactor and enable manifests by default
manifest: update manifest header with transport parameters
manifest: batch interests for first manifest from RTC producer
manifest: refactor processing of RTC manifests
manifest: update manifest-related socket options of consumers
manifest: update unit tests for manifests
manifest: pack manifest headers
manifest: verify FEC packets
auth: add consumer socket option to set max unverified delay
manifest: process manifests after full FEC decoding
manifest: manage forward jumps in RTC verifier
fec: remove useless fec codes
rs: add new code rate
rs: add new code rate
rs: add new code rate
rs: add new code rate
libtransport: increase internal packet cache size
remove internal cisco info in cmake
manifest: add option to set manifest capacity
data_input_node.c: add information about adj_index[VLIB_RX] on received data packetsi
sysrepo plugin: update build
Change-Id: I0cf64d91bd0a1b7cad4eeaa9871f58f5f10434af
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Diffstat (limited to 'libtransport/src/auth/crypto_hash.cc')
-rw-r--r-- | libtransport/src/auth/crypto_hash.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/libtransport/src/auth/crypto_hash.cc b/libtransport/src/auth/crypto_hash.cc index f60f46051..08be47aff 100644 --- a/libtransport/src/auth/crypto_hash.cc +++ b/libtransport/src/auth/crypto_hash.cc @@ -14,6 +14,9 @@ */ #include <hicn/transport/auth/crypto_hash.h> +#include <hicn/transport/core/global_object_pool.h> + +#include "glog/logging.h" namespace transport { namespace auth { @@ -27,18 +30,20 @@ CryptoHash::CryptoHash(const CryptoHash &other) CryptoHash::CryptoHash(CryptoHash &&other) : digest_type_(std::move(other.digest_type_)), - digest_(other.digest_), - digest_size_(other.digest_size_) { - other.reset(); -} + digest_(std::move(other.digest_)), + digest_size_(other.digest_size_) {} -CryptoHash::CryptoHash(CryptoHashType hash_type) { setType(hash_type); } +CryptoHash::CryptoHash(CryptoHashType hash_type) + : digest_(core::PacketManager<>::getInstance().getMemBuf()) { + setType(hash_type); +} CryptoHash::CryptoHash(const uint8_t *hash, size_t size, CryptoHashType hash_type) : digest_type_(hash_type), digest_size_(size) { - digest_.resize(size); - memcpy(digest_.data(), hash, size); + digest_ = core::PacketManager<>::getInstance().getMemBuf(); + digest_->append(size); + memcpy(digest_->writableData(), hash, size); } CryptoHash::CryptoHash(const std::vector<uint8_t> &hash, @@ -55,7 +60,7 @@ CryptoHash &CryptoHash::operator=(const CryptoHash &other) { } bool CryptoHash::operator==(const CryptoHash &other) const { - return (digest_type_ == other.digest_type_ && digest_ == other.digest_); + return (digest_type_ == other.digest_type_ && *digest_ == *other.digest_); } void CryptoHash::computeDigest(const uint8_t *buffer, size_t len) { @@ -65,8 +70,8 @@ void CryptoHash::computeDigest(const uint8_t *buffer, size_t len) { throw errors::RuntimeException("Unknown hash type"); } - EVP_Digest(buffer, len, digest_.data(), (unsigned int *)&digest_size_, - (*hash_evp)(), nullptr); + EVP_Digest(buffer, len, digest_->writableData(), + (unsigned int *)&digest_size_, (*hash_evp)(), nullptr); } void CryptoHash::computeDigest(const std::vector<uint8_t> &buffer) { @@ -95,7 +100,7 @@ void CryptoHash::computeDigest(const utils::MemBuf *buffer) { p = p->next(); } while (p != buffer); - if (EVP_DigestFinal_ex(mcdtx, digest_.data(), + if (EVP_DigestFinal_ex(mcdtx, digest_->writableData(), (unsigned int *)&digest_size_) != 1) { throw errors::RuntimeException("Digest computation failed"); } @@ -103,15 +108,16 @@ void CryptoHash::computeDigest(const utils::MemBuf *buffer) { EVP_MD_CTX_free(mcdtx); } -std::vector<uint8_t> CryptoHash::getDigest() const { return digest_; } +const utils::MemBuf::Ptr &CryptoHash::getDigest() const { return digest_; } std::string CryptoHash::getStringDigest() const { std::stringstream string_digest; string_digest << std::hex << std::setfill('0'); - for (auto byte : digest_) { - string_digest << std::hex << std::setw(2) << static_cast<int>(byte); + for (size_t i = 0; i < digest_size_; ++i) { + string_digest << std::hex << std::setw(2) + << static_cast<int>(digest_->data()[i]); } return string_digest.str(); @@ -122,10 +128,10 @@ CryptoHashType CryptoHash::getType() const { return digest_type_; } size_t CryptoHash::getSize() const { return digest_size_; } void CryptoHash::setType(CryptoHashType hash_type) { - reset(); digest_type_ = hash_type; digest_size_ = CryptoHash::getSize(hash_type); - digest_.resize(digest_size_); + DCHECK(digest_size_ <= digest_->tailroom()); + digest_->setLength(digest_size_); } void CryptoHash::display() { @@ -152,8 +158,8 @@ void CryptoHash::display() { void CryptoHash::reset() { digest_type_ = CryptoHashType::UNKNOWN; - digest_.clear(); digest_size_ = 0; + digest_->setLength(0); } CryptoHashEVP CryptoHash::getEVP(CryptoHashType hash_type) { |