tpm2_zgen2phase(1)
๐ NAME ๐
ok so this is tpm2_zgen2phase(1), straight out of the General Commands Manual, and it's the command that lets the TPM get its main-character moment ๐ซถ โ it combines the data from the other party with the ephemeral key that got generated back in the first phase of two-phase key exchange protocols. no cap, that's the whole vibe.
โจ SYNOPSIS โจ
tpm2_zgen2phase [OPTIONS]
๐ฆ DESCRIPTION ๐ฆ
tpm2_zgen2phase(1) is a command that enables the TPM to combine data from the other party with the ephemeral key generated in the first phase of two-phase key exchange protocols. literally that. it's the phase-two girlie of the whole exchange ๐
๐ธ OPTIONS ๐ธ
-c,--key-context=FILEโ the context object that points at your ECC key ๐. it can be either a file or a handle number, iykyk. go see the "Context Object Format" section for the deets.-p,--key-auth=AUTHโ the authorization value for that ECC key object (yes, the password-ish thing, don't look at me).-s,--scheme=ALGORITHMโ the key exchange scheme. optional bestie, so no pressure. valid options areecdhorsm2. โจ-t,--counter=NATURALNUMBERโ the commit count, which is how the key index to use gets determined. ๐ข--static-public=FILEโ the static public key input of the other party.--ephemeral-public=FILEโ the ephemeral public key input of the other party.--output-Z1=FILEโ specify the file path to save the calculated ecdh secretZ1point ๐พ--output-Z2=FILEโ specify the file path to save the calculated ecdh secretZ2point ๐พ
๐ References
(like, the algorithm specifier reference material โ it lives right down here โฌ๏ธ)
๐งฎ Algorithm Specifiers
ok so options that take algorithms support "nice-names". cute, right? ๐
there are two major algorithm specification string classes: simple and complex. and ngl, only certain algorithms will be accepted by the TPM, based on usage and conditions. so like, don't get too comfy.
๐ Simple specifiers
these are strings with no additional specification data. when you're creating objects, the non-specified portions of an object are assumed to defaults. the list of known "Simple Specifiers" is right below ๐
๐ Asymmetric
rsaecc
๐ Symmetric
aescamelliasm4
โญ Hashing Algorithms
sha1sha256sha384sha512sm3_256sha3_256sha3_384sha3_512
๐ฅ Keyed Hash
hmacxor
๐ Signing Schemes
rsassarsapssecdsaecdaaecschnorrsm2
๐ฆ Asymmetric Encryption Schemes
oaeprsaesecdh
๐ธ Modes
ctrofbcbccfbecb
๐ Misc
null
๐ง Complex Specifiers
so when objects get specified for creation by the TPM, they have numerous algorithms to populate in the public data. things like type, scheme and asymmetric details, key size, etc. it's giving very-many-sliders. here's the general format for specifying this data:
<type>:<scheme>:<symmetric-details>
๐ Type Specifiers
this portion of the complex algorithm specifier is required, bestie. no skipping. the remaining scheme and symmetric details will default based on the type specified and the type of the object being created.
aesโ Default AES:aes128aes128<mode>โ 128 bit AES with optional mode (ctr|ofb|cbc|cfb|ecb). if mode is not specified, it defaults tonull.aes192<mode>โ same asaes128<mode>, except for a 192 bit key size.aes256<mode>โ same asaes128<mode>, except for a 256 bit key size.sm4โ Default SM4:sm4128sm4128orsm4_128 <mode>โ 128 bit SM4 with optional mode (ctr|ofb|cbc|cfb|ecb). if mode is not specified, it defaults tonull.eccโ Elliptical Curve, defaults toecc256.ecc192orecc_nist_p192โ 192 bit ECC NIST curveecc224orecc_nist_p224โ 224 bit ECC NIST curveecc256orecc_nist_p256โ 256 bit ECC NIST curveecc384orecc_nist_p384โ 384 bit ECC NIST curveecc521orecc_nist_p521โ 521 bit ECC NIST curveecc_sm2orecc_sm2_p256โ 256 bit SM2 curversaโ Default RSA:rsa2048rsa1024โ RSA with 1024 bit keysize.rsa2048โ RSA with 2048 bit keysize.rsa3072โ RSA with 3072 bit keysize.rsa4096โ RSA with 4096 bit keysize.
๐ซถ Scheme Specifiers
next up is an optional field โ you can literally just skip it, no biggie.
schemes are usually Signing Schemes or Asymmetric Encryption Schemes. most signing schemes take a hash algorithm directly following the signing scheme. if the hash algorithm is missing, it defaults to sha256. some take no arguments, and some take multiple arguments. chaotic, honestly.
โญ Hash Optional Scheme Specifiers
these scheme specifiers are followed by a dash and a valid hash algorithm. for example: oaep-sha256.
oaepecdhrsassarsapssecdsaecschnorrsm2
๐ข Multiple Option Scheme Specifiers
this scheme specifier is followed by a count (max size UINT16), then followed by a dash (-) and a valid hash algorithm. that's ecdaa, for example ecdaa4-sha256. if no count is specified, it defaults to 4.
๐ No Option Scheme Specifiers
this scheme specifier takes NO arguments. that's rsaes. periodt.
๐ Symmetric Details Specifiers
this field is optional, and defaults based on the type of object being created and it's attributes. generally, any valid Symmetric specifier from the Type Specifiers list should work. if not specified, an asymmetric object's symmetric details defaults to aes128cfb.
๐ Examples
โจ Create an rsa2048 key with an rsaes asymmetric encryption scheme
tpm2_create -C parent.ctx -G rsa2048:rsaes -u key.pub -r key.priv
โจ Create an ecc256 key with an ecdaa signing scheme with a count of 4 and sha384 hash
/tpm2_create -C parent.ctx -G ecc256:ecdaa4-sha384 -u key.pub -r key.priv cryptographic algorithms ALGORITHM.
๐ COMMON OPTIONS ๐
this collection of options are common to many programs and provide information that many users may expect. like, the stuff you'd just assume is there ๐
-h,--help=[man|no-man]โ Display the tools manpage. by default it attempts to invoke the manpager for the tool, however, on failure it will output a short tool summary. same behavior if the "man" option argument is specified โ however, if explicit "man" is requested, the tool will provide errors from man on stderr. if the "no-man" option is specified, or the manpager fails, the short options will be output to stdout.
to successfully use the manpages feature you need the manpages installed or onMANPATH. seeman(1)for more details ๐
-v,--versionโ Display version information for this tool, supported tctis and exit. quick lil flex.-V,--verboseโ Increase the information that the tool prints to the console during its execution. when you use this option the file and line number are printed. very "tell me everything" energy ๐-Q,--quietโ Silence normal tool output to stdout. shhh ๐คซ-Z,--enable-errataโ Enable the application of errata fixups. useful if an errata fixup needs to be applied to commands sent to the TPM. defining the environmentTPM2TOOLS_ENABLE_ERRATAis equivalent.-z,--pwd-sessionโ Use password session instead of a HMAC session for authentication. a clear text password is passed to the TPM to authorize the action. this option can be used to avoid problems when unsalted sessions are used in OpenSSL FIPS mode. if auth values are used a salted session should be used for authentication.-R,--autoflushโ Enable autoflush for transient objects created by the command. if a parent object is loaded from a context file also the transient parent object will be flushed. autoflush can also be activated if the environment variableTPM2TOOLS_AUTOFLUSHis is set toyesortrue. information many users may expect.
๐ก TCTI Configuration
the TCTI, or "Transmission Interface", is the communication mechanism with the TPM. TCTIs can be changed for communication with TPMs across different mediums. it's basically the group chat your tool uses to reach the TPM ๐ซถ
to control the TCTI, the tools respect:
- The command line option
-Tor--tcti - The environment variable:
TPM2TOOLS_TCTI.
Note: the command line option always overrides the environment variable. always. no discussion ๐
the current known TCTIs are:
tabrmdโ the resource manager, called tabrmd. note that tabrmd and abrmd as a tcti name are synonymous.mssimโ typically used for communicating to the TPM software simulator.deviceโ used when talking directly to a TPM device file.noneโ do not initalize a connection with the TPM. some tools allow for off-tpm options and thus support not using a TCTI. tools that do not support it will error when attempted to be used without a TCTI connection. does not support ANY options and MUST BE presented as the exact text of "none".
the arguments to either the command line option or the environment variable are in the form:
<tcti-name>:<tcti-option-config>
specifying an empty string for either the <tcti-name> or <tcti-option-config> results in the default being used for that portion respectively.
๐ TCTI Defaults
when a TCTI is not specified, the default TCTI is searched for using dlopen(3) semantics. the tools will search for tabrmd, device and mssim TCTIs IN THAT ORDER and USE THE FIRST ONE FOUND. ๐ you can query what TCTI will be chosen as the default by using the -v option to print the version information. the "default-tcti" key-value pair will indicate which of the aforementioned TCTIs is the default.
๐ง Custom TCTIs
any TCTI that implements the dynamic TCTI interface can be loaded. the tools internally use dlopen(3), and the raw tcti-name value is used for the lookup. so this could be a path to the shared library, or a library name as understood by dlopen(3) semantics. build-your-own-adventure but make it linkage โจ
๐ TCTI OPTIONS
this collection of options are used to configure the various known TCTI modules available:
deviceโ for the device TCTI, the TPM character device file for use by the device TCTI can be specified. the default is/dev/tpm0.
example: -T device:/dev/tpm0 or export TPM2TOOLS_TCTI="device:/dev/tpm0"
mssimโ for the mssim TCTI, the domain name or IP address and port number used by the simulator can be specified. the default are127.0.0.1and2321.
example: -T mssim:host=localhost,port=2321 or export TPM2TOOLS_TCTI="mssim:host=localhost,port=2321"
abrmdโ for the abrmd TCTI, the configuration string format is a series of simple key value pairs separated by a,character. each key and value string are separated by a=character.- TCTI abrmd supports two keys:
bus_name: the name of the tabrmd service on the bus (a string).bus_type: the type of the dbus instance (a string) limited tosessionandsystem.
- TCTI abrmd supports two keys:
specify the tabrmd tcti name and a config string of bus_name=com.example.FooBar:
\--tcti=tabrmd:bus_name=com.example.FooBar
specify the default (abrmd) tcti and a config string of bus_type=session:
\--tcti:bus_type=session
NOTE: abrmd and tabrmd are synonymous. the various known TCTI modules.
๐ EXAMPLES ๐
okay bestie, here's the whole little friend-group journey from zero to shared secret โ copy these in order and you're golden โจ
First up, you gotta make yourself a primary, because everything in TPM-land needs a parent:
tpm2_createprimary -C o -c prim.ctx -Q
Then we birth the actual ECDH key, -G ecc256:ecdh so it knows it's for key agreement and not, like, signing your vibes:
tpm2_create -C prim.ctx -c key.ctx -u key.pub -r key.priv -G ecc256:ecdh -Q
Next, the other side's ephemeral key gets generated, with -t ecc.ctr for the counter and ecc256 for the curve โ she's giving main character energy:
tpm2_ecephemeral -u ecc.q -t ecc.ctr ecc256
Then we derive the ECDH keypair from that context, dropping the public and private halves into files like the icon she is:
tpm2_ecdhkeygen -u ecdh.pub -o ecdh.priv -c key.ctx
and finally, the moment we've all been waiting for โ the actual Z-generation, with -t 0 for the counter and both output halves landing in z1.bin and z2.bin:
tpm2_zgen2phase -c key.ctx --static-public ecdh.pub --ephemeral-public ecc.q \
-t 0 --output-Z1 z1.bin --output-Z2 z2.bin
slay. you did it. ๐
๐ Returns ๐
tools can hand back any of these codes, so don't @ them, just read the number:
0โ success ๐1โ general non-specific error (the "something's off but nobody knows what" vibe)2โ options handling error (you fumbled a flag, bestie)3โ authentication error (wrong creds, no cap)4โ TCTI related error5โ Non supported scheme. Applicable totpm2_testparams.
๐ฆ BUGS ๐ฆ
found something cursed? take it to the Github Issues. that's literally the whole assignment. ๐
๐ธ HELP ๐ธ
need a human? See the Mailing List โ real ones, ready to help you out. ๐ซถ
๐ License ๐
This work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). give credit where credit is due, periodt ๐
and that's the whole page, bestie โ the source is tpm2-tools, the page is tpm2_zgen2phase(1), and it's officially signed off. go forth and agree on some keys ๐ฅ๐๐
๐ฆ where this page comes from
- arch rolling: tpm2-tools 5.8-1 ยท BSD-3-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms