sha1.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef SHA_H
  2. #define SHA_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string>
  6. namespace qcloud_cos {
  7. /* Useful defines & typedefs */
  8. typedef unsigned char SHA_BYTE; /* 8-bit quantity */
  9. // SHA_LONG already defined in openssl/sha.h
  10. typedef unsigned int SHA_LONG; /* 32-or-more-bit quantity */
  11. #define SHA_BYTE_ORDER 1234
  12. #define SHA_VERSION 1
  13. #define SHA_BLOCKSIZE 64
  14. #define SHA_DIGESTSIZE 20
  15. typedef struct {
  16. SHA_LONG digest[5]; /* message digest */
  17. SHA_LONG count_lo, count_hi; /* 64-bit bit count */
  18. SHA_BYTE data[SHA_BLOCKSIZE]; /* SHA data buffer */
  19. int local; /* unprocessed amount in data */
  20. } SHA_INFO;
  21. void ShaInit(SHA_INFO *);
  22. void ShaUpdate(SHA_INFO *, SHA_BYTE *, int);
  23. void ShaFinal(unsigned char[20], SHA_INFO *);
  24. void ShaOutput(unsigned char[20], unsigned char[40]);
  25. const char *ShaVersion(void);
  26. class Sha1 {
  27. public:
  28. Sha1();
  29. ~Sha1();
  30. void Append(const char *data, unsigned int size);
  31. std::string Final();
  32. private:
  33. SHA_INFO m_sha;
  34. };
  35. } // namespace qcloud_cos
  36. #endif /* SHA_H */