summaryrefslogtreecommitdiff
path: root/include/tpm-v2.h
AgeCommit message (Collapse)Author
2025-12-04tpm2: add sm3 256 hash supportHeiko Schocher
add sm3 256 hash support, so TPM2 chips which report 5 pcrs with sm3 hash do not fail with: u-boot=> tpm2 autostart tpm2_get_pcr_info: too many pcrs: 5 Error: -90 Signed-off-by: Heiko Schocher <[email protected]>
2025-07-01cmd: tpm: Fix attempt to return value not in enumAndrew Goodbody
The function tpm2_name_to_algorithm is defined as returning an enum for the algorithm specified but it also attempts to return an error on failure, but that error is not included in the enum. Add the error to the enum so that it can be returned. This issue was reported by Smatch. Signed-off-by: Andrew Goodbody <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-28tpm: add wrapper and helper APIs for PCR allocateRaymond Mao
Add PCR allocate wrapper APIs for using in tcg2 protocol. The wrapper proceeds a PCR allocate command, followed by a shutdown command. A system boot is required after two commands since TPM device needs a HW reset to activate the new algorithms config. Also, a helper function is included to determine the new bank mask for PCR allocation by combining the status of current active, supported and eventlog bank masks. A new kconfig is created. PCR allocate and system reboot only happens when the kconfig is selected, otherwise just exit with errors. Signed-off-by: Raymond Mao <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-28tpm: add TPM2_PCR_Allocate commandRaymond Mao
TPM2_PCR_Allocate command is required to reconfigure a TPM device to enable or disable algorithms in run-time, thus this patch introduces the implementation of PCR allocate APIs and adds related cmd functions for testing. To test the feature, ensure that TPM is started up. Run pcr_allocate command to turn on/off an algorithm, multiple calls are supported and all changes will be cached: `tpm2 pcr_allocate <algorithm_name> <on|off>` Run startup command with argument 'off' to shutdown the TPM. `tpm2 startup TPM2_SU_CLEAR off` Reboot the board via `reset` to activate the changes. Signed-off-by: Raymond Mao <[email protected]> Acked-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-28tpm: add TPM2_Shutdown commandRaymond Mao
TPM2_shutdown command is sharing same structure and logics with TPM2_startup, thus this patch extends the existing startup APIs and cmd functions to support shutdown instead of created new ones. Signed-off-by: Raymond Mao <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-09tpm: update descriptions in tpm headersHeinrich Schuchardt
* Provide a link to 'TPM 2.0 Library Specification' * Remove outdated comment for TPM2_NUM_PCR_BANKS. The value 16 can be found in the current standard TCG TSS 2.0 Overview and Common Structures Specification 1.0, rev 10 * Describe some of the structures in Sphinx style. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-07tpm: Keep the active PCRs in the chip private dataIlias Apalodimas
We have a lot of code trying to reason about the active TPM PCRs when creating an EventLog. Since changing the active banks can't be done on the fly and requires a TPM reset, let's store them in the chip private data instead. Upcoming patches will use this during the EventLog creation. Signed-off-by: Raymond Mao <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-07tpm: Don't create an EventLog if algorithms are misconfiguredIlias Apalodimas
We already check the active banks vs what U-Boot was compiled with when trying to extend a PCR and we refuse to do so if the TPM active ones don't match the ones U-Boot supports. Do the same thing for the EventLog creation since extending will fail anyway and print a message so the user can figure out the missing algorithms. Co-developed-by: Raymond Mao <[email protected]> Signed-off-by: Raymond Mao <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-07tpm: add flag in hash_algo_list and API to check if algorithm is supportedRaymond Mao
Add a bool var into hash_algo_list to indicate whether the algorithm is supported or not and move the IS_ENABLED to only cover this var. So that we can have the name, hash, mask and size no matter the digest kconfigs are enabled or not. In before, tpm2_algorithm_to_len() and tcg2_algorithm_to_mask() are used to identify an unsupported algorithm when they return 0. It is not the case now when hash_algo_list always provides algorithm size and mask, thus a new API is introduced to check if an algorithm is supported by U-Boot. Suggested-by: Ilias Apalodimas <[email protected]> Signed-off-by: Raymond Mao <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-07tpm: Rename tpm2_allow_extend()Ilias Apalodimas
When that function was introduced we were only using it to check if extending a PCR was allowed, so the name made sense. A few patches ago we used that function to reason about the EventLog creation and general usage of PCRs , so let's rename it to something more generic that makes more sense in all contexts. Signed-off-by: Raymond Mao <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2025-01-07tpm: Rename tpm2_is_active_pcr()Ilias Apalodimas
This function is checking for active PCR banks, so rename it to something that's easier to read and closer to what the function does. Signed-off-by: Raymond Mao <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2024-06-30tpm: allow the user to select the compiled algorithmsIlias Apalodimas
Simon reports that after enabling all algorithms on the TPM some boards fail since they don't have enough storage to accommodate the ~5KB growth. The choice of hash algorithms is determined by the platform and the TPM configuration. Failing to cap a PCR in a bank which the platform left active is a security vulnerability. It might allow unsealing of secrets if an attacker can replay a good set of measurements into an unused bank. If MEASURED_BOOT or EFI_TCG2_PROTOCOL is enabled our Kconfig will enable all supported hashing algorithms. We still want to allow users to add a TPM and not enable measured boot via EFI or bootm though and at the same time, control the compiled algorithms for size reasons. So let's add a function tpm2_allow_extend() which checks the TPM active PCRs banks against the one U-Boot was compiled with. We only allow extending PCRs if the algorithms selected during build match the TPM configuration. It's worth noting that this is only added for TPM2.0, since TPM1.2 is lacking a lot of code at the moment to read the available PCR banks. We unconditionally enable SHA1 when a TPM is selected, which is the only hashing algorithm v1.2 supports. Signed-off-by: Ilias Apalodimas <[email protected]> Reviewed-by: Simon Glass <[email protected]> Tested-by: Simon Glass <[email protected]> # chromebook-link
2024-06-30tpm: Untangle tpm2_get_pcr_info()Ilias Apalodimas
This function was used on measured boot to retrieve the number of active PCR banks and was designed to work with the TCG protocols. Since we now have the need to retrieve the active PCRs outside the measured boot context -- e.g use the in the command line, decouple the function. Create one that will only adheres to TCG TSS2.0 [0] specification called tpm2_get_pcr_info() which can be used by the TPM2.0 APIs and a new one that is called from the measured boot context called tcg2_get_pcr_info() [0] https://trustedcomputinggroup.org/wp-content/uploads/TSS_Overview_Common_Structures_Version-0.9_Revision-03_Review_030918.pdf Signed-off-by: Ilias Apalodimas <[email protected]>
2024-06-30tpm: Move TCG functions into a separate fileIlias Apalodimas
The previous patch is moving the TPM TCG headers in their own file for a cleaner API. Move the functions in their own file as well. Signed-off-by: Ilias Apalodimas <[email protected]>
2024-06-30tpm: Move TCG headers into a separate fileIlias Apalodimas
commit 97707f12fdab ("tpm: Support boot measurements") moved out code from the EFI subsystem into the TPM one to support measurements when booting with !EFI. Those were moved directly into the TPM subsystem and in the tpm-v2.c library. In hindsight, it would have been better to move it in new files since the TCG2 is governed by its own spec, it's overeall cleaner and also easier to enable certain parts of the TPM functionality. So let's start moving the headers in a new file containing the TCG specific bits. Signed-off-by: Ilias Apalodimas <[email protected]>
2024-05-27tpm-v2: add support for mapping algorithm names to algosTim Harvey
replace tpm2_supported_algorithms with an array of structures relating algorithm names, to TCG id's, digest length and mask values. While at it fix the tpm2_algorithm_to_mask to return the proper value. Cc: Eddie James <[email protected]> Cc: Ilias Apalodimas <[email protected]> Fixes: 97707f12fdab ("tpm: Support boot measurements") Signed-off-by: Tim Harvey <[email protected]> Tested-by: Ilias Apalodimas <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2023-10-27tpm: Support boot measurementsEddie James
Add TPM2 functions to support boot measurement. This includes starting up the TPM, initializing/appending the event log, and measuring the U-Boot version. Much of the code was used in the EFI subsystem, so remove it there and use the common functions. Signed-off-by: Eddie James <[email protected]> For the API moving around from EFI -> u-boot core Reviewed-by: Ilias Apalodimas <[email protected]> For EFI testing Tested-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2023-10-27tpm: Fix spelling for tpmu_ha unionEddie James
tmpu -> tpmu Signed-off-by: Eddie James <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2023-02-28tpm: add a function that performs selftest + startupIlias Apalodimas
As described in [0] if a command requires use of an untested algorithm or functional module, the TPM performs the test and then completes the command actions. Since we don't check for TPM_RC_NEEDS_TEST (which is the return code of the TPM in that case) and even if we would, it would complicate our TPM code for no apparent reason, add a wrapper function that performs both the selftest and the startup sequence of the TPM. It's worth noting that this is implemented on TPMv2.0. The code for 1.2 would look similar, but I don't have a device available to test. [0] https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.07-2014-03-13.pdf ยง12.3 Self-test modes Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2023-02-19efi_loader: Measure the loaded DTBEtienne Carriere
Measures the DTB passed to the EFI application upon new boolean config switch CONFIG_EFI_TCG2_PROTOCOL_MEASURE_DTB. For platforms where the content of the DTB passed to the OS can change across reboots, there is not point measuring it hence the config switch to allow platform to not embed this feature. Co-developed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]> Signed-off-by: Etienne Carriere <[email protected]> Tested-by: Ilias Apalodimas <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
2022-09-03tpm: Allow committing non-volatile dataSimon Glass
Add an option to tell the TPM to commit non-volatile data immediately it is changed, rather than waiting until later. This is needed in some situations, since if the device reboots it may not write the data. Add definitions for the rest of the Cr50 commands while we are here. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2022-09-03tpm: Implement state command for Cr50Simon Glass
Add a vendor-specific TPM2 command for this and implement it for Cr50. Note: This is not part of the TPM spec, but is a Cr50 extension. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
2022-01-19doc: replace @return by Return:Heinrich Schuchardt
Sphinx expects Return: and not @return to indicate a return value. find . -name '*.c' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; find . -name '*.h' -exec \ sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \; Signed-off-by: Heinrich Schuchardt <[email protected]>
2021-11-30tpm: use more algorithms than sha256 on pcr_readRuchika Gupta
The current tpm2_pcr_read is hardcoded using SHA256. Make the actual command to TPM configurable to use wider range of algorithms. The current command line is kept as is i.e limited to SHA-256 only. Signed-off-by: Ruchika Gupta <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
2021-11-10tpm2: Introduce TIS tpm coreIlias Apalodimas
There's a lot of code duplication in U-Boot right now. All the TPM TIS compatible drivers we have at the moment have their own copy of a TIS implementation. So let's create a common layer which implements the core TIS functions. Any driver added from now own, which is compatible with the TIS spec, will only have to provide the underlying bus communication mechanisms. Signed-off-by: Ilias Apalodimas <[email protected]>
2021-11-07efi_loader: add EFI_TCG2_PROTOCOL.SubmitCommandMasahisa Kojima
This commit adds the EFI_TCG2_PROTOCOL.SubmitCommand required in the TCG PC Client PFP spec. SubmitCommand enables to send the raw command to the TPM device. To implement this api, tpm2_submit_command() is added into tpm-v2.c. Signed-off-by: Masahisa Kojima <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
2021-08-14efi_loader: add boot variable measurementMasahisa Kojima
TCG PC Client PFP spec requires to measure "Boot####" and "BootOrder" variables, EV_SEPARATOR event prior to the Ready to Boot invocation. Since u-boot does not implement Ready to Boot event, these measurements are performed when efi_start_image() is called. TCG spec also requires to measure "Calling EFI Application from Boot Option" for each boot attempt, and "Returning from EFI Application from Boot Option" if a boot device returns control back to the Boot Manager. Signed-off-by: Masahisa Kojima <[email protected]>
2021-08-01sandbox: tpm: Support nvdata in TPM2Simon Glass
Add support for this feature in the TPM2 emulator, to support Chromium OS vboot. Signed-off-by: Simon Glass <[email protected]>
2021-05-28efi_loader: add PE/COFF image measurementMasahisa Kojima
"TCG PC Client Platform Firmware Profile Specification" requires to measure every attempt to load and execute a OS Loader(a UEFI application) into PCR[4]. This commit adds the PE/COFF image measurement, extends PCR, and appends measurement into Event Log. Acked-by: Ilias Apalodimas <[email protected]> Tested-by: Ilias Apalodimas <[email protected]> Signed-off-by: Masahisa Kojima <[email protected]> Replace CONFIG_HASH_CALCULATE by CONFIG_HASH Fix conversions between pointers and u64. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
2021-04-29tpm: missing event typesHeinrich Schuchardt
Add a reference for the TPM event types and provide missing constants. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]>
2021-03-02tpm: Allow disabling platform hierarchy with TPM2Simon Glass
With TPM2 we don't actually lock the TPM once verified boot is finished. Instead we disable the platform hierarchy which serves the same purpose. Add an implementation of this so we can safely boot into the kernel. Signed-off-by: Simon Glass <[email protected]> Acked-by: Ilias Apalodimas <[email protected]>
2021-03-02tpm: Add TPM2 support for write_lockSimon Glass
Implement this API function for TPM2. Signed-off-by: Simon Glass <[email protected]> Acked-by: Ilias Apalodimas <[email protected]>
2021-03-02tpm: Add TPM2 support for read/write valuesSimon Glass
Implement this API function for TPM2. Signed-off-by: Simon Glass <[email protected]> Acked-by: Ilias Apalodimas <[email protected]>
2021-03-02tpm: Add an implementation of define_spaceSimon Glass
Add support for this so that the TPM can be set up for use with Chromium OS verified boot. Signed-off-by: Simon Glass <[email protected]> Acked-by: Ilias Apalodimas <[email protected]>
2021-02-02common: Drop asm/global_data.h from common headerSimon Glass
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2020-12-03tpm: Add tpm2 headers for TCG2 eventlog supportIlias Apalodimas
A following patch introduces support for the EFI_TCG2_PROTOCOL eventlog management. Introduce the necessary tpm related headers Signed-off-by: Ilias Apalodimas <[email protected]>
2020-12-03tpm: use more than sha256 on pcr_extendIlias Apalodimas
The current tpm2_pcr_extend is hardcoded using SHA256. Let's make the actual command to the TPM2 configurable so we can support a wider range of algorithms and keep the current command line as-is i.e limited to SHA256 only Signed-off-by: Ilias Apalodimas <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2020-11-14tpm: Add some headers from the specIlias Apalodimas
A following patch introduces EFI_TCG2_PROTOCOL. Add the required TPMv2 headers to support it. Signed-off-by: Ilias Apalodimas <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2020-07-08tpm: add TPM2_GetRandom command supportDhananjay Phadke
Add support for TPM2 GetRandom command Signed-off-by: Dhananjay Phadke <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2020-02-07tpm: Add more TPM2 definitionsSimon Glass
Add definitions for access and status. Need to drop the mixed case. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2018-12-05tpm: Add non-volatile index attributes needed for v2Simon Glass
Version-2 TPMs support attributes for nvdata. Add definitions to the header file so that clients can use it. Signed-off-by: Simon Glass <[email protected]>
2018-11-29tpm: Convert to use a device parameterSimon Glass
At present many TPM calls assume there is only one TPM in the system and look up this TPM themselves. This is inconsistent with driver model, which expects all driver methods to have a device parameter. Update the code to correct this. Signed-off-by: Simon Glass <[email protected]>
2018-10-09sandbox: tpm: Tidy up enums and return valuesSimon Glass
Use an enum for command values instead of open-coding them. This removes the need for comments. Also make sure the driver returns proper error numbers instead of -1. Signed-off-by: Simon Glass <[email protected]>
2018-05-25tpm: add PCR authentication commands supportMiquel Raynal
Add support for the TPM2_PCR_SetAuthPolicy and TPM2_PCR_SetAuthValue commands. Change the command file and the help accordingly. Note: These commands could not be tested because the TPMs available do not support them, however they could be useful for someone else. The user is warned by the command help. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-05-25tpm: add TPM2_HierarchyChangeAuth command supportMiquel Raynal
Add support for the TPM2_HierarchyChangeAuth command. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-05-25tpm: add dictionary attack mitigation commands supportMiquel Raynal
Add support for the TPM2_DictionaryAttackParameters and TPM2_DictionaryAttackLockReset commands. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-05-25tpm: add TPM2_GetCapability command supportMiquel Raynal
Add support for the TPM2_GetCapability command. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-05-25tpm: add TPM2_PCR_Read command supportMiquel Raynal
Add support for the TPM2_PCR_Read command. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-05-25tpm: add TPM2_PCR_Extend command supportMiquel Raynal
Add support for the TPM2_PCR_Extend command. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>
2018-05-25tpm: add TPM2_Clear command supportMiquel Raynal
Add support for the TPM2_Clear command. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal <[email protected]> Reviewed-by: Simon Glass <[email protected]> Reviewed-by: Tom Rini <[email protected]>