Skip to content

Reduce wolfTPM and fwTPM RAM, stack and flash use for 5.0.0 - #693

Open
dgarske wants to merge 40 commits into
wolfSSL:masterfrom
dgarske:size_memory
Open

dgarske wants to merge 40 commits into
wolfSSL:masterfrom
dgarske:size_memory

Conversation

@dgarske

@dgarske dgarske commented Dec 4, 2026

Copy link
Copy Markdown
Member

This PR cuts static RAM, stack and flash in the client library and the firmware TPM (fwTPM), adds a power-loss safe fwTPM NV journal, and bumps the version to 5.0.0 for the ABI changes. Key changes include:

  • fwTPM static RAM: PCR digests stored at the size of each bank, and shared pools for the private keys of persistent and cached objects and for NV index data, with FWTPM_FULL_POOLS to keep the full-size pools.
  • RSA private keys stored as one prime in fwTPM private blobs and persistent objects, in the reference blob format; whole-key blobs and journals still load and are converted.
  • fwTPM NV journal format 5 for custom HALs: commit records, rollback of a torn tail, two alternating regions, and conversion of format 4 journals at first boot; OP-TEE keeps the journal in two objects.
  • fwTPM flash: value-returning parse helpers, the session tag check inside the auth-area skip, one response position, and a packed command table.
  • fwTPM and client stack: large locals moved to the heap under small stack, and the small stack packet buffers sized for the RSA keys the build stores.
  • Client: a shared command prologue and send path, and WOLFTPM_NO_STRINGS to compile out the name and response code tables.
  • TPM2B_PUBLIC_KEY_RSA sized at the modulus of a new public RSA limit, MAX_RSA_PUB_KEY_BITS (default 4096); MAX_RSA_KEY_BITS keeps its meaning and default.

ABI and compatibility:

  • Public struct layouts change in builds that raise the RSA limits, so the version moves to 5.0.0 and the libtool version to 19:0:0.
  • Existing fwTPM NV state loads: the file backend stays on format 4, custom HALs convert to format 5, whole RSA keys convert to one prime at load, and NV data larger than the new default pool needs FWTPM_FULL_POOLS. A journal written by this release does not load in an older one.

Testing:

  • New unit tests for the NV layout, the format 4 conversion, power-cut sweeps over custom HALs (sampled in append-only builds, every cut with FWTPM_TEST_NV_CUT_ALL), whole-key blob and journal conversion, and RSA 4096 in small-stack builds.
  • CI entries for the append-only journal, full-size pools, small stack with v1.85 and the small-stack fwTPM through make check.
  • Client unit tests and examples on an Infineon SLB9670 (Raspberry Pi 4) and examples on an SLB9678 (Raspberry Pi 5), with results matching master. Not tested on a real OP-TEE.

Resolves F-18944

Copilot AI balanced review requested due to automatic review settings December 4, 2026 04:19
@dgarske dgarske self-assigned this Dec 4, 2026

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.

🟡 Changes recommended

An allowed fast-math RSA configuration fails to build without key generation, and misleading NV-format documentation risks downgrades that lose TPM state.

2 open issues
What changed in this PR

Reduces wolfTPM client and fwTPM memory usage for 5.0.0, while adding power-loss recovery for custom NV storage backends.

Changes:

  • Introduces compact PCR storage, shared memory pools, one-prime RSA storage, and revised small-stack sizing.
  • Adds format 5 NV journals, migration support, and two-region OP-TEE storage.
  • Updates ABI versions, documentation, regression tests, and CI coverage.
File Description
wolftpm/​version.h Bumps version to 5.0.0.
wolftpm/​tpm2.h Separates RSA private-buffer sizing.
wolftpm/​tpm2_types.h Defines RSA limits and conditional buffer sizes.
wolftpm/​fwtpm/​fwtpm.h Adds compact storage, pools, and journal state.
wolftpm/​fwtpm/​fwtpm_optee.h Defines dual-object NV storage.
wolftpm/​fwtpm/​fwtpm_nv.h Defines format 5 journal records.
wolftpm/​fwtpm/​fwtpm_crypto.h Updates RSA and response helper interfaces.
tests/​unit_tests.c Expands RSA and no-strings coverage.
tests/​optee/​tee_internal_api.h Adds the mock overwrite flag.
tests/​optee/​README.md Describes expanded storage tests.
tests/​optee/​optee_core_tests.c Tests migration and power-loss recovery.
tests/​optee/​mock_tee.h Exposes storage fault-injection controls.
tests/​optee/​mock_tee.c Implements snapshots and simulated power cuts.
tests/​optee/​fwtpm_optee_port_tests.c Tests dual-region storage operations.
tests/​fwtpm_check.sh Enables small-stack RSA examples.
src/​fwtpm/​ports/​optee/​README.md Documents storage recovery and compatibility.
src/​fwtpm/​ports/​optee/​fwtpm_optee_nv.c Implements dual-object NV access.
src/​fwtpm/​fwtpm.c Implements pools and persistent-key expansion.
src/​fwtpm/​fwtpm_crypto.c Implements one-prime RSA conversion.
examples/​keygen/​keygen.c Adjusts public-key PEM buffer sizing.
docs/​release-notes.md Summarizes sizing and client changes.
docs/​fwtpm/​usage.md Documents key blobs and test configurations.
docs/​fwtpm/​hal-and-porting.md Explains journal formats and recovery guarantees.
docs/​fwtpm/​building.md Documents pools and memory costs.
docs/​build-options.md Documents new sizing and string options.
configure.ac Updates versions and small-stack definitions.
CMakeLists.txt Updates version and buffer configuration.
ChangeLog.md Records ABI and memory changes.
.github/​workflows/​make-test-swtpm.yml Adds no-strings testing.
.github/​workflows/​fwtpm-test.yml Expands journal, pool, and small-stack testing.

Review effort: Balanced

Comment thread src/fwtpm/fwtpm_crypto.c Resolved
Comment thread ChangeLog.md Resolved
@dgarske
dgarske requested a review from aidangarske December 5, 2026 03:05
@dgarske dgarske assigned wolfSSL-Bot and aidangarske and unassigned dgarske Dec 5, 2026
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.

4 participants