new polarssl
[syren.git] / src / libpolarssl / md5.h
blobbb0ebf37db5531d8cda923cc67bad731df2846f5
1 /**
2 * \file md5.h
4 * \brief MD5 message digest algorithm (hash function)
6 * Copyright (C) 2006-2013, Brainspark B.V.
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #ifndef POLARSSL_MD5_H
28 #define POLARSSL_MD5_H
30 #if !defined(POLARSSL_CONFIG_FILE)
31 #include "config.h"
32 #else
33 #include POLARSSL_CONFIG_FILE
34 #endif
36 #include <string.h>
38 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
39 #include <basetsd.h>
40 typedef UINT32 uint32_t;
41 #else
42 #include <inttypes.h>
43 #endif
45 #define POLARSSL_ERR_MD5_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
47 #if !defined(POLARSSL_MD5_ALT)
48 // Regular implementation
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
55 /**
56 * \brief MD5 context structure
58 typedef struct
60 uint32_t total[2]; /*!< number of bytes processed */
61 uint32_t state[4]; /*!< intermediate digest state */
62 unsigned char buffer[64]; /*!< data block being processed */
64 unsigned char ipad[64]; /*!< HMAC: inner padding */
65 unsigned char opad[64]; /*!< HMAC: outer padding */
67 md5_context;
69 /**
70 * \brief MD5 context setup
72 * \param ctx context to be initialized
74 void md5_starts( md5_context *ctx );
76 /**
77 * \brief MD5 process buffer
79 * \param ctx MD5 context
80 * \param input buffer holding the data
81 * \param ilen length of the input data
83 void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen );
85 /**
86 * \brief MD5 final digest
88 * \param ctx MD5 context
89 * \param output MD5 checksum result
91 void md5_finish( md5_context *ctx, unsigned char output[16] );
93 /* Internal use */
94 void md5_process( md5_context *ctx, const unsigned char data[64] );
96 #ifdef __cplusplus
98 #endif
100 #else /* POLARSSL_MD5_ALT */
101 #include "md5_alt.h"
102 #endif /* POLARSSL_MD5_ALT */
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
109 * \brief Output = MD5( input buffer )
111 * \param input buffer holding the data
112 * \param ilen length of the input data
113 * \param output MD5 checksum result
115 void md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
118 * \brief Output = MD5( file contents )
120 * \param path input file name
121 * \param output MD5 checksum result
123 * \return 0 if successful, or POLARSSL_ERR_MD5_FILE_IO_ERROR
125 int md5_file( const char *path, unsigned char output[16] );
128 * \brief MD5 HMAC context setup
130 * \param ctx HMAC context to be initialized
131 * \param key HMAC secret key
132 * \param keylen length of the HMAC key
134 void md5_hmac_starts( md5_context *ctx,
135 const unsigned char *key, size_t keylen );
138 * \brief MD5 HMAC process buffer
140 * \param ctx HMAC context
141 * \param input buffer holding the data
142 * \param ilen length of the input data
144 void md5_hmac_update( md5_context *ctx,
145 const unsigned char *input, size_t ilen );
148 * \brief MD5 HMAC final digest
150 * \param ctx HMAC context
151 * \param output MD5 HMAC checksum result
153 void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
156 * \brief MD5 HMAC context reset
158 * \param ctx HMAC context to be reset
160 void md5_hmac_reset( md5_context *ctx );
163 * \brief Output = HMAC-MD5( hmac key, input buffer )
165 * \param key HMAC secret key
166 * \param keylen length of the HMAC key
167 * \param input buffer holding the data
168 * \param ilen length of the input data
169 * \param output HMAC-MD5 result
171 void md5_hmac( const unsigned char *key, size_t keylen,
172 const unsigned char *input, size_t ilen,
173 unsigned char output[16] );
176 * \brief Checkup routine
178 * \return 0 if successful, or 1 if the test failed
180 int md5_self_test( int verbose );
182 #ifdef __cplusplus
184 #endif
186 #endif /* md5.h */