mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
fix(esp_tee): Snapshot input arguments in TEE memory before secure service execution
- Also fix the `tee_cli_app` build failure due to TEE heap size overflow
This commit is contained in:
@@ -334,11 +334,12 @@ esp_err_t esp_ds_start_sign(const void *message,
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (!(data->rsa_length == ESP_DS_RSA_1024
|
||||
|| data->rsa_length == ESP_DS_RSA_2048
|
||||
|| data->rsa_length == ESP_DS_RSA_3072
|
||||
const uint32_t rsa_length = data->rsa_length;
|
||||
if (!(rsa_length == ESP_DS_RSA_1024
|
||||
|| rsa_length == ESP_DS_RSA_2048
|
||||
|| rsa_length == ESP_DS_RSA_3072
|
||||
#if SOC_RSA_MAX_BIT_LEN == 4096
|
||||
|| data->rsa_length == ESP_DS_RSA_4096
|
||||
|| rsa_length == ESP_DS_RSA_4096
|
||||
#endif
|
||||
)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@@ -393,7 +394,7 @@ esp_err_t esp_ds_start_sign(const void *message,
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
size_t rsa_len = (data->rsa_length + 1) * 4;
|
||||
size_t rsa_len = (rsa_length + 1) * 4;
|
||||
ds_hal_write_private_key_params(data->c);
|
||||
ds_hal_configure_iv((uint32_t *)data->iv);
|
||||
ds_hal_write_message(message, rsa_len);
|
||||
@@ -426,22 +427,31 @@ esp_err_t esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx)
|
||||
}
|
||||
|
||||
const esp_ds_data_t *data = (const esp_ds_data_t *)esp_ds_ctx->data;
|
||||
unsigned rsa_len = (data->rsa_length + 1) * 4;
|
||||
esp_err_t return_value = ESP_ERR_INVALID_ARG;
|
||||
|
||||
while (ds_hal_busy()) { }
|
||||
|
||||
ds_signature_check_t sig_check_result = ds_hal_read_result((uint8_t *) signature, (size_t) rsa_len);
|
||||
uint32_t rsa_length = data->rsa_length;
|
||||
if (rsa_length == ESP_DS_RSA_1024
|
||||
|| rsa_length == ESP_DS_RSA_2048
|
||||
|| rsa_length == ESP_DS_RSA_3072
|
||||
#if SOC_DS_SIGNATURE_MAX_BIT_LEN == 4096
|
||||
|| rsa_length == ESP_DS_RSA_4096
|
||||
#endif
|
||||
) {
|
||||
unsigned rsa_len = (rsa_length + 1) * 4;
|
||||
|
||||
esp_err_t return_value = ESP_OK;
|
||||
ds_signature_check_t res = ds_hal_read_result((uint8_t *) signature, (size_t) rsa_len);
|
||||
|
||||
if (sig_check_result == DS_SIGNATURE_MD_FAIL || sig_check_result == DS_SIGNATURE_PADDING_AND_MD_FAIL) {
|
||||
esp_ds_zeroize(signature, rsa_len);
|
||||
return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST;
|
||||
}
|
||||
|
||||
if (sig_check_result == DS_SIGNATURE_PADDING_FAIL) {
|
||||
esp_ds_zeroize(signature, rsa_len);
|
||||
return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING;
|
||||
if (res == DS_SIGNATURE_MD_FAIL || res == DS_SIGNATURE_PADDING_AND_MD_FAIL) {
|
||||
esp_ds_zeroize(signature, rsa_len);
|
||||
return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_DIGEST;
|
||||
} else if (res == DS_SIGNATURE_PADDING_FAIL) {
|
||||
esp_ds_zeroize(signature, rsa_len);
|
||||
return_value = ESP_ERR_HW_CRYPTO_DS_INVALID_PADDING;
|
||||
} else if (res == DS_SIGNATURE_OK) {
|
||||
return_value = ESP_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#if !ESP_TEE_BUILD
|
||||
|
||||
Reference in New Issue
Block a user