blob: 84f8b1f9d71596d395a35339d02c99b105ac4e30 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md4.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000011 * 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.
15 *
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.
20 *
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.
Paul Bakker5121ce52009-01-03 21:22:43 +000024 */
Paul Bakker40e46942009-01-03 21:51:57 +000025#ifndef POLARSSL_MD4_H
26#define POLARSSL_MD4_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
28/**
29 * \brief MD4 context structure
30 */
31typedef struct
32{
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 */
36
37 unsigned char ipad[64]; /*!< HMAC: inner padding */
38 unsigned char opad[64]; /*!< HMAC: outer padding */
39}
40md4_context;
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 * \brief MD4 context setup
48 *
49 * \param ctx context to be initialized
50 */
51void md4_starts( md4_context *ctx );
52
53/**
54 * \brief MD4 process buffer
55 *
56 * \param ctx MD4 context
57 * \param input buffer holding the data
58 * \param ilen length of the input data
59 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000060void md4_update( md4_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000061
62/**
63 * \brief MD4 final digest
64 *
65 * \param ctx MD4 context
66 * \param output MD4 checksum result
67 */
68void md4_finish( md4_context *ctx, unsigned char output[16] );
69
70/**
71 * \brief Output = MD4( input buffer )
72 *
73 * \param input buffer holding the data
74 * \param ilen length of the input data
75 * \param output MD4 checksum result
76 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000077void md4( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000078
79/**
80 * \brief Output = MD4( file contents )
81 *
82 * \param path input file name
83 * \param output MD4 checksum result
84 *
85 * \return 0 if successful, 1 if fopen failed,
86 * or 2 if fread failed
87 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000088int md4_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000089
90/**
91 * \brief MD4 HMAC context setup
92 *
93 * \param ctx HMAC context to be initialized
94 * \param key HMAC secret key
95 * \param keylen length of the HMAC key
96 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000097void md4_hmac_starts( md4_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000098
99/**
100 * \brief MD4 HMAC process buffer
101 *
102 * \param ctx HMAC context
103 * \param input buffer holding the data
104 * \param ilen length of the input data
105 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000106void md4_hmac_update( md4_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000107
108/**
109 * \brief MD4 HMAC final digest
110 *
111 * \param ctx HMAC context
112 * \param output MD4 HMAC checksum result
113 */
114void md4_hmac_finish( md4_context *ctx, unsigned char output[16] );
115
116/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000117 * \brief MD4 HMAC context reset
118 *
119 * \param ctx HMAC context to be reset
120 */
121void md4_hmac_reset( md4_context *ctx );
122
123/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 * \brief Output = HMAC-MD4( hmac key, input buffer )
125 *
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
131 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000132void md4_hmac( const unsigned char *key, int keylen,
133 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 unsigned char output[16] );
135
136/**
137 * \brief Checkup routine
138 *
139 * \return 0 if successful, or 1 if the test failed
140 */
141int md4_self_test( int verbose );
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* md4.h */