TPMLIB_Process(3)

πŸ’… TPMLIB_Process β€” bestie, this is page 3 of the libtpms manual, and it's about to be your new fave

okay so real talk: TPMLIB_Process(3) is the function that sends TPM commands to the TPM and hands you back the result. That's the whole vibe. Let's get into it 🫢


✨ LIBRARY ✨

TPM library (that's libtpms, link it with -ltpms) πŸ’œ


πŸŽ€ SYNOPSIS πŸŽ€

#include <libtpms/tpm_library.h>

#include <libtpms/tpm_error.h>

TPM_RESULT TPMLIB_Process(unsigned char **respbuffer,
                          uint32_t *resp_size,
                          uint32_t *respbufsize,
                          unsigned char *command,
                          uint32_t command_size);

like, look at those five parameters. iconic. no notes πŸ’…


🌸 DESCRIPTION 🌸

The TPMLIB_Process() function is literally the way you slide a TPM command over to the TPM and collect whatever it sends back. sending + receiving, one function, main character energy ✨

The command parameter is your buffer holding the TPM command, and command_size is how many bytes inside that buffer are actually valid TPM command bytes. don't be out here claiming bytes that aren't real πŸ™ˆ

respbuffer is a pointer to the buffer where the TPM will drop its result. here's the cute part: if you pass NULL for respbuffer, the TPM allocates a buffer for you. king behavior πŸ‘‘

Then resp_size tells you how many valid TPM response bytes ended up in that buffer. and ngl, the number of valid bytes in the response is guaranteed not to exceed the maximum I/O buffer size β€” that's a promise, bestie 🫢. wanna know what that max actually is? hit up the TPMLIB_GetTPMProperty() API with the parameter TPMPROP_TPM_BUFFER_MAX and it'll tell you fr fr.

If you're supplying your own buffer, you must tell us how big it is via the respbufsize parameter. and if your buffer turns out to be not big enough for the response? no stress β€” the TPM frees the buffer you provided, allocates one that's actually big enough, and adapts respbufsize accordingly. glow-up via reallocation πŸ’…βœ¨

πŸ‘‘ the returned buffer is only subject to the size restrictions as explained for TPM_Malloc(). that's the rule, periodt.

πŸ”₯ ERRORS πŸ”₯

  • TPM_SUCCESS β€” slayed. the function completed successfully πŸ’–
  • TPM_FAIL β€” general failure 😭 it's giving "something went wrong" and nothing more specific.
for a complete list of TPM error codes, please consult the include file libtpms/tpm_error.h β€” it's all in there, iykyk πŸ“–

πŸ¦‹ EXAMPLE πŸ¦‹

okay here's a whole little program, and yes it's cute:

 #include <stdio.h>

 #include <libtpms/tpm_types.h>
 #include <libtpms/tpm_library.h>
 #include <libtpms/tpm_error.h>

 static unsigned char TPM_Startup_ST_CLEAR[] = {
     0x00, 0xC1, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x99,
     0x00, TPM_ST_CLEAR
 };

 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 */
     command = TPM_Startup_ST_CLEAR;
     command_size = sizeof(TPM_Startup_ST_CLEAR);
     [...]

     res = TPMLIB_Process(&respbuffer, &resp_size,
                          &respbufsize,
                          command, command_size);
     [...]

     TPMLIB_Terminate();

     return 0;
 }

see how respbuffer starts as NULL so the TPM allocates for you? that's the move 🌈 and don't forget TPMLIB_Terminate() at the end, clean up after yourself queen πŸ’…


πŸ’€ SEE ALSO πŸ’€


and that's the page!! πŸŽ€ this one's from libtpms, dated 2026-01-02 β€” go forth and process those TPM commands, bestie, you're gonna ate it fr fr πŸ’–βœ¨πŸ“

πŸ“¦ where this page comes from