summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2017-11-30 13:11:43 -0800
committerVernon Mauery <vernon.mauery@linux.intel.com>2017-12-05 16:33:59 -0800
commit70fd29cf487ceefd21af58bab988a7ff9ec07efb (patch)
tree384f140fd16aef4deb78236bd924afce04f98cc0
parent2207f51cbdd3962b1e94fb8432edfc2e294fd9c7 (diff)
downloadphosphor-net-ipmid-70fd29cf487ceefd21af58bab988a7ff9ec07efb.tar.gz
phosphor-net-ipmid-70fd29cf487ceefd21af58bab988a7ff9ec07efb.zip
explicit use of std::vector instead of buffer/Buffer
There were several scoped 'using buffer = std::vector<uint8_t>;' in header files. This consolidates the code base to use std::vector<uint8_t> instead of buffer or Buffer. This makes the code easier to read and debug. Change-Id: I918a0f6ca9b8e4b9d331175dccff45cbf4c8379d Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
-rw-r--r--auth_algo.cpp6
-rw-r--r--auth_algo.hpp12
-rw-r--r--command/sol_cmds.cpp2
-rw-r--r--crypt_algo.cpp22
-rw-r--r--crypt_algo.hpp25
-rw-r--r--integrity_algo.cpp18
-rw-r--r--integrity_algo.hpp23
-rw-r--r--message_handler.cpp2
-rw-r--r--message_handler.hpp2
-rw-r--r--socket_channel.cpp6
-rw-r--r--socket_channel.hpp5
-rw-r--r--sol/console_buffer.hpp3
-rw-r--r--sol/sol_context.cpp6
-rw-r--r--sol/sol_context.hpp6
-rw-r--r--sol/sol_manager.cpp2
-rw-r--r--sol/sol_manager.hpp2
-rw-r--r--test/cipher.cpp4
17 files changed, 79 insertions, 67 deletions
diff --git a/auth_algo.cpp b/auth_algo.cpp
index b71636b..f062b0f 100644
--- a/auth_algo.cpp
+++ b/auth_algo.cpp
@@ -11,7 +11,8 @@ namespace cipher
namespace rakp_auth
{
-std::vector<uint8_t> AlgoSHA1::generateHMAC(std::vector<uint8_t>& input) const
+std::vector<uint8_t> AlgoSHA1::generateHMAC(
+ const std::vector<uint8_t>& input) const
{
std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
unsigned int mdLen = 0;
@@ -26,7 +27,8 @@ std::vector<uint8_t> AlgoSHA1::generateHMAC(std::vector<uint8_t>& input) const
return output;
}
-std::vector<uint8_t> AlgoSHA1::generateICV(std::vector<uint8_t>& input) const
+std::vector<uint8_t> AlgoSHA1::generateICV(
+ const std::vector<uint8_t>& input) const
{
std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
unsigned int mdLen = 0;
diff --git a/auth_algo.hpp b/auth_algo.hpp
index 2c3b0da..997e2c9 100644
--- a/auth_algo.hpp
+++ b/auth_algo.hpp
@@ -74,7 +74,7 @@ class Interface
* needs to be set before this operation.
*/
std::vector<uint8_t> virtual generateHMAC(
- std::vector<uint8_t>& input) const = 0;
+ const std::vector<uint8_t>& input) const = 0;
/**
* @brief Generate the Integrity Check Value
@@ -90,7 +90,7 @@ class Interface
* hash operation needs to be set before this operation.
*/
std::vector<uint8_t> virtual generateICV(
- std::vector<uint8_t>& input) const = 0;
+ const std::vector<uint8_t>& input) const = 0;
// User Key is hardcoded to PASSW0RD till the IPMI User account
// management is in place.
@@ -150,11 +150,11 @@ class AlgoSHA1 : public Interface
AlgoSHA1(AlgoSHA1&&) = default;
AlgoSHA1& operator=(AlgoSHA1&&) = default;
- std::vector<uint8_t> generateHMAC(std::vector<uint8_t>& input) const
- override;
+ std::vector<uint8_t> generateHMAC(
+ const std::vector<uint8_t>& input) const override;
- std::vector<uint8_t> generateICV(std::vector<uint8_t>& input) const
- override;
+ std::vector<uint8_t> generateICV(
+ const std::vector<uint8_t>& input) const override;
};
}// namespace auth
diff --git a/command/sol_cmds.cpp b/command/sol_cmds.cpp
index f475c03..fd9a610 100644
--- a/command/sol_cmds.cpp
+++ b/command/sol_cmds.cpp
@@ -18,7 +18,7 @@ std::vector<uint8_t> payloadHandler(const std::vector<uint8_t>& inPayload,
auto request = reinterpret_cast<const Payload*>(inPayload.data());
auto solDataSize = inPayload.size() - sizeof(Payload);
- Buffer charData(solDataSize);
+ std::vector<uint8_t> charData(solDataSize);
if( solDataSize > 0)
{
std::copy_n(inPayload.data() + sizeof(Payload),
diff --git a/crypt_algo.cpp b/crypt_algo.cpp
index baeb606..f33bca4 100644
--- a/crypt_algo.cpp
+++ b/crypt_algo.cpp
@@ -12,12 +12,13 @@ namespace cipher
namespace crypt
{
-Interface::Interface(const buffer& sik, const key& addKey)
+Interface::Interface(const std::vector<uint8_t>& sik, const key& addKey)
{
unsigned int mdLen = 0;
// Generated K2 for the confidentiality algorithm with the additional key
// keyed with SIK.
+ k2.resize(sik.size());
if (HMAC(EVP_sha1(), sik.data(), sik.size(), addKey.data(),
addKey.size(), k2.data(), &mdLen) == NULL)
{
@@ -31,9 +32,10 @@ constexpr key AlgoAES128::const2;
constexpr std::array<uint8_t, AlgoAES128::AESCBC128BlockSize - 1>
AlgoAES128::confPadBytes;
-buffer AlgoAES128::decryptPayload(const buffer& packet,
- const size_t sessHeaderLen,
- const size_t payloadLen) const
+std::vector<uint8_t> AlgoAES128::decryptPayload(
+ const std::vector<uint8_t>& packet,
+ const size_t sessHeaderLen,
+ const size_t payloadLen) const
{
auto plainPayload = decryptData(
packet.data() + sessHeaderLen,
@@ -63,7 +65,8 @@ buffer AlgoAES128::decryptPayload(const buffer& packet,
return plainPayload;
}
-buffer AlgoAES128::encryptPayload(buffer& payload) const
+std::vector<uint8_t> AlgoAES128::encryptPayload(
+ std::vector<uint8_t>& payload) const
{
auto payloadLen = payload.size();
@@ -100,7 +103,7 @@ buffer AlgoAES128::encryptPayload(buffer& payload) const
return encryptData(payload.data(), payload.size());
}
-buffer AlgoAES128::decryptData(const uint8_t* iv,
+std::vector<uint8_t> AlgoAES128::decryptData(const uint8_t* iv,
const uint8_t* input,
const int inputLen) const
{
@@ -136,7 +139,7 @@ buffer AlgoAES128::decryptData(const uint8_t* iv,
*/
EVP_CIPHER_CTX_set_padding(ctxPtr.get(), 0);
- buffer output(inputLen + AESCBC128BlockSize);
+ std::vector<uint8_t> output(inputLen + AESCBC128BlockSize);
int outputLen = 0;
@@ -159,9 +162,10 @@ buffer AlgoAES128::decryptData(const uint8_t* iv,
return output;
}
-buffer AlgoAES128::encryptData(const uint8_t* input, const int inputLen) const
+std::vector<uint8_t> AlgoAES128::encryptData(const uint8_t* input,
+ const int inputLen) const
{
- buffer output(inputLen + AESCBC128BlockSize);
+ std::vector<uint8_t> output(inputLen + AESCBC128BlockSize);
// Generate the initialization vector
if (!RAND_bytes(output.data(), AESCBC128ConfHeader))
diff --git a/crypt_algo.hpp b/crypt_algo.hpp
index d1e3940..ccef7d8 100644
--- a/crypt_algo.hpp
+++ b/crypt_algo.hpp
@@ -10,7 +10,6 @@ namespace cipher
namespace crypt
{
-using buffer = std::vector<uint8_t>;
using key = std::array<uint8_t, SHA_DIGEST_LENGTH>;
/**
@@ -47,7 +46,7 @@ class Interface
* @param[in] - Session Integrity key to generate K2
* @param[in] - Additional keying material to generate K2
*/
- explicit Interface(const buffer& sik, const key& addKey);
+ explicit Interface(const std::vector<uint8_t>& sik, const key& addKey);
Interface() = delete;
virtual ~Interface() = default;
@@ -65,8 +64,8 @@ class Interface
*
* @return decrypted payload if the operation is successful
*/
- virtual buffer decryptPayload(
- const buffer& packet,
+ virtual std::vector<uint8_t> decryptPayload(
+ const std::vector<uint8_t>& packet,
const size_t sessHeaderLen,
const size_t payloadLen) const = 0;
@@ -78,7 +77,8 @@ class Interface
* @return encrypted payload if the operation is successful
*
*/
- virtual buffer encryptPayload(buffer& payload) const = 0;
+ virtual std::vector<uint8_t> encryptPayload(
+ std::vector<uint8_t>& payload) const = 0;
/**
* @brief Check if the Confidentiality algorithm is supported
@@ -107,7 +107,7 @@ class Interface
* generated by processing a pre-defined constant keyed by Session
* Integrity Key (SIK) that was created during session activation.
*/
- key k2;
+ std::vector<uint8_t> k2;
};
/**
@@ -166,7 +166,7 @@ class AlgoAES128 final : public Interface
*
* @param[in] - Session Integrity key
*/
- explicit AlgoAES128(const buffer& sik) : Interface(sik, const2) {}
+ explicit AlgoAES128(const std::vector<uint8_t>& sik) : Interface(sik, const2) {}
AlgoAES128() = delete;
~AlgoAES128() = default;
@@ -184,8 +184,8 @@ class AlgoAES128 final : public Interface
*
* @return decrypted payload if the operation is successful
*/
- buffer decryptPayload(
- const buffer& packet,
+ std::vector<uint8_t> decryptPayload(
+ const std::vector<uint8_t>& packet,
const size_t sessHeaderLen,
const size_t payloadLen) const override;
@@ -197,7 +197,8 @@ class AlgoAES128 final : public Interface
* @return encrypted payload if the operation is successful
*
*/
- buffer encryptPayload(buffer& payload) const override;
+ std::vector<uint8_t> encryptPayload(
+ std::vector<uint8_t>& payload) const override;
private:
@@ -210,7 +211,7 @@ class AlgoAES128 final : public Interface
*
* @return decrypted data if the operation is successful
*/
- buffer decryptData(const uint8_t* iv,
+ std::vector<uint8_t> decryptData(const uint8_t* iv,
const uint8_t* input,
const int inputLen) const;
@@ -222,7 +223,7 @@ class AlgoAES128 final : public Interface
*
* @return encrypted data if the operation is successful
*/
- buffer encryptData(const uint8_t* input,
+ std::vector<uint8_t> encryptData(const uint8_t* input,
const int inputLen) const;
};
diff --git a/integrity_algo.cpp b/integrity_algo.cpp
index 16d0863..3a6c34d 100644
--- a/integrity_algo.cpp
+++ b/integrity_algo.cpp
@@ -9,7 +9,8 @@ namespace cipher
namespace integrity
{
-Interface::Interface(const Buffer& sik, const Key& addKey, size_t authLength)
+Interface::Interface(const std::vector<uint8_t>& sik,
+ const Key& addKey, size_t authLength)
{
unsigned int mdLen = 0;
@@ -25,9 +26,10 @@ Interface::Interface(const Buffer& sik, const Key& addKey, size_t authLength)
authCodeLength = authLength;
}
-Buffer AlgoSHA1::generateHMAC(const uint8_t* input, const size_t len) const
+std::vector<uint8_t> AlgoSHA1::generateHMAC(const uint8_t* input,
+ const size_t len) const
{
- Buffer output(SHA_DIGEST_LENGTH);
+ std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
unsigned int mdLen = 0;
if (HMAC(EVP_sha1(), K1.data(), K1.size(), input, len,
@@ -45,9 +47,10 @@ Buffer AlgoSHA1::generateHMAC(const uint8_t* input, const size_t len) const
return output;
}
-bool AlgoSHA1::verifyIntegrityData(const Buffer& packet,
- const size_t length,
- Buffer::const_iterator integrityData) const
+bool AlgoSHA1::verifyIntegrityData(
+ const std::vector<uint8_t>& packet,
+ const size_t length,
+ std::vector<uint8_t>::const_iterator integrityData) const
{
auto output = generateHMAC(
@@ -59,7 +62,8 @@ bool AlgoSHA1::verifyIntegrityData(const Buffer& packet,
return (std::equal(output.begin(), output.end(), integrityData));
}
-Buffer AlgoSHA1::generateIntegrityData(const Buffer& packet) const
+std::vector<uint8_t> AlgoSHA1::generateIntegrityData(
+ const std::vector<uint8_t>& packet) const
{
return generateHMAC(
packet.data() + message::parser::RMCP_SESSION_HEADER_SIZE,
diff --git a/integrity_algo.hpp b/integrity_algo.hpp
index eb78578..0d869c7 100644
--- a/integrity_algo.hpp
+++ b/integrity_algo.hpp
@@ -10,7 +10,6 @@ namespace cipher
namespace integrity
{
-using Buffer = std::vector<uint8_t>;
using Key = std::array<uint8_t, SHA_DIGEST_LENGTH>;
/*
@@ -66,7 +65,7 @@ class Interface
* @param[in] - Additional keying material to generate K1
* @param[in] - AuthCode length
*/
- explicit Interface(const Buffer& sik,
+ explicit Interface(const std::vector<uint8_t>& sik,
const Key& addKey,
size_t authLength);
@@ -88,9 +87,9 @@ class Interface
* using integrity algorithm on the packet data, false otherwise
*/
bool virtual verifyIntegrityData(
- const Buffer& packet,
+ const std::vector<uint8_t>& packet,
const size_t packetLen,
- Buffer::const_iterator integrityData) const = 0;
+ std::vector<uint8_t>::const_iterator integrityData) const = 0;
/**
* @brief Generate integrity data for the outgoing IPMI packet
@@ -100,7 +99,8 @@ class Interface
* @return authcode for the outgoing IPMI packet
*
*/
- Buffer virtual generateIntegrityData(const Buffer& input) const = 0;
+ std::vector<uint8_t> virtual generateIntegrityData(
+ const std::vector<uint8_t>& input) const = 0;
/**
* @brief Check if the Integrity algorithm is supported
@@ -157,7 +157,7 @@ class AlgoSHA1 final : public Interface
*
* @param[in] - Session Integrity Key
*/
- explicit AlgoSHA1(const Buffer& sik) :
+ explicit AlgoSHA1(const std::vector<uint8_t>& sik) :
Interface(sik, const1, SHA1_96_AUTHCODE_LENGTH) {}
AlgoSHA1() = delete;
@@ -179,9 +179,10 @@ class AlgoSHA1 final : public Interface
* using integrity algorithm on the packet data, false otherwise
*/
bool verifyIntegrityData(
- const Buffer& packet,
+ const std::vector<uint8_t>& packet,
const size_t length,
- Buffer::const_iterator integrityData) const override;
+ std::vector<uint8_t>::const_iterator integrityData)
+ const override;
/**
* @brief Generate integrity data for the outgoing IPMI packet
@@ -191,7 +192,8 @@ class AlgoSHA1 final : public Interface
* @return on success return the integrity data for the outgoing IPMI
* packet
*/
- Buffer generateIntegrityData(const Buffer& packet) const override;
+ std::vector<uint8_t> generateIntegrityData(
+ const std::vector<uint8_t>& packet) const override;
private:
/**
@@ -203,7 +205,8 @@ class AlgoSHA1 final : public Interface
* @return on success returns the message authentication code
*
*/
- Buffer generateHMAC(const uint8_t* input, const size_t len) const;
+ std::vector<uint8_t> generateHMAC(const uint8_t* input,
+ const size_t len) const;
};
}// namespace integrity
diff --git a/message_handler.cpp b/message_handler.cpp
index e66e39c..beeb798 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -187,7 +187,7 @@ void Handler::setChannelInSession() const
session->channelPtr = channel;
}
-void Handler::sendSOLPayload(const sol::Buffer& input)
+void Handler::sendSOLPayload(const std::vector<uint8_t>& input)
{
Message outMessage;
diff --git a/message_handler.hpp b/message_handler.hpp
index 11cc42a..7fb06f1 100644
--- a/message_handler.hpp
+++ b/message_handler.hpp
@@ -68,7 +68,7 @@ class Handler
*
* @param[in] input - SOL Payload
*/
- void sendSOLPayload(const sol::Buffer& input);
+ void sendSOLPayload(const std::vector<uint8_t>& input);
/** @brief Send the unsolicited IPMI payload to the remote console.
*
diff --git a/socket_channel.cpp b/socket_channel.cpp
index e77c6cf..8414f51 100644
--- a/socket_channel.cpp
+++ b/socket_channel.cpp
@@ -19,12 +19,12 @@ std::string Channel::getRemoteAddress() const
return std::string(tmp);
}
-std::tuple<int, buffer> Channel::read()
+std::tuple<int, std::vector<uint8_t>> Channel::read()
{
int rc = 0;
int readSize = 0;
ssize_t readDataLen = 0;
- buffer outBuffer(0);
+ std::vector<uint8_t> outBuffer(0);
if (ioctl(sockfd, FIONREAD, &readSize) < 0)
{
@@ -70,7 +70,7 @@ std::tuple<int, buffer> Channel::read()
return std::make_tuple(rc, std::move(outBuffer));
}
-int Channel::write(buffer& inBuffer)
+int Channel::write(const std::vector<uint8_t>& inBuffer)
{
int rc = 0;
auto outputPtr = inBuffer.data();
diff --git a/socket_channel.hpp b/socket_channel.hpp
index 2bc7a33..5996b62 100644
--- a/socket_channel.hpp
+++ b/socket_channel.hpp
@@ -10,7 +10,6 @@
namespace udpsocket
{
-using buffer = std::vector<uint8_t>;
/** @class Channel
*
* @brief Provides encapsulation for UDP socket operations like Read, Peek,
@@ -79,7 +78,7 @@ class Channel
* In case of error, the return code is < 0 and vector is set
* to size 0.
*/
- std::tuple<int, buffer> read();
+ std::tuple<int, std::vector<uint8_t>> read();
/**
* @brief Write the outgoing packet
@@ -92,7 +91,7 @@ class Channel
* @return In case of success the return code is 0 and return code is
* < 0 in case of failure.
*/
- int write(buffer& inBuffer);
+ int write(const std::vector<uint8_t>& inBuffer);
/**
* @brief Returns file descriptor for the socket
diff --git a/sol/console_buffer.hpp b/sol/console_buffer.hpp
index b874be5..fe4bfe8 100644
--- a/sol/console_buffer.hpp
+++ b/sol/console_buffer.hpp
@@ -8,7 +8,6 @@ namespace sol
{
using ConsoleBuffer = std::deque<uint8_t>;
-using Buffer = std::vector<uint8_t>;
/** @class ConsoleData
*
@@ -47,7 +46,7 @@ class ConsoleData
*
* @param[in] input - data to be written to the console buffer.
*/
- void write(const Buffer& input)
+ void write(const std::vector<uint8_t>& input)
{
data.insert(data.end(), input.begin(), input.end());
}
diff --git a/sol/sol_context.cpp b/sol/sol_context.cpp
index 08be77b..ffa6834 100644
--- a/sol/sol_context.cpp
+++ b/sol/sol_context.cpp
@@ -13,7 +13,7 @@ void Context::processInboundPayload(uint8_t seqNum,
uint8_t ackSeqNum,
uint8_t count,
bool status,
- const Buffer& input)
+ const std::vector<uint8_t>& input)
{
uint8_t respAckSeqNum = 0;
uint8_t acceptedCount = 0;
@@ -127,7 +127,7 @@ void Context::prepareResponse(uint8_t ackSeqNum, uint8_t count, bool ack)
std::get<eventloop::EventLoop&>(singletonPool).switchTimer
(payloadInstance, eventloop::Timers::ACCUMULATE, true);
- Buffer outPayload(sizeof(Payload));
+ std::vector<uint8_t> outPayload(sizeof(Payload));
auto response = reinterpret_cast<Payload*>(outPayload.data());
response->packetSeqNum = 0;
response->packetAckSeqNum = ackSeqNum;
@@ -204,7 +204,7 @@ void Context::resendPayload(bool clear)
}
}
-void Context::sendPayload(const Buffer& out) const
+void Context::sendPayload(const std::vector<uint8_t>& out) const
{
auto session = (std::get<session::Manager&>(singletonPool).getSession(
sessionID)).lock();
diff --git a/sol/sol_context.hpp b/sol/sol_context.hpp
index 9de88c9..dadf492 100644
--- a/sol/sol_context.hpp
+++ b/sol/sol_context.hpp
@@ -209,7 +209,7 @@ class Context
uint8_t ackSeqNum,
uint8_t count,
bool status,
- const Buffer& input);
+ const std::vector<uint8_t>& input);
/** @brief Send the outbound SOL payload.
*
@@ -242,7 +242,7 @@ class Context
* A copy of the SOL payload is kept here, so that when a retry needs
* to be attempted the payload is sent again.
*/
- Buffer payloadCache;
+ std::vector<uint8_t> payloadCache;
/**
* @brief Send Response for Incoming SOL payload.
@@ -257,7 +257,7 @@ class Context
*
* @param[in] out - buffer containing the SOL payload.
*/
- void sendPayload(const Buffer& out) const;
+ void sendPayload(const std::vector<uint8_t>& out) const;
};
} // namespace sol
diff --git a/sol/sol_manager.cpp b/sol/sol_manager.cpp
index 889065f..b6cf31d 100644
--- a/sol/sol_manager.cpp
+++ b/sol/sol_manager.cpp
@@ -52,7 +52,7 @@ void Manager::initHostConsoleFd()
}
}
-int Manager::writeConsoleSocket(const Buffer& input) const
+int Manager::writeConsoleSocket(const std::vector<uint8_t>& input) const
{
auto inBuffer = input.data();
auto inBufferSize = input.size();
diff --git a/sol/sol_manager.hpp b/sol/sol_manager.hpp
index a107994..4a615af 100644
--- a/sol/sol_manager.hpp
+++ b/sol/sol_manager.hpp
@@ -247,7 +247,7 @@ class Manager
*
* @return 0 on success and errno on failure.
*/
- int writeConsoleSocket(const Buffer& input) const;
+ int writeConsoleSocket(const std::vector<uint8_t>& input) const;
private:
SOLPayloadMap payloadMap;
diff --git a/test/cipher.cpp b/test/cipher.cpp
index 84929d6..f10c8a0 100644
--- a/test/cipher.cpp
+++ b/test/cipher.cpp
@@ -51,7 +51,7 @@ TEST(IntegrityAlgo, HMAC_SHA1_96_GenerateIntegrityDataCheck)
}
mdLen = 0;
- cipher::integrity::Buffer output(SHA_DIGEST_LENGTH);
+ std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
size_t length = packet.size() - message::parser::RMCP_SESSION_HEADER_SIZE;
if (HMAC(EVP_sha1(), K1.data(), K1.size(),
@@ -102,7 +102,7 @@ TEST(IntegrityAlgo, HMAC_SHA1_96_VerifyIntegrityDataPass)
}
mdLen = 0;
- cipher::integrity::Buffer output(SHA_DIGEST_LENGTH);
+ std::vector<uint8_t> output(SHA_DIGEST_LENGTH);
size_t length = packet.size() - message::parser::RMCP_SESSION_HEADER_SIZE;
if (HMAC(EVP_sha1(), K1.data(), K1.size(),
OpenPOWER on IntegriCloud