blob: 1a9940bba2de7d02ec12ec691f5459b5f16c3160 [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
Gilles Peskinea381fe82018-01-23 18:16:11 +010034#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
35
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010036#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
37 !defined(inline) && !defined(__cplusplus)
38#define inline __inline
39#endif
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#if !defined(MBEDTLS_MD2_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020042// Regular implementation
43//
44
Paul Bakker407a0da2013-06-27 14:29:21 +020045#ifdef __cplusplus
46extern "C" {
47#endif
48
Paul Bakker5121ce52009-01-03 21:22:43 +000049/**
50 * \brief MD2 context structure
51 */
52typedef struct
53{
54 unsigned char cksum[16]; /*!< checksum of the data block */
55 unsigned char state[48]; /*!< intermediate digest state */
56 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000057 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000058}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000060
Paul Bakker5121ce52009-01-03 21:22:43 +000061/**
Paul Bakker5b4af392014-06-26 12:09:34 +020062 * \brief Initialize MD2 context
63 *
64 * \param ctx MD2 context to be initialized
65 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020067
68/**
69 * \brief Clear MD2 context
70 *
71 * \param ctx MD2 context to be cleared
72 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020074
75/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020076 * \brief Clone (the state of) an MD2 context
77 *
78 * \param dst The destination context
79 * \param src The context to be cloned
80 */
81void mbedtls_md2_clone( mbedtls_md2_context *dst,
82 const mbedtls_md2_context *src );
83
84/**
Paul Bakker5121ce52009-01-03 21:22:43 +000085 * \brief MD2 context setup
86 *
87 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010088 *
89 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000090 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010091int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000092
93/**
94 * \brief MD2 process buffer
95 *
96 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010097 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +000098 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010099 *
100 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +0000101 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100102int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100103 const unsigned char *input,
104 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000105
106/**
107 * \brief MD2 final digest
108 *
109 * \param ctx MD2 context
110 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100111 *
112 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +0000113 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100114int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100115 unsigned char output[16] );
116
117/**
118 * \brief MD2 process data block (internal use only)
119 *
120 * \param ctx MD2 context
121 *
122 * \return 0 if successful
123 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100124int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100125
126#if !defined(MBEDTLS_DEPRECATED_REMOVED)
127#if defined(MBEDTLS_DEPRECATED_WARNING)
128#define MBEDTLS_DEPRECATED __attribute__((deprecated))
129#else
130#define MBEDTLS_DEPRECATED
131#endif
132/**
133 * \brief MD2 context setup
134 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100135 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100136 *
137 * \param ctx context to be initialized
138 */
139MBEDTLS_DEPRECATED static inline void mbedtls_md2_starts(
140 mbedtls_md2_context *ctx )
141{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100142 mbedtls_md2_starts_ret( ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100143}
144
145/**
146 * \brief MD2 process buffer
147 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100148 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100149 *
150 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100151 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100152 * \param ilen length of the input data
153 */
154MBEDTLS_DEPRECATED static inline void mbedtls_md2_update(
155 mbedtls_md2_context *ctx,
156 const unsigned char *input,
157 size_t ilen )
158{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100159 mbedtls_md2_update_ret( ctx, input, ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100160}
161
162/**
163 * \brief MD2 final digest
164 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100165 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100166 *
167 * \param ctx MD2 context
168 * \param output MD2 checksum result
169 */
170MBEDTLS_DEPRECATED static inline void mbedtls_md2_finish(
171 mbedtls_md2_context *ctx,
172 unsigned char output[16] )
173{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100174 mbedtls_md2_finish_ret( ctx, output );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100175}
176
177/**
178 * \brief MD2 process data block (internal use only)
179 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100180 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100181 *
182 * \param ctx MD2 context
183 */
184MBEDTLS_DEPRECATED static inline void mbedtls_md2_process(
185 mbedtls_md2_context *ctx )
186{
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100187 mbedtls_internal_md2_process( ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100188}
189
190#undef MBEDTLS_DEPRECATED
191#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000192
Paul Bakker90995b52013-06-24 19:20:35 +0200193#ifdef __cplusplus
194}
195#endif
196
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#else /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200198#include "md2_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199#endif /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200200
201#ifdef __cplusplus
202extern "C" {
203#endif
204
Paul Bakker5121ce52009-01-03 21:22:43 +0000205/**
206 * \brief Output = MD2( input buffer )
207 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100208 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000209 * \param ilen length of the input data
210 * \param output MD2 checksum result
211 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100212int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100213 size_t ilen,
214 unsigned char output[16] );
215
216#if !defined(MBEDTLS_DEPRECATED_REMOVED)
217#if defined(MBEDTLS_DEPRECATED_WARNING)
218#define MBEDTLS_DEPRECATED __attribute__((deprecated))
219#else
220#define MBEDTLS_DEPRECATED
221#endif
222/**
223 * \brief Output = MD2( input buffer )
224 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100225 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100226 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100227 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100228 * \param ilen length of the input data
229 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100230 */
231MBEDTLS_DEPRECATED static inline void mbedtls_md2( const unsigned char *input,
232 size_t ilen,
233 unsigned char output[16] )
234{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100235 mbedtls_md2_ret( input, ilen, output );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100236}
237
238#undef MBEDTLS_DEPRECATED
239#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000240
241/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000242 * \brief Checkup routine
243 *
244 * \return 0 if successful, or 1 if the test failed
245 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000247
Paul Bakker5121ce52009-01-03 21:22:43 +0000248#ifdef __cplusplus
249}
250#endif
251
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252#endif /* mbedtls_md2.h */