Skip to content

Commit b0cdc82

Browse files
fix(ecdsa): Fixed ECDSA efuse purpose check condition
1 parent 28c4172 commit b0cdc82

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

components/mbedtls/port/ecdsa/ecdsa_alt.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,20 @@ static int esp_ecdsa_validate_efuse_block(mbedtls_ecp_group_id grp_id, int efuse
182182
expected_key_purpose_low = ESP_EFUSE_KEY_PURPOSE_ECDSA_KEY;
183183
#endif /* !SOC_ECDSA_SUPPORT_CURVE_SPECIFIC_KEY_PURPOSES */
184184

185-
if (expected_key_purpose_low != esp_efuse_get_key_purpose((esp_efuse_block_t)low_blk)
186-
#if SOC_ECDSA_SUPPORT_CURVE_SPECIFIC_KEY_PURPOSES && SOC_ECDSA_SUPPORT_CURVE_P384
187-
|| expected_key_purpose_high != esp_efuse_get_key_purpose((esp_efuse_block_t)high_blk)
188-
#endif
189-
) {
185+
if (expected_key_purpose_low != esp_efuse_get_key_purpose((esp_efuse_block_t)low_blk)) {
190186
ESP_LOGE(TAG, "Key burned in efuse has incorrect purpose");
191187
return MBEDTLS_ERR_ECP_INVALID_KEY;
192188
}
193189

190+
#if SOC_ECDSA_SUPPORT_CURVE_SPECIFIC_KEY_PURPOSES && SOC_ECDSA_SUPPORT_CURVE_P384
191+
// Only check high block purpose for P384 curves that actually use it
192+
if (grp_id == MBEDTLS_ECP_DP_SECP384R1 &&
193+
expected_key_purpose_high != esp_efuse_get_key_purpose((esp_efuse_block_t)high_blk)) {
194+
ESP_LOGE(TAG, "Key burned in efuse has incorrect purpose for high block");
195+
return MBEDTLS_ERR_ECP_INVALID_KEY;
196+
}
197+
#endif
198+
194199
return 0;
195200
}
196201
#endif /* SOC_ECDSA_SUPPORT_EXPORT_PUBKEY || CONFIG_MBEDTLS_HARDWARE_ECDSA_SIGN */

0 commit comments

Comments
 (0)