---
name: "TPMLIB_SetState"
section: "3"
platform: "linux"
package: "libtpms"
version: "0.10.2-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/TPMLIB_SetState"
---

# TPMLIB\_SetState(3)

Set the TPM's volatile, permanent, or save state TPMLIB\_GetState - Get the TPM's volatile, permanent, or save state

## NAME

TPMLIB\_SetState  - Set the TPM's volatile, permanent, or save state

TPMLIB\_GetState  - Get the TPM's volatile, permanent, or save state

## LIBRARY

TPM library (libtpms, -ltpms)

## SYNOPSIS

**#include \<libtpms/tpm\_library.h**\>

**TPM\_RESULT TPMLIB\_SetState(enum TPMLIB\_StateType st,**\
                            **const unsigned char \*buffer, uint32\_t buflen);**

**TPM\_RESULT TPMLIB\_GetState(enum TPMLIB\_StateType st,**\
                            **unsigned char \*\*buffer, uint32\_t \*buflen);**

## DESCRIPTION

The **TPMLIB\_SetState()** function allows to set either one of the state blobs of the TPM. The passed state blob is tested for whether it can be accepted and a TPM error code is returned in case it cannot be accepted. In case of acceptance, the state blob will be passed to the TPM upon **TPM\_MainInit()**. Setting a state blob hides a file that may contain the same type of blob and would be read otherwise. It is required to call this function with a NULL pointer for the buffer parameter to hide a state blob in a file.

It is only possible to set the state blobs after **TPMLIB\_ChooseTPMVersion()** has been called. All state blobs are cleared when a different version of TPM is chosen using **TPMLIB\_ChooseTPMVersion** or when a call to **TPMLIB\_SetState()** fails because a state blob could not be accepted.

The order in which state blobs are set is important. The first state blob has to be the one representing the TPM's permanent state. Only after that either the volatile or save state blobs can be set.

The **TPMLIB\_GetState()** function allows to get the current state of the TPM. For as long as the TPM has not been started, this function either returns the state blob previously set with **TPMLIB\_SetState()** or the state is read from a file. Once the TPM has been start the state of the running TPM is returned.

The **TPMLIB\_STATE\_SAVE\_STATE** (save state) type of TPM state can be set with this function. The same state blob will be returned until TPM\_Startup(ST\_STATE) has been called, after which an empty blob will be returned. This blob can also only be read after **TPM\_SaveState()** has been sent to the TPM.

## SEE ALSO

[**TPMLIB\_ChooseTPMVersion**(3)](/TPMLIB_ChooseTPMVersion/3.md), [**TPMLIB\_MainInit**(3)](/TPMLIB_MainInit/3.md), [**TPMLIB\_Terminate**(3)](/TPMLIB_Terminate/3.md)
