blob: fe6b5a23459ffcababf97987e94b999f940e320f [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.
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_MD5_H
26#define POLARSSL_MD5_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
28/**
29 * \brief MD5 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}
40md5_context;
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/**
47 * \brief MD5 context setup
48 *
49 * \param ctx context to be initialized
50 */
51void md5_starts( md5_context *ctx );
52
53/**
54 * \brief MD5 process buffer
55 *
56 * \param ctx MD5 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 md5_update( md5_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000061
62/**
63 * \brief MD5 final digest
64 *
65 * \param ctx MD5 context
66 * \param output MD5 checksum result
67 */
68void md5_finish( md5_context *ctx, unsigned char output[16] );
69
70/**
71 * \brief Output = MD5( input buffer )
72 *
73 * \param input buffer holding the data
74 * \param ilen length of the input data
75 * \param output MD5 checksum result
76 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000077void md5( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000078
79/**
80 * \brief Output = MD5( file contents )
81 *
82 * \param path input file name
83 * \param output MD5 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 md5_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000089
90/**
91 * \brief MD5 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 md5_hmac_starts( md5_context *ctx,
98 const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000099
100/**
101 * \brief MD5 HMAC process buffer
102 *
103 * \param ctx HMAC context
104 * \param input buffer holding the data
105 * \param ilen length of the input data
106 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000107void md5_hmac_update( md5_context *ctx,
108 const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000109
110/**
111 * \brief MD5 HMAC final digest
112 *
113 * \param ctx HMAC context
114 * \param output MD5 HMAC checksum result
115 */
116void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
117
118/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000119 * \brief MD5 HMAC context reset
120 *
121 * \param ctx HMAC context to be reset
122 */
123void md5_hmac_reset( md5_context *ctx );
124
125/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 * \brief Output = HMAC-MD5( hmac key, input buffer )
127 *
128 * \param key HMAC secret key
129 * \param keylen length of the HMAC key
130 * \param input buffer holding the data
131 * \param ilen length of the input data
132 * \param output HMAC-MD5 result
133 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000134void md5_hmac( const unsigned char *key, int keylen,
135 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 unsigned char output[16] );
137
138/**
139 * \brief Checkup routine
140 *
141 * \return 0 if successful, or 1 if the test failed
142 */
143int md5_self_test( int verbose );
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif /* md5.h */