Skip to content

Commit 56dc272

Browse files
committed
Merge branch 'feature/esp32h2_secure_boot' into 'master'
esp32h2: add secure boot feature support Closes IDF-6281 and IDF-6681 See merge request espressif/esp-idf!22625
2 parents afbdb0f + 11e034b commit 56dc272

File tree

10 files changed

+82
-30
lines changed

10 files changed

+82
-30
lines changed

components/app_update/esp_ota_ops.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "esp32c2/rom/secure_boot.h"
4444
#elif CONFIG_IDF_TARGET_ESP32C6
4545
#include "esp32c6/rom/secure_boot.h"
46+
#elif CONFIG_IDF_TARGET_ESP32H2
47+
#include "esp32h2/rom/secure_boot.h"
4648
#endif
4749

4850
#define SUB_TYPE_ID(i) (i & 0x0F)

components/bootloader_support/src/esp32h2/bootloader_sha.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -24,7 +24,11 @@ bootloader_sha256_handle_t bootloader_sha256_start()
2424
void bootloader_sha256_data(bootloader_sha256_handle_t handle, const void *data, size_t data_len)
2525
{
2626
assert(handle != NULL);
27-
assert(data_len % 4 == 0);
27+
/* H2 secure boot key field consists of 1 byte of curve identifier and 64 bytes of ECDSA public key.
28+
* While verifying the signature block, we need to calculate the SHA of this key field which is of 65 bytes.
29+
* ets_sha_update handles it cleanly so we can safely remove the check:
30+
* assert(data_len % 4) == 0
31+
*/
2832
ets_sha_update(&ctx, data, data_len, false);
2933
}
3034

components/bootloader_support/src/secure_boot_v2/secure_boot.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,8 @@
1414
#include "esp_image_format.h"
1515
#include "esp_efuse.h"
1616
#include "esp_efuse_table.h"
17+
#include "secure_boot_signature_priv.h"
1718

18-
#if CONFIG_IDF_TARGET_ESP32
19-
#include "esp32/rom/secure_boot.h"
20-
#elif CONFIG_IDF_TARGET_ESP32S2
21-
#include "esp32s2/rom/secure_boot.h"
22-
#elif CONFIG_IDF_TARGET_ESP32C3
23-
#include "esp32c3/rom/secure_boot.h"
24-
#elif CONFIG_IDF_TARGET_ESP32S3
25-
#include "esp32s3/rom/secure_boot.h"
26-
#elif CONFIG_IDF_TARGET_ESP32H4
27-
#include "esp32h4/rom/secure_boot.h"
28-
#elif CONFIG_IDF_TARGET_ESP32C2
29-
#include "esp32c2/rom/secure_boot.h"
30-
#elif CONFIG_IDF_TARGET_ESP32C6
31-
#include "esp32c6/rom/secure_boot.h"
32-
#endif
3319

3420
/* The following API implementations are used only when called
3521
* from the bootloader code.

components/bootloader_support/src/secure_boot_v2/secure_boot_signature_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "esp32c2/rom/secure_boot.h"
2020
#elif CONFIG_IDF_TARGET_ESP32C6
2121
#include "esp32c6/rom/secure_boot.h"
22+
#elif CONFIG_IDF_TARGET_ESP32H2
23+
#include "esp32h2/rom/secure_boot.h"
2224
#endif
2325

2426
esp_err_t verify_ecdsa_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, const ets_secure_boot_sig_block_t *trusted_block);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
#define ETS_DIGEST_LEN 32 /* SHA-256, bytes */
16+
17+
typedef enum {
18+
ECDSA_CURVE_P192 = 1,
19+
ECDSA_CURVE_P256 = 2
20+
} ECDSA_CURVE;
21+
22+
int ets_ecdsa_verify(const uint8_t *key, const uint8_t *sig, ECDSA_CURVE curve_id, const uint8_t *digest, uint8_t *verified_digest);
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif

components/esp_rom/include/esp32h2/rom/secure_boot.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -9,13 +9,16 @@
99
#include <stdint.h>
1010
#include <stdbool.h>
1111
#include "ets_sys.h"
12+
#include "ecdsa.h"
1213
#include "rsa_pss.h"
1314
#include "esp_assert.h"
1415

1516
#ifdef __cplusplus
1617
extern "C" {
1718
#endif
1819

20+
#if CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT
21+
1922
typedef struct ets_secure_boot_sig_block ets_secure_boot_sig_block_t;
2023
typedef struct ets_secure_boot_signature ets_secure_boot_signature_t;
2124
typedef struct ets_secure_boot_key_digests ets_secure_boot_key_digests_t;
@@ -69,6 +72,8 @@ void ets_secure_boot_revoke_public_key_digest(int index);
6972
7073
(Up to 3 in a signature sector are appended to the image)
7174
*/
75+
#if CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
76+
7277
struct ets_secure_boot_sig_block {
7378
uint8_t magic_byte;
7479
uint8_t version;
@@ -81,6 +86,27 @@ struct ets_secure_boot_sig_block {
8186
uint8_t _padding[16];
8287
};
8388

89+
#elif CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME
90+
91+
struct __attribute((packed)) ets_secure_boot_sig_block {
92+
uint8_t magic_byte;
93+
uint8_t version;
94+
uint8_t _reserved1;
95+
uint8_t _reserved2;
96+
uint8_t image_digest[32];
97+
struct {
98+
struct {
99+
uint8_t curve_id; /* ETS_ECDSA_CURVE_P192 / ETS_ECDSA_CURVE_P256 */
100+
uint8_t point[64]; /* X followed by Y (both little-endian), plus zero bytes if P192 */
101+
} key;
102+
uint8_t signature[64]; /* r followed by s (both little-endian) */
103+
uint8_t padding[1031];
104+
} ecdsa;
105+
uint32_t block_crc; /* note: crc covers all bytes in the structure before it, regardless of version field */
106+
uint8_t _padding[16];
107+
};
108+
#endif
109+
84110
ESP_STATIC_ASSERT(sizeof(ets_secure_boot_sig_block_t) == 1216, "invalid sig block size");
85111

86112
#define SECURE_BOOT_NUM_BLOCKS 3
@@ -100,6 +126,8 @@ struct ets_secure_boot_key_digests {
100126
bool allow_key_revoke;
101127
};
102128

129+
#endif /* CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT */
130+
103131
#ifdef __cplusplus
104132
}
105133
#endif

components/soc/esp32h2/include/soc/Kconfig.soc_caps.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ config SOC_TEMP_SENSOR_SUPPORTED
5959
bool
6060
default y
6161

62+
config SOC_SUPPORTS_SECURE_DL_MODE
63+
bool
64+
default y
65+
6266
config SOC_EFUSE_KEY_PURPOSE_FIELD
6367
bool
6468
default y
@@ -131,6 +135,10 @@ config SOC_FLASH_ENC_SUPPORTED
131135
bool
132136
default y
133137

138+
config SOC_SECURE_BOOT_SUPPORTED
139+
bool
140+
default y
141+
134142
config SOC_BOD_SUPPORTED
135143
bool
136144
default y

components/soc/esp32h2/include/soc/soc_caps.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define SOC_IEEE802154_BLE_ONLY 1
4040
#define SOC_USB_SERIAL_JTAG_SUPPORTED 1
4141
#define SOC_TEMP_SENSOR_SUPPORTED 1
42-
// #define SOC_SUPPORTS_SECURE_DL_MODE 1 // TODO: IDF-6281
42+
#define SOC_SUPPORTS_SECURE_DL_MODE 1
4343
//#define SOC_RISCV_COPROC_SUPPORTED 1 // TODO: IDF-6272
4444
#define SOC_EFUSE_KEY_PURPOSE_FIELD 1
4545
#define SOC_RTC_FAST_MEM_SUPPORTED 1
@@ -60,7 +60,7 @@
6060
#define SOC_HMAC_SUPPORTED 1
6161
#define SOC_DIG_SIGN_SUPPORTED 1
6262
#define SOC_FLASH_ENC_SUPPORTED 1
63-
// #define SOC_SECURE_BOOT_SUPPORTED 1 // TODO: IDF-6281
63+
#define SOC_SECURE_BOOT_SUPPORTED 1
6464
#define SOC_BOD_SUPPORTED 1
6565
#define SOC_APM_SUPPORTED 1
6666
#define SOC_PMU_SUPPORTED 1
@@ -397,7 +397,6 @@
397397
#define SOC_EFUSE_DIS_DIRECT_BOOT 1
398398
#define SOC_EFUSE_SOFT_DIS_JTAG 1
399399

400-
// TODO: IDF-6281 (Copy from esp32c6, need check)
401400
/*-------------------------- Secure Boot CAPS----------------------------*/
402401
#define SOC_SECURE_BOOT_V2_RSA 1
403402
#define SOC_SECURE_BOOT_V2_ECC 1

docs/docs_not_updated/esp32h2.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ api-reference/protocols/mdns
118118
api-reference/protocols/index
119119
api-reference/protocols/asio
120120
security/esp32h2_log.inc
121-
security/security
122-
security/secure-boot-v2
123-
security/secure-boot-v1
124121
about
125122
resources
126123
migration-guides/release-5.x/5.1/index

docs/en/security/secure-boot-v2.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
Secure Boot V2
44
==============
55

6-
{IDF_TARGET_SBV2_SCHEME:default="RSA-PSS", esp32c2="ECDSA", esp32c6="RSA-PSS or ECDSA"}
6+
{IDF_TARGET_SBV2_SCHEME:default="RSA-PSS", esp32c2="ECDSA", esp32c6 or esp32h2="RSA-PSS or ECDSA"}
77

8-
{IDF_TARGET_SBV2_KEY:default="RSA-3072", esp32c2="ECDSA-256 or ECDSA-192", esp32c6="RSA-3072, ECDSA-256, or ECDSA-192"}
8+
{IDF_TARGET_SBV2_KEY:default="RSA-3072", esp32c2="ECDSA-256 or ECDSA-192", esp32c6 or esp32h2="RSA-3072, ECDSA-256, or ECDSA-192"}
99

10-
{IDF_TARGET_SECURE_BOOT_OPTION_TEXT:default="", esp32c6="RSA is recommended because of faster verification time. You can choose between RSA and ECDSA scheme from the menu."}
10+
{IDF_TARGET_SECURE_BOOT_OPTION_TEXT:default="", esp32c6 or esp32h2="RSA is recommended because of faster verification time. You can choose between RSA and ECDSA scheme from the menu."}
1111

1212
{IDF_TARGET_ECO_VERSION:default="", esp32="(ECO 3 onwards)", esp32c3="(ECO 3 onwards)"}
1313

14-
{IDF_TARGET_RSA_TIME:default="", esp32c6="~2.7 ms"}
14+
{IDF_TARGET_RSA_TIME:default="", esp32c6="~2.7 ms", esp32h2="~4.5 ms"}
1515

16-
{IDF_TARGET_ECDSA_TIME:default="", esp32c6="~21.5 ms"}
16+
{IDF_TARGET_ECDSA_TIME:default="", esp32c6="~21.5 ms", esp32h2="~36 ms"}
1717

18-
{IDF_TARGET_CPU_FREQ:default="", esp32c6="160 MHz"}
18+
{IDF_TARGET_CPU_FREQ:default="", esp32c6="160 MHz", esp32h2="96 MHz"}
1919

2020
{IDF_TARGET_SBV2_DEFAULT_SCHEME:default="RSA", esp32c2="ECDSA (V2)"}
2121

0 commit comments

Comments
 (0)