1 // Copyright 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 
14 #pragma once
15 
16 #include "esp_rom_md5.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef struct MD5Context mbedtls_md5_context;
23 
24 /**
25  * \brief          Initialize MD5 context
26  *
27  * \param ctx      MD5 context to be initialized
28  *
29  * \warning        MD5 is considered a weak message digest and its use
30  *                 constitutes a security risk. We recommend considering
31  *                 stronger message digests instead.
32  *
33  */
34 int esp_md5_init_ret( mbedtls_md5_context *ctx );
35 
36 /**
37  * \brief          Clear MD5 context
38  *
39  * \param ctx      MD5 context to be cleared
40  *
41  * \warning        MD5 is considered a weak message digest and its use
42  *                 constitutes a security risk. We recommend considering
43  *                 stronger message digests instead.
44  *
45  */
46 void esp_md5_free( mbedtls_md5_context *ctx );
47 
48 /**
49  * \brief          Clone (the state of) an MD5 context
50  *
51  * \param dst      The destination context
52  * \param src      The context to be cloned
53  *
54  * \warning        MD5 is considered a weak message digest and its use
55  *                 constitutes a security risk. We recommend considering
56  *                 stronger message digests instead.
57  *
58  */
59 void esp_md5_clone( mbedtls_md5_context *dst, const mbedtls_md5_context *src );
60 
61 /**
62  * \brief          MD5 process buffer
63  *
64  * \param ctx      MD5 context
65  * \param input    buffer holding the data
66  * \param ilen     length of the input data
67  *
68  * \return         0 if successful
69  *
70  * \warning        MD5 is considered a weak message digest and its use
71  *                 constitutes a security risk. We recommend considering
72  *                 stronger message digests instead.
73  *
74  */
75 int esp_md5_update_ret( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
76 
77 /**
78  * \brief          MD5 final digest
79  *
80  * \param ctx      MD5 context
81  * \param output   MD5 checksum result
82  *
83  * \return         0 if successful
84  *
85  * \warning        MD5 is considered a weak message digest and its use
86  *                 constitutes a security risk. We recommend considering
87  *                 stronger message digests instead.
88  *
89  */
90 int esp_md5_finish_ret( mbedtls_md5_context *ctx, unsigned char output[16] );
91 
92 /**
93  * \brief          MD5 process data block (internal use only)
94  *
95  * \param ctx      MD5 context
96  * \param data     buffer holding one block of data
97  *
98  * \return         0 if successful
99  *
100  * \warning        MD5 is considered a weak message digest and its use
101  *                 constitutes a security risk. We recommend considering
102  *                 stronger message digests instead.
103  *
104  */
105 int esp_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] );
106 
107 /**
108  * \brief          MD5 context setup
109  *
110  * \deprecated     Superseded by mbedtls_md5_starts_ret() in 2.7.0
111  *
112  * \param ctx      context to be initialized
113  *
114  * \warning        MD5 is considered a weak message digest and its use
115  *                 constitutes a security risk. We recommend considering
116  *                 stronger message digests instead.
117  *
118  */
119 void esp_md5_init( mbedtls_md5_context *ctx );
120 
121 /**
122  * \brief          MD5 process buffer
123  *
124  * \deprecated     Superseded by mbedtls_md5_update_ret() in 2.7.0
125  *
126  * \param ctx      MD5 context
127  * \param input    buffer holding the data
128  * \param ilen     length of the input data
129  *
130  * \warning        MD5 is considered a weak message digest and its use
131  *                 constitutes a security risk. We recommend considering
132  *                 stronger message digests instead.
133  *
134  */
135 void esp_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
136 
137 /**
138  * \brief          MD5 final digest
139  *
140  * \deprecated     Superseded by mbedtls_md5_finish_ret() in 2.7.0
141  *
142  * \param ctx      MD5 context
143  * \param output   MD5 checksum result
144  *
145  * \warning        MD5 is considered a weak message digest and its use
146  *                 constitutes a security risk. We recommend considering
147  *                 stronger message digests instead.
148  *
149  */
150 void esp_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
151 
152 #ifdef __cplusplus
153 }
154 #endif
155