Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-27 09:37:32

0001 /**
0002  * \file md5.h
0003  *
0004  * \brief MD5 message digest algorithm (hash function)
0005  *
0006  * \warning   MD5 is considered a weak message digest and its use constitutes a
0007  *            security risk. We recommend considering stronger message
0008  *            digests instead.
0009  */
0010 /*
0011  *  Copyright The Mbed TLS Contributors
0012  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
0013  */
0014 #ifndef MBEDTLS_MD5_H
0015 #define MBEDTLS_MD5_H
0016 #include "mbedtls/private_access.h"
0017 
0018 #include "mbedtls/build_info.h"
0019 
0020 #include <stddef.h>
0021 #include <stdint.h>
0022 
0023 #ifdef __cplusplus
0024 extern "C" {
0025 #endif
0026 
0027 #if !defined(MBEDTLS_MD5_ALT)
0028 // Regular implementation
0029 //
0030 
0031 /**
0032  * \brief          MD5 context structure
0033  *
0034  * \warning        MD5 is considered a weak message digest and its use
0035  *                 constitutes a security risk. We recommend considering
0036  *                 stronger message digests instead.
0037  *
0038  */
0039 typedef struct mbedtls_md5_context {
0040     uint32_t MBEDTLS_PRIVATE(total)[2];          /*!< number of bytes processed  */
0041     uint32_t MBEDTLS_PRIVATE(state)[4];          /*!< intermediate digest state  */
0042     unsigned char MBEDTLS_PRIVATE(buffer)[64];   /*!< data block being processed */
0043 }
0044 mbedtls_md5_context;
0045 
0046 #else  /* MBEDTLS_MD5_ALT */
0047 #include "md5_alt.h"
0048 #endif /* MBEDTLS_MD5_ALT */
0049 
0050 /**
0051  * \brief          Initialize MD5 context
0052  *
0053  * \param ctx      MD5 context to be initialized
0054  *
0055  * \warning        MD5 is considered a weak message digest and its use
0056  *                 constitutes a security risk. We recommend considering
0057  *                 stronger message digests instead.
0058  *
0059  */
0060 void mbedtls_md5_init(mbedtls_md5_context *ctx);
0061 
0062 /**
0063  * \brief          Clear MD5 context
0064  *
0065  * \param ctx      MD5 context to be cleared
0066  *
0067  * \warning        MD5 is considered a weak message digest and its use
0068  *                 constitutes a security risk. We recommend considering
0069  *                 stronger message digests instead.
0070  *
0071  */
0072 void mbedtls_md5_free(mbedtls_md5_context *ctx);
0073 
0074 /**
0075  * \brief          Clone (the state of) an MD5 context
0076  *
0077  * \param dst      The destination context
0078  * \param src      The context to be cloned
0079  *
0080  * \warning        MD5 is considered a weak message digest and its use
0081  *                 constitutes a security risk. We recommend considering
0082  *                 stronger message digests instead.
0083  *
0084  */
0085 void mbedtls_md5_clone(mbedtls_md5_context *dst,
0086                        const mbedtls_md5_context *src);
0087 
0088 /**
0089  * \brief          MD5 context setup
0090  *
0091  * \param ctx      context to be initialized
0092  *
0093  * \return         0 if successful
0094  *
0095  * \warning        MD5 is considered a weak message digest and its use
0096  *                 constitutes a security risk. We recommend considering
0097  *                 stronger message digests instead.
0098  *
0099  */
0100 int mbedtls_md5_starts(mbedtls_md5_context *ctx);
0101 
0102 /**
0103  * \brief          MD5 process buffer
0104  *
0105  * \param ctx      MD5 context
0106  * \param input    buffer holding the data
0107  * \param ilen     length of the input data
0108  *
0109  * \return         0 if successful
0110  *
0111  * \warning        MD5 is considered a weak message digest and its use
0112  *                 constitutes a security risk. We recommend considering
0113  *                 stronger message digests instead.
0114  *
0115  */
0116 int mbedtls_md5_update(mbedtls_md5_context *ctx,
0117                        const unsigned char *input,
0118                        size_t ilen);
0119 
0120 /**
0121  * \brief          MD5 final digest
0122  *
0123  * \param ctx      MD5 context
0124  * \param output   MD5 checksum result
0125  *
0126  * \return         0 if successful
0127  *
0128  * \warning        MD5 is considered a weak message digest and its use
0129  *                 constitutes a security risk. We recommend considering
0130  *                 stronger message digests instead.
0131  *
0132  */
0133 int mbedtls_md5_finish(mbedtls_md5_context *ctx,
0134                        unsigned char output[16]);
0135 
0136 /**
0137  * \brief          MD5 process data block (internal use only)
0138  *
0139  * \param ctx      MD5 context
0140  * \param data     buffer holding one block of data
0141  *
0142  * \return         0 if successful
0143  *
0144  * \warning        MD5 is considered a weak message digest and its use
0145  *                 constitutes a security risk. We recommend considering
0146  *                 stronger message digests instead.
0147  *
0148  */
0149 int mbedtls_internal_md5_process(mbedtls_md5_context *ctx,
0150                                  const unsigned char data[64]);
0151 
0152 /**
0153  * \brief          Output = MD5( input buffer )
0154  *
0155  * \param input    buffer holding the data
0156  * \param ilen     length of the input data
0157  * \param output   MD5 checksum result
0158  *
0159  * \return         0 if successful
0160  *
0161  * \warning        MD5 is considered a weak message digest and its use
0162  *                 constitutes a security risk. We recommend considering
0163  *                 stronger message digests instead.
0164  *
0165  */
0166 int mbedtls_md5(const unsigned char *input,
0167                 size_t ilen,
0168                 unsigned char output[16]);
0169 
0170 #if defined(MBEDTLS_SELF_TEST)
0171 
0172 /**
0173  * \brief          Checkup routine
0174  *
0175  * \return         0 if successful, or 1 if the test failed
0176  *
0177  * \warning        MD5 is considered a weak message digest and its use
0178  *                 constitutes a security risk. We recommend considering
0179  *                 stronger message digests instead.
0180  *
0181  */
0182 int mbedtls_md5_self_test(int verbose);
0183 
0184 #endif /* MBEDTLS_SELF_TEST */
0185 
0186 #ifdef __cplusplus
0187 }
0188 #endif
0189 
0190 #endif /* mbedtls_md5.h */