Add firmware TPM 2.0 (fwTPM) implementation#474
Merged
aidangarske merged 1 commit intowolfSSL:masterfrom Apr 17, 2026
Merged
Conversation
9c0208f to
eae465e
Compare
b186ecc to
f529484
Compare
danielinux
requested changes
Apr 3, 2026
Add portable firmware TPM 2.0 implementation (fwTPM) built on wolfCrypt. Implements 105/113 TPM 2.0 v1.38 commands (93%) as a standalone server with socket and TIS transports, NV storage, and full CI/fuzz coverage.
aidangarske
approved these changes
Apr 17, 2026
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
Add
fwtpm_server: a portable, standards-compliant firmware TPM 2.0 commandprocessor built entirely on wolfCrypt. The fwTPM can replace a hardware TPM on
embedded platforms without a discrete TPM chip, or serve as a drop-in
development/CI replacement for external simulators (swtpm, MS TPM simulator).
71 files changed, ~32,000 lines added, ~2,000 lines removed.
Features
TPM 2.0 Command Processor (105 commands, 93% of v1.38 spec)
104 command handler functions in
fwtpm_command.c(~13,300 lines) covering:Cryptographic Engine (
fwtpm_crypto.c, ~3,000 lines)39 helper functions built on wolfCrypt providing:
Transport Layers
Socket/SWTPM Protocol (
fwtpm_io.c, 669 lines):mssimandswtpmTCTI protocols (auto-detected)TIS Register-Level Transport (
fwtpm_tis.c+fwtpm_tis_shm.c, 688 lines):hal/tpm_io_fwtpm.c, 262 lines) translates wolfTPM TIS register ops to shared memoryUART Transport (client-side, in
tpm2_swtpm.c):--enable-swtpm=uart)NV Persistent Storage (
fwtpm_nv.c, ~1,800 lines)Session and Authorization
Primary Key Derivation and Caching
Compile-Time Feature Selection
All features independently gateable for size optimization on constrained targets:
FWTPM_NO_ATTESTATIONFWTPM_NO_NVFWTPM_NO_POLICYFWTPM_NO_CREDENTIALFWTPM_NO_DAFWTPM_NO_PARAM_ENCNO_RSA/NO_AESWOLFTPM_SMALL_STACKHAL Abstraction for Embedded Porting
docs/FWTPM.mdLibrary Refactoring
Extracted shared code from existing library files into new reusable modules:
tpm2_crypto.c(515 lines):TPM2_KDFa_ex,TPM2_KDFe, AES-CFB encrypt/decrypt, HMAC helpers, hash wrappers -- moved fromtpm2_param_enc.ctpm2_util.c(168 lines):TPM2_GetHashType,TPM2_GetHashDigestSize,ConstantCompare,ForceZero,PrintBin-- moved fromtpm2.ctpm2_packet.c: Added byte-array endian conversion helpers (U16/U32/U64 ToByteArray/FromByteArray, both BE and LE), shared by fwTPM wire format and NV serializationtpm2_swtpm.c: Added UART serial transport option (WOLFTPM_SWTPM_UART), SWTPM protocol auto-detection (mssim vs swtpm TCTI)tpm2.c,tpm2_param_enc.c,tpm2_wrap.c)Testing
Unit Tests (
fwtpm_unit_tests.c, 2,223 lines)56 test functions calling
FWTPM_ProcessCommand()directly with crafted packets:tpm2-tools Integration Tests (
tpm2_tools_test.sh, 2,127 lines)318 tests across 63 test groups using standard
tpm2-toolscommands:Fuzz Testing (
tests/fuzz/, libFuzzer)fwtpm_fuzz.c: Feeds raw byte streams toFWTPM_ProcessCommand()with ASangen_corpus.py: Generates 29 seed corpus entries (valid TPM command packets)tpm2.dict: Fuzzer dictionary with TPM tags, command codes, algorithm IDsCI Workflows
New:
fwtpm-test.yml(11 matrix entries)Runtime tests (build + examples + make check):
Build-only tests (compilation + pedantic warnings):
Separate job: tpm2-tools (311 tests via
scripts/tpm2_tools_test.sh)New:
fuzz.ymlUpdated Existing Workflows
cmake-build.yml: Added fwTPM matrix entries (socket, TIS, fwtpm-only) + CTest stepcoverity-scan-fixes.yml: Updated wolfSSL build flagsmake-test-swtpm.yml: Enhanced for fwTPM server lifecycle managementsanitizer.yml: Added fwTPM sanitizer configurationsseal-test.yml: Updated for fwTPM compatibilitycodespell.yml: Added new word exceptions (daa, pris, hsi)multi-compiler.yml: Updated wolfSSL flagsBuild System
configure.ac: New--enable-fwtpm,--enable-fwtpm-only,--enable-fuzzoptions;WOLFTPM_FWTPM_HAL/WOLFTPM_FWTPM_TISauto-configuration when swtpm is not enabledCMakeLists.txt: Full CMake support withWOLFTPM_FWTPM,WOLFTPM_FWTPM_ONLYoptions, fwtpm_server target, fuzz target, CTest integrationMakefile.am: Updated for new source files and scriptssrc/fwtpm/include.am: Build rules for fwtpm_server and fwtpm_fuzz targetsIDE/VisualStudio/wolftpm.vcxproj: Added new shared source filesDocumentation
docs/FWTPM.md(688 lines): Architecture, build instructions, all 105 commands documented, HAL porting guide with examples, configuration macro reference, transport mode details, API reference, lifecycle documentation, primary key derivation explanationsrc/fwtpm/README.md(248 lines): Full CI test matrix, spec coverage gap analysis (v1.38/v1.59/v1.84/v1.85 roadmap), build/test quick referencedocs/SWTPM.md: Added fwTPM as alternative to external swtpmREADME.md: Added fwTPM feature section with summary and link to docssrc/fwtpm/ports/README.md: Porting placeholder for embedded targetsOther Changes
examples/run_examples.sh: Updated to manage fwtpm_server lifecycle, stale cert/blob cleanup on NV wipeexamples/native/native_test.c: Conditional compilation for fwTPM compatibilitytests/unit_tests.c: Updated for shared utility refactoring.gitignore: Added fwtpm_server binary, NV file, fuzz artifactspre-commit.sh: Removed (superseded by CI workflows)zephyr/user_settings.h: Added WOLFTPM_FWTPM supportRemaining Known Gaps
tpm2_import -i key.pem(direct import without tpm2_duplicate wrapping) returns TPM_RC_INTEGRITY due to tpm2-tools internal format difference; workaround viatpm2_duplicate --tcti noneworks correctly