Skip to content

Commit 565b239

Browse files
authored
Merge pull request #502 from dgarske/caps_fips140-3
2 parents 0ae18dc + 3bd3f0a commit 565b239

8 files changed

Lines changed: 69 additions & 11 deletions

File tree

examples/wrap/caps.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ int TPM2_Wrapper_CapsArgs(void* userCtx, int argc, char *argv[])
115115
if (rc != 0) goto exit;
116116

117117
printf("Mfg %s (%d), Vendor %s, Fw %u.%u (0x%x), "
118-
"FIPS 140-2 %d, CC-EAL4 %d\n",
118+
"FIPS %s, CC-EAL4 %d\n",
119119
caps.mfgStr, caps.mfg, caps.vendorStr, caps.fwVerMajor,
120-
caps.fwVerMinor, caps.fwVerVendor, caps.fips140_2, caps.cc_eal4);
120+
caps.fwVerMinor, caps.fwVerVendor,
121+
TPM2_GetCapsFipsStr(caps.fips140_3, caps.fips140_2),
122+
caps.cc_eal4);
121123
#if defined(WOLFTPM_SLB9672) || defined(WOLFTPM_SLB9673)
122124
printf("\tKeyGroupId 0x%x, Operational Mode 0x%x, FwCounter %d (%d same)\n",
123125
caps.keyGroupId, caps.opMode, caps.fwCounter, caps.fwCounterSame);

examples/wrap/wrap_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ int TPM2_Wrapper_TestArgs(void* userCtx, int argc, char *argv[])
191191
if (rc != 0) goto exit;
192192

193193
printf("Mfg %s (%d), Vendor %s, Fw %u.%u (0x%x), "
194-
"FIPS 140-2 %d, CC-EAL4 %d\n",
194+
"FIPS %s, CC-EAL4 %d\n",
195195
caps.mfgStr, caps.mfg, caps.vendorStr, caps.fwVerMajor,
196-
caps.fwVerMinor, caps.fwVerVendor, caps.fips140_2, caps.cc_eal4);
196+
caps.fwVerMinor, caps.fwVerVendor,
197+
TPM2_GetCapsFipsStr(caps.fips140_3, caps.fips140_2),
198+
caps.cc_eal4);
197199
#if defined(WOLFTPM_SLB9672) || defined(WOLFTPM_SLB9673)
198200
printf("\tKeyGroupId 0x%x, Operational Mode 0x%x, FwCounter %d (%d same)\n",
199201
caps.keyGroupId, caps.opMode, caps.fwCounter, caps.fwCounterSame);

src/fwtpm/fwtpm_command.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,23 @@ static TPM_RC FwCmd_GetCapability(FWTPM_CTX* ctx, TPM2_Packet* cmd,
10971097
{ TPM_PT_MAX_DIGEST, TPM_SHA256_DIGEST_SIZE },
10981098
#endif
10991099
{ TPM_PT_TOTAL_COMMANDS, 0 }, /* patched to FwGetCmdCount() at emission */
1100-
{ TPM_PT_MODES, 0 },
1100+
/* TPMA_MODES (TPM_PT_MODES): bit 0 = FIPS_140_2 (spec
1101+
* v1.38+), bit 1 = FIPS_140_3 (spec v1.83+). Mirror the
1102+
* underlying wolfCrypt module's FIPS status so callers
1103+
* (tpm2-tools, examples/wrap/caps) see the same level
1104+
* the crypto provider is validated at. wolfCrypt FIPS
1105+
* v6.x targets 140-3; earlier HAVE_FIPS revisions are
1106+
* 140-2. Non-FIPS builds leave both bits clear. */
1107+
{ TPM_PT_MODES,
1108+
#if defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
1109+
(HAVE_FIPS_VERSION >= 6)
1110+
TPMA_MODES_FIPS_140_3
1111+
#elif defined(HAVE_FIPS)
1112+
TPMA_MODES_FIPS_140_2
1113+
#else
1114+
0
1115+
#endif
1116+
},
11011117
#ifdef WOLFTPM_V185
11021118
/* v1.85 Part 2 Sec.8.13 TPMA_ML_PARAMETER_SET: bits 0-5 for
11031119
* MLKEM-512/768/1024 and MLDSA-44/65/87. Each bit is gated

src/tpm2_util.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,12 @@ void TPM2_PrintAuth(const TPMS_AUTH_COMMAND* authCmd)
194194
TPM2_PrintBin(authCmd->hmac.buffer, authCmd->hmac.size);
195195
}
196196
#endif /* DEBUG_WOLFTPM */
197+
198+
const char* TPM2_GetCapsFipsStr(int fips140_3, int fips140_2)
199+
{
200+
if (fips140_3)
201+
return "140-3";
202+
if (fips140_2)
203+
return "140-2";
204+
return "none";
205+
}

src/tpm2_wrap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ int wolfTPM2_SelfTest(WOLFTPM2_DEV* dev)
792792
* Byte 1: reserved.
793793
* Bytes 2-3: build num = 11CB,
794794
* Byte 4: 0x00 (TPM CC), 0x02 (no CC)
795-
* TPM_PT_MODES = Bit 0 = FIPS_140_2
795+
* TPM_PT_MODES = Bit 0 = FIPS_140_2 (spec v1.38+)
796+
* Bit 1 = FIPS_140_3 (spec v1.83+)
796797
*/
797798

798799
#if defined(WOLFTPM_SLB9672) || defined(WOLFTPM_SLB9673)
@@ -874,7 +875,8 @@ static int wolfTPM2_ParseCapabilities(WOLFTPM2_CAPS* caps,
874875
}
875876
break;
876877
case TPM_PT_MODES:
877-
caps->fips140_2 = (val & 0x00000001) ? 1: 0;
878+
caps->fips140_2 = (val & TPMA_MODES_FIPS_140_2) ? 1 : 0;
879+
caps->fips140_3 = (val & TPMA_MODES_FIPS_140_3) ? 1 : 0;
878880
break;
879881
default:
880882
break;

tests/unit_tests.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,11 @@ static void test_wolfTPM2_GetCapabilities(void)
206206
AssertIntEQ(rc, 0);
207207

208208
#ifdef DEBUG_WOLFTPM
209-
printf("Mfg %s (%d), Vendor %s, Fw %u.%u (%u), FIPS 140-2 %d, CC-EAL4 %d\n",
209+
printf("Mfg %s (%d), Vendor %s, Fw %u.%u (%u), FIPS %s, CC-EAL4 %d\n",
210210
caps.mfgStr, caps.mfg, caps.vendorStr, caps.fwVerMajor,
211-
caps.fwVerMinor, caps.fwVerVendor, caps.fips140_2, caps.cc_eal4);
211+
caps.fwVerMinor, caps.fwVerVendor,
212+
TPM2_GetCapsFipsStr(caps.fips140_3, caps.fips140_2),
213+
caps.cc_eal4);
212214
#endif
213215

214216
wolfTPM2_Cleanup(&dev);

wolftpm/tpm2.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,20 @@ enum TPMA_CC_mask {
933933
TPMA_CC_V = 0x20000000,
934934
};
935935

936+
/* TPM 2.0 Library Spec Part 2: bitfield returned from
937+
* TPM2_GetCapability(TPM_CAP_TPM_PROPERTIES, TPM_PT_MODES)
938+
* indicating FIPS compliance level. Bit 0 (FIPS_140_2) is defined
939+
* since v1.38; bit 1 (FIPS_140_3) was added in v1.83. Bits 2..31
940+
* are reserved. Decoded unconditionally so any host build can
941+
* interpret either flag from any TPM. */
942+
typedef UINT32 TPMA_MODES;
943+
enum TPMA_MODES_mask {
944+
TPMA_MODES_FIPS_140_2 = 0x00000001,
945+
TPMA_MODES_FIPS_140_3 = 0x00000002,
946+
};
947+
936948
#ifdef WOLFTPM_V185
937-
/* v185 rc4 Part 2 Sec.8.13 Table 46 bitfield returned from
949+
/* v185 rc4 Part 2 Sec.8.13 Table 46 - bitfield returned from
938950
* TPM2_GetCapability(TPM_CAP_TPM_PROPERTIES, TPM_PT_ML_PARAMETER_SETS)
939951
* indicating which ML-KEM/ML-DSA parameter sets the TPM supports. */
940952
typedef UINT32 TPMA_ML_PARAMETER_SET;
@@ -4329,6 +4341,18 @@ typedef enum {
43294341
WOLFTPM_API UINT16 TPM2_GetVendorID(void);
43304342

43314343

4344+
/*!
4345+
\brief Returns a human-readable FIPS mode string from FIPS capability
4346+
bits: "140-3" when fips140_3 is set, "140-2" when fips140_2 is set,
4347+
otherwise "none". Used for capability reporting in examples and
4348+
tools.
4349+
\return Non-NULL pointer to a static string. Never NULL.
4350+
\param fips140_3 non-zero if the TPM reports FIPS 140-3 mode
4351+
\param fips140_2 non-zero if the TPM reports FIPS 140-2 mode
4352+
*/
4353+
WOLFTPM_API const char* TPM2_GetCapsFipsStr(int fips140_3, int fips140_2);
4354+
4355+
43324356
/*!
43334357
\ingroup TPM2_Proprietary
43344358
\brief Forcefully zero a memory region. Unlike memset, this call is not

wolftpm/tpm2_wrap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ typedef struct WOLFTPM2_CAPS {
167167
#endif
168168

169169
/* bits */
170-
word16 fips140_2 : 1; /* using FIPS mode */
170+
word16 fips140_2 : 1; /* FIPS 140-2 mode (TPMA_MODES bit 0) */
171171
word16 cc_eal4 : 1; /* Common Criteria EAL4+ */
172172
word16 req_wait_state : 1; /* requires SPI wait state */
173+
word16 fips140_3 : 1; /* FIPS 140-3 mode (TPMA_MODES bit 1, spec v1.83+) */
173174
#ifdef WOLFTPM_SPDM
174175
word32 acHandleCount; /* Number of AC handles discovered */
175176
TPM_HANDLE acHandles[MAX_AC_HANDLES]; /* AC handles */

0 commit comments

Comments
 (0)