From fe293dfd83fd99c137118f3ac1e396d5aecdca2a Mon Sep 17 00:00:00 2001 From: "harshal.patil" Date: Thu, 7 Dec 2023 14:54:11 +0530 Subject: [PATCH] feat(bootloader_support): Make `esp_secure_boot_verify_sbv2_signature_block()` function public Closes https://github.com/espressif/esp-idf/issues/12717 --- components/app_update/esp_ota_ops.c | 18 ---------- .../include/esp_secure_boot.h | 36 +++++++++++++++++++ .../private_include/bootloader_signature.h | 13 ------- .../src/bootloader_utility.c | 7 ---- .../bootloader_support/src/esp_image_format.c | 15 +------- tools/idf_py_actions/hints.yml | 4 +-- 6 files changed, 39 insertions(+), 54 deletions(-) diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index 232b112f1b6..130ca41a194 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -31,24 +31,6 @@ #include "esp_bootloader_desc.h" #include "esp_flash.h" -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32C3 -#include "esp32c3/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32S3 -#include "esp32s3/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32C2 -#include "esp32c2/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32C6 -#include "esp32c6/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32H2 -#include "esp32h2/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32P4 -#include "esp32p4/rom/secure_boot.h" -#endif - #define SUB_TYPE_ID(i) (i & 0x0F) /* Partial_data is word aligned so no reallocation is necessary for encrypted flash write */ diff --git a/components/bootloader_support/include/esp_secure_boot.h b/components/bootloader_support/include/esp_secure_boot.h index 9250ca0bd57..fdb757db3bb 100644 --- a/components/bootloader_support/include/esp_secure_boot.h +++ b/components/bootloader_support/include/esp_secure_boot.h @@ -15,6 +15,24 @@ #include "esp_rom_crc.h" #include "hal/efuse_ll.h" +#if CONFIG_IDF_TARGET_ESP32 +#include "esp32/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32S2 +#include "esp32s2/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32C3 +#include "esp32c3/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32C2 +#include "esp32c2/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32C6 +#include "esp32c6/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32H2 +#include "esp32h2/rom/secure_boot.h" +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/secure_boot.h" +#endif + #ifdef CONFIG_SECURE_BOOT_V1_ENABLED #if !defined(CONFIG_SECURE_SIGNED_ON_BOOT) || !defined(CONFIG_SECURE_SIGNED_ON_UPDATE) || !defined(CONFIG_SECURE_SIGNED_APPS) #error "internal sdkconfig error, secure boot should always enable all signature options" @@ -192,6 +210,24 @@ typedef struct { esp_err_t esp_secure_boot_verify_ecdsa_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest); #if !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_FULL >= 300 + +#if CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT + +/** @brief Verify the secure boot signature block for Secure Boot V2. + * + * Performs RSA-PSS or ECDSA verification of the SHA-256 image based on the public key + * in the signature block, compared against the public key digest stored in efuse. + * + * Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated. + * @param[in] sig_block Pointer to signature block data + * @param[in] image_digest Pointer to 32 byte buffer holding SHA-256 hash. + * @param[out] verified_digest Pointer to 32 byte buffer that will receive verified digest if verification completes. (Used during bootloader implementation only, result is invalid otherwise.) + * + */ +esp_err_t esp_secure_boot_verify_sbv2_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest); + +#endif /* CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT */ + /** * @brief Structure to hold public key digests calculated from the signature blocks of a single image. * diff --git a/components/bootloader_support/private_include/bootloader_signature.h b/components/bootloader_support/private_include/bootloader_signature.h index 3582db60647..1821995c7ad 100644 --- a/components/bootloader_support/private_include/bootloader_signature.h +++ b/components/bootloader_support/private_include/bootloader_signature.h @@ -31,19 +31,6 @@ #if CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT -/** @brief Verify the secure boot signature block for Secure Boot V2. - * - * Performs RSA-PSS or ECDSA verification of the SHA-256 image based on the public key - * in the signature block, compared against the public key digest stored in efuse. - * - * Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated. - * @param sig_block Pointer to signature block data - * @param image_digest Pointer to 32 byte buffer holding SHA-256 hash. - * @param verified_digest Pointer to 32 byte buffer that will receive verified digest if verification completes. (Used during bootloader implementation only, result is invalid otherwise.) - * - */ -esp_err_t esp_secure_boot_verify_sbv2_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest); - /** @brief Legacy function to verify RSA secure boot signature block for Secure Boot V2. * * @note This is kept for backward compatibility. It internally calls esp_secure_boot_verify_sbv2_signature_block. diff --git a/components/bootloader_support/src/bootloader_utility.c b/components/bootloader_support/src/bootloader_utility.c index 10100cb6fef..a1e688f67e4 100644 --- a/components/bootloader_support/src/bootloader_utility.c +++ b/components/bootloader_support/src/bootloader_utility.c @@ -17,34 +17,27 @@ #if CONFIG_IDF_TARGET_ESP32 #include "soc/dport_reg.h" #include "esp32/rom/cache.h" -#include "esp32/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32S3 -#include "esp32s3/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/efuse.h" #include "esp32c3/rom/crc.h" #include "esp32c3/rom/uart.h" -#include "esp32c3/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32C2 #include "esp32c2/rom/efuse.h" #include "esp32c2/rom/crc.h" #include "esp32c2/rom/rtc.h" #include "esp32c2/rom/uart.h" -#include "esp32c2/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32C6 #include "esp32c6/rom/efuse.h" #include "esp32c6/rom/crc.h" #include "esp32c6/rom/rtc.h" #include "esp32c6/rom/uart.h" -#include "esp32c6/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/efuse.h" #include "esp32h2/rom/crc.h" #include "esp32h2/rom/rtc.h" #include "esp32h2/rom/uart.h" -#include "esp32h2/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32P4 #else // CONFIG_IDF_TARGET_* diff --git a/components/bootloader_support/src/esp_image_format.c b/components/bootloader_support/src/esp_image_format.c index e45c6c2d7ec..67f4f7df4f4 100644 --- a/components/bootloader_support/src/esp_image_format.c +++ b/components/bootloader_support/src/esp_image_format.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -22,26 +21,14 @@ #include "bootloader_memory_utils.h" #include "soc/soc_caps.h" #include "hal/cache_ll.h" -#if CONFIG_IDF_TARGET_ESP32 -#include "esp32/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32S3 -#include "esp32s3/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32C3 -#include "esp32c3/rom/secure_boot.h" -#elif CONFIG_IDF_TARGET_ESP32C2 +#if CONFIG_IDF_TARGET_ESP32C2 #include "esp32c2/rom/rtc.h" -#include "esp32c2/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32C6 #include "esp32c6/rom/rtc.h" -#include "esp32c6/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32H2 #include "esp32h2/rom/rtc.h" -#include "esp32h2/rom/secure_boot.h" #elif CONFIG_IDF_TARGET_ESP32P4 #include "esp32p4/rom/rtc.h" -#include "esp32p4/rom/secure_boot.h" #endif #define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1)) diff --git a/tools/idf_py_actions/hints.yml b/tools/idf_py_actions/hints.yml index 05585eed9bf..9cb3dd3845d 100644 --- a/tools/idf_py_actions/hints.yml +++ b/tools/idf_py_actions/hints.yml @@ -55,8 +55,8 @@ hint_variables: ['esp_spiram_get_chip_size and esp_spiram_get_size', 'esp_psram_get_size()'] - - re: "error: implicit declaration of function 'esp_secure_boot_verify_sbv2_signature_block|esp_secure_boot_verify_rsa_signature_block'" - hint: "'esp_secure_boot_verify_sbv2_signature_block()' and 'esp_secure_boot_verify_rsa_signature_block()' and have been made private and are no longer available." + re: "error: implicit declaration of function 'esp_secure_boot_verify_rsa_signature_block'" + hint: "'esp_secure_boot_verify_rsa_signature_block()' has been made private and is no longer available." - re: "error: implicit declaration of function '{}'"