md2.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**
  2. * \file md2.h
  3. *
  4. * \brief MD2 message digest algorithm (hash function)
  5. *
  6. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  7. * SPDX-License-Identifier: GPL-2.0
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. *
  23. * This file is part of mbed TLS (https://tls.mbed.org)
  24. */
  25. #ifndef MBEDTLS_MD2_H
  26. #define MBEDTLS_MD2_H
  27. #if !defined(MBEDTLS_CONFIG_FILE)
  28. #include "config.h"
  29. #else
  30. #include MBEDTLS_CONFIG_FILE
  31. #endif
  32. #include <stddef.h>
  33. #if !defined(MBEDTLS_MD2_ALT)
  34. // Regular implementation
  35. //
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. * \brief MD2 context structure
  41. */
  42. typedef struct
  43. {
  44. unsigned char cksum[16]; /*!< checksum of the data block */
  45. unsigned char state[48]; /*!< intermediate digest state */
  46. unsigned char buffer[16]; /*!< data block being processed */
  47. size_t left; /*!< amount of data in buffer */
  48. }
  49. mbedtls_md2_context;
  50. /**
  51. * \brief Initialize MD2 context
  52. *
  53. * \param ctx MD2 context to be initialized
  54. */
  55. void mbedtls_md2_init( mbedtls_md2_context *ctx );
  56. /**
  57. * \brief Clear MD2 context
  58. *
  59. * \param ctx MD2 context to be cleared
  60. */
  61. void mbedtls_md2_free( mbedtls_md2_context *ctx );
  62. /**
  63. * \brief Clone (the state of) an MD2 context
  64. *
  65. * \param dst The destination context
  66. * \param src The context to be cloned
  67. */
  68. void mbedtls_md2_clone( mbedtls_md2_context *dst,
  69. const mbedtls_md2_context *src );
  70. /**
  71. * \brief MD2 context setup
  72. *
  73. * \param ctx context to be initialized
  74. */
  75. void mbedtls_md2_starts( mbedtls_md2_context *ctx );
  76. /**
  77. * \brief MD2 process buffer
  78. *
  79. * \param ctx MD2 context
  80. * \param input buffer holding the data
  81. * \param ilen length of the input data
  82. */
  83. void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen );
  84. /**
  85. * \brief MD2 final digest
  86. *
  87. * \param ctx MD2 context
  88. * \param output MD2 checksum result
  89. */
  90. void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] );
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #else /* MBEDTLS_MD2_ALT */
  95. #include "md2_alt.h"
  96. #endif /* MBEDTLS_MD2_ALT */
  97. #ifdef __cplusplus
  98. extern "C" {
  99. #endif
  100. /**
  101. * \brief Output = MD2( input buffer )
  102. *
  103. * \param input buffer holding the data
  104. * \param ilen length of the input data
  105. * \param output MD2 checksum result
  106. */
  107. void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
  108. /**
  109. * \brief Checkup routine
  110. *
  111. * \return 0 if successful, or 1 if the test failed
  112. */
  113. int mbedtls_md2_self_test( int verbose );
  114. /* Internal use */
  115. void mbedtls_md2_process( mbedtls_md2_context *ctx );
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* mbedtls_md2.h */