blob: 68ac6c1396b5718d3a7803f60f70f28db7f7c7c2 [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.
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Paul Bakker40e46942009-01-03 21:51:57 +000024#ifndef POLARSSL_MD4_H
25#define POLARSSL_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000034
Paul Bakkerfa6a6202013-10-28 18:48:30 +010035#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000036#include <basetsd.h>
37typedef UINT32 uint32_t;
38#else
39#include <inttypes.h>
40#endif
41
Paul Bakker69e095c2011-12-10 21:55:01 +000042#define POLARSSL_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */
43
Paul Bakker90995b52013-06-24 19:20:35 +020044#if !defined(POLARSSL_MD4_ALT)
45// Regular implementation
46//
47
Paul Bakker407a0da2013-06-27 14:29:21 +020048#ifdef __cplusplus
49extern "C" {
50#endif
51
Paul Bakker5121ce52009-01-03 21:22:43 +000052/**
53 * \brief MD4 context structure
54 */
55typedef struct
56{
Paul Bakker5c2364c2012-10-01 14:41:15 +000057 uint32_t total[2]; /*!< number of bytes processed */
58 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000059 unsigned char buffer[64]; /*!< data block being processed */
60
61 unsigned char ipad[64]; /*!< HMAC: inner padding */
62 unsigned char opad[64]; /*!< HMAC: outer padding */
63}
64md4_context;
65
Paul Bakker5121ce52009-01-03 21:22:43 +000066/**
Paul Bakker5b4af392014-06-26 12:09:34 +020067 * \brief Initialize MD4 context
68 *
69 * \param ctx MD4 context to be initialized
70 */
71void md4_init( md4_context *ctx );
72
73/**
74 * \brief Clear MD4 context
75 *
76 * \param ctx MD4 context to be cleared
77 */
78void md4_free( md4_context *ctx );
79
80/**
Paul Bakker5121ce52009-01-03 21:22:43 +000081 * \brief MD4 context setup
82 *
83 * \param ctx context to be initialized
84 */
85void md4_starts( md4_context *ctx );
86
87/**
88 * \brief MD4 process buffer
89 *
90 * \param ctx MD4 context
91 * \param input buffer holding the data
92 * \param ilen length of the input data
93 */
Paul Bakker23986e52011-04-24 08:57:21 +000094void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000095
96/**
97 * \brief MD4 final digest
98 *
99 * \param ctx MD4 context
100 * \param output MD4 checksum result
101 */
102void md4_finish( md4_context *ctx, unsigned char output[16] );
103
Paul Bakker90995b52013-06-24 19:20:35 +0200104#ifdef __cplusplus
105}
106#endif
107
108#else /* POLARSSL_MD4_ALT */
109#include "md4_alt.h"
110#endif /* POLARSSL_MD4_ALT */
111
112#ifdef __cplusplus
113extern "C" {
114#endif
115
Paul Bakker5121ce52009-01-03 21:22:43 +0000116/**
117 * \brief Output = MD4( input buffer )
118 *
119 * \param input buffer holding the data
120 * \param ilen length of the input data
121 * \param output MD4 checksum result
122 */
Paul Bakker23986e52011-04-24 08:57:21 +0000123void md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000124
125/**
126 * \brief Output = MD4( file contents )
127 *
128 * \param path input file name
129 * \param output MD4 checksum result
130 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000131 * \return 0 if successful, or POLARSSL_ERR_MD4_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000133int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000134
135/**
136 * \brief MD4 HMAC context setup
137 *
138 * \param ctx HMAC context to be initialized
139 * \param key HMAC secret key
140 * \param keylen length of the HMAC key
141 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200142void md4_hmac_starts( md4_context *ctx, const unsigned char *key,
143 size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000144
145/**
146 * \brief MD4 HMAC process buffer
147 *
148 * \param ctx HMAC context
149 * \param input buffer holding the data
150 * \param ilen length of the input data
151 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200152void md4_hmac_update( md4_context *ctx, const unsigned char *input,
153 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000154
155/**
156 * \brief MD4 HMAC final digest
157 *
158 * \param ctx HMAC context
159 * \param output MD4 HMAC checksum result
160 */
161void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
162
163/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000164 * \brief MD4 HMAC context reset
165 *
166 * \param ctx HMAC context to be reset
167 */
168void md4_hmac_reset( md4_context *ctx );
169
170/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000171 * \brief Output = HMAC-MD4( hmac key, input buffer )
172 *
173 * \param key HMAC secret key
174 * \param keylen length of the HMAC key
175 * \param input buffer holding the data
176 * \param ilen length of the input data
177 * \param output HMAC-MD4 result
178 */
Paul Bakker23986e52011-04-24 08:57:21 +0000179void md4_hmac( const unsigned char *key, size_t keylen,
180 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000181 unsigned char output[16] );
182
183/**
184 * \brief Checkup routine
185 *
186 * \return 0 if successful, or 1 if the test failed
187 */
188int md4_self_test( int verbose );
189
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100190/* Internal use */
191void md4_process( md4_context *ctx, const unsigned char data[64] );
192
Paul Bakker5121ce52009-01-03 21:22:43 +0000193#ifdef __cplusplus
194}
195#endif
196
197#endif /* md4.h */