1 // Copyright 2010-2020 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 #pragma once
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <stdint.h>
22 
23 /**
24  * The MD5 functions calculate a 128-bit cryptographic digest for any number of input bytes.
25  */
26 
27 /**
28  * @brief Type defined for MD5 context
29  *
30  */
31 typedef struct MD5Context {
32     uint32_t buf[4];
33     uint32_t bits[2];
34     uint8_t in[64];
35 } md5_context_t;
36 
37 /**
38  * @brief Initialize the MD5 context
39  *
40  * @param context Context object allocated by user
41  */
42 void esp_rom_md5_init(md5_context_t *context);
43 
44 /**
45  * @brief Running MD5 algorithm over input data
46  *
47  * @param context MD5 context which has been initialized by `MD5Init`
48  * @param buf Input buffer
49  * @param len Buffer length
50  */
51 void esp_rom_md5_update(md5_context_t *context, const uint8_t *buf, uint32_t len);
52 
53 /**
54  * @brief Extract the MD5 result, and erase the context
55  *
56  * @param digest Where to store the 128-bit digest value
57  * @param context MD5 context
58  */
59 void esp_rom_md5_final(uint8_t digest[16], md5_context_t *context);
60 
61 #ifdef __cplusplus
62 }
63 #endif
64