md5.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
  2. /*
  3. Independent implementation of MD5 (RFC 1321).
  4. This code implements the MD5 Algorithm defined in RFC 1321, whose
  5. text is available at
  6. http://www.ietf.org/rfc/rfc1321.txt
  7. The code is derived from the text of the RFC, including the test suite
  8. (section A.5) but excluding the rest of Appendix A. It does not include
  9. any code or documentation that is identified in the RFC as being
  10. copyrighted.
  11. The original and principal author of md5.h is L. Peter Deutsch
  12. <ghost@aladdin.com>. Other authors are noted in the change history
  13. that follows (in reverse chronological order):
  14. 2002-04-13 lpd Removed support for non-ANSI compilers; removed
  15. references to Ghostscript; clarified derivation from RFC 1321;
  16. now handles byte order either statically or dynamically.
  17. 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
  18. 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
  19. added conditionalization for C++ compilation from Martin
  20. Purschke <purschke@bnl.gov>.
  21. 1999-05-03 lpd Original version.
  22. */
  23. #ifndef md5_INCLUDED
  24. # define md5_INCLUDED
  25. /*
  26. * This package supports both compile-time and run-time determination of CPU
  27. * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
  28. * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
  29. * defined as non-zero, the code will be compiled to run only on big-endian
  30. * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
  31. * run on either big- or little-endian CPUs, but will run slightly less
  32. * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
  33. */
  34. typedef unsigned char md5_byte_t; /* 8-bit byte */
  35. typedef unsigned int md5_word_t; /* 32-bit word */
  36. /* Define the state of the MD5 Algorithm. */
  37. typedef struct md5_state_s {
  38. md5_word_t count[2]; /* message length in bits, lsw first */
  39. md5_word_t abcd[4]; /* digest buffer */
  40. md5_byte_t buf[64]; /* accumulate block */
  41. } md5_state_t;
  42. #ifdef __cplusplus
  43. extern "C"
  44. {
  45. #endif
  46. /* Initialize the algorithm. */
  47. void md5_init(md5_state_t *pms);
  48. /* Append a string to the message. */
  49. void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
  50. /* Finish the message and return the digest. */
  51. void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
  52. #ifdef __cplusplus
  53. } /* end extern "C" */
  54. #endif
  55. #endif /* md5_INCLUDED */