Skip to content

tpm: pair the PCR bank algorithm with its digest size - #907

Open
dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:tpm_pcr_pairing
Open

dgarske wants to merge 2 commits into
wolfSSL:masterfrom
dgarske:tpm_pcr_pairing

Conversation

@dgarske

@dgarske dgarske commented Sep 19, 2026

Copy link
Copy Markdown
Member

Found while adding SHA2-384 measured boot for a Tiger Lake TPM target.

WOLFBOOT_TPM_PCR_ALG and WOLFBOOT_TPM_PCR_DIG_SZ were defined together under a single #ifndef on the algorithm. Overriding only the algorithm therefore left the digest size undefined, and an undefined macro is 0 to the preprocessor, so the downstream digest-size checks silently changed meaning rather than failing to build.

This selects the pair with one switch - WOLFBOOT_TPM_PCR_SHA384 chooses SHA2-384 (digest size 48), otherwise SHA2-256 (digest size 32) - and adds an #error when exactly one of the two macros is defined, so a half-specified override is caught at compile time. The algorithm itself cannot be validated with #if: TPM_ALG_SHA256 and friends are enum constants, not macros, so any #if comparison against them evaluates 0 == 0 and is always true.

Note: a SHA2-384 PCR bank exists on parts like the Infineon SLB9672 but not the SLB9670; selecting it on a part without that bank makes every extend fail, which measured boot treats as fatal.

Copilot AI lite review requested due to automatic review settings September 19, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

SHA-384 PCR selection can cause existing 32-byte measurement buffers to be read as 48-byte inputs.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This PR makes TPM PCR algorithm and digest-size configuration explicit and adds SHA-384 PCR-bank selection.

Changes:

  • Detects half-specified PCR overrides at compile time.
  • Adds WOLFBOOT_TPM_PCR_SHA384 for SHA-384/48-byte PCRs.
  • Retains SHA-256/32-byte defaults.
File Description
include/​tpm.h Defines PCR algorithm and digest-size selection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread include/tpm.h
Comment on lines +57 to +61
#ifdef WOLFBOOT_TPM_PCR_SHA384
/* SHA2-384 bank. Present on parts like the Infineon SLB9672, absent on
* the SLB9670 - selecting it on a part with no such bank makes every
* extend fail, which measured boot treats as fatal. */
#define WOLFBOOT_TPM_PCR_ALG TPM_ALG_SHA384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants