Skip to content

Commit 8d0527d

Browse files
Merge branch 'feat/support_sha512_for_esp32c5' into 'master'
Support SHA 512 for ESP32-C5 See merge request espressif/esp-idf!39421
2 parents 5b7922b + 85ec4df commit 8d0527d

File tree

46 files changed

+349
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+349
-281
lines changed

components/esp_rom/esp32c5/include/esp32c5/rom/sha.h

Lines changed: 6 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,11 @@ typedef enum {
1818
SHA1 = 0,
1919
SHA2_224,
2020
SHA2_256,
21+
SHA2_384,
22+
SHA2_512,
23+
SHA2_512224,
24+
SHA2_512256,
25+
SHA2_512T,
2126
SHA_TYPE_MAX
2227
} SHA_TYPE;
2328

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
@@ -132,6 +132,16 @@ static inline void sha_ll_load(esp_sha_type sha_type)
132132
DPORT_REG_WRITE(SHA_LOAD_REG(sha_type), 1);
133133
}
134134

135+
/**
136+
* @brief Load the mode for the SHA engine
137+
*
138+
* @param sha_type The SHA algorithm type
139+
*/
140+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
141+
{
142+
(void) sha_type;
143+
}
144+
135145
/**
136146
* @brief Checks if the SHA engine is currently busy hashing a block
137147
*

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,24 @@ static inline void sha_ll_reset_register(void)
4848
sha_ll_reset_register(__VA_ARGS__); \
4949
} while(0)
5050

51+
/**
52+
* @brief Load the mode for the SHA engine
53+
*
54+
* @param sha_type The SHA algorithm type
55+
*/
56+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
57+
{
58+
REG_WRITE(SHA_MODE_REG, sha_type);
59+
}
60+
5161
/**
5262
* @brief Start a new SHA block conversions (no initial hash in HW)
5363
*
5464
* @param sha_type The SHA algorithm type
5565
*/
5666
static inline void sha_ll_start_block(esp_sha_type sha_type)
5767
{
58-
REG_WRITE(SHA_MODE_REG, sha_type);
68+
(void) sha_type;
5969
REG_WRITE(SHA_START_REG, 1);
6070
}
6171

@@ -66,29 +76,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
6676
*/
6777
static inline void sha_ll_continue_block(esp_sha_type sha_type)
6878
{
69-
REG_WRITE(SHA_MODE_REG, sha_type);
79+
(void) sha_type;
7080
REG_WRITE(SHA_CONTINUE_REG, 1);
7181
}
7282

7383
/**
7484
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
75-
*
76-
* @param sha_type The SHA algorithm type
7785
*/
78-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
86+
static inline void sha_ll_start_dma(void)
7987
{
80-
REG_WRITE(SHA_MODE_REG, sha_type);
8188
REG_WRITE(SHA_DMA_START_REG, 1);
8289
}
8390

8491
/**
8592
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
86-
*
87-
* @param sha_type The SHA algorithm type
8893
*/
89-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
94+
static inline void sha_ll_continue_dma(void)
9095
{
91-
REG_WRITE(SHA_MODE_REG, sha_type);
9296
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
9397
}
9498

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ static inline void sha_ll_reset_register(void)
5151
sha_ll_reset_register(__VA_ARGS__); \
5252
} while(0)
5353

54+
/**
55+
* @brief Load the mode for the SHA engine
56+
*
57+
* @param sha_type The SHA algorithm type
58+
*/
59+
static inline void sha_ll_set_mode(esp_sha_type sha_type)
60+
{
61+
REG_WRITE(SHA_MODE_REG, sha_type);
62+
}
63+
5464
/**
5565
* @brief Start a new SHA block conversions (no initial hash in HW)
5666
*
5767
* @param sha_type The SHA algorithm type
5868
*/
5969
static inline void sha_ll_start_block(esp_sha_type sha_type)
6070
{
61-
REG_WRITE(SHA_MODE_REG, sha_type);
71+
(void) sha_type;
6272
REG_WRITE(SHA_START_REG, 1);
6373
}
6474

@@ -69,29 +79,23 @@ static inline void sha_ll_start_block(esp_sha_type sha_type)
6979
*/
7080
static inline void sha_ll_continue_block(esp_sha_type sha_type)
7181
{
72-
REG_WRITE(SHA_MODE_REG, sha_type);
82+
(void) sha_type;
7383
REG_WRITE(SHA_CONTINUE_REG, 1);
7484
}
7585

7686
/**
7787
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
78-
*
79-
* @param sha_type The SHA algorithm type
8088
*/
81-
static inline void sha_ll_start_dma(esp_sha_type sha_type)
89+
static inline void sha_ll_start_dma(void)
8290
{
83-
REG_WRITE(SHA_MODE_REG, sha_type);
8491
REG_WRITE(SHA_DMA_START_REG, 1);
8592
}
8693

8794
/**
8895
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
89-
*
90-
* @param sha_type The SHA algorithm type
9196
*/
92-
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
97+
static inline void sha_ll_continue_dma(void)
9398
{
94-
REG_WRITE(SHA_MODE_REG, sha_type);
9599
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
96100
}
97101

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

Lines changed: 34 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

@@ -168,6 +172,25 @@ static inline void sha_ll_write_digest(esp_sha_type sha_type, void *digest_state
168172
}
169173
}
170174

175+
/**
176+
* @brief Sets SHA512_t T_string parameter
177+
*
178+
* @param t_string T_string parameter
179+
*/
180+
static inline void sha_ll_t_string_set(uint32_t t_string)
181+
{
182+
REG_WRITE(SHA_T_STRING_REG, t_string);
183+
}
184+
185+
/**
186+
* @brief Sets SHA512_t T_string parameter's length
187+
*
188+
* @param t_len T_string parameter length
189+
*/
190+
static inline void sha_ll_t_len_set(uint8_t t_len)
191+
{
192+
REG_WRITE(SHA_T_LENGTH_REG, t_len);
193+
}
171194

172195
#ifdef __cplusplus
173196
}

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

0 commit comments

Comments
 (0)