mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-01 18:50:34 +03:00
feat(esp_tee): Protect the HMAC and DS peripherals from REE access
This commit is contained in:
@@ -11,9 +11,13 @@
|
||||
|
||||
#include "hal/sha_types.h"
|
||||
#include "hal/sha_hal.h"
|
||||
#include "rom/digital_signature.h"
|
||||
#include "hal/mmu_types.h"
|
||||
#include "hal/wdt_hal.h"
|
||||
#include "hal/spi_flash_types.h"
|
||||
#include "esp_hmac.h"
|
||||
#include "esp_ds.h"
|
||||
#include "esp_crypto_lock.h"
|
||||
#include "esp_flash.h"
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
@@ -97,7 +101,10 @@ int __wrap_esp_aes_crypt_cbc(esp_aes_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
return esp_tee_service_call(7, SS_ESP_AES_CRYPT_CBC, ctx, mode, length, iv, input, output);
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(7, SS_ESP_AES_CRYPT_CBC, ctx, mode, length, iv, input, output);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
int __wrap_esp_aes_crypt_cfb128(esp_aes_context *ctx,
|
||||
@@ -108,8 +115,11 @@ int __wrap_esp_aes_crypt_cfb128(esp_aes_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
return esp_tee_service_call(8, SS_ESP_AES_CRYPT_CFB128, (uint32_t)ctx,
|
||||
mode, length, iv_off, iv, (uint32_t)input, (uint32_t)output);
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(8, SS_ESP_AES_CRYPT_CFB128, (uint32_t)ctx,
|
||||
mode, length, iv_off, iv, (uint32_t)input, (uint32_t)output);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
int __wrap_esp_aes_crypt_cfb8(esp_aes_context *ctx,
|
||||
@@ -119,8 +129,11 @@ int __wrap_esp_aes_crypt_cfb8(esp_aes_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
return esp_tee_service_call(7, SS_ESP_AES_CRYPT_CFB8, ctx,
|
||||
mode, length, iv, input, output);
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(7, SS_ESP_AES_CRYPT_CFB8, ctx,
|
||||
mode, length, iv, input, output);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
int __wrap_esp_aes_crypt_ctr(esp_aes_context *ctx,
|
||||
@@ -131,7 +144,10 @@ int __wrap_esp_aes_crypt_ctr(esp_aes_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
return esp_tee_service_call(8, SS_ESP_AES_CRYPT_CTR, ctx, length, nc_off, nonce_counter, stream_block, input, output);
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(8, SS_ESP_AES_CRYPT_CTR, ctx, length, nc_off, nonce_counter, stream_block, input, output);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
int __wrap_esp_aes_crypt_ecb(esp_aes_context *ctx,
|
||||
@@ -139,9 +155,12 @@ int __wrap_esp_aes_crypt_ecb(esp_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16])
|
||||
{
|
||||
return esp_tee_service_call(5, SS_ESP_AES_CRYPT_ECB,
|
||||
(uint32_t)ctx, (uint32_t)mode,
|
||||
(uint32_t)input, (uint32_t)output);
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(5, SS_ESP_AES_CRYPT_ECB,
|
||||
(uint32_t)ctx, (uint32_t)mode,
|
||||
(uint32_t)input, (uint32_t)output);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
int __wrap_esp_aes_crypt_ofb(esp_aes_context *ctx,
|
||||
@@ -151,8 +170,11 @@ int __wrap_esp_aes_crypt_ofb(esp_aes_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output)
|
||||
{
|
||||
return esp_tee_service_call(7, SS_ESP_AES_CRYPT_OFB, (uint32_t)ctx, length,
|
||||
iv_off, iv, (uint32_t)input, (uint32_t)output);
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(7, SS_ESP_AES_CRYPT_OFB, (uint32_t)ctx, length,
|
||||
iv_off, iv, (uint32_t)input, (uint32_t)output);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- SHA ------------------------------------------------- */
|
||||
@@ -233,6 +255,93 @@ void __wrap_esp_crypto_sha_enable_periph_clk(bool enable)
|
||||
esp_tee_service_call(2, SS_ESP_CRYPTO_SHA_ENABLE_PERIPH_CLK, enable);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- HMAC ------------------------------------------------- */
|
||||
|
||||
esp_err_t __wrap_esp_hmac_calculate(hmac_key_id_t key_id, const void *message, size_t message_len, uint8_t *hmac)
|
||||
{
|
||||
esp_crypto_hmac_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(5, SS_ESP_HMAC_CALCULATE, key_id, message, message_len, hmac);
|
||||
esp_crypto_hmac_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t __wrap_esp_hmac_jtag_enable(hmac_key_id_t key_id, const uint8_t *token)
|
||||
{
|
||||
esp_crypto_hmac_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(3, SS_ESP_HMAC_JTAG_ENABLE, key_id, token);
|
||||
esp_crypto_hmac_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t __wrap_esp_hmac_jtag_disable(void)
|
||||
{
|
||||
esp_crypto_hmac_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(1, SS_ESP_HMAC_JTAG_DISABLE);
|
||||
esp_crypto_hmac_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- DS ------------------------------------------------- */
|
||||
|
||||
esp_err_t __wrap_esp_ds_sign(const void *message,
|
||||
const esp_ds_data_t *data,
|
||||
hmac_key_id_t key_id,
|
||||
void *signature)
|
||||
{
|
||||
esp_crypto_ds_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(5, SS_ESP_DS_SIGN, message, data, key_id, signature);
|
||||
esp_crypto_ds_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t __wrap_esp_ds_start_sign(const void *message,
|
||||
const esp_ds_data_t *data,
|
||||
hmac_key_id_t key_id,
|
||||
esp_ds_context_t **esp_ds_ctx)
|
||||
{
|
||||
esp_crypto_ds_lock_acquire();
|
||||
if (esp_ds_ctx != NULL) {
|
||||
*esp_ds_ctx = malloc(sizeof(esp_ds_context_t));
|
||||
if (!*esp_ds_ctx) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
}
|
||||
return esp_tee_service_call(5, SS_ESP_DS_START_SIGN, message, data, key_id, esp_ds_ctx);
|
||||
}
|
||||
|
||||
bool __wrap_esp_ds_is_busy(void)
|
||||
{
|
||||
return esp_tee_service_call(1, SS_ESP_DS_IS_BUSY);
|
||||
}
|
||||
|
||||
esp_err_t __wrap_esp_ds_finish_sign(void *signature, esp_ds_context_t *esp_ds_ctx)
|
||||
{
|
||||
esp_err_t err = esp_tee_service_call(3, SS_ESP_DS_FINISH_SIGN, signature, esp_ds_ctx);
|
||||
if (err != ESP_ERR_INVALID_ARG) {
|
||||
free(esp_ds_ctx);
|
||||
}
|
||||
esp_crypto_ds_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t __wrap_esp_ds_encrypt_params(esp_ds_data_t *data,
|
||||
const void *iv,
|
||||
const esp_ds_p_data_t *p_data,
|
||||
const void *key)
|
||||
{
|
||||
esp_crypto_sha_aes_lock_acquire();
|
||||
esp_err_t err = esp_tee_service_call(5, SS_ESP_DS_ENCRYPT_PARAMS, data, iv, p_data, key);
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- MPI ------------------------------------------------- */
|
||||
|
||||
void __wrap_esp_crypto_mpi_enable_periph_clk(bool enable)
|
||||
{
|
||||
esp_tee_service_call(2, SS_ESP_CRYPTO_MPI_ENABLE_PERIPH_CLK, enable);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- MMU HAL ------------------------------------------------- */
|
||||
|
||||
void IRAM_ATTR __wrap_mmu_hal_map_region(uint32_t mmu_id, mmu_target_t mem_type, uint32_t vaddr, uint32_t paddr, uint32_t len, uint32_t *out_len)
|
||||
|
||||
Reference in New Issue
Block a user