From 9c55ee2710df218c30015ac6775015b7095457ad Mon Sep 17 00:00:00 2001 From: Manoj Takasi Date: Sat, 22 Jun 2024 00:08:30 +0530 Subject: [PATCH] Replaced OpenSSL calls to EVP Digest calls Signed-off-by: Manoj Takasi --- .../pcie/tools/cloud-daemon/azure/azure.cpp | 33 ++++++++++++------- .../cloud-daemon/container/container.cpp | 12 +++---- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/runtime_src/core/pcie/tools/cloud-daemon/azure/azure.cpp b/src/runtime_src/core/pcie/tools/cloud-daemon/azure/azure.cpp index 05a3643374c..218c962184e 100644 --- a/src/runtime_src/core/pcie/tools/cloud-daemon/azure/azure.cpp +++ b/src/runtime_src/core/pcie/tools/cloud-daemon/azure/azure.cpp @@ -9,9 +9,8 @@ #include #include #include -#define OPENSSL_SUPPRESS_DEPRECATED #include -#undef OPENSSL_SUPPRESS_DEPRECATED +#include #include #include @@ -563,22 +562,29 @@ int AzureDev::Sha256AndSplit( std::vector &output, std::string &sha) { + + std::stringstream shastr; + unsigned pos = 0; // Initialize openssl - SHA256_CTX context; - if (!SHA256_Init(&context)) { + EVP_MD_CTX *context; + if(!(context = EVP_MD_CTX_new())) { + std::cerr << "Failed to initialize OpenSSL context" << std::endl; + return 1; + } + + if (!EVP_DigestInit(context, EVP_sha256())) { std::cerr << "Unable to initiate SHA256" << std::endl; - return 1; + goto out; } - unsigned pos = 0; while (pos < input.size()) { std::string segment = input.substr(pos, transfer_segment_size); - if(!SHA256_Update(&context, segment.c_str(), segment.size())) + if(!EVP_DigestUpdate(context, segment.c_str(), segment.size())) { std::cerr << "Unable to Update SHA256 buffer" << std::endl; - return 1; + goto out; } output.push_back(segment); pos += transfer_segment_size; @@ -586,19 +592,24 @@ int AzureDev::Sha256AndSplit( // Get Final SHA unsigned char result[SHA256_DIGEST_LENGTH]; - if(!SHA256_Final(result, &context)) { + if(!EVP_DigestFinal(context, result, NULL)) { std::cerr << "Error finalizing SHA256 calculation" << std::endl; - return 1; + goto out; } // Convert the byte array into a string - std::stringstream shastr; shastr << std::hex << std::setfill('0'); for (auto &byte: result) shastr << std::setw(2) << (int)byte; sha = shastr.str(); + EVP_MD_CTX_free(context); return 0; + +out: + if (context) + EVP_MD_CTX_free(context); + return 1; } void AzureDev::get_fpga_serialNo(std::string &fpgaSerialNo) diff --git a/src/runtime_src/core/pcie/tools/cloud-daemon/container/container.cpp b/src/runtime_src/core/pcie/tools/cloud-daemon/container/container.cpp index 6a5c6a1c605..61044f8ab2b 100644 --- a/src/runtime_src/core/pcie/tools/cloud-daemon/container/container.cpp +++ b/src/runtime_src/core/pcie/tools/cloud-daemon/container/container.cpp @@ -23,9 +23,8 @@ #include #include #include -#define OPENSSL_SUPPRESS_DEPRECATED #include -#undef OPENSSL_SUPPRESS_DEPRECATED +#include #include "xrt/detail/xclbin.h" #include "container.h" @@ -223,10 +222,10 @@ int Container::retrieve_xclbin(const xclBin *&orig, std::vector &real_xclb std::string Container::calculate_md5(char *buf, size_t len) { unsigned char s[16]; - MD5_CTX context; - MD5_Init(&context); - MD5_Update(&context, buf, len); - MD5_Final(s, &context); + EVP_MD_CTX *context = EVP_MD_CTX_new(); + EVP_DigestInit(context, EVP_md5()); + EVP_DigestUpdate(context, buf, len); + EVP_DigestFinal(context, s, NULL); std::stringstream md5; md5 << std::hex << std::setfill('0'); @@ -235,6 +234,7 @@ std::string Container::calculate_md5(char *buf, size_t len) md5 << std::setw(2) << (int)byte; } + EVP_MD_CTX_free(context); return md5.str(); }