blob: 5b61db30ecd97e3ee36b258c01e987dc9a916d0d [file] [log] [blame]
Jaeden Ameroe54e6932018-08-06 16:19:58 +01001/**
2 * \file md4.h
3 *
4 * \brief MD4 message digest algorithm (hash function)
5 *
6 * \warning MD4 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 (C) 2006-2015, ARM Limited, All Rights Reserved
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 * This file is part of Mbed Crypto (https://tls.mbed.org)
27 *
28 */
29#ifndef MBEDCRYPTO_MD4_H
30#define MBEDCRYPTO_MD4_H
31
32#if !defined(MBEDCRYPTO_CONFIG_FILE)
33#include "config.h"
34#else
35#include MBEDCRYPTO_CONFIG_FILE
36#endif
37
38#include <stddef.h>
39#include <stdint.h>
40
41#define MBEDCRYPTO_ERR_MD4_HW_ACCEL_FAILED -0x002D /**< MD4 hardware accelerator failed */
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47#if !defined(MBEDCRYPTO_MD4_ALT)
48// Regular implementation
49//
50
51/**
52 * \brief MD4 context structure
53 *
54 * \warning MD4 is considered a weak message digest and its use
55 * constitutes a security risk. We recommend considering
56 * stronger message digests instead.
57 *
58 */
59typedef struct
60{
61 uint32_t total[2]; /*!< number of bytes processed */
62 uint32_t state[4]; /*!< intermediate digest state */
63 unsigned char buffer[64]; /*!< data block being processed */
64}
65mbedcrypto_md4_context;
66
67#else /* MBEDCRYPTO_MD4_ALT */
68#include "md4_alt.h"
69#endif /* MBEDCRYPTO_MD4_ALT */
70
71/**
72 * \brief Initialize MD4 context
73 *
74 * \param ctx MD4 context to be initialized
75 *
76 * \warning MD4 is considered a weak message digest and its use
77 * constitutes a security risk. We recommend considering
78 * stronger message digests instead.
79 *
80 */
81void mbedcrypto_md4_init( mbedcrypto_md4_context *ctx );
82
83/**
84 * \brief Clear MD4 context
85 *
86 * \param ctx MD4 context to be cleared
87 *
88 * \warning MD4 is considered a weak message digest and its use
89 * constitutes a security risk. We recommend considering
90 * stronger message digests instead.
91 *
92 */
93void mbedcrypto_md4_free( mbedcrypto_md4_context *ctx );
94
95/**
96 * \brief Clone (the state of) an MD4 context
97 *
98 * \param dst The destination context
99 * \param src The context to be cloned
100 *
101 * \warning MD4 is considered a weak message digest and its use
102 * constitutes a security risk. We recommend considering
103 * stronger message digests instead.
104 *
105 */
106void mbedcrypto_md4_clone( mbedcrypto_md4_context *dst,
107 const mbedcrypto_md4_context *src );
108
109/**
110 * \brief MD4 context setup
111 *
112 * \param ctx context to be initialized
113 *
114 * \return 0 if successful
115 *
116 * \warning MD4 is considered a weak message digest and its use
117 * constitutes a security risk. We recommend considering
118 * stronger message digests instead.
119 */
120int mbedcrypto_md4_starts_ret( mbedcrypto_md4_context *ctx );
121
122/**
123 * \brief MD4 process buffer
124 *
125 * \param ctx MD4 context
126 * \param input buffer holding the data
127 * \param ilen length of the input data
128 *
129 * \return 0 if successful
130 *
131 * \warning MD4 is considered a weak message digest and its use
132 * constitutes a security risk. We recommend considering
133 * stronger message digests instead.
134 *
135 */
136int mbedcrypto_md4_update_ret( mbedcrypto_md4_context *ctx,
137 const unsigned char *input,
138 size_t ilen );
139
140/**
141 * \brief MD4 final digest
142 *
143 * \param ctx MD4 context
144 * \param output MD4 checksum result
145 *
146 * \return 0 if successful
147 *
148 * \warning MD4 is considered a weak message digest and its use
149 * constitutes a security risk. We recommend considering
150 * stronger message digests instead.
151 *
152 */
153int mbedcrypto_md4_finish_ret( mbedcrypto_md4_context *ctx,
154 unsigned char output[16] );
155
156/**
157 * \brief MD4 process data block (internal use only)
158 *
159 * \param ctx MD4 context
160 * \param data buffer holding one block of data
161 *
162 * \return 0 if successful
163 *
164 * \warning MD4 is considered a weak message digest and its use
165 * constitutes a security risk. We recommend considering
166 * stronger message digests instead.
167 *
168 */
169int mbedcrypto_internal_md4_process( mbedcrypto_md4_context *ctx,
170 const unsigned char data[64] );
171
172#if !defined(MBEDCRYPTO_DEPRECATED_REMOVED)
173#if defined(MBEDCRYPTO_DEPRECATED_WARNING)
174#define MBEDCRYPTO_DEPRECATED __attribute__((deprecated))
175#else
176#define MBEDCRYPTO_DEPRECATED
177#endif
178/**
179 * \brief MD4 context setup
180 *
181 * \deprecated Superseded by mbedcrypto_md4_starts_ret() in 2.7.0
182 *
183 * \param ctx context to be initialized
184 *
185 * \warning MD4 is considered a weak message digest and its use
186 * constitutes a security risk. We recommend considering
187 * stronger message digests instead.
188 *
189 */
190MBEDCRYPTO_DEPRECATED void mbedcrypto_md4_starts( mbedcrypto_md4_context *ctx );
191
192/**
193 * \brief MD4 process buffer
194 *
195 * \deprecated Superseded by mbedcrypto_md4_update_ret() in 2.7.0
196 *
197 * \param ctx MD4 context
198 * \param input buffer holding the data
199 * \param ilen length of the input data
200 *
201 * \warning MD4 is considered a weak message digest and its use
202 * constitutes a security risk. We recommend considering
203 * stronger message digests instead.
204 *
205 */
206MBEDCRYPTO_DEPRECATED void mbedcrypto_md4_update( mbedcrypto_md4_context *ctx,
207 const unsigned char *input,
208 size_t ilen );
209
210/**
211 * \brief MD4 final digest
212 *
213 * \deprecated Superseded by mbedcrypto_md4_finish_ret() in 2.7.0
214 *
215 * \param ctx MD4 context
216 * \param output MD4 checksum result
217 *
218 * \warning MD4 is considered a weak message digest and its use
219 * constitutes a security risk. We recommend considering
220 * stronger message digests instead.
221 *
222 */
223MBEDCRYPTO_DEPRECATED void mbedcrypto_md4_finish( mbedcrypto_md4_context *ctx,
224 unsigned char output[16] );
225
226/**
227 * \brief MD4 process data block (internal use only)
228 *
229 * \deprecated Superseded by mbedcrypto_internal_md4_process() in 2.7.0
230 *
231 * \param ctx MD4 context
232 * \param data buffer holding one block of data
233 *
234 * \warning MD4 is considered a weak message digest and its use
235 * constitutes a security risk. We recommend considering
236 * stronger message digests instead.
237 *
238 */
239MBEDCRYPTO_DEPRECATED void mbedcrypto_md4_process( mbedcrypto_md4_context *ctx,
240 const unsigned char data[64] );
241
242#undef MBEDCRYPTO_DEPRECATED
243#endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */
244
245/**
246 * \brief Output = MD4( input buffer )
247 *
248 * \param input buffer holding the data
249 * \param ilen length of the input data
250 * \param output MD4 checksum result
251 *
252 * \return 0 if successful
253 *
254 * \warning MD4 is considered a weak message digest and its use
255 * constitutes a security risk. We recommend considering
256 * stronger message digests instead.
257 *
258 */
259int mbedcrypto_md4_ret( const unsigned char *input,
260 size_t ilen,
261 unsigned char output[16] );
262
263#if !defined(MBEDCRYPTO_DEPRECATED_REMOVED)
264#if defined(MBEDCRYPTO_DEPRECATED_WARNING)
265#define MBEDCRYPTO_DEPRECATED __attribute__((deprecated))
266#else
267#define MBEDCRYPTO_DEPRECATED
268#endif
269/**
270 * \brief Output = MD4( input buffer )
271 *
272 * \deprecated Superseded by mbedcrypto_md4_ret() in 2.7.0
273 *
274 * \param input buffer holding the data
275 * \param ilen length of the input data
276 * \param output MD4 checksum result
277 *
278 * \warning MD4 is considered a weak message digest and its use
279 * constitutes a security risk. We recommend considering
280 * stronger message digests instead.
281 *
282 */
283MBEDCRYPTO_DEPRECATED void mbedcrypto_md4( const unsigned char *input,
284 size_t ilen,
285 unsigned char output[16] );
286
287#undef MBEDCRYPTO_DEPRECATED
288#endif /* !MBEDCRYPTO_DEPRECATED_REMOVED */
289
290/**
291 * \brief Checkup routine
292 *
293 * \return 0 if successful, or 1 if the test failed
294 *
295 * \warning MD4 is considered a weak message digest and its use
296 * constitutes a security risk. We recommend considering
297 * stronger message digests instead.
298 *
299 */
300int mbedcrypto_md4_self_test( int verbose );
301
302#ifdef __cplusplus
303}
304#endif
305
306#endif /* mbedcrypto_md4.h */