1 | /** |
2 | * \file md5.h |
3 | */ |
4 | #ifndef XYSSL_MD5_H |
5 | #define XYSSL_MD5_H |
6 | |
7 | /** |
8 | * \brief MD5 context structure |
9 | */ |
10 | typedef 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 | } |
19 | md5_context; |
20 | |
21 | #ifdef __cplusplus |
22 | extern "C" { |
23 | #endif |
24 | |
25 | /** |
26 | * \brief MD5 context setup |
27 | * |
28 | * \param ctx context to be initialized |
29 | */ |
30 | void 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 | */ |
39 | void 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 | */ |
47 | void 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 | */ |
56 | void md5( unsigned char *input, int ilen, unsigned char output[16] ); |
57 | |
58 | void md5_hex (char *input, int ilen, char output[32]); |
59 | |
60 | |
61 | /** |
62 | * \brief Output = MD5( file contents ) |
63 | * |
64 | * \param path input file name |
65 | * \param output MD5 checksum result |
66 | * |
67 | * \return 0 if successful, 1 if fopen failed, |
68 | * or 2 if fread failed |
69 | */ |
70 | int md5_file( char *path, unsigned char output[16] ); |
71 | |
72 | /** |
73 | * \brief MD5 HMAC context setup |
74 | * |
75 | * \param ctx HMAC context to be initialized |
76 | * \param key HMAC secret key |
77 | * \param keylen length of the HMAC key |
78 | */ |
79 | void md5_hmac_starts( md5_context *ctx, unsigned char *key, int keylen ); |
80 | |
81 | /** |
82 | * \brief MD5 HMAC process buffer |
83 | * |
84 | * \param ctx HMAC context |
85 | * \param input buffer holding the data |
86 | * \param ilen length of the input data |
87 | */ |
88 | void md5_hmac_update( md5_context *ctx, unsigned char *input, int ilen ); |
89 | |
90 | /** |
91 | * \brief MD5 HMAC final digest |
92 | * |
93 | * \param ctx HMAC context |
94 | * \param output MD5 HMAC checksum result |
95 | */ |
96 | void md5_hmac_finish( md5_context *ctx, unsigned char output[16] ); |
97 | |
98 | /** |
99 | * \brief Output = HMAC-MD5( hmac key, input buffer ) |
100 | * |
101 | * \param key HMAC secret key |
102 | * \param keylen length of the HMAC key |
103 | * \param input buffer holding the data |
104 | * \param ilen length of the input data |
105 | * \param output HMAC-MD5 result |
106 | */ |
107 | void md5_hmac( unsigned char *key, int keylen, |
108 | unsigned char *input, int ilen, |
109 | unsigned char output[16] ); |
110 | |
111 | /** |
112 | * \brief Checkup routine |
113 | * |
114 | * \return 0 if successful, or 1 if the test failed |
115 | */ |
116 | int md5_self_test( int verbose ); |
117 | |
118 | #ifdef __cplusplus |
119 | } |
120 | #endif |
121 | |
122 | #endif /* md5.h */ |
123 | |