Upgrade to OpenSSL3 API 43/299143/4
authorJacek Kryszyn <j.kryszyn@samsung.com>
Wed, 20 Sep 2023 14:26:32 +0000 (16:26 +0200)
committerJacek Kryszyn <j.kryszyn@samsung.com>
Thu, 21 Sep 2023 12:30:12 +0000 (14:30 +0200)
Changed calls to OpenSSL API to use OpenSSL3 style functions with
proper error handling. Suppressed warnings about strncpy which is
used in a liblp library for copying bytes between char arrays
which don't have to be terminated with NUL

Change-Id: Ifb4c1e10ae39fbf03f7bd9a4087b631884fcddc0

src/parse-dynparts/liblp/CMakeLists.txt
src/parse-dynparts/liblp/utility.cpp

index 76a49e2411a10ef448f2a82a1e9cff4868355d69..44f3c8af7ac789eb0c09e6baffce2338a8b41a40 100644 (file)
@@ -1,7 +1,7 @@
 add_library(lp STATIC reader.cpp utility.cpp)
 
 target_include_directories(lp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
-target_compile_options(lp PRIVATE -Wall -Wextra -pedantic -fPIE)
+target_compile_options(lp PRIVATE -Wall -Wextra -pedantic -fPIE -Wno-stringop-truncation)
 
 find_package(OpenSSL REQUIRED)
 target_link_libraries(lp PRIVATE OpenSSL::Crypto)
\ No newline at end of file
index 4f7b0cecfc7d6b98cdaace5d8e0d5f44c4e2e6e5..afab23784be61ed2a622be6fad2507cfbbc68104 100644 (file)
@@ -31,6 +31,7 @@
 #include <vector>
 
 #include <openssl/sha.h>
+#include <openssl/evp.h>
 
 #include "utility.h"
 
@@ -77,10 +78,10 @@ const LpMetadataBlockDevice* GetMetadataSuperBlockDevice(const LpMetadata& metad
 }
 
 void SHA256(const void* data, size_t length, uint8_t out[32]) {
-    SHA256_CTX c;
-    SHA256_Init(&c);
-    SHA256_Update(&c, data, length);
-    SHA256_Final(out, &c);
+    const EVP_MD *md = EVP_sha256();
+
+    if (!EVP_Digest(data, length, out, nullptr, md, nullptr))
+        LERROR << __PRETTY_FUNCTION__ << "Unable to compute hash";
 }
 
 uint32_t SlotNumberForSlotSuffix(const std::string& suffix) {