md5.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* $OpenBSD: md5.h,v 1.15 2004/05/03 17:30:14 millert Exp $ */
  2. /*
  3. * This code implements the MD5 message-digest algorithm.
  4. * The algorithm is due to Ron Rivest. This code was
  5. * written by Colin Plumb in 1993, no copyright is claimed.
  6. * This code is in the public domain; do with it what you wish.
  7. *
  8. * Equivalent code is available from RSA Data Security, Inc.
  9. * This code has been tested against that, and is equivalent,
  10. * except that you don't need to include two pages of legalese
  11. * with every copy.
  12. */
  13. #ifndef _MD5_H_
  14. #define _MD5_H_
  15. #include <sys/types.h>
  16. #include <stdint.h>
  17. #define MD5_BLOCK_LENGTH 64
  18. #define MD5_DIGEST_LENGTH 16
  19. #define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
  20. typedef struct MD5Context {
  21. uint32_t state[4]; /* state */
  22. uint64_t count; /* number of bits, mod 2^64 */
  23. uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
  24. } MD5_CTX;
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. void MD5Init(MD5_CTX *);
  29. void MD5Update(MD5_CTX *, const uint8_t *, size_t);
  30. void MD5Pad(MD5_CTX *);
  31. void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *);
  32. void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH]);
  33. char *MD5End(MD5_CTX *, char *);
  34. char *MD5File(const char *, char *);
  35. char *MD5FileChunk(const char *, char *, off_t, off_t);
  36. char *MD5Data(const uint8_t *, size_t, char *);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. /* Avoid polluting the namespace. Even though this makes this usage
  41. * implementation-specific, defining it unconditionally should not be
  42. * a problem, and better than possibly breaking unexpecting code. */
  43. #ifdef LIBMD_MD5_ALADDIN
  44. /*
  45. * Interface compatibility with Aladdin Enterprises independent
  46. * implementation from RFC 1321.
  47. */
  48. typedef uint8_t md5_byte_t;
  49. typedef uint32_t md5_word_t;
  50. typedef MD5_CTX md5_state_t;
  51. #define md5_init(pms) MD5Init(pms)
  52. #define md5_append(pms, data, nbytes) MD5Update(pms, data, nbytes)
  53. #define md5_finish(pms, digest) MD5Final(digest, pms)
  54. #endif /* LIBMD_MD5_ALADDIN */
  55. #endif /* _MD5_H_ */