From a5f1820120bfc4f058c0a58d26eadec073cd60d4 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 29 Jun 2022 14:13:35 +0530 Subject: [PATCH] esp_hw_support: Merge esp_hmac.h file for different targets into one --- .../include/{soc/esp32c3 => }/esp_hmac.h | 20 ++-- .../include/soc/esp32c6/esp_hmac.h | 92 ------------------ .../include/soc/esp32h2/esp_hmac.h | 92 ------------------ .../include/soc/esp32s2/esp_hmac.h | 95 ------------------- .../include/soc/esp32s3/esp_hmac.h | 87 ----------------- 5 files changed, 11 insertions(+), 375 deletions(-) rename components/esp_hw_support/include/{soc/esp32c3 => }/esp_hmac.h (88%) delete mode 100644 components/esp_hw_support/include/soc/esp32c6/esp_hmac.h delete mode 100644 components/esp_hw_support/include/soc/esp32h2/esp_hmac.h delete mode 100644 components/esp_hw_support/include/soc/esp32s2/esp_hmac.h delete mode 100644 components/esp_hw_support/include/soc/esp32s3/esp_hmac.h diff --git a/components/esp_hw_support/include/soc/esp32c3/esp_hmac.h b/components/esp_hw_support/include/esp_hmac.h similarity index 88% rename from components/esp_hw_support/include/soc/esp32c3/esp_hmac.h rename to components/esp_hw_support/include/esp_hmac.h index c35d9a34f9..5bb3a01cf0 100644 --- a/components/esp_hw_support/include/soc/esp32c3/esp_hmac.h +++ b/components/esp_hw_support/include/esp_hmac.h @@ -4,11 +4,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _ESP_HMAC_H_ -#define _ESP_HMAC_H_ +#pragma once #include #include "esp_err.h" +#include "soc/soc_caps.h" + +#if !SOC_HMAC_SUPPORTED && !CI_HEADER_CHECK +#error "HMAC peripheral is not supported for the selected target" +#endif #ifdef __cplusplus extern "C" { @@ -32,7 +36,7 @@ typedef enum { * Calculate the HMAC of a given message. * * Calculate the HMAC \c hmac of a given message \c message with length \c message_len. - * SHA256 is used for the calculation (fixed on ESP32S2). + * SHA256 is used for the calculation. * * @note Uses the HMAC peripheral in "upstream" mode. * @@ -40,7 +44,7 @@ typedef enum { * The corresponding purpose field of the key block in the efuse must be set to the HMAC upstream purpose value. * @param message the message for which to calculate the HMAC * @param message_len message length - * return ESP_ERR_INVALID_STATE if unsuccessful + * return ESP_ERR_INVALID_STATE if unsuccessful * @param [out] hmac the hmac result; the buffer behind the provided pointer must be a writeable buffer of 32 bytes * * @return @@ -49,9 +53,9 @@ typedef enum { * * ESP_FAIL, if the hmac calculation failed */ esp_err_t esp_hmac_calculate(hmac_key_id_t key_id, - const void *message, - size_t message_len, - uint8_t *hmac); + const void *message, + size_t message_len, + uint8_t *hmac); /** * @brief Use HMAC peripheral in Downstream mode to re-enable the JTAG, if it is not permanently disabled by HW. @@ -88,5 +92,3 @@ esp_err_t esp_hmac_jtag_disable(void); #ifdef __cplusplus } #endif - -#endif // _ESP_HMAC_H_ diff --git a/components/esp_hw_support/include/soc/esp32c6/esp_hmac.h b/components/esp_hw_support/include/soc/esp32c6/esp_hmac.h deleted file mode 100644 index 635834d594..0000000000 --- a/components/esp_hw_support/include/soc/esp32c6/esp_hmac.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _ESP_HMAC_H_ -#define _ESP_HMAC_H_ - -#include -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The possible efuse keys for the HMAC peripheral - */ -typedef enum { - HMAC_KEY0 = 0, - HMAC_KEY1, - HMAC_KEY2, - HMAC_KEY3, - HMAC_KEY4, - HMAC_KEY5, - HMAC_KEY_MAX -} hmac_key_id_t; - -/** - * @brief - * Calculate the HMAC of a given message. - * - * Calculate the HMAC \c hmac of a given message \c message with length \c message_len. - * SHA256 is used for the calculation (fixed on ESP32S2). - * - * @note Uses the HMAC peripheral in "upstream" mode. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calcuation. - * The corresponding purpose field of the key block in the efuse must be set to the HMAC upstream purpose value. - * @param message the message for which to calculate the HMAC - * @param message_len message length - * return ESP_ERR_INVALID_STATE if unsuccessful - * @param [out] hmac the hmac result; the buffer behind the provided pointer must be a writeable buffer of 32 bytes - * - * @return - * * ESP_OK, if the calculation was successful, - * * ESP_ERR_INVALID_ARG if message or hmac is a nullptr or if key_id out of range - * * ESP_FAIL, if the hmac calculation failed - */ -esp_err_t esp_hmac_calculate(hmac_key_id_t key_id, - const void *message, - size_t message_len, - uint8_t *hmac); - -/** - * @brief Use HMAC peripheral in Downstream mode to re-enable the JTAG, if it is not permanently disabled by HW. - * In downstream mode, HMAC calculations performed by peripheral are used internally and not provided back to user. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calculation. - * The corresponding purpose field of the key block in the efuse must be set to HMAC downstream purpose. - * - * @param token Pre calculated HMAC value of the 32-byte 0x00 using SHA-256 and the known private HMAC key. The key is already - * programmed to a eFuse key block. The key block number is provided as the first parameter to this function. - * - * @return - * * ESP_OK, if the key_purpose of the key_id matches to HMAC downstread mode, - * The API returns success even if calculated HMAC does not match with the provided token. - * However, The JTAG will be re-enabled only if the calculated HMAC value matches with provided token, - * otherwise JTAG will remain disabled. - * * ESP_FAIL, if the key_purpose of the key_id is not set to HMAC downstream purpose - * or JTAG is permanently disabled by EFUSE_HARD_DIS_JTAG eFuse parameter. - * * ESP_ERR_INVALID_ARG, invalid input arguments - * - * @note Return value of the API does not indicate the JTAG status. - */ -esp_err_t esp_hmac_jtag_enable(hmac_key_id_t key_id, const uint8_t *token); - -/** - * @brief Disable the JTAG which might be enabled using the HMAC downstream mode. This function just clears the result generated - * by calling esp_hmac_jtag_enable() API. - * - * @return - * * ESP_OK return ESP_OK after writing the HMAC_SET_INVALIDATE_JTAG_REG with value 1. - */ -esp_err_t esp_hmac_jtag_disable(void); - -#ifdef __cplusplus -} -#endif - -#endif // _ESP_HMAC_H_ diff --git a/components/esp_hw_support/include/soc/esp32h2/esp_hmac.h b/components/esp_hw_support/include/soc/esp32h2/esp_hmac.h deleted file mode 100644 index c35d9a34f9..0000000000 --- a/components/esp_hw_support/include/soc/esp32h2/esp_hmac.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _ESP_HMAC_H_ -#define _ESP_HMAC_H_ - -#include -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The possible efuse keys for the HMAC peripheral - */ -typedef enum { - HMAC_KEY0 = 0, - HMAC_KEY1, - HMAC_KEY2, - HMAC_KEY3, - HMAC_KEY4, - HMAC_KEY5, - HMAC_KEY_MAX -} hmac_key_id_t; - -/** - * @brief - * Calculate the HMAC of a given message. - * - * Calculate the HMAC \c hmac of a given message \c message with length \c message_len. - * SHA256 is used for the calculation (fixed on ESP32S2). - * - * @note Uses the HMAC peripheral in "upstream" mode. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calcuation. - * The corresponding purpose field of the key block in the efuse must be set to the HMAC upstream purpose value. - * @param message the message for which to calculate the HMAC - * @param message_len message length - * return ESP_ERR_INVALID_STATE if unsuccessful - * @param [out] hmac the hmac result; the buffer behind the provided pointer must be a writeable buffer of 32 bytes - * - * @return - * * ESP_OK, if the calculation was successful, - * * ESP_ERR_INVALID_ARG if message or hmac is a nullptr or if key_id out of range - * * ESP_FAIL, if the hmac calculation failed - */ -esp_err_t esp_hmac_calculate(hmac_key_id_t key_id, - const void *message, - size_t message_len, - uint8_t *hmac); - -/** - * @brief Use HMAC peripheral in Downstream mode to re-enable the JTAG, if it is not permanently disabled by HW. - * In downstream mode, HMAC calculations performed by peripheral are used internally and not provided back to user. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calculation. - * The corresponding purpose field of the key block in the efuse must be set to HMAC downstream purpose. - * - * @param token Pre calculated HMAC value of the 32-byte 0x00 using SHA-256 and the known private HMAC key. The key is already - * programmed to a eFuse key block. The key block number is provided as the first parameter to this function. - * - * @return - * * ESP_OK, if the key_purpose of the key_id matches to HMAC downstread mode, - * The API returns success even if calculated HMAC does not match with the provided token. - * However, The JTAG will be re-enabled only if the calculated HMAC value matches with provided token, - * otherwise JTAG will remain disabled. - * * ESP_FAIL, if the key_purpose of the key_id is not set to HMAC downstream purpose - * or JTAG is permanently disabled by EFUSE_HARD_DIS_JTAG eFuse parameter. - * * ESP_ERR_INVALID_ARG, invalid input arguments - * - * @note Return value of the API does not indicate the JTAG status. - */ -esp_err_t esp_hmac_jtag_enable(hmac_key_id_t key_id, const uint8_t *token); - -/** - * @brief Disable the JTAG which might be enabled using the HMAC downstream mode. This function just clears the result generated - * by calling esp_hmac_jtag_enable() API. - * - * @return - * * ESP_OK return ESP_OK after writing the HMAC_SET_INVALIDATE_JTAG_REG with value 1. - */ -esp_err_t esp_hmac_jtag_disable(void); - -#ifdef __cplusplus -} -#endif - -#endif // _ESP_HMAC_H_ diff --git a/components/esp_hw_support/include/soc/esp32s2/esp_hmac.h b/components/esp_hw_support/include/soc/esp32s2/esp_hmac.h deleted file mode 100644 index f54054fb14..0000000000 --- a/components/esp_hw_support/include/soc/esp32s2/esp_hmac.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _ESP_HMAC_H_ -#define _ESP_HMAC_H_ - -#include "esp_err.h" -#include "stdbool.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The possible efuse keys for the HMAC peripheral - */ -typedef enum { - HMAC_KEY0 = 0, - HMAC_KEY1, - HMAC_KEY2, - HMAC_KEY3, - HMAC_KEY4, - HMAC_KEY5, - HMAC_KEY_MAX -} hmac_key_id_t; - -/** - * @brief - * Calculate the HMAC of a given message. - * - * Calculate the HMAC \c hmac of a given message \c message with length \c message_len. - * SHA256 is used for the calculation (fixed on ESP32S2). - * - * @note Uses the HMAC peripheral in "upstream" mode. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calcuation. - * The corresponding purpose field of the key block in the efuse must be set to the HMAC upstream purpose value. - * @param message the message for which to calculate the HMAC - * @param message_len message length - * return ESP_ERR_INVALID_STATE if unsuccessful - * @param [out] hmac the hmac result; the buffer behind the provided pointer must be a writeable buffer of 32 bytes - * - * @return - * * ESP_OK, if the calculation was successful, - * * ESP_ERR_INVALID_ARG if message or hmac is a nullptr or if key_id out of range - * * ESP_FAIL, if the hmac calculation failed - */ -esp_err_t esp_hmac_calculate(hmac_key_id_t key_id, - const void *message, - size_t message_len, - uint8_t *hmac); - -/** - * @brief - * Use HMAC peripheral in Downstream mode to re-enable the JTAG, if it is not permanently disable by HW. - * In downstream mode HMAC calculations perfomred by peripheral used internally and not provided back to user. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calculation. - * The corresponding purpose field of the key block in the efuse must be set to HMAC downstream purpose. - * - * @param token Pre calculated HMAC value of the 32-byte 0x00 using SHA-256 and the known private HMAC key. The key is already - * programmed to a eFuse key block. The key block number is provided as the first parameter to this function. - * - * @return - * * ESP_OK, if the key_purpose of the key_id matches to HMAC downstread mode, - * The API returns success even if calculated HMAC does not match with the provided token. - * However, The JTAG will be re-enabled only if the calculated HMAC value matches with provided token, - * otherwise JTAG will remain disabled. - * * ESP_FAIL, if the key_purpose of the key_id is not set to HMAC downstream purpose - * or JTAG is permanently disabled by EFUSE_HARD_DIS_JTAG eFuse parameter. - * * ESP_ERR_INVALID_ARG, invalid input arguments - * - * @note Return value of the API does not indicate the JTAG status. - */ -esp_err_t esp_hmac_jtag_enable(hmac_key_id_t key_id, - const uint8_t *token); - -/** - * @brief - * Disable the JTAG which might be enable using the HMAC downstream mode. This function just clear the result generated by - * JTAG key by calling esp_hmac_jtag_enable() API. - * - * @return - * * ESP_OK return ESP_OK after writing the HMAC_SET_INVALIDATE_JTAG_REG with value 1. - */ -esp_err_t esp_hmac_jtag_disable(void); - -#ifdef __cplusplus -} -#endif - -#endif // _ESP_HMAC_H_ diff --git a/components/esp_hw_support/include/soc/esp32s3/esp_hmac.h b/components/esp_hw_support/include/soc/esp32s3/esp_hmac.h deleted file mode 100644 index f6d7300812..0000000000 --- a/components/esp_hw_support/include/soc/esp32s3/esp_hmac.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "esp_err.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The possible efuse keys for the HMAC peripheral - */ -typedef enum { - HMAC_KEY0 = 0, - HMAC_KEY1, - HMAC_KEY2, - HMAC_KEY3, - HMAC_KEY4, - HMAC_KEY5, - HMAC_KEY_MAX -} hmac_key_id_t; - -/** - * @brief - * Calculate the HMAC of a given message. - * - * Calculate the HMAC \c hmac of a given message \c message with length \c message_len. - * SHA256 is used for the calculation (fixed on ESP32S3). - * - * @note Uses the HMAC peripheral in "upstream" mode. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calcuation. - * The corresponding purpose field of the key block in the efuse must be set to the HMAC upstream purpose value. - * @param message the message for which to calculate the HMAC - * @param message_len message length - * @param [out] hmac the hmac result; the buffer behind the provided pointer must be a writeable buffer of 32 bytes - * - * @return - * * ESP_OK, if the calculation was successful, - * * ESP_ERR_INVALID_ARG if message or hmac is a nullptr or if key_id out of range - * * ESP_FAIL, if the hmac calculation failed - */ -esp_err_t esp_hmac_calculate(hmac_key_id_t key_id, - const void *message, - size_t message_len, - uint8_t *hmac); - -/** - * @brief Use HMAC peripheral in Downstream mode to re-enable the JTAG, if it is not permanently disabled by HW. - * In downstream mode, HMAC calculations performed by peripheral are used internally and not provided back to user. - * - * @param key_id Determines which of the 6 key blocks in the efuses should be used for the HMAC calculation. - * The corresponding purpose field of the key block in the efuse must be set to HMAC downstream purpose. - * - * @param token Pre calculated HMAC value of the 32-byte 0x00 using SHA-256 and the known private HMAC key. The key is already - * programmed to a eFuse key block. The key block number is provided as the first parameter to this function. - * - * @return - * * ESP_OK, if the key_purpose of the key_id matches to HMAC downstread mode, - * The API returns success even if calculated HMAC does not match with the provided token. - * However, The JTAG will be re-enabled only if the calculated HMAC value matches with provided token, - * otherwise JTAG will remain disabled. - * * ESP_FAIL, if the key_purpose of the key_id is not set to HMAC downstream purpose - * or JTAG is permanently disabled by EFUSE_HARD_DIS_JTAG eFuse parameter. - * * ESP_ERR_INVALID_ARG, invalid input arguments - * - * @note Return value of the API does not indicate the JTAG status. - */ -esp_err_t esp_hmac_jtag_enable(hmac_key_id_t key_id, const uint8_t *token); - -/** - * @brief Disable the JTAG which might be enabled using the HMAC downstream mode. This function just clears the result generated - * by calling esp_hmac_jtag_enable() API. - * - * @return - * * ESP_OK return ESP_OK after writing the HMAC_SET_INVALIDATE_JTAG_REG with value 1. - */ -esp_err_t esp_hmac_jtag_disable(void); - -#ifdef __cplusplus -} -#endif