Skip to content

Add finer per-command-group gating macros in fTPM - #574

Open
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_finer_gating
Open

Add finer per-command-group gating macros in fTPM#574
dgarske wants to merge 1 commit into
wolfSSL:masterfrom
dgarske:fwtpm_finer_gating

Conversation

@dgarske

@dgarske dgarske commented Aug 13, 2026

Copy link
Copy Markdown
Member

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_ENC precedent:

Macro Compiles out
FWTPM_NO_KEY_MIGRATION Import, Duplicate, Rewrap (keeps the shared wrap/import helpers, LoadExternal, CreateLoaded)
FWTPM_NO_ECDH ECDH_KeyGen, ECDH_ZGen, EC_Ephemeral, ZGen_2Phase, ECC_Parameters (and the ecEphemeral* context fields)
FWTPM_NO_HASH_CMDS Hash, HMAC and the hash sequence commands (kept alive when WOLFTPM_MLDSA still needs the shared sequence path)
FWTPM_NO_CONTEXT ContextSave, ContextLoad (keeps FlushContext)
FWTPM_NO_SYM_ENCRYPT EncryptDecrypt, EncryptDecrypt2
FWTPM_NO_CLOCK ReadClock, ClockSet, ClockRateAdjust

There 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_GetCapability derives the advertised command list and TPM_PT_TOTAL_COMMANDS from the same fwCmdTable[] 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 -Os build, 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

  • Compile-clean across every new -DFWTPM_NO_* flag individually and with all of them enabled together, including the FWTPM_NO_HASH_CMDS + WOLFTPM_MLDSA combination.
  • CI (.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.md feature-group table (new macros + the previously missing FWTPM_NO_PARAM_ENC row), src/fwtpm/README.md (macro list + build-only matrix rows), root README.md, and a ChangeLog.md entry.

@dgarske dgarske self-assigned this Aug 13, 2026
Copilot AI lite review requested due to automatic review settings August 13, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread docs/FWTPM.md
**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 thread src/fwtpm/fwtpm_command.c
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 thread src/fwtpm/fwtpm_command.c
Comment on lines 12688 to 12692
{
return FwEncryptDecryptCore(ctx, cmd, cmdSize, rsp, cmdTag, 1);
}
#endif /* !FWTPM_NO_SYM_ENCRYPT */
#endif /* !NO_AES */
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