md5.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: md5.h,v 1.6 2001/05/07 05:06:52 jgg Exp $
  4. /* ######################################################################
  5. MD5SumValue - Storage for a MD5Sum
  6. MD5Summation - MD5 Message Digest Algorithm.
  7. This is a C++ interface to a set of MD5Sum functions. The class can
  8. store a MD5Sum in 16 bytes of memory.
  9. A MD5Sum is used to generate a (hopefully) unique 16 byte number for a
  10. block of data. This can be used to guard against corruption of a file.
  11. MD5 should not be used for tamper protection, use SHA or something more
  12. secure.
  13. There are two classes because computing a MD5 is not a continual
  14. operation unless 64 byte blocks are used. Also the summation requires an
  15. extra 18*4 bytes to operate.
  16. ##################################################################### */
  17. /*}}}*/
  18. #ifndef APTPKG_MD5_H
  19. #define APTPKG_MD5_H
  20. #include <string>
  21. #include <cstring>
  22. #include <algorithm>
  23. #include <stdint.h>
  24. #include "hashsum_template.h"
  25. #ifndef APT_8_CLEANER_HEADERS
  26. using std::string;
  27. using std::min;
  28. #endif
  29. typedef HashSumValue<128> MD5SumValue;
  30. class MD5Summation : public SummationImplementation
  31. {
  32. uint32_t Buf[4];
  33. unsigned char Bytes[2*4];
  34. unsigned char In[16*4];
  35. bool Done;
  36. public:
  37. bool Add(const unsigned char *inbuf, unsigned long long inlen);
  38. using SummationImplementation::Add;
  39. MD5SumValue Result();
  40. MD5Summation();
  41. };
  42. #endif