102102 #error "wolfTPM and MAXQ10XX are incompatible with each other."
103103#endif
104104
105- /* wc_ForceZero was added in wolfSSL 5.8.4. Provide a fallback for older
106- * versions to securely zero sensitive memory. */
107- #if defined(LIBWOLFSSL_VERSION_HEX ) && LIBWOLFSSL_VERSION_HEX >= 0x05008004
108- #include <wolfssl/wolfcrypt/memory.h>
109- #else
110- static void wc_ForceZero (void * mem , size_t len ) {
111- volatile byte * p = (volatile byte * )mem ;
112- while (len -- ) * p ++ = 0 ;
113- }
114- #endif
115-
116105/* Helper to get size of struct field */
117106#define FIELD_SIZE (type , field ) (sizeof(((type *)0)->field))
118107
@@ -2056,10 +2045,10 @@ static int wp11_storage_read_word32(void* storage, word32* val)
20562045 ret = wp11_storage_read (storage , num , sizeof (num ));
20572046 if (ret == 0 ) {
20582047 /* Convert to 32-bit value. */
2059- * val = ((int )num [0 ] << 24 ) |
2060- ((int )num [1 ] << 16 ) |
2061- ((int )num [2 ] << 8 ) |
2062- ((int )num [3 ] << 0 );
2048+ * val = ((word32 )num [0 ] << 24 ) |
2049+ ((word32 )num [1 ] << 16 ) |
2050+ ((word32 )num [2 ] << 8 ) |
2051+ ((word32 )num [3 ] << 0 );
20632052 }
20642053
20652054 return ret ;
@@ -3630,7 +3619,7 @@ static int wp11_Object_Decode_RsaKey(WP11_Object* object)
36303619 if (ret == 0 ) {
36313620 /* Decode RSA private key. */
36323621 ret = wc_RsaPrivateKeyDecode (der , & idx , key , len );
3633- XMEMSET (der , 0 , len );
3622+ wc_ForceZero (der , len );
36343623 }
36353624 if (der != NULL )
36363625 XFREE (der , NULL , DYNAMIC_TYPE_TMP_BUFFER );
@@ -3846,8 +3835,10 @@ int WP11_Rsa_SerializeKeyPTPKC8(WP11_Object* object, byte* output, word32* pouts
38463835 ret = 0 ;
38473836
38483837end_func :
3849- if (NULL != der )
3838+ if (NULL != der ) {
3839+ wc_ForceZero (der , dersz );
38503840 XFREE (der , NULL , DYNAMIC_TYPE_TMP_BUFFER );
3841+ }
38513842
38523843 return ret ;
38533844}
@@ -3979,7 +3970,7 @@ static int wp11_Object_Decode_EccKey(WP11_Object* object)
39793970 if (ret == 0 ) {
39803971 /* Decode ECC private key. */
39813972 ret = wc_EccPrivateKeyDecode (der , & idx , key , len );
3982- XMEMSET (der , 0 , len );
3973+ wc_ForceZero (der , len );
39833974 }
39843975 if (der != NULL )
39853976 XFREE (der , NULL , DYNAMIC_TYPE_TMP_BUFFER );
@@ -5343,7 +5334,7 @@ static int wp11_Object_Encode(WP11_Object* object, int protect)
53435334 case CKK_DH :
53445335 ret = wp11_Object_Encode_DhKey (object );
53455336 if (protect && ret == 0 && object -> objClass == CKO_PRIVATE_KEY ) {
5346- XMEMSET (object -> data .dhKey -> key , 0 , object -> data .dhKey -> len );
5337+ wc_ForceZero (object -> data .dhKey -> key , object -> data .dhKey -> len );
53475338 object -> encoded = 1 ;
53485339 }
53495340 break ;
@@ -5354,7 +5345,7 @@ static int wp11_Object_Encode(WP11_Object* object, int protect)
53545345 case CKK_GENERIC_SECRET :
53555346 ret = wp11_Object_Encode_SymmKey (object );
53565347 if (protect && ret == 0 ) {
5357- XMEMSET (object -> data .symmKey -> data , 0 , object -> data .symmKey -> len );
5348+ wc_ForceZero (object -> data .symmKey -> data , object -> data .symmKey -> len );
53585349 object -> encoded = 1 ;
53595350 }
53605351 break ;
@@ -8476,7 +8467,8 @@ static int ecc_lookup_curve(const byte* oid, word32 len)
84768467
84778468 for (curve = DefinedCurves ; curve -> curve_id < ECC_CURVE_MAX ; curve ++ )
84788469 {
8479- if (XMEMCMP (oid , curve -> curve_oid , MIN (len , curve -> curve_size )) == 0 ) {
8470+ if (len == curve -> curve_size &&
8471+ XMEMCMP (oid , curve -> curve_oid , len ) == 0 ) {
84808472 return curve -> curve_id ;
84818473 }
84828474 }
0 commit comments