blob: 3124cb7282618e13f0b427903013172f37eee271 [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.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Paul Bakker5121ce52009-01-03 21:22:43 +000024 */
Paul Bakker40e46942009-01-03 21:51:57 +000025#ifndef POLARSSL_MD2_H
26#define POLARSSL_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000027
28/**
29 * \brief MD2 context structure
30 */
31typedef struct
32{
33 unsigned char cksum[16]; /*!< checksum of the data block */
34 unsigned char state[48]; /*!< intermediate digest state */
35 unsigned char buffer[16]; /*!< data block being processed */
36
37 unsigned char ipad[64]; /*!< HMAC: inner padding */
38 unsigned char opad[64]; /*!< HMAC: outer padding */
39 int left; /*!< amount of data in buffer */
40}
41md2_context;
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/**
48 * \brief MD2 context setup
49 *
50 * \param ctx context to be initialized
51 */
52void md2_starts( md2_context *ctx );
53
54/**
55 * \brief MD2 process buffer
56 *
57 * \param ctx MD2 context
58 * \param input buffer holding the data
59 * \param ilen length of the input data
60 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000061void md2_update( md2_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000062
63/**
64 * \brief MD2 final digest
65 *
66 * \param ctx MD2 context
67 * \param output MD2 checksum result
68 */
69void md2_finish( md2_context *ctx, unsigned char output[16] );
70
71/**
72 * \brief Output = MD2( input buffer )
73 *
74 * \param input buffer holding the data
75 * \param ilen length of the input data
76 * \param output MD2 checksum result
77 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000078void md2( const unsigned char *input, int ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000079
80/**
81 * \brief Output = MD2( file contents )
82 *
83 * \param path input file name
84 * \param output MD2 checksum result
85 *
86 * \return 0 if successful, 1 if fopen failed,
87 * or 2 if fread failed
88 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000089int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000090
91/**
92 * \brief MD2 HMAC context setup
93 *
94 * \param ctx HMAC context to be initialized
95 * \param key HMAC secret key
96 * \param keylen length of the HMAC key
97 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000098void md2_hmac_starts( md2_context *ctx, const unsigned char *key, int keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +000099
100/**
101 * \brief MD2 HMAC process buffer
102 *
103 * \param ctx HMAC context
104 * \param input buffer holding the data
105 * \param ilen length of the input data
106 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000107void md2_hmac_update( md2_context *ctx, const unsigned char *input, int ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000108
109/**
110 * \brief MD2 HMAC final digest
111 *
112 * \param ctx HMAC context
113 * \param output MD2 HMAC checksum result
114 */
115void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
116
117/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000118 * \brief MD2 HMAC context reset
119 *
120 * \param ctx HMAC context to be reset
121 */
122void md2_hmac_reset( md2_context *ctx );
123
124/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000125 * \brief Output = HMAC-MD2( hmac key, input buffer )
126 *
127 * \param key HMAC secret key
128 * \param keylen length of the HMAC key
129 * \param input buffer holding the data
130 * \param ilen length of the input data
131 * \param output HMAC-MD2 result
132 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000133void md2_hmac( const unsigned char *key, int keylen,
134 const unsigned char *input, int ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000135 unsigned char output[16] );
136
137/**
138 * \brief Checkup routine
139 *
140 * \return 0 if successful, or 1 if the test failed
141 */
142int md2_self_test( int verbose );
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif /* md2.h */