Skip to content

Commit 5210e57

Browse files
committed
feat(mbedtls/sha): New API for setting SHA mode
1 parent e7a76ff commit 5210e57

File tree

32 files changed

+279
-135
lines changed

32 files changed

+279
-135
lines changed

components/esp_tee/scripts/esp32c6/sec_srv_tbl_default.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ secure_services:
240240
type: IDF
241241
function: esp_ecc_point_verify
242242
args: 1
243+
- id: 110
244+
type: IDF
245+
function: esp_sha_set_mode
246+
args: 1
243247
# ID: 134-169 (36) - Reserved for future use
244248
- family: attestation
245249
entries:

components/esp_tee/scripts/esp32h2/sec_srv_tbl_default.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ secure_services:
244244
type: IDF
245245
function: esp_crypto_ecc_enable_periph_clk
246246
args: 1
247+
- id: 111
248+
type: IDF
249+
function: esp_sha_set_mode
250+
args: 1
247251
# ID: 134-169 (36) - Reserved for future use
248252
- family: attestation
249253
entries:

components/esp_tee/src/esp_secure_service_wrapper.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ int __wrap_esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_
202202
return esp_tee_service_call(4, SS_ESP_SHA_BLOCK, sha_type, data_block, is_first_block);
203203
}
204204

205+
void __wrap_esp_sha_set_mode(esp_sha_type sha_type)
206+
{
207+
esp_tee_service_call(2, SS_ESP_SHA_SET_MODE, sha_type);
208+
}
209+
205210
void __wrap_esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state)
206211
{
207212
esp_tee_service_call(3, SS_ESP_SHA_READ_DIGEST_STATE, sha_type, digest_state);

components/esp_tee/subproject/main/core/esp_secure_services.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ void _ss_esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_fi
193193
esp_sha_block(sha_type, data_block, is_first_block);
194194
}
195195

196+
void _ss_esp_sha_set_mode(esp_sha_type sha_type)
197+
{
198+
esp_sha_set_mode(sha_type);
199+
}
200+
196201
void _ss_esp_crypto_sha_enable_periph_clk(bool enable)
197202
{
198203
esp_crypto_sha_enable_periph_clk(enable);

components/hal/esp32/include/hal/sha_ll.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ static inline void sha_ll_load(esp_sha_type sha_type)
126126
DPORT_REG_WRITE(SHA_LOAD_REG(sha_type), 1);
127127
}
128128

129+
/**
130+
* @brief Load the mode for the SHA engine
131+
*
132+
* @param sha_type The SHA algorithm type
133+
*/
134+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
135+
{
136+
(void) sha_type;
137+
}
138+
129139
/**
130140
* @brief Checks if the SHA engine is currently busy hashing a block
131141
*

components/hal/esp32c2/include/hal/sha_ll.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,24 @@ static inline void sha_ll_reset_register(void)
4242
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
4343
#define sha_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; sha_ll_reset_register(__VA_ARGS__)
4444

45+
/**
46+
* @brief Load the mode for the SHA engine
47+
*
48+
* @param sha_type The SHA algorithm type
49+
*/
50+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
51+
{
52+
REG_WRITE(SHA_MODE_REG, sha_type);
53+
}
54+
4555
/**
4656
* @brief Start a new SHA block conversions (no initial hash in HW)
4757
*
4858
* @param sha_type The SHA algorithm type
4959
*/
5060
static inline void sha_ll_start_block(esp_sha_type sha_type)
5161
{
52-
REG_WRITE(SHA_MODE_REG, sha_type);
62+
(void) sha_type;
5363
REG_WRITE(SHA_START_REG, 1);
5464
}
5565

@@ -60,29 +70,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
6070
*/
6171
static inline void sha_ll_continue_block(esp_sha_type sha_type)
6272
{
63-
REG_WRITE(SHA_MODE_REG, sha_type);
73+
(void) sha_type;
6474
REG_WRITE(SHA_CONTINUE_REG, 1);
6575
}
6676

6777
/**
6878
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
69-
*
70-
* @param sha_type The SHA algorithm type
7179
*/
72-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
80+
static inline void sha_ll_start_dma(void)
7381
{
74-
REG_WRITE(SHA_MODE_REG, sha_type);
7582
REG_WRITE(SHA_DMA_START_REG, 1);
7683
}
7784

7885
/**
7986
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
80-
*
81-
* @param sha_type The SHA algorithm type
8287
*/
83-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
88+
static inline void sha_ll_continue_dma(void)
8489
{
85-
REG_WRITE(SHA_MODE_REG, sha_type);
8690
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
8791
}
8892

components/hal/esp32c3/include/hal/sha_ll.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,24 @@ static inline void sha_ll_reset_register(void)
4545
/// the critical section needs to declare the __DECLARE_RCC_ATOMIC_ENV variable in advance
4646
#define sha_ll_reset_register(...) (void)__DECLARE_RCC_ATOMIC_ENV; sha_ll_reset_register(__VA_ARGS__)
4747

48+
/**
49+
* @brief Load the mode for the SHA engine
50+
*
51+
* @param sha_type The SHA algorithm type
52+
*/
53+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
54+
{
55+
REG_WRITE(SHA_MODE_REG, sha_type);
56+
}
57+
4858
/**
4959
* @brief Start a new SHA block conversions (no initial hash in HW)
5060
*
5161
* @param sha_type The SHA algorithm type
5262
*/
5363
static inline void sha_ll_start_block(esp_sha_type sha_type)
5464
{
55-
REG_WRITE(SHA_MODE_REG, sha_type);
65+
(void) sha_type;
5666
REG_WRITE(SHA_START_REG, 1);
5767
}
5868

@@ -63,29 +73,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
6373
*/
6474
static inline void sha_ll_continue_block(esp_sha_type sha_type)
6575
{
66-
REG_WRITE(SHA_MODE_REG, sha_type);
76+
(void) sha_type;
6777
REG_WRITE(SHA_CONTINUE_REG, 1);
6878
}
6979

7080
/**
7181
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
72-
*
73-
* @param sha_type The SHA algorithm type
7482
*/
75-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
83+
static inline void sha_ll_start_dma(void)
7684
{
77-
REG_WRITE(SHA_MODE_REG, sha_type);
7885
REG_WRITE(SHA_DMA_START_REG, 1);
7986
}
8087

8188
/**
8289
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
83-
*
84-
* @param sha_type The SHA algorithm type
8590
*/
86-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
91+
static inline void sha_ll_continue_dma(void)
8792
{
88-
REG_WRITE(SHA_MODE_REG, sha_type);
8993
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
9094
}
9195

components/hal/esp32c5/include/hal/sha_ll.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,24 @@ static inline void sha_ll_reset_register(void)
3939
PCR.ecdsa_conf.ecdsa_rst_en = 0;
4040
}
4141

42+
/**
43+
* @brief Load the mode for the SHA engine
44+
*
45+
* @param sha_type The SHA algorithm type
46+
*/
47+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
48+
{
49+
REG_WRITE(SHA_MODE_REG, sha_type);
50+
}
51+
4252
/**
4353
* @brief Start a new SHA block conversions (no initial hash in HW)
4454
*
4555
* @param sha_type The SHA algorithm type
4656
*/
4757
static inline void sha_ll_start_block(esp_sha_type sha_type)
4858
{
49-
REG_WRITE(SHA_MODE_REG, sha_type);
59+
(void) sha_type;
5060
REG_WRITE(SHA_START_REG, 1);
5161
}
5262

@@ -57,29 +67,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
5767
*/
5868
static inline void sha_ll_continue_block(esp_sha_type sha_type)
5969
{
60-
REG_WRITE(SHA_MODE_REG, sha_type);
70+
(void) sha_type;
6171
REG_WRITE(SHA_CONTINUE_REG, 1);
6272
}
6373

6474
/**
6575
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
66-
*
67-
* @param sha_type The SHA algorithm type
6876
*/
69-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
77+
static inline void sha_ll_start_dma(void)
7078
{
71-
REG_WRITE(SHA_MODE_REG, sha_type);
7279
REG_WRITE(SHA_DMA_START_REG, 1);
7380
}
7481

7582
/**
7683
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
77-
*
78-
* @param sha_type The SHA algorithm type
7984
*/
80-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
85+
static inline void sha_ll_continue_dma(void)
8186
{
82-
REG_WRITE(SHA_MODE_REG, sha_type);
8387
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
8488
}
8589

components/hal/esp32c6/include/hal/sha_ll.h

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -37,14 +37,24 @@ static inline void sha_ll_reset_register(void)
3737
PCR.hmac_conf.hmac_rst_en = 0;
3838
}
3939

40+
/**
41+
* @brief Load the mode for the SHA engine
42+
*
43+
* @param sha_type The SHA algorithm type
44+
*/
45+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
46+
{
47+
REG_WRITE(SHA_MODE_REG, sha_type);
48+
}
49+
4050
/**
4151
* @brief Start a new SHA block conversions (no initial hash in HW)
4252
*
4353
* @param sha_type The SHA algorithm type
4454
*/
4555
static inline void sha_ll_start_block(esp_sha_type sha_type)
4656
{
47-
REG_WRITE(SHA_MODE_REG, sha_type);
57+
(void) sha_type;
4858
REG_WRITE(SHA_START_REG, 1);
4959
}
5060

@@ -55,29 +65,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
5565
*/
5666
static inline void sha_ll_continue_block(esp_sha_type sha_type)
5767
{
58-
REG_WRITE(SHA_MODE_REG, sha_type);
68+
(void) sha_type;
5969
REG_WRITE(SHA_CONTINUE_REG, 1);
6070
}
6171

6272
/**
6373
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
64-
*
65-
* @param sha_type The SHA algorithm type
6674
*/
67-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
75+
static inline void sha_ll_start_dma(void)
6876
{
69-
REG_WRITE(SHA_MODE_REG, sha_type);
7077
REG_WRITE(SHA_DMA_START_REG, 1);
7178
}
7279

7380
/**
7481
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
75-
*
76-
* @param sha_type The SHA algorithm type
7782
*/
78-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
83+
static inline void sha_ll_continue_dma(void)
7984
{
80-
REG_WRITE(SHA_MODE_REG, sha_type);
8185
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
8286
}
8387

components/hal/esp32c61/include/hal/sha_ll.h

Lines changed: 15 additions & 11 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
*/
@@ -39,14 +39,24 @@ static inline void sha_ll_reset_register(void)
3939
PCR.ecdsa_conf.ecdsa_rst_en = 0;
4040
}
4141

42+
/**
43+
* @brief Load the mode for the SHA engine
44+
*
45+
* @param sha_type The SHA algorithm type
46+
*/
47+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
48+
{
49+
REG_WRITE(SHA_MODE_REG, sha_type);
50+
}
51+
4252
/**
4353
* @brief Start a new SHA block conversions (no initial hash in HW)
4454
*
4555
* @param sha_type The SHA algorithm type
4656
*/
4757
static inline void sha_ll_start_block(esp_sha_type sha_type)
4858
{
49-
REG_WRITE(SHA_MODE_REG, sha_type);
59+
(void) sha_type;
5060
REG_WRITE(SHA_START_REG, 1);
5161
}
5262

@@ -57,29 +67,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
5767
*/
5868
static inline void sha_ll_continue_block(esp_sha_type sha_type)
5969
{
60-
REG_WRITE(SHA_MODE_REG, sha_type);
70+
(void) sha_type;
6171
REG_WRITE(SHA_CONTINUE_REG, 1);
6272
}
6373

6474
/**
6575
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
66-
*
67-
* @param sha_type The SHA algorithm type
6876
*/
69-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
77+
static inline void sha_ll_start_dma(void)
7078
{
71-
REG_WRITE(SHA_MODE_REG, sha_type);
7279
REG_WRITE(SHA_DMA_START_REG, 1);
7380
}
7481

7582
/**
7683
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
77-
*
78-
* @param sha_type The SHA algorithm type
7984
*/
80-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
85+
static inline void sha_ll_continue_dma(void)
8186
{
82-
REG_WRITE(SHA_MODE_REG, sha_type);
8387
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
8488
}
8589

0 commit comments

Comments
 (0)