From Sending Raw TPM Commands to Parsing Responses with Windows TBS
I tried interacting with TPM 2.0 by sending raw commands through Windows TBS (TPM Base Services). The implementation is written in Rust . This article walks through the entire process, from creating a TBS context to sending a TPM command and parsing the response. Overall Flow The following is a simplified example of the complete TPM2_GetRandom flow: marshal the command → submit it → parse the…
The article describes the process of interacting with TPM 2.0 by sending raw commands through Windows TBS (TPM Base Services), implemented in Rust. The example focuses on the TPM2_GetRandom command, which generates random bytes.
First, a TBS context is created using Tbsi_Context_Create function. This context is necessary for further communication with the TPM. Then, the command to be sent is marshaled - essentially converting the command into a sequence of bytes in big-endian byte order. The command header comprises three elements: tag, commandSize, and commandCode, and is always 10 bytes long.
The function marshal_get_random_command takes the number of requested bytes as input and returns a vector of bytes representing the command. The header is created by setting the tag to TPM_ST_NO_SESSIONS, commandSize to the total size of the command, and commandCode to TPM2_GET_RANDOM.
Once the command is ready, it is submitted to the TPM using the submit function, which returns a response. The response is then parsed to extract the generated random bytes using the parse_response function. These bytes are printed to the console. Finally, the TBS context is closed using close_context function.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.