blob: f690ea6b19f16ff4e3ad1be6ae45e101b889b653 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md4.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD4 message digest algorithm (hash function)
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Hanno Beckerce0c9db2017-09-28 15:39:45 +010023 *
24 * \warning MD4 is considered a weak message digest and its use constitutes a
25 * security risk. We recommend considering stronger message digests
26 * instead.
27 *
Paul Bakker5121ce52009-01-03 21:22:43 +000028 */
Paul Bakker40e46942009-01-03 21:51:57 +000029#ifndef POLARSSL_MD4_H
30#define POLARSSL_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020033#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#else
35#include POLARSSL_CONFIG_FILE
36#endif
Paul Bakker90995b52013-06-24 19:20:35 +020037
Rich Evans00ab4702015-02-06 13:43:58 +000038#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000039
Paul Bakkerfa6a6202013-10-28 18:48:30 +010040#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000041#include <basetsd.h>
42typedef UINT32 uint32_t;
43#else
44#include <inttypes.h>
45#endif
46
Paul Bakker69e095c2011-12-10 21:55:01 +000047#define POLARSSL_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */
48
Paul Bakker90995b52013-06-24 19:20:35 +020049#if !defined(POLARSSL_MD4_ALT)
50// Regular implementation
51//
52
Paul Bakker407a0da2013-06-27 14:29:21 +020053#ifdef __cplusplus
54extern "C" {
55#endif
56
Paul Bakker5121ce52009-01-03 21:22:43 +000057/**
58 * \brief MD4 context structure
Hanno Beckerce0c9db2017-09-28 15:39:45 +010059 *
60 * \warning MD4 is considered a weak message digest and its use
61 * constitutes a security risk. We recommend considering
62 * stronger message digests instead.
63 *
Paul Bakker5121ce52009-01-03 21:22:43 +000064 */
65typedef struct
66{
Paul Bakker5c2364c2012-10-01 14:41:15 +000067 uint32_t total[2]; /*!< number of bytes processed */
68 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000069 unsigned char buffer[64]; /*!< data block being processed */
70
71 unsigned char ipad[64]; /*!< HMAC: inner padding */
72 unsigned char opad[64]; /*!< HMAC: outer padding */
73}
74md4_context;
75
Paul Bakker5121ce52009-01-03 21:22:43 +000076/**
Paul Bakker5b4af392014-06-26 12:09:34 +020077 * \brief Initialize MD4 context
78 *
79 * \param ctx MD4 context to be initialized
Hanno Beckerce0c9db2017-09-28 15:39:45 +010080 *
81 * \warning MD4 is considered a weak message digest and its use
82 * constitutes a security risk. We recommend considering
83 * stronger message digests instead.
84 *
Paul Bakker5b4af392014-06-26 12:09:34 +020085 */
86void md4_init( md4_context *ctx );
87
88/**
89 * \brief Clear MD4 context
90 *
91 * \param ctx MD4 context to be cleared
Hanno Beckerce0c9db2017-09-28 15:39:45 +010092 *
93 * \warning MD4 is considered a weak message digest and its use
94 * constitutes a security risk. We recommend considering
95 * stronger message digests instead.
96 *
Paul Bakker5b4af392014-06-26 12:09:34 +020097 */
98void md4_free( md4_context *ctx );
99
100/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000101 * \brief MD4 context setup
102 *
103 * \param ctx context to be initialized
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100104 *
105 * \warning MD4 is considered a weak message digest and its use
106 * constitutes a security risk. We recommend considering
107 * stronger message digests instead.
108 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000109 */
110void md4_starts( md4_context *ctx );
111
112/**
113 * \brief MD4 process buffer
114 *
115 * \param ctx MD4 context
116 * \param input buffer holding the data
117 * \param ilen length of the input data
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100118 *
119 * \warning MD4 is considered a weak message digest and its use
120 * constitutes a security risk. We recommend considering
121 * stronger message digests instead.
122 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 */
Paul Bakker23986e52011-04-24 08:57:21 +0000124void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
126/**
127 * \brief MD4 final digest
128 *
129 * \param ctx MD4 context
130 * \param output MD4 checksum result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100131 *
132 * \warning MD4 is considered a weak message digest and its use
133 * constitutes a security risk. We recommend considering
134 * stronger message digests instead.
135 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 */
137void md4_finish( md4_context *ctx, unsigned char output[16] );
138
Paul Bakker90995b52013-06-24 19:20:35 +0200139#ifdef __cplusplus
140}
141#endif
142
143#else /* POLARSSL_MD4_ALT */
144#include "md4_alt.h"
145#endif /* POLARSSL_MD4_ALT */
146
147#ifdef __cplusplus
148extern "C" {
149#endif
150
Paul Bakker5121ce52009-01-03 21:22:43 +0000151/**
152 * \brief Output = MD4( input buffer )
153 *
154 * \param input buffer holding the data
155 * \param ilen length of the input data
156 * \param output MD4 checksum result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100157 *
158 * \warning MD4 is considered a weak message digest and its use
159 * constitutes a security risk. We recommend considering
160 * stronger message digests instead.
161 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000162 */
Paul Bakker23986e52011-04-24 08:57:21 +0000163void md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000164
165/**
166 * \brief Output = MD4( file contents )
167 *
168 * \param path input file name
169 * \param output MD4 checksum result
170 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000171 * \return 0 if successful, or POLARSSL_ERR_MD4_FILE_IO_ERROR
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100172 *
173 * \warning MD4 is considered a weak message digest and its use
174 * constitutes a security risk. We recommend considering
175 * stronger message digests instead.
176 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000177 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000178int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000179
180/**
181 * \brief MD4 HMAC context setup
182 *
183 * \param ctx HMAC context to be initialized
184 * \param key HMAC secret key
185 * \param keylen length of the HMAC key
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100186 *
187 * \warning MD4 is considered a weak message digest and its use
188 * constitutes a security risk. We recommend considering
189 * stronger message digests instead.
190 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000191 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200192void md4_hmac_starts( md4_context *ctx, const unsigned char *key,
193 size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000194
195/**
196 * \brief MD4 HMAC process buffer
197 *
198 * \param ctx HMAC context
199 * \param input buffer holding the data
200 * \param ilen length of the input data
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100201 *
202 * \warning MD4 is considered a weak message digest and its use
203 * constitutes a security risk. We recommend considering
204 * stronger message digests instead.
205 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000206 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200207void md4_hmac_update( md4_context *ctx, const unsigned char *input,
208 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000209
210/**
211 * \brief MD4 HMAC final digest
212 *
213 * \param ctx HMAC context
214 * \param output MD4 HMAC checksum result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100215 *
216 * \warning MD4 is considered a weak message digest and its use
217 * constitutes a security risk. We recommend considering
218 * stronger message digests instead.
219 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000220 */
221void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
222
223/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000224 * \brief MD4 HMAC context reset
225 *
226 * \param ctx HMAC context to be reset
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100227 *
228 * \warning MD4 is considered a weak message digest and its use
229 * constitutes a security risk. We recommend considering
230 * stronger message digests instead.
231 *
Paul Bakker7d3b6612010-03-21 16:23:13 +0000232 */
233void md4_hmac_reset( md4_context *ctx );
234
235/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000236 * \brief Output = HMAC-MD4( hmac key, input buffer )
237 *
238 * \param key HMAC secret key
239 * \param keylen length of the HMAC key
240 * \param input buffer holding the data
241 * \param ilen length of the input data
242 * \param output HMAC-MD4 result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100243 *
244 * \warning MD4 is considered a weak message digest and its use
245 * constitutes a security risk. We recommend considering
246 * stronger message digests instead.
247 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 */
Paul Bakker23986e52011-04-24 08:57:21 +0000249void md4_hmac( const unsigned char *key, size_t keylen,
250 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000251 unsigned char output[16] );
252
253/**
254 * \brief Checkup routine
255 *
256 * \return 0 if successful, or 1 if the test failed
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100257 *
258 * \warning MD4 is considered a weak message digest and its use
259 * constitutes a security risk. We recommend considering
260 * stronger message digests instead.
261 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000262 */
263int md4_self_test( int verbose );
264
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100265/* Internal use */
266void md4_process( md4_context *ctx, const unsigned char data[64] );
267
Paul Bakker5121ce52009-01-03 21:22:43 +0000268#ifdef __cplusplus
269}
270#endif
271
272#endif /* md4.h */