libtpmtss: Initialize library from all users
Previously, only the tpm plugin initialized the library, so in order to use a TPM 2.0 (a required TCTI library is loaded via init), it was necessary to load it even if none of its actual features were used.
This commit is contained in:
+15
-2
@@ -24,12 +24,22 @@
|
||||
#include "plugin_constructors.c"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Reference counter for library initialization
|
||||
*/
|
||||
static refcount_t libtpmtss_ref = 0;
|
||||
|
||||
/**
|
||||
* Described in header.
|
||||
*/
|
||||
bool libtpmtss_init(void)
|
||||
{
|
||||
return tpm_tss_tss2_init();
|
||||
if (ref_cur(&libtpmtss_ref) || tpm_tss_tss2_init())
|
||||
{
|
||||
ref_get(&libtpmtss_ref);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +47,10 @@ bool libtpmtss_init(void)
|
||||
*/
|
||||
void libtpmtss_deinit(void)
|
||||
{
|
||||
tpm_tss_tss2_deinit();
|
||||
if (ref_cur(&libtpmtss_ref) && ref_put(&libtpmtss_ref))
|
||||
{
|
||||
tpm_tss_tss2_deinit();
|
||||
}
|
||||
}
|
||||
|
||||
typedef tpm_tss_t*(*tpm_tss_create)(void);
|
||||
|
||||
@@ -192,22 +192,22 @@ struct tpm_tss_t {
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a tpm_tss instance.
|
||||
*
|
||||
* @param version TPM version that must be supported by TSS
|
||||
*/
|
||||
tpm_tss_t *tpm_tss_probe(tpm_version_t version);
|
||||
|
||||
/**
|
||||
* libtpmtss initialization function
|
||||
* Initialize libtpmtss
|
||||
*
|
||||
* @return TRUE if initialization was successful
|
||||
*/
|
||||
bool libtpmtss_init(void);
|
||||
|
||||
/**
|
||||
* libtpmtss de-initialization function
|
||||
* Deinitialize libtpmtss
|
||||
*/
|
||||
void libtpmtss_deinit(void);
|
||||
|
||||
/**
|
||||
* Create a tpm_tss instance.
|
||||
*
|
||||
* @param version TPM version that must be supported by TSS
|
||||
*/
|
||||
tpm_tss_t *tpm_tss_probe(tpm_version_t version);
|
||||
|
||||
#endif /** TPM_TSS_H_ @}*/
|
||||
|
||||
Reference in New Issue
Block a user