blob: b245b5b7bd90438f05185691a82698afd83d5a26 [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)
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_MD2_H
25#define MBEDTLS_MD2_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000034
Gilles Peskinea381fe82018-01-23 18:16:11 +010035#define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED -0x002B /**< MD2 hardware accelerator failed */
36
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010037#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
38 !defined(inline) && !defined(__cplusplus)
39#define inline __inline
40#endif
41
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042#if !defined(MBEDTLS_MD2_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020043// 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
52 */
53typedef struct
54{
55 unsigned char cksum[16]; /*!< checksum of the data block */
56 unsigned char state[48]; /*!< intermediate digest state */
57 unsigned char buffer[16]; /*!< data block being processed */
Paul Bakker23986e52011-04-24 08:57:21 +000058 size_t left; /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000059}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000061
Paul Bakker5121ce52009-01-03 21:22:43 +000062/**
Paul Bakker5b4af392014-06-26 12:09:34 +020063 * \brief Initialize MD2 context
64 *
65 * \param ctx MD2 context to be initialized
66 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020068
69/**
70 * \brief Clear MD2 context
71 *
72 * \param ctx MD2 context to be cleared
73 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020075
76/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020077 * \brief Clone (the state of) an MD2 context
78 *
79 * \param dst The destination context
80 * \param src The context to be cloned
81 */
82void mbedtls_md2_clone( mbedtls_md2_context *dst,
83 const mbedtls_md2_context *src );
84
85/**
Paul Bakker5121ce52009-01-03 21:22:43 +000086 * \brief MD2 context setup
87 *
88 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +010089 *
90 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +000091 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +010092int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000093
94/**
95 * \brief MD2 process buffer
96 *
97 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +010098 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +000099 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100100 *
101 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +0000102 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100103int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100104 const unsigned char *input,
105 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000106
107/**
108 * \brief MD2 final digest
109 *
110 * \param ctx MD2 context
111 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100112 *
113 * \return 0 if successful
Paul Bakker5121ce52009-01-03 21:22:43 +0000114 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100115int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100116 unsigned char output[16] );
117
118/**
119 * \brief MD2 process data block (internal use only)
120 *
121 * \param ctx MD2 context
122 *
123 * \return 0 if successful
124 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100125int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100126
127#if !defined(MBEDTLS_DEPRECATED_REMOVED)
128#if defined(MBEDTLS_DEPRECATED_WARNING)
129#define MBEDTLS_DEPRECATED __attribute__((deprecated))
130#else
131#define MBEDTLS_DEPRECATED
132#endif
133/**
134 * \brief MD2 context setup
135 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100136 * \deprecated Superseded by mbedtls_md2_starts_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100137 *
138 * \param ctx context to be initialized
139 */
140MBEDTLS_DEPRECATED static inline void mbedtls_md2_starts(
141 mbedtls_md2_context *ctx )
142{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100143 mbedtls_md2_starts_ret( ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100144}
145
146/**
147 * \brief MD2 process buffer
148 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100149 * \deprecated Superseded by mbedtls_md2_update_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100150 *
151 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100152 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100153 * \param ilen length of the input data
154 */
155MBEDTLS_DEPRECATED static inline void mbedtls_md2_update(
156 mbedtls_md2_context *ctx,
157 const unsigned char *input,
158 size_t ilen )
159{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100160 mbedtls_md2_update_ret( ctx, input, ilen );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100161}
162
163/**
164 * \brief MD2 final digest
165 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100166 * \deprecated Superseded by mbedtls_md2_finish_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100167 *
168 * \param ctx MD2 context
169 * \param output MD2 checksum result
170 */
171MBEDTLS_DEPRECATED static inline void mbedtls_md2_finish(
172 mbedtls_md2_context *ctx,
173 unsigned char output[16] )
174{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100175 mbedtls_md2_finish_ret( ctx, output );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100176}
177
178/**
179 * \brief MD2 process data block (internal use only)
180 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100181 * \deprecated Superseded by mbedtls_internal_md2_process() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100182 *
183 * \param ctx MD2 context
184 */
185MBEDTLS_DEPRECATED static inline void mbedtls_md2_process(
186 mbedtls_md2_context *ctx )
187{
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100188 mbedtls_internal_md2_process( ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100189}
190
191#undef MBEDTLS_DEPRECATED
192#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000193
Paul Bakker90995b52013-06-24 19:20:35 +0200194#ifdef __cplusplus
195}
196#endif
197
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200198#else /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200199#include "md2_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200#endif /* MBEDTLS_MD2_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200201
202#ifdef __cplusplus
203extern "C" {
204#endif
205
Paul Bakker5121ce52009-01-03 21:22:43 +0000206/**
207 * \brief Output = MD2( input buffer )
208 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100209 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000210 * \param ilen length of the input data
211 * \param output MD2 checksum result
212 */
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100213int mbedtls_md2_ret( const unsigned char *input,
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100214 size_t ilen,
215 unsigned char output[16] );
216
217#if !defined(MBEDTLS_DEPRECATED_REMOVED)
218#if defined(MBEDTLS_DEPRECATED_WARNING)
219#define MBEDTLS_DEPRECATED __attribute__((deprecated))
220#else
221#define MBEDTLS_DEPRECATED
222#endif
223/**
224 * \brief Output = MD2( input buffer )
225 *
Gilles Peskine3e28d702018-01-22 12:18:59 +0100226 * \deprecated Superseded by mbedtls_md2_ret() in 2.7.0
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100227 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100228 * \param input buffer holding the data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100229 * \param ilen length of the input data
230 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100231 */
232MBEDTLS_DEPRECATED static inline void mbedtls_md2( const unsigned char *input,
233 size_t ilen,
234 unsigned char output[16] )
235{
Gilles Peskine9e4f77c2018-01-22 11:48:08 +0100236 mbedtls_md2_ret( input, ilen, output );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100237}
238
239#undef MBEDTLS_DEPRECATED
240#endif /* !MBEDTLS_DEPRECATED_REMOVED */
Paul Bakker5121ce52009-01-03 21:22:43 +0000241
242/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000243 * \brief Checkup routine
244 *
245 * \return 0 if successful, or 1 if the test failed
246 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000248
Paul Bakker5121ce52009-01-03 21:22:43 +0000249#ifdef __cplusplus
250}
251#endif
252
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200253#endif /* mbedtls_md2.h */