summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaqib Khan <khansa@us.ibm.com>2017-09-19 15:33:06 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-10-04 02:58:20 +0000
commit2308b8bfaf1307c76c2a50984047a71fdaff7e53 (patch)
tree2a9ec3219ef08074f88bb4b4b112c8f3413dfa78
parentfa7aa12cdbf1ef7e70655fd62ed4ec28a885ce83 (diff)
downloadopenpower-pnor-code-mgmt-2308b8bfaf1307c76c2a50984047a71fdaff7e53.tar.gz
openpower-pnor-code-mgmt-2308b8bfaf1307c76c2a50984047a71fdaff7e53.zip
Use sha512 to calcualte the versionID for images.
- We needed a hash algorithm that can be replicated on multiple platforms and across multiple programming languages. - This would allow the user to calculate the versionID by executing the following command to obtain correct versionID. echo -n "<versionID>" | sha512sum | cut -b 1-8 - This is part of the change required for openbmc/openbmc#2323 Change-Id: I799a9a2b83fdf35beaf61b9df5ed69162f610d2f Signed-off-by: Saqib Khan <khansa@us.ibm.com>
-rwxr-xr-xMakefile.am4
-rw-r--r--version.cpp20
2 files changed, 18 insertions, 6 deletions
diff --git a/Makefile.am b/Makefile.am
index 0b94db409..cada5a269 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,7 +34,9 @@ generic_ldflags = \
$(PHOSPHOR_DBUS_INTERFACES_LIBS) \
$(SDBUSPLUS_LIBS) \
$(PHOSPHOR_LOGGING_LIBS) \
- -lstdc++fs
+ -lstdc++fs \
+ -lssl \
+ -lcrypto
org/openbmc/Associations/server.cpp: org/openbmc/Associations.interface.yaml
@mkdir -p `dirname $@`
diff --git a/version.cpp b/version.cpp
index 013cc68b0..8e36071fd 100644
--- a/version.cpp
+++ b/version.cpp
@@ -8,6 +8,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include "xyz/openbmc_project/Common/error.hpp"
#include "item_updater.hpp"
+#include <openssl/sha.h>
namespace openpower
{
@@ -22,7 +23,6 @@ using Argument = xyz::openbmc_project::Common::InvalidArgument;
std::string Version::getId(const std::string& version)
{
- std::stringstream hexId;
if (version.empty())
{
@@ -31,10 +31,20 @@ std::string Version::getId(const std::string& version)
Argument::ARGUMENT_VALUE(version.c_str()));
}
- // Only want 8 hex digits.
- hexId << std::hex << ((std::hash<std::string> {}(
- version)) & 0xFFFFFFFF);
- return hexId.str();
+ unsigned char digest[SHA512_DIGEST_LENGTH];
+ SHA512_CTX ctx;
+ SHA512_Init(&ctx);
+ SHA512_Update(&ctx, version.c_str(), strlen(version.c_str()));
+ SHA512_Final(digest, &ctx);
+ char mdString[SHA512_DIGEST_LENGTH*2+1];
+ for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
+ {
+ snprintf(&mdString[i*2], 3, "%02x", (unsigned int)digest[i]);
+ }
+
+ // Only need 8 hex digits.
+ std::string hexId = std::string(mdString);
+ return (hexId.substr(0, 8));
}
std::map<std::string, std::string> Version::getValue(
OpenPOWER on IntegriCloud