Blame SOURCES/0008-openssl-Replace-SHA256_CTX-by-EVP_MD_CTX.patch

05e1a9
From 59f35567cf810d9eafdeedced5dc5571d9b33dfd Mon Sep 17 00:00:00 2001
05e1a9
From: Petr Gotthard <petr.gotthard@centrum.cz>
05e1a9
Date: Sat, 7 Aug 2021 12:26:15 +0200
05e1a9
Subject: [PATCH 07/17] openssl: Replace SHA256_CTX by EVP_MD_CTX
05e1a9
05e1a9
The EVP_MD_CTX_new() was introduced in OpenSSL 1.1.0 and
05e1a9
the SHA256_CTX was deprecated in OpenSSL 3.0.0.
05e1a9
05e1a9
Signed-off-by: Petr Gotthard <petr.gotthard@centrum.cz>
05e1a9
---
05e1a9
 tools/tpm2_getekcertificate.c | 28 +++++++++++++++-------------
05e1a9
 1 file changed, 15 insertions(+), 13 deletions(-)
05e1a9
05e1a9
diff --git a/tools/tpm2_getekcertificate.c b/tools/tpm2_getekcertificate.c
05e1a9
index b480dbc3..81600b61 100644
05e1a9
--- a/tools/tpm2_getekcertificate.c
05e1a9
+++ b/tools/tpm2_getekcertificate.c
05e1a9
@@ -63,20 +63,20 @@ static unsigned char *hash_ek_public(void) {
05e1a9
         return NULL;
05e1a9
     }
05e1a9
 
05e1a9
-    SHA256_CTX sha256;
05e1a9
-    int is_success = SHA256_Init(&sha256);
05e1a9
+    EVP_MD_CTX *sha256 = EVP_MD_CTX_new();
05e1a9
+    int is_success = EVP_DigestInit(sha256, EVP_sha256());
05e1a9
     if (!is_success) {
05e1a9
-        LOG_ERR("SHA256_Init failed");
05e1a9
+        LOG_ERR("EVP_DigestInit failed");
05e1a9
         goto err;
05e1a9
     }
05e1a9
 
05e1a9
     switch (ctx.out_public->publicArea.type) {
05e1a9
     case TPM2_ALG_RSA:
05e1a9
-        is_success = SHA256_Update(&sha256,
05e1a9
+        is_success = EVP_DigestUpdate(sha256,
05e1a9
                 ctx.out_public->publicArea.unique.rsa.buffer,
05e1a9
                 ctx.out_public->publicArea.unique.rsa.size);
05e1a9
         if (!is_success) {
05e1a9
-            LOG_ERR("SHA256_Update failed");
05e1a9
+            LOG_ERR("EVP_DigestUpdate failed");
05e1a9
             goto err;
05e1a9
         }
05e1a9
 
05e1a9
@@ -85,27 +85,27 @@ static unsigned char *hash_ek_public(void) {
05e1a9
             goto err;
05e1a9
         }
05e1a9
         BYTE buf[3] = { 0x1, 0x00, 0x01 }; // Exponent
05e1a9
-        is_success = SHA256_Update(&sha256, buf, sizeof(buf));
05e1a9
+        is_success = EVP_DigestUpdate(sha256, buf, sizeof(buf));
05e1a9
         if (!is_success) {
05e1a9
-            LOG_ERR("SHA256_Update failed");
05e1a9
+            LOG_ERR("EVP_DigestUpdate failed");
05e1a9
             goto err;
05e1a9
         }
05e1a9
         break;
05e1a9
 
05e1a9
     case TPM2_ALG_ECC:
05e1a9
-        is_success = SHA256_Update(&sha256,
05e1a9
+        is_success = EVP_DigestUpdate(sha256,
05e1a9
                 ctx.out_public->publicArea.unique.ecc.x.buffer,
05e1a9
                 ctx.out_public->publicArea.unique.ecc.x.size);
05e1a9
         if (!is_success) {
05e1a9
-            LOG_ERR("SHA256_Update failed");
05e1a9
+            LOG_ERR("EVP_DigestUpdate failed");
05e1a9
             goto err;
05e1a9
         }
05e1a9
 
05e1a9
-        is_success = SHA256_Update(&sha256,
05e1a9
+        is_success = EVP_DigestUpdate(sha256,
05e1a9
                 ctx.out_public->publicArea.unique.ecc.y.buffer,
05e1a9
                 ctx.out_public->publicArea.unique.ecc.y.size);
05e1a9
         if (!is_success) {
05e1a9
-            LOG_ERR("SHA256_Update failed");
05e1a9
+            LOG_ERR("EVP_DigestUpdate failed");
05e1a9
             goto err;
05e1a9
         }
05e1a9
         break;
05e1a9
@@ -115,12 +115,13 @@ static unsigned char *hash_ek_public(void) {
05e1a9
         goto err;
05e1a9
     }
05e1a9
 
05e1a9
-    is_success = SHA256_Final(hash, &sha256);
05e1a9
+    is_success = EVP_DigestFinal_ex(sha256, hash, NULL);
05e1a9
     if (!is_success) {
05e1a9
-        LOG_ERR("SHA256_Final failed");
05e1a9
+        LOG_ERR("EVP_DigestFinal failed");
05e1a9
         goto err;
05e1a9
     }
05e1a9
 
05e1a9
+    EVP_MD_CTX_free(sha256);
05e1a9
     if (ctx.verbose) {
05e1a9
         tpm2_tool_output("public-key-hash:\n");
05e1a9
         tpm2_tool_output("  sha256: ");
05e1a9
@@ -134,6 +135,7 @@ static unsigned char *hash_ek_public(void) {
05e1a9
     return hash;
05e1a9
 err:
05e1a9
     free(hash);
05e1a9
+    EVP_MD_CTX_free(sha256);
05e1a9
     return NULL;
05e1a9
 }
05e1a9
 
05e1a9
-- 
05e1a9
2.31.1
05e1a9