Subversion Repositories Kolibri OS

Rev

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

  1. /**
  2.  * \file md2.h
  3.  *
  4.  * \brief MD2 message digest algorithm (hash function)
  5.  *
  6.  * \warning MD2 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_MD2_H
  32. #define MBEDTLS_MD2_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.  
  42. /* MBEDTLS_ERR_MD2_HW_ACCEL_FAILED is deprecated and should not be used. */
  43. #define MBEDTLS_ERR_MD2_HW_ACCEL_FAILED                   -0x002B  /**< MD2 hardware accelerator failed */
  44.  
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48.  
  49. #if !defined(MBEDTLS_MD2_ALT)
  50. // Regular implementation
  51. //
  52.  
  53. /**
  54.  * \brief          MD2 context structure
  55.  *
  56.  * \warning        MD2 is considered a weak message digest and its use
  57.  *                 constitutes a security risk. We recommend considering
  58.  *                 stronger message digests instead.
  59.  *
  60.  */
  61. typedef struct mbedtls_md2_context
  62. {
  63.     unsigned char cksum[16];    /*!< checksum of the data block */
  64.     unsigned char state[48];    /*!< intermediate digest state  */
  65.     unsigned char buffer[16];   /*!< data block being processed */
  66.     size_t left;                /*!< amount of data in buffer   */
  67. }
  68. mbedtls_md2_context;
  69.  
  70. #else  /* MBEDTLS_MD2_ALT */
  71. #include "md2_alt.h"
  72. #endif /* MBEDTLS_MD2_ALT */
  73.  
  74. /**
  75.  * \brief          Initialize MD2 context
  76.  *
  77.  * \param ctx      MD2 context to be initialized
  78.  *
  79.  * \warning        MD2 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_md2_init( mbedtls_md2_context *ctx );
  85.  
  86. /**
  87.  * \brief          Clear MD2 context
  88.  *
  89.  * \param ctx      MD2 context to be cleared
  90.  *
  91.  * \warning        MD2 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_md2_free( mbedtls_md2_context *ctx );
  97.  
  98. /**
  99.  * \brief          Clone (the state of) an MD2 context
  100.  *
  101.  * \param dst      The destination context
  102.  * \param src      The context to be cloned
  103.  *
  104.  * \warning        MD2 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_md2_clone( mbedtls_md2_context *dst,
  110.                         const mbedtls_md2_context *src );
  111.  
  112. /**
  113.  * \brief          MD2 context setup
  114.  *
  115.  * \param ctx      context to be initialized
  116.  *
  117.  * \return         0 if successful
  118.  *
  119.  * \warning        MD2 is considered a weak message digest and its use
  120.  *                 constitutes a security risk. We recommend considering
  121.  *                 stronger message digests instead.
  122.  *
  123.  */
  124. int mbedtls_md2_starts_ret( mbedtls_md2_context *ctx );
  125.  
  126. /**
  127.  * \brief          MD2 process buffer
  128.  *
  129.  * \param ctx      MD2 context
  130.  * \param input    buffer holding the data
  131.  * \param ilen     length of the input data
  132.  *
  133.  * \return         0 if successful
  134.  *
  135.  * \warning        MD2 is considered a weak message digest and its use
  136.  *                 constitutes a security risk. We recommend considering
  137.  *                 stronger message digests instead.
  138.  *
  139.  */
  140. int mbedtls_md2_update_ret( mbedtls_md2_context *ctx,
  141.                             const unsigned char *input,
  142.                             size_t ilen );
  143.  
  144. /**
  145.  * \brief          MD2 final digest
  146.  *
  147.  * \param ctx      MD2 context
  148.  * \param output   MD2 checksum result
  149.  *
  150.  * \return         0 if successful
  151.  *
  152.  * \warning        MD2 is considered a weak message digest and its use
  153.  *                 constitutes a security risk. We recommend considering
  154.  *                 stronger message digests instead.
  155.  *
  156.  */
  157. int mbedtls_md2_finish_ret( mbedtls_md2_context *ctx,
  158.                             unsigned char output[16] );
  159.  
  160. /**
  161.  * \brief          MD2 process data block (internal use only)
  162.  *
  163.  * \param ctx      MD2 context
  164.  *
  165.  * \return         0 if successful
  166.  *
  167.  * \warning        MD2 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_md2_process( mbedtls_md2_context *ctx );
  173.  
  174. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  175. #if defined(MBEDTLS_DEPRECATED_WARNING)
  176. #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
  177. #else
  178. #define MBEDTLS_DEPRECATED
  179. #endif
  180. /**
  181.  * \brief          MD2 context setup
  182.  *
  183.  * \deprecated     Superseded by mbedtls_md2_starts_ret() in 2.7.0
  184.  *
  185.  * \param ctx      context to be initialized
  186.  *
  187.  * \warning        MD2 is considered a weak message digest and its use
  188.  *                 constitutes a security risk. We recommend considering
  189.  *                 stronger message digests instead.
  190.  *
  191.  */
  192. MBEDTLS_DEPRECATED void mbedtls_md2_starts( mbedtls_md2_context *ctx );
  193.  
  194. /**
  195.  * \brief          MD2 process buffer
  196.  *
  197.  * \deprecated     Superseded by mbedtls_md2_update_ret() in 2.7.0
  198.  *
  199.  * \param ctx      MD2 context
  200.  * \param input    buffer holding the data
  201.  * \param ilen     length of the input data
  202.  *
  203.  * \warning        MD2 is considered a weak message digest and its use
  204.  *                 constitutes a security risk. We recommend considering
  205.  *                 stronger message digests instead.
  206.  *
  207.  */
  208. MBEDTLS_DEPRECATED void mbedtls_md2_update( mbedtls_md2_context *ctx,
  209.                                             const unsigned char *input,
  210.                                             size_t ilen );
  211.  
  212. /**
  213.  * \brief          MD2 final digest
  214.  *
  215.  * \deprecated     Superseded by mbedtls_md2_finish_ret() in 2.7.0
  216.  *
  217.  * \param ctx      MD2 context
  218.  * \param output   MD2 checksum result
  219.  *
  220.  * \warning        MD2 is considered a weak message digest and its use
  221.  *                 constitutes a security risk. We recommend considering
  222.  *                 stronger message digests instead.
  223.  *
  224.  */
  225. MBEDTLS_DEPRECATED void mbedtls_md2_finish( mbedtls_md2_context *ctx,
  226.                                             unsigned char output[16] );
  227.  
  228. /**
  229.  * \brief          MD2 process data block (internal use only)
  230.  *
  231.  * \deprecated     Superseded by mbedtls_internal_md2_process() in 2.7.0
  232.  *
  233.  * \param ctx      MD2 context
  234.  *
  235.  * \warning        MD2 is considered a weak message digest and its use
  236.  *                 constitutes a security risk. We recommend considering
  237.  *                 stronger message digests instead.
  238.  *
  239.  */
  240. MBEDTLS_DEPRECATED void mbedtls_md2_process( mbedtls_md2_context *ctx );
  241.  
  242. #undef MBEDTLS_DEPRECATED
  243. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  244.  
  245. /**
  246.  * \brief          Output = MD2( input buffer )
  247.  *
  248.  * \param input    buffer holding the data
  249.  * \param ilen     length of the input data
  250.  * \param output   MD2 checksum result
  251.  *
  252.  * \warning        MD2 is considered a weak message digest and its use
  253.  *                 constitutes a security risk. We recommend considering
  254.  *                 stronger message digests instead.
  255.  *
  256.  */
  257. int mbedtls_md2_ret( const unsigned char *input,
  258.                      size_t ilen,
  259.                      unsigned char output[16] );
  260.  
  261. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  262. #if defined(MBEDTLS_DEPRECATED_WARNING)
  263. #define MBEDTLS_DEPRECATED      __attribute__((deprecated))
  264. #else
  265. #define MBEDTLS_DEPRECATED
  266. #endif
  267. /**
  268.  * \brief          Output = MD2( input buffer )
  269.  *
  270.  * \deprecated     Superseded by mbedtls_md2_ret() in 2.7.0
  271.  *
  272.  * \param input    buffer holding the data
  273.  * \param ilen     length of the input data
  274.  * \param output   MD2 checksum result
  275.  *
  276.  * \warning        MD2 is considered a weak message digest and its use
  277.  *                 constitutes a security risk. We recommend considering
  278.  *                 stronger message digests instead.
  279.  *
  280.  */
  281. MBEDTLS_DEPRECATED void mbedtls_md2( const unsigned char *input,
  282.                                      size_t ilen,
  283.                                      unsigned char output[16] );
  284.  
  285. #undef MBEDTLS_DEPRECATED
  286. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  287.  
  288. #if defined(MBEDTLS_SELF_TEST)
  289.  
  290. /**
  291.  * \brief          Checkup routine
  292.  *
  293.  * \return         0 if successful, or 1 if the test failed
  294.  *
  295.  * \warning        MD2 is considered a weak message digest and its use
  296.  *                 constitutes a security risk. We recommend considering
  297.  *                 stronger message digests instead.
  298.  *
  299.  */
  300. int mbedtls_md2_self_test( int verbose );
  301.  
  302. #endif /* MBEDTLS_SELF_TEST */
  303.  
  304. #ifdef __cplusplus
  305. }
  306. #endif
  307.  
  308. #endif /* mbedtls_md2.h */
  309.