blob: 1e67343221324b822b91c122173663912e9f8b40 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butchera02fe7c2016-01-03 16:14:14 +00002 * \file md5.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief MD5 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)
Hanno Becker15e49512017-09-25 14:53:51 +010022 *
23 * \warning MD5 is considered a weak message digest and its use constitutes a
24 * security risk. We recommend considering stronger message
25 * digests instead.
26 *
Paul Bakker5121ce52009-01-03 21:22:43 +000027 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#ifndef MBEDTLS_MD5_H
29#define MBEDTLS_MD5_H
Paul Bakker5121ce52009-01-03 21:22:43 +000030
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020032#include "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>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020038#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000039
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if !defined(MBEDTLS_MD5_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020041// Regular implementation
42//
43
Paul Bakker407a0da2013-06-27 14:29:21 +020044#ifdef __cplusplus
45extern "C" {
46#endif
47
Paul Bakker5121ce52009-01-03 21:22:43 +000048/**
49 * \brief MD5 context structure
Hanno Becker15e49512017-09-25 14:53:51 +010050 *
51 * \warning MD5 is considered a weak message digest and its use
52 * constitutes a security risk. We recommend considering
53 * stronger message digests instead.
54 *
Paul Bakker5121ce52009-01-03 21:22:43 +000055 */
56typedef struct
57{
Paul Bakker5c2364c2012-10-01 14:41:15 +000058 uint32_t total[2]; /*!< number of bytes processed */
59 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000060 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000061}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062mbedtls_md5_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000063
Paul Bakker5121ce52009-01-03 21:22:43 +000064/**
Paul Bakker5b4af392014-06-26 12:09:34 +020065 * \brief Initialize MD5 context
66 *
67 * \param ctx MD5 context to be initialized
Hanno Becker15e49512017-09-25 14:53:51 +010068 *
69 * \warning MD5 is considered a weak message digest and its use
70 * constitutes a security risk. We recommend considering
71 * stronger message digests instead.
72 *
Paul Bakker5b4af392014-06-26 12:09:34 +020073 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074void mbedtls_md5_init( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020075
76/**
77 * \brief Clear MD5 context
78 *
79 * \param ctx MD5 context to be cleared
Hanno Becker15e49512017-09-25 14:53:51 +010080 *
81 * \warning MD5 is considered a weak message digest and its use
82 * constitutes a security risk. We recommend considering
83 * stronger message digests instead.
84 *
Paul Bakker5b4af392014-06-26 12:09:34 +020085 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086void mbedtls_md5_free( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020087
88/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020089 * \brief Clone (the state of) an MD5 context
90 *
91 * \param dst The destination context
92 * \param src The context to be cloned
Hanno Becker15e49512017-09-25 14:53:51 +010093 *
94 * \warning MD5 is considered a weak message digest and its use
95 * constitutes a security risk. We recommend considering
96 * stronger message digests instead.
97 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020098 */
99void mbedtls_md5_clone( mbedtls_md5_context *dst,
100 const mbedtls_md5_context *src );
101
102/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000103 * \brief MD5 context setup
104 *
105 * \param ctx context to be initialized
Hanno Becker15e49512017-09-25 14:53:51 +0100106 *
107 * \warning MD5 is considered a weak message digest and its use
108 * constitutes a security risk. We recommend considering
109 * stronger message digests instead.
110 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000111 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112void mbedtls_md5_starts( mbedtls_md5_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000113
114/**
115 * \brief MD5 process buffer
116 *
117 * \param ctx MD5 context
118 * \param input buffer holding the data
119 * \param ilen length of the input data
Hanno Becker15e49512017-09-25 14:53:51 +0100120 *
121 * \warning MD5 is considered a weak message digest and its use
122 * constitutes a security risk. We recommend considering
123 * stronger message digests instead.
124 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000125 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +0000127
128/**
129 * \brief MD5 final digest
130 *
131 * \param ctx MD5 context
132 * \param output MD5 checksum result
Hanno Becker15e49512017-09-25 14:53:51 +0100133 *
134 * \warning MD5 is considered a weak message digest and its use
135 * constitutes a security risk. We recommend considering
136 * stronger message digests instead.
137 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000140
Paul Bakker90995b52013-06-24 19:20:35 +0200141/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] );
Paul Bakker90995b52013-06-24 19:20:35 +0200143
144#ifdef __cplusplus
145}
146#endif
147
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148#else /* MBEDTLS_MD5_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200149#include "md5_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150#endif /* MBEDTLS_MD5_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200151
152#ifdef __cplusplus
153extern "C" {
154#endif
155
Paul Bakker5121ce52009-01-03 21:22:43 +0000156/**
157 * \brief Output = MD5( input buffer )
158 *
159 * \param input buffer holding the data
160 * \param ilen length of the input data
161 * \param output MD5 checksum result
Hanno Becker15e49512017-09-25 14:53:51 +0100162 *
163 * \warning MD5 is considered a weak message digest and its use
164 * constitutes a security risk. We recommend considering
165 * stronger message digests instead.
166 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000167 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000169
170/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000171 * \brief Checkup routine
172 *
173 * \return 0 if successful, or 1 if the test failed
Hanno Becker15e49512017-09-25 14:53:51 +0100174 *
175 * \warning MD5 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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200180int mbedtls_md5_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000181
Paul Bakker5121ce52009-01-03 21:22:43 +0000182#ifdef __cplusplus
183}
184#endif
185
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186#endif /* mbedtls_md5.h */