md5.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include "hashsum_template.h"
  25. typedef HashSumValue<128> MD5SumValue;
  26. class MD5Summation : public SummationImplementation
  27. {
  28. uint32_t Buf[4];
  29. unsigned char Bytes[2*4];
  30. unsigned char In[16*4];
  31. bool Done;
  32. public:
  33. bool Add(const unsigned char *inbuf, unsigned long long inlen);
  34. using SummationImplementation::Add;
  35. MD5SumValue Result();
  36. MD5Summation();
  37. };
  38. #endif