Skip to content

Commit

Permalink
Merge branch 'feature/add_dma_suppport_for_aes_and_sha' into 'master'
Browse files Browse the repository at this point in the history
feat(hal/testapps): Added AES and SHA testcases with DMA support

Closes IDF-7986 and IDF-7987

See merge request espressif/esp-idf!26497
  • Loading branch information
mahavirj committed Feb 13, 2024
2 parents 70b1ebe + aab3f60 commit 4d90eed
Show file tree
Hide file tree
Showing 23 changed files with 1,516 additions and 181 deletions.
8 changes: 8 additions & 0 deletions components/hal/.build-test-rules.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
components/hal/test_apps/crypto:
disable_test:
- if: IDF_TARGET == "esp32p4"
temporary: true
reason: test not pass, should be re-enable # TODO: IDF-8982
depends_components:
- efuse

components/hal/test_apps/hal_i2c:
disable:
- if: SOC_I2C_SUPPORTED != 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# The mbedtls component gets pulled in during the build(due to a dependency of component bootloader_support),
# but we needed to avoid inclusion of mbedtls in this hal layer test app, thus creating a "dummy" mbedtls component.
# This dummy mbedtls component will get the priority during the build stage and thus the "real" mbedtls component
# does not get pulled.
#
idf_build_get_property(idf_target IDF_TARGET)
idf_build_get_property(python PYTHON)

set(mbedtls_srcs ".")
set(mbedtls_include_dirs include)

idf_component_register(SRCS "${mbedtls_srcs}"
INCLUDE_DIRS "${mbedtls_include_dirs}")
11 changes: 11 additions & 0 deletions components/hal/test_apps/crypto/components/mbedtls/include/aes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -1
#define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -2
#define MBEDTLS_ERR_AES_BAD_INPUT_DATA -3

#define MBEDTLS_AES_ENCRYPT ESP_AES_ENCRYPT
#define MBEDTLS_AES_DECRYPT ESP_AES_DECRYPT
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
typedef int mbedtls_cipher_id_t;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stddef.h>

static inline void mbedtls_platform_zeroize( void *buf, size_t len )
{
bzero(buf, len);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stddef.h>
#include <stdint.h>

typedef void *bootloader_sha256_handle_t;

bootloader_sha256_handle_t bootloader_sha256_start(void);

void bootloader_sha256_data(bootloader_sha256_handle_t handle, const void *data, size_t data_len);

void bootloader_sha256_finish(bootloader_sha256_handle_t handle, uint8_t *digest);

typedef void mbedtls_sha256_context;

void mbedtls_sha256_init(mbedtls_sha256_context *ctx);

void mbedtls_sha256_free(mbedtls_sha256_context *ctx);

int mbedtls_sha256_starts(mbedtls_sha256_context *ctx, int is224);

int mbedtls_sha256_update(mbedtls_sha256_context *ctx,
const unsigned char *input,
size_t ilen);
int mbedtls_sha256_finish(mbedtls_sha256_context *ctx,
unsigned char *output);
35 changes: 29 additions & 6 deletions components/hal/test_apps/crypto/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(srcs "app_main.c")
set(priv_include_dirs ".")

if(CONFIG_SOC_MPI_SUPPORTED)
list(APPEND srcs "mpi/test_mpi.c")
Expand All @@ -21,19 +22,41 @@ if(CONFIG_SOC_ECDSA_SUPPORTED)
endif()

if(CONFIG_SOC_AES_SUPPORTED)
list(APPEND srcs "aes/aes_block.c")
list(APPEND srcs "aes/test_aes_block.c")
list(APPEND srcs "aes/test_aes.c"
"$ENV{IDF_PATH}/components/mbedtls/port/aes/esp_aes_common.c"
"aes/aes_block.c")
list(APPEND priv_include_dirs "$ENV{IDF_PATH}/components/mbedtls/port/include")

if(CONFIG_SOC_AES_SUPPORT_DMA)
list(APPEND priv_include_dirs "$ENV{IDF_PATH}/components/mbedtls/port/aes/dma/include")
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/aes/dma/esp_aes.c")

if(NOT CONFIG_SOC_AES_GDMA)
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/aes/dma/esp_aes_crypto_dma_impl.c")
else()
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/aes/dma/esp_aes_gdma_impl.c"
"$ENV{IDF_PATH}/components/mbedtls/port/crypto_shared_gdma/esp_crypto_shared_gdma.c")
endif()

if(CONFIG_SOC_AES_SUPPORT_GCM)
list(APPEND srcs "$ENV{IDF_PATH}/components/mbedtls/port/aes/esp_aes_gcm.c")
endif()
endif()
endif()

if(CONFIG_SOC_SHA_SUPPORTED)
if(NOT CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG)
list(APPEND srcs "sha/sha_block.c")
list(APPEND srcs "sha/test_sha_block.c")
list(APPEND srcs "sha/test_sha.c"
"sha/sha_block.c")
if(CONFIG_SOC_SHA_SUPPORT_DMA)
list(APPEND srcs "sha/sha_dma.c")
endif()
endif()
endif()

idf_component_register(SRCS ${srcs}
PRIV_REQUIRES efuse
PRIV_REQUIRES efuse mbedtls
REQUIRES test_utils unity
WHOLE_ARCHIVE
PRIV_INCLUDE_DIRS ".")
PRIV_INCLUDE_DIRS "${priv_include_dirs}"
)
8 changes: 8 additions & 0 deletions components/hal/test_apps/crypto/main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

menu "Test App Configuration"

config CRYPTO_TEST_APP_ENABLE_DS_TESTS
Expand All @@ -19,4 +20,11 @@ menu "Test App Configuration"
help
Enabling this option includes ECDSA Peripheral related test cases in the build for supported targets.

config CRYPTO_TESTAPP_USE_AES_INTERRUPT
bool "Use interrupt for long AES operations"
depends on SOC_AES_SUPPORTED
default n
help
Use an interrupt to coordinate long AES operations.

endmenu
Loading

0 comments on commit 4d90eed

Please sign in to comment.