chantra / rpms / tpm2-tools

Forked from rpms/tpm2-tools 2 years ago
Clone

Blame SOURCES/0007-openssl-Remove-unnecesary-EVP_CIPHER_CTX-and-HMAC_CT.patch

28a59a
From 43ad483907069798920a949a3cc9615cb3156975 Mon Sep 17 00:00:00 2001
28a59a
From: Petr Gotthard <petr.gotthard@centrum.cz>
28a59a
Date: Sat, 7 Aug 2021 11:56:22 +0200
28a59a
Subject: [PATCH 06/17] openssl: Remove unnecesary EVP_CIPHER_CTX and HMAC_CTX
28a59a
 wrappers
28a59a
28a59a
Signed-off-by: Petr Gotthard <petr.gotthard@centrum.cz>
28a59a
---
28a59a
 lib/tpm2_identity_util.c |  7 +++++--
28a59a
 lib/tpm2_kdfa.c          |  4 ++--
28a59a
 lib/tpm2_openssl.c       | 26 --------------------------
28a59a
 lib/tpm2_openssl.h       | 31 -------------------------------
28a59a
 4 files changed, 7 insertions(+), 61 deletions(-)
28a59a
28a59a
diff --git a/lib/tpm2_identity_util.c b/lib/tpm2_identity_util.c
28a59a
index e11137ab..a268295f 100644
28a59a
--- a/lib/tpm2_identity_util.c
28a59a
+++ b/lib/tpm2_identity_util.c
28a59a
@@ -289,7 +289,10 @@ static bool aes_encrypt_buffers(TPMT_SYM_DEF_OBJECT *sym,
28a59a
         return false;
28a59a
     }
28a59a
 
28a59a
-    EVP_CIPHER_CTX *ctx = tpm2_openssl_cipher_new();
28a59a
+    EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
28a59a
+    if (!ctx) {
28a59a
+        return false;
28a59a
+    }
28a59a
 
28a59a
     int rc = EVP_EncryptInit_ex(ctx, cipher, NULL, encryption_key, iv);
28a59a
     if (!rc) {
28a59a
@@ -336,7 +339,7 @@ static bool aes_encrypt_buffers(TPMT_SYM_DEF_OBJECT *sym,
28a59a
     result = true;
28a59a
 
28a59a
 out:
28a59a
-    tpm2_openssl_cipher_free(ctx);
28a59a
+    EVP_CIPHER_CTX_free(ctx);
28a59a
 
28a59a
     return result;
28a59a
 }
28a59a
diff --git a/lib/tpm2_kdfa.c b/lib/tpm2_kdfa.c
28a59a
index 354516e8..5747b3ca 100644
28a59a
--- a/lib/tpm2_kdfa.c
28a59a
+++ b/lib/tpm2_kdfa.c
28a59a
@@ -40,7 +40,7 @@ TSS2_RC tpm2_kdfa(TPMI_ALG_HASH hash_alg, TPM2B *key, char *label,
28a59a
         return TPM2_RC_HASH;
28a59a
     }
28a59a
 
28a59a
-    HMAC_CTX *ctx = tpm2_openssl_hmac_new();
28a59a
+    HMAC_CTX *ctx = HMAC_CTX_new();
28a59a
     if (!ctx) {
28a59a
         LOG_ERR("HMAC context allocation failed");
28a59a
         return TPM2_RC_MEMORY;
28a59a
@@ -100,7 +100,7 @@ TSS2_RC tpm2_kdfa(TPMI_ALG_HASH hash_alg, TPM2B *key, char *label,
28a59a
     result_key->size = bytes;
28a59a
 
28a59a
 err:
28a59a
-    tpm2_openssl_hmac_free(ctx);
28a59a
+    HMAC_CTX_free(ctx);
28a59a
 
28a59a
     return rval;
28a59a
 }
28a59a
diff --git a/lib/tpm2_openssl.c b/lib/tpm2_openssl.c
28a59a
index 877d2764..1752525e 100644
28a59a
--- a/lib/tpm2_openssl.c
28a59a
+++ b/lib/tpm2_openssl.c
28a59a
@@ -368,32 +368,6 @@ out:
28a59a
     return result;
28a59a
 }
28a59a
 
28a59a
-HMAC_CTX *tpm2_openssl_hmac_new() {
28a59a
-    HMAC_CTX *ctx;
28a59a
-    ctx = HMAC_CTX_new();
28a59a
-    if (!ctx)
28a59a
-        return NULL;
28a59a
-
28a59a
-    return ctx;
28a59a
-}
28a59a
-
28a59a
-void tpm2_openssl_hmac_free(HMAC_CTX *ctx) {
28a59a
-    HMAC_CTX_free(ctx);
28a59a
-}
28a59a
-
28a59a
-EVP_CIPHER_CTX *tpm2_openssl_cipher_new(void) {
28a59a
-    EVP_CIPHER_CTX *ctx;
28a59a
-    ctx = EVP_CIPHER_CTX_new();
28a59a
-    if (!ctx)
28a59a
-        return NULL;
28a59a
-
28a59a
-    return ctx;
28a59a
-}
28a59a
-
28a59a
-void tpm2_openssl_cipher_free(EVP_CIPHER_CTX *ctx) {
28a59a
-    EVP_CIPHER_CTX_free(ctx);
28a59a
-}
28a59a
-
28a59a
 digester tpm2_openssl_halg_to_digester(TPMI_ALG_HASH halg) {
28a59a
 
28a59a
     switch (halg) {
28a59a
diff --git a/lib/tpm2_openssl.h b/lib/tpm2_openssl.h
28a59a
index 8e3e0c17..642e4635 100644
28a59a
--- a/lib/tpm2_openssl.h
28a59a
+++ b/lib/tpm2_openssl.h
28a59a
@@ -67,20 +67,6 @@ int tpm2_openssl_halgid_from_tpmhalg(TPMI_ALG_HASH algorithm);
28a59a
  */
28a59a
 const EVP_MD *tpm2_openssl_halg_from_tpmhalg(TPMI_ALG_HASH algorithm);
28a59a
 
28a59a
-/**
28a59a
- * Start an openssl hmac session.
28a59a
- * @return
28a59a
- *  A valid session pointer or NULL on error.
28a59a
- */
28a59a
-HMAC_CTX *tpm2_openssl_hmac_new();
28a59a
-
28a59a
-/**
28a59a
- * Free an hmac context created via tpm2_openssl_hmac_new().
28a59a
- * @param ctx
28a59a
- *  The context to release resources of.
28a59a
- */
28a59a
-void tpm2_openssl_hmac_free(HMAC_CTX *ctx);
28a59a
-
28a59a
 /**
28a59a
  * Hash a byte buffer.
28a59a
  * @param halg
28a59a
@@ -161,23 +147,6 @@ bool tpm2_openssl_hash_pcr_banks_le(TPMI_ALG_HASH hashAlg,
28a59a
 bool tpm2_openssl_pcr_extend(TPMI_ALG_HASH halg, BYTE *pcr,
28a59a
         const BYTE *data, UINT16 length);
28a59a
 
28a59a
-/**
28a59a
- * Obtains an OpenSSL EVP_CIPHER_CTX dealing with version
28a59a
- * API changes in OSSL.
28a59a
- *
28a59a
- * @return
28a59a
- *  An Initialized OpenSSL EVP_CIPHER_CTX.
28a59a
- */
28a59a
-EVP_CIPHER_CTX *tpm2_openssl_cipher_new(void);
28a59a
-
28a59a
-/**
28a59a
- * Free's an EVP_CIPHER_CTX obtained via tpm2_openssl_cipher_new()
28a59a
- * dealing with OSSL API version changes.
28a59a
- * @param ctx
28a59a
- *  The EVP_CIPHER_CTX to free.
28a59a
- */
28a59a
-void tpm2_openssl_cipher_free(EVP_CIPHER_CTX *ctx);
28a59a
-
28a59a
 /**
28a59a
  * Returns a function pointer capable of performing the
28a59a
  * given digest from a TPMI_HASH_ALG.
28a59a
-- 
28a59a
2.31.1
28a59a