blob: a772542b4df08749a303a976eee23967de4cb84d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md5.h
3 */
4#ifndef XYSSL_MD5_H
5#define XYSSL_MD5_H
6
7/**
8 * \brief MD5 context structure
9 */
10typedef struct
11{
12 unsigned long total[2]; /*!< number of bytes processed */
13 unsigned long state[4]; /*!< intermediate digest state */
14 unsigned char buffer[64]; /*!< data block being processed */
15
16 unsigned char ipad[64]; /*!< HMAC: inner padding */
17 unsigned char opad[64]; /*!< HMAC: outer padding */
18}
19md5_context;
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/**
26 * \brief MD5 context setup
27 *
28 * \param ctx context to be initialized
29 */
30void md5_starts( md5_context *ctx );
31
32/**
33 * \brief MD5 process buffer
34 *
35 * \param ctx MD5 context
36 * \param input buffer holding the data
37 * \param ilen length of the input data
38 */
39void md5_update( md5_context *ctx, unsigned char *input, int ilen );
40
41/**
42 * \brief MD5 final digest
43 *
44 * \param ctx MD5 context
45 * \param output MD5 checksum result
46 */
47void md5_finish( md5_context *ctx, unsigned char output[16] );
48
49/**
50 * \brief Output = MD5( input buffer )
51 *
52 * \param input buffer holding the data
53 * \param ilen length of the input data
54 * \param output MD5 checksum result
55 */
56void md5( unsigned char *input, int ilen, unsigned char output[16] );
57
58/**
59 * \brief Output = MD5( file contents )
60 *
61 * \param path input file name
62 * \param output MD5 checksum result
63 *
64 * \return 0 if successful, 1 if fopen failed,
65 * or 2 if fread failed
66 */
67int md5_file( char *path, unsigned char output[16] );
68
69/**
70 * \brief MD5 HMAC context setup
71 *
72 * \param ctx HMAC context to be initialized
73 * \param key HMAC secret key
74 * \param keylen length of the HMAC key
75 */
76void md5_hmac_starts( md5_context *ctx, unsigned char *key, int keylen );
77
78/**
79 * \brief MD5 HMAC process buffer
80 *
81 * \param ctx HMAC context
82 * \param input buffer holding the data
83 * \param ilen length of the input data
84 */
85void md5_hmac_update( md5_context *ctx, unsigned char *input, int ilen );
86
87/**
88 * \brief MD5 HMAC final digest
89 *
90 * \param ctx HMAC context
91 * \param output MD5 HMAC checksum result
92 */
93void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
94
95/**
96 * \brief Output = HMAC-MD5( hmac key, input buffer )
97 *
98 * \param key HMAC secret key
99 * \param keylen length of the HMAC key
100 * \param input buffer holding the data
101 * \param ilen length of the input data
102 * \param output HMAC-MD5 result
103 */
104void md5_hmac( unsigned char *key, int keylen,
105 unsigned char *input, int ilen,
106 unsigned char output[16] );
107
108/**
109 * \brief Checkup routine
110 *
111 * \return 0 if successful, or 1 if the test failed
112 */
113int md5_self_test( int verbose );
114
115#ifdef __cplusplus
116}
117#endif
118
119#endif /* md5.h */