blob: aaf9b5838a3d90646b1e11118a313068c28c6c8d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md5.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_MD5_H
22#define POLARSSL_MD5_H
Paul Bakker5121ce52009-01-03 21:22:43 +000023
24/**
25 * \brief MD5 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}
36md5_context;
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/**
43 * \brief MD5 context setup
44 *
45 * \param ctx context to be initialized
46 */
47void md5_starts( md5_context *ctx );
48
49/**
50 * \brief MD5 process buffer
51 *
52 * \param ctx MD5 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 md5_update( md5_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000057
58/**
59 * \brief MD5 final digest
60 *
61 * \param ctx MD5 context
62 * \param output MD5 checksum result
63 */
64void md5_finish( md5_context *ctx, unsigned char output[16] );
65
66/**
67 * \brief Output = MD5( input buffer )
68 *
69 * \param input buffer holding the data
70 * \param ilen length of the input data
71 * \param output MD5 checksum result
72 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000073void md5( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000074
75/**
76 * \brief Output = MD5( file contents )
77 *
78 * \param path input file name
79 * \param output MD5 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 md5_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000085
86/**
87 * \brief MD5 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 md5_hmac_starts( md5_context *ctx,
94 const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000095
96/**
97 * \brief MD5 HMAC process buffer
98 *
99 * \param ctx HMAC context
100 * \param input buffer holding the data
101 * \param ilen length of the input data
102 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000103void md5_hmac_update( md5_context *ctx,
104 const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000105
106/**
107 * \brief MD5 HMAC final digest
108 *
109 * \param ctx HMAC context
110 * \param output MD5 HMAC checksum result
111 */
112void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
113
114/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000115 * \brief MD5 HMAC context reset
116 *
117 * \param ctx HMAC context to be reset
118 */
119void md5_hmac_reset( md5_context *ctx );
120
121/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000122 * \brief Output = HMAC-MD5( 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-MD5 result
129 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000130void md5_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 md5_self_test( int verbose );
140
141#ifdef __cplusplus
142}
143#endif
144
145#endif /* md5.h */