mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(hal): Update HAL layer for Key manager
1)Added new clk related changes
This commit is contained in:
parent
3eabb62850
commit
5a1726c18c
@ -9,11 +9,15 @@
|
||||
#include "hal/huk_types.h"
|
||||
#include "hal/huk_hal.h"
|
||||
#include "esp_key_mgr.h"
|
||||
#include "hal/clk_gate_ll.h"
|
||||
#include "esp_private/periph_ctrl.h"
|
||||
#include "hal/key_mgr_ll.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_err.h"
|
||||
#include "assert.h"
|
||||
#include "string.h"
|
||||
#include "esp_heap_caps.h"
|
||||
|
||||
#define KEY_MANAGER_RCC_ATOMIC() PERIPH_RCC_ATOMIC()
|
||||
|
||||
static const char *TAG = "esp_key_mgr";
|
||||
static void key_mgr_wait_for_state(esp_key_mgr_state_t state)
|
||||
@ -27,14 +31,17 @@ esp_err_t esp_key_mgr_deploy_key_in_aes_mode(esp_key_mgr_aes_key_config_t *key_c
|
||||
{
|
||||
ESP_LOGI(TAG, "Key Deployment");
|
||||
// Reset the Key Manager Clock
|
||||
periph_ll_enable_clk_clear_rst(PERIPH_KEY_MANAGER_MODULE);
|
||||
KEY_MANAGER_RCC_ATOMIC() {
|
||||
key_mgr_ll_enable_bus_clock(true);
|
||||
key_mgr_ll_reset_register();
|
||||
}
|
||||
|
||||
key_mgr_wait_for_state(ESP_KEY_MGR_STATE_IDLE);
|
||||
uint8_t *huk_recovery_info = (uint8_t *) calloc(1, sizeof(KEY_MGR_HUK_INFO_SIZE));
|
||||
uint8_t *huk_recovery_info = (uint8_t *) heap_caps_calloc(1, KEY_MGR_HUK_INFO_SIZE, MALLOC_CAP_INTERNAL);
|
||||
if (!huk_recovery_info) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
uint8_t *key_recovery_info = (uint8_t *) calloc(1, sizeof(KEY_MGR_KEY_RECOVERY_INFO_SIZE));
|
||||
uint8_t *key_recovery_info = (uint8_t *) heap_caps_calloc(1, KEY_MGR_KEY_RECOVERY_INFO_SIZE, MALLOC_CAP_INTERNAL);
|
||||
if (!key_recovery_info) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
@ -100,15 +107,23 @@ esp_err_t esp_key_mgr_deploy_key_in_aes_mode(esp_key_mgr_aes_key_config_t *key_c
|
||||
//memcpy(&key_info->huk_recovery_info[0], huk_recovery_info, KEY_MGR_HUK_INFO_SIZE);
|
||||
//memcpy(&key_info->key_recovery_info[0], key_recovery_info, KEY_MGR_KEY_RECOVERY_INFO_SIZE);
|
||||
key_info->key_purpose = key_config->key_purpose;
|
||||
free(key_recovery_info);
|
||||
free(huk_recovery_info);
|
||||
heap_caps_free(key_recovery_info);
|
||||
heap_caps_free(huk_recovery_info);
|
||||
key_mgr_hal_set_key_usage(ESP_KEY_MGR_XTS_KEY, ESP_KEY_MGR_USE_OWN_KEY);
|
||||
KEY_MANAGER_RCC_ATOMIC() {
|
||||
key_mgr_ll_enable_bus_clock(false);
|
||||
key_mgr_ll_reset_register();
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_key_mgr_recover_key(esp_key_mgr_key_recovery_info_t *key_recovery_info)
|
||||
{
|
||||
periph_ll_enable_clk_clear_rst(PERIPH_KEY_MANAGER_MODULE);
|
||||
KEY_MANAGER_RCC_ATOMIC() {
|
||||
key_mgr_ll_enable_bus_clock(true);
|
||||
key_mgr_ll_reset_register();
|
||||
}
|
||||
|
||||
key_mgr_wait_for_state(ESP_KEY_MGR_STATE_IDLE);
|
||||
huk_hal_configure(ESP_HUK_MODE_RECOVERY, key_recovery_info->huk_recovery_info);
|
||||
if (key_mgr_hal_is_huk_valid()) {
|
||||
@ -132,6 +147,10 @@ esp_err_t esp_key_mgr_recover_key(esp_key_mgr_key_recovery_info_t *key_recovery_
|
||||
ESP_LOGI(TAG, "Key deployment valid");
|
||||
key_mgr_hal_continue();
|
||||
key_mgr_wait_for_state(ESP_KEY_MGR_STATE_IDLE);
|
||||
KEY_MANAGER_RCC_ATOMIC() {
|
||||
key_mgr_ll_enable_bus_clock(false);
|
||||
key_mgr_ll_reset_register();
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@ -139,14 +158,17 @@ esp_err_t esp_key_mgr_deploy_key_in_ecdh0_mode(esp_key_mgr_ecdh0_key_config_t *k
|
||||
{
|
||||
ESP_LOGI(TAG, "Key Deployment");
|
||||
// Reset the Key Manager Clock
|
||||
periph_ll_enable_clk_clear_rst(PERIPH_KEY_MANAGER_MODULE);
|
||||
KEY_MANAGER_RCC_ATOMIC() {
|
||||
key_mgr_ll_enable_bus_clock(true);
|
||||
key_mgr_ll_reset_register();
|
||||
}
|
||||
|
||||
key_mgr_wait_for_state(ESP_KEY_MGR_STATE_IDLE);
|
||||
uint8_t *huk_recovery_info = (uint8_t *) calloc(1, sizeof(KEY_MGR_HUK_INFO_SIZE));
|
||||
uint8_t *huk_recovery_info = (uint8_t *) heap_caps_calloc(1, KEY_MGR_HUK_INFO_SIZE, MALLOC_CAP_INTERNAL);
|
||||
if (!huk_recovery_info) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
uint8_t *key_recovery_info = (uint8_t *) calloc(1, sizeof(KEY_MGR_KEY_RECOVERY_INFO_SIZE));
|
||||
uint8_t *key_recovery_info = (uint8_t *) heap_caps_calloc(1, KEY_MGR_KEY_RECOVERY_INFO_SIZE, MALLOC_CAP_INTERNAL);
|
||||
if (!key_recovery_info) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
@ -212,8 +234,13 @@ esp_err_t esp_key_mgr_deploy_key_in_ecdh0_mode(esp_key_mgr_ecdh0_key_config_t *k
|
||||
//memcpy(&key_info->huk_recovery_info[0], huk_recovery_info, KEY_MGR_HUK_INFO_SIZE);
|
||||
//memcpy(&key_info->key_recovery_info[0], key_recovery_info, KEY_MGR_KEY_RECOVERY_INFO_SIZE);
|
||||
key_info->key_purpose = key_config->key_purpose;
|
||||
free(key_recovery_info);
|
||||
free(huk_recovery_info);
|
||||
key_mgr_hal_set_key_usage(ESP_KEY_MGR_XTS_KEY, ESP_KEY_MGR_USE_OWN_KEY);
|
||||
heap_caps_free(key_recovery_info);
|
||||
heap_caps_free(huk_recovery_info);
|
||||
ESP_LOGI(TAG, "\nKey deployment complete\n");
|
||||
//key_mgr_hal_set_key_usage(ESP_KEY_MGR_XTS_KEY, ESP_KEY_MGR_USE_OWN_KEY);
|
||||
KEY_MANAGER_RCC_ATOMIC() {
|
||||
key_mgr_ll_enable_bus_clock(false);
|
||||
key_mgr_ll_reset_register();
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ extern "C" {
|
||||
#define KEY_MGR_SW_INIT_KEY_SIZE 32
|
||||
#define KEY_MGR_ASSIST_INFO_SIZE 64
|
||||
#define KEY_MGR_KEY_RECOVERY_INFO_SIZE 64
|
||||
#define KEY_MGR_HUK_INFO_SIZE 64
|
||||
#define KEY_MGR_HUK_INFO_SIZE HUK_INFO_SIZE
|
||||
/* AES deploy mode */
|
||||
#define KEY_MGR_K2_INFO_SIZE 64
|
||||
#define KEY_MGR_K1_ENCRYPTED_SIZE 32
|
||||
@ -76,7 +76,7 @@ esp_err_t esp_key_mgr_deploy_key_in_aes_mode(esp_key_mgr_aes_key_config_t *key_c
|
||||
* ESP_OK for success
|
||||
* ESP_FAIL/relevant error code for failure
|
||||
*/
|
||||
esp_err_t esp_key_mgr_deploy_key_in_aes_mode(esp_key_mgr_aes_key_config_t *key_config, esp_key_mgr_key_recovery_info_t *key_info);
|
||||
esp_err_t esp_key_mgr_deploy_key_in_ecdh0_mode(esp_key_mgr_ecdh0_key_config_t *key_config, esp_key_mgr_key_recovery_info_t *key_info);
|
||||
|
||||
/*
|
||||
* @brief Recover a key from the given key info
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -12,8 +12,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#if SOC_KEY_MANAGER_SUPPORTED
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
@ -32,12 +32,12 @@ static inline void huk_ll_configure_mode(const esp_huk_mode_t huk_mode)
|
||||
REG_SET_FIELD(HUK_CONF_REG, HUK_MODE, huk_mode);
|
||||
}
|
||||
|
||||
void huk_ll_write_info(const uint8_t *buffer, const size_t size)
|
||||
static inline void huk_ll_write_info(const uint8_t *buffer, const size_t size)
|
||||
{
|
||||
memcpy((uint8_t *)HUK_INFO_MEM, buffer, size);
|
||||
}
|
||||
|
||||
void huk_ll_read_info(uint8_t *buffer, const size_t size)
|
||||
static inline void huk_ll_read_info(uint8_t *buffer, const size_t size)
|
||||
{
|
||||
memcpy(buffer, (uint8_t *)HUK_INFO_MEM, size);
|
||||
}
|
||||
@ -91,15 +91,15 @@ static inline void huk_ll_clear_int(const esp_huk_interrupt_type_t intr)
|
||||
*/
|
||||
static inline esp_huk_state_t huk_ll_get_state(void)
|
||||
{
|
||||
return REG_GET_FIELD(HUK_STATE_REG, HUK_STATE);
|
||||
return (esp_huk_state_t) REG_GET_FIELD(HUK_STATE_REG, HUK_STATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the HUK generation status: esp_huk_gen_status_t
|
||||
* @brief Get the HUK generation status
|
||||
*/
|
||||
static inline esp_huk_gen_status_t huk_ll_get_gen_status(void)
|
||||
{
|
||||
return REG_GET_FIELD(HUK_STATUS_REG, HUK_STATUS);
|
||||
return (esp_huk_gen_status_t) REG_GET_FIELD(HUK_STATUS_REG, HUK_STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,9 +10,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#if SOC_KEY_MANAGER_SUPPORTED
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "hal/assert.h"
|
||||
#include "hal/log.h"
|
||||
#include "rom/km.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
esp_huk_state_t huk_hal_get_state(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user