From a7151f54a163b9b559b30d31f2d252c0c3b953a7 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Fri, 14 Jul 2023 07:23:55 -0400 Subject: [PATCH] tpm2: declare tpm2_log_debug_*() functions in tpm2_util.h Allow other code to use the log debug functions; e.g. they are useful in test code. (cherry picked from commit 75de375aafa78ccf2cd93a2c0a15d3bc4b0fe4b7) Related: RHEL-16182 --- src/shared/tpm2-util.c | 10 +++++----- src/shared/tpm2-util.h | 6 ++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index cef251e69c..c3e1ca8f3a 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -1829,7 +1829,7 @@ char *tpm2_pcr_values_to_string(const Tpm2PCRValue *pcr_values, size_t n_pcr_val return s ? TAKE_PTR(s) : strdup(""); } -static void tpm2_log_debug_tpml_pcr_selection(const TPML_PCR_SELECTION *l, const char *msg) { +void tpm2_log_debug_tpml_pcr_selection(const TPML_PCR_SELECTION *l, const char *msg) { if (!DEBUG_LOGGING || !l) return; @@ -1837,7 +1837,7 @@ static void tpm2_log_debug_tpml_pcr_selection(const TPML_PCR_SELECTION *l, const log_debug("%s: %s", msg ?: "PCR selection", strna(s)); } -static void tpm2_log_debug_pcr_value(const Tpm2PCRValue *pcr_value, const char *msg) { +void tpm2_log_debug_pcr_value(const Tpm2PCRValue *pcr_value, const char *msg) { if (!DEBUG_LOGGING || !pcr_value) return; @@ -1845,7 +1845,7 @@ static void tpm2_log_debug_pcr_value(const Tpm2PCRValue *pcr_value, const char * log_debug("%s: %s", msg ?: "PCR value", strna(s)); } -static void tpm2_log_debug_buffer(const void *buffer, size_t size, const char *msg) { +void tpm2_log_debug_buffer(const void *buffer, size_t size, const char *msg) { if (!DEBUG_LOGGING || !buffer || size == 0) return; @@ -1853,12 +1853,12 @@ static void tpm2_log_debug_buffer(const void *buffer, size_t size, const char *m log_debug("%s: %s", msg ?: "Buffer", strna(h)); } -static void tpm2_log_debug_digest(const TPM2B_DIGEST *digest, const char *msg) { +void tpm2_log_debug_digest(const TPM2B_DIGEST *digest, const char *msg) { if (digest) tpm2_log_debug_buffer(digest->buffer, digest->size, msg ?: "Digest"); } -static void tpm2_log_debug_name(const TPM2B_NAME *name, const char *msg) { +void tpm2_log_debug_name(const TPM2B_NAME *name, const char *msg) { if (name) tpm2_log_debug_buffer(name->name, name->size, msg ?: "Name"); } diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index 52016ca8d7..cecf35af4d 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -139,6 +139,12 @@ static inline int tpm2_digest_init(TPMI_ALG_HASH alg, TPM2B_DIGEST *digest) { return tpm2_digest_many(alg, digest, NULL, 0, false); } +void tpm2_log_debug_tpml_pcr_selection(const TPML_PCR_SELECTION *l, const char *msg); +void tpm2_log_debug_pcr_value(const Tpm2PCRValue *pcr_value, const char *msg); +void tpm2_log_debug_buffer(const void *buffer, size_t size, const char *msg); +void tpm2_log_debug_digest(const TPM2B_DIGEST *digest, const char *msg); +void tpm2_log_debug_name(const TPM2B_NAME *name, const char *msg); + int tpm2_calculate_name(const TPMT_PUBLIC *public, TPM2B_NAME *ret_name); int tpm2_calculate_policy_auth_value(TPM2B_DIGEST *digest); int tpm2_calculate_policy_authorize(const TPM2B_PUBLIC *public, const TPM2B_DIGEST *policy_ref, TPM2B_DIGEST *digest);