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