1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /******************************************************************************* 16 * NOTICE 17 * The hal is not public api, don't use in application code. 18 * See readme.md in soc/include/hal/readme.md 19 ******************************************************************************/ 20 21 #pragma once 22 23 #include <stddef.h> 24 #include <stdbool.h> 25 #include "soc/soc_caps.h" 26 #include "soc/lldesc.h" 27 #include "hal/sha_types.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /** 34 * @brief Hashes a single message block 35 * 36 * @param sha_type SHA algorithm to hash with 37 * @param data_block Input message to be hashed 38 * @param block_word_len Length of the input message 39 * @param first_block Is this the first block in a message or a continuation? 40 */ 41 void sha_hal_hash_block(esp_sha_type sha_type, const void *data_block, size_t block_word_len, bool first_block); 42 43 /** 44 * @brief Polls and waits until the SHA engine is idle 45 * 46 */ 47 void sha_hal_wait_idle(void); 48 49 /** 50 * @brief Reads the current message digest from the SHA engine 51 * 52 * @param sha_type SHA algorithm used 53 * @param digest_state Output buffer to which to read message digest to 54 */ 55 void sha_hal_read_digest(esp_sha_type sha_type, void *digest_state); 56 57 #if SOC_SHA_SUPPORT_RESUME 58 /** 59 * @brief Writes the message digest to the SHA engine 60 * 61 * @param sha_type The SHA algorithm type 62 * @param digest_state Message digest to be written to SHA engine 63 */ 64 void sha_hal_write_digest(esp_sha_type sha_type, void *digest_state); 65 #endif 66 67 #if SOC_SHA_SUPPORT_DMA 68 /** 69 * @brief Hashes a number of message blocks using DMA 70 * 71 * @param sha_type SHA algorithm to hash with 72 * @param num_blocks Number of blocks to hash 73 * @param first_block Is this the first block in a message or a continuation? 74 */ 75 void sha_hal_hash_dma(esp_sha_type sha_type, size_t num_blocks, bool first_block); 76 #endif 77 78 #if SOC_SHA_SUPPORT_SHA512_T 79 /** 80 * @brief Calculates and sets the initial digiest for SHA512_t 81 * 82 * @param t_string 83 * @param t_len 84 */ 85 void sha_hal_sha512_init_hash(uint32_t t_string, uint8_t t_len); 86 #endif 87 88 #ifdef __cplusplus 89 } 90 #endif 91