1 /*
2   ROM functions for hardware SHA support.
3 
4   It is not recommended to use these functions directly.  If using
5   them from esp-idf then use the esp_sha_lock_engine() and
6   esp_sha_lock_memory_block() functions in esp32/sha.h to ensure
7   exclusive access.
8  */
9 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
10 //
11 // Licensed under the Apache License, Version 2.0 (the "License");
12 // you may not use this file except in compliance with the License.
13 // You may obtain a copy of the License at
14 
15 //     http://www.apache.org/licenses/LICENSE-2.0
16 //
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the License is distributed on an "AS IS" BASIS,
19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 // See the License for the specific language governing permissions and
21 // limitations under the License.
22 #ifndef _ROM_SHA_H_
23 #define _ROM_SHA_H_
24 
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include <stddef.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 typedef struct SHAContext {
34     bool start;
35     uint32_t total_input_bits[4];
36 } SHA_CTX;
37 
38 enum SHA_TYPE {
39     SHA1 = 0,
40     SHA2_256,
41     SHA2_384,
42     SHA2_512,
43 
44 
45     SHA_INVALID = -1,
46 };
47 
48 /* Do not use these function in multi core mode due to
49  * inside they have no safe implementation (without DPORT workaround).
50 */
51 void ets_sha_init(SHA_CTX *ctx);
52 
53 void ets_sha_enable(void);
54 
55 void ets_sha_disable(void);
56 
57 void ets_sha_update(SHA_CTX *ctx, enum SHA_TYPE type, const uint8_t *input, size_t input_bits);
58 
59 void ets_sha_finish(SHA_CTX *ctx, enum SHA_TYPE type, uint8_t *output);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif /* _ROM_SHA_H_ */
66