Skip to content

Commit 1c4969b

Browse files
committed
feat(esp_security): Add a TEE-specific crypto lock layer with stub implementations
1 parent 16d7910 commit 1c4969b

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

components/esp_security/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if(NOT non_os_build)
3232
list(APPEND srcs "src/esp_crypto_lock.c" "src/esp_crypto_periph_clk.c")
3333
list(APPEND priv_requires efuse esp_hw_support esp_system esp_timer)
3434
elseif(esp_tee_build)
35-
list(APPEND srcs "src/esp_crypto_periph_clk.c")
35+
list(APPEND srcs "src/esp_crypto_lock.c" "src/esp_crypto_periph_clk.c")
3636
list(APPEND includes "src/${IDF_TARGET}")
3737
list(APPEND priv_requires esp_hw_support)
3838
endif()

components/esp_security/src/esp_crypto_lock.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -18,6 +18,7 @@ DS: needs HMAC (which needs SHA), AES and MPI
1818
ECDSA: needs ECC and MPI
1919
*/
2020

21+
#if !NON_OS_BUILD
2122
#ifdef SOC_DIG_SIGN_SUPPORTED
2223
/* Lock for DS peripheral */
2324
static _lock_t s_crypto_ds_lock;
@@ -162,3 +163,52 @@ void esp_crypto_key_manager_lock_release(void)
162163
_lock_release(&s_crypto_key_manager_lock);
163164
}
164165
#endif /* SOC_KEY_MANAGER_SUPPORTED */
166+
#else /* NON_OS_BUILD */
167+
#ifdef SOC_HMAC_SUPPORTED
168+
void esp_crypto_hmac_lock_acquire(void) {}
169+
170+
void esp_crypto_hmac_lock_release(void) {}
171+
#endif /* SOC_HMAC_SUPPORTED */
172+
173+
#ifdef SOC_DIG_SIGN_SUPPORTED
174+
void esp_crypto_ds_lock_acquire(void) {}
175+
176+
void esp_crypto_ds_lock_release(void) {}
177+
#endif /* SOC_DIG_SIGN_SUPPORTED */
178+
179+
#if defined(SOC_SHA_SUPPORTED) || defined(SOC_AES_SUPPORTED)
180+
void esp_crypto_sha_aes_lock_acquire(void) {}
181+
182+
void esp_crypto_sha_aes_lock_release(void) {}
183+
#endif /* defined(SOC_SHA_SUPPORTED) || defined(SOC_AES_SUPPORTED) */
184+
185+
#if defined(SOC_SHA_CRYPTO_DMA) || defined(SOC_AES_CRYPTO_DMA)
186+
void esp_crypto_dma_lock_acquire(void) {}
187+
188+
void esp_crypto_dma_lock_release(void) {}
189+
#endif /* defined(SOC_SHA_CRYPTO_DMA) || defined(SOC_AES_CRYPTO_DMA) */
190+
191+
#ifdef SOC_MPI_SUPPORTED
192+
void esp_crypto_mpi_lock_acquire(void) {}
193+
194+
void esp_crypto_mpi_lock_release(void) {}
195+
#endif /* SOC_MPI_SUPPORTED */
196+
197+
#ifdef SOC_ECC_SUPPORTED
198+
void esp_crypto_ecc_lock_acquire(void) {}
199+
200+
void esp_crypto_ecc_lock_release(void) {}
201+
#endif /* SOC_ECC_SUPPORTED */
202+
203+
#ifdef SOC_ECDSA_SUPPORTED
204+
void esp_crypto_ecdsa_lock_acquire(void) {}
205+
206+
void esp_crypto_ecdsa_lock_release(void) {}
207+
#endif /* SOC_ECDSA_SUPPORTED */
208+
209+
#ifdef SOC_KEY_MANAGER_SUPPORTED
210+
void esp_crypto_key_manager_lock_acquire(void) {}
211+
212+
void esp_crypto_key_manager_lock_release(void) {}
213+
#endif /* SOC_KEY_MANAGER_SUPPORTED */
214+
#endif /* !NON_OS_BUILD */

components/mbedtls/port/aes/dma/esp_aes.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,8 @@
3535
#include "esp_crypto_periph_clk.h"
3636

3737
#if SOC_AES_GDMA
38-
#if !ESP_TEE_BUILD
3938
#define AES_LOCK() esp_crypto_sha_aes_lock_acquire()
4039
#define AES_RELEASE() esp_crypto_sha_aes_lock_release()
41-
#else
42-
#define AES_LOCK()
43-
#define AES_RELEASE()
44-
#endif
4540
#elif SOC_AES_CRYPTO_DMA
4641
#define AES_LOCK() esp_crypto_dma_lock_acquire()
4742
#define AES_RELEASE() esp_crypto_dma_lock_release()

components/mbedtls/port/sha/core/sha.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@
5252
#endif
5353
#endif /* SOC_SHA_SUPPORT_DMA */
5454

55-
#if !ESP_TEE_BUILD
56-
#define SHA_LOCK() esp_crypto_sha_aes_lock_acquire()
57-
#define SHA_RELEASE() esp_crypto_sha_aes_lock_release()
58-
#else
59-
#define SHA_LOCK()
60-
#define SHA_RELEASE()
61-
#endif
62-
6355
void esp_sha_write_digest_state(esp_sha_type sha_type, void *digest_state)
6456
{
6557
sha_hal_write_digest(sha_type, digest_state);
@@ -99,15 +91,15 @@ inline static size_t block_length(esp_sha_type type)
9991
void esp_sha_acquire_hardware(void)
10092
{
10193
/* Released when releasing hw with esp_sha_release_hardware() */
102-
SHA_LOCK();
94+
esp_crypto_sha_aes_lock_acquire();
10395
esp_crypto_sha_enable_periph_clk(true);
10496
}
10597

10698
/* Disable SHA peripheral block and then release it */
10799
void esp_sha_release_hardware(void)
108100
{
109101
esp_crypto_sha_enable_periph_clk(false);
110-
SHA_RELEASE();
102+
esp_crypto_sha_aes_lock_release();
111103
}
112104

113105
void esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_block)

0 commit comments

Comments
 (0)