blob: 891828ee21e9b1122069d4bf8a9e44fbd3d87fa8 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md5.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
5 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00006 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000021 */
Paul Bakker40e46942009-01-03 21:51:57 +000022#ifndef POLARSSL_MD5_H
23#define POLARSSL_MD5_H
Paul Bakker5121ce52009-01-03 21:22:43 +000024
25/**
26 * \brief MD5 context structure
27 */
28typedef struct
29{
30 unsigned long total[2]; /*!< number of bytes processed */
31 unsigned long state[4]; /*!< intermediate digest state */
32 unsigned char buffer[64]; /*!< data block being processed */
33
34 unsigned char ipad[64]; /*!< HMAC: inner padding */
35 unsigned char opad[64]; /*!< HMAC: outer padding */
36}
37md5_context;
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/**
44 * \brief MD5 context setup
45 *
46 * \param ctx context to be initialized
47 */
48void md5_starts( md5_context *ctx );
49
50/**
51 * \brief MD5 process buffer
52 *
53 * \param ctx MD5 context
54 * \param input buffer holding the data
55 * \param ilen length of the input data
56 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000057void md5_update( md5_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000058
59/**
60 * \brief MD5 final digest
61 *
62 * \param ctx MD5 context
63 * \param output MD5 checksum result
64 */
65void md5_finish( md5_context *ctx, unsigned char output[16] );
66
67/**
68 * \brief Output = MD5( input buffer )
69 *
70 * \param input buffer holding the data
71 * \param ilen length of the input data
72 * \param output MD5 checksum result
73 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000074void md5( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000075
76/**
77 * \brief Output = MD5( file contents )
78 *
79 * \param path input file name
80 * \param output MD5 checksum result
81 *
82 * \return 0 if successful, 1 if fopen failed,
83 * or 2 if fread failed
84 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000085int md5_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000086
87/**
88 * \brief MD5 HMAC context setup
89 *
90 * \param ctx HMAC context to be initialized
91 * \param key HMAC secret key
92 * \param keylen length of the HMAC key
93 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000094void md5_hmac_starts( md5_context *ctx,
95 const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000096
97/**
98 * \brief MD5 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 md5_hmac_update( md5_context *ctx,
105 const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000106
107/**
108 * \brief MD5 HMAC final digest
109 *
110 * \param ctx HMAC context
111 * \param output MD5 HMAC checksum result
112 */
113void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
114
115/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000116 * \brief MD5 HMAC context reset
117 *
118 * \param ctx HMAC context to be reset
119 */
120void md5_hmac_reset( md5_context *ctx );
121
122/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000123 * \brief Output = HMAC-MD5( hmac key, input buffer )
124 *
125 * \param key HMAC secret key
126 * \param keylen length of the HMAC key
127 * \param input buffer holding the data
128 * \param ilen length of the input data
129 * \param output HMAC-MD5 result
130 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000131void md5_hmac( const unsigned char *key, int keylen,
132 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 unsigned char output[16] );
134
135/**
136 * \brief Checkup routine
137 *
138 * \return 0 if successful, or 1 if the test failed
139 */
140int md5_self_test( int verbose );
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif /* md5.h */