• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file md2.h
3  *
4  * \brief MD2 message digest algorithm (hash function)
5  *
6  * \warning MD2 is considered a weak message digest and its use constitutes a
7  *          security risk. We recommend considering stronger message digests
8  *          instead.
9  */
10 /*
11  *  Copyright The Mbed TLS Contributors
12  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
13  *
14  */
15 #ifndef MBEDTLS_MD2_H
16 #define MBEDTLS_MD2_H
17 
18 #if !defined(MBEDTLS_CONFIG_FILE)
19 #include "mbedtls/config.h"
20 #else
21 #include MBEDTLS_CONFIG_FILE
22 #endif
23 
24 #include <stddef.h>
25 
26 /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
27 /** MD2 hardware accelerator failed */
28 #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED                   -0x002B
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #if !defined(MBEDTLS_MD2_ALT)
35 // Regular implementation
36 //
37 
38 /**
39  * \brief          MD2 context structure
40  *
41  * \warning        MD2 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 typedef struct mbedtls_md2_context {
47     unsigned char cksum[16];    /*!< checksum of the data block */
48     unsigned char state[48];    /*!< intermediate digest state  */
49     unsigned char buffer[16];   /*!< data block being processed */
50     size_t left;                /*!< amount of data in buffer   */
51 }
52 mbedtls_md2_context;
53 
54 #else  /* MBEDTLS_MD2_ALT */
55 #include "md2_alt.h"
56 #endif /* MBEDTLS_MD2_ALT */
57 
58 /**
59  * \brief          Initialize MD2 context
60  *
61  * \param ctx      MD2 context to be initialized
62  *
63  * \warning        MD2 is considered a weak message digest and its use
64  *                 constitutes a security risk. We recommend considering
65  *                 stronger message digests instead.
66  *
67  */
68 void mbedtls_md2_init(mbedtls_md2_context *ctx);
69 
70 /**
71  * \brief          Clear MD2 context
72  *
73  * \param ctx      MD2 context to be cleared
74  *
75  * \warning        MD2 is considered a weak message digest and its use
76  *                 constitutes a security risk. We recommend considering
77  *                 stronger message digests instead.
78  *
79  */
80 void mbedtls_md2_free(mbedtls_md2_context *ctx);
81 
82 /**
83  * \brief          Clone (the state of) an MD2 context
84  *
85  * \param dst      The destination context
86  * \param src      The context to be cloned
87  *
88  * \warning        MD2 is considered a weak message digest and its use
89  *                 constitutes a security risk. We recommend considering
90  *                 stronger message digests instead.
91  *
92  */
93 void mbedtls_md2_clone(mbedtls_md2_context *dst,
94                        const mbedtls_md2_context *src);
95 
96 /**
97  * \brief          MD2 context setup
98  *
99  * \param ctx      context to be initialized
100  *
101  * \return         0 if successful
102  *
103  * \warning        MD2 is considered a weak message digest and its use
104  *                 constitutes a security risk. We recommend considering
105  *                 stronger message digests instead.
106  *
107  */
108 int mbedtls_md2_starts_ret(mbedtls_md2_context *ctx);
109 
110 /**
111  * \brief          MD2 process buffer
112  *
113  * \param ctx      MD2 context
114  * \param input    buffer holding the data
115  * \param ilen     length of the input data
116  *
117  * \return         0 if successful
118  *
119  * \warning        MD2 is considered a weak message digest and its use
120  *                 constitutes a security risk. We recommend considering
121  *                 stronger message digests instead.
122  *
123  */
124 int mbedtls_md2_update_ret(mbedtls_md2_context *ctx,
125                            const unsigned char *input,
126                            size_t ilen);
127 
128 /**
129  * \brief          MD2 final digest
130  *
131  * \param ctx      MD2 context
132  * \param output   MD2 checksum result
133  *
134  * \return         0 if successful
135  *
136  * \warning        MD2 is considered a weak message digest and its use
137  *                 constitutes a security risk. We recommend considering
138  *                 stronger message digests instead.
139  *
140  */
141 int mbedtls_md2_finish_ret(mbedtls_md2_context *ctx,
142                            unsigned char output[16]);
143 
144 /**
145  * \brief          MD2 process data block (internal use only)
146  *
147  * \param ctx      MD2 context
148  *
149  * \return         0 if successful
150  *
151  * \warning        MD2 is considered a weak message digest and its use
152  *                 constitutes a security risk. We recommend considering
153  *                 stronger message digests instead.
154  *
155  */
156 int mbedtls_internal_md2_process(mbedtls_md2_context *ctx);
157 
158 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
159 #if defined(MBEDTLS_DEPRECATED_WARNING)
160 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
161 #else
162 #define MBEDTLS_DEPRECATED
163 #endif
164 /**
165  * \brief          MD2 context setup
166  *
167  * \deprecated     Superseded by mbedtls_md2_starts_ret() in 2.7.0
168  *
169  * \param ctx      context to be initialized
170  *
171  * \warning        MD2 is considered a weak message digest and its use
172  *                 constitutes a security risk. We recommend considering
173  *                 stronger message digests instead.
174  *
175  */
176 MBEDTLS_DEPRECATED void mbedtls_md2_starts(mbedtls_md2_context *ctx);
177 
178 /**
179  * \brief          MD2 process buffer
180  *
181  * \deprecated     Superseded by mbedtls_md2_update_ret() in 2.7.0
182  *
183  * \param ctx      MD2 context
184  * \param input    buffer holding the data
185  * \param ilen     length of the input data
186  *
187  * \warning        MD2 is considered a weak message digest and its use
188  *                 constitutes a security risk. We recommend considering
189  *                 stronger message digests instead.
190  *
191  */
192 MBEDTLS_DEPRECATED void mbedtls_md2_update(mbedtls_md2_context *ctx,
193                                            const unsigned char *input,
194                                            size_t ilen);
195 
196 /**
197  * \brief          MD2 final digest
198  *
199  * \deprecated     Superseded by mbedtls_md2_finish_ret() in 2.7.0
200  *
201  * \param ctx      MD2 context
202  * \param output   MD2 checksum result
203  *
204  * \warning        MD2 is considered a weak message digest and its use
205  *                 constitutes a security risk. We recommend considering
206  *                 stronger message digests instead.
207  *
208  */
209 MBEDTLS_DEPRECATED void mbedtls_md2_finish(mbedtls_md2_context *ctx,
210                                            unsigned char output[16]);
211 
212 /**
213  * \brief          MD2 process data block (internal use only)
214  *
215  * \deprecated     Superseded by mbedtls_internal_md2_process() in 2.7.0
216  *
217  * \param ctx      MD2 context
218  *
219  * \warning        MD2 is considered a weak message digest and its use
220  *                 constitutes a security risk. We recommend considering
221  *                 stronger message digests instead.
222  *
223  */
224 MBEDTLS_DEPRECATED void mbedtls_md2_process(mbedtls_md2_context *ctx);
225 
226 #undef MBEDTLS_DEPRECATED
227 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
228 
229 /**
230  * \brief          Output = MD2( input buffer )
231  *
232  * \param input    buffer holding the data
233  * \param ilen     length of the input data
234  * \param output   MD2 checksum result
235  *
236  * \warning        MD2 is considered a weak message digest and its use
237  *                 constitutes a security risk. We recommend considering
238  *                 stronger message digests instead.
239  *
240  */
241 int mbedtls_md2_ret(const unsigned char *input,
242                     size_t ilen,
243                     unsigned char output[16]);
244 
245 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
246 #if defined(MBEDTLS_DEPRECATED_WARNING)
247 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
248 #else
249 #define MBEDTLS_DEPRECATED
250 #endif
251 /**
252  * \brief          Output = MD2( input buffer )
253  *
254  * \deprecated     Superseded by mbedtls_md2_ret() in 2.7.0
255  *
256  * \param input    buffer holding the data
257  * \param ilen     length of the input data
258  * \param output   MD2 checksum result
259  *
260  * \warning        MD2 is considered a weak message digest and its use
261  *                 constitutes a security risk. We recommend considering
262  *                 stronger message digests instead.
263  *
264  */
265 MBEDTLS_DEPRECATED void mbedtls_md2(const unsigned char *input,
266                                     size_t ilen,
267                                     unsigned char output[16]);
268 
269 #undef MBEDTLS_DEPRECATED
270 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
271 
272 #if defined(MBEDTLS_SELF_TEST)
273 
274 /**
275  * \brief          Checkup routine
276  *
277  * \return         0 if successful, or 1 if the test failed
278  *
279  * \warning        MD2 is considered a weak message digest and its use
280  *                 constitutes a security risk. We recommend considering
281  *                 stronger message digests instead.
282  *
283  */
284 int mbedtls_md2_self_test(int verbose);
285 
286 #endif /* MBEDTLS_SELF_TEST */
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* mbedtls_md2.h */
293