~ubuntu-branches/ubuntu/trusty/unrar-nonfree/trusty-security

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