mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
Merge branch 'feat/support_sha512_for_esp32c5' into 'master'
Support SHA 512 for ESP32-C5 See merge request espressif/esp-idf!39421
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* \brief AES block cipher, ESP32 hardware accelerated version
|
||||
* Based on mbedTLS FIPS-197 compliant version.
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* Additions Copyright (C) 2016, Espressif Systems (Shanghai) PTE Ltd
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ESP_AES_H
|
||||
#define ESP_AES_H
|
||||
|
||||
#warning "esp32/aes.h is deprecated, please use aes/esp_aes.h instead"
|
||||
|
||||
#include "aes/esp_aes.h"
|
||||
|
||||
#endif /* aes.h */
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright 2019-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "sha/sha_parallel_engine.h"
|
||||
|
||||
#warning esp32/sha.h is deprecated, please use sha_parallel_engine.h instead
|
||||
@@ -1,33 +0,0 @@
|
||||
/**
|
||||
* \brief AES block cipher, ESP32 hardware accelerated version
|
||||
* Based on mbedTLS FIPS-197 compliant version.
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* Additions Copyright (C) 2016-20, Espressif Systems (Shanghai) PTE Ltd
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ESP_AES_H
|
||||
#define ESP_AES_H
|
||||
|
||||
|
||||
//#warning "esp32s2/aes.h is deprecated, please use aes/esp_aes.h instead"
|
||||
|
||||
#include "aes/esp_aes.h"
|
||||
|
||||
|
||||
#endif /* aes.h */
|
||||
@@ -1,27 +0,0 @@
|
||||
/**
|
||||
* \brief AES block cipher, ESP32C hardware accelerated version
|
||||
* Based on mbedTLS FIPS-197 compliant version.
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* Additions Copyright (C) 2019-2020, Espressif Systems (Shanghai) PTE Ltd
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed 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.
|
||||
*
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#warning "esp32s2/gcm.h is deprecated, please use aes/esp_aes_gcm.h instead"
|
||||
|
||||
#include "aes/esp_aes_gcm.h"
|
||||
@@ -1,11 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sha/sha_core.h"
|
||||
|
||||
#warning esp32s2/sha.h is deprecated, please use sha/sha_core.h instead
|
||||
@@ -1,9 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sha/sha_core.h"
|
||||
@@ -50,12 +50,19 @@ extern "C" {
|
||||
*/
|
||||
void esp_sha(esp_sha_type sha_type, const unsigned char *input, size_t ilen, unsigned char *output);
|
||||
|
||||
/**
|
||||
* @brief Set the mode for the SHA engine
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
void esp_sha_set_mode(esp_sha_type sha_type);
|
||||
|
||||
/** @brief Execute SHA block operation
|
||||
*
|
||||
* @note This is a piece of a SHA algorithm, rather than an entire SHA
|
||||
* algorithm.
|
||||
*
|
||||
* @note Call esp_sha_acquire_hardware() before calling this
|
||||
* @note Call esp_sha_acquire_hardware() and esp_sha_set_mode() before calling this
|
||||
* function.
|
||||
*
|
||||
* @param sha_type SHA algorithm to use.
|
||||
@@ -78,7 +85,7 @@ void esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_
|
||||
* @note This is a piece of a SHA algorithm, rather than an entire SHA
|
||||
* algorithm.
|
||||
*
|
||||
* @note Call esp_sha_aquire_hardware() before calling this
|
||||
* @note Call esp_sha_aquire_hardware() and esp_sha_set_mode() before calling this
|
||||
* function.
|
||||
*
|
||||
* @param sha_type SHA algorithm to use.
|
||||
@@ -145,7 +152,6 @@ void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state);
|
||||
*/
|
||||
void esp_sha_write_digest_state(esp_sha_type sha_type, void *digest_state);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables the SHA and crypto DMA peripheral and takes the
|
||||
* locks for both of them.
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sha/sha_core.h"
|
||||
@@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "hal/sha_types.h"
|
||||
@@ -69,6 +61,13 @@ extern "C" {
|
||||
*/
|
||||
void esp_sha(esp_sha_type sha_type, const unsigned char *input, size_t ilen, unsigned char *output);
|
||||
|
||||
/**
|
||||
* @brief Set the mode for the SHA engine
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
void esp_sha_set_mode(esp_sha_type sha_type);
|
||||
|
||||
/* @brief Begin to execute a single SHA block operation
|
||||
*
|
||||
* @note This is a piece of a SHA algorithm, rather than an entire SHA
|
||||
|
||||
@@ -113,6 +113,9 @@ static void esp_internal_sha1_block_process(mbedtls_sha1_context *ctx, const uin
|
||||
int mbedtls_internal_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64])
|
||||
{
|
||||
esp_sha_acquire_hardware();
|
||||
|
||||
esp_sha_set_mode(ctx->mode);
|
||||
|
||||
esp_internal_sha_update_state(ctx);
|
||||
|
||||
#if SOC_SHA_SUPPORT_DMA
|
||||
@@ -166,6 +169,8 @@ int mbedtls_sha1_update(mbedtls_sha1_context *ctx, const unsigned char *input, s
|
||||
|
||||
esp_sha_acquire_hardware();
|
||||
|
||||
esp_sha_set_mode(ctx->mode);
|
||||
|
||||
esp_internal_sha_update_state(ctx);
|
||||
|
||||
#if SOC_SHA_SUPPORT_DMA
|
||||
|
||||
@@ -126,6 +126,9 @@ static void esp_internal_sha256_block_process(mbedtls_sha256_context *ctx, const
|
||||
int mbedtls_internal_sha256_process(mbedtls_sha256_context *ctx, const unsigned char data[64])
|
||||
{
|
||||
esp_sha_acquire_hardware();
|
||||
|
||||
esp_sha_set_mode(ctx->mode);
|
||||
|
||||
esp_internal_sha_update_state(ctx);
|
||||
|
||||
#if SOC_SHA_SUPPORT_DMA
|
||||
@@ -185,6 +188,8 @@ int mbedtls_sha256_update(mbedtls_sha256_context *ctx, const unsigned char *inpu
|
||||
|
||||
esp_sha_acquire_hardware();
|
||||
|
||||
esp_sha_set_mode(ctx->mode);
|
||||
|
||||
esp_internal_sha_update_state(ctx);
|
||||
|
||||
#if SOC_SHA_SUPPORT_DMA
|
||||
|
||||
@@ -160,6 +160,8 @@ int mbedtls_internal_sha512_process(mbedtls_sha512_context *ctx, const unsigned
|
||||
|
||||
esp_sha_acquire_hardware();
|
||||
|
||||
esp_sha_set_mode(ctx->mode);
|
||||
|
||||
ret = esp_internal_sha_update_state(ctx);
|
||||
if (ret != 0) {
|
||||
esp_sha_release_hardware();
|
||||
@@ -220,6 +222,8 @@ int mbedtls_sha512_update(mbedtls_sha512_context *ctx, const unsigned char *inpu
|
||||
|
||||
esp_sha_acquire_hardware();
|
||||
|
||||
esp_sha_set_mode(ctx->mode);
|
||||
|
||||
int ret = esp_internal_sha_update_state(ctx);
|
||||
|
||||
if (ret != 0) {
|
||||
|
||||
@@ -102,6 +102,12 @@ void esp_sha_release_hardware(void)
|
||||
esp_crypto_sha_aes_lock_release();
|
||||
}
|
||||
|
||||
void esp_sha_set_mode(esp_sha_type sha_type)
|
||||
{
|
||||
sha_hal_wait_idle();
|
||||
sha_hal_set_mode(sha_type);
|
||||
}
|
||||
|
||||
void esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_block)
|
||||
{
|
||||
sha_hal_hash_block(sha_type, data_block, block_length(sha_type) / 4, is_first_block);
|
||||
@@ -284,7 +290,7 @@ static esp_err_t esp_sha_dma_process(esp_sha_type sha_type, const void *input, u
|
||||
return -1;
|
||||
}
|
||||
|
||||
sha_hal_hash_dma(sha_type, num_blks, is_first_block);
|
||||
sha_hal_hash_dma(num_blks, is_first_block);
|
||||
|
||||
sha_hal_wait_idle();
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ static portMUX_TYPE memory_block_lock = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
/* Binary semaphore managing the state of each concurrent SHA engine.
|
||||
|
||||
Available = noone is using this SHA engine
|
||||
Available = no one is using this SHA engine
|
||||
Taken = a SHA session is running on this SHA engine
|
||||
|
||||
Indexes:
|
||||
@@ -209,6 +209,11 @@ void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state)
|
||||
esp_sha_unlock_memory_block();
|
||||
}
|
||||
|
||||
void esp_sha_set_mode(esp_sha_type sha_type)
|
||||
{
|
||||
sha_hal_set_mode(sha_type);
|
||||
}
|
||||
|
||||
void esp_sha_block(esp_sha_type sha_type, const void *data_block, bool first_block)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
|
||||
Reference in New Issue
Block a user