blob: 6bf0754a4a688f528db192331c246c5b880f5993 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butcher5b331b92016-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)
Hanno Beckerbbca8c52017-09-25 14:53:51 +01005 *
6 * \warning MD5 is considered a weak message digest and its use constitutes a
7 * security risk. We recommend considering stronger message
8 * digests 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
Dave Rodgman16799db2023-11-02 19:47:20 +000012 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker5121ce52009-01-03 21:22:43 +000013 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014#ifndef MBEDTLS_MD5_H
15#define MBEDTLS_MD5_H
Mateusz Starzyk846f0212021-05-19 19:44:07 +020016#include "mbedtls/private_access.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000017
Bence Szépkútic662b362021-05-27 11:25:03 +020018#include "mbedtls/build_info.h"
Paul Bakker90995b52013-06-24 19:20:35 +020019
Rich Evans00ab4702015-02-06 13:43:58 +000020#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020021#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000022
Paul Bakker407a0da2013-06-27 14:29:21 +020023#ifdef __cplusplus
24extern "C" {
25#endif
26
Ron Eldorb2aacec2017-05-18 16:53:08 +030027#if !defined(MBEDTLS_MD5_ALT)
28// Regular implementation
29//
30
Paul Bakker5121ce52009-01-03 21:22:43 +000031/**
32 * \brief MD5 context structure
Hanno Beckerbbca8c52017-09-25 14:53:51 +010033 *
34 * \warning MD5 is considered a weak message digest and its use
35 * constitutes a security risk. We recommend considering
36 * stronger message digests instead.
37 *
Paul Bakker5121ce52009-01-03 21:22:43 +000038 */
Gilles Peskine449bd832023-01-11 14:50:10 +010039typedef struct mbedtls_md5_context {
Mateusz Starzyk846f0212021-05-19 19:44:07 +020040 uint32_t MBEDTLS_PRIVATE(total)[2]; /*!< number of bytes processed */
41 uint32_t MBEDTLS_PRIVATE(state)[4]; /*!< intermediate digest state */
42 unsigned char MBEDTLS_PRIVATE(buffer)[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000043}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044mbedtls_md5_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000045
Ron Eldorb2aacec2017-05-18 16:53:08 +030046#else /* MBEDTLS_MD5_ALT */
47#include "md5_alt.h"
48#endif /* MBEDTLS_MD5_ALT */
49
Paul Bakker5121ce52009-01-03 21:22:43 +000050/**
Paul Bakker5b4af392014-06-26 12:09:34 +020051 * \brief Initialize MD5 context
52 *
53 * \param ctx MD5 context to be initialized
Hanno Beckerbbca8c52017-09-25 14:53:51 +010054 *
55 * \warning MD5 is considered a weak message digest and its use
56 * constitutes a security risk. We recommend considering
57 * stronger message digests instead.
58 *
Paul Bakker5b4af392014-06-26 12:09:34 +020059 */
Gilles Peskine449bd832023-01-11 14:50:10 +010060void mbedtls_md5_init(mbedtls_md5_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020061
62/**
63 * \brief Clear MD5 context
64 *
65 * \param ctx MD5 context to be cleared
Hanno Beckerbbca8c52017-09-25 14:53:51 +010066 *
67 * \warning MD5 is considered a weak message digest and its use
68 * constitutes a security risk. We recommend considering
69 * stronger message digests instead.
70 *
Paul Bakker5b4af392014-06-26 12:09:34 +020071 */
Gilles Peskine449bd832023-01-11 14:50:10 +010072void mbedtls_md5_free(mbedtls_md5_context *ctx);
Paul Bakker5b4af392014-06-26 12:09:34 +020073
74/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020075 * \brief Clone (the state of) an MD5 context
76 *
77 * \param dst The destination context
78 * \param src The context to be cloned
Hanno Beckerbbca8c52017-09-25 14:53:51 +010079 *
80 * \warning MD5 is considered a weak message digest and its use
81 * constitutes a security risk. We recommend considering
82 * stronger message digests instead.
83 *
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020084 */
Gilles Peskine449bd832023-01-11 14:50:10 +010085void mbedtls_md5_clone(mbedtls_md5_context *dst,
86 const mbedtls_md5_context *src);
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020087
88/**
Paul Bakker5121ce52009-01-03 21:22:43 +000089 * \brief MD5 context setup
90 *
91 * \param ctx context to be initialized
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +010092 *
93 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +010094 *
95 * \warning MD5 is considered a weak message digest and its use
96 * constitutes a security risk. We recommend considering
97 * stronger message digests instead.
98 *
Paul Bakker5121ce52009-01-03 21:22:43 +000099 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100100int mbedtls_md5_starts(mbedtls_md5_context *ctx);
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
102/**
103 * \brief MD5 process buffer
104 *
105 * \param ctx MD5 context
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100106 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000107 * \param ilen length of the input data
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100108 *
109 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100110 *
111 * \warning MD5 is considered a weak message digest and its use
112 * constitutes a security risk. We recommend considering
113 * stronger message digests instead.
114 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000115 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100116int mbedtls_md5_update(mbedtls_md5_context *ctx,
117 const unsigned char *input,
118 size_t ilen);
Paul Bakker5121ce52009-01-03 21:22:43 +0000119
120/**
121 * \brief MD5 final digest
122 *
123 * \param ctx MD5 context
124 * \param output MD5 checksum result
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100125 *
126 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100127 *
128 * \warning MD5 is considered a weak message digest and its use
129 * constitutes a security risk. We recommend considering
130 * stronger message digests instead.
131 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100133int mbedtls_md5_finish(mbedtls_md5_context *ctx,
134 unsigned char output[16]);
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100136/**
137 * \brief MD5 process data block (internal use only)
138 *
139 * \param ctx MD5 context
140 * \param data buffer holding one block of data
141 *
142 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100143 *
144 * \warning MD5 is considered a weak message digest and its use
145 * constitutes a security risk. We recommend considering
146 * stronger message digests instead.
147 *
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100148 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100149int mbedtls_internal_md5_process(mbedtls_md5_context *ctx,
150 const unsigned char data[64]);
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100151
Paul Bakker5121ce52009-01-03 21:22:43 +0000152/**
153 * \brief Output = MD5( input buffer )
154 *
Andres Amaya Garciaa21247e2017-07-20 14:01:08 +0100155 * \param input buffer holding the data
Paul Bakker5121ce52009-01-03 21:22:43 +0000156 * \param ilen length of the input data
157 * \param output MD5 checksum result
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100158 *
159 * \return 0 if successful
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100160 *
161 * \warning MD5 is considered a weak message digest and its use
162 * constitutes a security risk. We recommend considering
163 * stronger message digests instead.
164 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000165 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100166int mbedtls_md5(const unsigned char *input,
167 size_t ilen,
168 unsigned char output[16]);
Andres Amaya Garcia2cfd7a92017-05-02 10:19:27 +0100169
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500170#if defined(MBEDTLS_SELF_TEST)
171
Paul Bakker5121ce52009-01-03 21:22:43 +0000172/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000173 * \brief Checkup routine
174 *
175 * \return 0 if successful, or 1 if the test failed
Hanno Beckerbbca8c52017-09-25 14:53:51 +0100176 *
177 * \warning MD5 is considered a weak message digest and its use
178 * constitutes a security risk. We recommend considering
179 * stronger message digests instead.
180 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000181 */
Gilles Peskine449bd832023-01-11 14:50:10 +0100182int mbedtls_md5_self_test(int verbose);
Paul Bakker5121ce52009-01-03 21:22:43 +0000183
Andrzej Kurekc470b6b2019-01-31 08:20:20 -0500184#endif /* MBEDTLS_SELF_TEST */
185
Paul Bakker5121ce52009-01-03 21:22:43 +0000186#ifdef __cplusplus
187}
188#endif
189
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190#endif /* mbedtls_md5.h */