blob: 5a796ae325007f36f194d76fb3e5d0ca85d61971 [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 Bakker5121ce52009-01-03 21:22:43 +000032/**
33 * \brief MD4 context structure
34 */
35typedef struct
36{
37 unsigned long total[2]; /*!< number of bytes processed */
38 unsigned long state[4]; /*!< intermediate digest state */
39 unsigned char buffer[64]; /*!< data block being processed */
40
41 unsigned char ipad[64]; /*!< HMAC: inner padding */
42 unsigned char opad[64]; /*!< HMAC: outer padding */
43}
44md4_context;
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/**
51 * \brief MD4 context setup
52 *
53 * \param ctx context to be initialized
54 */
55void md4_starts( md4_context *ctx );
56
57/**
58 * \brief MD4 process buffer
59 *
60 * \param ctx MD4 context
61 * \param input buffer holding the data
62 * \param ilen length of the input data
63 */
Paul Bakker23986e52011-04-24 08:57:21 +000064void md4_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000065
66/**
67 * \brief MD4 final digest
68 *
69 * \param ctx MD4 context
70 * \param output MD4 checksum result
71 */
72void md4_finish( md4_context *ctx, unsigned char output[16] );
73
74/**
75 * \brief Output = MD4( input buffer )
76 *
77 * \param input buffer holding the data
78 * \param ilen length of the input data
79 * \param output MD4 checksum result
80 */
Paul Bakker23986e52011-04-24 08:57:21 +000081void md4( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000082
83/**
84 * \brief Output = MD4( file contents )
85 *
86 * \param path input file name
87 * \param output MD4 checksum result
88 *
89 * \return 0 if successful, 1 if fopen failed,
90 * or 2 if fread failed
91 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000092int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000093
94/**
95 * \brief MD4 HMAC context setup
96 *
97 * \param ctx HMAC context to be initialized
98 * \param key HMAC secret key
99 * \param keylen length of the HMAC key
100 */
Paul Bakker23986e52011-04-24 08:57:21 +0000101void md4_hmac_starts( md4_context *ctx, const unsigned char *key, size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000102
103/**
104 * \brief MD4 HMAC process buffer
105 *
106 * \param ctx HMAC context
107 * \param input buffer holding the data
108 * \param ilen length of the input data
109 */
Paul Bakker23986e52011-04-24 08:57:21 +0000110void md4_hmac_update( md4_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000111
112/**
113 * \brief MD4 HMAC final digest
114 *
115 * \param ctx HMAC context
116 * \param output MD4 HMAC checksum result
117 */
118void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
119
120/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000121 * \brief MD4 HMAC context reset
122 *
123 * \param ctx HMAC context to be reset
124 */
125void md4_hmac_reset( md4_context *ctx );
126
127/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000128 * \brief Output = HMAC-MD4( hmac key, input buffer )
129 *
130 * \param key HMAC secret key
131 * \param keylen length of the HMAC key
132 * \param input buffer holding the data
133 * \param ilen length of the input data
134 * \param output HMAC-MD4 result
135 */
Paul Bakker23986e52011-04-24 08:57:21 +0000136void md4_hmac( const unsigned char *key, size_t keylen,
137 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 unsigned char output[16] );
139
140/**
141 * \brief Checkup routine
142 *
143 * \return 0 if successful, or 1 if the test failed
144 */
145int md4_self_test( int verbose );
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif /* md4.h */