ssl_tls: fix format warning in ssl_parse_certificate() on x86_64
[tropicssl.git] / include / tropicssl / md5.h
blob335080dea0a25d83b5884ec3d3c3d2061c1125e3
1 /**
2 * \file md5.h
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
6 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * * Neither the names of PolarSSL or XySSL nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #ifndef TROPICSSL_MD5_H
36 #define TROPICSSL_MD5_H
38 /**
39 * \brief MD5 context structure
41 typedef struct {
42 unsigned long total[2]; /*!< number of bytes processed */
43 unsigned long state[4]; /*!< intermediate digest state */
44 unsigned char buffer[64]; /*!< data block being processed */
46 unsigned char ipad[64]; /*!< HMAC: inner padding */
47 unsigned char opad[64]; /*!< HMAC: outer padding */
48 } md5_context;
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
54 /**
55 * \brief MD5 context setup
57 * \param ctx context to be initialized
59 void md5_starts(md5_context * ctx);
61 /**
62 * \brief MD5 process buffer
64 * \param ctx MD5 context
65 * \param input buffer holding the data
66 * \param ilen length of the input data
68 void md5_update(md5_context * ctx, const unsigned char *input, int ilen);
70 /**
71 * \brief MD5 final digest
73 * \param ctx MD5 context
74 * \param output MD5 checksum result
76 void md5_finish(md5_context * ctx, unsigned char output[16]);
78 /**
79 * \brief Output = MD5( input buffer )
81 * \param input buffer holding the data
82 * \param ilen length of the input data
83 * \param output MD5 checksum result
85 void md5(const unsigned char *input, int ilen, unsigned char output[16]);
87 /**
88 * \brief Output = MD5( file contents )
90 * \param path input file name
91 * \param output MD5 checksum result
93 * \return 0 if successful, 1 if fopen failed,
94 * or 2 if fread failed
96 int md5_file(const char *path, unsigned char output[16]);
98 /**
99 * \brief MD5 HMAC context setup
101 * \param ctx HMAC context to be initialized
102 * \param key HMAC secret key
103 * \param keylen length of the HMAC key
105 void md5_hmac_starts(md5_context * ctx,
106 const unsigned char *key, int keylen);
109 * \brief MD5 HMAC process buffer
111 * \param ctx HMAC context
112 * \param input buffer holding the data
113 * \param ilen length of the input data
115 void md5_hmac_update(md5_context * ctx,
116 const unsigned char *input, int ilen);
119 * \brief MD5 HMAC final digest
121 * \param ctx HMAC context
122 * \param output MD5 HMAC checksum result
124 void md5_hmac_finish(md5_context * ctx, unsigned char output[16]);
127 * \brief Output = HMAC-MD5( hmac key, input buffer )
129 * \param key HMAC secret key
130 * \param keylen length of the HMAC key
131 * \param input buffer holding the data
132 * \param ilen length of the input data
133 * \param output HMAC-MD5 result
135 void md5_hmac(const unsigned char *key, int keylen,
136 const unsigned char *input, int ilen,
137 unsigned char output[16]);
140 * \brief Checkup routine
142 * \return 0 if successful, or 1 if the test failed
144 int md5_self_test(int verbose);
146 #ifdef __cplusplus
148 #endif
149 #endif /* md5.h */