blob: c2433045f5264e1623816d55f025b3a64aa14643 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md2.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
4 * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine
5 *
Paul Bakker785a9ee2009-01-25 14:15:10 +00006 * Copyright (C) 2009 Paul Bakker <polarssl_maintainer at polarssl dot org>
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000021 */
Paul Bakker40e46942009-01-03 21:51:57 +000022#ifndef POLARSSL_MD2_H
23#define POLARSSL_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000024
25/**
26 * \brief MD2 context structure
27 */
28typedef struct
29{
30 unsigned char cksum[16]; /*!< checksum of the data block */
31 unsigned char state[48]; /*!< intermediate digest state */
32 unsigned char buffer[16]; /*!< data block being processed */
33
34 unsigned char ipad[64]; /*!< HMAC: inner padding */
35 unsigned char opad[64]; /*!< HMAC: outer padding */
36 int left; /*!< amount of data in buffer */
37}
38md2_context;
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/**
45 * \brief MD2 context setup
46 *
47 * \param ctx context to be initialized
48 */
49void md2_starts( md2_context *ctx );
50
51/**
52 * \brief MD2 process buffer
53 *
54 * \param ctx MD2 context
55 * \param input buffer holding the data
56 * \param ilen length of the input data
57 */
58void md2_update( md2_context *ctx, unsigned char *input, int ilen );
59
60/**
61 * \brief MD2 final digest
62 *
63 * \param ctx MD2 context
64 * \param output MD2 checksum result
65 */
66void md2_finish( md2_context *ctx, unsigned char output[16] );
67
68/**
69 * \brief Output = MD2( input buffer )
70 *
71 * \param input buffer holding the data
72 * \param ilen length of the input data
73 * \param output MD2 checksum result
74 */
75void md2( unsigned char *input, int ilen, unsigned char output[16] );
76
77/**
78 * \brief Output = MD2( file contents )
79 *
80 * \param path input file name
81 * \param output MD2 checksum result
82 *
83 * \return 0 if successful, 1 if fopen failed,
84 * or 2 if fread failed
85 */
86int md2_file( char *path, unsigned char output[16] );
87
88/**
89 * \brief MD2 HMAC context setup
90 *
91 * \param ctx HMAC context to be initialized
92 * \param key HMAC secret key
93 * \param keylen length of the HMAC key
94 */
95void md2_hmac_starts( md2_context *ctx, unsigned char *key, int keylen );
96
97/**
98 * \brief MD2 HMAC process buffer
99 *
100 * \param ctx HMAC context
101 * \param input buffer holding the data
102 * \param ilen length of the input data
103 */
104void md2_hmac_update( md2_context *ctx, unsigned char *input, int ilen );
105
106/**
107 * \brief MD2 HMAC final digest
108 *
109 * \param ctx HMAC context
110 * \param output MD2 HMAC checksum result
111 */
112void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
113
114/**
115 * \brief Output = HMAC-MD2( hmac key, input buffer )
116 *
117 * \param key HMAC secret key
118 * \param keylen length of the HMAC key
119 * \param input buffer holding the data
120 * \param ilen length of the input data
121 * \param output HMAC-MD2 result
122 */
123void md2_hmac( unsigned char *key, int keylen,
124 unsigned char *input, int ilen,
125 unsigned char output[16] );
126
127/**
128 * \brief Checkup routine
129 *
130 * \return 0 if successful, or 1 if the test failed
131 */
132int md2_self_test( int verbose );
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif /* md2.h */