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