blob: 6302c3c28c4f8567e3dc94afd5a9c0d90b3aef80 [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 *
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02006 * Copyright (C) 2006-2014, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000012 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000013 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Paul Bakker40e46942009-01-03 21:51:57 +000027#ifndef POLARSSL_MD4_H
28#define POLARSSL_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000029
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020031#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakker90995b52013-06-24 19:20:35 +020035
Paul Bakker23986e52011-04-24 08:57:21 +000036#include <string.h>
37
Paul Bakkerfa6a6202013-10-28 18:48:30 +010038#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000039#include <basetsd.h>
40typedef UINT32 uint32_t;
41#else
42#include <inttypes.h>
43#endif
44
Paul Bakker69e095c2011-12-10 21:55:01 +000045#define POLARSSL_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */
46
Paul Bakker90995b52013-06-24 19:20:35 +020047#if !defined(POLARSSL_MD4_ALT)
48// Regular implementation
49//
50
Paul Bakker407a0da2013-06-27 14:29:21 +020051#ifdef __cplusplus
52extern "C" {
53#endif
54
Paul Bakker5121ce52009-01-03 21:22:43 +000055/**
56 * \brief MD4 context structure
57 */
58typedef struct
59{
Paul Bakker5c2364c2012-10-01 14:41:15 +000060 uint32_t total[2]; /*!< number of bytes processed */
61 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000062 unsigned char buffer[64]; /*!< data block being processed */
63
64 unsigned char ipad[64]; /*!< HMAC: inner padding */
65 unsigned char opad[64]; /*!< HMAC: outer padding */
66}
67md4_context;
68
Paul Bakker5121ce52009-01-03 21:22:43 +000069/**
70 * \brief MD4 context setup
71 *
72 * \param ctx context to be initialized
73 */
74void md4_starts( md4_context *ctx );
75
76/**
77 * \brief MD4 process buffer
78 *
79 * \param ctx MD4 context
80 * \param input buffer holding the data
81 * \param ilen length of the input data
82 */
Paul Bakker23986e52011-04-24 08:57:21 +000083void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000084
85/**
86 * \brief MD4 final digest
87 *
88 * \param ctx MD4 context
89 * \param output MD4 checksum result
90 */
91void md4_finish( md4_context *ctx, unsigned char output[16] );
92
Paul Bakker90995b52013-06-24 19:20:35 +020093#ifdef __cplusplus
94}
95#endif
96
97#else /* POLARSSL_MD4_ALT */
98#include "md4_alt.h"
99#endif /* POLARSSL_MD4_ALT */
100
101#ifdef __cplusplus
102extern "C" {
103#endif
104
Paul Bakker5121ce52009-01-03 21:22:43 +0000105/**
106 * \brief Output = MD4( input buffer )
107 *
108 * \param input buffer holding the data
109 * \param ilen length of the input data
110 * \param output MD4 checksum result
111 */
Paul Bakker23986e52011-04-24 08:57:21 +0000112void md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000113
114/**
115 * \brief Output = MD4( file contents )
116 *
117 * \param path input file name
118 * \param output MD4 checksum result
119 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000120 * \return 0 if successful, or POLARSSL_ERR_MD4_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000121 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000122int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000123
124/**
125 * \brief MD4 HMAC context setup
126 *
127 * \param ctx HMAC context to be initialized
128 * \param key HMAC secret key
129 * \param keylen length of the HMAC key
130 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200131void md4_hmac_starts( md4_context *ctx, const unsigned char *key,
132 size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000133
134/**
135 * \brief MD4 HMAC process buffer
136 *
137 * \param ctx HMAC context
138 * \param input buffer holding the data
139 * \param ilen length of the input data
140 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200141void md4_hmac_update( md4_context *ctx, const unsigned char *input,
142 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000143
144/**
145 * \brief MD4 HMAC final digest
146 *
147 * \param ctx HMAC context
148 * \param output MD4 HMAC checksum result
149 */
150void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
151
152/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000153 * \brief MD4 HMAC context reset
154 *
155 * \param ctx HMAC context to be reset
156 */
157void md4_hmac_reset( md4_context *ctx );
158
159/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000160 * \brief Output = HMAC-MD4( hmac key, input buffer )
161 *
162 * \param key HMAC secret key
163 * \param keylen length of the HMAC key
164 * \param input buffer holding the data
165 * \param ilen length of the input data
166 * \param output HMAC-MD4 result
167 */
Paul Bakker23986e52011-04-24 08:57:21 +0000168void md4_hmac( const unsigned char *key, size_t keylen,
169 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000170 unsigned char output[16] );
171
172/**
173 * \brief Checkup routine
174 *
175 * \return 0 if successful, or 1 if the test failed
176 */
177int md4_self_test( int verbose );
178
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100179/* Internal use */
180void md4_process( md4_context *ctx, const unsigned char data[64] );
181
Paul Bakker5121ce52009-01-03 21:22:43 +0000182#ifdef __cplusplus
183}
184#endif
185
186#endif /* md4.h */