@@ -44,15 +44,15 @@ int wolfSPDM_Init(WOLFSPDM_CTX* ctx)
4444 if (rc != 0 ) {
4545 return WOLFSPDM_E_CRYPTO_FAIL ;
4646 }
47- ctx -> rngInitialized = 1 ;
47+ ctx -> flags . rngInitialized = 1 ;
4848
4949 /* Set default requester capabilities */
5050 ctx -> reqCaps = WOLFSPDM_DEFAULT_REQ_CAPS ;
5151
5252 /* Set default session ID (0x0001 is valid; 0x0000/0xFFFF are reserved) */
5353 ctx -> reqSessionId = 0x0001 ;
5454
55- ctx -> initialized = 1 ;
55+ ctx -> flags . initialized = 1 ;
5656 /* isDynamic remains 0 — only wolfSPDM_New sets it */
5757
5858 return WOLFSPDM_SUCCESS ;
@@ -73,7 +73,7 @@ WOLFSPDM_CTX* wolfSPDM_New(void)
7373 XFREE (ctx , NULL , DYNAMIC_TYPE_TMP_BUFFER );
7474 return NULL ;
7575 }
76- ctx -> isDynamic = 1 ; /* Tag AFTER Init so it isn't wiped */
76+ ctx -> flags . isDynamic = 1 ; /* Tag AFTER Init so it isn't wiped */
7777
7878 return ctx ;
7979}
@@ -87,29 +87,29 @@ void wolfSPDM_Free(WOLFSPDM_CTX* ctx)
8787
8888#ifdef WOLFSPDM_DYNAMIC_MEMORY
8989 {
90- int wasDynamic = ctx -> isDynamic ;
90+ int wasDynamic = ctx -> flags . isDynamic ;
9191#endif
9292
9393 /* Free RNG */
94- if (ctx -> rngInitialized ) {
94+ if (ctx -> flags . rngInitialized ) {
9595 wc_FreeRng (& ctx -> rng );
9696 }
9797
9898 /* Free ephemeral key */
99- if (ctx -> ephemeralKeyInitialized ) {
99+ if (ctx -> flags . ephemeralKeyInit ) {
100100 wc_ecc_free (& ctx -> ephemeralKey );
101101 }
102102
103103 /* Free responder public key (used for measurement/challenge verification) */
104- if (ctx -> hasResponderPubKey ) {
104+ if (ctx -> flags . hasResponderPubKey ) {
105105 wc_ecc_free (& ctx -> responderPubKey );
106106 }
107107
108108#ifndef NO_WOLFSPDM_CHALLENGE
109109 /* Free M1/M2 challenge hash if still initialized */
110- if (ctx -> m1m2HashInit ) {
110+ if (ctx -> flags . m1m2HashInit ) {
111111 wc_Sha384Free (& ctx -> m1m2Hash );
112- ctx -> m1m2HashInit = 0 ;
112+ ctx -> flags . m1m2HashInit = 0 ;
113113 }
114114#endif
115115
@@ -169,7 +169,7 @@ int wolfSPDM_SetResponderPubKey(WOLFSPDM_CTX* ctx,
169169
170170 XMEMCPY (ctx -> rspPubKey , pubKey , pubKeySz );
171171 ctx -> rspPubKeyLen = pubKeySz ;
172- ctx -> hasRspPubKey = 1 ;
172+ ctx -> flags . hasRspPubKey = 1 ;
173173
174174 return WOLFSPDM_SUCCESS ;
175175}
@@ -191,7 +191,7 @@ int wolfSPDM_SetRequesterKeyPair(WOLFSPDM_CTX* ctx,
191191 ctx -> reqPrivKeyLen = privKeySz ;
192192 XMEMCPY (ctx -> reqPubKey , pubKey , pubKeySz );
193193 ctx -> reqPubKeyLen = pubKeySz ;
194- ctx -> hasReqKeyPair = 1 ;
194+ ctx -> flags . hasReqKeyPair = 1 ;
195195
196196 return WOLFSPDM_SUCCESS ;
197197}
@@ -225,15 +225,15 @@ int wolfSPDM_SetTrustedCAs(WOLFSPDM_CTX* ctx, const byte* derCerts,
225225
226226 XMEMCPY (ctx -> trustedCAs , derCerts , derCertsSz );
227227 ctx -> trustedCAsSz = derCertsSz ;
228- ctx -> hasTrustedCAs = 1 ;
228+ ctx -> flags . hasTrustedCAs = 1 ;
229229
230230 return WOLFSPDM_SUCCESS ;
231231}
232232
233233void wolfSPDM_SetDebug (WOLFSPDM_CTX * ctx , int enable )
234234{
235235 if (ctx != NULL ) {
236- ctx -> debug = enable ;
236+ ctx -> flags . debug = enable ;
237237 }
238238}
239239
@@ -334,11 +334,11 @@ static int wolfSPDM_ConnectStandard(WOLFSPDM_CTX* ctx)
334334 wolfSPDM_GetCertificate (ctx , 0 ));
335335
336336 /* Validate certificate chain if trusted CAs are loaded */
337- if (ctx -> hasTrustedCAs ) {
337+ if (ctx -> flags . hasTrustedCAs ) {
338338 SPDM_CONNECT_STEP (ctx , "Validating certificate chain\n" ,
339339 wolfSPDM_ValidateCertChain (ctx ));
340340 }
341- else if (!ctx -> hasResponderPubKey ) {
341+ else if (!ctx -> flags . hasResponderPubKey ) {
342342 wolfSPDM_DebugPrint (ctx ,
343343 "Warning: No trusted CAs loaded — chain not validated\n" );
344344 }
@@ -361,7 +361,7 @@ int wolfSPDM_Connect(WOLFSPDM_CTX* ctx)
361361 return WOLFSPDM_E_INVALID_ARG ;
362362 }
363363
364- if (!ctx -> initialized ) {
364+ if (!ctx -> flags . initialized ) {
365365 return WOLFSPDM_E_BAD_STATE ;
366366 }
367367
@@ -453,11 +453,8 @@ int wolfSPDM_SendReceive(WOLFSPDM_CTX* ctx,
453453 if (totalSz > sizeof (tcgTx )) {
454454 return WOLFSPDM_E_BUFFER_SMALL ;
455455 }
456- SPDM_Set16BE (tcgTx , WOLFSPDM_TCG_TAG_SECURED );
457- SPDM_Set32BE (tcgTx + 2 , totalSz );
458- SPDM_Set32BE (tcgTx + 6 , ctx -> connectionHandle );
459- SPDM_Set16BE (tcgTx + 10 , ctx -> fipsIndicator );
460- XMEMSET (tcgTx + 12 , 0 , 4 ); /* Reserved */
456+ wolfSPDM_WriteTcgHeader (tcgTx , WOLFSPDM_TCG_TAG_SECURED ,
457+ totalSz , ctx -> connectionHandle , ctx -> fipsIndicator );
461458 XMEMCPY (tcgTx + WOLFSPDM_TCG_HEADER_SIZE , txBuf , txSz );
462459 tcgTxSz = (int )totalSz ;
463460 }
@@ -538,7 +535,7 @@ void wolfSPDM_DebugPrint(WOLFSPDM_CTX* ctx, const char* fmt, ...)
538535{
539536 va_list args ;
540537
541- if (ctx == NULL || !ctx -> debug ) {
538+ if (ctx == NULL || !ctx -> flags . debug ) {
542539 return ;
543540 }
544541
@@ -554,7 +551,7 @@ void wolfSPDM_DebugHex(WOLFSPDM_CTX* ctx, const char* label,
554551{
555552 word32 i ;
556553
557- if (ctx == NULL || !ctx -> debug || data == NULL ) {
554+ if (ctx == NULL || !ctx -> flags . debug || data == NULL ) {
558555 return ;
559556 }
560557
@@ -575,7 +572,7 @@ void wolfSPDM_DebugHex(WOLFSPDM_CTX* ctx, const char* label,
575572
576573int wolfSPDM_GetMeasurementCount (WOLFSPDM_CTX * ctx )
577574{
578- if (ctx == NULL || !ctx -> hasMeasurements ) {
575+ if (ctx == NULL || !ctx -> flags . hasMeasurements ) {
579576 return 0 ;
580577 }
581578 return (int )ctx -> measBlockCount ;
@@ -586,7 +583,7 @@ int wolfSPDM_GetMeasurementBlock(WOLFSPDM_CTX* ctx, int blockIdx,
586583{
587584 const WOLFSPDM_MEAS_BLOCK * blk ;
588585
589- if (ctx == NULL || !ctx -> hasMeasurements ) {
586+ if (ctx == NULL || !ctx -> flags . hasMeasurements ) {
590587 return WOLFSPDM_E_INVALID_ARG ;
591588 }
592589 if (blockIdx < 0 || blockIdx >= (int )ctx -> measBlockCount ) {
0 commit comments