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