blob: c8b4e158f7420527ce83d85a25a2cbc751b4fdeb [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é-Gonnard0edee5e2015-01-26 15:29:40 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00008 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +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
Paul Bakker4087c472013-06-12 16:49:10 +020027#include "config.h"
28
Paul Bakker23986e52011-04-24 08:57:21 +000029#include <string.h>
30
Paul Bakker5c2364c2012-10-01 14:41:15 +000031#ifdef _MSC_VER
32#include <basetsd.h>
33typedef UINT32 uint32_t;
34#else
35#include <inttypes.h>
36#endif
37
Paul Bakker69e095c2011-12-10 21:55:01 +000038#define POLARSSL_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */
39
Paul Bakker4087c472013-06-12 16:49:10 +020040#if !defined(POLARSSL_MD4_ALT)
41// Regular implementation
42//
43
Paul Bakker5121ce52009-01-03 21:22:43 +000044/**
45 * \brief MD4 context structure
46 */
47typedef struct
48{
Paul Bakker5c2364c2012-10-01 14:41:15 +000049 uint32_t total[2]; /*!< number of bytes processed */
50 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000051 unsigned char buffer[64]; /*!< data block being processed */
52
53 unsigned char ipad[64]; /*!< HMAC: inner padding */
54 unsigned char opad[64]; /*!< HMAC: outer padding */
55}
56md4_context;
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
62/**
63 * \brief MD4 context setup
64 *
65 * \param ctx context to be initialized
66 */
67void md4_starts( md4_context *ctx );
68
69/**
70 * \brief MD4 process buffer
71 *
72 * \param ctx MD4 context
73 * \param input buffer holding the data
74 * \param ilen length of the input data
75 */
Paul Bakker23986e52011-04-24 08:57:21 +000076void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000077
78/**
79 * \brief MD4 final digest
80 *
81 * \param ctx MD4 context
82 * \param output MD4 checksum result
83 */
84void md4_finish( md4_context *ctx, unsigned char output[16] );
85
Paul Bakker4087c472013-06-12 16:49:10 +020086#ifdef __cplusplus
87}
88#endif
89
90#else /* POLARSSL_MD4_ALT */
91#include "md4_alt.h"
92#endif /* POLARSSL_MD4_ALT */
93
94#ifdef __cplusplus
95extern "C" {
96#endif
97
Paul Bakker5121ce52009-01-03 21:22:43 +000098/**
99 * \brief Output = MD4( input buffer )
100 *
101 * \param input buffer holding the data
102 * \param ilen length of the input data
103 * \param output MD4 checksum result
104 */
Paul Bakker23986e52011-04-24 08:57:21 +0000105void md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000106
107/**
108 * \brief Output = MD4( file contents )
109 *
110 * \param path input file name
111 * \param output MD4 checksum result
112 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000113 * \return 0 if successful, or POLARSSL_ERR_MD4_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000115int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000116
117/**
118 * \brief MD4 HMAC context setup
119 *
120 * \param ctx HMAC context to be initialized
121 * \param key HMAC secret key
122 * \param keylen length of the HMAC key
123 */
Paul Bakker23986e52011-04-24 08:57:21 +0000124void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
126/**
127 * \brief MD4 HMAC process buffer
128 *
129 * \param ctx HMAC context
130 * \param input buffer holding the data
131 * \param ilen length of the input data
132 */
Paul Bakker23986e52011-04-24 08:57:21 +0000133void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000134
135/**
136 * \brief MD4 HMAC final digest
137 *
138 * \param ctx HMAC context
139 * \param output MD4 HMAC checksum result
140 */
141void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
142
143/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000144 * \brief MD4 HMAC context reset
145 *
146 * \param ctx HMAC context to be reset
147 */
148void md4_hmac_reset( md4_context *ctx );
149
150/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000151 * \brief Output = HMAC-MD4( hmac key, input buffer )
152 *
153 * \param key HMAC secret key
154 * \param keylen length of the HMAC key
155 * \param input buffer holding the data
156 * \param ilen length of the input data
157 * \param output HMAC-MD4 result
158 */
Paul Bakker23986e52011-04-24 08:57:21 +0000159void md4_hmac( const unsigned char *key, size_t keylen,
160 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000161 unsigned char output[16] );
162
163/**
164 * \brief Checkup routine
165 *
166 * \return 0 if successful, or 1 if the test failed
167 */
168int md4_self_test( int verbose );
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif /* md4.h */