TPMLIB_MainInit(3)

okay bestie, welcome to the libtpms manual page for TPMLIB_MainInit(3) β€” this is the init/terminate page and it’s literally essential ✨

✨ NAME ✨

TPMLIB_MainInit β€” initialize the TPM, bestie πŸ’–

TPMLIB_Terminate β€” terminate the TPM, byeee πŸ‘‹

πŸ“š LIBRARY πŸ“š

TPM library (libtpms, -ltpms) β€” yes, link it like that 🫢

πŸ› οΈ SYNOPSIS πŸ› οΈ

#include <libtpms/tpm_types.h>

#include <libtpms/tpm_library.h>

#include <libtpms/tpm_error.h>

TPM_RESULT TPMLIB_MainInit(void);

TPM_RESULT TPMLIB_Terminate(void);

πŸ’¬ DESCRIPTION πŸ’¬

Okay so TPMLIB_MainInit() and TPMLIB_Terminate() are the two functions that initialize and terminate the TPM, respectively β€” they’re literally the start-and-stop girlies of this whole thing πŸ’…

TPMLIB_MainInit() has to be called before the TPM processes any TPM command. No skipping ahead, bestie β€” init first, command later, periodt.

TPMLIB_Terminate() is the one you call to free all the internal resources (memory allocations) the TPM has used. It must be called after the last TPM command was processed by the TPM. Then, after that, TPMLIB_MainInit() can be called again. Cleanup queen behavior ✨

Use TPMLIB_RegisterCallbacks() to set callback functions for initialization and writing and restoring the internal state in a portable format. That’s the move if you need those callbacks hooked up πŸŽ€

🚨 ERRORS 🚨

  • TPM_SUCCESS β€” the function completed successfully. slay πŸ’–
  • TPM_FAIL β€” general failure. not slay 😭

For a complete list of TPM error codes please consult the include file libtpms/tpm_error.h β€” it’s all in there, iykyk πŸ‘‘

🌸 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 πŸ”—


okay that’s the whole TPMLIB_MainInit(3) page! this iconic manual comes from libtpms, dated 2026-01-02, and it’s literally the TPMLIB_MainInit(3) man page β€” now go init that TPM, bestie πŸ’…βœ¨

πŸ“¦ where this page comes from