Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers md5.h Source File

md5.h

00001 /**
00002  * \file md5.h
00003  *
00004  * \brief MD5 message digest algorithm (hash function)
00005  *
00006  * \warning   MD5 is considered a weak message digest and its use constitutes a
00007  *            security risk. We recommend considering stronger message
00008  *            digests instead.
00009  */
00010 /*
00011  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
00012  *  SPDX-License-Identifier: Apache-2.0
00013  *
00014  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
00015  *  not use this file except in compliance with the License.
00016  *  You may obtain a copy of the License at
00017  *
00018  *  http://www.apache.org/licenses/LICENSE-2.0
00019  *
00020  *  Unless required by applicable law or agreed to in writing, software
00021  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00022  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023  *  See the License for the specific language governing permissions and
00024  *  limitations under the License.
00025  *
00026  *  This file is part of mbed TLS (https://tls.mbed.org)
00027  */
00028 #ifndef MBEDTLS_MD5_H
00029 #define MBEDTLS_MD5_H
00030 
00031 #if !defined(MBEDTLS_CONFIG_FILE)
00032 #include "config.h"
00033 #else
00034 #include MBEDTLS_CONFIG_FILE
00035 #endif
00036 
00037 #include <stddef.h>
00038 #include <stdint.h>
00039 
00040 #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED                   -0x002F  /**< MD5 hardware accelerator failed */
00041 
00042 #if !defined(MBEDTLS_MD5_ALT)
00043 // Regular implementation
00044 //
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /**
00051  * \brief          MD5 context structure
00052  *
00053  * \warning        MD5 is considered a weak message digest and its use
00054  *                 constitutes a security risk. We recommend considering
00055  *                 stronger message digests instead.
00056  *
00057  */
00058 typedef struct
00059 {
00060     uint32_t total[2];          /*!< number of bytes processed  */
00061     uint32_t state[4];          /*!< intermediate digest state  */
00062     unsigned char buffer[64];   /*!< data block being processed */
00063 }
00064 mbedtls_md5_context;
00065 
00066 /**
00067  * \brief          Initialize MD5 context
00068  *
00069  * \param ctx      MD5 context to be initialized
00070  *
00071  * \warning        MD5 is considered a weak message digest and its use
00072  *                 constitutes a security risk. We recommend considering
00073  *                 stronger message digests instead.
00074  *
00075  */
00076 void mbedtls_md5_init( mbedtls_md5_context *ctx );
00077 
00078 /**
00079  * \brief          Clear MD5 context
00080  *
00081  * \param ctx      MD5 context to be cleared
00082  *
00083  * \warning        MD5 is considered a weak message digest and its use
00084  *                 constitutes a security risk. We recommend considering
00085  *                 stronger message digests instead.
00086  *
00087  */
00088 void mbedtls_md5_free( mbedtls_md5_context *ctx );
00089 
00090 /**
00091  * \brief          Clone (the state of) an MD5 context
00092  *
00093  * \param dst      The destination context
00094  * \param src      The context to be cloned
00095  *
00096  * \warning        MD5 is considered a weak message digest and its use
00097  *                 constitutes a security risk. We recommend considering
00098  *                 stronger message digests instead.
00099  *
00100  */
00101 void mbedtls_md5_clone( mbedtls_md5_context *dst,
00102                         const mbedtls_md5_context *src );
00103 
00104 /**
00105  * \brief          MD5 context setup
00106  *
00107  * \param ctx      context to be initialized
00108  *
00109  * \return         0 if successful
00110  *
00111  * \warning        MD5 is considered a weak message digest and its use
00112  *                 constitutes a security risk. We recommend considering
00113  *                 stronger message digests instead.
00114  *
00115  */
00116 int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
00117 
00118 /**
00119  * \brief          MD5 process buffer
00120  *
00121  * \param ctx      MD5 context
00122  * \param input    buffer holding the data
00123  * \param ilen     length of the input data
00124  *
00125  * \return         0 if successful
00126  *
00127  * \warning        MD5 is considered a weak message digest and its use
00128  *                 constitutes a security risk. We recommend considering
00129  *                 stronger message digests instead.
00130  *
00131  */
00132 int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
00133                             const unsigned char *input,
00134                             size_t ilen );
00135 
00136 /**
00137  * \brief          MD5 final digest
00138  *
00139  * \param ctx      MD5 context
00140  * \param output   MD5 checksum result
00141  *
00142  * \return         0 if successful
00143  *
00144  * \warning        MD5 is considered a weak message digest and its use
00145  *                 constitutes a security risk. We recommend considering
00146  *                 stronger message digests instead.
00147  *
00148  */
00149 int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
00150                             unsigned char output[16] );
00151 
00152 /**
00153  * \brief          MD5 process data block (internal use only)
00154  *
00155  * \param ctx      MD5 context
00156  * \param data     buffer holding one block of data
00157  *
00158  * \return         0 if successful
00159  *
00160  * \warning        MD5 is considered a weak message digest and its use
00161  *                 constitutes a security risk. We recommend considering
00162  *                 stronger message digests instead.
00163  *
00164  */
00165 int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
00166                                   const unsigned char data[64] );
00167 
00168 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00169 #if defined(MBEDTLS_DEPRECATED_WARNING)
00170 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00171 #else
00172 #define MBEDTLS_DEPRECATED
00173 #endif
00174 /**
00175  * \brief          MD5 context setup
00176  *
00177  * \deprecated     Superseded by mbedtls_md5_starts_ret() in 2.7.0
00178  *
00179  * \param ctx      context to be initialized
00180  *
00181  * \warning        MD5 is considered a weak message digest and its use
00182  *                 constitutes a security risk. We recommend considering
00183  *                 stronger message digests instead.
00184  *
00185  */
00186 MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
00187 
00188 /**
00189  * \brief          MD5 process buffer
00190  *
00191  * \deprecated     Superseded by mbedtls_md5_update_ret() in 2.7.0
00192  *
00193  * \param ctx      MD5 context
00194  * \param input    buffer holding the data
00195  * \param ilen     length of the input data
00196  *
00197  * \warning        MD5 is considered a weak message digest and its use
00198  *                 constitutes a security risk. We recommend considering
00199  *                 stronger message digests instead.
00200  *
00201  */
00202 MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
00203                                             const unsigned char *input,
00204                                             size_t ilen );
00205 
00206 /**
00207  * \brief          MD5 final digest
00208  *
00209  * \deprecated     Superseded by mbedtls_md5_finish_ret() in 2.7.0
00210  *
00211  * \param ctx      MD5 context
00212  * \param output   MD5 checksum result
00213  *
00214  * \warning        MD5 is considered a weak message digest and its use
00215  *                 constitutes a security risk. We recommend considering
00216  *                 stronger message digests instead.
00217  *
00218  */
00219 MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
00220                                             unsigned char output[16] );
00221 
00222 /**
00223  * \brief          MD5 process data block (internal use only)
00224  *
00225  * \deprecated     Superseded by mbedtls_internal_md5_process() in 2.7.0
00226  *
00227  * \param ctx      MD5 context
00228  * \param data     buffer holding one block of data
00229  *
00230  * \warning        MD5 is considered a weak message digest and its use
00231  *                 constitutes a security risk. We recommend considering
00232  *                 stronger message digests instead.
00233  *
00234  */
00235 MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
00236                                              const unsigned char data[64] );
00237 
00238 #undef MBEDTLS_DEPRECATED
00239 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00240 
00241 #ifdef __cplusplus
00242 }
00243 #endif
00244 
00245 #else  /* MBEDTLS_MD5_ALT */
00246 #include "md5_alt.h"
00247 #endif /* MBEDTLS_MD5_ALT */
00248 
00249 #ifdef __cplusplus
00250 extern "C" {
00251 #endif
00252 
00253 /**
00254  * \brief          Output = MD5( input buffer )
00255  *
00256  * \param input    buffer holding the data
00257  * \param ilen     length of the input data
00258  * \param output   MD5 checksum result
00259  *
00260  * \return         0 if successful
00261  *
00262  * \warning        MD5 is considered a weak message digest and its use
00263  *                 constitutes a security risk. We recommend considering
00264  *                 stronger message digests instead.
00265  *
00266  */
00267 int mbedtls_md5_ret( const unsigned char *input,
00268                      size_t ilen,
00269                      unsigned char output[16] );
00270 
00271 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00272 #if defined(MBEDTLS_DEPRECATED_WARNING)
00273 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00274 #else
00275 #define MBEDTLS_DEPRECATED
00276 #endif
00277 /**
00278  * \brief          Output = MD5( input buffer )
00279  *
00280  * \deprecated     Superseded by mbedtls_md5_ret() in 2.7.0
00281  *
00282  * \param input    buffer holding the data
00283  * \param ilen     length of the input data
00284  * \param output   MD5 checksum result
00285  *
00286  * \warning        MD5 is considered a weak message digest and its use
00287  *                 constitutes a security risk. We recommend considering
00288  *                 stronger message digests instead.
00289  *
00290  */
00291 MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
00292                                      size_t ilen,
00293                                      unsigned char output[16] );
00294 
00295 #undef MBEDTLS_DEPRECATED
00296 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00297 
00298 /**
00299  * \brief          Checkup routine
00300  *
00301  * \return         0 if successful, or 1 if the test failed
00302  *
00303  * \warning        MD5 is considered a weak message digest and its use
00304  *                 constitutes a security risk. We recommend considering
00305  *                 stronger message digests instead.
00306  *
00307  */
00308 int mbedtls_md5_self_test( int verbose );
00309 
00310 #ifdef __cplusplus
00311 }
00312 #endif
00313 
00314 #endif /* mbedtls_md5.h */