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 are ecdh or sm2. โœจ
  • -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 secret Z1 point ๐Ÿ’พ
  • --output-Z2=FILE โ€” specify the file path to save the calculated ecdh secret Z2 point ๐Ÿ’พ

๐Ÿ“š 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

  • rsa
  • ecc

๐Ÿ“ Symmetric

  • aes
  • camellia
  • sm4

โญ Hashing Algorithms

  • sha1
  • sha256
  • sha384
  • sha512
  • sm3_256
  • sha3_256
  • sha3_384
  • sha3_512

๐Ÿ”ฅ Keyed Hash

  • hmac
  • xor

๐Ÿ‘‘ Signing Schemes

  • rsassa
  • rsapss
  • ecdsa
  • ecdaa
  • ecschnorr
  • sm2

๐Ÿฆ‹ Asymmetric Encryption Schemes

  • oaep
  • rsaes
  • ecdh

๐ŸŒธ Modes

  • ctr
  • ofb
  • cbc
  • cfb
  • ecb

๐ŸŽ€ 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: aes128
  • aes128<mode> โ€” 128 bit AES with optional mode (ctr|ofb|cbc|cfb|ecb). if mode is not specified, it defaults to null.
  • aes192<mode> โ€” same as aes128<mode>, except for a 192 bit key size.
  • aes256<mode> โ€” same as aes128<mode>, except for a 256 bit key size.
  • sm4 โ€” Default SM4: sm4128
  • sm4128 or sm4_128 <mode> โ€” 128 bit SM4 with optional mode (ctr|ofb|cbc|cfb|ecb). if mode is not specified, it defaults to null.
  • ecc โ€” Elliptical Curve, defaults to ecc256.
  • ecc192 or ecc_nist_p192 โ€” 192 bit ECC NIST curve
  • ecc224 or ecc_nist_p224 โ€” 224 bit ECC NIST curve
  • ecc256 or ecc_nist_p256 โ€” 256 bit ECC NIST curve
  • ecc384 or ecc_nist_p384 โ€” 384 bit ECC NIST curve
  • ecc521 or ecc_nist_p521 โ€” 521 bit ECC NIST curve
  • ecc_sm2 or ecc_sm2_p256 โ€” 256 bit SM2 curve
  • rsa โ€” Default RSA: rsa2048
  • rsa1024 โ€” 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.

  • oaep
  • ecdh
  • rsassa
  • rsapss
  • ecdsa
  • ecschnorr
  • sm2

๐Ÿ”ข 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 on MANPATH. see man(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 environment TPM2TOOLS_ENABLE_ERRATA is 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 variable TPM2TOOLS_AUTOFLUSH is is set to yes or true. 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:

  1. The command line option -T or --tcti
  2. 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 are 127.0.0.1 and 2321.

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:
      1. bus_name : the name of the tabrmd service on the bus (a string).
      2. bus_type : the type of the dbus instance (a string) limited to session and system.

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 error
  • 5 โ€” Non supported scheme. Applicable to tpm2_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