Add finer per-command-group gating macros in fTPM - #574
Open
dgarske wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Adds opt-in compile-time gates to selectively compile out additional fwTPM command groups, reducing fTPM footprint on constrained targets while keeping the default command set unchanged.
Changes:
- Introduces new
FWTPM_NO_*macros for finer per-command-group feature gating (clock, context, key migration, ECDH, hash cmds, symmetric encrypt). - Updates the fwTPM dispatch table and command implementations to honor the new gates (including MLDSA-specific exceptions for shared sequences).
- Expands documentation and CI build matrix coverage for the new configuration combinations.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
wolftpm/fwtpm/fwtpm.h |
Documents the new command-group gating macros and intended usage. |
src/fwtpm/fwtpm_command.c |
Wraps command handlers and fwCmdTable[] entries with new per-group #ifndef gates. |
src/fwtpm/README.md |
Documents new macros and adds CI matrix rows describing the build-only configurations. |
docs/FWTPM.md |
Updates feature-gating table and rewrites the “minimal build example” for explicit gate selection. |
README.md |
Updates top-level feature blurb to mention per-command-group feature selection. |
.github/workflows/fwtpm-test.yml |
Adds build-only CI jobs for each new gate and for “all gates” configurations (incl. MLDSA). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| **Minimal build example** (measured boot only): | ||
| **Minimal build example.** There is no umbrella macro - select the command | ||
| groups to drop explicitly, so each is a deliberate choice. For example, to build | ||
| a small ECC-only attestation + NV fTPM: |
Comment on lines
+203
to
+210
| extra_cflags: -DFWTPM_NO_POLICY -DFWTPM_NO_ATTESTATION -DFWTPM_NO_CREDENTIAL -DFWTPM_NO_DA -DFWTPM_NO_PARAM_ENC -DFWTPM_NO_KEY_MIGRATION -DFWTPM_NO_ECDH -DFWTPM_NO_HASH_CMDS -DFWTPM_NO_CONTEXT -DFWTPM_NO_SYM_ENCRYPT -DFWTPM_NO_CLOCK | ||
|
|
||
| - name: fwtpm-all-gates-mldsa | ||
| os: ubuntu-latest | ||
| wolftpm_config: --enable-fwtpm --enable-swtpm --enable-v185 --enable-mldsa | ||
| wolfssl_config: --enable-wolftpm --enable-pkcallbacks --enable-keygen --enable-experimental --enable-mldsa | ||
| build_only: true | ||
| extra_cflags: -DFWTPM_NO_POLICY -DFWTPM_NO_ATTESTATION -DFWTPM_NO_CREDENTIAL -DFWTPM_NO_DA -DFWTPM_NO_PARAM_ENC -DFWTPM_NO_KEY_MIGRATION -DFWTPM_NO_ECDH -DFWTPM_NO_HASH_CMDS -DFWTPM_NO_CONTEXT -DFWTPM_NO_SYM_ENCRYPT -DFWTPM_NO_CLOCK |
Comment on lines
12397
to
12401
| #ifndef NO_AES | ||
| #ifndef FWTPM_NO_SYM_ENCRYPT | ||
| /* --- TPM2_EncryptDecrypt (CC 0x0164) and EncryptDecrypt2 (CC 0x0187) --- | ||
| * Symmetric encrypt/decrypt using a loaded SYMCIPHER key. | ||
| * EncryptDecrypt: keyHandle, decrypt, mode, ivIn, inData |
Comment on lines
12688
to
12692
| { | ||
| return FwEncryptDecryptCore(ctx, cmd, cmdSize, rsp, cmdTag, 1); | ||
| } | ||
| #endif /* !FWTPM_NO_SYM_ENCRYPT */ | ||
| #endif /* !NO_AES */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds opt-in macros that let a firmware-TPM (fwTPM) build compile out command groups it does not need, so wolfTPM's fwTPM can fit deeply memory-constrained targets. All new macros default OFF, so the default fwTPM command set is unchanged and no existing build is affected.
What is added
Six new per-group gates plus one umbrella, following the existing
FWTPM_NO_POLICY/NO_ATTESTATION/NO_CREDENTIAL/NO_DA/NO_PARAM_ENCprecedent:FWTPM_NO_KEY_MIGRATIONFWTPM_NO_ECDHecEphemeral*context fields)FWTPM_NO_HASH_CMDSWOLFTPM_MLDSAstill needs the shared sequence path)FWTPM_NO_CONTEXTFWTPM_NO_SYM_ENCRYPTFWTPM_NO_CLOCKThere is intentionally no "minimal" umbrella macro: dropping a command group removes real TPM functionality, so a build must select each gate deliberately rather than flipping one switch. Applying all six new gates plus the five pre-existing
FWTPM_NO_*gates leaves a core fTPM (Startup / GetCapability / GetRandom / PCR / Create / Load / Sign / VerifySignature / NV / sessions).Why it is safe
TPM2_GetCapabilityderives the advertised command list andTPM_PT_TOTAL_COMMANDSfrom the samefwCmdTable[]dispatch table, so removing a table row removes the command from capability reporting automatically - no separate GetCapability edits are needed and a gated command cannot be advertised-but-missing. Shared helpers used by the retained commands (key wrap/import, hash sequence lookups used by MLDSA signing, FlushContext) are explicitly kept. The MLDSA sign path shares the TPM sequence commands, so those are guarded with#if !defined(FWTPM_NO_HASH_CMDS) || defined(WOLFTPM_MLDSA)to avoid breaking a gated + MLDSA build.Footprint impact
On a 32-bit RISC-V
-Osbuild, enabling all of these gates removes roughly 20 KB of code from the fwTPM command engine. Combined with a hardware-TRNG entropy source this is what lets an ECC-only fwTPM fit a 192 KB soft-core target (see the AMD SCU35 example in wolftpm-examples, which selects the gate set explicitly in its user_settings.h).Testing
-DFWTPM_NO_*flag individually and with all of them enabled together, including theFWTPM_NO_HASH_CMDS+WOLFTPM_MLDSAcombination..github/workflows/fwtpm-test.yml): build-only matrix entries for each new flag plus an all-gates-together build standalone and with MLDSA. Functional unit tests continue to run on the default (full) build; gated commands are guarded there by the matching#ifndef.Docs
docs/FWTPM.mdfeature-group table (new macros + the previously missingFWTPM_NO_PARAM_ENCrow),src/fwtpm/README.md(macro list + build-only matrix rows), rootREADME.md, and aChangeLog.mdentry.