util_md5.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. *
  20. * L. Peter Deutsch
  21. * ghost@aladdin.com
  22. */
  23. /* MD5
  24. *
  25. * Simply MD5 hash computation, used by disk cache. Adapted from external
  26. * code, with minor code modifications done to remove some unused code and
  27. * change code style. */
  28. #ifndef __UTIL_MD5_H__
  29. #define __UTIL_MD5_H__
  30. #include "util/util_string.h"
  31. #include "util/util_types.h"
  32. CCL_NAMESPACE_BEGIN
  33. class MD5Hash {
  34. public:
  35. MD5Hash();
  36. ~MD5Hash();
  37. void append(const uint8_t *data, int size);
  38. void append(const string &str);
  39. bool append_file(const string &filepath);
  40. string get_hex();
  41. protected:
  42. void process(const uint8_t *data);
  43. void finish(uint8_t digest[16]);
  44. uint32_t count[2]; /* message length in bits, lsw first */
  45. uint32_t abcd[4]; /* digest buffer */
  46. uint8_t buf[64]; /* accumulate block */
  47. };
  48. string util_md5_string(const string &str);
  49. CCL_NAMESPACE_END
  50. #endif /* __UTIL_MD5_H__ */