summaryrefslogtreecommitdiff
path: root/src/shared/tpm2-util.h
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2023-01-23 19:52:56 -0500
committerDan Streetman <ddstreet@ieee.org>2023-02-01 12:51:17 -0500
commit68d084cee56e2686fb840106de20e267482183be (patch)
tree7d56e860be25458e9b4640baa57c45a2ef22275b /src/shared/tpm2-util.h
parentbd860983a6f884e37e88915f545d5520f92890ec (diff)
downloadsystemd-68d084cee56e2686fb840106de20e267482183be.tar.gz
tpm2: use ref counter for Tpm2Context
This will be used by Tpm2Handle instances, which is added in later patches. The refcounting allows the context to be retained until all Tpm2Handles have been cleaned up, and the initial ref is released, before cleaning the context.
Diffstat (limited to 'src/shared/tpm2-util.h')
-rw-r--r--src/shared/tpm2-util.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h
index d48cbecd42..bb89931913 100644
--- a/src/shared/tpm2-util.h
+++ b/src/shared/tpm2-util.h
@@ -54,11 +54,19 @@ int tpm2_seal(const char *device, uint32_t hash_pcr_mask, const void *pubkey, si
int tpm2_unseal(const char *device, uint32_t hash_pcr_mask, uint16_t pcr_bank, const void *pubkey, size_t pubkey_size, uint32_t pubkey_pcr_mask, JsonVariant *signature, const char *pin, uint16_t primary_alg, const void *blob, size_t blob_size, const void *policy_hash, size_t policy_hash_size, void **ret_secret, size_t *ret_secret_size);
typedef struct {
+ unsigned n_ref;
+
void *tcti_dl;
TSS2_TCTI_CONTEXT *tcti_context;
ESYS_CONTEXT *esys_context;
} Tpm2Context;
+int tpm2_context_new(const char *device, Tpm2Context **ret_context);
+Tpm2Context *tpm2_context_ref(Tpm2Context *context);
+Tpm2Context *tpm2_context_unref(Tpm2Context *context);
+DEFINE_TRIVIAL_CLEANUP_FUNC(Tpm2Context*, tpm2_context_unref);
+#define _cleanup_tpm2_context_ _cleanup_(tpm2_context_unrefp)
+
ESYS_TR tpm2_flush_context_verbose(ESYS_CONTEXT *c, ESYS_TR handle);
void tpm2_pcr_mask_to_selection(uint32_t mask, uint16_t bank, TPML_PCR_SELECTION *ret);
@@ -77,9 +85,6 @@ int tpm2_extend_bytes(ESYS_CONTEXT *c, char **banks, unsigned pcr_index, const v
typedef struct {} Tpm2Context;
#endif /* HAVE_TPM2 */
-int tpm2_context_init(const char *device, Tpm2Context *ret);
-void tpm2_context_destroy(Tpm2Context *c);
-
int tpm2_list_devices(void);
int tpm2_find_device_auto(int log_level, char **ret);