Skip to content

Harden fwTPM key derivation and command validation - #596

Draft
aidangarske wants to merge 8 commits into
wolfSSL:masterfrom
aidangarske:fwtpm-fixes-12728
Draft

Harden fwTPM key derivation and command validation#596
aidangarske wants to merge 8 commits into
wolfSSL:masterfrom
aidangarske:fwtpm-fixes-12728

Conversation

@aidangarske

Copy link
Copy Markdown
Member
F-12728, F-11915, F-12711, F-12737, F-13450, F-13451, F-13462, F-13537

@aidangarske aidangarske self-assigned this Sep 9, 2026
Copilot AI lite review requested due to automatic review settings September 9, 2026 00:53

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

The new RNG parameters are used without defined NULL-handling in hardened ECC paths and the public header prototype changes are API-breaking without an explicit compatibility/versioning plan.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens fwTPM cryptographic operations and command validation paths, primarily by adding RNG-backed blinding to ECC operations and tightening command behavior around PCR capability reporting, hierarchy selection, and physical presence.

Changes:

  • Plumbs WC_RNG* into ECC primary key derivation and ECC shared-point computation to enable RNG-backed timing/blinding hardening where supported.
  • Improves safety/robustness in crypto helpers (OOM handling in FwComputePublicName, guarded sensitive marshaling in FwWrapPrivate, and safer RSA CRT cleanup on init failures).
  • Tightens command behavior (PCR bank capability output reflects allocated banks; invalid hierarchy selectors return TPM_RC_VALUE vs TPM_RC_HIERARCHY; platform PP latch disabled unless explicitly opted-in).
File summaries
File Description
wolftpm/fwtpm/fwtpm_crypto.h Updates public prototypes to accept WC_RNG* for ECC derivation/shared-point routines.
src/fwtpm/fwtpm_crypto.c Implements RNG-backed ECC hardening and improves error/cleanup handling in several crypto helpers.
src/fwtpm/fwtpm_command.c Updates PCR capability response generation, refines hierarchy-handle validation, and gates platform PP latch behind an opt-in macro.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/fwtpm/fwtpm_crypto.c
Comment on lines 751 to 755
#ifdef ECC_TIMING_RESISTANT
rc = wc_ecc_make_pub_ex(eccKey, NULL, NULL);
rc = wc_ecc_make_pub_ex(eccKey, NULL, rng);
#else
(void)rng;
rc = wc_ecc_make_pub(eccKey, NULL);
Comment thread src/fwtpm/fwtpm_crypto.c
Comment on lines +3637 to +3646
#ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
/* RNG-blinded scalar multiply bound to the curve order */
rc = wc_ecc_mulmod_ex2(ecc_get_k(priv), &peer->pubkey, R, &a,
&prime, &order, rng, 1, NULL);
#else
/* wc_ecc_mulmod_ex2 is public only with WOLFSSL_PUBLIC_ECC_ADD_DBL;
* fall back to the base multiply when it is unavailable */
(void)rng;
rc = wc_ecc_mulmod(ecc_get_k(priv), &peer->pubkey, R, &a, &prime, 1);
#endif
Comment on lines 127 to 130
TPM_RC FwDeriveEccPrimaryKey(TPMI_ALG_HASH nameAlg,
const byte* seed, const byte* hashUnique, int hashUniqueSz,
UINT16 curveId, TPMS_ECC_POINT* pubOut,
UINT16 curveId, WC_RNG* rng, TPMS_ECC_POINT* pubOut,
byte* privKeyDer, int privKeyDerBufSz, int* privKeyDerSz);
Comment on lines 333 to 337
int FwImportEccKeyFromDer(const FWTPM_Object* obj, ecc_key* key);
int FwImportEccPubFromPublic(const TPMT_PUBLIC* pub, ecc_key* key);
int FwImportEccKey(const FWTPM_Object* obj, ecc_key* key);
int FwEccSharedPoint(ecc_key* priv, ecc_key* peer,
int FwEccSharedPoint(ecc_key* priv, ecc_key* peer, WC_RNG* rng,
byte* xBuf, word32* xSz, byte* yBuf, word32* ySz);
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