blob: 19acc6b45de5a1f23ea756f8ee31b0166b8ed3ab [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md5.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 *
6 * Copyright (C) 2009 Paul Bakker
7 *
8 * 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 */
57void md5_update( md5_context *ctx, unsigned char *input, int ilen );
58
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 */
74void md5( unsigned char *input, int ilen, unsigned char output[16] );
75
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 */
85int md5_file( char *path, unsigned char output[16] );
86
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 */
94void md5_hmac_starts( md5_context *ctx, unsigned char *key, int keylen );
95
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 */
103void md5_hmac_update( md5_context *ctx, unsigned char *input, int ilen );
104
105/**
106 * \brief MD5 HMAC final digest
107 *
108 * \param ctx HMAC context
109 * \param output MD5 HMAC checksum result
110 */
111void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
112
113/**
114 * \brief Output = HMAC-MD5( hmac key, input buffer )
115 *
116 * \param key HMAC secret key
117 * \param keylen length of the HMAC key
118 * \param input buffer holding the data
119 * \param ilen length of the input data
120 * \param output HMAC-MD5 result
121 */
122void md5_hmac( unsigned char *key, int keylen,
123 unsigned char *input, int ilen,
124 unsigned char output[16] );
125
126/**
127 * \brief Checkup routine
128 *
129 * \return 0 if successful, or 1 if the test failed
130 */
131int md5_self_test( int verbose );
132
133#ifdef __cplusplus
134}
135#endif
136
137#endif /* md5.h */