blob: b2c0e3ba4526fc58a9888e7f9de92f3edfedad60 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md2.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
5 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00006 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00008 * 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 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000058void md2_update( md2_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000059
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 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000075void md2( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000076
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 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000086int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000087
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 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000095void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000096
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 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000104void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000105
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/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000115 * \brief MD2 HMAC context reset
116 *
117 * \param ctx HMAC context to be reset
118 */
119void md2_hmac_reset( md2_context *ctx );
120
121/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000122 * \brief Output = HMAC-MD2( hmac key, input buffer )
123 *
124 * \param key HMAC secret key
125 * \param keylen length of the HMAC key
126 * \param input buffer holding the data
127 * \param ilen length of the input data
128 * \param output HMAC-MD2 result
129 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000130void md2_hmac( const unsigned char *key, int keylen,
131 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 unsigned char output[16] );
133
134/**
135 * \brief Checkup routine
136 *
137 * \return 0 if successful, or 1 if the test failed
138 */
139int md2_self_test( int verbose );
140
141#ifdef __cplusplus
142}
143#endif
144
145#endif /* md2.h */