1 /* 2 * SHA-512 implementation with hardware ESP32 support added. 3 * Uses mbedTLS software implementation for failover when concurrent 4 * SHA operations are in use. 5 * 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 * Additions Copyright (C) 2016, Espressif Systems (Shanghai) PTE LTD 8 * SPDX-License-Identifier: Apache-2.0 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); you may 11 * not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 */ 23 #ifndef _SHA512_ALT_H_ 24 #define _SHA512_ALT_H_ 25 26 #if defined(MBEDTLS_SHA512_ALT) 27 28 #include "hal/sha_types.h" 29 #include "soc/soc_caps.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 36 #if SOC_SHA_SUPPORT_PARALLEL_ENG 37 38 typedef enum { 39 ESP_MBEDTLS_SHA512_UNUSED, /* first block hasn't been processed yet */ 40 ESP_MBEDTLS_SHA512_HARDWARE, /* using hardware SHA engine */ 41 ESP_MBEDTLS_SHA512_SOFTWARE, /* using software SHA */ 42 } esp_mbedtls_sha512_mode; 43 44 /** 45 * \brief SHA-512 context structure 46 */ 47 typedef struct { 48 uint64_t total[2]; /*!< number of bytes processed */ 49 uint64_t state[8]; /*!< intermediate digest state */ 50 unsigned char buffer[128]; /*!< data block being processed */ 51 int is384; /*!< 0 => SHA-512, else SHA-384 */ 52 esp_mbedtls_sha512_mode mode; 53 } mbedtls_sha512_context; 54 55 #elif SOC_SHA_SUPPORT_DMA || SOC_SHA_SUPPORT_RESUME 56 57 typedef enum { 58 ESP_SHA512_STATE_INIT, 59 ESP_SHA512_STATE_IN_PROCESS 60 } esp_sha512_state; 61 62 /** 63 * \brief SHA-512 context structure 64 */ 65 typedef struct { 66 uint64_t total[2]; /*!< number of bytes processed */ 67 uint64_t state[8]; /*!< intermediate digest state */ 68 unsigned char buffer[128]; /*!< data block being processed */ 69 int first_block; 70 esp_sha_type mode; 71 uint32_t t_val; /*!< t_val for 512/t mode */ 72 esp_sha512_state sha_state; 73 } mbedtls_sha512_context; 74 75 /** 76 * @brief Sets the specfic algorithm for SHA512 77 * 78 * @param ctx The mbedtls sha512 context 79 * 80 * @param type The mode, used for setting SHA2_512224 and SHA2_512256: 81 * 82 */ 83 void esp_sha512_set_mode(mbedtls_sha512_context *ctx, esp_sha_type type); 84 85 /* For SHA512/t mode the intial hash value will depend on t */ 86 void esp_sha512_set_t( mbedtls_sha512_context *ctx, uint16_t t_val); 87 88 89 #endif 90 91 #endif 92 93 #ifdef __cplusplus 94 } 95 #endif 96 97 #endif 98