md5.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 gaurd 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. using std::string;
  25. using std::min;
  26. #include "hashsum_template.h"
  27. class MD5Summation;
  28. typedef HashSumValue<128> MD5SumValue;
  29. class MD5Summation
  30. {
  31. uint32_t Buf[4];
  32. unsigned char Bytes[2*4];
  33. unsigned char In[16*4];
  34. bool Done;
  35. public:
  36. bool Add(const unsigned char *Data,unsigned long Size);
  37. inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
  38. bool AddFD(int Fd,unsigned long Size);
  39. inline bool Add(const unsigned char *Beg,const unsigned char *End)
  40. {return Add(Beg,End-Beg);};
  41. MD5SumValue Result();
  42. MD5Summation();
  43. };
  44. #endif