Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file md4.h
  3.  *
  4.  * \brief MD4 message digest algorithm (hash function)
  5.  *
  6.  * \warning MD4 is considered a weak message digest and its use constitutes a
  7.  *          security risk. We recommend considering stronger message digests
  8.  *          instead.
  9.  */
  10. /*
  11.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  12.  *  SPDX-License-Identifier: GPL-2.0
  13.  *
  14.  *  This program is free software; you can redistribute it and/or modify
  15.  *  it under the terms of the GNU General Public License as published by
  16.  *  the Free Software Foundation; either version 2 of the License, or
  17.  *  (at your option) any later version.
  18.  *
  19.  *  This program is distributed in the hope that it will be useful,
  20.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.  *  GNU General Public License for more details.
  23.  *
  24.  *  You should have received a copy of the GNU General Public License along
  25.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  26.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  27.  *
  28.  *  This file is part of mbed TLS (https://tls.mbed.org)
  29.  *
  30.  */
  31. #ifndef MBEDTLS_MD4_H
  32. #define MBEDTLS_MD4_H
  33.  
  34. #if !defined(MBEDTLS_CONFIG_FILE)
  35. #include "config.h"
  36. #else
  37. #include MBEDTLS_CONFIG_FILE
  38. #endif
  39.  
  40. #include <stddef.h>
  41. #include <stdint.h>
  42.  
  43. /* MBEDTLS_ERR_MD4_HW_ACCEL_FAILED is deprecated and should not be used. */
  44. #define MBEDTLS_ERR_MD4_HW_ACCEL_FAILED                   -0x002D  /**< MD4 hardware accelerator failed */
  45.  
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49.  
  50. #if !defined(MBEDTLS_MD4_ALT)
  51. // Regular implementation
  52. //
  53.  
  54. /**
  55.  * \brief          MD4 context structure
  56.  *
  57.  * \warning        MD4 is considered a weak message digest and its use
  58.  *                 constitutes a security risk. We recommend considering
  59.  *                 stronger message digests instead.
  60.  *
  61.  */
  62. typedef struct mbedtls_md4_context
  63. {
  64.     uint32_t total[2];          /*!< number of bytes processed  */
  65.     uint32_t state[4];          /*!< intermediate digest state  */
  66.     unsigned char buffer[64];   /*!< data block being processed */
  67. }
  68. mbedtls_md4_context;
  69.  
  70. #else  /* MBEDTLS_MD4_ALT */
  71. #include "md4_alt.h"
  72. #endif /* MBEDTLS_MD4_ALT */
  73.  
  74. /**
  75.  * \brief          Initialize MD4 context
  76.  *
  77.  * \param ctx      MD4 context to be initialized
  78.  *
  79.  * \warning        MD4 is considered a weak message digest and its use
  80.  *                 constitutes a security risk. We recommend considering
  81.  *                 stronger message digests instead.
  82.  *
  83.  */
  84. void mbedtls_md4_init( mbedtls_md4_context *ctx );
  85.  
  86. /**
  87.  * \brief          Clear MD4 context
  88.  *
  89.  * \param ctx      MD4 context to be cleared
  90.  *
  91.  * \warning        MD4 is considered a weak message digest and its use
  92.  *                 constitutes a security risk. We recommend considering
  93.  *                 stronger message digests instead.
  94.  *
  95.  */
  96. void mbedtls_md4_free( mbedtls_md4_context *ctx );
  97.  
  98. /**
  99.  * \brief          Clone (the state of) an MD4 context
  100.  *
  101.  * \param dst      The destination context
  102.  * \param src      The context to be cloned
  103.  *
  104.  * \warning        MD4 is considered a weak message digest and its use
  105.  *                 constitutes a security risk. We recommend considering
  106.  *                 stronger message digests instead.
  107.  *
  108.  */
  109. void mbedtls_md4_clone( mbedtls_md4_context *dst,
  110.                         const mbedtls_md4_context *src );
  111.  
  112. /**
  113.  * \brief          MD4 context setup
  114.  *
  115.  * \param ctx      context to be initialized
  116.  *
  117.  * \return         0 if successful
  118.  *
  119.  * \warning        MD4 is considered a weak message digest and its use
  120.  *                 constitutes a security risk. We recommend considering
  121.  *                 stronger message digests instead.
  122.  */
  123. int mbedtls_md4_starts_ret( mbedtls_md4_context *ctx );
  124.  
  125. /**
  126.  * \brief          MD4 process buffer
  127.  *
  128.  * \param ctx      MD4 context
  129.  * \param input    buffer holding the data
  130.  * \param ilen     length of the input data
  131.  *
  132.  * \return         0 if successful
  133.  *
  134.  * \warning        MD4 is considered a weak message digest and its use
  135.  *                 constitutes a security risk. We recommend considering
  136.  *                 stronger message digests instead.
  137.  *
  138.  */
  139. int mbedtls_md4_update_ret( mbedtls_md4_context *ctx,
  140.                             const unsigned char *input,
  141.                             size_t ilen );
  142.  
  143. /**
  144.  * \brief          MD4 final digest
  145.  *
  146.  * \param ctx      MD4 context
  147.  * \param output   MD4 checksum result
  148.  *
  149.  * \return         0 if successful
  150.  *
  151.  * \warning        MD4 is considered a weak message digest and its use
  152.  *                 constitutes a security risk. We recommend considering
  153.  *                 stronger message digests instead.
  154.  *
  155.  */
  156. int mbedtls_md4_finish_ret( mbedtls_md4_context *ctx,
  157.                             unsigned char output[16] );
  158.  
  159. /**
  160.  * \brief          MD4 process data block (internal use only)
  161.  *
  162.  * \param ctx      MD4 context
  163.  * \param data     buffer holding one block of data
  164.  *
  165.  * \return         0 if successful
  166.  *
  167.  * \warning        MD4 is considered a weak message digest and its use
  168.  *                 constitutes a security risk. We recommend considering
  169.  *                 stronger message digests instead.
  170.  *
  171.  */
  172. int mbedtls_internal_md4_process( mbedtls_md4_context *ctx,
  173.                                   const unsigned char data[64] );
  174.  
  175. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  176. #if defined(MBEDTLS_DEPRECATED_WARNING)
  177. #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
  178. #else
  179. #define MBEDTLS_DEPRECATED
  180. #endif
  181. /**
  182.  * \brief          MD4 context setup
  183.  *
  184.  * \deprecated     Superseded by mbedtls_md4_starts_ret() in 2.7.0
  185.  *
  186.  * \param ctx      context to be initialized
  187.  *
  188.  * \warning        MD4 is considered a weak message digest and its use
  189.  *                 constitutes a security risk. We recommend considering
  190.  *                 stronger message digests instead.
  191.  *
  192.  */
  193. MBEDTLS_DEPRECATED void mbedtls_md4_starts( mbedtls_md4_context *ctx );
  194.  
  195. /**
  196.  * \brief          MD4 process buffer
  197.  *
  198.  * \deprecated     Superseded by mbedtls_md4_update_ret() in 2.7.0
  199.  *
  200.  * \param ctx      MD4 context
  201.  * \param input    buffer holding the data
  202.  * \param ilen     length of the input data
  203.  *
  204.  * \warning        MD4 is considered a weak message digest and its use
  205.  *                 constitutes a security risk. We recommend considering
  206.  *                 stronger message digests instead.
  207.  *
  208.  */
  209. MBEDTLS_DEPRECATED void mbedtls_md4_update( mbedtls_md4_context *ctx,
  210.                                             const unsigned char *input,
  211.                                             size_t ilen );
  212.  
  213. /**
  214.  * \brief          MD4 final digest
  215.  *
  216.  * \deprecated     Superseded by mbedtls_md4_finish_ret() in 2.7.0
  217.  *
  218.  * \param ctx      MD4 context
  219.  * \param output   MD4 checksum result
  220.  *
  221.  * \warning        MD4 is considered a weak message digest and its use
  222.  *                 constitutes a security risk. We recommend considering
  223.  *                 stronger message digests instead.
  224.  *
  225.  */
  226. MBEDTLS_DEPRECATED void mbedtls_md4_finish( mbedtls_md4_context *ctx,
  227.                                             unsigned char output[16] );
  228.  
  229. /**
  230.  * \brief          MD4 process data block (internal use only)
  231.  *
  232.  * \deprecated     Superseded by mbedtls_internal_md4_process() in 2.7.0
  233.  *
  234.  * \param ctx      MD4 context
  235.  * \param data     buffer holding one block of data
  236.  *
  237.  * \warning        MD4 is considered a weak message digest and its use
  238.  *                 constitutes a security risk. We recommend considering
  239.  *                 stronger message digests instead.
  240.  *
  241.  */
  242. MBEDTLS_DEPRECATED void mbedtls_md4_process( mbedtls_md4_context *ctx,
  243.                                              const unsigned char data[64] );
  244.  
  245. #undef MBEDTLS_DEPRECATED
  246. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  247.  
  248. /**
  249.  * \brief          Output = MD4( input buffer )
  250.  *
  251.  * \param input    buffer holding the data
  252.  * \param ilen     length of the input data
  253.  * \param output   MD4 checksum result
  254.  *
  255.  * \return         0 if successful
  256.  *
  257.  * \warning        MD4 is considered a weak message digest and its use
  258.  *                 constitutes a security risk. We recommend considering
  259.  *                 stronger message digests instead.
  260.  *
  261.  */
  262. int mbedtls_md4_ret( const unsigned char *input,
  263.                      size_t ilen,
  264.                      unsigned char output[16] );
  265.  
  266. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  267. #if defined(MBEDTLS_DEPRECATED_WARNING)
  268. #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
  269. #else
  270. #define MBEDTLS_DEPRECATED
  271. #endif
  272. /**
  273.  * \brief          Output = MD4( input buffer )
  274.  *
  275.  * \deprecated     Superseded by mbedtls_md4_ret() in 2.7.0
  276.  *
  277.  * \param input    buffer holding the data
  278.  * \param ilen     length of the input data
  279.  * \param output   MD4 checksum result
  280.  *
  281.  * \warning        MD4 is considered a weak message digest and its use
  282.  *                 constitutes a security risk. We recommend considering
  283.  *                 stronger message digests instead.
  284.  *
  285.  */
  286. MBEDTLS_DEPRECATED void mbedtls_md4( const unsigned char *input,
  287.                                      size_t ilen,
  288.                                      unsigned char output[16] );
  289.  
  290. #undef MBEDTLS_DEPRECATED
  291. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  292.  
  293. #if defined(MBEDTLS_SELF_TEST)
  294.  
  295. /**
  296.  * \brief          Checkup routine
  297.  *
  298.  * \return         0 if successful, or 1 if the test failed
  299.  *
  300.  * \warning        MD4 is considered a weak message digest and its use
  301.  *                 constitutes a security risk. We recommend considering
  302.  *                 stronger message digests instead.
  303.  *
  304.  */
  305. int mbedtls_md4_self_test( int verbose );
  306.  
  307. #endif /* MBEDTLS_SELF_TEST */
  308.  
  309. #ifdef __cplusplus
  310. }
  311. #endif
  312.  
  313. #endif /* mbedtls_md4.h */
  314.