blob: 4791fb1bc2e02366a9b1122798e310c195cc803b [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 Bakker84f12b72010-07-18 10:13:04 +00006 * Copyright (C) 2006-2010, 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
Paul Bakker23986e52011-04-24 08:57:21 +000030#include <string.h>
31
Paul Bakker5c2364c2012-10-01 14:41:15 +000032#ifdef _MSC_VER
33#include <basetsd.h>
34typedef UINT32 uint32_t;
35#else
36#include <inttypes.h>
37#endif
38
Paul Bakker69e095c2011-12-10 21:55:01 +000039#define POLARSSL_ERR_MD4_FILE_IO_ERROR -0x0072 /**< Read/write error in file. */
40
Paul Bakker5121ce52009-01-03 21:22:43 +000041/**
42 * \brief MD4 context structure
43 */
44typedef struct
45{
Paul Bakker5c2364c2012-10-01 14:41:15 +000046 uint32_t total[2]; /*!< number of bytes processed */
47 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000048 unsigned char buffer[64]; /*!< data block being processed */
49
50 unsigned char ipad[64]; /*!< HMAC: inner padding */
51 unsigned char opad[64]; /*!< HMAC: outer padding */
52}
53md4_context;
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/**
60 * \brief MD4 context setup
61 *
62 * \param ctx context to be initialized
63 */
64void md4_starts( md4_context *ctx );
65
66/**
67 * \brief MD4 process buffer
68 *
69 * \param ctx MD4 context
70 * \param input buffer holding the data
71 * \param ilen length of the input data
72 */
Paul Bakker23986e52011-04-24 08:57:21 +000073void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000074
75/**
76 * \brief MD4 final digest
77 *
78 * \param ctx MD4 context
79 * \param output MD4 checksum result
80 */
81void md4_finish( md4_context *ctx, unsigned char output[16] );
82
83/**
84 * \brief Output = MD4( input buffer )
85 *
86 * \param input buffer holding the data
87 * \param ilen length of the input data
88 * \param output MD4 checksum result
89 */
Paul Bakker23986e52011-04-24 08:57:21 +000090void md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000091
92/**
93 * \brief Output = MD4( file contents )
94 *
95 * \param path input file name
96 * \param output MD4 checksum result
97 *
Paul Bakker69e095c2011-12-10 21:55:01 +000098 * \return 0 if successful, or POLARSSL_ERR_MD4_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +000099 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000100int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
102/**
103 * \brief MD4 HMAC context setup
104 *
105 * \param ctx HMAC context to be initialized
106 * \param key HMAC secret key
107 * \param keylen length of the HMAC key
108 */
Paul Bakker23986e52011-04-24 08:57:21 +0000109void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000110
111/**
112 * \brief MD4 HMAC process buffer
113 *
114 * \param ctx HMAC context
115 * \param input buffer holding the data
116 * \param ilen length of the input data
117 */
Paul Bakker23986e52011-04-24 08:57:21 +0000118void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
120/**
121 * \brief MD4 HMAC final digest
122 *
123 * \param ctx HMAC context
124 * \param output MD4 HMAC checksum result
125 */
126void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
127
128/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000129 * \brief MD4 HMAC context reset
130 *
131 * \param ctx HMAC context to be reset
132 */
133void md4_hmac_reset( md4_context *ctx );
134
135/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 * \brief Output = HMAC-MD4( hmac key, input buffer )
137 *
138 * \param key HMAC secret key
139 * \param keylen length of the HMAC key
140 * \param input buffer holding the data
141 * \param ilen length of the input data
142 * \param output HMAC-MD4 result
143 */
Paul Bakker23986e52011-04-24 08:57:21 +0000144void md4_hmac( const unsigned char *key, size_t keylen,
145 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000146 unsigned char output[16] );
147
148/**
149 * \brief Checkup routine
150 *
151 * \return 0 if successful, or 1 if the test failed
152 */
153int md4_self_test( int verbose );
154
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100155/* Internal use */
156void md4_process( md4_context *ctx, const unsigned char data[64] );
157
Paul Bakker5121ce52009-01-03 21:22:43 +0000158#ifdef __cplusplus
159}
160#endif
161
162#endif /* md4.h */