-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/esp32c5_add_hal_layer_for_key_manager' into 'ma…
…ster' Feature/esp32c5 add hal layer for key manager See merge request espressif/esp-idf!33955
- Loading branch information
Showing
15 changed files
with
639 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef _KM_H | ||
#define _KM_H | ||
|
||
#include "soc/soc_caps.h" | ||
#if SOC_KEY_MANAGER_SUPPORTED | ||
|
||
#include <stdint.h> | ||
#include "soc/soc.h" | ||
#include "ets_sys.h" | ||
|
||
#if __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* huk mode type */ | ||
typedef enum { | ||
HUK_MODE_RECOVER = 0, | ||
HUK_MODE_GEN = 1, | ||
} huk_mode_t; | ||
|
||
/** | ||
* @brief Recover efuse key or key manager key if flash encryption is enabled | ||
* | ||
* @param do_log : if km process print log | ||
* | ||
* @return ETS_OK when key is recovered, ETS_FAILED when key not recovered | ||
*/ | ||
ETS_STATUS esp_rom_check_recover_key(int do_log); | ||
|
||
/** | ||
* @brief Configure huk mode | ||
* | ||
* @param mode : HUK_MODE_RECOVER or HUK_MODE_GEN | ||
* | ||
* @param huk_info : uint8_t pointer to the buffer which will feed the huk info or | ||
* gain the huk info | ||
* | ||
* @return ETS_OK when huk configuration is done, else ETS_FAILED | ||
*/ | ||
ETS_STATUS esp_rom_km_huk_conf(huk_mode_t mode, uint8_t *huk_info); | ||
|
||
/** | ||
* @brief Get huk risk. The risk level of HUK is 0-6: the higher the risk level is, | ||
* the more error bits there are in the PUF SRAM. 7: Error level, HUK is invalid | ||
* | ||
* @param None | ||
* | ||
* @return The huk risk | ||
*/ | ||
int esp_rom_km_huk_risk(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* SOC_KEY_MANAGER_SUPPORTED */ | ||
|
||
#endif /* _KM_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/******************************************************************************* | ||
* NOTICE | ||
* The hal is not public api, don't use it in application code. | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "soc/soc_caps.h" | ||
|
||
#if SOC_KEY_MANAGER_SUPPORTED | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#include "hal/huk_types.h" | ||
#include "soc/huk_reg.h" | ||
#include "soc/soc_caps.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/* @brief Configure the HUK mode */ | ||
static inline void huk_ll_configure_mode(const esp_huk_mode_t huk_mode) | ||
{ | ||
REG_SET_FIELD(HUK_CONF_REG, HUK_MODE, huk_mode); | ||
} | ||
|
||
static inline void huk_ll_write_info(const uint8_t *buffer, const size_t size) | ||
{ | ||
memcpy((uint8_t *)HUK_INFO_MEM, buffer, size); | ||
} | ||
|
||
static inline void huk_ll_read_info(uint8_t *buffer, const size_t size) | ||
{ | ||
memcpy(buffer, (uint8_t *)HUK_INFO_MEM, size); | ||
} | ||
|
||
/* @brief Start the HUK at IDLE state */ | ||
static inline void huk_ll_start(void) | ||
{ | ||
REG_SET_FIELD(HUK_START_REG, HUK_START, 1); | ||
} | ||
|
||
/* @brief Continue HUK operation at LOAD/GAIN state */ | ||
static inline void huk_ll_continue(void) | ||
{ | ||
REG_SET_FIELD(HUK_START_REG, HUK_CONTINUE, 1); | ||
} | ||
|
||
/* @bried Enable or Disable the HUK interrupts */ | ||
static inline void huk_ll_configure_interrupt(const esp_huk_interrupt_type_t intr, const bool en) | ||
{ | ||
switch(intr) { | ||
case ESP_HUK_INT_PREP_DONE: | ||
REG_SET_FIELD(HUK_INT_ENA_REG, HUK_PREP_DONE_INT_ENA, en); | ||
case ESP_HUK_INT_PROC_DONE: | ||
REG_SET_FIELD(HUK_INT_ENA_REG, HUK_PROC_DONE_INT_ENA, en); | ||
case ESP_HUK_INT_POST_DONE: | ||
REG_SET_FIELD(HUK_INT_ENA_REG, HUK_POST_DONE_INT_ENA, en); | ||
default: | ||
return; | ||
} | ||
} | ||
|
||
/* @bried Clear the HUK interrupts */ | ||
static inline void huk_ll_clear_int(const esp_huk_interrupt_type_t intr) | ||
{ | ||
switch(intr) { | ||
case ESP_HUK_INT_PREP_DONE: | ||
REG_SET_FIELD(HUK_INT_CLR_REG, HUK_PREP_DONE_INT_CLR, 1); | ||
case ESP_HUK_INT_PROC_DONE: | ||
REG_SET_FIELD(HUK_INT_CLR_REG, HUK_PROC_DONE_INT_CLR, 1); | ||
case ESP_HUK_INT_POST_DONE: | ||
REG_SET_FIELD(HUK_INT_CLR_REG, HUK_POST_DONE_INT_CLR, 1); | ||
default: | ||
return; | ||
} | ||
} | ||
|
||
/** | ||
* @brief Read state of Hardware Unique Key Generator | ||
* | ||
* @return esp_huk_state_t | ||
*/ | ||
static inline esp_huk_state_t huk_ll_get_state(void) | ||
{ | ||
return (esp_huk_state_t) REG_GET_FIELD(HUK_STATE_REG, HUK_STATE); | ||
} | ||
|
||
/** | ||
* @brief Get the HUK generation status | ||
*/ | ||
static inline esp_huk_gen_status_t huk_ll_get_gen_status(void) | ||
{ | ||
return (esp_huk_gen_status_t) REG_GET_FIELD(HUK_STATUS_REG, HUK_STATUS); | ||
} | ||
|
||
/** | ||
* @brief Read the HUK date information | ||
*/ | ||
static inline uint32_t huk_ll_get_date_info(void) | ||
{ | ||
// Only the least significant 28 bits have desired information | ||
return (uint32_t)(0x0FFFFFFF & REG_READ(HUK_DATE_REG)); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
Oops, something went wrong.