blob: 0e26570271b45bdd5c7da0b778f4b650fd4b3af3 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002 * \file mbedtls_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é-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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#define MBEDTLS_ERR_MD5_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
Paul Bakker69e095c2011-12-10 21:55:01 +000037
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020038#if !defined(MBEDTLS_MD5_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020039// Regular implementation
40//
41
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Paul Bakker5121ce52009-01-03 21:22:43 +000046/**
47 * \brief MD5 context structure
48 */
49typedef struct
50{
Paul Bakker5c2364c2012-10-01 14:41:15 +000051 uint32_t total[2]; /*!< number of bytes processed */
52 uint32_t state[4]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000053 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000054}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055mbedtls_md5_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000056
Paul Bakker5121ce52009-01-03 21:22:43 +000057/**
Paul Bakker5b4af392014-06-26 12:09:34 +020058 * \brief Initialize MD5 context
59 *
60 * \param ctx MD5 context to be initialized
61 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062void mbedtls_md5_init( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020063
64/**
65 * \brief Clear MD5 context
66 *
67 * \param ctx MD5 context to be cleared
68 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069void mbedtls_md5_free( mbedtls_md5_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020070
71/**
Paul Bakker5121ce52009-01-03 21:22:43 +000072 * \brief MD5 context setup
73 *
74 * \param ctx context to be initialized
75 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076void mbedtls_md5_starts( mbedtls_md5_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000077
78/**
79 * \brief MD5 process buffer
80 *
81 * \param ctx MD5 context
82 * \param input buffer holding the data
83 * \param ilen length of the input data
84 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085void mbedtls_md5_update( mbedtls_md5_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000086
87/**
88 * \brief MD5 final digest
89 *
90 * \param ctx MD5 context
91 * \param output MD5 checksum result
92 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093void mbedtls_md5_finish( mbedtls_md5_context *ctx, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +000094
Paul Bakker90995b52013-06-24 19:20:35 +020095/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096void mbedtls_md5_process( mbedtls_md5_context *ctx, const unsigned char data[64] );
Paul Bakker90995b52013-06-24 19:20:35 +020097
98#ifdef __cplusplus
99}
100#endif
101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102#else /* MBEDTLS_MD5_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200103#include "md5_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#endif /* MBEDTLS_MD5_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200105
106#ifdef __cplusplus
107extern "C" {
108#endif
109
Paul Bakker5121ce52009-01-03 21:22:43 +0000110/**
111 * \brief Output = MD5( input buffer )
112 *
113 * \param input buffer holding the data
114 * \param ilen length of the input data
115 * \param output MD5 checksum result
116 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117void mbedtls_md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000118
119/**
120 * \brief Output = MD5( file contents )
121 *
122 * \param path input file name
123 * \param output MD5 checksum result
124 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125 * \return 0 if successful, or MBEDTLS_ERR_MD5_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127int mbedtls_md5_file( const char *path, unsigned char output[16] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000128
129/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000130 * \brief Checkup routine
131 *
132 * \return 0 if successful, or 1 if the test failed
133 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134int mbedtls_md5_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000135
Paul Bakker5121ce52009-01-03 21:22:43 +0000136#ifdef __cplusplus
137}
138#endif
139
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#endif /* mbedtls_md5.h */