Attestation Part 1
What is Attestation?
- Providing evidence that something is true.
How to create software evidences that we can trust?
- By using Hardware Security Modules (HSM) with minimal code base.
HSM is a piece of hardware that sits in your computer and can generate or protect secrets. There are many HSM models, but one stands out as the de-facto standard HSM, because we can find it in every computer equipment today - the Trusted Platform Module(TPM).
One of the unique features of a TPM is its Platform Configuration Registers(PCRs). The content put by the user in these special registers can be cleared only under strict conditions. This makes them difficult to tamper. And there is only one write operation accessible to the user called “PCR Extend”.
PCR Extend is a cryptographic operation that does not lose the existing information in the PCR, but appends any new information to the old one. This makes the PCRs a great tool for evaluating system properties over time. Especially useful for generating evidences of the system state.
Recently, I added PCR examples to the WolfTPM open-source library. We will use these examples to understand how PCRs work. There are currently three examples:
* Reset
* Extend
* Quote
PCR Reset
As already mentioned, PCRs can be cleared only under strict conditions. Typically, system power cycle. That is a system reboot or power on-off. However, there are 24 PCRs on a TPM and they are not all equal.
For example, PCR0-15 are reset at boot and can be cleared again only from a reboot(power) cycle. While PCR16 is a special “DEBUG” register that we can manually reset and safely use to experiment.
Note: For that reason, the examples in WolfTPM use PCR16 by default.
Using the PCR Reset example we can clear the content of PCR16. Additionally, we could clear PCR23. But PCR0-15 and 17-22 are protected by the TPM design.
PCR Extend
This is the only write operation possible for the user. PCR0-15 require privileged mode to allow PCR extend, while 16 and 23 are always available to the end user. For PCR17-22 there are special conditions before an “Extend” operation is possible.
What data can be stored in a PCR?
The content of a PCR consists of 32 bytes. That is enough for storing a hash digest. Typically, from SHA256. What the “Extend” operation does is to combine the existing value stored in the PCR with a fresh value.
How this helps us protect our systems?
For example, before starting our browser we can calculate the SHA256 hash of the application file and “Extend” the resulting digest into PCR16. If we do this every time when PCR16 is zeroed, the result of the “Extend” operation will be the same. This gives us reproducibility and if the value does not match we know something in our browser is different. And to create proof of the current state of our browser, the TPM supports an operation called Quote.
TPM2 Quote
This operation makes the TPM to sign the PCR content. The sign data contains:
- the user selected PCRs
- composite hash for the selected PCRs
- a nonce used to prevent replay attacks
and - signature that only the TPM can generate using special Attestation Keys(AIK)
This is good foundation for using the PCR examples.
Head to the WolfTPM github and download the library to play with the PCRs - https://github.com/wolfSSL/wolfTPM/tree/master/examples/pcr
To setup WolfTPM use these commands:
./autogen.sh
./configure –enable-devtpm –enable-debug
make
This is enough to run the examples
sudo examples/pcr/reset
sudo examples/pcr/extend
What is the content of the PCR?
Run again sudo examples/pcr/extend. Notice how the PCR content changed.
Copy the value to a text editor for a moment. Now repeat sudo examples/pcr/reset
and then sudo examples/pcr/extend . Notice that the PCR value is reproducible.
To make things more interesting, let us measure the zip application like this
sudo examples/pcr/extend 16 /usr/bin/zip
Notice the PCR value and compare with the value you wrote down in the editor. This trivial example is to show that measuring a file is simple. But what makes this useful is the fact that PCR0-15 cannot be cleared like PCR16. Also, using PCR16 gives us enough to create reference measurements of our system and have a snapshot of its state.
What did we achieve?
We learned how to manually create known values for the state of our browser, zip tool or any other application on our system. We can even check against these values manually and catch if our browser has been modified. May look simple, but it is a start.
In part 2 we will get into the details of TPM2 Quote and system attestation.
Thank you for reading the tutorial and please be critical. Ask questions, comment, all feedback is welcomed.
#Tutorials❤️
👍
💡
👏
😂
Explore More Posts
Sneak-peak at our #TPMDEV2026 Conference. One slide from each main talk. Expect the recordings soon as we are migrating to Youtube. The news from today is that we are resuming our monthly calls and we will have in-person #TPMDEV2027! Check TPM.dev for more info.
Random Number Generator (TPM2)
1. IntroductionAmong other features, Trusted Platform Modules (TPM) comes with a True Random Number Generator (TRNG) that can be used for various applications including cryptographic purposes. This RNG module serves as the source for randomness for the TPM 2.0 Chip. A RNG module in TPM2 will typically contain the following -
An entropy source and collector
State Register
A mixing func.
There can be two types of calls to the TPM’s Random Number Generator, Internal call and External Call. RNG is capable to provide enough randomness for all the internal calls made. As well as, RNG is capable of providing 32 octets of randomness as per the specification to an external call. Another thing to note here is, each call made to the RNG produces a new value irrespective of the type of call. 1.1 The source of RandomnessThe source of entropy in the TPM is the entropy collector. As the name suggests, entropy collector collects entropy from entropy sources and also removes bias. A TPM2.0 has at least one internal source of entropy. These sources can include noise, clock variations, air movement amongst other events. As depicted in Fig 1.1 the entropy collector provides input to the State Register. 1.2 Stages involved Various algorithms and process supported by TPM calls RNG for unpredictable numbers, which is actually obtained from “RNG Protected Capability”. The “Deterministic Random Bit Generator (DRBG) Protected Capability“ obtains entropy from “Entropy Protected Capability”. Along with Entropy Protected Capability, TPM2_StirRandom() can also gather entropy from other entropy sources within the same TPM. 2. Random Numbers via TPM2 ToolsIf one needs to use TPM’s RNG for other external applications, then TPM2 Tools Command Line tools can be a great option. TPM2 Tools Command : tpm2_getrandom - - hex 16 - - hex : Converts output to hexadecimal 16 : Size in bytes Now, if one wants to have additional randomness, TPM2 Tools provides a convenient utility for this purpose called tpm2_stirrandom. To inject entropy via TPM2_StirRandom() to “Entropy Protected Capability” , we can use some file or use stdin. TPM2 Tools Command : echo -n “some_random_data” | tpm2_stirrandom Note : 128 bytes can only be injected using stdin at once through stirrandom() 3. ConclusionThe TPM2 provides in a sense True Random Numbers for use. These unpredictable numbers are coming from a dedicated hardware, hence can be trusted to be given as input to Crypto Algorithms amongst other applications. TPM2 also uses this for its internal use, and TCG claims it to be as secure as the strongest algorithm that TPM supports. Also, using the RNG is pretty straight forward via TPM2 Tools. #Tutorials
The latest tpm2-tools 5.8 release addresses three GitHub security advisories. One is a heap overflow in tpm2_getekcertificate, and the other is an out-of-bounds write that happens when too many sessions are in use. I don’t have information on the third advisory. Beyond the fixes, 5.8 extends EK certificate handling. It adds the option to read EK certificates from NV RAM, introduces new EK templates and supports a marshaled quote format. https://github.com/tpm2-software/tpm2-tools/releases/tag/5.8



Comments
Start the Conversation
Do these same concepts apply for remote attest? What's different with remote attestation. I have a router which talks to a mgt. device and takes cfg. from this device. I need to attest the router from the mgmt. device before sending config. How to …more
Hi ploop plooop , nice nickname :) Same concepts apply for remote attestation. Difference is that the measurement(attested data) is transfered over a network. Otherwise, we call it local attestatoin …more
Yes sure I will join and thank you for the reply. Have a few questions:
How does the remote machine verify the data? I see the ibm tss utilities quote(). …more
That is correct. You don't have to use the AK - any suitable key will do, but as the AK is linked to the TPM this gives some form of identity too. The attestation server has to know the public AKs, which PCRs to select and what the good, expected …more
Thank you Ian.
As per my understanding:
The attestation server will use the public AK's …more
maybe signing the quote means: the data requested by the server is indeed from the TPM the quote was requested from? But not encrpted
Yes. The TPM signs the quote with the AK private key internally.
Page 103 of this is the definition of the structure: https://www.trustedcomputi …more