openssl: test: stop using deprecated SHA512_* functions
Complete the work from I91959eef65793f1092536f7e4c027839ce6cdf52 to
switch the test cases over to the OpenSSL 3 supported functions.
Tested: This was done in two steps to show that the conversion is
identical. Test cases pass with conversion.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ia2abc82f0b1282a52925a0eb9a2246d05f9b30cf
diff --git a/test/utest.cpp b/test/utest.cpp
index 40f7ea8..1c32b1a 100644
--- a/test/utest.cpp
+++ b/test/utest.cpp
@@ -2,7 +2,7 @@
#include "utils.hpp"
#include "version.hpp"
-#include <openssl/sha.h>
+#include <openssl/evp.h>
#include <stdlib.h>
#include <filesystem>
@@ -110,13 +110,17 @@
TEST_F(VersionTest, TestGetId)
{
auto version = "test-id";
- unsigned char digest[SHA512_DIGEST_LENGTH];
- SHA512_CTX ctx;
- SHA512_Init(&ctx);
- SHA512_Update(&ctx, version, strlen(version));
- SHA512_Final(digest, &ctx);
- char mdString[SHA512_DIGEST_LENGTH * 2 + 1];
- for (int i = 0; i < SHA512_DIGEST_LENGTH; i++)
+ unsigned char digest[EVP_MAX_MD_SIZE];
+ unsigned int digest_count = 0;
+
+ EVP_MD_CTX_Ptr ctx(EVP_MD_CTX_new(), &::EVP_MD_CTX_free);
+
+ EVP_DigestInit(ctx.get(), EVP_sha512());
+ EVP_DigestUpdate(ctx.get(), version, strlen(version));
+ EVP_DigestFinal(ctx.get(), digest, &digest_count);
+
+ char mdString[EVP_MAX_MD_SIZE * 2 + 1];
+ for (decltype(digest_count) i = 0; i < digest_count; i++)
{
snprintf(&mdString[i * 2], 3, "%02x", (unsigned int)digest[i]);
}