Skip to content

Commit d8bd783

Browse files
ying-cssankk-css
andauthored
Fixed the issues for p_local_crypt not being cleared properly for Infineon HSM OPTIGA Trust M (#34152) (#34188)
* Fixes the issues for p_local_crypt not being cleared. * 1)Bug fixing for ECDSA Verify Functions 2)Deleted redundant check * Apply restyled changes. --------- Co-authored-by: Ank Khandelwal <ank.khandelwal@infineon.com> Co-authored-by: Ank Khandelwal <108660995+ankk-css@users.noreply.github.com>
1 parent 7726d3b commit d8bd783

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/platform/Infineon/crypto/trustm/CHIPCryptoPALHsm_P256_trustm.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,16 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
252252

253253
return_status = trustm_ecdh_derive_secret(OPTIGA_KEY_ID_E100, (uint8_t *) remote_key, (uint16_t) rem_pubKeyLen + 3,
254254
out_secret.Bytes(), (uint8_t) secret_length);
255-
256255
VerifyOrExit(return_status == OPTIGA_LIB_SUCCESS, error = CHIP_ERROR_INTERNAL);
256+
out_secret.SetLength(secret_length);
257+
error = CHIP_NO_ERROR;
257258

258259
exit:
259260
if (error != CHIP_NO_ERROR)
260261
{
261262
trustm_close();
262263
}
263-
return out_secret.SetLength(secret_length);
264+
return error;
264265
#endif
265266
}
266267

@@ -295,7 +296,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_hash_signature(const uint8_t * hash, si
295296
(uint8_t *) bytes, (uint8_t) kP256_PublicKey_Length);
296297

297298
VerifyOrExit(return_status == OPTIGA_LIB_SUCCESS, error = CHIP_ERROR_INTERNAL);
298-
299+
error = CHIP_NO_ERROR;
299300
exit:
300301
if (error != CHIP_NO_ERROR)
301302
{
@@ -407,7 +408,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, size
407408
(uint8_t *) bytes, (uint8_t) kP256_PublicKey_Length);
408409

409410
VerifyOrExit(return_status == OPTIGA_LIB_SUCCESS, error = CHIP_ERROR_INTERNAL);
410-
411+
error = CHIP_NO_ERROR;
411412
exit:
412413
if (error != CHIP_NO_ERROR)
413414
{

src/platform/Infineon/crypto/trustm/CHIPCryptoPALHsm_utils_trustm.cpp

+20-18
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ optiga_lib_status_t deriveKey_HKDF(const uint8_t * salt, uint16_t salt_length, c
426426
break;
427427
}
428428

429-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
429+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
430430
;
431+
431432
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
432433
{
433434
// optiga_crypt_hkdf failed
@@ -539,8 +540,9 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
539540
break;
540541
}
541542

542-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
543+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
543544
;
545+
544546
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
545547
{
546548
// optiga_crypt_hkdf failed
@@ -578,8 +580,9 @@ optiga_lib_status_t optiga_crypt_rng(uint8_t * random_data, uint16_t random_data
578580
break;
579581
}
580582

581-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
583+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
582584
;
585+
583586
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
584587
{
585588
// optiga_crypt_random failed
@@ -626,7 +629,7 @@ optiga_lib_status_t trustm_ecc_keygen(uint16_t optiga_key_id, uint8_t key_type,
626629
break;
627630
}
628631

629-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
632+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
630633
;
631634

632635
} while (0);
@@ -696,8 +699,10 @@ optiga_lib_status_t trustm_hash(uint8_t * msg, uint16_t msg_length, uint8_t * di
696699
optiga_lib_print_message("optiga_crypt_hash api returns error !!!", OPTIGA_UTIL_SERVICE, OPTIGA_UTIL_SERVICE_COLOR);
697700
break;
698701
}
699-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
702+
703+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
700704
;
705+
701706
} while (0);
702707

703708
if (p_local_crypt)
@@ -729,7 +734,8 @@ optiga_lib_status_t trustm_ecdsa_sign(optiga_key_id_t optiga_key_id, uint8_t * d
729734
OPTIGA_UTIL_SERVICE_COLOR);
730735
break;
731736
}
732-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
737+
738+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
733739
;
734740

735741
for (i = (*signature_length - 1); i >= 0; i--)
@@ -803,8 +809,10 @@ optiga_lib_status_t trustm_ecdsa_verify(uint8_t * digest, uint8_t digest_length,
803809
OPTIGA_UTIL_SERVICE_COLOR);
804810
break;
805811
}
806-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
812+
813+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
807814
;
815+
808816
} while (0);
809817

810818
if (p_local_crypt)
@@ -852,14 +860,6 @@ CHIP_ERROR trustmGetCertificate(uint16_t optiga_oid, uint8_t * buf, uint16_t * b
852860

853861
memcpy(buf, ifx_cert_hex, ifx_cert_hex_len);
854862
*buflen = ifx_cert_hex_len;
855-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
856-
;
857-
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
858-
{
859-
// optiga_util_read_data failed
860-
optiga_lib_print_message("optiga_util_read_data failed", OPTIGA_UTIL_SERVICE, OPTIGA_UTIL_SERVICE_COLOR);
861-
break;
862-
}
863863
} while (0);
864864

865865
if (p_local_util)
@@ -896,8 +896,10 @@ optiga_lib_status_t trustm_ecdh_derive_secret(optiga_key_id_t optiga_key_id, uin
896896
optiga_lib_print_message("optiga_crypt_ecdh api returns error !!!", OPTIGA_UTIL_SERVICE, OPTIGA_UTIL_SERVICE_COLOR);
897897
break;
898898
}
899-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
899+
900+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
900901
;
902+
901903
} while (0);
902904

903905
if (p_local_crypt)
@@ -957,7 +959,7 @@ optiga_lib_status_t trustm_PBKDF2_HMAC(const unsigned char * salt, size_t slen,
957959
}
958960
}
959961

960-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
962+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
961963
;
962964

963965
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
@@ -978,4 +980,4 @@ optiga_lib_status_t trustm_PBKDF2_HMAC(const unsigned char * salt, size_t slen,
978980
optiga_crypt_destroy(p_local_crypt);
979981
}
980982
return return_status;
981-
}
983+
}

0 commit comments

Comments
 (0)