Use sha512 to calculate 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: Ibc96a2871f07cb549c482c06dec7090e6ba3a766
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/version.cpp b/version.cpp
index e6dd9de..133e5a4 100644
--- a/version.cpp
+++ b/version.cpp
@@ -6,6 +6,7 @@
 #include <phosphor-logging/log.hpp>
 #include "config.h"
 #include "version.hpp"
+#include <openssl/sha.h>
 
 namespace phosphor
 {
@@ -59,7 +60,6 @@
 
 std::string Version::getId(const std::string& version)
 {
-    std::stringstream hexId;
 
     if (version.empty())
     {
@@ -67,10 +67,20 @@
         throw std::runtime_error("Version is empty");
     }
 
-    // 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::string Version::getBMCVersion(const std::string& releaseFilePath)