md5.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * \file md5.h
  3. *
  4. * \brief MD5 message digest algorithm (hash function)
  5. *
  6. * Copyright (C) 2006-2013, 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. #include <string.h>
  28. #include <stdint.h>
  29. #include <stdlib.h>
  30. /**
  31. * \brief MD5 context structure
  32. */
  33. typedef struct {
  34. uint32_t total[2]; /*!< number of bytes processed */
  35. uint32_t state[4]; /*!< intermediate digest state */
  36. unsigned char buffer[64]; /*!< data block being processed */
  37. } md5_context;
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * \brief MD5 context setup
  43. *
  44. * \param ctx context to be initialized
  45. */
  46. void md5_starts(md5_context* ctx);
  47. /**
  48. * \brief MD5 process buffer
  49. *
  50. * \param ctx MD5 context
  51. * \param input buffer holding the data
  52. * \param ilen length of the input data
  53. */
  54. void md5_update(md5_context* ctx, const unsigned char* input, size_t ilen);
  55. /**
  56. * \brief MD5 final digest
  57. *
  58. * \param ctx MD5 context
  59. * \param output MD5 checksum result
  60. */
  61. void md5_finish(md5_context* ctx, unsigned char output[16]);
  62. /* Internal use */
  63. void md5_process(md5_context* ctx, const unsigned char data[64]);
  64. /**
  65. * \brief Output = MD5( input buffer )
  66. *
  67. * \param input buffer holding the data
  68. * \param ilen length of the input data
  69. * \param output MD5 checksum result
  70. */
  71. void md5(const unsigned char* input, size_t ilen, unsigned char output[16]);
  72. #ifdef __cplusplus
  73. }
  74. #endif