Hello! I'm new to TPM and sorry to ask very beginner question. All I want to do is store AES key in TPM and...
Hello!
I'm new to TPM and sorry to ask very beginner question.
All I want to do is store AES key in TPM and take out the key when decrypting a file.
I thought using TPM2_Create and TPM2_EvictControl to store key and TPM2_ReadPublic to read the key is what I need but, I'm stuck for more than a month at the very first step: generating the AES key by TPM2_Create.
I'm getting response code 2436 which represent some session related configuration is wrong.
TPM2_Create have to specify @parentHandle so I decided to put 0x81000001 which didn't give me handle error and possibly is storage primary key because it's in the range of 0x81000000β0x810000FF.
@parentHandle has @ decoration so I understand authorization session is required to use this handle.I don't have much confidence on my understanding of session, but I think this means, I have to first know what type of session is 0x81000001 requiring (password or HMAC or Policy) and put correct value in TPM2_Create's inSensitive parameter.
My question is that, first of all, is this understanding of what @parentHandle is requiring correct? If this is correct, how can I know 0x81000001's type of session and what to put in authValue?
I also thought I might have to use TPM2_CreatePrimary first, but this commands also requires @primaryHandle and I don't know what to put in inSensitive parameter.
I'm writing a code in C and running this program as a UEFI module so I can't use tpm2-tools or tss. Actually, if there is a way that I can do this without caring about session, that would be more appreciated. Also, if there are some good source to look at with some code example, I also want to know that too.
Thank you in advance!
and sorry if my English was weird or impolite since I'm not a native speaker.
π
1β€οΈ
π
π‘
π
π
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
Not directly solving your problem, but have looked at what the raw commands are when you implement it using for example tpm2-tools in combination with a TPM emulator?
You can use either swtpm or the IBM TPM β¦more
Thank you for your quick response!
I see, I didn't have the idea of using emulator to look at tpm2-tools<=>TPM emulator raw commands. Maybe I should give it a try.
the inSensitive argument is for the key being created not the parent key, you need to pass the right authorization for the parent handle in the authorization array for the command β¦more
Still, thank you so much for the information!
There were so many session related parameter so I was confused where to put what kind of authorization where, but β¦more