mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(mbedtls): fixes incorrect macro checks in PSA SHA driver
Closes https://github.com/espressif/esp-idf/issues/18354
This commit is contained in:
@@ -189,33 +189,39 @@
|
|||||||
with software fallback.
|
with software fallback.
|
||||||
*/
|
*/
|
||||||
#ifdef CONFIG_MBEDTLS_HARDWARE_SHA
|
#ifdef CONFIG_MBEDTLS_HARDWARE_SHA
|
||||||
#define ESP_SHA_DRIVER_ENABLED
|
#define ESP_SHA_DRIVER_ENABLED
|
||||||
#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
#define MBEDTLS_PSA_ACCEL_ALG_HMAC
|
||||||
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_1
|
#define MBEDTLS_PSA_BUILTIN_ALG_HMAC
|
||||||
#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
#if SOC_SHA_SUPPORT_SHA1
|
||||||
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_224
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#define MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_1
|
||||||
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_256
|
#undef MBEDTLS_SHA1_C
|
||||||
#undef MBEDTLS_SHA1_C
|
#endif // SOC_SHA_SUPPORT_SHA1
|
||||||
#undef MBEDTLS_SHA224_C
|
#if SOC_SHA_SUPPORT_SHA224
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
|
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_224
|
||||||
|
#undef MBEDTLS_SHA224_C
|
||||||
|
#endif // SOC_SHA_SUPPORT_SHA224
|
||||||
|
#if SOC_SHA_SUPPORT_SHA256
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
|
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_256
|
||||||
|
#endif // SOC_SHA_SUPPORT_SHA256
|
||||||
|
#if SOC_SHA_SUPPORT_SHA512
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
||||||
|
#define MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
|
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_512
|
||||||
|
#undef MBEDTLS_PSA_BUILTIN_ALG_SHA_384
|
||||||
|
#undef MBEDTLS_SHA512_C
|
||||||
|
#undef MBEDTLS_SHA384_C
|
||||||
|
#undef MBEDTLS_PSA_BUILTIN_ALG_HMAC
|
||||||
|
#else
|
||||||
|
#undef MBEDTLS_SHA512_ALT
|
||||||
|
#endif // SOC_SHA_SUPPORT_SHA512
|
||||||
#define ESP_HMAC_TRANSPARENT_DRIVER_ENABLED
|
#define ESP_HMAC_TRANSPARENT_DRIVER_ENABLED
|
||||||
#define MBEDTLS_PSA_ACCEL_ALG_HMAC
|
|
||||||
#define MBEDTLS_PSA_BUILTIN_ALG_HMAC
|
|
||||||
#if SOC_SHA_SUPPORT_SHA512
|
|
||||||
#define MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
|
||||||
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
|
||||||
#define MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
|
||||||
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
|
||||||
#undef MBEDTLS_SHA512_C
|
|
||||||
#undef MBEDTLS_SHA384_C
|
|
||||||
#undef MBEDTLS_PSA_BUILTIN_ALG_HMAC
|
|
||||||
#else
|
#else
|
||||||
#undef MBEDTLS_SHA512_ALT
|
#undef MBEDTLS_SHA1_ALT
|
||||||
#endif
|
#undef MBEDTLS_SHA256_ALT
|
||||||
#else
|
#undef MBEDTLS_SHA512_ALT
|
||||||
#undef MBEDTLS_SHA1_ALT
|
|
||||||
#undef MBEDTLS_SHA256_ALT
|
|
||||||
#undef MBEDTLS_SHA512_ALT
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* MBEDTLS_MDx_ALT to enable ROM MD support
|
/* MBEDTLS_MDx_ALT to enable ROM MD support
|
||||||
@@ -2581,6 +2587,7 @@
|
|||||||
#define PSA_WANT_ALG_SHA_1 1
|
#define PSA_WANT_ALG_SHA_1 1
|
||||||
#else
|
#else
|
||||||
#undef PSA_WANT_ALG_SHA_1
|
#undef PSA_WANT_ALG_SHA_1
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* \def MBEDTLS_SHA224_C
|
* \def MBEDTLS_SHA224_C
|
||||||
@@ -2619,6 +2626,7 @@
|
|||||||
#define PSA_WANT_ALG_SHA_512 1
|
#define PSA_WANT_ALG_SHA_512 1
|
||||||
#else
|
#else
|
||||||
#undef PSA_WANT_ALG_SHA_512
|
#undef PSA_WANT_ALG_SHA_512
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2639,6 +2647,7 @@
|
|||||||
#define PSA_WANT_ALG_SHA_384 1
|
#define PSA_WANT_ALG_SHA_384 1
|
||||||
#else
|
#else
|
||||||
#undef PSA_WANT_ALG_SHA_384
|
#undef PSA_WANT_ALG_SHA_384
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2662,7 +2671,9 @@
|
|||||||
#define PSA_WANT_ALG_SHA_224 1
|
#define PSA_WANT_ALG_SHA_224 1
|
||||||
#else
|
#else
|
||||||
#undef PSA_WANT_ALG_SHA_256
|
#undef PSA_WANT_ALG_SHA_256
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
#undef PSA_WANT_ALG_SHA_224
|
#undef PSA_WANT_ALG_SHA_224
|
||||||
|
#undef MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* MBEDTLS_MD_CAN_SHA* macros indicate whether a hash algorithm is available
|
/* MBEDTLS_MD_CAN_SHA* macros indicate whether a hash algorithm is available
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -23,8 +23,23 @@
|
|||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
|
||||||
static int esp_sha_driver_check_supported_algorithm(psa_algorithm_t alg) {
|
static int esp_sha_driver_check_supported_algorithm(psa_algorithm_t alg) {
|
||||||
if (alg == PSA_ALG_SHA_1 || alg == PSA_ALG_SHA_256 || alg == PSA_ALG_SHA_224 ||
|
if (0
|
||||||
alg == PSA_ALG_SHA_512 || alg == PSA_ALG_SHA_384) {
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
|
|| alg == PSA_ALG_SHA_1
|
||||||
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
|
|| alg == PSA_ALG_SHA_224
|
||||||
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
|
|| alg == PSA_ALG_SHA_256
|
||||||
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
|
|| alg == PSA_ALG_SHA_384
|
||||||
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
||||||
|
|| alg == PSA_ALG_SHA_512
|
||||||
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_512
|
||||||
|
) {
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
return ESP_ERR_NOT_SUPPORTED;
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
@@ -67,36 +82,36 @@ psa_status_t esp_sha_hash_compute(
|
|||||||
|
|
||||||
size_t hash_length_calculated = 0;
|
size_t hash_length_calculated = 0;
|
||||||
switch(alg) {
|
switch(alg) {
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA1
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
case PSA_ALG_SHA_1:
|
case PSA_ALG_SHA_1:
|
||||||
esp_sha1_context sha1_ctx = {0};
|
esp_sha1_context sha1_ctx = {0};
|
||||||
ret = esp_sha1_driver_compute(&sha1_ctx, input, input_length, hash, hash_size, &hash_length_calculated);
|
ret = esp_sha1_driver_compute(&sha1_ctx, input, input_length, hash, hash_size, &hash_length_calculated);
|
||||||
memset(&sha1_ctx, 0, sizeof(sha1_ctx));
|
memset(&sha1_ctx, 0, sizeof(sha1_ctx));
|
||||||
*hash_length = hash_length_calculated;
|
*hash_length = hash_length_calculated;
|
||||||
break;
|
break;
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA1
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
case PSA_ALG_SHA_224:
|
case PSA_ALG_SHA_224:
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA256
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
case PSA_ALG_SHA_256:
|
case PSA_ALG_SHA_256:
|
||||||
esp_sha256_context sha256_ctx = {0};
|
esp_sha256_context sha256_ctx = {0};
|
||||||
ret = esp_sha256_driver_compute(&sha256_ctx, alg, input, input_length, hash, hash_size, &hash_length_calculated);
|
ret = esp_sha256_driver_compute(&sha256_ctx, alg, input, input_length, hash, hash_size, &hash_length_calculated);
|
||||||
memset(&sha256_ctx, 0, sizeof(sha256_ctx));
|
memset(&sha256_ctx, 0, sizeof(sha256_ctx));
|
||||||
*hash_length = hash_length_calculated;
|
*hash_length = hash_length_calculated;
|
||||||
break;
|
break;
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA256
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_256
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
case PSA_ALG_SHA_384:
|
case PSA_ALG_SHA_384:
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA512
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
case PSA_ALG_SHA_512:
|
case PSA_ALG_SHA_512:
|
||||||
esp_sha512_context sha512_ctx = {0};
|
esp_sha512_context sha512_ctx = {0};
|
||||||
ret = esp_sha512_driver_compute(&sha512_ctx, alg, input, input_length, hash, hash_size, &hash_length_calculated);
|
ret = esp_sha512_driver_compute(&sha512_ctx, alg, input, input_length, hash, hash_size, &hash_length_calculated);
|
||||||
memset(&sha512_ctx, 0, sizeof(sha512_ctx));
|
memset(&sha512_ctx, 0, sizeof(sha512_ctx));
|
||||||
*hash_length = hash_length_calculated;
|
*hash_length = hash_length_calculated;
|
||||||
break;
|
break;
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA512
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
default:
|
default:
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
@@ -112,7 +127,7 @@ psa_status_t esp_sha_hash_setup(esp_sha_hash_operation_t *operation, psa_algorit
|
|||||||
if (!operation) {
|
if (!operation) {
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA1
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
if (alg == PSA_ALG_SHA_1) {
|
if (alg == PSA_ALG_SHA_1) {
|
||||||
esp_sha1_context *sha1_ctx = heap_caps_malloc(sizeof(esp_sha1_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
esp_sha1_context *sha1_ctx = heap_caps_malloc(sizeof(esp_sha1_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
||||||
if (!sha1_ctx) {
|
if (!sha1_ctx) {
|
||||||
@@ -123,12 +138,12 @@ psa_status_t esp_sha_hash_setup(esp_sha_hash_operation_t *operation, psa_algorit
|
|||||||
operation->sha_type = ESP_SHA_OPERATION_TYPE_SHA1;
|
operation->sha_type = ESP_SHA_OPERATION_TYPE_SHA1;
|
||||||
return esp_sha1_starts(sha1_ctx);
|
return esp_sha1_starts(sha1_ctx);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA1
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA256
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224)
|
||||||
if (
|
if (
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
alg == PSA_ALG_SHA_224 ||
|
alg == PSA_ALG_SHA_224 ||
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
alg == PSA_ALG_SHA_256) {
|
alg == PSA_ALG_SHA_256) {
|
||||||
esp_sha256_context *sha256_ctx = heap_caps_malloc(sizeof(esp_sha256_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
esp_sha256_context *sha256_ctx = heap_caps_malloc(sizeof(esp_sha256_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
||||||
if (!sha256_ctx) {
|
if (!sha256_ctx) {
|
||||||
@@ -137,21 +152,21 @@ psa_status_t esp_sha_hash_setup(esp_sha_hash_operation_t *operation, psa_algorit
|
|||||||
memset(sha256_ctx, 0, sizeof(esp_sha256_context));
|
memset(sha256_ctx, 0, sizeof(esp_sha256_context));
|
||||||
operation->sha_ctx = sha256_ctx;
|
operation->sha_ctx = sha256_ctx;
|
||||||
int mode;
|
int mode;
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
operation->sha_type = (alg == PSA_ALG_SHA_224) ? ESP_SHA_OPERATION_TYPE_SHA224 : ESP_SHA_OPERATION_TYPE_SHA256;
|
operation->sha_type = (alg == PSA_ALG_SHA_224) ? ESP_SHA_OPERATION_TYPE_SHA224 : ESP_SHA_OPERATION_TYPE_SHA256;
|
||||||
mode = (alg == PSA_ALG_SHA_224) ? SHA2_224 : SHA2_256;
|
mode = (alg == PSA_ALG_SHA_224) ? SHA2_224 : SHA2_256;
|
||||||
#else
|
#else
|
||||||
operation->sha_type = ESP_SHA_OPERATION_TYPE_SHA256;
|
operation->sha_type = ESP_SHA_OPERATION_TYPE_SHA256;
|
||||||
mode = SHA2_256;
|
mode = SHA2_256;
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
return esp_sha256_starts(sha256_ctx, mode);
|
return esp_sha256_starts(sha256_ctx, mode);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA256
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_256 || MBEDTLS_PSA_ACCEL_ALG_SHA_224
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA512
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
if (
|
if (
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
alg == PSA_ALG_SHA_384 ||
|
alg == PSA_ALG_SHA_384 ||
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
alg == PSA_ALG_SHA_512) {
|
alg == PSA_ALG_SHA_512) {
|
||||||
esp_sha512_context *sha512_ctx = heap_caps_malloc(sizeof(esp_sha512_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
esp_sha512_context *sha512_ctx = heap_caps_malloc(sizeof(esp_sha512_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
||||||
if (!sha512_ctx) {
|
if (!sha512_ctx) {
|
||||||
@@ -161,13 +176,13 @@ psa_status_t esp_sha_hash_setup(esp_sha_hash_operation_t *operation, psa_algorit
|
|||||||
operation->sha_ctx = sha512_ctx;
|
operation->sha_ctx = sha512_ctx;
|
||||||
int mode = SHA2_512;
|
int mode = SHA2_512;
|
||||||
operation->sha_type = ESP_SHA_OPERATION_TYPE_SHA512;
|
operation->sha_type = ESP_SHA_OPERATION_TYPE_SHA512;
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
operation->sha_type = (alg == PSA_ALG_SHA_384) ? ESP_SHA_OPERATION_TYPE_SHA384 : ESP_SHA_OPERATION_TYPE_SHA512;
|
operation->sha_type = (alg == PSA_ALG_SHA_384) ? ESP_SHA_OPERATION_TYPE_SHA384 : ESP_SHA_OPERATION_TYPE_SHA512;
|
||||||
mode = (alg == PSA_ALG_SHA_384) ? SHA2_384 : SHA2_512;
|
mode = (alg == PSA_ALG_SHA_384) ? SHA2_384 : SHA2_512;
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_384
|
||||||
return esp_sha512_starts(sha512_ctx, mode);
|
return esp_sha512_starts(sha512_ctx, mode);
|
||||||
}
|
}
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA512
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384)
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,24 +194,24 @@ psa_status_t esp_sha_hash_update(
|
|||||||
if (!operation || !operation->sha_ctx || !input) {
|
if (!operation || !operation->sha_ctx || !input) {
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA1
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
||||||
esp_sha1_context *ctx = (esp_sha1_context *)operation->sha_ctx;
|
esp_sha1_context *ctx = (esp_sha1_context *)operation->sha_ctx;
|
||||||
return esp_sha1_driver_update(ctx, input, input_length);
|
return esp_sha1_driver_update(ctx, input, input_length);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA1
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 || operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 || operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
||||||
esp_sha256_context *ctx = (esp_sha256_context *)operation->sha_ctx;
|
esp_sha256_context *ctx = (esp_sha256_context *)operation->sha_ctx;
|
||||||
return esp_sha256_driver_update(ctx, input, input_length);
|
return esp_sha256_driver_update(ctx, input, input_length);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#if (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 || operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 || operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
||||||
esp_sha512_context *ctx = (esp_sha512_context *)operation->sha_ctx;
|
esp_sha512_context *ctx = (esp_sha512_context *)operation->sha_ctx;
|
||||||
return esp_sha512_driver_update(ctx, input, input_length);
|
return esp_sha512_driver_update(ctx, input, input_length);
|
||||||
}
|
}
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#endif // (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +225,7 @@ psa_status_t esp_sha_hash_finish(
|
|||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA1
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
||||||
esp_sha1_context *ctx = (esp_sha1_context *)operation->sha_ctx;
|
esp_sha1_context *ctx = (esp_sha1_context *)operation->sha_ctx;
|
||||||
int ret = esp_sha1_driver_finish(ctx, hash, hash_size, hash_length);
|
int ret = esp_sha1_driver_finish(ctx, hash, hash_size, hash_length);
|
||||||
@@ -218,8 +233,8 @@ psa_status_t esp_sha_hash_finish(
|
|||||||
operation->sha_ctx = NULL;
|
operation->sha_ctx = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA1
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 ||
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 ||
|
||||||
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
||||||
esp_sha256_context *ctx = (esp_sha256_context *)operation->sha_ctx;
|
esp_sha256_context *ctx = (esp_sha256_context *)operation->sha_ctx;
|
||||||
@@ -228,8 +243,8 @@ psa_status_t esp_sha_hash_finish(
|
|||||||
operation->sha_ctx = NULL;
|
operation->sha_ctx = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#if (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 ||
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 ||
|
||||||
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
||||||
esp_sha512_context *ctx = (esp_sha512_context *)operation->sha_ctx;
|
esp_sha512_context *ctx = (esp_sha512_context *)operation->sha_ctx;
|
||||||
@@ -238,7 +253,7 @@ psa_status_t esp_sha_hash_finish(
|
|||||||
operation->sha_ctx = NULL;
|
operation->sha_ctx = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512)
|
||||||
|
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
@@ -248,15 +263,15 @@ psa_status_t esp_sha_hash_abort(esp_sha_hash_operation_t *operation)
|
|||||||
if (!operation) {
|
if (!operation) {
|
||||||
return PSA_ERROR_INVALID_ARGUMENT;
|
return PSA_ERROR_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA1
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
||||||
esp_sha1_context *ctx = (esp_sha1_context *)operation->sha_ctx;
|
esp_sha1_context *ctx = (esp_sha1_context *)operation->sha_ctx;
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
esp_sha1_driver_abort(ctx);
|
esp_sha1_driver_abort(ctx);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA1
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 ||
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 ||
|
||||||
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
||||||
esp_sha256_context *ctx = (esp_sha256_context *)operation->sha_ctx;
|
esp_sha256_context *ctx = (esp_sha256_context *)operation->sha_ctx;
|
||||||
@@ -264,8 +279,8 @@ psa_status_t esp_sha_hash_abort(esp_sha_hash_operation_t *operation)
|
|||||||
esp_sha256_driver_abort(ctx);
|
esp_sha256_driver_abort(ctx);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#if (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 ||
|
if (operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 ||
|
||||||
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
||||||
esp_sha512_context *ctx = (esp_sha512_context *)operation->sha_ctx;
|
esp_sha512_context *ctx = (esp_sha512_context *)operation->sha_ctx;
|
||||||
@@ -273,7 +288,7 @@ psa_status_t esp_sha_hash_abort(esp_sha_hash_operation_t *operation)
|
|||||||
esp_sha512_driver_abort(ctx);
|
esp_sha512_driver_abort(ctx);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#endif // (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
{
|
{
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
@@ -290,7 +305,7 @@ psa_status_t esp_sha_hash_clone(
|
|||||||
esp_sha_hash_operation_t *target_operation)
|
esp_sha_hash_operation_t *target_operation)
|
||||||
{
|
{
|
||||||
target_operation->sha_type = source_operation->sha_type;
|
target_operation->sha_type = source_operation->sha_type;
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA1
|
#ifdef MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
if (target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
if (target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA1) {
|
||||||
esp_sha1_context *sha1_ctx = heap_caps_malloc(sizeof(esp_sha1_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
esp_sha1_context *sha1_ctx = heap_caps_malloc(sizeof(esp_sha1_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
||||||
if (!sha1_ctx) {
|
if (!sha1_ctx) {
|
||||||
@@ -303,8 +318,8 @@ psa_status_t esp_sha_hash_clone(
|
|||||||
}
|
}
|
||||||
esp_sha1_driver_clone(source_operation->sha_ctx, target_operation->sha_ctx);
|
esp_sha1_driver_clone(source_operation->sha_ctx, target_operation->sha_ctx);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA1
|
#endif // MBEDTLS_PSA_ACCEL_ALG_SHA_1
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#if defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
if (target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 ||
|
if (target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA256 ||
|
||||||
target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA224) {
|
||||||
esp_sha256_context *sha256_ctx = heap_caps_malloc(sizeof(esp_sha256_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
esp_sha256_context *sha256_ctx = heap_caps_malloc(sizeof(esp_sha256_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
||||||
@@ -318,8 +333,8 @@ psa_status_t esp_sha_hash_clone(
|
|||||||
}
|
}
|
||||||
esp_sha256_driver_clone(source_operation->sha_ctx, target_operation->sha_ctx);
|
esp_sha256_driver_clone(source_operation->sha_ctx, target_operation->sha_ctx);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA224 || CONFIG_SOC_SHA_SUPPORT_SHA256
|
#endif // defined(MBEDTLS_PSA_ACCEL_ALG_SHA_224) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_256)
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#if (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
if (target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 ||
|
if (target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA384 ||
|
||||||
target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
target_operation->sha_type == ESP_SHA_OPERATION_TYPE_SHA512) {
|
||||||
esp_sha512_context *sha512_ctx = heap_caps_malloc(sizeof(esp_sha512_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
esp_sha512_context *sha512_ctx = heap_caps_malloc(sizeof(esp_sha512_context), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
|
||||||
@@ -333,7 +348,7 @@ psa_status_t esp_sha_hash_clone(
|
|||||||
}
|
}
|
||||||
esp_sha512_driver_clone(source_operation->sha_ctx, target_operation->sha_ctx);
|
esp_sha512_driver_clone(source_operation->sha_ctx, target_operation->sha_ctx);
|
||||||
} else
|
} else
|
||||||
#endif // CONFIG_SOC_SHA_SUPPORT_SHA384 || CONFIG_SOC_SHA_SUPPORT_SHA512
|
#endif // (defined(MBEDTLS_PSA_ACCEL_ALG_SHA_384) || defined(MBEDTLS_PSA_ACCEL_ALG_SHA_512))
|
||||||
{
|
{
|
||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ typedef struct {
|
|||||||
unsigned char buffer[128]; /**< The data block being processed. */
|
unsigned char buffer[128]; /**< The data block being processed. */
|
||||||
bool first_block; /**< First block flag for hardware initialization */
|
bool first_block; /**< First block flag for hardware initialization */
|
||||||
int sha_state; /**< SHA operation state */
|
int sha_state; /**< SHA operation state */
|
||||||
int mode; /**< SHA2_224 or SHA2_256 */
|
int mode; /**< SHA2_384 or SHA2_512 */
|
||||||
uint32_t t_val; /**< t_val for 512/t mode */
|
uint32_t t_val; /**< t_val for 512/t mode */
|
||||||
#if CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG
|
#if CONFIG_SOC_SHA_SUPPORT_PARALLEL_ENG
|
||||||
esp_sha_mode_t operation_mode; /**< Hardware or Software mode */
|
esp_sha_mode_t operation_mode; /**< Hardware or Software mode */
|
||||||
|
|||||||
Reference in New Issue
Block a user