hash.hpp 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _RAR_DATAHASH_
  2. #define _RAR_DATAHASH_
  3. enum HASH_TYPE {HASH_NONE,HASH_RAR14,HASH_CRC32,HASH_BLAKE2};
  4. struct HashValue
  5. {
  6. void Init(HASH_TYPE Type);
  7. bool operator == (const HashValue &cmp);
  8. bool operator != (const HashValue &cmp) {return !(*this==cmp);}
  9. HASH_TYPE Type;
  10. union
  11. {
  12. uint CRC32;
  13. byte Digest[SHA256_DIGEST_SIZE];
  14. };
  15. };
  16. #ifdef RAR_SMP
  17. class ThreadPool;
  18. class DataHash;
  19. #endif
  20. class DataHash
  21. {
  22. private:
  23. HASH_TYPE HashType;
  24. uint CurCRC32;
  25. blake2sp_state *blake2ctx;
  26. #ifdef RAR_SMP
  27. ThreadPool *ThPool;
  28. uint MaxThreads;
  29. // Upper limit for maximum threads to prevent wasting threads in pool.
  30. static const uint MaxHashThreads=8;
  31. #endif
  32. public:
  33. DataHash();
  34. ~DataHash();
  35. void Init(HASH_TYPE Type,uint MaxThreads);
  36. void Update(const void *Data,size_t DataSize);
  37. void Result(HashValue *Result);
  38. uint GetCRC32();
  39. bool Cmp(HashValue *CmpValue,byte *Key);
  40. HASH_TYPE Type() {return HashType;}
  41. };
  42. #endif