sha1.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: sha1.h,v 1.3 2001/05/07 05:05:47 jgg Exp $
  4. /* ######################################################################
  5. SHA1SumValue - Storage for a SHA-1 hash.
  6. SHA1Summation - SHA-1 Secure Hash Algorithm.
  7. This is a C++ interface to a set of SHA1Sum functions, that mirrors
  8. the equivalent MD5 classes.
  9. ##################################################################### */
  10. /*}}}*/
  11. #ifndef APTPKG_SHA1_H
  12. #define APTPKG_SHA1_H
  13. #include <string>
  14. #include <cstring>
  15. #include <algorithm>
  16. using std::string;
  17. using std::min;
  18. #include "hashsum_template.h"
  19. class SHA1Summation;
  20. typedef HashSumValue<160> SHA1SumValue;
  21. class SHA1Summation
  22. {
  23. /* assumes 64-bit alignment just in case */
  24. unsigned char Buffer[64] __attribute__((aligned(8)));
  25. unsigned char State[5*4] __attribute__((aligned(8)));
  26. unsigned char Count[2*4] __attribute__((aligned(8)));
  27. bool Done;
  28. public:
  29. bool Add(const unsigned char *inbuf,unsigned long inlen);
  30. inline bool Add(const char *Data) {return Add((unsigned char *)Data,strlen(Data));};
  31. bool AddFD(int Fd,unsigned long Size);
  32. inline bool Add(const unsigned char *Beg,const unsigned char *End)
  33. {return Add(Beg,End-Beg);};
  34. SHA1SumValue Result();
  35. SHA1Summation();
  36. };
  37. #endif