blob: 5ceb2c6fb7859a13ea91313e17e0ed543cfd0be8 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md4.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker83ded912010-03-21 17:46:26 +00004 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00005 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00006 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000020 */
Paul Bakker40e46942009-01-03 21:51:57 +000021#ifndef POLARSSL_MD4_H
22#define POLARSSL_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000023
24/**
25 * \brief MD4 context structure
26 */
27typedef struct
28{
29 unsigned long total[2]; /*!< number of bytes processed */
30 unsigned long state[4]; /*!< intermediate digest state */
31 unsigned char buffer[64]; /*!< data block being processed */
32
33 unsigned char ipad[64]; /*!< HMAC: inner padding */
34 unsigned char opad[64]; /*!< HMAC: outer padding */
35}
36md4_context;
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/**
43 * \brief MD4 context setup
44 *
45 * \param ctx context to be initialized
46 */
47void md4_starts( md4_context *ctx );
48
49/**
50 * \brief MD4 process buffer
51 *
52 * \param ctx MD4 context
53 * \param input buffer holding the data
54 * \param ilen length of the input data
55 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000056void md4_update( md4_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000057
58/**
59 * \brief MD4 final digest
60 *
61 * \param ctx MD4 context
62 * \param output MD4 checksum result
63 */
64void md4_finish( md4_context *ctx, unsigned char output[16] );
65
66/**
67 * \brief Output = MD4( input buffer )
68 *
69 * \param input buffer holding the data
70 * \param ilen length of the input data
71 * \param output MD4 checksum result
72 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000073void md4( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000074
75/**
76 * \brief Output = MD4( file contents )
77 *
78 * \param path input file name
79 * \param output MD4 checksum result
80 *
81 * \return 0 if successful, 1 if fopen failed,
82 * or 2 if fread failed
83 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000084int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000085
86/**
87 * \brief MD4 HMAC context setup
88 *
89 * \param ctx HMAC context to be initialized
90 * \param key HMAC secret key
91 * \param keylen length of the HMAC key
92 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000093void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000094
95/**
96 * \brief MD4 HMAC process buffer
97 *
98 * \param ctx HMAC context
99 * \param input buffer holding the data
100 * \param ilen length of the input data
101 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000102void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
104/**
105 * \brief MD4 HMAC final digest
106 *
107 * \param ctx HMAC context
108 * \param output MD4 HMAC checksum result
109 */
110void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
111
112/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000113 * \brief MD4 HMAC context reset
114 *
115 * \param ctx HMAC context to be reset
116 */
117void md4_hmac_reset( md4_context *ctx );
118
119/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000120 * \brief Output = HMAC-MD4( hmac key, input buffer )
121 *
122 * \param key HMAC secret key
123 * \param keylen length of the HMAC key
124 * \param input buffer holding the data
125 * \param ilen length of the input data
126 * \param output HMAC-MD4 result
127 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000128void md4_hmac( const unsigned char *key, int keylen,
129 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 unsigned char output[16] );
131
132/**
133 * \brief Checkup routine
134 *
135 * \return 0 if successful, or 1 if the test failed
136 */
137int md4_self_test( int verbose );
138
139#ifdef __cplusplus
140}
141#endif
142
143#endif /* md4.h */