Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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 "mbedtls/config.h"
00033 #else
00034 #include MBEDTLS_CONFIG_FILE
00035 #endif
00036 
00037 #include <stddef.h>
00038 #include <stdint.h>
00039 
00040 /* MBEDTLS_ERR_MD5_HW_ACCEL_FAILED is deprecated and should not be used. */
00041 #define MBEDTLS_ERR_MD5_HW_ACCEL_FAILED                   -0x002F  /**< MD5 hardware accelerator failed */
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 #if !defined(MBEDTLS_MD5_ALT)
00048 // Regular implementation
00049 //
00050 
00051 /**
00052  * \brief          MD5 context structure
00053  *
00054  * \warning        MD5 is considered a weak message digest and its use
00055  *                 constitutes a security risk. We recommend considering
00056  *                 stronger message digests instead.
00057  *
00058  */
00059 typedef struct mbedtls_md5_context
00060 {
00061     uint32_t total [2];          /*!< number of bytes processed  */
00062     uint32_t state [4];          /*!< intermediate digest state  */
00063     unsigned char buffer[64];   /*!< data block being processed */
00064 }
00065 mbedtls_md5_context;
00066 
00067 #else  /* MBEDTLS_MD5_ALT */
00068 #include "md5_alt.h"
00069 #endif /* MBEDTLS_MD5_ALT */
00070 
00071 /**
00072  * \brief          Initialize MD5 context
00073  *
00074  * \param ctx      MD5 context to be initialized
00075  *
00076  * \warning        MD5 is considered a weak message digest and its use
00077  *                 constitutes a security risk. We recommend considering
00078  *                 stronger message digests instead.
00079  *
00080  */
00081 void mbedtls_md5_init( mbedtls_md5_context *ctx );
00082 
00083 /**
00084  * \brief          Clear MD5 context
00085  *
00086  * \param ctx      MD5 context to be cleared
00087  *
00088  * \warning        MD5 is considered a weak message digest and its use
00089  *                 constitutes a security risk. We recommend considering
00090  *                 stronger message digests instead.
00091  *
00092  */
00093 void mbedtls_md5_free( mbedtls_md5_context *ctx );
00094 
00095 /**
00096  * \brief          Clone (the state of) an MD5 context
00097  *
00098  * \param dst      The destination context
00099  * \param src      The context to be cloned
00100  *
00101  * \warning        MD5 is considered a weak message digest and its use
00102  *                 constitutes a security risk. We recommend considering
00103  *                 stronger message digests instead.
00104  *
00105  */
00106 void mbedtls_md5_clone( mbedtls_md5_context *dst,
00107                         const mbedtls_md5_context *src );
00108 
00109 /**
00110  * \brief          MD5 context setup
00111  *
00112  * \param ctx      context to be initialized
00113  *
00114  * \return         0 if successful
00115  *
00116  * \warning        MD5 is considered a weak message digest and its use
00117  *                 constitutes a security risk. We recommend considering
00118  *                 stronger message digests instead.
00119  *
00120  */
00121 int mbedtls_md5_starts_ret( mbedtls_md5_context *ctx );
00122 
00123 /**
00124  * \brief          MD5 process buffer
00125  *
00126  * \param ctx      MD5 context
00127  * \param input    buffer holding the data
00128  * \param ilen     length of the input data
00129  *
00130  * \return         0 if successful
00131  *
00132  * \warning        MD5 is considered a weak message digest and its use
00133  *                 constitutes a security risk. We recommend considering
00134  *                 stronger message digests instead.
00135  *
00136  */
00137 int mbedtls_md5_update_ret( mbedtls_md5_context *ctx,
00138                             const unsigned char *input,
00139                             size_t ilen );
00140 
00141 /**
00142  * \brief          MD5 final digest
00143  *
00144  * \param ctx      MD5 context
00145  * \param output   MD5 checksum result
00146  *
00147  * \return         0 if successful
00148  *
00149  * \warning        MD5 is considered a weak message digest and its use
00150  *                 constitutes a security risk. We recommend considering
00151  *                 stronger message digests instead.
00152  *
00153  */
00154 int mbedtls_md5_finish_ret( mbedtls_md5_context *ctx,
00155                             unsigned char output[16] );
00156 
00157 /**
00158  * \brief          MD5 process data block (internal use only)
00159  *
00160  * \param ctx      MD5 context
00161  * \param data     buffer holding one block of data
00162  *
00163  * \return         0 if successful
00164  *
00165  * \warning        MD5 is considered a weak message digest and its use
00166  *                 constitutes a security risk. We recommend considering
00167  *                 stronger message digests instead.
00168  *
00169  */
00170 int mbedtls_internal_md5_process( mbedtls_md5_context *ctx,
00171                                   const unsigned char data[64] );
00172 
00173 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00174 #if defined(MBEDTLS_DEPRECATED_WARNING)
00175 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00176 #else
00177 #define MBEDTLS_DEPRECATED
00178 #endif
00179 /**
00180  * \brief          MD5 context setup
00181  *
00182  * \deprecated     Superseded by mbedtls_md5_starts_ret() in 2.7.0
00183  *
00184  * \param ctx      context to be initialized
00185  *
00186  * \warning        MD5 is considered a weak message digest and its use
00187  *                 constitutes a security risk. We recommend considering
00188  *                 stronger message digests instead.
00189  *
00190  */
00191 MBEDTLS_DEPRECATED void mbedtls_md5_starts( mbedtls_md5_context *ctx );
00192 
00193 /**
00194  * \brief          MD5 process buffer
00195  *
00196  * \deprecated     Superseded by mbedtls_md5_update_ret() in 2.7.0
00197  *
00198  * \param ctx      MD5 context
00199  * \param input    buffer holding the data
00200  * \param ilen     length of the input data
00201  *
00202  * \warning        MD5 is considered a weak message digest and its use
00203  *                 constitutes a security risk. We recommend considering
00204  *                 stronger message digests instead.
00205  *
00206  */
00207 MBEDTLS_DEPRECATED void mbedtls_md5_update( mbedtls_md5_context *ctx,
00208                                             const unsigned char *input,
00209                                             size_t ilen );
00210 
00211 /**
00212  * \brief          MD5 final digest
00213  *
00214  * \deprecated     Superseded by mbedtls_md5_finish_ret() in 2.7.0
00215  *
00216  * \param ctx      MD5 context
00217  * \param output   MD5 checksum result
00218  *
00219  * \warning        MD5 is considered a weak message digest and its use
00220  *                 constitutes a security risk. We recommend considering
00221  *                 stronger message digests instead.
00222  *
00223  */
00224 MBEDTLS_DEPRECATED void mbedtls_md5_finish( mbedtls_md5_context *ctx,
00225                                             unsigned char output[16] );
00226 
00227 /**
00228  * \brief          MD5 process data block (internal use only)
00229  *
00230  * \deprecated     Superseded by mbedtls_internal_md5_process() in 2.7.0
00231  *
00232  * \param ctx      MD5 context
00233  * \param data     buffer holding one block of data
00234  *
00235  * \warning        MD5 is considered a weak message digest and its use
00236  *                 constitutes a security risk. We recommend considering
00237  *                 stronger message digests instead.
00238  *
00239  */
00240 MBEDTLS_DEPRECATED void mbedtls_md5_process( mbedtls_md5_context *ctx,
00241                                              const unsigned char data[64] );
00242 
00243 #undef MBEDTLS_DEPRECATED
00244 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00245 
00246 /**
00247  * \brief          Output = MD5( input buffer )
00248  *
00249  * \param input    buffer holding the data
00250  * \param ilen     length of the input data
00251  * \param output   MD5 checksum result
00252  *
00253  * \return         0 if successful
00254  *
00255  * \warning        MD5 is considered a weak message digest and its use
00256  *                 constitutes a security risk. We recommend considering
00257  *                 stronger message digests instead.
00258  *
00259  */
00260 int mbedtls_md5_ret( const unsigned char *input,
00261                      size_t ilen,
00262                      unsigned char output[16] );
00263 
00264 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00265 #if defined(MBEDTLS_DEPRECATED_WARNING)
00266 #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
00267 #else
00268 #define MBEDTLS_DEPRECATED
00269 #endif
00270 /**
00271  * \brief          Output = MD5( input buffer )
00272  *
00273  * \deprecated     Superseded by mbedtls_md5_ret() in 2.7.0
00274  *
00275  * \param input    buffer holding the data
00276  * \param ilen     length of the input data
00277  * \param output   MD5 checksum result
00278  *
00279  * \warning        MD5 is considered a weak message digest and its use
00280  *                 constitutes a security risk. We recommend considering
00281  *                 stronger message digests instead.
00282  *
00283  */
00284 MBEDTLS_DEPRECATED void mbedtls_md5( const unsigned char *input,
00285                                      size_t ilen,
00286                                      unsigned char output[16] );
00287 
00288 #undef MBEDTLS_DEPRECATED
00289 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
00290 
00291 #if defined(MBEDTLS_SELF_TEST)
00292 
00293 /**
00294  * \brief          Checkup routine
00295  *
00296  * \return         0 if successful, or 1 if the test failed
00297  *
00298  * \warning        MD5 is considered a weak message digest and its use
00299  *                 constitutes a security risk. We recommend considering
00300  *                 stronger message digests instead.
00301  *
00302  */
00303 int mbedtls_md5_self_test( int verbose );
00304 
00305 #endif /* MBEDTLS_SELF_TEST */
00306 
00307 #ifdef __cplusplus
00308 }
00309 #endif
00310 
00311 #endif /* mbedtls_md5.h */