Skip to content

Commit c16fc04

Browse files
committed
docs(esp_tee): Revise TEE secure storage and related documentation
1 parent 033397b commit c16fc04

File tree

12 files changed

+84
-121
lines changed

12 files changed

+84
-121
lines changed

components/esp_tee/test_apps/tee_cli_app/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@ This example can be executed on any development board with a Espressif SOC chip
1515

1616
- Open the project configuration menu (`idf.py menuconfig`).
1717

18-
- Configure the secure storage slot ID for generating/fetching the ECDSA keypair for attestation token signing at `(Top) → Security featuresTEE: Secure Storage slot ID for EAT signing`. If this configuration is not set, the slot with ID **0** will be used as default.
18+
- Configure the secure storage key ID for generating/fetching the ECDSA keypair for attestation token signing at `ESP-TEE (Trusted Execution Environment) → Secure ServicesAttestation: Secure Storage key ID for EAT signing`.
1919

20-
- Configure the Secure Storage mode for determining which eFuse block stores the encryption key at `(Top) → Security features → Trusted Execution Environment → TEE: Secure Storage Mode`.
21-
- **Development** Mode: The encryption key is statically embedded in the TEE firmware.
22-
- **Release** Mode: The encryption key is stored in eFuse BLK4 - BLK9, depending on the `SECURE_TEE_SEC_STG_KEY_EFUSE_BLK` Kconfig option.
23-
- Set the eFuse block ID to store the encryption key in `Security features → Trusted Execution Environment → TEE: Secure Storage encryption key eFuse block`.
20+
Configure the Secure Storage mode for determining how the NVS XTS encryption keys are derived at `ESP-TEE (Trusted Execution Environment) → Secure Services → Secure Storage: Mode`
21+
22+
- **Development** Mode: Encryption keys are embedded in the ESP-TEE firmware (identical across all instances).
23+
- **Release** Mode: Encryption keys are derived via the HMAC peripheral using a key stored in eFuse.
24+
- Set the eFuse key ID storing the HMAC key at `ESP-TEE (Trusted Execution Environment) → Secure Services → Secure Storage: eFuse HMAC key ID`.
2425
- Snippet for burning the secure storage key in eFuse is given below.
2526

2627
```shell
27-
# Programming user key (256-bit) in eFuse
28+
# Generate a random 32-byte HMAC key
29+
openssl rand -out hmac_key_file.bin 32
30+
# Programming the HMAC key (256-bit) in eFuse
2831
# Here, BLOCK_KEYx is a free eFuse key-block between BLOCK_KEY0 and BLOCK_KEY5
29-
espefuse.py -p PORT burn_key BLOCK_KEYx user_key.bin USER
32+
espefuse.py -p PORT burn_key BLOCK_KEYx hmac_key_file.bin HMAC_UP
3033
```
3134

3235
### Build and Flash
@@ -121,7 +124,7 @@ help [<string>] [-v <0|1>]
121124
esp32c6> tee_att_info
122125
I (8180) tee_attest: Attestation token - Length: 1455
123126
I (8180) tee_attest: Attestation token - Data:
124-
'{"header":{"magic":"44fef7cc","encr_alg":"","sign_alg":"ecdsa_secp256r1_sha256","key_id":0},"eat":{"nonce":-1582119980,"client_id":262974944,"device_ver":0,"device_id":"cd9c173cb3675c7adfae243f0cd9841e4bce003237cb5321927a85a86cb4b32e","instance_id":"9616ef0ecf02cdc89a3749f8fc16b3103d5100bd42d9312fcd04593baa7bac64","psa_cert_ref":"0716053550477-10100","device_status":165,"sw_claims":{"tee":{"type":1,"ver":"v0.3.0","idf_ver":"v5.1.4-241-g7ff01fd46f-dirty","secure_ver":0,"part_chip_rev":{"min":0,"max":99},"part_digest":{"type":0,"calc_digest":"94536998e1dcb2a036477cb2feb01ed4fff67ba6208f30482346c62bca64b280","digest_validated":true,"sign_verified":true}},"app":{"type":2,"ver":"v0.1.0","idf_ver":"v5.1.4-241-g7ff01fd46f-dirty","secure_ver":0,"part_chip_rev":{"min":0,"max":99},"part_digest":{"type":0,"calc_digest":"3d4c038fcec76852b4d07acb9e94afaf5fca69fc2eb212a32032d09ce5b4f2b3","digest_validated":true,"sign_verified":true,"secure_padding":true}},"bootloader":{"type":0,"ver":"","idf_ver":"","secure_ver":-1,"part_chip_rev":{"min":0,"max":99},"part_digest":{"type":0,"calc_digest":"1bef421beb1a4642c6fcefb3e37fd4afad60cb4074e538f42605b012c482b946","digest_validated":true,"sign_verified":true}}}},"public_key":{"compressed":"02039c4bfab0762af1aff2fe5596b037f629cf839da8c4a9c0018afedfccf519a6"},"sign":{"r":"915e749f5a780bc21a2b21821cfeb54286dc742e9f12f2387e3de9b8b1a70bc9","s":"1e583236f2630b0fe8e291645ffa35d429f14035182e19868508d4dac0e1a441"}}'
127+
'{"header":{"magic":"44fef7cc","encr_alg":"","sign_alg":"ecdsa_secp256r1_sha256","key_id":"tee_att_key0"},"eat":{"nonce":-1582119980,"client_id":262974944,"device_ver":0,"device_id":"cd9c173cb3675c7adfae243f0cd9841e4bce003237cb5321927a85a86cb4b32e","instance_id":"9616ef0ecf02cdc89a3749f8fc16b3103d5100bd42d9312fcd04593baa7bac64","psa_cert_ref":"0716053550477-10100","device_status":165,"sw_claims":{"tee":{"type":1,"ver":"v0.3.0","idf_ver":"v5.1.4-241-g7ff01fd46f-dirty","secure_ver":0,"part_chip_rev":{"min":0,"max":99},"part_digest":{"type":0,"calc_digest":"94536998e1dcb2a036477cb2feb01ed4fff67ba6208f30482346c62bca64b280","digest_validated":true,"sign_verified":true}},"app":{"type":2,"ver":"v0.1.0","idf_ver":"v5.1.4-241-g7ff01fd46f-dirty","secure_ver":0,"part_chip_rev":{"min":0,"max":99},"part_digest":{"type":0,"calc_digest":"3d4c038fcec76852b4d07acb9e94afaf5fca69fc2eb212a32032d09ce5b4f2b3","digest_validated":true,"sign_verified":true,"secure_padding":true}},"bootloader":{"type":0,"ver":"","idf_ver":"","secure_ver":-1,"part_chip_rev":{"min":0,"max":99},"part_digest":{"type":0,"calc_digest":"1bef421beb1a4642c6fcefb3e37fd4afad60cb4074e538f42605b012c482b946","digest_validated":true,"sign_verified":true}}}},"public_key":{"compressed":"02039c4bfab0762af1aff2fe5596b037f629cf839da8c4a9c0018afedfccf519a6"},"sign":{"r":"915e749f5a780bc21a2b21821cfeb54286dc742e9f12f2387e3de9b8b1a70bc9","s":"1e583236f2630b0fe8e291645ffa35d429f14035182e19868508d4dac0e1a441"}}'
125128
126129
```
127130
-30.7 KB
Binary file not shown.
-27.6 KB
Binary file not shown.

docs/en/api-guides/partition-tables.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ See enum :cpp:type:`esp_partition_subtype_t` for the full list of subtypes defin
185185
.. only:: esp32c6
186186

187187
- ``tee_ota`` (0x90) is the :ref:`TEE OTA data partition <tee-ota-data-partition>` which stores information about the currently selected TEE OTA app slot. This partition should be 0x2000 bytes in size. Refer to the :doc:`TEE OTA documentation <../security/tee/tee-ota>` for more details.
188-
- ``tee_sec_stg`` (0x91) is the TEE secure storage partition which stores encrypted data that can only be accessed by the TEE application. This partition is used by the :doc:`TEE Secure Storage <../security/tee/tee-sec-storage>` to store sensitive data like cryptographic keys. The size of this partition depends on the application requirements.
189188

190189
- There are other predefined data subtypes for data storage supported by ESP-IDF. These include:
191190

docs/en/api-reference/storage/nvs_encryption.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Data stored in NVS partitions can be encrypted using XTS-AES in the manner simil
1414

1515
NVS encryption can be facilitated by enabling :ref:`CONFIG_NVS_ENCRYPTION` and :ref:`CONFIG_NVS_SEC_KEY_PROTECTION_SCHEME` > ``CONFIG_NVS_SEC_KEY_PROTECT_USING_FLASH_ENC`` or ``CONFIG_NVS_SEC_KEY_PROTECT_USING_HMAC`` depending on the scheme to be used.
1616

17+
.. _nvs_encr_flash_enc_scheme:
1718

1819
NVS Encryption: Flash Encryption-Based Scheme
1920
---------------------------------------------
@@ -104,6 +105,8 @@ It is possible for an application to use different keys for different NVS partit
104105

105106
.. only:: SOC_HMAC_SUPPORTED
106107

108+
.. _nvs_encr_hmac_scheme:
109+
107110
NVS Encryption: HMAC Peripheral-Based Scheme
108111
--------------------------------------------
109112

docs/en/security/tee/tee-attestation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ EAT: Header
8888
- Currently, only ``ecdsa_secp256r1_sha256`` is supported
8989
* - Key ID
9090
- Identifies the key to be utilized by the device for encryption and signing
91-
- TEE secure storage slot ID
91+
- TEE secure storage key ID (string)
9292

9393
EAT: Claim Table
9494
^^^^^^^^^^^^^^^^
@@ -173,7 +173,7 @@ Sample EAT in JSON format
173173
"magic": "44fef7cc",
174174
"encr_alg": "",
175175
"sign_alg": "ecdsa_secp256r1_sha256",
176-
"key_id": 0
176+
"key_id": "tee_att_key0"
177177
},
178178
"eat": {
179179
"nonce": -1582119980,

docs/en/security/tee/tee-sec-storage.rst

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,72 @@ Secure Storage
33

44
Overview
55
--------
6+
The TEE Secure Storage service provides persistent storage for securely storing sensitive data, such as cryptographic keys, cloud credentials, or other general-purpose information. It uses a dedicated flash partition of type ``data`` and subtype ``nvs``. The TEE ensures both confidentiality and integrity of the stored data.
67

7-
The TEE Secure Storage service offers a persistent storage for securely holding sensitive data, such as cryptographic keys, cloud credentials or any other general-purpose information. It utilizes a dedicated flash partition of type ``data`` and subtype ``tee_sec_stg``. The confidentiality and integrity of the data is ensured by the TEE.
8+
TEE Secure Storage adopts the :doc:`../../api-reference/storage/nvs_flash` partition format and uses the HMAC peripheral-based XTS-AES encryption scheme, as detailed :ref:`here <nvs_encr_hmac_scheme>`. The AES encryption keys are derived from an HMAC key programmed in eFuse with the purpose :cpp:enumerator:`esp_efuse_purpose_t::ESP_EFUSE_KEY_PURPOSE_HMAC_UP`. Please note that the TEE Secure storage does not support the :ref:`NVS Flash Encryption-based scheme <nvs_encr_flash_enc_scheme>`.
89

9-
For enhanced security, data stored in the secure storage is encrypted using a device-specific encryption key with ``AES-256-GCM`` algorithm. Additionally, the secure storage provides interfaces for performing the following cryptographic services from the TEE using securely stored key material:
10+
.. important::
1011

11-
#. Message signing and public key retrieval with the ``ecdsa_secp256r1`` algorithm
12-
#. Authenticated encryption and decryption using the ``aes256_gcm`` algorithm
12+
- One eFuse block is required to store the HMAC key used for deriving the NVS encryption keys. This key is exclusive to the TEE and **CANNOT** be used by the REE for any purpose.
13+
- The HMAC key must be programmed into eFuse before firmware execution, as TEE Secure Storage does not support generating it on-device. If no valid key with the required purpose is found in the configured eFuse block, an error will be raised at runtime.
1314

14-
Internals
15-
---------
15+
Additionally, the secure storage provides interfaces for performing the following cryptographic services from the TEE using securely stored key material:
1616

17-
The secure storage partition is 4 KB in size, of which only the first half is used for storing data. The partition is divided into slots which hold data objects. Each data object within the TEE secure storage is encapsulated in a structured format, comprising the metadata and actual data.
17+
#. Message signing and public key retrieval using the ``ecdsa_secp256r1`` and ``ecdsa_secp192r1`` algorithms
18+
#. Authenticated encryption and decryption using the ``aes256_gcm`` algorithm
1819

19-
.. figure:: ../../../_static/esp_tee/tee_sec_stg_part.png
20-
:align: center
21-
:scale: 80%
22-
:alt: TEE Secure storage partition
23-
:figclass: align-center
24-
25-
ESP-TEE: Secure Storage partition
20+
.. note::
2621

27-
Metadata is represented by the :cpp:type:`sec_stg_metadata_t` structure, which contains details related to the data stored in a specific slot of the storage. These details include information such as the owner, slot ID, data length, encryption parameters, etc.
22+
As per the current implementation, the TEE Secure Storage partition **must** have the label ``secure_storage``.
2823

29-
.. list-table::
30-
:header-rows: 1
31-
:widths: 35 65
32-
:align: center
24+
Internals
25+
---------
3326

34-
* - **Element**
35-
- **Description**
36-
* - Owner ID
37-
- Application ID defining the data ownership
38-
* - Slot ID
39-
- Slot ID for corresponding owner ID
40-
* - Encryption: Initialization Vector (IV)
41-
- IV for the encryption algorithm
42-
* - Encryption: Tag
43-
- Tag for the encryption algorithm
44-
* - Data Type
45-
- Type of data stored in this slot
46-
* - Data Length
47-
- Actual data length
27+
Each data object consisting of the type, associated metadata flags (e.g., ``WRITE_ONCE``), and the actual payload is encapsulated in a structured format and stored as a variable-length NVS blob in the secure storage partition.
4828

49-
.. figure:: ../../../_static/esp_tee/tee_sec_stg_metadata.png
50-
:align: center
51-
:scale: 80%
52-
:alt: TEE Secure storage metadata
53-
:figclass: align-center
29+
.. note::
5430

55-
ESP-TEE: Secure Storage Metadata
31+
As per the current implementation, all data objects in the TEE Secure Storage are to be stored in the ``tee_sec_stg_ns`` namespace.
5632

57-
.. warning::
33+
Currently, TEE secure storage supports storing the following cryptographic keys:
5834

59-
Future ESP-TEE framework releases may modify the internal data structure of the TEE secure storage, which could introduce breaking changes in existing applications.
35+
#. ``ecdsa_secp256r1`` and ``ecdsa_secp192r1`` curve key-pairs, including private and public key components
36+
#. ``aes256`` keys, including the key and initialization vector (IV)
6037

61-
Each data object in the secure storage is encrypted as specified in the **AES-GCM based AEAD** encryption policy with a platform instance unique key of length **256 bits**, stored in the eFuse.
38+
All assets related to TEE secure storage are protected by the APM peripheral and are inaccessible to the REE application. Any direct access attempts will result in a system fault. Future updates are planned to add support for additional key types and general-purpose data storage.
6239

63-
The TEE Secure Storage feature supports two modes (:ref:`CONFIG_SECURE_TEE_SEC_STG_MODE`) for determining which eFuse block stores the encryption key:
40+
The TEE Secure Storage feature supports two modes for determining how the NVS encryption keys are derived (see :ref:`CONFIG_SECURE_TEE_SEC_STG_MODE`):
6441

65-
- **Development** Mode: The encryption key is embedded (constant for all instances) in the ESP-TEE firmware.
66-
- **Release** Mode: The encryption key is stored in eFuse BLK4 - BLK9, depending on the :ref:`CONFIG_SECURE_TEE_SEC_STG_KEY_EFUSE_BLK` Kconfig option.
42+
- **Development** Mode: Encryption keys are embedded (constant for all instances) in the ESP-TEE firmware.
43+
- **Release** Mode: Encryption keys are derived via the HMAC peripheral using a key stored in eFuse, specified by :ref:`CONFIG_SECURE_TEE_SEC_STG_EFUSE_HMAC_KEY_ID`.
6744

68-
All the assets pertaining to the TEE secure storage are protected by the APM peripheral and thus, are inaccessible to the REE application. Any attempt to directly access them would result in a system fault.
45+
.. note::
6946

70-
.. note::
47+
- The valid range for :ref:`CONFIG_SECURE_TEE_SEC_STG_EFUSE_HMAC_KEY_ID` is from ``0`` (:cpp:enumerator:`hmac_key_id_t::HMAC_KEY0`) to ``5`` (:cpp:enumerator:`hmac_key_id_t::HMAC_KEY5`). By default, this config is set to ``-1`` and must be configured before building the TEE application.
7148

72-
- Currently, the TEE secure storage supports the storage of two types of cryptographic keys:
49+
- The following commands can be used to generate and program the HMAC key into the required eFuse block:
7350

74-
#. ``ecdsa_secp256r1`` curve key-pairs, including the private and public key components
75-
#. ``aes256_gcm`` keys, including the key and initialization vector (IV)
51+
::
7652

77-
The internal structures for these key types are as follows:
53+
# Generate a random 32-byte HMAC key
54+
openssl rand -out hmac_key_file.bin 32
7855

79-
.. code-block:: c
56+
# Program the HMAC key into the eFuse block
57+
idf.py -p PORT efuse-burn-key <BLOCK_KEY0-5> hmac_key_file.bin HMAC_UP
8058

81-
#define ECDSA_SECP256R1_KEY_LEN 32
82-
#define AES256_GCM_KEY_LEN 32
83-
#define AES256_GCM_IV_LEN 12
59+
Tools
60+
-----
8461

85-
typedef struct {
86-
/* Private key */
87-
uint8_t priv_key[ECDSA_SECP256R1_KEY_LEN];
88-
/* Public key - X and Y components */
89-
uint8_t pub_key[2 * ECDSA_SECP256R1_KEY_LEN];
90-
} sec_stg_ecdsa_secp256r1_t;
62+
The :doc:`../../api-reference/storage/nvs_partition_gen` tool can be used to generate binary images compatible with the NVS format for use with TEE Secure Storage. Since TEE Secure Storage stores data objects using a custom structured format, an additional step is required to convert input data into this format prior to image generation and encryption.
9163

92-
typedef struct {
93-
/* Key */
94-
uint8_t key[AES256_GCM_KEY_LEN];
95-
/* Initialization Vector */
96-
uint8_t iv[AES256_GCM_IV_LEN];
97-
} sec_stg_aes256_gcm_t;
64+
To support this process, the :component_file:`esp_tee_sec_stg_keygen.py<esp_tee/scripts/esp_tee_sec_stg_keygen/esp_tee_sec_stg_keygen.py>` script is provided for generating secure key blobs corresponding to the various supported cryptographic algorithms. These key blobs are then referenced in the input CSV file (format described :ref:`here <nvs-csv-file-format>`) and passed to the NVS Partition Generator utility to produce an encrypted images suitable for TEE Secure Storage.
9865

99-
- Future updates may include support for additional key types and general-purpose data storage.
66+
Refer the detailed steps given :component_file:`here<esp_tee/scripts/esp_tee_sec_stg_keygen/README.md>` on generating key blobs and encrypted NVS partition images for TEE Secure Storage.
10067

10168
Application Example
10269
-------------------
10370

104-
The :example:`tee_secure_storage <security/tee/tee_secure_storage>` example demonstrates how to generate ECDSA key pairs and AES-256-GCM keys in the TEE secure storage and use them for signing messages and encrypting/decrypting data.
71+
The :example:`tee_secure_storage <security/tee/tee_secure_storage>` example demonstrates how to generate ECDSA key pairs and AES-256 keys in the TEE secure storage and use them for signing messages and encrypting/decrypting data.
10572

10673
API Reference
10774
-------------

docs/en/security/tee/tee.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Example partition table is given below: ::
9696
# ESP-IDF Partition Table
9797
# Name, Type, SubType, Offset, Size, Flags
9898
tee_0, app, tee_0, 0x10000, 192K,
99-
secure_storage, data, tee_sec_stg, 0x40000, 64K,
99+
secure_storage, data, nvs, 0x40000, 64K,
100100
factory, app, factory, 0x50000, 1M,
101101
nvs, data, nvs, 0x150000, 24K,
102102
phy_init, data, phy, 0x156000, 4K,

docs/zh_CN/api-guides/partition-tables.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ SubType 字段长度为 8 bit,内容与具体分区 Type 有关。目前,ESP
185185
.. only:: esp32c6
186186

187187
- ``tee-ota`` (0x90) 是 :ref:`TEE OTA 数据分区 <tee-ota-data-partition>`,用于存储所选 TEE OTA 应用分区的信息。此分区大小应为 0x2000 字节。详情请参阅 :doc:`TEE OTA <../security/tee/tee-ota>`。
188-
- ``tee_sec_stg`` (0x91) 是 TEE 安全存储分区,用于存储仅能被 TEE 应用程序访问的加密数据。:doc:`TEE 安全存储 <../security/tee/tee-sec-storage>` 将使用此分区存储包括加密密钥在内的敏感数据。此分区大小取决于具体的应用需求。
189188

190189
- ESP-IDF 还支持其他用于数据存储的预定义子类型,包括:
191190

docs/zh_CN/api-reference/storage/nvs_encryption.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ NVS 加密
1414

1515
根据要使用的具体方案,可以选择启用 :ref:`CONFIG_NVS_ENCRYPTION` 和 :ref:`CONFIG_NVS_SEC_KEY_PROTECTION_SCHEME` > ``CONFIG_NVS_SEC_KEY_PROTECT_USING_FLASH_ENC`` 或 ``CONFIG_NVS_SEC_KEY_PROTECT_USING_HMAC`` 实现 NVS 加密。
1616

17+
.. _nvs_encr_flash_enc_scheme:
1718

1819
NVS 加密:基于 flash 加密的方案
1920
-------------------------------------
@@ -104,6 +105,8 @@ NVS 密钥分区
104105

105106
.. only:: SOC_HMAC_SUPPORTED
106107

108+
.. _nvs_encr_hmac_scheme:
109+
107110
NVS 加密:基于 HMAC 外设的方案
108111
--------------------------------------------
109112

0 commit comments

Comments
 (0)