Skip to content

Commit d116567

Browse files
committed
refactor(esp_tee): Update TEE secure storage interface APIs
1 parent c9f7bcd commit d116567

File tree

18 files changed

+442
-571
lines changed

18 files changed

+442
-571
lines changed

components/esp_tee/Kconfig.projbuild

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@ menu "ESP-TEE (Trusted Execution Environment)"
7272
config SECURE_TEE_SEC_STG_MODE_DEVELOPMENT
7373
bool "Development"
7474
help
75-
Secure storage will be encrypted by the data stored in eFuse BLK2
75+
Secure storage will be encrypted by a constant key embedded in the TEE firmware
7676

7777
config SECURE_TEE_SEC_STG_MODE_RELEASE
7878
depends on IDF_TARGET_ESP32C6
7979
bool "Release"
8080
help
8181
Secure storage will be encrypted by the data stored in eFuse block
82-
configured through the SECURE_TEE_SEC_STG_KEY_EFUSE_BLK option
82+
configured through the SECURE_TEE_SEC_STG_EFUSE_HMAC_KEY_ID option
8383

8484
endchoice
8585

86-
config SECURE_TEE_SEC_STG_KEY_EFUSE_BLK
87-
int "Secure Storage: Encryption key eFuse block"
86+
config SECURE_TEE_SEC_STG_EFUSE_HMAC_KEY_ID
87+
int "Secure Storage: eFuse HMAC key ID"
8888
depends on SECURE_TEE_SEC_STG_MODE_RELEASE
89-
range 4 10
90-
default 10
89+
range -1 5
90+
default -1
9191
help
92-
eFuse block ID storing the TEE secure storage encryption key
92+
eFuse block key ID storing the HMAC key for deriving the TEE secure storage encryption keys
9393

9494
config SECURE_TEE_SEC_STG_SUPPORT_SECP192R1_SIGN
9595
bool "Secure Storage: Support signing with the ECDSA SECP192R1 curve"
@@ -104,13 +104,12 @@ menu "ESP-TEE (Trusted Execution Environment)"
104104
This configuration enables the support for the Attestation service.
105105

106106

107-
config SECURE_TEE_ATT_KEY_SLOT_ID
107+
config SECURE_TEE_ATT_KEY_STR_ID
108108
depends on SECURE_TEE_ATTESTATION
109-
int "Attestation: Secure Storage slot ID for EAT signing"
110-
default 0
111-
range 0 14
109+
string "Attestation: Secure Storage key ID for EAT signing"
110+
default "tee_att_key0"
112111
help
113-
This configuration sets the slot ID from the TEE secure storage
112+
This configuration sets the key ID from the TEE secure storage
114113
storing the ECDSA keypair for executing sign/verify operations
115114
from the TEE side for attestation.
116115

components/esp_tee/scripts/esp32c6/sec_srv_tbl_default.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,36 +252,28 @@ secure_services:
252252
entries:
253253
- id: 175
254254
type: custom
255-
function: esp_tee_sec_storage_init
256-
args: 0
255+
function: esp_tee_sec_storage_clear_key
256+
args: 1
257257
- id: 176
258258
type: custom
259259
function: esp_tee_sec_storage_gen_key
260-
args: 2
260+
args: 1
261261
- id: 177
262262
type: custom
263-
function: esp_tee_sec_storage_get_signature
264-
args: 5
263+
function: esp_tee_sec_storage_ecdsa_sign
264+
args: 4
265265
- id: 178
266266
type: custom
267-
function: esp_tee_sec_storage_get_pubkey
268-
args: 3
267+
function: esp_tee_sec_storage_ecdsa_get_pubkey
268+
args: 2
269269
- id: 179
270270
type: custom
271-
function: esp_tee_sec_storage_encrypt
272-
args: 8
271+
function: esp_tee_sec_storage_aead_encrypt
272+
args: 4
273273
- id: 180
274274
type: custom
275-
function: esp_tee_sec_storage_decrypt
276-
args: 8
277-
- id: 181
278-
type: custom
279-
function: esp_tee_sec_storage_is_slot_empty
280-
args: 1
281-
- id: 182
282-
type: custom
283-
function: esp_tee_sec_storage_clear_slot
284-
args: 1
275+
function: esp_tee_sec_storage_aead_decrypt
276+
args: 4
285277
# ID: 195-199 (5) - OTA
286278
- family: ota
287279
entries:

components/esp_tee/subproject/components/attestation/esp_att_utils_crypto.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -41,26 +41,23 @@ static esp_err_t gen_ecdsa_keypair_secp256r1(esp_att_ecdsa_keypair_t *keypair)
4141
if (keypair == NULL) {
4242
return ESP_ERR_INVALID_ARG;
4343
}
44-
4544
memset(keypair, 0x00, sizeof(esp_att_ecdsa_keypair_t));
4645

47-
uint16_t slot_id = ESP_ATT_TK_KEY_ID;
48-
esp_tee_sec_storage_pubkey_t pubkey = {0};
46+
esp_tee_sec_storage_key_cfg_t key_cfg = {
47+
.id = (const char *)(ESP_ATT_TK_KEY_ID),
48+
.type = ESP_SEC_STG_KEY_ECDSA_SECP256R1,
49+
};
4950

50-
esp_err_t err = esp_tee_sec_storage_init();
51-
if (err != ESP_OK) {
51+
esp_err_t err = esp_tee_sec_storage_gen_key(&key_cfg);
52+
if (err == ESP_ERR_INVALID_STATE) {
53+
ESP_LOGW(TAG, "Using pre-existing key...");
54+
} else if (err != ESP_OK) {
55+
ESP_LOGE(TAG, "Failed to generate ECDSA keypair (%d)", err);
5256
return err;
5357
}
5458

55-
if (esp_tee_sec_storage_is_slot_empty(slot_id)) {
56-
err = esp_tee_sec_storage_gen_key(slot_id, ESP_SEC_STG_KEY_ECDSA_SECP256R1);
57-
if (err != ESP_OK) {
58-
ESP_LOGE(TAG, "Failed to generate ECDSA keypair (%d)", err);
59-
return err;
60-
}
61-
}
62-
63-
err = esp_tee_sec_storage_get_pubkey(slot_id, ESP_SEC_STG_KEY_ECDSA_SECP256R1, &pubkey);
59+
esp_tee_sec_storage_ecdsa_pubkey_t pubkey = {};
60+
err = esp_tee_sec_storage_ecdsa_get_pubkey(&key_cfg, &pubkey);
6461
if (err != ESP_OK) {
6562
ESP_LOGE(TAG, "Failed to fetch ECDSA pubkey (%d)", err);
6663
return err;
@@ -83,8 +80,13 @@ static esp_err_t get_ecdsa_sign_secp256r1(const esp_att_ecdsa_keypair_t *keypair
8380
return ESP_ERR_INVALID_SIZE;
8481
}
8582

86-
esp_tee_sec_storage_sign_t sign = {};
87-
esp_err_t err = esp_tee_sec_storage_get_signature(ESP_ATT_TK_KEY_ID, ESP_SEC_STG_KEY_ECDSA_SECP256R1, (uint8_t *)digest, len, &sign);
83+
esp_tee_sec_storage_key_cfg_t key_cfg = {
84+
.id = (const char *)(ESP_ATT_TK_KEY_ID),
85+
.type = ESP_SEC_STG_KEY_ECDSA_SECP256R1,
86+
};
87+
88+
esp_tee_sec_storage_ecdsa_sign_t sign = {};
89+
esp_err_t err = esp_tee_sec_storage_ecdsa_sign(&key_cfg, (uint8_t *)digest, len, &sign);
8890
if (err != ESP_OK) {
8991
return err;
9092
}

components/esp_tee/subproject/components/attestation/esp_att_utils_json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ esp_err_t esp_att_utils_header_to_json(const esp_att_token_hdr_t *tk_hdr, char *
126126
json_gen_obj_set_string(&json_gen, "encr_alg", NULL);
127127
json_gen_obj_set_string(&json_gen, "sign_alg", ESP_ATT_TK_SIGN_ALG);
128128

129-
json_gen_obj_set_int(&json_gen, "key_id", ESP_ATT_TK_KEY_ID);
129+
json_gen_obj_set_string(&json_gen, "key_id", ESP_ATT_TK_KEY_ID);
130130

131131
// End the top-level JSON object
132132
json_gen_end_object(&json_gen);

components/esp_tee/subproject/components/attestation/private_include/esp_attestation_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ extern "C" {
4242
#define ESP_ATT_TK_MIN_SIZE (ESP_ATT_HDR_JSON_MAX_SZ + ESP_ATT_EAT_JSON_MAX_SZ + ESP_ATT_PUBKEY_JSON_MAX_SZ + ESP_ATT_SIGN_JSON_MAX_SZ)
4343

4444
#if ESP_TEE_BUILD && CONFIG_SECURE_TEE_ATTESTATION
45-
#define ESP_ATT_TK_KEY_ID (CONFIG_SECURE_TEE_ATT_KEY_SLOT_ID)
45+
#define ESP_ATT_TK_KEY_ID (CONFIG_SECURE_TEE_ATT_KEY_STR_ID)
4646
#else
47-
#define ESP_ATT_TK_KEY_ID (-1)
47+
#define ESP_ATT_TK_KEY_ID ("NULL")
4848
#endif
4949

5050
/**

components/esp_tee/subproject/components/tee_sec_storage/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(priv_requires efuse mbedtls spi_flash)
55

66
if(esp_tee_build)
77
list(APPEND srcs "tee_sec_storage.c")
8-
list(APPEND priv_requires log tee_flash_mgr)
8+
list(APPEND priv_requires esp_partition log nvs_flash tee_flash_mgr)
99
else()
1010
list(APPEND srcs "tee_sec_storage_wrapper.c")
1111
set(priv_requires esp_tee)

0 commit comments

Comments
 (0)