@@ -5457,9 +5457,13 @@ static TPM_RC FwCmd_RSA_Encrypt(FWTPM_CTX* ctx, TPM2_Packet* cmd,
54575457 }
54585458 else if (encScheme == TPM_ALG_NULL ) {
54595459 /* Raw RSA (no padding) */
5460+ #ifdef WC_RSA_NO_PADDING
54605461 outSz = wc_RsaPublicEncrypt_ex (message .buffer , message .size ,
54615462 outBuf , (word32 )FWTPM_MAX_PUB_BUF , rsaKey , & ctx -> rng ,
54625463 WC_RSA_NO_PAD , WC_HASH_TYPE_NONE , 0 , NULL , 0 );
5464+ #else
5465+ rc = TPM_RC_SCHEME ;
5466+ #endif
54635467 }
54645468 else {
54655469 /* RSAES PKCS1 v1.5 */
@@ -5602,9 +5606,13 @@ static TPM_RC FwCmd_RSA_Decrypt(FWTPM_CTX* ctx, TPM2_Packet* cmd,
56025606 }
56035607 else if (decScheme == TPM_ALG_NULL ) {
56045608 /* Raw RSA (no padding) */
5609+ #ifdef WC_RSA_NO_PADDING
56055610 outSz = wc_RsaPrivateDecrypt_ex (cipherText .buffer , cipherText .size ,
56065611 outBuf , (word32 )FWTPM_MAX_PUB_BUF , rsaKey ,
56075612 WC_RSA_NO_PAD , WC_HASH_TYPE_NONE , 0 , NULL , 0 );
5613+ #else
5614+ rc = TPM_RC_SCHEME ;
5615+ #endif
56085616 }
56095617 else {
56105618 /* RSAES PKCS1 v1.5 */
@@ -10964,7 +10972,10 @@ static TPM_RC FwCmd_MakeCredential(FWTPM_CTX* ctx, TPM2_Packet* cmd,
1096410972 XMEMCPY (oaepLabel , "IDENTITY" , 8 );
1096510973 oaepLabelSz = 8 ;
1096610974 oaepLabel [oaepLabelSz ++ ] = 0x00 ;
10967- if (objectName .size + oaepLabelSz <= (int )sizeof (oaepLabel )) {
10975+ if (objectName .size + oaepLabelSz > (int )sizeof (oaepLabel )) {
10976+ rc = TPM_RC_SIZE ;
10977+ }
10978+ else {
1096810979 XMEMCPY (oaepLabel + oaepLabelSz , objectName .name ,
1096910980 objectName .size );
1097010981 oaepLabelSz += objectName .size ;
@@ -11016,14 +11027,20 @@ static TPM_RC FwCmd_MakeCredential(FWTPM_CTX* ctx, TPM2_Packet* cmd,
1101611027 TPM2_Packet_AppendBytes (rsp , encCred , (int )encCredSz );
1101711028 /* patch blob size */
1101811029 blobSz = rsp -> pos - blobStart ;
11019- savedPos = rsp -> pos ;
11020- rsp -> pos = blobSzPos ;
11021- TPM2_Packet_AppendU16 (rsp , (UINT16 )blobSz );
11022- rsp -> pos = savedPos ;
11023- /* secret = TPM2B_ENCRYPTED_SECRET */
11024- TPM2_Packet_AppendU16 (rsp , (UINT16 )encSeedSz );
11025- TPM2_Packet_AppendBytes (rsp , encSeed , encSeedSz );
11026- FwRspParamsEnd (rsp , cmdTag , paramSzPos , paramStart );
11030+ if (blobSz < 0 || blobSz > 0xFFFF ||
11031+ encSeedSz < 0 || encSeedSz > 0xFFFF ) {
11032+ rc = TPM_RC_SIZE ;
11033+ }
11034+ if (rc == 0 ) {
11035+ savedPos = rsp -> pos ;
11036+ rsp -> pos = blobSzPos ;
11037+ TPM2_Packet_AppendU16 (rsp , (UINT16 )blobSz );
11038+ rsp -> pos = savedPos ;
11039+ /* secret = TPM2B_ENCRYPTED_SECRET */
11040+ TPM2_Packet_AppendU16 (rsp , (UINT16 )encSeedSz );
11041+ TPM2_Packet_AppendBytes (rsp , encSeed , encSeedSz );
11042+ FwRspParamsEnd (rsp , cmdTag , paramSzPos , paramStart );
11043+ }
1102711044 }
1102811045
1102911046 TPM2_ForceZero (seed , sizeof (seed ));
@@ -11151,7 +11168,10 @@ static TPM_RC FwCmd_ActivateCredential(FWTPM_CTX* ctx, TPM2_Packet* cmd,
1115111168 XMEMCPY (oaepLabel , "IDENTITY" , 8 );
1115211169 oaepLabelSz = 8 ;
1115311170 oaepLabel [oaepLabelSz ++ ] = 0x00 ;
11154- if (objName -> size + oaepLabelSz <= (int )sizeof (oaepLabel )) {
11171+ if (objName -> size + oaepLabelSz > (int )sizeof (oaepLabel )) {
11172+ rc = TPM_RC_SIZE ;
11173+ }
11174+ else {
1115511175 XMEMCPY (oaepLabel + oaepLabelSz , objName -> name , objName -> size );
1115611176 oaepLabelSz += objName -> size ;
1115711177 }
@@ -12293,6 +12313,10 @@ int FWTPM_ProcessCommand(FWTPM_CTX* ctx,
1229312313 int rspParamEnd ;
1229412314#endif
1229512315 int j ;
12316+ int rngRc ;
12317+ byte rpHash [TPM_MAX_DIGEST_SIZE ];
12318+ int rpHashSz = 0 ;
12319+ TPMI_ALG_HASH rpHashAlg = TPM_ALG_SHA256 ;
1229612320
1229712321 /* Read parameterSize from response buffer */
1229812322 if (rspHandleEnd + 4 <= rspPkt .pos ) {
@@ -12314,9 +12338,14 @@ int FWTPM_ProcessCommand(FWTPM_CTX* ctx,
1231412338 FWTPM_Session * sess = cmdAuths [j ].sess ;
1231512339 int digestSz = TPM2_GetHashDigestSize (sess -> authHash );
1231612340 if (digestSz > 0 ) {
12317- sess -> nonceTPM .size = digestSz ;
12318- wc_RNG_GenerateBlock (& ctx -> rng , sess -> nonceTPM .buffer ,
12319- digestSz );
12341+ rngRc = wc_RNG_GenerateBlock (& ctx -> rng ,
12342+ sess -> nonceTPM .buffer , digestSz );
12343+ if (rngRc == 0 ) {
12344+ sess -> nonceTPM .size = digestSz ;
12345+ }
12346+ else {
12347+ sess -> nonceTPM .size = 0 ;
12348+ }
1232012349 }
1232112350 }
1232212351 }
@@ -12340,8 +12369,6 @@ int FWTPM_ProcessCommand(FWTPM_CTX* ctx,
1234012369#endif /* !FWTPM_NO_PARAM_ENC */
1234112370
1234212371 /* Compute rpHash on (possibly encrypted) response parameters */
12343- byte rpHash [TPM_MAX_DIGEST_SIZE ];
12344- int rpHashSz = 0 ;
1234512372 {
1234612373 const byte * rpBytes = NULL ;
1234712374 int rpBytesSz = 0 ;
@@ -12350,7 +12377,6 @@ int FWTPM_ProcessCommand(FWTPM_CTX* ctx,
1235012377 rpBytesSz = (int )rspParamSzVal ;
1235112378 }
1235212379 /* Use first session's hashAlg for rpHash (or SHA-256 default) */
12353- TPMI_ALG_HASH rpHashAlg = TPM_ALG_SHA256 ;
1235412380 for (j = 0 ; j < cmdAuthCnt ; j ++ ) {
1235512381 if (cmdAuths [j ].sess != NULL ) {
1235612382 rpHashAlg = cmdAuths [j ].sess -> authHash ;
0 commit comments