4 * Copyright (C) 2006-2010, Brainspark B.V.
6 * This file is part of PolarSSL (http://www.polarssl.org)
7 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef POLARSSL_MD4_H
26 #define POLARSSL_MD4_H
29 * \brief MD4 context structure
33 unsigned long total[2]; /*!< number of bytes processed */
34 unsigned long state[4]; /*!< intermediate digest state */
35 unsigned char buffer[64]; /*!< data block being processed */
37 unsigned char ipad[64]; /*!< HMAC: inner padding */
38 unsigned char opad[64]; /*!< HMAC: outer padding */
47 * \brief MD4 context setup
49 * \param ctx context to be initialized
51 void md4_starts( md4_context *ctx );
54 * \brief MD4 process buffer
56 * \param ctx MD4 context
57 * \param input buffer holding the data
58 * \param ilen length of the input data
60 void md4_update( md4_context *ctx, const unsigned char *input, int ilen );
63 * \brief MD4 final digest
65 * \param ctx MD4 context
66 * \param output MD4 checksum result
68 void md4_finish( md4_context *ctx, unsigned char output[16] );
71 * \brief Output = MD4( input buffer )
73 * \param input buffer holding the data
74 * \param ilen length of the input data
75 * \param output MD4 checksum result
77 void md4( const unsigned char *input, int ilen, unsigned char output[16] );
80 * \brief Output = MD4( file contents )
82 * \param path input file name
83 * \param output MD4 checksum result
85 * \return 0 if successful, 1 if fopen failed,
86 * or 2 if fread failed
88 int md4_file( const char *path, unsigned char output[16] );
91 * \brief MD4 HMAC context setup
93 * \param ctx HMAC context to be initialized
94 * \param key HMAC secret key
95 * \param keylen length of the HMAC key
97 void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen );
100 * \brief MD4 HMAC process buffer
102 * \param ctx HMAC context
103 * \param input buffer holding the data
104 * \param ilen length of the input data
106 void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen );
109 * \brief MD4 HMAC final digest
111 * \param ctx HMAC context
112 * \param output MD4 HMAC checksum result
114 void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
117 * \brief MD4 HMAC context reset
119 * \param ctx HMAC context to be reset
121 void md4_hmac_reset( md4_context *ctx );
124 * \brief Output = HMAC-MD4( hmac key, input buffer )
126 * \param key HMAC secret key
127 * \param keylen length of the HMAC key
128 * \param input buffer holding the data
129 * \param ilen length of the input data
130 * \param output HMAC-MD4 result
132 void md4_hmac( const unsigned char *key, int keylen,
133 const unsigned char *input, int ilen,
134 unsigned char output[16] );
137 * \brief Checkup routine
139 * \return 0 if successful, or 1 if the test failed
141 int md4_self_test( int verbose );