md2.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * \file md2.h
  3. *
  4. * \brief MD2 message digest algorithm (hash function)
  5. *
  6. * Copyright (C) 2006-2010, Brainspark B.V.
  7. *
  8. * This file is part of PolarSSL (http://www.polarssl.org)
  9. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  10. *
  11. * All rights reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #ifndef POLARSSL_MD2_H
  28. #define POLARSSL_MD2_H
  29. #include <string.h>
  30. /**
  31. * \brief MD2 context structure
  32. */
  33. typedef struct
  34. {
  35. unsigned char cksum[16]; /*!< checksum of the data block */
  36. unsigned char state[48]; /*!< intermediate digest state */
  37. unsigned char buffer[16]; /*!< data block being processed */
  38. unsigned char ipad[64]; /*!< HMAC: inner padding */
  39. unsigned char opad[64]; /*!< HMAC: outer padding */
  40. size_t left; /*!< amount of data in buffer */
  41. }
  42. md2_context;
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * \brief MD2 context setup
  48. *
  49. * \param ctx context to be initialized
  50. */
  51. void md2_starts( md2_context *ctx );
  52. /**
  53. * \brief MD2 process buffer
  54. *
  55. * \param ctx MD2 context
  56. * \param input buffer holding the data
  57. * \param ilen length of the input data
  58. */
  59. void md2_update( md2_context *ctx, const unsigned char *input, size_t ilen );
  60. /**
  61. * \brief MD2 final digest
  62. *
  63. * \param ctx MD2 context
  64. * \param output MD2 checksum result
  65. */
  66. void md2_finish( md2_context *ctx, unsigned char output[16] );
  67. /**
  68. * \brief Output = MD2( input buffer )
  69. *
  70. * \param input buffer holding the data
  71. * \param ilen length of the input data
  72. * \param output MD2 checksum result
  73. */
  74. void md2( const unsigned char *input, size_t ilen, unsigned char output[16] );
  75. /**
  76. * \brief Output = MD2( file contents )
  77. *
  78. * \param path input file name
  79. * \param output MD2 checksum result
  80. *
  81. * \return 0 if successful, 1 if fopen failed,
  82. * or 2 if fread failed
  83. */
  84. int md2_file( const char *path, unsigned char output[16] );
  85. /**
  86. * \brief MD2 HMAC context setup
  87. *
  88. * \param ctx HMAC context to be initialized
  89. * \param key HMAC secret key
  90. * \param keylen length of the HMAC key
  91. */
  92. void md2_hmac_starts( md2_context *ctx, const unsigned char *key, size_t keylen );
  93. /**
  94. * \brief MD2 HMAC process buffer
  95. *
  96. * \param ctx HMAC context
  97. * \param input buffer holding the data
  98. * \param ilen length of the input data
  99. */
  100. void md2_hmac_update( md2_context *ctx, const unsigned char *input, size_t ilen );
  101. /**
  102. * \brief MD2 HMAC final digest
  103. *
  104. * \param ctx HMAC context
  105. * \param output MD2 HMAC checksum result
  106. */
  107. void md2_hmac_finish( md2_context *ctx, unsigned char output[16] );
  108. /**
  109. * \brief MD2 HMAC context reset
  110. *
  111. * \param ctx HMAC context to be reset
  112. */
  113. void md2_hmac_reset( md2_context *ctx );
  114. /**
  115. * \brief Output = HMAC-MD2( hmac key, input buffer )
  116. *
  117. * \param key HMAC secret key
  118. * \param keylen length of the HMAC key
  119. * \param input buffer holding the data
  120. * \param ilen length of the input data
  121. * \param output HMAC-MD2 result
  122. */
  123. void md2_hmac( const unsigned char *key, size_t keylen,
  124. const unsigned char *input, size_t ilen,
  125. unsigned char output[16] );
  126. /**
  127. * \brief Checkup routine
  128. *
  129. * \return 0 if successful, or 1 if the test failed
  130. */
  131. int md2_self_test( int verbose );
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif /* md2.h */