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