tpm2_getrandom(1)

πŸ’… tpm2_getrandom β€” like, the manual page, but make it make sense

okay so first things first: this is from the General Commands Manual (iykyk, it's a section 1 situation), and honestly bestie, it's giving "tiny tool, big personality." Let's get into it. πŸŽ€


✨ NAME ✨

tpm2_getrandom(1) β€” retrieves random bytes from the TPM. that's it. that's the whole job. and it ate. πŸ¦‹


🌸 SYNOPSIS 🌸

tpm2_getrandom [OPTIONS] [ARGUMENT]

πŸ’– DESCRIPTION πŸ’–

tpm2_getrandom(1) β€” returns the next SIZE octets from the random number generator. the SIZE parameter is expected as the only argument to the tool, so don't go wild with extra args, bestie.

so here's the lore 🫢: the TPM specification recommends that TPMs fix the number of available entry to the maximum size of a hash algorithm output in bytes. (yes, that phrasing is a little cursed, but it's what the page says and I don't make the rules.)

most TPMs do this, and thus the tool verifies that input size is bounded by the property TPM2_PT_MAX_DIGEST and issues an error if it is too large. so if you ask for too many bytes it will clock you and throw an error. πŸ’€

output defaults to stdout and binary format unless otherwise specified with -o and --hex options respectively.

okay real talk πŸ™ˆ β€” the OPTIONS section below also says -o "Defaults to stdout as a hex string," which is a whole different vibe from what the DESCRIPTION just said. both statements are literally in here, so I'm passing them along to you verbatim-ish and you can be the judge. the manpage is having a moment. 😭

⭐ OPTIONS ⭐

  • -o, --output=FILE β€” specifies the filename to output the raw bytes to. defaults to stdout as a hex string.
  • --hex β€” convert the output data to hex format without a leading 0x. no 0x, no cap. πŸŽ€
  • -f, --force β€” override checking that the:
    • requested size is within the hash size limit of the TPM.
    • number of retrieved random bytes matches requested amount.

like, it skips the vibe check. use with intention, bestie. πŸ”₯

  • -S, --session=FILE β€” 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 of the parameters. iconic multi-tasking. πŸ‘‘
  • --cphash=FILE β€” file path to record the hash of the command parameters. this is commonly termed as cpHash. NOTE: when this option is selected, in absence of rphash option, the tool will not actually execute the command, it simply returns a cpHash. so like… it's all talk, no action. πŸ’…
  • --rphash=FILE β€” file path to record the hash of the response parameters. this is commonly termed as rpHash.
  • ARGUMENT β€” the command line argument specifies the size of the output. that's the SIZE, the main character of this whole page. ⭐

🧚 References

(that's it. that's the section. it's just vibes and a heading. leaving it here because I keep every detail, periodt.)


🌈 COMMON OPTIONS 🌈

this collection of options are common to many programs and provide information that many users may expect. think of it as the shared group chat of options. πŸ’¬

  • -h, --help=[man|no-man] β€” display the tool's manpage. by default, it attempts to invoke the manpager for the tool, however, on failure will output a short tool summary. this is the 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 requires the manpages to be installed or on MANPATH, see man(1) for more details. no manpages? no problem, you get the short version. 🫢

  • -v, --version β€” display version information for this tool, supported tctis and exit.
  • -V, --verbose β€” increase the information that the tool prints to the console during its execution. when using this option the file and line number are printed. very "show your work" of it. ✨
  • -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. same energy, different spelling. πŸ¦‹
  • -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. noted, and important. πŸ”₯
  • -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 set to yes or true. (the page says "is is set," and I'm choosing to believe that's a typo and not a secret third thing. πŸ’€) 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. basically: it's the group chat your tool uses to talk to 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 tie-breakers, no vibes-based decisions. πŸ‘‘

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. (yes, "initalize," the page's spelling, not mine 🫢) 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. blank = default, slay. ✨

πŸŽ€ 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. mystery solved. πŸ”

πŸ’œ 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. thus, this could be a path to the shared library, or a library name as understood by dlopen(3) semantics. bring your own TCTI, it's very "build your own adventure." 🧚


πŸ’… 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. (yes, that sentence is trailing off into the void, but I refuse to delete a single detail, so here it is in all its unfinished glory. 😭)

πŸ“ EXAMPLES πŸ“

🌸 Generate a random 20 bytes and output the binary data to a file

tpm2_getrandom -o random.out 20

🌸 Generate a random 8 bytes and output the hex formatted data to stdout

tpm2_getrandom 8 --hex

⭐ Returns ⭐

tools can return any of the following codes:

  • 0 β€” success. we love to see it. πŸ‘‘
  • 1 β€” general non-specific error.
  • 2 β€” options handling error.
  • 3 β€” authentication error.
  • 4 β€” TCTI related error.
  • 5 β€” non supported scheme. applicable to tpm2_testparams.

πŸ’€ BUGS πŸ’€

Github Issues.

(that's the whole section. very concise, very "link in bio." 🫢)


🫢 HELP 🫢

See the Mailing List.

(also extremely concise. the page is being mysterious. πŸ’…)


πŸŽ€ License πŸŽ€

this work is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). so like, share the knowledge, give credit, be a good citizen. πŸ’–


and that's the whole page bestie β€” brought to you by tpm2-tools, aka tpm2_getrandom(1), the random bytes specialist. go get yourself some entropy. πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from