bootloader_signature.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include "sdkconfig.h"
  8. #include <esp_err.h>
  9. #include <stdint.h>
  10. #if CONFIG_IDF_TARGET_ESP32
  11. #include "esp32/rom/secure_boot.h"
  12. #elif CONFIG_IDF_TARGET_ESP32S2
  13. #include "esp32s2/rom/secure_boot.h"
  14. #elif CONFIG_IDF_TARGET_ESP32C3
  15. #include "esp32c3/rom/secure_boot.h"
  16. #elif CONFIG_IDF_TARGET_ESP32S3
  17. #include "esp32s3/rom/secure_boot.h"
  18. #elif CONFIG_IDF_TARGET_ESP32C2
  19. #include "esp32c2/rom/secure_boot.h"
  20. #elif CONFIG_IDF_TARGET_ESP32C6
  21. #include "esp32c6/rom/secure_boot.h"
  22. #elif CONFIG_IDF_TARGET_ESP32H2
  23. #include "esp32h2/rom/secure_boot.h"
  24. #elif CONFIG_IDF_TARGET_ESP32P4
  25. #include "esp32p4/rom/secure_boot.h"
  26. #endif
  27. #if !CONFIG_IDF_TARGET_ESP32 || CONFIG_ESP32_REV_MIN_FULL >= 300
  28. #if CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT
  29. /** @brief Verify the secure boot signature block for Secure Boot V2.
  30. *
  31. * Performs RSA-PSS or ECDSA verification of the SHA-256 image based on the public key
  32. * in the signature block, compared against the public key digest stored in efuse.
  33. *
  34. * Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated.
  35. * @param sig_block Pointer to signature block data
  36. * @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
  37. * @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.)
  38. *
  39. */
  40. 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);
  41. /** @brief Legacy function to verify RSA secure boot signature block for Secure Boot V2.
  42. *
  43. * @note This is kept for backward compatibility. It internally calls esp_secure_boot_verify_sbv2_signature_block.
  44. *
  45. * @param sig_block Pointer to RSA signature block data
  46. * @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
  47. * @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.)
  48. *
  49. */
  50. esp_err_t esp_secure_boot_verify_rsa_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest);
  51. #endif /* CONFIG_SECURE_BOOT_V2_ENABLED || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT */
  52. #endif