TPMLIB\_MainInit(3) TPMLIB\_MainInit(3)

# [NAME](#NAME)

TPMLIB\_MainInit - Initialize the TPM

TPMLIB\_Terminate - Terminate the TPM

# [LIBRARY](#LIBRARY)

TPM library (libtpms, -ltpms)

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;libtpms/tpm\_types.h**&gt;

**#include &lt;libtpms/tpm\_library.h**&gt;

**#include &lt;libtpms/tpm\_error.h**&gt;

**TPM\_RESULT TPMLIB\_MainInit(void);**

**TPM\_RESULT TPMLIB\_Terminate(void);**

# [DESCRIPTION](#DESCRIPTION)

The **TPMLIB\_MainInit()** and **TPMLIB\_Terminate()** functions are used to initialize and terminate the TPM respectively. The **TPMLIB\_MainInit()** function must be called before the TPM processes any TPM command. The **TPMLIB\_Terminate()** function is called to free all the internal resources (memory allocations) the TPM has used and must be called after the last TPM command was processed by the TPM. The **TPMLIB\_MainInit()** function can then be called again.

Use **TPMLIB\_RegisterCallbacks()** to set callback functions for initialization and writing and restoring the internal state in a portable format.

# [ERRORS](#ERRORS)

[**TPM\_SUCCESS**](#TPM_SUCCESS)

The function completed successfully.

[**TPM\_FAIL**](#TPM_FAIL)

General failure.

For a complete list of TPM error codes please consult the include file **libtpms/tpm\_error.h**

# [EXAMPLE](#EXAMPLE)

```
 #include <stdio.h>
 #include <libtpms/tpm_types.h>
 #include <libtpms/tpm_library.h>
 #include <libtpms/tpm_error.h>
 int main(void) {
     TPM_RESULT res;
     unsigned char *respbuffer = NULL;
     uint32_t resp_size = 0;
     uint32_t respbufsize = 0;
     unsigned char *command;
     uint32_t command_size;
     [...]
     if (TPMLIB_MainInit() != TPM_SUCCESS) {
         fprintf(stderr, "Could not start the TPM.\n");
         return 1;
     }
     [...]
     /* build TPM command */
     [...]
     res = TPMLIB_Process(&respbuffer, &resp_size,
                          &respbufsize,
                          command, command_size);
     [...]
     TPMLIB_Terminate();
     return 0;
 }
```

# [SEE ALSO](#SEE_ALSO)

[**TPMLIB\_Process**(3)](/man/enterprise-packages/libtpms/TPMLIB_Process.3), [**TPMLIB\_RegisterCallbacks**(3)](/man/enterprise-packages/libtpms/TPMLIB_RegisterCallbacks.3), [**TPMLIB\_GetVersion**(3)](/man/enterprise-packages/libtpms/TPMLIB_GetVersion.3) [**TPMLIB\_GetTPMProperty**(3)](/man/enterprise-packages/libtpms/TPMLIB_GetTPMProperty.3), [**TPMLIB\_DecodeBlob**(3)](/man/enterprise-packages/libtpms/TPMLIB_DecodeBlob.3)

2026-10-01 libtpms

---

Document: TPMLIB_MainInit(3) from libtpms 0.10.2-r3 (Chainguard OS)
Source: https://github.com/stefanberger/libtpms
