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 leading0x. no0x, 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 usingtpm2_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 ofrphashoption, 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 themanoption argument is specified, however if explicitmanis requested, the tool will provide errors from man on stderr. if theno-manoption 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 environmentTPM2TOOLS_ENABLE_ERRATAis 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 variableTPM2TOOLS_AUTOFLUSHis set toyesortrue. (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:
- the command line option
-Tor--tcti - 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 thattabrmdandabrmdas 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 ofnone.
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 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:abrmdandtabrmdare 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 totpm2_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
- 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