% tpm2_create(1) tpm2-tools | General Commands Manual
tpm2_create(1) - Create a child object.
tpm2_create(1) - Create a child object. The object can either be a key or a sealing object. A sealing object allows to seal user data to the TPM, with a maximum size of 128 bytes. Additionally it will load the created object if the -c is specified.
These options for creating the TPM entity:
The parent of the object to be created.
The authorization value of the parent object specified with -C.
The authorization value for the created object.
The hash algorithm for generating the objects name. This is optional and defaults to sha256 when not specified.
The key algorithm associated with this object. It defaults to "rsa" if not specified.
The object attributes, optional. The default for created objects is:
TPMA_OBJECT_SIGN_ENCRYPT|TPMA_OBJECT_DECRYPT|TPMA_OBJECT_FIXEDTPM| TPMA_OBJECT_FIXEDPARENT|TPMA_OBJECT_SENSITIVEDATAORIGIN| TPMA_OBJECT_USERWITHAUTH
When -i is specified for sealing,
TPMA_OBJECT_DECRYPTare removed from the default attribute set. The algorithm is set in a way where the the object is only good for sealing and unsealing. I.e. one cannot use an object for sealing and cryptography operations.
When -L is specified for adding policy based authorization information AND no string password is specified, the attribute
TPMA_OBJECT_USERWITHAUTHis cleared unless an explicit choice is made by setting of the attribute with -a option. This prevents creation of objects with inadvertent auth model where in user intended to enforce a policy but inadvertently created an object with empty auth which can be used instead of policy authorization.
-i, --sealing-input=FILE or STDIN:
The data file to be sealed, optional. If file is -, read from stdin. When sealing data only the TPM_ALG_KEYEDHASH algorithm with a NULL scheme is allowed. Thus, -G cannot be specified.
The input policy file, optional.
The output file which contains the public portion of the created object, optional.
The output file which contains the sensitive portion of the object, optional. protection details
The output file which contains the key context, optional. The key context is analogous to the context file produced by tpm2_load(1), however is generated via a tpm2_createloaded(1) command. This option can be used to avoid the normal tpm2_create(1) and tpm2_load(1) command sequences and do it all in one command, atomically.
An optional file output that saves the creation data for certification.
An optional file output that saves the key template data (TPM2B_PUBLIC) to be used in tpm2_policytemplate.
An optional file output that saves the creation ticket for certification.
An optional file output that saves the creation hash for certification.
An optional hex string or path to add unique data to the creation data. Note that it does not contribute in creating statistically unique object.
The list of PCR banks and selected PCRs' ids for each bank to be included in the creation data for certification.
File path to record the hash of the command parameters. This is commonly termed as cpHash. NOTE: When this option is selected, The tool will not actually execute the command, it simply returns a cpHash.
File path to record the hash of the response parameters. This is commonly termed as rpHash.
The session created using tpm2_startauthsession. Multiple of these can be specified. For example, you can have one session for auditing and another for encryption/decryption of the parameters.
Public key format.
The output file path, recording the public portion of the object.
context object format details the methods for specifying OBJECT.
authorization formatting details the methods for specifying AUTH.
algorithm specifiers details the options for specifying cryptographic algorithms ALGORITHM.
object attribute specifiers details the options for specifying the object attributes ATTRIBUTES.
common options collection of common options that provide information many users may expect.
common tcti options collection of options used to configure the various known TCTI modules.
In order to create an object, we must first create a primary key as it's parent.
tpm2_createprimary -c primary.ctx
Create an Object
This will create an object using all the default values and store the TPM sealed private and public portions to the paths specified via -u and -r respectively. The tool defaults to an RSA key.
tpm2_create -C primary.ctx -u obj.pub -r obj.priv
Seal Data to the TPM
Outside of key objects, the TPM allows for small amounts of user specified data to be sealed to the TPM.
echo "my sealed data" > seal.dat tpm2_create -C primary.ctx -i seal.dat -u obj.pub -r obj.priv
Create an EC Key Object and Load it to the TPM
Normally, when creating an object, only the public and private portions of the object are returned and the caller needs to use tpm2_load(1) to load those public and private portions to the TPM before being able to use the object. However, this can be accomplished within this command as well, when supported by the TPM. You can verify your TPM supports this feature by checking that tpm2_getcap(1) commands returns TPM2_CC_CreateLoaded in the command set. If your TPM does not support TPM2_CC_CreateLoaded an unsuported command code error will be returned. If it's not supported one must use tpm2_load(1). See that manpage for details on its usage.
tpm2_create -C primary.ctx -G ecc -u obj.pub -r obj.priv -c ecc.ctx
Create an Object and get the public key as a PEM file
This will create an object using all the default values but also output the public key as a PEM file compatible with tools like OpenSSL and whatever supports PEM files.
tpm2_create -C primary.ctx -u obj.pub -r obj.priv -f pem -o obj.pem