blob: efb11ffc91d8cf89d01533f988bc7fb33a5695db [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)
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
6 * \warning MD2 is considered a weak message digest and its use constitutes a
7 * security risk. We recommend considering stronger message digests
8 * instead.
Darryl Greena40a1012018-01-05 15:33:17 +00009 */
10/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020011 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020012 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000025 *
Paul Bakker5121ce52009-01-03 21:22:43 +000026 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#ifndef MBEDTLS_MD2_H
28#define MBEDTLS_MD2_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020029#include "mbedtls/private_access.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if !defined(MBEDTLS_CONFIG_FILE)
Jaeden Ameroc49fbbf2019-07-04 20:01:14 +010032#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020033#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#endif
Paul Bakker90995b52013-06-24 19:20:35 +020036
Rich Evans00ab4702015-02-06 13:43:58 +000037#include <stddef.h>
Paul Bakker23986e52011-04-24 08:57:21 +000038
Paul Bakker407a0da2013-06-27 14:29:21 +020039#ifdef __cplusplus
40extern "C" {
41#endif
42
Ron Eldorb2aacec2017-05-18 16:53:08 +030043#if !defined(MBEDTLS_MD2_ALT)
44// Regular implementation
45//
46
Paul Bakker5121ce52009-01-03 21:22:43 +000047/**
48 * \brief MD2 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010049 *
50 * \warning MD2 is considered a weak message digest and its use
51 * constitutes a security risk. We recommend considering
52 * stronger message digests instead.
53 *
Paul Bakker5121ce52009-01-03 21:22:43 +000054 */
Dawid Drozd428cc522018-07-24 10:02:47 +020055typedef struct mbedtls_md2_context
Paul Bakker5121ce52009-01-03 21:22:43 +000056{
Mateusz Starzyk846f0212021-05-19 19:44:07 +020057 unsigned char MBEDTLS_PRIVATE(cksum)[16]; /*!< checksum of the data block */
58 unsigned char MBEDTLS_PRIVATE(state)[48]; /*!< intermediate digest state */
59 unsigned char MBEDTLS_PRIVATE(buffer)[16]; /*!< data block being processed */
60 size_t MBEDTLS_PRIVATE(left); /*!< amount of data in buffer */
Paul Bakker5121ce52009-01-03 21:22:43 +000061}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062mbedtls_md2_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000063
Ron Eldorb2aacec2017-05-18 16:53:08 +030064#else /* MBEDTLS_MD2_ALT */
65#include "md2_alt.h"
66#endif /* MBEDTLS_MD2_ALT */
67
Paul Bakker5121ce52009-01-03 21:22:43 +000068/**
Paul Bakker5b4af392014-06-26 12:09:34 +020069 * \brief Initialize MD2 context
70 *
71 * \param ctx MD2 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010072 *
73 * \warning MD2 is considered a weak message digest and its use
74 * constitutes a security risk. We recommend considering
75 * stronger message digests instead.
76 *
Paul Bakker5b4af392014-06-26 12:09:34 +020077 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078void mbedtls_md2_init( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020079
80/**
81 * \brief Clear MD2 context
82 *
83 * \param ctx MD2 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010084 *
85 * \warning MD2 is considered a weak message digest and its use
86 * constitutes a security risk. We recommend considering
87 * stronger message digests instead.
88 *
Paul Bakker5b4af392014-06-26 12:09:34 +020089 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090void mbedtls_md2_free( mbedtls_md2_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020091
92/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020093 * \brief Clone (the state of) an MD2 context
94 *
95 * \param dst The destination context
96 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010097 *
98 * \warning MD2 is considered a weak message digest and its use
99 * constitutes a security risk. We recommend considering
100 * stronger message digests instead.
101 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +0200102 */
103void mbedtls_md2_clone( mbedtls_md2_context *dst,
104 const mbedtls_md2_context *src );
105
106/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 * \brief MD2 context setup
108 *
109 * \param ctx context to be initialized
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100110 *
111 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +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 */
TRodziewicz26371e42021-06-08 16:45:41 +0200118int mbedtls_md2_starts( mbedtls_md2_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
120/**
121 * \brief MD2 process buffer
122 *
123 * \param ctx MD2 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100124 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000125 * \param ilen length of the input data
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100126 *
127 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100128 *
129 * \warning MD2 is considered a weak message digest and its use
130 * constitutes a security risk. We recommend considering
131 * stronger message digests instead.
132 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 */
TRodziewicz26371e42021-06-08 16:45:41 +0200134int mbedtls_md2_update( mbedtls_md2_context *ctx,
135 const unsigned char *input,
136 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000137
138/**
139 * \brief MD2 final digest
140 *
141 * \param ctx MD2 context
142 * \param output MD2 checksum result
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100143 *
144 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100145 *
146 * \warning MD2 is considered a weak message digest and its use
147 * constitutes a security risk. We recommend considering
148 * stronger message digests instead.
149 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000150 */
TRodziewicz26371e42021-06-08 16:45:41 +0200151int mbedtls_md2_finish( mbedtls_md2_context *ctx,
152 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100153
154/**
155 * \brief MD2 process data block (internal use only)
156 *
157 * \param ctx MD2 context
158 *
159 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100160 *
161 * \warning MD2 is considered a weak message digest and its use
162 * constitutes a security risk. We recommend considering
163 * stronger message digests instead.
164 *
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100165 */
Andres Amaya Garciacccfe082017-06-28 10:36:39 +0100166int mbedtls_internal_md2_process( mbedtls_md2_context *ctx );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100167
Paul Bakker5121ce52009-01-03 21:22:43 +0000168/**
169 * \brief Output = MD2( input buffer )
170 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100171 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000172 * \param ilen length of the input data
173 * \param output MD2 checksum result
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100174 *
175 * \warning MD2 is considered a weak message digest and its use
176 * constitutes a security risk. We recommend considering
177 * stronger message digests instead.
178 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000179 */
TRodziewicz26371e42021-06-08 16:45:41 +0200180int mbedtls_md2( const unsigned char *input,
181 size_t ilen,
182 unsigned char output[16] );
Andres Amaya Garcia1d852132017-04-28 16:21:40 +0100183
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500184#if defined(MBEDTLS_SELF_TEST)
185
Paul Bakker5121ce52009-01-03 21:22:43 +0000186/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000187 * \brief Checkup routine
188 *
189 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100190 *
191 * \warning MD2 is considered a weak message digest and its use
192 * constitutes a security risk. We recommend considering
193 * stronger message digests instead.
194 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000195 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196int mbedtls_md2_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000197
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500198#endif /* MBEDTLS_SELF_TEST */
199
Paul Bakker5121ce52009-01-03 21:22:43 +0000200#ifdef __cplusplus
201}
202#endif
203
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204#endif /* mbedtls_md2.h */