Commit Graph

52 Commits (master)

Author SHA1 Message Date
Aidan Garske 64a6437e0e Reduce FWTPM_NO_NV context memory 2026-09-16 10:41:13 -07:00
Aidan Garske 18d9ead84f Keep fixed fwTPM TIS semaphore names and protocol version 2026-09-02 14:14:59 -07:00
Aidan Garske a7b1aa6c3b Inline fwTPM TIS atomics and semaphore name helpers 2026-09-02 14:14:59 -07:00
Aidan Garske 95696b36ef F-12736 - Authenticate fwTPM shared-memory endpoints 2026-09-02 14:14:58 -07:00
Aidan Garske 5e3cbd2241 F-12735 - Pin the SPDM responder identity 2026-09-02 14:14:58 -07:00
Aidan Garske 3507da0429 F-12710 - Advertise supported ECC curves 2026-09-02 14:14:28 -07:00
David Garske a5a400bd0b Add support for the NVIDIA Jetson Orin OP-TEE firmware TPM 2026-08-18 14:03:58 -07:00
David Garske 20dae36517 fwTPM: add finer per-command-group gating macros 2026-08-17 12:14:10 -07:00
Aidan Garske f6b364f7b8 F-7609 - Keep swtpm TCP connection open across commands 2026-08-04 13:03:25 -07:00
David Garske c5e06368af fwTPM: enforce TPM 2.0 command-code masking and fix TPM_CAP_COMMANDS TPMA_CC reporting; mask vendor bits in WOLFTPM_IS_COMMAND_UNAVAILABLE 2026-07-22 10:41:39 -07:00
David Garske b8709b13dd fwTPM: append-only NV journal for write-once flash ports and swtpm UART symlink support 2026-06-29 11:33:19 -07:00
aidan garske a5dfa141ae fwTPM: document lockoutAuth recovery as post-boot uptime and platform escape hatch per review 2026-06-25 14:36:46 -07:00
aidan garske df0fb838d9 fwTPM: harden Dictionary Attack (DA) protection to TCG spec and add DA/noDA test coverage 2026-06-25 09:09:36 -07:00
Tobias Frauenschläger 77e31c0ebb ML-DSA renaming 2026-05-20 13:09:26 -07:00
Aidan Garske 9ce41885e0 fwTPM v185: PR review fixes + TCG/security hardening
Build / portability:
  - Drop #pragma message in fwtpm_crypto.c (MSVC-incompatible)
  - Replace non-ASCII section sign with Sec. across all sources/docs

  Configure:
  - Add --enable-pqc alias for --enable-v185 (same WOLFTPM_V185 macro)
  - Auto-detect: when --enable-fwtpm + wolfCrypt has dilithium.h+mlkem.h
    and neither flag is set, configure auto-enables PQC; --disable-pqc
    opts out
  - Both flags probe the wolfSSL PQC headers and fail at configure time
    with a clear hint when missing

  Spec / security hardening:
  - VerifySequenceComplete now emits TPM_ST_DIGEST_VERIFIED (with hashAlg
    metadata) for Hash-ML-DSA tickets, MESSAGE_VERIFIED for Pure ML-DSA
    (was mis-tagging digests as messages, breaking PolicyTicket consumers)
  - Sign/VerifySequenceComplete: free the slot on TPM_RC_SIGN_CONTEXT_KEY
    too, so wrong-key Complete cannot exhaust FWTPM_MAX_SIGN_SEQ slots
    (CWE-772 DoS)
  - TestParms PQC arms return TPM_RC_PARMS (spec-correct) instead of
    TPM_RC_VALUE; reject MLDSA/MLKEM parameter sets not actually compiled
    in; parse TPMS_MLKEM_PARMS.symmetric via TPM2_Packet_ParseSymmetric
  - GetCapability TPMA_ML_PARAMETER_SETS gates each MLDSA/MLKEM bit on the
    per-set wolfCrypt availability macro (subset builds advertise truth)
  - TPM2_VerifySignature client parser now defensive: only consume the
    v1.85 metaAlg when tag==DIGEST_VERIFIED && hierarchy!=RH_NULL
  - VerifyDigestSignature: hard-fail on keyName overflow instead of
    silently emitting a ticket missing the name binding
  - TPM_GENERATED_VALUE prefix check guarded with rc==0
  - Drop dead (void)cmdSize casts in Sign/VerifySequenceStart
  - wolfTPM2_EncryptSecret_MLKEM: track wc_InitRng_ex/wc_MlKemKey_Init
    success flags so Free is only called on initialized state
  - UBSan-v185 sanitizer cflags: explicitly disable signed-integer-overflow
    and shift checks (matches the comment about wolfSSL Hash_df 440<<24)

  Embedded RAM:
  - FWTPM_NV_PUBAREA_EST derives from FWTPM_MAX_MLDSA_PUB_SIZE /
    FWTPM_MAX_MLKEM_PUB_SIZE auto-shrink macros (subset builds save NV)
  - tpm2_types.h MAX_MLDSA_*/MAX_MLKEM_* stay at worst-case (ABI floor
    for TPM2B wire buffers) with comment

  Tests:
  - Negative test for Hash-MLDSA VerifySeqComplete ticket tag
  - Negative test exposing sign-seq slot leak on TPM_RC_SIGN_CONTEXT_KEY
  - Roundtrip test for wolfTPM2_SignDigest + VerifyDigestSignature

  Documentation:
  - README, FWTPM.md, fwtpm/README.md, examples/pqc/README.md mention
    both --enable-pqc and --enable-v185 + auto-detect
  - README wolfSSL line: --enable-pkcallbacks + WC_RSA_NO_PADDING
  - fwtpm/README.md: drop FWTPM_SPEC_* labels (macros never existed),
    remove v1.85 Additions table (all 8 commands implemented), update
    coverage table to 137/113/24 (82%); note remaining gaps are
    inherited v1.59/v1.84 commands, not PQC
  - fwtpm_nv.h:52: clarify 2592 vs 2720 math (PQC pub key + header slack)
2026-04-29 10:29:51 -07:00
Aidan Garske f568e048bd fwTPM v185: TCG/security review fixes + embedded RAM auto-shrink
Code quality / defensive fixes:
  - TPM2_Encap/Decap: drop bare scope braces, hoist wireSize locals
  - FwCmd_SequenceUpdate: clarify Pure ML-DSA sign accumulation comment
  - FwAllocSignSeq: _Static_assert transient slot range stays valid
  - keygen: drop unused hashMldsaHash local, pass TPM_ALG_SHA256 directly
  - FwCmd_Encapsulate: skip auth area when cmdTag == TPM_ST_SESSIONS
  - writeKeyBlob: restore no-op TPM_RC_SUCCESS in NO_FILESYSTEM build
  - FwCmd_SignDigest restricted-key ticket compare: TPM2_ConstantCompare
  - FwCmd_VerifySequenceComplete: hard-fail if ticket data binding lost
    (no silent fallback that emits a weakened ticket)
  - wolfTPM2_VerifySequenceComplete: validate sigSz before SequenceUpdate
    so BUFFER_E does not leak the TPM-side sequence handle
  - FwCmd_VerifySequenceComplete: heap-allocate ~1KB ticketData via
    FWTPM_DECLARE_BUF / FWTPM_ALLOC_BUF (matches sibling buffers)

  v1.85 capability + scope:
  - GetCapability: report TPM_PT_FIRMWARE_SVN/MAX_SVN = 0
  - Allow Pure ML-DSA streaming via SequenceUpdate per FIPS 204 (SHAKE256
    absorbing is incremental); SignSequenceComplete concatenates msgBuf
    with the trailing complete-time buffer and signs the full message
  - Document v1.85 scope: Encap/Decap is ML-KEM only; Sign/VerifySequence
    and SignDigest/VerifyDigestSignature are ML-DSA / Hash-ML-DSA only
    (classical schemes still go via TPM2_Sign / TPM2_VerifySignature)

  TCG ticket wire-format fixes (security):
  - TPMT_TK_HASHCHECK: SignDigest now validates tag = TPM_ST_HASHCHECK
    unconditionally (TPM_RC_TAG); wolfTPM2_SignDigest wrapper synthesizes
    the NULL Hashcheck instead of sending tag=0/hierarchy=0 from XMEMSET
  - NULL Verified Tickets: FwAppendTicket no longer appends metadata
    bytes when hierarchy == TPM_RH_NULL; client parser conditions
    metaAlg consumption on hierarchy != TPM_RH_NULL (Part 2 §10.6.5)

  Embedded RAM auto-shrink (v1.85):
  - New FWTPM_MAX_MLDSA_{SIG,PUB}_SIZE / FWTPM_MAX_MLKEM_{CT,PUB}_SIZE
    resolve to the largest enabled parameter set via wolfCrypt's
    WOLFSSL_NO_ML_DSA_{44,65,87} / WOLFSSL_NO_KYBER{512,768,1024} gates
  - FWTPM_MAX_DER_SIG_BUF, FWTPM_MAX_PUB_BUF, FWTPM_MAX_KEM_CT_BUF
    derive from those (no per-board override needed)
  - FWTPM_MAX_COMMAND_SIZE / FWTPM_TIS_FIFO_SIZE only lift to 8192 when
    MLDSA-65 or MLDSA-87 is enabled; MLDSA-44-only and MLKEM-only
    v1.85 builds stay at 4096
  - docs/FWTPM.md: per-build size table + override + small-stack notes

  Test coverage:
  - examples/run_examples.sh: invoke pqc/mldsa_sign and pqc/mlkem_encap
    inside the v1.85 block
  - tests/fwtpm_unit_tests.c:
    * SignDigest with malformed HASHCHECK tag rejected (TPM_RC_TAG)
    * FwAppendTicket NULL DIGEST_VERIFIED emits no metadata
    * SignSeqComplete Pure-MLDSA streaming (FIPS 204 §6) — replaces
      obsolete one-shot rejection assertion
  - tests/unit_tests.c:
    * Hash-ML-DSA SignSeqUpdate streaming end-to-end + arg validation
    * TPMT_SIGNATURE round-trip for ML-DSA / Hash-ML-DSA arms
    * TPM2B_PUBLIC round-trip for ML-DSA / Hash-ML-DSA / ML-KEM arms
2026-04-29 10:28:44 -07:00
Aidan Garske 0801a30ede fwTPM v1.85: TCG compliance fixes + PQC CI matrix
Closes 13 spec-conformance findings flagged by two TCG compliance reviews
  of the v1.85 PQC handlers. Each fix maps to a specific Part 2 / Part 3
  section; all are exercised by negative test fixtures in
  tests/fwtpm_unit_tests.c that bite-verify each fix in isolation.

  Spec-RC corrections (one-line each):
  - Drop TPMA_ML_PARAMETER_SET_extMu from TPM_PT_ML_PARAMETER_SETS — Part 2
    §12.2.3.6 (no μ-direct sign API in wolfCrypt yet).
  - Sign* handlers return TPM_RC_SCHEME (not TPM_RC_KEY) for valid keys
    with unsupported scheme — Part 3 §17.5.1 / §20.7.1.
  - SignDigest / VerifyDigestSignature return TPM_RC_ATTRIBUTES (not
    TPM_RC_EXT_MU) when key's allowExternalMu=NO — EXT_MU is reserved for
    capability errors, ATTRIBUTES for key-attribute errors.

  Validation additions:
  - SignDigest rejects restricted and x509sign keys at entry
    (TPM_RC_ATTRIBUTES, Part 3 §20.7.1).
  - VerifyDigestSignature enforces sigHashAlg == key.hashAlg
    (TPM_RC_SCHEME, Part 3 §20.4.1) and digest size == hashAlg digest size
    (TPM_RC_SIZE).
  - CreatePrimary / Create / CreateLoaded / TestParms reject MLDSA with
    allowExternalMu=YES at object-creation time (TPM_RC_EXT_MU, Part 2
    §12.2.3.6) instead of letting the request succeed and fail later.
  - TestParms validates ML-DSA / Hash-ML-DSA / ML-KEM parameterSet ranges.
  - SignSequenceComplete rejects restricted keys signing messages whose
    first 4 bytes are TPM_GENERATED_VALUE (0xFF544347) (TPM_RC_VALUE,
    Part 3 §20.6.1).
  - SignSequenceComplete rejects x509sign keys (TPM_RC_ATTRIBUTES).
  - TPM_RC_ONE_SHOT_SIGNATURE moved from SequenceUpdate to
    SignSequenceComplete (Part 3 §20.6.1: it's a Complete-time RC about
    non-empty sequence, not an Update-time RC).

  Structural fixes:
  - TPMA_OBJECT_x509sign (bit 19, Part 2 §8.3.3 v1.85) added to the enum
    in wolftpm/tpm2.h and enforced in the two sign-side handlers.
  - TPM_PT_ML_PARAMETER_SETS bits gated on wolfCrypt build symbols
    (WOLFSSL_HAVE_MLKEM / KYBER_*, WOLFSSL_WC_DILITHIUM / HAVE_DILITHIUM)
    so the capability matches what the build actually delivers.
  - wolfTPM2_EncryptSecret_MLKEM applies KDFa(SECRET, ct, pub) over the
    ML-KEM shared secret per Part 1 §47.4 Eq 66 (Labeled-KEM); previous
    code emitted raw K as the salt.
  - VerifySequenceComplete and VerifyDigestSignature emit hierarchy-bound
    TPMT_TK_VERIFIED tickets (Part 2 §10.6.5) instead of the
    TPM_RH_NULL + empty-HMAC stub.

  Tests (tests/fwtpm_unit_tests.c, 8 new + 4 updated, all under fwtpm_unit):
  - 8 new spec-bite negatives, one per finding where a single-RC test is
    meaningful. Each was bite-verified by reverting its source fix and
    confirming the test fails with a different RC.
  - 4 existing negatives updated to assert the new spec-mandated RCs and
    reshaped where the rejection point moved (SequenceUpdate → Complete).

  CI:
  - New .github/workflows/pqc-examples.yml: builds + smoke-runs the v1.85
    examples + invokes tests/check_doc_constants.sh on each PR.
  - tests/check_doc_constants.sh greps every FWTPM_* size/seed/digest
    constant from wolftpm/fwtpm/fwtpm.h and asserts each is mentioned in
    docs/FWTPM.md (catches doc drift like the v1.85
    FWTPM_MAX_COMMAND_SIZE 4096→8192 bump). docs/FWTPM.md gains 6 missing
    entries (CMD_AUTHS, SENSITIVE_SIZE, SIGN_SEQ, SYM_KEY_SIZE,
    HMAC_KEY_SIZE, HMAC_DIGEST_SIZE) so the check passes clean.
  - fuzz.yml / fwtpm-test.yml / make-test-swtpm.yml / sanitizer.yml each
    gain a v1.85 matrix entry running the same checks under
    --enable-v185 + wolfSSL --enable-dilithium --enable-mlkem
    --enable-experimental.
2026-04-29 10:28:44 -07:00
Aidan Garske 723b582438 Strip SPEC_DECISIONS.md pointers from shipped code + docs 2026-04-29 10:28:44 -07:00
Aidan Garske eeb7196547 Phase 11: Add docs for fwtpm and tpm 2026-04-29 10:27:17 -07:00
David Garske 16708f4ce2 Update keywords for firmware TPM 2026-04-28 13:24:18 -07:00
David Garske 0c52f3be4d Add firmware TPM 2.0 (fwTPM) implementation
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.
2026-04-16 16:57:57 -07:00
aidan garske d6ba3812a9 Upgrade wolfTPM CI testing 2026-02-16 11:06:33 -08:00
David Garske 971a2abfec Minor documentation fix. 2025-07-02 13:56:29 -07:00
David Garske c09418dc25 Peer review cleanups. 2025-07-02 11:11:11 -07:00
David Garske c1a59453f4 Further cleanups 2025-07-02 10:40:48 -07:00
David Garske d729de90f6 Added TCG TPM to the SWTPM documentation. Various document cleanups. 2025-07-02 10:13:40 -07:00
JacobBarthelmeh 388e32912e use XMALLOC/XFREE and update macro guards 2024-09-20 10:02:45 -07:00
Andras Fekete 10a077838a Minor naming fix 2024-08-01 22:48:21 -04:00
David Garske 6951b8d307 Fix for /dev/tpm0 file descriptor check (fixes #365). Added documentation for /dev/tpm0 permissions (fixes #358). Various spelling and documentation cleanups. 2024-07-31 11:21:53 -07:00
David Garske a441646682 Fixes for wolfTPM documentation generation. 2024-07-30 14:52:34 -07:00
David Garske f7e0e9948c Add documentation for using `ms-tpm-20-ref` TPM simulator. Move the "QEMU and swtpm" into `docs/SWTPM.md`. 2024-04-30 14:04:21 -07:00
David Garske 93441f0e59 Documentation fixes. 2024-03-18 15:38:38 -07:00
David Garske e601803f1b Added support for PK callbacks with RSA Sign using PKCSv1.5 and PSS.
Fixes for building wolfTPM without crypto callbacks.
Fixes for building/running with FIPS.
2023-12-01 08:25:53 -08:00
David Garske c05bf659c2 Fix broken paths with HAL refactor. Update TLS examples to use latest TLS version (allowing downgrade). 2023-01-20 08:29:53 -08:00
David Garske 1ea4a591a8 HAL refactor and documentation improvements. Move example HAL implementations into new `hal` directory. Include the example HAL in the library when building. Updated HAL IO documentation. 2023-01-18 12:38:04 -08:00
Anthony Hu 6433d832e6 Fix command line option. 2022-08-25 10:39:31 -04:00
David Garske 6d7937ac82 Fixes from enabling warning reporting. Moving `WOLFTPM2_HANDLE` fixed an issue with the struct not being detected. 2021-06-02 11:08:00 -07:00
David Garske 1942b3fd05 Move doxy group defs to the same header files and remove `doxygen.h`. 2021-06-02 10:20:00 -07:00
David Garske 6daac56d1a Fix for "make dox" to use the right README.md. 2021-06-02 10:20:00 -07:00
David Garske 9b6791657b Fixes to support "make dox". 2021-06-02 10:20:00 -07:00
Dimitar Tomov 52f384fe9c Script not working, use manual doxygen ./docs/Doxyfile from root
Signed-off-by: Dimitar Tomov <dimi@wolfssl.com>
2021-06-02 10:20:00 -07:00
Dimitar Tomov 9d7f3fd79d Added Doxygen documentation
* Doxygen configuration and script file under docs
* Added doxygen header to describe the different documentation modules
* Added doxygen comments about TPM2 Proprietary commands in wolfTPM
* Added doxygen comments about wolfTPM2 wrappers
* Added explanatory comments for TPM2 Standard commands and TPM2 IO examples
* Updates from peer feedback

Signed-off-by: Dimitar Tomov <dimi@wolfssl.com>
2021-06-02 10:20:00 -07:00
David Garske dc5a3d8eae wolfTPM documentation improvement efforts. Most documentation exists in the root README.md and examples/README.md, but as we now have a /docs directory this PR helps provide guidance. As time permits plan to add doxygen style inline documentation for all API's. 2021-06-02 10:20:00 -07:00
David Garske 6b769376ee Improvements to the Windows TBS documentation. Also fix for link the examples/README.md. 2021-05-06 11:08:50 -07:00
Elms c8c382b36c docs: update mingw cross-compile for windows 2021-04-20 13:26:15 -07:00
Elms fc909efefc docs: Add detail about TPM 2.0 with Windows TBS
Add limitation of TPM 1.2 and commands for retreiving TPM versions in
PowerShell
2021-02-11 10:48:50 -08:00
Elms 375eda23d8 doc: Add TLS specific build options for Windows API 2020-11-12 14:04:00 -08:00
Elms 8e00ff8daf winapi: wrap $PREFIX in " to allow spaces in paths 2020-10-13 14:17:10 -07:00
Elms 6bb14c20b6 winapi: Add readme 2020-10-13 12:04:07 -07:00
David Garske 1ba2a8800e Add section for building swtpm on Mac. 2020-09-25 11:58:03 -07:00