arch/xtensa: Add arch layer SHA accelerator support for esp32[-s2|-s3]

Add arch layer SHA accelerator support for Xtensa based Espressif devices

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
This commit is contained in:
Eren Terzioglu
2025-05-20 14:45:24 +02:00
committed by Xiang Xiao
parent d2eb3db5b6
commit 2e4eaf69ee
7 changed files with 1973 additions and 0 deletions
+7
View File
@@ -61,6 +61,13 @@ config ESPRESSIF_LEDC
select PWM select PWM
select ARCH_HAVE_PWM_MULTICHAN select ARCH_HAVE_PWM_MULTICHAN
config ESPRESSIF_SHA_ACCELERATOR
bool "SHA Accelerator"
depends on !ARCH_CHIP_ESP32
default n
---help---
Enable SHA accelerator support.
config ESPRESSIF_I2S config ESPRESSIF_I2S
bool bool
default n default n
@@ -84,6 +84,13 @@ ifeq ($(CONFIG_ESPRESSIF_DEDICATED_GPIO),y)
CHIP_CSRCS += esp_dedic_gpio.c CHIP_CSRCS += esp_dedic_gpio.c
endif endif
ifeq ($(CONFIG_ESPRESSIF_SHA_ACCELERATOR),y)
CHIP_CSRCS += esp_sha.c
ifeq ($(CONFIG_CRYPTO_CRYPTODEV_HARDWARE),y)
CHIP_CSRCS += esp_crypto.c
endif
endif
ifeq ($(CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP_WO_TOOL),y) ifeq ($(CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP_WO_TOOL),y)
CHIP_CSRCS += esp_nxdiag.c CHIP_CSRCS += esp_nxdiag.c
endif endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+360
View File
@@ -0,0 +1,360 @@
/****************************************************************************
* arch/xtensa/src/common/espressif/esp_sha.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_COMMON_ESPRESSIF_ESP_SHA_H
#define __ARCH_XTENSA_SRC_COMMON_ESPRESSIF_ESP_SHA_H
#include <nuttx/config.h>
#include <stdint.h>
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Types
****************************************************************************/
enum esp_sha_type_e
{
ESP_SHA1_1 = 0,
ESP_SHA2_224,
ESP_SHA2_256,
ESP_SHA3_384,
ESP_SHA3_512,
ESP_SHA_TYPE_MAX
};
enum esp_sha_state_e
{
ESP_SHA_STATE_INIT,
ESP_SHA_STATE_IN_PROCESS
};
/* SHA-1 context structure */
struct esp_sha1_context_s
{
uint32_t total[2]; /* number of bytes processed */
uint32_t state[5]; /* intermediate digest state */
unsigned char buffer[64]; /* data block being processed */
bool first_block; /* if first then true, else false */
enum esp_sha_type_e mode;
enum esp_sha_state_e sha_state;
};
/* SHA-256 context structure */
struct esp_sha256_context_s
{
uint32_t total[2]; /* number of bytes processed */
uint32_t state[8]; /* intermediate digest state */
unsigned char buffer[64]; /* data block being processed */
bool first_block; /* if first then true, else false */
enum esp_sha_type_e mode;
enum esp_sha_state_e sha_state;
};
/* SHA-512 context structure */
struct esp_sha512_context_s
{
uint64_t total[2]; /* number of bytes processed */
uint64_t state[8]; /* intermediate digest state */
unsigned char buffer[128]; /* data block being processed */
bool first_block; /* if first then true, else false */
enum esp_sha_type_e mode;
enum esp_sha_state_e sha_state;
};
/****************************************************************************
* Name: esp_sha_init
*
* Description:
* Initialize ESP32-C3 SHA hardware.
*
* Input Parameters:
* None
*
* Returned Value:
* OK is returned on success. Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha_init(void);
/****************************************************************************
* Name: esp_sha1_init
*
* Description:
* Initializes a SHA-1 context.
*
* Input Parameters:
* ctx - The SHA-1 context to initialize
*
* Returned Value:
* None.
*
****************************************************************************/
void esp_sha1_init(struct esp_sha1_context_s *ctx);
/****************************************************************************
* Name: esp_sha1_starts
*
* Description:
* Starts a SHA-1 checksum calculation.
*
* Input Parameters:
* ctx - The SHA-1 context to initialize
*
* Returned Value:
* OK is returned on success.
*
****************************************************************************/
int esp_sha1_starts(struct esp_sha1_context_s *ctx);
/****************************************************************************
* Name: esp_sha1_update
*
* Description:
* Feeds an input buffer into an ongoing SHA-1 checksum calculation.
*
* Input Parameters:
* ctx - The SHA-1 context to use
* input - The buffer holding the input data
* ilen - The length of the input data in Bytes
*
* Returned Value:
* OK is returned on success.
* Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha1_update(struct esp_sha1_context_s *ctx,
const unsigned char *input,
size_t ilen);
/****************************************************************************
* Name: esp_sha1_finish
*
* Description:
* Finishes the SHA-1 operation,
* and writes the result to the output buffer.
*
* Input Parameters:
* ctx - The SHA-1 context to use
* output - The SHA-1 checksum result
*
* Returned Value:
* OK is returned on success.
* Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha1_finish(struct esp_sha1_context_s *ctx,
unsigned char output[20]);
/****************************************************************************
* Name: esp_sha256_init
*
* Description:
* Initializes a SHA-256 context.
*
* Input Parameters:
* ctx - The SHA-256 context to initialize
*
* Returned Value:
* None.
*
****************************************************************************/
void esp_sha256_init(struct esp_sha256_context_s *ctx);
/****************************************************************************
* Name: esp_sha256_starts
*
* Description:
* Starts a SHA-224 or SHA-256 checksum calculation.
*
* Input Parameters:
* ctx - The SHA-256 context to initialize
* is224 - Determines which function to use
*
* Returned Value:
* OK is returned on success.
*
****************************************************************************/
int esp_sha256_starts(struct esp_sha256_context_s *ctx, bool is224);
/****************************************************************************
* Name: esp_sha256_update
*
* Description:
* Feeds an input buffer into an ongoing SHA-224 or SHA-256
* checksum calculation.
*
* Input Parameters:
* ctx - The SHA-256 context to use
* input - The buffer holding the input data
* ilen - The length of the input data in Bytes
*
* Returned Value:
* OK is returned on success.
* Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha256_update(struct esp_sha256_context_s *ctx,
const unsigned char *input,
size_t ilen);
/****************************************************************************
* Name: esp_sha256_finish
*
* Description:
* Finishes the SHA-224 or SHA-256 operation, and writes the result to
* the output buffer.
*
* Input Parameters:
* ctx - The SHA-256 context to use
* output - The SHA-256 checksum result
*
* Returned Value:
* OK is returned on success.
* Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha256_finish(struct esp_sha256_context_s *ctx,
unsigned char output[32]);
/****************************************************************************
* Name: esp_sha512_init
*
* Description:
* Initializes a SHA-512 context.
*
* Input Parameters:
* ctx - The SHA-512 context to initialize
*
* Returned Value:
* None.
*
****************************************************************************/
void esp_sha512_init(struct esp_sha512_context_s *ctx);
/****************************************************************************
* Name: esp_sha512_starts
*
* Description:
* Starts a SHA-384 or SHA-512 checksum calculation.
*
* Input Parameters:
* ctx - The SHA-512 context to initialize
* is384 - Determines which function to use
*
* Returned Value:
* OK is returned on success.
*
****************************************************************************/
int esp_sha512_starts(struct esp_sha512_context_s *ctx, bool is384);
/****************************************************************************
* Name: esp_sha512_update
*
* Description:
* Feeds an input buffer into an ongoing SHA-384 or SHA-512
* checksum calculation.
*
* Input Parameters:
* ctx - The SHA-512 context to use
* input - The buffer holding the input data
* ilen - The length of the input data in Bytes
*
* Returned Value:
* OK is returned on success.
* Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha512_update(struct esp_sha512_context_s *ctx,
const unsigned char *input,
size_t ilen);
/****************************************************************************
* Name: esp_sha512_finish
*
* Description:
* Finishes the SHA-384 or SHA-512 operation, and writes the result to
* the output buffer.
*
* Input Parameters:
* ctx - The SHA-512 context to use
* output - The SHA-512 checksum result
*
* Returned Value:
* OK is returned on success.
* Otherwise, a negated errno value is returned.
*
****************************************************************************/
int esp_sha512_finish(struct esp_sha512_context_s *ctx,
unsigned char output[64]);
/****************************************************************************
* Name: esp_sha512_free
*
* Description:
* Clears a SHA-512 context.
*
* Input Parameters:
*
* Returned Value:
* None.
*
****************************************************************************/
void esp_sha512_free(struct esp_sha512_context_s *ctx);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_COMMON_ESPRESSIF_ESP_SHA_H */
+2
View File
@@ -158,9 +158,11 @@ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)rmt_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)rmt_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)sdm_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)sdm_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)i2s_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)i2s_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)sha_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)timer_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)timer_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)uart_hal_iram.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)uart_hal_iram.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)uart_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)uart_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)dport_access_common.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)adc_periph.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)adc_periph.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)dedic_gpio_periph.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)dedic_gpio_periph.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)gpio_periph.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)gpio_periph.c
+2
View File
@@ -148,6 +148,7 @@ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)rmt_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)rmt_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)sdm_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)sdm_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)i2s_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)i2s_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)sha_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)mcpwm_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)mcpwm_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)timer_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)timer_hal.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)cache_hal.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)hal$(DELIM)cache_hal.c
@@ -165,6 +166,7 @@ CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log$
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log$(DELIM)src$(DELIM)noos$(DELIM)log_timestamp.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log$(DELIM)src$(DELIM)noos$(DELIM)log_timestamp.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log$(DELIM)src$(DELIM)os$(DELIM)log_write.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)log$(DELIM)src$(DELIM)os$(DELIM)log_write.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)mbedtls$(DELIM)port$(DELIM)sha$(DELIM)core$(DELIM)esp_sha256.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)mbedtls$(DELIM)port$(DELIM)sha$(DELIM)core$(DELIM)esp_sha256.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)dport_access_common.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)dedic_gpio_periph.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)dedic_gpio_periph.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)gdma_periph.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)gdma_periph.c
CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)adc_periph.c CHIP_CSRCS += chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)soc$(DELIM)$(CHIP_SERIES)$(DELIM)adc_periph.c