Merge pull request #4852 from FernetMenta/aefixes
[vuplus_xbmc] / lib / UnrarXLib / crypt.hpp
1 #ifndef _RAR_CRYPT_
2 #define _RAR_CRYPT_
3
4 enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 };
5
6 struct CryptKeyCacheItem
7 {
8 #ifndef _SFX_RTL_
9   CryptKeyCacheItem()
10   {
11     *Password=0;
12   }
13
14   ~CryptKeyCacheItem()
15   {
16     memset(AESKey,0,sizeof(AESKey));
17     memset(AESInit,0,sizeof(AESInit));
18     memset(Password,0,sizeof(Password));
19   }
20 #endif
21   byte AESKey[16],AESInit[16];
22   char Password[MAXPASSWORD];
23   bool SaltPresent;
24   byte Salt[SALT_SIZE];
25 };
26
27 class CryptData
28 {
29   private:
30     void Encode13(byte *Data,uint Count);
31     void Decode13(byte *Data,uint Count);
32     void Crypt15(byte *Data,uint Count);
33     void UpdKeys(byte *Buf);
34     void Swap(byte *Ch1,byte *Ch2);
35     void SetOldKeys(char *Password);
36
37     Rijndael rin;
38     
39     byte SubstTable[256];
40     uint Key[4];
41     ushort OldKey[4];
42     byte PN1,PN2,PN3;
43
44     byte AESKey[16],AESInit[16];
45
46     static CryptKeyCacheItem Cache[4];
47     static int CachePos;
48   public:
49     void SetCryptKeys(char *Password,byte *Salt,bool Encrypt,bool OldOnly=false);
50     void SetAV15Encryption();
51     void SetCmt13Encryption();
52     void EncryptBlock20(byte *Buf);
53     void DecryptBlock20(byte *Buf);
54     void EncryptBlock(byte *Buf,int Size);
55     void DecryptBlock(byte *Buf,int Size);
56     void Crypt(byte *Data,uint Count,int Method);
57     static void SetSalt(byte *Salt,int SaltSize);
58 };
59
60 #endif