blob: 03f2b18fce7a8e11b84b5ee97b3ce15a8b1dca9d [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file md2.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD2 message digest algorithm (hash function)
5 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Hanno Beckerce0c9db2017-09-28 15:39:45 +010023 *
24 * \warning MD2 is considered a weak message digest and its use constitutes a
25 * security risk. We recommend considering stronger message digests
26 * instead.
27 *
Paul Bakker5121ce52009-01-03 21:22:43 +000028 */
Paul Bakker40e46942009-01-03 21:51:57 +000029#ifndef POLARSSL_MD2_H
30#define POLARSSL_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000031
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020033#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020034#else
35#include POLARSSL_CONFIG_FILE
36#endif
Paul Bakker90995b52013-06-24 19:20:35 +020037
Rich Evans00ab4702015-02-06 13:43:58 +000038#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000039
Paul Bakker69e095c2011-12-10 21:55:01 +000040#define POLARSSL_ERR_MD2_FILE_IO_ERROR -0x0070 /**< Read/write error in file. */
41
Paul Bakker90995b52013-06-24 19:20:35 +020042#if !defined(POLARSSL_MD2_ALT)
43// Regular implementation
44//
45
Paul Bakker407a0da2013-06-27 14:29:21 +020046#ifdef __cplusplus
47extern "C" {
48#endif
49
Paul Bakker5121ce52009-01-03 21:22:43 +000050/**
51 * \brief MD2 context structure
Hanno Beckerce0c9db2017-09-28 15:39:45 +010052 *
53 * \warning MD2 is considered a weak message digest and its use
54 * constitutes a security risk. We recommend considering
55 * stronger message digests instead.
56 *
Paul Bakker5121ce52009-01-03 21:22:43 +000057 */
58typedef struct
59{
60 unsigned char cksum[16]; /*!< checksum of the data block */
61 unsigned char state[48]; /*!< intermediate digest state */
62 unsigned char buffer[16]; /*!< data block being processed */
63
Paul Bakkerfa1c5922011-10-06 14:18:49 +000064 unsigned char ipad[16]; /*!< HMAC: inner padding */
65 unsigned char opad[16]; /*!< HMAC: outer padding */
Paul Bakker23986e52011-04-24 08:57:21 +000066 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000067}
68md2_context;
69
Paul Bakker5121ce52009-01-03 21:22:43 +000070/**
Paul Bakker5b4af392014-06-26 12:09:34 +020071 * \brief Initialize MD2 context
72 *
73 * \param ctx MD2 context to be initialized
Hanno Beckerce0c9db2017-09-28 15:39:45 +010074 *
75 * \warning MD2 is considered a weak message digest and its use
76 * constitutes a security risk. We recommend considering
77 * stronger message digests instead.
78 *
Paul Bakker5b4af392014-06-26 12:09:34 +020079 */
80void md2_init( md2_context *ctx );
81
82/**
83 * \brief Clear MD2 context
84 *
85 * \param ctx MD2 context to be cleared
Hanno Beckerce0c9db2017-09-28 15:39:45 +010086 *
87 * \warning MD2 is considered a weak message digest and its use
88 * constitutes a security risk. We recommend considering
89 * stronger message digests instead.
90 *
Paul Bakker5b4af392014-06-26 12:09:34 +020091 */
92void md2_free( md2_context *ctx );
93
94/**
Paul Bakker5121ce52009-01-03 21:22:43 +000095 * \brief MD2 context setup
96 *
97 * \param ctx context to be initialized
Hanno Beckerce0c9db2017-09-28 15:39:45 +010098 *
99 * \warning MD2 is considered a weak message digest and its use
100 * constitutes a security risk. We recommend considering
101 * stronger message digests instead.
102 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000103 */
104void md2_starts( md2_context *ctx );
105
106/**
107 * \brief MD2 process buffer
108 *
109 * \param ctx MD2 context
110 * \param input buffer holding the data
111 * \param ilen length of the input data
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100112 *
113 * \warning MD2 is considered a weak message digest and its use
114 * constitutes a security risk. We recommend considering
115 * stronger message digests instead.
116 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000117 */
Paul Bakker23986e52011-04-24 08:57:21 +0000118void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
120/**
121 * \brief MD2 final digest
122 *
123 * \param ctx MD2 context
124 * \param output MD2 checksum result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100125 *
126 * \warning MD2 is considered a weak message digest and its use
127 * constitutes a security risk. We recommend considering
128 * stronger message digests instead.
129 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 */
131void md2_finish( md2_context *ctx, unsigned char output[16] );
132
Paul Bakker90995b52013-06-24 19:20:35 +0200133#ifdef __cplusplus
134}
135#endif
136
137#else /* POLARSSL_MD2_ALT */
138#include "md2_alt.h"
139#endif /* POLARSSL_MD2_ALT */
140
141#ifdef __cplusplus
142extern "C" {
143#endif
144
Paul Bakker5121ce52009-01-03 21:22:43 +0000145/**
146 * \brief Output = MD2( input buffer )
147 *
148 * \param input buffer holding the data
149 * \param ilen length of the input data
150 * \param output MD2 checksum result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100151 *
152 * \warning MD2 is considered a weak message digest and its use
153 * constitutes a security risk. We recommend considering
154 * stronger message digests instead.
155 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 */
Paul Bakker23986e52011-04-24 08:57:21 +0000157void md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000158
159/**
160 * \brief Output = MD2( file contents )
161 *
162 * \param path input file name
163 * \param output MD2 checksum result
164 *
Paul Bakker69e095c2011-12-10 21:55:01 +0000165 * \return 0 if successful, or POLARSSL_ERR_MD2_FILE_IO_ERROR
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100166 *
167 * \warning MD2 is considered a weak message digest and its use
168 * constitutes a security risk. We recommend considering
169 * stronger message digests instead.
170 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000171 */
Paul Bakkerff60ee62010-03-16 21:09:09 +0000172int md2_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000173
174/**
175 * \brief MD2 HMAC context setup
176 *
177 * \param ctx HMAC context to be initialized
178 * \param key HMAC secret key
179 * \param keylen length of the HMAC key
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100180 *
181 * \warning MD2 is considered a weak message digest and its use
182 * constitutes a security risk. We recommend considering
183 * stronger message digests instead.
184 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000185 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200186void md2_hmac_starts( md2_context *ctx, const unsigned char *key,
187 size_t keylen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000188
189/**
190 * \brief MD2 HMAC process buffer
191 *
192 * \param ctx HMAC context
193 * \param input buffer holding the data
194 * \param ilen length of the input data
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100195 *
196 * \warning MD2 is considered a weak message digest and its use
197 * constitutes a security risk. We recommend considering
198 * stronger message digests instead.
199 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000200 */
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200201void md2_hmac_update( md2_context *ctx, const unsigned char *input,
202 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000203
204/**
205 * \brief MD2 HMAC final digest
206 *
207 * \param ctx HMAC context
208 * \param output MD2 HMAC checksum result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100209 *
210 * \warning MD2 is considered a weak message digest and its use
211 * constitutes a security risk. We recommend considering
212 * stronger message digests instead.
213 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000214 */
215void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
216
217/**
Paul Bakker7d3b6612010-03-21 16:23:13 +0000218 * \brief MD2 HMAC context reset
219 *
220 * \param ctx HMAC context to be reset
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100221 *
222 * \warning MD2 is considered a weak message digest and its use
223 * constitutes a security risk. We recommend considering
224 * stronger message digests instead.
225 *
Paul Bakker7d3b6612010-03-21 16:23:13 +0000226 */
227void md2_hmac_reset( md2_context *ctx );
228
229/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000230 * \brief Output = HMAC-MD2( hmac key, input buffer )
231 *
232 * \param key HMAC secret key
233 * \param keylen length of the HMAC key
234 * \param input buffer holding the data
235 * \param ilen length of the input data
236 * \param output HMAC-MD2 result
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100237 *
238 * \warning MD2 is considered a weak message digest and its use
239 * constitutes a security risk. We recommend considering
240 * stronger message digests instead.
241 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000242 */
Paul Bakker23986e52011-04-24 08:57:21 +0000243void md2_hmac( const unsigned char *key, size_t keylen,
244 const unsigned char *input, size_t ilen,
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 unsigned char output[16] );
246
247/**
248 * \brief Checkup routine
249 *
250 * \return 0 if successful, or 1 if the test failed
Hanno Beckerce0c9db2017-09-28 15:39:45 +0100251 *
252 * \warning MD2 is considered a weak message digest and its use
253 * constitutes a security risk. We recommend considering
254 * stronger message digests instead.
255 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000256 */
257int md2_self_test( int verbose );
258
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100259/* Internal use */
260void md2_process( md2_context *ctx );
261
Paul Bakker5121ce52009-01-03 21:22:43 +0000262#ifdef __cplusplus
263}
264#endif
265
266#endif /* md2.h */