blob: 378f63f58701907b61af5eb0b84b2e27ef4d68ec [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)
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_MD5_H
25#define MBEDTLS_MD5_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>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020034#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if !defined(MBEDTLS_MD5_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020037// Regular implementation
38//
39
Paul Bakker407a0da2013-06-27 14:29:21 +020040#ifdef __cplusplus
41extern "C" {
42#endif
43
Paul Bakker5121ce52009-01-03 21:22:43 +000044/**
45 * \brief MD5 context structure
46 */
47typedef struct
48{
Paul Bakker5c2364c2012-10-01 14:41:15 +000049 uint32_t total[2]; /*!< number of bytes processed */
50 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000051 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000052}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053mbedtls_md5_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Paul Bakker5121ce52009-01-03 21:22:43 +000055/**
Paul Bakker5b4af392014-06-26 12:09:34 +020056 * \brief Initialize MD5 context
57 *
58 * \param ctx MD5 context to be initialized
59 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060void 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
66 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067void mbedtls_md5_free( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020068
69/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020070 * \brief Clone (the state of) an MD5 context
71 *
72 * \param dst The destination context
73 * \param src The context to be cloned
74 */
75void mbedtls_md5_clone( mbedtls_md5_context *dst,
76 const mbedtls_md5_context *src );
77
78/**
Paul Bakker5121ce52009-01-03 21:22:43 +000079 * \brief MD5 context setup
80 *
81 * \param ctx context to be initialized
82 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083void mbedtls_md5_starts( mbedtls_md5_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000084
85/**
86 * \brief MD5 process buffer
87 *
88 * \param ctx MD5 context
89 * \param input buffer holding the data
90 * \param ilen length of the input data
91 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000093
94/**
95 * \brief MD5 final digest
96 *
97 * \param ctx MD5 context
98 * \param output MD5 checksum result
99 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000101
Paul Bakker90995b52013-06-24 19:20:35 +0200102/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] );
Paul Bakker90995b52013-06-24 19:20:35 +0200104
105#ifdef __cplusplus
106}
107#endif
108
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#else /* MBEDTLS_MD5_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200110#include "md5_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#endif /* MBEDTLS_MD5_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200112
113#ifdef __cplusplus
114extern "C" {
115#endif
116
Paul Bakker5121ce52009-01-03 21:22:43 +0000117/**
118 * \brief Output = MD5( input buffer )
119 *
120 * \param input buffer holding the data
121 * \param ilen length of the input data
122 * \param output MD5 checksum result
123 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
126/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 * \brief Checkup routine
128 *
129 * \return 0 if successful, or 1 if the test failed
130 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131int mbedtls_md5_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000132
Paul Bakker5121ce52009-01-03 21:22:43 +0000133#ifdef __cplusplus
134}
135#endif
136
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137#endif /* mbedtls_md5.h */