Commit Graph

320 Commits (master)

Author SHA1 Message Date
Aidan Garske 4354f2012a F-10826 - Validate v1.85 ML templates in TPM2_CreateLoaded 2026-08-18 12:12:07 -07:00
Aidan Garske fa57c838eb F-10825 - Validate ML public areas and key sizes in TPM2_LoadExternal 2026-08-18 11:09:48 -07:00
Aidan Garske fbbfabd02e
Merge pull request #574 from dgarske/fwtpm_finer_gating
Add finer per-command-group gating macros in fTPM
2026-08-17 13:03:37 -07:00
David Garske 20dae36517 fwTPM: add finer per-command-group gating macros 2026-08-17 12:14:10 -07:00
David Garske 2b8e41caf1 Add caller-supplied policy authorization for TPM firmware upgrade
Lets a deployment gate the TPM firmware-update start command behind its own
platform hierarchy policy instead of the vendor default. Previously wolfTPM
always managed that authorization internally: on Infineon it installed and
satisfied a PolicyCommandCode(TPM_CC_FieldUpgradeStartVendor) policy on the
platform primary policy, and on ST33 it used password authorization with an
empty platform password. Both assume default platform auth, which a hardened
deployment will not have.

New _ex entry points take an already-satisfied session:
  wolfTPM2_FirmwareUpgradeHash_ex()
  wolfTPM2_FirmwareUpgrade_ex()
  wolfTPM2_FirmwareUpgradeRecover_ex()
Passing NULL for startSession keeps the existing library-managed behavior, so
the original functions are unchanged wrappers and existing code is unaffected.
With a session supplied, Infineon no longer overwrites the platform primary
policy (the caller provisions it) and ST33 uses the session in place of
TPM_RS_PW.

Supporting wrappers:
  wolfTPM2_PolicyOR()               satisfy a session with a compound OR
  wolfTPM2_PolicyCommandCodeMake()  offline PolicyCommandCode digest
  wolfTPM2_IsAlgSupported()         report whether the TPM implements an alg
PolicyOR is hash-agnostic (each branch carries its own size), so SHA2-256
through SHA2-512 policy branches all work. It requires at least two branches
per TPM 2.0 Part 3 Sec.23.6 and validates each branch size against the digest
buffer. PolicyCommandCodeMake takes digestSz as in/out - input is the output
buffer capacity and BUFFER_E is returned when it is too small, checked before
the buffer is written. IsAlgSupported reports through an out-parameter and
returns TPM_RC, so a capability-query failure cannot be misread as
"supported"; it sets the out-parameter to 0 on every error path.

Session contract: the vendor FieldUpgradeStart commands are hand-marshalled
with an authorization area carrying only the session handle - empty
nonceCaller, zero attributes, empty HMAC. That is correct only for an
unsalted, unbound policy session with no auth value, so the _ex path validates
the caller session up front and rejects anything needing a computed session
HMAC or parameter encryption (PolicyAuthValue/PolicyPassword, attached auth
value, bind, salt, encrypt/decrypt/audit attributes, or a non-policy handle).
Validation runs before any TPM traffic. On a successful start the TPM consumes
the session and the library sets handle.hndl to TPM_RH_NULL; this is now
documented, including that it is not zero and that wolfTPM2_UnloadHandle
no-ops on it.

Examples: ifx_fw_update and st33_fw_update gain --policy, --policyor and
--policytest, backed by a shared examples/firmware/firmware_policy.c. The
--policytest mode is a non-destructive self-test that checks the TPM's running
policy digest against an offline computation at SHA2-256/384/512, skipping any
hash the TPM does not implement or the local wolfCrypt build was not compiled
with (a build mismatch is a skip, not a failure). The provisioned PolicyOR
carries a PolicyCommandCode(TPM_CC_SetPrimaryPolicy) branch so the policy can
authorize its own removal, and cleanup is gated on a FirmwarePolicyCtx that
records what was actually provisioned, so an early failure cannot clear a
policy the deployment installed itself. A failed rollback is reported but
never overwrites the upgrade error that explains the run, and is skipped once
the start has succeeded (the TPM has reset into upgrade mode and will not
service SetPrimaryPolicy).

Because TPM 2.0 offers no way to read a hierarchy authPolicy back, the example
cannot detect or restore one it replaces, so provisioning prints an explicit
warning naming that. The policy modes are also refused where the session could
never be used: any Infineon operational mode other than normal (recovery and
finalize skip the start entirely), and on ST33 when the TPM is already in
firmware-upgrade mode - previously the flags were silently ignored there,
which is the authorization downgrade they exist to prevent. Rollback normally uses platform password
authorization, which an installed authPolicy does not disable (TPM 2.0 Part 1
Sec.19.7); this was confirmed on ST33KTPM2X, SLB9670 and SLB9673 parts.

The firmware examples now require wolfCrypt in their feature guards. They
drive wolfTPM2_FirmwareUpgrade_ex, which hashes the manifest with SHA-384 and
only exists with wolfCrypt, so --enable-firmware with --disable-wolfcrypt
previously failed to compile.

Also converts examples/nvram/extend.c to the new PolicyCommandCodeMake
capacity contract.

Tests: argument validation and known-answer vectors for the new wrappers,
short-buffer and canary coverage for PolicyCommandCodeMake, caller-session
rejection for every unsupported session shape plus an accepted session,
simulator-backed success paths for PolicyOR and IsAlgSupported, and a
regression test that a platform authPolicy remains clearable with password
authorization while a non-matching policy session is refused.
2026-08-13 11:18:25 -07:00
David Garske 46d2d337a4
Merge pull request #563 from aidangarske/fenrir-fixes-7606-7610
Reuse transport connections and reduce NV write and hash cache overhead
2026-08-11 15:30:00 -07:00
David Garske c7433c1097
Merge pull request #568 from aidangarske/fenrir-9205-contextload-object-integrity
Fix v185 spec compliance authenticate object context blobs on ContextSave/Load
2026-08-10 12:56:50 -07:00
David Garske f9d8d51308
Merge pull request #567 from aidangarske/fenrir-9198-policyauthorize-metaalg
Fix v185 fwtpm compliance issues for PolicyAuthorize
2026-08-10 12:56:42 -07:00
Aidan Garske 5d3ebba350 F-9205 - Authenticate object context blobs on ContextSave/Load 2026-08-10 10:03:09 -07:00
Aidan Garske 5f5c81eda3 F-9198 - Emit checkTicket metaAlg for DIGEST_VERIFIED in PolicyAuthorize 2026-08-10 10:03:07 -07:00
Aidan Garske 10d0075d06 F-9186 - Require an auth entry for every @auth handle in SESSIONS commands 2026-08-10 10:03:04 -07:00
Aidan Garske f6b364f7b8 F-7609 - Keep swtpm TCP connection open across commands 2026-08-04 13:03:25 -07:00
Aidan Garske b7dc3ba92e F-7607 - Grow crypto callback hash cache geometrically 2026-08-04 12:15:07 -07:00
Aidan Garske 51475032c9 F-7606 - Skip redundant NV_ReadPublic in NV write chunk loop 2026-08-04 12:15:07 -07:00
David Garske fa87ed478b
Merge pull request #559 from aidangarske/mldsa-tls-cryptocb
Add TPM MLDSA authentication for post quantum TLS 1.3 with example and tests
2026-07-29 16:00:40 -07:00
Aidan Garske 6cbf2d14d7 F-7260 - Document PKCS#1 v1.5 unpadding is for public signature data only 2026-07-28 18:49:37 -07:00
Aidan Garske 4f695f3661 F-7276 - Validate classical public parameters in TestParms 2026-07-28 18:41:04 -07:00
Aidan Garske 247853b4b0 F-7272 - Honor caller response buffer capacity in FWTPM_ProcessCommand 2026-07-28 18:41:04 -07:00
Aidan Garske 43903b6f2e Fold PQC TLS into tls_client, tls_server and run_examples.sh 2026-07-28 15:27:48 -07:00
aidan garske 0063c16e7e Add TPM backed ML-DSA authentication for TLS 1.3 with PQC example and tests 2026-07-22 18:02:48 -07:00
David Garske 5a0350ff52
Merge pull request #558 from aidangarske/coverity-cid911493-fwtpm-pcr-props
Guard tainted PCR select copy in fwTPM properties Coverity test
2026-07-22 14:16:39 -07:00
David Garske b67e650bb3
Merge pull request #555 from aidangarske/fenrir-fixes-7011-7020
Bound TPM2 response decrypt-parameter size, zeroize primary-key auth, and expand marshalling/import test coverage
2026-07-22 14:15:00 -07:00
aidan garske e79d060f4d Guard tainted PCR select copy in fwTPM PCR_PROPERTIES test (Coverity CID 911493) 2026-07-22 10:57:45 -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
aidan garske 79f497becd F-7018 - Cover RSASSA/RSAPSS/HMAC signature and KEYEDHASH/SYMCIPHER public marshalling roundtrips (F-7019) 2026-07-20 11:46:06 -07:00
aidan garske 09c8af0d4c F-7017 - Cover import private-key TPM2B size guards at their boundary 2026-07-20 11:46:06 -07:00
aidan garske 493e3359c7 F-7014 - Bound decrypt-parameter size in TPM2_ResponseProcess against OOB write 2026-07-20 11:46:06 -07:00
Eric Blankenhorn 7d02b58e4c
Merge pull request #551 from aidangarske/fenrir-fixes-6839-6850
Harden crypto callback, ASN.1 parsing, param-enc and marshalling; add negative tests
2026-07-13 16:48:00 -05:00
aidan garske fac885a804 F-6847 - Drop keySz==0 ECC verify test; old wolfSSL wc_ecc_size derefs NULL dp 2026-07-13 14:26:08 -07:00
aidan garske c76dbe615f F-6847 - Cover keySz==0 fallback in ECC verify crypto callback test 2026-07-13 13:36:26 -07:00
aidan garske 5c682e167b F-6839 - Cover truncated-buffer error path in DecodeX509Cert test 2026-07-13 13:03:10 -07:00
aidan garske 14d02a32b2 F-6842 - Share TPM2_XOR_MASK_MAX via header so test matches impl 2026-07-13 12:54:21 -07:00
aidan garske 2ef42a0151 F-6840 - Use fixed pass print in DecodeTag error test 2026-07-13 12:46:16 -07:00
aidan garske ce96373632 F-6839 - Add valid-certificate happy-path test for DecodeX509Cert 2026-07-13 12:46:16 -07:00
aidan garske 45369f5d5e F-6847 - Guard ECC verify test on curve size and add oversized-S case 2026-07-13 12:46:03 -07:00
aidan garske b7241a71a2 F-6844 - Cover keyedHash/sym/mldsa/mlkem clamp arms in append test 2026-07-13 12:45:54 -07:00
aidan garske 9188fcd1aa F-6845 - Run RSA/ECC public roundtrip test in non-PQC builds 2026-07-13 12:29:16 -07:00
aidan garske 3964e7fd48 F-6844 - Clamp ECC point sizes in TPM2_Packet_AppendEccPoint 2026-07-13 12:29:08 -07:00
aidan garske 5aa84dda84 F-6841 - Exercise response nonceTPM update in HMAC verify test 2026-07-13 12:28:50 -07:00
aidan garske 212f425783 F-6841 - Add response HMAC verification test for TPM2_ResponseProcess 2026-07-13 12:00:31 -07:00
aidan garske e770f3b99a F-6845 - Add field-level roundtrip test for RSA and ECC TPMT_PUBLIC 2026-07-13 11:51:17 -07:00
aidan garske c9ec8031b9 F-6843 - Add AES-CFB param-enc key-size boundary test 2026-07-13 11:47:15 -07:00
aidan garske 2b68fa99bb F-6842 - Add XOR param-enc mask-size boundary test 2026-07-13 11:46:51 -07:00
aidan garske 378c181283 F-6844 - Clamp TPM2B sizes in TPM2_Packet_AppendPublicArea 2026-07-13 11:44:34 -07:00
aidan garske 46c906ed2a F-6840 - Report tag mismatch from TPM2_ASN_DecodeTag 2026-07-13 11:41:31 -07:00
aidan garske 71d0b3d3f1 F-6839 - Fix dead error handling in TPM2_ASN_DecodeX509Cert 2026-07-13 11:40:50 -07:00
aidan garske c63386bf93 F-6847 - Bound ECDSA verify R/S to key size in crypto callback 2026-07-13 11:27:46 -07:00
aidan garske 9b18c016a7 Bound tainted count and index in fwTPM PCR_PROPERTIES capability test (Coverity CID 911468) 2026-07-09 17:51:23 -07:00
David Garske e6a11fdac2 Fix for wolfSSL PR 10604 crypto callback ALREADY_E 2026-07-09 15:50:12 -07:00
David Garske f623ddbf1a Add fwTPM GetCapability paging and wolfTPM2_SetLocality unit tests 2026-07-09 15:50:12 -07:00
David Garske 30562ce46a Add TPM locality control (wolfTPM2_SetLocality) and fwTPM per-PCR locality enforcement
The fwTPM per-PCR reset/extend locality map follows the TCG PC Client TPM
Profile and matches the ibmswtpm2 PlatformPCR.c s_initAttributes table
byte-for-byte (hardware-confirmed on an ST33 over SPI). This replaces the
prior ad-hoc checks with a single source-of-truth table, which also changes
some access-control outcomes: PCR 20-22 are now resettable at localities 2-4
(previously locality 3-4 only), while other cases tighten (PCR 16/23 no
longer resettable at locality 4; PCR 18/19 require locality 4). The exact map
is asserted by unit tests. Downstream users relying on the prior stricter
fwTPM reset rules should note the relaxation for PCR 20-22.
2026-07-09 15:50:12 -07:00
aidan garske 732e4c8e61 6738 - Gate identity sample password on ST33/autodetect not Infineon 2026-07-08 18:03:10 -07:00
aidan garske 3d2f217c37 6743 - Assert HMAC size before comparing against fixed KAT length 2026-07-07 14:59:35 -07:00
aidan garske ea50fa571c 6746 - Drop redundant WOLFTPM2_NO_WRAPPER guard on TpmToWolf tests 2026-07-07 14:08:27 -07:00
aidan garske d91adb6415 6738 - Match SetIdentityAuth test guard to production autodetect gating 2026-07-07 13:58:40 -07:00
aidan garske a79760c3db 6746 - Use deterministic P-256 vector in short-coordinate test 2026-07-07 13:47:56 -07:00
aidan garske 67feae3d8b 6744 - Exercise crypto-callback ECDSA invalid-signature branch in test 2026-07-07 13:30:59 -07:00
aidan garske ee00c70468 6746 - Right-align short ECC coordinates in wolfTPM2_EccKey_TpmToWolf 2026-07-07 13:26:00 -07:00
aidan garske 9a56a4632d 6745 - Fix RSA exponent byte order in wolfTPM2_RsaKey_TpmToWolf 2026-07-07 13:19:17 -07:00
aidan garske c29d5ecf3a 6743 - Add CalcHmac KAT and cpHash/attributes binding checks 2026-07-07 13:16:02 -07:00
aidan garske 7b853561ae 6742 - Add KDFe known-answer vector to pin hash-input construction 2026-07-07 13:14:20 -07:00
aidan garske e41d2c91d9 6738 - Require explicit master password in wolfTPM2_SetIdentityAuth 2026-07-07 12:41:16 -07:00
aidan garske cd46447d0b 6749 - Bound ECDH response x-coordinate against caller buffer capacity 2026-07-07 12:41:03 -07:00
aidan garske 7e8aec50f1 6748 - Gate fwTPM TestParms PQC arms on WOLFTPM_MLDSA/WOLFTPM_MLKEM 2026-07-07 12:40:08 -07:00
aidan garske 3580000772 F-6554 - Bound response parameterSize against response size in TPM2_ResponseProcess 2026-06-30 12:15:36 -07:00
Aidan Garske 5506a191a2
Merge pull request #540 from dgarske/fwtpm_flash_nv_and_uart_symlink
fwTPM: append-only NV journal for write-once flash + swtpm UART symlinks
2026-06-29 12:40:45 -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
David Garske 9ddd51b06d Add parameter-encryption regression tests and PQC example coverage 2026-06-29 09:56:44 -07:00
aidan garske 720d90285a Address review: guard retry code with WOLFTPM_NO_RETRY, drop wrappers, document option 2026-06-25 15:18:25 -07:00
aidan garske 550cea93ab Add transparent TPM_RC_RETRY resubmit at command chokepoint 2026-06-25 15:18:24 -07:00
David Garske 1601a78890
Merge pull request #541 from aidangarske/fwtpm-da-hardening
fwTPM: Dictionary Attack (DA) hardening and DA/noDA test coverage
2026-06-25 15:11:51 -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
aidan garske 41a89aa5a8 Add _ex wrappers to select session, RSA OAEP and PQC template hash algorithms 2026-06-24 11:15:38 -07:00
aidan garske ac87e6bb7a F-6318 - Create readKeyBlob test files with owner-only permissions 2026-06-22 13:03:13 -07:00
aidan garske 68f4084830 F-6312 - Cover ECC, KEYEDHASH, SYMCIPHER arms in AppendSensitive clamp test 2026-06-22 12:38:24 -07:00
aidan garske 9e7769a08a F-6318 - Return BUFFER_E on short private read in readKeyBlob 2026-06-22 12:37:54 -07:00
aidan garske b5be21d275 F-6314 - Add maximum-size TPM2B sensitive roundtrip test 2026-06-22 12:04:42 -07:00
aidan garske 05f6cb7fd0 F-6317 - Add testable SPDM I/O response-size validation helper 2026-06-22 12:02:29 -07:00
aidan garske 02bc64173a F-6316 - Add testable TIS response-size validation helper 2026-06-22 12:00:04 -07:00
aidan garske af8fe5b72b F-6313 - Clear publicArea when ParsePublic reads zero size 2026-06-22 11:56:46 -07:00
aidan garske 98a5f95fff F-6312 - Clamp classic-arm inner size in TPM2_Packet_AppendSensitive 2026-06-22 11:55:03 -07:00
aidan garske 7e060e1915 F-6315 - Add testable swtpm response-size validation helper 2026-06-22 11:37:35 -07:00
aidan garske c6b2104f3f F-6318 - Validate priv size marker before read in readKeyBlob 2026-06-22 11:28:56 -07:00
David Garske 85757e94a2
Merge pull request #527 from aidangarske/pqc-granular-macros
Fine-grained PQC (v1.85) build macros: trim ML-DSA/ML-KEM by algorithm and operation
2026-06-16 15:11:54 -07:00
aidan garske 8512df5bf7 fwTPM: always set continueSession in password authorization response (issue #529) 2026-06-16 13:50:46 -07:00
aidan garske ad08b88d6e Add fine-grained PQC build macros to trim v1.85 ML-DSA/ML-KEM by algorithm and operation 2026-06-15 15:49:34 -07:00
David Garske ba6563edac
Merge pull request #520 from aidangarske/pqc-tpm-fixes
Fix PQC minor leak, capability-gate tests, add negative examples, add PQC benchmarks
2026-06-09 15:13:08 -07:00
David Garske 5b8e46f77b
Merge pull request #523 from aidangarske/fenrir-fixes-15
Harden Testing and fwTPM/src
2026-06-09 15:11:55 -07:00
aidan garske 0ed88b3753 tests: add HashFinish undersized-buffer regression test 2026-06-09 12:29:31 -07:00
David Garske 01301c40d0 Fix ecc-default-curve-p384 CI: P256-sized buffer overflow + scope to make check
test_wolfTPM2_LoadEccPublicKey_Ex harvested SRK X/Y coordinates into
byte[32] buffers and reloaded them hardcoding TPM_ECC_NIST_P256. Under
-DWOLFTPM2_ECC_DEFAULT_CURVE=TPM_ECC_NIST_P384 the SRK is P384, so the
48-byte coordinates overflowed the 32-byte stack buffers (FORTIFY abort,
the failing CI job). Size the buffers to MAX_ECC_KEY_BYTES and reload
using the SRK's actual curve/nameAlg so the test is curve-agnostic.

Scope the ecc-default-curve-p384 job to 'make check': unit.test exercises
the SRK/AIK -> P384/SHA384 upgrade and explicit-curve/ECDHE honoring
end-to-end. run_examples.sh is omitted because several demos (pcr/quote,
boot/secure_rot, native_test) hardcode SHA256 for the ECC sign/quote
scheme - a demo limitation, not a library issue.
2026-06-09 11:09:06 -07:00
David Garske 4590e79e14 Improve testing for WOLFTPM2_ECC_DEFAULT_CURVE 2026-06-09 10:43:27 -07:00
Aidan Garske 557aae6d03 wolfTPM v1.85 PQC: leak fix, capability-gated tests, negative examples, benchmark 2026-06-08 23:08:27 +01:00
David Garske 6c11045492 Add new WOLFTPM2_ECC_DEFAULT_CURVE 2026-06-05 12:44:48 -07:00
aidan garske 5699061b53 fwtpm: scope context replay to sessions and accept unsalted param-enc 2026-06-03 10:57:13 -07:00
aidan garske 57f49c79f8 F-4673 - Track live context sequences for any-order single-use load 2026-06-03 10:37:09 -07:00
aidan garske 5453e6ff26 F-5654 F-5719 F-5277 F-5122 F-4845 F-4955 - Harden fwTPM fixes per review 2026-06-03 10:37:08 -07:00
aidan garske 34930558e3 F-5648 F-5649 - Add HMAC verify truncation and compute buffer-size tests 2026-06-03 10:37:08 -07:00
aidan garske 5617f43aae F-5277 F-5122 - Store and enforce policy cpHashA command binding 2026-06-03 10:36:32 -07:00
aidan garske 77f502279e F-5105 F-5106 F-5107 - Require signing key for attestation commands 2026-06-03 10:36:32 -07:00
aidan garske 6c9a64efd7 F-5102 F-5119 F-5833 - Authenticate NV journal with integrity MAC 2026-06-03 10:36:32 -07:00