md5.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <stdint.h>
  21. #include "hashsum_template.h"
  22. #ifndef APT_10_CLEANER_HEADERS
  23. #include <string>
  24. #include <cstring>
  25. #include <algorithm>
  26. #endif
  27. #ifndef APT_8_CLEANER_HEADERS
  28. using std::string;
  29. using std::min;
  30. #endif
  31. typedef HashSumValue<128> MD5SumValue;
  32. class MD5Summation : public SummationImplementation
  33. {
  34. uint32_t Buf[4];
  35. unsigned char Bytes[2*4];
  36. unsigned char In[16*4];
  37. bool Done;
  38. public:
  39. bool Add(const unsigned char *inbuf, unsigned long long inlen) APT_OVERRIDE APT_NONNULL(2);
  40. using SummationImplementation::Add;
  41. MD5SumValue Result();
  42. MD5Summation();
  43. };
  44. #endif