1 /*
2  * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #pragma once
7 
8 #include "esp_rom_md5.h"
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #if CONFIG_IDF_TARGET_ESP32C2
15 typedef struct mbedtls_md5_context mbedtls_md5_context;
16 #else
17 typedef struct MD5Context mbedtls_md5_context;
18 #endif
19 
20 /**
21  * \brief          Initialize MD5 context
22  *
23  * \param ctx      MD5 context to be initialized
24  *
25  * \warning        MD5 is considered a weak message digest and its use
26  *                 constitutes a security risk. We recommend considering
27  *                 stronger message digests instead.
28  *
29  */
30 void esp_md5_init( mbedtls_md5_context *ctx );
31 
32 /**
33  * \brief          Clear MD5 context
34  *
35  * \param ctx      MD5 context to be cleared
36  *
37  * \warning        MD5 is considered a weak message digest and its use
38  *                 constitutes a security risk. We recommend considering
39  *                 stronger message digests instead.
40  *
41  */
42 void esp_md5_free( mbedtls_md5_context *ctx );
43 
44 /**
45  * \brief          Clone (the state of) an MD5 context
46  *
47  * \param dst      The destination context
48  * \param src      The context to be cloned
49  *
50  * \warning        MD5 is considered a weak message digest and its use
51  *                 constitutes a security risk. We recommend considering
52  *                 stronger message digests instead.
53  *
54  */
55 void esp_md5_clone( mbedtls_md5_context *dst, const mbedtls_md5_context *src );
56 
57 /**
58  * \brief          MD5 context setup
59  *
60  * \param ctx      context to be initialized
61  *
62  * \return         0 if successful
63  *
64  * \warning        MD5 is considered a weak message digest and its use
65  *                 constitutes a security risk. We recommend considering
66  *                 stronger message digests instead.
67  *
68  */
69 int mbedtls_md5_starts( mbedtls_md5_context *ctx );
70 
71 /**
72  * \brief          MD5 process buffer
73  *
74  * \param ctx      MD5 context
75  * \param input    buffer holding the data
76  * \param ilen     length of the input data
77  *
78  * \return         0 if successful
79  *
80  * \warning        MD5 is considered a weak message digest and its use
81  *                 constitutes a security risk. We recommend considering
82  *                 stronger message digests instead.
83  *
84  */
85 int esp_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
86 
87 /**
88  * \brief          MD5 final digest
89  *
90  * \param ctx      MD5 context
91  * \param output   MD5 checksum result
92  *
93  * \return         0 if successful
94  *
95  * \warning        MD5 is considered a weak message digest and its use
96  *                 constitutes a security risk. We recommend considering
97  *                 stronger message digests instead.
98  *
99  */
100 int esp_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
101 
102 /**
103  * \brief          MD5 process data block (internal use only)
104  *
105  * \param ctx      MD5 context
106  * \param data     buffer holding one block of data
107  *
108  * \return         0 if successful
109  *
110  * \warning        MD5 is considered a weak message digest and its use
111  *                 constitutes a security risk. We recommend considering
112  *                 stronger message digests instead.
113  *
114  */
115 int esp_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] );
116 
117 #ifdef __cplusplus
118 }
119 #endif
120