blob: 1d81c2844d99dbe4faa34a6d45a0063f0419c265 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \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é-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
10 * not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_MD2_H
24#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020027#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker90995b52013-06-24 19:20:35 +020031
Rich Evans00ab4702015-02-06 13:43:58 +000032#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000033
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010034#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
35 !defined(inline) && !defined(__cplusplus)
36#define inline __inline
37#endif
38
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if !defined(MBEDTLS_MD2_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020040// Regular implementation
41//
42
Paul Bakker407a0da2013-06-27 14:29:21 +020043#ifdef __cplusplus
44extern "C" {
45#endif
46
Paul Bakker5121ce52009-01-03 21:22:43 +000047/**
48 * \brief MD2 context structure
49 */
50typedef struct
51{
52 unsigned char cksum[16]; /*!< checksum of the data block */
53 unsigned char state[48]; /*!< intermediate digest state */
54 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000055 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000056}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000058
Paul Bakker5121ce52009-01-03 21:22:43 +000059/**
Paul Bakker5b4af392014-06-26 12:09:34 +020060 * \brief Initialize MD2 context
61 *
62 * \param ctx MD2 context to be initialized
63 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020065
66/**
67 * \brief Clear MD2 context
68 *
69 * \param ctx MD2 context to be cleared
70 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020072
73/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020074 * \brief Clone (the state of) an MD2 context
75 *
76 * \param dst The destination context
77 * \param src The context to be cloned
78 */
79void mbedtls_md2_clone( mbedtls_md2_context *dst,
80 const mbedtls_md2_context *src );
81
82/**
Paul Bakker5121ce52009-01-03 21:22:43 +000083 * \brief MD2 context setup
84 *
85 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010086 *
87 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000088 */
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010089int mbedtls_md2_starts_ext( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000090
91/**
92 * \brief MD2 process buffer
93 *
94 * \param ctx MD2 context
95 * \param input buffer holding the data
96 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010097 *
98 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000099 */
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100100int mbedtls_md2_update_ext( mbedtls_md2_context *ctx,
101 const unsigned char *input,
102 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
104/**
105 * \brief MD2 final digest
106 *
107 * \param ctx MD2 context
108 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100109 *
110 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +0000111 */
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100112int mbedtls_md2_finish_ext( mbedtls_md2_context *ctx,
113 unsigned char output[16] );
114
115/**
116 * \brief MD2 process data block (internal use only)
117 *
118 * \param ctx MD2 context
119 *
120 * \return 0 if successful
121 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100122int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100123
124#if !defined(MBEDTLS_DEPRECATED_REMOVED)
125#if defined(MBEDTLS_DEPRECATED_WARNING)
126#define MBEDTLS_DEPRECATED __attribute__((deprecated))
127#else
128#define MBEDTLS_DEPRECATED
129#endif
130/**
131 * \brief MD2 context setup
132 *
133 * \deprecated Superseded by mbedtls_md2_starts_ext() in 2.5.0
134 *
135 * \param ctx context to be initialized
136 */
137MBEDTLS_DEPRECATED static inline void mbedtls_md2_starts(
138 mbedtls_md2_context *ctx )
139{
140 mbedtls_md2_starts_ext( ctx );
141}
142
143/**
144 * \brief MD2 process buffer
145 *
146 * \deprecated Superseded by mbedtls_md2_update_ext() in 2.5.0
147 *
148 * \param ctx MD2 context
149 * \param input buffer holding the data
150 * \param ilen length of the input data
151 */
152MBEDTLS_DEPRECATED static inline void mbedtls_md2_update(
153 mbedtls_md2_context *ctx,
154 const unsigned char *input,
155 size_t ilen )
156{
157 mbedtls_md2_update_ext( ctx, input, ilen );
158}
159
160/**
161 * \brief MD2 final digest
162 *
163 * \deprecated Superseded by mbedtls_md2_finish_ext() in 2.5.0
164 *
165 * \param ctx MD2 context
166 * \param output MD2 checksum result
167 */
168MBEDTLS_DEPRECATED static inline void mbedtls_md2_finish(
169 mbedtls_md2_context *ctx,
170 unsigned char output[16] )
171{
172 mbedtls_md2_finish_ext( ctx, output );
173}
174
175/**
176 * \brief MD2 process data block (internal use only)
177 *
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100178 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.5.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100179 *
180 * \param ctx MD2 context
181 */
182MBEDTLS_DEPRECATED static inline void mbedtls_md2_process(
183 mbedtls_md2_context *ctx )
184{
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100185 mbedtls_internal_md2_process( ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100186}
187
188#undef MBEDTLS_DEPRECATED
189#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000190
Paul Bakker90995b52013-06-24 19:20:35 +0200191#ifdef __cplusplus
192}
193#endif
194
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200195#else /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200196#include "md2_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#endif /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200198
199#ifdef __cplusplus
200extern "C" {
201#endif
202
Paul Bakker5121ce52009-01-03 21:22:43 +0000203/**
204 * \brief Output = MD2( input buffer )
205 *
206 * \param input buffer holding the data
207 * \param ilen length of the input data
208 * \param output MD2 checksum result
209 */
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100210int mbedtls_md2_ext( const unsigned char *input,
211 size_t ilen,
212 unsigned char output[16] );
213
214#if !defined(MBEDTLS_DEPRECATED_REMOVED)
215#if defined(MBEDTLS_DEPRECATED_WARNING)
216#define MBEDTLS_DEPRECATED __attribute__((deprecated))
217#else
218#define MBEDTLS_DEPRECATED
219#endif
220/**
221 * \brief Output = MD2( input buffer )
222 *
223 * \deprecated Superseded by mbedtls_md2() in 2.5.0
224 *
225 * \param input buffer holding the data
226 * \param ilen length of the input data
227 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100228 */
229MBEDTLS_DEPRECATED static inline void mbedtls_md2( const unsigned char *input,
230 size_t ilen,
231 unsigned char output[16] )
232{
233 mbedtls_md2_ext( input, ilen, output );
234}
235
236#undef MBEDTLS_DEPRECATED
237#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000238
239/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000240 * \brief Checkup routine
241 *
242 * \return 0 if successful, or 1 if the test failed
243 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000245
Paul Bakker5121ce52009-01-03 21:22:43 +0000246#ifdef __cplusplus
247}
248#endif
249
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200250#endif /* mbedtls_md2.h */