• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file md5.h
3  *
4  * \brief MD5 message digest algorithm (hash function)
5  *
6  * \warning   MD5 is considered a weak message digest and its use constitutes a
7  *            security risk. We recommend considering stronger message
8  *            digests instead.
9  */
10 /*
11  *  Copyright The Mbed TLS Contributors
12  *  SPDX-License-Identifier: Apache-2.0
13  *
14  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
15  *  not use this file except in compliance with the License.
16  *  You may obtain a copy of the License at
17  *
18  *  http://www.apache.org/licenses/LICENSE-2.0
19  *
20  *  Unless required by applicable law or agreed to in writing, software
21  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  *  See the License for the specific language governing permissions and
24  *  limitations under the License.
25  */
26 #ifndef MBEDTLS_MD5_H
27 #define MBEDTLS_MD5_H
28 #include "mbedtls/private_access.h"
29 
30 #include "mbedtls/build_info.h"
31 
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #if !defined(MBEDTLS_MD5_ALT)
40 // Regular implementation
41 //
42 
43 /**
44  * \brief          MD5 context structure
45  *
46  * \warning        MD5 is considered a weak message digest and its use
47  *                 constitutes a security risk. We recommend considering
48  *                 stronger message digests instead.
49  *
50  */
51 typedef struct mbedtls_md5_context
52 {
53     uint32_t MBEDTLS_PRIVATE(total)[2];          /*!< number of bytes processed  */
54     uint32_t MBEDTLS_PRIVATE(state)[4];          /*!< intermediate digest state  */
55     unsigned char MBEDTLS_PRIVATE(buffer)[64];   /*!< data block being processed */
56 }
57 mbedtls_md5_context;
58 
59 #else  /* MBEDTLS_MD5_ALT */
60 #include "md5_alt.h"
61 #endif /* MBEDTLS_MD5_ALT */
62 
63 /**
64  * \brief          Initialize MD5 context
65  *
66  * \param ctx      MD5 context to be initialized
67  *
68  * \warning        MD5 is considered a weak message digest and its use
69  *                 constitutes a security risk. We recommend considering
70  *                 stronger message digests instead.
71  *
72  */
73 void mbedtls_md5_init( mbedtls_md5_context *ctx );
74 
75 /**
76  * \brief          Clear MD5 context
77  *
78  * \param ctx      MD5 context to be cleared
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 void mbedtls_md5_free( mbedtls_md5_context *ctx );
86 
87 /**
88  * \brief          Clone (the state of) an MD5 context
89  *
90  * \param dst      The destination context
91  * \param src      The context to be cloned
92  *
93  * \warning        MD5 is considered a weak message digest and its use
94  *                 constitutes a security risk. We recommend considering
95  *                 stronger message digests instead.
96  *
97  */
98 void mbedtls_md5_clone( mbedtls_md5_context *dst,
99                         const mbedtls_md5_context *src );
100 
101 /**
102  * \brief          MD5 context setup
103  *
104  * \param ctx      context to be initialized
105  *
106  * \return         0 if successful
107  *
108  * \warning        MD5 is considered a weak message digest and its use
109  *                 constitutes a security risk. We recommend considering
110  *                 stronger message digests instead.
111  *
112  */
113 int mbedtls_md5_starts( mbedtls_md5_context *ctx );
114 
115 /**
116  * \brief          MD5 process buffer
117  *
118  * \param ctx      MD5 context
119  * \param input    buffer holding the data
120  * \param ilen     length of the input data
121  *
122  * \return         0 if successful
123  *
124  * \warning        MD5 is considered a weak message digest and its use
125  *                 constitutes a security risk. We recommend considering
126  *                 stronger message digests instead.
127  *
128  */
129 int mbedtls_md5_update( mbedtls_md5_context *ctx,
130                         const unsigned char *input,
131                         size_t ilen );
132 
133 /**
134  * \brief          MD5 final digest
135  *
136  * \param ctx      MD5 context
137  * \param output   MD5 checksum result
138  *
139  * \return         0 if successful
140  *
141  * \warning        MD5 is considered a weak message digest and its use
142  *                 constitutes a security risk. We recommend considering
143  *                 stronger message digests instead.
144  *
145  */
146 int mbedtls_md5_finish( mbedtls_md5_context *ctx,
147                         unsigned char output[16] );
148 
149 /**
150  * \brief          MD5 process data block (internal use only)
151  *
152  * \param ctx      MD5 context
153  * \param data     buffer holding one block of data
154  *
155  * \return         0 if successful
156  *
157  * \warning        MD5 is considered a weak message digest and its use
158  *                 constitutes a security risk. We recommend considering
159  *                 stronger message digests instead.
160  *
161  */
162 int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
163                                   const unsigned char data[64] );
164 
165 /**
166  * \brief          Output = MD5( input buffer )
167  *
168  * \param input    buffer holding the data
169  * \param ilen     length of the input data
170  * \param output   MD5 checksum result
171  *
172  * \return         0 if successful
173  *
174  * \warning        MD5 is considered a weak message digest and its use
175  *                 constitutes a security risk. We recommend considering
176  *                 stronger message digests instead.
177  *
178  */
179 int mbedtls_md5( const unsigned char *input,
180                  size_t ilen,
181                  unsigned char output[16] );
182 
183 #if defined(MBEDTLS_SELF_TEST)
184 
185 /**
186  * \brief          Checkup routine
187  *
188  * \return         0 if successful, or 1 if the test failed
189  *
190  * \warning        MD5 is considered a weak message digest and its use
191  *                 constitutes a security risk. We recommend considering
192  *                 stronger message digests instead.
193  *
194  */
195 int mbedtls_md5_self_test( int verbose );
196 
197 #endif /* MBEDTLS_SELF_TEST */
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif /* mbedtls_md5.h */
204